Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate hardcoded offsets to PROFILE_PLATFORM_SPECIFIC_DATA struct #91595

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions src/coreclr/vm/amd64/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,81 @@ ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForMethod == offsetof(CallCoun
#define CallCountingStubData__TargetForThresholdReached 0x10
ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForThresholdReached == offsetof(CallCountingStubData, TargetForThresholdReached))

#ifdef PROFILING_SUPPORTED
#define PROFILE_ENTER 0x1
#define PROFILE_LEAVE 0x2
#define PROFILE_TAILCALL 0x4

#define ASMCONSTANTS_C_ASSERT_OFFSET(type, field) \
ASMCONSTANTS_C_ASSERT(type##__##field == offsetof(type, field))

#if defined(UNIX_AMD64_ABI)
#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA__buffer 0x8*16
ASMCONSTANTS_C_ASSERT(SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA__buffer ==
sizeof((*(PROFILE_PLATFORM_SPECIFIC_DATA*)0).buffer))
#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 0x8*22 + SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA__buffer
#else
#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA__buffer 0
#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 0x8*12
#endif // UNIX_AMD64_ABI
ASMCONSTANT_SIZEOF_ASSERT(PROFILE_PLATFORM_SPECIFIC_DATA)

#define PROFILE_PLATFORM_SPECIFIC_DATA__functionId 0x0
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, functionId)
#define PROFILE_PLATFORM_SPECIFIC_DATA__rbp 0x8
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rbp)
#define PROFILE_PLATFORM_SPECIFIC_DATA__probeRsp 0x10
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, probeRsp)
#define PROFILE_PLATFORM_SPECIFIC_DATA__ip 0x18
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, ip)
#define PROFILE_PLATFORM_SPECIFIC_DATA__profiledRsp 0x20
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, profiledRsp)
#define PROFILE_PLATFORM_SPECIFIC_DATA__rax 0x28
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rax)
#define PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg 0x30
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, hiddenArg)
#define PROFILE_PLATFORM_SPECIFIC_DATA__flt0 0x38
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt0)
#define PROFILE_PLATFORM_SPECIFIC_DATA__flt1 0x40
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt1)
#define PROFILE_PLATFORM_SPECIFIC_DATA__flt2 0x48
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt2)
#define PROFILE_PLATFORM_SPECIFIC_DATA__flt3 0x50
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt3)
#if defined(UNIX_AMD64_ABI)
#define PROFILE_PLATFORM_SPECIFIC_DATA__flt4 0x58
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt4)
#define PROFILE_PLATFORM_SPECIFIC_DATA__flt5 0x60
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt5)
#define PROFILE_PLATFORM_SPECIFIC_DATA__flt6 0x68
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt6)
#define PROFILE_PLATFORM_SPECIFIC_DATA__flt7 0x70
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt7)
#define PROFILE_PLATFORM_SPECIFIC_DATA__rdi 0x78
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rdi)
#define PROFILE_PLATFORM_SPECIFIC_DATA__rsi 0x80
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rsi)
#define PROFILE_PLATFORM_SPECIFIC_DATA__rdx 0x88
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rdx)
#define PROFILE_PLATFORM_SPECIFIC_DATA__rcx 0x90
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rcx)
#define PROFILE_PLATFORM_SPECIFIC_DATA__r8 0x98
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, r8)
#define PROFILE_PLATFORM_SPECIFIC_DATA__r9 0xa0
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, r9)
#define PROFILE_PLATFORM_SPECIFIC_DATA__flags 0xa8
#else // !UNIX_AMD64_ABI
#define PROFILE_PLATFORM_SPECIFIC_DATA__flags 0x58
#endif // UNIX_AMD64_ABI
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flags)
#if defined(UNIX_AMD64_ABI)
#define PROFILE_PLATFORM_SPECIFIC_DATA__buffer 0xb0
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, buffer)
#endif

#undef ASMCONSTANTS_C_ASSERT_OFFSET
#endif // PROFILING_SUPPORTED

