22# Auto-generates syscall mapping constants for lind-wasm.
33#
44# Reads syscall definitions from glibc's lind_syscall_num.h and generates:
5- # - src/sysdefs/src/constants/syscall_const.rs (full set)
6- # - src/wasmtime/crates/lind-utils/src/lind_syscall_numbers.rs (minimal set)
5+ # - src/sysdefs/src/constants/syscall_const.rs (full set of syscalls)
6+ #
7+ # This script should be run before building lind-boot and glibc.
78#
89# Source of truth: src/glibc/lind_syscall/lind_syscall_num.h
910
@@ -62,37 +63,7 @@ def generate_rust_constants(syscalls: dict[str, int]) -> str:
6263 return "\n " .join (lines )
6364
6465
65- def get_minimal_syscalls () -> dict [str , int ]:
66- """Return the minimal set of syscalls needed by Wasmtime runtime."""
67- return {
68- 'MMAP_SYSCALL' : 9 ,
69- 'CLONE_SYSCALL' : 56 ,
70- 'FORK_SYSCALL' : 57 ,
71- 'EXEC_SYSCALL' : 59 ,
72- 'EXIT_SYSCALL' : 60 ,
73- 'EXIT_GROUP_SYSCALL' : 231 ,
74- }
75-
76-
77- def generate_wasmtime_minimal (minimal : dict [str , int ]) -> str :
78- """Generate minimal Rust constants for wasmtime lind_syscall_numbers.rs."""
79- lines = [
80- "// Minimal set of syscall numbers used by Wasmtime side for Lind" ,
81- "// Keeps the runtime minimal and the rawposix dispatcher handles the rest" ,
82- "// Source of truth: Linux x86_64 syscall table" ,
83- "// https://github.com/torvalds/linux/blob/v6.16-rc1/arch/x86/entry/syscalls/syscall_64.tbl" ,
84- "// (Historical overview: https://filippo.io/linux-syscall-table/)" ,
85- "// Keep these in sync with glibc's lind_syscall_num.h and RawPOSIX dispatcher" ,
86- ]
87-
88- # Sort by syscall number
89- sorted_syscalls = sorted (minimal .items (), key = lambda x : x [1 ])
90-
91- for name , number in sorted_syscalls :
92- lines .append (f"pub const { name } : i32 = { number } ;" )
9366
94- lines .append ("" )
95- return "\n " .join (lines )
9667
9768
9869def write_file (path : str , content : str ) -> None :
@@ -104,31 +75,24 @@ def write_file(path: str, content: str) -> None:
10475
10576
10677def main () -> None :
107- """Generate all syscall mapping files ."""
78+ """Generate syscall mapping constants from glibc header ."""
10879 # Find workspace root (should be run from lind-wasm directory)
10980 workspace_root = Path (__file__ ).parent .parent
11081
11182 c_header = workspace_root / "src/glibc/lind_syscall/lind_syscall_num.h"
11283 rust_sysdefs_out = workspace_root / "src/sysdefs/src/constants/syscall_const.rs"
113- rust_wasmtime_out = workspace_root / "src/wasmtime/crates/lind-utils/src/lind_syscall_numbers.rs"
11484
11585 print ("Parsing syscall definitions..." )
11686 syscalls = parse_c_header (str (c_header ))
11787 print (f"Found { len (syscalls )} syscall definitions" )
11888
119- # Generate full Rust constants for sysdefs
89+ # Generate Rust constants for sysdefs
12090 print ("\n Generating sysdefs constants..." )
12191 rust_content = generate_rust_constants (syscalls )
12292 write_file (str (rust_sysdefs_out ), rust_content )
12393
124- # Generate minimal constants for wasmtime
125- print ("Generating wasmtime minimal constants..." )
126- minimal = get_minimal_syscalls ()
127- wasmtime_content = generate_wasmtime_minimal (minimal )
128- write_file (str (rust_wasmtime_out ), wasmtime_content )
129-
130- print ("\n Done!" )
94+ print ("Done!" )
13195
13296
13397if __name__ == "__main__" :
134- main ()
98+ main ()
0 commit comments