* [PATCH 01/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 [PATCH 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project Karim Taha
@ 2023-04-21 5:22 ` Karim Taha
2023-04-21 7:17 ` Daniel P. Berrangé
2023-04-21 5:22 ` [PATCH 02/11] " Karim Taha
` (9 subsequent siblings)
10 siblings, 1 reply; 18+ messages in thread
From: Karim Taha @ 2023-04-21 5:22 UTC (permalink / raw)
To: qemu-devel; +Cc: imp
From: Warner Losh <imp@bsdimp.com>
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(-)
diff --git a/bsd-user/main.c b/bsd-user/main.c
index babc3b009b..afdc1b5f3c 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -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.
--
2.40.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH 01/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 ` [PATCH 01/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com> Karim Taha
@ 2023-04-21 7:17 ` Daniel P. Berrangé
2023-04-21 16:56 ` Karim Taha
0 siblings, 1 reply; 18+ messages in thread
From: Daniel P. Berrangé @ 2023-04-21 7:17 UTC (permalink / raw)
To: Karim Taha; +Cc: qemu-devel, imp
On Fri, Apr 21, 2023 at 07:22:45AM +0200, Karim Taha wrote:
> From: Warner Losh <imp@bsdimp.com>
>
> 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
This commit message is all incorrectly structured I'm afraid.
There needs to a short 1 line summary, then a blank line,
then the full commit description text, then a blank line,
then the Signed-off-by tag(s).
Also if you're sending work done by Warner (as the From
tag suggests), then we would expect to see Warner's own
Signed-off-by tag, in addition to your own Signed-off-by.
> ---
> bsd-user/main.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/bsd-user/main.c b/bsd-user/main.c
> index babc3b009b..afdc1b5f3c 100644
> --- a/bsd-user/main.c
> +++ b/bsd-user/main.c
> @@ -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.
> --
> 2.40.0
>
>
With regards,
Daniel
--
|: 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 :|
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 01/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 7:17 ` Daniel P. Berrangé
@ 2023-04-21 16:56 ` Karim Taha
2023-04-21 17:21 ` Alex Bennée
0 siblings, 1 reply; 18+ messages in thread
From: Karim Taha @ 2023-04-21 16:56 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: qemu-devel, Warner Losh
[-- Attachment #1: Type: text/plain, Size: 2421 bytes --]
On Fri, Apr 21, 2023 at 9:17 AM Daniel P. Berrangé <berrange@redhat.com>
wrote:
> On Fri, Apr 21, 2023 at 07:22:45AM +0200, Karim Taha wrote:
> > From: Warner Losh <imp@bsdimp.com>
> >
> > 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
>
> This commit message is all incorrectly structured I'm afraid.
>
> There needs to a short 1 line summary, then a blank line,
> then the full commit description text, then a blank line,
> then the Signed-off-by tag(s).
>
> Also if you're sending work done by Warner (as the From
> tag suggests), then we would expect to see Warner's own
> Signed-off-by tag, in addition to your own Signed-off-by.
>
> > ---
> > bsd-user/main.c | 16 +++++++++++++++-
> > 1 file changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/bsd-user/main.c b/bsd-user/main.c
> > index babc3b009b..afdc1b5f3c 100644
> > --- a/bsd-user/main.c
> > +++ b/bsd-user/main.c
> > @@ -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.
> > --
> > 2.40.0
> >
> >
>
> With regards,
> Daniel
> --
> |: 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 :|
>
>
Alright, thanks for the commit formatting tips, I resent the patch series,
with my signed off by tag and the author signed off by tags as well.
Best regards,
Karim
[-- Attachment #2: Type: text/html, Size: 3608 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 01/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 16:56 ` Karim Taha
@ 2023-04-21 17:21 ` Alex Bennée
2023-04-21 22:40 ` Karim Taha
0 siblings, 1 reply; 18+ messages in thread
From: Alex Bennée @ 2023-04-21 17:21 UTC (permalink / raw)
To: Karim Taha; +Cc: Daniel P. Berrangé, Warner Losh, qemu-devel
Karim Taha <kariem.taha2.7@gmail.com> writes:
> On Fri, Apr 21, 2023 at 9:17 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Fri, Apr 21, 2023 at 07:22:45AM +0200, Karim Taha wrote:
> > From: Warner Losh <imp@bsdimp.com>
> >
> > 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
>
> This commit message is all incorrectly structured I'm afraid.
>
> There needs to a short 1 line summary, then a blank line,
> then the full commit description text, then a blank line,
> then the Signed-off-by tag(s).
>
> Also if you're sending work done by Warner (as the From
> tag suggests), then we would expect to see Warner's own
> Signed-off-by tag, in addition to your own Signed-off-by.
<snip>
>
> Alright, thanks for the commit formatting tips, I resent the patch series, with my signed off by tag and the
> author signed off by tags as well.
Hmm something has gone wrong. Was this sent with a plain git-send-email
or using a tool like git-publish?
Can you point to a branch?
>
> Best regards,
> Karim
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 01/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 17:21 ` Alex Bennée
@ 2023-04-21 22:40 ` Karim Taha
[not found] ` <CANCZdfr=32YFV0mHJxJn0F3aNUQT5YccQdRYdtq1au6BFF8WHw@mail.gmail.com>
0 siblings, 1 reply; 18+ messages in thread
From: Karim Taha @ 2023-04-21 22:40 UTC (permalink / raw)
To: Alex Bennée; +Cc: Daniel P. Berrangé, Warner Losh, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1442 bytes --]
It was sent with git-publish, what do you mean by pointing to a branch?
On Fri, Apr 21, 2023 at 7:22 PM Alex Bennée <alex.bennee@linaro.org> wrote:
>
> Karim Taha <kariem.taha2.7@gmail.com> writes:
>
> > On Fri, Apr 21, 2023 at 9:17 AM Daniel P. Berrangé <berrange@redhat.com>
> wrote:
> >
> > On Fri, Apr 21, 2023 at 07:22:45AM +0200, Karim Taha wrote:
> > > From: Warner Losh <imp@bsdimp.com>
> > >
> > > 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
> >
> > This commit message is all incorrectly structured I'm afraid.
> >
> > There needs to a short 1 line summary, then a blank line,
> > then the full commit description text, then a blank line,
> > then the Signed-off-by tag(s).
> >
> > Also if you're sending work done by Warner (as the From
> > tag suggests), then we would expect to see Warner's own
> > Signed-off-by tag, in addition to your own Signed-off-by.
> <snip>
> >
> > Alright, thanks for the commit formatting tips, I resent the patch
> series, with my signed off by tag and the
> > author signed off by tags as well.
>
> Hmm something has gone wrong. Was this sent with a plain git-send-email
> or using a tool like git-publish?
>
> Can you point to a branch?
>
> >
> > Best regards,
> > Karim
>
>
> --
> Alex Bennée
> Virtualisation Tech Lead @ Linaro
>
[-- Attachment #2: Type: text/html, Size: 2094 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 02/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 [PATCH 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project Karim Taha
2023-04-21 5:22 ` [PATCH 01/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com> Karim Taha
@ 2023-04-21 5:22 ` Karim Taha
2023-04-21 5:22 ` [PATCH 03/11] " Karim Taha
` (8 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Karim Taha @ 2023-04-21 5:22 UTC (permalink / raw)
To: qemu-devel; +Cc: imp, Stacey Son
From: Stacey Son <sson@FreeBSD.org>
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(+)
diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h
index b6d113d24a..f041245792 100644
--- a/bsd-user/syscall_defs.h
+++ b/bsd-user/syscall_defs.h
@@ -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) \
{ \
--
2.40.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 03/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 [PATCH 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project Karim Taha
2023-04-21 5:22 ` [PATCH 01/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com> Karim Taha
2023-04-21 5:22 ` [PATCH 02/11] " Karim Taha
@ 2023-04-21 5:22 ` Karim Taha
2023-04-21 5:22 ` [PATCH 04/11] " Karim Taha
` (7 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Karim Taha @ 2023-04-21 5:22 UTC (permalink / raw)
To: qemu-devel; +Cc: imp, Sean Bruno, Kyle Evans
From: Sean Bruno <sbruno@FreeBSD.org>
Co-authored-by: Kyle Evans <kevans@FreeBSD.org>
---
bsd-user/syscall_defs.h | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h
index f041245792..b594fafecc 100644
--- a/bsd-user/syscall_defs.h
+++ b/bsd-user/syscall_defs.h
@@ -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
*/
--
2.40.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 04/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 [PATCH 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project Karim Taha
` (2 preceding siblings ...)
2023-04-21 5:22 ` [PATCH 03/11] " Karim Taha
@ 2023-04-21 5:22 ` Karim Taha
2023-04-21 5:22 ` [PATCH 05/11] " Karim Taha
` (6 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Karim Taha @ 2023-04-21 5:22 UTC (permalink / raw)
To: qemu-devel; +Cc: imp, Stacey Son
From: Stacey Son <sson@FreeBSD.org>
added 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
diff --git a/bsd-user/qemu-bsd.h b/bsd-user/qemu-bsd.h
new file mode 100644
index 0000000000..a052688596
--- /dev/null
+++ b/bsd-user/qemu-bsd.h
@@ -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 */
--
2.40.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 05/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 [PATCH 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project Karim Taha
` (3 preceding siblings ...)
2023-04-21 5:22 ` [PATCH 04/11] " Karim Taha
@ 2023-04-21 5:22 ` Karim Taha
2023-04-21 5:22 ` [PATCH 06/11] " Karim Taha
` (5 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Karim Taha @ 2023-04-21 5:22 UTC (permalink / raw)
To: qemu-devel; +Cc: imp, Stacey Son
From: Stacey Son <sson@FreeBSD.org>
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
diff --git a/bsd-user/bsd-socket.c b/bsd-user/bsd-socket.c
new file mode 100644
index 0000000000..8a5e44444d
--- /dev/null
+++ b/bsd-user/bsd-socket.c
@@ -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;
+}
--
2.40.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 06/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 [PATCH 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project Karim Taha
` (4 preceding siblings ...)
2023-04-21 5:22 ` [PATCH 05/11] " Karim Taha
@ 2023-04-21 5:22 ` Karim Taha
2023-04-21 5:22 ` [PATCH 07/11] " Karim Taha
` (4 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Karim Taha @ 2023-04-21 5:22 UTC (permalink / raw)
To: qemu-devel; +Cc: imp, Karim Taha
From: Karim Taha <kariem.taha2.7@gmail.com>
add bsd-user/bsd-socket.c to meson.build
---
bsd-user/meson.build | 1 +
1 file changed, 1 insertion(+)
diff --git a/bsd-user/meson.build b/bsd-user/meson.build
index 5243122fc5..f648bd3554 100644
--- a/bsd-user/meson.build
+++ b/bsd-user/meson.build
@@ -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',
--
2.40.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 07/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 [PATCH 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project Karim Taha
` (5 preceding siblings ...)
2023-04-21 5:22 ` [PATCH 06/11] " Karim Taha
@ 2023-04-21 5:22 ` Karim Taha
2023-04-21 5:22 ` [PATCH 08/11] " Karim Taha
` (3 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Karim Taha @ 2023-04-21 5:22 UTC (permalink / raw)
To: qemu-devel; +Cc: imp, Stacey Son
From: Stacey Son <sson@FreeBSD.org>
added bsd-user/bsd-socket.h, which contains the implementation of 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
diff --git a/bsd-user/bsd-socket.h b/bsd-user/bsd-socket.h
new file mode 100644
index 0000000000..7da4cf11a0
--- /dev/null
+++ b/bsd-user/bsd-socket.h
@@ -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 */
--
2.40.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 08/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 [PATCH 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project Karim Taha
` (6 preceding siblings ...)
2023-04-21 5:22 ` [PATCH 07/11] " Karim Taha
@ 2023-04-21 5:22 ` Karim Taha
2023-04-21 5:22 ` [PATCH 09/11] " Karim Taha
` (2 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Karim Taha @ 2023-04-21 5:22 UTC (permalink / raw)
To: qemu-devel; +Cc: imp, Stacey Son
From: Stacey Son <sson@FreeBSD.org>
added the connect(2) syscall to bsd-user/bsd-socket.h.
---
bsd-user/bsd-socket.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/bsd-user/bsd-socket.h b/bsd-user/bsd-socket.h
index 7da4cf11a0..f191f22d63 100644
--- a/bsd-user/bsd-socket.h
+++ b/bsd-user/bsd-socket.h
@@ -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 */
--
2.40.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 09/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 [PATCH 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project Karim Taha
` (7 preceding siblings ...)
2023-04-21 5:22 ` [PATCH 08/11] " Karim Taha
@ 2023-04-21 5:22 ` Karim Taha
2023-04-21 5:22 ` [PATCH 10/11] " Karim Taha
2023-04-21 5:22 ` [PATCH 11/11] " Karim Taha
10 siblings, 0 replies; 18+ messages in thread
From: Karim Taha @ 2023-04-21 5:22 UTC (permalink / raw)
To: qemu-devel; +Cc: imp, Stacey Son
From: Stacey Son <sson@FreeBSD.org>
added the accept(2) syscall to bsd-user/bsd-socket.h.
---
bsd-user/bsd-socket.h | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/bsd-user/bsd-socket.h b/bsd-user/bsd-socket.h
index f191f22d63..f748266730 100644
--- a/bsd-user/bsd-socket.h
+++ b/bsd-user/bsd-socket.h
@@ -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 */
--
2.40.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 10/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 [PATCH 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project Karim Taha
` (8 preceding siblings ...)
2023-04-21 5:22 ` [PATCH 09/11] " Karim Taha
@ 2023-04-21 5:22 ` Karim Taha
2023-04-21 5:22 ` [PATCH 11/11] " Karim Taha
10 siblings, 0 replies; 18+ messages in thread
From: Karim Taha @ 2023-04-21 5:22 UTC (permalink / raw)
To: qemu-devel; +Cc: imp, Stacey Son
From: Stacey Son <sson@FreeBSD.org>
added the getpeername(2) syscall to bsd-user/bsd-socket.h.
---
bsd-user/bsd-socket.h | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/bsd-user/bsd-socket.h b/bsd-user/bsd-socket.h
index f748266730..16fae3752a 100644
--- a/bsd-user/bsd-socket.h
+++ b/bsd-user/bsd-socket.h
@@ -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 */
--
2.40.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 11/11] Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
2023-04-21 5:22 [PATCH 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project Karim Taha
` (9 preceding siblings ...)
2023-04-21 5:22 ` [PATCH 10/11] " Karim Taha
@ 2023-04-21 5:22 ` Karim Taha
10 siblings, 0 replies; 18+ messages in thread
From: Karim Taha @ 2023-04-21 5:22 UTC (permalink / raw)
To: qemu-devel; +Cc: imp
From: Warner Losh <imp@bsdimp.com>
added the bind(2), connect(2), accept(2), getpeername(2) syscalls to
freebsd_syscall function defined in bsd-user/freebsd/os-syscall.c
---
bsd-user/freebsd/os-syscall.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index c8f998ecec..7f29196a05 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -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
^ permalink raw reply related [flat|nested] 18+ messages in thread