Skip to content

Commit bdb6f61

Browse files
committed
more older clone syscall work since the new one, clone3, is not supported by qemu
1 parent 7ff53ad commit bdb6f61

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

FE/Lib/os.cw

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,16 @@ pub global CLONE_NEWPID = 0x20000000_uint
628628
pub global CLONE_NEWNET = 0x40000000_uint
629629
pub global CLONE_IO = 0x80000000_uint
630630

631+
{{extern}} {{cdecl}} pub fun clone_wrapper(proc ThreadFun, sp ^!u8, tls uint,
632+
user_arg uint, flags uint) s32:
633+
634+
; The param must be mutable because clone3_wrapper may modify it
635+
pub fun CloneWrapper(proc ThreadFun, sp ^!u8, tls uint,
636+
user_arg uint, flags uint) union(u32, Error):
637+
let res = clone_wrapper(proc, sp, tls, user_arg, flags)
638+
if res < 0:
639+
return wrap_as(res, Error)
640+
return as(res, u32)
631641

632642
{{extern}} {{cdecl}} pub fun clone3_wrapper(proc ThreadFun, arg uint, param ^CloneArgs, param_size uint) s32:
633643

FE/TestData/thread_test.cw

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@ fun run() uint:
2222
ref let! params os\CloneArgs
2323
set params.flags = os\CLONE_VM | os\CLONE_FS | os\CLONE_FILES | os\CLONE_SIGHAND |
2424
os\CLONE_THREAD | os\CLONE_SYSVSEM
25+
set params.stack_size = gStackSize
26+
fmt\print#("stack ", wrap_as(bitwise_as(params.stack, uint), fmt\uint_hex), "\n")
27+
28+
2529
for i = 0, gThreads, 1:
2630
fmt\print#("spawning ", i, "\n")
2731
; do os\nanosleep(@req, @!rem)
2832
set params.stack = front!(gStacks[i + 1])
29-
set params.stack_size = gStackSize
30-
fmt\print#("stack ", wrap_as(bitwise_as(params.stack, uint), fmt\uint_hex), "\n")
31-
trylet pid u32 = os\Clone3Wrapper(thread_runner, i, @!params), err:
32-
fmt\print#("clone failed at ", i, " with ", unwrap(err), "\n")
33+
; Note: here the stack parameter is the top of the stack
34+
trylet pid u32 = os\CloneWrapper(thread_runner, params.stack, 0, i, params.flags), err:
35+
fmt\print#("clone failed at ", i, " with ", unwrap(err), "\n")
3336
continue
37+
; Note: here the stack parameter is the bottom of the stack
38+
; trylet pid u32 = os\Clone3Wrapper(thread_runner, i, @!params), err:
39+
; fmt\print#("clone failed at ", i, " with ", unwrap(err), "\n")
40+
; continue
3441

3542
do os\nanosleep(@req, @!rem)
3643
return gIterations * gThreads

0 commit comments

Comments
 (0)