aboutsummaryrefslogtreecommitdiffstats
path: root/src/android.c
diff options
context:
space:
mode:
authorPo Lu2023-02-25 21:52:11 +0800
committerPo Lu2023-02-25 21:52:11 +0800
commit8fa86cc7cd708fae8657b4e977711132999054bc (patch)
tree5b4b5984bb8ed5914fb7e34aba124e01852b7e56 /src/android.c
parent80f26cc3988bf06e876ee9ed4b05a4400bf626b7 (diff)
downloademacs-8fa86cc7cd708fae8657b4e977711132999054bc.tar.gz
emacs-8fa86cc7cd708fae8657b4e977711132999054bc.zip
Update Android port
* java/debug.sh (is_root): Fix tee detection again for old systems which don't return exit codes from adb shell. * src/android.c (android_run_select_thread, NATIVE_NAME, JNICALL): * src/android.h (NATIVE_NAME): * src/androidterm.c (JNICALL, NATIVE_NAME): Apply stack alignment to all JNICALL functions.
Diffstat (limited to 'src/android.c')
-rw-r--r--src/android.c97
1 files changed, 81 insertions, 16 deletions
diff --git a/src/android.c b/src/android.c
index 50871c94987..99c612f13df 100644
--- a/src/android.c
+++ b/src/android.c
@@ -224,9 +224,13 @@ static struct android_emacs_window window_class;
224 stored in unsigned long to be consistent with X. */ 224 stored in unsigned long to be consistent with X. */
225unsigned int event_serial; 225unsigned int event_serial;
226 226
227#ifdef __i386__
228
227/* Unused pointer used to control compiler optimizations. */ 229/* Unused pointer used to control compiler optimizations. */
228void *unused_pointer; 230void *unused_pointer;
229 231
232#endif /* __i386__ */
233
230 234
231 235
232/* Event handling functions. Events are stored on a (circular) queue 236/* Event handling functions. Events are stored on a (circular) queue
@@ -295,10 +299,13 @@ static int select_pipe[2];
295static void * 299static void *
296android_run_select_thread (void *data) 300android_run_select_thread (void *data)
297{ 301{
302 /* Apparently this is required too. */
303 JNI_STACK_ALIGNMENT_PROLOGUE;
304
298 int rc; 305 int rc;
299#if __ANDROID_API__ < 16 306#if __ANDROID_API__ < 16
300 int nfds; 307 int nfds;
301 fd_set readfds; 308 fd_set readfds, writefds;
302 char byte; 309 char byte;
303#else 310#else
304 sigset_t signals, waitset; 311 sigset_t signals, waitset;
@@ -325,23 +332,29 @@ android_run_select_thread (void *data)
325 332
326 pthread_mutex_lock (&event_queue.select_mutex); 333 pthread_mutex_lock (&event_queue.select_mutex);
327 nfds = android_pselect_nfds; 334 nfds = android_pselect_nfds;
328 readfds = *android_pselect_readfds; 335
336 if (android_pselect_readfds)
337 readfds = *android_pselect_readfds;
338 else
339 FD_ZERO (&readfds);
329 340
330 if (nfds < select_pipe[0] + 1) 341 if (nfds < select_pipe[0] + 1)
331 nfds = select_pipe[0] + 1; 342 nfds = select_pipe[0] + 1;
332 FD_SET (select_pipe[0], &readfds); 343 FD_SET (select_pipe[0], &readfds);
333 344
334 rc = pselect (nfds, &readfds, 345 rc = pselect (nfds, &readfds, &writefds,
335 android_pselect_writefds,
336 android_pselect_exceptfds, 346 android_pselect_exceptfds,
337 android_pselect_timeout, 347 android_pselect_timeout,
338 NULL); 348 NULL);
339 349
340 /* Subtract 1 from rc if writefds contains the select pipe. */ 350 /* Subtract 1 from rc if writefds contains the select pipe. */
341 if (FD_ISSET (select_pipe[0], 351 if (FD_ISSET (select_pipe[0], &writefds))
342 android_pselect_writefds))
343 rc -= 1; 352 rc -= 1;
344 353
354 /* Save the writefds back again. */
355 if (android_pselect_writefds)
356 *android_pselect_writefds = writefds;
357
345 android_pselect_rc = rc; 358 android_pselect_rc = rc;
346 pthread_mutex_unlock (&event_queue.select_mutex); 359 pthread_mutex_unlock (&event_queue.select_mutex);
347 360
@@ -1641,12 +1654,16 @@ android_proc_name (int fd, char *buffer, size_t size)
1641JNIEXPORT jint JNICALL 1654JNIEXPORT jint JNICALL
1642NATIVE_NAME (dup) (JNIEnv *env, jobject object, jint fd) 1655NATIVE_NAME (dup) (JNIEnv *env, jobject object, jint fd)
1643{ 1656{
1657 JNI_STACK_ALIGNMENT_PROLOGUE;
1658
1644 return dup (fd); 1659 return dup (fd);
1645} 1660}
1646 1661
1647JNIEXPORT jstring JNICALL 1662JNIEXPORT jstring JNICALL
1648NATIVE_NAME (getFingerprint) (JNIEnv *env, jobject object) 1663NATIVE_NAME (getFingerprint) (JNIEnv *env, jobject object)
1649{ 1664{
1665 JNI_STACK_ALIGNMENT_PROLOGUE;
1666
1650 char buffer[sizeof fingerprint * 2 + 1]; 1667 char buffer[sizeof fingerprint * 2 + 1];
1651 1668
1652 memset (buffer, 0, sizeof buffer); 1669 memset (buffer, 0, sizeof buffer);
@@ -1666,6 +1683,8 @@ NATIVE_NAME (setEmacsParams) (JNIEnv *env, jobject object,
1666 jobject class_path, 1683 jobject class_path,
1667 jobject emacs_service_object) 1684 jobject emacs_service_object)
1668{ 1685{
1686 JNI_STACK_ALIGNMENT_PROLOGUE;
1687
1669 int pipefd[2]; 1688 int pipefd[2];
1670 pthread_t thread; 1689 pthread_t thread;
1671 const char *java_string; 1690 const char *java_string;
@@ -1864,6 +1883,8 @@ NATIVE_NAME (setEmacsParams) (JNIEnv *env, jobject object,
1864JNIEXPORT jobject JNICALL 1883JNIEXPORT jobject JNICALL
1865NATIVE_NAME (getProcName) (JNIEnv *env, jobject object, jint fd) 1884NATIVE_NAME (getProcName) (JNIEnv *env, jobject object, jint fd)
1866{ 1885{
1886 JNI_STACK_ALIGNMENT_PROLOGUE;
1887
1867 char buffer[PATH_MAX + 1]; 1888 char buffer[PATH_MAX + 1];
1868 size_t length; 1889 size_t length;
1869 jbyteArray array; 1890 jbyteArray array;
@@ -2090,22 +2111,20 @@ JNIEXPORT void JNICALL
2090NATIVE_NAME (initEmacs) (JNIEnv *env, jobject object, jarray argv, 2111NATIVE_NAME (initEmacs) (JNIEnv *env, jobject object, jarray argv,
2091 jobject dump_file_object, jint api_level) 2112 jobject dump_file_object, jint api_level)
2092{ 2113{
2093 char **c_argv;
2094 jsize nelements, i;
2095 jobject argument;
2096 const char *c_argument;
2097 char *dump_file;
2098
2099 /* android_emacs_init is not main, so GCC is not nice enough to add 2114 /* android_emacs_init is not main, so GCC is not nice enough to add
2100 the stack alignment prologue. 2115 the stack alignment prologue.
2101 2116
2102 Unfortunately for us, dalvik on Android 4.0.x calls native code 2117 Unfortunately for us, dalvik on Android 4.0.x calls native code
2103 with a 4 byte aligned stack. */ 2118 with a 4 byte aligned stack, so this prologue must be inserted
2119 before each function exported via JNI. */
2104 2120
2105 __attribute__ ((aligned (32))) char buffer[32]; 2121 JNI_STACK_ALIGNMENT_PROLOGUE;
2106 2122
2107 /* Trick GCC into not optimizing this variable away. */ 2123 char **c_argv;
2108 unused_pointer = buffer; 2124 jsize nelements, i;
2125 jobject argument;
2126 const char *c_argument;
2127 char *dump_file;
2109 2128
2110 /* Set the Android API level. */ 2129 /* Set the Android API level. */
2111 android_api_level = api_level; 2130 android_api_level = api_level;
@@ -2183,12 +2202,16 @@ NATIVE_NAME (initEmacs) (JNIEnv *env, jobject object, jarray argv,
2183JNIEXPORT void JNICALL 2202JNIEXPORT void JNICALL
2184NATIVE_NAME (emacsAbort) (JNIEnv *env, jobject object) 2203NATIVE_NAME (emacsAbort) (JNIEnv *env, jobject object)
2185{ 2204{
2205 JNI_STACK_ALIGNMENT_PROLOGUE;
2206
2186 emacs_abort (); 2207 emacs_abort ();
2187} 2208}
2188 2209
2189JNIEXPORT void JNICALL 2210JNIEXPORT void JNICALL
2190NATIVE_NAME (quit) (JNIEnv *env, jobject object) 2211NATIVE_NAME (quit) (JNIEnv *env, jobject object)
2191{ 2212{
2213 JNI_STACK_ALIGNMENT_PROLOGUE;
2214
2192 Vquit_flag = Qt; 2215 Vquit_flag = Qt;
2193} 2216}
2194 2217
@@ -2198,6 +2221,8 @@ NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object,
2198 jint x, jint y, jint width, 2221 jint x, jint y, jint width,
2199 jint height) 2222 jint height)
2200{ 2223{
2224 JNI_STACK_ALIGNMENT_PROLOGUE;
2225
2201 union android_event event; 2226 union android_event event;
2202 2227
2203 event.xconfigure.type = ANDROID_CONFIGURE_NOTIFY; 2228 event.xconfigure.type = ANDROID_CONFIGURE_NOTIFY;
@@ -2219,6 +2244,8 @@ NATIVE_NAME (sendKeyPress) (JNIEnv *env, jobject object,
2219 jint state, jint keycode, 2244 jint state, jint keycode,
2220 jint unicode_char) 2245 jint unicode_char)
2221{ 2246{
2247 JNI_STACK_ALIGNMENT_PROLOGUE;
2248
2222 union android_event event; 2249 union android_event event;
2223 2250
2224 event.xkey.type = ANDROID_KEY_PRESS; 2251 event.xkey.type = ANDROID_KEY_PRESS;
@@ -2239,6 +2266,8 @@ NATIVE_NAME (sendKeyRelease) (JNIEnv *env, jobject object,
2239 jint state, jint keycode, 2266 jint state, jint keycode,
2240 jint unicode_char) 2267 jint unicode_char)
2241{ 2268{
2269 JNI_STACK_ALIGNMENT_PROLOGUE;
2270
2242 union android_event event; 2271 union android_event event;
2243 2272
2244 event.xkey.type = ANDROID_KEY_RELEASE; 2273 event.xkey.type = ANDROID_KEY_RELEASE;
@@ -2257,6 +2286,8 @@ JNIEXPORT jlong JNICALL
2257NATIVE_NAME (sendFocusIn) (JNIEnv *env, jobject object, 2286NATIVE_NAME (sendFocusIn) (JNIEnv *env, jobject object,
2258 jshort window, jlong time) 2287 jshort window, jlong time)
2259{ 2288{
2289 JNI_STACK_ALIGNMENT_PROLOGUE;
2290
2260 union android_event event; 2291 union android_event event;
2261 2292
2262 event.xfocus.type = ANDROID_FOCUS_IN; 2293 event.xfocus.type = ANDROID_FOCUS_IN;
@@ -2272,6 +2303,8 @@ JNIEXPORT jlong JNICALL
2272NATIVE_NAME (sendFocusOut) (JNIEnv *env, jobject object, 2303NATIVE_NAME (sendFocusOut) (JNIEnv *env, jobject object,
2273 jshort window, jlong time) 2304 jshort window, jlong time)
2274{ 2305{
2306 JNI_STACK_ALIGNMENT_PROLOGUE;
2307
2275 union android_event event; 2308 union android_event event;
2276 2309
2277 event.xfocus.type = ANDROID_FOCUS_OUT; 2310 event.xfocus.type = ANDROID_FOCUS_OUT;
@@ -2287,6 +2320,8 @@ JNIEXPORT jlong JNICALL
2287NATIVE_NAME (sendWindowAction) (JNIEnv *env, jobject object, 2320NATIVE_NAME (sendWindowAction) (JNIEnv *env, jobject object,
2288 jshort window, jint action) 2321 jshort window, jint action)
2289{ 2322{
2323 JNI_STACK_ALIGNMENT_PROLOGUE;
2324
2290 union android_event event; 2325 union android_event event;
2291 2326
2292 event.xaction.type = ANDROID_WINDOW_ACTION; 2327 event.xaction.type = ANDROID_WINDOW_ACTION;
@@ -2303,6 +2338,8 @@ NATIVE_NAME (sendEnterNotify) (JNIEnv *env, jobject object,
2303 jshort window, jint x, jint y, 2338 jshort window, jint x, jint y,
2304 jlong time) 2339 jlong time)
2305{ 2340{
2341 JNI_STACK_ALIGNMENT_PROLOGUE;
2342
2306 union android_event event; 2343 union android_event event;
2307 2344
2308 event.xcrossing.type = ANDROID_ENTER_NOTIFY; 2345 event.xcrossing.type = ANDROID_ENTER_NOTIFY;
@@ -2321,6 +2358,8 @@ NATIVE_NAME (sendLeaveNotify) (JNIEnv *env, jobject object,
2321 jshort window, jint x, jint y, 2358 jshort window, jint x, jint y,
2322 jlong time) 2359 jlong time)
2323{ 2360{
2361 JNI_STACK_ALIGNMENT_PROLOGUE;
2362
2324 union android_event event; 2363 union android_event event;
2325 2364
2326 event.xcrossing.type = ANDROID_LEAVE_NOTIFY; 2365 event.xcrossing.type = ANDROID_LEAVE_NOTIFY;
@@ -2339,6 +2378,8 @@ NATIVE_NAME (sendMotionNotify) (JNIEnv *env, jobject object,
2339 jshort window, jint x, jint y, 2378 jshort window, jint x, jint y,
2340 jlong time) 2379 jlong time)
2341{ 2380{
2381 JNI_STACK_ALIGNMENT_PROLOGUE;
2382
2342 union android_event event; 2383 union android_event event;
2343 2384
2344 event.xmotion.type = ANDROID_MOTION_NOTIFY; 2385 event.xmotion.type = ANDROID_MOTION_NOTIFY;
@@ -2358,6 +2399,8 @@ NATIVE_NAME (sendButtonPress) (JNIEnv *env, jobject object,
2358 jlong time, jint state, 2399 jlong time, jint state,
2359 jint button) 2400 jint button)
2360{ 2401{
2402 JNI_STACK_ALIGNMENT_PROLOGUE;
2403
2361 union android_event event; 2404 union android_event event;
2362 2405
2363 event.xbutton.type = ANDROID_BUTTON_PRESS; 2406 event.xbutton.type = ANDROID_BUTTON_PRESS;
@@ -2379,6 +2422,8 @@ NATIVE_NAME (sendButtonRelease) (JNIEnv *env, jobject object,
2379 jlong time, jint state, 2422 jlong time, jint state,
2380 jint button) 2423 jint button)
2381{ 2424{
2425 JNI_STACK_ALIGNMENT_PROLOGUE;
2426
2382 union android_event event; 2427 union android_event event;
2383 2428
2384 event.xbutton.type = ANDROID_BUTTON_RELEASE; 2429 event.xbutton.type = ANDROID_BUTTON_RELEASE;
@@ -2399,6 +2444,8 @@ NATIVE_NAME (sendTouchDown) (JNIEnv *env, jobject object,
2399 jshort window, jint x, jint y, 2444 jshort window, jint x, jint y,
2400 jlong time, jint pointer_id) 2445 jlong time, jint pointer_id)
2401{ 2446{
2447 JNI_STACK_ALIGNMENT_PROLOGUE;
2448
2402 union android_event event; 2449 union android_event event;
2403 2450
2404 event.touch.type = ANDROID_TOUCH_DOWN; 2451 event.touch.type = ANDROID_TOUCH_DOWN;
@@ -2418,6 +2465,8 @@ NATIVE_NAME (sendTouchUp) (JNIEnv *env, jobject object,
2418 jshort window, jint x, jint y, 2465 jshort window, jint x, jint y,
2419 jlong time, jint pointer_id) 2466 jlong time, jint pointer_id)
2420{ 2467{
2468 JNI_STACK_ALIGNMENT_PROLOGUE;
2469
2421 union android_event event; 2470 union android_event event;
2422 2471
2423 event.touch.type = ANDROID_TOUCH_UP; 2472 event.touch.type = ANDROID_TOUCH_UP;
@@ -2437,6 +2486,8 @@ NATIVE_NAME (sendTouchMove) (JNIEnv *env, jobject object,
2437 jshort window, jint x, jint y, 2486 jshort window, jint x, jint y,
2438 jlong time, jint pointer_id) 2487 jlong time, jint pointer_id)
2439{ 2488{
2489 JNI_STACK_ALIGNMENT_PROLOGUE;
2490
2440 union android_event event; 2491 union android_event event;
2441 2492
2442 event.touch.type = ANDROID_TOUCH_MOVE; 2493 event.touch.type = ANDROID_TOUCH_MOVE;
@@ -2457,6 +2508,8 @@ NATIVE_NAME (sendWheel) (JNIEnv *env, jobject object,
2457 jlong time, jint state, 2508 jlong time, jint state,
2458 jfloat x_delta, jfloat y_delta) 2509 jfloat x_delta, jfloat y_delta)
2459{ 2510{
2511 JNI_STACK_ALIGNMENT_PROLOGUE;
2512
2460 union android_event event; 2513 union android_event event;
2461 2514
2462 event.wheel.type = ANDROID_WHEEL; 2515 event.wheel.type = ANDROID_WHEEL;
@@ -2477,6 +2530,8 @@ JNIEXPORT jlong JNICALL
2477NATIVE_NAME (sendIconified) (JNIEnv *env, jobject object, 2530NATIVE_NAME (sendIconified) (JNIEnv *env, jobject object,
2478 jshort window) 2531 jshort window)
2479{ 2532{
2533 JNI_STACK_ALIGNMENT_PROLOGUE;
2534
2480 union android_event event; 2535 union android_event event;
2481 2536
2482 event.iconified.type = ANDROID_ICONIFIED; 2537 event.iconified.type = ANDROID_ICONIFIED;
@@ -2491,6 +2546,8 @@ JNIEXPORT jlong JNICALL
2491NATIVE_NAME (sendDeiconified) (JNIEnv *env, jobject object, 2546NATIVE_NAME (sendDeiconified) (JNIEnv *env, jobject object,
2492 jshort window) 2547 jshort window)
2493{ 2548{
2549 JNI_STACK_ALIGNMENT_PROLOGUE;
2550
2494 union android_event event; 2551 union android_event event;
2495 2552
2496 event.iconified.type = ANDROID_DEICONIFIED; 2553 event.iconified.type = ANDROID_DEICONIFIED;
@@ -2505,6 +2562,8 @@ JNIEXPORT jlong JNICALL
2505NATIVE_NAME (sendContextMenu) (JNIEnv *env, jobject object, 2562NATIVE_NAME (sendContextMenu) (JNIEnv *env, jobject object,
2506 jshort window, jint menu_event_id) 2563 jshort window, jint menu_event_id)
2507{ 2564{
2565 JNI_STACK_ALIGNMENT_PROLOGUE;
2566
2508 union android_event event; 2567 union android_event event;
2509 2568
2510 event.menu.type = ANDROID_CONTEXT_MENU; 2569 event.menu.type = ANDROID_CONTEXT_MENU;
@@ -2521,6 +2580,8 @@ NATIVE_NAME (sendExpose) (JNIEnv *env, jobject object,
2521 jshort window, jint x, jint y, 2580 jshort window, jint x, jint y,
2522 jint width, jint height) 2581 jint width, jint height)
2523{ 2582{
2583 JNI_STACK_ALIGNMENT_PROLOGUE;
2584
2524 union android_event event; 2585 union android_event event;
2525 2586
2526 event.xexpose.type = ANDROID_EXPOSE; 2587 event.xexpose.type = ANDROID_EXPOSE;
@@ -2543,12 +2604,16 @@ static void android_end_query (void);
2543JNIEXPORT void JNICALL 2604JNIEXPORT void JNICALL
2544NATIVE_NAME (beginSynchronous) (JNIEnv *env, jobject object) 2605NATIVE_NAME (beginSynchronous) (JNIEnv *env, jobject object)
2545{ 2606{
2607 JNI_STACK_ALIGNMENT_PROLOGUE;
2608
2546 android_begin_query (); 2609 android_begin_query ();
2547} 2610}
2548 2611
2549JNIEXPORT void JNICALL 2612JNIEXPORT void JNICALL
2550NATIVE_NAME (endSynchronous) (JNIEnv *env, jobject object) 2613NATIVE_NAME (endSynchronous) (JNIEnv *env, jobject object)
2551{ 2614{
2615 JNI_STACK_ALIGNMENT_PROLOGUE;
2616
2552 android_end_query (); 2617 android_end_query ();
2553} 2618}
2554 2619