#undef ASMCONSTANTS_RUNTIME_ASSERT
#undef ASMCONSTANTS_C_ASSERT
#ifndef UNIX_AMD64_ABI
Expand Down
241 changes: 102 additions & 139 deletions src/coreclr/vm/amd64/asmhelpers.S

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions src/coreclr/vm/amd64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,47 @@ struct EHContext {

#include "stublinkeramd64.h"

//**********************************************************************
// Profiling
//**********************************************************************

#ifdef PROFILING_SUPPORTED

#define PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE 16

typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA
{
FunctionID functionId;
void *rbp;
void *probeRsp;
void *ip;
void *profiledRsp;
UINT64 rax;
LPVOID hiddenArg;
UINT64 flt0; // floats stored as doubles
UINT64 flt1;
UINT64 flt2;
UINT64 flt3;
#if defined(UNIX_AMD64_ABI)
UINT64 flt4;
UINT64 flt5;
UINT64 flt6;
UINT64 flt7;
UINT64 rdi;
UINT64 rsi;
UINT64 rdx;
UINT64 rcx;
UINT64 r8;
UINT64 r9;
#endif
UINT32 flags;
#if defined(UNIX_AMD64_ABI)
// A buffer to copy structs in to so they are sequential for GetFunctionEnter3Info.
UINT64 buffer[PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE];
#endif
} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA;

#endif // PROFILING_SUPPORTED

//**********************************************************************
// Exception handling
Expand Down
42 changes: 1 addition & 41 deletions src/coreclr/vm/amd64/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,12 @@
#include "common.h"

#ifdef PROFILING_SUPPORTED
#include "asmconstants.h"
#include "proftoeeinterfaceimpl.h"
#include "argdestination.h"

MethodDesc *FunctionIdToMethodDesc(FunctionID functionID);

// TODO: move these to some common.h file
// FLAGS
#define PROFILE_ENTER 0x1
#define PROFILE_LEAVE 0x2
#define PROFILE_TAILCALL 0x4

#define PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE 16

typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA
{
FunctionID functionId;
void *rbp;
void *probeRsp;
void *ip;
void *profiledRsp;
UINT64 rax;
LPVOID hiddenArg;
UINT64 flt0; // floats stored as doubles
UINT64 flt1;
UINT64 flt2;
UINT64 flt3;
#if defined(UNIX_AMD64_ABI)
UINT64 flt4;
UINT64 flt5;
UINT64 flt6;
UINT64 flt7;
UINT64 rdi;
UINT64 rsi;
UINT64 rdx;
UINT64 rcx;
UINT64 r8;
UINT64 r9;
#endif
UINT32 flags;
#if defined(UNIX_AMD64_ABI)
// A buffer to copy structs in to so they are sequential for GetFunctionEnter3Info.
UINT64 buffer[PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE];
#endif
} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA;


/*
* ProfileGetIPFromPlatformSpecificHandle
*
Expand Down
25 changes: 25 additions & 0 deletions src/coreclr/vm/arm/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,30 @@ ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForMethod == offsetof(CallCoun
#define CallCountingStubData__TargetForThresholdReached 0x08
ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForThresholdReached == offsetof(CallCountingStubData, TargetForThresholdReached))

#ifdef PROFILING_SUPPORTED
#define PROFILE_ENTER 0x1
#define PROFILE_LEAVE 0x2
#define PROFILE_TAILCALL 0x4

#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 104
ASMCONSTANTS_C_ASSERT(SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA == sizeof(PROFILE_PLATFORM_SPECIFIC_DATA))

#define ASMCONSTANTS_C_ASSERT_OFFSET(type, field) \
ASMCONSTANTS_C_ASSERT(type##__##field == offsetof(type, field))

#define PROFILE_PLATFORM_SPECIFIC_DATA__functionId 80
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, functionId)
#define PROFILE_PLATFORM_SPECIFIC_DATA__probeSp 84
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, probeSp)
#define PROFILE_PLATFORM_SPECIFIC_DATA__profiledSp 88
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, profiledSp)
#define PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg 92
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, hiddenArg)
#define PROFILE_PLATFORM_SPECIFIC_DATA__flags 96
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flags)

#undef ASMCONSTANTS_C_ASSERT_OFFSET
#endif // PROFILING_SUPPORTED

#undef ASMCONSTANTS_RUNTIME_ASSERT
#undef ASMCONSTANTS_C_ASSERT
17 changes: 7 additions & 10 deletions src/coreclr/vm/arm/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,8 @@ LEAF_ENTRY JIT_ProfilerEnterLeaveTailcallStub, _TEXT
bx lr
LEAF_END JIT_ProfilerEnterLeaveTailcallStub, _TEXT

#define PROFILE_ENTER 1
#define PROFILE_LEAVE 2
#define PROFILE_TAILCALL 4
// size of profiler data structure plus alignment padding
#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 104+4
#define PADDED_SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA+4

// typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA
// {
Expand Down Expand Up @@ -385,23 +382,23 @@ NESTED_ENTRY \helper\()Naked, _TEXT, NoHandler
CHECK_STACK_ALIGNMENT

// set the other args, starting with functionID
str r0, [sp, #80]
str r0, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__functionId]

// probeSp is the original sp when this stub was called
add r2, sp, SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA+20
str r2, [sp, #84]
add r2, sp, PADDED_SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA+20
str r2, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__probeSp]

// get the address of the arguments from the frame pointer, store in profiledSp
add r2, r11, #8
str r2, [sp, #88]
str r2, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__profiledSp]

// clear hiddenArg
movw r2, #0
str r2, [sp, #92]
str r2, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg]

// set the flag to indicate what hook this is
movw r2, \flags
str r2, [sp, #96]
str r2, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__flags]

// sp is the address of PROFILE_PLATFORM_SPECIFIC_DATA, then call to C++
mov r1, sp
Expand Down
27 changes: 27 additions & 0 deletions src/coreclr/vm/arm/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,33 @@ struct EHContext {

#define ARGUMENTREGISTERS_SIZE sizeof(ArgumentRegisters)


//**********************************************************************
// Profiling
//**********************************************************************

#ifdef PROFILING_SUPPORTED

typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA
{
UINT32 r0; // Keep r0 & r1 contiguous to make returning 64-bit results easier
UINT32 r1;
void *R11;
void *Pc;
union // Float arg registers as 32-bit (s0-s15) and 64-bit (d0-d7)
{
UINT32 s[16];
UINT64 d[8];
};
FunctionID functionId;
void *probeSp; // stack pointer of managed function
void *profiledSp; // location of arguments on stack
LPVOID hiddenArg;
UINT32 flags;
} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA;

#endif // PROFILING_SUPPORTED

//**********************************************************************
// Exception handling
//**********************************************************************
Expand Down
26 changes: 1 addition & 25 deletions src/coreclr/vm/arm/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,10 @@

#ifdef PROFILING_SUPPORTED
#include "proftoeeinterfaceimpl.h"
#include "asmconstants.h"

MethodDesc *FunctionIdToMethodDesc(FunctionID functionID);

// TODO: move these to some common.h file
// FLAGS
#define PROFILE_ENTER 0x1
#define PROFILE_LEAVE 0x2
#define PROFILE_TAILCALL 0x4

typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA
{
UINT32 r0; // Keep r0 & r1 contiguous to make returning 64-bit results easier
UINT32 r1;
void *R11;
void *Pc;
union // Float arg registers as 32-bit (s0-s15) and 64-bit (d0-d7)
{
UINT32 s[16];
UINT64 d[8];
};
FunctionID functionId;
void *probeSp; // stack pointer of managed function
void *profiledSp; // location of arguments on stack
LPVOID hiddenArg;
UINT32 flags;
} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA;


/*
* ProfileGetIPFromPlatformSpecificHandle
*
Expand Down
39 changes: 39 additions & 0 deletions src/coreclr/vm/arm64/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,44 @@ ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForMethod == offsetof(CallCoun
#define CallCountingStubData__TargetForThresholdReached 0x10
ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForThresholdReached == offsetof(CallCountingStubData, TargetForThresholdReached))

#ifdef PROFILING_SUPPORTED
#define PROFILE_ENTER 0x1
#define PROFILE_LEAVE 0x2
#define PROFILE_TAILCALL 0x4

#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 320
ASMCONSTANTS_C_ASSERT(SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA == sizeof(PROFILE_PLATFORM_SPECIFIC_DATA))

#define ASMCONSTANTS_C_ASSERT_OFFSET(type, field) \
ASMCONSTANTS_C_ASSERT(type##__##field == offsetof(type, field))

#define PROFILE_PLATFORM_SPECIFIC_DATA__Fp 0
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, Fp)
#define PROFILE_PLATFORM_SPECIFIC_DATA__Pc 8
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, Pc)
#define PROFILE_PLATFORM_SPECIFIC_DATA__x8 16
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, x8)
#define PROFILE_PLATFORM_SPECIFIC_DATA__argumentRegisters 24
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, argumentRegisters)
#define PROFILE_PLATFORM_SPECIFIC_DATA__functionId 88
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, functionId)
#define PROFILE_PLATFORM_SPECIFIC_DATA__floatArgumentRegisters 96
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, floatArgumentRegisters)
#define PROFILE_PLATFORM_SPECIFIC_DATA__probeSp 224
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, probeSp)
#define PROFILE_PLATFORM_SPECIFIC_DATA__profiledSp 232
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, profiledSp)
#define PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg 240
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, hiddenArg)
#define PROFILE_PLATFORM_SPECIFIC_DATA__flags 248
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flags)
#define PROFILE_PLATFORM_SPECIFIC_DATA__unused 252
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, unused)
#define PROFILE_PLATFORM_SPECIFIC_DATA__buffer 256
ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, buffer)

#undef ASMCONSTANTS_C_ASSERT_OFFSET
#endif // PROFILING_SUPPORTED

#undef ASMCONSTANTS_RUNTIME_ASSERT
#undef ASMCONSTANTS_C_ASSERT
Loading
Loading