4 ms·
If you write your own allocator in C, do yourself a favor and use the valgrind API inside it. Its use can be conditional so you can "compile it out". Or should
by kazinator 2y ago
If you write your own allocator in C, do yourself a favor and use the valgrind API inside it. Its use can be conditional so you can "compile it out". Or should I say it has to be, so you can build the code in an environment where there's no valgrind API.
- gopalv 2y ago+1 - this isn't even that hard, it is include a single header + annotate allocations/frees, with some redzones around the actual allocation to know when the user-code is writing into the pool pointer areas. https://developers.redhat.com/articles/2022/03/23/use-valgrind-memcheck-custom-memory-manager https://developers.redhat.com/articles/2022/03/23/use-valgri...
- deleted 2y ago[deleted]
- hooli_gan 2y agohttps://en.wikipedia.org/wiki/Red_zone_(computing) https://en.wikipedia.org/wiki/Red_zone_(computing)
- dsp_person 2y agooof love on this page how scrolling hijacks the back button
- swah 2y agoThats with Claude, right?
- gopalv 2y ago> with Claude The comment itself is AI generated or the code reference? Here's some of my old code https://github.com/php/pecl-caching-apc/blob/0dd2a69bab58822ba86a88445de06638a6a2456d/apc_pool.c#L221 https://github.com/php/pecl-caching-apc/blob/0dd2a69bab58822...
- 8dcc 2y agoI have never heard about this (using valgrind with a "non-standard allocator"), but it looks really interesting, specially for other projects I am working on. I will definitely look into it.
- mananaysiempre 2y agoYou can also integrate with AddressSanitizer to some extent, look into[1] ASAN_{UN,}POISON_MEMORY_REGION from <sanitizer/asan_interface.h> or the underlying intrinsics __asan_{un,}poison_memory_region. [1] https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning https://github.com/google/sanitizers/wiki/AddressSanitizerMa...
- kazinator 2y agoI integrated the TXR Lisp garbage collector with valgrind. That came in handy on a number of occasions. It's not always the case that you want special behavior for the garbage collector to assist with debugging, but also this: if you want to use Valgrind to debug anything that does not have to do with the garbage collector, you want all the false positives generated by it out of your way. Some of the scanning that a conservative garbage collector has to do looks like access errors to Valgrind. By using the Valgrind API, you can grant yourself access to that memory, and then lock it again when done. That aspect doesn't necessarily apply to a pool allocator being described in this article; that should not be triggering any false positives.
- 8dcc 2y ago(In case you missed my other post, I ended up adding valgrind support in the article and in the 'libpool' project.) > I integrated the TXR Lisp garbage collector with valgrind. That's funny, because when I said "for other projects I am working on", I specifically meant a Lisp interpreter which uses a memory pool and garbage collection (I am still working on implementing this last part, anyway). I am very happy about the fact that I can continue using valgrind in this project.
- kragen 2y ago
- kragen 2y agoThanks for the tip!
- tavianator 2y agoI've replaced Valgrind with sanitizers for most of my workflow. Using the sanitizer APIs in your custom allocator is also easy: https://github.com/tavianator/bfs/blob/main/src/sanity.h https://github.com/tavianator/bfs/blob/main/src/sanity.h https://github.com/tavianator/bfs/blob/31dffd6441ba80ea998cedd10f9138198298e9fc/src/alloc.c#L218 https://github.com/tavianator/bfs/blob/31dffd6441ba80ea998ce...
- lsllc 2y agoThe Address Sanitizer (ASAN) in both clang and gcc is/are excellent: https://github.com/google/sanitizers/wiki/addresssanitizer https://github.com/google/sanitizers/wiki/addresssanitizer I believe to integrate a custom allocator with ASAN, you need to look at the memory "poisoning" mechanisms: https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning https://github.com/google/sanitizers/wiki/AddressSanitizerMa...
- pjmlp 2y agoIt is also available on MVSC nowadays. https://learn.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-170 https://learn.microsoft.com/en-us/cpp/sanitizers/asan?view=m... .NET team also makes use of it for the runtime parts, https://devblogs.microsoft.com/cppblog/msvc-address-sanitizer-adoption-in-nets-coreclr/ https://devblogs.microsoft.com/cppblog/msvc-address-sanitize...