Mach is the name of the foundational component of the XNU kernel, common to macOS, iOS, tvOS and watchOS. Originally developed by CMU, it was adopted by NeXTSTEP, and integrated into macOS (formally known as Mac OS X) when the former merged with Apple. Though largely undocumented, Mach APIs make up the core of XNU's IPC, scheduling and memory management, supplementing the more widely known POSIX APIs offered in Darwin.
Questions tagged [mach]
159 questions
6
votes
1 answer
Locate __proc_info symbol in XNU project
I'd like to figure out how does VMMAP process operates.
After running this executable with dtrace, it seems that the method proc_regionfilename that extract the address space of each section in the virtual memory.
So, I dug a little deeper, and…

Zohar81
- 4,554
- 5
- 29
- 82
6
votes
1 answer
How do I recover from EXC_BAD_ACCESS?
I'm intentionally causing an EXC_BAD_ACCESS. By triggering a write to an NSObject in a read-only virtual memory page. Ideally, I'd like to catch EXC_BAD_ACCESS, mark the virtual memory page as read-write and have execution continue as it normally…

Heath Borders
- 30,998
- 16
- 147
- 256
5
votes
1 answer
"__CFRunLoopModeFindSourceForMachPort returned NULL" messages when using AVAudioPlayer
We're working on a SpriteKit game. In order to have more control over sound effects, we switched from using SKAudioNodes to having some AVAudioPlayers. While everything seems to be working well in terms of game play, frame rate, and sounds, we're…

bg2b
- 1,939
- 2
- 11
- 18
5
votes
2 answers
How to set the host exception port using the Mach kernel on macOS?
I want to use Mach Exception Ports to handle exceptions for all tasks (processes) running on macOS. My understanding is that host_set_exception_ports is to be used in this case. However, host_set_exception_ports returns KERN_NO_ACCESS (error code 8)…

Jan Deinhard
- 19,645
- 24
- 81
- 137
5
votes
1 answer
x86_64 assembly exit system call parameter on macOS Mojave?
I have the following file:
; hello.s
.section __TEXT,__text
.globl _main
_main:
movl $0x2000001, %eax
movl $42, %ebx
syscall
I try to run it as follows:
# run.sh
as -mmacosx-version-min=10.9 hello.s -o hello.o
ld -macosx_version_min…

OregonTrail
- 8,594
- 7
- 43
- 58
4
votes
1 answer
Using Mach semaphores as a replacement of inter-process anonymous semaphores
I want to use anonymous semaphores in shared memory to synchronise multiple processes.
While multiple POSIX operating systems provide anonymous semaphores (through sem_init and associated functions), macOS doesn't support them.
I discovered that the…

Pop Flamingo
- 3,023
- 2
- 26
- 64
4
votes
1 answer
NSMachBootstrapServer is deprecated, how can NSXPCConnection be used to register a Mach Service?
I need to write a Mach Service that both my app and a system plugin can talk to, I use the NSMachPort API to create a new port, then register it with NSMachBootstrapServer:
- (void) run
{
NSMachPort *serverPort = (NSMachPort *)[NSMachPort…

alfwatt
- 2,010
- 2
- 18
- 29
4
votes
1 answer
How should I go about debugging a Mach port leak?
I have a server written in c++ that leaks Mach ports when run on osx. Specifically, when running top I noticed that it had around 50000 (under #PORTS) . Curiously, I left it running overnight and the next day the machine was basically dead (took…

Bwmat
- 4,314
- 3
- 27
- 42
4
votes
2 answers
Pass mach port to child process
I'm trying to pass a mach port to a child process created with fork on Mac OSX. I saw this SO question Sharing Mach ports with child processes but it doesn't have a solution it just describes the problem. Looking at this site…

2trill2spill
- 1,333
- 2
- 20
- 41
4
votes
4 answers
What's the difference between mach_vm_allocate and vm_allocate?
I would like to know what's the difference betweenmach_vm_allocate and vm_allocate. I know mach_vm_allocate is only available in OS X and not iOS, but I'm not sure why. The file that has all the function prototypes in for the mach_vm_... functions…

Roberto
- 3,487
- 1
- 22
- 24
3
votes
1 answer
Getting information that vmmap gets with a program on Mac OS
I was trying to print all the memory regions of a process using the mach_vm_region and it seemed to work fine but when I compared it to the vmmap command vmmap -v -interleaved , I realized that I was still missing many memory regions.
For…

Aayush
- 84
- 1
- 9
3
votes
1 answer
Given a mach_header how do I find the binary image name?
I'm investigating the Mach dynamic linker dyld. This question applies to all Apple platforms but happy for an answer to be platform specific; I'm using ObjC but also happy to translate Swift if that works for you. The relevant Apple docs can be…

Robin Macharg
- 1,468
- 14
- 22
3
votes
1 answer
Converting mach_absolute_time to (nano)seconds in iOS (objective-C)
I am trying to write a helper method in iOS to allow me to use mach_absolute_time() into seconds (or nanoseconds), so that I can find the time derivative incoming device sensor data. Here is my attempt:
#include
- (double)…

davwillev
- 83
- 10
3
votes
0 answers
how to check if a class has its meta class definition in mach-o file
So I am learning mach-o file.
Now I was able to tell how to map a pointer to a class struct, but I found that, if I use otool, sometimes it will print out something has meta class:
00000001000990d8 0x1000b75c8
isa 0x1000b75f0
…

Wingzero
- 9,644
- 10
- 39
- 80
3
votes
2 answers
Mac kernel programming generic kernel extension prinf() not working
I've followed the Creating a Generic Kernel Extension with Xcode tutorial.
MyKext.c:
#include
#include
kern_return_t MyKext_start (kmod_info_t * ki, void * d)
{
printf("MyKext has started.\n");
return…

sleepy_dog
- 277
- 1
- 2
- 11