[PATCH v3 18/20] bsd-user: Automatically generate syscall_nr.h

Warner Losh posted 20 patches 2 years, 10 months ago
Maintainers: Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
[PATCH v3 18/20] bsd-user: Automatically generate syscall_nr.h
Posted by Warner Losh 2 years, 10 months ago
Automatically generate syscall_nr.h from /usr/include/sys/syscall.h
since we can only run on a system that matches... This should reduce the
churn in the future.

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/freebsd/os-syscall.h | 2 +-
 bsd-user/meson.build          | 4 ++++
 bsd-user/syscallhdr.sh        | 7 +++++++
 meson.build                   | 2 ++
 4 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 bsd-user/syscallhdr.sh

diff --git a/bsd-user/freebsd/os-syscall.h b/bsd-user/freebsd/os-syscall.h
index 1f2c0acb1c5..b04d44ba78c 100644
--- a/bsd-user/freebsd/os-syscall.h
+++ b/bsd-user/freebsd/os-syscall.h
@@ -6,7 +6,7 @@
  * OS-Specific portion of syscall_defs.h
  */
 
-#include "freebsd/syscall_nr.h"
+#include "syscall_nr.h"
 
 /*
  * FreeBSD uses a 64bits time_t except on i386 so we have to add a special case
diff --git a/bsd-user/meson.build b/bsd-user/meson.build
index 7d1b4de78b1..67480dc5290 100644
--- a/bsd-user/meson.build
+++ b/bsd-user/meson.build
@@ -21,3 +21,7 @@ bsd_user_ss.add(files(
 subdir(targetos)
 
 specific_ss.add_all(when: 'CONFIG_BSD_USER', if_true: bsd_user_ss)
+
+bsd_syscall_nr = generator(sh,
+			   arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@'],
+			   output: '@BASENAME@_nr.h')
diff --git a/bsd-user/syscallhdr.sh b/bsd-user/syscallhdr.sh
new file mode 100644
index 00000000000..c991c2df1d0
--- /dev/null
+++ b/bsd-user/syscallhdr.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+in="$1"
+out="$2"
+bsd="$3"
+
+awk -v bsd="$3" '{sub("SYS_", "TARGET_" bsd "_NR_", $0); print;}' < $in > $out
diff --git a/meson.build b/meson.build
index 29f8644d6d0..aedf0798d81 100644
--- a/meson.build
+++ b/meson.build
@@ -3470,6 +3470,8 @@ foreach target : target_dirs
       target_inc += include_directories('bsd-user/host/' / host_arch)
       dir = base_dir / abi
       arch_srcs += files(dir / 'signal.c', dir / 'target_arch_cpu.c')
+      arch_srcs += bsd_syscall_nr.process('/usr/include/sys/syscall.h',
+					  extra_args : targetos.to_upper())
     endif
     target_inc += include_directories(
       base_dir,
-- 
2.40.0
Re: [PATCH v3 18/20] bsd-user: Automatically generate syscall_nr.h
Posted by Richard Henderson 2 years, 10 months ago
On 4/11/23 19:09, Warner Losh wrote:
> +++ b/bsd-user/syscallhdr.sh
> @@ -0,0 +1,7 @@
> +#!/bin/sh
> +
> +in="$1"
> +out="$2"
> +bsd="$3"
> +
> +awk -v bsd="$3" '{sub("SYS_", "TARGET_" bsd "_NR_", $0); print;}' < $in > $out

If the host/guest syscall numbers always match, there's no point in using 
TARGET_freebsd_NR_foo at all -- just use the original SYS_foo symbol from <sys/syscall.h>.


r~
Re: [PATCH v3 18/20] bsd-user: Automatically generate syscall_nr.h
Posted by Warner Losh 2 years, 10 months ago
On Wed, Apr 12, 2023 at 4:10 AM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 4/11/23 19:09, Warner Losh wrote:
> > +++ b/bsd-user/syscallhdr.sh
> > @@ -0,0 +1,7 @@
> > +#!/bin/sh
> > +
> > +in="$1"
> > +out="$2"
> > +bsd="$3"
> > +
> > +awk -v bsd="$3" '{sub("SYS_", "TARGET_" bsd "_NR_", $0); print;}' < $in
> > $out
>
> If the host/guest syscall numbers always match, there's no point in using
> TARGET_freebsd_NR_foo at all -- just use the original SYS_foo symbol from
> <sys/syscall.h>.
>

long term, this is likely correct. Short term, though, changing to SYS_foo
would cause quite a bit
of churn that I'm looking to avoid. bsd-user has two branches, and the
newest branch has problems
with threads we've not been able to completely track down, so we can't
switch to using it just yet.
So we have to still add new system calls to the old code base, which is
made harder as the number
of differences proliferate.

This is the first step, though, towards that goal: not updating the system
call tables as much, and
generating more code where possible to reduce the load we have on
hand-coded stuff.

Warner
Re: [PATCH v3 18/20] bsd-user: Automatically generate syscall_nr.h
Posted by Richard Henderson 2 years, 10 months ago
On 4/12/23 16:21, Warner Losh wrote:
> 
> 
> On Wed, Apr 12, 2023 at 4:10 AM Richard Henderson <richard.henderson@linaro.org 
> <mailto:richard.henderson@linaro.org>> wrote:
> 
>     On 4/11/23 19:09, Warner Losh wrote:
>      > +++ b/bsd-user/syscallhdr.sh
>      > @@ -0,0 +1,7 @@
>      > +#!/bin/sh
>      > +
>      > +in="$1"
>      > +out="$2"
>      > +bsd="$3"
>      > +
>      > +awk -v bsd="$3" '{sub("SYS_", "TARGET_" bsd "_NR_", $0); print;}' < $in > $out
> 
>     If the host/guest syscall numbers always match, there's no point in using
>     TARGET_freebsd_NR_foo at all -- just use the original SYS_foo symbol from <sys/syscall.h>.
> 
> 
> long term, this is likely correct. Short term, though, changing to SYS_foo would cause 
> quite a bit
> of churn that I'm looking to avoid. 

Fair.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~