Make __mach_msg_destroy portable for x86_64
authorFlavio Cruz <flaviocruz@gmail.com>
Sun, 30 Apr 2023 03:02:20 +0000 (23:02 -0400)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 30 Apr 2023 22:54:11 +0000 (00:54 +0200)
We need to align on uintptr_t to make this work for x86_64,
otherwise things will go wrong when RPCs return errors.
Message-Id: <ZE3aPH7uCEDti47H@jupiter.tail36e24.ts.net>

mach/msg-destroy.c

index 7429ecbc2d78404b2fd6d05162995c723e16d7a8..0a8b46c8953dea4ab5195d08a5ea05b64bc9f317 100644 (file)
@@ -38,6 +38,7 @@
  *
  */
 
+#include <libc-pointer-arith.h>
 #if 1
 #include <mach.h>
 #else
@@ -162,9 +163,10 @@ __mach_msg_destroy (mach_msg_header_t *msg)
                    saddr += sizeof(mach_msg_type_t);
            }
 
-           /* calculate length of data in bytes, rounding up */
-           length = (((((number * size) + 7) >> 3) + sizeof (int) - 1)
-                     &~ (sizeof (int) - 1));
+           /* Calculate length of data in bytes... */
+           length = ((number * size) + 7) >> 3;
+           /* ... and round up using uintptr_t alignment */
+           length = ALIGN_UP (length, __alignof__ (uintptr_t));
 
            addr = is_inline ? saddr : * (vm_offset_t *) saddr;
 
@@ -177,7 +179,6 @@ __mach_msg_destroy (mach_msg_header_t *msg)
            }
 
            if (is_inline) {
-               /* inline data sizes round up to int boundaries */
                saddr += length;
            } else {
                mach_msg_destroy_memory(addr, length);