Message ID | 20230819094806.14965-19-kariem.taha2.7@gmail.com |
---|---|
State | New |
Headers | show |
Series | Implement the mmap system call for FreeBSD. | expand |
On Sat, Aug 19, 2023 at 3:49 AM Karim Taha <kariem.taha2.7@gmail.com> wrote: > From: Stacey Son <sson@FreeBSD.org> > > Co-authored-by: Kyle Evans <kevans@FreeBSD.org> > > Signed-off-by: Stacey Son <sson@FreeBSD.org> > Signed-off-by: Kyle Evans <kevans@FreeBSD.org> > Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com> > --- > bsd-user/bsd-mem.h | 27 +++++++++++++++++++++++++++ > bsd-user/freebsd/os-syscall.c | 4 ++++ > 2 files changed, 31 insertions(+) > Reviewed-by: Warner Losh <imp@bsdimp.com>
On 8/19/23 02:48, Karim Taha wrote: > +#define SHM_PATH(p) ((p) == SHM_ANON ? (p) : path(p)) > + if (arg1 == (uintptr_t)SHM_ANON) { > + p = SHM_ANON; > + } else { > + p = lock_user_string(arg1); > + if (p == NULL) { > + return -TARGET_EFAULT; > + } > + } > + ret = get_errno(shm_open(SHM_PATH(p), Again, SHM_PATH is not needed, because the condition is handled by this IF. r~
On 8/20/23 08:04, Richard Henderson wrote: > On 8/19/23 02:48, Karim Taha wrote: >> +#define SHM_PATH(p) ((p) == SHM_ANON ? (p) : path(p)) >> + if (arg1 == (uintptr_t)SHM_ANON) { >> + p = SHM_ANON; >> + } else { >> + p = lock_user_string(arg1); >> + if (p == NULL) { >> + return -TARGET_EFAULT; >> + } >> + } >> + ret = get_errno(shm_open(SHM_PATH(p), > > Again, SHM_PATH is not needed, because the condition is handled by this IF. Oh, no, that's something different. But path() is wrong for shm_open, because it's not a path in the regular file system. r~
diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index 6f33148eb7..013b82f49a 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -252,4 +252,31 @@ static inline abi_long do_obreak(abi_ulong new_brk) return bsd_target_brk; } +/* shm_open(2) */ +static inline abi_long do_bsd_shm_open(abi_ulong arg1, abi_long arg2, + abi_long arg3) +{ + int ret; + void *p; + +#define SHM_PATH(p) ((p) == SHM_ANON ? (p) : path(p)) + if (arg1 == (uintptr_t)SHM_ANON) { + p = SHM_ANON; + } else { + p = lock_user_string(arg1); + if (p == NULL) { + return -TARGET_EFAULT; + } + } + ret = get_errno(shm_open(SHM_PATH(p), + target_to_host_bitmask(arg2, fcntl_flags_tbl), arg3)); + + if (p != SHM_ANON) { + unlock_user(p, arg1, 0); + } + + return ret; +} +#undef SHM_PATH + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 1b9dca9164..2d15255c20 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -531,6 +531,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_mincore(arg1, arg2, arg3); break; + case TARGET_FREEBSD_NR_freebsd12_shm_open: /* shm_open(2) */ + ret = do_bsd_shm_open(arg1, arg2, arg3); + break; + #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048 case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */ ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5);