Commit 1be9e1dc569eb3817441baf60d26648c5dcef12d

Authored by pbrook
1 parent ec2db7de

Remove do_socketcallwrapper.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2215 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 129 additions and 92 deletions
linux-user/syscall.c
... ... @@ -837,6 +837,113 @@ static long do_sendrecvmsg(int fd, target_ulong target_msg,
837 837 return ret;
838 838 }
839 839  
  840 +static long do_accept(int fd, target_ulong target_addr,
  841 + target_ulong target_addrlen)
  842 +{
  843 + socklen_t addrlen = tget32(target_addrlen);
  844 + void *addr = alloca(target_addrlen);
  845 + long ret;
  846 +
  847 + ret = get_errno(accept(fd, addr, &addrlen));
  848 + if (!is_error(ret)) {
  849 + host_to_target_sockaddr(target_addr, addr, addrlen);
  850 + tput32(target_addrlen, addrlen);
  851 + }
  852 + return ret;
  853 +}
  854 +
  855 +static long do_getpeername(int fd, target_ulong target_addr,
  856 + target_ulong target_addrlen)
  857 +{
  858 + socklen_t addrlen = tget32(target_addrlen);
  859 + void *addr = alloca(target_addrlen);
  860 + long ret;
  861 +
  862 + ret = get_errno(getpeername(fd, addr, &addrlen));
  863 + if (!is_error(ret)) {
  864 + host_to_target_sockaddr(target_addr, addr, addrlen);
  865 + tput32(target_addrlen, addrlen);
  866 + }
  867 + return ret;
  868 +}
  869 +
  870 +static long do_getsockname(int fd, target_ulong target_addr,
  871 + target_ulong target_addrlen)
  872 +{
  873 + socklen_t addrlen = tget32(target_addrlen);
  874 + void *addr = alloca(target_addrlen);
  875 + long ret;
  876 +
  877 + ret = get_errno(getsockname(fd, addr, &addrlen));
  878 + if (!is_error(ret)) {
  879 + host_to_target_sockaddr(target_addr, addr, addrlen);
  880 + tput32(target_addrlen, addrlen);
  881 + }
  882 + return ret;
  883 +}
  884 +
  885 +static long do_socketpair(int domain, int type, int protocol,
  886 + target_ulong target_tab)
  887 +{
  888 + int tab[2];
  889 + long ret;
  890 +
  891 + ret = get_errno(socketpair(domain, type, protocol, tab));
  892 + if (!is_error(ret)) {
  893 + tput32(target_tab, tab[0]);
  894 + tput32(target_tab + 4, tab[1]);
  895 + }
  896 + return ret;
  897 +}
  898 +
  899 +static long do_sendto(int fd, target_ulong msg, size_t len, int flags,
  900 + target_ulong target_addr, socklen_t addrlen)
  901 +{
  902 + void *addr;
  903 + void *host_msg;
  904 + long ret;
  905 +
  906 + host_msg = lock_user(msg, len, 1);
  907 + if (target_addr) {
  908 + addr = alloca(addrlen);
  909 + target_to_host_sockaddr(addr, target_addr, addrlen);
  910 + ret = get_errno(sendto(fd, host_msg, len, flags, addr, addrlen));
  911 + } else {
  912 + ret = get_errno(send(fd, host_msg, len, flags));
  913 + }
  914 + unlock_user(host_msg, msg, 0);
  915 + return ret;
  916 +}
  917 +
  918 +static long do_recvfrom(int fd, target_ulong msg, size_t len, int flags,
  919 + target_ulong target_addr, target_ulong target_addrlen)
  920 +{
  921 + socklen_t addrlen;
  922 + void *addr;
  923 + void *host_msg;
  924 + long ret;
  925 +
  926 + host_msg = lock_user(msg, len, 0);
  927 + if (target_addr) {
  928 + addrlen = tget32(target_addrlen);
  929 + addr = alloca(addrlen);
  930 + ret = get_errno(recvfrom(fd, host_msg, len, flags, addr, &addrlen));
  931 + } else {
  932 + addr = NULL; /* To keep compiler quiet. */
  933 + ret = get_errno(recv(fd, host_msg, len, flags));
  934 + }
  935 + if (!is_error(ret)) {
  936 + if (target_addr) {
  937 + host_to_target_sockaddr(target_addr, addr, addrlen);
  938 + tput32(target_addrlen, addrlen);
  939 + }
  940 + unlock_user(host_msg, msg, len);
  941 + } else {
  942 + unlock_user(host_msg, msg, 0);
  943 + }
  944 + return ret;
  945 +}
  946 +
