diff options
author | Flavio Cruz <flaviocruz@gmail.com> | 2023-02-12 18:54:58 -0500 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2023-02-13 01:00:32 +0100 |
commit | ea2646b6d6f2dc02a59a2693d08957596c84e9d3 (patch) | |
tree | 7a6c0e61eec61c4b7231fd2f35ff6c226b53b5c5 /x86_64 | |
parent | 7170cfbfb70cdce12ea6ec6697ed95c557aa1989 (diff) | |
download | gnumach-ea2646b6d6f2dc02a59a2693d08957596c84e9d3.tar.gz gnumach-ea2646b6d6f2dc02a59a2693d08957596c84e9d3.tar.bz2 gnumach-ea2646b6d6f2dc02a59a2693d08957596c84e9d3.zip |
Make mach_msg_header_t have the same size for both 64 bit kernel and userland.
This has several advantages:
1) We don't need to resize mach_msg_header_t, it is just a copy.
2) Mig won't require any changes because it statically computes the size
of mach_msg_header_t, otherwise we would need two sizes (28 vs 32 bytes).
Message-Id: <Y+l8UhXXX9Qo9tVA@jupiter.tail36e24.ts.net>
Diffstat (limited to 'x86_64')
-rw-r--r-- | x86_64/copy_user.c | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/x86_64/copy_user.c b/x86_64/copy_user.c index ae062645..dd9fe2d7 100644 --- a/x86_64/copy_user.c +++ b/x86_64/copy_user.c @@ -177,29 +177,24 @@ int copyinmsg (const void *userbuf, void *kernelbuf, const size_t usize) const mach_msg_user_header_t *umsg = userbuf; mach_msg_header_t *kmsg = kernelbuf; +#ifdef USER32 if (copyin(&umsg->msgh_bits, &kmsg->msgh_bits, sizeof(kmsg->msgh_bits))) return 1; /* kmsg->msgh_size is filled in later */ if (copyin_port(&umsg->msgh_remote_port, &kmsg->msgh_remote_port)) return 1; -#ifdef USER32 - /* This could contain a payload, but for 32 bits it will be the same size as a mach_port_name_t */ - _Static_assert(sizeof(rpc_uintptr_t) == sizeof(mach_port_name_t), - "rpc_uintptr_t and mach_port_name_t expected to have the same size"); if (copyin_port(&umsg->msgh_local_port, &kmsg->msgh_local_port)) return 1; -#else - /* For pure 64 bits, the protected payload is as large as a port pointer. */ - _Static_assert(sizeof(rpc_uintptr_t) == sizeof(mach_port_t), - "rpc_uintptr_t and mach_port_t expected to have the same size"); - if (copyin((char*)umsg + offsetof(mach_msg_user_header_t, msgh_local_port), - (char*)kmsg + offsetof(mach_msg_header_t, msgh_local_port), - sizeof(rpc_uintptr_t))) - return 1; -#endif if (copyin(&umsg->msgh_seqno, &kmsg->msgh_seqno, sizeof(kmsg->msgh_seqno) + sizeof(kmsg->msgh_id))) return 1; +#else + /* The 64 bit interface ensures the header is the same size, so it does not need any resizing. */ + _Static_assert(sizeof(mach_msg_header_t) == sizeof(mach_msg_user_header_t), + "mach_msg_header_t and mach_msg_user_header_t expected to be of the same size"); + if (copyin(&umsg, &kmsg, sizeof(mach_msg_header_t))) + return 1; +#endif vm_offset_t usaddr, ueaddr, ksaddr; ksaddr = (vm_offset_t)(kmsg + 1); @@ -283,25 +278,21 @@ int copyoutmsg (const void *kernelbuf, void *userbuf, const size_t ksize) { const mach_msg_header_t *kmsg = kernelbuf; mach_msg_user_header_t *umsg = userbuf; - +#ifdef USER32 if (copyout(&kmsg->msgh_bits, &umsg->msgh_bits, sizeof(kmsg->msgh_bits))) return 1; /* umsg->msgh_size is filled in later */ if (copyout_port(&kmsg->msgh_remote_port, &umsg->msgh_remote_port)) return 1; -#ifdef USER32 if (copyout_port(&kmsg->msgh_local_port, &umsg->msgh_local_port)) return 1; -#else - /* Handle protected payloads correctly, same as copyinmsg. */ - if (copyout((char*)kmsg + offsetof(mach_msg_header_t, msgh_local_port), - (char*)umsg + offsetof(mach_msg_user_header_t, msgh_local_port), - sizeof(rpc_uintptr_t))) - return 1; -#endif if (copyout(&kmsg->msgh_seqno, &umsg->msgh_seqno, sizeof(kmsg->msgh_seqno) + sizeof(kmsg->msgh_id))) return 1; +#else + if (copyout(&kmsg, &umsg, sizeof(mach_msg_header_t))) + return 1; +#endif /* USER32 */ vm_offset_t ksaddr, keaddr, usaddr; ksaddr = (vm_offset_t)(kmsg + 1); |