Skip to content

Commit

Permalink
linux-user: Use safe_syscall wrapper for accept and accept4 syscalls
Browse files Browse the repository at this point in the history
Use the safe_syscall wrapper for the accept and accept4 syscalls.
accept4 has been in the kernel since 2.6.28 so we can assume it
is always present.

Signed-off-by: Peter Maydell <[email protected]>
Signed-off-by: Riku Voipio <[email protected]>
  • Loading branch information
pm215 authored and Riku Voipio committed Jun 8, 2016
1 parent ffb7ee7 commit ff6dc13
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions linux-user/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ safe_syscall3(ssize_t, recvmsg, int, fd, struct msghdr *, msg, int, flags)
safe_syscall2(int, flock, int, fd, int, operation)
safe_syscall4(int, rt_sigtimedwait, const sigset_t *, these, siginfo_t *, uinfo,
const struct timespec *, uts, size_t, sigsetsize)
safe_syscall4(int, accept4, int, fd, struct sockaddr *, addr, socklen_t *, len,
int, flags)
safe_syscall2(int, nanosleep, const struct timespec *, req,
struct timespec *, rem)
#ifdef TARGET_NR_clock_nanosleep
Expand Down Expand Up @@ -3061,19 +3063,6 @@ static abi_long do_sendrecvmmsg(int fd, abi_ulong target_msgvec,
return ret;
}

/* If we don't have a system accept4() then just call accept.
* The callsites to do_accept4() will ensure that they don't
* pass a non-zero flags argument in this config.
*/
#ifndef CONFIG_ACCEPT4
static inline int accept4(int sockfd, struct sockaddr *addr,
socklen_t *addrlen, int flags)
{
assert(flags == 0);
return accept(sockfd, addr, addrlen);
}
#endif

/* do_accept4() Must return target values and target errnos. */
static abi_long do_accept4(int fd, abi_ulong target_addr,
abi_ulong target_addrlen_addr, int flags)
Expand All @@ -3086,7 +3075,7 @@ static abi_long do_accept4(int fd, abi_ulong target_addr,
host_flags = target_to_host_bitmask(flags, fcntl_flags_tbl);

if (target_addr == 0) {
return get_errno(accept4(fd, NULL, NULL, host_flags));
return get_errno(safe_accept4(fd, NULL, NULL, host_flags));
}

/* linux returns EINVAL if addrlen pointer is invalid */
Expand All @@ -3102,7 +3091,7 @@ static abi_long do_accept4(int fd, abi_ulong target_addr,

addr = alloca(addrlen);

ret = get_errno(accept4(fd, addr, &addrlen, host_flags));
ret = get_errno(safe_accept4(fd, addr, &addrlen, host_flags));
if (!is_error(ret)) {
host_to_target_sockaddr(target_addr, addr, addrlen);
if (put_user_u32(addrlen, target_addrlen_addr))
Expand Down Expand Up @@ -8334,11 +8323,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
#endif
#ifdef TARGET_NR_accept4
case TARGET_NR_accept4:
#ifdef CONFIG_ACCEPT4
ret = do_accept4(arg1, arg2, arg3, arg4);
#else
goto unimplemented;
#endif
break;
#endif
#ifdef TARGET_NR_bind
Expand Down

0 comments on commit ff6dc13

Please sign in to comment.