If you load the application assembly into a separate domain, then in the event of unchecked "Stack overflow exception" errors, memory corruption, will the main application domain work, or will it put the whole process?
- The stack belongs to Thread-y, try performing such actions in a separate Thread. Crash of minor threads in c ++ does not affect the operation of the main one. Not sure if it’s with #, most likely yes. Thread can not continue to work, but you can understand at what phase it is laid down. - nick_n_a Nov.
- @nick_n_a, that is, if if you need to make a cross-domain application and that if the domain fell, the application did not die, then you need to do this cross-domain interaction in a separate stream? - iluxa1810
- @nick_n_a does not work. - iluxa1810
- @ iluxa1810 see ... surprised. Well ... the second option is to make an interlayer on c ++, and add c try ++ to c ++ ... (what would the native treat) - nick_n_a
- @nick_n_a, but there is some CER. I have never worked with him, but there one can attribute to the attributes methods that override the process. Can it be used in some way? - iluxa1810
1 answer
Starting with the .NET Framework version 2.0, the corresponding process is terminated by default. Consequently, users can advise you to overload stack. For example, if your application depends on the recursion loop, terminate the recursive loop. There can be a process that can occur in the CLR. For more information, see ICLRPolicyManager Interface and Hosting the Common Language Runtime.
Starting with version 2.0, stack overflow can be intercepted only if it is thrown by the user.
It turns out that if you believe this answer, then even an overflow in another domain kills the process, arguing that the whole place on the stack is possible and nothing will be done.
There is also such an article on Habré , where hacks are done through WinApi, which allow the process not to die, but this is a risky business ...
The article also recommends using RuntimeHelpers , for example, there is such a method RuntimeHelpers.ProbeForSufficientStack , which checks the possibility of memory allocation.
Back in 7.2, Span and stackallock/trystackalloc , which allow you to safely place data on the stack:
Span<byte> span; if (CanAllocateOnStack(size)) span = stackalloc byte[size]; else span = new byte[size]; UPD
Regarding the option with a separate thread:
static void Main(string[] args) { var thread=new Thread(() => { Recursive(); }); try { thread.Start(); while (thread.IsAlive) { } } catch (Exception e) { Console.WriteLine(e); throw; } } static void Recursive() { Recursive(); } The process still dies completely.
Here is my question on this topic.
UPD2
Alternatively, you can use StackTrace().FrameCount , but if we do not have access to the source code, we will not be able to insert it into recursion, which would check from time to time and fall out on the threshold of stack overflow.
- The problem with interacting with native c ++ libraries that can destroy memory from time to time. Unfortunately, there is no source code, so most likely you will have to load the assemblies into separate processes - Aleksandr Necheukhin
- So the question was then the domain, and not about the flow. - Qwertiy ♦