2008-03-05 09:52:00 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Microsoft Research Singularity - Singularity ABI
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// File: StackService.cs
|
|
|
|
//
|
|
|
|
// Note:
|
|
|
|
//
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using Microsoft.Singularity.Memory;
|
2008-11-17 18:29:00 -05:00
|
|
|
using Microsoft.Singularity.Isal;
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
namespace Microsoft.Singularity.V1.Services
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
[AccessedByRuntime("referenced from halstack.asm")]
|
2008-03-05 09:52:00 -05:00
|
|
|
public struct StackService
|
|
|
|
{
|
|
|
|
[ExternalEntryPoint]
|
|
|
|
public static void WalkStack()
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
Stacks.WalkStack(Isa.GetFramePointer());
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
[ExternalEntryPoint]
|
|
|
|
[NoHeapAllocation]
|
|
|
|
[CLSCompliant(false)]
|
|
|
|
public static unsafe void GetUsageStatisticsImpl(ulong *gets, ulong *returns)
|
|
|
|
{
|
|
|
|
GetUsageStatistics(out *gets, out *returns);
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
// The ABI service MemoryUsageInfo provides more comprehensive information
|
2008-03-05 09:52:00 -05:00
|
|
|
[NoHeapAllocation]
|
|
|
|
[CLSCompliant(false)]
|
|
|
|
public static void GetUsageStatistics(out ulong gets, out ulong returns)
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
ulong kernelStackCount = 0;
|
|
|
|
ulong kernelStackReturnCount = 0;
|
|
|
|
ulong kernelStackBytes = 0;
|
|
|
|
ulong kernelStackReturnBytes = 0;
|
|
|
|
ulong kernelStackReservationLocal = 0;
|
|
|
|
ulong SIPStackCount = 0;
|
|
|
|
ulong SIPStackReturnCount = 0;
|
|
|
|
ulong SIPStackBytes = 0;
|
|
|
|
ulong SIPStackReturnBytes = 0;
|
|
|
|
ulong SIPStackReservation = 0;
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
MemoryManager.GetStackUsage(
|
|
|
|
out kernelStackCount,
|
|
|
|
out kernelStackReturnCount,
|
|
|
|
out kernelStackBytes,
|
|
|
|
out kernelStackReturnBytes,
|
|
|
|
out kernelStackReservationLocal,
|
|
|
|
out SIPStackCount,
|
|
|
|
out SIPStackReturnCount,
|
|
|
|
out SIPStackBytes,
|
|
|
|
out SIPStackReturnBytes,
|
|
|
|
out SIPStackReservation
|
|
|
|
);
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
// Just summary information
|
|
|
|
gets = kernelStackCount + SIPStackCount;
|
|
|
|
returns = kernelStackReturnCount + SIPStackReturnCount;
|
|
|
|
}
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
[ExternalEntryPoint]
|
|
|
|
[CLSCompliant(false)]
|
2008-11-17 18:29:00 -05:00
|
|
|
[NoStackLinkCheckTrans]
|
|
|
|
public static UIntPtr AllocateStackSegmentAbi(UIntPtr growSize)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
return Stacks.GetSipStackSegment(growSize);
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
[ExternalEntryPoint]
|
|
|
|
[CLSCompliant(false)]
|
2008-11-17 18:29:00 -05:00
|
|
|
[NoStackLinkCheckTrans]
|
|
|
|
[NoStackOverflowCheck]
|
|
|
|
public static void FreeStackSegmentAbi()
|
|
|
|
{
|
|
|
|
// First, set threadRecord->activeStackLimit to the proper
|
|
|
|
// value for the previous (now current) stack segment. This
|
|
|
|
// ensures that subsequent stack checks are done using the
|
|
|
|
// correct stack segment limit.
|
|
|
|
Stacks.ActivatePreviousStackSegmentLimit();
|
|
|
|
Stacks.ReturnSipStackSegment();
|
|
|
|
}
|
|
|
|
|
|
|
|
[CLSCompliant(false)]
|
|
|
|
[AccessedByRuntime("called from halstack.asm")]
|
|
|
|
[NoStackLinkCheckTrans]
|
|
|
|
public static UIntPtr AllocateStackSegment(UIntPtr growSize)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
return Stacks.GetKernelStackSegment(growSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
[CLSCompliant(false)]
|
|
|
|
[AccessedByRuntime("called from halstack.asm")]
|
|
|
|
[NoStackLinkCheckTrans]
|
|
|
|
[NoStackOverflowCheck]
|
|
|
|
public static void FreeStackSegment()
|
|
|
|
{
|
|
|
|
// First, set threadRecord->activeStackLimit to the proper
|
|
|
|
// value for the previous (now current) stack segment. This
|
|
|
|
// ensures that subsequent stack checks are done using the
|
|
|
|
// correct stack segment limit.
|
|
|
|
Stacks.ActivatePreviousStackSegmentLimit();
|
|
|
|
Stacks.ReturnKernelStackSegment();
|
|
|
|
}
|
|
|
|
|
|
|
|
[ExternalEntryPoint]
|
|
|
|
public static void StackOverflowImpl()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// This is called when a SIP has a stack overflow so
|
|
|
|
// that it can fail fast.
|
|
|
|
//
|
|
|
|
|
|
|
|
Stacks.StackOverflowForSIP();
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|