Skip to content

Commit ab895dd

Browse files
committed
liburing.h: Do not discard low 32 bits of length in send
1 parent 9a0461d commit ab895dd

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/include/liburing.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -919,10 +919,15 @@ IOURINGINLINE void io_uring_prep_statx(struct io_uring_sqe *sqe, int dfd,
919919
sqe->statx_flags = (__u32) flags;
920920
}
921921

922+
IOURINGINLINE __u32 __io_uring_cap_len(size_t len) {
923+
size_t mask = -(size_t)(len > UINT32_MAX);
924+
return (len & ~mask) | (UINT32_MAX & mask);
925+
}
926+
922927
IOURINGINLINE void io_uring_prep_fadvise(struct io_uring_sqe *sqe, int fd,
923928
__u64 offset, __u32 len, int advice)
924929
{
925-
io_uring_prep_rw(IORING_OP_FADVISE, sqe, fd, NULL, (__u32) len, offset);
930+
io_uring_prep_rw(IORING_OP_FADVISE, sqe, fd, NULL, __io_uring_cap_len(len), offset);
926931
sqe->fadvise_advice = (__u32) advice;
927932
}
928933

@@ -951,7 +956,7 @@ IOURINGINLINE void io_uring_prep_madvise64(struct io_uring_sqe *sqe, void *addr,
951956
IOURINGINLINE void io_uring_prep_send(struct io_uring_sqe *sqe, int sockfd,
952957
const void *buf, size_t len, int flags)
953958
{
954-
io_uring_prep_rw(IORING_OP_SEND, sqe, sockfd, buf, (__u32) len, 0);
959+
io_uring_prep_rw(IORING_OP_SEND, sqe, sockfd, buf, __io_uring_cap_len(len), 0);
955960
sqe->msg_flags = (__u32) flags;
956961
}
957962

@@ -983,7 +988,7 @@ IOURINGINLINE void io_uring_prep_send_zc(struct io_uring_sqe *sqe, int sockfd,
983988
const void *buf, size_t len, int flags,
984989
unsigned zc_flags)
985990
{
986-
io_uring_prep_rw(IORING_OP_SEND_ZC, sqe, sockfd, buf, (__u32) len, 0);
991+
io_uring_prep_rw(IORING_OP_SEND_ZC, sqe, sockfd, buf, __io_uring_cap_len(len), 0);
987992
sqe->msg_flags = (__u32) flags;
988993
sqe->ioprio = zc_flags;
989994
}
@@ -1021,7 +1026,7 @@ IOURINGINLINE void io_uring_prep_sendmsg_zc_fixed(struct io_uring_sqe *sqe,
10211026
IOURINGINLINE void io_uring_prep_recv(struct io_uring_sqe *sqe, int sockfd,
10221027
void *buf, size_t len, int flags)
10231028
{
1024-
io_uring_prep_rw(IORING_OP_RECV, sqe, sockfd, buf, (__u32) len, 0);
1029+
io_uring_prep_rw(IORING_OP_RECV, sqe, sockfd, buf, __io_uring_cap_len(len), 0);
10251030
sqe->msg_flags = (__u32) flags;
10261031
}
10271032

@@ -1131,7 +1136,7 @@ IOURINGINLINE void io_uring_prep_provide_buffers(struct io_uring_sqe *sqe,
11311136
void *addr, int len, int nr,
11321137
int bgid, int bid)
11331138
{
1134-
io_uring_prep_rw(IORING_OP_PROVIDE_BUFFERS, sqe, nr, addr, (__u32) len,
1139+
io_uring_prep_rw(IORING_OP_PROVIDE_BUFFERS, sqe, nr, addr, __io_uring_cap_len(len),
11351140
(__u64) bid);
11361141
sqe->buf_group = (__u16) bgid;
11371142
}

0 commit comments

Comments
 (0)