예제 #1
0
        void TakeDormantControlNoGC(int currentThreadIndex)
        {
            ThreadContext *threadContext =
                GetCurrentThreadContext(currentThreadIndex);

            TakeDormantControlNoGC(ref threadContext->gcStates);
        }
예제 #2
0
        internal static unsafe bool InDormantState(int threadIndex)
        {
            ThreadContext *threadContext = GetThreadContext(threadIndex);

            return(threadContext == null ||
                   fInDormantState(threadContext->gcStates));
        }
예제 #3
0
        void TakeMutatorControlNoGC(int currentThreadIndex)
        {
            ThreadContext *threadContext =
                GetCurrentThreadContext(currentThreadIndex);

            TakeMutatorControlNoGC(threadContext);
        }
예제 #4
0
        internal static unsafe void EntryIntoManagedSpace()
        {
            ThreadContext *currentThreadContext =
                Processor.GetCurrentThreadContext();

            EnsureMutatorControl(currentThreadContext);
        }
예제 #5
0
        // To be called at the beginning of a thread
        internal static unsafe void ThreadStart()
        {
            ThreadContext *currentThreadContext =
                Processor.GetCurrentThreadContext();

            TakeInitialMutatorControl(currentThreadContext);
        }
예제 #6
0
        internal static unsafe void RestoreMutatorControlIfNeeded()
        {
            ThreadContext *currentThreadContext =
                Processor.GetCurrentThreadContext();

            if (!Transitions.InMutatorState(currentThreadContext))
            {
                // NOTE: There is a window where OtherMutatorControl may be
                // set simultaneously with OtherGCRequest.  When clearing
                // OtherMutatorControl and setting OtherDormantControl, the
                // normal thing to do is to check for a GC request, but in
                // this case it doesn't matter as this code is only run
                // when an kernel exception is supposed to pass over an
                // application stack segment.
                int  oldValue, newValue;
                bool consumedSignal = false;
                int  threadIndex    = currentThreadContext->threadIndex;
                do
                {
                    oldValue = currentThreadContext->gcStates;
                    if (fUnderGCControl(oldValue))
                    {
                        Thread.WaitForGCEvent(threadIndex);
                        consumedSignal = true;
                    }
                    newValue = ((oldValue | MutatorState | OtherDormantState) &
                                ~(DormantState | OtherMutatorState));
                } while (!CompareAndSwap(ref currentThreadContext->gcStates,
                                         newValue, oldValue));
                if (consumedSignal)
                {
                    Thread.SignalGCEvent(threadIndex);
                }
            }
        }
예제 #7
0
        internal static unsafe bool TakeGCControl(int threadIndex)
        {
            ThreadContext *threadContext = GetThreadContext(threadIndex);

            return(threadContext != null &&
                   TakeGCControl(ref threadContext->gcStates));
        }
예제 #8
0
        internal static unsafe bool HasGCRequest(int threadIndex)
        {
            ThreadContext *threadContext = GetThreadContext(threadIndex);

            return(threadContext != null &&
                   fHasGCRequest(threadContext->gcStates));
        }
        internal static unsafe void ThrowProcessUncaughtException()
        {
            ThreadContext *context = Processor.GetCurrentThreadContext();

            context->uncaughtFlag = false;
            throw new ProcessUncaughtException();
        }
예제 #10
0
        internal static unsafe void ReleaseGCControl(int threadIndex)
        {
            ThreadContext *threadContext = GetThreadContext(threadIndex);

            if (threadContext != null)
            {
                ReleaseGCControl(ref threadContext->gcStates, threadIndex);
            }
        }
예제 #11
0
        internal static unsafe void ClearGCRequest(int threadIndex)
        {
            ThreadContext *threadContext = GetThreadContext(threadIndex);

            if (threadContext != null)
            {
                ClearGCRequest(ref threadContext->gcStates, threadIndex);
            }
        }
예제 #12
0
        void EnsureDormantControl(int currentThreadIndex)
        {
            ThreadContext *threadContext =
                GetCurrentThreadContext(currentThreadIndex);

            if (!fInDormantState(threadContext->gcStates))
            {
                TakeDormantControlNoGC(ref threadContext->gcStates);
            }
        }
예제 #13
0
        // To be called at the beginning of a thread
        internal static unsafe void ThreadStart()
        {
            ThreadContext *currentThreadContext =
                Processor.GetCurrentThreadContext();

            // The thread has been started in the kernel.  We need
            // to ensure that the transition to application space
            // is completed properly.
            EnsureMutatorControlNoGC(currentThreadContext);
        }
예제 #14
0
        internal static unsafe void ReturnFromManagedSpaceNoCallerTransition()
        {
            ThreadContext *currentThreadContext =
                Processor.GetCurrentThreadContext();

#if SINGULARITY_KERNEL
            // In Singularity kernel this function is the exit point of a kernel ABI.
            // If the thread is requested to be aborted, we stop it right here
            currentThreadContext->thread.ProcessAbortIfRequested(AbortRequestSource.ABINoGCExit);
#endif
            TakeDormantControl(currentThreadContext);
        }
