Make __mach_msg_destroy portable for x86_64

Message ID ZE3aPH7uCEDti47H@jupiter.tail36e24.ts.net
State Committed, archived
Headers
Series Make __mach_msg_destroy portable for x86_64 |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Flavio Cruz April 30, 2023, 3:02 a.m. UTC
  We need to align on uintptr_t to make this work for x86_64, 
otherwise things will go wrong when RPCs return errors.
---
 mach/msg-destroy.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
  

Comments

Samuel Thibault April 30, 2023, 10:54 p.m. UTC | #1
Applied, thanks!

Flavio Cruz, le sam. 29 avril 2023 23:02:20 -0400, a ecrit:
> We need to align on uintptr_t to make this work for x86_64, 
> otherwise things will go wrong when RPCs return errors.
> ---
>  mach/msg-destroy.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/mach/msg-destroy.c b/mach/msg-destroy.c
> index 7429ecbc2d..0a8b46c895 100644
> --- a/mach/msg-destroy.c
> +++ b/mach/msg-destroy.c
> @@ -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);
> -- 
> 2.39.2
>
  

Patch

diff --git a/mach/msg-destroy.c b/mach/msg-destroy.c
index 7429ecbc2d..0a8b46c895 100644
--- a/mach/msg-destroy.c
+++ b/mach/msg-destroy.c
@@ -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);