nx_ftp2.nx source
↩ module page · 56 lines · 1770 B
1// nx_ftp2.nx -- closer repro. My first probe (2 params) REFUTED the field-misalignment theory.
2// This mirrors the real failing call EXACTLY: 4 params with a POINTER first, called with
3// (ptr, i64const, ptr.field, ptr.field) -- i.e. x86ctx_emit_condjump(c, NX_X64_CC_NE, i.op1, i.op2).
4// expect_exit: 0 license_tier: ORIGINAL
5import "nx_syscalls.nx"
6
7struct FtType { k: i64 }
8struct FtCtx { o: i64 }
9struct FtInstr {
10 op: i64,
11 result: i64,
12 ty: *FtType,
13 n: i64,
14 op0: i64,
15 op1: i64,
16 op2: i64,
17 next: *FtInstr,
18}
19
20const FT_CC_NE: i64 = 1
21
22// same shape as x86ctx_emit_condjump(c: *X86Ctx, cc: i64, t: i64, fjb: i64)
23func ft_condjump(c: *FtCtx, cc: i64, t: i64, fjb: i64) -> i64 { return cc + t + fjb }
24
25func ft_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
26func ft_puts(s: *u8) -> i64 { sys_write(1, s, ft_len(s)); return 0 }
27
28func ft_emit_br(c: *FtCtx, i: *FtInstr) -> i64 {
29 // exact shape of the failing line 1694
30 return ft_condjump(c, FT_CC_NE, i.op1, i.op2)
31}
32
33func ft_emit_br2(c: *FtCtx, i2: *FtInstr) -> i64 {
34 // exact shape of line 1664: a chained pointer field then its i64 fields
35 let i3: *FtInstr = i2.next
36 if i3 != (0 as *FtInstr) {
37 let ccv: i64 = FT_CC_NE
38 return ft_condjump(c, ccv, i3.op1, i3.op2)
39 }
40 return 0
41}
42
43func main() -> i64 {
44 let rc: *u8 = sys_mmap(128)
45 let c: *FtCtx = rc as *FtCtx
46 let ri: *u8 = sys_mmap(256)
47 let i: *FtInstr = ri as *FtInstr
48 i.op1 = 10
49 i.op2 = 31
50 i.next = 0 as *FtInstr
51 let a: i64 = ft_emit_br(c, i)
52 let b: i64 = ft_emit_br2(c, i)
53 if a == 42 { ft_puts("BOTH-CALL-SHAPES-OK\n" as *u8) }
54 if a != 42 { ft_puts("VALUE-WRONG\n" as *u8) }
55 return 0
56}