Skip to content

Commit 821576a

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

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/include/liburing.h

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

922+
static inline __u32 __io_uring_cap_len(size_t len)
923+
{
924+
size_t mask = -(size_t)(len > UINT32_MAX);
925+
return (len & ~mask) | (UINT32_MAX & mask);
926+
}
927+
922928
IOURINGINLINE void io_uring_prep_fadvise(struct io_uring_sqe *sqe, int fd,
923929
__u64 offset, __u32 len, int advice)
924930
{
925-
io_uring_prep_rw(IORING_OP_FADVISE, sqe, fd, NULL, (__u32) len, offset);
931+
io_uring_prep_rw(IORING_OP_FADVISE, sqe, fd, NULL, __io_uring_cap_len(len), offset);
926932
sqe->fadvise_advice = (__u32) advice;
927933
}
928934

929935
IOURINGINLINE void io_uring_prep_madvise(struct io_uring_sqe *sqe, void *addr,
930936
__u32 length, int advice)
931937
{
932-
io_uring_prep_rw(IORING_OP_MADVISE, sqe, -1, addr, (__u32) length, 0);
938+
io_uring_prep_rw(IORING_OP_MADVISE, sqe, -1, addr, __io_uring_cap_len(length), 0);
933939
sqe->fadvise_advice = (__u32) advice;
934940
}
935941

@@ -951,7 +957,7 @@ IOURINGINLINE void io_uring_prep_madvise64(struct io_uring_sqe *sqe, void *addr,
951957
IOURINGINLINE void io_uring_prep_send(struct io_uring_sqe *sqe, int sockfd,
952958
const void *buf, size_t len, int flags)
953959
{
954-
io_uring_prep_rw(IORING_OP_SEND, sqe, sockfd, buf, (__u32) len, 0);
960+
io_uring_prep_rw(IORING_OP_SEND, sqe, sockfd, buf, __io_uring_cap_len(len), 0);
955961
sqe->msg_flags = (__u32) flags;
956962
}
957963

@@ -983,7 +989,7 @@ IOURINGINLINE void io_uring_prep_send_zc(struct io_uring_sqe *sqe, int sockfd,
983989
const void *buf, size_t len, int flags,
984990
unsigned zc_flags)
985991
{
986-
io_uring_prep_rw(IORING_OP_SEND_ZC, sqe, sockfd, buf, (__u32) len, 0);
992+
io_uring_prep_rw(IORING_OP_SEND_ZC, sqe, sockfd, buf, __io_uring_cap_len(len), 0);
987993
sqe->msg_flags = (__u32) flags;
988994
sqe->ioprio = zc_flags;
989995
}
@@ -1021,7 +1027,7 @@ IOURINGINLINE void io_uring_prep_sendmsg_zc_fixed(struct io_uring_sqe *sqe,
10211027
IOURINGINLINE void io_uring_prep_recv(struct io_uring_sqe *sqe, int sockfd,
10221028
void *buf, size_t len, int flags)
10231029
{
1024-
io_uring_prep_rw(IORING_OP_RECV, sqe, sockfd, buf, (__u32) len, 0);
1030+
io_uring_prep_rw(IORING_OP_RECV, sqe, sockfd, buf, __io_uring_cap_len(len), 0);
10251031
sqe->msg_flags = (__u32) flags;
10261032
}
10271033

@@ -1131,7 +1137,7 @@ IOURINGINLINE void io_uring_prep_provide_buffers(struct io_uring_sqe *sqe,
11311137
void *addr, int len, int nr,
11321138
int bgid, int bid)
11331139
{
1134-
io_uring_prep_rw(IORING_OP_PROVIDE_BUFFERS, sqe, nr, addr, (__u32) len,
1140+
io_uring_prep_rw(IORING_OP_PROVIDE_BUFFERS, sqe, nr, addr, __io_uring_cap_len(len),
11351141
(__u64) bid);
11361142
sqe->buf_group = (__u16) bgid;
11371143
}

0 commit comments

Comments
 (0)