Exemplo n.º 1
0
        void TakeDormantControlNoGC(int currentThreadIndex)
        {
            ThreadContext *threadContext =
                GetCurrentThreadContext(currentThreadIndex);

            TakeDormantControlNoGC(ref threadContext->gcStates);
        }
Exemplo n.º 2
0
        internal static unsafe bool InDormantState(int threadIndex)
        {
            ThreadContext *threadContext = GetThreadContext(threadIndex);

            return(threadContext == null ||
                   fInDormantState(threadContext->gcStates));
        }
Exemplo n.º 3
0
        void TakeMutatorControlNoGC(int currentThreadIndex)
        {
            ThreadContext *threadContext =
                GetCurrentThreadContext(currentThreadIndex);

            TakeMutatorControlNoGC(threadContext);
        }
Exemplo n.º 4
0
        internal static unsafe void EntryIntoManagedSpace()
        {
            ThreadContext *currentThreadContext =
                Processor.GetCurrentThreadContext();

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

            TakeInitialMutatorControl(currentThreadContext);
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 7
0
        internal static unsafe bool TakeGCControl(int threadIndex)
        {
            ThreadContext *threadContext = GetThreadContext(threadIndex);

            return(threadContext != null &&
                   TakeGCControl(ref threadContext->gcStates));
        }
Exemplo n.º 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();
        }
Exemplo n.º 10
0
        internal static unsafe void ReleaseGCControl(int threadIndex)
        {
            ThreadContext *threadContext = GetThreadContext(threadIndex);

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

            if (threadContext != null)
            {
                ClearGCRequest(ref threadContext->gcStates, threadIndex);
            }
        }
Exemplo n.º 12
0
        void EnsureDormantControl(int currentThreadIndex)
        {
            ThreadContext *threadContext =
                GetCurrentThreadContext(currentThreadIndex);

            if (!fInDormantState(threadContext->gcStates))
            {
                TakeDormantControlNoGC(ref threadContext->gcStates);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
                }
            }
Exemplo n.º 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);
            }
        }
Exemplo n.º 18
0
 void LeaveManagedSpace(ThreadContext *currentThreadContext)
 {
     TransferMutatorControl(currentThreadContext);
 }
Exemplo n.º 19
0
 internal static unsafe bool InMutatorState(ThreadContext *threadContext)
 {
     return(threadContext != null &&
            fInMutatorState(threadContext->gcStates));
 }
Exemplo n.º 20
0
 void SuspendThread(ThreadContext *currentThreadContext)
 {
     TakeDormantControl(currentThreadContext);
 }
Exemplo n.º 21
0
 void ReturnToManagedSpace(ThreadContext *currentThreadContext)
 {
     EnsureMutatorControl(currentThreadContext);
 }
Exemplo n.º 22
0
 void EnsureMutatorControlNoGC(ThreadContext *currentThreadContext)
 {
     EnsureMutatorControlNoGC(ref currentThreadContext->gcStates,
                              currentThreadContext->threadIndex);
 }
Exemplo n.º 23
0
 void ReviveThread(ThreadContext *currentThreadContext)
 {
     TakeMutatorControl(currentThreadContext);
 }
Exemplo n.º 24
0
 void TakeInitialMutatorControl(ThreadContext *threadContext)
 {
     TakeInitialMutatorControl(ref threadContext->gcStates,
                               threadContext->threadIndex);
 }
Exemplo n.º 25
0
 void TransferMutatorControl(ThreadContext *currentThreadContext)
 {
     TransferMutatorControl(ref currentThreadContext->gcStates,
                            currentThreadContext->threadIndex);
 }
Exemplo n.º 26
0
 void TakeMutatorControlNoGC(ThreadContext *threadContext)
 {
     TakeMutatorControlNoGC(ref threadContext->gcStates,
                            threadContext->threadIndex);
 }
Exemplo n.º 27
0
        internal static unsafe bool InMutatorState(int threadIndex)
        {
            ThreadContext *threadContext = GetThreadContext(threadIndex);

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

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