From 9c639de68202ecbf56634ff3b779fa31830ad170 Mon Sep 17 00:00:00 2001 From: markj Date: Tue, 16 Jul 2019 16:28:50 +0000 Subject: [PATCH] Use a platform-independent constant for PKG_MAX_SIZE. This constant determines the number of rights libnv will attempt to transmit in a given control message. In practice, the upper limit defined by the kernel is machine-dependent and is smaller on 64-bit kernels than on 32-bit kernels. To ensure that a 32-bit libnv works as expected when run on a 64-bit kernel, use a limit that will work on both 32-bit and 64-bit kernels. PR: 238511 Discussed with: oshogbo MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D20942 --- lib/libnv/msgio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/libnv/msgio.c b/lib/libnv/msgio.c index ee64ce8c8609..7cec4c898f04 100644 --- a/lib/libnv/msgio.c +++ b/lib/libnv/msgio.c @@ -63,7 +63,13 @@ __FBSDID("$FreeBSD$"); /* Linux: arbitrary size, but must be lower than SCM_MAX_FD. */ #define PKG_MAX_SIZE ((64U - 1) * CMSG_SPACE(sizeof(int))) #else -#define PKG_MAX_SIZE (MCLBYTES / CMSG_SPACE(sizeof(int)) - 1) +/* + * To work around limitations in 32-bit emulation on 64-bit kernels, use a + * machine-independent limit on the number of FDs per message. Each control + * message contains 1 FD and requires 12 bytes for the header, 4 pad bytes, + * 4 bytes for the descriptor, and another 4 pad bytes. + */ +#define PKG_MAX_SIZE (MCLBYTES / 24) #endif static int