linux_socket.c (132347) | linux_socket.c (133816) |
---|---|
1/*- 2 * Copyright (c) 1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_socket.c 132347 2004-07-18 09:26:34Z dwmalone $"); | 30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_socket.c 133816 2004-08-16 07:28:16Z tjr $"); |
31 32/* XXX we use functions that might not exist. */ 33#include "opt_compat.h" 34#include "opt_inet6.h" 35 36#ifndef COMPAT_43 37#error "Unable to compile Linux-emulator due to missing COMPAT_43 option!" 38#endif --- 16 unchanged lines hidden (view full) --- 55#include <netinet/in.h> 56#include <netinet/in_systm.h> 57#include <netinet/ip.h> 58#ifdef INET6 59#include <netinet/ip6.h> 60#include <netinet6/ip6_var.h> 61#endif 62 | 31 32/* XXX we use functions that might not exist. */ 33#include "opt_compat.h" 34#include "opt_inet6.h" 35 36#ifndef COMPAT_43 37#error "Unable to compile Linux-emulator due to missing COMPAT_43 option!" 38#endif --- 16 unchanged lines hidden (view full) --- 55#include <netinet/in.h> 56#include <netinet/in_systm.h> 57#include <netinet/ip.h> 58#ifdef INET6 59#include <netinet/ip6.h> 60#include <netinet6/ip6_var.h> 61#endif 62 |
63#include "opt_compat.h" 64 65#if !COMPAT_LINUX32 |
|
63#include <machine/../linux/linux.h> 64#include <machine/../linux/linux_proto.h> | 66#include <machine/../linux/linux.h> 67#include <machine/../linux/linux_proto.h> |
68#else 69#include <machine/../linux32/linux.h> 70#include <machine/../linux32/linux32_proto.h> 71#endif |
|
65#include <compat/linux/linux_socket.h> 66#include <compat/linux/linux_util.h> 67 68static int do_sa_get(struct sockaddr **, const struct osockaddr *, int *, 69 struct malloc_type *); 70static int linux_to_bsd_domain(int); 71 72/* --- 339 unchanged lines hidden (view full) --- 412 if (error) 413 return (error); 414 415 return (optval == 0); 416} 417 418struct linux_sendto_args { 419 int s; | 72#include <compat/linux/linux_socket.h> 73#include <compat/linux/linux_util.h> 74 75static int do_sa_get(struct sockaddr **, const struct osockaddr *, int *, 76 struct malloc_type *); 77static int linux_to_bsd_domain(int); 78 79/* --- 339 unchanged lines hidden (view full) --- 419 if (error) 420 return (error); 421 422 return (optval == 0); 423} 424 425struct linux_sendto_args { 426 int s; |
420 void *msg; | 427 l_uintptr_t msg; |
421 int len; 422 int flags; | 428 int len; 429 int flags; |
423 caddr_t to; | 430 l_uintptr_t to; |
424 int tolen; 425}; 426 427/* 428 * Updated sendto() when IP_HDRINCL is set: 429 * tweak endian-dependent fields in the IP packet. 430 */ 431static int --- 21 unchanged lines hidden (view full) --- 453 * Tweaking the user buffer in place would be bad manners. 454 * We create a corrected IP header with just the needed length, 455 * then use an iovec to glue it to the rest of the user packet 456 * when calling sendit(). 457 */ 458 packet = (struct ip *)stackgap_alloc(&sg, linux_ip_copysize); 459 460 /* Make a copy of the beginning of the packet to be sent */ | 431 int tolen; 432}; 433 434/* 435 * Updated sendto() when IP_HDRINCL is set: 436 * tweak endian-dependent fields in the IP packet. 437 */ 438static int --- 21 unchanged lines hidden (view full) --- 460 * Tweaking the user buffer in place would be bad manners. 461 * We create a corrected IP header with just the needed length, 462 * then use an iovec to glue it to the rest of the user packet 463 * when calling sendit(). 464 */ 465 packet = (struct ip *)stackgap_alloc(&sg, linux_ip_copysize); 466 467 /* Make a copy of the beginning of the packet to be sent */ |
461 if ((error = copyin(linux_args->msg, packet, linux_ip_copysize))) | 468 if ((error = copyin(PTRIN(linux_args->msg), packet, 469 linux_ip_copysize))) |
462 return (error); 463 464 /* Convert fields from Linux to BSD raw IP socket format */ 465 packet->ip_len = linux_args->len; 466 packet->ip_off = ntohs(packet->ip_off); 467 468 /* Prepare the msghdr and iovec structures describing the new packet */ | 470 return (error); 471 472 /* Convert fields from Linux to BSD raw IP socket format */ 473 packet->ip_len = linux_args->len; 474 packet->ip_off = ntohs(packet->ip_off); 475 476 /* Prepare the msghdr and iovec structures describing the new packet */ |
469 msg.msg_name = linux_args->to; | 477 msg.msg_name = PTRIN(linux_args->to); |
470 msg.msg_namelen = linux_args->tolen; 471 msg.msg_iov = aiov; 472 msg.msg_iovlen = 2; 473 msg.msg_control = NULL; 474 msg.msg_flags = 0; 475 aiov[0].iov_base = (char *)packet; 476 aiov[0].iov_len = linux_ip_copysize; | 478 msg.msg_namelen = linux_args->tolen; 479 msg.msg_iov = aiov; 480 msg.msg_iovlen = 2; 481 msg.msg_control = NULL; 482 msg.msg_flags = 0; 483 aiov[0].iov_base = (char *)packet; 484 aiov[0].iov_len = linux_ip_copysize; |
477 aiov[1].iov_base = (char *)(linux_args->msg) + linux_ip_copysize; | 485 aiov[1].iov_base = (char *)PTRIN(linux_args->msg) + 486 linux_ip_copysize; |
478 aiov[1].iov_len = linux_args->len - linux_ip_copysize; 479 error = linux_sendit(td, linux_args->s, &msg, linux_args->flags); 480 return (error); 481} 482 483struct linux_socket_args { 484 int domain; 485 int type; --- 58 unchanged lines hidden (view full) --- 544 } 545#endif 546 547 return (retval_socket); 548} 549 550struct linux_bind_args { 551 int s; | 487 aiov[1].iov_len = linux_args->len - linux_ip_copysize; 488 error = linux_sendit(td, linux_args->s, &msg, linux_args->flags); 489 return (error); 490} 491 492struct linux_socket_args { 493 int domain; 494 int type; --- 58 unchanged lines hidden (view full) --- 553 } 554#endif 555 556 return (retval_socket); 557} 558 559struct linux_bind_args { 560 int s; |
552 struct osockaddr *name; | 561 l_uintptr_t name; |
553 int namelen; 554}; 555 556static int 557linux_bind(struct thread *td, struct linux_bind_args *args) 558{ 559 struct linux_bind_args linux_args; 560 struct sockaddr *sa; 561 int error; 562 563 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 564 return (error); 565 | 562 int namelen; 563}; 564 565static int 566linux_bind(struct thread *td, struct linux_bind_args *args) 567{ 568 struct linux_bind_args linux_args; 569 struct sockaddr *sa; 570 int error; 571 572 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 573 return (error); 574 |
566 error = linux_getsockaddr(&sa, linux_args.name, linux_args.namelen); | 575 error = linux_getsockaddr(&sa, PTRIN(linux_args.name), 576 linux_args.namelen); |
567 if (error) 568 return (error); 569 570 return (kern_bind(td, linux_args.s, sa)); 571} 572 573struct linux_connect_args { 574 int s; | 577 if (error) 578 return (error); 579 580 return (kern_bind(td, linux_args.s, sa)); 581} 582 583struct linux_connect_args { 584 int s; |
575 struct osockaddr * name; | 585 l_uintptr_t name; |
576 int namelen; 577}; 578int linux_connect(struct thread *, struct linux_connect_args *); 579#endif /* !__alpha__*/ 580 581int 582linux_connect(struct thread *td, struct linux_connect_args *args) 583{ --- 5 unchanged lines hidden (view full) --- 589 590#ifdef __alpha__ 591 bcopy(args, &linux_args, sizeof(linux_args)); 592#else 593 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 594 return (error); 595#endif /* __alpha__ */ 596 | 586 int namelen; 587}; 588int linux_connect(struct thread *, struct linux_connect_args *); 589#endif /* !__alpha__*/ 590 591int 592linux_connect(struct thread *td, struct linux_connect_args *args) 593{ --- 5 unchanged lines hidden (view full) --- 599 600#ifdef __alpha__ 601 bcopy(args, &linux_args, sizeof(linux_args)); 602#else 603 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 604 return (error); 605#endif /* __alpha__ */ 606 |
597 error = linux_getsockaddr(&sa, (struct osockaddr *)linux_args.name, | 607 error = linux_getsockaddr(&sa, 608 (struct osockaddr *)PTRIN(linux_args.name), |
598 linux_args.namelen); 599 if (error) 600 return (error); 601 602 error = kern_connect(td, linux_args.s, sa); 603 if (error != EISCONN) 604 return (error); 605 --- 36 unchanged lines hidden (view full) --- 642 643 bsd_args.s = linux_args.s; 644 bsd_args.backlog = linux_args.backlog; 645 return (listen(td, &bsd_args)); 646} 647 648struct linux_accept_args { 649 int s; | 609 linux_args.namelen); 610 if (error) 611 return (error); 612 613 error = kern_connect(td, linux_args.s, sa); 614 if (error != EISCONN) 615 return (error); 616 --- 36 unchanged lines hidden (view full) --- 653 654 bsd_args.s = linux_args.s; 655 bsd_args.backlog = linux_args.backlog; 656 return (listen(td, &bsd_args)); 657} 658 659struct linux_accept_args { 660 int s; |
650 struct osockaddr *addr; 651 int *namelen; | 661 l_uintptr_t addr; 662 l_uintptr_t namelen; |
652}; 653 654static int 655linux_accept(struct thread *td, struct linux_accept_args *args) 656{ 657 struct linux_accept_args linux_args; 658 struct accept_args /* { 659 int s; --- 10 unchanged lines hidden (view full) --- 670 } */ f_args; 671 int error; 672 673 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 674 return (error); 675 676 bsd_args.s = linux_args.s; 677 /* XXX: */ | 663}; 664 665static int 666linux_accept(struct thread *td, struct linux_accept_args *args) 667{ 668 struct linux_accept_args linux_args; 669 struct accept_args /* { 670 int s; --- 10 unchanged lines hidden (view full) --- 681 } */ f_args; 682 int error; 683 684 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 685 return (error); 686 687 bsd_args.s = linux_args.s; 688 /* XXX: */ |
678 bsd_args.name = (struct sockaddr * __restrict)linux_args.addr; 679 bsd_args.anamelen = linux_args.namelen; /* XXX */ | 689 bsd_args.name = (struct sockaddr * __restrict)PTRIN(linux_args.addr); 690 bsd_args.anamelen = PTRIN(linux_args.namelen);/* XXX */ |
680 error = oaccept(td, &bsd_args); 681 if (error) 682 return (error); 683 if (linux_args.addr) { | 691 error = oaccept(td, &bsd_args); 692 if (error) 693 return (error); 694 if (linux_args.addr) { |
684 error = linux_sa_put(linux_args.addr); | 695 error = linux_sa_put(PTRIN(linux_args.addr)); |
685 if (error) { 686 c_args.fd = td->td_retval[0]; 687 (void)close(td, &c_args); 688 return (error); 689 } 690 } 691 692 /* --- 6 unchanged lines hidden (view full) --- 699 f_args.arg = 0; 700 (void)fcntl(td, &f_args); 701 td->td_retval[0] = f_args.fd; 702 return (0); 703} 704 705struct linux_getsockname_args { 706 int s; | 696 if (error) { 697 c_args.fd = td->td_retval[0]; 698 (void)close(td, &c_args); 699 return (error); 700 } 701 } 702 703 /* --- 6 unchanged lines hidden (view full) --- 710 f_args.arg = 0; 711 (void)fcntl(td, &f_args); 712 td->td_retval[0] = f_args.fd; 713 return (0); 714} 715 716struct linux_getsockname_args { 717 int s; |
707 struct osockaddr *addr; 708 int *namelen; | 718 l_uintptr_t addr; 719 l_uintptr_t namelen; |
709}; 710 711static int 712linux_getsockname(struct thread *td, struct linux_getsockname_args *args) 713{ 714 struct linux_getsockname_args linux_args; 715 struct getsockname_args /* { 716 int fdes; 717 struct sockaddr * __restrict asa; 718 socklen_t * __restrict alen; 719 } */ bsd_args; 720 int error; 721 722 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 723 return (error); 724 725 bsd_args.fdes = linux_args.s; 726 /* XXX: */ | 720}; 721 722static int 723linux_getsockname(struct thread *td, struct linux_getsockname_args *args) 724{ 725 struct linux_getsockname_args linux_args; 726 struct getsockname_args /* { 727 int fdes; 728 struct sockaddr * __restrict asa; 729 socklen_t * __restrict alen; 730 } */ bsd_args; 731 int error; 732 733 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 734 return (error); 735 736 bsd_args.fdes = linux_args.s; 737 /* XXX: */ |
727 bsd_args.asa = (struct sockaddr * __restrict)linux_args.addr; 728 bsd_args.alen = linux_args.namelen; /* XXX */ | 738 bsd_args.asa = (struct sockaddr * __restrict)PTRIN(linux_args.addr); 739 bsd_args.alen = PTRIN(linux_args.namelen); /* XXX */ |
729 error = ogetsockname(td, &bsd_args); 730 if (error) 731 return (error); | 740 error = ogetsockname(td, &bsd_args); 741 if (error) 742 return (error); |
732 error = linux_sa_put(linux_args.addr); | 743 error = linux_sa_put(PTRIN(linux_args.addr)); |
733 if (error) 734 return (error); 735 return (0); 736} 737 738struct linux_getpeername_args { 739 int s; | 744 if (error) 745 return (error); 746 return (0); 747} 748 749struct linux_getpeername_args { 750 int s; |
740 struct osockaddr *addr; 741 int *namelen; | 751 l_uintptr_t addr; 752 l_uintptr_t namelen; |
742}; 743 744static int 745linux_getpeername(struct thread *td, struct linux_getpeername_args *args) 746{ 747 struct linux_getpeername_args linux_args; 748 struct ogetpeername_args /* { 749 int fdes; 750 caddr_t asa; 751 int *alen; 752 } */ bsd_args; 753 int error; 754 755 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 756 return (error); 757 758 bsd_args.fdes = linux_args.s; | 753}; 754 755static int 756linux_getpeername(struct thread *td, struct linux_getpeername_args *args) 757{ 758 struct linux_getpeername_args linux_args; 759 struct ogetpeername_args /* { 760 int fdes; 761 caddr_t asa; 762 int *alen; 763 } */ bsd_args; 764 int error; 765 766 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 767 return (error); 768 769 bsd_args.fdes = linux_args.s; |
759 bsd_args.asa = (caddr_t) linux_args.addr; 760 bsd_args.alen = linux_args.namelen; | 770 bsd_args.asa = (caddr_t)PTRIN(linux_args.addr); 771 bsd_args.alen = (int *)PTRIN(linux_args.namelen); |
761 error = ogetpeername(td, &bsd_args); 762 if (error) 763 return (error); | 772 error = ogetpeername(td, &bsd_args); 773 if (error) 774 return (error); |
764 error = linux_sa_put(linux_args.addr); | 775 error = linux_sa_put(PTRIN(linux_args.addr)); |
765 if (error) 766 return (error); 767 return (0); 768} 769 770struct linux_socketpair_args { 771 int domain; 772 int type; 773 int protocol; | 776 if (error) 777 return (error); 778 return (0); 779} 780 781struct linux_socketpair_args { 782 int domain; 783 int type; 784 int protocol; |
774 int *rsv; | 785 l_uintptr_t rsv; |
775}; 776 777static int 778linux_socketpair(struct thread *td, struct linux_socketpair_args *args) 779{ 780 struct linux_socketpair_args linux_args; 781 struct socketpair_args /* { 782 int domain; --- 7 unchanged lines hidden (view full) --- 790 return (error); 791 792 bsd_args.domain = linux_to_bsd_domain(linux_args.domain); 793 if (bsd_args.domain == -1) 794 return (EINVAL); 795 796 bsd_args.type = linux_args.type; 797 bsd_args.protocol = linux_args.protocol; | 786}; 787 788static int 789linux_socketpair(struct thread *td, struct linux_socketpair_args *args) 790{ 791 struct linux_socketpair_args linux_args; 792 struct socketpair_args /* { 793 int domain; --- 7 unchanged lines hidden (view full) --- 801 return (error); 802 803 bsd_args.domain = linux_to_bsd_domain(linux_args.domain); 804 if (bsd_args.domain == -1) 805 return (EINVAL); 806 807 bsd_args.type = linux_args.type; 808 bsd_args.protocol = linux_args.protocol; |
798 bsd_args.rsv = linux_args.rsv; | 809 bsd_args.rsv = (int *)PTRIN(linux_args.rsv); |
799 return (socketpair(td, &bsd_args)); 800} 801 802struct linux_send_args { 803 int s; | 810 return (socketpair(td, &bsd_args)); 811} 812 813struct linux_send_args { 814 int s; |
804 void *msg; | 815 l_uintptr_t msg; |
805 int len; 806 int flags; 807}; 808 809static int 810linux_send(struct thread *td, struct linux_send_args *args) 811{ 812 struct linux_send_args linux_args; --- 6 unchanged lines hidden (view full) --- 819 int tolen; 820 } */ bsd_args; 821 int error; 822 823 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 824 return (error); 825 826 bsd_args.s = linux_args.s; | 816 int len; 817 int flags; 818}; 819 820static int 821linux_send(struct thread *td, struct linux_send_args *args) 822{ 823 struct linux_send_args linux_args; --- 6 unchanged lines hidden (view full) --- 830 int tolen; 831 } */ bsd_args; 832 int error; 833 834 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 835 return (error); 836 837 bsd_args.s = linux_args.s; |
827 bsd_args.buf = linux_args.msg; | 838 bsd_args.buf = (caddr_t)PTRIN(linux_args.msg); |
828 bsd_args.len = linux_args.len; 829 bsd_args.flags = linux_args.flags; 830 bsd_args.to = NULL; 831 bsd_args.tolen = 0; 832 return (sendto(td, &bsd_args)); 833} 834 835struct linux_recv_args { 836 int s; | 839 bsd_args.len = linux_args.len; 840 bsd_args.flags = linux_args.flags; 841 bsd_args.to = NULL; 842 bsd_args.tolen = 0; 843 return (sendto(td, &bsd_args)); 844} 845 846struct linux_recv_args { 847 int s; |
837 void *msg; | 848 l_uintptr_t msg; |
838 int len; 839 int flags; 840}; 841 842static int 843linux_recv(struct thread *td, struct linux_recv_args *args) 844{ 845 struct linux_recv_args linux_args; --- 6 unchanged lines hidden (view full) --- 852 socklen_t fromlenaddr; 853 } */ bsd_args; 854 int error; 855 856 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 857 return (error); 858 859 bsd_args.s = linux_args.s; | 849 int len; 850 int flags; 851}; 852 853static int 854linux_recv(struct thread *td, struct linux_recv_args *args) 855{ 856 struct linux_recv_args linux_args; --- 6 unchanged lines hidden (view full) --- 863 socklen_t fromlenaddr; 864 } */ bsd_args; 865 int error; 866 867 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 868 return (error); 869 870 bsd_args.s = linux_args.s; |
860 bsd_args.buf = linux_args.msg; | 871 bsd_args.buf = (caddr_t)PTRIN(linux_args.msg); |
861 bsd_args.len = linux_args.len; 862 bsd_args.flags = linux_args.flags; 863 bsd_args.from = NULL; 864 bsd_args.fromlenaddr = 0; 865 return (recvfrom(td, &bsd_args)); 866} 867 868static int --- 6 unchanged lines hidden (view full) --- 875 876 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 877 return (error); 878 879 if (linux_check_hdrincl(td, linux_args.s) == 0) 880 /* IP_HDRINCL set, tweak the packet before sending */ 881 return (linux_sendto_hdrincl(td, &linux_args)); 882 | 872 bsd_args.len = linux_args.len; 873 bsd_args.flags = linux_args.flags; 874 bsd_args.from = NULL; 875 bsd_args.fromlenaddr = 0; 876 return (recvfrom(td, &bsd_args)); 877} 878 879static int --- 6 unchanged lines hidden (view full) --- 886 887 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 888 return (error); 889 890 if (linux_check_hdrincl(td, linux_args.s) == 0) 891 /* IP_HDRINCL set, tweak the packet before sending */ 892 return (linux_sendto_hdrincl(td, &linux_args)); 893 |
883 msg.msg_name = linux_args.to; | 894 msg.msg_name = PTRIN(linux_args.to); |
884 msg.msg_namelen = linux_args.tolen; 885 msg.msg_iov = &aiov; 886 msg.msg_iovlen = 1; 887 msg.msg_control = NULL; 888 msg.msg_flags = 0; | 895 msg.msg_namelen = linux_args.tolen; 896 msg.msg_iov = &aiov; 897 msg.msg_iovlen = 1; 898 msg.msg_control = NULL; 899 msg.msg_flags = 0; |
889 aiov.iov_base = linux_args.msg; | 900 aiov.iov_base = PTRIN(linux_args.msg); |
890 aiov.iov_len = linux_args.len; 891 error = linux_sendit(td, linux_args.s, &msg, linux_args.flags); 892 return (error); 893} 894 895struct linux_recvfrom_args { 896 int s; | 901 aiov.iov_len = linux_args.len; 902 error = linux_sendit(td, linux_args.s, &msg, linux_args.flags); 903 return (error); 904} 905 906struct linux_recvfrom_args { 907 int s; |
897 void *buf; | 908 l_uintptr_t buf; |
898 int len; 899 int flags; | 909 int len; 910 int flags; |
900 caddr_t from; 901 int *fromlen; | 911 l_uintptr_t from; 912 l_uintptr_t fromlen; |
902}; 903 904static int 905linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args) 906{ 907 struct linux_recvfrom_args linux_args; 908 struct recvfrom_args /* { 909 int s; --- 4 unchanged lines hidden (view full) --- 914 socklen_t * __restrict fromlenaddr; 915 } */ bsd_args; 916 int error; 917 918 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 919 return (error); 920 921 bsd_args.s = linux_args.s; | 913}; 914 915static int 916linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args) 917{ 918 struct linux_recvfrom_args linux_args; 919 struct recvfrom_args /* { 920 int s; --- 4 unchanged lines hidden (view full) --- 925 socklen_t * __restrict fromlenaddr; 926 } */ bsd_args; 927 int error; 928 929 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 930 return (error); 931 932 bsd_args.s = linux_args.s; |
922 bsd_args.buf = linux_args.buf; | 933 bsd_args.buf = PTRIN(linux_args.buf); |
923 bsd_args.len = linux_args.len; 924 bsd_args.flags = linux_to_bsd_msg_flags(linux_args.flags); 925 /* XXX: */ | 934 bsd_args.len = linux_args.len; 935 bsd_args.flags = linux_to_bsd_msg_flags(linux_args.flags); 936 /* XXX: */ |
926 bsd_args.from = (struct sockaddr * __restrict)linux_args.from; 927 bsd_args.fromlenaddr = linux_args.fromlen; /* XXX */ | 937 bsd_args.from = (struct sockaddr * __restrict)PTRIN(linux_args.from); 938 bsd_args.fromlenaddr = PTRIN(linux_args.fromlen);/* XXX */ |
928 error = orecvfrom(td, &bsd_args); 929 if (error) 930 return (error); 931 if (linux_args.from) { | 939 error = orecvfrom(td, &bsd_args); 940 if (error) 941 return (error); 942 if (linux_args.from) { |
932 error = linux_sa_put((struct osockaddr *) linux_args.from); | 943 error = linux_sa_put((struct osockaddr *) 944 PTRIN(linux_args.from)); |
933 if (error) 934 return (error); 935 } 936 return (0); 937} 938 939struct linux_sendmsg_args { 940 int s; | 945 if (error) 946 return (error); 947 } 948 return (0); 949} 950 951struct linux_sendmsg_args { 952 int s; |
941 const struct msghdr *msg; | 953 l_uintptr_t msg; |
942 int flags; 943}; 944 945static int 946linux_sendmsg(struct thread *td, struct linux_sendmsg_args *args) 947{ 948 struct linux_sendmsg_args linux_args; 949 struct msghdr msg; 950 struct iovec *iov; 951 int error; 952 | 954 int flags; 955}; 956 957static int 958linux_sendmsg(struct thread *td, struct linux_sendmsg_args *args) 959{ 960 struct linux_sendmsg_args linux_args; 961 struct msghdr msg; 962 struct iovec *iov; 963 int error; 964 |
965 /* XXXTJR sendmsg is broken on amd64 */ 966 |
|
953 error = copyin(args, &linux_args, sizeof(linux_args)); 954 if (error) 955 return (error); | 967 error = copyin(args, &linux_args, sizeof(linux_args)); 968 if (error) 969 return (error); |
956 error = copyin(linux_args.msg, &msg, sizeof(msg)); | 970 error = copyin(PTRIN(linux_args.msg), &msg, sizeof(msg)); |
957 if (error) 958 return (error); 959 error = copyiniov(msg.msg_iov, msg.msg_iovlen, &iov, EMSGSIZE); 960 if (error) 961 return (error); 962 msg.msg_iov = iov; 963 msg.msg_flags = 0; 964 error = linux_sendit(td, linux_args.s, &msg, linux_args.flags); 965 free(iov, M_IOV); 966 return (error); 967} 968 969struct linux_recvmsg_args { 970 int s; | 971 if (error) 972 return (error); 973 error = copyiniov(msg.msg_iov, msg.msg_iovlen, &iov, EMSGSIZE); 974 if (error) 975 return (error); 976 msg.msg_iov = iov; 977 msg.msg_flags = 0; 978 error = linux_sendit(td, linux_args.s, &msg, linux_args.flags); 979 free(iov, M_IOV); 980 return (error); 981} 982 983struct linux_recvmsg_args { 984 int s; |
971 struct msghdr *msg; | 985 l_uintptr_t msg; |
972 int flags; 973}; 974 975static int 976linux_recvmsg(struct thread *td, struct linux_recvmsg_args *args) 977{ 978 struct linux_recvmsg_args linux_args; 979 struct recvmsg_args /* { 980 int s; 981 struct msghdr *msg; 982 int flags; 983 } */ bsd_args; 984 struct msghdr msg; 985 struct cmsghdr *cmsg; 986 int error; 987 | 986 int flags; 987}; 988 989static int 990linux_recvmsg(struct thread *td, struct linux_recvmsg_args *args) 991{ 992 struct linux_recvmsg_args linux_args; 993 struct recvmsg_args /* { 994 int s; 995 struct msghdr *msg; 996 int flags; 997 } */ bsd_args; 998 struct msghdr msg; 999 struct cmsghdr *cmsg; 1000 int error; 1001 |
1002 /* XXXTJR recvmsg is broken on amd64 */ 1003 |
|
988 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 989 return (error); 990 991 bsd_args.s = linux_args.s; | 1004 if ((error = copyin(args, &linux_args, sizeof(linux_args)))) 1005 return (error); 1006 1007 bsd_args.s = linux_args.s; |
992 bsd_args.msg = linux_args.msg; | 1008 bsd_args.msg = PTRIN(linux_args.msg); |
993 bsd_args.flags = linux_to_bsd_msg_flags(linux_args.flags); 994 error = recvmsg(td, &bsd_args); 995 if (error) 996 return (error); 997 998 if (bsd_args.msg->msg_control != NULL) { 999 cmsg = (struct cmsghdr*)bsd_args.msg->msg_control; 1000 cmsg->cmsg_level = bsd_to_linux_sockopt_level(cmsg->cmsg_level); 1001 } 1002 | 1009 bsd_args.flags = linux_to_bsd_msg_flags(linux_args.flags); 1010 error = recvmsg(td, &bsd_args); 1011 if (error) 1012 return (error); 1013 1014 if (bsd_args.msg->msg_control != NULL) { 1015 cmsg = (struct cmsghdr*)bsd_args.msg->msg_control; 1016 cmsg->cmsg_level = bsd_to_linux_sockopt_level(cmsg->cmsg_level); 1017 } 1018 |
1003 error = copyin(linux_args.msg, &msg, sizeof(msg)); | 1019 error = copyin(PTRIN(linux_args.msg), &msg, sizeof(msg)); |
1004 if (error) 1005 return (error); 1006 if (msg.msg_name && msg.msg_namelen > 2) 1007 error = linux_sa_put(msg.msg_name); 1008 return (error); 1009} 1010 1011struct linux_shutdown_args { --- 18 unchanged lines hidden (view full) --- 1030 bsd_args.how = linux_args.how; 1031 return (shutdown(td, &bsd_args)); 1032} 1033 1034struct linux_setsockopt_args { 1035 int s; 1036 int level; 1037 int optname; | 1020 if (error) 1021 return (error); 1022 if (msg.msg_name && msg.msg_namelen > 2) 1023 error = linux_sa_put(msg.msg_name); 1024 return (error); 1025} 1026 1027struct linux_shutdown_args { --- 18 unchanged lines hidden (view full) --- 1046 bsd_args.how = linux_args.how; 1047 return (shutdown(td, &bsd_args)); 1048} 1049 1050struct linux_setsockopt_args { 1051 int s; 1052 int level; 1053 int optname; |
1038 void *optval; | 1054 l_uintptr_t optval; |
1039 int optlen; 1040}; 1041 1042static int 1043linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args) 1044{ 1045 struct linux_setsockopt_args linux_args; 1046 struct setsockopt_args /* { --- 24 unchanged lines hidden (view full) --- 1071 default: 1072 name = -1; 1073 break; 1074 } 1075 if (name == -1) 1076 return (EINVAL); 1077 1078 bsd_args.name = name; | 1055 int optlen; 1056}; 1057 1058static int 1059linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args) 1060{ 1061 struct linux_setsockopt_args linux_args; 1062 struct setsockopt_args /* { --- 24 unchanged lines hidden (view full) --- 1087 default: 1088 name = -1; 1089 break; 1090 } 1091 if (name == -1) 1092 return (EINVAL); 1093 1094 bsd_args.name = name; |
1079 bsd_args.val = linux_args.optval; | 1095 bsd_args.val = PTRIN(linux_args.optval); |
1080 bsd_args.valsize = linux_args.optlen; 1081 return (setsockopt(td, &bsd_args)); 1082} 1083 1084struct linux_getsockopt_args { 1085 int s; 1086 int level; 1087 int optname; | 1096 bsd_args.valsize = linux_args.optlen; 1097 return (setsockopt(td, &bsd_args)); 1098} 1099 1100struct linux_getsockopt_args { 1101 int s; 1102 int level; 1103 int optname; |
1088 void *optval; 1089 int *optlen; | 1104 l_uintptr_t optval; 1105 l_uintptr_t optlen; |
1090}; 1091 1092static int 1093linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args) 1094{ 1095 struct linux_getsockopt_args linux_args; 1096 struct getsockopt_args /* { 1097 int s; --- 23 unchanged lines hidden (view full) --- 1121 default: 1122 name = -1; 1123 break; 1124 } 1125 if (name == -1) 1126 return (EINVAL); 1127 1128 bsd_args.name = name; | 1106}; 1107 1108static int 1109linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args) 1110{ 1111 struct linux_getsockopt_args linux_args; 1112 struct getsockopt_args /* { 1113 int s; --- 23 unchanged lines hidden (view full) --- 1137 default: 1138 name = -1; 1139 break; 1140 } 1141 if (name == -1) 1142 return (EINVAL); 1143 1144 bsd_args.name = name; |
1129 bsd_args.val = linux_args.optval; 1130 bsd_args.avalsize = linux_args.optlen; | 1145 bsd_args.val = PTRIN(linux_args.optval); 1146 bsd_args.avalsize = PTRIN(linux_args.optlen); |
1131 return (getsockopt(td, &bsd_args)); 1132} 1133 1134int 1135linux_socketcall(struct thread *td, struct linux_socketcall_args *args) 1136{ | 1147 return (getsockopt(td, &bsd_args)); 1148} 1149 1150int 1151linux_socketcall(struct thread *td, struct linux_socketcall_args *args) 1152{ |
1137 void *arg = (void *)args->args; | 1153 void *arg = (void *)(intptr_t)args->args; |
1138 1139 switch (args->what) { 1140 case LINUX_SOCKET: 1141 return (linux_socket(td, arg)); 1142 case LINUX_BIND: 1143 return (linux_bind(td, arg)); 1144 case LINUX_CONNECT: 1145 return (linux_connect(td, arg)); --- 34 unchanged lines hidden --- | 1154 1155 switch (args->what) { 1156 case LINUX_SOCKET: 1157 return (linux_socket(td, arg)); 1158 case LINUX_BIND: 1159 return (linux_bind(td, arg)); 1160 case LINUX_CONNECT: 1161 return (linux_connect(td, arg)); --- 34 unchanged lines hidden --- |