Skip to content

Commit

Permalink
Byte swap the returned MIB/OID data from special sysctl() (name2oid).
Browse files Browse the repository at this point in the history
  • Loading branch information
staceyson committed Feb 26, 2013
1 parent c62b5a0 commit a344a13
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions work/qemu-1.4.0/bsd-user/syscall.c
Expand Up @@ -293,12 +293,16 @@ static abi_long do_freebsd_sysarch(void *env, int op, abi_ulong parms)
static abi_long do_freebsd_sysarch(void *env, int op, abi_ulong parms) static abi_long do_freebsd_sysarch(void *env, int op, abi_ulong parms)
{ {
int ret = 0; int ret = 0;
abi_ulong tmp;
CPUMIPSState *mips_env = (CPUMIPSState *)env; CPUMIPSState *mips_env = (CPUMIPSState *)env;


switch(op) { switch(op) {
case TARGET_MIPS_SET_TLS: case TARGET_MIPS_SET_TLS:
if (get_user(mips_env->tls_value, parms, abi_ulong)) if (get_user(tmp, parms, abi_ulong))
ret = -TARGET_EFAULT; ret = -TARGET_EFAULT;
/* XXX temporary hack to work around FreeBSD 10 problem. */
if (0 == mips_env->tls_value && tmp != 1)
mips_env->tls_value = tmp;
break; break;
case TARGET_MIPS_GET_TLS: case TARGET_MIPS_GET_TLS:
if (put_user(mips_env->tls_value, parms, abi_ulong)) if (put_user(mips_env->tls_value, parms, abi_ulong))
Expand Down Expand Up @@ -386,6 +390,18 @@ static int sysctl_oldcvt(void *holdp, size_t holdlen, uint32_t kind)
return 0; return 0;
} }


/*
* Convert the undocmented name2oid sysctl data for the target.
*/
static inline void
sysctl_name2oid(uint32_t *holdp, size_t holdlen)
{
size_t i;

for(i = 0; i < holdlen; i++)
holdp[i] = tswap32(holdp[i]);
}

/* XXX this needs to be emulated on non-FreeBSD hosts... */ /* XXX this needs to be emulated on non-FreeBSD hosts... */
static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong oldp, static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong oldp,
abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen) abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen)
Expand All @@ -411,7 +427,8 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
oidfmt(snamep, namelen, NULL, &kind); oidfmt(snamep, namelen, NULL, &kind);


/* Handle some arch/emulator dependent sysctl()'s here. */ /* Handle some arch/emulator dependent sysctl()'s here. */
if (CTL_KERN == snamep[0]) { switch(snamep[0]) {
case CTL_KERN:
switch(snamep[1]) { switch(snamep[1]) {
case KERN_USRSTACK: case KERN_USRSTACK:
#if defined(TARGET_ARM) && HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32 #if defined(TARGET_ARM) && HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
Expand Down Expand Up @@ -440,11 +457,21 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
default: default:
break; break;
} }
break;

default:
break;
} }


ret = get_errno(sysctl(snamep, namelen, holdp, &holdlen, hnewp, newlen)); ret = get_errno(sysctl(snamep, namelen, holdp, &holdlen, hnewp, newlen));
if (!ret) if (!ret) {
sysctl_oldcvt(holdp, holdlen, kind); if (0 == snamep[0] && 3 == snamep[1]) {
/* Handle the undocumented name2oid special case. */
sysctl_name2oid(holdp, holdlen);
} else {
sysctl_oldcvt(holdp, holdlen, kind);
}
}


out: out:
put_user_ual(holdlen, oldlenp); put_user_ual(holdlen, oldlenp);
Expand Down

0 comments on commit a344a13

Please sign in to comment.