Răsfoiți Sursa

libmem: update to 5.1.0 (#7762)

* libmem: update to 5.1.0

* fix win arm64

* Fix bsd

* fix mingw

* fixup

* try fix bsd

* fixup

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* pass cflags into port/xmake.lua
Saikari 1 lună în urmă
părinte
comite
5cf1025a36

+ 43 - 0
packages/l/libmem/patches/5.1.0/fix-freebsd.diff

@@ -0,0 +1,43 @@
+diff --git a/src/freebsd/process.c b/src/freebsd/process.c
+index dee0f76..90e65a5 100644
+--- a/src/freebsd/process.c
++++ b/src/freebsd/process.c
+@@ -184,7 +184,7 @@ LM_GetCommandLine(lm_process_t *process)
+ 
+ 	ps = procstat_open_sysctl();
+ 	if (!ps)
+-		return result;
++		return cmdargs;
+ 
+ 	proc = procstat_getprocs(ps, KERN_PROC_PID, process->pid, &nprocs);
+ 	if (!proc)
+diff --git a/src/freebsd/utils.c b/src/freebsd/utils.c
+index 86c80a1..b3c6a81 100644
+--- a/src/freebsd/utils.c
++++ b/src/freebsd/utils.c
+@@ -21,6 +21,7 @@
+  */
+ 
+ #include "utils.h"
++#include <string.h>
+ #include <assert.h>
+ 
+ lm_time_t
+@@ -43,7 +44,7 @@ get_process_cmdline(struct procstat *procstat, struct kinfo_proc *proc)
+ 	char **args;
+ 	size_t size;
+ 
+-	args = procstat_getargv(procstat, kipp, 0);
++	args = procstat_getargv(procstat, proc, 0);
+ 
+ 	buf = calloc(sizeof(lm_char_t), length + sizeof(proc->ki_comm) + 1);
+ 	if (!buf)
+@@ -62,7 +63,7 @@ get_process_cmdline(struct procstat *procstat, struct kinfo_proc *proc)
+ 	for (i = 0; args[i] != NULL; ++i) {
+ 		size = strlen(args[i]) + 1; // we will include the null term
+ 		ptr = buf;
+-		buf = realloc(buf, (length + size) * sizeof(lm_char_t))
++		buf = realloc(buf, (length + size) * sizeof(lm_char_t));
+ 		if (!buf) {
+ 			free(ptr);
+ 			return NULL;

+ 33 - 1
packages/l/libmem/port/xmake.lua

@@ -38,7 +38,7 @@ target("libmem")
         "external/llvm/lib/Demangle/*.cpp"
     )
 
-    if is_plat("linux", "bsd") then
+    if is_plat("linux", "bsd") and is_arch("x86_64", "x64", "x86", "i386", "i686") then
         add_syslinks("dl", "stdc++", "m")
         if is_plat("bsd") then
             add_syslinks("kvm", "procstat", "elf")
@@ -52,12 +52,44 @@ target("libmem")
         add_files(path.join(prefix, "ptrace", "*.c"))
         add_files(path.join(prefix, "*.c"))
         add_files(path.join(prefix, "ptrace", arch, "*.c"))
+        if os.exists("src/common/arch/generic.c") then
+            remove_files("src/common/arch/generic.c")
+        end
     
     elseif is_plat("windows", "mingw") then
         add_syslinks("user32", "psapi", "ntdll", "shell32", "ole32")
         if is_plat("mingw") then
             add_syslinks("uuid")
+            add_cflags("-Wno-int-conversion", "-Wno-incompatible-pointer-types")
         end
         add_files("internal/winutils/*.c")
         add_files("src/win/*.c")
+        if os.exists("src/common/arch/generic.c") then
+            remove_files("src/common/arch/generic.c")
+        end
+    elseif os.exists("src/common/arch/generic.c") and is_plat("linux", "android") then
+        if is_plat("linux") then
+            add_syslinks("dl", "stdc++", "m")
+        end
+        add_files("internal/posixutils/*.c")
+        add_files("internal/elfutils/*.c")
+
+        local prefix = path.join("src", "linux")
+        add_files(path.join(prefix, "ptrace", "*.c"))
+        add_files(path.join(prefix, "*.c"))
+        add_files(path.join(prefix, "ptrace", "generic", "*.c"))
+
+        remove_files("src/common/arch/x86.c")
+    elseif os.exists("src/common/arch/generic.c") and is_plat("bsd") then
+        add_syslinks("dl", "stdc++", "m", "kvm", "procstat", "elf")
+
+        add_files("internal/posixutils/*.c")
+        add_files("internal/elfutils/*.c")
+
+        local prefix = path.join("src", "freebsd")
+        add_files(path.join(prefix, "ptrace", "*.c"))
+        add_files(path.join(prefix, "*.c"))
+        add_files(path.join(prefix, "ptrace", "generic", "*.c"))
+
+        remove_files("src/common/arch/x86.c")
     end

+ 10 - 2
packages/l/libmem/xmake.lua

@@ -5,12 +5,14 @@ package("libmem")
 
     add_urls("https://github.com/rdbo/libmem/archive/refs/tags/$(version).tar.gz",
              "https://github.com/rdbo/libmem.git", {submodules = false})
+    add_versions("5.1.0", "9f61b53ce86fd59afb13bc4f48db40e8c8dc156f56879b9e9929014924f95495")
     add_versions("5.0.5", "9693d38b17b000b06cd9fbaff72f4e0873d3cf219a6e99a20bb90cf98a7b562d")
     add_versions("5.0.4", "32b968fb2bd1e33ae854db3bd3fc9ce4374bd9e61ff420f365c52d5f7bbd85dd")
     add_versions("5.0.3", "75a190d1195c641c7d5d2c37ac79d8d1b5f18e43268d023454765a566d6f0d88")
     add_versions("5.0.2", "99adea3e86bd3b83985dce9076adda16968646ebd9d9316c9f57e6854aeeab9c")
 
-    add_patches("5.0.5", "patches/5.0.5/fix-mingw.diff", "7239f459204975ce2efcf63529dcb09273028c4dc166d7cbacb5f5f0e70f93a9")
+    add_patches("5.1.0", "patches/5.1.0/fix-freebsd.diff", "98a454d2c71f8f7a63ed5714301ad5f51f92790e3debe5b35a16f14b83c34404")
+    add_patches(">=5.0.5", "patches/5.0.5/fix-mingw.diff", "7239f459204975ce2efcf63529dcb09273028c4dc166d7cbacb5f5f0e70f93a9")
 
     add_deps("capstone", "keystone")
 
@@ -25,13 +27,19 @@ package("libmem")
         add_syslinks("dl", "kvm", "procstat", "elf", "m")
     end
 
+    on_check("android", function(package)
+        local ndk = package:toolchain("ndk")
+        local ndk_sdkver = ndk:config("ndk_sdkver")
+        assert(ndk_sdkver and tonumber(ndk_sdkver) >= 24, "package(libmem): need ndk api level >= 24 for android")
+    end)
+
     on_load(function(package)
         if package:is_plat("windows") or package:config("shared") then
             package:add("defines", "LM_EXPORT")
         end
     end)
 
-    on_install("windows", "linux|!arm64", "bsd", "mingw", "msys", function (package)
+    on_install("windows", "linux|!arm64", "bsd", "mingw", "msys", "android", function (package)
         os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
         import("package.tools.xmake").install(package)
     end)