2 * 32bit -> 64bit ioctl helpers
3 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * This file registers the converters from 32-bit ioctls to 64-bit ones.
21 * The converter assumes that a 32-bit user-pointer can be casted by A(x)
22 * macro to a valid 64-bit pointer which is accessible via copy_from/to_user.
26 #ifndef __ALSA_IOCTL32_H
27 #define __ALSA_IOCTL32_H
29 #include <linux/compat.h>
31 #define COPY(x) (dst->x = src->x)
32 #define CPTR(x) (dst->x = compat_ptr(src->x))
34 #define convert_from_32(type, dstp, srcp)\
36 struct sndrv_##type *dst = dstp;\
37 struct sndrv_##type##32 *src = srcp;\
38 CVT_##sndrv_##type();\
41 #define convert_to_32(type, dstp, srcp)\
43 struct sndrv_##type *src = srcp;\
44 struct sndrv_##type##32 *dst = dstp;\
45 CVT_##sndrv_##type();\
49 #define DEFINE_ALSA_IOCTL(type) \
50 static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl)\
52 struct sndrv_##type##32 data32;\
53 struct sndrv_##type data;\
56 if (copy_from_user(&data32, (void __user *)arg, sizeof(data32)))\
58 memset(&data, 0, sizeof(data));\
59 convert_from_32(type, &data, &data32);\
62 err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)&data);\
66 if (native_ctl & (_IOC_READ << _IOC_DIRSHIFT)) {\
67 convert_to_32(type, &data32, &data);\
68 if (copy_to_user((void __user *)arg, &data32, sizeof(data32)))\
74 #define DEFINE_ALSA_IOCTL_BIG(type) \
75 static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl)\
77 struct sndrv_##type##32 *data32;\
78 struct sndrv_##type *data;\
81 data32 = kmalloc(sizeof(*data32), GFP_KERNEL); \
82 data = kmalloc(sizeof(*data), GFP_KERNEL); \
83 if (data32 == NULL || data == NULL) { \
87 if (copy_from_user(data32, (void __user *)arg, sizeof(*data32))) { \
91 memset(data, 0, sizeof(*data));\
92 convert_from_32(type, data, data32);\
95 err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)data);\
100 if (native_ctl & (_IOC_READ << _IOC_DIRSHIFT)) {\
101 convert_to_32(type, data32, data);\
102 if (copy_to_user((void __user *)arg, data32, sizeof(*data32)))\
113 #define DEFINE_ALSA_IOCTL_ENTRY(name,type,native_ctl) \
114 static int snd_ioctl32_##name(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file) {\
115 return _snd_ioctl32_##type(fd, cmd, arg, file, native_ctl);\
118 #define MAP_COMPAT(ctl) { ctl, snd_ioctl32_compat }
120 struct ioctl32_mapper
{
122 int (*handler
)(unsigned int, unsigned int, unsigned long, struct file
* filp
);
126 int snd_ioctl32_compat(unsigned int, unsigned int, unsigned long, struct file
*);
128 int snd_ioctl32_register(struct ioctl32_mapper
*mappers
);
129 void snd_ioctl32_unregister(struct ioctl32_mapper
*mappers
);
131 #endif /* __ALSA_IOCTL32_H */