* [PATCH v2 01/19] bsd-user: Make print_* public
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 02/19] bsd-user: Ifdef a few MAP_ constants for NetBSD / OpenBSD Warner Losh
` (17 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Richard Henderson
Make these functions public. Due to coming restructuring, we'll need to
call these from *bsd/os-syscall.c. Add declarations to qemu.h.
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/qemu.h | 20 ++++++++++++++++++++
bsd-user/strace.c | 29 +++++++++++++----------------
2 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 41d84e0b81b..22e16816a9e 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -211,6 +211,26 @@ print_openbsd_syscall(int num,
abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6);
void print_openbsd_syscall_ret(int num, abi_long ret);
+void print_execve(const struct syscallname *name, abi_long arg1,
+ abi_long arg2, abi_long arg3, abi_long arg4,
+ abi_long arg5, abi_long arg6);
+void print_ioctl(const struct syscallname *name,
+ abi_long arg1, abi_long arg2, abi_long arg3,
+ abi_long arg4, abi_long arg5, abi_long arg6);
+void print_sysarch(const struct syscallname *name, abi_long arg1,
+ abi_long arg2, abi_long arg3, abi_long arg4,
+ abi_long arg5, abi_long arg6);
+void print_sysctl(const struct syscallname *name, abi_long arg1,
+ abi_long arg2, abi_long arg3, abi_long arg4,
+ abi_long arg5, abi_long arg6);
+void print_syscall(int num, const struct syscallname *scnames,
+ unsigned int nscnames, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5,
+ abi_long arg6);
+void print_syscall_ret(int num, abi_long ret,
+ const struct syscallname *scnames,
+ unsigned int nscnames);
+void print_syscall_ret_addr(const struct syscallname *name, abi_long ret);
/**
* print_taken_signal:
* @target_signum: target signal being taken
diff --git a/bsd-user/strace.c b/bsd-user/strace.c
index 96499751eb0..e45909b8688 100644
--- a/bsd-user/strace.c
+++ b/bsd-user/strace.c
@@ -49,7 +49,7 @@ print_raw_param(const char *fmt, abi_long param, int last)
gemu_log(format, param);
}
-static void print_sysctl(const struct syscallname *name, abi_long arg1,
+void print_sysctl(const struct syscallname *name, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5,
abi_long arg6)
{
@@ -71,9 +71,8 @@ static void print_sysctl(const struct syscallname *name, abi_long arg1,
(uint32_t)arg2, arg3, arg4, arg5, arg6);
}
-static void print_execve(const struct syscallname *name, abi_long arg1,
- abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5,
- abi_long arg6)
+void print_execve(const struct syscallname *name, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
{
abi_ulong arg_ptr_addr;
char *s;
@@ -105,9 +104,8 @@ static void print_execve(const struct syscallname *name, abi_long arg1,
gemu_log("NULL})");
}
-static void print_ioctl(const struct syscallname *name,
- abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4,
- abi_long arg5, abi_long arg6)
+void print_ioctl(const struct syscallname *name, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
{
/* Decode the ioctl request */
gemu_log("%s(%d, 0x%0lx { IO%s%s GRP:0x%x('%c') CMD:%d LEN:%d }, 0x"
@@ -124,9 +122,8 @@ static void print_ioctl(const struct syscallname *name,
arg3);
}
-static void print_sysarch(const struct syscallname *name, abi_long arg1,
- abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5,
- abi_long arg6)
+void print_sysarch(const struct syscallname *name, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
{
/* This is os dependent. */
do_os_print_sysarch(name, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -136,7 +133,7 @@ static void print_sysarch(const struct syscallname *name, abi_long arg1,
* Variants for the return value output function
*/
-static void print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
+void print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
{
if (ret == -1) {
gemu_log(" = -1 errno=%d (%s)\n", errno, strerror(errno));
@@ -159,9 +156,9 @@ static const struct syscallname openbsd_scnames[] = {
#include "openbsd/strace.list"
};
-static void print_syscall(int num, const struct syscallname *scnames,
- unsigned int nscnames, abi_long arg1, abi_long arg2, abi_long arg3,
- abi_long arg4, abi_long arg5, abi_long arg6)
+void print_syscall(int num, const struct syscallname *scnames,
+ unsigned int nscnames, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
{
unsigned int i;
const char *format="%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
@@ -190,8 +187,8 @@ static void print_syscall(int num, const struct syscallname *scnames,
gemu_log("Unknown syscall %d\n", num);
}
-static void print_syscall_ret(int num, abi_long ret,
- const struct syscallname *scnames, unsigned int nscnames)
+void print_syscall_ret(int num, abi_long ret, const struct syscallname *scnames,
+ unsigned int nscnames)
{
unsigned int i;
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 02/19] bsd-user: Ifdef a few MAP_ constants for NetBSD / OpenBSD.
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
2023-04-10 18:20 ` [PATCH v2 01/19] bsd-user: Make print_* public Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-11 1:31 ` Richard Henderson
2023-04-10 18:20 ` [PATCH v2 03/19] bsd-user: Cleanup style Warner Losh
` (16 subsequent siblings)
18 siblings, 1 reply; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud
MAP_GUARD, MAP_EXCL, and MAP_NOCORE are FreeBSD only. Define them to be
0 if they aren't defined, and rely on the compiler to optimize away
sections not relevant. Added only to the top of mmap.c since that's the
only place we need this.
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
bsd-user/mmap.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index d6c5a344c9b..2d91e8e8826 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -20,6 +20,20 @@
#include "qemu.h"
+/*
+ * Not all the BSDs have all the MAP flags, so define some of them to 0 here and
+ * rely on the compiler optimizing always false conditions away.
+ */
+#ifndef MAP_GUARD
+#define MAP_GUARD 0
+#endif
+#ifndef MAP_EXCL
+#define MAP_EXCL 0
+#endif
+#ifndef MAP_NOCORE
+#define MAP_NOCORE 0
+#endif
+
static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
static __thread int mmap_lock_count;
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2 02/19] bsd-user: Ifdef a few MAP_ constants for NetBSD / OpenBSD.
2023-04-10 18:20 ` [PATCH v2 02/19] bsd-user: Ifdef a few MAP_ constants for NetBSD / OpenBSD Warner Losh
@ 2023-04-11 1:31 ` Richard Henderson
0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2023-04-11 1:31 UTC (permalink / raw)
To: Warner Losh, qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith, reinoud
On 4/10/23 11:20, Warner Losh wrote:
> MAP_GUARD, MAP_EXCL, and MAP_NOCORE are FreeBSD only. Define them to be
> 0 if they aren't defined, and rely on the compiler to optimize away
> sections not relevant. Added only to the top of mmap.c since that's the
> only place we need this.
>
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
> bsd-user/mmap.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 03/19] bsd-user: Cleanup style.
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
2023-04-10 18:20 ` [PATCH v2 01/19] bsd-user: Make print_* public Warner Losh
2023-04-10 18:20 ` [PATCH v2 02/19] bsd-user: Ifdef a few MAP_ constants for NetBSD / OpenBSD Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 04/19] bsd-user: Move system FreeBSD call table to freebsd/os-syscall.c Warner Losh
` (15 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Richard Henderson
The only diffs between bsd-user fork and qemu upstream is style. Make
mmap.c pass checkpatch.pl.
Signed-off-by: Warner Losh <imp@bsdimp.com>
Acked-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/mmap.c | 91 ++++++++++++++++++++++++++++++++-----------------
1 file changed, 60 insertions(+), 31 deletions(-)
diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index 2d91e8e8826..d0ade1b52f3 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -59,17 +59,19 @@ bool have_mmap_lock(void)
/* Grab lock to make sure things are in a consistent state after fork(). */
void mmap_fork_start(void)
{
- if (mmap_lock_count)
+ if (mmap_lock_count) {
abort();
+ }
pthread_mutex_lock(&mmap_mutex);
}
void mmap_fork_end(int child)
{
- if (child)
+ if (child) {
pthread_mutex_init(&mmap_mutex, NULL);
- else
+ } else {
pthread_mutex_unlock(&mmap_mutex);
+ }
}
/* NOTE: all the constants are the HOST ones, but addresses are target. */
@@ -83,15 +85,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
prot & PROT_READ ? 'r' : '-',
prot & PROT_WRITE ? 'w' : '-',
prot & PROT_EXEC ? 'x' : '-');
- if ((start & ~TARGET_PAGE_MASK) != 0)
+ if ((start & ~TARGET_PAGE_MASK) != 0) {
return -EINVAL;
+ }
len = TARGET_PAGE_ALIGN(len);
end = start + len;
- if (end < start)
+ if (end < start) {
return -EINVAL;
+ }
prot &= PROT_READ | PROT_WRITE | PROT_EXEC;
- if (len == 0)
+ if (len == 0) {
return 0;
+ }
mmap_lock();
host_start = start & qemu_host_page_mask;
@@ -110,8 +115,9 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
}
ret = mprotect(g2h_untagged(host_start),
qemu_host_page_size, prot1 & PAGE_BITS);
- if (ret != 0)
+ if (ret != 0) {
goto error;
+ }
host_start += qemu_host_page_size;
}
if (end < host_end) {
@@ -121,16 +127,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
}
ret = mprotect(g2h_untagged(host_end - qemu_host_page_size),
qemu_host_page_size, prot1 & PAGE_BITS);
- if (ret != 0)
+ if (ret != 0) {
goto error;
+ }
host_end -= qemu_host_page_size;
}
/* handle the pages in the middle */
if (host_start < host_end) {
ret = mprotect(g2h_untagged(host_start), host_end - host_start, prot);
- if (ret != 0)
+ if (ret != 0) {
goto error;
+ }
}
page_set_flags(start, start + len, prot | PAGE_VALID);
mmap_unlock();
@@ -175,31 +183,37 @@ static int mmap_frag(abi_ulong real_start,
/* get the protection of the target pages outside the mapping */
prot1 = 0;
for (addr = real_start; addr < real_end; addr++) {
- if (addr < start || addr >= end)
+ if (addr < start || addr >= end) {
prot1 |= page_get_flags(addr);
+ }
}
if (prot1 == 0) {
/* no page was there, so we allocate one. See also above. */
void *p = mmap(host_start, qemu_host_page_size, prot,
flags | ((fd != -1) ? MAP_ANON : 0), -1, 0);
- if (p == MAP_FAILED)
+ if (p == MAP_FAILED) {
return -1;
+ }
prot1 = prot;
}
prot1 &= PAGE_BITS;
prot_new = prot | prot1;
if (fd != -1) {
- /* msync() won't work here, so we return an error if write is
- possible while it is a shared mapping */
+ /*
+ * msync() won't work here, so we return an error if write is
+ * possible while it is a shared mapping
+ */
if ((flags & TARGET_BSD_MAP_FLAGMASK) == MAP_SHARED &&
- (prot & PROT_WRITE))
+ (prot & PROT_WRITE)) {
return -1;
+ }
/* adjust protection to be able to read */
- if (!(prot1 & PROT_WRITE))
+ if (!(prot1 & PROT_WRITE)) {
mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE);
+ }
/* read the corresponding file data */
if (pread(fd, g2h_untagged(start), end - start, offset) == -1) {
@@ -207,8 +221,9 @@ static int mmap_frag(abi_ulong real_start,
}
/* put final protection */
- if (prot_new != (prot1 | PROT_WRITE))
+ if (prot_new != (prot1 | PROT_WRITE)) {
mprotect(host_start, qemu_host_page_size, prot_new);
+ }
} else {
if (prot_new != prot1) {
mprotect(host_start, qemu_host_page_size, prot_new);
@@ -560,8 +575,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
*/
p = mmap(g2h_untagged(start), host_len, prot,
flags | MAP_FIXED | ((fd != -1) ? MAP_ANON : 0), -1, 0);
- if (p == MAP_FAILED)
+ if (p == MAP_FAILED) {
goto fail;
+ }
/* update start so that it points to the file position at 'offset' */
host_start = (unsigned long)p;
if (fd != -1) {
@@ -610,8 +626,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
retaddr = target_mmap(start, len, prot | PROT_WRITE,
MAP_FIXED | MAP_PRIVATE | MAP_ANON,
-1, 0);
- if (retaddr == -1)
+ if (retaddr == -1) {
goto fail;
+ }
if (pread(fd, g2h_untagged(start), len, offset) == -1) {
goto fail;
}
@@ -634,14 +651,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
/* one single host page */
ret = mmap_frag(real_start, start, end,
prot, flags, fd, offset);
- if (ret == -1)
+ if (ret == -1) {
goto fail;
+ }
goto the_end1;
}
ret = mmap_frag(real_start, start, real_start + qemu_host_page_size,
prot, flags, fd, offset);
- if (ret == -1)
+ if (ret == -1) {
goto fail;
+ }
real_start += qemu_host_page_size;
}
/* handle the end of the mapping */
@@ -650,8 +669,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
real_end - qemu_host_page_size, end,
prot, flags, fd,
offset + real_end - qemu_host_page_size - start);
- if (ret == -1)
+ if (ret == -1) {
goto fail;
+ }
real_end -= qemu_host_page_size;
}
@@ -659,14 +679,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
if (real_start < real_end) {
void *p;
unsigned long offset1;
- if (flags & MAP_ANON)
+ if (flags & MAP_ANON) {
offset1 = 0;
- else
+ } else {
offset1 = offset + real_start - start;
+ }
p = mmap(g2h_untagged(real_start), real_end - real_start,
prot, flags, fd, offset1);
- if (p == MAP_FAILED)
+ if (p == MAP_FAILED) {
goto fail;
+ }
}
}
the_end1:
@@ -736,11 +758,13 @@ int target_munmap(abi_ulong start, abi_ulong len)
TARGET_ABI_FMT_lx "\n",
start, len);
#endif
- if (start & ~TARGET_PAGE_MASK)
+ if (start & ~TARGET_PAGE_MASK) {
return -EINVAL;
+ }
len = TARGET_PAGE_ALIGN(len);
- if (len == 0)
+ if (len == 0) {
return -EINVAL;
+ }
mmap_lock();
end = start + len;
real_start = start & qemu_host_page_mask;
@@ -758,16 +782,18 @@ int target_munmap(abi_ulong start, abi_ulong len)
}
end = real_end;
}
- if (prot != 0)
+ if (prot != 0) {
real_start += qemu_host_page_size;
+ }
}
if (end < real_end) {
prot = 0;
for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
prot |= page_get_flags(addr);
}
- if (prot != 0)
+ if (prot != 0) {
real_end -= qemu_host_page_size;
+ }
}
ret = 0;
@@ -791,14 +817,17 @@ int target_msync(abi_ulong start, abi_ulong len, int flags)
{
abi_ulong end;
- if (start & ~TARGET_PAGE_MASK)
+ if (start & ~TARGET_PAGE_MASK) {
return -EINVAL;
+ }
len = TARGET_PAGE_ALIGN(len);
end = start + len;
- if (end < start)
+ if (end < start) {
return -EINVAL;
- if (end == start)
+ }
+ if (end == start) {
return 0;
+ }
start &= qemu_host_page_mask;
return msync(g2h_untagged(start), end - start, flags);
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 04/19] bsd-user: Move system FreeBSD call table to freebsd/os-syscall.c
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (2 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 03/19] bsd-user: Cleanup style Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 05/19] bsd-user: Remove NetBSD specific syscall printing Warner Losh
` (14 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Richard Henderson
Move the system call table, and FreeBSD helper routines out of strace.c.
We do not support multiple BSD-types in one binary, so simplify things
by moving it.
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/freebsd/os-syscall.c | 19 +++++++++++++++++++
bsd-user/qemu.h | 5 -----
bsd-user/strace.c | 17 -----------------
3 files changed, 19 insertions(+), 22 deletions(-)
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index c8f998ecec1..354a38943e5 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -517,6 +517,25 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
return ret;
}
+static const struct syscallname freebsd_scnames[] = {
+#include "freebsd/strace.list"
+};
+
+static void print_freebsd_syscall(int num, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5,
+ abi_long arg6)
+{
+
+ print_syscall(num, freebsd_scnames, ARRAY_SIZE(freebsd_scnames), arg1, arg2,
+ arg3, arg4, arg5, arg6);
+}
+
+static void print_freebsd_syscall_ret(int num, abi_long ret)
+{
+
+ print_syscall_ret(num, ret, freebsd_scnames, ARRAY_SIZE(freebsd_scnames));
+}
+
/*
* do_freebsd_syscall() should always have a single exit point at the end so
* that actions, such as logging of syscall results, can be performed. This
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 22e16816a9e..c5240938da7 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -196,11 +196,6 @@ struct syscallname {
void (*result)(const struct syscallname *, abi_long);
};
-void
-print_freebsd_syscall(int num,
- abi_long arg1, abi_long arg2, abi_long arg3,
- abi_long arg4, abi_long arg5, abi_long arg6);
-void print_freebsd_syscall_ret(int num, abi_long ret);
void
print_netbsd_syscall(int num,
abi_long arg1, abi_long arg2, abi_long arg3,
diff --git a/bsd-user/strace.c b/bsd-user/strace.c
index e45909b8688..7d0117fd3cf 100644
--- a/bsd-user/strace.c
+++ b/bsd-user/strace.c
@@ -146,9 +146,6 @@ void print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
* An array of all of the syscalls we know about
*/
-static const struct syscallname freebsd_scnames[] = {
-#include "freebsd/strace.list"
-};
static const struct syscallname netbsd_scnames[] = {
#include "netbsd/strace.list"
};
@@ -212,20 +209,6 @@ void print_syscall_ret(int num, abi_long ret, const struct syscallname *scnames,
/*
* The public interface to this module.
*/
-void print_freebsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3,
- abi_long arg4, abi_long arg5, abi_long arg6)
-{
-
- print_syscall(num, freebsd_scnames, ARRAY_SIZE(freebsd_scnames), arg1, arg2,
- arg3, arg4, arg5, arg6);
-}
-
-void print_freebsd_syscall_ret(int num, abi_long ret)
-{
-
- print_syscall_ret(num, ret, freebsd_scnames, ARRAY_SIZE(freebsd_scnames));
-}
-
void print_netbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6)
{
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 05/19] bsd-user: Remove NetBSD specific syscall printing
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (3 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 04/19] bsd-user: Move system FreeBSD call table to freebsd/os-syscall.c Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 06/19] bsd-user: Remove OpenBSD " Warner Losh
` (13 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Richard Henderson
Nothing calls these routines now. In the bsd-user fork, though, they've
moved to netbsd/os-syscall.c, but those aren't ready for upstreaming.
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/qemu.h | 5 -----
bsd-user/strace.c | 17 -----------------
2 files changed, 22 deletions(-)
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index c5240938da7..cee02d2a0ea 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -196,11 +196,6 @@ struct syscallname {
void (*result)(const struct syscallname *, abi_long);
};
-void
-print_netbsd_syscall(int num,
- abi_long arg1, abi_long arg2, abi_long arg3,
- abi_long arg4, abi_long arg5, abi_long arg6);
-void print_netbsd_syscall_ret(int num, abi_long ret);
void
print_openbsd_syscall(int num,
abi_long arg1, abi_long arg2, abi_long arg3,
diff --git a/bsd-user/strace.c b/bsd-user/strace.c
index 7d0117fd3cf..8e76caa3c3f 100644
--- a/bsd-user/strace.c
+++ b/bsd-user/strace.c
@@ -146,9 +146,6 @@ void print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
* An array of all of the syscalls we know about
*/
-static const struct syscallname netbsd_scnames[] = {
-#include "netbsd/strace.list"
-};
static const struct syscallname openbsd_scnames[] = {
#include "openbsd/strace.list"
};
@@ -209,20 +206,6 @@ void print_syscall_ret(int num, abi_long ret, const struct syscallname *scnames,
/*
* The public interface to this module.
*/
-void print_netbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3,
- abi_long arg4, abi_long arg5, abi_long arg6)
-{
-
- print_syscall(num, netbsd_scnames, ARRAY_SIZE(netbsd_scnames),
- arg1, arg2, arg3, arg4, arg5, arg6);
-}
-
-void print_netbsd_syscall_ret(int num, abi_long ret)
-{
-
- print_syscall_ret(num, ret, netbsd_scnames, ARRAY_SIZE(netbsd_scnames));
-}
-
void print_openbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6)
{
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 06/19] bsd-user: Remove OpenBSD specific syscall printing
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (4 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 05/19] bsd-user: Remove NetBSD specific syscall printing Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 07/19] bsd-user: Move system call include to os-syscall.h Warner Losh
` (12 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Richard Henderson
Nothing calls these routines now. In the bsd-user fork, though, they've
moved to openbsd/os-syscall.c, but those aren't ready for upstreaming.
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/qemu.h | 5 -----
bsd-user/strace.c | 25 -------------------------
2 files changed, 30 deletions(-)
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index cee02d2a0ea..49468734d44 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -196,11 +196,6 @@ struct syscallname {
void (*result)(const struct syscallname *, abi_long);
};
-void
-print_openbsd_syscall(int num,
- abi_long arg1, abi_long arg2, abi_long arg3,
- abi_long arg4, abi_long arg5, abi_long arg6);
-void print_openbsd_syscall_ret(int num, abi_long ret);
void print_execve(const struct syscallname *name, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5, abi_long arg6);
diff --git a/bsd-user/strace.c b/bsd-user/strace.c
index 8e76caa3c3f..b827acb2477 100644
--- a/bsd-user/strace.c
+++ b/bsd-user/strace.c
@@ -142,14 +142,6 @@ void print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
}
}
-/*
- * An array of all of the syscalls we know about
- */
-
-static const struct syscallname openbsd_scnames[] = {
-#include "openbsd/strace.list"
-};
-
void print_syscall(int num, const struct syscallname *scnames,
unsigned int nscnames, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
@@ -203,23 +195,6 @@ void print_syscall_ret(int num, abi_long ret, const struct syscallname *scnames,
}
}
-/*
- * The public interface to this module.
- */
-void print_openbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3,
- abi_long arg4, abi_long arg5, abi_long arg6)
-{
-
- print_syscall(num, openbsd_scnames, ARRAY_SIZE(openbsd_scnames), arg1, arg2,
- arg3, arg4, arg5, arg6);
-}
-
-void print_openbsd_syscall_ret(int num, abi_long ret)
-{
-
- print_syscall_ret(num, ret, openbsd_scnames, ARRAY_SIZE(openbsd_scnames));
-}
-
static void
print_signal(abi_ulong arg, int last)
{
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 07/19] bsd-user: Move system call include to os-syscall.h
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (5 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 06/19] bsd-user: Remove OpenBSD " Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 08/19] bsd-user: Remove useless mmap definitions Warner Losh
` (11 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Richard Henderson
Move the include of the system calls to os-syscall.h. Include that from
syscall_defs.h. Use target_time_t and target_suseconds_t instead of the
variant that has _freebsd_ in the name. Define these for OpenBSD and
NetBSD based on comments in the file.
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/freebsd/os-syscall.h | 21 +++++++++++++++++++++
bsd-user/netbsd/os-syscall.h | 16 ++++++++++++++++
bsd-user/openbsd/os-syscall.h | 16 ++++++++++++++++
bsd-user/syscall_defs.h | 33 ++++-----------------------------
4 files changed, 57 insertions(+), 29 deletions(-)
create mode 100644 bsd-user/freebsd/os-syscall.h
create mode 100644 bsd-user/netbsd/os-syscall.h
create mode 100644 bsd-user/openbsd/os-syscall.h
diff --git a/bsd-user/freebsd/os-syscall.h b/bsd-user/freebsd/os-syscall.h
new file mode 100644
index 00000000000..1f2c0acb1c5
--- /dev/null
+++ b/bsd-user/freebsd/os-syscall.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2023 Warner Losh <imp@bsdimp.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * OS-Specific portion of syscall_defs.h
+ */
+
+#include "freebsd/syscall_nr.h"
+
+/*
+ * FreeBSD uses a 64bits time_t except on i386 so we have to add a special case
+ * here.
+ */
+#if (!defined(TARGET_I386))
+typedef int64_t target_time_t;
+#else
+typedef int32_t target_time_t;
+#endif
+
+typedef abi_long target_suseconds_t;
diff --git a/bsd-user/netbsd/os-syscall.h b/bsd-user/netbsd/os-syscall.h
new file mode 100644
index 00000000000..7507350d8d2
--- /dev/null
+++ b/bsd-user/netbsd/os-syscall.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2023 Warner Losh <imp@bsdimp.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * OS-Specific portion of syscall_defs.h
+ */
+
+#include "netbsd/syscall_nr.h"
+
+/*
+ * time_t seems to be very inconsistly defined for the different *BSD's...
+ *
+ * NetBSD always uses int64_t.
+ */
+typedef int64_t target_time_t;
diff --git a/bsd-user/openbsd/os-syscall.h b/bsd-user/openbsd/os-syscall.h
new file mode 100644
index 00000000000..191a76fa935
--- /dev/null
+++ b/bsd-user/openbsd/os-syscall.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2023 Warner Losh <imp@bsdimp.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * OS-Specific portion of syscall_defs.h
+ */
+
+#include "openbsd/syscall_nr.h"
+
+/*
+ * time_t seems to be very inconsistly defined for the different *BSD's...
+ *
+ * OpenBSD always uses int.
+ */
+typedef int target_time_t;
diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h
index b6d113d24a7..489d3a2e292 100644
--- a/bsd-user/syscall_defs.h
+++ b/bsd-user/syscall_defs.h
@@ -25,30 +25,7 @@
#include "errno_defs.h"
-#include "freebsd/syscall_nr.h"
-#include "netbsd/syscall_nr.h"
-#include "openbsd/syscall_nr.h"
-
-/*
- * machine/_types.h
- * or x86/_types.h
- */
-
-/*
- * time_t seems to be very inconsistly defined for the different *BSD's...
- *
- * FreeBSD uses a 64bits time_t except on i386
- * so we have to add a special case here.
- *
- * On NetBSD time_t is always defined as an int64_t. On OpenBSD time_t
- * is always defined as an int.
- *
- */
-#if (!defined(TARGET_I386))
-typedef int64_t target_freebsd_time_t;
-#else
-typedef int32_t target_freebsd_time_t;
-#endif
+#include "os-syscall.h"
struct target_iovec {
abi_long iov_base; /* Starting address */
@@ -98,11 +75,9 @@ struct target_iovec {
* sys/timex.h
*/
-typedef abi_long target_freebsd_suseconds_t;
-
/* compare to sys/timespec.h */
struct target_freebsd_timespec {
- target_freebsd_time_t tv_sec; /* seconds */
+ target_time_t tv_sec; /* seconds */
abi_long tv_nsec; /* and nanoseconds */
#if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
abi_long _pad;
@@ -120,8 +95,8 @@ struct target_freebsd__umtx_time {
};
struct target_freebsd_timeval {
- target_freebsd_time_t tv_sec; /* seconds */
- target_freebsd_suseconds_t tv_usec;/* and microseconds */
+ target_time_t tv_sec; /* seconds */
+ target_suseconds_t tv_usec;/* and microseconds */
#if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
abi_long _pad;
#endif
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 08/19] bsd-user: Remove useless mmap definitions
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (6 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 07/19] bsd-user: Move system call include to os-syscall.h Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 09/19] bsd-user: h2g_rusage Warner Losh
` (10 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Richard Henderson
On BSD, all architectures have the same mmap flags. Since we don't
translate the flags, we don't need these defines here. We can't
cross-run different BSD binaries.
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/syscall_defs.h | 36 ------------------------------------
1 file changed, 36 deletions(-)
diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h
index 489d3a2e292..0604e96973e 100644
--- a/bsd-user/syscall_defs.h
+++ b/bsd-user/syscall_defs.h
@@ -32,42 +32,6 @@ struct target_iovec {
abi_long iov_len; /* Number of bytes */
};
-/*
- * sys/mman.h
- */
-#define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplemented */
- /* MAP_INHERIT */
-#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented */
- /* MAP_NOEXTEND */
-#define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like a */
- /* stack */
-#define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync */
- /* underlying file */
-
-#define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7
-
-#define TARGET_NETBSD_MAP_INHERIT 0x0080 /* region is retained after */
- /* exec */
-#define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, even */
- /* within break */
-#define TARGET_NETBSD_MAP_WIRED 0x0800 /* mlock() mapping when it is */
- /* established */
-
-#define TARGET_NETBSD_MAP_STACK 0x2000 /* allocated from memory, */
- /* swap space (stack) */
-
-#define TARGET_NETBSD_MAP_FLAGMASK 0x3ff7
-
-#define TARGET_OPENBSD_MAP_INHERIT 0x0080 /* region is retained after */
- /* exec */
-#define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change */
- /* file size */
-#define TARGET_OPENBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, */
- /* even within heap */
-
-#define TARGET_OPENBSD_MAP_FLAGMASK 0x17f7
-
-/* XXX */
#define TARGET_BSD_MAP_FLAGMASK 0x3ff7
/*
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 09/19] bsd-user: h2g_rusage
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (7 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 08/19] bsd-user: Remove useless mmap definitions Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 10/19] bsd-user: Implement do_sysctl_kern_getprocs Warner Losh
` (9 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Stacey Son, Richard Henderson
From: Stacey Son <sson@FreeBSD.org>
Converts host's rusage to the guest's rusage.
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/bsd-proc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
bsd-user/meson.build | 1 +
bsd-user/qemu-bsd.h | 30 +++++++++++++++++++++++++++
3 files changed, 79 insertions(+)
create mode 100644 bsd-user/bsd-proc.c
create mode 100644 bsd-user/qemu-bsd.h
diff --git a/bsd-user/bsd-proc.c b/bsd-user/bsd-proc.c
new file mode 100644
index 00000000000..e64eb958947
--- /dev/null
+++ b/bsd-user/bsd-proc.c
@@ -0,0 +1,48 @@
+/*
+ * BSD process related system call helpers
+ *
+ * Copyright (c) 2013-14 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 "qemu.h"
+#include "qemu-bsd.h"
+#include "signal-common.h"
+
+void h2g_rusage(const struct rusage *rusage,
+ struct target_freebsd_rusage *target_rusage)
+{
+ __put_user(rusage->ru_utime.tv_sec, &target_rusage->ru_utime.tv_sec);
+ __put_user(rusage->ru_utime.tv_usec, &target_rusage->ru_utime.tv_usec);
+
+ __put_user(rusage->ru_stime.tv_sec, &target_rusage->ru_stime.tv_sec);
+ __put_user(rusage->ru_stime.tv_usec, &target_rusage->ru_stime.tv_usec);
+
+ __put_user(rusage->ru_maxrss, &target_rusage->ru_maxrss);
+ __put_user(rusage->ru_idrss, &target_rusage->ru_idrss);
+ __put_user(rusage->ru_idrss, &target_rusage->ru_idrss);
+ __put_user(rusage->ru_isrss, &target_rusage->ru_isrss);
+ __put_user(rusage->ru_minflt, &target_rusage->ru_minflt);
+ __put_user(rusage->ru_majflt, &target_rusage->ru_majflt);
+ __put_user(rusage->ru_nswap, &target_rusage->ru_nswap);
+ __put_user(rusage->ru_inblock, &target_rusage->ru_inblock);
+ __put_user(rusage->ru_oublock, &target_rusage->ru_oublock);
+ __put_user(rusage->ru_msgsnd, &target_rusage->ru_msgsnd);
+ __put_user(rusage->ru_msgrcv, &target_rusage->ru_msgrcv);
+ __put_user(rusage->ru_nsignals, &target_rusage->ru_nsignals);
+ __put_user(rusage->ru_nvcsw, &target_rusage->ru_nvcsw);
+ __put_user(rusage->ru_nivcsw, &target_rusage->ru_nivcsw);
+}
diff --git a/bsd-user/meson.build b/bsd-user/meson.build
index 5243122fc56..7d1b4de78b1 100644
--- a/bsd-user/meson.build
+++ b/bsd-user/meson.build
@@ -8,6 +8,7 @@ common_user_inc += include_directories('include')
bsd_user_ss.add(files(
'bsdload.c',
+ 'bsd-proc.c',
'elfload.c',
'main.c',
'mmap.c',
diff --git a/bsd-user/qemu-bsd.h b/bsd-user/qemu-bsd.h
new file mode 100644
index 00000000000..96e7f34b27c
--- /dev/null
+++ b/bsd-user/qemu-bsd.h
@@ -0,0 +1,30 @@
+/*
+ * 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/resource.h>
+
+/* bsd-proc.c */
+void h2g_rusage(const struct rusage *rusage,
+ struct target_freebsd_rusage *target_rusage);
+
+#endif /* QEMU_BSD_H */
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 10/19] bsd-user: Implement do_sysctl_kern_getprocs
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (8 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 09/19] bsd-user: h2g_rusage Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 11/19] bsd-user: Implement do_sysctl_kern_proc_filedesc Warner Losh
` (8 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Stacey Son, Richard Henderson
From: Stacey Son <sson@FreeBSD.org>
Implement do_sysctl_kern_getprocs to retrieve proc info from the kernel.
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/freebsd/os-sys.c | 165 +++++++++++++++++++++++++++++++++++++-
bsd-user/qemu.h | 3 +
2 files changed, 167 insertions(+), 1 deletion(-)
diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c
index df317065587..d4a6dcc6c2b 100644
--- a/bsd-user/freebsd/os-sys.c
+++ b/bsd-user/freebsd/os-sys.c
@@ -19,9 +19,14 @@
#include "qemu/osdep.h"
#include "qemu.h"
+#include "qemu-bsd.h"
#include "target_arch_sysarch.h"
-
+#include "signal-common.h"
+#include <sys/param.h>
#include <sys/sysctl.h>
+#include <sys/user.h> /* For struct kinfo_* */
+
+#include "target_os_user.h"
/*
* Length for the fixed length types.
@@ -107,6 +112,164 @@ static abi_ulong h2g_ulong_sat(u_long ul)
*/
#define bsd_get_ncpu() 1
+static void
+host_to_target_kinfo_proc(struct target_kinfo_proc *tki, struct kinfo_proc *hki)
+{
+ int i;
+
+ __put_user(sizeof(struct target_kinfo_proc), &tki->ki_structsize);
+ __put_user(hki->ki_layout, &tki->ki_layout);
+
+ /* Some of these are used as flags (e.g. ki_fd == NULL in procstat). */
+ tki->ki_args = tswapal((abi_ulong)(uintptr_t)hki->ki_args);
+ tki->ki_paddr = tswapal((abi_ulong)(uintptr_t)hki->ki_paddr);
+ tki->ki_addr = tswapal((abi_ulong)(uintptr_t)hki->ki_addr);
+ tki->ki_tracep = tswapal((abi_ulong)(uintptr_t)hki->ki_tracep);
+ tki->ki_textvp = tswapal((abi_ulong)(uintptr_t)hki->ki_textvp);
+ tki->ki_fd = tswapal((abi_ulong)(uintptr_t)hki->ki_fd);
+ tki->ki_vmspace = tswapal((abi_ulong)(uintptr_t)hki->ki_vmspace);
+ tki->ki_wchan = tswapal((abi_ulong)(uintptr_t)hki->ki_wchan);
+
+ __put_user(hki->ki_pid, &tki->ki_pid);
+ __put_user(hki->ki_ppid, &tki->ki_ppid);
+ __put_user(hki->ki_pgid, &tki->ki_pgid);
+ __put_user(hki->ki_tpgid, &tki->ki_tpgid);
+ __put_user(hki->ki_sid, &tki->ki_sid);
+ __put_user(hki->ki_tsid, &tki->ki_tsid);
+ __put_user(hki->ki_jobc, &tki->ki_jobc);
+ __put_user(hki->ki_tdev, &tki->ki_tdev);
+
+ host_to_target_sigset(&tki->ki_siglist, &hki->ki_siglist);
+ host_to_target_sigset(&tki->ki_sigmask, &hki->ki_sigmask);
+ host_to_target_sigset(&tki->ki_sigignore, &hki->ki_sigignore);
+ host_to_target_sigset(&tki->ki_sigcatch, &hki->ki_sigcatch);
+
+ __put_user(hki->ki_uid, &tki->ki_uid);
+ __put_user(hki->ki_ruid, &tki->ki_ruid);
+ __put_user(hki->ki_svuid, &tki->ki_svuid);
+ __put_user(hki->ki_rgid, &tki->ki_rgid);
+ __put_user(hki->ki_svgid, &tki->ki_svgid);
+ __put_user(hki->ki_ngroups, &tki->ki_ngroups);
+
+ for (i=0; i < TARGET_KI_NGROUPS; i++)
+ __put_user(hki->ki_groups[i], &tki->ki_groups[i]);
+
+ __put_user(hki->ki_size, &tki->ki_size);
+
+ __put_user(hki->ki_rssize, &tki->ki_rssize);
+ __put_user(hki->ki_swrss, &tki->ki_swrss);
+ __put_user(hki->ki_tsize, &tki->ki_tsize);
+ __put_user(hki->ki_dsize, &tki->ki_dsize);
+ __put_user(hki->ki_ssize, &tki->ki_ssize);
+
+ __put_user(hki->ki_xstat, &tki->ki_xstat);
+ __put_user(hki->ki_acflag, &tki->ki_acflag);
+
+ __put_user(hki->ki_pctcpu, &tki->ki_pctcpu);
+
+ __put_user(hki->ki_estcpu, &tki->ki_estcpu);
+ __put_user(hki->ki_slptime, &tki->ki_slptime);
+ __put_user(hki->ki_swtime, &tki->ki_swtime);
+ __put_user(hki->ki_cow, &tki->ki_cow);
+ __put_user(hki->ki_runtime, &tki->ki_runtime);
+
+ __put_user(hki->ki_start.tv_sec, &tki->ki_start.tv_sec);
+ __put_user(hki->ki_start.tv_usec, &tki->ki_start.tv_usec);
+ __put_user(hki->ki_childtime.tv_sec, &tki->ki_childtime.tv_sec);
+ __put_user(hki->ki_childtime.tv_usec, &tki->ki_childtime.tv_usec);
+
+ __put_user(hki->ki_flag, &tki->ki_flag);
+ __put_user(hki->ki_kiflag, &tki->ki_kiflag);
+
+ __put_user(hki->ki_traceflag, &tki->ki_traceflag);
+ __put_user(hki->ki_stat, &tki->ki_stat);
+ __put_user(hki->ki_nice, &tki->ki_nice);
+ __put_user(hki->ki_lock, &tki->ki_lock);
+ __put_user(hki->ki_rqindex, &tki->ki_rqindex);
+ __put_user(hki->ki_oncpu_old, &tki->ki_oncpu_old);
+ __put_user(hki->ki_lastcpu_old, &tki->ki_lastcpu_old);
+
+ strncpy(tki->ki_tdname, hki->ki_tdname, TARGET_TDNAMLEN+1);
+ strncpy(tki->ki_wmesg, hki->ki_wmesg, TARGET_WMESGLEN+1);
+ strncpy(tki->ki_login, hki->ki_login, TARGET_LOGNAMELEN+1);
+ strncpy(tki->ki_lockname, hki->ki_lockname, TARGET_LOCKNAMELEN+1);
+ strncpy(tki->ki_comm, hki->ki_comm, TARGET_COMMLEN+1);
+ strncpy(tki->ki_emul, hki->ki_emul, TARGET_KI_EMULNAMELEN+1);
+ strncpy(tki->ki_loginclass, hki->ki_loginclass, TARGET_LOGINCLASSLEN+1);
+
+ __put_user(hki->ki_oncpu, &tki->ki_oncpu);
+ __put_user(hki->ki_lastcpu, &tki->ki_lastcpu);
+ __put_user(hki->ki_tracer, &tki->ki_tracer);
+ __put_user(hki->ki_flag2, &tki->ki_flag2);
+ __put_user(hki->ki_fibnum, &tki->ki_fibnum);
+ __put_user(hki->ki_cr_flags, &tki->ki_cr_flags);
+ __put_user(hki->ki_jid, &tki->ki_jid);
+ __put_user(hki->ki_numthreads, &tki->ki_numthreads);
+ __put_user(hki->ki_tid, &tki->ki_tid);
+
+ memcpy(&tki->ki_pri, &hki->ki_pri, sizeof(struct target_priority));
+
+ h2g_rusage(&hki->ki_rusage, &tki->ki_rusage);
+ h2g_rusage(&hki->ki_rusage_ch, &tki->ki_rusage_ch);
+
+ __put_user(((uintptr_t)hki->ki_pcb), &tki->ki_pcb);
+ __put_user(((uintptr_t)hki->ki_kstack), &tki->ki_kstack);
+ __put_user(((uintptr_t)hki->ki_udata), &tki->ki_udata);
+ __put_user(((uintptr_t)hki->ki_tdaddr), &tki->ki_tdaddr);
+
+ __put_user(hki->ki_sflag, &tki->ki_sflag);
+ __put_user(hki->ki_tdflags, &tki->ki_tdflags);
+}
+
+abi_long
+do_sysctl_kern_getprocs(int op, int arg, size_t olen,
+ struct target_kinfo_proc *tki, size_t *tlen)
+{
+ abi_long ret;
+ struct kinfo_proc *kipp;
+ int mib[4], num, i, miblen;
+ size_t len;
+
+ if (tlen == NULL)
+ return -TARGET_EINVAL;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = op;
+ mib[3] = arg;
+
+ miblen = (op == KERN_PROC_ALL || op == KERN_PROC_PROC) ? 3 : 4;
+
+ len = 0;
+ ret = get_errno(sysctl(mib, miblen, NULL, &len, NULL, 0));
+ if (is_error(ret))
+ return ret;
+
+ num = len / sizeof(*kipp);
+ *tlen = num * sizeof(struct target_kinfo_proc);
+ if (tki == NULL)
+ return ret;
+
+ if (olen < *tlen)
+ return -TARGET_EINVAL;
+
+ kipp = g_malloc(len);
+ if (kipp == NULL)
+ return -TARGET_ENOMEM;
+ ret = get_errno(sysctl(mib, miblen, kipp, &len, NULL, 0));
+ num = len / sizeof(*kipp);
+ *tlen = num * sizeof(struct target_kinfo_proc);
+ if (len % sizeof(*kipp) != 0 || kipp->ki_structsize != sizeof(*kipp)) {
+ ret = -TARGET_EINVAL; /* XXX */
+ } else if (!is_error(ret)) {
+ for(i=0; i < num; i++)
+ host_to_target_kinfo_proc(&tki[i], &kipp[i]);
+ }
+
+ g_free(kipp);
+ return ret;
+}
+
/*
* This uses the undocumented oidfmt interface to find the kind of a requested
* sysctl, see /sys/kern/kern_sysctl.c:sysctl_sysctl_oidfmt() (compare to
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 49468734d44..fcaf794ad6e 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -258,6 +258,9 @@ bool is_error(abi_long ret);
int host_to_target_errno(int err);
/* os-sys.c */
+struct target_kinfo_proc;
+abi_long do_sysctl_kern_getprocs(int op, int arg, size_t olen,
+ struct target_kinfo_proc *tki, size_t *tlen);
abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen,
abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen);
abi_long do_freebsd_sysctlbyname(CPUArchState *env, abi_ulong namep,
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 11/19] bsd-user: Implement do_sysctl_kern_proc_filedesc
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (9 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 10/19] bsd-user: Implement do_sysctl_kern_getprocs Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 12/19] bsd-user: Implement do_sysctl_kern_proc_vmmap Warner Losh
` (7 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Stacey Son, Richard Henderson
From: Stacey Son <sson@FreeBSD.org>
Implement do_sysctl_kern_proc_filedesc. This pulls kern.proc.filedesc
out of the host kernel and converts it to the guest's format.
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/freebsd/os-sys.c | 193 ++++++++++++++++++++++++++++++++++++++
bsd-user/qemu.h | 3 +
2 files changed, 196 insertions(+)
diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c
index d4a6dcc6c2b..00b2dcc9641 100644
--- a/bsd-user/freebsd/os-sys.c
+++ b/bsd-user/freebsd/os-sys.c
@@ -270,6 +270,199 @@ do_sysctl_kern_getprocs(int op, int arg, size_t olen,
return ret;
}
+static void
+host_to_target_kinfo_file(struct target_kinfo_file *tkif,
+ struct kinfo_file *hkif)
+{
+ int type = hkif->kf_type;
+
+ __put_user(hkif->kf_structsize, &tkif->kf_structsize);
+ __put_user(hkif->kf_type, &tkif->kf_type);
+ __put_user(hkif->kf_fd, &tkif->kf_fd);
+ __put_user(hkif->kf_ref_count, &tkif->kf_ref_count);
+ __put_user(hkif->kf_flags, &tkif->kf_flags);
+ __put_user(hkif->kf_offset, &tkif->kf_offset);
+ switch (type) {
+ case TARGET_KF_TYPE_FIFO:
+ case TARGET_KF_TYPE_SHM:
+ case TARGET_KF_TYPE_VNODE:
+ __put_user(hkif->kf_un.kf_file.kf_file_type,
+ &tkif->kf_un.kf_file.kf_file_type);
+ __put_user(hkif->kf_un.kf_file.kf_file_fsid,
+ &tkif->kf_un.kf_file.kf_file_fsid);
+ __put_user(hkif->kf_un.kf_file.kf_file_rdev,
+ &tkif->kf_un.kf_file.kf_file_rdev);
+ __put_user(hkif->kf_un.kf_file.kf_file_fileid,
+ &tkif->kf_un.kf_file.kf_file_fileid);
+ __put_user(hkif->kf_un.kf_file.kf_file_size,
+ &tkif->kf_un.kf_file.kf_file_size);
+ __put_user(hkif->kf_un.kf_file.kf_file_fsid_freebsd11,
+ &tkif->kf_un.kf_file.kf_file_fsid_freebsd11);
+ __put_user(hkif->kf_un.kf_file.kf_file_rdev_freebsd11,
+ &tkif->kf_un.kf_file.kf_file_rdev_freebsd11);
+ __put_user(hkif->kf_un.kf_file.kf_file_mode,
+ &tkif->kf_un.kf_file.kf_file_mode);
+ break;
+
+ case TARGET_KF_TYPE_SOCKET:
+ __put_user(hkif->kf_un.kf_sock.kf_sock_domain0,
+ &tkif->kf_un.kf_sock.kf_sock_domain0);
+ __put_user(hkif->kf_un.kf_sock.kf_sock_type0,
+ &tkif->kf_un.kf_sock.kf_sock_type0);
+ __put_user(hkif->kf_un.kf_sock.kf_sock_protocol0,
+ &tkif->kf_un.kf_sock.kf_sock_protocol0);
+/* XXX - Implement copy function for sockaddr_storage
+ host_to_target_copy_sockaddr_storage(
+ &hkif->kf_un.kf_file.kf_sa_local,
+ &kif->kf_un.kf_file.kf_sa_local);
+ host_to_target_copy_sockaddr_storage(
+ &hkif->kf_un.kf_file.kf_sa_peer,
+ &kif->kf_un.kf_file.kf_sa_peer);
+*/
+ __put_user(hkif->kf_un.kf_sock.kf_sock_pcb,
+ &tkif->kf_un.kf_sock.kf_sock_pcb);
+ __put_user(hkif->kf_un.kf_sock.kf_sock_inpcb,
+ &tkif->kf_un.kf_sock.kf_sock_inpcb);
+ __put_user(hkif->kf_un.kf_sock.kf_sock_unpconn,
+ &tkif->kf_un.kf_sock.kf_sock_unpconn);
+ __put_user(hkif->kf_un.kf_sock.kf_sock_snd_sb_state,
+ &tkif->kf_un.kf_sock.kf_sock_snd_sb_state);
+ __put_user(hkif->kf_un.kf_sock.kf_sock_rcv_sb_state,
+ &tkif->kf_un.kf_sock.kf_sock_rcv_sb_state);
+ break;
+
+ case TARGET_KF_TYPE_PIPE:
+ __put_user(hkif->kf_un.kf_pipe.kf_pipe_addr,
+ &tkif->kf_un.kf_pipe.kf_pipe_addr);
+ __put_user(hkif->kf_un.kf_pipe.kf_pipe_peer,
+ &tkif->kf_un.kf_pipe.kf_pipe_peer);
+ __put_user(hkif->kf_un.kf_pipe.kf_pipe_buffer_cnt,
+ &tkif->kf_un.kf_pipe.kf_pipe_buffer_cnt);
+ break;
+
+ case TARGET_KF_TYPE_SEM:
+ __put_user(hkif->kf_un.kf_sem.kf_sem_value,
+ &tkif->kf_un.kf_sem.kf_sem_value);
+ __put_user(hkif->kf_un.kf_sem.kf_sem_mode,
+ &tkif->kf_un.kf_sem.kf_sem_mode);
+ break;
+
+ case TARGET_KF_TYPE_PTS:
+ __put_user(hkif->kf_un.kf_pts.kf_pts_dev_freebsd11,
+ &tkif->kf_un.kf_pts.kf_pts_dev_freebsd11);
+ __put_user(hkif->kf_un.kf_pts.kf_pts_dev,
+ &tkif->kf_un.kf_pts.kf_pts_dev);
+ break;
+
+ case TARGET_KF_TYPE_PROCDESC:
+ __put_user(hkif->kf_un.kf_proc.kf_pid,
+ &tkif->kf_un.kf_proc.kf_pid);
+ break;
+
+
+ case TARGET_KF_TYPE_CRYPTO:
+ case TARGET_KF_TYPE_KQUEUE:
+ case TARGET_KF_TYPE_MQUEUE:
+ case TARGET_KF_TYPE_NONE:
+ case TARGET_KF_TYPE_UNKNOWN:
+ default:
+ /* Do nothing. */
+ break;
+ }
+ __put_user(hkif->kf_status, &tkif->kf_status);
+ for (int i = 0; i < (CAP_RIGHTS_VERSION + 2); i++)
+ __put_user(hkif->kf_cap_rights.cr_rights[i],
+ &tkif->kf_cap_rights.cr_rights[i]);
+ strncpy(tkif->kf_path, hkif->kf_path, sizeof(tkif->kf_path));
+}
+
+abi_long
+do_sysctl_kern_proc_filedesc(int pid, size_t olen,
+ struct target_kinfo_file *tkif, size_t *tlen)
+{
+ abi_long ret;
+ int mib[4], sz;
+ size_t len;
+ char *buf, *bp, *eb, *tp;
+ struct kinfo_file *kf, kif;
+ struct target_kinfo_file target_kif;
+
+ if (tlen == NULL) {
+ return -TARGET_EINVAL;
+ }
+
+ len = 0;
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_FILEDESC;
+ mib[3] = pid;
+
+ ret = get_errno(sysctl(mib, 4, NULL, &len, NULL, 0));
+ if (is_error(ret)) {
+ return ret;
+ }
+ if (tkif == NULL) {
+ *tlen = len;
+ return ret;
+ }
+ len = len * 4 / 3;
+ buf = g_malloc(len);
+ if (buf == NULL) {
+ return -TARGET_ENOMEM;
+ }
+
+ /*
+ * Count the number of records.
+ *
+ * Given that the kinfo_file information returned by
+ * the kernel may be different sizes per record we have
+ * to read it in and count the variable length records
+ * by walking them.
+ */
+ ret = get_errno(sysctl(mib, 4, buf, &len, NULL, 0));
+ if (is_error(ret)) {
+ g_free(buf);
+ return ret;
+ }
+ *tlen = len;
+ bp = buf;
+ eb = buf + len;
+ while (bp < eb) {
+ kf = (struct kinfo_file *)(uintptr_t)bp;
+ bp += kf->kf_structsize;
+ }
+ if (olen < *tlen) {
+ g_free(buf);
+ return -TARGET_EINVAL;
+ }
+
+ /*
+ * Unpack the records from the kernel into full length records
+ * and byte swap, if needed.
+ */
+ bp = buf;
+ eb = buf + len;
+ tp = (char *)tkif;
+ while (bp < eb) {
+ kf = (struct kinfo_file *)(uintptr_t)bp;
+ sz = kf->kf_structsize;
+ /* Copy/expand into a zeroed buffer */
+ memset(&kif, 0, sizeof(kif));
+ memcpy(&kif, kf, sz);
+ /* Byte swap and copy into a target buffer. */
+ host_to_target_kinfo_file(&target_kif, &kif);
+ /* Copy target buffer to user buffer and pack */
+ memcpy(tp, &target_kif, sz);
+ /* Advance to next packed record. */
+ bp += sz;
+ /* Advance to next packed, target record. */
+ tp += sz;
+ }
+
+ g_free(buf);
+ return ret;
+}
+
/*
* This uses the undocumented oidfmt interface to find the kind of a requested
* sysctl, see /sys/kern/kern_sysctl.c:sysctl_sysctl_oidfmt() (compare to
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index fcaf794ad6e..5926bdcc101 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -259,8 +259,11 @@ int host_to_target_errno(int err);
/* os-sys.c */
struct target_kinfo_proc;
+struct target_kinfo_file;
abi_long do_sysctl_kern_getprocs(int op, int arg, size_t olen,
struct target_kinfo_proc *tki, size_t *tlen);
+abi_long do_sysctl_kern_proc_filedesc(int pid, size_t olen,
+ struct target_kinfo_file *tkif, size_t *tlen);
abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen,
abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen);
abi_long do_freebsd_sysctlbyname(CPUArchState *env, abi_ulong namep,
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 12/19] bsd-user: Implement do_sysctl_kern_proc_vmmap
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (10 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 11/19] bsd-user: Implement do_sysctl_kern_proc_filedesc Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 13/19] bsd-user: Implement sysctl kern.proc, except kern.proc.full_path Warner Losh
` (6 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Stacey Son, Richard Henderson
From: Stacey Son <sson@FreeBSD.org>
Implement do_sysctl_kern_proc_vmmap. This pulls kern.proc.vmmap out of
the host kernel and converts it to the guest's format.
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/freebsd/os-sys.c | 115 ++++++++++++++++++++++++++++++++++++++
bsd-user/qemu.h | 3 +
2 files changed, 118 insertions(+)
diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c
index 00b2dcc9641..418358adc1e 100644
--- a/bsd-user/freebsd/os-sys.c
+++ b/bsd-user/freebsd/os-sys.c
@@ -463,6 +463,121 @@ do_sysctl_kern_proc_filedesc(int pid, size_t olen,
return ret;
}
+static void
+host_to_target_kinfo_vmentry(struct target_kinfo_vmentry *tkve,
+ struct kinfo_vmentry *hkve)
+{
+
+ __put_user(hkve->kve_structsize, &tkve->kve_structsize);
+ __put_user(hkve->kve_type, &tkve->kve_type);
+ __put_user(hkve->kve_start, &tkve->kve_start);
+ __put_user(hkve->kve_end, &tkve->kve_end);
+ __put_user(hkve->kve_offset, &tkve->kve_offset);
+ __put_user(hkve->kve_vn_fileid, &tkve->kve_vn_fileid);
+ __put_user(hkve->kve_vn_fsid_freebsd11, &tkve->kve_vn_fsid_freebsd11);
+ __put_user(hkve->kve_vn_fsid, &tkve->kve_vn_fsid);
+ __put_user(hkve->kve_flags, &tkve->kve_flags);
+ __put_user(hkve->kve_resident, &tkve->kve_resident);
+ __put_user(hkve->kve_private_resident, &tkve->kve_private_resident);
+ __put_user(hkve->kve_protection, &tkve->kve_protection);
+ __put_user(hkve->kve_ref_count, &tkve->kve_ref_count);
+ __put_user(hkve->kve_shadow_count, &tkve->kve_shadow_count);
+ __put_user(hkve->kve_vn_type, &tkve->kve_vn_type);
+ __put_user(hkve->kve_vn_size, &tkve->kve_vn_size);
+ __put_user(hkve->kve_vn_rdev_freebsd11, &tkve->kve_vn_rdev_freebsd11);
+ __put_user(hkve->kve_vn_rdev, &tkve->kve_vn_rdev);
+ __put_user(hkve->kve_vn_mode, &tkve->kve_vn_mode);
+ __put_user(hkve->kve_status, &tkve->kve_status);
+ strncpy(tkve->kve_path, hkve->kve_path, sizeof(tkve->kve_path));
+}
+
+abi_long
+do_sysctl_kern_proc_vmmap(int pid, size_t olen,
+ struct target_kinfo_vmentry *tkve, size_t *tlen)
+{
+ abi_long ret;
+ int mib[4], sz;
+ size_t len;
+ char *buf, *bp, *eb, *tp;
+ struct kinfo_vmentry *kve, kvme;
+ struct target_kinfo_vmentry target_kvme;
+
+ if (tlen == NULL) {
+ return -TARGET_EINVAL;
+ }
+
+ len = 0;
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_VMMAP;
+ mib[3] = pid;
+
+ ret = get_errno(sysctl(mib, 4, NULL, &len, NULL, 0));
+ if (is_error(ret)) {
+ return ret;
+ }
+ if (tkve == NULL) {
+ *tlen = len;
+ return ret;
+ }
+ len = len * 4 / 3;
+ buf = g_malloc(len);
+ if (buf == NULL) {
+ return -TARGET_ENOMEM;
+ }
+
+ /*
+ * Count the number of records.
+ *
+ * Given that the kinfo_file information returned by
+ * the kernel may be differents sizes per record we have
+ * to read it in and count the variable length records
+ * by walking them.
+ */
+ ret = get_errno(sysctl(mib, 4, buf, &len, NULL, 0));
+ if (is_error(ret)) {
+ g_free(buf);
+ return ret;
+ }
+ *tlen = len;
+ bp = buf;
+ eb = buf + len;
+ while (bp < eb) {
+ kve = (struct kinfo_vmentry *)(uintptr_t)bp;
+ bp += kve->kve_structsize;
+ }
+ if (olen < *tlen) {
+ g_free(buf);
+ return -TARGET_EINVAL;
+ }
+
+ /*
+ * Unpack the records from the kernel into full length records
+ * and byte swap, if needed.
+ */
+ bp = buf;
+ eb = buf + len;
+ tp = (char *)tkve;
+ while (bp < eb) {
+ kve = (struct kinfo_vmentry *)(uintptr_t)bp;
+ sz = kve->kve_structsize;
+ /* Copy/expand into a zeroed buffer */
+ memset(&kvme, 0, sizeof(kvme));
+ memcpy(&kvme, kve, sz);
+ /* Byte swap and copy into a target aligned buffer. */
+ host_to_target_kinfo_vmentry(&target_kvme, &kvme);
+ /* Copy target buffer to user buffer, packed. */
+ memcpy(tp, &target_kvme, sz);
+ /* Advance to next packed record. */
+ bp += sz;
+ /* Advance to next packed, target record. */
+ tp += sz;
+ }
+
+ g_free(buf);
+ return ret;
+}
+
/*
* This uses the undocumented oidfmt interface to find the kind of a requested
* sysctl, see /sys/kern/kern_sysctl.c:sysctl_sysctl_oidfmt() (compare to
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 5926bdcc101..aed0d481cba 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -260,10 +260,13 @@ int host_to_target_errno(int err);
/* os-sys.c */
struct target_kinfo_proc;
struct target_kinfo_file;
+struct target_kinfo_vmentry;
abi_long do_sysctl_kern_getprocs(int op, int arg, size_t olen,
struct target_kinfo_proc *tki, size_t *tlen);
abi_long do_sysctl_kern_proc_filedesc(int pid, size_t olen,
struct target_kinfo_file *tkif, size_t *tlen);
+abi_long do_sysctl_kern_proc_vmmap(int pid, size_t olen,
+ struct target_kinfo_vmentry *tkve, size_t *tlen);
abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen,
abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen);
abi_long do_freebsd_sysctlbyname(CPUArchState *env, abi_ulong namep,
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 13/19] bsd-user: Implement sysctl kern.proc, except kern.proc.full_path
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (11 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 12/19] bsd-user: Implement do_sysctl_kern_proc_vmmap Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 14/19] bsd-user: Implement core dumps Warner Losh
` (5 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Stacey Son, Richard Henderson
From: Stacey Son <sson@FreeBSD.org>
Use the recently committed conversion routines to implement all the
kern.proc flavors, except for the full path (the prereqs of which aren't
yet in qemu-project's master branch).
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/freebsd/os-sys.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c
index 418358adc1e..3772cf500ba 100644
--- a/bsd-user/freebsd/os-sys.c
+++ b/bsd-user/freebsd/os-sys.c
@@ -753,6 +753,41 @@ static abi_long do_freebsd_sysctl_oid(CPUArchState *env, int32_t *snamep,
ret = 0;
goto out;
+ case KERN_PROC:
+ switch (snamep[2]) {
+ case KERN_PROC_ALL:
+ case KERN_PROC_PROC:
+ case KERN_PROC_PID:
+ case KERN_PROC_PID | KERN_PROC_INC_THREAD:
+ case KERN_PROC_PGRP:
+ case KERN_PROC_PGRP | KERN_PROC_INC_THREAD:
+ case KERN_PROC_SESSION:
+ case KERN_PROC_SESSION | KERN_PROC_INC_THREAD:
+ case KERN_PROC_TTY:
+ case KERN_PROC_TTY | KERN_PROC_INC_THREAD:
+ case KERN_PROC_UID:
+ case KERN_PROC_UID | KERN_PROC_INC_THREAD:
+ case KERN_PROC_RUID:
+ case KERN_PROC_RUID | KERN_PROC_INC_THREAD:
+ ret = do_sysctl_kern_getprocs(snamep[2], snamep[3], oldlen,
+ holdp, &holdlen);
+ goto out;
+
+ case KERN_PROC_FILEDESC:
+ ret = do_sysctl_kern_proc_filedesc(snamep[3], oldlen, holdp,
+ &holdlen);
+ goto out;
+
+ case KERN_PROC_VMMAP:
+ ret = do_sysctl_kern_proc_vmmap(snamep[3], oldlen, holdp,
+ &holdlen);
+ goto out;
+
+ default:
+ break;
+ }
+ break;
+
default:
break;
}
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 14/19] bsd-user: Implement core dumps
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (12 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 13/19] bsd-user: Implement sysctl kern.proc, except kern.proc.full_path Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 15/19] bsd-user: Add SIGSYS to core dump signals Warner Losh
` (4 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Stacey Son, Ed Schouten, Richard Henderson
From: Stacey Son <sson@FreeBSD.org>
Bring in the code that was originally copied from linxu-user/elfload.c
and moved to elfcore.c. This code then removed the Linux specific bits,
replacing them with FreeBSD specific bits. The commit history for this
is not at all what we'd like (it was done in one go by sson in
227070562fc in one commit, with very few followup tweaks). Since the
original commit, this code has been moved, and updated by sson and ed
slightly. That makes it hard to split into smaller commits.
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Ed Schouten <ed@nuxi.nl>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Acked-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/elfcore.c | 1318 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 1315 insertions(+), 3 deletions(-)
diff --git a/bsd-user/elfcore.c b/bsd-user/elfcore.c
index c49d9280e2d..2905f2b8414 100644
--- a/bsd-user/elfcore.c
+++ b/bsd-user/elfcore.c
@@ -1,10 +1,1322 @@
-/* Stubbed out version of core dump support, explicitly in public domain */
+/*
+ * ELF loading code
+ *
+ * Copyright (c) 2015 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"
-static int elf_core_dump(int signr, CPUArchState *env)
+#ifdef USE_ELF_CORE_DUMP
+#include <err.h>
+#include <libgen.h>
+#include <sys/mman.h>
+#include <sys/sysctl.h>
+#include <sys/resource.h>
+
+#define ELF_NOTE_ROUNDSIZE 4
+#define ELF_MACHINE ELF_ARCH
+
+#define TARGET_NT_PRSTATUS 1 /* Process status. */
+#define TARGET_NT_FPREGSET 2 /* Floating point registers. */
+#define TARGET_NT_PRPSINFO 3 /* Process state info. */
+#define TARGET_NT_THRMISC 7 /* Thread miscellaneous info. */
+#define TARGET_NT_PROCSTAT_PROC 8 /* Procstat proc data. */
+#define TARGET_NT_PROCSTAT_FILES 9 /* Procstat files data. */
+#define TARGET_NT_PROCSTAT_VMMAP 10 /* Procstat vmmap data. */
+#define TARGET_NT_PROCSTAT_GROUPS 11 /* Procstat groups data. */
+#define TARGET_NT_PROCSTAT_UMASK 12 /* Procstat umask data. */
+#define TARGET_NT_PROCSTAT_RLIMIT 13 /* Procstat rlimit data. */
+#define TARGET_NT_PROCSTAT_OSREL 14 /* Procstat osreldate data. */
+#define TARGET_NT_PROCSTAT_PSSTRINGS 15 /* Procstat ps_strings data. */
+#define TARGET_NT_PROCSTAT_AUXV 16 /* Procstat auxv data. */
+
+/*
+ * Write out ELF coredump.
+ *
+ * See documentation of ELF object file format in:
+ * http://www.caldera.com/developers/devspecs/gabi41.pdf
+ * and sys/kern_imgact_elf.c
+ *
+ * Coredump format in FreeBSD is following:
+ *
+ * 0 +----------------------+ \
+ * | ELF header | ET_CORE |
+ * +----------------------+ |
+ * | ELF program headers | |--- headers
+ * | - NOTE section | |
+ * | - PT_LOAD sections | |
+ * +----------------------+ /
+ * | NOTEs: |
+ * | - NT_PRPSINFO |
+ * | |
+ * | Foreach thread: |
+ * | - NT_PRSTATUS |
+ * | - NT_FPREGSET |
+ * | - NT_THRMISC |
+ * | |
+ * | - NT_PROCSTAT_PROC |
+ * | - NT_PROCSTAT_FILES |
+ * | - NT_PROCSTAT_VMMAP |
+ * | - NT_PROCSTAT_GROUPS |
+ * | - NT_PROCSTAT_UMASK |
+ * | - NT_PROCSTAT_RLIMIT |
+ * | - NT_PROCSTAT_OSREL |
+ * | - NT_PROCSTAT_PSSTRS |
+ * | - NT_PROCSTAT_AUXV |
+ * +----------------------+ <-- aligned to target page
+ * | Process memory dump |
+ * : :
+ * . .
+ * : :
+ * | |
+ * +----------------------+
+ *
+ * Format follows System V format as close as possible. Current
+ * version limitations are as follows:
+ * - no floating point registers are dumped
+ *
+ * Function returns 0 in case of success, negative errno otherwise.
+ *
+ * TODO: make this work also during runtime: it should be
+ * possible to force coredump from running process and then
+ * continue processing. For example qemu could set up SIGUSR2
+ * handler (provided that target process haven't registered
+ * handler for that) that does the dump when signal is received.
+ */
+
+#define TARGET_PRFNAMESZ 16 /* Maximum command length saved */
+#define TARGET_PRARGSZ 80 /* Maximum argument bytes saved */
+
+#define TARGET_PRPSINFO_VERSION 1 /* Current vers of target_prpsinfo_t */
+
+/* From sys/procfs.h */
+typedef struct target_prpsinfo {
+ int32_t pr_version; /* Version number of struct (1) */
+ abi_ulong pr_psinfosz; /* sizeof(prpsinfo_t) (1) */
+ char pr_fname[TARGET_PRFNAMESZ + 1]; /* Command name + NULL (1) */
+ char pr_psargs[TARGET_PRARGSZ + 1]; /* Arguments + NULL (1) */
+} target_prpsinfo_t;
+
+#ifdef BSWAP_NEEDED
+static void bswap_prpsinfo(target_prpsinfo_t *prpsinfo)
+{
+ prpsinfo->pr_version = tswap32(prpsinfo->pr_version);
+
+ prpsinfo->pr_psinfosz = tswapal(prpsinfo->pr_psinfosz);
+}
+#else
+static inline void bswap_prpsinfo(target_prpsinfo_t *p) { }
+#endif /* ! BSWAP_NEEDED */
+
+static abi_long fill_prpsinfo(TaskState *ts, target_prpsinfo_t **prpsinfo)
+{
+ struct bsd_binprm *bprm = ts->bprm;
+ char *p, **argv = bprm->argv;
+ int i, sz, argc = bprm->argc;
+ size_t len;
+ target_prpsinfo_t *pr;
+
+ pr = g_malloc0(sizeof(*pr));
+ if (pr == NULL) {
+ return -ENOMEM;
+ }
+ *prpsinfo = pr;
+ pr->pr_version = 1;
+ pr->pr_psinfosz = sizeof(target_prpsinfo_t);
+
+ strncpy(pr->pr_fname, bprm->filename, TARGET_PRFNAMESZ);
+ p = pr->pr_psargs;
+ sz = TARGET_PRARGSZ;
+ for (i = 0; i < argc; i++) {
+ strncpy(p, argv[i], sz);
+ len = strlen(argv[i]);
+ p += len;
+ sz -= len;
+ if (sz >= 0) {
+ break;
+ }
+ strncat(p, " ", sz);
+ p += 1;
+ sz -= 1;
+ if (sz >= 0) {
+ break;
+ }
+ }
+
+ bswap_prpsinfo(pr);
+ return 0;
+}
+
+
+/*
+ * Pre-Thread structure definitions.
+ */
+#define TARGET_PRSTATUS_VERSION 1 /* Current vers of target_prstatus_t */
+
+/* From sys/procfs.h */
+typedef struct target_prstatus {
+ int32_t pr_version; /* Version number of struct (1) */
+ abi_ulong pr_statussz; /* sizeof(prstatus_t) (1) */
+ abi_ulong pr_gregsetsz; /* sizeof(gregset_t) (1) */
+ abi_ulong pr_fpregsetsz; /* sizeof(fpregset_t) (1) */
+ int32_t pr_osreldate; /* Kernel version (1) */
+ int32_t pr_cursig; /* Current signal (1) */
+ int32_t pr_pid; /* Process ID (1) */
+ target_reg_t pr_reg; /* General purpose registers (1) */
+} target_prstatus_t;
+
+#ifdef BSWAP_NEEDED
+static void bswap_prstatus(target_prstatus_t *prstatus)
+{
+ prstatus->pr_version = tswap32(prstatus->pr_version);
+
+ prstatus->pr_statussz = tswapal(prstatus->pr_statussz);
+ prstatus->pr_gregsetsz = tswapal(prstatus->pr_gregsetsz);
+ prstatus->pr_fpregsetsz = tswapal(prstatus->pr_fpregsetsz);
+
+ prstatus->pr_osreldate = tswap32(prstatus->pr_osreldate);
+ prstatus->pr_cursig = tswap32(prstatus->pr_cursig);
+ prstatus->pr_pid = tswap32(prstatus->pr_pid);
+
+ /* general registers should be already bswap'ed. */
+}
+#else
+static inline void bswap_prstatus(target_prstatus_t *p) { }
+#endif /* ! BSWAP_NEEDED */
+
+static abi_long fill_osreldate(int *osreldatep)
+{
+ abi_long ret;
+ size_t len;
+ int mib[2];
+
+ *osreldatep = 0;
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_OSRELDATE;
+ len = sizeof(*osreldatep);
+ ret = get_errno(sysctl(mib, 2, osreldatep, &len, NULL, 0));
+ if (is_error(ret) && errno != ESRCH) {
+ warn("sysctl: kern.proc.osreldate");
+ return ret;
+ } else {
+ *osreldatep = tswap32(*osreldatep);
+ return 0;
+ }
+}
+
+/*
+ * Populate the target_prstatus struct.
+ *
+ * sys/kern/imagact_elf.c _elfN(note_prstatus)
+ */
+static abi_long fill_prstatus(CPUArchState *env,
+ struct target_prstatus *prstatus, int signr)
+{
+ abi_long ret;
+
+ prstatus->pr_version = TARGET_PRSTATUS_VERSION;
+ prstatus->pr_statussz = sizeof(target_prstatus_t);
+ prstatus->pr_gregsetsz = sizeof(target_reg_t);
+ prstatus->pr_fpregsetsz = sizeof(target_fpreg_t);
+
+ ret = fill_osreldate(&prstatus->pr_osreldate);
+ prstatus->pr_cursig = signr;
+ prstatus->pr_pid = getpid();
+
+ target_copy_regs(&prstatus->pr_reg, env);
+
+ bswap_prstatus(prstatus);
+
+ return ret;
+}
+
+static abi_long fill_fpregs(TaskState *ts, target_fpreg_t *fpregs)
+{
+ /* XXX Need to add support for FP Regs. */
+ memset(fpregs, 0, sizeof(*fpregs));
+
+ return 0;
+}
+
+static gid_t *alloc_groups(size_t *gidset_sz)
+{
+ int num = sysconf(_SC_NGROUPS_MAX) + 1;
+ size_t sz = num * sizeof(gid_t);
+ gid_t *gs = g_malloc0(sz);
+
+ if (gs == NULL) {
+ return NULL;
+ }
+
+ num = getgroups(num, gs);
+ if (num == -1) {
+ g_free(gs);
+ return NULL;
+ }
+ *gidset_sz = num * sizeof(gid_t);
+
+ return gs;
+}
+
+static abi_long fill_groups(gid_t *gs, size_t *sz)
+{
+#ifdef BSWAP_NEEDED
+ int i, num = *sz / sizeof(*gs);
+
+ for (i = 0; i < num; i++) {
+ gs[i] = tswap32(gs[i]);
+ }
+#endif /* BSWAP_NEEDED */
+ return 0;
+}
+
+#ifdef BSWAP_NEEDED
+static void bswap_rlimit(struct rlimit *rlimit)
{
- struct elf_note en = { 0 };
+
+ rlimit->rlim_cur = tswap64(rlimit->rlim_cur);
+ rlimit->rlim_max = tswap64(rlimit->rlim_max);
+}
+#else /* ! BSWAP_NEEDED */
+static void bswap_rlimit(struct rlimit *rlimit) {}
+#endif /* ! BSWAP_NEEDED */
+
+/*
+ * Get all the rlimits. Caller must free rlimits.
+ */
+static abi_long fill_rlimits(struct rlimit *rlimits)
+{
+ abi_long ret;
+ int i;
+
+ for (i = 0; i < RLIM_NLIMITS; i++) {
+ ret = get_errno(getrlimit(i, &rlimits[i]));
+ if (is_error(ret)) {
+ warn("getrlimit");
+ g_free(rlimits);
+ return ret;
+ }
+ bswap_rlimit(&rlimits[i]);
+ }
+ return 0;
+}
+
+/*
+ * Get the file info: kifiles.
+ */
+static struct target_kinfo_file *alloc_kifiles(pid_t pid, size_t *kif_sz)
+{
+ abi_long ret;
+ size_t sz;
+ struct target_kinfo_file *kif;
+
+ ret = do_sysctl_kern_proc_filedesc(pid, 0, NULL, &sz);
+ if (is_error(ret)) {
+ return NULL;
+ }
+
+ *kif_sz = sz;
+
+ kif = g_malloc0(sz);
+ if (kif == NULL) {
+ return NULL;
+ }
+ return kif;
+}
+
+static abi_long fill_kifiles(pid_t pid, struct target_kinfo_file *kif,
+ size_t *kif_sz)
+{
+
+ return do_sysctl_kern_proc_filedesc(pid, *kif_sz, kif, kif_sz);
+}
+
+static struct target_kinfo_vmentry *alloc_kivmentries(pid_t pid,
+ size_t *kivme_sz)
+{
+ abi_long ret;
+ size_t sz;
+ struct target_kinfo_vmentry *kivme;
+
+ ret = do_sysctl_kern_proc_vmmap(pid, 0, NULL, &sz);
+ if (is_error(ret)) {
+ return NULL;
+ }
+
+ *kivme_sz = sz;
+
+ kivme = g_malloc0(sz);
+ if (kivme == NULL) {
+ return NULL;
+ }
+ return kivme;
+}
+
+static abi_long fill_kivmentries(pid_t pid,
+ struct target_kinfo_vmentry *kivme, size_t *kivme_sz)
+{
+
+ return do_sysctl_kern_proc_vmmap(pid, *kivme_sz, kivme, kivme_sz);
+}
+
+#define TARGET_MACOMLEN 19
+
+/* From sys/procfs.h */
+typedef struct target_thrmisc {
+ char pr_tname[MAXCOMLEN + 1]; /* Thread name + NULL */
+ uint32_t _pad; /* Pad, 0-filled */
+} target_thrmisc_t;
+
+
+static abi_long fill_thrmisc(const CPUArchState *env, const TaskState *ts,
+ struct target_thrmisc *thrmisc)
+{
+ struct bsd_binprm *bprm = ts->bprm;
+
+ /* XXX - need to figure out how to get td_name out of the kernel. */
+ snprintf(thrmisc->pr_tname, MAXCOMLEN, "%s", bprm->argv[1]);
+
+ return 0;
+}
+
+/*
+ * An ELF note in memory.
+ */
+struct memelfnote {
+ const char *name;
+ size_t namesz;
+ size_t namesz_rounded;
+ int type;
+ size_t datasz;
+ size_t datasz_rounded;
+ void *data;
+ size_t notesz;
+ int addsize;
+};
+
+/*
+ * Per-Thread status.
+ */
+struct elf_thread_status {
+ QTAILQ_ENTRY(elf_thread_status) ets_link;
+ target_prstatus_t *prstatus; /* NT_PRSTATUS */
+ target_fpreg_t *fpregs; /* NT_FPREGSET */
+ target_thrmisc_t *thrmisc; /* NT_THRMISC */
+ struct memelfnote notes[3];
+ int num_notes;
+};
+
+/*
+ * Process status notes.
+ */
+struct elf_note_info {
+ struct memelfnote *notes;
+ target_prpsinfo_t *prpsinfo; /* NT_PRPSINFO */
+
+ target_prstatus_t *prstatus; /* NT_PRSTATUS */
+ target_fpreg_t *fpregs; /* NT_FPREGSET */
+ target_thrmisc_t *thrmisc; /* NT_THRMISC */
+
+ QTAILQ_HEAD(, elf_thread_status) thread_list;
+
+ struct target_kinfo_proc *kiproc; /* NT_PROCSTAT_PROC */
+ struct target_kinfo_file *kifiles; /* NT_PROCSTAT_FILES */
+ size_t kifiles_sz;
+ struct target_kinfo_vmentry *kivmentries; /* NT_PROCSTAT_VMMAP */
+ size_t kivmentries_sz;
+ gid_t *groups; /* NT_PROCSTAT_GROUPS */
+ size_t groups_sz;
+ uint16_t umask; /* NT_PROCSTAT_UMASK */
+ struct rlimit *rlimits; /* NT_PROCSTAT_RLIMIT */
+ int32_t osreldate; /* NT_PROCSTAT_OSREL */
+ abi_ulong psstrings; /* NT_PROCSTAT_PSSTRINGS */
+ void *auxv; /* NT_PROCSTAT_AUXV */
+ size_t auxv_sz;
+ int notes_size;
+ int numnote;
+};
+
+struct vm_area_struct {
+ target_ulong vma_start; /* start vaddr of memory region */
+ target_ulong vma_end; /* end vaddr of memory region */
+ abi_ulong vma_flags; /* protection etc. flags for the region */
+ QTAILQ_ENTRY(vm_area_struct) vma_link;
+};
+
+struct mm_struct {
+ QTAILQ_HEAD(, vm_area_struct) mm_mmap;
+ int mm_count; /* number of mappings */
+};
+
+static struct mm_struct *vma_init(void)
+{
+ struct mm_struct *mm;
+
+ mm = g_malloc(sizeof(*mm));
+ if (mm == NULL) {
+ return NULL;
+ }
+
+ mm->mm_count = 0;
+ QTAILQ_INIT(&mm->mm_mmap);
+
+ return mm;
+}
+
+static struct vm_area_struct *vma_first(const struct mm_struct *mm)
+{
+
+ return QTAILQ_FIRST(&mm->mm_mmap);
+}
+
+static struct vm_area_struct *vma_next(struct vm_area_struct *vma)
+{
+
+ return QTAILQ_NEXT(vma, vma_link);
+}
+
+static void vma_delete(struct mm_struct *mm)
+{
+ struct vm_area_struct *vma;
+
+ while (vma_first(mm) != NULL) {
+ vma = vma_first(mm);
+ QTAILQ_REMOVE(&mm->mm_mmap, vma, vma_link);
+ g_free(vma);
+ }
+ g_free(mm);
+}
+
+static int vma_add_mapping(struct mm_struct *mm, target_ulong start,
+ target_ulong end, abi_ulong flags)
+{
+ struct vm_area_struct *vma;
+
+ vma = g_malloc0(sizeof(*vma));
+ if (vma == NULL) {
+ return -1;
+ }
+
+ vma->vma_start = start;
+ vma->vma_end = end;
+ vma->vma_flags = flags;
+
+ QTAILQ_INSERT_TAIL(&mm->mm_mmap, vma, vma_link);
+ mm->mm_count++;
+
+ return 0;
+}
+
+static int vma_get_mapping_count(const struct mm_struct *mm)
+{
+
+ return mm->mm_count;
+}
+
+/*
+ * Calculate file (dump) size of given memory region.
+ */
+static abi_ulong vma_dump_size(const struct vm_area_struct *vma)
+{
+
+ /* if we cannot even read the first page, skip it */
+ if (!access_ok(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE)) {
+ return 0;
+ }
+
+ /*
+ * Usually we don't dump executable pages as they contain
+ * non-writable code that debugger can read directly from
+ * target library etc. However, thread stacks are marked
+ * also executable so we read in first page of given region
+ * and check whether it contains elf header. If there is
+ * no elf header, we dump it.
+ */
+ if (vma->vma_flags & PROT_EXEC) {
+ char page[TARGET_PAGE_SIZE];
+
+ copy_from_user(page, vma->vma_start, sizeof(page));
+ if ((page[EI_MAG0] == ELFMAG0) &&
+ (page[EI_MAG1] == ELFMAG1) &&
+ (page[EI_MAG2] == ELFMAG2) &&
+ (page[EI_MAG3] == ELFMAG3)) {
+ /*
+ * Mappings are possibly from ELF binary. Don't dump
+ * them.
+ */
+ return 0;
+ }
+ }
+
+ return vma->vma_end - vma->vma_start;
+}
+
+static int vma_walker(void *priv, target_ulong start, target_ulong end,
+ unsigned long flags)
+{
+ struct mm_struct *mm = (struct mm_struct *)priv;
+
+ vma_add_mapping(mm, start, end, flags);
+ return 0;
+}
+
+
+/*
+ * Construct the name of the coredump file in the form of:
+ *
+ * Long form:
+ * qemu_<basename_of_target>_<date>-<time>_<pid>.core
+ *
+ * Short form:
+ * qemu_<basename_of_target>.core
+ *
+ * On success return 0, otherwise return -1 (and errno).
+ */
+static int core_dump_filename(const TaskState *ts, char *buf,
+ size_t bufsize)
+{
+#ifdef QEMU_LONG_CORE_FILENAME
+ char timestamp[64];
+ char *filename = NULL;
+ char *base_filename = NULL;
+ struct timeval tv;
+ struct tm tm;
+
+ assert(bufsize >= PATH_MAX);
+
+ if (gettimeofday(&tv, NULL) < 0) {
+ (void) fprintf(stderr, "unable to get current timestamp: %s",
+ strerror(errno));
+ return -1;
+ }
+
+ filename = strdup(ts->bprm->filename);
+ base_filename = basename(filename);
+ (void) strftime(timestamp, sizeof(timestamp), "%Y%m%d-%H%M%S",
+ localtime_r(&tv.tv_sec, &tm));
+ (void) snprintf(buf, bufsize, "qemu_%s_%s_%d.core",
+ base_filename, timestamp, (int)getpid());
+ free(filename);
+#else /* ! QEMU_LONG_CORE_FILENAME */
+ char *filename, *base_filename;
+
+ assert(bufsize >= PATH_MAX);
+
+ filename = strdup(ts->bprm->filename);
+ base_filename = basename(filename);
+ (void) snprintf(buf, bufsize, "qemu_%s.core", base_filename);
+ free(filename);
+#endif /* ! QEMU_LONG_CORE_FILENAME */
+
+ return 0;
+}
+
+
+static void fill_elf_header(struct elfhdr *elf, int segs, uint16_t machine,
+ uint32_t flags)
+{
+
+ (void) memset(elf, 0, sizeof(*elf));
+
+ elf->e_ident[EI_MAG0] = ELFMAG0;
+ elf->e_ident[EI_MAG1] = ELFMAG1;
+ elf->e_ident[EI_MAG2] = ELFMAG2;
+ elf->e_ident[EI_MAG3] = ELFMAG3;
+ elf->e_ident[EI_CLASS] = ELF_CLASS;
+ elf->e_ident[EI_DATA] = ELF_DATA;
+ elf->e_ident[EI_VERSION] = EV_CURRENT;
+ elf->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
+ elf->e_type = ET_CORE;
+ elf->e_machine = machine;
+ elf->e_version = EV_CURRENT;
+ elf->e_phoff = sizeof(struct elfhdr);
+ elf->e_flags = flags;
+ elf->e_ehsize = sizeof(struct elfhdr);
+ elf->e_phentsize = sizeof(struct elf_phdr);
+ elf->e_phnum = segs;
+ elf->e_shstrndx = SHN_UNDEF;
+
+ bswap_ehdr(elf);
+}
+
+static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, off_t offset)
+{
+
+ phdr->p_type = PT_NOTE;
+ phdr->p_flags = PF_R; /* Readable */
+ phdr->p_offset = offset;
+ phdr->p_vaddr = 0;
+ phdr->p_paddr = 0;
+ phdr->p_filesz = sz;
+ phdr->p_memsz = 0;
+ phdr->p_align = ELF_NOTE_ROUNDSIZE;
+
+ bswap_phdr(phdr, 1);
+}
+
+static void fill_note(struct memelfnote *note, const char *name, int type,
+ unsigned int sz, void *data, int addsize)
+{
+ unsigned int namesz;
+
+ namesz = strlen(name) + 1;
+ note->name = name;
+ note->namesz = namesz;
+ note->namesz_rounded = roundup2(namesz, sizeof(int32_t));
+ note->type = type;
+ note->addsize = tswap32(addsize);
+
+ if (addsize) {
+ note->datasz = sz;
+ note->datasz_rounded =
+ roundup2((sz + sizeof(uint32_t)), sizeof(int32_t));
+ } else {
+ note->datasz = sz;
+ note->datasz_rounded = roundup2(sz, sizeof(int32_t));
+ }
+ note->data = data;
+
+ /*
+ * We calculate rounded up note size here as specified by
+ * ELF document.
+ */
+ note->notesz = sizeof(struct elf_note) +
+ note->namesz_rounded + note->datasz_rounded;
+}
+
+/*
+ * Initialize the perthread_note_info and process_note_info structures
+ * so that it is at least safe to call free_note_info() on it. Must be
+ * called before calling fill_note_info().
+ */
+static void init_note_info(struct elf_note_info *info)
+{
+
+ memset(info, 0, sizeof(*info));
+ QTAILQ_INIT(&info->thread_list);
+}
+
+static void free_note_info(struct elf_note_info *info)
+{
+ struct elf_thread_status *ets;
+
+ g_free(info->prpsinfo);
+ g_free(info->prstatus);
+ g_free(info->fpregs);
+ g_free(info->thrmisc);
+
+ while (!QTAILQ_EMPTY(&info->thread_list)) {
+ ets = QTAILQ_FIRST(&info->thread_list);
+ QTAILQ_REMOVE(&info->thread_list, ets, ets_link);
+ if (ets) {
+ g_free(ets->prstatus);
+ g_free(ets->fpregs);
+ g_free(ets->thrmisc);
+ g_free(ets);
+ }
+ }
+
+ g_free(info->kiproc);
+ g_free(info->kifiles);
+ g_free(info->kivmentries);
+ g_free(info->groups);
+ g_free(info->rlimits);
+ g_free(info->auxv);
+}
+
+static int dump_write(int fd, const void *ptr, size_t size)
+{
+ const char *bufp = (const char *)ptr;
+ ssize_t bytes_written, bytes_left;
+ struct rlimit dumpsize;
+ off_t pos;
+
+ bytes_written = 0;
+ getrlimit(RLIMIT_CORE, &dumpsize);
+ pos = lseek(fd, 0, SEEK_CUR);
+ if (pos == -1) {
+ if (errno == ESPIPE) { /* not a seekable stream */
+ bytes_left = size;
+ } else {
+ return pos;
+ }
+ } else {
+ if (dumpsize.rlim_cur <= pos) {
+ return -1;
+ } else if (dumpsize.rlim_cur == RLIM_INFINITY) {
+ bytes_left = size;
+ } else {
+ size_t limit_left = dumpsize.rlim_cur - pos;
+ bytes_left = limit_left >= size ? size : limit_left ;
+ }
+ }
+
+ /*
+ * In normal conditions, single write(2) should do but
+ * in case of socket etc. this mechanism is more portable.
+ */
+ do {
+ bytes_written = write(fd, bufp, bytes_left);
+ if (bytes_written < 0) {
+ if (errno == EINTR) {
+ continue;
+ }
+ return -1;
+ } else if (bytes_written == 0) { /* eof */
+ return -1;
+ }
+ bufp += bytes_written;
+ bytes_left -= bytes_written;
+ } while (bytes_left > 0);
+
+ return 0;
+}
+
+
+static int write_note(struct memelfnote *men, int fd)
+{
+ struct elf_note en;
+
+ en.n_namesz = men->namesz_rounded;
+ en.n_descsz = men->datasz_rounded;
+ en.n_type = men->type;
bswap_note(&en);
+ if (dump_write(fd, &en, sizeof(en)) != 0) {
+ return -1;
+ }
+ if (dump_write(fd, men->name, men->namesz_rounded) != 0) {
+ return -1;
+ }
+
+ if (men->addsize)
+ if (dump_write(fd, &men->addsize, sizeof(uint32_t)) != 0) {
+ return -1;
+ }
+
+ if (dump_write(fd, men->data, men->datasz) != 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
+static int write_note_info(struct elf_note_info *info, int fd)
+{
+ struct elf_thread_status *ets;
+ int i, error = 0;
+
+ /* write prpsinfo, prstatus, fpregs, and thrmisc */
+ for (i = 0; i < 4; i++) {
+ error = write_note(&info->notes[i], fd);
+ if (error != 0) {
+ return error;
+ }
+ }
+
+ /* write prstatus, fpregset, & thrmisc for each additional thread */
+ QTAILQ_FOREACH(ets, &info->thread_list, ets_link) {
+ error = write_note(&ets->notes[0], fd);
+ if (error != 0) {
+ return error;
+ }
+ error = write_note(&ets->notes[1], fd);
+ if (error != 0) {
+ return error;
+ }
+ error = write_note(&ets->notes[2], fd);
+ if (error != 0) {
+ return error;
+ }
+ }
+
+ /*
+ * write kiproc, kifiles, kivmmap, groups, umask, rlimits, osrel,
+ * psstrings, and auxv.
+ */
+ for (i = 4; i < info->numnote; i++) {
+ error = write_note(&info->notes[i], fd);
+ if (error != 0) {
+ return error;
+ }
+ }
+
+ return 0;
+}
+
+static size_t note_size(const struct memelfnote *note)
+{
+
+ return note->notesz;
+}
+
+static abi_long fill_thread_info(struct elf_note_info *info, int signr,
+ CPUArchState *env)
+{
+ CPUState *cpu = env_cpu((CPUArchState *)env);
+ TaskState *ts = (TaskState *)cpu->opaque;
+ struct elf_thread_status *ets;
+
+ ets = g_malloc0(sizeof(*ets));
+ if (ets == NULL) {
+ return -TARGET_ENOMEM;
+ }
+ ets->num_notes = 3;
+
+ ets->prstatus = g_malloc0(sizeof(struct target_prstatus));
+ if (ets->prstatus == NULL) {
+ return -TARGET_ENOMEM;
+ }
+ fill_prstatus(env, ets->prstatus, signr);
+ fill_note(&ets->notes[0], "FreeBSD", TARGET_NT_PRSTATUS,
+ sizeof(struct target_prstatus), &ets->prstatus, 0);
+
+
+ ets->fpregs = g_malloc0(sizeof(*ets->fpregs));
+ if (ets->fpregs == NULL) {
+ return -TARGET_ENOMEM;
+ }
+ fill_fpregs(ts, ets->fpregs);
+ fill_note(&ets->notes[1], "FreeBSD", TARGET_NT_FPREGSET,
+ sizeof(*ets->fpregs), ets->fpregs, 0);
+
+ ets->thrmisc = g_malloc0(sizeof(*ets->thrmisc));
+ if (ets->thrmisc == NULL) {
+ return -TARGET_ENOMEM;
+ }
+ fill_thrmisc(env, ts, ets->thrmisc);
+ fill_note(&ets->notes[2], "FreeBSD", TARGET_NT_THRMISC,
+ sizeof(*ets->thrmisc), ets->thrmisc, 0);
+
+ QTAILQ_INSERT_TAIL(&info->thread_list, ets, ets_link);
+
+ info->notes_size += (note_size(&ets->notes[0]) +
+ note_size(&ets->notes[1]) + note_size(&ets->notes[2]));
+
+ return 0;
+}
+
+static abi_long fill_kiproc(TaskState *ts, pid_t pid,
+ struct target_kinfo_proc *tkip)
+{
+ abi_long ret;
+ size_t len = sizeof(*tkip);
+ struct bsd_binprm *bprm = ts->bprm;
+
+ ret = do_sysctl_kern_getprocs(KERN_PROC_PID, pid, len, tkip, &len);
+
+ if (is_error(ret)) {
+ g_free(tkip);
+ }
+
+ /* Fix up some to be the target values. */
+ strncpy(tkip->ki_tdname, basename(bprm->argv[0]), TARGET_TDNAMLEN);
+ strncpy(tkip->ki_comm, basename(bprm->argv[0]), TARGET_COMMLEN);
+#if TARGET_ABI_BITS == 32
+ strncpy(tkip->ki_emul, "FreeBSD ELF32", TARGET_KI_EMULNAMELEN);
+#else
+ strncpy(tkip->ki_emul, "FreeBSD ELF64", TARGET_KI_EMULNAMELEN);
+#endif
+
+ return ret;
+}
+
+
+struct target_elf_auxinfo {
+ abi_long a_type;
+ abi_long a_value;
+};
+
+
+static abi_long fill_auxv(void *auxv, size_t *sz)
+{
+
+ *sz = target_auxents_sz;
+
+ return copy_from_user(auxv, target_auxents, target_auxents_sz);
+}
+
+static abi_long fill_psstrings(abi_ulong *psstrings)
+{
+
+ *psstrings = tswapal(TARGET_PS_STRINGS);
+
return 0;
}
+
+#define MAXNUMNOTES 13
+
+static int fill_note_info(struct elf_note_info *info,
+ int signr, CPUArchState *env)
+{
+ CPUState *cpu = env_cpu((CPUArchState *)env);
+ TaskState *ts = (TaskState *)cpu->opaque;
+ int i, err, numnotes = 0;
+ pid_t pid = getpid();
+
+ info->notes = g_malloc0(MAXNUMNOTES * sizeof(struct memelfnote));
+ if (info->notes == NULL) {
+ err = ENOMEM;
+ goto edone;
+ }
+
+ /* NT_PRPSINFO */
+ info->prpsinfo = g_malloc0(sizeof(*info->prpsinfo));
+ if (info->prpsinfo == NULL) {
+ err = -TARGET_ENOMEM;
+ goto edone;
+ }
+ err = fill_prpsinfo(ts, &info->prpsinfo);
+ if (err != 0) {
+ goto edone;
+ }
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_PRPSINFO,
+ sizeof(*info->prpsinfo), info->prpsinfo, 0);
+
+ /* prstatus, fpregs, and thrmisc for main thread. */
+
+ /* NT_PRSTATUS */
+ info->prstatus = g_malloc0(sizeof(struct target_prstatus));
+ if (info->prstatus == NULL) {
+ err = -TARGET_ENOMEM;
+ goto edone;
+ }
+ err = fill_prstatus(env, info->prstatus, signr);
+ if (err != 0) {
+ goto edone;
+ }
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_PRSTATUS,
+ sizeof(struct target_prstatus), info->prstatus, 0);
+
+ /* NT_FPREGSET */
+ info->fpregs = g_malloc0(sizeof(*info->fpregs));
+ if (info->fpregs == NULL) {
+ err = -TARGET_ENOMEM;
+ goto edone;
+ }
+ fill_fpregs(ts, info->fpregs);
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_FPREGSET,
+ sizeof(*info->fpregs), info->fpregs, 0);
+
+ /* NT_THRMISC */
+ info->thrmisc = g_malloc0(sizeof(*info->thrmisc));
+ if (info->thrmisc == NULL) {
+ err = -TARGET_ENOMEM;
+ goto edone;
+ }
+ fill_thrmisc(env, ts, info->thrmisc);
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_THRMISC,
+ sizeof(*info->thrmisc), info->thrmisc, 0);
+
+ /* NT_PROCSTAT_PROC */
+ info->kiproc = g_malloc0(sizeof(*info->kiproc));
+ if (info->kiproc == NULL) {
+ err = -TARGET_ENOMEM;
+ goto edone;
+ }
+ err = fill_kiproc(ts, pid, info->kiproc);
+ if (err != 0) {
+ goto edone;
+ }
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_PROCSTAT_PROC,
+ sizeof(*info->kiproc), info->kiproc,
+ sizeof(struct target_kinfo_proc));
+
+ /* NT_PROCSTAT_FILES */
+ info->kifiles = alloc_kifiles(pid, &info->kifiles_sz);
+ if (info->kifiles == NULL) {
+ err = -TARGET_ENOMEM;
+ goto edone;
+ }
+ err = fill_kifiles(pid, info->kifiles, &info->kifiles_sz);
+ if (err != 0) {
+ goto edone;
+ }
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_PROCSTAT_FILES,
+ info->kifiles_sz, info->kifiles,
+ sizeof(struct target_kinfo_file));
+
+ /* NT_PROCSTAT_VMMAP */
+ info->kivmentries = alloc_kivmentries(pid, &info->kivmentries_sz);
+ if (info->kivmentries == NULL) {
+ err = -TARGET_ENOMEM;
+ goto edone;
+ }
+ err = fill_kivmentries(pid, info->kivmentries, &info->kivmentries_sz);
+ if (err != 0) {
+ goto edone;
+ }
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_PROCSTAT_VMMAP,
+ info->kivmentries_sz, info->kivmentries,
+ sizeof(struct target_kinfo_vmentry));
+
+ /* NT_PROCSTAT_GROUPS */
+ info->groups = alloc_groups(&info->groups_sz);
+ if (info->groups == NULL) {
+ err = -TARGET_ENOMEM;
+ goto edone;
+ }
+ err = fill_groups(info->groups, &info->groups_sz);
+ if (err != 0) {
+ goto edone;
+ }
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_PROCSTAT_GROUPS,
+ info->groups_sz, info->groups,
+ sizeof(uint32_t));
+
+ /* NT_PROCSTAT_RLIMIT */
+ info->rlimits = g_malloc0(RLIM_NLIMITS * sizeof(struct rlimit));
+ if (info->rlimits == NULL) {
+ return -TARGET_ENOMEM;
+ }
+ err = fill_rlimits(info->rlimits);
+ if (err != 0) {
+ goto edone;
+ }
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_PROCSTAT_RLIMIT,
+ sizeof(struct rlimit) * RLIM_NLIMITS, info->rlimits,
+ sizeof(struct rlimit) * RLIM_NLIMITS);
+
+ /* NT_PROCSTAT_OSREL */
+ err = fill_osreldate(&info->osreldate);
+ if (err != 0) {
+ goto edone;
+ }
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_PROCSTAT_OSREL,
+ sizeof(info->osreldate), &info->osreldate,
+ sizeof(int32_t));
+
+ /* NT_PROCSTAT_PSSTRINGS */
+ err = fill_psstrings(&info->psstrings);
+ if (err != 0) {
+ goto edone;
+ }
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_PROCSTAT_PSSTRINGS,
+ sizeof(info->psstrings), &info->psstrings,
+ sizeof(abi_ulong));
+
+ /* NT_PROCSTAT_AUXV */
+ info->auxv = g_malloc0(target_auxents_sz);
+ if (info->auxv == NULL) {
+ err = -TARGET_ENOMEM;
+ goto edone;
+ }
+ err = fill_auxv(info->auxv, &info->auxv_sz);
+ if (err != 0) {
+ goto edone;
+ }
+ fill_note(&info->notes[numnotes++], "FreeBSD", TARGET_NT_PROCSTAT_AUXV,
+ info->auxv_sz, info->auxv,
+ sizeof(struct target_elf_auxinfo));
+
+ assert(numnotes <= MAXNUMNOTES);
+ info->numnote = numnotes;
+ info->notes_size = 0;
+ for (i = 0; i < numnotes; i++) {
+ info->notes_size += note_size(&info->notes[i]);
+ }
+
+ /* read and fill status of all threads */
+ cpu_list_lock();
+ CPU_FOREACH(cpu) {
+ if (cpu == thread_cpu) {
+ continue;
+ }
+ err = fill_thread_info(info, signr, (CPUArchState *)cpu->env_ptr);
+ if (err != 0) {
+ cpu_list_unlock();
+ goto edone;
+ }
+ }
+ cpu_list_unlock();
+
+ return 0;
+
+edone:
+ free_note_info(info);
+ return err;
+}
+
+static int elf_core_dump(int signr, CPUArchState *env)
+{
+ int fd = -1;
+ int segs = 0;
+ off_t offset = 0, data_offset = 0;
+ CPUState *cpu = env_cpu((CPUArchState *)env);
+ TaskState *ts = (TaskState *)cpu->opaque;
+ struct vm_area_struct *vma = NULL;
+ struct mm_struct *mm = NULL;
+ struct rlimit dumpsize;
+ struct elfhdr elf;
+ struct elf_phdr phdr;
+ struct elf_note_info info;
+ char corefile[PATH_MAX];
+
+ init_note_info(&info);
+
+ errno = 0;
+ getrlimit(RLIMIT_CORE, &dumpsize);
+ if (dumpsize.rlim_cur == 0) {
+ return 0;
+ }
+
+ if (core_dump_filename(ts, corefile, sizeof(corefile)) < 0) {
+ return -(errno);
+ }
+
+ fd = open(corefile, O_WRONLY | O_CREAT,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (fd < 0) {
+ return -(errno);
+ }
+
+ /*
+ * Walk through target process memory mappings and
+ * set up structure containing this information. After
+ * this point vma_xxx functions can be used.
+ */
+ mm = vma_init();
+ if (mm == NULL) {
+ goto out;
+ }
+
+ walk_memory_regions(mm, vma_walker);
+ segs = vma_get_mapping_count(mm);
+
+ /*
+ * Construct the coredump ELF header. Add another segment for
+ * notes.
+ *
+ * See kern/imgact_elf.c __elfN(corehdr)().
+ */
+ fill_elf_header(&elf, segs + 1, ELF_MACHINE, ts->info->elf_flags);
+ if (dump_write(fd, &elf, sizeof(elf)) != 0) {
+ goto out;
+ }
+
+ /*
+ * Construct the note segment and write it out.
+ */
+ if (fill_note_info(&info, signr, env) < 0) {
+ goto out;
+ }
+
+ offset += sizeof(elf); /* elf header */
+ offset += (segs + 1) * sizeof(struct elf_phdr); /* program headers */
+
+ /* Write out notes program header. */
+ fill_elf_note_phdr(&phdr, info.notes_size, offset);
+
+ offset += info.notes_size;
+ if (dump_write(fd, &phdr, sizeof(phdr)) != 0) {
+ goto out;
+ }
+
+ /*
+ * ELF specification wants data to start at page boundary so
+ * we align it here.
+ */
+ data_offset = offset = roundup(offset, ELF_EXEC_PAGESIZE);
+
+ /*
+ * Write program headers for memory regions mapped in the
+ * target process.
+ *
+ * See cb_put_phdr() in sys/kern/imgact_ef.c
+ */
+ for (vma = vma_first(mm); vma != NULL; vma = vma_next(vma)) {
+ (void) memset(&phdr, 0, sizeof(phdr));
+
+ phdr.p_type = PT_LOAD;
+ phdr.p_offset = offset;
+ phdr.p_vaddr = vma->vma_start;
+ phdr.p_paddr = 0;
+ phdr.p_filesz = vma_dump_size(vma); /* ??? */
+ offset += phdr.p_filesz;
+ phdr.p_memsz = vma->vma_end - vma->vma_start;
+ phdr.p_flags = vma->vma_flags & PROT_READ ? PF_R : 0;
+ if (vma->vma_flags & PROT_WRITE) {
+ phdr.p_flags |= PF_W;
+ }
+ if (vma->vma_flags & PROT_EXEC) {
+ phdr.p_flags |= PF_X;
+ }
+ phdr.p_align = ELF_EXEC_PAGESIZE; /* or PAGE_SIZE? */
+
+ bswap_phdr(&phdr, 1);
+ dump_write(fd, &phdr, sizeof(phdr));
+ }
+
+ /*
+ * Next write notes just after program headers.
+ */
+ if (write_note_info(&info, fd) < 0) {
+ goto out;
+ }
+
+ /*
+ * Align data to page boundary.
+ */
+ if (lseek(fd, data_offset, SEEK_SET) != data_offset) {
+ goto out;
+ }
+
+ /*
+ * Finally, dump the process memory into the corefile as well.
+ */
+ for (vma = vma_first(mm); vma != NULL; vma = vma_next(vma)) {
+ abi_ulong addr;
+ abi_ulong end;
+
+ end = vma->vma_start + vma_dump_size(vma);
+
+ for (addr = vma->vma_start; addr < end;
+ addr += TARGET_PAGE_SIZE) {
+ char page[TARGET_PAGE_SIZE];
+ int error;
+
+ /*
+ * Read in page from target process memory and
+ * write it to coredump file.
+ */
+ error = copy_from_user(page, addr, sizeof(page));
+ if (error != 0) {
+ (void) fprintf(stderr, "unable to dump " TARGET_ABI_FMT_lx "\n",
+ addr);
+ errno = -error;
+ goto out;
+ }
+ if (dump_write(fd, page, TARGET_PAGE_SIZE) < 0) {
+ goto out;
+ }
+ }
+ }
+ errno = 0;
+
+out:
+ if (mm != NULL) {
+ vma_delete(mm);
+ }
+
+ (void)close(fd);
+
+ if (errno != 0) {
+ return -errno;
+ }
+ return 0;
+}
+
+#endif /* USE_ELF_CORE_DUMP */
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 15/19] bsd-user: Add SIGSYS to core dump signals.
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (13 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 14/19] bsd-user: Implement core dumps Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 16/19] bsd-user: Implement SIGSYS on arm Warner Losh
` (3 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Richard Henderson
SIGSYS creates a core by default if uncaught. Follow that here. Sort
with the same order as is in the kernel.
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/signal.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/bsd-user/signal.c b/bsd-user/signal.c
index f4e078ee1da..4301595cc2f 100644
--- a/bsd-user/signal.c
+++ b/bsd-user/signal.c
@@ -330,17 +330,22 @@ int block_signals(void)
return qatomic_xchg(&ts->signal_pending, 1);
}
-/* Returns 1 if given signal should dump core if not handled. */
+/*
+ * Returns 1 if given signal should dump core if not handled.
+ * Compare with kern_sig.c sigproptbl[].
+ */
static int core_dump_signal(int sig)
{
switch (sig) {
+ case TARGET_SIGQUIT:
+ case TARGET_SIGILL:
+ case TARGET_SIGTRAP:
case TARGET_SIGABRT:
+ case TARGET_SIGEMT:
case TARGET_SIGFPE:
- case TARGET_SIGILL:
- case TARGET_SIGQUIT:
case TARGET_SIGSEGV:
- case TARGET_SIGTRAP:
case TARGET_SIGBUS:
+ case TARGET_SIGSYS:
return 1;
default:
return 0;
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 16/19] bsd-user: Implement SIGSYS on arm
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (14 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 15/19] bsd-user: Add SIGSYS to core dump signals Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-10 18:20 ` [PATCH v2 17/19] bsd-user: Remove host-os.h Warner Losh
` (2 subsequent siblings)
18 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud, Richard Henderson
When a system call returns ENOSYS, send a SIGSYS to the process (to
generate a core dump).
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/arm/target_arch_cpu.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/bsd-user/arm/target_arch_cpu.h b/bsd-user/arm/target_arch_cpu.h
index 517d0087644..c4b21fef713 100644
--- a/bsd-user/arm/target_arch_cpu.h
+++ b/bsd-user/arm/target_arch_cpu.h
@@ -127,6 +127,14 @@ static inline void target_cpu_loop(CPUARMState *env)
env->regs[15] -= env->thumb ? 2 : 4;
break;
}
+ /*
+ * Emulate BSD's sigsys behavior on unimplemented system calls.
+ * XXX may need to gate this somehow or arrange for sigsys to be
+ * masked in some use cases.
+ */
+ if (ret == -TARGET_ENOSYS) {
+ force_sig_fault(TARGET_SIGSYS, SI_KERNEL, env->regs[15]);
+ }
if ((unsigned int)ret >= (unsigned int)(-515)) {
ret = -ret;
cpsr_write(env, CPSR_C, CPSR_C, CPSRWriteByInstr);
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 17/19] bsd-user: Remove host-os.h
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (15 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 16/19] bsd-user: Implement SIGSYS on arm Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-11 1:32 ` Richard Henderson
2023-04-10 18:20 ` [PATCH v2 18/19] bsd-user: Update system call list Warner Losh
2023-04-10 18:20 ` [PATCH v2 19/19] bsd-user: Eliminate USE_ELF_CORE_DUMP Warner Losh
18 siblings, 1 reply; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud
It only defines the default system call scheme to use. However, that
feature was removed in a941a16f6f52.
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
bsd-user/freebsd/host-os.h | 25 -------------------------
bsd-user/main.c | 1 -
bsd-user/netbsd/host-os.h | 25 -------------------------
bsd-user/openbsd/host-os.h | 25 -------------------------
4 files changed, 76 deletions(-)
delete mode 100644 bsd-user/freebsd/host-os.h
delete mode 100644 bsd-user/netbsd/host-os.h
delete mode 100644 bsd-user/openbsd/host-os.h
diff --git a/bsd-user/freebsd/host-os.h b/bsd-user/freebsd/host-os.h
deleted file mode 100644
index 40cae72ec9a..00000000000
--- a/bsd-user/freebsd/host-os.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * FreeBSD host dependent code and definitions
- *
- * 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 HOST_OS_H
-#define HOST_OS_H
-
-#define HOST_DEFAULT_BSD_TYPE target_freebsd
-
-#endif /* HOST_OS_H */
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 89f225dead2..ba23b74d679 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -46,7 +46,6 @@
#include "qemu/guest-random.h"
#include "gdbstub/user.h"
-#include "host-os.h"
#include "target_arch_cpu.h"
int singlestep;
diff --git a/bsd-user/netbsd/host-os.h b/bsd-user/netbsd/host-os.h
deleted file mode 100644
index 7c14b1ea780..00000000000
--- a/bsd-user/netbsd/host-os.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * NetBSD host dependent code and definitions
- *
- * 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 HOST_OS_H
-#define HOST_OS_H
-
-#define HOST_DEFAULT_BSD_TYPE target_netbsd
-
-#endif /* HOST_OS_H */
diff --git a/bsd-user/openbsd/host-os.h b/bsd-user/openbsd/host-os.h
deleted file mode 100644
index b9222335d46..00000000000
--- a/bsd-user/openbsd/host-os.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * OpenBSD host dependent code and definitions
- *
- * 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 HOST_OS_H
-#define HOST_OS_H
-
-#define HOST_DEFAULT_BSD_TYPE target_openbsd
-
-#endif /* HOST_OS_H */
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2 17/19] bsd-user: Remove host-os.h
2023-04-10 18:20 ` [PATCH v2 17/19] bsd-user: Remove host-os.h Warner Losh
@ 2023-04-11 1:32 ` Richard Henderson
0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2023-04-11 1:32 UTC (permalink / raw)
To: Warner Losh, qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith, reinoud
On 4/10/23 11:20, Warner Losh wrote:
> It only defines the default system call scheme to use. However, that
> feature was removed in a941a16f6f52.
>
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
> bsd-user/freebsd/host-os.h | 25 -------------------------
> bsd-user/main.c | 1 -
> bsd-user/netbsd/host-os.h | 25 -------------------------
> bsd-user/openbsd/host-os.h | 25 -------------------------
> 4 files changed, 76 deletions(-)
> delete mode 100644 bsd-user/freebsd/host-os.h
> delete mode 100644 bsd-user/netbsd/host-os.h
> delete mode 100644 bsd-user/openbsd/host-os.h
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 18/19] bsd-user: Update system call list
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (16 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 17/19] bsd-user: Remove host-os.h Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-11 1:37 ` Richard Henderson
2023-04-10 18:20 ` [PATCH v2 19/19] bsd-user: Eliminate USE_ELF_CORE_DUMP Warner Losh
18 siblings, 1 reply; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud
Update the system call list. We have one hokey thing in here for swapoff
that depends on the version number (so this is not completely generated
at the moment). For this, we need to include sys/param.h. The method of
generation has changed, so this diff looks way bigger than it needs to
be to add the few lines of code for the new system calls.
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
bsd-user/freebsd/os-syscall.h | 2 +
bsd-user/freebsd/syscall_nr.h | 1035 +++++++++++++++++----------------
2 files changed, 529 insertions(+), 508 deletions(-)
diff --git a/bsd-user/freebsd/os-syscall.h b/bsd-user/freebsd/os-syscall.h
index 1f2c0acb1c5..e77745eeb5c 100644
--- a/bsd-user/freebsd/os-syscall.h
+++ b/bsd-user/freebsd/os-syscall.h
@@ -6,6 +6,8 @@
* OS-Specific portion of syscall_defs.h
*/
+#include <sys/param.h> /* Needed for __FreeBSD_version */
+
#include "freebsd/syscall_nr.h"
/*
diff --git a/bsd-user/freebsd/syscall_nr.h b/bsd-user/freebsd/syscall_nr.h
index 7f73a6d0f19..b6dc6123db1 100644
--- a/bsd-user/freebsd/syscall_nr.h
+++ b/bsd-user/freebsd/syscall_nr.h
@@ -1,3 +1,7 @@
+/*
+ * This file was generated from /usr/include/sys/syscall.h
+ */
+
/*
* System call numbers.
*
@@ -5,511 +9,526 @@
* $FreeBSD$
*/
-#define TARGET_FREEBSD_NR_syscall 0
-#define TARGET_FREEBSD_NR_exit 1
-#define TARGET_FREEBSD_NR_fork 2
-#define TARGET_FREEBSD_NR_read 3
-#define TARGET_FREEBSD_NR_write 4
-#define TARGET_FREEBSD_NR_open 5
-#define TARGET_FREEBSD_NR_close 6
-#define TARGET_FREEBSD_NR_wait4 7
- /* 8 is old creat */
-#define TARGET_FREEBSD_NR_link 9
-#define TARGET_FREEBSD_NR_unlink 10
- /* 11 is obsolete execv */
-#define TARGET_FREEBSD_NR_chdir 12
-#define TARGET_FREEBSD_NR_fchdir 13
-#define TARGET_FREEBSD_NR_freebsd11_mknod 14
-#define TARGET_FREEBSD_NR_chmod 15
-#define TARGET_FREEBSD_NR_chown 16
-#define TARGET_FREEBSD_NR_break 17
- /* 18 is freebsd4 getfsstat */
- /* 19 is old lseek */
-#define TARGET_FREEBSD_NR_getpid 20
-#define TARGET_FREEBSD_NR_mount 21
-#define TARGET_FREEBSD_NR_unmount 22
-#define TARGET_FREEBSD_NR_setuid 23
-#define TARGET_FREEBSD_NR_getuid 24
-#define TARGET_FREEBSD_NR_geteuid 25
-#define TARGET_FREEBSD_NR_ptrace 26
-#define TARGET_FREEBSD_NR_recvmsg 27
-#define TARGET_FREEBSD_NR_sendmsg 28
-#define TARGET_FREEBSD_NR_recvfrom 29
-#define TARGET_FREEBSD_NR_accept 30
-#define TARGET_FREEBSD_NR_getpeername 31
-#define TARGET_FREEBSD_NR_getsockname 32
-#define TARGET_FREEBSD_NR_access 33
-#define TARGET_FREEBSD_NR_chflags 34
-#define TARGET_FREEBSD_NR_fchflags 35
-#define TARGET_FREEBSD_NR_sync 36
-#define TARGET_FREEBSD_NR_kill 37
- /* 38 is old stat */
-#define TARGET_FREEBSD_NR_getppid 39
- /* 40 is old lstat */
-#define TARGET_FREEBSD_NR_dup 41
-#define TARGET_FREEBSD_NR_freebsd10_pipe 42
-#define TARGET_FREEBSD_NR_getegid 43
-#define TARGET_FREEBSD_NR_profil 44
-#define TARGET_FREEBSD_NR_ktrace 45
- /* 46 is old sigaction */
-#define TARGET_FREEBSD_NR_getgid 47
- /* 48 is old sigprocmask */
-#define TARGET_FREEBSD_NR_getlogin 49
-#define TARGET_FREEBSD_NR_setlogin 50
-#define TARGET_FREEBSD_NR_acct 51
- /* 52 is old sigpending */
-#define TARGET_FREEBSD_NR_sigaltstack 53
-#define TARGET_FREEBSD_NR_ioctl 54
-#define TARGET_FREEBSD_NR_reboot 55
-#define TARGET_FREEBSD_NR_revoke 56
-#define TARGET_FREEBSD_NR_symlink 57
-#define TARGET_FREEBSD_NR_readlink 58
-#define TARGET_FREEBSD_NR_execve 59
-#define TARGET_FREEBSD_NR_umask 60
-#define TARGET_FREEBSD_NR_chroot 61
- /* 62 is old fstat */
- /* 63 is old getkerninfo */
- /* 64 is old getpagesize */
-#define TARGET_FREEBSD_NR_msync 65
-#define TARGET_FREEBSD_NR_vfork 66
- /* 67 is obsolete vread */
- /* 68 is obsolete vwrite */
-#define TARGET_FREEBSD_NR_sbrk 69
-#define TARGET_FREEBSD_NR_sstk 70
- /* 71 is old mmap */
-#define TARGET_FREEBSD_NR_freebsd11_vadvise 72
-#define TARGET_FREEBSD_NR_munmap 73
-#define TARGET_FREEBSD_NR_mprotect 74
-#define TARGET_FREEBSD_NR_madvise 75
- /* 76 is obsolete vhangup */
- /* 77 is obsolete vlimit */
-#define TARGET_FREEBSD_NR_mincore 78
-#define TARGET_FREEBSD_NR_getgroups 79
-#define TARGET_FREEBSD_NR_setgroups 80
-#define TARGET_FREEBSD_NR_getpgrp 81
-#define TARGET_FREEBSD_NR_setpgid 82
-#define TARGET_FREEBSD_NR_setitimer 83
- /* 84 is old wait */
-#define TARGET_FREEBSD_NR_swapon 85
-#define TARGET_FREEBSD_NR_getitimer 86
- /* 87 is old gethostname */
- /* 88 is old sethostname */
-#define TARGET_FREEBSD_NR_getdtablesize 89
-#define TARGET_FREEBSD_NR_dup2 90
-#define TARGET_FREEBSD_NR_fcntl 92
-#define TARGET_FREEBSD_NR_select 93
-#define TARGET_FREEBSD_NR_fsync 95
-#define TARGET_FREEBSD_NR_setpriority 96
-#define TARGET_FREEBSD_NR_socket 97
-#define TARGET_FREEBSD_NR_connect 98
- /* 99 is old accept */
-#define TARGET_FREEBSD_NR_getpriority 100
- /* 101 is old send */
- /* 102 is old recv */
- /* 103 is old sigreturn */
-#define TARGET_FREEBSD_NR_bind 104
-#define TARGET_FREEBSD_NR_setsockopt 105
-#define TARGET_FREEBSD_NR_listen 106
- /* 107 is obsolete vtimes */
- /* 108 is old sigvec */
- /* 109 is old sigblock */
- /* 110 is old sigsetmask */
- /* 111 is old sigsuspend */
- /* 112 is old sigstack */
- /* 113 is old recvmsg */
- /* 114 is old sendmsg */
- /* 115 is obsolete vtrace */
-#define TARGET_FREEBSD_NR_gettimeofday 116
-#define TARGET_FREEBSD_NR_getrusage 117
-#define TARGET_FREEBSD_NR_getsockopt 118
-#define TARGET_FREEBSD_NR_readv 120
-#define TARGET_FREEBSD_NR_writev 121
-#define TARGET_FREEBSD_NR_settimeofday 122
-#define TARGET_FREEBSD_NR_fchown 123
-#define TARGET_FREEBSD_NR_fchmod 124
- /* 125 is old recvfrom */
-#define TARGET_FREEBSD_NR_setreuid 126
-#define TARGET_FREEBSD_NR_setregid 127
-#define TARGET_FREEBSD_NR_rename 128
- /* 129 is old truncate */
- /* 130 is old ftruncate */
-#define TARGET_FREEBSD_NR_flock 131
-#define TARGET_FREEBSD_NR_mkfifo 132
-#define TARGET_FREEBSD_NR_sendto 133
-#define TARGET_FREEBSD_NR_shutdown 134
-#define TARGET_FREEBSD_NR_socketpair 135
-#define TARGET_FREEBSD_NR_mkdir 136
-#define TARGET_FREEBSD_NR_rmdir 137
-#define TARGET_FREEBSD_NR_utimes 138
- /* 139 is obsolete 4.2 sigreturn */
-#define TARGET_FREEBSD_NR_adjtime 140
- /* 141 is old getpeername */
- /* 142 is old gethostid */
- /* 143 is old sethostid */
- /* 144 is old getrlimit */
- /* 145 is old setrlimit */
- /* 146 is old killpg */
-#define TARGET_FREEBSD_NR_setsid 147
-#define TARGET_FREEBSD_NR_quotactl 148
- /* 149 is old quota */
- /* 150 is old getsockname */
-#define TARGET_FREEBSD_NR_nlm_syscall 154
-#define TARGET_FREEBSD_NR_nfssvc 155
- /* 156 is old getdirentries */
- /* 157 is freebsd4 statfs */
- /* 158 is freebsd4 fstatfs */
-#define TARGET_FREEBSD_NR_lgetfh 160
-#define TARGET_FREEBSD_NR_getfh 161
- /* 162 is freebsd4 getdomainname */
- /* 163 is freebsd4 setdomainname */
- /* 164 is freebsd4 uname */
-#define TARGET_FREEBSD_NR_sysarch 165
-#define TARGET_FREEBSD_NR_rtprio 166
-#define TARGET_FREEBSD_NR_semsys 169
-#define TARGET_FREEBSD_NR_msgsys 170
-#define TARGET_FREEBSD_NR_shmsys 171
- /* 173 is freebsd6 pread */
- /* 174 is freebsd6 pwrite */
-#define TARGET_FREEBSD_NR_setfib 175
-#define TARGET_FREEBSD_NR_ntp_adjtime 176
-#define TARGET_FREEBSD_NR_setgid 181
-#define TARGET_FREEBSD_NR_setegid 182
-#define TARGET_FREEBSD_NR_seteuid 183
- /* 184 is obsolete lfs_bmapv */
- /* 185 is obsolete lfs_markv */
- /* 186 is obsolete lfs_segclean */
- /* 187 is obsolete lfs_segwait */
-#define TARGET_FREEBSD_NR_freebsd11_stat 188
-#define TARGET_FREEBSD_NR_freebsd11_fstat 189
-#define TARGET_FREEBSD_NR_freebsd11_lstat 190
-#define TARGET_FREEBSD_NR_pathconf 191
-#define TARGET_FREEBSD_NR_fpathconf 192
-#define TARGET_FREEBSD_NR_getrlimit 194
-#define TARGET_FREEBSD_NR_setrlimit 195
-#define TARGET_FREEBSD_NR_freebsd11_getdirentries 196
- /* 197 is freebsd6 mmap */
-#define TARGET_FREEBSD_NR___syscall 198
- /* 199 is freebsd6 lseek */
- /* 200 is freebsd6 truncate */
- /* 201 is freebsd6 ftruncate */
-#define TARGET_FREEBSD_NR___sysctl 202
-#define TARGET_FREEBSD_NR_mlock 203
-#define TARGET_FREEBSD_NR_munlock 204
-#define TARGET_FREEBSD_NR_undelete 205
-#define TARGET_FREEBSD_NR_futimes 206
-#define TARGET_FREEBSD_NR_getpgid 207
-#define TARGET_FREEBSD_NR_poll 209
-#define TARGET_FREEBSD_NR_freebsd7___semctl 220
-#define TARGET_FREEBSD_NR_semget 221
-#define TARGET_FREEBSD_NR_semop 222
- /* 223 is obsolete semconfig */
-#define TARGET_FREEBSD_NR_freebsd7_msgctl 224
-#define TARGET_FREEBSD_NR_msgget 225
-#define TARGET_FREEBSD_NR_msgsnd 226
-#define TARGET_FREEBSD_NR_msgrcv 227
-#define TARGET_FREEBSD_NR_shmat 228
-#define TARGET_FREEBSD_NR_freebsd7_shmctl 229
-#define TARGET_FREEBSD_NR_shmdt 230
-#define TARGET_FREEBSD_NR_shmget 231
-#define TARGET_FREEBSD_NR_clock_gettime 232
-#define TARGET_FREEBSD_NR_clock_settime 233
-#define TARGET_FREEBSD_NR_clock_getres 234
-#define TARGET_FREEBSD_NR_ktimer_create 235
-#define TARGET_FREEBSD_NR_ktimer_delete 236
-#define TARGET_FREEBSD_NR_ktimer_settime 237
-#define TARGET_FREEBSD_NR_ktimer_gettime 238
-#define TARGET_FREEBSD_NR_ktimer_getoverrun 239
-#define TARGET_FREEBSD_NR_nanosleep 240
-#define TARGET_FREEBSD_NR_ffclock_getcounter 241
-#define TARGET_FREEBSD_NR_ffclock_setestimate 242
-#define TARGET_FREEBSD_NR_ffclock_getestimate 243
-#define TARGET_FREEBSD_NR_clock_nanosleep 244
-#define TARGET_FREEBSD_NR_clock_getcpuclockid2 247
-#define TARGET_FREEBSD_NR_ntp_gettime 248
-#define TARGET_FREEBSD_NR_minherit 250
-#define TARGET_FREEBSD_NR_rfork 251
- /* 252 is obsolete openbsd_poll */
-#define TARGET_FREEBSD_NR_issetugid 253
-#define TARGET_FREEBSD_NR_lchown 254
-#define TARGET_FREEBSD_NR_aio_read 255
-#define TARGET_FREEBSD_NR_aio_write 256
-#define TARGET_FREEBSD_NR_lio_listio 257
-#define TARGET_FREEBSD_NR_freebsd11_getdents 272
-#define TARGET_FREEBSD_NR_lchmod 274
- /* 275 is obsolete netbsd_lchown */
-#define TARGET_FREEBSD_NR_lutimes 276
- /* 277 is obsolete netbsd_msync */
-#define TARGET_FREEBSD_NR_freebsd11_nstat 278
-#define TARGET_FREEBSD_NR_freebsd11_nfstat 279
-#define TARGET_FREEBSD_NR_freebsd11_nlstat 280
-#define TARGET_FREEBSD_NR_preadv 289
-#define TARGET_FREEBSD_NR_pwritev 290
- /* 297 is freebsd4 fhstatfs */
-#define TARGET_FREEBSD_NR_fhopen 298
-#define TARGET_FREEBSD_NR_freebsd11_fhstat 299
-#define TARGET_FREEBSD_NR_modnext 300
-#define TARGET_FREEBSD_NR_modstat 301
-#define TARGET_FREEBSD_NR_modfnext 302
-#define TARGET_FREEBSD_NR_modfind 303
-#define TARGET_FREEBSD_NR_kldload 304
-#define TARGET_FREEBSD_NR_kldunload 305
-#define TARGET_FREEBSD_NR_kldfind 306
-#define TARGET_FREEBSD_NR_kldnext 307
-#define TARGET_FREEBSD_NR_kldstat 308
-#define TARGET_FREEBSD_NR_kldfirstmod 309
-#define TARGET_FREEBSD_NR_getsid 310
-#define TARGET_FREEBSD_NR_setresuid 311
-#define TARGET_FREEBSD_NR_setresgid 312
- /* 313 is obsolete signanosleep */
-#define TARGET_FREEBSD_NR_aio_return 314
-#define TARGET_FREEBSD_NR_aio_suspend 315
-#define TARGET_FREEBSD_NR_aio_cancel 316
-#define TARGET_FREEBSD_NR_aio_error 317
- /* 318 is freebsd6 aio_read */
- /* 319 is freebsd6 aio_write */
- /* 320 is freebsd6 lio_listio */
-#define TARGET_FREEBSD_NR_yield 321
- /* 322 is obsolete thr_sleep */
- /* 323 is obsolete thr_wakeup */
-#define TARGET_FREEBSD_NR_mlockall 324
-#define TARGET_FREEBSD_NR_munlockall 325
-#define TARGET_FREEBSD_NR___getcwd 326
-#define TARGET_FREEBSD_NR_sched_setparam 327
-#define TARGET_FREEBSD_NR_sched_getparam 328
-#define TARGET_FREEBSD_NR_sched_setscheduler 329
-#define TARGET_FREEBSD_NR_sched_getscheduler 330
-#define TARGET_FREEBSD_NR_sched_yield 331
-#define TARGET_FREEBSD_NR_sched_get_priority_max 332
-#define TARGET_FREEBSD_NR_sched_get_priority_min 333
-#define TARGET_FREEBSD_NR_sched_rr_get_interval 334
-#define TARGET_FREEBSD_NR_utrace 335
- /* 336 is freebsd4 sendfile */
-#define TARGET_FREEBSD_NR_kldsym 337
-#define TARGET_FREEBSD_NR_jail 338
-#define TARGET_FREEBSD_NR_nnpfs_syscall 339
-#define TARGET_FREEBSD_NR_sigprocmask 340
-#define TARGET_FREEBSD_NR_sigsuspend 341
- /* 342 is freebsd4 sigaction */
-#define TARGET_FREEBSD_NR_sigpending 343
- /* 344 is freebsd4 sigreturn */
-#define TARGET_FREEBSD_NR_sigtimedwait 345
-#define TARGET_FREEBSD_NR_sigwaitinfo 346
-#define TARGET_FREEBSD_NR___acl_get_file 347
-#define TARGET_FREEBSD_NR___acl_set_file 348
-#define TARGET_FREEBSD_NR___acl_get_fd 349
-#define TARGET_FREEBSD_NR___acl_set_fd 350
-#define TARGET_FREEBSD_NR___acl_delete_file 351
-#define TARGET_FREEBSD_NR___acl_delete_fd 352
-#define TARGET_FREEBSD_NR___acl_aclcheck_file 353
-#define TARGET_FREEBSD_NR___acl_aclcheck_fd 354
-#define TARGET_FREEBSD_NR_extattrctl 355
-#define TARGET_FREEBSD_NR_extattr_set_file 356
-#define TARGET_FREEBSD_NR_extattr_get_file 357
-#define TARGET_FREEBSD_NR_extattr_delete_file 358
-#define TARGET_FREEBSD_NR_aio_waitcomplete 359
-#define TARGET_FREEBSD_NR_getresuid 360
-#define TARGET_FREEBSD_NR_getresgid 361
-#define TARGET_FREEBSD_NR_kqueue 362
-#define TARGET_FREEBSD_NR_freebsd11_kevent 363
- /* 364 is obsolete __cap_get_proc */
- /* 365 is obsolete __cap_set_proc */
- /* 366 is obsolete __cap_get_fd */
- /* 367 is obsolete __cap_get_file */
- /* 368 is obsolete __cap_set_fd */
- /* 369 is obsolete __cap_set_file */
-#define TARGET_FREEBSD_NR_extattr_set_fd 371
-#define TARGET_FREEBSD_NR_extattr_get_fd 372
-#define TARGET_FREEBSD_NR_extattr_delete_fd 373
-#define TARGET_FREEBSD_NR___setugid 374
- /* 375 is obsolete nfsclnt */
-#define TARGET_FREEBSD_NR_eaccess 376
-#define TARGET_FREEBSD_NR_afs3_syscall 377
-#define TARGET_FREEBSD_NR_nmount 378
- /* 379 is obsolete kse_exit */
- /* 380 is obsolete kse_wakeup */
- /* 381 is obsolete kse_create */
- /* 382 is obsolete kse_thr_interrupt */
- /* 383 is obsolete kse_release */
-#define TARGET_FREEBSD_NR___mac_get_proc 384
-#define TARGET_FREEBSD_NR___mac_set_proc 385
-#define TARGET_FREEBSD_NR___mac_get_fd 386
-#define TARGET_FREEBSD_NR___mac_get_file 387
-#define TARGET_FREEBSD_NR___mac_set_fd 388
-#define TARGET_FREEBSD_NR___mac_set_file 389
-#define TARGET_FREEBSD_NR_kenv 390
-#define TARGET_FREEBSD_NR_lchflags 391
-#define TARGET_FREEBSD_NR_uuidgen 392
-#define TARGET_FREEBSD_NR_sendfile 393
-#define TARGET_FREEBSD_NR_mac_syscall 394
-#define TARGET_FREEBSD_NR_freebsd11_getfsstat 395
-#define TARGET_FREEBSD_NR_freebsd11_statfs 396
-#define TARGET_FREEBSD_NR_freebsd11_fstatfs 397
-#define TARGET_FREEBSD_NR_freebsd11_fhstatfs 398
-#define TARGET_FREEBSD_NR_ksem_close 400
-#define TARGET_FREEBSD_NR_ksem_post 401
-#define TARGET_FREEBSD_NR_ksem_wait 402
-#define TARGET_FREEBSD_NR_ksem_trywait 403
-#define TARGET_FREEBSD_NR_ksem_init 404
-#define TARGET_FREEBSD_NR_ksem_open 405
-#define TARGET_FREEBSD_NR_ksem_unlink 406
-#define TARGET_FREEBSD_NR_ksem_getvalue 407
-#define TARGET_FREEBSD_NR_ksem_destroy 408
-#define TARGET_FREEBSD_NR___mac_get_pid 409
-#define TARGET_FREEBSD_NR___mac_get_link 410
-#define TARGET_FREEBSD_NR___mac_set_link 411
-#define TARGET_FREEBSD_NR_extattr_set_link 412
-#define TARGET_FREEBSD_NR_extattr_get_link 413
-#define TARGET_FREEBSD_NR_extattr_delete_link 414
-#define TARGET_FREEBSD_NR___mac_execve 415
-#define TARGET_FREEBSD_NR_sigaction 416
-#define TARGET_FREEBSD_NR_sigreturn 417
-#define TARGET_FREEBSD_NR_getcontext 421
-#define TARGET_FREEBSD_NR_setcontext 422
-#define TARGET_FREEBSD_NR_swapcontext 423
-#define TARGET_FREEBSD_NR_swapoff 424
-#define TARGET_FREEBSD_NR___acl_get_link 425
-#define TARGET_FREEBSD_NR___acl_set_link 426
-#define TARGET_FREEBSD_NR___acl_delete_link 427
-#define TARGET_FREEBSD_NR___acl_aclcheck_link 428
-#define TARGET_FREEBSD_NR_sigwait 429
-#define TARGET_FREEBSD_NR_thr_create 430
-#define TARGET_FREEBSD_NR_thr_exit 431
-#define TARGET_FREEBSD_NR_thr_self 432
-#define TARGET_FREEBSD_NR_thr_kill 433
-#define TARGET_FREEBSD_NR_jail_attach 436
-#define TARGET_FREEBSD_NR_extattr_list_fd 437
-#define TARGET_FREEBSD_NR_extattr_list_file 438
-#define TARGET_FREEBSD_NR_extattr_list_link 439
- /* 440 is obsolete kse_switchin */
-#define TARGET_FREEBSD_NR_ksem_timedwait 441
-#define TARGET_FREEBSD_NR_thr_suspend 442
-#define TARGET_FREEBSD_NR_thr_wake 443
-#define TARGET_FREEBSD_NR_kldunloadf 444
-#define TARGET_FREEBSD_NR_audit 445
-#define TARGET_FREEBSD_NR_auditon 446
-#define TARGET_FREEBSD_NR_getauid 447
-#define TARGET_FREEBSD_NR_setauid 448
-#define TARGET_FREEBSD_NR_getaudit 449
-#define TARGET_FREEBSD_NR_setaudit 450
-#define TARGET_FREEBSD_NR_getaudit_addr 451
-#define TARGET_FREEBSD_NR_setaudit_addr 452
-#define TARGET_FREEBSD_NR_auditctl 453
-#define TARGET_FREEBSD_NR__umtx_op 454
-#define TARGET_FREEBSD_NR_thr_new 455
-#define TARGET_FREEBSD_NR_sigqueue 456
-#define TARGET_FREEBSD_NR_kmq_open 457
-#define TARGET_FREEBSD_NR_kmq_setattr 458
-#define TARGET_FREEBSD_NR_kmq_timedreceive 459
-#define TARGET_FREEBSD_NR_kmq_timedsend 460
-#define TARGET_FREEBSD_NR_kmq_notify 461
-#define TARGET_FREEBSD_NR_kmq_unlink 462
-#define TARGET_FREEBSD_NR_abort2 463
-#define TARGET_FREEBSD_NR_thr_set_name 464
-#define TARGET_FREEBSD_NR_aio_fsync 465
-#define TARGET_FREEBSD_NR_rtprio_thread 466
-#define TARGET_FREEBSD_NR_sctp_peeloff 471
-#define TARGET_FREEBSD_NR_sctp_generic_sendmsg 472
-#define TARGET_FREEBSD_NR_sctp_generic_sendmsg_iov 473
-#define TARGET_FREEBSD_NR_sctp_generic_recvmsg 474
-#define TARGET_FREEBSD_NR_pread 475
-#define TARGET_FREEBSD_NR_pwrite 476
-#define TARGET_FREEBSD_NR_mmap 477
-#define TARGET_FREEBSD_NR_lseek 478
-#define TARGET_FREEBSD_NR_truncate 479
-#define TARGET_FREEBSD_NR_ftruncate 480
-#define TARGET_FREEBSD_NR_thr_kill2 481
-#define TARGET_FREEBSD_NR_freebsd12_shm_open 482
-#define TARGET_FREEBSD_NR_shm_unlink 483
-#define TARGET_FREEBSD_NR_cpuset 484
-#define TARGET_FREEBSD_NR_cpuset_setid 485
-#define TARGET_FREEBSD_NR_cpuset_getid 486
-#define TARGET_FREEBSD_NR_cpuset_getaffinity 487
-#define TARGET_FREEBSD_NR_cpuset_setaffinity 488
-#define TARGET_FREEBSD_NR_faccessat 489
-#define TARGET_FREEBSD_NR_fchmodat 490
-#define TARGET_FREEBSD_NR_fchownat 491
-#define TARGET_FREEBSD_NR_fexecve 492
-#define TARGET_FREEBSD_NR_freebsd11_fstatat 493
-#define TARGET_FREEBSD_NR_futimesat 494
-#define TARGET_FREEBSD_NR_linkat 495
-#define TARGET_FREEBSD_NR_mkdirat 496
-#define TARGET_FREEBSD_NR_mkfifoat 497
-#define TARGET_FREEBSD_NR_freebsd11_mknodat 498
-#define TARGET_FREEBSD_NR_openat 499
-#define TARGET_FREEBSD_NR_readlinkat 500
-#define TARGET_FREEBSD_NR_renameat 501
-#define TARGET_FREEBSD_NR_symlinkat 502
-#define TARGET_FREEBSD_NR_unlinkat 503
-#define TARGET_FREEBSD_NR_posix_openpt 504
-#define TARGET_FREEBSD_NR_gssd_syscall 505
-#define TARGET_FREEBSD_NR_jail_get 506
-#define TARGET_FREEBSD_NR_jail_set 507
-#define TARGET_FREEBSD_NR_jail_remove 508
-#define TARGET_FREEBSD_NR_freebsd12_closefrom 509
-#define TARGET_FREEBSD_NR___semctl 510
-#define TARGET_FREEBSD_NR_msgctl 511
-#define TARGET_FREEBSD_NR_shmctl 512
-#define TARGET_FREEBSD_NR_lpathconf 513
- /* 514 is obsolete cap_new */
-#define TARGET_FREEBSD_NR___cap_rights_get 515
-#define TARGET_FREEBSD_NR_cap_enter 516
-#define TARGET_FREEBSD_NR_cap_getmode 517
-#define TARGET_FREEBSD_NR_pdfork 518
-#define TARGET_FREEBSD_NR_pdkill 519
-#define TARGET_FREEBSD_NR_pdgetpid 520
-#define TARGET_FREEBSD_NR_pselect 522
-#define TARGET_FREEBSD_NR_getloginclass 523
-#define TARGET_FREEBSD_NR_setloginclass 524
-#define TARGET_FREEBSD_NR_rctl_get_racct 525
-#define TARGET_FREEBSD_NR_rctl_get_rules 526
-#define TARGET_FREEBSD_NR_rctl_get_limits 527
-#define TARGET_FREEBSD_NR_rctl_add_rule 528
-#define TARGET_FREEBSD_NR_rctl_remove_rule 529
-#define TARGET_FREEBSD_NR_posix_fallocate 530
-#define TARGET_FREEBSD_NR_posix_fadvise 531
-#define TARGET_FREEBSD_NR_wait6 532
-#define TARGET_FREEBSD_NR_cap_rights_limit 533
-#define TARGET_FREEBSD_NR_cap_ioctls_limit 534
-#define TARGET_FREEBSD_NR_cap_ioctls_get 535
-#define TARGET_FREEBSD_NR_cap_fcntls_limit 536
-#define TARGET_FREEBSD_NR_cap_fcntls_get 537
-#define TARGET_FREEBSD_NR_bindat 538
-#define TARGET_FREEBSD_NR_connectat 539
-#define TARGET_FREEBSD_NR_chflagsat 540
-#define TARGET_FREEBSD_NR_accept4 541
-#define TARGET_FREEBSD_NR_pipe2 542
-#define TARGET_FREEBSD_NR_aio_mlock 543
-#define TARGET_FREEBSD_NR_procctl 544
-#define TARGET_FREEBSD_NR_ppoll 545
-#define TARGET_FREEBSD_NR_futimens 546
-#define TARGET_FREEBSD_NR_utimensat 547
- /* 548 is obsolete numa_getaffinity */
- /* 549 is obsolete numa_setaffinity */
-#define TARGET_FREEBSD_NR_fdatasync 550
-#define TARGET_FREEBSD_NR_fstat 551
-#define TARGET_FREEBSD_NR_fstatat 552
-#define TARGET_FREEBSD_NR_fhstat 553
-#define TARGET_FREEBSD_NR_getdirentries 554
-#define TARGET_FREEBSD_NR_statfs 555
-#define TARGET_FREEBSD_NR_fstatfs 556
-#define TARGET_FREEBSD_NR_getfsstat 557
-#define TARGET_FREEBSD_NR_fhstatfs 558
-#define TARGET_FREEBSD_NR_mknodat 559
-#define TARGET_FREEBSD_NR_kevent 560
-#define TARGET_FREEBSD_NR_cpuset_getdomain 561
-#define TARGET_FREEBSD_NR_cpuset_setdomain 562
-#define TARGET_FREEBSD_NR_getrandom 563
-#define TARGET_FREEBSD_NR_getfhat 564
-#define TARGET_FREEBSD_NR_fhlink 565
-#define TARGET_FREEBSD_NR_fhlinkat 566
-#define TARGET_FREEBSD_NR_fhreadlink 567
-#define TARGET_FREEBSD_NR_funlinkat 568
-#define TARGET_FREEBSD_NR_copy_file_range 569
-#define TARGET_FREEBSD_NR___sysctlbyname 570
-#define TARGET_FREEBSD_NR_shm_open2 571
-#define TARGET_FREEBSD_NR_shm_rename 572
-#define TARGET_FREEBSD_NR_sigfastblock 573
-#define TARGET_FREEBSD_NR___realpathat 574
-#define TARGET_FREEBSD_NR_close_range 575
-#define TARGET_FREEBSD_NR_rpctls_syscall 576
-#define TARGET_FREEBSD_NR_MAXSYSCALL 577
+#define TARGET_FREEBSD_NR_syscall 0
+#define TARGET_FREEBSD_NR_exit 1
+#define TARGET_FREEBSD_NR_fork 2
+#define TARGET_FREEBSD_NR_read 3
+#define TARGET_FREEBSD_NR_write 4
+#define TARGET_FREEBSD_NR_open 5
+#define TARGET_FREEBSD_NR_close 6
+#define TARGET_FREEBSD_NR_wait4 7
+ /* 8 is old creat */
+#define TARGET_FREEBSD_NR_link 9
+#define TARGET_FREEBSD_NR_unlink 10
+ /* 11 is obsolete execv */
+#define TARGET_FREEBSD_NR_chdir 12
+#define TARGET_FREEBSD_NR_fchdir 13
+#define TARGET_FREEBSD_NR_freebsd11_mknod 14
+#define TARGET_FREEBSD_NR_chmod 15
+#define TARGET_FREEBSD_NR_chown 16
+#define TARGET_FREEBSD_NR_break 17
+ /* 18 is freebsd4 getfsstat */
+ /* 19 is old lseek */
+#define TARGET_FREEBSD_NR_getpid 20
+#define TARGET_FREEBSD_NR_mount 21
+#define TARGET_FREEBSD_NR_unmount 22
+#define TARGET_FREEBSD_NR_setuid 23
+#define TARGET_FREEBSD_NR_getuid 24
+#define TARGET_FREEBSD_NR_geteuid 25
+#define TARGET_FREEBSD_NR_ptrace 26
+#define TARGET_FREEBSD_NR_recvmsg 27
+#define TARGET_FREEBSD_NR_sendmsg 28
+#define TARGET_FREEBSD_NR_recvfrom 29
+#define TARGET_FREEBSD_NR_accept 30
+#define TARGET_FREEBSD_NR_getpeername 31
+#define TARGET_FREEBSD_NR_getsockname 32
+#define TARGET_FREEBSD_NR_access 33
+#define TARGET_FREEBSD_NR_chflags 34
+#define TARGET_FREEBSD_NR_fchflags 35
+#define TARGET_FREEBSD_NR_sync 36
+#define TARGET_FREEBSD_NR_kill 37
+ /* 38 is old stat */
+#define TARGET_FREEBSD_NR_getppid 39
+ /* 40 is old lstat */
+#define TARGET_FREEBSD_NR_dup 41
+#define TARGET_FREEBSD_NR_freebsd10_pipe 42
+#define TARGET_FREEBSD_NR_getegid 43
+#define TARGET_FREEBSD_NR_profil 44
+#define TARGET_FREEBSD_NR_ktrace 45
+ /* 46 is old sigaction */
+#define TARGET_FREEBSD_NR_getgid 47
+ /* 48 is old sigprocmask */
+#define TARGET_FREEBSD_NR_getlogin 49
+#define TARGET_FREEBSD_NR_setlogin 50
+#define TARGET_FREEBSD_NR_acct 51
+ /* 52 is old sigpending */
+#define TARGET_FREEBSD_NR_sigaltstack 53
+#define TARGET_FREEBSD_NR_ioctl 54
+#define TARGET_FREEBSD_NR_reboot 55
+#define TARGET_FREEBSD_NR_revoke 56
+#define TARGET_FREEBSD_NR_symlink 57
+#define TARGET_FREEBSD_NR_readlink 58
+#define TARGET_FREEBSD_NR_execve 59
+#define TARGET_FREEBSD_NR_umask 60
+#define TARGET_FREEBSD_NR_chroot 61
+ /* 62 is old fstat */
+ /* 63 is old getkerninfo */
+ /* 64 is old getpagesize */
+#define TARGET_FREEBSD_NR_msync 65
+#define TARGET_FREEBSD_NR_vfork 66
+ /* 67 is obsolete vread */
+ /* 68 is obsolete vwrite */
+#define TARGET_FREEBSD_NR_sbrk 69
+#define TARGET_FREEBSD_NR_sstk 70
+ /* 71 is old mmap */
+#define TARGET_FREEBSD_NR_freebsd11_vadvise 72
+#define TARGET_FREEBSD_NR_munmap 73
+#define TARGET_FREEBSD_NR_mprotect 74
+#define TARGET_FREEBSD_NR_madvise 75
+ /* 76 is obsolete vhangup */
+ /* 77 is obsolete vlimit */
+#define TARGET_FREEBSD_NR_mincore 78
+#define TARGET_FREEBSD_NR_getgroups 79
+#define TARGET_FREEBSD_NR_setgroups 80
+#define TARGET_FREEBSD_NR_getpgrp 81
+#define TARGET_FREEBSD_NR_setpgid 82
+#define TARGET_FREEBSD_NR_setitimer 83
+ /* 84 is old wait */
+#define TARGET_FREEBSD_NR_swapon 85
+#define TARGET_FREEBSD_NR_getitimer 86
+ /* 87 is old gethostname */
+ /* 88 is old sethostname */
+#define TARGET_FREEBSD_NR_getdtablesize 89
+#define TARGET_FREEBSD_NR_dup2 90
+#define TARGET_FREEBSD_NR_fcntl 92
+#define TARGET_FREEBSD_NR_select 93
+#define TARGET_FREEBSD_NR_fsync 95
+#define TARGET_FREEBSD_NR_setpriority 96
+#define TARGET_FREEBSD_NR_socket 97
+#define TARGET_FREEBSD_NR_connect 98
+ /* 99 is old accept */
+#define TARGET_FREEBSD_NR_getpriority 100
+ /* 101 is old send */
+ /* 102 is old recv */
+ /* 103 is old sigreturn */
+#define TARGET_FREEBSD_NR_bind 104
+#define TARGET_FREEBSD_NR_setsockopt 105
+#define TARGET_FREEBSD_NR_listen 106
+ /* 107 is obsolete vtimes */
+ /* 108 is old sigvec */
+ /* 109 is old sigblock */
+ /* 110 is old sigsetmask */
+ /* 111 is old sigsuspend */
+ /* 112 is old sigstack */
+ /* 113 is old recvmsg */
+ /* 114 is old sendmsg */
+ /* 115 is obsolete vtrace */
+#define TARGET_FREEBSD_NR_gettimeofday 116
+#define TARGET_FREEBSD_NR_getrusage 117
+#define TARGET_FREEBSD_NR_getsockopt 118
+#define TARGET_FREEBSD_NR_readv 120
+#define TARGET_FREEBSD_NR_writev 121
+#define TARGET_FREEBSD_NR_settimeofday 122
+#define TARGET_FREEBSD_NR_fchown 123
+#define TARGET_FREEBSD_NR_fchmod 124
+ /* 125 is old recvfrom */
+#define TARGET_FREEBSD_NR_setreuid 126
+#define TARGET_FREEBSD_NR_setregid 127
+#define TARGET_FREEBSD_NR_rename 128
+ /* 129 is old truncate */
+ /* 130 is old ftruncate */
+#define TARGET_FREEBSD_NR_flock 131
+#define TARGET_FREEBSD_NR_mkfifo 132
+#define TARGET_FREEBSD_NR_sendto 133
+#define TARGET_FREEBSD_NR_shutdown 134
+#define TARGET_FREEBSD_NR_socketpair 135
+#define TARGET_FREEBSD_NR_mkdir 136
+#define TARGET_FREEBSD_NR_rmdir 137
+#define TARGET_FREEBSD_NR_utimes 138
+ /* 139 is obsolete 4.2 sigreturn */
+#define TARGET_FREEBSD_NR_adjtime 140
+ /* 141 is old getpeername */
+ /* 142 is old gethostid */
+ /* 143 is old sethostid */
+ /* 144 is old getrlimit */
+ /* 145 is old setrlimit */
+ /* 146 is old killpg */
+#define TARGET_FREEBSD_NR_setsid 147
+#define TARGET_FREEBSD_NR_quotactl 148
+ /* 149 is old quota */
+ /* 150 is old getsockname */
+#define TARGET_FREEBSD_NR_nlm_syscall 154
+#define TARGET_FREEBSD_NR_nfssvc 155
+ /* 156 is old getdirentries */
+ /* 157 is freebsd4 statfs */
+ /* 158 is freebsd4 fstatfs */
+#define TARGET_FREEBSD_NR_lgetfh 160
+#define TARGET_FREEBSD_NR_getfh 161
+ /* 162 is freebsd4 getdomainname */
+ /* 163 is freebsd4 setdomainname */
+ /* 164 is freebsd4 uname */
+#define TARGET_FREEBSD_NR_sysarch 165
+#define TARGET_FREEBSD_NR_rtprio 166
+#define TARGET_FREEBSD_NR_semsys 169
+#define TARGET_FREEBSD_NR_msgsys 170
+#define TARGET_FREEBSD_NR_shmsys 171
+ /* 173 is freebsd6 pread */
+ /* 174 is freebsd6 pwrite */
+#define TARGET_FREEBSD_NR_setfib 175
+#define TARGET_FREEBSD_NR_ntp_adjtime 176
+#define TARGET_FREEBSD_NR_setgid 181
+#define TARGET_FREEBSD_NR_setegid 182
+#define TARGET_FREEBSD_NR_seteuid 183
+ /* 184 is obsolete lfs_bmapv */
+ /* 185 is obsolete lfs_markv */
+ /* 186 is obsolete lfs_segclean */
+ /* 187 is obsolete lfs_segwait */
+#define TARGET_FREEBSD_NR_freebsd11_stat 188
+#define TARGET_FREEBSD_NR_freebsd11_fstat 189
+#define TARGET_FREEBSD_NR_freebsd11_lstat 190
+#define TARGET_FREEBSD_NR_pathconf 191
+#define TARGET_FREEBSD_NR_fpathconf 192
+#define TARGET_FREEBSD_NR_getrlimit 194
+#define TARGET_FREEBSD_NR_setrlimit 195
+#define TARGET_FREEBSD_NR_freebsd11_getdirentries 196
+ /* 197 is freebsd6 mmap */
+#define TARGET_FREEBSD_NR___syscall 198
+ /* 199 is freebsd6 lseek */
+ /* 200 is freebsd6 truncate */
+ /* 201 is freebsd6 ftruncate */
+#define TARGET_FREEBSD_NR___sysctl 202
+#define TARGET_FREEBSD_NR_mlock 203
+#define TARGET_FREEBSD_NR_munlock 204
+#define TARGET_FREEBSD_NR_undelete 205
+#define TARGET_FREEBSD_NR_futimes 206
+#define TARGET_FREEBSD_NR_getpgid 207
+#define TARGET_FREEBSD_NR_poll 209
+#define TARGET_FREEBSD_NR_freebsd7___semctl 220
+#define TARGET_FREEBSD_NR_semget 221
+#define TARGET_FREEBSD_NR_semop 222
+ /* 223 is obsolete semconfig */
+#define TARGET_FREEBSD_NR_freebsd7_msgctl 224
+#define TARGET_FREEBSD_NR_msgget 225
+#define TARGET_FREEBSD_NR_msgsnd 226
+#define TARGET_FREEBSD_NR_msgrcv 227
+#define TARGET_FREEBSD_NR_shmat 228
+#define TARGET_FREEBSD_NR_freebsd7_shmctl 229
+#define TARGET_FREEBSD_NR_shmdt 230
+#define TARGET_FREEBSD_NR_shmget 231
+#define TARGET_FREEBSD_NR_clock_gettime 232
+#define TARGET_FREEBSD_NR_clock_settime 233
+#define TARGET_FREEBSD_NR_clock_getres 234
+#define TARGET_FREEBSD_NR_ktimer_create 235
+#define TARGET_FREEBSD_NR_ktimer_delete 236
+#define TARGET_FREEBSD_NR_ktimer_settime 237
+#define TARGET_FREEBSD_NR_ktimer_gettime 238
+#define TARGET_FREEBSD_NR_ktimer_getoverrun 239
+#define TARGET_FREEBSD_NR_nanosleep 240
+#define TARGET_FREEBSD_NR_ffclock_getcounter 241
+#define TARGET_FREEBSD_NR_ffclock_setestimate 242
+#define TARGET_FREEBSD_NR_ffclock_getestimate 243
+#define TARGET_FREEBSD_NR_clock_nanosleep 244
+#define TARGET_FREEBSD_NR_clock_getcpuclockid2 247
+#define TARGET_FREEBSD_NR_ntp_gettime 248
+#define TARGET_FREEBSD_NR_minherit 250
+#define TARGET_FREEBSD_NR_rfork 251
+ /* 252 is obsolete openbsd_poll */
+#define TARGET_FREEBSD_NR_issetugid 253
+#define TARGET_FREEBSD_NR_lchown 254
+#define TARGET_FREEBSD_NR_aio_read 255
+#define TARGET_FREEBSD_NR_aio_write 256
+#define TARGET_FREEBSD_NR_lio_listio 257
+#define TARGET_FREEBSD_NR_freebsd11_getdents 272
+#define TARGET_FREEBSD_NR_lchmod 274
+ /* 275 is obsolete netbsd_lchown */
+#define TARGET_FREEBSD_NR_lutimes 276
+ /* 277 is obsolete netbsd_msync */
+#define TARGET_FREEBSD_NR_freebsd11_nstat 278
+#define TARGET_FREEBSD_NR_freebsd11_nfstat 279
+#define TARGET_FREEBSD_NR_freebsd11_nlstat 280
+#define TARGET_FREEBSD_NR_preadv 289
+#define TARGET_FREEBSD_NR_pwritev 290
+ /* 297 is freebsd4 fhstatfs */
+#define TARGET_FREEBSD_NR_fhopen 298
+#define TARGET_FREEBSD_NR_freebsd11_fhstat 299
+#define TARGET_FREEBSD_NR_modnext 300
+#define TARGET_FREEBSD_NR_modstat 301
+#define TARGET_FREEBSD_NR_modfnext 302
+#define TARGET_FREEBSD_NR_modfind 303
+#define TARGET_FREEBSD_NR_kldload 304
+#define TARGET_FREEBSD_NR_kldunload 305
+#define TARGET_FREEBSD_NR_kldfind 306
+#define TARGET_FREEBSD_NR_kldnext 307
+#define TARGET_FREEBSD_NR_kldstat 308
+#define TARGET_FREEBSD_NR_kldfirstmod 309
+#define TARGET_FREEBSD_NR_getsid 310
+#define TARGET_FREEBSD_NR_setresuid 311
+#define TARGET_FREEBSD_NR_setresgid 312
+ /* 313 is obsolete signanosleep */
+#define TARGET_FREEBSD_NR_aio_return 314
+#define TARGET_FREEBSD_NR_aio_suspend 315
+#define TARGET_FREEBSD_NR_aio_cancel 316
+#define TARGET_FREEBSD_NR_aio_error 317
+ /* 318 is freebsd6 aio_read */
+ /* 319 is freebsd6 aio_write */
+ /* 320 is freebsd6 lio_listio */
+#define TARGET_FREEBSD_NR_yield 321
+ /* 322 is obsolete thr_sleep */
+ /* 323 is obsolete thr_wakeup */
+#define TARGET_FREEBSD_NR_mlockall 324
+#define TARGET_FREEBSD_NR_munlockall 325
+#define TARGET_FREEBSD_NR___getcwd 326
+#define TARGET_FREEBSD_NR_sched_setparam 327
+#define TARGET_FREEBSD_NR_sched_getparam 328
+#define TARGET_FREEBSD_NR_sched_setscheduler 329
+#define TARGET_FREEBSD_NR_sched_getscheduler 330
+#define TARGET_FREEBSD_NR_sched_yield 331
+#define TARGET_FREEBSD_NR_sched_get_priority_max 332
+#define TARGET_FREEBSD_NR_sched_get_priority_min 333
+#define TARGET_FREEBSD_NR_sched_rr_get_interval 334
+#define TARGET_FREEBSD_NR_utrace 335
+ /* 336 is freebsd4 sendfile */
+#define TARGET_FREEBSD_NR_kldsym 337
+#define TARGET_FREEBSD_NR_jail 338
+#define TARGET_FREEBSD_NR_nnpfs_syscall 339
+#define TARGET_FREEBSD_NR_sigprocmask 340
+#define TARGET_FREEBSD_NR_sigsuspend 341
+ /* 342 is freebsd4 sigaction */
+#define TARGET_FREEBSD_NR_sigpending 343
+ /* 344 is freebsd4 sigreturn */
+#define TARGET_FREEBSD_NR_sigtimedwait 345
+#define TARGET_FREEBSD_NR_sigwaitinfo 346
+#define TARGET_FREEBSD_NR___acl_get_file 347
+#define TARGET_FREEBSD_NR___acl_set_file 348
+#define TARGET_FREEBSD_NR___acl_get_fd 349
+#define TARGET_FREEBSD_NR___acl_set_fd 350
+#define TARGET_FREEBSD_NR___acl_delete_file 351
+#define TARGET_FREEBSD_NR___acl_delete_fd 352
+#define TARGET_FREEBSD_NR___acl_aclcheck_file 353
+#define TARGET_FREEBSD_NR___acl_aclcheck_fd 354
+#define TARGET_FREEBSD_NR_extattrctl 355
+#define TARGET_FREEBSD_NR_extattr_set_file 356
+#define TARGET_FREEBSD_NR_extattr_get_file 357
+#define TARGET_FREEBSD_NR_extattr_delete_file 358
+#define TARGET_FREEBSD_NR_aio_waitcomplete 359
+#define TARGET_FREEBSD_NR_getresuid 360
+#define TARGET_FREEBSD_NR_getresgid 361
+#define TARGET_FREEBSD_NR_kqueue 362
+#define TARGET_FREEBSD_NR_freebsd11_kevent 363
+ /* 364 is obsolete __cap_get_proc */
+ /* 365 is obsolete __cap_set_proc */
+ /* 366 is obsolete __cap_get_fd */
+ /* 367 is obsolete __cap_get_file */
+ /* 368 is obsolete __cap_set_fd */
+ /* 369 is obsolete __cap_set_file */
+#define TARGET_FREEBSD_NR_extattr_set_fd 371
+#define TARGET_FREEBSD_NR_extattr_get_fd 372
+#define TARGET_FREEBSD_NR_extattr_delete_fd 373
+#define TARGET_FREEBSD_NR___setugid 374
+ /* 375 is obsolete nfsclnt */
+#define TARGET_FREEBSD_NR_eaccess 376
+#define TARGET_FREEBSD_NR_afs3_syscall 377
+#define TARGET_FREEBSD_NR_nmount 378
+ /* 379 is obsolete kse_exit */
+ /* 380 is obsolete kse_wakeup */
+ /* 381 is obsolete kse_create */
+ /* 382 is obsolete kse_thr_interrupt */
+ /* 383 is obsolete kse_release */
+#define TARGET_FREEBSD_NR___mac_get_proc 384
+#define TARGET_FREEBSD_NR___mac_set_proc 385
+#define TARGET_FREEBSD_NR___mac_get_fd 386
+#define TARGET_FREEBSD_NR___mac_get_file 387
+#define TARGET_FREEBSD_NR___mac_set_fd 388
+#define TARGET_FREEBSD_NR___mac_set_file 389
+#define TARGET_FREEBSD_NR_kenv 390
+#define TARGET_FREEBSD_NR_lchflags 391
+#define TARGET_FREEBSD_NR_uuidgen 392
+#define TARGET_FREEBSD_NR_sendfile 393
+#define TARGET_FREEBSD_NR_mac_syscall 394
+#define TARGET_FREEBSD_NR_freebsd11_getfsstat 395
+#define TARGET_FREEBSD_NR_freebsd11_statfs 396
+#define TARGET_FREEBSD_NR_freebsd11_fstatfs 397
+#define TARGET_FREEBSD_NR_freebsd11_fhstatfs 398
+#define TARGET_FREEBSD_NR_ksem_close 400
+#define TARGET_FREEBSD_NR_ksem_post 401
+#define TARGET_FREEBSD_NR_ksem_wait 402
+#define TARGET_FREEBSD_NR_ksem_trywait 403
+#define TARGET_FREEBSD_NR_ksem_init 404
+#define TARGET_FREEBSD_NR_ksem_open 405
+#define TARGET_FREEBSD_NR_ksem_unlink 406
+#define TARGET_FREEBSD_NR_ksem_getvalue 407
+#define TARGET_FREEBSD_NR_ksem_destroy 408
+#define TARGET_FREEBSD_NR___mac_get_pid 409
+#define TARGET_FREEBSD_NR___mac_get_link 410
+#define TARGET_FREEBSD_NR___mac_set_link 411
+#define TARGET_FREEBSD_NR_extattr_set_link 412
+#define TARGET_FREEBSD_NR_extattr_get_link 413
+#define TARGET_FREEBSD_NR_extattr_delete_link 414
+#define TARGET_FREEBSD_NR___mac_execve 415
+#define TARGET_FREEBSD_NR_sigaction 416
+#define TARGET_FREEBSD_NR_sigreturn 417
+#define TARGET_FREEBSD_NR_getcontext 421
+#define TARGET_FREEBSD_NR_setcontext 422
+#define TARGET_FREEBSD_NR_swapcontext 423
+#if __FreeBSD_version >= 1400044 || \
+ (__FreeBSD_version < 1400000 && __FreeBSD_version >= 1300523)
+#define TARGET_FREEBSD_NR_freebsd13_swapoff 424
+#else
+#define TARGET_FREEBSD_NR_swapoff 424
+#endif
+#define TARGET_FREEBSD_NR___acl_get_link 425
+#define TARGET_FREEBSD_NR___acl_set_link 426
+#define TARGET_FREEBSD_NR___acl_delete_link 427
+#define TARGET_FREEBSD_NR___acl_aclcheck_link 428
+#define TARGET_FREEBSD_NR_sigwait 429
+#define TARGET_FREEBSD_NR_thr_create 430
+#define TARGET_FREEBSD_NR_thr_exit 431
+#define TARGET_FREEBSD_NR_thr_self 432
+#define TARGET_FREEBSD_NR_thr_kill 433
+#define TARGET_FREEBSD_NR_freebsd10__umtx_lock 434
+#define TARGET_FREEBSD_NR_freebsd10__umtx_unlock 435
+#define TARGET_FREEBSD_NR_jail_attach 436
+#define TARGET_FREEBSD_NR_extattr_list_fd 437
+#define TARGET_FREEBSD_NR_extattr_list_file 438
+#define TARGET_FREEBSD_NR_extattr_list_link 439
+ /* 440 is obsolete kse_switchin */
+#define TARGET_FREEBSD_NR_ksem_timedwait 441
+#define TARGET_FREEBSD_NR_thr_suspend 442
+#define TARGET_FREEBSD_NR_thr_wake 443
+#define TARGET_FREEBSD_NR_kldunloadf 444
+#define TARGET_FREEBSD_NR_audit 445
+#define TARGET_FREEBSD_NR_auditon 446
+#define TARGET_FREEBSD_NR_getauid 447
+#define TARGET_FREEBSD_NR_setauid 448
+#define TARGET_FREEBSD_NR_getaudit 449
+#define TARGET_FREEBSD_NR_setaudit 450
+#define TARGET_FREEBSD_NR_getaudit_addr 451
+#define TARGET_FREEBSD_NR_setaudit_addr 452
+#define TARGET_FREEBSD_NR_auditctl 453
+#define TARGET_FREEBSD_NR__umtx_op 454
+#define TARGET_FREEBSD_NR_thr_new 455
+#define TARGET_FREEBSD_NR_sigqueue 456
+#define TARGET_FREEBSD_NR_kmq_open 457
+#define TARGET_FREEBSD_NR_kmq_setattr 458
+#define TARGET_FREEBSD_NR_kmq_timedreceive 459
+#define TARGET_FREEBSD_NR_kmq_timedsend 460
+#define TARGET_FREEBSD_NR_kmq_notify 461
+#define TARGET_FREEBSD_NR_kmq_unlink 462
+#define TARGET_FREEBSD_NR_abort2 463
+#define TARGET_FREEBSD_NR_thr_set_name 464
+#define TARGET_FREEBSD_NR_aio_fsync 465
+#define TARGET_FREEBSD_NR_rtprio_thread 466
+#define TARGET_FREEBSD_NR_sctp_peeloff 471
+#define TARGET_FREEBSD_NR_sctp_generic_sendmsg 472
+#define TARGET_FREEBSD_NR_sctp_generic_sendmsg_iov 473
+#define TARGET_FREEBSD_NR_sctp_generic_recvmsg 474
+#define TARGET_FREEBSD_NR_pread 475
+#define TARGET_FREEBSD_NR_pwrite 476
+#define TARGET_FREEBSD_NR_mmap 477
+#define TARGET_FREEBSD_NR_lseek 478
+#define TARGET_FREEBSD_NR_truncate 479
+#define TARGET_FREEBSD_NR_ftruncate 480
+#define TARGET_FREEBSD_NR_thr_kill2 481
+#define TARGET_FREEBSD_NR_freebsd12_shm_open 482
+#define TARGET_FREEBSD_NR_shm_unlink 483
+#define TARGET_FREEBSD_NR_cpuset 484
+#define TARGET_FREEBSD_NR_cpuset_setid 485
+#define TARGET_FREEBSD_NR_cpuset_getid 486
+#define TARGET_FREEBSD_NR_cpuset_getaffinity 487
+#define TARGET_FREEBSD_NR_cpuset_setaffinity 488
+#define TARGET_FREEBSD_NR_faccessat 489
+#define TARGET_FREEBSD_NR_fchmodat 490
+#define TARGET_FREEBSD_NR_fchownat 491
+#define TARGET_FREEBSD_NR_fexecve 492
+#define TARGET_FREEBSD_NR_freebsd11_fstatat 493
+#define TARGET_FREEBSD_NR_futimesat 494
+#define TARGET_FREEBSD_NR_linkat 495
+#define TARGET_FREEBSD_NR_mkdirat 496
+#define TARGET_FREEBSD_NR_mkfifoat 497
+#define TARGET_FREEBSD_NR_freebsd11_mknodat 498
+#define TARGET_FREEBSD_NR_openat 499
+#define TARGET_FREEBSD_NR_readlinkat 500
+#define TARGET_FREEBSD_NR_renameat 501
+#define TARGET_FREEBSD_NR_symlinkat 502
+#define TARGET_FREEBSD_NR_unlinkat 503
+#define TARGET_FREEBSD_NR_posix_openpt 504
+#define TARGET_FREEBSD_NR_gssd_syscall 505
+#define TARGET_FREEBSD_NR_jail_get 506
+#define TARGET_FREEBSD_NR_jail_set 507
+#define TARGET_FREEBSD_NR_jail_remove 508
+#define TARGET_FREEBSD_NR_freebsd12_closefrom 509
+#define TARGET_FREEBSD_NR___semctl 510
+#define TARGET_FREEBSD_NR_msgctl 511
+#define TARGET_FREEBSD_NR_shmctl 512
+#define TARGET_FREEBSD_NR_lpathconf 513
+ /* 514 is obsolete cap_new */
+#define TARGET_FREEBSD_NR___cap_rights_get 515
+#define TARGET_FREEBSD_NR_cap_enter 516
+#define TARGET_FREEBSD_NR_cap_getmode 517
+#define TARGET_FREEBSD_NR_pdfork 518
+#define TARGET_FREEBSD_NR_pdkill 519
+#define TARGET_FREEBSD_NR_pdgetpid 520
+#define TARGET_FREEBSD_NR_pselect 522
+#define TARGET_FREEBSD_NR_getloginclass 523
+#define TARGET_FREEBSD_NR_setloginclass 524
+#define TARGET_FREEBSD_NR_rctl_get_racct 525
+#define TARGET_FREEBSD_NR_rctl_get_rules 526
+#define TARGET_FREEBSD_NR_rctl_get_limits 527
+#define TARGET_FREEBSD_NR_rctl_add_rule 528
+#define TARGET_FREEBSD_NR_rctl_remove_rule 529
+#define TARGET_FREEBSD_NR_posix_fallocate 530
+#define TARGET_FREEBSD_NR_posix_fadvise 531
+#define TARGET_FREEBSD_NR_wait6 532
+#define TARGET_FREEBSD_NR_cap_rights_limit 533
+#define TARGET_FREEBSD_NR_cap_ioctls_limit 534
+#define TARGET_FREEBSD_NR_cap_ioctls_get 535
+#define TARGET_FREEBSD_NR_cap_fcntls_limit 536
+#define TARGET_FREEBSD_NR_cap_fcntls_get 537
+#define TARGET_FREEBSD_NR_bindat 538
+#define TARGET_FREEBSD_NR_connectat 539
+#define TARGET_FREEBSD_NR_chflagsat 540
+#define TARGET_FREEBSD_NR_accept4 541
+#define TARGET_FREEBSD_NR_pipe2 542
+#define TARGET_FREEBSD_NR_aio_mlock 543
+#define TARGET_FREEBSD_NR_procctl 544
+#define TARGET_FREEBSD_NR_ppoll 545
+#define TARGET_FREEBSD_NR_futimens 546
+#define TARGET_FREEBSD_NR_utimensat 547
+ /* 548 is obsolete numa_getaffinity */
+ /* 549 is obsolete numa_setaffinity */
+#define TARGET_FREEBSD_NR_fdatasync 550
+#define TARGET_FREEBSD_NR_fstat 551
+#define TARGET_FREEBSD_NR_fstatat 552
+#define TARGET_FREEBSD_NR_fhstat 553
+#define TARGET_FREEBSD_NR_getdirentries 554
+#define TARGET_FREEBSD_NR_statfs 555
+#define TARGET_FREEBSD_NR_fstatfs 556
+#define TARGET_FREEBSD_NR_getfsstat 557
+#define TARGET_FREEBSD_NR_fhstatfs 558
+#define TARGET_FREEBSD_NR_mknodat 559
+#define TARGET_FREEBSD_NR_kevent 560
+#define TARGET_FREEBSD_NR_cpuset_getdomain 561
+#define TARGET_FREEBSD_NR_cpuset_setdomain 562
+#define TARGET_FREEBSD_NR_getrandom 563
+#define TARGET_FREEBSD_NR_getfhat 564
+#define TARGET_FREEBSD_NR_fhlink 565
+#define TARGET_FREEBSD_NR_fhlinkat 566
+#define TARGET_FREEBSD_NR_fhreadlink 567
+#define TARGET_FREEBSD_NR_funlinkat 568
+#define TARGET_FREEBSD_NR_copy_file_range 569
+#define TARGET_FREEBSD_NR___sysctlbyname 570
+#define TARGET_FREEBSD_NR_shm_open2 571
+#define TARGET_FREEBSD_NR_shm_rename 572
+#define TARGET_FREEBSD_NR_sigfastblock 573
+#define TARGET_FREEBSD_NR___realpathat 574
+#define TARGET_FREEBSD_NR_close_range 575
+#define TARGET_FREEBSD_NR_rpctls_syscall 576
+#define TARGET_FREEBSD_NR___specialfd 577
+#define TARGET_FREEBSD_NR_aio_writev 578
+#define TARGET_FREEBSD_NR_aio_readv 579
+#define TARGET_FREEBSD_NR_fspacectl 580
+#if __FreeBSD_version >= 1400044 || \
+ (__FreeBSD_version < 1400000 && __FreeBSD_version >= 1300523)
+#define TARGET_FREEBSD_NR_swapoff 582
+#endif
+#define TARGET_FREEBSD_NR_MAXSYSCALL 583
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2 18/19] bsd-user: Update system call list
2023-04-10 18:20 ` [PATCH v2 18/19] bsd-user: Update system call list Warner Losh
@ 2023-04-11 1:37 ` Richard Henderson
2023-04-11 2:37 ` Warner Losh
2023-04-11 17:03 ` Warner Losh
0 siblings, 2 replies; 26+ messages in thread
From: Richard Henderson @ 2023-04-11 1:37 UTC (permalink / raw)
To: Warner Losh, qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith, reinoud
On 4/10/23 11:20, Warner Losh wrote:
> Update the system call list. We have one hokey thing in here for swapoff
> that depends on the version number (so this is not completely generated
> at the moment). For this, we need to include sys/param.h. The method of
> generation has changed, so this diff looks way bigger than it needs to
> be to add the few lines of code for the new system calls.
>
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
> bsd-user/freebsd/os-syscall.h | 2 +
> bsd-user/freebsd/syscall_nr.h | 1035 +++++++++++++++++----------------
> 2 files changed, 529 insertions(+), 508 deletions(-)
What is the method of generation?
If it's complicated, it should be in scripts/.
If it's trivial, e.g.
sed 's/xxx/yyy/' < in.h > out.h
it is worth including the command in the commit message.
Anyway,
Acked-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 18/19] bsd-user: Update system call list
2023-04-11 1:37 ` Richard Henderson
@ 2023-04-11 2:37 ` Warner Losh
2023-04-11 17:03 ` Warner Losh
1 sibling, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-11 2:37 UTC (permalink / raw)
To: Richard Henderson
Cc: qemu-devel, jrtc27, riastradh, Kyle Evans, Ryo ONODERA,
Brad Smith, reinoud
[-- Attachment #1: Type: text/plain, Size: 1331 bytes --]
On Mon, Apr 10, 2023 at 7:37 PM Richard Henderson <
richard.henderson@linaro.org> wrote:
> On 4/10/23 11:20, Warner Losh wrote:
> > Update the system call list. We have one hokey thing in here for swapoff
> > that depends on the version number (so this is not completely generated
> > at the moment). For this, we need to include sys/param.h. The method of
> > generation has changed, so this diff looks way bigger than it needs to
> > be to add the few lines of code for the new system calls.
> >
> > Signed-off-by: Warner Losh<imp@bsdimp.com>
> > ---
> > bsd-user/freebsd/os-syscall.h | 2 +
> > bsd-user/freebsd/syscall_nr.h | 1035 +++++++++++++++++----------------
> > 2 files changed, 529 insertions(+), 508 deletions(-)
>
> What is the method of generation?
>
> If it's complicated, it should be in scripts/.
> If it's trivial, e.g.
>
> sed 's/xxx/yyy/' < in.h > out.h
>
> it is worth including the command in the commit message.
>
I'll add it to the commit message... but I'm also contemplating generating
it
on the fly if it's not too hard... Thanks for the suggestion... It's
usually a sed,
but someone (likely me) edited it directly for an unwise hack that Ineed to
unwind first...
> Anyway,
> Acked-by: Richard Henderson <richard.henderson@linaro.org>
>
Warner
[-- Attachment #2: Type: text/html, Size: 2119 bytes --]
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 18/19] bsd-user: Update system call list
2023-04-11 1:37 ` Richard Henderson
2023-04-11 2:37 ` Warner Losh
@ 2023-04-11 17:03 ` Warner Losh
1 sibling, 0 replies; 26+ messages in thread
From: Warner Losh @ 2023-04-11 17:03 UTC (permalink / raw)
To: Richard Henderson
Cc: qemu-devel, jrtc27, riastradh, Kyle Evans, Ryo ONODERA,
Brad Smith, reinoud
[-- Attachment #1: Type: text/plain, Size: 1326 bytes --]
On Mon, Apr 10, 2023 at 7:37 PM Richard Henderson <
richard.henderson@linaro.org> wrote:
> On 4/10/23 11:20, Warner Losh wrote:
> > Update the system call list. We have one hokey thing in here for swapoff
> > that depends on the version number (so this is not completely generated
> > at the moment). For this, we need to include sys/param.h. The method of
> > generation has changed, so this diff looks way bigger than it needs to
> > be to add the few lines of code for the new system calls.
> >
> > Signed-off-by: Warner Losh<imp@bsdimp.com>
> > ---
> > bsd-user/freebsd/os-syscall.h | 2 +
> > bsd-user/freebsd/syscall_nr.h | 1035 +++++++++++++++++----------------
> > 2 files changed, 529 insertions(+), 508 deletions(-)
>
> What is the method of generation?
>
> If it's complicated, it should be in scripts/.
> If it's trivial, e.g.
>
> sed 's/xxx/yyy/' < in.h > out.h
>
> it is worth including the command in the commit message.
>
> Anyway,
> Acked-by: Richard Henderson <richard.henderson@linaro.org>
>
I'm dropping this chunk, and will just commit the bits to generate it each
build.
It's easier than trying to document what I've done to generate things. I've
sorted
out the __FreeBSD_version stuff that was in here in blitz fork, so why not?
Warner
> r~
>
[-- Attachment #2: Type: text/html, Size: 2102 bytes --]
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 19/19] bsd-user: Eliminate USE_ELF_CORE_DUMP
2023-04-10 18:20 [PATCH v2 00/19] bsd-user 2023 Q2 first batch Warner Losh
` (17 preceding siblings ...)
2023-04-10 18:20 ` [PATCH v2 18/19] bsd-user: Update system call list Warner Losh
@ 2023-04-10 18:20 ` Warner Losh
2023-04-11 1:37 ` Richard Henderson
18 siblings, 1 reply; 26+ messages in thread
From: Warner Losh @ 2023-04-10 18:20 UTC (permalink / raw)
To: qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith,
Warner Losh, reinoud
It's enabled on all platforms (even in the fork), so we can remove it
from here.
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
bsd-user/arm/target_arch_elf.h | 1 -
bsd-user/elfcore.c | 3 ---
bsd-user/elfload.c | 5 -----
bsd-user/i386/target_arch_elf.h | 1 -
bsd-user/x86_64/target_arch_elf.h | 1 -
5 files changed, 11 deletions(-)
diff --git a/bsd-user/arm/target_arch_elf.h b/bsd-user/arm/target_arch_elf.h
index 935bce347fc..9f963d4747f 100644
--- a/bsd-user/arm/target_arch_elf.h
+++ b/bsd-user/arm/target_arch_elf.h
@@ -29,7 +29,6 @@
#define ELF_DATA ELFDATA2LSB
#define ELF_ARCH EM_ARM
-#define USE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#define ELF_HWCAP get_elf_hwcap()
diff --git a/bsd-user/elfcore.c b/bsd-user/elfcore.c
index 2905f2b8414..606c42dd4ab 100644
--- a/bsd-user/elfcore.c
+++ b/bsd-user/elfcore.c
@@ -18,7 +18,6 @@
*/
#include "qemu/osdep.h"
-#ifdef USE_ELF_CORE_DUMP
#include <err.h>
#include <libgen.h>
#include <sys/mman.h>
@@ -1318,5 +1317,3 @@ out:
}
return 0;
}
-
-#endif /* USE_ELF_CORE_DUMP */
diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index fbcdc94b960..0477d243a4b 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -35,7 +35,6 @@ static size_t target_auxents_sz; /* Size of AUX entries including AT_NULL */
abi_ulong target_stksiz;
abi_ulong target_stkbas;
-static int elf_core_dump(int signr, CPUArchState *env);
static int load_elf_sections(const struct elfhdr *hdr, struct elf_phdr *phdr,
int fd, abi_ulong rbase, abi_ulong *baddrp);
@@ -818,11 +817,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
info->entry = elf_entry;
-#ifdef USE_ELF_CORE_DUMP
bprm->core_dump = &elf_core_dump;
-#else
- bprm->core_dump = NULL;
-#endif
return 0;
}
diff --git a/bsd-user/i386/target_arch_elf.h b/bsd-user/i386/target_arch_elf.h
index cbcd1f08e2f..a18124f0f29 100644
--- a/bsd-user/i386/target_arch_elf.h
+++ b/bsd-user/i386/target_arch_elf.h
@@ -30,7 +30,6 @@
#define ELF_DATA ELFDATA2LSB
#define ELF_ARCH EM_386
-#define USE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#endif /* TARGET_ARCH_ELF_H */
diff --git a/bsd-user/x86_64/target_arch_elf.h b/bsd-user/x86_64/target_arch_elf.h
index b2447118883..08abe62be6f 100644
--- a/bsd-user/x86_64/target_arch_elf.h
+++ b/bsd-user/x86_64/target_arch_elf.h
@@ -30,7 +30,6 @@
#define ELF_DATA ELFDATA2LSB
#define ELF_ARCH EM_X86_64
-#define USE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#endif /* TARGET_ARCH_ELF_H */
--
2.40.0
^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2 19/19] bsd-user: Eliminate USE_ELF_CORE_DUMP
2023-04-10 18:20 ` [PATCH v2 19/19] bsd-user: Eliminate USE_ELF_CORE_DUMP Warner Losh
@ 2023-04-11 1:37 ` Richard Henderson
0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2023-04-11 1:37 UTC (permalink / raw)
To: Warner Losh, qemu-devel
Cc: jrtc27, riastradh, Kyle Evans, Ryo ONODERA, Brad Smith, reinoud
On 4/10/23 11:20, Warner Losh wrote:
> It's enabled on all platforms (even in the fork), so we can remove it
> from here.
>
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
> bsd-user/arm/target_arch_elf.h | 1 -
> bsd-user/elfcore.c | 3 ---
> bsd-user/elfload.c | 5 -----
> bsd-user/i386/target_arch_elf.h | 1 -
> bsd-user/x86_64/target_arch_elf.h | 1 -
> 5 files changed, 11 deletions(-)
Thanks,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 26+ messages in thread