https://sourceware.org/cgit/valgrind/commit/?id=1a60f23515367e99b1cc059d276ce4671a752d4d
commit 1a60f23515367e99b1cc059d276ce4671a752d4d
Author: Paul Floyd <pj...@wa...>
Date: Tue Nov 4 20:36:45 2025 +0100
Darwin: add ML_(get_darwin_syscall_entry)
There was a comment saying that exposing the table arrays and
sizes should be fixed (all other OSes use a function). Now done.
Taken from
https://github.com/LouisBrunner/valgrind-macos
Thanks, Louis Brunner.
Diff:
---
coregrind/m_syswrap/priv_types_n_macros.h | 7 ++---
coregrind/m_syswrap/syswrap-darwin.c | 47 +++++++++++++++++++++++++++----
coregrind/m_syswrap/syswrap-main.c | 23 +--------------
3 files changed, 44 insertions(+), 33 deletions(-)
diff --git a/coregrind/m_syswrap/priv_types_n_macros.h b/coregrind/m_syswrap/priv_types_n_macros.h
index 0ce26bd33d..ff5d6a2de7 100644
--- a/coregrind/m_syswrap/priv_types_n_macros.h
+++ b/coregrind/m_syswrap/priv_types_n_macros.h
@@ -240,12 +240,9 @@ extern
SyscallTableEntry* ML_(get_linux_syscall_entry)( UInt sysno );
#elif defined(VGO_darwin)
-/* XXX: Darwin still uses the old scheme of exposing the table
- array(s) and size(s) directly to syswrap-main.c. This should be
- fixed. */
-extern const SyscallTableEntry ML_(syscall_table)[];
-extern const UInt ML_(syscall_table_size);
+extern
+const SyscallTableEntry* ML_(get_darwin_syscall_entry)( UInt sysno );
#elif defined(VGO_solaris)
extern
diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c
index 62bd589ae2..4eec0eb36b 100644
--- a/coregrind/m_syswrap/syswrap-darwin.c
+++ b/coregrind/m_syswrap/syswrap-darwin.c
@@ -11368,14 +11368,49 @@ const SyscallTableEntry ML_(mdep_trap_table)[] = {
#error unknown architecture
#endif
-const UInt ML_(syscall_table_size) =
- sizeof(ML_(syscall_table)) / sizeof(ML_(syscall_table)[0]);
+const SyscallTableEntry* ML_(get_darwin_syscall_entry) ( UInt sysno )
+{
+ const UInt syscall_table_size =
+ sizeof(ML_(syscall_table)) / sizeof(ML_(syscall_table)[0]);
+
+ const UInt mach_trap_table_size =
+ sizeof(ML_(mach_trap_table)) / sizeof(ML_(mach_trap_table)[0]);
+
+ const UInt mdep_trap_table_size =
+ sizeof(ML_(mdep_trap_table)) / sizeof(ML_(mdep_trap_table)[0]);
+
+ const SyscallTableEntry *table;
+ Int size;
+
+ switch (VG_DARWIN_SYSNO_CLASS(sysno)) {
+ case VG_DARWIN_SYSCALL_CLASS_UNIX:
+ table = ML_(syscall_table);
+ size = syscall_table_size;
+ break;
+ case VG_DARWIN_SYSCALL_CLASS_MACH:
+ table = ML_(mach_trap_table);
+ size = mach_trap_table_size;
+ break;
+ case VG_DARWIN_SYSCALL_CLASS_MDEP:
+ table = ML_(mdep_trap_table);
+ size = mdep_trap_table_size;
+ break;
+ default:
+ vg_assert2(0, "invalid syscall class: %d (syscall: %d / %#x)\n", VG_DARWIN_SYSNO_CLASS(sysno), VG_DARWIN_SYSNO_INDEX(sysno), sysno);
+ break;
+ }
-const UInt ML_(mach_trap_table_size) =
- sizeof(ML_(mach_trap_table)) / sizeof(ML_(mach_trap_table)[0]);
+ sysno = VG_DARWIN_SYSNO_INDEX(sysno);
+ if (sysno < size) {
+ const SyscallTableEntry *sys = &table[sysno];
+ if (!sys->before)
+ return NULL; /* no entry */
+ return sys;
+ }
-const UInt ML_(mdep_trap_table_size) =
- sizeof(ML_(mdep_trap_table)) / sizeof(ML_(mdep_trap_table)[0]);
+ /* Can't find a wrapper. */
+ return NULL;
+}
#endif // defined(VGO_darwin)
diff --git a/coregrind/m_syswrap/syswrap-main.c b/coregrind/m_syswrap/syswrap-main.c
index 49c264c40e..884836c267 100644
--- a/coregrind/m_syswrap/syswrap-main.c
+++ b/coregrind/m_syswrap/syswrap-main.c
@@ -2119,28 +2119,7 @@ static const SyscallTableEntry* get_syscall_entry ( Int syscallno )
sys = ML_(get_freebsd_syscall_entry)( syscallno );
# elif defined(VGO_darwin)
- Int idx = VG_DARWIN_SYSNO_INDEX(syscallno);
-
- switch (VG_DARWIN_SYSNO_CLASS(syscallno)) {
- case VG_DARWIN_SYSCALL_CLASS_UNIX:
- if (idx >= 0 && idx < ML_(syscall_table_size) &&
- ML_(syscall_table)[idx].before != NULL)
- sys = &ML_(syscall_table)[idx];
- break;
- case VG_DARWIN_SYSCALL_CLASS_MACH:
- if (idx >= 0 && idx < ML_(mach_trap_table_size) &&
- ML_(mach_trap_table)[idx].before != NULL)
- sys = &ML_(mach_trap_table)[idx];
- break;
- case VG_DARWIN_SYSCALL_CLASS_MDEP:
- if (idx >= 0 && idx < ML_(mdep_trap_table_size) &&
- ML_(mdep_trap_table)[idx].before != NULL)
- sys = &ML_(mdep_trap_table)[idx];
- break;
- default:
- vg_assert(0);
- break;
- }
+ sys = ML_(get_darwin_syscall_entry)( syscallno );
# elif defined(VGO_solaris)
sys = ML_(get_solaris_syscall_entry)(syscallno);
|