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 {...@@ -297,9 +297,10 @@ fn posixCallMainAndExit() noreturn {
297 std.os.linux.tls.initStaticTLS();297 std.os.linux.tls.initStaticTLS();
298 }298 }
299299
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 out334 // Because we could not increase the stack size to the upper bound,
334 // why this failed. If it is a release build, we allow the335 // depending on what happens at runtime, a stack overflow may occur.
335 // stack overflow to cause a segmentation fault. Memory safety336 // 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 not338 // 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 },