summaryrefslogtreecommitdiff
path: root/ipc
diff options
context:
space:
mode:
authorLuca Dariz <luca@orpolo.org>2022-06-28 12:10:45 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-08-28 03:32:11 +0200
commit286ae33f3b02045491e651326aaf544db3ace4ad (patch)
treeb76d8e0fb553e2fa60111ce0f72f5e183f1e4365 /ipc
parent8c58257c4da364ffcb797f9d454c37de939a052b (diff)
kmsg: fix msg body alignment
* ipc/ipc_kmsg.c: align msg body to 4 bytes as done in mig Signed-off-by: Luca Dariz <luca@orpolo.org> Message-Id: <20220628101054.446126-7-luca@orpolo.org>
Diffstat (limited to 'ipc')
-rw-r--r--ipc/ipc_kmsg.c49
1 files changed, 22 insertions, 27 deletions
diff --git a/ipc/ipc_kmsg.c b/ipc/ipc_kmsg.c
index 292aa569..cf7ec77d 100644
--- a/ipc/ipc_kmsg.c
+++ b/ipc/ipc_kmsg.c
@@ -68,9 +68,10 @@
#include <ipc/ipc_print.h>
#endif
-#define is_misaligned(x) ( ((vm_offset_t)(x)) & (sizeof(vm_offset_t)-1) )
-#define ptr_align(x) \
- ( ( ((vm_offset_t)(x)) + (sizeof(vm_offset_t)-1) ) & ~(sizeof(vm_offset_t)-1) )
+/* msg body is always aligned to 4 bytes */
+#define msg_is_misaligned(x) ( ((vm_offset_t)(x)) & (sizeof(uint32_t)-1) )
+#define msg_align(x) \
+ ( ( ((vm_offset_t)(x)) + (sizeof(uint32_t)-1) ) & ~(sizeof(uint32_t)-1) )
ipc_kmsg_t ipc_kmsg_cache[NCPUS];
@@ -232,8 +233,8 @@ ipc_kmsg_clean_body(
if (((mach_msg_type_t*)type)->msgt_longform) {
/* This must be aligned */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
- (is_misaligned(type))) {
- saddr = ptr_align(saddr);
+ (msg_is_misaligned(type))) {
+ saddr = msg_align(saddr);
continue;
}
name = type->msgtl_name;
@@ -250,7 +251,7 @@ ipc_kmsg_clean_body(
/* padding (ptrs and ports) ? */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
((size >> 3) == sizeof(natural_t)))
- saddr = ptr_align(saddr);
+ saddr = msg_align(saddr);
/* calculate length of data in bytes, rounding up */
@@ -393,8 +394,8 @@ xxx: type = (mach_msg_type_long_t *) eaddr;
if (((mach_msg_type_t*)type)->msgt_longform) {
/* This must be aligned */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
- (is_misaligned(type))) {
- eaddr = ptr_align(eaddr);
+ (msg_is_misaligned(type))) {
+ eaddr = msg_align(eaddr);
goto xxx;
}
name = type->msgtl_name;
@@ -411,7 +412,7 @@ xxx: type = (mach_msg_type_long_t *) eaddr;
/* padding (ptrs and ports) ? */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
((size >> 3) == sizeof(natural_t)))
- eaddr = ptr_align(eaddr);
+ eaddr = msg_align(eaddr);
/* calculate length of data in bytes, rounding up */
@@ -1324,8 +1325,8 @@ ipc_kmsg_copyin_body(
if (longform) {
/* This must be aligned */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
- (is_misaligned(type))) {
- saddr = ptr_align(saddr);
+ (msg_is_misaligned(type))) {
+ saddr = msg_align(saddr);
continue;
}
name = type->msgtl_name;
@@ -1354,7 +1355,7 @@ ipc_kmsg_copyin_body(
/* padding (ptrs and ports) ? */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
((size >> 3) == sizeof(natural_t)))
- saddr = ptr_align(saddr);
+ saddr = msg_align(saddr);
/* calculate length of data in bytes, rounding up */
@@ -1376,9 +1377,6 @@ ipc_kmsg_copyin_body(
} else {
vm_offset_t addr;
- if (sizeof(vm_offset_t) > sizeof(mach_msg_type_t))
- saddr = ptr_align(saddr);
-
if ((eaddr - saddr) < sizeof(vm_offset_t)) {
ipc_kmsg_clean_partial(kmsg, taddr, FALSE, 0);
return MACH_SEND_MSG_TOO_SMALL;
@@ -1591,8 +1589,8 @@ ipc_kmsg_copyin_from_kernel(ipc_kmsg_t kmsg)
if (longform) {
/* This must be aligned */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
- (is_misaligned(type))) {
- saddr = ptr_align(saddr);
+ (msg_is_misaligned(type))) {
+ saddr = msg_align(saddr);
continue;
}
name = type->msgtl_name;
@@ -1609,7 +1607,7 @@ ipc_kmsg_copyin_from_kernel(ipc_kmsg_t kmsg)
/* padding (ptrs and ports) ? */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
((size >> 3) == sizeof(natural_t)))
- saddr = ptr_align(saddr);
+ saddr = msg_align(saddr);
/* calculate length of data in bytes, rounding up */
@@ -2364,8 +2362,8 @@ ipc_kmsg_copyout_body(
if (longform) {
/* This must be aligned */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
- (is_misaligned(type))) {
- saddr = ptr_align(saddr);
+ (msg_is_misaligned(type))) {
+ saddr = msg_align(saddr);
continue;
}
name = type->msgtl_name;
@@ -2382,7 +2380,7 @@ ipc_kmsg_copyout_body(
/* padding (ptrs and ports) ? */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
((size >> 3) == sizeof(natural_t)))
- saddr = ptr_align(saddr);
+ saddr = msg_align(saddr);
/* calculate length of data in bytes, rounding up */
@@ -2426,9 +2424,6 @@ ipc_kmsg_copyout_body(
} else {
vm_offset_t data;
- if (sizeof(vm_offset_t) > sizeof(mach_msg_type_t))
- saddr = ptr_align(saddr);
-
data = * (vm_offset_t *) saddr;
/* copyout memory carried in the message */
@@ -2795,8 +2790,8 @@ ipc_msg_print(mach_msg_header_t *msgh)
if (longform) {
/* This must be aligned */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
- (is_misaligned(type))) {
- saddr = ptr_align(saddr);
+ (msg_is_misaligned(type))) {
+ saddr = msg_align(saddr);
continue;
}
name = type->msgtl_name;
@@ -2841,7 +2836,7 @@ ipc_msg_print(mach_msg_header_t *msgh)
/* padding (ptrs and ports) ? */
if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
((size >> 3) == sizeof(natural_t)))
- saddr = ptr_align(saddr);
+ saddr = msg_align(saddr);
/* calculate length of data in bytes, rounding up */