From d783b6c4135ecf437cb4fd5b212d74c03ff14352 Mon Sep 17 00:00:00 2001 From: eventlOwOp <3064273390@qq.com> Date: Sat, 5 Apr 2025 17:57:55 +0800 Subject: [PATCH] [fix] NDK pthread_np support --- build/patch.py | 35 ++++++++++++++++++++++++++--------- magisk/handle.sh | 5 +++++ magisk/lib.sh | 5 +++++ magisk/service.sh | 5 ----- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/build/patch.py b/build/patch.py index e7b0cd5..6a9195f 100644 --- a/build/patch.py +++ b/build/patch.py @@ -28,6 +28,25 @@ with open(config_toml_path, 'w') as f: # ------------------------------------------------------------------------------------------------------- +# Patch ZeroTierOne/osdep/LinuxEthernetTap.cpp + +linux_tap_path = 'ZeroTierOne/osdep/LinuxEthernetTap.cpp' + +linux_tap_match1 = 'int rc = pthread_setaffinity_np(self, sizeof(cpu_set_t), &cpuset);' +linux_tap_replace1 = 'int rc = sched_setaffinity(pthread_gettid_np(self), sizeof(cpu_set_t), &cpuset);' + +linxu_tap_match2 = '#include ' +linux_tap_replace2 = '#include \n#include ' + +with open(linux_tap_path, 'r') as file: + data = file.read() + patch_NDK = data.replace(linux_tap_match1, linux_tap_replace1).replace(linux_tap_match2, linux_tap_replace2) + +with open(linux_tap_path, 'w') as file: + file.write(patch_NDK) + +# ------------------------------------------------------------------------------------------------------- + # Patch make-linux.mk make_linux_path = 'ZeroTierOne/make-linux.mk' @@ -57,19 +76,17 @@ with open(make_linux_path, 'r') as file: 'override CFLAGS+=-march=armv7-a -marm -mfpu=vfp -fexceptions' ) - with open(make_linux_path + '.aarch64', 'w') as file: - file.write(patch_aarch64) - with open(make_linux_path + '.arm', 'w') as file: - file.write(patch_arm) - with open(make_linux_path + '.arm.ndk', 'w') as file: - file.write(patch_arm_ndk) +with open(make_linux_path + '.aarch64', 'w') as file: + file.write(patch_aarch64) +with open(make_linux_path + '.arm', 'w') as file: + file.write(patch_arm) +with open(make_linux_path + '.arm.ndk', 'w') as file: + file.write(patch_arm_ndk) # Patch ZeroTierOne/osdep/OSUtils.cpp osutil_path = 'ZeroTierOne/osdep/OSUtils.cpp' with open(osutil_path, 'r') as file: - data = file.read().replace( - '/var/lib/zerotier-one', '/data/adb/zerotier/home' - ) + data = file.read().replace('/var/lib/zerotier-one', '/data/adb/zerotier/home') with open(osutil_path, 'w') as file: file.write(data) \ No newline at end of file diff --git a/magisk/handle.sh b/magisk/handle.sh index ee99d6e..6ed9038 100644 --- a/magisk/handle.sh +++ b/magisk/handle.sh @@ -21,6 +21,11 @@ _stop() { fi kill -9 $pid + + # delete from ip rules + ip rule del from all lookup main pref 1 + ip -6 rule del from all lookup main pref 1 + if [[ $? -ne 0 ]]; then log "kill zerotier-one failed" return diff --git a/magisk/lib.sh b/magisk/lib.sh index a0504bf..e52fcaf 100644 --- a/magisk/lib.sh +++ b/magisk/lib.sh @@ -13,5 +13,10 @@ PIPE_APP=$APPROOT/run/pipe export LD_LIBRARY_PATH=/system/lib64:/data/adb/zerotier/lib __start() { + # add main route table to lookup rules + ip rule add from all lookup main pref 1 + ip -6 rule add from all lookup main pref 1 + + # start zerotier daemon nohup $ZTROOT/zerotier-one -d >> $ZT_LOG 2>&1 & } \ No newline at end of file diff --git a/magisk/service.sh b/magisk/service.sh index 0acdbb4..6ec2c82 100644 --- a/magisk/service.sh +++ b/magisk/service.sh @@ -33,11 +33,6 @@ mkdir -p $ZTROOT/run # start zerotier # ---------------------------------------------- -# add main route table to lookup rules -ip rule add from all lookup main pref 1 -ip -6 rule add from all lookup main pref 1 - -# start zerotier __start # ----------------------------------------------