diff options
| author | Po Lu | 2024-07-07 10:19:31 +0800 |
|---|---|---|
| committer | Po Lu | 2024-07-07 10:21:47 +0800 |
| commit | 99e510977b22ca60e48b2af70a3c2cdbd90b2b01 (patch) | |
| tree | 272cbf70afee36d54807768fcac0df40ede58a43 /src | |
| parent | bbe95a8ceabfa1f4ad2064e1607fe64cf56434fd (diff) | |
| download | emacs-99e510977b22ca60e48b2af70a3c2cdbd90b2b01.tar.gz emacs-99e510977b22ca60e48b2af70a3c2cdbd90b2b01.zip | |
Correct JNI string error checking and miscellaneous corrections
* src/android-emacs.c (main): Do not attempt to load the
bootstrap class path, which is redundant on all Android releases.
* src/android.c (initEmacs, android_browse_url): Do not assume
exceptions will be raised if GetStringUTFChars fails. Decode
Android JNI strings as Qandroid_jni.
* src/androidvfs.c (android_saf_check_nonnull): New function.
(android_saf_new_mkdir): Likewise.
Diffstat (limited to 'src')
| -rw-r--r-- | src/android-emacs.c | 63 | ||||
| -rw-r--r-- | src/android.c | 10 | ||||
| -rw-r--r-- | src/androidvfs.c | 33 |
3 files changed, 42 insertions, 64 deletions
diff --git a/src/android-emacs.c b/src/android-emacs.c index 5a43445612a..d68734da1bd 100644 --- a/src/android-emacs.c +++ b/src/android-emacs.c | |||
| @@ -52,49 +52,6 @@ main (int argc, char **argv) | |||
| 52 | args[0] = (char *) "/system/bin/app_process"; | 52 | args[0] = (char *) "/system/bin/app_process"; |
| 53 | #endif /* __x86_64__ || __aarch64__ || __mips64 */ | 53 | #endif /* __x86_64__ || __aarch64__ || __mips64 */ |
| 54 | 54 | ||
| 55 | /* Machines with ART require the boot classpath to be manually | ||
| 56 | specified. Machines with Dalvik however refuse to do so, as they | ||
| 57 | open the jars inside the BOOTCLASSPATH environment variable at | ||
| 58 | startup, resulting in the following crash: | ||
| 59 | |||
| 60 | W/dalvikvm( 1608): Refusing to reopen boot DEX | ||
| 61 | '/system/framework/core.jar' | ||
| 62 | W/dalvikvm( 1608): Refusing to reopen boot DEX | ||
| 63 | '/system/framework/bouncycastle.jar' | ||
| 64 | E/dalvikvm( 1608): Too many exceptions during init (failed on | ||
| 65 | 'Ljava/io/IOException;' 'Re-opening BOOTCLASSPATH DEX files is | ||
| 66 | not allowed') | ||
| 67 | E/dalvikvm( 1608): VM aborting */ | ||
| 68 | |||
| 69 | #if HAVE_DECL_ANDROID_GET_DEVICE_API_LEVEL | ||
| 70 | if (android_get_device_api_level () < 21) | ||
| 71 | { | ||
| 72 | bootclasspath = NULL; | ||
| 73 | goto skip_setup; | ||
| 74 | } | ||
| 75 | #else /* !HAVE_DECL_ANDROID_GET_DEVICE_API_LEVEL */ | ||
| 76 | if (__ANDROID_API__ < 21) | ||
| 77 | { | ||
| 78 | bootclasspath = NULL; | ||
| 79 | goto skip_setup; | ||
| 80 | } | ||
| 81 | #endif /* HAVE_DECL_ANDROID_GET_DEVICE_API_LEVEL */ | ||
| 82 | |||
| 83 | /* Next, obtain the boot class path. */ | ||
| 84 | bootclasspath = getenv ("BOOTCLASSPATH"); | ||
| 85 | |||
| 86 | if (!bootclasspath) | ||
| 87 | { | ||
| 88 | fprintf (stderr, "The BOOTCLASSPATH environment variable" | ||
| 89 | " is not set. As a result, Emacs does not know" | ||
| 90 | " how to start app_process.\n" | ||
| 91 | "This is likely a change in the Android platform." | ||
| 92 | " Please report this to bug-gnu-emacs@gnu.org.\n"); | ||
| 93 | return 1; | ||
| 94 | } | ||
| 95 | |||
| 96 | skip_setup: | ||
| 97 | |||
| 98 | /* And the Emacs class path. */ | 55 | /* And the Emacs class path. */ |
| 99 | emacs_class_path = getenv ("EMACS_CLASS_PATH"); | 56 | emacs_class_path = getenv ("EMACS_CLASS_PATH"); |
| 100 | 57 | ||
| @@ -115,23 +72,11 @@ main (int argc, char **argv) | |||
| 115 | if (ld_library_path) | 72 | if (ld_library_path) |
| 116 | setenv ("LD_LIBRARY_PATH", ld_library_path, 1); | 73 | setenv ("LD_LIBRARY_PATH", ld_library_path, 1); |
| 117 | 74 | ||
| 118 | if (bootclasspath) | 75 | if (asprintf (&bootclasspath, "-Djava.class.path=%s", |
| 76 | emacs_class_path) < 0) | ||
| 119 | { | 77 | { |
| 120 | if (asprintf (&bootclasspath, "-Djava.class.path=%s:%s", | 78 | perror ("asprintf"); |
| 121 | bootclasspath, emacs_class_path) < 0) | 79 | return 1; |
| 122 | { | ||
| 123 | perror ("asprintf"); | ||
| 124 | return 1; | ||
| 125 | } | ||
| 126 | } | ||
| 127 | else | ||
| 128 | { | ||
| 129 | if (asprintf (&bootclasspath, "-Djava.class.path=%s", | ||
| 130 | emacs_class_path) < 0) | ||
| 131 | { | ||
| 132 | perror ("asprintf"); | ||
| 133 | return 1; | ||
| 134 | } | ||
| 135 | } | 80 | } |
| 136 | 81 | ||
| 137 | args[1] = bootclasspath; | 82 | args[1] = bootclasspath; |
diff --git a/src/android.c b/src/android.c index 3c0e3ee1558..f90ebc04925 100644 --- a/src/android.c +++ b/src/android.c | |||
| @@ -2019,6 +2019,8 @@ NATIVE_NAME (initEmacs) (JNIEnv *env, jobject object, jarray argv, | |||
| 2019 | c_argument | 2019 | c_argument |
| 2020 | = (*env)->GetStringUTFChars (env, (jstring) dump_file_object, | 2020 | = (*env)->GetStringUTFChars (env, (jstring) dump_file_object, |
| 2021 | NULL); | 2021 | NULL); |
| 2022 | if (!c_argument) | ||
| 2023 | emacs_abort (); | ||
| 2022 | 2024 | ||
| 2023 | /* Copy the Java string data once. */ | 2025 | /* Copy the Java string data once. */ |
| 2024 | dump_file = strdup (c_argument); | 2026 | dump_file = strdup (c_argument); |
| @@ -6497,18 +6499,18 @@ android_browse_url (Lisp_Object url, Lisp_Object send) | |||
| 6497 | buffer = (*android_java_env)->GetStringUTFChars (android_java_env, | 6499 | buffer = (*android_java_env)->GetStringUTFChars (android_java_env, |
| 6498 | (jstring) value, | 6500 | (jstring) value, |
| 6499 | NULL); | 6501 | NULL); |
| 6500 | android_exception_check_1 (value); | 6502 | android_exception_check_nonnull ((void *) buffer, value); |
| 6501 | 6503 | ||
| 6502 | /* Otherwise, build the string describing the error. */ | 6504 | /* Otherwise, build the string describing the error. */ |
| 6503 | tem = build_string_from_utf8 (buffer); | 6505 | tem = build_unibyte_string (buffer); |
| 6504 | 6506 | ||
| 6505 | (*android_java_env)->ReleaseStringUTFChars (android_java_env, | 6507 | (*android_java_env)->ReleaseStringUTFChars (android_java_env, |
| 6506 | (jstring) value, | 6508 | (jstring) value, |
| 6507 | buffer); | 6509 | buffer); |
| 6508 | 6510 | ||
| 6509 | /* And return it. */ | 6511 | /* And decode and return the same. */ |
| 6510 | ANDROID_DELETE_LOCAL_REF (value); | 6512 | ANDROID_DELETE_LOCAL_REF (value); |
| 6511 | return tem; | 6513 | return code_convert_string_norecord (tem, Qandroid_jni, false); |
| 6512 | } | 6514 | } |
| 6513 | 6515 | ||
| 6514 | /* Tell the system to restart Emacs in a short amount of time, and | 6516 | /* Tell the system to restart Emacs in a short amount of time, and |
diff --git a/src/androidvfs.c b/src/androidvfs.c index 346eb639b11..2427708be34 100644 --- a/src/androidvfs.c +++ b/src/androidvfs.c | |||
| @@ -3162,6 +3162,37 @@ android_saf_exception_check (int n, ...) | |||
| 3162 | return 1; | 3162 | return 1; |
| 3163 | } | 3163 | } |
| 3164 | 3164 | ||
| 3165 | /* Verify that OBJECT is non-NULL. If NULL, free each of the N local | ||
| 3166 | references given as arguments, and clear exceptions. | ||
| 3167 | |||
| 3168 | Value is 1 if it be NULL, 0 otherwise. */ | ||
| 3169 | |||
| 3170 | static int | ||
| 3171 | android_saf_check_nonnull (jobject object, int n, ...) | ||
| 3172 | { | ||
| 3173 | va_list ap; | ||
| 3174 | |||
| 3175 | if (object) | ||
| 3176 | return 0; | ||
| 3177 | |||
| 3178 | va_start (ap, n); | ||
| 3179 | |||
| 3180 | /* Clear the active exception, making it safe to subsequently call | ||
| 3181 | other JNI functions. */ | ||
| 3182 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 3183 | |||
| 3184 | /* Delete each of the N arguments. */ | ||
| 3185 | |||
| 3186 | while (n > 0) | ||
| 3187 | { | ||
| 3188 | ANDROID_DELETE_LOCAL_REF (va_arg (ap, jobject)); | ||
| 3189 | n--; | ||
| 3190 | } | ||
| 3191 | |||
| 3192 | va_end (ap); | ||
| 3193 | return 1; | ||
| 3194 | } | ||
| 3195 | |||
| 3165 | 3196 | ||
| 3166 | 3197 | ||
| 3167 | /* Content authority-based vnode implementation. | 3198 | /* Content authority-based vnode implementation. |
| @@ -6428,7 +6459,7 @@ android_saf_new_mkdir (struct android_vnode *vnode, mode_t mode) | |||
| 6428 | new_doc_id = (*android_java_env)->GetStringUTFChars (android_java_env, | 6459 | new_doc_id = (*android_java_env)->GetStringUTFChars (android_java_env, |
| 6429 | new_id, NULL); | 6460 | new_id, NULL); |
| 6430 | 6461 | ||
| 6431 | if (android_saf_exception_check (3, name, id, uri)) | 6462 | if (android_saf_check_nonnull (new_doc_id, 3, name, id, uri)) |
| 6432 | return -1; | 6463 | return -1; |
| 6433 | 6464 | ||
| 6434 | xfree (vp->document_id); | 6465 | xfree (vp->document_id); |