authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-28 13:17:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-28 13:17:04-07:00
log33a779c7f65b9eb5115253bfe1cf4f4ea86336af
tree2689fedc9b1226bf57010e11f054ece7a2d7b773
parent673ae5b457479760ff8e08b3e06917a4b2651436

start.zig: intentional silent failure when cannot increase stack size


1 files changed, 12 insertions(+), 12 deletions(-)

lib/std/start.zig+12-12
......@@ -297,9 +297,10 @@ fn posixCallMainAndExit() noreturn {
297297 std.os.linux.tls.initStaticTLS();
298298 }
299299
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.
303304 {
304305 var i: usize = 0;
305306 var at_phdr: usize = undefined;
......@@ -330,15 +331,14 @@ fn expandStackSize(at_phdr: usize, at_phnum: usize) void {
330331 .cur = wanted_stack_size,
331332 .max = wanted_stack_size,
332333 }) 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
342342 };
343343 break;
344344 },