Skip to main content

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

The Horizon class (src/Ryujinx.HLE/HOS/Horizon.cs) is the core OS emulator:
Key components:
Emulates Horizon kernel primitives:
  • Process/thread management
  • Memory management (virtual memory, page tables)
  • Synchronization objects (mutexes, events, semaphores)
  • Inter-process communication
Background threads handling service requests:
Direct memory sharing between guest and services:

Service Implementation

Service Manager (sm)

The Service Manager is the cornerstone of Horizon’s service architecture:
Common services:

IPC (Inter-Process Communication)

Ryujinx implements the Horizon IPC protocol for service communication:

IPC Message Structure

Message types:

IPC Service Handler

Base class for all service implementations:

Example Service Implementation

Attribute-based dispatch: Methods are marked with [CommandCmif(id)] for automatic IPC routing

Domain Objects

Services can be converted to “domains” for efficient object management:
Benefits:
  • 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:
Common SVCs:

Kernel Emulation

Process Management

Thread Scheduling

Scheduler implementation:
  • 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:
Memory regions:
  • Application: Game code and data
  • Applet: System applets
  • System: System modules
  • NvServices: GPU/multimedia

Applet System

Emulates Switch’s overlay applet system:
Implemented applets:

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:
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

  • Method reflection cached at service creation
  • Direct C# method invocation (no marshaling)
  • Typical IPC latency: 1-5 microseconds
  • Zero-copy for shared memory regions
  • Direct pointer access for mapped buffers
  • Efficient for HID, graphics, audio data
  • Server threads handle IPC asynchronously
  • Guest threads scheduled by kernel emulator
  • Synchronization primitives map to host OS

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 class
  • src/Ryujinx.HLE/HOS/Services/IpcService.cs:14 - IPC service base
  • src/Ryujinx.HLE/HOS/Ipc/IpcMessage.cs - IPC message structure
  • src/Ryujinx.HLE/HOS/Kernel/ - Kernel emulation
  • src/Ryujinx.HLE/HOS/Services/ - All service implementations