Crate nx

Crate nx 

Source
Expand description

Userland library for Nintendo Switch homebrew (and other potential purposes), written in pure Rust and some assembly bits

§Features

This library covers a lot of different modules, wrappers, etc. so some of them (essentially those which can be opt-in) are separated as optional features:

  • services: Enables custom client-IPC service implementations, AKA the nx::service module

  • smc: Enables secure-monitor support, AKA the nx::smc module

  • gpu: Enables graphics support, AKA the nx::gpu module (also enables services)

  • console: Enables console support, AKA the nx::console module (also enables canvas and the font8x8 dependency)

  • vty: Enables virtual tty support, AKA, the nx::console::vty module (also enables console as well as the dependencies embedded-term and embedded-graphics-core)

  • fs: Enables support for this library’s FS implementation, aka the nx::fs module (also enables services)

  • input: Enables input support, AKA the nx::input module (also enables services)

  • la: Enables library applet support, AKA the nx::la module (also enables services)

  • rand: Enables pseudo-RNG support, AKA the nx::rand module (also enables services)

  • socket : Enables std-like network support, AKA the nx::socket module (also enables services)

  • applet : Enables applet service support, AKA the nx::applet module (also enables services)

  • mii : Enables mii support, AKA the nx::mii module (also enables services)

Note that most of these features/modules are just simplified and easy-to-use wrappers around IPC/raw system features, so not using them doesn’t fully block those features (for instance, you could use services using IPC commands more directly without the services feature).

§Contributing

You can always contribute to these libraries, report bugs, etc. at their repository

§Examples

Library examples are located at this other repository

Modules§

applet
AppletAE/AppletOE Support
arm
ARM support and utils
console
Console Services
diag
Diagnostics (logging and aborting) support
elf
ELF (aarch64) support and utils
exception
Exception handling support (stubbed for now).
fs
FileSystem support
gpu
Graphics and GPU support and utils
hbl
HBL (homebrew loader) ABI support and utils
input
Input utils and wrappers
ipc
Contains the machinery for Horizon OS’s IPC interface
la
Library applet support and utils
macros
Library macros
mem
Memory (heap) support and utils
mii
Mii Support
rand
Pseudo-RNG support
rc
Generic library result definitions
result
Common result support
rrt0
Initial code/entrypoint support and utils
service
Base service/named port support and wrappers
smc
Secure monitor support and wrappers
socket
Implementation of the Rust libstd TCP/UDP APIs, and re-exports of the raw bsd sockets API.
svc
This module wraps svc calls provided by asm.rs. There is generally no function-level Safety docs, but the core requirement is that all raw pointers provided must be validated by the caller.
sync
Synchronization support and utils
thread
Threading support and wrappers
util
Common library utilities
version
System version utils
vmem
Virtual memory support
wait
Sync/waiting utilities and wrappers

Macros§

acquire
align_up
Aligns a value up based on the provided alignment which should be a power of two.
alloc_set_default_heap_size
Defines the default heap size of the current project
api_mark_request_command_parameters_types_as_copy
bit
Gets a value corresponding to the given bit
bit_group
Constructs a define_bit_set type value from various flags
client_mark_request_command_parameters_types_as_copy
cur_fn_name
Gets the current function name
define_bit_set
Defines a type meant to serve as a bitflag set with enum-like API
diag_assert
diag_log
diag_log_assert
diag_result_code_log_assert
diag_result_log_assert
ipc_client_define_client_default
Simplifies the creation of a (client-side IPC) type implementing an IPC interface, without implementing the trait or IPC serialization
ipc_client_send_control_command
Identical to ipc_client_send_request_command but for a “Control” command
ipc_client_send_request_command
Sends an IPC “Request” command
ipc_sf_define_control_interface_trait
Identical to ipc_sf_define_interface_trait but for “Control” IPC interfaces (inner trait functionality differs)
ipc_sf_define_default_client_for_interface
Simplifies the creation of a (client-side IPC) type implementing an IPC interface (and implementing the trait)
ipc_sf_define_interface_trait
Defines a trait meant to be used for IPC interfaces
is_aligned
Checks if the provided value is aligned to the provided alignment
read_bits
Reads bits from a given value
result_define
Creates a result definition
result_define_group
Creates a group of result definitions (all under the same module)
result_define_subgroup
Creates a group of result definitions (all under the same module and submodule)
result_return_if
Returns a given result if the given condition is true
result_return_unless
Returns a given result unless the given condition is true
result_try
Wraps and returns a given result if it’s not successful
rrt0_define_default_module_name
Defines the (runtime) module name of the current project as the package name
rrt0_define_module_name
Defines the (runtime) module name of the current project
rrt0_initialize_heap
Defines a default heap initialization function for NROs (homebrew loaded apps)
server_mark_request_command_parameters_types_as_copy
session_type
write_bits
Writes bits into a given value