diff mbox series

[13/22] bsd-user/bsd-file.h: Implementation details for the filesystem calls

Message ID 20220201111455.52511-14-imp@bsdimp.com (mailing list archive)
State New, archived
Headers show
Series bsd-user: Start upstreaming the system calls. | expand

Commit Message

Warner Losh Feb. 1, 2022, 11:14 a.m. UTC
An include file that pulls in all the definitions needed for the file
related system calls. This also includes the host definitions to
implement the system calls and some helper routines to lock/unlock
different aspects of the system call arguments.

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-file.h           | 39 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  2 ++
 2 files changed, 41 insertions(+)
 create mode 100644 bsd-user/bsd-file.h

Comments

Kyle Evans Feb. 1, 2022, 4:47 p.m. UTC | #1
On Tue, Feb 1, 2022 at 5:15 AM Warner Losh <imp@bsdimp.com> wrote:
>
> An include file that pulls in all the definitions needed for the file
> related system calls. This also includes the host definitions to
> implement the system calls and some helper routines to lock/unlock
> different aspects of the system call arguments.
>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>  bsd-user/bsd-file.h           | 39 +++++++++++++++++++++++++++++++++++
>  bsd-user/freebsd/os-syscall.c |  2 ++
>  2 files changed, 41 insertions(+)
>  create mode 100644 bsd-user/bsd-file.h
>

Reviewed-by: Kyle Evans <kevans@FreeBSD.org>

> diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
> new file mode 100644
> index 00000000000..2f743db38e1
> --- /dev/null
> +++ b/bsd-user/bsd-file.h
> @@ -0,0 +1,39 @@
> +/*
> + *  file related system call shims 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 BSD_FILE_H_
> +#define BSD_FILE_H_
> +
> +#include <sys/types.h>
> +#include <sys/mount.h>
> +#include <sys/uio.h>
> +#include <fcntl.h>
> +#include <poll.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +#include "qemu/path.h"
> +
> +extern struct iovec *lock_iovec(int type, abi_ulong target_addr, int count,
> +        int copy);
> +extern void unlock_iovec(struct iovec *vec, abi_ulong target_addr, int count,
> +        int copy);
> +
> +#endif /* !BSD_FILE_H_ */
> diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
> index 2e84cf350b1..060134a9ecd 100644
> --- a/bsd-user/freebsd/os-syscall.c
> +++ b/bsd-user/freebsd/os-syscall.c
> @@ -40,6 +40,8 @@
>  #include "signal-common.h"
>  #include "user/syscall-trace.h"
>
> +#include "bsd-file.h"
> +
>  void target_set_brk(abi_ulong new_brk)
>  {
>  }
> --
> 2.33.1
>
Richard Henderson Feb. 1, 2022, 5:43 p.m. UTC | #2
On 2/1/22 22:14, Warner Losh wrote:
> +#ifndef BSD_FILE_H_
> +#define BSD_FILE_H_
> +
> +#include <sys/types.h>
> +#include <sys/mount.h>
> +#include <sys/uio.h>
> +#include <fcntl.h>
> +#include <poll.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>

Many of these should be done by "qemu/osdep.h" already.  Otherwise I question putting them 
into this header, as opposed to as needed by other syscall handling c files.


r~
Warner Losh Feb. 1, 2022, 11:55 p.m. UTC | #3
On Tue, Feb 1, 2022 at 10:43 AM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 2/1/22 22:14, Warner Losh wrote:
> > +#ifndef BSD_FILE_H_
> > +#define BSD_FILE_H_
> > +
> > +#include <sys/types.h>
> > +#include <sys/mount.h>
> > +#include <sys/uio.h>
> > +#include <fcntl.h>
> > +#include <poll.h>
> > +#include <stdio.h>
> > +#include <stdlib.h>
> > +#include <unistd.h>
>
> Many of these should be done by "qemu/osdep.h" already.  Otherwise I
> question putting them
> into this header, as opposed to as needed by other syscall handling c
> files.
>

I can remove the ones that are done by qemu/osdep.h easily enough. That's
changed over time
and these used to be required. I'm hesitant to remove the others since
that's starting to get
into restructuring the code we have working upstream. On the other hand,
the ordering of these
files make it such that these are often included just once, so moving to a
bsd-file.h that's just the
functions and bsd-file.c that's the definition and relying on LTO to
optimize. That would make things
less fragile than they are now. So I'm torn since part of floating these
patches is to do a small sliver
to get feedback...  I may need to sleep on this to figure out how to
weigh the 'cleaner code' vs 'risk
of introducing regressions during refactoring'.

Warner
Warner Losh Feb. 26, 2022, 4:24 p.m. UTC | #4
On Tue, Feb 1, 2022 at 10:43 AM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 2/1/22 22:14, Warner Losh wrote:
> > +#ifndef BSD_FILE_H_
> > +#define BSD_FILE_H_
> > +
> > +#include <sys/types.h>
> > +#include <sys/mount.h>
> > +#include <sys/uio.h>
> > +#include <fcntl.h>
> > +#include <poll.h>
> > +#include <stdio.h>
> > +#include <stdlib.h>
> > +#include <unistd.h>
>
> Many of these should be done by "qemu/osdep.h" already.  Otherwise I
> question putting them
> into this header, as opposed to as needed by other syscall handling c
> files.
>

Indeed. None of these are needed here. I've removed them.
diff mbox series

Patch

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
new file mode 100644
index 00000000000..2f743db38e1
--- /dev/null
+++ b/bsd-user/bsd-file.h
@@ -0,0 +1,39 @@ 
+/*
+ *  file related system call shims 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 BSD_FILE_H_
+#define BSD_FILE_H_
+
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/uio.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "qemu/path.h"
+
+extern struct iovec *lock_iovec(int type, abi_ulong target_addr, int count,
+        int copy);
+extern void unlock_iovec(struct iovec *vec, abi_ulong target_addr, int count,
+        int copy);
+
+#endif /* !BSD_FILE_H_ */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 2e84cf350b1..060134a9ecd 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -40,6 +40,8 @@ 
 #include "signal-common.h"
 #include "user/syscall-trace.h"
 
+#include "bsd-file.h"
+
 void target_set_brk(abi_ulong new_brk)
 {
 }