diff --git a/luci-app-timewol/Makefile b/luci-app-timewol/Makefile index 7c238ef8..31f6bd1a 100644 --- a/luci-app-timewol/Makefile +++ b/luci-app-timewol/Makefile @@ -1,4 +1,5 @@ -# Copyright (C) 2025 Openwrt.org +# Copyright (C) 2016 Openwrt.org +# Copyright (C) 2025 LWB1978 # # This is free software, licensed under the Apache License, Version 2.0 . # @@ -6,8 +7,8 @@ include $(TOPDIR)/rules.mk LUCI_TITLE:=LuCI support for Timewol -PKG_VERSION:=20250407 -PKG_RELEASE:=4 +PKG_VERSION:=20260422 +PKG_RELEASE:=5 LUCI_DEPENDS:=+luci-base +etherwake LUCI_PKGARCH:=all diff --git a/luci-app-timewol/luasrc/controller/timewol.lua b/luci-app-timewol/luasrc/controller/timewol.lua index 21c07707..af807233 100644 --- a/luci-app-timewol/luasrc/controller/timewol.lua +++ b/luci-app-timewol/luasrc/controller/timewol.lua @@ -1,5 +1,13 @@ +-- Copyright (C) 2025 LWB1978 + module("luci.controller.timewol", package.seeall) +local http = require "luci.http" +local uci = require "luci.model.uci".cursor() +local sys = require "luci.sys" +local json = require "luci.jsonc" +local util = require "luci.util" + function index() if not nixio.fs.access("/etc/config/timewol") then return end @@ -11,36 +19,42 @@ function index() page.acl_depends = { "luci-app-timewol" } entry({"admin", "control", "timewol", "status"}, call("status")).leaf = true - entry({"admin", "control", "timewol", "awake"}, call("awake")).leaf = true + + entry({"admin", "control", "timewol", "wakeup"}, call("wakeup")).leaf = true +end + +local function http_write_json(content) + http.prepare_content("application/json") + http.write(json.stringify(content or {code = 1})) end function status() local e = {} - e.status = luci.sys.call("cat /etc/crontabs/root | grep -v '^[ \t]*#' | grep etherwake >/dev/null") == 0 - luci.http.prepare_content("application/json") - luci.http.write_json(e) + e.status = sys.call("grep -v '^[ \t]*#' /etc/crontabs/root | grep etherwake >/dev/null") == 0 + http_write_json(e) end -function awake(sections) - lan = x:get("timewol",sections,"maceth") - mac = x:get("timewol",sections,"macaddr") - local e = {} - cmd = "/usr/bin/etherwake -D -i " .. lan .. " -b " .. mac .. " 2>&1" - local p = io.popen(cmd) - local msg = "" - if p then - while true do - local l = p:read("*l") - if l then - if #l > 100 then l = l:sub(1, 100) .. "..." end - msg = msg .. l - else - break - end - end - p:close() +function wakeup() + uci:revert("timewol") + local section = http.formvalue("section") or "" + if section == "" then + http_write_json({ success = false, msg = "Missing section" }) + return end - e["data"] = msg - luci.http.prepare_content("application/json") - luci.http.write_json(e) + local maceth = uci:get("timewol", section, "maceth") or "" + local macaddr = uci:get("timewol", section, "macaddr") or "" + if maceth == "" or macaddr == "" then + http_write_json({ success = false, msg = "Missing MAC or interface" }) + return + end + local cmd = string.format( + "/usr/bin/etherwake -D -i %s %s", + util.shellquote(maceth), + util.shellquote(macaddr) + ) + if sys.call(cmd) ~= 0 then + http_write_json({ success = false, msg = "Wake failed" }) + return + end + http_write_json({ success = true }) end diff --git a/luci-app-timewol/luasrc/model/cbi/timewol.lua b/luci-app-timewol/luasrc/model/cbi/timewol.lua index 8efd90f0..cdfa2316 100644 --- a/luci-app-timewol/luasrc/model/cbi/timewol.lua +++ b/luci-app-timewol/luasrc/model/cbi/timewol.lua @@ -1,3 +1,5 @@ +-- Copyright (C) 2025 LWB1978 + local sys = require "luci.sys" local m, s, o @@ -31,6 +33,10 @@ o = s:option(Flag, "enable", translate("Enable")) o.default = 1 o.rmempty = false +o = s:option(Value, "remark", translate("Remarks")) +o.width = "auto" +o.rmempty = false + -- Client MAC Address o = s:option(Value, "macaddr", translate("Client MAC")) o.rmempty = false @@ -48,13 +54,6 @@ for _, device in ipairs(sys.net.devices()) do end end --- wake device -local btn = s:option(Button, "_awake",translate("Wake Up Host")) -btn.inputtitle = translate("Awake") -btn.inputstyle = "apply" -btn.disabled = false -btn.template = "timewol/awake" - -- Function to validate cron field values local function validate_cron_field(option_name, value, min, max, default) if value == "" then @@ -88,6 +87,14 @@ for _, opt in ipairs(schedule_options) do end end +o = s:option(DummyValue, "_Wake") +o.rawhtml = true +o.cfgvalue = function(self, section) + return string.format([[ + ]], + section, translate("Wake")) +end + -- Apply the configuration changes m.apply_on_parse = true function m.on_apply(self) diff --git a/luci-app-timewol/luasrc/view/timewol/awake.htm b/luci-app-timewol/luasrc/view/timewol/awake.htm deleted file mode 100644 index 91cd71b1..00000000 --- a/luci-app-timewol/luasrc/view/timewol/awake.htm +++ /dev/null @@ -1,3 +0,0 @@ -<%+cbi/valueheader%> - " style="font-size: 100%;" type="button" onclick="onclick_awake(this.id)" <%=attr("name", section) .. attr("id", cbid) .. attr("value", self.inputtitle)%> /> -<%+cbi/valuefooter%> diff --git a/luci-app-timewol/luasrc/view/timewol/index.htm b/luci-app-timewol/luasrc/view/timewol/index.htm index b06f2cf5..02fa14ef 100644 --- a/luci-app-timewol/luasrc/view/timewol/index.htm +++ b/luci-app-timewol/luasrc/view/timewol/index.htm @@ -1,11 +1,12 @@ <%# Copyright 2016 Chen RuiWei + Copyright (C) 2025 LWB1978 Licensed to the public under the Apache License 2.0. -%> <% include("cbi/map") %> + + diff --git a/luci-app-timewol/po/zh-cn/timewol.po b/luci-app-timewol/po/zh-cn/timewol.po index 0d8a0523..2020ae8b 100644 --- a/luci-app-timewol/po/zh-cn/timewol.po +++ b/luci-app-timewol/po/zh-cn/timewol.po @@ -52,5 +52,11 @@ msgstr "星期" msgid "Invalid value for %s: %s. Must be between %d and %d or '*'" msgstr "%s: %s 的值无效. 必须在 %d 和 %d 之间,或为 '*'" -msgid "Awake" -msgstr "立即唤醒" +msgid "Remarks" +msgstr "备注" + +msgid "Wake" +msgstr "唤醒" + +msgid "Are you sure you want to wake" +msgstr "你是否要唤醒" diff --git a/luci-app-timewol/root/etc/init.d/timewol b/luci-app-timewol/root/etc/init.d/timewol index 875b6b1a..611cbb91 100755 --- a/luci-app-timewol/root/etc/init.d/timewol +++ b/luci-app-timewol/root/etc/init.d/timewol @@ -1,6 +1,8 @@ #!/bin/sh /etc/rc.common # -# Copyright (C) 2025 OpenWrt.org +# Copyright (C) 2015 OpenWrt-dist +# Copyright (C) 2016 fw867 +# Copyright (C) 2025 LWB1978 # # This is free software, licensed under the GNU General Public License v3. # See /LICENSE for more information. diff --git a/mtproxy/patches/0001-musl-rand_r-function.patch b/mtproxy/patches/0001-musl-rand_r-function.patch deleted file mode 100644 index 70bb59f4..00000000 --- a/mtproxy/patches/0001-musl-rand_r-function.patch +++ /dev/null @@ -1,257 +0,0 @@ -Index: mtproxy/common/server-functions.c -=================================================================== ---- mtproxy.orig/common/server-functions.c -+++ mtproxy/common/server-functions.c -@@ -35,7 +35,9 @@ - #include - #include - #include -+#ifdef __GLIBC__ - #include -+#endif - #include - #include - #include -@@ -168,6 +170,7 @@ const char *get_version_string (void) { - } - - void print_backtrace (void) { -+#ifdef __GLIBC__ - void *buffer[64]; - int nptrs = backtrace (buffer, 64); - kwrite (2, "\n------- Stack Backtrace -------\n", 33); -@@ -178,6 +181,7 @@ void print_backtrace (void) { - kwrite (2, s, strlen (s)); - kwrite (2, "\n", 1); - } -+#endif - } - - pthread_t debug_main_pthread_id; -Index: mtproxy/jobs/jobs.h -=================================================================== ---- mtproxy.orig/jobs/jobs.h -+++ mtproxy/jobs/jobs.h -@@ -27,6 +27,7 @@ - #include "net/net-events.h" - #include "net/net-msg.h" - #include "net/net-timers.h" -+#include "common/randr_compat.h" - - #define __joblocked - #define __jobref -Index: mtproxy/Makefile -=================================================================== ---- mtproxy.orig/Makefile -+++ mtproxy/Makefile -@@ -56,6 +56,7 @@ DEPENDENCE_STRANGE := $(subst ${OBJ}/,${ - DEPENDENCE_NORM := $(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJECTS})) - - LIB_OBJS_NORMAL := \ -+ ${OBJ}/common/randr_compat.o \ - ${OBJ}/common/crc32c.o \ - ${OBJ}/common/pid.o \ - ${OBJ}/common/sha1.o \ -Index: mtproxy/common/randr_compat.c -=================================================================== ---- /dev/null -+++ mtproxy/common/randr_compat.c -@@ -0,0 +1,121 @@ -+/* -+ The GNU C Library is free software. See the file COPYING.LIB for copying -+ conditions, and LICENSES for notices about a few contributions that require -+ these additional notices to be distributed. License copyright years may be -+ listed using range notation, e.g., 2000-2011, indicating that every year in -+ the range, inclusive, is a copyrightable year that would otherwise be listed -+ individually. -+*/ -+ -+#include -+#include "common/randr_compat.h" -+#include -+ -+int __drand48_iterate (unsigned short int xsubi[3], struct drand48_data *buffer) { -+ uint64_t X; -+ uint64_t result; -+ -+ /* Initialize buffer, if not yet done. */ -+ if (!buffer->__init == 0) -+ { -+ buffer->__a = 0x5deece66dull; -+ buffer->__c = 0xb; -+ buffer->__init = 1; -+ } -+ -+ /* Do the real work. We choose a data type which contains at least -+ 48 bits. Because we compute the modulus it does not care how -+ many bits really are computed. */ -+ -+ X = (uint64_t) xsubi[2] << 32 | (uint32_t) xsubi[1] << 16 | xsubi[0]; -+ -+ result = X * buffer->__a + buffer->__c; -+ -+ xsubi[0] = result & 0xffff; -+ xsubi[1] = (result >> 16) & 0xffff; -+ xsubi[2] = (result >> 32) & 0xffff; -+ -+ return 0; -+} -+ -+int __erand48_r (unsigned short int xsubi[3], struct drand48_data *buffer, double *result) { -+ union ieee754_double temp; -+ -+ /* Compute next state. */ -+ if (__drand48_iterate (xsubi, buffer) < 0) -+ return -1; -+ -+ /* Construct a positive double with the 48 random bits distributed over -+ its fractional part so the resulting FP number is [0.0,1.0). */ -+ -+ temp.ieee.negative = 0; -+ temp.ieee.exponent = IEEE754_DOUBLE_BIAS; -+ temp.ieee.mantissa0 = (xsubi[2] << 4) | (xsubi[1] >> 12); -+ temp.ieee.mantissa1 = ((xsubi[1] & 0xfff) << 20) | (xsubi[0] << 4); -+ -+ /* Please note the lower 4 bits of mantissa1 are always 0. */ -+ *result = temp.d - 1.0; -+ -+ return 0; -+} -+ -+int __nrand48_r (unsigned short int xsubi[3], struct drand48_data *buffer, long int *result) { -+ /* Compute next state. */ -+ if (__drand48_iterate (xsubi, buffer) < 0) -+ return -1; -+ -+ /* Store the result. */ -+ if (sizeof (unsigned short int) == 2) -+ *result = xsubi[2] << 15 | xsubi[1] >> 1; -+ else -+ *result = xsubi[2] >> 1; -+ -+ return 0; -+} -+ -+int __jrand48_r (unsigned short int xsubi[3], struct drand48_data *buffer, long int *result) { -+ /* Compute next state. */ -+ if (__drand48_iterate (xsubi, buffer) < 0) -+ return -1; -+ -+ /* Store the result. */ -+ *result = (int32_t) ((xsubi[2] << 16) | xsubi[1]); -+ -+ return 0; -+} -+ -+int drand48_r (struct drand48_data *buffer, double *result) { -+ return __erand48_r (buffer->__x, buffer, result); -+} -+ -+int lrand48_r (struct drand48_data *buffer, long int *result) { -+ /* Be generous for the arguments, detect some errors. */ -+ if (buffer == NULL) -+ return -1; -+ -+ return __nrand48_r (buffer->__x, buffer, result); -+} -+ -+int mrand48_r (struct drand48_data *buffer, long int *result) { -+ /* Be generous for the arguments, detect some errors. */ -+ if (buffer == NULL) -+ return -1; -+ -+ return __jrand48_r (buffer->__x, buffer, result); -+} -+ -+int srand48_r (long int seedval, struct drand48_data *buffer) { -+ /* The standards say we only have 32 bits. */ -+ if (sizeof (long int) > 4) -+ seedval &= 0xffffffffl; -+ -+ buffer->__x[2] = seedval >> 16; -+ buffer->__x[1] = seedval & 0xffffl; -+ buffer->__x[0] = 0x330e; -+ -+ buffer->__a = 0x5deece66dull; -+ buffer->__c = 0xb; -+ buffer->__init = 1; -+ -+ return 0; -+} -Index: mtproxy/common/randr_compat.h -=================================================================== ---- /dev/null -+++ mtproxy/common/randr_compat.h -@@ -0,0 +1,72 @@ -+/* -+ The GNU C Library is free software. See the file COPYING.LIB for copying -+ conditions, and LICENSES for notices about a few contributions that require -+ these additional notices to be distributed. License copyright years may be -+ listed using range notation, e.g., 2000-2011, indicating that every year in -+ the range, inclusive, is a copyrightable year that would otherwise be listed -+ individually. -+*/ -+ -+#pragma once -+ -+#include -+#include -+ -+struct drand48_data { -+ unsigned short int __x[3]; /* Current state. */ -+ unsigned short int __old_x[3]; /* Old state. */ -+ unsigned short int __c; /* Additive const. in congruential formula. */ -+ unsigned short int __init; /* Flag for initializing. */ -+ unsigned long long int __a; /* Factor in congruential formula. */ -+}; -+ -+union ieee754_double -+{ -+ double d; -+ -+ /* This is the IEEE 754 double-precision format. */ -+ struct -+ { -+#if __BYTE_ORDER == __BIG_ENDIAN -+ unsigned int negative:1; -+ unsigned int exponent:11; -+ /* Together these comprise the mantissa. */ -+ unsigned int mantissa0:20; -+ unsigned int mantissa1:32; -+#endif /* Big endian. */ -+#if __BYTE_ORDER == __LITTLE_ENDIAN -+ /* Together these comprise the mantissa. */ -+ unsigned int mantissa1:32; -+ unsigned int mantissa0:20; -+ unsigned int exponent:11; -+ unsigned int negative:1; -+#endif /* Little endian. */ -+ } ieee; -+ -+ /* This format makes it easier to see if a NaN is a signalling NaN. */ -+ struct -+ { -+#if __BYTE_ORDER == __BIG_ENDIAN -+ unsigned int negative:1; -+ unsigned int exponent:11; -+ unsigned int quiet_nan:1; -+ /* Together these comprise the mantissa. */ -+ unsigned int mantissa0:19; -+ unsigned int mantissa1:32; -+#else -+ /* Together these comprise the mantissa. */ -+ unsigned int mantissa1:32; -+ unsigned int mantissa0:19; -+ unsigned int quiet_nan:1; -+ unsigned int exponent:11; -+ unsigned int negative:1; -+#endif -+ } ieee_nan; -+}; -+ -+#define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */ -+ -+int drand48_r (struct drand48_data *buffer, double *result); -+int lrand48_r (struct drand48_data *buffer, long int *result); -+int mrand48_r (struct drand48_data *buffer, long int *result); -+int srand48_r (long int seedval, struct drand48_data *buffer); diff --git a/mtproxy/patches/0002-version.patch b/mtproxy/patches/0002-version.patch deleted file mode 100644 index d30a94d9..00000000 --- a/mtproxy/patches/0002-version.patch +++ /dev/null @@ -1,13 +0,0 @@ -Index: mtproxy/mtproto/mtproto-proxy.c -=================================================================== ---- mtproxy.orig/mtproto/mtproto-proxy.c -+++ mtproxy/mtproto/mtproto-proxy.c -@@ -68,7 +68,7 @@ - #define COMMIT "unknown" - #endif - --#define VERSION_STR "mtproxy-3.0.5" -+#define VERSION_STR "mtproxy-3.0.6" - const char FullVersionStr[] = VERSION_STR " compiled at " __DATE__ " " __TIME__ " by gcc " __VERSION__ " " - #ifdef __LP64__ - "64-bit" diff --git a/mtproxy/Makefile b/teleproxy/Makefile similarity index 70% rename from mtproxy/Makefile rename to teleproxy/Makefile index 4e27ba8d..4c511d67 100644 --- a/mtproxy/Makefile +++ b/teleproxy/Makefile @@ -1,16 +1,16 @@ include $(TOPDIR)/rules.mk -PKG_NAME:=mtproxy -PKG_VERSION:=3.5.5 -PKG_RELEASE:=14 +PKG_NAME:=teleproxy +PKG_VERSION:=4.11.0 +PKG_RELEASE:=1 PKG_MAINTAINER:=Kosntantine Shevlakov PKG_LICENSE:=GPLv2 PKG_LICENSE_FILES:=LICENSE PKG_SOURCE_PROTO:=git -PKG_SOURCE_URL:=https://github.com/GetPageSpeed/MTProxy.git -PKG_SOURCE_VERSION:=55e5f0f575c2dd5decbf5282f4c1ea1f816a7eb0 +PKG_SOURCE_URL:=https://github.com/teleproxy/teleproxy.git +PKG_SOURCE_VERSION:=09b1ae9c39c456a7b91d24fdd3597ea08519ef22 PKG_SOURCE_SUBDIR:=$(PKG_NAME) PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz @@ -32,6 +32,4 @@ define Package/$(PKG_NAME)/install $(1)/usr/bin/ endef -ifeq ($(ARCH),$(filter $(ARCH), x86_64)) - $(eval $(call BuildPackage,$(PKG_NAME))) -endif +$(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/teleproxy/patches/0001-makefile.patch b/teleproxy/patches/0001-makefile.patch new file mode 100644 index 00000000..7f2c4683 --- /dev/null +++ b/teleproxy/patches/0001-makefile.patch @@ -0,0 +1,20 @@ +Index: teleproxy/Makefile +=================================================================== +--- teleproxy.orig/Makefile ++++ teleproxy/Makefile +@@ -56,11 +56,11 @@ COMMON_CFLAGS += $(EXTRA_CFLAGS) + COMMON_LDFLAGS += $(EXTRA_LDFLAGS) + + # Architecture-specific CFLAGS +-ifeq ($(HOST_ARCH), x86_64) ++ifeq ($(ARCH), x86_64) + CFLAGS := $(COMMON_CFLAGS) -mpclmul -march=core2 -mfpmath=sse -mssse3 $(BITNESS_FLAGS) +-else ifeq ($(HOST_ARCH), aarch64) +-CFLAGS := $(COMMON_CFLAGS) $(BITNESS_FLAGS) +-else ifeq ($(HOST_ARCH), arm64) ++else ifeq ($(ARCH), mipsel) ++CFLAGS := $(COMMON_CFLAGS) $(BITNESS_FLAGS) -march=mips32r2 -Wno-builtin-declaration-mismatch ++else + CFLAGS := $(COMMON_CFLAGS) $(BITNESS_FLAGS) + endif + diff --git a/teleproxy/patches/0002-fix-mips-variable.patch b/teleproxy/patches/0002-fix-mips-variable.patch new file mode 100644 index 00000000..b776c79b --- /dev/null +++ b/teleproxy/patches/0002-fix-mips-variable.patch @@ -0,0 +1,17 @@ +Index: teleproxy/src/mtproto/mtproto-proxy-stats.c +=================================================================== +--- teleproxy.orig/src/mtproto/mtproto-proxy-stats.c ++++ teleproxy/src/mtproto/mtproto-proxy-stats.c +@@ -602,9 +602,9 @@ void mtfront_prepare_stats (stats_buffer + if (_quota > 0) { + sb_printf (sb, "secret_%s_quota\t%lld\n", _lbl, _quota); + } +- int _mips = tcp_rpcs_get_ext_secret_max_ips (_i); +- if (_mips > 0) { +- sb_printf (sb, "secret_%s_max_ips\t%d\n", _lbl, _mips); ++ int _mips_ips = tcp_rpcs_get_ext_secret_max_ips (_i); ++ if (_mips_ips > 0) { ++ sb_printf (sb, "secret_%s_max_ips\t%d\n", _lbl, _mips_ips); + } + int64_t _exp = tcp_rpcs_get_ext_secret_expires (_i); + if (_exp > 0) { diff --git a/teleproxy/patches/0003-rtds-alternate.patch b/teleproxy/patches/0003-rtds-alternate.patch new file mode 100644 index 00000000..e59f8e7f --- /dev/null +++ b/teleproxy/patches/0003-rtds-alternate.patch @@ -0,0 +1,86 @@ +Index: teleproxy/src/common/rdtsc_32bit.h +=================================================================== +--- /dev/null ++++ teleproxy/src/common/rdtsc_32bit.h +@@ -0,0 +1,14 @@ ++#ifndef RDTSC_EMUL_H ++#define RDTSC_EMUL_H ++ ++#if defined(__arm__) || defined(__mips__) || defined(__mipsel__) ++#include ++ ++static inline unsigned long long rdtsc(void) { ++ struct timespec ts; ++ clock_gettime(CLOCK_MONOTONIC, &ts); ++ return (unsigned long long)ts.tv_sec * 1000000000ULL + ts.tv_nsec; ++} ++#endif ++ ++#endif +Index: teleproxy/src/engine/engine-rpc-common.c +=================================================================== +--- teleproxy.orig/src/engine/engine-rpc-common.c ++++ teleproxy/src/engine/engine-rpc-common.c +@@ -51,6 +51,7 @@ + ++#include "common/rdtsc_32bit.h" + #include "engine/engine.h" + #include "engine/engine-rpc-common.h" + + #include "common/tl-parse.h" + +Index: teleproxy/src/jobs/jobs.c +=================================================================== +--- teleproxy.orig/src/jobs/jobs.c ++++ teleproxy/src/jobs/jobs.c +@@ -53,6 +53,7 @@ + #include "net/net-connections.h" + #include "jobs/jobs.h" + #include "common/common-stats.h" ++#include "common/rdtsc_32bit.h" + + //#include "auto/engine/engine.h" + +Index: teleproxy/src/net/net-crypto-aes.c +=================================================================== +--- teleproxy.orig/src/net/net-crypto-aes.c ++++ teleproxy/src/net/net-crypto-aes.c +@@ -48,6 +48,7 @@ + + #include "jobs/jobs.h" + #include "common/common-stats.h" ++#include "common/rdtsc_32bit.h" + + #define MODULE crypto_aes + +Index: teleproxy/src/common/precise-time.c +=================================================================== +--- teleproxy.orig/src/common/precise-time.c ++++ teleproxy/src/common/precise-time.c +@@ -19,10 +19,11 @@ + */ + #include + #include ++ + #include + /* unistd.h defines _POSIX_TIMERS */ + #include +- ++#include "rdtsc_32bit.h" + #include "precise-time.h" + + __thread int now; + +Index: teleproxy/src/engine/engine-rpc.c +=================================================================== +--- teleproxy.orig/src/engine/engine-rpc.c ++++ teleproxy/src/engine/engine-rpc.c +@@ -25,6 +25,8 @@ + Copyright 2015-2016 Telegram Messenger Inc + 2015-2016 Vitaliy Valtman + */ ++#include "common/rdtsc_32bit.h" ++ + #include "engine/engine-rpc.h" + #include "common/tl-parse.h" + diff --git a/teleproxy/patches/0004-atomic-32bit-emu.patch b/teleproxy/patches/0004-atomic-32bit-emu.patch new file mode 100644 index 00000000..00ac0b3a --- /dev/null +++ b/teleproxy/patches/0004-atomic-32bit-emu.patch @@ -0,0 +1,79 @@ +Index: teleproxy/src/common/atomic_32bit.c +=================================================================== +--- /dev/null ++++ teleproxy/src/common/atomic_32bit.c +@@ -0,0 +1,73 @@ ++#if defined(__arm__) || defined(__mips__) || defined(__mipsel__) ++ ++#include ++#include ++ ++static pthread_mutex_t atomic_mutex = PTHREAD_MUTEX_INITIALIZER; ++ ++/* 64-bit atomic operations emulation */ ++uint64_t __sync_fetch_and_add_8(uint64_t *ptr, uint64_t val) { ++ pthread_mutex_lock(&atomic_mutex); ++ uint64_t old = *ptr; ++ *ptr += val; ++ pthread_mutex_unlock(&atomic_mutex); ++ return old; ++} ++ ++uint64_t __sync_fetch_and_sub_8(uint64_t *ptr, uint64_t val) { ++ pthread_mutex_lock(&atomic_mutex); ++ uint64_t old = *ptr; ++ *ptr -= val; ++ pthread_mutex_unlock(&atomic_mutex); ++ return old; ++} ++ ++uint64_t __sync_fetch_and_or_8(uint64_t *ptr, uint64_t val) { ++ pthread_mutex_lock(&atomic_mutex); ++ uint64_t old = *ptr; ++ *ptr |= val; ++ pthread_mutex_unlock(&atomic_mutex); ++ return old; ++} ++ ++uint64_t __sync_fetch_and_and_8(uint64_t *ptr, uint64_t val) { ++ pthread_mutex_lock(&atomic_mutex); ++ uint64_t old = *ptr; ++ *ptr &= val; ++ pthread_mutex_unlock(&atomic_mutex); ++ return old; ++} ++ ++uint64_t __sync_add_and_fetch_8(uint64_t *ptr, uint64_t val) { ++ pthread_mutex_lock(&atomic_mutex); ++ *ptr += val; ++ uint64_t newval = *ptr; ++ pthread_mutex_unlock(&atomic_mutex); ++ return newval; ++} ++ ++uint64_t __sync_sub_and_fetch_8(uint64_t *ptr, uint64_t val) { ++ pthread_mutex_lock(&atomic_mutex); ++ *ptr -= val; ++ uint64_t newval = *ptr; ++ pthread_mutex_unlock(&atomic_mutex); ++ return newval; ++} ++ ++int __sync_bool_compare_and_swap_8(uint64_t *ptr, uint64_t oldval, uint64_t newval) { ++ pthread_mutex_lock(&atomic_mutex); ++ int ret = (*ptr == oldval); ++ if (ret) *ptr = newval; ++ pthread_mutex_unlock(&atomic_mutex); ++ return ret; ++} ++ ++uint64_t __sync_val_compare_and_swap_8(uint64_t *ptr, uint64_t oldval, uint64_t newval) { ++ pthread_mutex_lock(&atomic_mutex); ++ uint64_t old = *ptr; ++ if (old == oldval) *ptr = newval; ++ pthread_mutex_unlock(&atomic_mutex); ++ return old; ++} ++ ++#endif /* 32bits arch */ + diff --git a/teleproxy/patches/0005-makefile-atomic-emu.patch b/teleproxy/patches/0005-makefile-atomic-emu.patch new file mode 100644 index 00000000..4e92a9d5 --- /dev/null +++ b/teleproxy/patches/0005-makefile-atomic-emu.patch @@ -0,0 +1,12 @@ +Index: teleproxy/Makefile +=================================================================== +--- teleproxy.orig/Makefile ++++ teleproxy/Makefile +@@ -92,6 +92,7 @@ DEPENDENCE_STRANGE := $(subst ${OBJ}/,${ + DEPENDENCE_NORM := $(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJECTS})) + + LIB_OBJS_NORMAL := \ ++ ${OBJ}/src/common/atomic_32bit.o \ + ${OBJ}/src/common/crc32c.o \ + ${OBJ}/src/common/pid.o \ + ${OBJ}/src/common/sha1.o \ diff --git a/teleproxy/patches/0006-fix-mips-musl-sigrtmax.patch b/teleproxy/patches/0006-fix-mips-musl-sigrtmax.patch new file mode 100644 index 00000000..be26c444 --- /dev/null +++ b/teleproxy/patches/0006-fix-mips-musl-sigrtmax.patch @@ -0,0 +1,22 @@ +Index: teleproxy/src/engine/engine.c +=================================================================== +--- teleproxy.orig/src/engine/engine.c ++++ teleproxy/src/engine/engine.c +@@ -612,8 +612,15 @@ void engine_startup (engine_t *E, server + precise_now_diff = get_utime_monotonic () - get_double_time (); + + #ifdef __linux__ +- assert (SIGRTMAX == OUR_SIGRTMAX); +- assert (SIGRTMAX - SIGRTMIN >= 20); ++ #ifdef __mips__ ++ if (SIGRTMAX != OUR_SIGRTMAX) { ++ vkprintf(0, "MIPS: SIGRTMAX mismatch (libc=%d, expected=%d), continuing\n", ++ SIGRTMAX, OUR_SIGRTMAX); ++ } ++ #else ++ assert(SIGRTMAX == OUR_SIGRTMAX); ++ #endif ++ assert(SIGRTMAX - SIGRTMIN >= 20); + #endif + + E->sfd = 0;