Skip to content

Commit f1337d9

Browse files
shushanhfqiaopengcheng
and
qiaopengcheng
authored
[LoongArch64] add the coreclr/unwinder/loongarch64 from the #62979. (#63489)
* [LoongArch64] add the `coreclr/unwinder/loongarch64` from the #62979. * [LoongArch64] replace the `__in` with `_In_`. * [LoongArch64] update the version of the `LICENSE description`. * [LoongArch64] update the macro-define for crossgen2. * [LoongArch64] amend the comment notes. Co-authored-by: qiaopengcheng <[email protected]>
1 parent 135a960 commit f1337d9

File tree

4 files changed

+1592
-0
lines changed

4 files changed

+1592
-0
lines changed

src/coreclr/inc/clrnt.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,4 +1030,69 @@ RtlVirtualUnwind(
10301030

10311031
#endif
10321032

1033+
#ifdef TARGET_LOONGARCH64
1034+
#include "daccess.h"
1035+
1036+
#define UNW_FLAG_NHANDLER 0x0 /* any handler */
1037+
#define UNW_FLAG_EHANDLER 0x1 /* filter handler */
1038+
#define UNW_FLAG_UHANDLER 0x2 /* unwind handler */
1039+
1040+
// This function returns the RVA of the end of the function (exclusive, so one byte after the actual end)
1041+
// using the unwind info on LOONGARCH64. (see ExternalAPIs\Win9CoreSystem\inc\winnt.h)
1042+
FORCEINLINE
1043+
ULONG64
1044+
RtlpGetFunctionEndAddress (
1045+
_In_ PT_RUNTIME_FUNCTION FunctionEntry,
1046+
_In_ ULONG64 ImageBase
1047+
)
1048+
{
1049+
ULONG64 FunctionLength;
1050+
1051+
FunctionLength = FunctionEntry->UnwindData;
1052+
if ((FunctionLength & 3) != 0) {
1053+
FunctionLength = (FunctionLength >> 2) & 0x7ff;
1054+
} else {
1055+
memcpy(&FunctionLength, (void*)(ImageBase + FunctionLength), sizeof(UINT32));
1056+
FunctionLength &= 0x3ffff;
1057+
}
1058+
1059+
return FunctionEntry->BeginAddress + 4 * FunctionLength;
1060+
}
1061+
1062+
#define RUNTIME_FUNCTION__BeginAddress(FunctionEntry) ((FunctionEntry)->BeginAddress)
1063+
#define RUNTIME_FUNCTION__SetBeginAddress(FunctionEntry,address) ((FunctionEntry)->BeginAddress = (address))
1064+
1065+
#define RUNTIME_FUNCTION__EndAddress(FunctionEntry, ImageBase) (RtlpGetFunctionEndAddress(FunctionEntry, (ULONG64)(ImageBase)))
1066+
1067+
#define RUNTIME_FUNCTION__SetUnwindInfoAddress(prf,address) do { (prf)->UnwindData = (address); } while (0)
1068+
1069+
typedef struct _UNWIND_INFO {
1070+
// dummy
1071+
} UNWIND_INFO, *PUNWIND_INFO;
1072+
1073+
EXTERN_C
1074+
NTSYSAPI
1075+
PEXCEPTION_ROUTINE
1076+
NTAPI
1077+
RtlVirtualUnwind(
1078+
IN ULONG HandlerType,
1079+
IN ULONG64 ImageBase,
1080+
IN ULONG64 ControlPc,
1081+
IN PRUNTIME_FUNCTION FunctionEntry,
1082+
IN OUT PCONTEXT ContextRecord,
1083+
OUT PVOID *HandlerData,
1084+
OUT PULONG64 EstablisherFrame,
1085+
IN OUT PKNONVOLATILE_CONTEXT_POINTERS ContextPointers OPTIONAL
1086+
);
1087+
1088+
#ifndef IMAGE_REL_LOONGARCH64_PC
1089+
#define IMAGE_REL_LOONGARCH64_PC 0x0003
1090+
#endif
1091+
1092+
#ifndef IMAGE_REL_LOONGARCH64_JIR
1093+
#define IMAGE_REL_LOONGARCH64_JIR 0x0004
1094+
#endif
1095+
1096+
#endif // TARGET_LOONGARCH64
1097+
10331098
#endif // CLRNT_H_

src/coreclr/pal/inc/rt/ntimage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,12 @@ typedef IMAGE_RELOCATION UNALIGNED *PIMAGE_RELOCATION;
10251025
#define IMAGE_REL_IA64_GPREL32 0x001C
10261026
#define IMAGE_REL_IA64_ADDEND 0x001F
10271027

1028+
//
1029+
// LOONGARCH64 relocation types
1030+
//
1031+
#define IMAGE_REL_LOONGARCH64_PC 0x0003
1032+
#define IMAGE_REL_LOONGARCH64_JIR 0x0004
1033+
10281034
//
10291035
// CEF relocation types.
10301036
//

0 commit comments

Comments
 (0)