| ... | ... | @@ -459,22 +459,29 @@ fn expandStackSize(phdrs: []elf.Phdr) void { |
| 459 | 459 | for (phdrs) |*phdr| { |
| 460 | 460 | switch (phdr.p_type) { |
| 461 | 461 | elf.PT_GNU_STACK => { |
| 462 | | const wanted_stack_size = phdr.p_memsz; |
| 463 | | assert(wanted_stack_size % std.mem.page_size == 0); |
| 464 | | |
| 465 | | std.os.setrlimit(.STACK, .{ |
| 466 | | .cur = wanted_stack_size, |
| 467 | | .max = wanted_stack_size, |
| 468 | | }) catch { |
| 469 | | // Because we could not increase the stack size to the upper bound, |
| 470 | | // depending on what happens at runtime, a stack overflow may occur. |
| 471 | | // However it would cause a segmentation fault, thanks to stack probing, |
| 472 | | // so we do not have a memory safety issue here. |
| 473 | | // This is intentional silent failure. |
| 474 | | // This logic should be revisited when the following issues are addressed: |
| 475 | | // https://github.com/ziglang/zig/issues/157 |
| 476 | | // https://github.com/ziglang/zig/issues/1006 |
| 477 | | }; |
| 462 | assert(phdr.p_memsz % std.mem.page_size == 0); |
| 463 | |
| 464 | // Silently fail if we are unable to get limits. |
| 465 | const limits = std.os.getrlimit(.STACK) catch break; |
| 466 | |
| 467 | // Clamp to limits.max . |
| 468 | const wanted_stack_size = @min(phdr.p_memsz, limits.max); |
| 469 | |
| 470 | if (wanted_stack_size > limits.cur) { |
| 471 | std.os.setrlimit(.STACK, .{ |
| 472 | .cur = wanted_stack_size, |
| 473 | .max = limits.max, |
| 474 | }) catch { |
| 475 | // Because we could not increase the stack size to the upper bound, |
| 476 | // depending on what happens at runtime, a stack overflow may occur. |
| 477 | // However it would cause a segmentation fault, thanks to stack probing, |
| 478 | // so we do not have a memory safety issue here. |
| 479 | // This is intentional silent failure. |
| 480 | // This logic should be revisited when the following issues are addressed: |
| 481 | // https://github.com/ziglang/zig/issues/157 |
| 482 | // https://github.com/ziglang/zig/issues/1006 |
| 483 | }; |
| 484 | } |
| 478 | 485 | break; |
| 479 | 486 | }, |
| 480 | 487 | else => {}, |