#include "pub_core_basics.h"
#include "pub_core_mach.h"
+#include "pub_core_libcassert.h" // vg_assert
#include <mach/mach.h>
#include <mach/machine/ndr_def.h>
extern mach_port_t mach_reply_port(void);
/* Global variables set in mach_init() */
+int vm_page_shift = 0;
vm_size_t vm_page_size = 0;
mach_port_name_t mach_task_self_ = 0;
// its own behalf, and doesn't call mig outside the semaphore
}
+void mach_msg_destroy(mach_msg_header_t *msg)
+{
+ // TODO: copy from XNU?
+}
void mig_dealloc_reply_port(mach_port_t reply_port)
{
mach_task_self_ = task_self_trap();
// GrP fixme host_page_size(host_self_trap(), &vm_page_size);
- vm_page_size = 4096;
+ vm_page_shift = 12;
+ // FIXME: stored in COMM_PAGE + 0x025, (1 << 12) = 4096
+ vm_page_size = 0x1000;
+
+ vg_assert(1 << vm_page_shift == vm_page_size);
}
#endif // defined(VGO_darwin)
#if defined(VGO_darwin)
+#include "config.h" // for DARWIN_VERS
#include "pub_core_basics.h"
#include "pub_core_mach.h"
mach_msg_timeout_t timeout,
mach_port_t notify);
-mach_msg_return_t
-mach_msg(msg, option, send_size, rcv_size, rcv_name, timeout, notify)
- mach_msg_header_t *msg;
- mach_msg_option_t option;
- mach_msg_size_t send_size;
- mach_msg_size_t rcv_size;
- mach_port_t rcv_name;
- mach_msg_timeout_t timeout;
- mach_port_t notify;
-{
+mach_msg_return_t mach_msg(
+ mach_msg_header_t *msg,
+ mach_msg_option_t option,
+ mach_msg_size_t send_size,
+ mach_msg_size_t rcv_size,
+ mach_port_t rcv_name,
+ mach_msg_timeout_t timeout,
+ mach_port_t notify
+) {
mach_msg_return_t mr;
/*
vki_uint8_t *linker_entry; // dylinker entry point
Addr linker_offset; // dylinker text offset
vki_size_t max_addr; // biggest address reached while loading segments
+ Addr text_slide; // slide of the text segment because of "ASLR" (arm64-only)
} load_info_t;
static void print(const HChar *str)
vki_size_t vmsize; // page-aligned
vki_size_t vmend; // page-aligned
unsigned int prot;
- Addr slided_addr = segcmd->vmaddr + out_info->linker_offset;
+ Addr slided_addr = segcmd->vmaddr + out_info->linker_offset + out_info->text_slide;
// GrP fixme mark __UNIXSTACK as SF_STACK
linker_info.entry = NULL;
linker_info.linker_entry = NULL;
linker_info.linker_offset = 0;
+ linker_info.text_slide = 0;
linker_info.max_addr = out_info->max_addr;
if (dycmd->name.offset >= dycmd->cmdsize) {
// GrP fixme check more carefully for matching fat arch?
- return (len >= VKI_PAGE_SIZE &&
+ return (len >= sizeof(*magic) &&
(*magic == MAGIC || *magic == VG_(ntohl)(FAT_MAGIC)))
? True : False;
}
load_info.linker_entry = NULL;
load_info.linker_offset = 0;
load_info.max_addr = 0;
+ load_info.text_slide = 0;
err = VG_(fstat)(fd, &sb);
if (err) {
info->text = (Addr) load_info.text;
info->dynamic = load_info.linker_entry ? True : False;
+ if (!info->dynamic && load_info.text_slide) {
+ print("cannot slide static executables\n");
+ return VKI_ENOEXEC;
+ }
+
info->executable_path = VG_(strdup)("ume.macho.executable_path", name);
SysRes res = VG_(dup)(fd);