Contribution task implementations, for the 'FreeBSD user emulation improvements' project.
v4 cover Contribution task implementations, for the 'FreeBSD user emulation improvements' project.
Upstream the implementations of bind(2), connect(2), accept(2) and getpeername(2) system calls from the blitz branch of the bsd-user fork hosted at
https://github.com/qemu-bsd-user/qemu-bsd-user/tree/blitz.
Karim Taha (1):
Sean Bruno (1):
Stacey Son (7):
Warner Losh (2):
bsd-user/bsd-socket.c | 108 +++++++++++++++++++++++++ bsd-user/bsd-socket.h | 143 ++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 21 +++++ bsd-user/main.c | 16 +++- bsd-user/meson.build | 1 + bsd-user/qemu-bsd.h | 36 +++++++++ bsd-user/syscall_defs.h | 148 ++++++++++++++++++++++++++++++++++ 7 files changed, 472 insertions(+), 1 deletion(-) create mode 100644 bsd-user/bsd-socket.c create mode 100644 bsd-user/bsd-socket.h create mode 100644 bsd-user/qemu-bsd.h
Signature · 1 line
2.40.0
PATCH v4 1/11 Signed-off-by: Karim Taha <[email protected]>
From: Warner Losh <[email protected]>
Intialize guest_base in bsd-user/main.c.
Allow guest_base to be initialized on 64-bit hosts, the initial value is used by g2h_untagged function defined in include/exec/cpu_ldst.h
--- bsd-user/main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
bsd-user/main.c +15 -1
@@ -50,8 +50,22 @@#include "target_arch_cpu.h" int singlestep; -uintptr_t guest_base; + +/* +* Going hand in hand with the va space needed (see below), we need +* to find a host address to map the guest to. Assume that qemu +* itself doesn't need memory above 32GB (or that we don't collide +* with anything interesting). This is selected rather arbitrarily, +* but seems to produce good results in tests to date. +*/ +# if HOST_LONG_BITS >=64 +uintptr_t guest_base =0x800000000ul ;/* at 32GB */ +bool have_guest_base = true; +#else +uintptr_t guest_base;/* TODO: use sysctl to find big enough hole */ bool have_guest_base; +#endif +/* * When running 32-on-64 we should make sure we can fit all of the possible * guest address space into a contiguous chunk of virtual host memory.
Signature · 1 line
2.40.0
Re: [PATCH v4 01/11] Signed-off-by: Karim Taha <[email protected]>
You've not fully addressed the feedback on v3. The first line of the commit message needs to be a short sumary, not the Signed-off-by, which should be at the end of the commit message
Quoted 5 lines · Karim Taha
From: Warner Losh <[email protected]>
Intialize
guest_baseinbsd-user/main.c.Allow
guest_baseto be initialized on 64-bit hosts, the initial value is used byg2h_untaggedfunction defined ininclude/exec/cpu_ldst.h
You also need to put line breaks in the commit message to keep it at around 72 chars
Quoted 39 lines
Signed-off-by Warner Losh <[email protected]>Signed-off-by Karim Taha <[email protected]>--- bsd-user/main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)bsd-user/main.c +15
-1@@ -50,8 +50,22 @@#include "target_arch_cpu.h" int singlestep; -uintptr_t guest_base; + +/* +* Going hand in hand with the va space needed (see below), we need +* to find a host address to map the guest to. Assume that qemu +* itself doesn't need memory above 32GB (or that we don't collide +* with anything interesting). This is selected rather arbitrarily, +* but seems to produce good results in tests to date. +*/ +# if HOST_LONG_BITS >=64 +uintptr_t guest_base =0x800000000ul ;/* at 32GB */ +bool have_guest_base = true; +#else +uintptr_t guest_base;/* TODO: use sysctl to find big enough hole */ bool have_guest_base; +#endif +/* * When running 32-on-64 we should make sure we can fit all of the possible * guest address space into a contiguous chunk of virtual host memory. Signature · 1 line
2.40.0
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v4 2/11 Signed-off-by: Karim Taha <[email protected]>
In reply to Karim TahaFrom: Stacey Son <[email protected]>
Add the socket conversion related flags and structs.
Add the relevant definitions of struct target_sockaddr and struct target_ip_mreq and the related flags, to be used in bsd-user/bsd-socket.c for the socket conversion functions:target_to_host_sockaddr, host_to_target_sockaddr, target_to_host_ip_mreq
--- bsd-user/syscall_defs.h | 110 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+)
bsd-user/syscall_defs.h +110 -0
@@ -179,6 +179,116 @@ struct target_freebsd__wrusage {struct target_freebsd_rusage wru_children; }; +/* +* sys/socket.h +*/ + +/* +* Types +*/ +#define TARGET_SOCK_STREAM 1/* stream socket */ +#define TARGET_SOCK_DGRAM 2/* datagram socket */ +#define TARGET_SOCK_RAW 3/* raw-protocol interface */ +#define TARGET_SOCK_RDM 4/* reliably-delivered message */ +#define TARGET_SOCK_SEQPACKET 5/* sequenced packet stream */ + + +/* +* Option flags per-socket. +*/ + +#define TARGET_SO_DEBUG 0x0001/* turn on debugging info recording */ +#define TARGET_SO_ACCEPTCONN 0x0002/* socket has had listen() */ +#define TARGET_SO_REUSEADDR 0x0004/* allow local address reuse */ +#define TARGET_SO_KEEPALIVE 0x0008/* keep connections alive */ +#define TARGET_SO_DONTROUTE 0x0010/* just use interface addresses */ +#define TARGET_SO_BROADCAST 0x0020/* permit sending of broadcast msgs */ +#define TARGET_SO_USELOOPBACK 0x0040/* bypass hardware when possible */ +#define TARGET_SO_LINGER 0x0080/* linger on close if data present */ +#define TARGET_SO_OOBINLINE 0x0100/* leave received OOB data in line */ +#define TARGET_SO_REUSEPORT 0x0200/* allow local address & port reuse */ +#define TARGET_SO_TIMESTAMP 0x0400/* timestamp received dgram traffic */ +#define TARGET_SO_NOSIGPIPE 0x0800/* no SIGPIPE from EPIPE */ +#define TARGET_SO_ACCEPTFILTER 0x1000/* there is an accept filter */ +#define TARGET_SO_BINTIME 0x2000/* timestamp received dgram traffic */ +#define TARGET_SO_NO_OFFLOAD 0x4000/* socket cannot be offloaded */ +#define TARGET_SO_NO_DDP 0x8000/* disable direct data placement */ + +/* +* Additional options, not kept in so_options. +*/ +#define TARGET_SO_SNDBUF 0x1001/* send buffer size */ +#define TARGET_SO_RCVBUF 0x1002/* receive buffer size */ +#define TARGET_SO_SNDLOWAT 0x1003/* send low-water mark */ +#define TARGET_SO_RCVLOWAT 0x1004/* receive low-water mark */ +#define TARGET_SO_SNDTIMEO 0x1005/* send timeout */ +#define TARGET_SO_RCVTIMEO 0x1006/* receive timeout */ +#define TARGET_SO_ERROR 0x1007/* get error status and clear */ +#define TARGET_SO_TYPE 0x1008/* get socket type */ +#define TARGET_SO_LABEL 0x1009/* socket's MAC label */ +#define TARGET_SO_PEERLABEL 0x1010/* socket's peer's MAC label */ +#define TARGET_SO_LISTENQLIMIT 0x1011/* socket's backlog limit */ +#define TARGET_SO_LISTENQLEN 0x1012/* socket's complete queue length */ +#define TARGET_SO_LISTENINCQLEN 0x1013/* socket's incomplete queue length */ +#define TARGET_SO_SETFIB 0x1014/* use this FIB to route */ +#define TARGET_SO_USER_COOKIE 0x1015/* user cookie (dummynet etc.) */ +#define TARGET_SO_PROTOCOL 0x1016/* get socket protocol (Linux name) */ + +/* alias for SO_PROTOCOL (SunOS name) */ +#define TARGET_SO_PROTOTYPE TARGET_SO_PROTOCOL + +/* +* Level number for (get/set)sockopt() to apply to socket itself. +*/ +#define TARGET_SOL_SOCKET 0xffff/* options for socket level */ + +#ifndef CMSG_ALIGN +#define CMSG_ALIGN (len) (((len) + sizeof(long) - 1) & ~(sizeof(long) - 1)) +#endif + +/* +* sys/socket.h +*/ +struct target_msghdr { +abi_long msg_name;/* Socket name */ +int32_t msg_namelen;/* Length of name */ +abi_long msg_iov;/* Data blocks */ +int32_t msg_iovlen;/* Number of blocks */ +abi_long msg_control;/* Per protocol magic (eg BSD fd passing) */ +int32_t msg_controllen;/* Length of cmsg list */ +int32_t msg_flags;/* flags on received message */ +}; + +struct target_sockaddr { +uint8_t sa_len; +uint8_t sa_family; +uint8_t sa_data[14 ]; +}QEMU_PACKED ; + +struct target_in_addr { +uint32_t s_addr;/* big endian */ +}; + +struct target_cmsghdr { +uint32_t cmsg_len; +int32_t cmsg_level; +int32_t cmsg_type; +}; + +/* +* netinet/in.h +*/ +struct target_ip_mreq { +struct target_in_addr imr_multiaddr; +struct target_in_addr imr_interface; +}; + +struct target_ip_mreqn { +struct target_in_addr imr_multiaddr; +struct target_in_addr imr_address; +int32_t imr_ifindex; +}; +#define safe_syscall0 (type, name) \ type safe_##name(void) \ { \
Signature · 1 line
2.40.0
PATCH v4 3/11 Signed-off-by: Karim Taha <[email protected]>
In reply to Karim TahaFrom: Sean Bruno <[email protected]>
Target cmsghdr struct and flags.
Add the cmsghdr struct and alignment flags.
--- bsd-user/syscall_defs.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
bsd-user/syscall_defs.h +38 -0
@@ -275,6 +275,44 @@ struct target_cmsghdr {int32_t cmsg_type; }; +/* +* mips32 is the exception to the general rule of long-alignment; it +* unconditionally uses 64-bit alignment instead. +*/ +#if defined(TARGET_MIPS ) &&TARGET_ABI_BITS ==32 +#define TARGET_ALIGNBYTES (sizeof(abi_llong) - 1) +#else +#define TARGET_ALIGNBYTES (sizeof(abi_long) - 1) +#endif + +#define TARGET_CMSG_NXTHDR (mhdr, cmsg, cmsg_start) \ + __target_cmsg_nxthdr(mhdr, cmsg, cmsg_start) +#define TARGET_CMSG_ALIGN (len) (((len) + TARGET_ALIGNBYTES) \ + & (size_t) ~TARGET_ALIGNBYTES) +#define TARGET_CMSG_DATA (cmsg) \ + ((unsigned char *)(cmsg) + TARGET_CMSG_ALIGN(sizeof(struct target_cmsghdr))) +#define TARGET_CMSG_SPACE (len) \ + (TARGET_CMSG_ALIGN(sizeof(struct target_cmsghdr)) + TARGET_CMSG_ALIGN(len)) +#define TARGET_CMSG_LEN (len) \ + (TARGET_CMSG_ALIGN(sizeof(struct target_cmsghdr)) + (len)) + +static inline struct target_cmsghdr * +__target_cmsg_nxthdr (struct target_msghdr *__mhdr, +struct target_cmsghdr *__cmsg, +struct target_cmsghdr *__cmsg_start) +{ +struct target_cmsghdr *__ptr; + + __ptr = (struct target_cmsghdr *)((unsigned char *) __cmsg + +TARGET_CMSG_ALIGN (tswap32 (__cmsg->cmsg_len))); +if ((unsigned long )((char *)(__ptr +1 ) - (char *)__cmsg_start) > +tswap32 (__mhdr->msg_controllen)) { +/* No more entries. */ +return (struct target_cmsghdr *)0 ; + } +return __ptr; +} +/* * netinet/in.h */
Signature · 1 line
2.40.0
PATCH v4 4/11 Signed-off-by: Karim Taha <[email protected]>
In reply to Karim TahaFrom: Stacey Son <[email protected]>
Declaration of the socket conversion functions.
Add bsd-user/qemu-bsd.h, required by bsd-user/bsd-socket.h, contains forward declarations of the socket conversion functions defined in bsd-user/bsd-socket.c.
--- bsd-user/qemu-bsd.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 bsd-user/qemu-bsd.h
bsd-user/qemu-bsd.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* BSD conversion extern declarations +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef QEMU_BSD_H +#define QEMU_BSD_H + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <netinet/in.h> + +/* bsd-socket.c */ +abi_long target_to_host_sockaddr (struct sockaddr *addr,abi_ulong target_addr, +socklen_t len); +abi_long host_to_target_sockaddr (abi_ulong target_addr,struct sockaddr *addr, +socklen_t len); +abi_long target_to_host_ip_mreq (struct ip_mreqn *mreqn,abi_ulong target_addr, +socklen_t len); + +#endif /* QEMU_BSD_H */
Signature · 1 line
2.40.0
PATCH v4 5/11 Signed-off-by: Karim Taha <[email protected]>
In reply to Karim TahaFrom: Stacey Son <[email protected]>
Definitions of the socket conversion functions.
Add bsd-user/bsd-socket.c, which contains the actual definitions of the socket conversion functions.
--- bsd-user/bsd-socket.c | 108 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 bsd-user/bsd-socket.c
bsd-user/bsd-socket.c new file +108 -0
@@ -0,0 +1,108 @@ +/* +* BSD socket system call related helpers +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <netinet/in.h> + +#include "qemu.h" +#include "qemu-bsd.h" + +/* +* socket conversion +*/ +abi_long target_to_host_sockaddr (struct sockaddr *addr,abi_ulong target_addr, +socklen_t len) +{ +const socklen_t unix_maxlen =sizeof (struct sockaddr_un ); +sa_family_t sa_family; +struct target_sockaddr *target_saddr; + + target_saddr =lock_user (VERIFY_READ , target_addr, len,1 ); +if (target_saddr ==0 ) { +return -TARGET_EFAULT ; + } + + sa_family = target_saddr->sa_family; + +/* +* Oops. The caller might send a incomplete sun_path; sun_path +* must be terminated by \0 (see the manual page), but unfortunately +* it is quite common to specify sockaddr_un length as +* "strlen(x->sun_path)" while it should be "strlen(...) + 1". We will +* fix that here if needed. +*/ +if (target_saddr->sa_family ==AF_UNIX ) { +if (len < unix_maxlen && len >0 ) { +char *cp = (char *)target_saddr; + +if (cp[len -1 ] && !cp[len]) { + len++; + } + } +if (len > unix_maxlen) { + len = unix_maxlen; + } + } + +memcpy (addr, target_saddr, len); + addr->sa_family = sa_family;/* type uint8_t */ + addr->sa_len = target_saddr->sa_len;/* type uint8_t */ +unlock_user (target_saddr, target_addr,0 ); + +return 0 ; +} + +abi_long host_to_target_sockaddr (abi_ulong target_addr,struct sockaddr *addr, +socklen_t len) +{ +struct target_sockaddr *target_saddr; + + target_saddr =lock_user (VERIFY_WRITE , target_addr, len,0 ); +if (target_saddr ==0 ) { +return -TARGET_EFAULT ; + } +memcpy (target_saddr, addr, len); + target_saddr->sa_family = addr->sa_family;/* type uint8_t */ + target_saddr->sa_len = addr->sa_len;/* type uint8_t */ +unlock_user (target_saddr, target_addr, len); + +return 0 ; +} + +abi_long target_to_host_ip_mreq (struct ip_mreqn *mreqn,abi_ulong target_addr, +socklen_t len) +{ +struct target_ip_mreqn *target_smreqn; + + target_smreqn =lock_user (VERIFY_READ , target_addr, len,1 ); +if (target_smreqn ==0 ) { +return -TARGET_EFAULT ; + } + mreqn->imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr; + mreqn->imr_address.s_addr = target_smreqn->imr_address.s_addr; +if (len ==sizeof (struct target_ip_mreqn )) { + mreqn->imr_ifindex =tswapal (target_smreqn->imr_ifindex); + } +unlock_user (target_smreqn, target_addr,0 ); + +return 0 ; +}
Signature · 1 line
2.40.0
PATCH v4 6/11 Signed-off-by: Karim Taha <[email protected]>
In reply to Karim TahaBuild bsd-user/bsd-socket.c.
Add bsd-user/bsd-socket.c to meson.build.
--- bsd-user/meson.build | 1 + 1 file changed, 1 insertion(+)
bsd-user/meson.build +1 -0
@@ -7,6 +7,7 @@ bsd_user_ss = ss.source_set() common_user_inc += include_directories('include') bsd_user_ss.add(files( + 'bsd-socket.c', 'bsdload.c', 'elfload.c', 'main.c',
Signature · 1 line
2.40.0
PATCH v4 7/11 Signed-off-by: Karim Taha <[email protected]>
In reply to Karim TahaFrom: Stacey Son <[email protected]>
The implementation of bind(2) syscall and socket related syscalls.
Add bsd-user/bsd-socket.h, which contains the implementation of bind(2), and the socket related system call shims.
--- bsd-user/bsd-socket.h | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 bsd-user/bsd-socket.h
bsd-user/bsd-socket.h new file +61 -0
@@ -0,0 +1,61 @@ +/* +* socket related system call shims +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef BSD_SOCKET_H +#define BSD_SOCKET_H + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <netinet/in.h> + +#include "qemu-bsd.h" + +ssize_t safe_recvfrom (int s,void *buf,size_t len,int flags, +struct sockaddr *restrict from,socklen_t *restrict fromlen); +ssize_t safe_sendto (int s,const void *buf,size_t len,int flags, +const struct sockaddr *to,socklen_t tolen); +int safe_select (int nfds,fd_set *readfs,fd_set *writefds,fd_set *exceptfds, +struct timeval *timeout); +int safe_pselect (int nfds,fd_set *restrict readfds, +fd_set *restrict writefds,fd_set *restrict exceptfds, +const struct timespec *restrict timeout, +const sigset_t *restrict newsigmask); + +/* bind(2) */ +static inline abi_long do_bsd_bind (int sockfd,abi_ulong target_addr, +socklen_t addrlen) +{ +abi_long ret; +void *addr; + +if ((int )addrlen <0 ) { +return -TARGET_EINVAL ; + } + + addr =alloca (addrlen +1 ); + ret =target_to_host_sockaddr (addr, target_addr, addrlen); +if (is_error (ret)) { +return ret; + } + +return get_errno (bind (sockfd, addr, addrlen)); +} + +#endif /* BSD_SOCKET_H */
Signature · 1 line
2.40.0
PATCH v4 8/11 Signed-off-by: Karim Taha <[email protected]>
In reply to Karim TahaFrom: Stacey Son <[email protected]>
connect(2) syscall.
Add the connect(2) syscall to bsd-user/bsd-socket.h.
--- bsd-user/bsd-socket.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
bsd-user/bsd-socket.h +21 -0
@@ -58,4 +58,25 @@ static inline abi_long do_bsd_bind(int sockfd, abi_ulong target_addr, return get_errno(bind(sockfd, addr, addrlen)); } +/* connect(2) */ +static inline abi_long do_bsd_connect (int sockfd,abi_ulong target_addr, +socklen_t addrlen) +{ +abi_long ret; +void *addr; + +if ((int )addrlen <0 ) { +return -TARGET_EINVAL ; + } + addr =alloca (addrlen +1 ); + + ret =target_to_host_sockaddr (addr, target_addr, addrlen); + +if (is_error (ret)) { +return ret; + } + +return get_errno (connect (sockfd, addr, addrlen)); +} +#endif /* BSD_SOCKET_H */
Signature · 1 line
2.40.0
PATCH v4 9/11 Signed-off-by: Karim Taha <[email protected]>
In reply to Karim TahaFrom: Stacey Son <[email protected]>
accept(2) syscall.
Add the accept(2) syscall to bsd-user/bsd-socket.h.
--- bsd-user/bsd-socket.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
bsd-user/bsd-socket.h +33 -0
@@ -79,4 +79,37 @@ static inline abi_long do_bsd_connect(int sockfd, abi_ulong target_addr,return get_errno (connect (sockfd, addr, addrlen)); } +/* accept(2) */ +static inline abi_long do_bsd_accept (int fd,abi_ulong target_addr, +abi_ulong target_addrlen_addr) +{ +socklen_t addrlen; +void *addr; +abi_long ret; + +if (target_addr ==0 ) { +return get_errno (accept (fd,NULL ,NULL )); + } +/* return EINVAL if addrlen pointer is invalid */ +if (get_user_u32 (addrlen, target_addrlen_addr)) { +return -TARGET_EINVAL ; + } +if ((int )addrlen <0 ) { +return -TARGET_EINVAL ; + } +if (!access_ok (VERIFY_WRITE , target_addr, addrlen)) { +return -TARGET_EINVAL ; + } + addr =alloca (addrlen); + + ret =get_errno (accept (fd, addr, &addrlen)); +if (!is_error (ret)) { +host_to_target_sockaddr (target_addr, addr, addrlen); +if (put_user_u32 (addrlen, target_addrlen_addr)) { + ret = -TARGET_EFAULT ; + } + } +return ret; +} +#endif /* BSD_SOCKET_H */
Signature · 1 line
2.40.0
PATCH v4 10/11 Signed-off-by: Karim Taha <[email protected]>
In reply to Karim TahaFrom: Stacey Son <[email protected]>
getpeername(2) syscall.
Add the getpeername(2) syscall to bsd-user/bsd-socket.h.
--- bsd-user/bsd-socket.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
bsd-user/bsd-socket.h +28 -0
@@ -112,4 +112,32 @@ static inline abi_long do_bsd_accept(int fd, abi_ulong target_addr, return ret; } +/* getpeername(2) */ +static inline abi_long do_bsd_getpeername (int fd,abi_ulong target_addr, +abi_ulong target_addrlen_addr) +{ +socklen_t addrlen; +void *addr; +abi_long ret; + +if (get_user_u32 (addrlen, target_addrlen_addr)) { +return -TARGET_EFAULT ; + } +if ((int )addrlen <0 ) { +return -TARGET_EINVAL ; + } +if (!access_ok (VERIFY_WRITE , target_addr, addrlen)) { +return -TARGET_EFAULT ; + } + addr =alloca (addrlen); + ret =get_errno (getpeername (fd, addr, &addrlen)); +if (!is_error (ret)) { +host_to_target_sockaddr (target_addr, addr, addrlen); +if (put_user_u32 (addrlen, target_addrlen_addr)) { + ret = -TARGET_EFAULT ; + } + } +return ret; +} +#endif /* BSD_SOCKET_H */
Signature · 1 line
2.40.0
PATCH v4 11/11 Signed-off-by: Karim Taha <[email protected]>
In reply to Karim TahaFrom: Warner Losh <[email protected]>
Add the dispatching code of bind(2),connect(2), accpet(2), getpeername(2).
Add the bind(2), connect(2), accept(2), getpeername(2) syscalls case statements to freebsd_syscall function defined in bsd-user/freebsd/os-syscall.c
--- bsd-user/freebsd/os-syscall.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
bsd-user/freebsd/os-syscall.c +21 -0
@@ -44,6 +44,8 @@#include "signal-common.h" #include "user/syscall-trace.h" +/* BSD independent syscall shims */ +#include "bsd-socket.h" #include "bsd-file.h" #include "bsd-proc.h"
@@ -508,6 +510,25 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_freebsd_sysarch (cpu_env, arg1, arg2);break ; +/* +* socket related system calls +*/ +case TARGET_FREEBSD_NR_accept:/* accept(2) */ + ret =do_bsd_accept (arg1, arg2, arg3); +break ; + +case TARGET_FREEBSD_NR_bind:/* bind(2) */ + ret =do_bsd_bind (arg1, arg2, arg3); +break ; + +case TARGET_FREEBSD_NR_connect:/* connect(2) */ + ret =do_bsd_connect (arg1, arg2, arg3); +break ; + +case TARGET_FREEBSD_NR_getpeername:/* getpeername(2) */ + ret =do_bsd_getpeername (arg1, arg2, arg3); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
Signature · 1 line
2.40.0
Re: [PATCH v4 11/11] Signed-off-by: Karim Taha <[email protected]>
Oh, I see you've uploaded an improved version of the patches, with the fixes I'd
recommended. I'll queue that series instead.
Warner
Quoted 58 lines · Karim Taha
From: Warner Losh <[email protected]>
Add the dispatching code of bind(2),connect(2), accpet(2), getpeername(2).
Add the bind(2), connect(2), accept(2), getpeername(2) syscalls case statements to
freebsd_syscallfunction defined inbsd-user/freebsd/os-syscall.cSigned-off-by Warner Losh <[email protected]>Signed-off-by Karim Taha <[email protected]>--- bsd-user/freebsd/os-syscall.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)bsd-user/freebsd/os-syscall.c +21
-0@@ -44,6 +44,8 @@#include "signal-common.h" #include "user/syscall-trace.h" +/* BSD independent syscall shims */ +#include "bsd-socket.h" #include "bsd-file.h" #include "bsd-proc.h" @@ -508,6 +510,25 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_freebsd_sysarch (cpu_env, arg1, arg2);break ; +/* +* socket related system calls +*/ +case TARGET_FREEBSD_NR_accept:/* accept(2) */ + ret =do_bsd_accept (arg1, arg2, arg3); +break ; + +case TARGET_FREEBSD_NR_bind:/* bind(2) */ + ret =do_bsd_bind (arg1, arg2, arg3); +break ; + +case TARGET_FREEBSD_NR_connect:/* connect(2) */ + ret =do_bsd_connect (arg1, arg2, arg3); +break ; + +case TARGET_FREEBSD_NR_getpeername:/* getpeername(2) */ + ret =do_bsd_getpeername (arg1, arg2, arg3); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num);ret = -TARGET_ENOSYS;--
2.40.0