From 8c7165193f164422429f2bf6a9136a8b7bf2c92a Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 22 Jul 2022 07:06:02 -0700 Subject: [PATCH] Delete ConservativelyReportedRegion and CallingConventionConverterHelpers (#72659) --- .../src/System/Runtime/RuntimeExports.cs | 62 --------- src/coreclr/nativeaot/Runtime/CMakeLists.txt | 1 - .../amd64/CallingConventionConverterHelpers.S | 57 -------- .../amd64/CallingConventionConverterHelpers.asm | 85 ------------ .../arm/CallingConventionConverterHelpers.S | 65 --------- .../arm/CallingConventionConverterHelpers.asm | 88 ------------ .../arm64/CallingConventionConverterHelpers.S | 61 --------- .../arm64/CallingConventionConverterHelpers.asm | 63 --------- src/coreclr/nativeaot/Runtime/gcrhenv.cpp | 150 --------------------- .../i386/CallingConventionConverterHelpers.S | 4 - .../i386/CallingConventionConverterHelpers.asm | 126 ----------------- src/coreclr/nativeaot/Runtime/portable.cpp | 9 -- .../Internal/Runtime/Augments/RuntimeAugments.cs | 92 ------------- .../src/System/Runtime/RuntimeImports.cs | 28 ---- 14 files changed, 891 deletions(-) delete mode 100644 src/coreclr/nativeaot/Runtime/amd64/CallingConventionConverterHelpers.S delete mode 100644 src/coreclr/nativeaot/Runtime/amd64/CallingConventionConverterHelpers.asm delete mode 100644 src/coreclr/nativeaot/Runtime/arm/CallingConventionConverterHelpers.S delete mode 100644 src/coreclr/nativeaot/Runtime/arm/CallingConventionConverterHelpers.asm delete mode 100644 src/coreclr/nativeaot/Runtime/arm64/CallingConventionConverterHelpers.S delete mode 100644 src/coreclr/nativeaot/Runtime/arm64/CallingConventionConverterHelpers.asm delete mode 100644 src/coreclr/nativeaot/Runtime/i386/CallingConventionConverterHelpers.S delete mode 100644 src/coreclr/nativeaot/Runtime/i386/CallingConventionConverterHelpers.asm diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs index b277d80..4a4ac45 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs @@ -345,68 +345,6 @@ namespace System.Runtime return success ? (int)nFrames : -(int)nFrames; } - // The GC conservative reporting descriptor is a special structure of data that the GC - // parses to determine whether there are specific regions of memory that it should not - // collect or move around. - // During garbage collection, the GC will inspect the data in this structure, and verify that: - // 1) _magic is set to the magic number (also hard coded on the GC side) - // 2) The reported region is valid (checks alignments, size, within bounds of the thread memory, etc...) - // 3) The ConservativelyReportedRegionDesc pointer must be reported by a frame which does not make a pinvoke transition. - // 4) The value of the _hash field is the computed hash of _regionPointerLow with _regionPointerHigh - // 5) The region must be IntPtr aligned, and have a size which is also IntPtr aligned - // If all conditions are satisfied, the region of memory starting at _regionPointerLow and ending at - // _regionPointerHigh will be conservatively reported. - // This can only be used to report memory regions on the current stack and the structure must itself - // be located on the stack. - public struct ConservativelyReportedRegionDesc - { - internal const ulong MagicNumber64 = 0x87DF7A104F09E0A9UL; - internal const uint MagicNumber32 = 0x4F09E0A9; - - internal UIntPtr _magic; - internal UIntPtr _regionPointerLow; - internal UIntPtr _regionPointerHigh; - internal UIntPtr _hash; - } - - [RuntimeExport("RhInitializeConservativeReportingRegion")] - public static unsafe void RhInitializeConservativeReportingRegion(ConservativelyReportedRegionDesc* regionDesc, void* bufferBegin, int cbBuffer) - { - Debug.Assert((((int)bufferBegin) & (sizeof(IntPtr) - 1)) == 0, "Buffer not IntPtr aligned"); - Debug.Assert((cbBuffer & (sizeof(IntPtr) - 1)) == 0, "Size of buffer not IntPtr aligned"); - - UIntPtr regionPointerLow = (UIntPtr)bufferBegin; - UIntPtr regionPointerHigh = (UIntPtr)(((byte*)bufferBegin) + cbBuffer); - - // Setup pointers to start and end of region - regionDesc->_regionPointerLow = regionPointerLow; - regionDesc->_regionPointerHigh = regionPointerHigh; - - // Activate the region for processing -#if TARGET_64BIT - ulong hash = ConservativelyReportedRegionDesc.MagicNumber64; - hash = ((hash << 13) ^ hash) ^ (ulong)regionPointerLow; - hash = ((hash << 13) ^ hash) ^ (ulong)regionPointerHigh; - - regionDesc->_hash = new UIntPtr(hash); - regionDesc->_magic = new UIntPtr(ConservativelyReportedRegionDesc.MagicNumber64); -#else - uint hash = ConservativelyReportedRegionDesc.MagicNumber32; - hash = ((hash << 13) ^ hash) ^ (uint)regionPointerLow; - hash = ((hash << 13) ^ hash) ^ (uint)regionPointerHigh; - - regionDesc->_hash = new UIntPtr(hash); - regionDesc->_magic = new UIntPtr(ConservativelyReportedRegionDesc.MagicNumber32); -#endif - } - - // Disable conservative reporting - [RuntimeExport("RhDisableConservativeReportingRegion")] - public static unsafe void RhDisableConservativeReportingRegion(ConservativelyReportedRegionDesc* regionDesc) - { - regionDesc->_magic = default(UIntPtr); - } - [RuntimeExport("RhCreateThunksHeap")] public static object RhCreateThunksHeap(IntPtr commonStubAddress) { diff --git a/src/coreclr/nativeaot/Runtime/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/CMakeLists.txt index 65308e7..7feb64d 100644 --- a/src/coreclr/nativeaot/Runtime/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/CMakeLists.txt @@ -189,7 +189,6 @@ endif (CLR_CMAKE_TARGET_ARCH_AMD64 AND CLR_CMAKE_TARGET_WIN32) list(APPEND RUNTIME_SOURCES_ARCH_ASM ${ARCH_SOURCES_DIR}/AllocFast.${ASM_SUFFIX} ${ARCH_SOURCES_DIR}/CallDescrWorker.${ASM_SUFFIX} - ${ARCH_SOURCES_DIR}/CallingConventionConverterHelpers.${ASM_SUFFIX} ${ARCH_SOURCES_DIR}/ExceptionHandling.${ASM_SUFFIX} ${ARCH_SOURCES_DIR}/GcProbe.${ASM_SUFFIX} ${ARCH_SOURCES_DIR}/Interlocked.${ASM_SUFFIX} diff --git a/src/coreclr/nativeaot/Runtime/amd64/CallingConventionConverterHelpers.S b/src/coreclr/nativeaot/Runtime/amd64/CallingConventionConverterHelpers.S deleted file mode 100644 index 6ce126a..0000000 --- a/src/coreclr/nativeaot/Runtime/amd64/CallingConventionConverterHelpers.S +++ /dev/null @@ -1,57 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -.intel_syntax noprefix -#include - -// -// void CallingConventionConverter_ReturnVoidReturnThunk() -// -LEAF_ENTRY CallingConventionConverter_ReturnVoidReturnThunk, _TEXT - ret -LEAF_END CallingConventionConverter_ReturnVoidReturnThunk, _TEXT - -// -// int CallingConventionConverter_ReturnIntegerReturnThunk(int) -// -LEAF_ENTRY CallingConventionConverter_ReturnIntegerReturnThunk, _TEXT - // UNIXTODO: Implement this function - int 3 -LEAF_END CallingConventionConverter_ReturnIntegerReturnThunk, _TEXT - -// -// Note: The "__jmpstub__" prefix is used to indicate to debugger -// that it must step-through this stub when it encounters it while -// stepping. -// - -// __jmpstub__CallingConventionConverter_CommonCallingStub -// -// -// struct CallingConventionConverter_CommonCallingStub_PointerData -// { -// void *ManagedCallConverterThunk; -// void *UniversalThunk; -// } -// -// struct CommonCallingStubInputData -// { -// ULONG_PTR CallingConventionId; -// CallingConventionConverter_CommonCallingStub_PointerData *commonData; -// } -// -// r10 - Points at CommonCallingStubInputData -// -// -LEAF_ENTRY __jmpstub__CallingConventionConverter_CommonCallingStub, _TEXT - // UNIXTODO: Implement this function - int 3 -LEAF_END __jmpstub__CallingConventionConverter_CommonCallingStub, _TEXT - -// -// void CallingConventionConverter_GetStubs(IntPtr *returnVoidStub, IntPtr *returnIntegerStub, IntPtr *commonStub) -// -LEAF_ENTRY CallingConventionConverter_GetStubs, _TEXT - // UNIXTODO: Implement this function - int 3 -LEAF_END CallingConventionConverter_GetStubs, _TEXT diff --git a/src/coreclr/nativeaot/Runtime/amd64/CallingConventionConverterHelpers.asm b/src/coreclr/nativeaot/Runtime/amd64/CallingConventionConverterHelpers.asm deleted file mode 100644 index b4525cb..0000000 --- a/src/coreclr/nativeaot/Runtime/amd64/CallingConventionConverterHelpers.asm +++ /dev/null @@ -1,85 +0,0 @@ -;; Licensed to the .NET Foundation under one or more agreements. -;; The .NET Foundation licenses this file to you under the MIT license. - -;; ----------------------------------------------------------------------------------------------------------- -;; #include "asmmacros.inc" -;; ----------------------------------------------------------------------------------------------------------- - -LEAF_ENTRY macro Name, Section - Section segment para 'CODE' - align 16 - public Name - Name proc -endm - -LEAF_END macro Name, Section - Name endp - Section ends -endm - -; - TAILCALL_RAX: ("jmp rax") should be used for tailcalls, this emits an instruction -; sequence which is recognized by the unwinder as a valid epilogue terminator -TAILJMP_RAX TEXTEQU -POINTER_SIZE equ 08h - -;; -;; void CallingConventionConverter_ReturnVoidReturnThunk() -;; -LEAF_ENTRY CallingConventionConverter_ReturnVoidReturnThunk, _TEXT - ret -LEAF_END CallingConventionConverter_ReturnVoidReturnThunk, _TEXT - -;; -;; int CallingConventionConverter_ReturnIntegerReturnThunk(int) -;; -LEAF_ENTRY CallingConventionConverter_ReturnIntegerReturnThunk, _TEXT - mov rax, rcx - ret -LEAF_END CallingConventionConverter_ReturnIntegerReturnThunk, _TEXT - -;; -;; Note: The "__jmpstub__" prefix is used to indicate to debugger -;; that it must step-through this stub when it encounters it while -;; stepping. -;; - -;; __jmpstub__CallingConventionConverter_CommonCallingStub -;; -;; -;; struct CallingConventionConverter_CommonCallingStub_PointerData -;; { -;; void *ManagedCallConverterThunk; -;; void *UniversalThunk; -;; } -;; -;; struct CommonCallingStubInputData -;; { -;; ULONG_PTR CallingConventionId; -;; CallingConventionConverter_CommonCallingStub_PointerData *commonData; -;; } -;; -;; r10 - Points at CommonCallingStubInputData -;; -;; -LEAF_ENTRY __jmpstub__CallingConventionConverter_CommonCallingStub, _TEXT - mov r11, [r10] ; put CallingConventionId into r11 as "parameter" to universal transition thunk - mov r10, [r10 + POINTER_SIZE] ; get pointer to CallingConventionConverter_CommonCallingStub_PointerData into r10 - mov rax, [r10 + POINTER_SIZE] ; get address of UniversalTransitionThunk - mov r10, [r10] ; get address of ManagedCallConverterThunk - TAILJMP_RAX -LEAF_END __jmpstub__CallingConventionConverter_CommonCallingStub, _TEXT - -;; -;; void CallingConventionConverter_GetStubs(IntPtr *returnVoidStub, IntPtr *returnIntegerStub, IntPtr *commonStub) -;; -LEAF_ENTRY CallingConventionConverter_GetStubs, _TEXT - lea rax, [CallingConventionConverter_ReturnVoidReturnThunk] - mov [rcx], rax - lea rax, [CallingConventionConverter_ReturnIntegerReturnThunk] - mov [rdx], rax - lea rax, [__jmpstub__CallingConventionConverter_CommonCallingStub] - mov [r8], rax - ret -LEAF_END CallingConventionConverter_GetStubs, _TEXT - -end diff --git a/src/coreclr/nativeaot/Runtime/arm/CallingConventionConverterHelpers.S b/src/coreclr/nativeaot/Runtime/arm/CallingConventionConverterHelpers.S deleted file mode 100644 index 3e21660..0000000 --- a/src/coreclr/nativeaot/Runtime/arm/CallingConventionConverterHelpers.S +++ /dev/null @@ -1,65 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// TODO: Implement Arm support -.syntax unified -.thumb - -#include // generated by the build from AsmOffsets.cpp -#include - -// -// void CallingConventionConverter_ReturnVoidReturnThunk() -// -LEAF_ENTRY CallingConventionConverter_ReturnVoidReturnThunk, _TEXT - bx lr -LEAF_END CallingConventionConverter_ReturnVoidReturnThunk, _TEXT - -// -// int CallingConventionConverter_ReturnIntegerReturnThunk(int) -// -LEAF_ENTRY CallingConventionConverter_ReturnIntegerReturnThunk, _TEXT - // UNIXTODO: Implement this function - EMIT_BREAKPOINT -LEAF_END CallingConventionConverter_ReturnIntegerReturnThunk, _TEXT - -// -// __jmpstub__CallingConventionConverter_CommonCallingStub -// -// struct CallingConventionConverter_CommonCallingStub_PointerData -// { -// void *ManagedCallConverterThunk; -// void *UniversalThunk; -// } -// -// struct CommonCallingStubInputData -// { -// ULONG_PTR CallingConventionId; -// CallingConventionConverter_CommonCallingStub_PointerData *commonData; // Only the ManagedCallConverterThunk field is used -// // However, it is specified just like other platforms, so the behavior of the common -// // calling stub is easier to debug -// } -// -// sp-4 - Points at CommonCallingStubInputData -// -// -LEAF_ENTRY __jmpstub__CallingConventionConverter_CommonCallingStub - // UNIXTODO: Implement this function - EMIT_BREAKPOINT -LEAF_END __jmpstub__CallingConventionConverter_CommonCallingStub - -// -// void CallingConventionConverter_GetStubs(IntPtr *returnVoidStub, IntPtr *returnIntegerStub, IntPtr *commonCallingStub) -// -LEAF_ENTRY CallingConventionConverter_GetStubs, _TEXT - // UNIXTODO: Implement this function - EMIT_BREAKPOINT -LEAF_END CallingConventionConverter_GetStubs, _TEXT - -// -// void CallingConventionConverter_SpecifyCommonStubData(CallingConventionConverter_CommonCallingStub_PointerData *commonData); -// -LEAF_ENTRY CallingConventionConverter_SpecifyCommonStubData - // UNIXTODO: Implement this function - EMIT_BREAKPOINT -LEAF_END CallingConventionConverter_SpecifyCommonStubData diff --git a/src/coreclr/nativeaot/Runtime/arm/CallingConventionConverterHelpers.asm b/src/coreclr/nativeaot/Runtime/arm/CallingConventionConverterHelpers.asm deleted file mode 100644 index 6a65987..0000000 --- a/src/coreclr/nativeaot/Runtime/arm/CallingConventionConverterHelpers.asm +++ /dev/null @@ -1,88 +0,0 @@ -;; Licensed to the .NET Foundation under one or more agreements. -;; The .NET Foundation licenses this file to you under the MIT license. - -#include "kxarm.h" - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA SECTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - - DATAAREA -UniversalThunkPointer % 4 - TEXTAREA - -OFFSETOF_CallingConventionId EQU 0 -OFFSETOF_commonData EQU 4 -OFFSETOF_ManagedCallConverterThunk EQU 0 -OFFSETOF_UniversalThunk EQU 4 - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CallingConventionCoverter Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; -;; Note: The "__jmpstub__" prefix is used to indicate to debugger -;; that it must step-through this stub when it encounters it while -;; stepping. -;; - - ;; - ;; void CallingConventionConverter_ReturnThunk() - ;; - LEAF_ENTRY CallingConventionConverter_ReturnThunk - bx lr - LEAF_END CallingConventionConverter_ReturnThunk - - ;; - ;; __jmpstub__CallingConventionConverter_CommonCallingStub - ;; - ;; struct CallingConventionConverter_CommonCallingStub_PointerData - ;; { - ;; void *ManagedCallConverterThunk; - ;; void *UniversalThunk; - ;; } - ;; - ;; struct CommonCallingStubInputData - ;; { - ;; ULONG_PTR CallingConventionId; - ;; CallingConventionConverter_CommonCallingStub_PointerData *commonData; // Only the ManagedCallConverterThunk field is used - ;; // However, it is specified just like other platforms, so the behavior of the common - ;; // calling stub is easier to debug - ;; } - ;; - ;; sp-4 - Points at CommonCallingStubInputData - ;; - ;; - LEAF_ENTRY __jmpstub__CallingConventionConverter_CommonCallingStub - ldr r12, [sp, #-4] - ldr r12, [r12, #OFFSETOF_CallingConventionId] ; Get CallingConventionId into r12 - str r12, [sp, #-8] ; Put calling convention id into red zone - ldr r12, [sp, #-4] - ldr r12, [r12, #OFFSETOF_commonData] ; Get pointer to common data - ldr r12, [r12, #OFFSETOF_ManagedCallConverterThunk] ; Get pointer to managed call converter thunk - str r12, [sp, #-4] ; Put managed calling convention thunk pointer into red zone (overwrites pointer to CommonCallingStubInputData) - ldr r12, =UniversalThunkPointer - ldr r12, [r12] - bx r12 - LEAF_END __jmpstub__CallingConventionConverter_CommonCallingStub - - ;; - ;; void CallingConventionConverter_SpecifyCommonStubData(CallingConventionConverter_CommonCallingStub_PointerData *commonData); - ;; - LEAF_ENTRY CallingConventionConverter_SpecifyCommonStubData - ldr r1, [r0, #OFFSETOF_ManagedCallConverterThunk] ; Load ManagedCallConverterThunk into r1 {r1 = (CallingConventionConverter_CommonCallingStub_PointerData*)r0->ManagedCallConverterThunk } - ldr r2, [r0, #OFFSETOF_UniversalThunk] ; Load UniversalThunk into r2 {r2 = (CallingConventionConverter_CommonCallingStub_PointerData*)r0->UniversalThunk } - ldr r12, =UniversalThunkPointer - str r2, [r12] - bx lr - LEAF_END CallingConventionConverter_SpecifyCommonStubData - - ;; - ;; void CallingConventionConverter_GetStubs(IntPtr *returnVoidStub, IntPtr *returnIntegerStub, IntPtr *commonCallingStub) - ;; - LEAF_ENTRY CallingConventionConverter_GetStubs - ldr r12, =CallingConventionConverter_ReturnThunk - str r12, [r0] ;; ARM doesn't need different return thunks. - str r12, [r1] - ldr r12, =__jmpstub__CallingConventionConverter_CommonCallingStub - str r12, [r2] - bx lr - LEAF_END CallingConventionConverter_GetStubs - - END diff --git a/src/coreclr/nativeaot/Runtime/arm64/CallingConventionConverterHelpers.S b/src/coreclr/nativeaot/Runtime/arm64/CallingConventionConverterHelpers.S deleted file mode 100644 index 67cd6fd..0000000 --- a/src/coreclr/nativeaot/Runtime/arm64/CallingConventionConverterHelpers.S +++ /dev/null @@ -1,61 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include -#include "AsmOffsets.inc" - -//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CallingConventionCoverter Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -POINTER_SIZE = 0x08 - -// Note: The "__jmpstub__" prefix is used to indicate to debugger -// that it must step-through this stub when it encounters it while -// stepping. - - - // - // void CallingConventionConverter_ReturnThunk() - // - LEAF_ENTRY CallingConventionConverter_ReturnThunk, _TEXT - ret - LEAF_END CallingConventionConverter_ReturnThunk, _TEXT - - // - // __jmpstub__CallingConventionConverter_CommonCallingStub - // - // struct CallingConventionConverter_CommonCallingStub_PointerData - // { - // void *ManagedCallConverterThunk; - // void *UniversalThunk; - // } - // - // struct CommonCallingStubInputData - // { - // ULONG_PTR CallingConventionId; - // CallingConventionConverter_CommonCallingStub_PointerData *commonData; // Only the ManagedCallConverterThunk field is used - // // However, it is specified just like other platforms, so the behavior of the common - // // calling stub is easier to debug - // } - // - // xip0 - Points at CommonCallingStubInputData - // - // - LEAF_ENTRY __jmpstub__CallingConventionConverter_CommonCallingStub, _TEXT - ldr xip1, [xip0] // put CallingConventionId into xip1 as "parameter" to universal transition thunk - ldr xip0, [xip0, #POINTER_SIZE] // get pointer to CallingConventionConverter_CommonCallingStub_PointerData into xip0 - ldr x12, [xip0, #POINTER_SIZE] // get address of UniversalTransitionThunk (which we'll tailcall to later) - ldr xip0, [xip0] // get address of ManagedCallConverterThunk (target for universal thunk to call) - br x12 - LEAF_END __jmpstub__CallingConventionConverter_CommonCallingStub, _TEXT - - // - // void CallingConventionConverter_GetStubs(IntPtr *returnVoidStub, IntPtr *returnIntegerStub, IntPtr *commonCallingStub) - // - LEAF_ENTRY CallingConventionConverter_GetStubs, _TEXT - PREPARE_EXTERNAL_VAR CallingConventionConverter_ReturnThunk, x12 - str x12, [x0] // ARM doesn't need different return thunks. - str x12, [x1] - PREPARE_EXTERNAL_VAR __jmpstub__CallingConventionConverter_CommonCallingStub, x12 - str x12, [x2] - ret - LEAF_END CallingConventionConverter_GetStubs, _TEXT diff --git a/src/coreclr/nativeaot/Runtime/arm64/CallingConventionConverterHelpers.asm b/src/coreclr/nativeaot/Runtime/arm64/CallingConventionConverterHelpers.asm deleted file mode 100644 index 0d6ea3e..0000000 --- a/src/coreclr/nativeaot/Runtime/arm64/CallingConventionConverterHelpers.asm +++ /dev/null @@ -1,63 +0,0 @@ -;; Licensed to the .NET Foundation under one or more agreements. -;; The .NET Foundation licenses this file to you under the MIT license. - -#include "ksarm64.h" - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CallingConventionCoverter Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -POINTER_SIZE equ 0x08 - -;; -;; Note: The "__jmpstub__" prefix is used to indicate to debugger -;; that it must step-through this stub when it encounters it while -;; stepping. -;; - - ;; - ;; void CallingConventionConverter_ReturnThunk() - ;; - LEAF_ENTRY CallingConventionConverter_ReturnThunk - ret - LEAF_END CallingConventionConverter_ReturnThunk - - ;; - ;; __jmpstub__CallingConventionConverter_CommonCallingStub - ;; - ;; struct CallingConventionConverter_CommonCallingStub_PointerData - ;; { - ;; void *ManagedCallConverterThunk; - ;; void *UniversalThunk; - ;; } - ;; - ;; struct CommonCallingStubInputData - ;; { - ;; ULONG_PTR CallingConventionId; - ;; CallingConventionConverter_CommonCallingStub_PointerData *commonData; // Only the ManagedCallConverterThunk field is used - ;; // However, it is specified just like other platforms, so the behavior of the common - ;; // calling stub is easier to debug - ;; } - ;; - ;; xip0 - Points at CommonCallingStubInputData - ;; - ;; - LEAF_ENTRY __jmpstub__CallingConventionConverter_CommonCallingStub - ldr xip1, [xip0] ; put CallingConventionId into xip1 as "parameter" to universal transition thunk - ldr xip0, [xip0, #POINTER_SIZE] ; get pointer to CallingConventionConverter_CommonCallingStub_PointerData into xip0 - ldr x12, [xip0, #POINTER_SIZE] ; get address of UniversalTransitionThunk (which we'll tailcall to later) - ldr xip0, [xip0] ; get address of ManagedCallConverterThunk (target for universal thunk to call) - br x12 - LEAF_END __jmpstub__CallingConventionConverter_CommonCallingStub - - ;; - ;; void CallingConventionConverter_GetStubs(IntPtr *returnVoidStub, IntPtr *returnIntegerStub, IntPtr *commonCallingStub) - ;; - LEAF_ENTRY CallingConventionConverter_GetStubs - ldr x12, =CallingConventionConverter_ReturnThunk - str x12, [x0] ;; ARM doesn't need different return thunks. - str x12, [x1] - ldr x12, =__jmpstub__CallingConventionConverter_CommonCallingStub - str x12, [x2] - ret - LEAF_END CallingConventionConverter_GetStubs - - END diff --git a/src/coreclr/nativeaot/Runtime/gcrhenv.cpp b/src/coreclr/nativeaot/Runtime/gcrhenv.cpp index 85f82f0..f3d3010 100644 --- a/src/coreclr/nativeaot/Runtime/gcrhenv.cpp +++ b/src/coreclr/nativeaot/Runtime/gcrhenv.cpp @@ -352,161 +352,11 @@ struct EnumGcRefContext : GCEnumContext EnumGcRefScanContext * sc; }; -bool IsOnReadablePortionOfThread(EnumGcRefScanContext * pSc, PTR_VOID pointer) -{ - if (!pSc->thread_under_crawl->IsWithinStackBounds(pointer)) - { - return false; - } - - // If the stack_limit is 0, then it wasn't set properly, and the check below will not - // operate correctly. - ASSERT(pSc->stack_limit != 0); - - // This ensures that the pointer is not in a currently-unused portion of the stack - // because the above check is only verifying against the entire stack bounds, - // but stack_limit is describing the current bound of the stack - if (PTR_TO_TADDR(pointer) < pSc->stack_limit) - { - return false; - } - return true; -} - -#ifdef HOST_64BIT -#define CONSERVATIVE_REGION_MAGIC_NUMBER 0x87DF7A104F09E0A9ULL -#else -#define CONSERVATIVE_REGION_MAGIC_NUMBER 0x4F09E0A9 -#endif - -// This is a structure that is created by executing runtime code in order to report a conservative -// region. In managed code if there is a pinned byref pointer to one of this (with the appropriate -// magic number set in it, and a hash that matches up) then the region from regionPointerLow to -// regionPointerHigh will be reported conservatively. This can only be used to report memory regions -// on the current stack and the structure must itself be located on the stack. -struct ConservativelyReportedRegionDesc -{ - // If this is really a ConservativelyReportedRegionDesc then the magic value will be - // CONSERVATIVE_REGION_MAGIC_NUMBER, and the hash will be the result of CalculateHash - // across magic, regionPointerLow, and regionPointerHigh - uintptr_t magic; - PTR_VOID regionPointerLow; - PTR_VOID regionPointerHigh; - uintptr_t hash; - - static uintptr_t CalculateHash(uintptr_t h1, uintptr_t h2, uintptr_t h3) - { - uintptr_t hash = h1; - hash = ((hash << 13) ^ hash) ^ h2; - hash = ((hash << 13) ^ hash) ^ h3; - return hash; - } -}; - -typedef DPTR(ConservativelyReportedRegionDesc) PTR_ConservativelyReportedRegionDesc; - -bool IsPtrAligned(TADDR value) -{ - return (value & (POINTER_SIZE - 1)) == 0; -} - -// Logic to actually conservatively report a ConservativelyReportedRegionDesc -// This logic is to be used when attempting to promote a pinned, interior pointer. -// It will attempt to heuristically identify ConservativelyReportedRegionDesc structures -// and if they exist, it will conservatively report a memory region. -static void ReportExplicitConservativeReportedRegionIfValid(EnumGcRefContext * pCtx, PTR_PTR_VOID pObject) -{ - // If the stack_limit isn't set (which can only happen for frames which make a p/invoke call - // there cannot be a ConservativelyReportedRegionDesc - if (pCtx->sc->stack_limit == 0) - return; - - PTR_ConservativelyReportedRegionDesc conservativeRegionDesc = (PTR_ConservativelyReportedRegionDesc)(*pObject); - - // Ensure that conservativeRegionDesc pointer points at a readable memory region - if (!IsPtrAligned(PTR_TO_TADDR(conservativeRegionDesc))) - { - return; - } - - if (!IsOnReadablePortionOfThread(pCtx->sc, conservativeRegionDesc)) - { - return; - } - if (!IsOnReadablePortionOfThread(pCtx->sc, conservativeRegionDesc + 1)) - { - return; - } - - // Now, check to see if what we're pointing at is actually a ConservativeRegionDesc - // First: check the magic number. If that doesn't match, it cannot be one - if (conservativeRegionDesc->magic != CONSERVATIVE_REGION_MAGIC_NUMBER) - { - return; - } - - // Second: check to see that the region pointers point at memory which is aligned - // such that the pointers could be pointers to object references - if (!IsPtrAligned(PTR_TO_TADDR(conservativeRegionDesc->regionPointerLow))) - { - return; - } - if (!IsPtrAligned(PTR_TO_TADDR(conservativeRegionDesc->regionPointerHigh))) - { - return; - } - - // Third: check that start is before end. - if (conservativeRegionDesc->regionPointerLow >= conservativeRegionDesc->regionPointerHigh) - { - return; - } - -#ifndef DACCESS_COMPILE - // This fails for cross-bitness dac compiles and isn't really needed in the DAC anyways. - - // Fourth: Compute a hash of the above numbers. Check to see that the hash matches the hash - // value stored - if (ConservativelyReportedRegionDesc::CalculateHash(CONSERVATIVE_REGION_MAGIC_NUMBER, - (uintptr_t)PTR_TO_TADDR(conservativeRegionDesc->regionPointerLow), - (uintptr_t)PTR_TO_TADDR(conservativeRegionDesc->regionPointerHigh)) - != conservativeRegionDesc->hash) - { - return; - } -#endif // DACCESS_COMPILE - - // Fifth: Check to see that the region pointed at is within the bounds of the thread - if (!IsOnReadablePortionOfThread(pCtx->sc, conservativeRegionDesc->regionPointerLow)) - { - return; - } - if (!IsOnReadablePortionOfThread(pCtx->sc, ((PTR_OBJECTREF)conservativeRegionDesc->regionPointerHigh) - 1)) - { - return; - } - - // At this point we're most likely working with a ConservativeRegionDesc. We'll assume - // that's true, and perform conservative reporting. (We've done enough checks to ensure that - // this conservative reporting won't itself cause an AV, even if our heuristics are wrong - // with the second and fifth set of checks) - GcEnumObjectsConservatively((PTR_OBJECTREF)conservativeRegionDesc->regionPointerLow, (PTR_OBJECTREF)conservativeRegionDesc->regionPointerHigh, pCtx->f, pCtx->sc); -} - static void EnumGcRefsCallback(void * hCallback, PTR_PTR_VOID pObject, uint32_t flags) { EnumGcRefContext * pCtx = (EnumGcRefContext *)hCallback; GcEnumObject((PTR_OBJECTREF)pObject, flags, pCtx->f, pCtx->sc); - - const uint32_t interiorPinned = GC_CALL_INTERIOR | GC_CALL_PINNED; - // If this is an interior pinned pointer, check to see if we're working with a ConservativeRegionDesc - // and if so, report a conservative region. NOTE: do this only during promotion as conservative - // reporting has no value during other GC phases. - if (((flags & interiorPinned) == interiorPinned) && (pCtx->sc->promotion)) - { - ReportExplicitConservativeReportedRegionIfValid(pCtx, pObject); - } } // static diff --git a/src/coreclr/nativeaot/Runtime/i386/CallingConventionConverterHelpers.S b/src/coreclr/nativeaot/Runtime/i386/CallingConventionConverterHelpers.S deleted file mode 100644 index 876f2df..0000000 --- a/src/coreclr/nativeaot/Runtime/i386/CallingConventionConverterHelpers.S +++ /dev/null @@ -1,4 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// TODO: Implement diff --git a/src/coreclr/nativeaot/Runtime/i386/CallingConventionConverterHelpers.asm b/src/coreclr/nativeaot/Runtime/i386/CallingConventionConverterHelpers.asm deleted file mode 100644 index bd46406..0000000 --- a/src/coreclr/nativeaot/Runtime/i386/CallingConventionConverterHelpers.asm +++ /dev/null @@ -1,126 +0,0 @@ -;; Licensed to the .NET Foundation under one or more agreements. -;; The .NET Foundation licenses this file to you under the MIT license. - -.586 -.model flat -option casemap:none -.code - -;; ----------------------------------------------------------------------------------------------------------- -;; standard macros -;; ----------------------------------------------------------------------------------------------------------- -LEAF_ENTRY macro Name, Section - Section segment para 'CODE' - public Name - Name proc -endm - -LEAF_END macro Name, Section - Name endp - Section ends -endm - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA SECTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; -;; struct ReturnBlock -;; { -;; 8 bytes of space -;; Used to hold return information. -;; eax, and 32bit float returns use the first 4 bytes, -;; eax,edx and 64bit float returns use the full 8 bytes -;; }; -;; - -ReturnInformation__ReturnData EQU 4h - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interop Thunks Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; ? CallingConventionConverter_ReturnVoidReturnThunk(int cbBytesOfStackToPop) -;; -LEAF_ENTRY CallingConventionConverter_ReturnVoidReturnThunk, _TEXT - pop edx ; pop return address into edx - add esp,ecx ; remove ecx bytes from the call stack - push edx ; put the return address back on the stack - ret ; return to it (use a push/ret pair here so that the return stack buffer still works) -LEAF_END CallingConventionConverter_ReturnVoidReturnThunk, _TEXT - -;; -;; int CallingConventionConverter_ReturnIntegerReturnThunk(int cbBytesOfStackToPop, ReturnBlock*) -;; -LEAF_ENTRY CallingConventionConverter_ReturnIntegerReturnThunk, _TEXT - pop eax ; pop return address into edx - add esp,ecx ; remove ecx bytes from the call stack - push eax ; put the return address back on the stack - mov eax, [edx] ; setup eax and edx to hold the return value - mov edx, [edx + 4] - ret ; return (use a push/ret pair here so that the return stack buffer still works) -LEAF_END CallingConventionConverter_ReturnIntegerReturnThunk, _TEXT - -;; -;; float CallingConventionConverter_Return4ByteFloatReturnThunk(int cbBytesOfStackToPop, ReturnBlock*) -;; -LEAF_ENTRY CallingConventionConverter_Return4ByteFloatReturnThunk, _TEXT - pop eax ; pop return address into edx - add esp,ecx ; remove ecx bytes from the call stack - push eax ; put the return address back on the stack - fld dword ptr [edx]; fill in the return value - ret ; return (use a push/ret pair here so that the return stack buffer still works) -LEAF_END CallingConventionConverter_Return4ByteFloatReturnThunk, _TEXT - -;; -;; double CallingConventionConverter_Return4ByteFloatReturnThunk(int cbBytesOfStackToPop, ReturnBlock*) -;; -LEAF_ENTRY CallingConventionConverter_Return8ByteFloatReturnThunk, _TEXT - pop eax ; pop return address into edx - add esp,ecx ; remove ecx bytes from the call stack - push eax ; put the return address back on the stack - fld qword ptr [edx]; fill in the return value - ret ; return (use a push/ret pair here so that the return stack buffer still works) -LEAF_END CallingConventionConverter_Return8ByteFloatReturnThunk, _TEXT - -;; -;; Note: The "__jmpstub__" prefix is used to indicate to debugger -;; that it must step-through this stub when it encounters it while -;; stepping. -;; - -;; -;; __jmpstub__CallingConventionConverter_CommonCallingStub(?) -;; -LEAF_ENTRY __jmpstub__CallingConventionConverter_CommonCallingStub, _TEXT - ;; rax <- stub info - push ebp - mov ebp, esp - push [eax] ; First argument - mov eax,[eax+4] ; - push [eax] ; Pointer to CallingConventionConverter Managed thunk - mov eax,[eax+4] ; Pointer to UniversalTransitionThunk - jmp eax -LEAF_END __jmpstub__CallingConventionConverter_CommonCallingStub, _TEXT - - ;; - ;; void CallingConventionConverter_GetStubs(IntPtr *returnVoidStub, IntPtr *returnIntegerStub, IntPtr* commonCallingStub, IntPtr *return4ByteFloat, IntPtr *return8ByteFloat) - ;; -LEAF_ENTRY CallingConventionConverter_GetStubs, _TEXT - lea eax, [CallingConventionConverter_ReturnVoidReturnThunk] - mov ecx, [esp+04h] - mov [ecx], eax - lea eax, [CallingConventionConverter_ReturnIntegerReturnThunk] - mov ecx, [esp+08h] - mov [ecx], eax - lea eax, [__jmpstub__CallingConventionConverter_CommonCallingStub] - mov ecx, [esp+0Ch] - mov [ecx], eax - lea eax, [CallingConventionConverter_Return4ByteFloatReturnThunk] - mov ecx, [esp+10h] - mov [ecx], eax - lea eax, [CallingConventionConverter_Return8ByteFloatReturnThunk] - mov ecx, [esp+14h] - mov [ecx], eax - retn 14h -LEAF_END CallingConventionConverter_GetStubs, _TEXT - - -end diff --git a/src/coreclr/nativeaot/Runtime/portable.cpp b/src/coreclr/nativeaot/Runtime/portable.cpp index af11b2a..4d4db03 100644 --- a/src/coreclr/nativeaot/Runtime/portable.cpp +++ b/src/coreclr/nativeaot/Runtime/portable.cpp @@ -535,15 +535,6 @@ COOP_PINVOKE_HELPER(void, RhCallDescrWorker, (void * callDescr)) ASSERT_UNCONDITIONALLY("NYI"); } -#ifdef CALLDESCR_FPARGREGSARERETURNREGS -COOP_PINVOKE_HELPER(void, CallingConventionConverter_GetStubs, (uintptr_t* pReturnVoidStub, uintptr_t* pReturnIntegerStub, uintptr_t* pCommonStub)) -#else -COOP_PINVOKE_HELPER(void, CallingConventionConverter_GetStubs, (uintptr_t* pReturnVoidStub, uintptr_t* pReturnIntegerStub, uintptr_t* pCommonStub, uintptr_t* pReturnFloatingPointReturn4Thunk, uintptr_t* pReturnFloatingPointReturn8Thunk)) -#endif -{ - ASSERT_UNCONDITIONALLY("NYI"); -} - COOP_PINVOKE_HELPER(void *, RhGetCommonStubAddress, ()) { ASSERT_UNCONDITIONALLY("NYI"); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs index b089a30..14aa9b6 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs @@ -934,98 +934,6 @@ namespace Internal.Runtime.Augments return Delegate.CreateObjectArrayDelegate(delegateType, invoker); } - internal static class RawCalliHelper - { - [DebuggerHidden] - [DebuggerStepThrough] - [MethodImplAttribute(MethodImplOptions.AggressiveInlining)] - public static unsafe void Call(System.IntPtr pfn, void* arg1, ref T arg2) - => ((delegate*)pfn)(arg1, ref arg2); - - [DebuggerHidden] - [DebuggerStepThrough] - [MethodImplAttribute(MethodImplOptions.AggressiveInlining)] - public static unsafe void Call(System.IntPtr pfn, void* arg1, ref T arg2, ref U arg3) - => ((delegate*)pfn)(arg1, ref arg2, ref arg3); - } - - /// - /// This method creates a conservatively reported region and calls a function - /// while that region is conservatively reported. - /// - /// size of buffer to allocated (buffer size described in bytes) - /// function pointer to execute. - /// context to pass to inner function. Passed by-ref to allow for efficient use of a struct as a context. - [DebuggerGuidedStepThroughAttribute] - [CLSCompliant(false)] - public static unsafe void RunFunctionWithConservativelyReportedBuffer(int cbBuffer, delegate* pfnTargetToInvoke, ref T context) - { - RuntimeImports.ConservativelyReportedRegionDesc regionDesc = default; - RunFunctionWithConservativelyReportedBufferInternal(cbBuffer, pfnTargetToInvoke, ref context, ref regionDesc); - System.Diagnostics.DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); - } - - // Marked as no-inlining so optimizer won't decide to optimize away the fact that pRegionDesc is a pinned interior pointer. - // This function must also not make a p/invoke transition, or the fixed statement reporting of the ConservativelyReportedRegionDesc - // will be ignored. - [DebuggerGuidedStepThroughAttribute] - [MethodImpl(MethodImplOptions.NoInlining)] - private static unsafe void RunFunctionWithConservativelyReportedBufferInternal(int cbBuffer, delegate* pfnTargetToInvoke, ref T context, ref RuntimeImports.ConservativelyReportedRegionDesc regionDesc) - { - fixed (RuntimeImports.ConservativelyReportedRegionDesc* pRegionDesc = ®ionDesc) - { - int cbBufferAligned = (cbBuffer + (sizeof(IntPtr) - 1)) & ~(sizeof(IntPtr) - 1); - // The conservative region must be IntPtr aligned, and a multiple of IntPtr in size - void* region = stackalloc IntPtr[cbBufferAligned / sizeof(IntPtr)]; - NativeMemory.Clear(region, (nuint)cbBufferAligned); - RuntimeImports.RhInitializeConservativeReportingRegion(pRegionDesc, region, cbBufferAligned); - - RawCalliHelper.Call((IntPtr)pfnTargetToInvoke, region, ref context); - System.Diagnostics.DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); - - RuntimeImports.RhDisableConservativeReportingRegion(pRegionDesc); - } - } - - /// - /// This method creates a conservatively reported region and calls a function - /// while that region is conservatively reported. - /// - /// size of buffer to allocated (buffer size described in bytes) - /// function pointer to execute. - /// context to pass to inner function. Passed by-ref to allow for efficient use of a struct as a context. - /// context2 to pass to inner function. Passed by-ref to allow for efficient use of a struct as a context. - [DebuggerGuidedStepThroughAttribute] - [CLSCompliant(false)] - public static unsafe void RunFunctionWithConservativelyReportedBuffer(int cbBuffer, delegate* pfnTargetToInvoke, ref T context, ref U context2) - { - RuntimeImports.ConservativelyReportedRegionDesc regionDesc = default; - RunFunctionWithConservativelyReportedBufferInternal(cbBuffer, pfnTargetToInvoke, ref context, ref context2, ref regionDesc); - System.Diagnostics.DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); - } - - // Marked as no-inlining so optimizer won't decide to optimize away the fact that pRegionDesc is a pinned interior pointer. - // This function must also not make a p/invoke transition, or the fixed statement reporting of the ConservativelyReportedRegionDesc - // will be ignored. - [DebuggerGuidedStepThroughAttribute] - [MethodImpl(MethodImplOptions.NoInlining)] - private static unsafe void RunFunctionWithConservativelyReportedBufferInternal(int cbBuffer, delegate* pfnTargetToInvoke, ref T context, ref U context2, ref RuntimeImports.ConservativelyReportedRegionDesc regionDesc) - { - fixed (RuntimeImports.ConservativelyReportedRegionDesc* pRegionDesc = ®ionDesc) - { - int cbBufferAligned = (cbBuffer + (sizeof(IntPtr) - 1)) & ~(sizeof(IntPtr) - 1); - // The conservative region must be IntPtr aligned, and a multiple of IntPtr in size - void* region = stackalloc IntPtr[cbBufferAligned / sizeof(IntPtr)]; - NativeMemory.Clear(region, (nuint)cbBufferAligned); - RuntimeImports.RhInitializeConservativeReportingRegion(pRegionDesc, region, cbBufferAligned); - - RawCalliHelper.Call((IntPtr)pfnTargetToInvoke, region, ref context, ref context2); - System.Diagnostics.DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); - - RuntimeImports.RhDisableConservativeReportingRegion(pRegionDesc); - } - } - public static string GetLastResortString(RuntimeTypeHandle typeHandle) { return typeHandle.LastResortToString; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index f349195..3b08ed7 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -645,34 +645,6 @@ namespace System.Runtime [RuntimeImport(RuntimeLibrary, "RhBulkMoveWithWriteBarrier")] internal static extern unsafe void RhBulkMoveWithWriteBarrier(ref byte dmem, ref byte smem, nuint size); - // The GC conservative reporting descriptor is a special structure of data that the GC - // parses to determine whether there are specific regions of memory that it should not - // collect or move around. - // This can only be used to report memory regions on the current stack and the structure must itself - // be located on the stack. - // This structure is contractually required to be 4 pointers in size. All details about - // the contents are abstracted into the runtime - // To use, place one of these structures on the stack, and then pass it by ref to a function - // which will pin the byref to create a pinned interior pointer. - // Then, call RhInitializeConservativeReportingRegion to mark the region as conservatively reported. - // When done, call RhDisableConservativeReportingRegion to disable conservative reporting, or - // simply let it be pulled off the stack. - internal struct ConservativelyReportedRegionDesc - { - private IntPtr _ptr1; - private IntPtr _ptr2; - private IntPtr _ptr3; - private IntPtr _ptr4; - } - - [MethodImplAttribute(MethodImplOptions.InternalCall)] - [RuntimeImport(RuntimeLibrary, "RhInitializeConservativeReportingRegion")] - internal static extern unsafe void RhInitializeConservativeReportingRegion(ConservativelyReportedRegionDesc* regionDesc, void* bufferBegin, int cbBuffer); - - [MethodImplAttribute(MethodImplOptions.InternalCall)] - [RuntimeImport(RuntimeLibrary, "RhDisableConservativeReportingRegion")] - internal static extern unsafe void RhDisableConservativeReportingRegion(ConservativelyReportedRegionDesc* regionDesc); - // // ETW helpers. // -- 2.7.4