Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 15 additions & 2 deletions src/coreclr/pal/src/exception/machexception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,8 +1325,21 @@ void MachExceptionInfo::RestoreState(mach_port_t thread)
kern_return_t machret = thread_set_state(thread, x86_THREAD_STATE, (thread_state_t)&ThreadState, x86_THREAD_STATE_COUNT);
CHECK_MACH("thread_set_state(thread)", machret);

machret = thread_set_state(thread, x86_FLOAT_STATE, (thread_state_t)&FloatState, x86_FLOAT_STATE_COUNT);
CHECK_MACH("thread_set_state(float)", machret);
switch (FloatState.ash.flavor)
{
case x86_FLOAT_STATE:
machret = thread_set_state(thread, x86_FLOAT_STATE, (thread_state_t)&FloatState, x86_FLOAT_STATE_COUNT);
CHECK_MACH("thread_set_state(float)", machret);
break;
case x86_AVX_STATE:
machret = thread_set_state(thread, x86_AVX_STATE, (thread_state_t)&FloatState, x86_AVX_STATE_COUNT);
CHECK_MACH("thread_set_state(avx)", machret);
break;
case x86_AVX512_STATE:
machret = thread_set_state(thread, x86_AVX512_STATE, (thread_state_t)&FloatState, x86_AVX512_STATE_COUNT);
CHECK_MACH("thread_set_state(avx512)", machret);
break;
}

machret = thread_set_state(thread, x86_DEBUG_STATE, (thread_state_t)&DebugState, x86_DEBUG_STATE_COUNT);
CHECK_MACH("thread_set_state(debug)", machret);
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/pal/src/exception/machmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class MachMessage
// The maximum size in bytes of any Mach message we can send or receive. Calculating an exact size for
// this is non trivial (basically because of the security trailers that Mach appends) but the current
// value has proven to be more than enough so far.
static const size_t kcbMaxMessageSize = 1500;
static const size_t kcbMaxMessageSize = 0x1500;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to define this as sizeof(mach_message_t) plus some extra space?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've actually found a constant in the headers representing the maximum trailer size, so we can define it as sizeof(mach_message_t) + MAX_TRAILER_SIZE and be safe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a commit with that change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the MAX_TRAILER_SIZE in a mach source file header? And I am guessing it refers to the security trailers that are mentioned in the comment above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is in the Apple headers and it refers to those trailers.


// The following are structures describing the formats of the Mach messages we understand.

Expand Down Expand Up @@ -298,6 +298,9 @@ class MachMessage
} data;
} __attribute__((packed));;


static_assert_no_msg(sizeof(mach_message_t) <= MachMessage::kcbMaxMessageSize);

// Re-initializes this data structure (to the same state as default construction, containing no message).
void ResetMessage();

Expand Down