[POWERPC] Add Makefile rules to wrap dts file in zImage
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / compat.c
blob9a0f5f2b90c80653acbe2282d3820e8502307429
1 /*
2 * 32bit Socket syscall emulation. Based on arch/sparc64/kernel/sys_sparc32.c.
4 * Copyright (C) 2000 VA Linux Co
5 * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
6 * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
7 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
8 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
9 * Copyright (C) 2000 Hewlett-Packard Co.
10 * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
11 * Copyright (C) 2000,2001 Andi Kleen, SuSE Labs
14 #include <linux/kernel.h>
15 #include <linux/fs.h>
16 #include <linux/types.h>
17 #include <linux/file.h>
18 #include <linux/icmpv6.h>
19 #include <linux/socket.h>
20 #include <linux/syscalls.h>
21 #include <linux/filter.h>
22 #include <linux/compat.h>
23 #include <linux/netfilter_ipv4/ip_tables.h>
24 #include <linux/security.h>
26 #include <net/scm.h>
27 #include <net/sock.h>
28 #include <asm/uaccess.h>
29 #include <net/compat.h>
31 static inline int iov_from_user_compat_to_kern(struct iovec *kiov,
32 struct compat_iovec __user *uiov32,
33 int niov)
35 int tot_len = 0;
37 while (niov > 0) {
38 compat_uptr_t buf;
39 compat_size_t len;
41 if (get_user(len, &uiov32->iov_len) ||
42 get_user(buf, &uiov32->iov_base)) {
43 tot_len = -EFAULT;
44 break;
46 tot_len += len;
47 kiov->iov_base = compat_ptr(buf);
48 kiov->iov_len = (__kernel_size_t) len;
49 uiov32++;
50 kiov++;
51 niov--;
53 return tot_len;
56 int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
58 compat_uptr_t tmp1, tmp2, tmp3;
60 if (!access_ok(VERIFY_READ, umsg, sizeof(*umsg)) ||
61 __get_user(tmp1, &umsg->msg_name) ||
62 __get_user(kmsg->msg_namelen, &umsg->msg_namelen) ||
63 __get_user(tmp2, &umsg->msg_iov) ||
64 __get_user(kmsg->msg_iovlen, &umsg->msg_iovlen) ||
65 __get_user(tmp3, &umsg->msg_control) ||
66 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
67 __get_user(kmsg->msg_flags, &umsg->msg_flags))
68 return -EFAULT;
69 kmsg->msg_name = compat_ptr(tmp1);
70 kmsg->msg_iov = compat_ptr(tmp2);
71 kmsg->msg_control = compat_ptr(tmp3);
72 return 0;
75 /* I've named the args so it is easy to tell whose space the pointers are in. */
76 int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
77 char *kern_address, int mode)
79 int tot_len;
81 if (kern_msg->msg_namelen) {
82 if (mode==VERIFY_READ) {
83 int err = move_addr_to_kernel(kern_msg->msg_name,
84 kern_msg->msg_namelen,
85 kern_address);
86 if (err < 0)
87 return err;
89 kern_msg->msg_name = kern_address;
90 } else
91 kern_msg->msg_name = NULL;
93 tot_len = iov_from_user_compat_to_kern(kern_iov,
94 (struct compat_iovec __user *)kern_msg->msg_iov,
95 kern_msg->msg_iovlen);
96 if (tot_len >= 0)
97 kern_msg->msg_iov = kern_iov;
99 return tot_len;
102 /* Bleech... */
103 #define CMSG_COMPAT_ALIGN(len) ALIGN((len), sizeof(s32))
105 #define CMSG_COMPAT_DATA(cmsg) \
106 ((void __user *)((char __user *)(cmsg) + CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))))
107 #define CMSG_COMPAT_SPACE(len) \
108 (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + CMSG_COMPAT_ALIGN(len))
109 #define CMSG_COMPAT_LEN(len) \
110 (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + (len))
112 #define CMSG_COMPAT_FIRSTHDR(msg) \
113 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
114 (struct compat_cmsghdr __user *)((msg)->msg_control) : \
115 (struct compat_cmsghdr __user *)NULL)
117 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
118 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
119 (ucmlen) <= (unsigned long) \
120 ((mhdr)->msg_controllen - \
121 ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
123 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
124 struct compat_cmsghdr __user *cmsg, int cmsg_len)
126 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
127 if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
128 msg->msg_controllen)
129 return NULL;
130 return (struct compat_cmsghdr __user *)ptr;
133 /* There is a lot of hair here because the alignment rules (and
134 * thus placement) of cmsg headers and length are different for
135 * 32-bit apps. -DaveM
137 int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk,
138 unsigned char *stackbuf, int stackbuf_size)
140 struct compat_cmsghdr __user *ucmsg;
141 struct cmsghdr *kcmsg, *kcmsg_base;
142 compat_size_t ucmlen;
143 __kernel_size_t kcmlen, tmp;
144 int err = -EFAULT;
146 kcmlen = 0;
147 kcmsg_base = kcmsg = (struct cmsghdr *)stackbuf;
148 ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
149 while (ucmsg != NULL) {
150 if (get_user(ucmlen, &ucmsg->cmsg_len))
151 return -EFAULT;
153 /* Catch bogons. */
154 if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg))
155 return -EINVAL;
157 tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) +
158 CMSG_ALIGN(sizeof(struct cmsghdr)));
159 tmp = CMSG_ALIGN(tmp);
160 kcmlen += tmp;
161 ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen);
163 if (kcmlen == 0)
164 return -EINVAL;
166 /* The kcmlen holds the 64-bit version of the control length.
167 * It may not be modified as we do not stick it into the kmsg
168 * until we have successfully copied over all of the data
169 * from the user.
171 if (kcmlen > stackbuf_size)
172 kcmsg_base = kcmsg = sock_kmalloc(sk, kcmlen, GFP_KERNEL);
173 if (kcmsg == NULL)
174 return -ENOBUFS;
176 /* Now copy them over neatly. */
177 memset(kcmsg, 0, kcmlen);
178 ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
179 while (ucmsg != NULL) {
180 if (__get_user(ucmlen, &ucmsg->cmsg_len))
181 goto Efault;
182 if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg))
183 goto Einval;
184 tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) +
185 CMSG_ALIGN(sizeof(struct cmsghdr)));
186 if ((char *)kcmsg_base + kcmlen - (char *)kcmsg < CMSG_ALIGN(tmp))
187 goto Einval;
188 kcmsg->cmsg_len = tmp;
189 tmp = CMSG_ALIGN(tmp);
190 if (__get_user(kcmsg->cmsg_level, &ucmsg->cmsg_level) ||
191 __get_user(kcmsg->cmsg_type, &ucmsg->cmsg_type) ||
192 copy_from_user(CMSG_DATA(kcmsg),
193 CMSG_COMPAT_DATA(ucmsg),
194 (ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg)))))
195 goto Efault;
197 /* Advance. */
198 kcmsg = (struct cmsghdr *)((char *)kcmsg + tmp);
199 ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen);
202 /* Ok, looks like we made it. Hook it up and return success. */
203 kmsg->msg_control = kcmsg_base;
204 kmsg->msg_controllen = kcmlen;
205 return 0;
207 Einval:
208 err = -EINVAL;
209 Efault:
210 if (kcmsg_base != (struct cmsghdr *)stackbuf)
211 sock_kfree_s(sk, kcmsg_base, kcmlen);
212 return err;
215 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
217 struct compat_timeval ctv;
218 struct compat_timespec cts;
219 struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
220 struct compat_cmsghdr cmhdr;
221 int cmlen;
223 if (cm == NULL || kmsg->msg_controllen < sizeof(*cm)) {
224 kmsg->msg_flags |= MSG_CTRUNC;
225 return 0; /* XXX: return error? check spec. */
228 if (level == SOL_SOCKET && type == SO_TIMESTAMP) {
229 struct timeval *tv = (struct timeval *)data;
230 ctv.tv_sec = tv->tv_sec;
231 ctv.tv_usec = tv->tv_usec;
232 data = &ctv;
233 len = sizeof(ctv);
235 if (level == SOL_SOCKET && type == SO_TIMESTAMPNS) {
236 struct timespec *ts = (struct timespec *)data;
237 cts.tv_sec = ts->tv_sec;
238 cts.tv_nsec = ts->tv_nsec;
239 data = &cts;
240 len = sizeof(cts);
243 cmlen = CMSG_COMPAT_LEN(len);
244 if (kmsg->msg_controllen < cmlen) {
245 kmsg->msg_flags |= MSG_CTRUNC;
246 cmlen = kmsg->msg_controllen;
248 cmhdr.cmsg_level = level;
249 cmhdr.cmsg_type = type;
250 cmhdr.cmsg_len = cmlen;
252 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
253 return -EFAULT;
254 if (copy_to_user(CMSG_COMPAT_DATA(cm), data, cmlen - sizeof(struct compat_cmsghdr)))
255 return -EFAULT;
256 cmlen = CMSG_COMPAT_SPACE(len);
257 kmsg->msg_control += cmlen;
258 kmsg->msg_controllen -= cmlen;
259 return 0;
262 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
264 struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
265 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
266 int fdnum = scm->fp->count;
267 struct file **fp = scm->fp->fp;
268 int __user *cmfptr;
269 int err = 0, i;
271 if (fdnum < fdmax)
272 fdmax = fdnum;
274 for (i = 0, cmfptr = (int __user *) CMSG_COMPAT_DATA(cm); i < fdmax; i++, cmfptr++) {
275 int new_fd;
276 err = security_file_receive(fp[i]);
277 if (err)
278 break;
279 err = get_unused_fd();
280 if (err < 0)
281 break;
282 new_fd = err;
283 err = put_user(new_fd, cmfptr);
284 if (err) {
285 put_unused_fd(new_fd);
286 break;
288 /* Bump the usage count and install the file. */
289 get_file(fp[i]);
290 fd_install(new_fd, fp[i]);
293 if (i > 0) {
294 int cmlen = CMSG_COMPAT_LEN(i * sizeof(int));
295 err = put_user(SOL_SOCKET, &cm->cmsg_level);
296 if (!err)
297 err = put_user(SCM_RIGHTS, &cm->cmsg_type);
298 if (!err)
299 err = put_user(cmlen, &cm->cmsg_len);
300 if (!err) {
301 cmlen = CMSG_COMPAT_SPACE(i * sizeof(int));
302 kmsg->msg_control += cmlen;
303 kmsg->msg_controllen -= cmlen;
306 if (i < fdnum)
307 kmsg->msg_flags |= MSG_CTRUNC;
310 * All of the files that fit in the message have had their
311 * usage counts incremented, so we just free the list.
313 __scm_destroy(scm);
317 * For now, we assume that the compatibility and native version
318 * of struct ipt_entry are the same - sfr. FIXME
320 struct compat_ipt_replace {
321 char name[IPT_TABLE_MAXNAMELEN];
322 u32 valid_hooks;
323 u32 num_entries;
324 u32 size;
325 u32 hook_entry[NF_IP_NUMHOOKS];
326 u32 underflow[NF_IP_NUMHOOKS];
327 u32 num_counters;
328 compat_uptr_t counters; /* struct ipt_counters * */
329 struct ipt_entry entries[0];
332 static int do_netfilter_replace(int fd, int level, int optname,
333 char __user *optval, int optlen)
335 struct compat_ipt_replace __user *urepl;
336 struct ipt_replace __user *repl_nat;
337 char name[IPT_TABLE_MAXNAMELEN];
338 u32 origsize, tmp32, num_counters;
339 unsigned int repl_nat_size;
340 int ret;
341 int i;
342 compat_uptr_t ucntrs;
344 urepl = (struct compat_ipt_replace __user *)optval;
345 if (get_user(origsize, &urepl->size))
346 return -EFAULT;
348 /* Hack: Causes ipchains to give correct error msg --RR */
349 if (optlen != sizeof(*urepl) + origsize)
350 return -ENOPROTOOPT;
352 /* XXX Assumes that size of ipt_entry is the same both in
353 * native and compat environments.
355 repl_nat_size = sizeof(*repl_nat) + origsize;
356 repl_nat = compat_alloc_user_space(repl_nat_size);
358 ret = -EFAULT;
359 if (put_user(origsize, &repl_nat->size))
360 goto out;
362 if (!access_ok(VERIFY_READ, urepl, optlen) ||
363 !access_ok(VERIFY_WRITE, repl_nat, optlen))
364 goto out;
366 if (__copy_from_user(name, urepl->name, sizeof(urepl->name)) ||
367 __copy_to_user(repl_nat->name, name, sizeof(repl_nat->name)))
368 goto out;
370 if (__get_user(tmp32, &urepl->valid_hooks) ||
371 __put_user(tmp32, &repl_nat->valid_hooks))
372 goto out;
374 if (__get_user(tmp32, &urepl->num_entries) ||
375 __put_user(tmp32, &repl_nat->num_entries))
376 goto out;
378 if (__get_user(num_counters, &urepl->num_counters) ||
379 __put_user(num_counters, &repl_nat->num_counters))
380 goto out;
382 if (__get_user(ucntrs, &urepl->counters) ||
383 __put_user(compat_ptr(ucntrs), &repl_nat->counters))
384 goto out;
386 if (__copy_in_user(&repl_nat->entries[0],
387 &urepl->entries[0],
388 origsize))
389 goto out;
391 for (i = 0; i < NF_IP_NUMHOOKS; i++) {
392 if (__get_user(tmp32, &urepl->hook_entry[i]) ||
393 __put_user(tmp32, &repl_nat->hook_entry[i]) ||
394 __get_user(tmp32, &urepl->underflow[i]) ||
395 __put_user(tmp32, &repl_nat->underflow[i]))
396 goto out;
400 * Since struct ipt_counters just contains two u_int64_t members
401 * we can just do the access_ok check here and pass the (converted)
402 * pointer into the standard syscall. We hope that the pointer is
403 * not misaligned ...
405 if (!access_ok(VERIFY_WRITE, compat_ptr(ucntrs),
406 num_counters * sizeof(struct ipt_counters)))
407 goto out;
410 ret = sys_setsockopt(fd, level, optname,
411 (char __user *)repl_nat, repl_nat_size);
413 out:
414 return ret;
418 * A struct sock_filter is architecture independent.
420 struct compat_sock_fprog {
421 u16 len;
422 compat_uptr_t filter; /* struct sock_filter * */
425 static int do_set_attach_filter(struct socket *sock, int level, int optname,
426 char __user *optval, int optlen)
428 struct compat_sock_fprog __user *fprog32 = (struct compat_sock_fprog __user *)optval;
429 struct sock_fprog __user *kfprog = compat_alloc_user_space(sizeof(struct sock_fprog));
430 compat_uptr_t ptr;
431 u16 len;
433 if (!access_ok(VERIFY_READ, fprog32, sizeof(*fprog32)) ||
434 !access_ok(VERIFY_WRITE, kfprog, sizeof(struct sock_fprog)) ||
435 __get_user(len, &fprog32->len) ||
436 __get_user(ptr, &fprog32->filter) ||
437 __put_user(len, &kfprog->len) ||
438 __put_user(compat_ptr(ptr), &kfprog->filter))
439 return -EFAULT;
441 return sock_setsockopt(sock, level, optname, (char __user *)kfprog,
442 sizeof(struct sock_fprog));
445 static int do_set_sock_timeout(struct socket *sock, int level,
446 int optname, char __user *optval, int optlen)
448 struct compat_timeval __user *up = (struct compat_timeval __user *) optval;
449 struct timeval ktime;
450 mm_segment_t old_fs;
451 int err;
453 if (optlen < sizeof(*up))
454 return -EINVAL;
455 if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
456 __get_user(ktime.tv_sec, &up->tv_sec) ||
457 __get_user(ktime.tv_usec, &up->tv_usec))
458 return -EFAULT;
459 old_fs = get_fs();
460 set_fs(KERNEL_DS);
461 err = sock_setsockopt(sock, level, optname, (char *) &ktime, sizeof(ktime));
462 set_fs(old_fs);
464 return err;
467 static int compat_sock_setsockopt(struct socket *sock, int level, int optname,
468 char __user *optval, int optlen)
470 if (optname == SO_ATTACH_FILTER)
471 return do_set_attach_filter(sock, level, optname,
472 optval, optlen);
473 if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
474 return do_set_sock_timeout(sock, level, optname, optval, optlen);
476 return sock_setsockopt(sock, level, optname, optval, optlen);
479 asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
480 char __user *optval, int optlen)
482 int err;
483 struct socket *sock;
485 if (level == SOL_IPV6 && optname == IPT_SO_SET_REPLACE)
486 return do_netfilter_replace(fd, level, optname,
487 optval, optlen);
489 if (optlen < 0)
490 return -EINVAL;
492 if ((sock = sockfd_lookup(fd, &err))!=NULL)
494 err = security_socket_setsockopt(sock,level,optname);
495 if (err) {
496 sockfd_put(sock);
497 return err;
500 if (level == SOL_SOCKET)
501 err = compat_sock_setsockopt(sock, level,
502 optname, optval, optlen);
503 else if (sock->ops->compat_setsockopt)
504 err = sock->ops->compat_setsockopt(sock, level,
505 optname, optval, optlen);
506 else
507 err = sock->ops->setsockopt(sock, level,
508 optname, optval, optlen);
509 sockfd_put(sock);
511 return err;
514 static int do_get_sock_timeout(struct socket *sock, int level, int optname,
515 char __user *optval, int __user *optlen)
517 struct compat_timeval __user *up;
518 struct timeval ktime;
519 mm_segment_t old_fs;
520 int len, err;
522 up = (struct compat_timeval __user *) optval;
523 if (get_user(len, optlen))
524 return -EFAULT;
525 if (len < sizeof(*up))
526 return -EINVAL;
527 len = sizeof(ktime);
528 old_fs = get_fs();
529 set_fs(KERNEL_DS);
530 err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
531 set_fs(old_fs);
533 if (!err) {
534 if (put_user(sizeof(*up), optlen) ||
535 !access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
536 __put_user(ktime.tv_sec, &up->tv_sec) ||
537 __put_user(ktime.tv_usec, &up->tv_usec))
538 err = -EFAULT;
540 return err;
543 static int compat_sock_getsockopt(struct socket *sock, int level, int optname,
544 char __user *optval, int __user *optlen)
546 if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
547 return do_get_sock_timeout(sock, level, optname, optval, optlen);
548 return sock_getsockopt(sock, level, optname, optval, optlen);
551 int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
553 struct compat_timeval __user *ctv =
554 (struct compat_timeval __user*) userstamp;
555 int err = -ENOENT;
556 struct timeval tv;
558 if (!sock_flag(sk, SOCK_TIMESTAMP))
559 sock_enable_timestamp(sk);
560 tv = ktime_to_timeval(sk->sk_stamp);
561 if (tv.tv_sec == -1)
562 return err;
563 if (tv.tv_sec == 0) {
564 sk->sk_stamp = ktime_get_real();
565 tv = ktime_to_timeval(sk->sk_stamp);
567 err = 0;
568 if (put_user(tv.tv_sec, &ctv->tv_sec) ||
569 put_user(tv.tv_usec, &ctv->tv_usec))
570 err = -EFAULT;
571 return err;
573 EXPORT_SYMBOL(compat_sock_get_timestamp);
575 int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp)
577 struct compat_timespec __user *ctv =
578 (struct compat_timespec __user*) userstamp;
579 int err = -ENOENT;
580 struct timespec ts;
582 if (!sock_flag(sk, SOCK_TIMESTAMP))
583 sock_enable_timestamp(sk);
584 ts = ktime_to_timespec(sk->sk_stamp);
585 if (ts.tv_sec == -1)
586 return err;
587 if (ts.tv_sec == 0) {
588 sk->sk_stamp = ktime_get_real();
589 ts = ktime_to_timespec(sk->sk_stamp);
591 err = 0;
592 if (put_user(ts.tv_sec, &ctv->tv_sec) ||
593 put_user(ts.tv_nsec, &ctv->tv_nsec))
594 err = -EFAULT;
595 return err;
597 EXPORT_SYMBOL(compat_sock_get_timestampns);
599 asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,
600 char __user *optval, int __user *optlen)
602 int err;
603 struct socket *sock;
605 if ((sock = sockfd_lookup(fd, &err))!=NULL)
607 err = security_socket_getsockopt(sock, level,
608 optname);
609 if (err) {
610 sockfd_put(sock);
611 return err;
614 if (level == SOL_SOCKET)
615 err = compat_sock_getsockopt(sock, level,
616 optname, optval, optlen);
617 else if (sock->ops->compat_getsockopt)
618 err = sock->ops->compat_getsockopt(sock, level,
619 optname, optval, optlen);
620 else
621 err = sock->ops->getsockopt(sock, level,
622 optname, optval, optlen);
623 sockfd_put(sock);
625 return err;
627 /* Argument list sizes for compat_sys_socketcall */
628 #define AL(x) ((x) * sizeof(u32))
629 static unsigned char nas[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
630 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
631 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)};
632 #undef AL
634 asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned flags)
636 return sys_sendmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
639 asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg, unsigned int flags)
641 return sys_recvmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
644 asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
646 int ret;
647 u32 a[6];
648 u32 a0, a1;
650 if (call < SYS_SOCKET || call > SYS_RECVMSG)
651 return -EINVAL;
652 if (copy_from_user(a, args, nas[call]))
653 return -EFAULT;
654 a0 = a[0];
655 a1 = a[1];
657 switch (call) {
658 case SYS_SOCKET:
659 ret = sys_socket(a0, a1, a[2]);
660 break;
661 case SYS_BIND:
662 ret = sys_bind(a0, compat_ptr(a1), a[2]);
663 break;
664 case SYS_CONNECT:
665 ret = sys_connect(a0, compat_ptr(a1), a[2]);
666 break;
667 case SYS_LISTEN:
668 ret = sys_listen(a0, a1);
669 break;
670 case SYS_ACCEPT:
671 ret = sys_accept(a0, compat_ptr(a1), compat_ptr(a[2]));
672 break;
673 case SYS_GETSOCKNAME:
674 ret = sys_getsockname(a0, compat_ptr(a1), compat_ptr(a[2]));
675 break;
676 case SYS_GETPEERNAME:
677 ret = sys_getpeername(a0, compat_ptr(a1), compat_ptr(a[2]));
678 break;
679 case SYS_SOCKETPAIR:
680 ret = sys_socketpair(a0, a1, a[2], compat_ptr(a[3]));
681 break;
682 case SYS_SEND:
683 ret = sys_send(a0, compat_ptr(a1), a[2], a[3]);
684 break;
685 case SYS_SENDTO:
686 ret = sys_sendto(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), a[5]);
687 break;
688 case SYS_RECV:
689 ret = sys_recv(a0, compat_ptr(a1), a[2], a[3]);
690 break;
691 case SYS_RECVFROM:
692 ret = sys_recvfrom(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), compat_ptr(a[5]));
693 break;
694 case SYS_SHUTDOWN:
695 ret = sys_shutdown(a0,a1);
696 break;
697 case SYS_SETSOCKOPT:
698 ret = compat_sys_setsockopt(a0, a1, a[2],
699 compat_ptr(a[3]), a[4]);
700 break;
701 case SYS_GETSOCKOPT:
702 ret = compat_sys_getsockopt(a0, a1, a[2],
703 compat_ptr(a[3]), compat_ptr(a[4]));
704 break;
705 case SYS_SENDMSG:
706 ret = compat_sys_sendmsg(a0, compat_ptr(a1), a[2]);
707 break;
708 case SYS_RECVMSG:
709 ret = compat_sys_recvmsg(a0, compat_ptr(a1), a[2]);
710 break;
711 default:
712 ret = -EINVAL;
713 break;
715 return ret;