This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!
Services Based on Stack Format
The primary requirement for managed code is that it is possible to trace the stack at runtime. Different source languages may make different decisions about the layout of stack frames under their control, so the runtime uses a specific API, the code manager, to understand the format of individual stack frames. The code manager is specified either by the JITter or the source language compiler (persisted in the PE file format) that produces each native managed code method.
The code manager is used for four separate services:
- Garbage Collection. Any source language that allows access to VOS objects is required to have a code manager that can report the locations in its stack frame that contain object references. The garbage collector supports both pointers to the start of an object or interior pointers (also known as managed pointers) that point inside the representation of an object. The garbage collector runs in two phases: the first to find all objects still active in the system and the second to copy those objects and modify references to them to point to their new locations. It uses the code manager both to locate the references on the stack and to arrange for execution to be suspended (“hijacking”) while the pointers are updated.
- Exceptions. The VES supports an exception mechanism that is compatible with SEH (Win32 Structured Exception Handling). It uses the code manager to determine which exception handlers or filters are active in each stack frame. The code manager is free to use any mechanism it likes for this purpose. The code manager for the existing JITters uses an exception handler table that is part of the method header for this purpose.
CLS Rule 40: Exception objects must derive from System.Exception
CLS (consumer): Must allow exceptions derived from System.Exception to be caught and thrown.
CLS (extender): Must allow new exceptions to be defined by deriving them from System.Exception.
CLS (framework): Should, where reasonable, throw exceptions derived from System.Exception to signal error conditions, rather than returning status flags or success codes. Must not throw any value not derived from System.Exception.
- Security. The implementation of code access security uses the code manager to examine the stack for special security markers that indicate permissions granted to executing procedures. These markers may be allocated on the stack by a JITter and are only accessible through the code manager.
- Debugging and Profiling. Both debugging and profiling allow external processes to examine and modify the stack of a NGWS runtime process using the code manager.