From 9c6e64f47d5c9f4dc776cf83ec5d008d2b8eb1f7 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 21 Feb 2018 14:44:24 +0800 Subject: [PATCH] Workaround compiler optimization bug --- native/jni/core/magiskinit.c | 2 +- native/jni/core/socket.c | 4 +++- native/jni/include/magisk.h | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/native/jni/core/magiskinit.c b/native/jni/core/magiskinit.c index bcabec5a5..d555a9a04 100644 --- a/native/jni/core/magiskinit.c +++ b/native/jni/core/magiskinit.c @@ -339,7 +339,7 @@ static void patch_socket_name(const char *path) { mmap_rw(path, &buf, &size); if (SOCKET_OFF < 0) { for (int i = 0; i < size; ++i) { - if (memcmp(buf + i, SOCKET_NAME, sizeof(SOCKET_NAME)) == 0) { + if (memcmp(buf + i, socket_name, sizeof(SOCKET_NAME)) == 0) { SOCKET_OFF = i; break; } diff --git a/native/jni/core/socket.c b/native/jni/core/socket.c index e99f3d590..9b1d8bd17 100644 --- a/native/jni/core/socket.c +++ b/native/jni/core/socket.c @@ -8,13 +8,15 @@ #include "utils.h" #include "magisk.h" +char socket_name[] = SOCKET_NAME; + /* Setup the address and return socket fd */ int setup_socket(struct sockaddr_un *sun) { int fd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); memset(sun, 0, sizeof(*sun)); sun->sun_family = AF_LOCAL; sun->sun_path[0] = '\0'; - memcpy(sun->sun_path + 1, SOCKET_NAME, sizeof(SOCKET_NAME)); + memcpy(sun->sun_path + 1, socket_name, sizeof(SOCKET_NAME)); return fd; } diff --git a/native/jni/include/magisk.h b/native/jni/include/magisk.h index 6564ebc41..1f15c7df3 100644 --- a/native/jni/include/magisk.h +++ b/native/jni/include/magisk.h @@ -55,6 +55,7 @@ extern char *argv0; /* For changing process name */ #define init_applet ((char *[]) { "magiskpolicy", "supolicy", NULL }) extern int (*applet_main[]) (int, char *[]), (*init_applet_main[]) (int, char *[]); +extern char socket_name[]; /* Workaround compiler bug pre NDK r13 */ int create_links(const char *bin, const char *path);