4 ms·
> Why would an api be able to tell you anything the debugger can’t? An error message is much easier to read then a stacktrace, especially if you dont have sour
by quelsolaar 6y ago
> Why would an api be able to tell you anything the debugger can’t?
An error message is much easier to read then a stacktrace, especially if you dont have source-code.
> If you want to do what you describe you have to make such changes that the language really isn’t c anymore.
I dont want any changes to C. I just want to be able to query a process allocations. the OS has to keep the information in order to implement realloc and free, so the information is already there.
- tinus_hn 6y agoThe operating system doesn’t handle malloc, realloc and free. That task is handled by the C library. All the operating system provides is a way for these functions to claim and release large areas of memory. Applications use malloc to allocate some memory they then use to store a collection of data. Pointers often don’t point to the exact start of that memory area, which is what you need to do memory management. So from a pointer you can’t necessarily realloc or free. And the problem is, if a buffer overruns for instance, you end up writing memory that is allocated and valid, just not for the thing the developer thought. Alternative implementations of malloc exist that try to help with this, by encasing memory between guard pages. Also, with for example glibc malloc you can use the MALLOC_TRACE environment variable to get a log of all allocations.
- quelsolaar 6y agoI already have an alternative implementation of malloc that does this. But i still need Microsoft s help to get the same information from a process that didn't use my implementation. I dont need to free or realloc pointers i just need to know if a pointer is valid.
- tinus_hn 6y agoIn normal processes you can find this through the _heapwalk function: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/heapwalk?view=msvc-160 https://docs.microsoft.com/en-us/cpp/c-runtime-library/refer...