bsd-user: Next round of syscalls
cover bsd-user: Next round of syscalls
Implement the next round of system calls. These are open, openat, close, fdatasync, fsync, close_from, revoke, access, eacccess, facccessat, chdir, fchdir, rename, renameat, mkdir, mkdirat, rmdir, _getcwd, dup, dup2, truncate, ftruncate, acct and sync. In addition, the helper functions needed for these to work are included. With the helper functions, all of these system calls are the 'obvious' wrapper...
I've tried to lump these together with related functions in the same change, all less than 100 lines per change (most less than 40). This represents a little over 1/3 of the remaining system calls related to files (we have quite a few more cagegories to go through). I think the lumping represents a good trade-off between 'small enough to review' and 'few enough parts to not add too much overhead' vs 'one commit per system call' which would have bloated this series to 35 pieces. I hope to do the remaining system calls at this chunk granularity and maybe twice as many parts to get through the ~15k backlog I still have to go through.
Warner Losh (11):
bsd-user: Implement open, openat and close
bsd-user: Implement fdatasync, fsync and close_from
bsd-user: Implement revoke, access, eaccess and faccessat
bsd-user: Implement chdir and fchdir
bsd-user: Implement rename and renameat
bsd-user: Implement link, linkat, unlink and unlinkat
bsd-user: Implement mkdir and mkdirat
bsd-user: Implement rmdir and undocumented -_getcwd
bsd-user: Implement dup and dup2
bsd-user: Implement trunctate and ftruncate
bsd-user: Implement acct and sync
bsd-user/bsd-file.h | 369 ++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 116 +++++++++++ bsd-user/syscall_defs.h | 4 + 3 files changed, 489 insertions(+)
Signature · 1 line
2.33.1
PATCH 1/11 bsd-user: Implement open, openat and close
Add the open, openat and close system calls. We need to lock paths, so implmenent that as well.
--- bsd-user/bsd-file.h | 50 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 16 +++++++++++ bsd-user/syscall_defs.h | 4 +++ 3 files changed, 70 insertions(+)
bsd-user/bsd-file.h +50 -0
@@ -22,11 +22,25 @@#include "qemu/path.h" +#define LOCK_PATH (p, arg) \ +do { \ + (p) = lock_user_string(arg); \ + if ((p) == NULL) { \ + return -TARGET_EFAULT; \ + } \ +} while (0) + +#define UNLOCK_PATH (p, arg) unlock_user(p, arg, 0) + +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); +int safe_open (const char *path,int flags,mode_t mode); +int safe_openat (int fd,const char *path,int flags,mode_t mode); +ssize_t safe_read (int fd,void *buf,size_t nbytes);ssize_t safe_pread (int fd,void *buf,size_t nbytes,off_t offset);ssize_t safe_readv (int fd,const struct iovec *iov,int iovcnt);
@@ -190,4 +204,40 @@ static abi_long do_bsd_pwritev(void *cpu_env, abi_long arg1,return ret; } +/* open(2) */ +static abi_long do_bsd_open (abi_long arg1,abi_long arg2,abi_long arg3) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg1); + ret =get_errno (safe_open (path (p),target_to_host_bitmask (arg2, + fcntl_flags_tbl), arg3)); +UNLOCK_PATH (p, arg1); + +return ret; +} + +/* openat(2) */ +static abi_long do_bsd_openat (abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg2); + ret =get_errno (safe_openat (arg1,path (p), +target_to_host_bitmask (arg3, fcntl_flags_tbl), arg4)); +UNLOCK_PATH (p, arg2); + +return ret; +} + +/* close(2) */ +static inline abi_long do_bsd_close (abi_long arg1) +{ + +return get_errno (close (arg1)); +} +#endif /* BSD_FILE_H */
bsd-user/freebsd/os-syscall.c +16 -0
@@ -44,6 +44,10 @@#include "bsd-proc.h" /* I/O */ +safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode); +safe_syscall4(int, openat, int, fd, const char *, path, int, flags, mode_t, + mode); + safe_syscall3(ssize_t, read, int, fd, void *, buf, size_t, nbytes); safe_syscall4(ssize_t, pread, int, fd, void *, buf, size_t, nbytes, off_t, offset);
@@ -257,6 +261,18 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_bsd_pwritev (cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);break ; +case TARGET_FREEBSD_NR_open:/* open(2) */ + ret =do_bsd_open (arg1, arg2, arg3); +break ; + +case TARGET_FREEBSD_NR_openat:/* openat(2) */ + ret =do_bsd_openat (arg1, arg2, arg3, arg4); +break ; + +case TARGET_FREEBSD_NR_close:/* close(2) */ + ret =do_bsd_close (arg1); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
bsd-user/syscall_defs.h +4 -0
@@ -226,4 +226,8 @@ type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5, arg6); \ } +/* So far all target and host bitmasks are the same */ +#define target_to_host_bitmask (x, tbl) (x) +#define host_to_target_bitmask (x, tbl) (x) +#endif /* SYSCALL_DEFS_H */
Signature · 1 line
2.33.1
Re: [PATCH 01/11] bsd-user: Implement open, openat and close
bsd-user/bsd-file.h static abi_long do_bsd_pwritev(void *cpu_env, abi_long arg1, · line 239
Quoted 3 lines · Warner Losh
bsd-user/bsd-file.h +3
-0+static inline abi_long do_bsd_close (abi_long arg1) +{ +
Watch the extra linefeed. Otherwise,
r~
PATCH 2/11 bsd-user: Implement fdatasync, fsync and close_from
In reply to Warner LoshImplement fdatasync(2), fsync(2) and close_from(2).
--- bsd-user/bsd-file.h | 22 ++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 12 ++++++++++++ 2 files changed, 34 insertions(+)
bsd-user/bsd-file.h +22 -0
@@ -240,4 +240,26 @@ static inline abi_long do_bsd_close(abi_long arg1) return get_errno(close(arg1)); } +/* fdatasync(2) */ +static abi_long do_bsd_fdatasync (abi_long arg1) +{ + +return get_errno (fdatasync (arg1)); +} + +/* fsync(2) */ +static abi_long do_bsd_fsync (abi_long arg1) +{ + +return get_errno (fsync (arg1)); +} + +/* closefrom(2) */ +static abi_long do_bsd_closefrom (abi_long arg1) +{ + +closefrom (arg1);/* returns void */ +return get_errno (0 ); +} +#endif /* BSD_FILE_H */
bsd-user/freebsd/os-syscall.c +12 -0
@@ -273,6 +273,18 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_bsd_close (arg1);break ; +case TARGET_FREEBSD_NR_fdatasync:/* fdatasync(2) */ + ret =do_bsd_fdatasync (arg1); +break ; + +case TARGET_FREEBSD_NR_fsync:/* fsync(2) */ + ret =do_bsd_fsync (arg1); +break ; + +case TARGET_FREEBSD_NR_freebsd12_closefrom:/* closefrom(2) */ + ret =do_bsd_closefrom (arg1); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
Signature · 1 line
2.33.1
Re: [PATCH 02/11] bsd-user: Implement fdatasync, fsync and close_from
Quoted 29 lines · Warner Losh
Implement fdatasync(2), fsync(2) and
close_from(2).Signed-off-by Stacey Son <[email protected]>Signed-off-by Jung-uk Kim <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/bsd-file.h | 22 ++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 12 ++++++++++++ 2 files changed, 34 insertions(+)bsd-user/bsd-file.h +11
-0@@ -240,4 +240,26 @@ static inline abi_long do_bsd_close(abi_long arg1)return get_errno (close (arg1)); } +/* fdatasync(2) */ +static abi_long do_bsd_fdatasync (abi_long arg1) +{ + +return get_errno (fdatasync (arg1)); +} + +/* fsync(2) */ +static abi_long do_bsd_fsync (abi_long arg1) +{ +
bsd-user/bsd-file.h static inline abi_long do_bsd_close(abi_long arg1) · line 263
Quoted 10 lines
bsd-user/bsd-file.h +10
-0+return get_errno (fsync (arg1)); +} + +/* closefrom(2) */ +static abi_long do_bsd_closefrom (abi_long arg1) +{ + +closefrom (arg1);/* returns void */ +return get_errno (0 ); +}
All with extra linefeed. Otherwise,
r~
PATCH 3/11 bsd-user: Implement revoke, access, eaccess and faccessat
In reply to Warner Losh--- bsd-user/bsd-file.h | 53 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 16 +++++++++++ 2 files changed, 69 insertions(+)
bsd-user/bsd-file.h +53 -0
@@ -262,4 +262,57 @@ static abi_long do_bsd_closefrom(abi_long arg1)return get_errno (0 ); } +/* revoke(2) */ +static abi_long do_bsd_revoke (abi_long arg1) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg1); + ret =get_errno (revoke (p));/* XXX path(p)? */ +UNLOCK_PATH (p, arg1); + +return ret; +} + +/* access(2) */ +static abi_long do_bsd_access (abi_long arg1,abi_long arg2) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg1); + ret =get_errno (access (path (p), arg2)); +UNLOCK_PATH (p, arg1); + +return ret; +} + +/* eaccess(2) */ +static abi_long do_bsd_eaccess (abi_long arg1,abi_long arg2) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg1); + ret =get_errno (eaccess (path (p), arg2)); +UNLOCK_PATH (p, arg1); + +return ret; +} + +/* faccessat(2) */ +static abi_long do_bsd_faccessat (abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg2); + ret =get_errno (faccessat (arg1, p, arg3, arg4));/* XXX path(p)? */ +UNLOCK_PATH (p, arg2); + +return ret; +} +#endif /* BSD_FILE_H */
bsd-user/freebsd/os-syscall.c +16 -0
@@ -285,6 +285,22 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_bsd_closefrom (arg1);break ; +case TARGET_FREEBSD_NR_revoke:/* revoke(2) */ + ret =do_bsd_revoke (arg1); +break ; + +case TARGET_FREEBSD_NR_access:/* access(2) */ + ret =do_bsd_access (arg1, arg2); +break ; + +case TARGET_FREEBSD_NR_eaccess:/* eaccess(2) */ + ret =do_bsd_eaccess (arg1, arg2); +break ; + +case TARGET_FREEBSD_NR_faccessat:/* faccessat(2) */ + ret =do_bsd_faccessat (arg1, arg2, arg3, arg4); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
Signature · 1 line
2.33.1
Re: [PATCH 03/11] bsd-user: Implement revoke, access, eaccess and faccessat
Quoted 6 lines · Warner Losh
Signed-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/bsd-file.h | 53 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 16 +++++++++++ 2 files changed, 69 insertions(+)
r~
Re: [PATCH 03/11] bsd-user: Implement revoke, access, eaccess and faccessat
In reply to Warner LoshQuoted 17 lines · Warner Losh
Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/bsd-file.h | 53 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 16 +++++++++++ 2 files changed, 69 insertions(+)bsd-user/bsd-file.h +2
-0@@ -262,4 +262,57 @@ static abi_long do_bsd_closefrom(abi_long arg1)return get_errno (0 ); } +/* revoke(2) */ +static abi_long do_bsd_revoke (abi_long arg1)
bsd-user/bsd-file.h static abi_long do_bsd_closefrom(abi_long arg1) · line 276
Quoted 10 lines
bsd-user/bsd-file.h +10
-0+{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg1); + ret =get_errno (revoke (p));/* XXX path(p)? */ +UNLOCK_PATH (p, arg1); + +return ret; +}
Out of curiosity, what is the problem with path(p) here?
Quoted 13 lines
bsd-user/bsd-file.h +13
-0+/* faccessat(2) */ +static abi_long do_bsd_faccessat (abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg2); + ret =get_errno (faccessat (arg1, p, arg3, arg4));/* XXX path(p)? */ +UNLOCK_PATH (p, arg2); + +return ret; +}
PATCH 4/11 bsd-user: Implement chdir and fchdir
In reply to Warner Losh--- bsd-user/bsd-file.h | 20 ++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 28 insertions(+)
bsd-user/bsd-file.h +20 -0
@@ -315,4 +315,24 @@ static abi_long do_bsd_faccessat(abi_long arg1, abi_long arg2, return ret; } +/* chdir(2) */ +static abi_long do_bsd_chdir (abi_long arg1) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg1); + ret =get_errno (chdir (p));/* XXX path(p)? */ +UNLOCK_PATH (p, arg1); + +return ret; +} + +/* fchdir(2) */ +static abi_long do_bsd_fchdir (abi_long arg1) +{ + +return get_errno (fchdir (arg1)); +} +#endif /* BSD_FILE_H */
bsd-user/freebsd/os-syscall.c +8 -0
@@ -301,6 +301,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_bsd_faccessat (arg1, arg2, arg3, arg4);break ; +case TARGET_FREEBSD_NR_chdir:/* chdir(2) */ + ret =do_bsd_chdir (arg1); +break ; + +case TARGET_FREEBSD_NR_fchdir:/* fchdir(2) */ + ret =do_bsd_fchdir (arg1); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
Signature · 1 line
2.33.1
Re: [PATCH 04/11] bsd-user: Implement chdir and fchdir
Quoted 6 lines · Warner Losh
Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/bsd-file.h | 20 ++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 28 insertions(+)
r~
PATCH 5/11 bsd-user: Implement rename and renameat
In reply to Warner LoshPlus the helper LOCK_PATH2 and UNLOCK_PATH2 macros.
--- bsd-user/bsd-file.h | 45 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 +++++++ 2 files changed, 53 insertions(+)
bsd-user/bsd-file.h +45 -0
@@ -32,6 +32,24 @@ do { \#define UNLOCK_PATH (p, arg) unlock_user(p, arg, 0) +#define LOCK_PATH2 (p1, arg1, p2, arg2) \ +do { \ + (p1) = lock_user_string(arg1); \ + if ((p1) == NULL) { \ + return -TARGET_EFAULT; \ + } \ + (p2) = lock_user_string(arg2); \ + if ((p2) == NULL) { \ + unlock_user(p1, arg1, 0); \ + return -TARGET_EFAULT; \ + } \ +} while (0) + +#define UNLOCK_PATH2 (p1, arg1, p2, arg2) \ +do { \ + unlock_user(p2, arg2, 0); \ + unlock_user(p1, arg1, 0); \ +} while (0)extern struct iovec *lock_iovec (int type,abi_ulong target_addr,int count,int copy);
@@ -335,4 +353,31 @@ static abi_long do_bsd_fchdir(abi_long arg1) return get_errno(fchdir(arg1)); } +/* rename(2) */ +static abi_long do_bsd_rename (abi_long arg1,abi_long arg2) +{ +abi_long ret; +void *p1, *p2; + +LOCK_PATH2 (p1, arg1, p2, arg2); + ret =get_errno (rename (p1, p2));/* XXX path(p1), path(p2) */ +UNLOCK_PATH2 (p1, arg1, p2, arg2); + +return ret; +} + +/* renameat(2) */ +static abi_long do_bsd_renameat (abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4) +{ +abi_long ret; +void *p1, *p2; + +LOCK_PATH2 (p1, arg2, p2, arg4); + ret =get_errno (renameat (arg1, p1, arg3, p2)); +UNLOCK_PATH2 (p1, arg2, p2, arg4); + +return ret; +} +#endif /* BSD_FILE_H */
bsd-user/freebsd/os-syscall.c +8 -0
@@ -309,6 +309,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_bsd_fchdir (arg1);break ; +case TARGET_FREEBSD_NR_rename:/* rename(2) */ + ret =do_bsd_rename (arg1, arg2); +break ; + +case TARGET_FREEBSD_NR_renameat:/* renameat(2) */ + ret =do_bsd_renameat (arg1, arg2, arg3, arg4); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
Signature · 1 line
2.33.1
Re: [PATCH 05/11] bsd-user: Implement rename and renameat
Quoted 9 lines · Warner Losh
Plus the helper
LOCK_PATH2andUNLOCK_PATH2macros.Signed-off-by Stacey Son<[email protected]>Signed-off-by Jung-uk Kim<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/bsd-file.h | 45 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 +++++++ 2 files changed, 53 insertions(+)
r~
PATCH 6/11 bsd-user: Implement link, linkat, unlink and unlinkat
In reply to Warner Losh--- bsd-user/bsd-file.h | 54 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 16 +++++++++++ 2 files changed, 70 insertions(+)
bsd-user/bsd-file.h +54 -0
@@ -380,4 +380,58 @@ static abi_long do_bsd_renameat(abi_long arg1, abi_long arg2,return ret; } +/* link(2) */ +static abi_long do_bsd_link (abi_long arg1,abi_long arg2) +{ +abi_long ret; +void *p1, *p2; + +LOCK_PATH2 (p1, arg1, p2, arg2); + ret =get_errno (link (p1, p2));/* XXX path(p1), path(p2) */ +UNLOCK_PATH2 (p1, arg1, p2, arg2); + +return ret; +} + +/* linkat(2) */ +static abi_long do_bsd_linkat (abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +abi_long ret; +void *p1, *p2; + +LOCK_PATH2 (p1, arg2, p2, arg4); + ret =get_errno (linkat (arg1, p1, arg3, p2, arg5)); +UNLOCK_PATH2 (p1, arg2, p2, arg4); + +return ret; +} + +/* unlink(2) */ +static abi_long do_bsd_unlink (abi_long arg1) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg1); + ret =get_errno (unlink (p));/* XXX path(p) */ +UNLOCK_PATH (p, arg1); + +return ret; +} + +/* unlinkat(2) */ +static abi_long do_bsd_unlinkat (abi_long arg1,abi_long arg2, +abi_long arg3) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg2); + ret =get_errno (unlinkat (arg1, p, arg3));/* XXX path(p) */ +UNLOCK_PATH (p, arg2); + +return ret; +} +#endif /* BSD_FILE_H */
bsd-user/freebsd/os-syscall.c +16 -0
@@ -317,6 +317,22 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_bsd_renameat (arg1, arg2, arg3, arg4);break ; +case TARGET_FREEBSD_NR_link:/* link(2) */ + ret =do_bsd_link (arg1, arg2); +break ; + +case TARGET_FREEBSD_NR_linkat:/* linkat(2) */ + ret =do_bsd_linkat (arg1, arg2, arg3, arg4, arg5); +break ; + +case TARGET_FREEBSD_NR_unlink:/* unlink(2) */ + ret =do_bsd_unlink (arg1); +break ; + +case TARGET_FREEBSD_NR_unlinkat:/* unlinkat(2) */ + ret =do_bsd_unlinkat (arg1, arg2, arg3); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
Signature · 1 line
2.33.1
Re: [PATCH 06/11] bsd-user: Implement link, linkat, unlink and unlinkat
Quoted 7 lines · Warner Losh
Signed-off-by Stacey Son<[email protected]>Signed-off-by Jung-uk Kim<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/bsd-file.h | 54 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 16 +++++++++++ 2 files changed, 70 insertions(+)
r~
PATCH 7/11 bsd-user: Implement mkdir and mkdirat
In reply to Warner Losh--- bsd-user/bsd-file.h | 27 +++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 35 insertions(+)
bsd-user/bsd-file.h +27 -0
@@ -434,4 +434,31 @@ static abi_long do_bsd_unlinkat(abi_long arg1, abi_long arg2, return ret; } +/* mkdir(2) */ +static abi_long do_bsd_mkdir (abi_long arg1,abi_long arg2) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg1); + ret =get_errno (mkdir (p, arg2));/* XXX path(p) */ +UNLOCK_PATH (p, arg1); + +return ret; +} + +/* mkdirat(2) */ +static abi_long do_bsd_mkdirat (abi_long arg1,abi_long arg2, +abi_long arg3) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg2); + ret =get_errno (mkdirat (arg1, p, arg3)); +UNLOCK_PATH (p, arg2); + +return ret; +} +#endif /* BSD_FILE_H */
bsd-user/freebsd/os-syscall.c +8 -0
@@ -333,6 +333,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_bsd_unlinkat (arg1, arg2, arg3);break ; +case TARGET_FREEBSD_NR_mkdir:/* mkdir(2) */ + ret =do_bsd_mkdir (arg1, arg2); +break ; + +case TARGET_FREEBSD_NR_mkdirat:/* mkdirat(2) */ + ret =do_bsd_mkdirat (arg1, arg2, arg3); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
Signature · 1 line
2.33.1
Re: [PATCH 07/11] bsd-user: Implement mkdir and mkdirat
Quoted 6 lines · Warner Losh
Signed-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/bsd-file.h | 27 +++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 35 insertions(+)
r~
PATCH 8/11 bsd-user: Implement rmdir and undocumented -_getcwd
In reply to Warner LoshImplemenet rmdir and __getcwd. Declare __getcwd as extern because there's no installed FreeBSD header that has it. It's used internally by libc, which doesn't provide an external declaration, but does export the symbol.
--- bsd-user/bsd-file.h | 30 ++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 38 insertions(+)
bsd-user/bsd-file.h +30 -0
@@ -55,6 +55,7 @@ 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); +extern int __getcwd (char *path,size_t len);int safe_open (const char *path,int flags,mode_t mode);int safe_openat (int fd,const char *path,int flags,mode_t mode);
@@ -461,4 +462,33 @@ static abi_long do_bsd_mkdirat(abi_long arg1, abi_long arg2, return ret; } +/* rmdir(2) */ +static abi_long do_bsd_rmdir (abi_long arg1) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg1); + ret =get_errno (rmdir (p));/* XXX path(p)? */ +UNLOCK_PATH (p, arg1); + +return ret; +} + +/* undocumented __getcwd(char *buf, size_t len) system call */ +static abi_long do_bsd___getcwd (abi_long arg1,abi_long arg2) +{ +abi_long ret; +void *p; + + p =lock_user (VERIFY_WRITE , arg1, arg2,0 ); +if (p ==NULL ) { +return -TARGET_EFAULT ; + } + ret =__getcwd (p, arg2); +unlock_user (p, arg1, ret ==0 ?strlen (p) +1 :0 ); + +return get_errno (ret); +} +#endif /* BSD_FILE_H */
bsd-user/freebsd/os-syscall.c +8 -0
@@ -341,6 +341,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_bsd_mkdirat (arg1, arg2, arg3);break ; +case TARGET_FREEBSD_NR_rmdir:/* rmdir(2) (XXX no rmdirat()?) */ + ret =do_bsd_rmdir (arg1); +break ; + +case TARGET_FREEBSD_NR___getcwd:/* undocumented __getcwd() */ + ret =do_bsd___getcwd (arg1, arg2); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
Signature · 1 line
2.33.1
Re: [PATCH 08/11] bsd-user: Implement rmdir and undocumented -_getcwd
Quoted 4 lines · Warner Losh
Implemenet rmdir and
__getcwd. Declare__getcwdas extern because there's no installed FreeBSD header that has it. It's used internally by libc, which doesn't provide an external declaration, but does export the symbol.
Typo in subject: s/-/_/.
bsd-user/bsd-file.h extern struct iovec *lock_iovec(int type, abi_ulong target_addr, int count, · line 58
Quoted 5 lines
bsd-user/bsd-file.h +1
-0@@ -55,6 +55,7 @@ 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); +extern int __getcwd (char *path,size_t len);
Do you really want to rely on this export?
Unless it does something special, I'd just declare a local version of the syscall as you do with safe_*.
bsd-user/bsd-file.h static abi_long do_bsd_mkdirat(abi_long arg1, abi_long arg2, · line 478
Quoted 1 line
bsd-user/bsd-file.h +1
-0+/* undocumented __getcwd(char *buf, size_t len) system call */
Surely the syscall itself is documented?
r~
Re: [PATCH 08/11] bsd-user: Implement rmdir and undocumented -_getcwd
Quoted 8 lines · Richard Henderson
Quoted 4 lines · Warner Losh
Implemenet rmdir and
__getcwd. Declare__getcwdas extern because there's no installed FreeBSD header that has it. It's used internally by libc, which doesn't provide an external declaration, but does export the symbol.Typo in subject: s/-/_/.
Indeed.
Quoted 4 lines
Review extern struct iovec *lock_iovec(int type, abi_ulong
Quoted 1 line
(quoted diff) +0
-0@@ -55,6 +55,7 @@ extern struct iovec *lock_iovec(int type, abi_ulong
target_addr, int count,Review extern struct iovec *lock_iovec(int type, abi_ulong · line 56
Quoted 2 lines
(quoted diff) +0
-0int copy); extern void unlock_iovec(struct iovec *vec, abi_ulong target_addr, int
Quoted 9 lines
count,
Review extern struct iovec *lock_iovec(int type, abi_ulong · line 58
Quoted 2 lines
(quoted diff) +1
-0int copy); +extern int __getcwd(char *path, size_t len);Do you really want to rely on this export?
Unless it does something special, I'd just declare a local version of the syscall as you
do with safe_*.
Indeed not. I was just copying what we've been running, but I see now that was unwise.
I'll do a safe_syscall directly here since we don't need to call it anywhere else. I'll do a
sanity check on our upstream and make sure I can still run my favorite shells, which
I believe use this call.
Quoted 4 lines
bsd-user/bsd-file.h static abi_long do_bsd_mkdirat(abi_long arg1, abi_long arg2, · line 478
Quoted 1 line
bsd-user/bsd-file.h +1
-0+/* undocumented __getcwd(char *buf, size_t len) system call */ Surely the syscall itself is documented?
One would think it was documented, but there's no man page for it and the getcwd()
call has some extensions that it implements, plus there's some weird special cases
that __getcwd() can sometimes return that getcwd() knows how to unwind (the oddest being that sometimes paths are returned backwards). All these quirks are not,
alas, documented in any place except the code. Hence the characterization that this
is undocumented :)... I was rather surprised by this when I went looking.
Warner
PATCH 9/11 bsd-user: Implement dup and dup2
In reply to Warner Losh--- bsd-user/bsd-file.h | 14 ++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 22 insertions(+)
bsd-user/bsd-file.h +14 -0
@@ -491,4 +491,18 @@ static abi_long do_bsd___getcwd(abi_long arg1, abi_long arg2) return get_errno(ret); } +/* dup(2) */ +static abi_long do_bsd_dup (abi_long arg1) +{ + +return get_errno (dup (arg1)); +} + +/* dup2(2) */ +static abi_long do_bsd_dup2 (abi_long arg1,abi_long arg2) +{ + +return get_errno (dup2 (arg1, arg2)); +} +#endif /* BSD_FILE_H */
bsd-user/freebsd/os-syscall.c +8 -0
@@ -349,6 +349,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_bsd___getcwd (arg1, arg2);break ; +case TARGET_FREEBSD_NR_dup:/* dup(2) */ + ret =do_bsd_dup (arg1); +break ; + +case TARGET_FREEBSD_NR_dup2:/* dup2(2) */ + ret =do_bsd_dup2 (arg1, arg2); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
Signature · 1 line
2.33.1
Re: [PATCH 09/11] bsd-user: Implement dup and dup2
Quoted 18 lines · Warner Losh
Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/bsd-file.h | 14 ++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 22 insertions(+)bsd-user/bsd-file.h +3
-0@@ -491,4 +491,18 @@ static abi_long do_bsd___getcwd(abi_long arg1, abi_long arg2)return get_errno (ret); } +/* dup(2) */ +static abi_long do_bsd_dup (abi_long arg1) +{
bsd-user/bsd-file.h static abi_long do_bsd___getcwd(abi_long arg1, abi_long arg2) · line 506
Quoted 10 lines
bsd-user/bsd-file.h +10
-0+ +return get_errno (dup (arg1)); +} + +/* dup2(2) */ +static abi_long do_bsd_dup2 (abi_long arg1,abi_long arg2) +{ + +return get_errno (dup2 (arg1, arg2)); +}
Extra lines. Is this some setting in your editor? Otherwise,
Re: [PATCH 09/11] bsd-user: Implement dup and dup2
Quoted 17 lines · Richard Henderson
bsd-user/bsd-file.h static abi_long do_bsd___getcwd(abi_long arg1,
Quoted 12 lines · Warner Losh
Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/bsd-file.h | 14 ++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 22 insertions(+)bsd-user/bsd-file.h +0
-0@@ -491,4 +491,18 @@ static abi_long do_bsd___getcwd(abi_long arg1,
abi_longarg2)Quoted 3 lines
bsd-user/bsd-file.h +0
-0return get_errno (ret); }
Quoted 16 lines
bsd-user/bsd-file.h static abi_long do_bsd___getcwd(abi_long arg1, abi_long arg2) · line 506
Quoted 13 lines
bsd-user/bsd-file.h +13
-0+/* dup(2) */ +static abi_long do_bsd_dup (abi_long arg1) +{ + +return get_errno (dup (arg1)); +} + +/* dup2(2) */ +static abi_long do_bsd_dup2 (abi_long arg1,abi_long arg2) +{ + +return get_errno (dup2 (arg1, arg2)); +}Extra lines. Is this some setting in your editor? Otherwise,
It's an odd quirk of FreeBSD's style from the 90s until 2020... I'm totally blind to
it most of the time...
Quoted 2 lines
Reviewed-by Richard Henderson <[email protected]>
Thanks for this, and all the other reviews.
Warner
PATCH 10/11 bsd-user: Implement trunctate and ftruncate
In reply to Warner Losh--- bsd-user/bsd-file.h | 30 ++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 38 insertions(+)
bsd-user/bsd-file.h +30 -0
@@ -505,4 +505,34 @@ static abi_long do_bsd_dup2(abi_long arg1, abi_long arg2) return get_errno(dup2(arg1, arg2)); } +/* truncate(2) */ +static abi_long do_bsd_truncate (void *cpu_env,abi_long arg1, +abi_long arg2,abi_long arg3,abi_long arg4) +{ +abi_long ret; +void *p; + +LOCK_PATH (p, arg1); +if (regpairs_aligned (cpu_env) !=0 ) { + arg2 = arg3; + arg3 = arg4; + } + ret =get_errno (truncate (p,target_arg64 (arg2, arg3))); +UNLOCK_PATH (p, arg1); + +return ret; +} + +/* ftruncate(2) */ +static abi_long do_bsd_ftruncate (void *cpu_env,abi_long arg1, +abi_long arg2,abi_long arg3,abi_long arg4) +{ + +if (regpairs_aligned (cpu_env) !=0 ) { + arg2 = arg3; + arg3 = arg4; + } +return get_errno (ftruncate (arg1,target_arg64 (arg2, arg3))); +} +#endif /* BSD_FILE_H */
bsd-user/freebsd/os-syscall.c +8 -0
@@ -357,6 +357,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_bsd_dup2 (arg1, arg2);break ; +case TARGET_FREEBSD_NR_truncate:/* truncate(2) */ + ret =do_bsd_truncate (cpu_env, arg1, arg2, arg3, arg4); +break ; + +case TARGET_FREEBSD_NR_ftruncate:/* ftruncate(2) */ + ret =do_bsd_ftruncate (cpu_env, arg1, arg2, arg3, arg4); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
Signature · 1 line
2.33.1
Re: [PATCH 10/11] bsd-user: Implement trunctate and ftruncate
bsd-user/bsd-file.h static abi_long do_bsd_dup2(abi_long arg1, abi_long arg2) · line 530
Quoted 4 lines · Warner Losh
bsd-user/bsd-file.h +4
-0+static abi_long do_bsd_ftruncate (void *cpu_env,abi_long arg1, +abi_long arg2,abi_long arg3,abi_long arg4) +{ +
Extra line. Otherwise,
r~
PATCH 11/11 bsd-user: Implement acct and sync
In reply to Warner Losh--- bsd-user/bsd-file.h | 24 ++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 32 insertions(+)
bsd-user/bsd-file.h +24 -0
@@ -535,4 +535,28 @@ static abi_long do_bsd_ftruncate(void *cpu_env, abi_long arg1, return get_errno(ftruncate(arg1, target_arg64(arg2, arg3))); } +/* acct(2) */ +static abi_long do_bsd_acct (abi_long arg1) +{ +abi_long ret; +void *p; + +if (arg1 ==0 ) { + ret =get_errno (acct (NULL )); + }else { +LOCK_PATH (p, arg1); + ret =get_errno (acct (path (p))); +UNLOCK_PATH (p, arg1); + } +return ret; +} + +/* sync(2) */ +static abi_long do_bsd_sync (void ) +{ + +sync (); +return 0 ; +} +#endif /* BSD_FILE_H */
bsd-user/freebsd/os-syscall.c +8 -0
@@ -365,6 +365,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret =do_bsd_ftruncate (cpu_env, arg1, arg2, arg3, arg4);break ; +case TARGET_FREEBSD_NR_acct:/* acct(2) */ + ret =do_bsd_acct (arg1); +break ; + +case TARGET_FREEBSD_NR_sync:/* sync(2) */ + ret =do_bsd_sync (); +break ; +default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num); ret = -TARGET_ENOSYS ;
Signature · 1 line
2.33.1
Re: [PATCH 11/11] bsd-user: Implement acct and sync
bsd-user/bsd-file.h static abi_long do_bsd_ftruncate(void *cpu_env, abi_long arg1, · line 557
Quoted 3 lines · Warner Losh
bsd-user/bsd-file.h +3
-0+static abi_long do_bsd_sync (void ) +{ +
Extra line, otherwise,
r~