authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-23 00:41:50-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-08-23 00:41:50-07:00
log56119c2cbc6818de7b7b17a2d0e242f607bc7edb
tree4c317f932b850aca6cc15ba742ecde2fb2fecb08
parentc6286eee4ba8065b4a3f37fe3668041871e1b42e
parentf0d6a211e06cbd3765411e3acd70c0eb037bea62
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21118 from alexrp/thread-porting

`std.Thread`: Support hexagon, sparc32, s390x in `freeAndExit()`

1 files changed, 49 insertions(+), 3 deletions(-)

lib/std/Thread.zig+49-3
......@@ -1130,6 +1130,19 @@ const LinuxThreadImpl = struct {
11301130 [len] "r" (self.mapped.len),
11311131 : "memory"
11321132 ),
1133 .hexagon => asm volatile (
1134 \\ r6 = #215 // SYS_munmap
1135 \\ r0 = %[ptr]
1136 \\ r1 = %[len]
1137 \\ trap0(#1)
1138 \\ r6 = #93 // SYS_exit
1139 \\ r0 = #0
1140 \\ trap0(#1)
1141 :
1142 : [ptr] "r" (@intFromPtr(self.mapped.ptr)),
1143 [len] "r" (self.mapped.len),
1144 : "memory"
1145 ),
11331146 // We set `sp` to the address of the current function as a workaround for a Linux
11341147 // kernel bug that caused syscalls to return EFAULT if the stack pointer is invalid.
11351148 // The bug was introduced in 46e12c07b3b9603c60fc1d421ff18618241cb081 and fixed in
......@@ -1188,18 +1201,51 @@ const LinuxThreadImpl = struct {
11881201 [len] "r" (self.mapped.len),
11891202 : "memory"
11901203 ),
1204 .s390x => asm volatile (
1205 \\ lgr %%r2, %[ptr]
1206 \\ lgr %%r3, %[len]
1207 \\ svc 91 # SYS_munmap
1208 \\ lghi %%r2, 0
1209 \\ svc 1 # SYS_exit
1210 :
1211 : [ptr] "r" (@intFromPtr(self.mapped.ptr)),
1212 [len] "r" (self.mapped.len),
1213 : "memory"
1214 ),
1215 .sparc => asm volatile (
1216 \\ # See sparc64 comments below.
1217 \\ 1:
1218 \\ cmp %%fp, 0
1219 \\ beq 2f
1220 \\ nop
1221 \\ ba 1b
1222 \\ restore
1223 \\ 2:
1224 \\ mov 73, %%g1 # SYS_munmap
1225 \\ mov %[ptr], %%o0
1226 \\ mov %[len], %%o1
1227 \\ t 0x3 # ST_FLUSH_WINDOWS
1228 \\ t 0x10
1229 \\ mov 1, %%g1 # SYS_exit
1230 \\ mov 0, %%o0
1231 \\ t 0x10
1232 :
1233 : [ptr] "r" (@intFromPtr(self.mapped.ptr)),
1234 [len] "r" (self.mapped.len),
1235 : "memory"
1236 ),
11911237 .sparc64 => asm volatile (
11921238 \\ # SPARCs really don't like it when active stack frames
11931239 \\ # is unmapped (it will result in a segfault), so we
11941240 \\ # force-deactivate it by running `restore` until
11951241 \\ # all frames are cleared.
1196 \\ 1:
1242 \\ 1:
11971243 \\ cmp %%fp, 0
11981244 \\ beq 2f
11991245 \\ nop
12001246 \\ ba 1b
12011247 \\ restore
1202 \\ 2:
1248 \\ 2:
12031249 \\ mov 73, %%g1 # SYS_munmap
12041250 \\ mov %[ptr], %%o0
12051251 \\ mov %[len], %%o1
......@@ -1208,7 +1254,7 @@ const LinuxThreadImpl = struct {
12081254 \\ flushw
12091255 \\ t 0x6d
12101256 \\ mov 1, %%g1 # SYS_exit
1211 \\ mov 1, %%o0
1257 \\ mov 0, %%o0
12121258 \\ t 0x6d
12131259 :
12141260 : [ptr] "r" (@intFromPtr(self.mapped.ptr)),