pub fn bsdthread_create_join() -> Vec<u8> ⓘExpand description
Micro program: bsdthread_register + bsdthread_create worker, join via flag, exit(0).
Worker (via registered start trampoline) writes T\\n, stores a flag, then
bsdthread_terminate. Main spins on the flag (no syscall) and exits 0.
Live only on Linux aarch64 (host pthread spawn).
Examples found in repository?
examples/write_fixture.rs (line 37)
19fn main() -> ExitCode {
20 let arg = env::args().nth(1);
21 let root = PathBuf::from("tests/fixtures");
22 drop(fs::create_dir_all(&root));
23
24 let jobs: Vec<(PathBuf, Vec<u8>)> = match arg.as_deref() {
25 None | Some("all") => vec![
26 (
27 root.join("minimal_arm64_execute.macho"),
28 minimal_arm64_execute(),
29 ),
30 (
31 root.join("errno_unknown_then_exit.macho"),
32 errno_unknown_then_exit(),
33 ),
34 (root.join("mmap_touch_exit.macho"), mmap_touch_exit()),
35 (
36 root.join("bsdthread_create_join.macho"),
37 bsdthread_create_join(),
38 ),
39 (
40 root.join("memory_file_roundtrip.macho"),
41 memory_file_roundtrip(),
42 ),
43 (
44 root.join("roundtrip_payload.bin"),
45 ROUNDTRIP_PAYLOAD.to_vec(),
46 ),
47 (root.join("libkh_add.dylib"), arm64_dylib_add()),
48 (root.join("call_dylib.macho"), call_dylib_exit()),
49 (
50 root.join("call_dylib_chained.macho"),
51 call_dylib_chained_exit(),
52 ),
53 (root.join("libkh_ctor.dylib"), arm64_dylib_ctor()),
54 (root.join("ctor_main.macho"), ctor_main_exit()),
55 (root.join("call_libsystem.macho"), call_libsystem_exit()),
56 (
57 root.join("bottle/usr/lib/libSystem.B.dylib"),
58 arm64_libsystem_stub(),
59 ),
60 ],
61 Some("minimal") => vec![(
62 root.join("minimal_arm64_execute.macho"),
63 minimal_arm64_execute(),
64 )],
65 Some("errno") => vec![(
66 root.join("errno_unknown_then_exit.macho"),
67 errno_unknown_then_exit(),
68 )],
69 Some("mmap") => vec![(root.join("mmap_touch_exit.macho"), mmap_touch_exit())],
70 Some("thread" | "bsdthread") => vec![(
71 root.join("bsdthread_create_join.macho"),
72 bsdthread_create_join(),
73 )],
74 Some("roundtrip") => vec![
75 (
76 root.join("memory_file_roundtrip.macho"),
77 memory_file_roundtrip(),
78 ),
79 (
80 root.join("roundtrip_payload.bin"),
81 ROUNDTRIP_PAYLOAD.to_vec(),
82 ),
83 ],
84 Some("dylib" | "call_dylib") => vec![
85 (root.join("libkh_add.dylib"), arm64_dylib_add()),
86 (root.join("call_dylib.macho"), call_dylib_exit()),
87 (
88 root.join("call_dylib_chained.macho"),
89 call_dylib_chained_exit(),
90 ),
91 ],
92 Some("ctor") => vec![
93 (root.join("libkh_ctor.dylib"), arm64_dylib_ctor()),
94 (root.join("ctor_main.macho"), ctor_main_exit()),
95 ],
96 Some("libsystem" | "bottle") => vec![
97 (root.join("call_libsystem.macho"), call_libsystem_exit()),
98 (
99 root.join("bottle/usr/lib/libSystem.B.dylib"),
100 arm64_libsystem_stub(),
101 ),
102 ],
103 Some(path)
104 if Path::new(path)
105 .extension()
106 .is_some_and(|ext| ext.eq_ignore_ascii_case("macho")) =>
107 {
108 vec![(PathBuf::from(path), minimal_arm64_execute())]
109 }
110 Some(other) => {
111 eprintln!(
112 "unknown fixture '{other}'; use all|minimal|errno|mmap|thread|roundtrip|dylib|ctor|libsystem|chained|*.macho"
113 );
114 return ExitCode::from(2);
115 }
116 };
117
118 for (path, bytes) in jobs {
119 if let Err(code) = write_one(&path, &bytes) {
120 return code;
121 }
122 }
123 ExitCode::SUCCESS
124}