840 947 static long do_socketcall(int num, target_ulong vptr)
841 948 {
842 949 long ret;
... ... @@ -879,14 +986,7 @@ static long do_socketcall(int num, target_ulong vptr)
879 986 int sockfd = tgetl(vptr);
880 987 target_ulong target_addr = tgetl(vptr + n);
881 988 target_ulong target_addrlen = tgetl(vptr + 2 * n);
882   - socklen_t addrlen = tget32(target_addrlen);
883   - void *addr = alloca(addrlen);
884   -
885   - ret = get_errno(accept(sockfd, addr, &addrlen));
886   - if (!is_error(ret)) {
887   - host_to_target_sockaddr(target_addr, addr, addrlen);
888   - tput32(target_addrlen, addrlen);
889   - }
  989 + ret = do_accept(sockfd, target_addr, target_addrlen);
890 990 }
891 991 break;
892 992 case SOCKOP_getsockname:
... ... @@ -894,14 +994,7 @@ static long do_socketcall(int num, target_ulong vptr)
894 994 int sockfd = tgetl(vptr);
895 995 target_ulong target_addr = tgetl(vptr + n);
896 996 target_ulong target_addrlen = tgetl(vptr + 2 * n);
897   - socklen_t addrlen = tget32(target_addrlen);
898   - void *addr = alloca(addrlen);
899   -
900   - ret = get_errno(getsockname(sockfd, addr, &addrlen));
901   - if (!is_error(ret)) {
902   - host_to_target_sockaddr(target_addr, addr, addrlen);
903   - tput32(target_addrlen, addrlen);
904   - }
  997 + ret = do_getsockname(sockfd, target_addr, target_addrlen);
905 998 }
906 999 break;
907 1000 case SOCKOP_getpeername:
... ... @@ -909,14 +1002,7 @@ static long do_socketcall(int num, target_ulong vptr)
909 1002 int sockfd = tgetl(vptr);
910 1003 target_ulong target_addr = tgetl(vptr + n);
911 1004 target_ulong target_addrlen = tgetl(vptr + 2 * n);
912   - socklen_t addrlen = tget32(target_addrlen);
913   - void *addr = alloca(addrlen);
914   -
915   - ret = get_errno(getpeername(sockfd, addr, &addrlen));
916   - if (!is_error(ret)) {
917   - host_to_target_sockaddr(target_addr, addr, addrlen);
918   - tput32(target_addrlen, addrlen);
919   - }
  1005 + ret = do_getpeername(sockfd, target_addr, target_addrlen);
920 1006 }
921 1007 break;
922 1008 case SOCKOP_socketpair:
... ... @@ -924,14 +1010,8 @@ static long do_socketcall(int num, target_ulong vptr)
924 1010 int domain = tgetl(vptr);
925 1011 int type = tgetl(vptr + n);
926 1012 int protocol = tgetl(vptr + 2 * n);
927   - target_ulong target_tab = tgetl(vptr + 3 * n);
928   - int tab[2];
929   -
930   - ret = get_errno(socketpair(domain, type, protocol, tab));
931   - if (!is_error(ret)) {
932   - tput32(target_tab, tab[0]);
933   - tput32(target_tab + 4, tab[1]);
934   - }
  1013 + target_ulong tab = tgetl(vptr + 3 * n);
  1014 + ret = do_socketpair(domain, type, protocol, tab);
935 1015 }
936 1016 break;
937 1017 case SOCKOP_send:
... ... @@ -940,11 +1020,7 @@ static long do_socketcall(int num, target_ulong vptr)
940 1020 target_ulong msg = tgetl(vptr + n);
941 1021 size_t len = tgetl(vptr + 2 * n);
942 1022 int flags = tgetl(vptr + 3 * n);
943   - void *host_msg;
944   -
945   - host_msg = lock_user(msg, len, 1);
946   - ret = get_errno(send(sockfd, host_msg, len, flags));
947   - unlock_user(host_msg, msg, 0);
  1023 + ret = do_sendto(sockfd, msg, len, flags, 0, 0);
