freebsd32_misc.c (337427) | freebsd32_misc.c (338617) |
---|---|
1/*- 2 * Copyright (c) 2002 Doug Rabson 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 --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2002 Doug Rabson 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 --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: stable/11/sys/compat/freebsd32/freebsd32_misc.c 337427 2018-08-07 17:44:13Z kib $"); | 28__FBSDID("$FreeBSD: stable/11/sys/compat/freebsd32/freebsd32_misc.c 338617 2018-09-12 18:52:18Z sobomax $"); |
29 30#include "opt_compat.h" 31#include "opt_inet.h" 32#include "opt_inet6.h" 33#include "opt_ktrace.h" 34 35#define __ELF_WORD_SIZE 32 36 --- 75 unchanged lines hidden (view full) --- 112#include <compat/freebsd32/freebsd32_proto.h> 113 114FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD"); 115 116#ifndef __mips__ 117CTASSERT(sizeof(struct timeval32) == 8); 118CTASSERT(sizeof(struct timespec32) == 8); 119CTASSERT(sizeof(struct itimerval32) == 16); | 29 30#include "opt_compat.h" 31#include "opt_inet.h" 32#include "opt_inet6.h" 33#include "opt_ktrace.h" 34 35#define __ELF_WORD_SIZE 32 36 --- 75 unchanged lines hidden (view full) --- 112#include <compat/freebsd32/freebsd32_proto.h> 113 114FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD"); 115 116#ifndef __mips__ 117CTASSERT(sizeof(struct timeval32) == 8); 118CTASSERT(sizeof(struct timespec32) == 8); 119CTASSERT(sizeof(struct itimerval32) == 16); |
120CTASSERT(sizeof(struct bintime32) == 12); |
|
120#endif 121CTASSERT(sizeof(struct statfs32) == 256); 122#ifndef __mips__ 123CTASSERT(sizeof(struct rusage32) == 72); 124#endif 125CTASSERT(sizeof(struct sigaltstack32) == 12); 126CTASSERT(sizeof(struct kevent32) == 20); 127CTASSERT(sizeof(struct iovec32) == 8); --- 771 unchanged lines hidden (view full) --- 899#endif 900#define FREEBSD32_ALIGN(p) \ 901 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES) 902#define FREEBSD32_CMSG_SPACE(l) \ 903 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l)) 904 905#define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \ 906 FREEBSD32_ALIGN(sizeof(struct cmsghdr))) | 121#endif 122CTASSERT(sizeof(struct statfs32) == 256); 123#ifndef __mips__ 124CTASSERT(sizeof(struct rusage32) == 72); 125#endif 126CTASSERT(sizeof(struct sigaltstack32) == 12); 127CTASSERT(sizeof(struct kevent32) == 20); 128CTASSERT(sizeof(struct iovec32) == 8); --- 771 unchanged lines hidden (view full) --- 900#endif 901#define FREEBSD32_ALIGN(p) \ 902 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES) 903#define FREEBSD32_CMSG_SPACE(l) \ 904 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l)) 905 906#define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \ 907 FREEBSD32_ALIGN(sizeof(struct cmsghdr))) |
908 909static size_t 910freebsd32_cmsg_convert(struct cmsghdr *cm, void *data, socklen_t datalen) 911{ 912 size_t copylen; 913 union { 914 struct timespec32 ts; 915 struct timeval32 tv; 916 struct bintime32 bt; 917 } tmp32; 918 919 union { 920 struct timespec ts; 921 struct timeval tv; 922 struct bintime bt; 923 } *in; 924 925 in = data; 926 copylen = 0; 927 switch (cm->cmsg_level) { 928 case SOL_SOCKET: 929 switch (cm->cmsg_type) { 930 case SCM_TIMESTAMP: 931 TV_CP(*in, tmp32, tv); 932 copylen = sizeof(tmp32.tv); 933 break; 934 935 case SCM_BINTIME: 936 BT_CP(*in, tmp32, bt); 937 copylen = sizeof(tmp32.bt); 938 break; 939 940 case SCM_REALTIME: 941 case SCM_MONOTONIC: 942 TS_CP(*in, tmp32, ts); 943 copylen = sizeof(tmp32.ts); 944 break; 945 946 default: 947 break; 948 } 949 950 default: 951 break; 952 } 953 954 if (copylen == 0) 955 return (datalen); 956 957 KASSERT((datalen >= copylen), ("corrupted cmsghdr")); 958 959 bcopy(&tmp32, data, copylen); 960 return (copylen); 961} 962 |
|
907static int 908freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control) 909{ 910 struct cmsghdr *cm; 911 void *data; | 963static int 964freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control) 965{ 966 struct cmsghdr *cm; 967 void *data; |
912 socklen_t clen, datalen; | 968 socklen_t clen, datalen, datalen_out; |
913 int error; 914 caddr_t ctlbuf; 915 int len, maxlen, copylen; 916 struct mbuf *m; 917 error = 0; 918 919 len = msg->msg_controllen; 920 maxlen = msg->msg_controllen; --- 7 unchanged lines hidden (view full) --- 928 clen = m->m_len; 929 930 while (cm != NULL) { 931 932 if (sizeof(struct cmsghdr) > clen || 933 cm->cmsg_len > clen) { 934 error = EINVAL; 935 break; | 969 int error; 970 caddr_t ctlbuf; 971 int len, maxlen, copylen; 972 struct mbuf *m; 973 error = 0; 974 975 len = msg->msg_controllen; 976 maxlen = msg->msg_controllen; --- 7 unchanged lines hidden (view full) --- 984 clen = m->m_len; 985 986 while (cm != NULL) { 987 988 if (sizeof(struct cmsghdr) > clen || 989 cm->cmsg_len > clen) { 990 error = EINVAL; 991 break; |
936 } | 992 } |
937 938 data = CMSG_DATA(cm); 939 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data; | 993 994 data = CMSG_DATA(cm); 995 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data; |
996 datalen_out = freebsd32_cmsg_convert(cm, data, datalen); |
|
940 941 /* Adjust message length */ 942 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + | 997 998 /* Adjust message length */ 999 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + |
943 datalen; | 1000 datalen_out; |
944 | 1001 |
945 | |
946 /* Copy cmsghdr */ 947 copylen = sizeof(struct cmsghdr); 948 if (len < copylen) { 949 msg->msg_flags |= MSG_CTRUNC; 950 copylen = len; 951 } 952 | 1002 /* Copy cmsghdr */ 1003 copylen = sizeof(struct cmsghdr); 1004 if (len < copylen) { 1005 msg->msg_flags |= MSG_CTRUNC; 1006 copylen = len; 1007 } 1008 |
953 error = copyout(cm,ctlbuf,copylen); | 1009 error = copyout(cm, ctlbuf, copylen); |
954 if (error) 955 goto exit; 956 957 ctlbuf += FREEBSD32_ALIGN(copylen); 958 len -= FREEBSD32_ALIGN(copylen); 959 960 if (len <= 0) 961 break; 962 963 /* Copy data */ | 1010 if (error) 1011 goto exit; 1012 1013 ctlbuf += FREEBSD32_ALIGN(copylen); 1014 len -= FREEBSD32_ALIGN(copylen); 1015 1016 if (len <= 0) 1017 break; 1018 1019 /* Copy data */ |
964 copylen = datalen; | 1020 copylen = datalen_out; |
965 if (len < copylen) { 966 msg->msg_flags |= MSG_CTRUNC; 967 copylen = len; 968 } 969 | 1021 if (len < copylen) { 1022 msg->msg_flags |= MSG_CTRUNC; 1023 copylen = len; 1024 } 1025 |
970 error = copyout(data,ctlbuf,copylen); | 1026 error = copyout(data, ctlbuf, copylen); |
971 if (error) 972 goto exit; 973 974 ctlbuf += FREEBSD32_ALIGN(copylen); 975 len -= FREEBSD32_ALIGN(copylen); 976 977 if (CMSG_SPACE(datalen) < clen) { 978 clen -= CMSG_SPACE(datalen); --- 2216 unchanged lines hidden --- | 1027 if (error) 1028 goto exit; 1029 1030 ctlbuf += FREEBSD32_ALIGN(copylen); 1031 len -= FREEBSD32_ALIGN(copylen); 1032 1033 if (CMSG_SPACE(datalen) < clen) { 1034 clen -= CMSG_SPACE(datalen); --- 2216 unchanged lines hidden --- |