mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 07:57:39 +00:00
Build on API 21 headers
This commit is contained in:
parent
62e464f706
commit
770b28ca30
14
build.py
14
build.py
@ -330,6 +330,12 @@ def build_binary(args):
|
||||
if 'test' in args.target:
|
||||
flag += ' B_TEST=1'
|
||||
|
||||
if flag:
|
||||
run_ndk_build(flag + ' B_SHARED=1')
|
||||
|
||||
if 'magisk' in args.target:
|
||||
clean_elf()
|
||||
|
||||
if 'magiskinit' in args.target:
|
||||
dump_bin_header()
|
||||
flag += ' B_INIT=1'
|
||||
@ -346,9 +352,6 @@ def build_binary(args):
|
||||
if flag:
|
||||
run_ndk_build(flag)
|
||||
|
||||
if 'magisk' in args.target:
|
||||
clean_elf()
|
||||
|
||||
if 'busybox' in args.target:
|
||||
run_ndk_build('B_BB=1')
|
||||
|
||||
@ -445,16 +448,15 @@ def setup_ndk(args):
|
||||
mv(op.join(ndk_root, f'android-ndk-r{ndk_ver}'), ndk_path)
|
||||
|
||||
header('* Patching static libs')
|
||||
for api in ['16', '21']:
|
||||
for target in ['aarch64-linux-android', 'arm-linux-androideabi',
|
||||
'i686-linux-android', 'x86_64-linux-android']:
|
||||
arch = target.split('-')[0]
|
||||
lib_dir = op.join(
|
||||
ndk_path, 'toolchains', 'llvm', 'prebuilt', f'{os_name}-x86_64',
|
||||
'sysroot', 'usr', 'lib', f'{target}', api)
|
||||
'sysroot', 'usr', 'lib', f'{target}', '21')
|
||||
if not op.exists(lib_dir):
|
||||
continue
|
||||
src_dir = op.join('tools', 'ndk-bins', api, arch)
|
||||
src_dir = op.join('tools', 'ndk-bins', '21', arch)
|
||||
rm(op.join(src_dir, '.DS_Store'))
|
||||
for path in copy_tree(src_dir, lib_dir):
|
||||
vprint(f'Replaced {path}')
|
||||
|
@ -8,7 +8,7 @@ ifdef B_MAGISK
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := magisk
|
||||
LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties libutils libphmap libxhook
|
||||
LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties libutils-shared libphmap libxhook
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
core/applets.cpp \
|
||||
@ -134,7 +134,7 @@ ifneq (,$(wildcard jni/test.cpp))
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := test
|
||||
LOCAL_STATIC_LIBRARIES := libutils libphmap
|
||||
LOCAL_STATIC_LIBRARIES := libutils-shared libphmap
|
||||
LOCAL_SRC_FILES := test.cpp
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
|
@ -3,10 +3,19 @@ APP_CFLAGS := -Wall -Oz -fomit-frame-pointer -flto
|
||||
APP_LDFLAGS := -flto
|
||||
APP_CPPFLAGS := -std=c++17
|
||||
APP_STL := none
|
||||
APP_PLATFORM := android-16
|
||||
APP_PLATFORM := android-21
|
||||
APP_THIN_ARCHIVE := true
|
||||
APP_STRIP_MODE := --strip-all
|
||||
|
||||
ifneq ($(TARGET_ARCH),arm64)
|
||||
ifneq ($(TARGET_ARCH),x86_64)
|
||||
ifndef B_SHARED
|
||||
# Disable fortify on static 32-bit targets
|
||||
APP_CFLAGS += -D_FORTIFY_SOURCE=0 -Wno-macro-redefined
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
# Busybox should use stock libc.a
|
||||
ifdef B_BB
|
||||
APP_PLATFORM := android-22
|
||||
|
@ -11,10 +11,6 @@
|
||||
#define PR_SET_VMA_ANON_NAME 0
|
||||
#endif
|
||||
|
||||
// Missing functions
|
||||
#define getline compat_getline
|
||||
ssize_t compat_getline(char **, size_t *, FILE *);
|
||||
|
||||
// Rename symbols
|
||||
#pragma redefine_extname __system_property_set _system_property_set2
|
||||
#pragma redefine_extname __system_property_find _system_property_find2
|
||||
|
@ -1,3 +1,11 @@
|
||||
// Force using legacy_signal_inlines.h
|
||||
#define __ANDROID_API_BACKUP__ __ANDROID_API__
|
||||
#undef __ANDROID_API__
|
||||
#define __ANDROID_API__ 20
|
||||
#include <android/legacy_signal_inlines.h>
|
||||
#undef __ANDROID_API__
|
||||
#define __ANDROID_API__ __ANDROID_API_BACKUP__
|
||||
|
||||
#include <sys/mount.h>
|
||||
#include <map>
|
||||
|
||||
|
@ -2,14 +2,7 @@ LOCAL_PATH := $(call my-dir)
|
||||
|
||||
# All Magisk common code lives here
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE:= libutils
|
||||
LOCAL_C_INCLUDES := jni/include $(LOCAL_PATH)/include out/generated
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
|
||||
LOCAL_EXPORT_STATIC_LIBRARIES := libcxx
|
||||
LOCAL_STATIC_LIBRARIES := libcxx
|
||||
LOCAL_SRC_FILES := \
|
||||
missing.cpp \
|
||||
UTILS_SRC_FILES := \
|
||||
new.cpp \
|
||||
files.cpp \
|
||||
misc.cpp \
|
||||
@ -18,4 +11,20 @@ LOCAL_SRC_FILES := \
|
||||
xwrap.cpp \
|
||||
stream.cpp
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE:= libutils
|
||||
LOCAL_C_INCLUDES := jni/include $(LOCAL_PATH)/include out/generated
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
|
||||
LOCAL_EXPORT_STATIC_LIBRARIES := libcxx
|
||||
LOCAL_STATIC_LIBRARIES := libcxx
|
||||
LOCAL_SRC_FILES := $(UTILS_SRC_FILES) missing.cpp
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE:= libutils-shared
|
||||
LOCAL_C_INCLUDES := jni/include $(LOCAL_PATH)/include out/generated
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
|
||||
LOCAL_EXPORT_STATIC_LIBRARIES := libcxx
|
||||
LOCAL_STATIC_LIBRARIES := libcxx
|
||||
LOCAL_SRC_FILES := $(UTILS_SRC_FILES)
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
@ -1,19 +1,19 @@
|
||||
/*
|
||||
* Host all missing/incomplete implementation in bionic
|
||||
* Copied from various sources
|
||||
* */
|
||||
// This file implements all missing symbols that should exist in normal API 21
|
||||
// libc.a but missing in our extremely lean libc.a replacements.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
#include <mntent.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include "missing.hpp"
|
||||
extern "C" {
|
||||
|
||||
/* Original source: https://github.com/freebsd/freebsd/blob/master/contrib/file/src/getline.c
|
||||
* License: BSD, full copyright notice please check original source */
|
||||
|
||||
ssize_t compat_getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp) {
|
||||
ssize_t getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp) {
|
||||
char *ptr, *eptr;
|
||||
|
||||
if (*buf == nullptr || *bufsiz == 0) {
|
||||
@ -49,14 +49,14 @@ ssize_t compat_getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp) {
|
||||
}
|
||||
}
|
||||
|
||||
ssize_t compat_getline(char **buf, size_t *bufsiz, FILE *fp) {
|
||||
ssize_t getline(char **buf, size_t *bufsiz, FILE *fp) {
|
||||
return getdelim(buf, bufsiz, '\n', fp);
|
||||
}
|
||||
|
||||
/* Original source: https://android.googlesource.com/platform/bionic/+/master/libc/bionic/mntent.cpp
|
||||
* License: AOSP, full copyright notice please check original source */
|
||||
|
||||
struct mntent *compat_getmntent_r(FILE* fp, struct mntent* e, char* buf, int buf_len) {
|
||||
struct mntent *getmntent_r(FILE *fp, struct mntent *e, char *buf, int buf_len) {
|
||||
memset(e, 0, sizeof(*e));
|
||||
while (fgets(buf, buf_len, fp) != nullptr) {
|
||||
// Entries look like "proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0".
|
||||
@ -79,31 +79,58 @@ struct mntent *compat_getmntent_r(FILE* fp, struct mntent* e, char* buf, int buf
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FILE *compat_setmntent(const char* path, const char* mode) {
|
||||
FILE *setmntent(const char *path, const char *mode) {
|
||||
return fopen(path, mode);
|
||||
}
|
||||
|
||||
int compat_endmntent(FILE* fp) {
|
||||
int endmntent(FILE *fp) {
|
||||
if (fp != nullptr) {
|
||||
fclose(fp);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *compat_hasmntopt(const struct mntent* mnt, const char* opt) {
|
||||
char* token = mnt->mnt_opts;
|
||||
char* const end = mnt->mnt_opts + strlen(mnt->mnt_opts);
|
||||
const size_t optLen = strlen(opt);
|
||||
while (token) {
|
||||
char* const tokenEnd = token + optLen;
|
||||
if (tokenEnd > end) break;
|
||||
if (memcmp(token, opt, optLen) == 0 &&
|
||||
(*tokenEnd == '\0' || *tokenEnd == ',' || *tokenEnd == '=')) {
|
||||
return token;
|
||||
}
|
||||
token = strchr(token, ',');
|
||||
if (token) token++;
|
||||
}
|
||||
return nullptr;
|
||||
// Missing system call wrappers
|
||||
|
||||
int setns(int fd, int nstype) {
|
||||
return syscall(__NR_setns, fd, nstype);
|
||||
}
|
||||
|
||||
int unshare(int flags) {
|
||||
return syscall(__NR_unshare, flags);
|
||||
}
|
||||
|
||||
int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
|
||||
return syscall(__NR_accept4, sockfd, addr, addrlen, flags);
|
||||
}
|
||||
|
||||
int dup3(int oldfd, int newfd, int flags) {
|
||||
return syscall(__NR_dup3, oldfd, newfd, flags);
|
||||
}
|
||||
|
||||
ssize_t readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz) {
|
||||
return syscall(__NR_readlinkat, dirfd, pathname, buf, bufsiz);
|
||||
}
|
||||
|
||||
int symlinkat(const char *target, int newdirfd, const char *linkpath) {
|
||||
return syscall(__NR_symlinkat, target, newdirfd, linkpath);
|
||||
}
|
||||
|
||||
int linkat(int olddirfd, const char *oldpath,
|
||||
int newdirfd, const char *newpath, int flags) {
|
||||
return syscall(__NR_linkat, olddirfd, oldpath, newdirfd, newpath, flags);
|
||||
}
|
||||
|
||||
int inotify_init1(int flags) {
|
||||
return syscall(__NR_inotify_init1, flags);
|
||||
}
|
||||
|
||||
int faccessat(int dirfd, const char *pathname, int mode, int flags) {
|
||||
return syscall(__NR_faccessat, dirfd, pathname, mode, flags);
|
||||
}
|
||||
|
||||
#if !defined(__LP64__)
|
||||
void android_set_abort_message(const char *msg) {}
|
||||
#endif
|
||||
|
||||
} // extern "C"
|
||||
|
@ -2,73 +2,8 @@
|
||||
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#include <mntent.h>
|
||||
|
||||
// Missing libc functions
|
||||
#define getline compat_getline
|
||||
#define getdelim compat_getdelim
|
||||
#define getmntent_r compat_getmntent_r
|
||||
#define setmntent compat_setmntent
|
||||
#define endmntent compat_endmntent
|
||||
#define hasmntopt compat_hasmntopt
|
||||
|
||||
// Missing syscall wrappers
|
||||
#define setns compat_setns
|
||||
#define unshare compat_unshare
|
||||
#define accept4 compat_accept4
|
||||
#define dup3 compat_dup3
|
||||
#define readlinkat compat_readlinkat
|
||||
#define symlinkat compat_symlinkat
|
||||
#define linkat compat_linkat
|
||||
#define inotify_init1 compat_inotify_init1
|
||||
#define faccessat compat_faccessat
|
||||
#define sigtimedwait compat_sigtimedwait
|
||||
|
||||
ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream);
|
||||
ssize_t compat_getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
|
||||
struct mntent *compat_getmntent_r(FILE* fp, struct mntent* e, char* buf, int buf_len);
|
||||
FILE *compat_setmntent(const char* path, const char* mode);
|
||||
int compat_endmntent(FILE* fp);
|
||||
char *compat_hasmntopt(const struct mntent* mnt, const char* opt);
|
||||
|
||||
static inline int compat_setns(int fd, int nstype) {
|
||||
return syscall(__NR_setns, fd, nstype);
|
||||
}
|
||||
|
||||
static inline int compat_unshare(int flags) {
|
||||
return syscall(__NR_unshare, flags);
|
||||
}
|
||||
|
||||
static inline int compat_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
|
||||
return syscall(__NR_accept4, sockfd, addr, addrlen, flags);
|
||||
}
|
||||
|
||||
static inline int compat_dup3(int oldfd, int newfd, int flags) {
|
||||
return syscall(__NR_dup3, oldfd, newfd, flags);
|
||||
}
|
||||
|
||||
static inline ssize_t compat_readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz) {
|
||||
return syscall(__NR_readlinkat, dirfd, pathname, buf, bufsiz);
|
||||
}
|
||||
|
||||
static inline int compat_symlinkat(const char *target, int newdirfd, const char *linkpath) {
|
||||
return syscall(__NR_symlinkat, target, newdirfd, linkpath);
|
||||
}
|
||||
|
||||
static inline int compat_linkat(int olddirfd, const char *oldpath,
|
||||
int newdirfd, const char *newpath, int flags) {
|
||||
return syscall(__NR_linkat, olddirfd, oldpath, newdirfd, newpath, flags);
|
||||
}
|
||||
|
||||
static inline int compat_inotify_init1(int flags) {
|
||||
return syscall(__NR_inotify_init1, flags);
|
||||
}
|
||||
|
||||
static inline int compat_faccessat(int dirfd, const char *pathname, int mode, int flags) {
|
||||
return syscall(__NR_faccessat, dirfd, pathname, mode, flags);
|
||||
}
|
||||
|
||||
static inline int compat_sigtimedwait(const sigset_t* set, siginfo_t* info, const timespec* timeout) {
|
||||
static inline int sigtimedwait(const sigset_t* set, siginfo_t* info, const timespec* timeout) {
|
||||
union {
|
||||
sigset_t set;
|
||||
sigset_t set64;
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/xattr.h>
|
||||
|
||||
#include <utils.hpp>
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <unistd.h>
|
||||
#include <cstddef>
|
||||
|
||||
#include <utils.hpp>
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/inotify.h>
|
||||
|
||||
#include <utils.hpp>
|
||||
|
||||
@ -198,26 +199,9 @@ int xlisten(int sockfd, int backlog) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int accept4_compat(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
|
||||
int fd = accept(sockfd, addr, addrlen);
|
||||
if (fd < 0) {
|
||||
PLOGE("accept");
|
||||
} else {
|
||||
if (flags & SOCK_CLOEXEC)
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
if (flags & SOCK_NONBLOCK) {
|
||||
int i = fcntl(fd, F_GETFL);
|
||||
fcntl(fd, F_SETFL, i | O_NONBLOCK);
|
||||
}
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
|
||||
int fd = accept4(sockfd, addr, addrlen, flags);
|
||||
if (fd < 0) {
|
||||
if (errno == ENOSYS)
|
||||
return accept4_compat(sockfd, addr, addrlen, flags);
|
||||
PLOGE("accept4");
|
||||
}
|
||||
return fd;
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user