diff --git a/src/disco/topo/fd_topo_run.c b/src/disco/topo/fd_topo_run.c index 36667085a3..4b1d81a791 100644 --- a/src/disco/topo/fd_topo_run.c +++ b/src/disco/topo/fd_topo_run.c @@ -147,6 +147,8 @@ typedef struct { uint gid; int * done_futex; volatile int copied; + void * stack_lo; + void * stack_hi; } fd_topo_run_thread_args_t; static void * @@ -155,6 +157,11 @@ run_tile_thread_main( void * _args ) { FD_COMPILER_MFENCE(); ((fd_topo_run_thread_args_t *)_args)->copied = 1; + /* Prevent fork() from smashing the stack */ + if( FD_UNLIKELY( madvise( args.stack_lo, (ulong)args.stack_hi - (ulong)args.stack_lo, MADV_DONTFORK ) ) ) { + FD_LOG_ERR(( "madvise(stack,MADV_DONTFORK) failed (%i-%s)", errno, fd_io_strerror( errno ) )); + } + fd_topo_run_tile( args.topo, args.tile, 0, 1, 1, args.uid, args.gid, -1, NULL, NULL, &args.tile_run ); if( FD_UNLIKELY( args.done_futex ) ) { for(;;) { @@ -282,6 +289,8 @@ run_tile_thread( fd_topo_t * topo, .gid = gid, .done_futex = done_futex, .copied = 0, + .stack_lo = stack, + .stack_hi = (uchar *)stack + FD_TILE_PRIVATE_STACK_SZ }; pthread_t pthread; diff --git a/src/util/tile/fd_tile_threads.cxx b/src/util/tile/fd_tile_threads.cxx index c735e2cb5e..50044bb7ef 100644 --- a/src/util/tile/fd_tile_threads.cxx +++ b/src/util/tile/fd_tile_threads.cxx @@ -297,6 +297,12 @@ fd_tile_private_manager( void * _args ) { if( FD_LIKELY( stack ) ) { /* User provided stack */ fd_tile_private_stack0 = (ulong)stack; fd_tile_private_stack1 = (ulong)stack + stack_sz; + + /* Prevent another fork() from smashing the stack */ + if( FD_UNLIKELY( madvise( stack, FD_TILE_PRIVATE_STACK_SZ, MADV_DONTFORK ) ) ) { + FD_LOG_ERR(( "madvise(stack,MADV_DONTFORK) failed (%i-%s)", errno, fd_io_strerror( errno ) )); + } + } else { /* Pthread provided stack */ fd_log_private_stack_discover( stack_sz, &fd_tile_private_stack0, &fd_tile_private_stack1 ); /* logs details */ if( FD_UNLIKELY( !fd_tile_private_stack0 ) )