linux-user: Use safe_syscall wrapper for accept and accept4 syscalls
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 <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
This commit is contained in:
		
							parent
							
								
									ffb7ee796a
								
							
						
					
					
						commit
						ff6dc13079
					
				| 
						 | 
					@ -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_syscall2(int, flock, int, fd, int, operation)
 | 
				
			||||||
safe_syscall4(int, rt_sigtimedwait, const sigset_t *, these, siginfo_t *, uinfo,
 | 
					safe_syscall4(int, rt_sigtimedwait, const sigset_t *, these, siginfo_t *, uinfo,
 | 
				
			||||||
              const struct timespec *, uts, size_t, sigsetsize)
 | 
					              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,
 | 
					safe_syscall2(int, nanosleep, const struct timespec *, req,
 | 
				
			||||||
              struct timespec *, rem)
 | 
					              struct timespec *, rem)
 | 
				
			||||||
#ifdef TARGET_NR_clock_nanosleep
 | 
					#ifdef TARGET_NR_clock_nanosleep
 | 
				
			||||||
| 
						 | 
					@ -3061,19 +3063,6 @@ static abi_long do_sendrecvmmsg(int fd, abi_ulong target_msgvec,
 | 
				
			||||||
    return ret;
 | 
					    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. */
 | 
					/* do_accept4() Must return target values and target errnos. */
 | 
				
			||||||
static abi_long do_accept4(int fd, abi_ulong target_addr,
 | 
					static abi_long do_accept4(int fd, abi_ulong target_addr,
 | 
				
			||||||
                           abi_ulong target_addrlen_addr, int flags)
 | 
					                           abi_ulong target_addrlen_addr, int flags)
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
					    host_flags = target_to_host_bitmask(flags, fcntl_flags_tbl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (target_addr == 0) {
 | 
					    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 */
 | 
					    /* linux returns EINVAL if addrlen pointer is invalid */
 | 
				
			||||||
| 
						 | 
					@ -3102,7 +3091,7 @@ static abi_long do_accept4(int fd, abi_ulong target_addr,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    addr = alloca(addrlen);
 | 
					    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)) {
 | 
					    if (!is_error(ret)) {
 | 
				
			||||||
        host_to_target_sockaddr(target_addr, addr, addrlen);
 | 
					        host_to_target_sockaddr(target_addr, addr, addrlen);
 | 
				
			||||||
        if (put_user_u32(addrlen, target_addrlen_addr))
 | 
					        if (put_user_u32(addrlen, target_addrlen_addr))
 | 
				
			||||||
| 
						 | 
					@ -8334,11 +8323,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef TARGET_NR_accept4
 | 
					#ifdef TARGET_NR_accept4
 | 
				
			||||||
    case TARGET_NR_accept4:
 | 
					    case TARGET_NR_accept4:
 | 
				
			||||||
#ifdef CONFIG_ACCEPT4
 | 
					 | 
				
			||||||
        ret = do_accept4(arg1, arg2, arg3, arg4);
 | 
					        ret = do_accept4(arg1, arg2, arg3, arg4);
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
        goto unimplemented;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef TARGET_NR_bind
 | 
					#ifdef TARGET_NR_bind
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue