mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:10 +00:00
bsd-user: Add init_bsd_ioctl function
Add initialization function that registers thunk structures and patches ioctl table entries with correct size parameters for target architecture. Signed-off-by: Stacey Son <sson@FreeBSD.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Signed-off-by: Warner Losh <imp@bsdimp.com>
This commit is contained in:
@@ -392,3 +392,45 @@ abi_long do_bsd_ioctl(int fd, abi_long cmd, abi_long arg)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void init_bsd_ioctl(void)
|
||||
{
|
||||
IOCTLEntry *ie;
|
||||
const argtype *arg_type;
|
||||
int size;
|
||||
|
||||
thunk_init(STRUCT_MAX);
|
||||
|
||||
#define STRUCT(name, ...) \
|
||||
thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
|
||||
#define STRUCT_SPECIAL(name) \
|
||||
thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
|
||||
#include "os-ioctl-types.h"
|
||||
#undef STRUCT
|
||||
#undef STRUCT_SPECIAL
|
||||
|
||||
/*
|
||||
* Patch the ioctl size if necessary using the fact that no
|
||||
* ioctl has all the bits at '1' in the size field
|
||||
* (IOCPARM_MAX - 1).
|
||||
*/
|
||||
ie = ioctl_entries;
|
||||
while (ie->target_cmd != 0) {
|
||||
if (((ie->target_cmd >> TARGET_IOCPARM_SHIFT) &
|
||||
TARGET_IOCPARM_MASK) == TARGET_IOCPARM_MASK) {
|
||||
arg_type = ie->arg_type;
|
||||
if (arg_type[0] != TYPE_PTR) {
|
||||
fprintf(stderr, "cannot patch size for ioctl 0x%x\n",
|
||||
ie->target_cmd);
|
||||
exit(1);
|
||||
}
|
||||
arg_type++;
|
||||
size = thunk_type_size(arg_type, 0);
|
||||
ie->target_cmd = (ie->target_cmd &
|
||||
~(TARGET_IOCPARM_MASK << TARGET_IOCPARM_SHIFT)) |
|
||||
(size << TARGET_IOCPARM_SHIFT);
|
||||
}
|
||||
ie++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user