#include <linux/compat.h> //否则报compat_alloc_user_space找不到 //compact_ioctl中先对arg做些处理,然后直接调用ioctl即可
long compact_ioctl(struct file *file, unsigned int cmd, unsigned long arg){ compat_uptr_t karg[4]; unsigned long __user *ubuffer; if (copy_from_user((void *)karg, (void __user *)arg, 4 * sizeof(compat_uptr_t))) { printk("copy_from_user fail\n"); return -EFAULT; } ubuffer = compat_alloc_user_space(4 * sizeof(unsigned long)); if (!access_ok(VERIFY_WRITE, ubuffer, 4 * sizeof(unsigned long))) return -EFAULT; if (put_user(karg[0], &ubuffer[0]) || put_user(karg[1], &ubuffer[1]) || put_user(karg[2], &ubuffer[2]) || put_user(karg[3], &ubuffer[3])) { printk("put_user fail\n"); return -EFAULT; } return ioctl(file, cmd, (unsigned long)ubuffer); }