code wiki / (root) / smoke_alloc_call.nx

smoke_alloc_call.nx source

↩ module page · 21 lines · 429 B

1// smoke_alloc_call.nx -- nested sys_mmap inside a called function. 2 3import "syscalls.nx" 4 5struct Box { 6 val: i64, 7} 8 9func make_box(v: i64) -> *Box { 10 let raw: *u8 = sys_mmap(16) 11 let b: *Box = raw as *Box 12 b.val = v 13 return b 14} 15 16func main() -> i64 { 17 let b1: *Box = make_box(20) 18 let b2: *Box = make_box(22) 19 let s: i64 = b1.val + b2.val 20 return __syscall(93, s, 0, 0, 0, 0, 0) 21}