Checking heap integrity and stack size in C #

I am trying to track down a crash that happens when I emphasize my C # code and work in low memory conditions. However, in some cases, instead of getting an OutOfMemoryException, my program just crashes and exits. This is usually caused by memory corruption due to a buffer overrun or due to (or corruption).

So, is there a way to run a heap integrity check, or is there a way to check how much stack is left in the stream?

I use a lot of insecure code for speed reasons, so it is likely that I have code that distorts memory somewhere. Unfortunately, the accident happens by chance after corruption occurs. I understand that C # closes the application when it detects a buffer overflow, but is there a way to get it to perform a check?

Thanks.

+3
source share
3 answers

You can handle these situations using Limited execution areas :

Limited execution area (CER) is part of the mechanism for creating robust managed code. CER defines the area in which the common CLR runtime is limited due to the exception of out-of-zone exceptions that would prevent the entire code from executing in that area. Within this region, the user code is restricted from executing code that will throw out-of-band exceptions. The method PrepareConstrainedRegionsmust immediately precede the block try, and the labels catch, finallyandfault . , , , , . CLR , CER.

, . . .

+3

:

...

IGCHost

.NET

:

, , . [,] , , , OutOfMemory .

, , , . , , , . , , . , . !

, , , , . , , .

+2

, , . , , ​​ EXCEPTION_RECORD , . , , , . , , , EXCEPTION_STACK_OVERFLOW , .

The best thing would be to fix corruption. Try running gflags PageHeap . If you know where the exception occurred, try setting a break point in the buffer in the debugger. Or try to identify the posthumous font from the recording template (maybe, for example, a string) or from a memory search for links back to your buffer.

+1
source

Source: https://habr.com/ru/post/1721305/


All Articles