@samitouri / QOSamiQemu / commits / edb4588309

linux-user: Add setsockopt() for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW

Add handlers for both sockopts which use 64-bit time_t from userspace. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/885 Signed-off-by: Helge Deller <deller@gmx.de>

Helge Deller committed Apr 24, 2026 at 10:25 UTC edb4588309a753dea40f338fb8e02e3cfc2eed70
1 file changed +19 -2
linux-user/syscall.c
+19 -2
@@ -1143,7 +1143,6 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
1143 return 0;
1144 }
1145
1146 -#if defined(TARGET_NR_clock_adjtime64) && defined(CONFIG_CLOCK_ADJTIME)
1146 static inline abi_long copy_from_user_timeval64(struct timeval *tv,
1147 abi_ulong target_tv_addr)
1148 {
@@ -1160,7 +1159,6 @@ static inline abi_long copy_from_user_timeval64(struct timeval *tv,
1159
1160 return 0;
1161 }
1163 -#endif
1162
1163 static inline abi_long copy_to_user_timeval64(abi_ulong target_tv_addr,
1164 const struct timeval *tv)
@@ -2391,6 +2389,25 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
2389 &tv, sizeof(tv)));
2390 return ret;
2391 }
2392 + case TARGET_SO_RCVTIMEO_NEW:
2393 + case TARGET_SO_SNDTIMEO_NEW:
2394 + {
2395 + struct timeval tv;
2396 +
2397 + if (optlen != sizeof(struct target__kernel_sock_timeval)) {
2398 + return -TARGET_EINVAL;
2399 + }
2400 +
2401 + if (copy_from_user_timeval64(&tv, optval_addr)) {
2402 + return -TARGET_EFAULT;
2403 + }
2404 +
2405 + ret = get_errno(setsockopt(sockfd, SOL_SOCKET,
2406 + optname == TARGET_SO_RCVTIMEO_NEW ?
2407 + SO_RCVTIMEO : SO_SNDTIMEO,
2408 + &tv, sizeof(tv)));
2409 + return ret;
2410 + }
2411 case TARGET_SO_ATTACH_FILTER:
2412 {
2413 struct target_sock_fprog *tfprog;