Overview
Ryujinx uses High-Level Emulation (HLE) to simulate Nintendo Switch system services and the Horizon operating system. Instead of emulating the entire OS at the binary level, HLE reimplements OS functionality in C#, providing:Performance
Direct C# implementations are faster than emulating ARM OS code
Compatibility
Handles version differences and missing firmware gracefully
Features
Enhanced functionality beyond real hardware (save states, cheats, mods)
Horizon OS Emulation
System Architecture
TheHorizon class (src/Ryujinx.HLE/HOS/Horizon.cs) is the core OS emulator:
Kernel Context
Kernel Context
Emulates Horizon kernel primitives:
- Process/thread management
- Memory management (virtual memory, page tables)
- Synchronization objects (mutexes, events, semaphores)
- Inter-process communication
System Servers
System Servers
Background threads handling service requests:
Service Implementation
Service Manager (sm)
The Service Manager is the cornerstone of Horizon’s service architecture:- System Services
- Audio Services
- Network Services
- Other Services
IPC (Inter-Process Communication)
Ryujinx implements the Horizon IPC protocol for service communication:IPC Message Structure
IPC Service Handler
Base class for all service implementations:Example Service Implementation
Attribute-based dispatch: Methods are marked with
[CommandCmif(id)] for automatic IPC routingDomain Objects
Services can be converted to “domains” for efficient object management:- Multiple service objects per session
- Efficient handle management
- Reduced IPC overhead
System Call Interface
SVC (Supervisor Call) Handling
When guest code executes an SVC instruction:- Memory
- Synchronization
- Threading
- IPC
Kernel Emulation
Process Management
Thread Scheduling
- Preemptive multitasking
- Priority-based scheduling (0-63, lower is higher priority)
- Round-robin within priority levels
- Thread affinity to CPU cores
Memory Management
Kernel memory manager handles:- Application: Game code and data
- Applet: System applets
- System: System modules
- NvServices: GPU/multimedia
Applet System
Emulates Switch’s overlay applet system:Software Keyboard
On-screen keyboard for text input
- Inline and full-screen modes
- Text validation
- Dictionary suggestions
Player Select
User account selection
- Shows configured user profiles
- Icon and nickname display
Error Display
Error message dialogs
- Error code formatting
- Custom error messages
Controller Config
Controller configuration
- Button remapping
- Controller order
File System Services
Virtual file system with multiple mount points:@SystemContent: System firmware@UserContent: User installed content@SdCard: SD card access@CalibFile: Calibration data@User: User partition
Service Context
Passed to all service methods:Result Codes
Horizon uses result codes for error handling:Performance Considerations
IPC Overhead
IPC Overhead
- Method reflection cached at service creation
- Direct C# method invocation (no marshaling)
- Typical IPC latency: 1-5 microseconds
Memory Sharing
Memory Sharing
- Zero-copy for shared memory regions
- Direct pointer access for mapped buffers
- Efficient for HID, graphics, audio data
Threading
Threading
- Server threads handle IPC asynchronously
- Guest threads scheduled by kernel emulator
- Synchronization primitives map to host OS
Related Topics
ARMeilleure
How guest code interfaces with HLE services
Graphics Subsystem
NVDRV service and GPU command handling
Audio Subsystem
Audio renderer service implementation
Input System
HID service and controller emulation
Source Code Reference
src/Ryujinx.HLE/HOS/Horizon.cs:45- Main Horizon OS classsrc/Ryujinx.HLE/HOS/Services/IpcService.cs:14- IPC service basesrc/Ryujinx.HLE/HOS/Ipc/IpcMessage.cs- IPC message structuresrc/Ryujinx.HLE/HOS/Kernel/- Kernel emulationsrc/Ryujinx.HLE/HOS/Services/- All service implementations