[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 12/51] bsd-user: Implement umask(2), setlogin(2) and getlogin(2)
From: |
Warner Losh |
Subject: |
[PULL 12/51] bsd-user: Implement umask(2), setlogin(2) and getlogin(2) |
Date: |
Tue, 3 Oct 2023 17:31:36 -0600 |
From: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Warner Losh <imp@bsdimp.com>
Message-Id: <20230925182425.3163-13-kariem.taha2.7@gmail.com>
---
bsd-user/bsd-proc.h | 39 +++++++++++++++++++++++++++++++++++
bsd-user/freebsd/os-syscall.c | 12 +++++++++++
2 files changed, 51 insertions(+)
diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h
index 7b25aa19829..cb7c69acb0c 100644
--- a/bsd-user/bsd-proc.h
+++ b/bsd-user/bsd-proc.h
@@ -26,6 +26,7 @@
#include "gdbstub/syscalls.h"
#include "qemu/plugin.h"
+extern int _getlogin(char*, int);
int bsd_get_ncpu(void);
/* exit(2) */
@@ -85,4 +86,42 @@ static inline abi_long do_bsd_setgroups(abi_long gidsetsize,
abi_long arg2)
return get_errno(setgroups(gidsetsize, grouplist));
}
+/* umask(2) */
+static inline abi_long do_bsd_umask(abi_long arg1)
+{
+ return get_errno(umask(arg1));
+}
+
+/* setlogin(2) */
+static inline abi_long do_bsd_setlogin(abi_long arg1)
+{
+ abi_long ret;
+ void *p;
+
+ p = lock_user_string(arg1);
+ if (p == NULL) {
+ return -TARGET_EFAULT;
+ }
+ ret = get_errno(setlogin(p));
+ unlock_user(p, arg1, 0);
+
+ return ret;
+}
+
+/* getlogin(2) */
+static inline abi_long do_bsd_getlogin(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 = get_errno(_getlogin(p, arg2));
+ unlock_user(p, arg1, arg2);
+
+ return ret;
+}
+
#endif /* !BSD_PROC_H_ */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 535e6287bde..44cbf52f087 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -231,6 +231,18 @@ static abi_long freebsd_syscall(void *cpu_env, int num,
abi_long arg1,
ret = do_bsd_setgroups(arg1, arg2);
break;
+ case TARGET_FREEBSD_NR_umask: /* umask(2) */
+ ret = do_bsd_umask(arg1);
+ break;
+
+ case TARGET_FREEBSD_NR_setlogin: /* setlogin(2) */
+ ret = do_bsd_setlogin(arg1);
+ break;
+
+ case TARGET_FREEBSD_NR_getlogin: /* getlogin(2) */
+ ret = do_bsd_getlogin(arg1, arg2);
+ break;
+
/*
* File system calls.
--
2.41.0
- [PULL 03/51] bsd-user: Implement host_to_target_siginfo., (continued)
- [PULL 03/51] bsd-user: Implement host_to_target_siginfo., Warner Losh, 2023/10/03
- [PULL 05/51] bsd-user: add extern declarations for bsd-proc.c conversion functions, Warner Losh, 2023/10/03
- [PULL 02/51] bsd-user: Define procctl(2) related structs, Warner Losh, 2023/10/03
- [PULL 07/51] bsd-user: Implement target_to_host_rlim and host_to_target_rlim conversion., Warner Losh, 2023/10/03
- [PULL 06/51] bsd-user: Implement target_to_host_resource conversion function, Warner Losh, 2023/10/03
- [PULL 08/51] bsd-user: Implement host_to_target_rusage and host_to_target_wrusage., Warner Losh, 2023/10/03
- [PULL 10/51] bsd-user: Get number of cpus., Warner Losh, 2023/10/03
- [PULL 09/51] bsd-user: Implement host_to_target_waitstatus conversion., Warner Losh, 2023/10/03
- [PULL 13/51] bsd-user: Implement getrusage(2)., Warner Losh, 2023/10/03
- [PULL 11/51] bsd-user: Implement getgroups(2) and setgroups(2) system calls., Warner Losh, 2023/10/03
- [PULL 12/51] bsd-user: Implement umask(2), setlogin(2) and getlogin(2),
Warner Losh <=
- [PULL 04/51] bsd-user: Add freebsd_exec_common and do_freebsd_procctl to qemu.h., Warner Losh, 2023/10/03
- [PULL 14/51] bsd-user: Implement getrlimit(2) and setrlimit(2), Warner Losh, 2023/10/03
- [PULL 15/51] bsd-user: Implement several get/set system calls:, Warner Losh, 2023/10/03
- [PULL 17/51] bsd-user: Add stubs for profil(2), ktrace(2), utrace(2) and ptrace(2)., Warner Losh, 2023/10/03
- [PULL 18/51] bsd-user: Implement getpriority(2) and setpriority(2)., Warner Losh, 2023/10/03
- [PULL 16/51] bsd-user: Implement get/set[resuid/resgid/sid] and issetugid., Warner Losh, 2023/10/03
- [PULL 20/51] bsd-user: Implement freebsd_exec_common, used in implementing execve/fexecve., Warner Losh, 2023/10/03
- [PULL 19/51] bsd-user: Implement get_filename_from_fd., Warner Losh, 2023/10/03
- [PULL 23/51] bsd-user: Implement wait4(2) and wait6(2) system calls., Warner Losh, 2023/10/03
- [PULL 25/51] bsd-user: Implement pdgetpid(2) and the undocumented setugid., Warner Losh, 2023/10/03