Skip to content
Snippets Groups Projects
  • Simon McVittie's avatar
    95204f4a
    utils: Allocate ld_libs on the heap · 95204f4a
    Simon McVittie authored
    The ld_libs data structure is pre-allocated at maximum size instead of
    using dynamic memory allocation, in an effort to avoid use of malloc()
    during critical-path interactions with basic shared library
    infrastructure. This makes it about 1 MiB, so if users have reduced
    RLIMIT_STACK from its post-1995 default of 8 MiB for whatever reason,
    it doesn't take many levels of recursion to exceed that limit.
    
    The symptom for a stack overflow is particularly un-diagnosable (instead
    of exiting unsuccessfully with an error message, the program will just
    segfault), so allocate this data structure on the heap instead, which
    gives us the opportunity to log "libcapsule: out of memory".
    
    The equivalent data structures within libcapsule itself are still
    allocated on the stack, to avoid introducing new memory allocation
    inside a critical section.
    
    Resolves: https://github.com/ValveSoftware/steam-runtime/issues/653
    
    
    Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
    95204f4a
    History
    utils: Allocate ld_libs on the heap
    Simon McVittie authored
    The ld_libs data structure is pre-allocated at maximum size instead of
    using dynamic memory allocation, in an effort to avoid use of malloc()
    during critical-path interactions with basic shared library
    infrastructure. This makes it about 1 MiB, so if users have reduced
    RLIMIT_STACK from its post-1995 default of 8 MiB for whatever reason,
    it doesn't take many levels of recursion to exceed that limit.
    
    The symptom for a stack overflow is particularly un-diagnosable (instead
    of exiting unsuccessfully with an error message, the program will just
    segfault), so allocate this data structure on the heap instead, which
    gives us the opportunity to log "libcapsule: out of memory".
    
    The equivalent data structures within libcapsule itself are still
    allocated on the stack, to avoid introducing new memory allocation
    inside a critical section.
    
    Resolves: https://github.com/ValveSoftware/steam-runtime/issues/653
    
    
    Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>