// p: fix_environment() [for 'env']
//--------------------------------------------------------------
{
+ /* When allocating space for the client stack on Linux, take
+ notice of the --max-stackframe value. This makes it possible
+ to run programs with very large (primary) stack requirements
+ simply by specifying --max-stackframe. */
void* init_sp = iicii.argv - 1;
SizeT m1 = 1024 * 1024;
SizeT m16 = 16 * m1;
+ SizeT msf = VG_(clo_max_stackframe) + m1;
VG_(debugLog)(1, "initimg", "Setup client stack\n");
+ /* For the max stack size, use the client's stack rlimit, but
+ clamp it to between 1M and 16M. */
iifii.clstack_max_size = (SizeT)VG_(client_rlimit_stack).rlim_cur;
if (iifii.clstack_max_size < m1) iifii.clstack_max_size = m1;
if (iifii.clstack_max_size > m16) iifii.clstack_max_size = m16;
+ /* However, if --max-stackframe= is specified, and the given
+ value (+ 1 M for spare) exceeds the current setting, use the
+ max-stackframe input instead. */
+
+ if (iifii.clstack_max_size < msf) iifii.clstack_max_size = msf;
iifii.clstack_max_size = VG_PGROUNDUP(iifii.clstack_max_size);
iifii.initial_client_SP
VG_(debugLog)(2, "initimg",
"Client info: "
- "initial_IP=%p initial_SP=%p initial_TOC=%p brk_base=%p\n",
+ "initial_IP=%p initial_TOC=%p brk_base=%p\n",
(void*)(iifii.initial_client_IP),
- (void*)(iifii.initial_client_SP),
(void*)(iifii.initial_client_TOC),
(void*)VG_(brk_base) );
+ VG_(debugLog)(2, "initimg",
+ "Client info: "
+ "initial_SP=%p max_stack_size=%ld\n",
+ (void*)(iifii.initial_client_SP),
+ (SizeT)iifii.clstack_max_size );
}
//--------------------------------------------------------------
/* Peer at previously set up VG_(args_for_valgrind) and extract any
- request for help and also the tool name. */
+ request for help and also the tool name, and also set up
+ VG_(clo_max_stackframe). */
static void get_helprequest_and_toolname ( Int* need_help, HChar** tool )
{
// here.
} else if (VG_CLO_STREQN(7, str, "--tool=")) {
*tool = &str[7];
- }
+
+ // Set up VG_(clo_max_stackframe). This is needed by
+ // VG_(ii_create_image), which happens before
+ // process_command_line_options().
+ } else VG_NUM_CLO (str, "--max-stackframe",
+ VG_(clo_max_stackframe));
+
}
}
else VG_BOOL_CLO(arg, "--error-limit", VG_(clo_error_limit))
else VG_NUM_CLO (arg, "--error-exitcode", VG_(clo_error_exitcode))
else VG_BOOL_CLO(arg, "--show-emwarns", VG_(clo_show_emwarns))
+ /* Already done in get_helprequest_and_toolname, but we need to
+ redundantly handle it again, so the flag does not get
+ rejected as invalid. */
else VG_NUM_CLO (arg, "--max-stackframe", VG_(clo_max_stackframe))
else VG_BOOL_CLO(arg, "--run-libc-freeres", VG_(clo_run_libc_freeres))
else VG_BOOL_CLO(arg, "--show-below-main", VG_(clo_show_below_main))
/* Assertion broken before main() is reached in pthreaded programs; the
* offending stack traces only have one item. --njn, 2002-aug-16 */
/* vg_assert(fp_min <= fp_max);*/
-
- if (fp_min + VG_(clo_max_stackframe) <= fp_max) {
- /* If the stack is ridiculously big, don't poke around ... but
- don't bomb out either. Needed to make John Regehr's
- user-space threads package work. JRS 20021001 */
+ if (fp_min + 512 >= fp_max) {
+ /* If the stack limits look bogus, don't poke around ... but
+ don't bomb out either. */
ips[0] = ip;
return 1;
}