예제 #15
0
        internal static unsafe void ActivatePreviousStackSegmentLimit()
        {
            // To avoid sprinkling [NoStackOverflowCheck] attributes
            // on too many methods, we manually inline a couple of methods.

            // ThreadContext *context = Processor.GetCurrentThreadContext();
            ThreadRecord * threadRecord = Isa.GetCurrentThread();
            ThreadContext *context      = (ThreadContext *)threadRecord;
            StackHead *    head         = (StackHead *)
                                          (context->stackBegin - sizeof(StackHead));

            // Isa.StackLimit = head->prevLimit;
            threadRecord->activeStackLimit = head->prevLimit;
        }
예제 #16
0
            internal override UIntPtr Callback(UIntPtr param)
            {
                unsafe {
                    ThreadContext *newContext = (ThreadContext *)param;

                    // Switch our thread context, synchronizing with the dispatcher as necessary.
                    ProcessorDispatcher.TransferToThreadContext(ref *GetCurrentThreadContext(),
                                                                ref *newContext);

                    // Resume in the new context. Note that this call does not return.
                    newContext->threadRecord.spill.Resume();

                    return(0);
                }
            }
예제 #17
0
        [NoStackLinkCheckTrans] // We don't want to throw an exception here;
        // Therefore, we cannot risk allocating stack segments,
        // and we should only call other NoStackLinkCheck functions (XXX).
        internal static unsafe UIntPtr CheckKernelProcessBoundary(UIntPtr esp, UIntPtr ebp, Exception exn)
        {
            ThreadContext *context = Processor.GetCurrentThreadContext();

            CallStack.TransitionRecord *topMarker    = context->kernelMarkers;
            CallStack.TransitionRecord *secondMarker = context->stackMarkers;
            UIntPtr topMarkerPtr = (UIntPtr)topMarker;

            // If the top marker is in our frame, we've reached a boundary:
            if (esp < topMarkerPtr && topMarkerPtr <= ebp)
            {
                context->uncaughtFlag = true;
                Thread.CurrentThread.lastUncaughtException = exn;
                Processor.GetCurrentThreadContext()->SetKernelMode();
                return(1);
            }
            else
            {
                return(0);
            }
        }
예제 #18
0
 void LeaveManagedSpace(ThreadContext *currentThreadContext)
 {
     TransferMutatorControl(currentThreadContext);
 }
예제 #19
0
 internal static unsafe bool InMutatorState(ThreadContext *threadContext)
 {
     return(threadContext != null &&
            fInMutatorState(threadContext->gcStates));
 }
예제 #20
0
 void SuspendThread(ThreadContext *currentThreadContext)
 {
     TakeDormantControl(currentThreadContext);
 }
예제 #21
0
 void ReturnToManagedSpace(ThreadContext *currentThreadContext)
 {
     EnsureMutatorControl(currentThreadContext);
 }
예제 #22
0
 void EnsureMutatorControlNoGC(ThreadContext *currentThreadContext)
 {
     EnsureMutatorControlNoGC(ref currentThreadContext->gcStates,
                              currentThreadContext->threadIndex);
 }
예제 #23
0
 void ReviveThread(ThreadContext *currentThreadContext)
 {
     TakeMutatorControl(currentThreadContext);
 }
예제 #24
0
 void TakeInitialMutatorControl(ThreadContext *threadContext)
 {
     TakeInitialMutatorControl(ref threadContext->gcStates,
                               threadContext->threadIndex);
 }
예제 #25
0
 void TransferMutatorControl(ThreadContext *currentThreadContext)
 {
     TransferMutatorControl(ref currentThreadContext->gcStates,
                            currentThreadContext->threadIndex);
 }
예제 #26
0
 void TakeMutatorControlNoGC(ThreadContext *threadContext)
 {
     TakeMutatorControlNoGC(ref threadContext->gcStates,
                            threadContext->threadIndex);
 }
예제 #27
0
        internal static unsafe bool InMutatorState(int threadIndex)
        {
            ThreadContext *threadContext = GetThreadContext(threadIndex);

            return(InMutatorState(threadContext));
        }
예제 #28
0
 internal void SetCalleeSaves(ThreadContext *context)
 {
     // Placeholder for an override method
 }
예제 #29
0
 void TakeDormantControl(ThreadContext *threadContext)
 {
     TakeDormantControl(ref threadContext->gcStates,
                        threadContext->threadIndex);
 }
예제 #30
0
        internal static unsafe void TakeDormantControl(int threadIndex)
        {
            ThreadContext *threadContext = GetThreadContext(threadIndex);

            TakeDormantControl(ref threadContext->gcStates, threadIndex);
        }