Skip to content

Commit

Permalink
server: Avoid a mach port leak on Apple Silicon.
Browse files Browse the repository at this point in the history
Check for Rosetta before extracting the port right, since we won't need
it in that case anyway.
  • Loading branch information
misterfifths authored and julliard committed Aug 10, 2023
1 parent 1135543 commit b2a099b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions server/mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,6 @@ void set_thread_context( struct thread *thread, const context_t *context, unsign
/* all other regs are handled on the client side */
assert( flags == SERVER_CTX_DEBUG_REGISTERS );

if (thread->unix_pid == -1 || !process_port ||
mach_port_extract_right( process_port, thread->unix_tid,
MACH_MSG_TYPE_COPY_SEND, &port, &type ))
{
set_error( STATUS_ACCESS_DENIED );
return;
}

if (is_rosetta())
{
/* Setting debug registers of a translated process is not supported cross-process
Expand All @@ -290,6 +282,14 @@ void set_thread_context( struct thread *thread, const context_t *context, unsign
return;
}

if (thread->unix_pid == -1 || !process_port ||
mach_port_extract_right( process_port, thread->unix_tid,
MACH_MSG_TYPE_COPY_SEND, &port, &type ))
{
set_error( STATUS_ACCESS_DENIED );
return;
}

/* get the debug state to determine which flavor to use */
ret = thread_get_state(port, x86_DEBUG_STATE, (thread_state_t)&state, &count);
if (ret)
Expand Down

0 comments on commit b2a099b

Please sign in to comment.