From: Kyle Evans <kev...@freebsd.org> do_freebsd_sysctlbyname needs to translate the 'name' back down to a OID so we can intercept the special ones. Do that and call the common wrapper do_freebsd_sysctl_oid.
Signed-off-by: Kyle Evans <kev...@freebsd.org> Signed-off-by: Warner Losh <i...@bsdimp.com> --- bsd-user/freebsd/os-sys.c | 58 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 +++ 2 files changed, 62 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 13736936e5f..62c729dfe47 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -345,6 +345,64 @@ out: return ret; } +/* + * This syscall was created to make sysctlbyname(3) more efficient. + * Unfortunately, because we have to fake some sysctls, we can't do that. + */ +abi_long do_freebsd_sysctlbyname(CPUArchState *env, abi_ulong namep, + int32_t namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, + abi_ulong newlen) +{ + abi_long ret; + void *holdp = NULL, *hnewp = NULL; + char *snamep; + int oid[CTL_MAXNAME + 2]; + size_t holdlen, oidplen; + abi_ulong oldlen = 0; + + if (oldlenp) { + if (get_user_ual(oldlen, oldlenp)) { + return -TARGET_EFAULT; + } + } + snamep = lock_user_string(namep); + if (snamep == NULL) { + return -TARGET_EFAULT; + } + if (newp) { + hnewp = lock_user(VERIFY_READ, newp, newlen, 1); + if (hnewp == NULL) { + return -TARGET_EFAULT; + } + } + if (oldp) { + holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0); + if (holdp == NULL) { + return -TARGET_EFAULT; + } + } + holdlen = oldlen; + + oidplen = sizeof(oid) / sizeof(int); + if (sysctlnametomib(snamep, oid, &oidplen) != 0) { + return -TARGET_EINVAL; + } + + ret = do_freebsd_sysctl_oid(env, oid, oidplen, holdp, &holdlen, hnewp, + newlen); + + if (oldlenp) { + put_user_ual(holdlen, oldlenp); + } + unlock_user(snamep, namep, 0); + unlock_user(holdp, oldp, holdlen); + if (hnewp) { + unlock_user(hnewp, newp, 0); + } + + return ret; +} + abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen) { diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 20ab3d4d9a1..179a20c304b 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -498,6 +498,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); break; + case TARGET_FREEBSD_NR___sysctlbyname: /* sysctlbyname(2) */ + ret = do_freebsd_sysctlbyname(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + break; + case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ ret = do_freebsd_sysarch(cpu_env, arg1, arg2); break; -- 2.39.1