Skip to content

Commit 1152067

Browse files
committed
The msghdr.msg_iov->iov_base and msghdr.msg_iov->iov_len of ff_sendmsg() and ff_recvmsg() compatible with the Linux.
Note: linux2freebsd_msghdr and freebsd2linux_msghdr must be called in sequence and in pairs.
1 parent 615b66a commit 1152067

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/ff_syscall_wrapper.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@
185185

186186
/* msghdr define start */
187187

188+
static /*__thread*/ struct iovec msg_iov_tmp[UIO_MAXIOV];
189+
static /*__thread*/ size_t msg_iovlen_tmp;
190+
188191
struct linux_msghdr {
189192
void *msg_name; /* Address to send to/receive from. */
190193
socklen_t msg_namelen; /* Length of address data. */
@@ -642,6 +645,7 @@ linux2freebsd_cmsg(const struct linux_msghdr *linux_msg, struct msghdr *freebsd_
642645
/*
643646
* While sendmsg, need convert msg_name and msg_control from Linux to FreeBSD.
644647
* While recvmsg, need convert msg_name and msg_control from FreeBSD to Linux.
648+
* Note: linux2freebsd_msghdr and freebsd2linux_msghdr must be called in sequence and in pairs.
645649
*/
646650
static int
647651
freebsd2linux_msghdr(struct linux_msghdr *linux_msg, struct msghdr *freebsd_msg, int send_flag)
@@ -658,6 +662,8 @@ freebsd2linux_msghdr(struct linux_msghdr *linux_msg, struct msghdr *freebsd_msg,
658662

659663
linux_msg->msg_iov = freebsd_msg->msg_iov;
660664
linux_msg->msg_iovlen = freebsd_msg->msg_iovlen;
665+
/* Restore the old iov pointer, compatible with the Linux interface */
666+
memcpy(linux_msg->msg_iov, msg_iov_tmp, msg_iovlen_tmp * sizeof(struct iovec));
661667

662668
if(freebsd_msg->msg_control && linux_msg->msg_control && !send_flag) {
663669
freebsd2linux_cmsghdr(linux_msg, freebsd_msg);
@@ -685,6 +691,12 @@ linux2freebsd_msghdr(const struct linux_msghdr *linux_msg, struct msghdr *freebs
685691
}
686692
freebsd_msg->msg_namelen = linux_msg->msg_namelen;
687693

694+
/* Save the old iov pointer, compatible with the Linux interface */
695+
msg_iovlen_tmp = linux_msg->msg_iovlen;
696+
if (msg_iovlen_tmp > UIO_MAXIOV) {
697+
return -1; // EMSGSIZE;
698+
}
699+
memcpy(msg_iov_tmp, linux_msg->msg_iov, msg_iovlen_tmp * sizeof(struct iovec));
688700
freebsd_msg->msg_iov = linux_msg->msg_iov;
689701
freebsd_msg->msg_iovlen = linux_msg->msg_iovlen;
690702

0 commit comments

Comments
 (0)