Followup-For: Bug #1030284 X-Debbugs-Cc: t...@mirbsd.de Thanks, Thorsten. I'm currently rebuilding (on x86) from the attached patch, adapted from yours.
* prefers a one-time repeat division over the clever-but-fragile div-assign * removes the upperbound check because integer greater-than checks can be problematic * places comparison constants on the lhs for safety I'll post test results when they are available. Cheers, James
Description: Request an rlimit-determined stack size from V8 Author: James Addison <j...@jp-hosting.net> Bug-Debian: https://bugs.debian.org/1030284 --- /dev/null +++ nodejs-18.13.0+dfsg1/foo.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main() { + if (4 > (int)(8 / 3)) { + printf("Hello world!"); + } +} --- nodejs-18.13.0+dfsg1.orig/src/node.cc +++ nodejs-18.13.0+dfsg1/src/node.cc @@ -785,6 +785,22 @@ int InitializeNodeWithArgs(std::vector<s V8::SetFlagsFromString(NODE_V8_OPTIONS, sizeof(NODE_V8_OPTIONS) - 1); #endif +#define V8_STACK_RESERVE 128 +if (!(flags & ProcessInitializationFlags::kNoAdjustResourceLimits)) { + struct rlimit lim; + char stackSize[sizeof("--stack-size=") + /* 2³¹ */ 10]; + + if (getrlimit(RLIMIT_STACK, &lim)) + fprintf(stderr, "W: stack size adjustment: cannot get RLIMIT_STACK\n"); + else if (RLIM_INFINITY == lim.rlim_cur) + fprintf(stderr, "W: stack size adjustment: RLIMIT_STACK is unlimited\n"); + else if (V8_STACK_RESERVE > (int)(lim.rlim_cur / 1024)) + fprintf(stderr, "W: stack size adjustment: RLIMIT_STACK is too small\n"); + else + V8::SetFlagsFromString(stackSize, snprintf(stackSize, sizeof(stackSize), + "--stack-size=%d", (int)(lim.rlim_cur / 1024))); +} + HandleEnvOptions(per_process::cli_options->per_isolate->per_env); #if !defined(NODE_WITHOUT_NODE_OPTIONS)