This is all intentionally vague because it is a strong implementation detail that the CLI specification does not want to nail. He looks through the cracks in the MSDN article for Opcodes.Localloc , though:
A StackOverflowException is thrown if there is not enough memory to service the request.
Only one way that you ever get SOE: you need to allocate from the stack.
C # is less shy when it is distributed, it uses the stackalloc keyword. Program Example:
class Program { static unsafe void Main(string[] args) { int* p = stackalloc int[42]; } }
Produces this IL:
.method private hidebysig static void Main(string[] args) cil managed { .entrypoint
Which creates this machine code at runtime:
02E42620 push ebp 02E42621 mov ebp,esp 02E42623 sub esp,8 02E42626 mov dword ptr [ebp-4],esp 02E42629 mov dword ptr [ebp-8],6A029823h 02E42630 mov eax,esp 02E42632 test dword ptr [esp],esp 02E42635 sub eax,0A8h // <=== Here 02E4263A mov esp,eax 02E4263C mov dword ptr [ebp-4],esp 02E4263F cmp dword ptr [ebp-8],6A029823h 02E42646 je 02E4264D 02E42648 call 730CA5C0 02E4264D lea esp,[ebp] 02E42650 pop ebp 02E42651 ret
The sub eax,0A8h instruction sub eax,0A8h subtracts 0xa8 = 168 = 42x4 bytes from the ESP register (stack pointer), the mov esp,eax command sets the stack pointer. So yes, it definitely comes from the stack.
source share