Bsd user syscall 2022q2 patches
The following changes since commit dcb40541ebca7ec98a14d461593b3cd7282b4fac:
Merge tag 'mips-20220611' of https://github.com/philmd/qemu into staging (2022-06-11 21:13:27 -0700)
are available in the Git repository at:
ssh://[email protected]/qemu-bsd-user/qemu-bsd-user.git tags/bsd-user-syscall-2022q2-pull-request
for you to fetch changes up to d35020ed00b1cb649ccd73ba4f5e918a5cc5363a:
bsd-user: Implement acct and sync (2022-06-14 08:17:44 -0600)
----------------------------------------------------------------
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...
----------------------------------------------------------------
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 | 359 ++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 116 +++++++++++ bsd-user/syscall_defs.h | 4 + 3 files changed, 479 insertions(+)
Signature · 1 line
2.33.1
[PULL 01/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 | 49 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 16 ++++++++++++ bsd-user/syscall_defs.h | 4 +++ 3 files changed, 69 insertions(+)
bsd-user/bsd-file.h +49 -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,39 @@ 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
[PULL 02/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 | 19 +++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 12 ++++++++++++ 2 files changed, 31 insertions(+)
bsd-user/bsd-file.h +19 -0
@@ -239,4 +239,23 @@ 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
[PULL 04/11] bsd-user: Implement chdir and fchdir
In reply to Warner Losh--- bsd-user/bsd-file.h | 19 +++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 27 insertions(+)
bsd-user/bsd-file.h +19 -0
@@ -311,4 +311,23 @@ 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
[PULL 10/11] bsd-user: Implement trunctate and ftruncate
In reply to Warner Losh--- bsd-user/bsd-file.h | 29 +++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 37 insertions(+)
bsd-user/bsd-file.h +29 -0
@@ -497,4 +497,33 @@ 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
[PULL 03/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
@@ -258,4 +258,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
[PULL 06/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
@@ -375,4 +375,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
[PULL 05/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);
@@ -330,4 +348,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
[PULL 09/11] bsd-user: Implement dup and dup2
In reply to Warner Losh--- bsd-user/bsd-file.h | 12 ++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 20 insertions(+)
bsd-user/bsd-file.h +12 -0
@@ -485,4 +485,16 @@ 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
[PULL 07/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
@@ -429,4 +429,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
[PULL 11/11] bsd-user: Implement acct and sync
In reply to Warner Losh--- bsd-user/bsd-file.h | 23 +++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 31 insertions(+)
bsd-user/bsd-file.h +23 -0
@@ -526,4 +526,27 @@ 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
[PULL 08/11] bsd-user: Implement rmdir and undocumented __getcwd
In reply to Warner LoshImplemenet rmdir and __getcwd. __getcwd is the undocumented back end to getcwd(3).
--- bsd-user/bsd-file.h | 29 +++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 37 insertions(+)
bsd-user/bsd-file.h +29 -0
@@ -456,4 +456,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 =safe_syscall (SYS___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
Richard Henderson
AppliedQuoted 15 lines · Warner Losh
The following changes since commit
dcb40541ebca7ec98a14d461593b3cd7282b4fac:Merge tag 'mips-20220611' of https://github.com/philmd/qemu into staging (2022-06-11 21:13:27 -0700)are available in the Git repository at:
ssh://[email protected]/qemu-bsd-user/qemu-bsd-user.git tags/bsd-user-syscall-2022q2-pull-request
for you to fetch changes up to
d35020ed00b1cb649ccd73ba4f5e918a5cc5363a:bsd-user: Implement acct and sync (2022-06-14 08:17:44 -0600)----------------------------------------------------------------
bsd-user: Next round of syscalls
Quoted 6 lines
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...
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/7.1 as appropriate.
r~
Quoted 21 lines
----------------------------------------------------------------
Warner Losh (11):
bsd-user: Implement open, openat and close
bsd-user: Implement fdatasync, fsync andclose_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 syncbsd-user/bsd-file.h | 359 ++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 116 +++++++++++ bsd-user/syscall_defs.h | 4 + 3 files changed, 479 insertions(+)