Skip to content

Commit 1606484

Browse files
janvorlipull[bot]
authored andcommitted
Fix mach hardware exception forwarding (#105003)
* Fix mach hardware exception forwarding A recent change to enable AVX512 register state processing in the mach exception handling on macOS x64 has broken a PAL test and also a case when a hardware exception occurs in 3rd party native code. In both cases runtime hangs, another exception occurs while forwarding the exception message and that ends up happenning infinitely. The problem is caused by the fact that the MachMessageInfo has grown, since we've changed a field containing float state to contain avx512 state instead. But the buffer that stores the message is of fixed size of 1500 bytes and it is not sufficient. I have grown the buffer size to the necessary size, but there was another issue lurking behind the first one. The MachExceptionInfo::RestoreState was trying to restore the float state always as x86_FLOAT_STATE instead of choosing x86_FLOAT_STATE, x86_AVX_STATE or x86_AVX512_STATE depending of which of them was stored. So the thread_set_state was failing. This change fixes both of the problems. * Simplify the RestoreState * Set the message buffer to the size of the mach_msg_t plus trailer size
1 parent 19b7dc9 commit 1606484

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

‎src/coreclr/pal/src/exception/machexception.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ void MachExceptionInfo::RestoreState(mach_port_t thread)
13251325
kern_return_t machret = thread_set_state(thread, x86_THREAD_STATE, (thread_state_t)&ThreadState, x86_THREAD_STATE_COUNT);
13261326
CHECK_MACH("thread_set_state(thread)", machret);
13271327

1328-
machret = thread_set_state(thread, x86_FLOAT_STATE, (thread_state_t)&FloatState, x86_FLOAT_STATE_COUNT);
1328+
machret = thread_set_state(thread, FloatState.ash.flavor, (thread_state_t)&FloatState, FloatState.ash.count);
13291329
CHECK_MACH("thread_set_state(float)", machret);
13301330

13311331
machret = thread_set_state(thread, x86_DEBUG_STATE, (thread_state_t)&DebugState, x86_DEBUG_STATE_COUNT);

‎src/coreclr/pal/src/exception/machmessage.h‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ class MachMessage
186186
void ReplyToNotification(MachMessage& message, kern_return_t eResult);
187187

188188
private:
189-
// The maximum size in bytes of any Mach message we can send or receive. Calculating an exact size for
190-
// this is non trivial (basically because of the security trailers that Mach appends) but the current
191-
// value has proven to be more than enough so far.
192-
static const size_t kcbMaxMessageSize = 1500;
193-
194189
// The following are structures describing the formats of the Mach messages we understand.
195190

196191
// Request to set the register context on a particular thread.
@@ -298,6 +293,9 @@ class MachMessage
298293
} data;
299294
} __attribute__((packed));;
300295

296+
// The maximum size in bytes of any Mach message we can send or receive including possible trailers
297+
static const size_t kcbMaxMessageSize = sizeof(mach_message_t) + MAX_TRAILER_SIZE;
298+
301299
// Re-initializes this data structure (to the same state as default construction, containing no message).
302300
void ResetMessage();
303301

0 commit comments

Comments
 (0)