This is probably the largest Nim library written with manual memory management:

  * <https://github.com/mratsim/constantine>
  * See allocators: 
<https://github.com/mratsim/constantine/blob/0a17002/constantine/platforms/allocs.nim#L72-L134>



That said for core cryptography, it's all stack objects. I could use 
destructors hook for more "automated manual" memory management.

I do pass a lot of flags for ensuring correctness in my test suite: 
<https://github.com/mratsim/constantine/blob/0a17002/constantine.nimble#L636-L661>
    
    
    const stackHardening =
        
        " --passC:-fstack-protector-strong " &
        
        # Fortify source wouldn't help us detect errors in Constantine
        # because everything is stack allocated
        # except with the threadpool:
        # - 
https://developers.redhat.com/blog/2021/04/16/broadening-compiler-checks-for-buffer-overflows-in-_fortify_source#what_s_next_for__fortify_source
        # - 
https://developers.redhat.com/articles/2023/02/06/how-improve-application-security-using-fortifysource3#how_to_improve_application_fortification
        # We also don't use memcpy as it is not constant-time and our copy is 
compile-time sized.
        
        " --passC:-D_FORTIFY_SOURCE=3 "
      
      const sanitizers =
        
        # Sanitizers are incompatible with nim default GC
        # The conservative stack scanning of Nim default GC triggers, alignment 
UB and stack-buffer-overflow check.
        # Address sanitizer requires free registers and needs to be disabled 
for some inline assembly files.
        # Ensure you use --mm:arc -d:useMalloc
        #
        # Sanitizers are deactivated by default as they slow down CI by at 
least 6x
        
        " --mm:arc -d:useMalloc" &
        " --passC:-fsanitize=undefined --passL:-fsanitize=undefined" &
        " --passC:-fsanitize=address --passL:-fsanitize=address" &
        " --passC:-fno-sanitize-recover" # Enforce crash on undefined behaviour
    
    
    Run

Reply via email to