Skip to content

Commit 7db9d7b

Browse files
authored
[Release/8.0] Fix FP state restore on macOS exception forwarding (#109579)
Backport of #105003, #109458 and part of #99255
1 parent b2ac274 commit 7db9d7b

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ HijackFaultingThread(
849849
if (fIsStackOverflow)
850850
{
851851
// Allocate the minimal stack necessary for handling stack overflow
852-
int stackOverflowStackSize = 7 * 4096;
852+
int stackOverflowStackSize = 15 * 4096;
853853
// Align the size to virtual page size and add one virtual page as a stack guard
854854
stackOverflowStackSize = ALIGN_UP(stackOverflowStackSize, GetVirtualPageSize()) + GetVirtualPageSize();
855855
void* stackOverflowHandlerStack = mmap(NULL, stackOverflowStackSize, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
@@ -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.ufs, 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)