948 1024 }
949 1025 break;
950 1026 case SOCKOP_recv:
... ... @@ -953,11 +1029,7 @@ static long do_socketcall(int num, target_ulong vptr)
953 1029 target_ulong msg = tgetl(vptr + n);
954 1030 size_t len = tgetl(vptr + 2 * n);
955 1031 int flags = tgetl(vptr + 3 * n);
956   - void *host_msg;
957   -
958   - host_msg = lock_user(msg, len, 0);
959   - ret = get_errno(recv(sockfd, host_msg, len, flags));
960   - unlock_user(host_msg, msg, ret);
  1032 + ret = do_recvfrom(sockfd, msg, len, flags, 0, 0);
961 1033 }
962 1034 break;
963 1035 case SOCKOP_sendto:
... ... @@ -966,15 +1038,9 @@ static long do_socketcall(int num, target_ulong vptr)
966 1038 target_ulong msg = tgetl(vptr + n);
967 1039 size_t len = tgetl(vptr + 2 * n);
968 1040 int flags = tgetl(vptr + 3 * n);
969   - target_ulong target_addr = tgetl(vptr + 4 * n);
  1041 + target_ulong addr = tgetl(vptr + 4 * n);
970 1042 socklen_t addrlen = tgetl(vptr + 5 * n);
971   - void *addr = alloca(addrlen);
972   - void *host_msg;
973   -
974   - host_msg = lock_user(msg, len, 1);
975   - target_to_host_sockaddr(addr, target_addr, addrlen);
976   - ret = get_errno(sendto(sockfd, host_msg, len, flags, addr, addrlen));
977   - unlock_user(host_msg, msg, 0);
  1043 + ret = do_sendto(sockfd, msg, len, flags, addr, addrlen);
978 1044 }
979 1045 break;
980 1046 case SOCKOP_recvfrom:
... ... @@ -983,21 +1049,9 @@ static long do_socketcall(int num, target_ulong vptr)
983 1049 target_ulong msg = tgetl(vptr + n);
984 1050 size_t len = tgetl(vptr + 2 * n);
985 1051 int flags = tgetl(vptr + 3 * n);
986   - target_ulong target_addr = tgetl(vptr + 4 * n);
987   - target_ulong target_addrlen = tgetl(vptr + 5 * n);
988   - socklen_t addrlen = tget32(target_addrlen);
989   - void *addr = alloca(addrlen);
990   - void *host_msg;
991   -
992   - host_msg = lock_user(msg, len, 0);
993   - ret = get_errno(recvfrom(sockfd, host_msg, len, flags, addr, &addrlen));
994   - if (!is_error(ret)) {
995   - host_to_target_sockaddr(target_addr, addr, addrlen);
996   - tput32(target_addrlen, addrlen);
997   - unlock_user(host_msg, msg, len);
998   - } else {
999   - unlock_user(host_msg, msg, 0);
1000   - }
  1052 + target_ulong addr = tgetl(vptr + 4 * n);
  1053 + target_ulong addrlen = tgetl(vptr + 5 * n);
  1054 + ret = do_recvfrom(sockfd, msg, len, flags, addr, addrlen);
