| ... | ... | @@ -297,9 +297,10 @@ fn posixCallMainAndExit() noreturn { |
| 297 | 297 | std.os.linux.tls.initStaticTLS(); |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | | // Linux ignores the stack size from the ELF file, and instead always gives 8 MiB. |
| 301 | | // Here we look for the stack size in our program headers and tell the kernel, |
| 302 | | // no, seriously, give me that stack space, I wasn't joking. |
| 300 | // The way Linux executables represent stack size is via the PT_GNU_STACK |
| 301 | // program header. However the kernel does not recognize it; it always gives 8 MiB. |
| 302 | // Here we look for the stack size in our program headers and use setrlimit |
| 303 | // to ask for more stack space. |
| 303 | 304 | { |
| 304 | 305 | var i: usize = 0; |
| 305 | 306 | var at_phdr: usize = undefined; |
| ... | ... | @@ -330,15 +331,14 @@ fn expandStackSize(at_phdr: usize, at_phnum: usize) void { |
| 330 | 331 | .cur = wanted_stack_size, |
| 331 | 332 | .max = wanted_stack_size, |
| 332 | 333 | }) catch { |
| 333 | | // If this is a debug build, it will be useful to find out |
| 334 | | // why this failed. If it is a release build, we allow the |
| 335 | | // stack overflow to cause a segmentation fault. Memory safety |
| 336 | | // is not compromised, however, depending on runtime state, |
| 337 | | // the application may crash due to provided stack space not |
| 338 | | // matching the known upper bound. |
| 339 | | if (builtin.mode == .Debug) { |
| 340 | | @panic("unable to increase stack size"); |
| 341 | | } |
| 334 | // Because we could not increase the stack size to the upper bound, |
| 335 | // depending on what happens at runtime, a stack overflow may occur. |
| 336 | // However it would cause a segmentation fault, thanks to stack probing, |
| 337 | // so we do not have a memory safety issue here. |
| 338 | // This is intentional silent failure. |
| 339 | // This logic should be revisited when the following issues are addressed: |
| 340 | // https://github.com/ziglang/zig/issues/157 |
| 341 | // https://github.com/ziglang/zig/issues/1006 |
| 342 | 342 | }; |
| 343 | 343 | break; |
| 344 | 344 | }, |