-
Notifications
You must be signed in to change notification settings - Fork 0
/
java-17.c
123 lines (100 loc) · 3.44 KB
/
java-17.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright (c) 2023-2024 Thomas Frohwein
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <jni.h> /* /usr/local/jdk-1.8.0/include/jni.h etc for 11, 17 */
#include "rigg.h"
#include "rigg_unveil.h"
static const unveil_pair unveils[] = {
};
int java17(int argc, char** argv) {
errx(1, "not implemented: java");
return 1;
#if 0
/* https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html */
JavaVM *jvm;
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption *options = new JavaVMOption[1];
options[0].optionString = "-Djava.class.path=/usr/local/jdk-17";
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = false
JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
delete options;
/* invoke the specified method */
jclass cls = env->FindClass("Main"); /* XXX: replace Main */
jmethodID mid = env->GetStaticMethodID(cls, "test", "(I)V"); /* XXX: replace test */
env->CallStaticVoidMethod(cls, mid, 100);
jvm->DestroyJavaVM();
#endif
#if 0
vprintf("unveiling:\n");
for (i = 0; i < sizeof(unveils) / sizeof(unveils[0]); i++) {
uvp = unveils[i];
vprintf(UNVEIL_VPRINT_FMT, uvp.path, uvp.permissions);
unveil_err(uvp.path, uvp.permissions);
}
if ((home_dir = getenv("HOME")) == NULL)
err(1, "getenv(\"HOME\")");
if (snprintf(config_dir, sizeof(config_dir), "%s/.config", home_dir) < 0)
err(1, "snprintf");
else {
vprintf(UNVEIL_VPRINT_FMT, config_dir, "rwc");
unveil_err(config_dir, "rwc");
}
if (snprintf(localshare_dir, sizeof(localshare_dir), "%s/.local/share", home_dir) < 0)
err(1, "snprintf");
else {
vprintf(UNVEIL_VPRINT_FMT, localshare_dir, "rwc");
unveil_err(localshare_dir, "rwc");
}
if (snprintf(sndio_dir, sizeof(sndio_dir), "%s/.sndio", home_dir) < 0)
err(1, "snprintf");
else {
vprintf(UNVEIL_VPRINT_FMT, sndio_dir, "rwc");
unveil_err(sndio_dir, "rwc");
}
if (snprintf(xauthority, sizeof(xauthority), "%s/.Xauthority", home_dir) < 0)
err(1, "snprintf");
else {
vprintf(UNVEIL_VPRINT_FMT, xauthority, "rw");
unveil_err(xauthority, "rw");
}
if ((xdg_data_home = getenv("XDG_DATA_HOME")) != NULL) {
vprintf(UNVEIL_VPRINT_FMT, xdg_data_home, "rwc");
unveil_err(xdg_data_home, "rwc");
}
/* hide incompatible bundled files */
for (i = 0; i < sizeof(unveil_hide) / sizeof(unveil_hide[0]); i++) {
if (access(unveil_hide[i], F_OK) == 0) {
vprintf(UNVEIL_VPRINT_FMT, unveil_hide[i], "");
unveil_err(unveil_hide[i], "");
}
}
vprintf("\n");
unveil_err(NULL, NULL);
vprintf("executing mono jit with the following arguments:");
for (i = 0; i < argc; i++)
vprintf(" \"%s\"", argv[i]);
vprintf("\n\n");
vprintf("cleaning up...\n");
return r;
#endif
}