1001 1055 }
1002 1056 break;
1003 1057 case SOCKOP_shutdown:
... ... @@ -1053,23 +1107,6 @@ static long do_socketcall(int num, target_ulong vptr)
1053 1107 return ret;
1054 1108 }
1055 1109  
1056   -/* XXX: suppress this function and call directly the related socket
1057   - functions */
1058   -static long do_socketcallwrapper(int num, long arg1, long arg2, long arg3,
1059   - long arg4, long arg5, long arg6)
1060   -{
1061   - target_long args[6];
1062   -
1063   - tputl(args, arg1);
1064   - tputl(args+1, arg2);
1065   - tputl(args+2, arg3);
1066   - tputl(args+3, arg4);
1067   - tputl(args+4, arg5);
1068   - tputl(args+5, arg6);
1069   -
1070   - return do_socketcall(num, (target_ulong) args);
1071   -}
1072   -
1073 1110 #define N_SHM_REGIONS 32
1074 1111  
1075 1112 static struct shm_region {
... ... @@ -2755,7 +2792,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2755 2792  
2756 2793 #ifdef TARGET_NR_accept
2757 2794 case TARGET_NR_accept:
2758   - ret = do_socketcallwrapper(SOCKOP_accept, arg1, arg2, arg3, arg4, arg5, arg6);
  2795 + ret = do_accept(arg1, arg2, arg3);
2759 2796 break;
2760 2797 #endif
2761 2798 #ifdef TARGET_NR_bind
... ... @@ -2770,12 +2807,12 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2770 2807 #endif
2771 2808 #ifdef TARGET_NR_getpeername
2772 2809 case TARGET_NR_getpeername:
2773   - ret = do_socketcallwrapper(SOCKOP_getpeername, arg1, arg2, arg3, arg4, arg5, arg6);
  2810 + ret = do_getpeername(arg1, arg2, arg3);
2774 2811 break;
2775 2812 #endif
2776 2813 #ifdef TARGET_NR_getsockname
2777 2814 case TARGET_NR_getsockname:
2778   - ret = do_socketcallwrapper(SOCKOP_getsockname, arg1, arg2, arg3, arg4, arg5, arg6);
  2815 + ret = do_getsockname(arg1, arg2, arg3);
2779 2816 break;
2780 2817 #endif
2781 2818 #ifdef TARGET_NR_getsockopt
... ... @@ -2785,17 +2822,17 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2785 2822 #endif
2786 2823 #ifdef TARGET_NR_listen
2787 2824 case TARGET_NR_listen:
2788   - ret = do_socketcallwrapper(SOCKOP_listen, arg1, arg2, arg3, arg4, arg5, arg6);
  2825 + ret = get_errno(listen(arg1, arg2));
2789 2826 break;
2790 2827 #endif
2791 2828 #ifdef TARGET_NR_recv
2792 2829 case TARGET_NR_recv:
2793   - ret = do_socketcallwrapper(SOCKOP_recv, arg1, arg2, arg3, arg4, arg5, arg6);
  2830 + ret = do_recvfrom(arg1, arg1, arg3, arg4, 0, 0);
2794 2831 break;
2795 2832 #endif
2796 2833 #ifdef TARGET_NR_recvfrom
2797 2834 case TARGET_NR_recvfrom:
2798   - ret = do_socketcallwrapper(SOCKOP_recvfrom, arg1, arg2, arg3, arg4, arg5, arg6);
  2835 + ret = do_recvfrom(arg1, arg1, arg3, arg4, arg5, arg6);
2799 2836 break;
2800 2837 #endif
2801 2838 #ifdef TARGET_NR_recvmsg
... ... @@ -2805,7 +2842,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2805 2842 #endif
2806 2843 #ifdef TARGET_NR_send
2807 2844 case TARGET_NR_send:
2808   - ret = do_socketcallwrapper(SOCKOP_send, arg1, arg2, arg3, arg4, arg5, arg6);
  2845 + ret = do_sendto(arg1, arg2, arg3, arg4, 0, 0);
2809 2846 break;
2810 2847 #endif
2811 2848 #ifdef TARGET_NR_sendmsg
... ... @@ -2815,12 +2852,12 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2815 2852 #endif
2816 2853 #ifdef TARGET_NR_sendto
2817 2854 case TARGET_NR_sendto:
2818   - ret = do_socketcallwrapper(SOCKOP_sendto, arg1, arg2, arg3, arg4, arg5, arg6);
  2855 + ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6);
2819 2856 break;
2820 2857 #endif
2821 2858 #ifdef TARGET_NR_shutdown
2822 2859 case TARGET_NR_shutdown:
2823   - ret = do_socketcallwrapper(SOCKOP_shutdown, arg1, arg2, arg3, arg4, arg5, arg6);
  2860 + ret = get_errno(shutdown(arg1, arg2));
2824 2861 break;
2825 2862 #endif
2826 2863 #ifdef TARGET_NR_socket
... ... @@ -2830,7 +2867,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2830 2867 #endif
2831 2868 #ifdef TARGET_NR_socketpair
2832 2869 case TARGET_NR_socketpair:
2833   - ret = do_socketcallwrapper(SOCKOP_socketpair, arg1, arg2, arg3, arg4, arg5, arg6);
  2870 + ret = do_socketpair(arg1, arg2, arg3, arg4);
2834 2871 break;
2835 2872 #endif
2836 2873 #ifdef TARGET_NR_setsockopt
... ...