Skip to content

Commit 6c3d257

Browse files
committed
Unmap MAP_SHARED stacks on fork()
1 parent 77da647 commit 6c3d257

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/disco/topo/fd_topo_run.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ fd_topo_tile_stack_join( char const * app_name,
197197
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, (off_t)0 )!=guard_hi ) )
198198
FD_LOG_ERR(( "mmap failed (%i-%s)", errno, fd_io_strerror( errno ) ));
199199

200+
/* fork() is incompatible with MAP_SHARED */
201+
if( FD_UNLIKELY( madvise( stack, FD_TILE_PRIVATE_STACK_SZ, MADV_DONTFORK ) ) ) {
202+
FD_LOG_ERR(( "madvise(stack,MADV_DONTFORK) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
203+
}
204+
200205
return stack;
201206
}
202207

src/util/tile/fd_tile_threads.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ fd_tile_private_stack_new( int optimize,
160160
FD_LOG_WARNING(( "fd_tile: mmap failed (%i-%s)\n\tAttempting to continue without stack guard hi.",
161161
errno, fd_io_strerror( errno ) ));
162162

163+
/* Prevent fork() from smashing the stack */
164+
165+
if( FD_UNLIKELY( madvise( stack, FD_TILE_PRIVATE_STACK_SZ, MADV_DONTFORK ) ) ) {
166+
FD_LOG_ERR(( "madvise(stack,MADV_DONTFORK) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
167+
}
168+
163169
return stack;
164170
}
165171

0 commit comments

Comments
 (0)