The macOS Concept Journey — Mach
In general, Mach is a kernel which was developed at CMU (Carnegie Mellon University) by both Richard Rashid and Avie Tevanian. The project ran at CMU from 1985 till 1994, ending with Mach 3.0. Mach’s derivatives are the basis of the OS “GNU Hurd” and Apple’s OSes like: macOS, iOS, iPadOS, tvOS and WatchOS (https://en.wikipedia.org/wiki/Mach_(kernel)).
Overall, the fundamental services and primitives of XNU (https://medium.com/@boutnaru/the-macos-concept-journey-xnu-x-is-not-unix-33c802368914) are based on Mach 3.0. Apple has modified and extended it to meet macOS functional/performance requirements. Mach is linked with other kernel components as part of XNU (more on that in future writeups), the reason for that is to avoid RPC between them for increased performance (https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/Mach/Mach.html).
Moreover, Mach provides different capabilities including: object based communication channels, parallel execution (including support for SMP), scheduling framework, IPC, memory management with virtual memory support security and resource management (https://papers.put.as/papers/macosx/2000/10.1.1.34.9641.pdf).
Thus, there are seven kernel abstractions that Mach provides that we should know about: “Task”, “Thread”, “Address Space”, “Memory Object”, “Port”, “IPC” and “Time” (https://papers.put.as/papers/macosx/2000/10.1.1.34.9641.pdf). “Task”, which is the unit of resource ownership (https://github.com/apple/darwin-xnu/blob/main/osfmk/kern/task.c). “Thread”, the unit of CPU execution (https://github.com/apple/darwin-xnu/blob/main/osfmk/kern/thread.c). “Address Space”, responsible for virtual addressing and shared memory (https://github.com/apple/darwin-xnu/blob/main/osfmk/vm/vm_map.h). “Memory Object”, which is the internal unit of memory management (https://github.com/apple/darwin-xnu/blob/main/osfmk/vm/memory_object.c).
“Port”, is a secure simplex communication channel (https://github.com/apple/darwin-xnu/blob/main/osfmk/mach/port.h). “IPC”, which includes messages queues, RPC (Remote Procedure Call), semaphores, notifications and lock sets (https://github.com/apple/darwin-xnu/tree/main/osfmk/ipc). “Time”, which is clocks, timers and waiting (https://github.com/apple/darwin-xnu/blob/main/osfmk/mach/mach_time.h).
Lastly, although Mach is considered as microkernel, XNU does not use it like that as we have both BSD and I/O kit run in the same level (https://www.vitadastudente.it/2011/02/10/xnu-kernel-mac-os-x/) — as also shown in the diagram below. See you in my next writeup ;-) You can follow me on twitter — @boutnaru (https://twitter.com/boutnaru). Also, you can read my other writeups on medium — https://medium.com/@boutnaru. You can find my free eBooks at “https://TheLearningJourneyEbooks.com”.