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