[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 15/28] bsd-user: Implement several get/set system calls:
From: |
Karim Taha |
Subject: |
[PATCH v4 15/28] bsd-user: Implement several get/set system calls: |
Date: |
Mon, 25 Sep 2023 00:01:23 +0300 |
From: Stacey Son <sson@FreeBSD.org>
getpid(2), getppid(2), getpgrp(2)
setreuid(2), setregid(2)
getuid(2), geteuid(2), getgid(2), getegid(2), getpgid(2)
setuid(2), seteuid(2), setgid(2), setegid(2), setpgid(2)
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Warner Losh <imp@bsdimp.com>
---
bsd-user/bsd-proc.h | 90 +++++++++++++++++++++++++++++++++++
bsd-user/freebsd/os-syscall.c | 60 +++++++++++++++++++++++
2 files changed, 150 insertions(+)
diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h
index 38d1324034..6ff07c0ac3 100644
--- a/bsd-user/bsd-proc.h
+++ b/bsd-user/bsd-proc.h
@@ -196,4 +196,94 @@ static inline abi_long do_bsd_setrlimit(abi_long arg1,
abi_ulong arg2)
return ret;
}
+/* getpid(2) */
+static inline abi_long do_bsd_getpid(void)
+{
+ return get_errno(getpid());
+}
+
+/* getppid(2) */
+static inline abi_long do_bsd_getppid(void)
+{
+ return get_errno(getppid());
+}
+
+/* getuid(2) */
+static inline abi_long do_bsd_getuid(void)
+{
+ return get_errno(getuid());
+}
+
+/* geteuid(2) */
+static inline abi_long do_bsd_geteuid(void)
+{
+ return get_errno(geteuid());
+}
+
+/* getgid(2) */
+static inline abi_long do_bsd_getgid(void)
+{
+ return get_errno(getgid());
+}
+
+/* getegid(2) */
+static inline abi_long do_bsd_getegid(void)
+{
+ return get_errno(getegid());
+}
+
+/* setuid(2) */
+static inline abi_long do_bsd_setuid(abi_long arg1)
+{
+ return get_errno(setuid(arg1));
+}
+
+/* seteuid(2) */
+static inline abi_long do_bsd_seteuid(abi_long arg1)
+{
+ return get_errno(seteuid(arg1));
+}
+
+/* setgid(2) */
+static inline abi_long do_bsd_setgid(abi_long arg1)
+{
+ return get_errno(setgid(arg1));
+}
+
+/* setegid(2) */
+static inline abi_long do_bsd_setegid(abi_long arg1)
+{
+ return get_errno(setegid(arg1));
+}
+
+/* getpgid(2) */
+static inline abi_long do_bsd_getpgid(pid_t pid)
+{
+ return get_errno(getpgid(pid));
+}
+
+/* setpgid(2) */
+static inline abi_long do_bsd_setpgid(int pid, int pgrp)
+{
+ return get_errno(setpgid(pid, pgrp));
+}
+
+/* getpgrp(2) */
+static inline abi_long do_bsd_getpgrp(void)
+{
+ return get_errno(getpgrp());
+}
+
+/* setreuid(2) */
+static inline abi_long do_bsd_setreuid(abi_long arg1, abi_long arg2)
+{
+ return get_errno(setreuid(arg1, arg2));
+}
+
+/* setregid(2) */
+static inline abi_long do_bsd_setregid(abi_long arg1, abi_long arg2)
+{
+ return get_errno(setregid(arg1, arg2));
+}
+
#endif /* !BSD_PROC_H_ */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 5cb6086230..7565e69e76 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -255,6 +255,66 @@ static abi_long freebsd_syscall(void *cpu_env, int num,
abi_long arg1,
ret = do_bsd_setrlimit(arg1, arg2);
break;
+ case TARGET_FREEBSD_NR_getpid: /* getpid(2) */
+ ret = do_bsd_getpid();
+ break;
+
+ case TARGET_FREEBSD_NR_getppid: /* getppid(2) */
+ ret = do_bsd_getppid();
+ break;
+
+ case TARGET_FREEBSD_NR_getuid: /* getuid(2) */
+ ret = do_bsd_getuid();
+ break;
+
+ case TARGET_FREEBSD_NR_geteuid: /* geteuid(2) */
+ ret = do_bsd_geteuid();
+ break;
+
+ case TARGET_FREEBSD_NR_getgid: /* getgid(2) */
+ ret = do_bsd_getgid();
+ break;
+
+ case TARGET_FREEBSD_NR_getegid: /* getegid(2) */
+ ret = do_bsd_getegid();
+ break;
+
+ case TARGET_FREEBSD_NR_setuid: /* setuid(2) */
+ ret = do_bsd_setuid(arg1);
+ break;
+
+ case TARGET_FREEBSD_NR_seteuid: /* seteuid(2) */
+ ret = do_bsd_seteuid(arg1);
+ break;
+
+ case TARGET_FREEBSD_NR_setgid: /* setgid(2) */
+ ret = do_bsd_setgid(arg1);
+ break;
+
+ case TARGET_FREEBSD_NR_setegid: /* setegid(2) */
+ ret = do_bsd_setegid(arg1);
+ break;
+
+ case TARGET_FREEBSD_NR_getpgrp: /* getpgrp(2) */
+ ret = do_bsd_getpgrp();
+ break;
+
+ case TARGET_FREEBSD_NR_getpgid: /* getpgid(2) */
+ ret = do_bsd_getpgid(arg1);
+ break;
+
+ case TARGET_FREEBSD_NR_setpgid: /* setpgid(2) */
+ ret = do_bsd_setpgid(arg1, arg2);
+ break;
+
+ case TARGET_FREEBSD_NR_setreuid: /* setreuid(2) */
+ ret = do_bsd_setreuid(arg1, arg2);
+ break;
+
+ case TARGET_FREEBSD_NR_setregid: /* setregid(2) */
+ ret = do_bsd_setregid(arg1, arg2);
+ break;
+
/*
* File system calls.
--
2.42.0
- [PATCH v4 07/28] bsd-user: Implement target_to_host_rlim and host_to_target_rlim conversion., (continued)
- [PATCH v4 07/28] bsd-user: Implement target_to_host_rlim and host_to_target_rlim conversion., Karim Taha, 2023/09/24
- [PATCH v4 09/28] bsd-user: Implement host_to_target_waitstatus conversion., Karim Taha, 2023/09/24
- [PATCH v4 08/28] bsd-user: Implement host_to_target_rusage and host_to_target_wrusage., Karim Taha, 2023/09/24
- [PATCH v4 10/28] bsd-user: Get number of cpus., Karim Taha, 2023/09/24
- [PATCH v4 11/28] bsd-user: Implement getgroups(2) and setgroups(2) system calls., Karim Taha, 2023/09/24
- [PATCH v4 12/28] bsd-user: Implement umask(2), setlogin(2) and getlogin(2), Karim Taha, 2023/09/24
- [PATCH v4 13/28] bsd-user: Implement getrusage(2)., Karim Taha, 2023/09/24
- [PATCH v4 14/28] bsd-user: Implement getrlimit(2) and setrlimit(2), Karim Taha, 2023/09/24
- [PATCH v4 16/28] bsd-user: Implement get/set[resuid/resgid/sid] and issetugid., Karim Taha, 2023/09/24
- [PATCH v4 15/28] bsd-user: Implement several get/set system calls:,
Karim Taha <=
- [PATCH v4 19/28] bsd-user: Implement get_filename_from_fd., Karim Taha, 2023/09/24
- [PATCH v4 17/28] bsd-user: Add stubs for profil(2), ktrace(2), utrace(2) and ptrace(2)., Karim Taha, 2023/09/24
- [PATCH v4 18/28] bsd-user: Implement getpriority(2) and setpriority(2)., Karim Taha, 2023/09/24
- [PATCH v4 20/28] bsd-user: Implement freebsd_exec_common, used in implementing execve/fexecve., Karim Taha, 2023/09/24
- [PATCH v4 21/28] bsd-user: Implement procctl(2) along with necessary conversion functions., Karim Taha, 2023/09/24
- [PATCH v4 22/28] bsd-user: Implement execve(2) and fexecve(2) system calls., Karim Taha, 2023/09/24
- [PATCH v4 23/28] bsd-user: Implement wait4(2) and wait6(2) system calls., Karim Taha, 2023/09/24
- [PATCH v4 24/28] bsd-user: Implement setloginclass(2) and getloginclass(2) system calls., Karim Taha, 2023/09/24