From d2482174dd91d2243a1a38781c11c4ceeb441bbb Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Thu, 4 Jun 2026 21:41:33 -0700 Subject: [PATCH] bsdsocket: preserve Unix trap context for host calls The Unix shutdown and setsockopt paths need the active TrapContext when they resolve guest socket descriptors and copy guest option data. Store the current context in the socket base before dispatching those host calls and when the deferred WaitSelect worker is armed. --- bsdsocket.cpp | 6 ++++++ od-unix/bsdsock_unix.cpp | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bsdsocket.cpp b/bsdsocket.cpp index f68e9145..641a2fc4 100644 --- a/bsdsocket.cpp +++ b/bsdsocket.cpp @@ -639,6 +639,9 @@ static uae_u32 REGPARAM2 bsdsocklib_recv (TrapContext *ctx) static uae_u32 REGPARAM2 bsdsocklib_shutdown (TrapContext *ctx) { struct socketbase *sb = get_socketbase (ctx); +#ifndef _WIN32 + sb->context = ctx; +#endif return host_shutdown (sb, trap_get_dreg(ctx, 0), trap_get_dreg(ctx, 1)); } @@ -646,6 +649,9 @@ static uae_u32 REGPARAM2 bsdsocklib_shutdown (TrapContext *ctx) static uae_u32 REGPARAM2 bsdsocklib_setsockopt (TrapContext *ctx) { struct socketbase *sb = get_socketbase (ctx); +#ifndef _WIN32 + sb->context = ctx; +#endif host_setsockopt (sb, trap_get_dreg(ctx, 0), trap_get_dreg(ctx, 1), trap_get_dreg(ctx, 2), trap_get_areg(ctx, 0), trap_get_dreg(ctx, 3)); return sb->resultval; diff --git a/od-unix/bsdsock_unix.cpp b/od-unix/bsdsock_unix.cpp index b5d53757..4682bcc6 100644 --- a/od-unix/bsdsock_unix.cpp +++ b/od-unix/bsdsock_unix.cpp @@ -1853,7 +1853,7 @@ void host_recvfrom(TrapContext *ctx, SB, uae_u32 sd, uae_u32 msg, uae_u8 *hmsg, uae_u32 host_shutdown(SB, uae_u32 sd, uae_u32 how) { - TrapContext *ctx = NULL; + TrapContext *ctx = sb->context; SOCKET s; write_log("shutdown(%d,%d) -> ", sd, how); @@ -1874,7 +1874,7 @@ uae_u32 host_shutdown(SB, uae_u32 sd, uae_u32 how) void host_setsockopt(SB, uae_u32 sd, uae_u32 level, uae_u32 optname, uae_u32 optval, uae_u32 len) { - TrapContext* ctx = NULL; + TrapContext* ctx = sb->context; int s = getsock(ctx, sb, sd + 1); void* buf = NULL; struct linger sl; @@ -2405,6 +2405,7 @@ void host_WaitSelect(TrapContext *ctx, SB, uae_u32 nfds, uae_u32 readfds, uae_u3 sb->sets [2] = exceptfds; sb->timeout = timeout; sb->sigmp = wssigs; + sb->context = ctx; sb->action = 5; uae_sem_post (&sb->sem); -- 2.47.3