Build from scratch to use latest libnx

This commit is contained in:
Joey Yakimowich-Payne 2018-06-26 13:37:51 +09:00
commit 6e36262369
131 changed files with 15 additions and 11252 deletions

View file

@ -14,6 +14,8 @@ You also must have DevkitPro and switch (libnx) libraries for [Mac and Linux](ht
Simply run
```bash
# Because of a bug in nimble right now, you must install this first!
nimble install "https://github.com/jyapayne/nimgenEx#head"
nimble install
```

View file

@ -12,14 +12,15 @@ requires "nim >= 0.18.1", "https://github.com/jyapayne/nimgenEx#head"
requires "https://github.com/jyapayne/switch-build#head"
task setup, "Download and generate bindings":
echo "Building libnx..."
exec "nimgen libnxGen.cfg"
task buildExamples, "Build switch examples":
exec "switch_build --author='jyapayne' --version='1.0.0' examples/helloworld/helloworld.nim"
exec "switch_build --author='jyapayne' --version='1.0.0' examples/accounts/account_ex.nim"
#before install:
# setupTask()
before install:
setupTask()
task test, "Run tests":
exec "nim c -r tests/test.nim"

View file

@ -22,9 +22,12 @@ filter=lock
"${output}/nim.cfg"
[n.prepare]
gitremote = "https://github.com/switchbrew/libnx"
gitsparse = """
nx/include/*
git = "https://github.com/switchbrew/libnx"
execute = """
cd ${output}
# for listing users
curl https://patch-diff.githubusercontent.com/raw/switchbrew/libnx/pull/103.patch | git am
make
"""
[n.after]

4
nim.cfg Normal file
View file

@ -0,0 +1,4 @@
--passC="-I$PWD/src/libnx/wrapper/nx/include"
--passL="-specs=$PWD/src/libnx/wrapper/nx/switch.specs -L$PWD/src/libnx/wrapper/nx/lib -lnx"
#--passC="-I$DEVKITPRO/libnx/include"
#--passL="-specs=$DEVKITPRO/libnx/switch.specs -L$DEVKITPRO/libnx/lib -lnx"

View file

@ -1,43 +0,0 @@
import strutils
import ospaths
const headeracc = currentSourcePath().splitPath().head & "/nx/include/switch/services/acc.h"
import libnx/ext/integer128
import libnx/wrapper/types
import libnx/wrapper/sm
type
AccountProfile* {.importc: "AccountProfile", header: headeracc, bycopy.} = object
s* {.importc: "s".}: Service
AccountUserData* {.importc: "AccountUserData", header: headeracc, bycopy.} = object
unk_x0* {.importc: "unk_x0".}: uint32
iconID* {.importc: "iconID".}: uint32
iconBackgroundColorID* {.importc: "iconBackgroundColorID".}: uint8
unk_x9* {.importc: "unk_x9".}: array[0x00000007, uint8]
miiID* {.importc: "miiID".}: array[0x00000010, uint8]
unk_x20* {.importc: "unk_x20".}: array[0x00000060, uint8]
AccountProfileBase* {.importc: "AccountProfileBase", header: headeracc, bycopy.} = object
userID* {.importc: "userID".}: u128
lastEditTimestamp* {.importc: "lastEditTimestamp".}: uint64
username* {.importc: "username".}: array[0x00000020, char]
proc accountInitialize*(): Result {.cdecl, importc: "accountInitialize",
header: headeracc.}
proc accountExit*() {.cdecl, importc: "accountExit", header: headeracc.}
proc accountGetService*(): ptr Service {.cdecl, importc: "accountGetService",
header: headeracc.}
proc accountGetActiveUser*(userID: ptr u128; account_selected: ptr bool): Result {.
cdecl, importc: "accountGetActiveUser", header: headeracc.}
proc accountGetProfile*(`out`: ptr AccountProfile; userID: u128): Result {.cdecl,
importc: "accountGetProfile", header: headeracc.}
proc accountProfileGet*(profile: ptr AccountProfile; userdata: ptr AccountUserData;
profilebase: ptr AccountProfileBase): Result {.cdecl,
importc: "accountProfileGet", header: headeracc.}
proc accountProfileGetImageSize*(profile: ptr AccountProfile; image_size: ptr csize): Result {.
cdecl, importc: "accountProfileGetImageSize", header: headeracc.}
proc accountProfileLoadImage*(profile: ptr AccountProfile; buf: pointer; len: csize;
image_size: ptr csize): Result {.cdecl,
importc: "accountProfileLoadImage", header: headeracc.}
proc accountProfileClose*(profile: ptr AccountProfile) {.cdecl,
importc: "accountProfileClose", header: headeracc.}

View file

@ -1,12 +0,0 @@
import strutils
import ospaths
const headerapm = currentSourcePath().splitPath().head & "/nx/include/switch/services/apm.h"
import libnx/wrapper/types
proc apmInitialize*(): Result {.cdecl, importc: "apmInitialize", header: headerapm.}
proc apmExit*() {.cdecl, importc: "apmExit", header: headerapm.}
proc apmSetPerformanceConfiguration*(PerformanceMode: uint32;
PerformanceConfiguration: uint32): Result {.
cdecl, importc: "apmSetPerformanceConfiguration", header: headerapm.}
proc apmGetPerformanceConfiguration*(PerformanceMode: uint32;
PerformanceConfiguration: ptr uint32): Result {.
cdecl, importc: "apmGetPerformanceConfiguration", header: headerapm.}

View file

@ -1,54 +0,0 @@
import strutils
import ospaths
const headerapplet = currentSourcePath().splitPath().head & "/nx/include/switch/services/applet.h"
import libnx/wrapper/types
type
AppletType* {.size: sizeof(cint).} = enum
AppletType_None = -2, AppletType_Default = -1, AppletType_Application = 0,
AppletType_SystemApplet = 1, AppletType_LibraryApplet = 2,
AppletType_OverlayApplet = 3, AppletType_SystemApplication = 4
AppletOperationMode* {.size: sizeof(cint).} = enum
AppletOperationMode_Handheld = 0, AppletOperationMode_Docked = 1
AppletHookType* {.size: sizeof(cint).} = enum
AppletHookType_OnFocusState = 0, AppletHookType_OnOperationMode,
AppletHookType_OnPerformanceMode, AppletHookType_Max
AppletHookFn* = proc (hook: AppletHookType; param: pointer) {.cdecl.}
type
AppletHookCookie* {.importc: "AppletHookCookie", header: headerapplet, bycopy.} = object
next* {.importc: "next".}: ptr AppletHookCookie
callback* {.importc: "callback".}: AppletHookFn
param* {.importc: "param".}: pointer
proc appletInitialize*(): Result {.cdecl, importc: "appletInitialize",
header: headerapplet.}
proc appletExit*() {.cdecl, importc: "appletExit", header: headerapplet.}
proc appletGetAppletResourceUserId*(`out`: ptr uint64): Result {.cdecl,
importc: "appletGetAppletResourceUserId", header: headerapplet.}
proc appletNotifyRunning*(`out`: ptr uint8) {.cdecl, importc: "appletNotifyRunning",
header: headerapplet.}
proc appletCreateManagedDisplayLayer*(`out`: ptr uint64): Result {.cdecl,
importc: "appletCreateManagedDisplayLayer", header: headerapplet.}
proc appletGetDesiredLanguage*(LanguageCode: ptr uint64): Result {.cdecl,
importc: "appletGetDesiredLanguage", header: headerapplet.}
proc appletSetScreenShotPermission*(val: s32): Result {.cdecl,
importc: "appletSetScreenShotPermission", header: headerapplet.}
proc appletSetScreenShotImageOrientation*(val: s32): Result {.cdecl,
importc: "appletSetScreenShotImageOrientation", header: headerapplet.}
proc appletMainLoop*(): bool {.cdecl, importc: "appletMainLoop",
header: headerapplet.}
proc appletHook*(cookie: ptr AppletHookCookie; callback: AppletHookFn; param: pointer) {.
cdecl, importc: "appletHook", header: headerapplet.}
proc appletUnhook*(cookie: ptr AppletHookCookie) {.cdecl, importc: "appletUnhook",
header: headerapplet.}
proc appletGetOperationMode*(): uint8 {.cdecl, importc: "appletGetOperationMode",
header: headerapplet.}
proc appletGetPerformanceMode*(): uint32 {.cdecl,
importc: "appletGetPerformanceMode",
header: headerapplet.}
proc appletGetFocusState*(): uint8 {.cdecl, importc: "appletGetFocusState",
header: headerapplet.}

View file

@ -1,56 +0,0 @@
import libnx/wrapper/types
import strutils
import ospaths
const headeraudin = currentSourcePath().splitPath().head & "/nx/include/switch/services/audin.h"
import libnx/wrapper/audio
type
AudioInState* {.size: sizeof(cint).} = enum
AudioInState_Started = 0, AudioInState_Stopped = 1
type
AudioInBuffer* {.importc: "AudioInBuffer", header: headeraudin, bycopy.} = object
next* {.importc: "next".}: ptr AudioInBuffer
buffer* {.importc: "buffer".}: pointer
buffer_size* {.importc: "buffer_size".}: uint64
data_size* {.importc: "data_size".}: uint64
data_offset* {.importc: "data_offset".}: uint64
proc audinInitialize*(): Result {.cdecl, importc: "audinInitialize",
header: headeraudin.}
proc audinExit*() {.cdecl, importc: "audinExit", header: headeraudin.}
proc audinListAudioIns*(DeviceNames: cstring; DeviceNamesCount: ptr uint32): Result {.
cdecl, importc: "audinListAudioIns", header: headeraudin.}
proc audinOpenAudioIn*(DeviceNameIn: cstring; DeviceNameOut: cstring;
SampleRateIn: uint32; ChannelCountIn: uint32;
SampleRateOut: ptr uint32; ChannelCountOut: ptr uint32;
Format: ptr PcmFormat; State: ptr AudioInState): Result {.
cdecl, importc: "audinOpenAudioIn", header: headeraudin.}
proc audinGetAudioInState*(State: ptr AudioInState): Result {.cdecl,
importc: "audinGetAudioInState", header: headeraudin.}
proc audinStartAudioIn*(): Result {.cdecl, importc: "audinStartAudioIn",
header: headeraudin.}
proc audinStopAudioIn*(): Result {.cdecl, importc: "audinStopAudioIn",
header: headeraudin.}
proc audinAppendAudioInBuffer*(Buffer: ptr AudioInBuffer): Result {.cdecl,
importc: "audinAppendAudioInBuffer", header: headeraudin.}
proc audinGetReleasedAudioInBuffer*(Buffer: ptr ptr AudioInBuffer;
ReleasedBuffersCount: ptr uint32): Result {.cdecl,
importc: "audinGetReleasedAudioInBuffer", header: headeraudin.}
proc audinContainsAudioInBuffer*(Buffer: ptr AudioInBuffer;
ContainsBuffer: ptr bool): Result {.cdecl,
importc: "audinContainsAudioInBuffer", header: headeraudin.}
proc audinCaptureBuffer*(source: ptr AudioInBuffer; released: ptr ptr AudioInBuffer): Result {.
cdecl, importc: "audinCaptureBuffer", header: headeraudin.}
proc audinWaitCaptureFinish*(released: ptr ptr AudioInBuffer;
released_count: ptr uint32; timeout: uint64): Result {.cdecl,
importc: "audinWaitCaptureFinish", header: headeraudin.}
proc audinGetSampleRate*(): uint32 {.cdecl, importc: "audinGetSampleRate",
header: headeraudin.}
proc audinGetChannelCount*(): uint32 {.cdecl, importc: "audinGetChannelCount",
header: headeraudin.}
proc audinGetPcmFormat*(): PcmFormat {.cdecl, importc: "audinGetPcmFormat",
header: headeraudin.}
proc audinGetDeviceState*(): AudioInState {.cdecl, importc: "audinGetDeviceState",
header: headeraudin.}

View file

@ -1,9 +0,0 @@
import strutils
import ospaths
const headeraudio = currentSourcePath().splitPath().head & "/nx/include/switch/audio/audio.h"
import libnx/wrapper/types
type
PcmFormat* {.size: sizeof(cint).} = enum
PcmFormat_Invalid = 0, PcmFormat_Int8 = 1, PcmFormat_Int16 = 2, PcmFormat_Int24 = 3,
PcmFormat_Int32 = 4, PcmFormat_Float = 5, PcmFormat_Adpcm = 6

View file

@ -1,56 +0,0 @@
import libnx/wrapper/types
import strutils
import ospaths
const headeraudout = currentSourcePath().splitPath().head & "/nx/include/switch/services/audout.h"
import libnx/wrapper/audio
type
AudioOutState* {.size: sizeof(cint).} = enum
AudioOutState_Started = 0, AudioOutState_Stopped = 1
type
AudioOutBuffer* {.importc: "AudioOutBuffer", header: headeraudout, bycopy.} = object
next* {.importc: "next".}: ptr AudioOutBuffer
buffer* {.importc: "buffer".}: pointer
buffer_size* {.importc: "buffer_size".}: uint64
data_size* {.importc: "data_size".}: uint64
data_offset* {.importc: "data_offset".}: uint64
proc audoutInitialize*(): Result {.cdecl, importc: "audoutInitialize",
header: headeraudout.}
proc audoutExit*() {.cdecl, importc: "audoutExit", header: headeraudout.}
proc audoutListAudioOuts*(DeviceNames: cstring; DeviceNamesCount: ptr uint32): Result {.
cdecl, importc: "audoutListAudioOuts", header: headeraudout.}
proc audoutOpenAudioOut*(DeviceNameIn: cstring; DeviceNameOut: cstring;
SampleRateIn: uint32; ChannelCountIn: uint32;
SampleRateOut: ptr uint32; ChannelCountOut: ptr uint32;
Format: ptr PcmFormat; State: ptr AudioOutState): Result {.
cdecl, importc: "audoutOpenAudioOut", header: headeraudout.}
proc audoutGetAudioOutState*(State: ptr AudioOutState): Result {.cdecl,
importc: "audoutGetAudioOutState", header: headeraudout.}
proc audoutStartAudioOut*(): Result {.cdecl, importc: "audoutStartAudioOut",
header: headeraudout.}
proc audoutStopAudioOut*(): Result {.cdecl, importc: "audoutStopAudioOut",
header: headeraudout.}
proc audoutAppendAudioOutBuffer*(Buffer: ptr AudioOutBuffer): Result {.cdecl,
importc: "audoutAppendAudioOutBuffer", header: headeraudout.}
proc audoutGetReleasedAudioOutBuffer*(Buffer: ptr ptr AudioOutBuffer;
ReleasedBuffersCount: ptr uint32): Result {.
cdecl, importc: "audoutGetReleasedAudioOutBuffer", header: headeraudout.}
proc audoutContainsAudioOutBuffer*(Buffer: ptr AudioOutBuffer;
ContainsBuffer: ptr bool): Result {.cdecl,
importc: "audoutContainsAudioOutBuffer", header: headeraudout.}
proc audoutPlayBuffer*(source: ptr AudioOutBuffer; released: ptr ptr AudioOutBuffer): Result {.
cdecl, importc: "audoutPlayBuffer", header: headeraudout.}
proc audoutWaitPlayFinish*(released: ptr ptr AudioOutBuffer; released_count: ptr uint32;
timeout: uint64): Result {.cdecl,
importc: "audoutWaitPlayFinish", header: headeraudout.}
proc audoutGetSampleRate*(): uint32 {.cdecl, importc: "audoutGetSampleRate",
header: headeraudout.}
proc audoutGetChannelCount*(): uint32 {.cdecl, importc: "audoutGetChannelCount",
header: headeraudout.}
proc audoutGetPcmFormat*(): PcmFormat {.cdecl, importc: "audoutGetPcmFormat",
header: headeraudout.}
proc audoutGetDeviceState*(): AudioOutState {.cdecl,
importc: "audoutGetDeviceState", header: headeraudout.}

View file

@ -1,32 +0,0 @@
import strutils
import ospaths
const headerbinder = currentSourcePath().splitPath().head & "/nx/include/switch/gfx/binder.h"
import libnx/wrapper/types
const
BINDER_FIRST_CALL_TRANSACTION* = 0x00000001
type
Binder* {.importc: "Binder", header: headerbinder, bycopy.} = object
created* {.importc: "created".}: bool
initialized* {.importc: "initialized".}: bool
sessionHandle* {.importc: "sessionHandle".}: Handle
id* {.importc: "id".}: s32
nativeHandle* {.importc: "nativeHandle".}: Handle
ipcBufferSize* {.importc: "ipcBufferSize".}: csize
hasTransactAuto* {.importc: "hasTransactAuto".}: bool
proc binderCreateSession*(session: ptr Binder; sessionHandle: Handle; ID: s32) {.
cdecl, importc: "binderCreateSession", header: headerbinder.}
proc binderInitSession*(session: ptr Binder; unk0: uint32): Result {.cdecl,
importc: "binderInitSession", header: headerbinder.}
proc binderExitSession*(session: ptr Binder) {.cdecl, importc: "binderExitSession",
header: headerbinder.}
proc binderTransactParcel*(session: ptr Binder; code: uint32; parcel_data: pointer;
parcel_data_size: csize; parcel_reply: pointer;
parcel_reply_size: csize; flags: uint32): Result {.cdecl,
importc: "binderTransactParcel", header: headerbinder.}
proc binderAdjustRefcount*(session: ptr Binder; addval: s32; `type`: s32): Result {.
cdecl, importc: "binderAdjustRefcount", header: headerbinder.}
proc binderGetNativeHandle*(session: ptr Binder; unk0: uint32; handle_out: ptr Handle): Result {.
cdecl, importc: "binderGetNativeHandle", header: headerbinder.}

View file

@ -1,135 +0,0 @@
import strutils
import ospaths
const headerbuffer_producer = currentSourcePath().splitPath().head & "/nx/include/switch/gfx/buffer_producer.h"
import libnx/wrapper/types
import libnx/wrapper/binder
import libnx/wrapper/nvioctl
type
INNER_C_STRUCT_3208597589* {.importc: "no_name", header: headerbuffer_producer,
bycopy.} = object
unk_x0* {.importc: "unk_x0".}: uint32
nvmap_handle0* {.importc: "nvmap_handle0".}: uint32
unk_x8* {.importc: "unk_x8".}: uint32
unk_xc* {.importc: "unk_xc".}: uint32
unk_x10* {.importc: "unk_x10".}: uint32
unk_x14* {.importc: "unk_x14".}: uint32
unk_x18* {.importc: "unk_x18".}: uint32
unk_x1c* {.importc: "unk_x1c".}: uint32
unk_x20* {.importc: "unk_x20".}: uint32
width_unk0* {.importc: "width_unk0".}: uint32
buffer_size0* {.importc: "buffer_size0".}: uint32
unk_x2c* {.importc: "unk_x2c".}: uint32
unk_x30* {.importc: "unk_x30".}: uint32
width_unk1* {.importc: "width_unk1".}: uint32
height_unk* {.importc: "height_unk".}: uint32
flags* {.importc: "flags".}: uint32
unk_x40* {.importc: "unk_x40".}: uint32
unk_x44* {.importc: "unk_x44".}: uint32
byte_stride* {.importc: "byte_stride".}: uint32
nvmap_handle1* {.importc: "nvmap_handle1".}: uint32
buffer_offset* {.importc: "buffer_offset".}: uint32
unk_x54* {.importc: "unk_x54".}: uint32
unk_x58* {.importc: "unk_x58".}: uint32
unk_x5c* {.importc: "unk_x5c".}: uint32
unk_x60* {.importc: "unk_x60".}: uint32
unk_x64* {.importc: "unk_x64".}: uint32
unk_x68* {.importc: "unk_x68".}: uint32
buffer_size1* {.importc: "buffer_size1".}: uint32
unk_x70* {.importc: "unk_x70".}: array[0x00000033, uint32]
timestamp* {.importc: "timestamp".}: uint64
bufferProducerFence* {.importc: "bufferProducerFence",
header: headerbuffer_producer, bycopy.} = object
is_valid* {.importc: "is_valid".}: uint32
nv_fences* {.importc: "nv_fences".}: array[4, nvioctl_fence]
bufferProducerRect* {.importc: "bufferProducerRect",
header: headerbuffer_producer, bycopy.} = object
left* {.importc: "left".}: s32
top* {.importc: "top".}: s32
right* {.importc: "right".}: s32
bottom* {.importc: "bottom".}: s32
bufferProducerQueueBufferInput* {.importc: "bufferProducerQueueBufferInput",
header: headerbuffer_producer, bycopy.} = object
timestamp* {.importc: "timestamp".}: s64
isAutoTimestamp* {.importc: "isAutoTimestamp".}: s32
crop* {.importc: "crop".}: bufferProducerRect
scalingMode* {.importc: "scalingMode".}: s32
transform* {.importc: "transform".}: uint32
stickyTransform* {.importc: "stickyTransform".}: uint32
unk* {.importc: "unk".}: array[2, uint32]
fence* {.importc: "fence".}: bufferProducerFence
bufferProducerQueueBufferOutput* {.importc: "bufferProducerQueueBufferOutput",
header: headerbuffer_producer, bycopy.} = object
width* {.importc: "width".}: uint32
height* {.importc: "height".}: uint32
transformHint* {.importc: "transformHint".}: uint32
numPendingBuffers* {.importc: "numPendingBuffers".}: uint32
bufferProducerGraphicBuffer* {.importc: "bufferProducerGraphicBuffer",
header: headerbuffer_producer, bycopy.} = object
magic* {.importc: "magic".}: uint32
width* {.importc: "width".}: uint32
height* {.importc: "height".}: uint32
stride* {.importc: "stride".}: uint32
format* {.importc: "format".}: uint32
usage* {.importc: "usage".}: uint32
pid* {.importc: "pid".}: uint32
refcount* {.importc: "refcount".}: uint32
numFds* {.importc: "numFds".}: uint32
numInts* {.importc: "numInts".}: uint32
data* {.importc: "data".}: INNER_C_STRUCT_3208597589
const
NATIVE_WINDOW_WIDTH* = 0
NATIVE_WINDOW_HEIGHT* = 1
NATIVE_WINDOW_FORMAT* = 2
const
NATIVE_WINDOW_API_CPU* = 2
const
HAL_TRANSFORM_FLIP_H* = 0x00000001
HAL_TRANSFORM_FLIP_V* = 0x00000002
HAL_TRANSFORM_ROT_90* = 0x00000004
HAL_TRANSFORM_ROT_180* = 0x00000003
HAL_TRANSFORM_ROT_270* = 0x00000007
const
NATIVE_WINDOW_TRANSFORM_FLIP_H* = HAL_TRANSFORM_FLIP_H
NATIVE_WINDOW_TRANSFORM_FLIP_V* = HAL_TRANSFORM_FLIP_V
NATIVE_WINDOW_TRANSFORM_ROT_90* = HAL_TRANSFORM_ROT_90
NATIVE_WINDOW_TRANSFORM_ROT_180* = HAL_TRANSFORM_ROT_180
NATIVE_WINDOW_TRANSFORM_ROT_270* = HAL_TRANSFORM_ROT_270
proc bufferProducerInitialize*(session: ptr Binder): Result {.cdecl,
importc: "bufferProducerInitialize", header: headerbuffer_producer.}
proc bufferProducerExit*() {.cdecl, importc: "bufferProducerExit",
header: headerbuffer_producer.}
proc bufferProducerRequestBuffer*(bufferIdx: s32;
buf: ptr bufferProducerGraphicBuffer): Result {.
cdecl, importc: "bufferProducerRequestBuffer", header: headerbuffer_producer.}
proc bufferProducerDequeueBuffer*(async: bool; width: uint32; height: uint32; format: s32;
usage: uint32; buf: ptr s32;
fence: ptr bufferProducerFence): Result {.cdecl,
importc: "bufferProducerDequeueBuffer", header: headerbuffer_producer.}
proc bufferProducerDetachBuffer*(slot: s32): Result {.cdecl,
importc: "bufferProducerDetachBuffer", header: headerbuffer_producer.}
proc bufferProducerQueueBuffer*(buf: s32;
input: ptr bufferProducerQueueBufferInput;
output: ptr bufferProducerQueueBufferOutput): Result {.
cdecl, importc: "bufferProducerQueueBuffer", header: headerbuffer_producer.}
proc bufferProducerQuery*(what: s32; value: ptr s32): Result {.cdecl,
importc: "bufferProducerQuery", header: headerbuffer_producer.}
proc bufferProducerConnect*(api: s32; producerControlledByApp: bool;
output: ptr bufferProducerQueueBufferOutput): Result {.
cdecl, importc: "bufferProducerConnect", header: headerbuffer_producer.}
proc bufferProducerDisconnect*(api: s32): Result {.cdecl,
importc: "bufferProducerDisconnect", header: headerbuffer_producer.}
proc bufferProducerGraphicBufferInit*(buf: s32;
input: ptr bufferProducerGraphicBuffer): Result {.
cdecl, importc: "bufferProducerGraphicBufferInit",
header: headerbuffer_producer.}

View file

@ -1,12 +0,0 @@
import strutils
import ospaths
const headercache = currentSourcePath().splitPath().head & "/nx/include/switch/arm/cache.h"
import libnx/wrapper/types
proc armDCacheFlush*(`addr`: pointer; size: csize) {.cdecl,
importc: "armDCacheFlush", header: headercache.}
proc armDCacheClean*(`addr`: pointer; size: csize) {.cdecl,
importc: "armDCacheClean", header: headercache.}
proc armICacheInvalidate*(`addr`: pointer; size: csize) {.cdecl,
importc: "armICacheInvalidate", header: headercache.}
proc armDCacheZero*(`addr`: pointer; size: csize) {.cdecl, importc: "armDCacheZero",
header: headercache.}

View file

@ -1,73 +0,0 @@
import strutils
import ospaths
const headercondvar = currentSourcePath().splitPath().head & "/nx/include/switch/kernel/condvar.h"
## *
## @file condvar.h
## @brief Condition variable synchronization primitive.
## @author plutoo
## @copyright libnx Authors
##
import
libnx/wrapper/types, libnx/wrapper/mutex
## / Condition variable structure.
type
CondVar* {.importc: "CondVar", header: headercondvar, bycopy.} = object
tag* {.importc: "tag".}: uint32
mutex* {.importc: "mutex".}: ptr Mutex
## *
## @brief Initializes a condition variable.
## @param[in] c Condition variable object.
## @param[in] m Mutex object to use inside the condition variable.
##
proc condvarInit*(c: ptr CondVar; m: ptr Mutex) {.cdecl, importc: "condvarInit",
header: headercondvar.}
## *
## @brief Waits on a condition variable with a timeout.
## @param[in] c Condition variable object.
## @param[in] timeout Timeout in nanoseconds.
## @return Result code (0xEA01 on timeout).
## @remark On function return, the underlying mutex is acquired.
##
proc condvarWaitTimeout*(c: ptr CondVar; timeout: uint64): Result {.cdecl,
importc: "condvarWaitTimeout", header: headercondvar.}
## *
## @brief Waits on a condition variable.
## @param[in] c Condition variable object.
## @return Result code.
## @remark On function return, the underlying mutex is acquired.
##
proc condvarWait*(c: ptr CondVar): Result {.inline, cdecl, importc: "condvarWait",
header: headercondvar.}
## *
## @brief Wakes up up to the specified number of threads waiting on a condition variable.
## @param[in] c Condition variable object.
## @param[in] num Maximum number of threads to wake up (or -1 to wake them all up).
## @return Result code.
##
proc condvarWake*(c: ptr CondVar; num: cint): Result {.cdecl, importc: "condvarWake",
header: headercondvar.}
## *
## @brief Wakes up a single thread waiting on a condition variable.
## @param[in] c Condition variable object.
## @return Result code.
##
proc condvarWakeOne*(c: ptr CondVar): Result {.inline, cdecl,
importc: "condvarWakeOne", header: headercondvar.}
## *
## @brief Wakes up all thread waiting on a condition variable.
## @param[in] c Condition variable object.
## @return Result code.
##
proc condvarWakeAll*(c: ptr CondVar): Result {.inline, cdecl,
importc: "condvarWakeAll", header: headercondvar.}

View file

@ -1,52 +0,0 @@
import strutils
import ospaths
const headerconsole = currentSourcePath().splitPath().head & "/nx/include/switch/runtime/devices/console.h"
import libnx/wrapper/types
type
ConsolePrint* = proc (con: pointer; c: cint): bool {.cdecl.}
ConsoleFont* {.importc: "ConsoleFont", header: headerconsole, bycopy.} = object
gfx* {.importc: "gfx".}: ptr uint16
asciiOffset* {.importc: "asciiOffset".}: uint16
numChars* {.importc: "numChars".}: uint16
PrintConsole* {.importc: "PrintConsole", header: headerconsole, bycopy.} = object
font* {.importc: "font".}: ConsoleFont
frameBuffer* {.importc: "frameBuffer".}: ptr uint32
frameBuffer2* {.importc: "frameBuffer2".}: ptr uint32
cursorX* {.importc: "cursorX".}: cint
cursorY* {.importc: "cursorY".}: cint
prevCursorX* {.importc: "prevCursorX".}: cint
prevCursorY* {.importc: "prevCursorY".}: cint
consoleWidth* {.importc: "consoleWidth".}: cint
consoleHeight* {.importc: "consoleHeight".}: cint
windowX* {.importc: "windowX".}: cint
windowY* {.importc: "windowY".}: cint
windowWidth* {.importc: "windowWidth".}: cint
windowHeight* {.importc: "windowHeight".}: cint
tabSize* {.importc: "tabSize".}: cint
fg* {.importc: "fg".}: cint
bg* {.importc: "bg".}: cint
flags* {.importc: "flags".}: cint
PrintChar* {.importc: "PrintChar".}: ConsolePrint
consoleInitialised* {.importc: "consoleInitialised".}: bool
debugDevice* {.size: sizeof(cint).} = enum
debugDevice_NULL, debugDevice_SVC, debugDevice_CONSOLE
const
debugDevice_3DMOO = debugDevice_SVC
proc consoleSetFont*(console: ptr PrintConsole; font: ptr ConsoleFont) {.cdecl,
importc: "consoleSetFont", header: headerconsole.}
proc consoleSetWindow*(console: ptr PrintConsole; x: cint; y: cint; width: cint;
height: cint) {.cdecl, importc: "consoleSetWindow",
header: headerconsole.}
proc consoleGetDefault*(): ptr PrintConsole {.cdecl, importc: "consoleGetDefault",
header: headerconsole.}
proc consoleSelect*(console: ptr PrintConsole): ptr PrintConsole {.cdecl,
importc: "consoleSelect", header: headerconsole.}
proc consoleInit*(console: ptr PrintConsole): ptr PrintConsole {.cdecl,
importc: "consoleInit", header: headerconsole.}
proc consoleDebugInit*(device: debugDevice) {.cdecl, importc: "consoleDebugInit",
header: headerconsole.}
proc consoleClear*() {.cdecl, importc: "consoleClear", header: headerconsole.}

View file

@ -1,9 +0,0 @@
import strutils
import ospaths
const headercsrng = currentSourcePath().splitPath().head & "/nx/include/switch/services/csrng.h"
import libnx/wrapper/types
proc csrngInitialize*(): Result {.cdecl, importc: "csrngInitialize",
header: headercsrng.}
proc csrngExit*() {.cdecl, importc: "csrngExit", header: headercsrng.}
proc csrngGetRandomBytes*(`out`: pointer; out_size: csize): Result {.cdecl,
importc: "csrngGetRandomBytes", header: headercsrng.}

View file

@ -1,14 +0,0 @@
import strutils
import ospaths
const headerdetect = currentSourcePath().splitPath().head & "/nx/include/switch/kernel/detect.h"
import libnx/wrapper/types
proc kernelAbove200*(): bool {.cdecl, importc: "kernelAbove200",
header: headerdetect.}
proc kernelAbove300*(): bool {.cdecl, importc: "kernelAbove300",
header: headerdetect.}
proc kernelAbove400*(): bool {.cdecl, importc: "kernelAbove400",
header: headerdetect.}
proc kernelAbove500*(): bool {.cdecl, importc: "kernelAbove500",
header: headerdetect.}
proc detectDebugger*(): bool {.cdecl, importc: "detectDebugger",
header: headerdetect.}

View file

@ -1,56 +0,0 @@
import strutils
import ospaths
const headerenv = currentSourcePath().splitPath().head & "/nx/include/switch/runtime/env.h"
import libnx/wrapper/types
type
ConfigEntry* {.importc: "ConfigEntry", header: headerenv, bycopy.} = object
Key* {.importc: "Key".}: uint32
Flags* {.importc: "Flags".}: uint32
Value* {.importc: "Value".}: array[2, uint64]
const
EntryFlag_IsMandatory* = (1 shl (0))
const
EntryType_EndOfList* = 0
EntryType_MainThreadHandle* = 1
EntryType_NextLoadPath* = 2
EntryType_OverrideHeap* = 3
EntryType_OverrideService* = 4
EntryType_Argv* = 5
EntryType_SyscallAvailableHint* = 6
EntryType_AppletType* = 7
EntryType_AppletWorkaround* = 8
EntryType_StdioSockets* = 9
EntryType_ProcessHandle* = 10
EntryType_LastLoadResult* = 11
type
LoaderReturnFn* = proc (result_code: cint) {.cdecl.}
proc envSetup*(ctx: pointer; main_thread: Handle; saved_lr: LoaderReturnFn) {.cdecl,
importc: "envSetup", header: headerenv.}
proc envGetMainThreadHandle*(): Handle {.cdecl, importc: "envGetMainThreadHandle",
header: headerenv.}
proc envIsNso*(): bool {.cdecl, importc: "envIsNso", header: headerenv.}
proc envHasHeapOverride*(): bool {.cdecl, importc: "envHasHeapOverride",
header: headerenv.}
proc envGetHeapOverrideAddr*(): pointer {.cdecl,
importc: "envGetHeapOverrideAddr",
header: headerenv.}
proc envGetHeapOverrideSize*(): uint64 {.cdecl, importc: "envGetHeapOverrideSize",
header: headerenv.}
proc envHasArgv*(): bool {.cdecl, importc: "envHasArgv", header: headerenv.}
proc envGetArgv*(): pointer {.cdecl, importc: "envGetArgv", header: headerenv.}
proc envIsSyscallHinted*(svc: uint8): bool {.cdecl, importc: "envIsSyscallHinted",
header: headerenv.}
proc envGetOwnProcessHandle*(): Handle {.cdecl, importc: "envGetOwnProcessHandle",
header: headerenv.}
proc envGetExitFuncPtr*(): LoaderReturnFn {.cdecl, importc: "envGetExitFuncPtr",
header: headerenv.}
proc envSetNextLoad*(path: cstring; argv: cstring): Result {.cdecl,
importc: "envSetNextLoad", header: headerenv.}
proc envHasNextLoad*(): bool {.cdecl, importc: "envHasNextLoad", header: headerenv.}
proc envGetLastLoadResult*(): Result {.cdecl, importc: "envGetLastLoadResult",
header: headerenv.}

View file

@ -1,13 +0,0 @@
import strutils
import ospaths
const headerfatal = currentSourcePath().splitPath().head & "/nx/include/switch/services/fatal.h"
import libnx/wrapper/types
type
FatalType* {.size: sizeof(cint).} = enum
FatalType_ErrorReportAndErrorScreen = 0, FatalType_ErrorReport = 1,
FatalType_ErrorScreen = 2
proc fatalSimple*(err: Result) {.cdecl, importc: "fatalSimple", header: headerfatal.}
proc fatalWithType*(err: Result; `type`: FatalType) {.cdecl,
importc: "fatalWithType", header: headerfatal.}

View file

@ -1,172 +0,0 @@
import strutils
import ospaths
const headerfs = currentSourcePath().splitPath().head & "/nx/include/switch/services/fs.h"
import libnx/ext/integer128
import libnx/wrapper/types
import libnx/wrapper/sm
const
FS_MAX_PATH* = 0x00000301
FS_SAVEDATA_CURRENT_TITLEID* = 0
FS_SAVEDATA_USERID_COMMONSAVE* = 0
type
FsFileSystem* {.importc: "FsFileSystem", header: headerfs, bycopy.} = object
s* {.importc: "s".}: Service
FsFile* {.importc: "FsFile", header: headerfs, bycopy.} = object
s* {.importc: "s".}: Service
FsDir* {.importc: "FsDir", header: headerfs, bycopy.} = object
s* {.importc: "s".}: Service
FsStorage* {.importc: "FsStorage", header: headerfs, bycopy.} = object
s* {.importc: "s".}: Service
FsSaveDataIterator* {.importc: "FsSaveDataIterator", header: headerfs, bycopy.} = object
s* {.importc: "s".}: Service
FsEventNotifier* {.importc: "FsEventNotifier", header: headerfs, bycopy.} = object
s* {.importc: "s".}: Service
FsDeviceOperator* {.importc: "FsDeviceOperator", header: headerfs, bycopy.} = object
s* {.importc: "s".}: Service
FsDirectoryEntry* {.importc: "FsDirectoryEntry", header: headerfs, bycopy.} = object
name* {.importc: "name".}: array[0x00000301, char]
pad* {.importc: "pad".}: array[3, uint8]
`type`* {.importc: "type".}: s8
pad2* {.importc: "pad2".}: array[3, uint8]
fileSize* {.importc: "fileSize".}: uint64
FsSave* {.importc: "FsSave", header: headerfs, bycopy.} = object
titleID* {.importc: "titleID".}: uint64
userID* {.importc: "userID".}: u128
saveID* {.importc: "saveID".}: uint64
SaveDataType* {.importc: "SaveDataType".}: uint64
unk_x28* {.importc: "unk_x28".}: uint64
unk_x30* {.importc: "unk_x30".}: uint64
unk_x38* {.importc: "unk_x38".}: uint64
FsSaveDataInfo* {.importc: "FsSaveDataInfo", header: headerfs, bycopy.} = object
saveID_unk* {.importc: "saveID_unk".}: uint64
SaveDataSpaceId* {.importc: "SaveDataSpaceId".}: uint8
SaveDataType* {.importc: "SaveDataType".}: uint8
pad* {.importc: "pad".}: array[6, uint8]
userID* {.importc: "userID".}: u128
saveID* {.importc: "saveID".}: uint64
titleID* {.importc: "titleID".}: uint64
size* {.importc: "size".}: uint64
unk_x38* {.importc: "unk_x38".}: array[0x00000028, uint8]
FsEntryType* {.size: sizeof(cint).} = enum
ENTRYTYPE_DIR = 0, ENTRYTYPE_FILE = 1
FsFileFlags* {.size: sizeof(cint).} = enum
FS_OPEN_READ = (1 shl (0)), FS_OPEN_WRITE = (1 shl (1)), FS_OPEN_APPEND = (1 shl (2))
FsDirectoryFlags* {.size: sizeof(cint).} = enum
FS_DIROPEN_DIRECTORY = (1 shl (0)), FS_DIROPEN_FILE = (1 shl (1))
FsStorageId* {.size: sizeof(cint).} = enum
FsStorageId_None = 0, FsStorageId_Host = 1, FsStorageId_GameCard = 2,
FsStorageId_NandSystem = 3, FsStorageId_NandUser = 4, FsStorageId_SdCard = 5
FsContentStorageId* {.size: sizeof(cint).} = enum
FS_CONTENTSTORAGEID_NandSystem = 0, FS_CONTENTSTORAGEID_NandUser = 1,
FS_CONTENTSTORAGEID_SdCard = 2
FsSaveDataSpaceId* {.size: sizeof(cint).} = enum
FsSaveDataSpaceId_All = -1, FsSaveDataSpaceId_NandSystem = 0,
FsSaveDataSpaceId_NandUser = 1, FsSaveDataSpaceId_SdCard = 2,
FsSaveDataSpaceId_TemporaryStorage = 3
FsSaveDataType* {.size: sizeof(cint).} = enum
FsSaveDataType_SystemSaveData = 0, FsSaveDataType_SaveData = 1,
FsSaveDataType_BcatDeliveryCacheStorage = 2, FsSaveDataType_DeviceSaveData = 3,
FsSaveDataType_TemporaryStorage = 4, FsSaveDataType_CacheStorage = 5
proc fsInitialize*(): Result {.cdecl, importc: "fsInitialize", header: headerfs.}
proc fsExit*() {.cdecl, importc: "fsExit", header: headerfs.}
proc fsGetServiceSession*(): ptr Service {.cdecl, importc: "fsGetServiceSession",
header: headerfs.}
proc fsMountSdcard*(`out`: ptr FsFileSystem): Result {.cdecl,
importc: "fsMountSdcard", header: headerfs.}
proc fsMountSaveData*(`out`: ptr FsFileSystem; inval: uint8; save: ptr FsSave): Result {.
cdecl, importc: "fsMountSaveData", header: headerfs.}
proc fsMountSystemSaveData*(`out`: ptr FsFileSystem; inval: uint8; save: ptr FsSave): Result {.
cdecl, importc: "fsMountSystemSaveData", header: headerfs.}
proc fsOpenSaveDataIterator*(`out`: ptr FsSaveDataIterator; SaveDataSpaceId: s32): Result {.
cdecl, importc: "fsOpenSaveDataIterator", header: headerfs.}
proc fsOpenDataStorageByCurrentProcess*(`out`: ptr FsStorage): Result {.cdecl,
importc: "fsOpenDataStorageByCurrentProcess", header: headerfs.}
proc fsOpenDeviceOperator*(`out`: ptr FsDeviceOperator): Result {.cdecl,
importc: "fsOpenDeviceOperator", header: headerfs.}
proc fsOpenSdCardDetectionEventNotifier*(`out`: ptr FsEventNotifier): Result {.
cdecl, importc: "fsOpenSdCardDetectionEventNotifier", header: headerfs.}
proc fsMount_SaveData*(`out`: ptr FsFileSystem; titleID: uint64; userID: u128): Result {.
cdecl, importc: "fsMount_SaveData", header: headerfs.}
proc fsMount_SystemSaveData*(`out`: ptr FsFileSystem; saveID: uint64): Result {.cdecl,
importc: "fsMount_SystemSaveData", header: headerfs.}
proc fsFsCreateFile*(fs: ptr FsFileSystem; path: cstring; size: csize; flags: cint): Result {.
cdecl, importc: "fsFsCreateFile", header: headerfs.}
proc fsFsDeleteFile*(fs: ptr FsFileSystem; path: cstring): Result {.cdecl,
importc: "fsFsDeleteFile", header: headerfs.}
proc fsFsCreateDirectory*(fs: ptr FsFileSystem; path: cstring): Result {.cdecl,
importc: "fsFsCreateDirectory", header: headerfs.}
proc fsFsDeleteDirectory*(fs: ptr FsFileSystem; path: cstring): Result {.cdecl,
importc: "fsFsDeleteDirectory", header: headerfs.}
proc fsFsDeleteDirectoryRecursively*(fs: ptr FsFileSystem; path: cstring): Result {.
cdecl, importc: "fsFsDeleteDirectoryRecursively", header: headerfs.}
proc fsFsRenameFile*(fs: ptr FsFileSystem; path0: cstring; path1: cstring): Result {.
cdecl, importc: "fsFsRenameFile", header: headerfs.}
proc fsFsRenameDirectory*(fs: ptr FsFileSystem; path0: cstring; path1: cstring): Result {.
cdecl, importc: "fsFsRenameDirectory", header: headerfs.}
proc fsFsGetEntryType*(fs: ptr FsFileSystem; path: cstring; `out`: ptr FsEntryType): Result {.
cdecl, importc: "fsFsGetEntryType", header: headerfs.}
proc fsFsOpenFile*(fs: ptr FsFileSystem; path: cstring; flags: cint; `out`: ptr FsFile): Result {.
cdecl, importc: "fsFsOpenFile", header: headerfs.}
proc fsFsOpenDirectory*(fs: ptr FsFileSystem; path: cstring; flags: cint;
`out`: ptr FsDir): Result {.cdecl,
importc: "fsFsOpenDirectory", header: headerfs.}
proc fsFsCommit*(fs: ptr FsFileSystem): Result {.cdecl, importc: "fsFsCommit",
header: headerfs.}
proc fsFsGetFreeSpace*(fs: ptr FsFileSystem; path: cstring; `out`: ptr uint64): Result {.
cdecl, importc: "fsFsGetFreeSpace", header: headerfs.}
proc fsFsGetTotalSpace*(fs: ptr FsFileSystem; path: cstring; `out`: ptr uint64): Result {.
cdecl, importc: "fsFsGetTotalSpace", header: headerfs.}
proc fsFsClose*(fs: ptr FsFileSystem) {.cdecl, importc: "fsFsClose", header: headerfs.}
proc fsFileRead*(f: ptr FsFile; off: uint64; buf: pointer; len: csize; `out`: ptr csize): Result {.
cdecl, importc: "fsFileRead", header: headerfs.}
proc fsFileWrite*(f: ptr FsFile; off: uint64; buf: pointer; len: csize): Result {.cdecl,
importc: "fsFileWrite", header: headerfs.}
proc fsFileFlush*(f: ptr FsFile): Result {.cdecl, importc: "fsFileFlush",
header: headerfs.}
proc fsFileSetSize*(f: ptr FsFile; sz: uint64): Result {.cdecl, importc: "fsFileSetSize",
header: headerfs.}
proc fsFileGetSize*(f: ptr FsFile; `out`: ptr uint64): Result {.cdecl,
importc: "fsFileGetSize", header: headerfs.}
proc fsFileClose*(f: ptr FsFile) {.cdecl, importc: "fsFileClose", header: headerfs.}
proc fsDirRead*(d: ptr FsDir; inval: uint64; total_entries: ptr csize; max_entries: csize;
buf: ptr FsDirectoryEntry): Result {.cdecl, importc: "fsDirRead",
header: headerfs.}
proc fsDirGetEntryCount*(d: ptr FsDir; count: ptr uint64): Result {.cdecl,
importc: "fsDirGetEntryCount", header: headerfs.}
proc fsDirClose*(d: ptr FsDir) {.cdecl, importc: "fsDirClose", header: headerfs.}
proc fsStorageRead*(s: ptr FsStorage; off: uint64; buf: pointer; len: csize): Result {.
cdecl, importc: "fsStorageRead", header: headerfs.}
proc fsStorageClose*(s: ptr FsStorage) {.cdecl, importc: "fsStorageClose",
header: headerfs.}
proc fsSaveDataIteratorRead*(s: ptr FsSaveDataIterator; buf: ptr FsSaveDataInfo;
max_entries: csize; total_entries: ptr csize): Result {.
cdecl, importc: "fsSaveDataIteratorRead", header: headerfs.}
proc fsSaveDataIteratorClose*(s: ptr FsSaveDataIterator) {.cdecl,
importc: "fsSaveDataIteratorClose", header: headerfs.}
proc fsEventNotifierGetEventHandle*(e: ptr FsEventNotifier; `out`: ptr Handle): Result {.
cdecl, importc: "fsEventNotifierGetEventHandle", header: headerfs.}
proc fsEventNotifierClose*(e: ptr FsEventNotifier) {.cdecl,
importc: "fsEventNotifierClose", header: headerfs.}
proc fsDeviceOperatorIsSdCardInserted*(d: ptr FsDeviceOperator; `out`: ptr bool): Result {.
cdecl, importc: "fsDeviceOperatorIsSdCardInserted", header: headerfs.}
proc fsDeviceOperatorClose*(d: ptr FsDeviceOperator) {.cdecl,
importc: "fsDeviceOperatorClose", header: headerfs.}

View file

@ -1,29 +0,0 @@
import strutils
import ospaths
const headerfs_dev = currentSourcePath().splitPath().head & "/nx/include/switch/runtime/devices/fs_dev.h"
import libnx/wrapper/types
import libnx/wrapper/fs
const
FSDEV_DIRITER_MAGIC* = 0x66736476
type
fsdev_dir_t* {.importc: "fsdev_dir_t", header: headerfs_dev, bycopy.} = object
magic* {.importc: "magic".}: uint32
fd* {.importc: "fd".}: FsDir
index* {.importc: "index".}: ssize_t
size* {.importc: "size".}: csize
entry_data* {.importc: "entry_data".}: array[32, FsDirectoryEntry]
proc fsdevMountSdmc*(): Result {.cdecl, importc: "fsdevMountSdmc",
header: headerfs_dev.}
proc fsdevMountDevice*(name: cstring; fs: FsFileSystem): cint {.cdecl,
importc: "fsdevMountDevice", header: headerfs_dev.}
proc fsdevUnmountDevice*(name: cstring): cint {.cdecl,
importc: "fsdevUnmountDevice", header: headerfs_dev.}
proc fsdevCommitDevice*(name: cstring): Result {.cdecl,
importc: "fsdevCommitDevice", header: headerfs_dev.}
proc fsdevGetDefaultFileSystem*(): ptr FsFileSystem {.cdecl,
importc: "fsdevGetDefaultFileSystem", header: headerfs_dev.}
proc fsdevUnmountAll*(): Result {.cdecl, importc: "fsdevUnmountAll",
header: headerfs_dev.}

View file

@ -1,15 +0,0 @@
import strutils
import ospaths
const headerfsldr = currentSourcePath().splitPath().head & "/nx/include/switch/services/fsldr.h"
import libnx/wrapper/types
import libnx/wrapper/sm
import libnx/wrapper/fs
proc fsldrInitialize*(): Result {.cdecl, importc: "fsldrInitialize",
header: headerfsldr.}
proc fsldrExit*() {.cdecl, importc: "fsldrExit", header: headerfsldr.}
proc fsldrOpenCodeFileSystem*(tid: uint64; path: cstring; `out`: ptr FsFileSystem): Result {.
cdecl, importc: "fsldrOpenCodeFileSystem", header: headerfsldr.}
proc fsldrIsArchivedProgram*(pid: uint64; `out`: ptr bool): Result {.cdecl,
importc: "fsldrIsArchivedProgram", header: headerfsldr.}
proc fsldrSetCurrentProcess*(): Result {.cdecl, importc: "fsldrSetCurrentProcess",
header: headerfsldr.}

View file

@ -1,19 +0,0 @@
import strutils
import ospaths
const headerfspr = currentSourcePath().splitPath().head & "/nx/include/switch/services/fspr.h"
import libnx/wrapper/types
import libnx/wrapper/sm
import libnx/wrapper/fs
proc fsprInitialize*(): Result {.cdecl, importc: "fsprInitialize",
header: headerfspr.}
proc fsprExit*() {.cdecl, importc: "fsprExit", header: headerfspr.}
proc fsprRegisterProgram*(pid: uint64; titleID: uint64; storageID: FsStorageId;
fs_access_header: pointer; fah_size: csize;
fs_access_control: pointer; fac_size: csize): Result {.
cdecl, importc: "fsprRegisterProgram", header: headerfspr.}
proc fsprUnregisterProgram*(pid: uint64): Result {.cdecl,
importc: "fsprUnregisterProgram", header: headerfspr.}
proc fsprSetCurrentProcess*(): Result {.cdecl, importc: "fsprSetCurrentProcess",
header: headerfspr.}
proc fsprSetEnabledProgramVerification*(enabled: bool): Result {.cdecl,
importc: "fsprSetEnabledProgramVerification", header: headerfspr.}

View file

@ -1,124 +0,0 @@
import strutils
import ospaths
const headergfx = currentSourcePath().splitPath().head & "/nx/include/switch/gfx/gfx.h"
## *
## @file gfx.h
## @brief High-level graphics API.
## This API exposes a framebuffer (technically speaking, a windowbuffer) to be used for drawing graphics.
## @author yellows8
## @copyright libnx Authors
##
import
libnx/wrapper/types
## / Converts red, green, blue, and alpha components to packed RGBA8.
template RGBA8*(r, g, b, a: untyped): untyped =
(((r) and 0x000000FF) or (((g) and 0x000000FF) shl 8) or
(((b) and 0x000000FF) shl 16) or (((a) and 0x000000FF) shl 24))
## / Same as \ref RGBA8 except with alpha=0xff.
template RGBA8_MAXALPHA*(r, g, b: untyped): untyped =
RGBA8(r, g, b, 0x000000FF)
## / GfxMode set by \ref gfxSetMode. The default is GfxMode_LinearDouble. Note that the text-console (see console.h) sets this to GfxMode_TiledDouble.
type
GfxMode* {.size: sizeof(cint).} = enum
GfxMode_TiledSingle, ## /< Single-buffering with raw tiled (block-linear) framebuffer.
GfxMode_TiledDouble, ## /< Double-buffering with raw tiled (block-linear) framebuffer.
GfxMode_LinearDouble ## /< Double-buffering with linear framebuffer, which is transferred to the actual framebuffer by \ref gfxFlushBuffers().
## / Framebuffer pixel-format is RGBA8888, there's no known way to change this.
## *
## @brief Initializes the graphics subsystem.
## @warning Do not use \ref viInitialize when using this function.
##
proc gfxInitDefault*() {.cdecl, importc: "gfxInitDefault", header: headergfx.}
## *
## @brief Uninitializes the graphics subsystem.
## @warning Do not use \ref viExit when using this function.
##
proc gfxExit*() {.cdecl, importc: "gfxExit", header: headergfx.}
## *
## @brief Sets the resolution to be used when initializing the graphics subsystem.
## @param[in] width Horizontal resolution, in pixels.
## @param[in] height Vertical resolution, in pixels.
## @note The default resolution is 720p.
## @note This can only be used before calling \ref gfxInitDefault, this will use \ref fatalSimple otherwise. If the input is 0, the default resolution will be used during \ref gfxInitDefault. This sets the maximum resolution for the framebuffer, used during \ref gfxInitDefault. This is also used as the current resolution when crop isn't set. The width/height are reset to the default when \ref gfxExit is used.
## @note Normally you should only use this when you need a maximum resolution larger than the default, see above.
## @note The width and height are aligned to 4.
##
proc gfxInitResolution*(width: uint32; height: uint32) {.cdecl,
importc: "gfxInitResolution", header: headergfx.}
## / Wrapper for \ref gfxInitResolution with resolution=1080p. Use this if you want to support 1080p or >720p in docked-mode.
proc gfxInitResolutionDefault*() {.cdecl, importc: "gfxInitResolutionDefault",
header: headergfx.}
## / Configure framebuffer crop, by default crop is all-zero. Use all-zero input to reset to default. \ref gfxExit resets this to the default.
## / When the input is invalid this returns without changing the crop data, this includes the input values being larger than the framebuf width/height.
## / This will update the display width/height returned by \ref gfxGetFramebuffer, with that width/height being reset to the default when required.
## / \ref gfxGetFramebufferDisplayOffset uses absolute x/y, it will not adjust for non-zero crop left/top.
## / The new crop config will not take affect with double-buffering disabled. When used during frame-drawing, this should be called before \ref gfxGetFramebuffer.
## / The right and bottom params are aligned to 4.
proc gfxConfigureCrop*(left: s32; top: s32; right: s32; bottom: s32) {.cdecl,
importc: "gfxConfigureCrop", header: headergfx.}
## / Wrapper for \ref gfxConfigureCrop. Use this to set the resolution, within the bounds of the maximum resolution. Use all-zero input to reset to default.
proc gfxConfigureResolution*(width: s32; height: s32) {.cdecl,
importc: "gfxConfigureResolution", header: headergfx.}
## / If enabled, \ref gfxConfigureResolution will be used with the input resolution for the current OperationMode. Then \ref gfxConfigureResolution will automatically be used with the specified resolution each time OperationMode changes.
proc gfxConfigureAutoResolution*(enable: bool; handheld_width: s32;
handheld_height: s32; docked_width: s32;
docked_height: s32) {.cdecl,
importc: "gfxConfigureAutoResolution", header: headergfx.}
## / Wrapper for \ref gfxConfigureAutoResolution. handheld_resolution=720p, docked_resolution={all-zero for using current maximum resolution}.
proc gfxConfigureAutoResolutionDefault*(enable: bool) {.cdecl,
importc: "gfxConfigureAutoResolutionDefault", header: headergfx.}
## / Waits for vertical sync.
proc gfxWaitForVsync*() {.cdecl, importc: "gfxWaitForVsync", header: headergfx.}
## / Swaps the framebuffers (for double-buffering).
proc gfxSwapBuffers*() {.cdecl, importc: "gfxSwapBuffers", header: headergfx.}
## / Get the current framebuffer address, with optional output ptrs for the display framebuffer width/height. The display width/height is adjusted by \ref gfxConfigureCrop and \ref gfxConfigureResolution.
proc gfxGetFramebuffer*(width: ptr uint32; height: ptr uint32): ptr uint8 {.cdecl,
importc: "gfxGetFramebuffer", header: headergfx.}
## / Get the framebuffer width/height without crop.
proc gfxGetFramebufferResolution*(width: ptr uint32; height: ptr uint32) {.cdecl,
importc: "gfxGetFramebufferResolution", header: headergfx.}
## / Use this to get the actual byte-size of the framebuffer for use with memset/etc.
proc gfxGetFramebufferSize*(): csize {.cdecl, importc: "gfxGetFramebufferSize",
header: headergfx.}
## / Sets the \ref GfxMode.
proc gfxSetMode*(mode: GfxMode) {.cdecl, importc: "gfxSetMode", header: headergfx.}
## / Controls whether a vertical-flip is done when determining the pixel-offset within the actual framebuffer. By default this is enabled.
proc gfxSetDrawFlip*(flip: bool) {.cdecl, importc: "gfxSetDrawFlip",
header: headergfx.}
## / Configures transform. See the NATIVE_WINDOW_TRANSFORM_* enums in buffer_producer.h. The default is NATIVE_WINDOW_TRANSFORM_FLIP_V.
proc gfxConfigureTransform*(transform: uint32) {.cdecl,
importc: "gfxConfigureTransform", header: headergfx.}
## / Flushes the framebuffer in the data cache. When \ref GfxMode is GfxMode_LinearDouble, this also transfers the linear-framebuffer to the actual framebuffer.
proc gfxFlushBuffers*() {.cdecl, importc: "gfxFlushBuffers", header: headergfx.}
## / Use this to get the pixel-offset in the framebuffer. Returned value is in pixels, not bytes.
## / This implements tegra blocklinear, with hard-coded constants etc.
## / Do not use this when \ref GfxMode is GfxMode_LinearDouble.
proc gfxGetFramebufferDisplayOffset*(x: uint32; y: uint32): uint32 {.inline, cdecl,
importc: "gfxGetFramebufferDisplayOffset", header: headergfx.}

View file

@ -1,508 +0,0 @@
import strutils
import ospaths
const headerhid = currentSourcePath().splitPath().head & "/nx/include/switch/services/hid.h"
## *
## @file hid.h
## @brief Human input device (hid) service IPC wrapper.
## @author shinyquagsire23
## @author yellows8
## @copyright libnx Authors
##
import
libnx/wrapper/types, libnx/wrapper/sm
## Begin enums and output structs
type
HidMouseButton* {.size: sizeof(cint).} = enum
MOUSE_LEFT = BIT(0), MOUSE_RIGHT = BIT(1), MOUSE_MIDDLE = BIT(2),
MOUSE_FORWARD = BIT(3), MOUSE_BACK = BIT(4)
HidKeyboardModifier* {.size: sizeof(cint).} = enum
KBD_MOD_LCTRL = BIT(0), KBD_MOD_LSHIFT = BIT(1), KBD_MOD_LALT = BIT(2),
KBD_MOD_LMETA = BIT(3), KBD_MOD_RCTRL = BIT(4), KBD_MOD_RSHIFT = BIT(5),
KBD_MOD_RALT = BIT(6), KBD_MOD_RMETA = BIT(7), KBD_MOD_CAPSLOCK = BIT(8),
KBD_MOD_SCROLLLOCK = BIT(9), KBD_MOD_NUMLOCK = BIT(10)
HidKeyboardScancode* {.size: sizeof(cint).} = enum
KBD_NONE = 0x00000000, KBD_ERR_OVF = 0x00000001, KBD_A = 0x00000004,
KBD_B = 0x00000005, KBD_C = 0x00000006, KBD_D = 0x00000007, KBD_E = 0x00000008,
KBD_F = 0x00000009, KBD_G = 0x0000000A, KBD_H = 0x0000000B, KBD_I = 0x0000000C,
KBD_J = 0x0000000D, KBD_K = 0x0000000E, KBD_L = 0x0000000F, KBD_M = 0x00000010,
KBD_N = 0x00000011, KBD_O = 0x00000012, KBD_P = 0x00000013, KBD_Q = 0x00000014,
KBD_R = 0x00000015, KBD_S = 0x00000016, KBD_T = 0x00000017, KBD_U = 0x00000018,
KBD_V = 0x00000019, KBD_W = 0x0000001A, KBD_X = 0x0000001B, KBD_Y = 0x0000001C,
KBD_Z = 0x0000001D, KBD_1 = 0x0000001E, KBD_2 = 0x0000001F, KBD_3 = 0x00000020,
KBD_4 = 0x00000021, KBD_5 = 0x00000022, KBD_6 = 0x00000023, KBD_7 = 0x00000024,
KBD_8 = 0x00000025, KBD_9 = 0x00000026, KBD_0 = 0x00000027, KBD_ENTER = 0x00000028,
KBD_ESC = 0x00000029, KBD_BACKSPACE = 0x0000002A, KBD_TAB = 0x0000002B,
KBD_SPACE = 0x0000002C, KBD_MINUS = 0x0000002D, KBD_EQUAL = 0x0000002E,
KBD_LEFTBRACE = 0x0000002F, KBD_RIGHTBRACE = 0x00000030,
KBD_BACKSLASH = 0x00000031, KBD_HASHTILDE = 0x00000032,
KBD_SEMICOLON = 0x00000033, KBD_APOSTROPHE = 0x00000034, KBD_GRAVE = 0x00000035,
KBD_COMMA = 0x00000036, KBD_DOT = 0x00000037, KBD_SLASH = 0x00000038,
KBD_CAPSLOCK = 0x00000039, KBD_F1 = 0x0000003A, KBD_F2 = 0x0000003B,
KBD_F3 = 0x0000003C, KBD_F4 = 0x0000003D, KBD_F5 = 0x0000003E, KBD_F6 = 0x0000003F,
KBD_F7 = 0x00000040, KBD_F8 = 0x00000041, KBD_F9 = 0x00000042, KBD_F10 = 0x00000043,
KBD_F11 = 0x00000044, KBD_F12 = 0x00000045, KBD_SYSRQ = 0x00000046,
KBD_SCROLLLOCK = 0x00000047, KBD_PAUSE = 0x00000048, KBD_INSERT = 0x00000049,
KBD_HOME = 0x0000004A, KBD_PAGEUP = 0x0000004B, KBD_DELETE = 0x0000004C,
KBD_END = 0x0000004D, KBD_PAGEDOWN = 0x0000004E, KBD_RIGHT = 0x0000004F,
KBD_LEFT = 0x00000050, KBD_DOWN = 0x00000051, KBD_UP = 0x00000052,
KBD_NUMLOCK = 0x00000053, KBD_KPSLASH = 0x00000054, KBD_KPASTERISK = 0x00000055,
KBD_KPMINUS = 0x00000056, KBD_KPPLUS = 0x00000057, KBD_KPENTER = 0x00000058,
KBD_KP1 = 0x00000059, KBD_KP2 = 0x0000005A, KBD_KP3 = 0x0000005B,
KBD_KP4 = 0x0000005C, KBD_KP5 = 0x0000005D, KBD_KP6 = 0x0000005E,
KBD_KP7 = 0x0000005F, KBD_KP8 = 0x00000060, KBD_KP9 = 0x00000061,
KBD_KP0 = 0x00000062, KBD_KPDOT = 0x00000063, KBD_102ND = 0x00000064,
KBD_COMPOSE = 0x00000065, KBD_POWER = 0x00000066, KBD_KPEQUAL = 0x00000067,
KBD_F13 = 0x00000068, KBD_F14 = 0x00000069, KBD_F15 = 0x0000006A,
KBD_F16 = 0x0000006B, KBD_F17 = 0x0000006C, KBD_F18 = 0x0000006D,
KBD_F19 = 0x0000006E, KBD_F20 = 0x0000006F, KBD_F21 = 0x00000070,
KBD_F22 = 0x00000071, KBD_F23 = 0x00000072, KBD_F24 = 0x00000073,
KBD_OPEN = 0x00000074, KBD_HELP = 0x00000075, KBD_PROPS = 0x00000076,
KBD_FRONT = 0x00000077, KBD_STOP = 0x00000078, KBD_AGAIN = 0x00000079,
KBD_UNDO = 0x0000007A, KBD_CUT = 0x0000007B, KBD_COPY = 0x0000007C,
KBD_PASTE = 0x0000007D, KBD_FIND = 0x0000007E, KBD_MUTE = 0x0000007F,
KBD_VOLUMEUP = 0x00000080, KBD_VOLUMEDOWN = 0x00000081,
KBD_CAPSLOCK_ACTIVE = 0x00000082, KBD_NUMLOCK_ACTIVE = 0x00000083,
KBD_SCROLLLOCK_ACTIVE = 0x00000084, KBD_KPCOMMA = 0x00000085,
KBD_KPLEFTPAREN = 0x000000B6, KBD_KPRIGHTPAREN = 0x000000B7,
KBD_LEFTCTRL = 0x000000E0, KBD_LEFTSHIFT = 0x000000E1, KBD_LEFTALT = 0x000000E2,
KBD_LEFTMETA = 0x000000E3, KBD_RIGHTCTRL = 0x000000E4,
KBD_RIGHTSHIFT = 0x000000E5, KBD_RIGHTALT = 0x000000E6,
KBD_RIGHTMETA = 0x000000E7, KBD_MEDIA_PLAYPAUSE = 0x000000E8,
KBD_MEDIA_STOPCD = 0x000000E9, KBD_MEDIA_PREVIOUSSONG = 0x000000EA,
KBD_MEDIA_NEXTSONG = 0x000000EB, KBD_MEDIA_EJECTCD = 0x000000EC,
KBD_MEDIA_VOLUMEUP = 0x000000ED, KBD_MEDIA_VOLUMEDOWN = 0x000000EE,
KBD_MEDIA_MUTE = 0x000000EF, KBD_MEDIA_WWW = 0x000000F0,
KBD_MEDIA_BACK = 0x000000F1, KBD_MEDIA_FORWARD = 0x000000F2,
KBD_MEDIA_STOP = 0x000000F3, KBD_MEDIA_FIND = 0x000000F4,
KBD_MEDIA_SCROLLUP = 0x000000F5, KBD_MEDIA_SCROLLDOWN = 0x000000F6,
KBD_MEDIA_EDIT = 0x000000F7, KBD_MEDIA_SLEEP = 0x000000F8,
KBD_MEDIA_COFFEE = 0x000000F9, KBD_MEDIA_REFRESH = 0x000000FA,
KBD_MEDIA_CALC = 0x000000FB
HidControllerType* {.size: sizeof(cint).} = enum
TYPE_PROCONTROLLER = BIT(0), TYPE_HANDHELD = BIT(1), TYPE_JOYCON_PAIR = BIT(2),
TYPE_JOYCON_LEFT = BIT(3), TYPE_JOYCON_RIGHT = BIT(4)
HidControllerLayoutType* {.size: sizeof(cint).} = enum
LAYOUT_PROCONTROLLER = 0, ## Pro Controller or Hid gamepad
LAYOUT_HANDHELD = 1, ## Two Joy-Con docked to rails
LAYOUT_SINGLE = 2, ## Horizontal single Joy-Con or pair of Joy-Con, adjusted for orientation
LAYOUT_LEFT = 3, ## Only raw left Joy-Con state, no orientation adjustment
LAYOUT_RIGHT = 4, ## Only raw right Joy-Con state, no orientation adjustment
LAYOUT_DEFAULT_DIGITAL = 5, ## Same as next, but sticks have 8-direction values only
LAYOUT_DEFAULT = 6 ## Safe default, single Joy-Con have buttons/sticks rotated for orientation
HidControllerColorDescription* {.size: sizeof(cint).} = enum
COLORS_NONEXISTENT = BIT(1)
HidControllerKeys* {.size: sizeof(cint).} = enum
KEY_A = BIT(0), ## /< A
KEY_B = BIT(1), ## /< B
KEY_X = BIT(2), ## /< X
KEY_Y = BIT(3), ## /< Y
KEY_LSTICK = BIT(4), ## /< Left Stick Button
KEY_RSTICK = BIT(5), ## /< Right Stick Button
KEY_L = BIT(6), ## /< L
KEY_R = BIT(7), ## /< R
KEY_ZL = BIT(8), ## /< ZL
KEY_ZR = BIT(9), ## /< ZR
KEY_PLUS = BIT(10), ## /< Plus
KEY_MINUS = BIT(11), ## /< Minus
KEY_DLEFT = BIT(12), ## /< D-Pad Left
KEY_DUP = BIT(13), ## /< D-Pad Up
KEY_DRIGHT = BIT(14), ## /< D-Pad Right
KEY_DDOWN = BIT(15), ## /< D-Pad Down
KEY_LSTICK_LEFT = BIT(16), ## /< Left Stick Left
KEY_LSTICK_UP = BIT(17), ## /< Left Stick Up
KEY_LSTICK_RIGHT = BIT(18), ## /< Left Stick Right
KEY_LSTICK_DOWN = BIT(19), ## /< Left Stick Down
KEY_RSTICK_LEFT = BIT(20), ## /< Right Stick Left
KEY_LEFT = KEY_DLEFT.int or KEY_LSTICK_LEFT.int or KEY_RSTICK_LEFT.int, ## /< D-Pad Left or Sticks Left
KEY_RSTICK_UP = BIT(21), ## /< Right Stick Up
KEY_UP = KEY_DUP.int or KEY_LSTICK_UP.int or KEY_RSTICK_UP.int, ## /< D-Pad Up or Sticks Up
KEY_RSTICK_RIGHT = BIT(22), ## /< Right Stick Right
KEY_RIGHT = KEY_DRIGHT.int or KEY_LSTICK_RIGHT.int or KEY_RSTICK_RIGHT.int, ## /< D-Pad Right or Sticks Right
KEY_RSTICK_DOWN = BIT(23), ## /< Right Stick Down
KEY_DOWN = KEY_DDOWN.int or KEY_LSTICK_DOWN.int or KEY_RSTICK_DOWN.int, ## /< D-Pad Down or Sticks Down
KEY_SL = BIT(24), ## /< SL
KEY_SR = BIT(25), ## /< SR
## Pseudo-key for at least one finger on the touch screen
KEY_TOUCH = BIT(26), ## Buttons by orientation (for single Joy-Con), also works with Joy-Con pairs, Pro Controller
## Generic catch-all directions, also works for single Joy-Con
HidControllerJoystick* {.size: sizeof(cint).} = enum
JOYSTICK_LEFT = 0, JOYSTICK_RIGHT = 1, JOYSTICK_NUM_STICKS = 2
HidControllerConnectionState* {.size: sizeof(cint).} = enum
CONTROLLER_STATE_CONNECTED = BIT(0), CONTROLLER_STATE_WIRED = BIT(1)
HidControllerID* {.size: sizeof(cint).} = enum
CONTROLLER_PLAYER_1 = 0, CONTROLLER_PLAYER_2 = 1, CONTROLLER_PLAYER_3 = 2,
CONTROLLER_PLAYER_4 = 3, CONTROLLER_PLAYER_5 = 4, CONTROLLER_PLAYER_6 = 5,
CONTROLLER_PLAYER_7 = 6, CONTROLLER_PLAYER_8 = 7, CONTROLLER_HANDHELD = 8,
CONTROLLER_UNKNOWN = 9, CONTROLLER_P1_AUTO = 10 ## / Not an actual HID-sysmodule ID. Only for hidKeys*()/hidJoystickRead(). Automatically uses CONTROLLER_PLAYER_1 when connected, otherwise uses CONTROLLER_HANDHELD.
touchPosition* {.importc: "touchPosition", header: headerhid, bycopy.} = object
px* {.importc: "px".}: uint32
py* {.importc: "py".}: uint32
dx* {.importc: "dx".}: uint32
dy* {.importc: "dy".}: uint32
angle* {.importc: "angle".}: uint32
JoystickPosition* {.importc: "JoystickPosition", header: headerhid, bycopy.} = object
dx* {.importc: "dx".}: s32
dy* {.importc: "dy".}: s32
MousePosition* {.importc: "MousePosition", header: headerhid, bycopy.} = object
x* {.importc: "x".}: uint32
y* {.importc: "y".}: uint32
velocityX* {.importc: "velocityX".}: uint32
velocityY* {.importc: "velocityY".}: uint32
scrollVelocityX* {.importc: "scrollVelocityX".}: uint32
scrollVelocityY* {.importc: "scrollVelocityY".}: uint32
const
JOYSTICK_MAX* = (0x00008000)
JOYSTICK_MIN* = (-0x00008000)
## End enums and output structs
## Begin HidTouchScreen
type
HidTouchScreenHeader* {.importc: "HidTouchScreenHeader", header: headerhid, bycopy.} = object
timestampTicks* {.importc: "timestampTicks".}: uint64
numEntries* {.importc: "numEntries".}: uint64
latestEntry* {.importc: "latestEntry".}: uint64
maxEntryIndex* {.importc: "maxEntryIndex".}: uint64
timestamp* {.importc: "timestamp".}: uint64
## static_assert(sizeof(HidTouchScreenHeader) == 0x28, "Hid touch screen header structure has incorrect size");
type
HidTouchScreenEntryHeader* {.importc: "HidTouchScreenEntryHeader",
header: headerhid, bycopy.} = object
timestamp* {.importc: "timestamp".}: uint64
numTouches* {.importc: "numTouches".}: uint64
## static_assert(sizeof(HidTouchScreenEntryHeader) == 0x10, "Hid touch screen entry header structure has incorrect size");
type
HidTouchScreenEntryTouch* {.importc: "HidTouchScreenEntryTouch",
header: headerhid, bycopy.} = object
timestamp* {.importc: "timestamp".}: uint64
padding* {.importc: "padding".}: uint32
touchIndex* {.importc: "touchIndex".}: uint32
x* {.importc: "x".}: uint32
y* {.importc: "y".}: uint32
diameterX* {.importc: "diameterX".}: uint32
diameterY* {.importc: "diameterY".}: uint32
angle* {.importc: "angle".}: uint32
padding_2* {.importc: "padding_2".}: uint32
## static_assert(sizeof(HidTouchScreenEntryTouch) == 0x28, "Hid touch screen touch structure has incorrect size");
type
HidTouchScreenEntry* {.importc: "HidTouchScreenEntry", header: headerhid, bycopy.} = object
header* {.importc: "header".}: HidTouchScreenEntryHeader
touches* {.importc: "touches".}: array[16, HidTouchScreenEntryTouch]
unk* {.importc: "unk".}: uint64
## static_assert(sizeof(HidTouchScreenEntry) == 0x298, "Hid touch screen entry structure has incorrect size");
type
HidTouchScreen* {.importc: "HidTouchScreen", header: headerhid, bycopy.} = object
header* {.importc: "header".}: HidTouchScreenHeader
entries* {.importc: "entries".}: array[17, HidTouchScreenEntry]
padding* {.importc: "padding".}: array[0x000003C0, uint8]
## static_assert(sizeof(HidTouchScreen) == 0x3000, "Hid touch screen structure has incorrect size");
## End HidTouchScreen
## Begin HidMouse
type
HidMouseHeader* {.importc: "HidMouseHeader", header: headerhid, bycopy.} = object
timestampTicks* {.importc: "timestampTicks".}: uint64
numEntries* {.importc: "numEntries".}: uint64
latestEntry* {.importc: "latestEntry".}: uint64
maxEntryIndex* {.importc: "maxEntryIndex".}: uint64
## static_assert(sizeof(HidMouseHeader) == 0x20, "Hid mouse header structure has incorrect size");
type
HidMouseEntry* {.importc: "HidMouseEntry", header: headerhid, bycopy.} = object
timestamp* {.importc: "timestamp".}: uint64
timestamp_2* {.importc: "timestamp_2".}: uint64
position* {.importc: "position".}: MousePosition
buttons* {.importc: "buttons".}: uint64
## static_assert(sizeof(HidMouseEntry) == 0x30, "Hid mouse entry structure has incorrect size");
type
HidMouse* {.importc: "HidMouse", header: headerhid, bycopy.} = object
header* {.importc: "header".}: HidMouseHeader
entries* {.importc: "entries".}: array[17, HidMouseEntry]
padding* {.importc: "padding".}: array[0x000000B0, uint8]
## static_assert(sizeof(HidMouse) == 0x400, "Hid mouse structure has incorrect size");
## End HidMouse
## Begin HidKeyboard
type
HidKeyboardHeader* {.importc: "HidKeyboardHeader", header: headerhid, bycopy.} = object
timestampTicks* {.importc: "timestampTicks".}: uint64
numEntries* {.importc: "numEntries".}: uint64
latestEntry* {.importc: "latestEntry".}: uint64
maxEntryIndex* {.importc: "maxEntryIndex".}: uint64
## static_assert(sizeof(HidKeyboardHeader) == 0x20, "Hid keyboard header structure has incorrect size");
type
HidKeyboardEntry* {.importc: "HidKeyboardEntry", header: headerhid, bycopy.} = object
timestamp* {.importc: "timestamp".}: uint64
timestamp_2* {.importc: "timestamp_2".}: uint64
modifier* {.importc: "modifier".}: uint64
keys* {.importc: "keys".}: array[8, uint32]
## static_assert(sizeof(HidKeyboardEntry) == 0x38, "Hid keyboard entry structure has incorrect size");
type
HidKeyboard* {.importc: "HidKeyboard", header: headerhid, bycopy.} = object
header* {.importc: "header".}: HidKeyboardHeader
entries* {.importc: "entries".}: array[17, HidKeyboardEntry]
padding* {.importc: "padding".}: array[0x00000028, uint8]
## static_assert(sizeof(HidKeyboard) == 0x400, "Hid keyboard structure has incorrect size");
## End HidKeyboard
## Begin HidController
type
HidControllerMAC* {.importc: "HidControllerMAC", header: headerhid, bycopy.} = object
timestamp* {.importc: "timestamp".}: uint64
mac* {.importc: "mac".}: array[0x00000008, uint8]
unk* {.importc: "unk".}: uint64
timestamp_2* {.importc: "timestamp_2".}: uint64
## static_assert(sizeof(HidControllerMAC) == 0x20, "Hid controller MAC structure has incorrect size");
type
HidControllerHeader* {.importc: "HidControllerHeader", header: headerhid, bycopy.} = object
`type`* {.importc: "type".}: uint32
isHalf* {.importc: "isHalf".}: uint32
singleColorsDescriptor* {.importc: "singleColorsDescriptor".}: uint32
singleColorBody* {.importc: "singleColorBody".}: uint32
singleColorButtons* {.importc: "singleColorButtons".}: uint32
splitColorsDescriptor* {.importc: "splitColorsDescriptor".}: uint32
leftColorBody* {.importc: "leftColorBody".}: uint32
leftColorButtons* {.importc: "leftColorButtons".}: uint32
rightColorBody* {.importc: "rightColorBody".}: uint32
rightColorbuttons* {.importc: "rightColorbuttons".}: uint32
## static_assert(sizeof(HidControllerHeader) == 0x28, "Hid controller header structure has incorrect size");
type
HidControllerLayoutHeader* {.importc: "HidControllerLayoutHeader",
header: headerhid, bycopy.} = object
timestampTicks* {.importc: "timestampTicks".}: uint64
numEntries* {.importc: "numEntries".}: uint64
latestEntry* {.importc: "latestEntry".}: uint64
maxEntryIndex* {.importc: "maxEntryIndex".}: uint64
## static_assert(sizeof(HidControllerLayoutHeader) == 0x20, "Hid controller layout header structure has incorrect size");
type
HidControllerInputEntry* {.importc: "HidControllerInputEntry", header: headerhid,
bycopy.} = object
timestamp* {.importc: "timestamp".}: uint64
timestamp_2* {.importc: "timestamp_2".}: uint64
buttons* {.importc: "buttons".}: uint64
joysticks* {.importc: "joysticks".}: array[JOYSTICK_NUM_STICKS, JoystickPosition]
connectionState* {.importc: "connectionState".}: uint64
## static_assert(sizeof(HidControllerInputEntry) == 0x30, "Hid controller input entry structure has incorrect size");
type
HidControllerLayout* {.importc: "HidControllerLayout", header: headerhid, bycopy.} = object
header* {.importc: "header".}: HidControllerLayoutHeader
entries* {.importc: "entries".}: array[17, HidControllerInputEntry]
## static_assert(sizeof(HidControllerLayout) == 0x350, "Hid controller layout structure has incorrect size");
type
HidController* {.importc: "HidController", header: headerhid, bycopy.} = object
header* {.importc: "header".}: HidControllerHeader
layouts* {.importc: "layouts".}: array[7, HidControllerLayout]
unk_1* {.importc: "unk_1".}: array[0x00002A70, uint8]
macLeft* {.importc: "macLeft".}: HidControllerMAC
macRight* {.importc: "macRight".}: HidControllerMAC
unk_2* {.importc: "unk_2".}: array[0x00000DF8, uint8]
## static_assert(sizeof(HidController) == 0x5000, "Hid controller structure has incorrect size");
## End HidController
type
HidSharedMemory* {.importc: "HidSharedMemory", header: headerhid, bycopy.} = object
header* {.importc: "header".}: array[0x00000400, uint8]
touchscreen* {.importc: "touchscreen".}: HidTouchScreen
mouse* {.importc: "mouse".}: HidMouse
keyboard* {.importc: "keyboard".}: HidKeyboard
unkSection1* {.importc: "unkSection1".}: array[0x00000400, uint8]
unkSection2* {.importc: "unkSection2".}: array[0x00000400, uint8]
unkSection3* {.importc: "unkSection3".}: array[0x00000400, uint8]
unkSection4* {.importc: "unkSection4".}: array[0x00000400, uint8]
unkSection5* {.importc: "unkSection5".}: array[0x00000200, uint8]
unkSection6* {.importc: "unkSection6".}: array[0x00000200, uint8]
unkSection7* {.importc: "unkSection7".}: array[0x00000200, uint8]
unkSection8* {.importc: "unkSection8".}: array[0x00000800, uint8]
controllerSerials* {.importc: "controllerSerials".}: array[0x00004000, uint8]
controllers* {.importc: "controllers".}: array[10, HidController]
unkSection9* {.importc: "unkSection9".}: array[0x00004600, uint8]
## static_assert(sizeof(HidSharedMemory) == 0x40000, "Hid Shared Memory structure has incorrect size");
type
HidVibrationDeviceInfo* {.importc: "HidVibrationDeviceInfo", header: headerhid,
bycopy.} = object
unk_x0* {.importc: "unk_x0".}: uint32
unk_x4* {.importc: "unk_x4".}: uint32 ## /< 0x1 for left-joycon, 0x2 for right-joycon.
## static_assert(sizeof(HidVibrationDeviceInfo) == 0x8, "Hid VibrationDeviceInfo structure has incorrect size");
type
HidVibrationValue* {.importc: "HidVibrationValue", header: headerhid, bycopy.} = object
amp_low* {.importc: "amp_low".}: cfloat ## /< Low Band amplitude. 1.0f: Max amplitude.
freq_low* {.importc: "freq_low".}: cfloat ## /< Low Band frequency in Hz.
amp_high* {.importc: "amp_high".}: cfloat ## /< High Band amplitude. 1.0f: Max amplitude.
freq_high* {.importc: "freq_high".}: cfloat ## /< High Band frequency in Hz.
## static_assert(sizeof(HidVibrationValue) == 0x10, "Hid VibrationValue structure has incorrect size");
proc hidInitialize*(): Result {.cdecl, importc: "hidInitialize", header: headerhid.}
proc hidExit*() {.cdecl, importc: "hidExit", header: headerhid.}
proc hidReset*() {.cdecl, importc: "hidReset", header: headerhid.}
proc hidGetSessionService*(): ptr Service {.cdecl, importc: "hidGetSessionService",
header: headerhid.}
proc hidGetSharedmemAddr*(): pointer {.cdecl, importc: "hidGetSharedmemAddr",
header: headerhid.}
proc hidSetControllerLayout*(id: HidControllerID;
layoutType: HidControllerLayoutType) {.cdecl,
importc: "hidSetControllerLayout", header: headerhid.}
proc hidGetControllerLayout*(id: HidControllerID): HidControllerLayoutType {.
cdecl, importc: "hidGetControllerLayout", header: headerhid.}
proc hidScanInput*() {.cdecl, importc: "hidScanInput", header: headerhid.}
proc hidKeysHeld*(id: HidControllerID): uint64 {.cdecl, importc: "hidKeysHeld",
header: headerhid.}
proc hidKeysDown*(id: HidControllerID): uint64 {.cdecl, importc: "hidKeysDown",
header: headerhid.}
proc hidKeysUp*(id: HidControllerID): uint64 {.cdecl, importc: "hidKeysUp",
header: headerhid.}
proc hidMouseButtonsHeld*(): uint64 {.cdecl, importc: "hidMouseButtonsHeld",
header: headerhid.}
proc hidMouseButtonsDown*(): uint64 {.cdecl, importc: "hidMouseButtonsDown",
header: headerhid.}
proc hidMouseButtonsUp*(): uint64 {.cdecl, importc: "hidMouseButtonsUp",
header: headerhid.}
proc hidMouseRead*(pos: ptr MousePosition) {.cdecl, importc: "hidMouseRead",
header: headerhid.}
proc hidKeyboardModifierHeld*(modifier: HidKeyboardModifier): bool {.cdecl,
importc: "hidKeyboardModifierHeld", header: headerhid.}
proc hidKeyboardModifierDown*(modifier: HidKeyboardModifier): bool {.cdecl,
importc: "hidKeyboardModifierDown", header: headerhid.}
proc hidKeyboardModifierUp*(modifier: HidKeyboardModifier): bool {.cdecl,
importc: "hidKeyboardModifierUp", header: headerhid.}
proc hidKeyboardHeld*(key: HidKeyboardScancode): bool {.cdecl,
importc: "hidKeyboardHeld", header: headerhid.}
proc hidKeyboardDown*(key: HidKeyboardScancode): bool {.cdecl,
importc: "hidKeyboardDown", header: headerhid.}
proc hidKeyboardUp*(key: HidKeyboardScancode): bool {.cdecl,
importc: "hidKeyboardUp", header: headerhid.}
proc hidTouchCount*(): uint32 {.cdecl, importc: "hidTouchCount", header: headerhid.}
proc hidTouchRead*(pos: ptr touchPosition; point_id: uint32) {.cdecl,
importc: "hidTouchRead", header: headerhid.}
proc hidJoystickRead*(pos: ptr JoystickPosition; id: HidControllerID;
stick: HidControllerJoystick) {.cdecl,
importc: "hidJoystickRead", header: headerhid.}
## / This can be used to check what CONTROLLER_P1_AUTO uses.
## / Returns 0 when CONTROLLER_PLAYER_1 is connected, otherwise returns 1 for handheld-mode.
proc hidGetHandheldMode*(): bool {.cdecl, importc: "hidGetHandheldMode",
header: headerhid.}
## / Use this if you want to use a single joy-con as a dedicated CONTROLLER_PLAYER_*.
## / When used, both joy-cons in a pair should be used with this (CONTROLLER_PLAYER_1 and CONTROLLER_PLAYER_2 for example).
## / id must be CONTROLLER_PLAYER_*.
proc hidSetNpadJoyAssignmentModeSingleByDefault*(id: HidControllerID): Result {.
cdecl, importc: "hidSetNpadJoyAssignmentModeSingleByDefault",
header: headerhid.}
## / Use this if you want to use a pair of joy-cons as a single CONTROLLER_PLAYER_*. Only necessary if you want to use this mode in your application after \ref hidSetNpadJoyAssignmentModeSingleByDefault was used with this pair of joy-cons.
## / Used automatically during app startup/exit for all controllers.
## / When used, both joy-cons in a pair should be used with this (CONTROLLER_PLAYER_1 and CONTROLLER_PLAYER_2 for example).
## / id must be CONTROLLER_PLAYER_*.
proc hidSetNpadJoyAssignmentModeDual*(id: HidControllerID): Result {.cdecl,
importc: "hidSetNpadJoyAssignmentModeDual", header: headerhid.}
## / Merge two single joy-cons into a dual-mode controller. Use this after \ref hidSetNpadJoyAssignmentModeDual, when \ref hidSetNpadJoyAssignmentModeSingleByDefault was previously used (this includes using this manually at application exit).
proc hidMergeSingleJoyAsDualJoy*(id0: HidControllerID; id1: HidControllerID): Result {.
cdecl, importc: "hidMergeSingleJoyAsDualJoy", header: headerhid.}
proc hidInitializeVibrationDevices*(VibrationDeviceHandles: ptr uint32;
total_handles: csize; id: HidControllerID;
`type`: HidControllerType): Result {.cdecl,
importc: "hidInitializeVibrationDevices", header: headerhid.}
## / Gets HidVibrationDeviceInfo for the specified VibrationDeviceHandle.
proc hidGetVibrationDeviceInfo*(VibrationDeviceHandle: ptr uint32;
VibrationDeviceInfo: ptr HidVibrationDeviceInfo): Result {.
cdecl, importc: "hidGetVibrationDeviceInfo", header: headerhid.}
## / Send the VibrationValue to the specified VibrationDeviceHandle.
proc hidSendVibrationValue*(VibrationDeviceHandle: ptr uint32;
VibrationValue: ptr HidVibrationValue): Result {.cdecl,
importc: "hidSendVibrationValue", header: headerhid.}
## / Gets the current HidVibrationValue for the specified VibrationDeviceHandle.
proc hidGetActualVibrationValue*(VibrationDeviceHandle: ptr uint32;
VibrationValue: ptr HidVibrationValue): Result {.
cdecl, importc: "hidGetActualVibrationValue", header: headerhid.}
## / Sets whether vibration is allowed, this also affects the config displayed by System Settings.
proc hidPermitVibration*(flag: bool): Result {.cdecl,
importc: "hidPermitVibration", header: headerhid.}
## / Gets whether vibration is allowed.
proc hidIsVibrationPermitted*(flag: ptr bool): Result {.cdecl,
importc: "hidIsVibrationPermitted", header: headerhid.}
## / Send VibrationValues[index] to VibrationDeviceHandles[index], where count is the number of entries in the VibrationDeviceHandles/VibrationValues arrays.
proc hidSendVibrationValues*(VibrationDeviceHandles: ptr uint32;
VibrationValues: ptr HidVibrationValue; count: csize): Result {.
cdecl, importc: "hidSendVibrationValues", header: headerhid.}

View file

@ -1,64 +0,0 @@
import strutils
import ospaths
const headerioctl = currentSourcePath().splitPath().head & "/nx/include/switch/gfx/ioctl.h"
## The below defines are based on Linux kernel ioctl.h.
const
UNV_IOC_NRBITS* = 8
UNV_IOC_TYPEBITS* = 8
UNV_IOC_SIZEBITS* = 14
UNV_IOC_DIRBITS* = 2
UNV_IOC_NRMASK* = ((1 shl UNV_IOC_NRBITS) - 1)
UNV_IOC_TYPEMASK* = ((1 shl UNV_IOC_TYPEBITS) - 1)
UNV_IOC_SIZEMASK* = ((1 shl UNV_IOC_SIZEBITS) - 1)
UNV_IOC_DIRMASK* = ((1 shl UNV_IOC_DIRBITS) - 1)
UNV_IOC_NRSHIFT* = 0
UNV_IOC_TYPESHIFT* = (UNV_IOC_NRSHIFT + UNV_IOC_NRBITS)
UNV_IOC_SIZESHIFT* = (UNV_IOC_TYPESHIFT + UNV_IOC_TYPEBITS)
UNV_IOC_DIRSHIFT* = (UNV_IOC_SIZESHIFT + UNV_IOC_SIZEBITS)
##
## Direction bits.
##
const
UNV_IOC_NONE* = 0
UNV_IOC_WRITE* = 1
UNV_IOC_READ* = 2
template UNV_IOC*(dir, `type`, nr, size: untyped): untyped =
(((dir) shl UNV_IOC_DIRSHIFT) or ((`type`) shl UNV_IOC_TYPESHIFT) or
((nr) shl UNV_IOC_NRSHIFT) or ((size) shl UNV_IOC_SIZESHIFT))
## used to create numbers
template UNV_IO*(`type`, nr: untyped): untyped =
UNV_IOC(UNV_IOC_NONE, (`type`), (nr), 0)
template UNV_IOR*(`type`, nr, size: untyped): untyped =
UNV_IOC(UNV_IOC_READ, (`type`), (nr), sizeof((size)))
template UNV_IOW*(`type`, nr, size: untyped): untyped =
UNV_IOC(UNV_IOC_WRITE, (`type`), (nr), sizeof((size)))
template UNV_IOWR*(`type`, nr, size: untyped): untyped =
UNV_IOC(UNV_IOC_READ or UNV_IOC_WRITE, (`type`), (nr), sizeof((size)))
## used to decode ioctl numbers..
template UNV_IOC_DIR*(nr: untyped): untyped =
(((nr) shr UNV_IOC_DIRSHIFT) and UNV_IOC_DIRMASK)
template UNV_IOC_TYPE*(nr: untyped): untyped =
(((nr) shr UNV_IOC_TYPESHIFT) and UNV_IOC_TYPEMASK)
template UNV_IOC_NR*(nr: untyped): untyped =
(((nr) shr UNV_IOC_NRSHIFT) and UNV_IOC_NRMASK)
template UNV_IOC_SIZE*(nr: untyped): untyped =
(((nr) shr UNV_IOC_SIZESHIFT) and UNV_IOC_SIZEMASK)
const
DUnv_in* = true
DUnv_out* = true
DUnv_inout* = true

View file

@ -1,348 +0,0 @@
import strutils
import ospaths
const headeripc = currentSourcePath().splitPath().head & "/nx/include/switch/kernel/ipc.h"
## *
## @file ipc.h
## @brief Inter-process communication handling
## @author plutoo
## @copyright libnx Authors
##
import
libnx/wrapper/types,
libnx/wrapper/result, libnx/wrapper/tls, libnx/wrapper/svc
## / IPC input header magic
const
SFCI_MAGIC* = 0x49434653
## / IPC output header magic
const
SFCO_MAGIC* = 0x4F434653
## / IPC invalid object ID
const
IPC_INVALID_OBJECT_ID* = uint32.high
## /@name IPC request building
## /@{
## / IPC command (request) structure.
const
IPC_MAX_BUFFERS* = 8
IPC_MAX_OBJECTS* = 8
type
BufferType* {.size: sizeof(cint).} = enum
BufferType_Normal = 0, ## /< Regular buffer.
BufferType_Type1 = 1, ## /< Allows ProcessMemory and shared TransferMemory.
BufferType_Invalid = 2, BufferType_Type3 = 3
BufferDirection* {.size: sizeof(cint).} = enum
BufferDirection_Send = 0, BufferDirection_Recv = 1, BufferDirection_Exch = 2
IpcCommandType* {.size: sizeof(cint).} = enum
IpcCommandType_Invalid = 0, IpcCommandType_LegacyRequest = 1,
IpcCommandType_Close = 2, IpcCommandType_LegacyControl = 3,
IpcCommandType_Request = 4, IpcCommandType_Control = 5,
IpcCommandType_RequestWithContext = 6, IpcCommandType_ControlWithContext = 7
DomainMessageType* {.size: sizeof(cint).} = enum
DomainMessageType_Invalid = 0, DomainMessageType_SendMessage = 1,
DomainMessageType_Close = 2
## / IPC domain message header.
type
DomainMessageHeader* {.importc: "DomainMessageHeader", header: headeripc, bycopy.} = object
Type* {.importc: "Type".}: uint8
NumObjectIds* {.importc: "NumObjectIds".}: uint8
Length* {.importc: "Length".}: uint16
ThisObjectId* {.importc: "ThisObjectId".}: uint32
Pad* {.importc: "Pad".}: array[2, uint32]
IpcCommand* {.importc: "IpcCommand", header: headeripc, bycopy.} = object
NumSend* {.importc: "NumSend".}: csize ## A
NumRecv* {.importc: "NumRecv".}: csize ## B
NumExch* {.importc: "NumExch".}: csize ## W
Buffers* {.importc: "Buffers".}: array[IPC_MAX_BUFFERS, pointer]
BufferSizes* {.importc: "BufferSizes".}: array[IPC_MAX_BUFFERS, csize]
BufferTypes* {.importc: "BufferTypes".}: array[IPC_MAX_BUFFERS, BufferType]
NumStaticIn* {.importc: "NumStaticIn".}: csize ## X
NumStaticOut* {.importc: "NumStaticOut".}: csize ## C
Statics* {.importc: "Statics".}: array[IPC_MAX_BUFFERS, pointer]
StaticSizes* {.importc: "StaticSizes".}: array[IPC_MAX_BUFFERS, csize]
StaticIndices* {.importc: "StaticIndices".}: array[IPC_MAX_BUFFERS, uint8]
SendPid* {.importc: "SendPid".}: bool
NumHandlesCopy* {.importc: "NumHandlesCopy".}: csize
NumHandlesMove* {.importc: "NumHandlesMove".}: csize
Handles* {.importc: "Handles".}: array[IPC_MAX_OBJECTS, Handle]
NumObjectIds* {.importc: "NumObjectIds".}: csize
ObjectIds* {.importc: "ObjectIds".}: array[IPC_MAX_OBJECTS, uint32]
## *
## @brief Initializes an IPC command structure.
## @param cmd IPC command structure.
##
proc ipcInitialize*(cmd: ptr IpcCommand) {.inline, cdecl, importc: "ipcInitialize",
header: headeripc.}
## / IPC buffer descriptor.
type
IpcBufferDescriptor* {.importc: "IpcBufferDescriptor", header: headeripc, bycopy.} = object
Size* {.importc: "Size".}: uint32 ## /< Size of the buffer.
Addr* {.importc: "Addr".}: uint32 ## /< Lower 32-bits of the address of the buffer
Packed* {.importc: "Packed".}: uint32 ## /< Packed data (including higher bits of the address)
## / IPC static send-buffer descriptor.
type
IpcStaticSendDescriptor* {.importc: "IpcStaticSendDescriptor", header: headeripc,
bycopy.} = object
Packed* {.importc: "Packed".}: uint32 ## /< Packed data (including higher bits of the address)
Addr* {.importc: "Addr".}: uint32 ## /< Lower 32-bits of the address
## / IPC static receive-buffer descriptor.
type
IpcStaticRecvDescriptor* {.importc: "IpcStaticRecvDescriptor", header: headeripc,
bycopy.} = object
Addr* {.importc: "Addr".}: uint32 ## /< Lower 32-bits of the address of the buffer
Packed* {.importc: "Packed".}: uint32 ## /< Packed data (including higher bits of the address)
## *
## @brief Adds a buffer to an IPC command structure.
## @param cmd IPC command structure.
## @param buffer Address of the buffer.
## @param size Size of the buffer.
## @param type Buffer type.
##
proc ipcAddSendBuffer*(cmd: ptr IpcCommand; buffer: pointer; size: csize;
`type`: BufferType) {.inline, cdecl,
importc: "ipcAddSendBuffer", header: headeripc.}
## *
## @brief Adds a receive-buffer to an IPC command structure.
## @param cmd IPC command structure.
## @param buffer Address of the buffer.
## @param size Size of the buffer.
## @param type Buffer type.
##
proc ipcAddRecvBuffer*(cmd: ptr IpcCommand; buffer: pointer; size: csize;
`type`: BufferType) {.inline, cdecl,
importc: "ipcAddRecvBuffer", header: headeripc.}
## *
## @brief Adds an exchange-buffer to an IPC command structure.
## @param cmd IPC command structure.
## @param buffer Address of the buffer.
## @param size Size of the buffer.
## @param type Buffer type.
##
proc ipcAddExchBuffer*(cmd: ptr IpcCommand; buffer: pointer; size: csize;
`type`: BufferType) {.inline, cdecl,
importc: "ipcAddExchBuffer", header: headeripc.}
## *
## @brief Adds a static-buffer to an IPC command structure.
## @param cmd IPC command structure.
## @param buffer Address of the buffer.
## @param size Size of the buffer.
## @param index Index of buffer.
##
proc ipcAddSendStatic*(cmd: ptr IpcCommand; buffer: pointer; size: csize; index: uint8) {.
inline, cdecl, importc: "ipcAddSendStatic", header: headeripc.}
## *
## @brief Adds a static-receive-buffer to an IPC command structure.
## @param cmd IPC command structure.
## @param buffer Address of the buffer.
## @param size Size of the buffer.
## @param index Index of buffer.
##
proc ipcAddRecvStatic*(cmd: ptr IpcCommand; buffer: pointer; size: csize; index: uint8) {.
inline, cdecl, importc: "ipcAddRecvStatic", header: headeripc.}
## *
## @brief Adds a smart-buffer (buffer + static-buffer pair) to an IPC command structure.
## @param cmd IPC command structure.
## @param ipc_buffer_size IPC buffer size.
## @param buffer Address of the buffer.
## @param size Size of the buffer.
## @param index Index of buffer.
##
proc ipcAddSendSmart*(cmd: ptr IpcCommand; ipc_buffer_size: csize; buffer: pointer;
size: csize; index: uint8) {.inline, cdecl,
importc: "ipcAddSendSmart", header: headeripc.}
## *
## @brief Adds a smart-receive-buffer (buffer + static-receive-buffer pair) to an IPC command structure.
## @param cmd IPC command structure.
## @param ipc_buffer_size IPC buffer size.
## @param buffer Address of the buffer.
## @param size Size of the buffer.
## @param index Index of buffer.
##
proc ipcAddRecvSmart*(cmd: ptr IpcCommand; ipc_buffer_size: csize; buffer: pointer;
size: csize; index: uint8) {.inline, cdecl,
importc: "ipcAddRecvSmart", header: headeripc.}
## *
## @brief Tags an IPC command structure to send the PID.
## @param cmd IPC command structure.
##
proc ipcSendPid*(cmd: ptr IpcCommand) {.inline, cdecl, importc: "ipcSendPid",
header: headeripc.}
## *
## @brief Adds a copy-handle to be sent through an IPC command structure.
## @param cmd IPC command structure.
## @param h Handle to send.
## @remark The receiving process gets a copy of the handle.
##
proc ipcSendHandleCopy*(cmd: ptr IpcCommand; h: Handle) {.inline, cdecl,
importc: "ipcSendHandleCopy", header: headeripc.}
## *
## @brief Adds a move-handle to be sent through an IPC command structure.
## @param cmd IPC command structure.
## @param h Handle to send.
## @remark The sending process loses ownership of the handle, which is transferred to the receiving process.
##
proc ipcSendHandleMove*(cmd: ptr IpcCommand; h: Handle) {.inline, cdecl,
importc: "ipcSendHandleMove", header: headeripc.}
## *
## @brief Prepares the header of an IPC command structure.
## @param cmd IPC command structure.
## @param sizeof_raw Size in bytes of the raw data structure to embed inside the IPC request
## @return Pointer to the raw embedded data structure in the request, ready to be filled out.
##
proc ipcPrepareHeader*(cmd: ptr IpcCommand; sizeof_raw: csize): pointer {.inline,
cdecl, importc: "ipcPrepareHeader", header: headeripc.}
## *
## @brief Dispatches an IPC request.
## @param session IPC session handle.
## @return Result code.
##
proc ipcDispatch*(session: Handle): Result {.inline, cdecl, importc: "ipcDispatch",
header: headeripc.}
## /@}
## /@name IPC response parsing
## /@{
## / IPC parsed command (response) structure.
type
IpcParsedCommand* {.importc: "IpcParsedCommand", header: headeripc, bycopy.} = object
CommandType* {.importc: "CommandType".}: IpcCommandType ## /< Type of the command
HasPid* {.importc: "HasPid".}: bool ## /< true if the 'Pid' field is filled out.
Pid* {.importc: "Pid".}: uint64 ## /< PID included in the response (only if HasPid is true)
NumHandles* {.importc: "NumHandles".}: csize ## /< Number of handles copied.
Handles* {.importc: "Handles".}: array[IPC_MAX_OBJECTS, Handle] ## /< Handles.
WasHandleCopied* {.importc: "WasHandleCopied".}: array[IPC_MAX_OBJECTS, bool] ## /< true if the handle was moved, false if it was copied.
IsDomainMessage* {.importc: "IsDomainMessage".}: bool ## /< true if the the message is a Domain message.
MessageType* {.importc: "MessageType".}: DomainMessageType ## /< Type of the domain message.
MessageLength* {.importc: "MessageLength".}: uint32 ## /< Size of rawdata (for domain messages).
ThisObjectId* {.importc: "ThisObjectId".}: uint32 ## /< Object ID to call the command on (for domain messages).
NumObjectIds* {.importc: "NumObjectIds".}: csize ## /< Number of object IDs (for domain messages).
ObjectIds* {.importc: "ObjectIds".}: array[IPC_MAX_OBJECTS, uint32] ## /< Object IDs (for domain messages).
NumBuffers* {.importc: "NumBuffers".}: csize ## /< Number of buffers in the response.
Buffers* {.importc: "Buffers".}: array[IPC_MAX_BUFFERS, pointer] ## /< Pointers to the buffers.
BufferSizes* {.importc: "BufferSizes".}: array[IPC_MAX_BUFFERS, csize] ## /< Sizes of the buffers.
BufferTypes* {.importc: "BufferTypes".}: array[IPC_MAX_BUFFERS, BufferType] ## /< Types of the buffers.
BufferDirections* {.importc: "BufferDirections".}: array[IPC_MAX_BUFFERS,
BufferDirection] ## /< Direction of each buffer.
NumStatics* {.importc: "NumStatics".}: csize ## /< Number of statics in the response.
Statics* {.importc: "Statics".}: array[IPC_MAX_BUFFERS, pointer] ## /< Pointers to the statics.
StaticSizes* {.importc: "StaticSizes".}: array[IPC_MAX_BUFFERS, csize] ## /< Sizes of the statics.
StaticIndices* {.importc: "StaticIndices".}: array[IPC_MAX_BUFFERS, uint8] ## /< Indices of the statics.
NumStaticsOut* {.importc: "NumStaticsOut".}: csize ## /< Number of output statics available in the response.
Raw* {.importc: "Raw".}: pointer ## /< Pointer to the raw embedded data structure in the response.
RawWithoutPadding* {.importc: "RawWithoutPadding".}: pointer ## /< Pointer to the raw embedded data structure, without padding.
RawSize* {.importc: "RawSize".}: csize ## /< Size of the raw embedded data.
## *
## @brief Parse an IPC command response into an IPC parsed command structure.
## @param IPC parsed command structure to fill in.
## @return Result code.
##
proc ipcParse*(r: ptr IpcParsedCommand): Result {.inline, cdecl, importc: "ipcParse",
header: headeripc.}
## *
## @brief Queries the size of an IPC pointer buffer.
## @param session IPC session handle.
## @param size Output variable in which to store the size.
## @return Result code.
##
proc ipcQueryPointerBufferSize*(session: Handle; size: ptr csize): Result {.inline,
cdecl, importc: "ipcQueryPointerBufferSize", header: headeripc.}
## *
## @brief Closes the IPC session with proper clean up.
## @param session IPC session handle.
## @return Result code.
##
proc ipcCloseSession*(session: Handle): Result {.inline, cdecl,
importc: "ipcCloseSession", header: headeripc.}
## /@}
## /@name IPC domain handling
## /@{
## *
## @brief Converts an IPC session handle into a domain.
## @param session IPC session handle.
## @param object_id_out Output variable in which to store the object ID.
## @return Result code.
##
proc ipcConvertSessionToDomain*(session: Handle; object_id_out: ptr uint32): Result {.
inline, cdecl, importc: "ipcConvertSessionToDomain", header: headeripc.}
## *
## @brief Adds an object ID to be sent through an IPC domain command structure.
## @param cmd IPC domain command structure.
## @param object_id Object ID to send.
##
proc ipcSendObjectId*(cmd: ptr IpcCommand; object_id: uint32) {.inline, cdecl,
importc: "ipcSendObjectId", header: headeripc.}
## *
## @brief Prepares the header of an IPC command structure (domain version).
## @param cmd IPC command structure.
## @param sizeof_raw Size in bytes of the raw data structure to embed inside the IPC request
## @oaram object_id Domain object ID.
## @return Pointer to the raw embedded data structure in the request, ready to be filled out.
##
proc ipcPrepareHeaderForDomain*(cmd: ptr IpcCommand; sizeof_raw: csize; object_id: uint32): pointer {.
inline, cdecl, importc: "ipcPrepareHeaderForDomain", header: headeripc.}
## *
## @brief Parse an IPC command response into an IPC parsed command structure (domain version).
## @param IPC parsed command structure to fill in.
## @return Result code.
##
proc ipcParseForDomain*(r: ptr IpcParsedCommand): Result {.inline, cdecl,
importc: "ipcParseForDomain", header: headeripc.}
## *
## @brief Closes a domain object by ID.
## @param session IPC session handle.
## @param object_id ID of the object to close.
## @return Result code.
##
proc ipcCloseObjectById*(session: Handle; object_id: uint32): Result {.inline, cdecl,
importc: "ipcCloseObjectById", header: headeripc.}
## /@}

View file

@ -1,71 +0,0 @@
import strutils
import ospaths
const headerirs = currentSourcePath().splitPath().head & "/nx/include/switch/services/irs.h"
import libnx/wrapper/types
import libnx/wrapper/sm
import libnx/wrapper/hid
type
IrsPackedMomentProcessorConfig* {.importc: "IrsPackedMomentProcessorConfig",
header: headerirs, bycopy.} = object
unk_x0* {.importc: "unk_x0".}: uint64
unk_x8* {.importc: "unk_x8".}: uint8
unk_x9* {.importc: "unk_x9".}: uint8
unk_xa* {.importc: "unk_xa".}: uint8
pad* {.importc: "pad".}: array[5, uint8]
unk_x10* {.importc: "unk_x10".}: uint16
unk_x12* {.importc: "unk_x12".}: uint32
unk_x16* {.importc: "unk_x16".}: uint16
unk_constant* {.importc: "unk_constant".}: uint32
unk_x1c* {.importc: "unk_x1c".}: uint8
unk_x1d* {.importc: "unk_x1d".}: uint8
pad2* {.importc: "pad2".}: array[2, uint8]
IrsImageTransferProcessorConfig* {.importc: "IrsImageTransferProcessorConfig",
header: headerirs, bycopy.} = object
exposure* {.importc: "exposure".}: uint64
ir_leds* {.importc: "ir_leds".}: uint32
digital_gain* {.importc: "digital_gain".}: uint32
color_invert* {.importc: "color_invert".}: uint8
pad* {.importc: "pad".}: array[7, uint8]
sensor_res* {.importc: "sensor_res".}: uint32
IrsPackedImageTransferProcessorConfig* {.
importc: "IrsPackedImageTransferProcessorConfig", header: headerirs, bycopy.} = object
exposure* {.importc: "exposure".}: uint64
ir_leds* {.importc: "ir_leds".}: uint8
digital_gain* {.importc: "digital_gain".}: uint8
color_invert* {.importc: "color_invert".}: uint8
pad* {.importc: "pad".}: array[5, uint8]
unk_constant* {.importc: "unk_constant".}: uint32
sensor_res* {.importc: "sensor_res".}: uint8
pad2* {.importc: "pad2".}: array[3, uint8]
IrsImageTransferProcessorState* {.importc: "IrsImageTransferProcessorState",
header: headerirs, bycopy.} = object
unk_x0* {.importc: "unk_x0".}: array[0x00000010, uint8]
proc irsInitialize*(): Result {.cdecl, importc: "irsInitialize", header: headerirs.}
proc irsExit*() {.cdecl, importc: "irsExit", header: headerirs.}
proc irsGetSessionService*(): ptr Service {.cdecl, importc: "irsGetSessionService",
header: headerirs.}
proc irsGetSharedmemAddr*(): pointer {.cdecl, importc: "irsGetSharedmemAddr",
header: headerirs.}
proc irsActivateIrsensor*(activate: bool): Result {.cdecl,
importc: "irsActivateIrsensor", header: headerirs.}
proc irsGetIrCameraHandle*(IrCameraHandle: ptr uint32; id: HidControllerID): Result {.
cdecl, importc: "irsGetIrCameraHandle", header: headerirs.}
proc irsRunImageTransferProcessor*(IrCameraHandle: uint32;
config: ptr IrsImageTransferProcessorConfig;
size: csize): Result {.cdecl,
importc: "irsRunImageTransferProcessor", header: headerirs.}
proc irsGetImageTransferProcessorState*(IrCameraHandle: uint32; buffer: pointer;
size: csize; state: ptr IrsImageTransferProcessorState): Result {.
cdecl, importc: "irsGetImageTransferProcessorState", header: headerirs.}
proc irsStopImageProcessor*(IrCameraHandle: uint32): Result {.cdecl,
importc: "irsStopImageProcessor", header: headerirs.}
proc irsSuspendImageProcessor*(IrCameraHandle: uint32): Result {.cdecl,
importc: "irsSuspendImageProcessor", header: headerirs.}
proc irsGetDefaultImageTransferProcessorConfig*(
config: ptr IrsImageTransferProcessorConfig) {.cdecl,
importc: "irsGetDefaultImageTransferProcessorConfig", header: headerirs.}

View file

@ -1,29 +0,0 @@
import strutils
import ospaths
const headerjit = currentSourcePath().splitPath().head & "/nx/include/switch/kernel/jit.h"
import libnx/wrapper/types
type
JitType* {.size: sizeof(cint).} = enum
JitType_CodeMemory, JitType_JitMemory
Jit* {.importc: "Jit", header: headerjit, bycopy.} = object
`type`* {.importc: "type".}: JitType
size* {.importc: "size".}: csize
src_addr* {.importc: "src_addr".}: pointer
rx_addr* {.importc: "rx_addr".}: pointer
rw_addr* {.importc: "rw_addr".}: pointer
is_executable* {.importc: "is_executable".}: bool
handle* {.importc: "handle".}: Handle
proc jitCreate*(j: ptr Jit; size: csize): Result {.cdecl, importc: "jitCreate",
header: headerjit.}
proc jitTransitionToWritable*(j: ptr Jit): Result {.cdecl,
importc: "jitTransitionToWritable", header: headerjit.}
proc jitTransitionToExecutable*(j: ptr Jit): Result {.cdecl,
importc: "jitTransitionToExecutable", header: headerjit.}
proc jitClose*(j: ptr Jit): Result {.cdecl, importc: "jitClose", header: headerjit.}
proc jitGetRwAddr*(j: ptr Jit): pointer {.cdecl, importc: "jitGetRwAddr",
header: headerjit.}
proc jitGetRxAddr*(j: ptr Jit): pointer {.cdecl, importc: "jitGetRxAddr",
header: headerjit.}

View file

@ -1,57 +0,0 @@
import strutils
import ospaths
const headerldr = currentSourcePath().splitPath().head & "/nx/include/switch/services/ldr.h"
import libnx/wrapper/types
import libnx/wrapper/sm
import libnx/wrapper/fs
type
LoaderProgramInfo* {.importc: "LoaderProgramInfo", header: headerldr, bycopy.} = object
main_thread_priority* {.importc: "main_thread_priority".}: uint8
default_cpu_id* {.importc: "default_cpu_id".}: uint8
application_type* {.importc: "application_type".}: uint16
main_thread_stack_size* {.importc: "main_thread_stack_size".}: uint32
title_id* {.importc: "title_id".}: uint64
acid_sac_size* {.importc: "acid_sac_size".}: uint32
aci0_sac_size* {.importc: "aci0_sac_size".}: uint32
acid_fac_size* {.importc: "acid_fac_size".}: uint32
aci0_fah_size* {.importc: "aci0_fah_size".}: uint32
ac_buffer* {.importc: "ac_buffer".}: array[0x000003E0, uint8]
LoaderNsoInfo* {.importc: "LoaderNsoInfo", header: headerldr, bycopy.} = object
base_address* {.importc: "base_address".}: uint64
size* {.importc: "size".}: uint64
build_id* {.importc: "build_id".}: array[0x00000020, uint8]
proc ldrShellInitialize*(): Result {.cdecl, importc: "ldrShellInitialize",
header: headerldr.}
proc ldrShellExit*() {.cdecl, importc: "ldrShellExit", header: headerldr.}
proc ldrDmntInitialize*(): Result {.cdecl, importc: "ldrDmntInitialize",
header: headerldr.}
proc ldrDmntExit*() {.cdecl, importc: "ldrDmntExit", header: headerldr.}
proc ldrPmInitialize*(): Result {.cdecl, importc: "ldrPmInitialize",
header: headerldr.}
proc ldrPmExit*() {.cdecl, importc: "ldrPmExit", header: headerldr.}
proc ldrShellAddTitleToLaunchQueue*(tid: uint64; args: pointer; args_size: csize): Result {.
cdecl, importc: "ldrShellAddTitleToLaunchQueue", header: headerldr.}
proc ldrShellClearLaunchQueue*(): Result {.cdecl,
importc: "ldrShellClearLaunchQueue",
header: headerldr.}
proc ldrDmntAddTitleToLaunchQueue*(tid: uint64; args: pointer; args_size: csize): Result {.
cdecl, importc: "ldrDmntAddTitleToLaunchQueue", header: headerldr.}
proc ldrDmntClearLaunchQueue*(): Result {.cdecl,
importc: "ldrDmntClearLaunchQueue",
header: headerldr.}
proc ldrDmntGetNsoInfos*(pid: uint64; out_nso_infos: ptr LoaderNsoInfo; out_size: csize;
num_out: ptr uint32): Result {.cdecl,
importc: "ldrDmntGetNsoInfos", header: headerldr.}
proc ldrPmCreateProcess*(flags: uint64; launch_index: uint64; reslimit_h: Handle;
out_process_h: ptr Handle): Result {.cdecl,
importc: "ldrPmCreateProcess", header: headerldr.}
proc ldrPmGetProgramInfo*(title_id: uint64; storage_id: FsStorageId;
out_program_info: ptr LoaderProgramInfo): Result {.cdecl,
importc: "ldrPmGetProgramInfo", header: headerldr.}
proc ldrPmRegisterTitle*(title_id: uint64; storage_id: FsStorageId; out_index: ptr uint64): Result {.
cdecl, importc: "ldrPmRegisterTitle", header: headerldr.}
proc ldrPmUnregisterTitle*(launch_index: uint64): Result {.cdecl,
importc: "ldrPmUnregisterTitle", header: headerldr.}

View file

@ -1,33 +0,0 @@
import strutils
import ospaths
const headerlock = "/opt/devkitpro/devkitA64/aarch64-none-elf/include/sys/lock.h"
import libnx/wrapper/types
type
LOCK_T* = int32_t
DUlock_t* {.importc: "__lock_t", header: headerlock, bycopy.} = object
lock* {.importc: "lock".}: LOCK_T
thread_tag* {.importc: "thread_tag".}: uint32_t
counter* {.importc: "counter".}: uint32_t
LOCK_RECURSIVE_T* = DUlock_t
proc DUlibc_lock_init*(lock: ptr LOCK_T) {.cdecl, importc: "__libc_lock_init",
header: headerlock.}
proc DUlibc_lock_init_recursive*(lock: ptr LOCK_RECURSIVE_T) {.cdecl,
importc: "__libc_lock_init_recursive", header: headerlock.}
proc DUlibc_lock_close*(lock: ptr LOCK_T) {.cdecl, importc: "__libc_lock_close",
header: headerlock.}
proc DUlibc_lock_close_recursive*(lock: ptr LOCK_RECURSIVE_T) {.cdecl,
importc: "__libc_lock_close_recursive", header: headerlock.}
proc DUlibc_lock_acquire*(lock: ptr LOCK_T) {.cdecl,
importc: "__libc_lock_acquire", header: headerlock.}
proc DUlibc_lock_acquire_recursive*(lock: ptr LOCK_RECURSIVE_T) {.cdecl,
importc: "__libc_lock_acquire_recursive", header: headerlock.}
proc DUlibc_lock_release*(lock: ptr LOCK_T) {.cdecl,
importc: "__libc_lock_release", header: headerlock.}
proc DUlibc_lock_release_recursive*(lock: ptr LOCK_RECURSIVE_T) {.cdecl,
importc: "__libc_lock_release_recursive", header: headerlock.}
proc DUlibc_lock_try_acquire*(lock: ptr LOCK_T): cint {.cdecl,
importc: "__libc_lock_try_acquire", header: headerlock.}
proc DUlibc_lock_try_acquire_recursive*(lock: ptr LOCK_RECURSIVE_T): cint {.cdecl,
importc: "__libc_lock_try_acquire_recursive", header: headerlock.}

View file

@ -1,52 +0,0 @@
import strutils
import ospaths
const headerlr = currentSourcePath().splitPath().head & "/nx/include/switch/services/lr.h"
import libnx/wrapper/types
import libnx/wrapper/sm
import libnx/wrapper/fs
type
LrLocationResolver* {.importc: "LrLocationResolver", header: headerlr, bycopy.} = object
s* {.importc: "s".}: Service
LrRegisteredLocationResolver* {.importc: "LrRegisteredLocationResolver",
header: headerlr, bycopy.} = object
s* {.importc: "s".}: Service
proc lrInitialize*(): Result {.cdecl, importc: "lrInitialize", header: headerlr.}
proc lrExit*() {.cdecl, importc: "lrExit", header: headerlr.}
proc lrOpenLocationResolver*(storage: FsStorageId; `out`: ptr LrLocationResolver): Result {.
cdecl, importc: "lrOpenLocationResolver", header: headerlr.}
proc lrOpenRegisteredLocationResolver*(`out`: ptr LrRegisteredLocationResolver): Result {.
cdecl, importc: "lrOpenRegisteredLocationResolver", header: headerlr.}
proc lrLrResolveProgramPath*(lr: ptr LrLocationResolver; tid: uint64; `out`: cstring): Result {.
cdecl, importc: "lrLrResolveProgramPath", header: headerlr.}
proc lrLrRedirectProgramPath*(lr: ptr LrLocationResolver; tid: uint64; path: cstring): Result {.
cdecl, importc: "lrLrRedirectProgramPath", header: headerlr.}
proc lrLrResolveApplicationControlPath*(lr: ptr LrLocationResolver; tid: uint64;
`out`: cstring): Result {.cdecl,
importc: "lrLrResolveApplicationControlPath", header: headerlr.}
proc lrLrResolveApplicationHtmlDocumentPath*(lr: ptr LrLocationResolver; tid: uint64;
`out`: cstring): Result {.cdecl,
importc: "lrLrResolveApplicationHtmlDocumentPath",
header: headerlr.}
proc lrLrResolveDataPath*(lr: ptr LrLocationResolver; tid: uint64; `out`: cstring): Result {.
cdecl, importc: "lrLrResolveDataPath", header: headerlr.}
proc lrLrRedirectApplicationControlPath*(lr: ptr LrLocationResolver; tid: uint64;
path: cstring): Result {.cdecl,
importc: "lrLrRedirectApplicationControlPath", header: headerlr.}
proc lrLrRedirectApplicationHtmlDocumentPath*(lr: ptr LrLocationResolver; tid: uint64;
path: cstring): Result {.cdecl,
importc: "lrLrRedirectApplicationHtmlDocumentPath",
header: headerlr.}
proc lrLrResolveLegalInformationPath*(lr: ptr LrLocationResolver; tid: uint64;
`out`: cstring): Result {.cdecl,
importc: "lrLrResolveLegalInformationPath", header: headerlr.}
proc lrLrRedirectLegalInformationPath*(lr: ptr LrLocationResolver; tid: uint64;
path: cstring): Result {.cdecl,
importc: "lrLrRedirectLegalInformationPath", header: headerlr.}
proc lrLrRefresh*(lr: ptr LrLocationResolver): Result {.cdecl,
importc: "lrLrRefresh", header: headerlr.}
proc lrRegLrResolveProgramPath*(reg: ptr LrRegisteredLocationResolver; tid: uint64;
`out`: cstring): Result {.cdecl,
importc: "lrRegLrResolveProgramPath", header: headerlr.}

View file

@ -1,26 +0,0 @@
import strutils
import ospaths
const headermutex = currentSourcePath().splitPath().head & "/nx/include/switch/kernel/mutex.h"
import libnx/wrapper/lock
import libnx/wrapper/types
type
Mutex* = LOCK_T
RMutex* = LOCK_RECURSIVE_T
proc mutexInit*(m: ptr Mutex) {.inline, cdecl.} =
m[] = 0
proc mutexLock*(m: ptr Mutex) {.cdecl, importc: "mutexLock", header: headermutex.}
proc mutexTryLock*(m: ptr Mutex): bool {.cdecl, importc: "mutexTryLock",
header: headermutex.}
proc mutexUnlock*(m: ptr Mutex) {.cdecl, importc: "mutexUnlock", header: headermutex.}
proc rmutexInit*(m: ptr RMutex) {.inline, cdecl.} =
m.lock = 0
m.thread_tag = 0
m.counter = 0
proc rmutexLock*(m: ptr RMutex) {.cdecl, importc: "rmutexLock", header: headermutex.}
proc rmutexTryLock*(m: ptr RMutex): bool {.cdecl, importc: "rmutexTryLock",
header: headermutex.}
proc rmutexUnlock*(m: ptr RMutex) {.cdecl, importc: "rmutexUnlock",
header: headermutex.}

View file

@ -1,38 +0,0 @@
import strutils
import ospaths
const headernacp = currentSourcePath().splitPath().head & "/nx/include/switch/nacp.h"
import libnx/wrapper/types
type
NacpLanguageEntry* {.importc: "NacpLanguageEntry", header: headernacp, bycopy.} = object
name* {.importc: "name".}: array[0x00000200, char]
author* {.importc: "author".}: array[0x00000100, char]
NacpStruct* {.importc: "NacpStruct", header: headernacp, bycopy.} = object
lang* {.importc: "lang".}: array[16, NacpLanguageEntry]
x3000_unk* {.importc: "x3000_unk".}: array[0x00000024, uint8]
x3024_unk* {.importc: "x3024_unk".}: uint32
x3028_unk* {.importc: "x3028_unk".}: uint32
x302C_unk* {.importc: "x302C_unk".}: uint32
x3030_unk* {.importc: "x3030_unk".}: uint32
x3034_unk* {.importc: "x3034_unk".}: uint32
titleID0* {.importc: "titleID0".}: uint64
x3040_unk* {.importc: "x3040_unk".}: array[0x00000020, uint8]
version* {.importc: "version".}: array[0x00000010, char]
titleID_DlcBase* {.importc: "titleID_DlcBase".}: uint64
titleID1* {.importc: "titleID1".}: uint64
x3080_unk* {.importc: "x3080_unk".}: uint32
x3084_unk* {.importc: "x3084_unk".}: uint32
x3088_unk* {.importc: "x3088_unk".}: uint32
x308C_unk* {.importc: "x308C_unk".}: array[0x00000024, uint8]
titleID2* {.importc: "titleID2".}: uint64
titleIDs* {.importc: "titleIDs".}: array[7, uint64]
x30F0_unk* {.importc: "x30F0_unk".}: uint32
x30F4_unk* {.importc: "x30F4_unk".}: uint32
titleID3* {.importc: "titleID3".}: uint64
bcatPassphrase* {.importc: "bcatPassphrase".}: array[0x00000040, char]
x3140_unk* {.importc: "x3140_unk".}: array[0x00000EC0, uint8]
proc nacpGetLanguageEntry*(nacp: ptr NacpStruct;
langentry: ptr ptr NacpLanguageEntry): Result {.cdecl,
importc: "nacpGetLanguageEntry", header: headernacp.}

View file

@ -1,12 +0,0 @@
import strutils
import ospaths
const headernifm = currentSourcePath().splitPath().head & "/nx/include/switch/services/nifm.h"
import libnx/wrapper/types
import libnx/wrapper/ipc
import libnx/wrapper/detect
import libnx/wrapper/sm
proc nifmInitialize*(): Result {.cdecl, importc: "nifmInitialize",
header: headernifm.}
proc nifmExit*() {.cdecl, importc: "nifmExit", header: headernifm.}
proc nifmGetCurrentIpAddress*(`out`: ptr uint32): Result {.cdecl,
importc: "nifmGetCurrentIpAddress", header: headernifm.}

View file

@ -1,2 +0,0 @@
--path:"../"
--path:"../../"

View file

@ -1,40 +0,0 @@
import strutils
import ospaths
const headernro = currentSourcePath().splitPath().head & "/nx/include/switch/nro.h"
const
NROHEADER_MAGIC* = 0x0304F524
NROASSETHEADER_MAGIC* = 0x54455341
NROASSETHEADER_VERSION* = 0
type
NroSegment* {.importc: "NroSegment", header: headernro, bycopy.} = object
file_off* {.importc: "file_off".}: uint32
size* {.importc: "size".}: uint32
NroStart* {.importc: "NroStart", header: headernro, bycopy.} = object
unused* {.importc: "unused".}: uint32
mod_offset* {.importc: "mod_offset".}: uint32
padding* {.importc: "padding".}: array[8, uint8]
NroHeader* {.importc: "NroHeader", header: headernro, bycopy.} = object
magic* {.importc: "magic".}: uint32
unk1* {.importc: "unk1".}: uint32
size* {.importc: "size".}: uint32
unk2* {.importc: "unk2".}: uint32
segments* {.importc: "segments".}: array[3, NroSegment]
bss_size* {.importc: "bss_size".}: uint32
unk3* {.importc: "unk3".}: uint32
build_id* {.importc: "build_id".}: array[0x00000020, uint8]
padding* {.importc: "padding".}: array[0x00000020, uint8]
NroAssetSection* {.importc: "NroAssetSection", header: headernro, bycopy.} = object
offset* {.importc: "offset".}: uint64
size* {.importc: "size".}: uint64
NroAssetHeader* {.importc: "NroAssetHeader", header: headernro, bycopy.} = object
magic* {.importc: "magic".}: uint32
version* {.importc: "version".}: uint32
icon* {.importc: "icon".}: NroAssetSection
nacp* {.importc: "nacp".}: NroAssetSection
romfs* {.importc: "romfs".}: NroAssetSection

View file

@ -1,36 +0,0 @@
import strutils
import ospaths
const headerns = currentSourcePath().splitPath().head & "/nx/include/switch/services/ns.h"
import libnx/wrapper/types
import libnx/wrapper/nacp
import libnx/wrapper/fs
type
NsApplicationControlData* {.importc: "NsApplicationControlData",
header: headerns, bycopy.} = object
nacp* {.importc: "nacp".}: NacpStruct
icon* {.importc: "icon".}: array[0x00020000, uint8]
proc nsInitialize*(): Result {.cdecl, importc: "nsInitialize", header: headerns.}
proc nsExit*() {.cdecl, importc: "nsExit", header: headerns.}
proc nsGetApplicationControlData*(flag: uint8; titleID: uint64;
buffer: ptr NsApplicationControlData; size: csize;
actual_size: ptr csize): Result {.cdecl,
importc: "nsGetApplicationControlData", header: headerns.}
proc nsGetTotalSpaceSize*(storage_id: FsStorageId; size: ptr uint64): Result {.cdecl,
importc: "nsGetTotalSpaceSize", header: headerns.}
proc nsGetFreeSpaceSize*(storage_id: FsStorageId; size: ptr uint64): Result {.cdecl,
importc: "nsGetFreeSpaceSize", header: headerns.}
proc nsvmInitialize*(): Result {.cdecl, importc: "nsvmInitialize", header: headerns.}
proc nsvmExit*() {.cdecl, importc: "nsvmExit", header: headerns.}
proc nsvmNeedsUpdateVulnerability*(`out`: ptr bool): Result {.cdecl,
importc: "nsvmNeedsUpdateVulnerability", header: headerns.}
proc nsvmGetSafeSystemVersion*(`out`: ptr uint16): Result {.cdecl,
importc: "nsvmGetSafeSystemVersion", header: headerns.}
proc nsdevInitialize*(): Result {.cdecl, importc: "nsdevInitialize",
header: headerns.}
proc nsdevExit*() {.cdecl, importc: "nsdevExit", header: headerns.}
proc nsdevTerminateProcess*(pid: uint64): Result {.cdecl,
importc: "nsdevTerminateProcess", header: headerns.}
proc nsdevTerminateProgram*(tid: uint64): Result {.cdecl,
importc: "nsdevTerminateProgram", header: headerns.}

View file

@ -1,22 +0,0 @@
import strutils
import ospaths
const headernv = currentSourcePath().splitPath().head & "/nx/include/switch/services/nv.h"
import libnx/wrapper/types
type
nvServiceType* {.size: sizeof(cint).} = enum
NVSERVTYPE_Default = -1, NVSERVTYPE_Application = 0, NVSERVTYPE_Applet = 1,
NVSERVTYPE_Sysmodule = 2, NVSERVTYPE_T = 3
proc nvInitialize*(servicetype: nvServiceType; sharedmem_size: csize): Result {.
cdecl, importc: "nvInitialize", header: headernv.}
proc nvExit*() {.cdecl, importc: "nvExit", header: headernv.}
proc nvOpen*(fd: ptr uint32; devicepath: cstring): Result {.cdecl, importc: "nvOpen",
header: headernv.}
proc nvIoctl*(fd: uint32; request: uint32; argp: pointer): Result {.cdecl,
importc: "nvIoctl", header: headernv.}
proc nvClose*(fd: uint32): Result {.cdecl, importc: "nvClose", header: headernv.}
proc nvQueryEvent*(fd: uint32; event_id: uint32; handle_out: ptr Handle): Result {.cdecl,
importc: "nvQueryEvent", header: headernv.}
proc nvConvertError*(rc: cint): Result {.cdecl, importc: "nvConvertError",
header: headernv.}

View file

@ -1,13 +0,0 @@
import strutils
import ospaths
const headernvgfx = currentSourcePath().splitPath().head & "/nx/include/switch/gfx/nvgfx.h"
import libnx/wrapper/types
proc nvgfxInitialize*(): Result {.cdecl, importc: "nvgfxInitialize",
header: headernvgfx.}
proc nvgfxExit*() {.cdecl, importc: "nvgfxExit", header: headernvgfx.}
proc nvgfxEventWait*(syncpt_id: uint32; threshold: uint32; timeout: s32): Result {.cdecl,
importc: "nvgfxEventWait", header: headernvgfx.}
proc nvgfxSubmitGpfifo*(): Result {.cdecl, importc: "nvgfxSubmitGpfifo",
header: headernvgfx.}
proc nvgfxGetFramebuffer*(buffer: ptr ptr uint8; size: ptr csize): Result {.cdecl,
importc: "nvgfxGetFramebuffer", header: headernvgfx.}

View file

@ -1,138 +0,0 @@
import strutils
import ospaths
const headernvioctl = currentSourcePath().splitPath().head & "/nx/include/switch/gfx/nvioctl.h"
import libnx/wrapper/types
type
gpu_characteristics* {.importc: "gpu_characteristics", header: headernvioctl,
bycopy.} = object
arch* {.importc: "arch".}: uint32
impl* {.importc: "impl".}: uint32
rev* {.importc: "rev".}: uint32
num_gpc* {.importc: "num_gpc".}: uint32
L2_cache_size* {.importc: "L2_cache_size".}: uint64
on_board_video_memory_size* {.importc: "on_board_video_memory_size".}: uint64
num_tpc_per_gpc* {.importc: "num_tpc_per_gpc".}: uint32
bus_type* {.importc: "bus_type".}: uint32
big_page_size* {.importc: "big_page_size".}: uint32
compression_page_size* {.importc: "compression_page_size".}: uint32
pde_coverage_bit_count* {.importc: "pde_coverage_bit_count".}: uint32
available_big_page_sizes* {.importc: "available_big_page_sizes".}: uint32
gpc_mask* {.importc: "gpc_mask".}: uint32
sm_arch_sm_version* {.importc: "sm_arch_sm_version".}: uint32
sm_arch_spa_version* {.importc: "sm_arch_spa_version".}: uint32
sm_arch_warp_count* {.importc: "sm_arch_warp_count".}: uint32
gpu_va_bit_count* {.importc: "gpu_va_bit_count".}: uint32
reserved* {.importc: "reserved".}: uint32
flags* {.importc: "flags".}: uint64
twod_class* {.importc: "twod_class".}: uint32
threed_class* {.importc: "threed_class".}: uint32
compute_class* {.importc: "compute_class".}: uint32
gpfifo_class* {.importc: "gpfifo_class".}: uint32
inline_to_memory_class* {.importc: "inline_to_memory_class".}: uint32
dma_copy_class* {.importc: "dma_copy_class".}: uint32
max_fbps_count* {.importc: "max_fbps_count".}: uint32
fbp_en_mask* {.importc: "fbp_en_mask".}: uint32
max_ltc_per_fbp* {.importc: "max_ltc_per_fbp".}: uint32
max_lts_per_ltc* {.importc: "max_lts_per_ltc".}: uint32
max_tex_per_tpc* {.importc: "max_tex_per_tpc".}: uint32
max_gpc_count* {.importc: "max_gpc_count".}: uint32
rop_l2_en_mask_0* {.importc: "rop_l2_en_mask_0".}: uint32
rop_l2_en_mask_1* {.importc: "rop_l2_en_mask_1".}: uint32
chipname* {.importc: "chipname".}: uint64
gr_compbit_store_base_hw* {.importc: "gr_compbit_store_base_hw".}: uint64
nvioctl_va_region* {.importc: "nvioctl_va_region", header: headernvioctl, bycopy.} = object
offset* {.importc: "offset".}: uint64
page_size* {.importc: "page_size".}: uint32
pad* {.importc: "pad".}: uint32
pages* {.importc: "pages".}: uint64
nvioctl_l2_state* {.importc: "nvioctl_l2_state", header: headernvioctl, bycopy.} = object
mask* {.importc: "mask".}: uint32
flush* {.importc: "flush".}: uint32
nvioctl_fence* {.importc: "nvioctl_fence", header: headernvioctl, bycopy.} = object
id* {.importc: "id".}: uint32
value* {.importc: "value".}: uint32
nvioctl_gpfifo_entry* {.importc: "nvioctl_gpfifo_entry", header: headernvioctl,
bycopy.} = object
entry0* {.importc: "entry0".}: uint32
entry1* {.importc: "entry1".}: uint32
nvioctl_channel_obj_classnum* {.size: sizeof(cint).} = enum
NvChannelObjClassNum_2D = 0x0000902D, NvChannelObjClassNum_Kepler = 0x0000A140,
NvChannelObjClassNum_ChannelGpfifo = 0x0000B06F,
NvChannelObjClassNum_DMA = 0x0000B0B5, NvChannelObjClassNum_3D = 0x0000B197,
NvChannelObjClassNum_Compute = 0x0000B1C0
type
nvioctl_channel_priority* {.size: sizeof(cint).} = enum
NvChannelPriority_Low = 0x00000032, NvChannelPriority_Medium = 0x00000064,
NvChannelPriority_High = 0x00000096
proc nvioctlNvhostCtrl_EventSignal*(fd: uint32; event_id: uint32): Result {.cdecl,
importc: "nvioctlNvhostCtrl_EventSignal", header: headernvioctl.}
proc nvioctlNvhostCtrl_EventWait*(fd: uint32; syncpt_id: uint32; threshold: uint32;
timeout: s32; event_id: uint32; `out`: ptr uint32): Result {.
cdecl, importc: "nvioctlNvhostCtrl_EventWait", header: headernvioctl.}
proc nvioctlNvhostCtrl_EventRegister*(fd: uint32; event_id: uint32): Result {.cdecl,
importc: "nvioctlNvhostCtrl_EventRegister", header: headernvioctl.}
proc nvioctlNvhostCtrlGpu_ZCullGetCtxSize*(fd: uint32; `out`: ptr uint32): Result {.cdecl,
importc: "nvioctlNvhostCtrlGpu_ZCullGetCtxSize", header: headernvioctl.}
proc nvioctlNvhostCtrlGpu_ZCullGetInfo*(fd: uint32; `out`: array[40 shr 2, uint32]): Result {.
cdecl, importc: "nvioctlNvhostCtrlGpu_ZCullGetInfo", header: headernvioctl.}
proc nvioctlNvhostCtrlGpu_GetCharacteristics*(fd: uint32;
`out`: ptr gpu_characteristics): Result {.cdecl,
importc: "nvioctlNvhostCtrlGpu_GetCharacteristics", header: headernvioctl.}
proc nvioctlNvhostCtrlGpu_GetTpcMasks*(fd: uint32; inval: uint32;
`out`: array[24 shr 2, uint32]): Result {.cdecl,
importc: "nvioctlNvhostCtrlGpu_GetTpcMasks", header: headernvioctl.}
proc nvioctlNvhostCtrlGpu_GetL2State*(fd: uint32; `out`: ptr nvioctl_l2_state): Result {.
cdecl, importc: "nvioctlNvhostCtrlGpu_GetL2State", header: headernvioctl.}
proc nvioctlNvhostAsGpu_BindChannel*(fd: uint32; channel_fd: uint32): Result {.cdecl,
importc: "nvioctlNvhostAsGpu_BindChannel", header: headernvioctl.}
proc nvioctlNvhostAsGpu_AllocSpace*(fd: uint32; pages: uint32; page_size: uint32; flags: uint32;
align: uint64; offset: ptr uint64): Result {.cdecl,
importc: "nvioctlNvhostAsGpu_AllocSpace", header: headernvioctl.}
proc nvioctlNvhostAsGpu_MapBufferEx*(fd: uint32; flags: uint32; kind: uint32; nvmap_handle: uint32;
page_size: uint32; buffer_offset: uint64;
mapping_size: uint64; input_offset: uint64;
offset: ptr uint64): Result {.cdecl,
importc: "nvioctlNvhostAsGpu_MapBufferEx", header: headernvioctl.}
proc nvioctlNvhostAsGpu_GetVARegions*(fd: uint32; regions: array[2, nvioctl_va_region]): Result {.
cdecl, importc: "nvioctlNvhostAsGpu_GetVARegions", header: headernvioctl.}
proc nvioctlNvhostAsGpu_InitializeEx*(fd: uint32; big_page_size: uint32; flags: uint32): Result {.
cdecl, importc: "nvioctlNvhostAsGpu_InitializeEx", header: headernvioctl.}
proc nvioctlNvmap_Create*(fd: uint32; size: uint32; nvmap_handle: ptr uint32): Result {.cdecl,
importc: "nvioctlNvmap_Create", header: headernvioctl.}
proc nvioctlNvmap_FromId*(fd: uint32; id: uint32; nvmap_handle: ptr uint32): Result {.cdecl,
importc: "nvioctlNvmap_FromId", header: headernvioctl.}
proc nvioctlNvmap_Alloc*(fd: uint32; nvmap_handle: uint32; heapmask: uint32; flags: uint32;
align: uint32; kind: uint8; `addr`: pointer): Result {.cdecl,
importc: "nvioctlNvmap_Alloc", header: headernvioctl.}
proc nvioctlNvmap_GetId*(fd: uint32; nvmap_handle: uint32; id: ptr uint32): Result {.cdecl,
importc: "nvioctlNvmap_GetId", header: headernvioctl.}
proc nvioctlChannel_SetNvmapFd*(fd: uint32; nvmap_fd: uint32): Result {.cdecl,
importc: "nvioctlChannel_SetNvmapFd", header: headernvioctl.}
proc nvioctlChannel_SubmitGpfifo*(fd: uint32; entries: ptr nvioctl_gpfifo_entry;
num_entries: uint32; flags: uint32;
fence_out: ptr nvioctl_fence): Result {.cdecl,
importc: "nvioctlChannel_SubmitGpfifo", header: headernvioctl.}
proc nvioctlChannel_AllocObjCtx*(fd: uint32; class_num: uint32; flags: uint32): Result {.cdecl,
importc: "nvioctlChannel_AllocObjCtx", header: headernvioctl.}
proc nvioctlChannel_ZCullBind*(fd: uint32; gpu_va: uint64; mode: uint32): Result {.cdecl,
importc: "nvioctlChannel_ZCullBind", header: headernvioctl.}
proc nvioctlChannel_SetErrorNotifier*(fd: uint32; offset: uint64; size: uint64;
nvmap_handle: uint32): Result {.cdecl,
importc: "nvioctlChannel_SetErrorNotifier", header: headernvioctl.}
proc nvioctlChannel_SetPriority*(fd: uint32; priority: uint32): Result {.cdecl,
importc: "nvioctlChannel_SetPriority", header: headernvioctl.}
proc nvioctlChannel_AllocGpfifoEx2*(fd: uint32; num_entries: uint32; flags: uint32; unk0: uint32;
unk1: uint32; unk2: uint32; unk3: uint32;
fence_out: ptr nvioctl_fence): Result {.cdecl,
importc: "nvioctlChannel_AllocGpfifoEx2", header: headernvioctl.}
proc nvioctlChannel_SetUserData*(fd: uint32; `addr`: pointer): Result {.cdecl,
importc: "nvioctlChannel_SetUserData", header: headernvioctl.}

View file

@ -1,84 +0,0 @@
/**
* @file switch.h
* @brief Central Switch header. Includes all others.
* @copyright libnx Authors
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "switch/types.h"
#include "switch/result.h"
#include "switch/nro.h"
#include "switch/nacp.h"
#include "switch/arm/tls.h"
#include "switch/arm/cache.h"
#include "switch/kernel/svc.h"
#include "switch/kernel/tmem.h"
#include "switch/kernel/shmem.h"
#include "switch/kernel/mutex.h"
#include "switch/kernel/rwlock.h"
#include "switch/kernel/condvar.h"
#include "switch/kernel/thread.h"
#include "switch/kernel/virtmem.h"
#include "switch/kernel/detect.h"
#include "switch/kernel/random.h"
#include "switch/kernel/jit.h"
#include "switch/kernel/ipc.h"
#include "switch/services/sm.h"
#include "switch/services/smm.h"
#include "switch/services/fs.h"
#include "switch/services/fsldr.h"
#include "switch/services/fspr.h"
#include "switch/services/acc.h"
#include "switch/services/apm.h"
#include "switch/services/applet.h"
#include "switch/services/audin.h"
#include "switch/services/audout.h"
#include "switch/services/csrng.h"
//#include "switch/services/bsd.h" Use switch/runtime/devices/socket.h instead
#include "switch/services/fatal.h"
#include "switch/services/time.h"
#include "switch/services/usb.h"
#include "switch/services/hid.h"
#include "switch/services/irs.h"
#include "switch/services/pl.h"
#include "switch/services/vi.h"
#include "switch/services/nv.h"
#include "switch/services/nifm.h"
#include "switch/services/ns.h"
#include "switch/services/ldr.h"
#include "switch/services/pm.h"
#include "switch/services/set.h"
#include "switch/services/lr.h"
#include "switch/services/spl.h"
#include "switch/gfx/gfx.h"
#include "switch/gfx/binder.h"
#include "switch/gfx/parcel.h"
#include "switch/gfx/buffer_producer.h"
#include "switch/gfx/ioctl.h"
#include "switch/gfx/nvioctl.h"
#include "switch/gfx/nvgfx.h"
#include "switch/runtime/env.h"
#include "switch/runtime/nxlink.h"
#include "switch/runtime/util/utf.h"
#include "switch/runtime/devices/console.h"
#include "switch/runtime/devices/usb_comms.h"
#include "switch/runtime/devices/fs_dev.h"
#include "switch/runtime/devices/romfs_dev.h"
#include "switch/runtime/devices/socket.h"
#ifdef __cplusplus
}
#endif

View file

@ -1,17 +0,0 @@
#include "../types.h"
static inline u32 atomicIncrement32(u32* p) {
return __atomic_fetch_add(p, 1, __ATOMIC_SEQ_CST);
}
static inline u32 atomicDecrement32(u32* p) {
return __atomic_sub_fetch(p, 1, __ATOMIC_SEQ_CST);
}
static inline u64 atomicIncrement64(u64* p) {
return __atomic_fetch_add(p, 1, __ATOMIC_SEQ_CST);
}
static inline u64 atomicDecrement64(u64* p) {
return __atomic_sub_fetch(p, 1, __ATOMIC_SEQ_CST);
}

View file

@ -1,41 +0,0 @@
/**
* @file cache.h
* @brief AArch64 cache operations.
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/**
* @brief Performs a data cache flush on the specified buffer.
* @param addr Address of the buffer.
* @param size Size of the buffer, in bytes.
* @remarks Cache flush is defined as Clean + Invalidate.
* @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register).
*/
void armDCacheFlush(void* addr, size_t size);
/**
* @brief Performs a data cache clean on the specified buffer.
* @param addr Address of the buffer.
* @param size Size of the buffer, in bytes.
* @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register).
*/
void armDCacheClean(void* addr, size_t size);
/**
* @brief Performs an instruction cache invalidation clean on the specified buffer.
* @param addr Address of the buffer.
* @param size Size of the buffer, in bytes.
* @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register).
*/
void armICacheInvalidate(void* addr, size_t size);
/**
* @brief Performs a data cache zeroing operation on the specified buffer.
* @param addr Address of the buffer.
* @param size Size of the buffer, in bytes.
* @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register).
*/
void armDCacheZero(void* addr, size_t size);

View file

@ -1,18 +0,0 @@
/**
* @file tls.h
* @brief AArch64 thread local storage.
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/**
* @brief Gets the thread local storage buffer.
* @return The thread local storage buffer.
*/
static inline void* armGetTls(void) {
void* ret;
__asm__ ("mrs %x[data], tpidrro_el0" : [data] "=r" (ret));
return ret;
}

View file

@ -1,19 +0,0 @@
/**
* @file audio.h
* @brief Global audio service.
* @author hexkyz
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
typedef enum {
PcmFormat_Invalid = 0,
PcmFormat_Int8 = 1,
PcmFormat_Int16 = 2,
PcmFormat_Int24 = 3,
PcmFormat_Int32 = 4,
PcmFormat_Float = 5,
PcmFormat_Adpcm = 6,
} PcmFormat;

View file

@ -1,29 +0,0 @@
#pragma once
#include "../types.h"
#define BINDER_FIRST_CALL_TRANSACTION 0x1
typedef struct {
bool created;
bool initialized;
Handle sessionHandle;
s32 id;
Handle nativeHandle;
size_t ipcBufferSize;
bool hasTransactAuto;
} Binder;
// binderExitSession will not close the sessionHandle since it's user-specified via binderCreateSession and may be used elsewhere.
void binderCreateSession(Binder *session, Handle sessionHandle, s32 ID);
Result binderInitSession(Binder *session, u32 unk0);
void binderExitSession(Binder *session);
Result binderTransactParcel(
Binder *session, u32 code,
void* parcel_data, size_t parcel_data_size,
void* parcel_reply, size_t parcel_reply_size,
u32 flags);
Result binderAdjustRefcount(Binder *session, s32 addval, s32 type);
Result binderGetNativeHandle(Binder *session, u32 unk0, Handle *handle_out);

View file

@ -1,151 +0,0 @@
#pragma once
#include "../gfx/nvioctl.h"
typedef struct {
u32 is_valid;
nvioctl_fence nv_fences[4];
} PACKED bufferProducerFence;
typedef struct {
s32 left;
s32 top;
s32 right;
s32 bottom;
} PACKED bufferProducerRect;
typedef struct {
s64 timestamp;
s32 isAutoTimestamp;
bufferProducerRect crop;
s32 scalingMode;
u32 transform;//See the NATIVE_WINDOW_TRANSFORM_* enums.
u32 stickyTransform;
u32 unk[2];
bufferProducerFence fence;
} PACKED bufferProducerQueueBufferInput;
typedef struct {
u32 width;
u32 height;
u32 transformHint;
u32 numPendingBuffers;
} PACKED bufferProducerQueueBufferOutput;
typedef struct {
u32 magic;
u32 width;
u32 height;
u32 stride;
u32 format;
u32 usage;
u32 pid;
u32 refcount;
u32 numFds;
u32 numInts;
struct {//Actual size is numFds*4 + numInts*4.
u32 unk_x0;
u32 nvmap_handle0;
u32 unk_x8;
u32 unk_xc;
u32 unk_x10;
u32 unk_x14;
u32 unk_x18;
u32 unk_x1c;
u32 unk_x20;
u32 width_unk0;
u32 buffer_size0;
u32 unk_x2c;
u32 unk_x30;
u32 width_unk1;
u32 height_unk;
u32 flags;
u32 unk_x40;
u32 unk_x44;
u32 byte_stride;
u32 nvmap_handle1;
u32 buffer_offset;
u32 unk_x54;
u32 unk_x58;
u32 unk_x5c;
u32 unk_x60;
u32 unk_x64;
u32 unk_x68;
u32 buffer_size1;
u32 unk_x70[0x33];//Normally all-zero.
u64 timestamp;
} PACKED data;
} PACKED bufferProducerGraphicBuffer;
//From Android window.h.
/* attributes queriable with query() */
enum {
NATIVE_WINDOW_WIDTH = 0,
NATIVE_WINDOW_HEIGHT = 1,
NATIVE_WINDOW_FORMAT = 2,
//...
// NATIVE_WINDOW_DEFAULT_WIDTH = 6, //These two return invalid data.
// NATIVE_WINDOW_DEFAULT_HEIGHT = 7,
};
//From Android window.h.
/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
enum {
//...
/* Buffers will be queued after being filled using the CPU
*/
NATIVE_WINDOW_API_CPU = 2,
//...
};
//From Android hardware.h.
/**
* Transformation definitions
*
* IMPORTANT NOTE:
* HAL_TRANSFORM_ROT_90 is applied CLOCKWISE and AFTER HAL_TRANSFORM_FLIP_{H|V}.
*
*/
enum {
/* flip source image horizontally (around the vertical axis) */
HAL_TRANSFORM_FLIP_H = 0x01,
/* flip source image vertically (around the horizontal axis)*/
HAL_TRANSFORM_FLIP_V = 0x02,
/* rotate source image 90 degrees clockwise */
HAL_TRANSFORM_ROT_90 = 0x04,
/* rotate source image 180 degrees */
HAL_TRANSFORM_ROT_180 = 0x03,
/* rotate source image 270 degrees clockwise */
HAL_TRANSFORM_ROT_270 = 0x07,
};
//From Android window.h.
/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
enum {
/* flip source image horizontally */
NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
/* flip source image vertically */
NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
/* rotate source image 90 degrees clock-wise */
NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
/* rotate source image 180 degrees */
NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
/* rotate source image 270 degrees clock-wise */
NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
};
Result bufferProducerInitialize(Binder *session);
void bufferProducerExit(void);
Result bufferProducerRequestBuffer(s32 bufferIdx, bufferProducerGraphicBuffer *buf);
Result bufferProducerDequeueBuffer(bool async, u32 width, u32 height, s32 format, u32 usage, s32 *buf, bufferProducerFence *fence);
Result bufferProducerDetachBuffer(s32 slot);
Result bufferProducerQueueBuffer(s32 buf, bufferProducerQueueBufferInput *input, bufferProducerQueueBufferOutput *output);
Result bufferProducerQuery(s32 what, s32* value);
Result bufferProducerConnect(s32 api, bool producerControlledByApp, bufferProducerQueueBufferOutput *output);
Result bufferProducerDisconnect(s32 api);
Result bufferProducerGraphicBufferInit(s32 buf, bufferProducerGraphicBuffer *input);

View file

@ -1,117 +0,0 @@
/**
* @file gfx.h
* @brief High-level graphics API.
* This API exposes a framebuffer (technically speaking, a windowbuffer) to be used for drawing graphics.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/// Converts red, green, blue, and alpha components to packed RGBA8.
#define RGBA8(r,g,b,a) (((r)&0xff)|(((g)&0xff)<<8)|(((b)&0xff)<<16)|(((a)&0xff)<<24))
/// Same as \ref RGBA8 except with alpha=0xff.
#define RGBA8_MAXALPHA(r,g,b) RGBA8(r,g,b,0xff)
/// GfxMode set by \ref gfxSetMode. The default is GfxMode_LinearDouble. Note that the text-console (see console.h) sets this to GfxMode_TiledDouble.
typedef enum
{
GfxMode_TiledSingle, ///< Single-buffering with raw tiled (block-linear) framebuffer.
GfxMode_TiledDouble, ///< Double-buffering with raw tiled (block-linear) framebuffer.
GfxMode_LinearDouble ///< Double-buffering with linear framebuffer, which is transferred to the actual framebuffer by \ref gfxFlushBuffers().
} GfxMode;
/// Framebuffer pixel-format is RGBA8888, there's no known way to change this.
/**
* @brief Initializes the graphics subsystem.
* @warning Do not use \ref viInitialize when using this function.
*/
void gfxInitDefault(void);
/**
* @brief Uninitializes the graphics subsystem.
* @warning Do not use \ref viExit when using this function.
*/
void gfxExit(void);
/**
* @brief Sets the resolution to be used when initializing the graphics subsystem.
* @param[in] width Horizontal resolution, in pixels.
* @param[in] height Vertical resolution, in pixels.
* @note The default resolution is 720p.
* @note This can only be used before calling \ref gfxInitDefault, this will use \ref fatalSimple otherwise. If the input is 0, the default resolution will be used during \ref gfxInitDefault. This sets the maximum resolution for the framebuffer, used during \ref gfxInitDefault. This is also used as the current resolution when crop isn't set. The width/height are reset to the default when \ref gfxExit is used.
* @note Normally you should only use this when you need a maximum resolution larger than the default, see above.
* @note The width and height are aligned to 4.
*/
void gfxInitResolution(u32 width, u32 height);
/// Wrapper for \ref gfxInitResolution with resolution=1080p. Use this if you want to support 1080p or >720p in docked-mode.
void gfxInitResolutionDefault(void);
/// Configure framebuffer crop, by default crop is all-zero. Use all-zero input to reset to default. \ref gfxExit resets this to the default.
/// When the input is invalid this returns without changing the crop data, this includes the input values being larger than the framebuf width/height.
/// This will update the display width/height returned by \ref gfxGetFramebuffer, with that width/height being reset to the default when required.
/// \ref gfxGetFramebufferDisplayOffset uses absolute x/y, it will not adjust for non-zero crop left/top.
/// The new crop config will not take affect with double-buffering disabled. When used during frame-drawing, this should be called before \ref gfxGetFramebuffer.
/// The right and bottom params are aligned to 4.
void gfxConfigureCrop(s32 left, s32 top, s32 right, s32 bottom);
/// Wrapper for \ref gfxConfigureCrop. Use this to set the resolution, within the bounds of the maximum resolution. Use all-zero input to reset to default.
void gfxConfigureResolution(s32 width, s32 height);
/// If enabled, \ref gfxConfigureResolution will be used with the input resolution for the current OperationMode. Then \ref gfxConfigureResolution will automatically be used with the specified resolution each time OperationMode changes.
void gfxConfigureAutoResolution(bool enable, s32 handheld_width, s32 handheld_height, s32 docked_width, s32 docked_height);
/// Wrapper for \ref gfxConfigureAutoResolution. handheld_resolution=720p, docked_resolution={all-zero for using current maximum resolution}.
void gfxConfigureAutoResolutionDefault(bool enable);
/// Waits for vertical sync.
void gfxWaitForVsync(void);
/// Swaps the framebuffers (for double-buffering).
void gfxSwapBuffers(void);
/// Get the current framebuffer address, with optional output ptrs for the display framebuffer width/height. The display width/height is adjusted by \ref gfxConfigureCrop and \ref gfxConfigureResolution.
u8* gfxGetFramebuffer(u32* width, u32* height);
/// Get the framebuffer width/height without crop.
void gfxGetFramebufferResolution(u32* width, u32* height);
/// Use this to get the actual byte-size of the framebuffer for use with memset/etc.
size_t gfxGetFramebufferSize(void);
/// Sets the \ref GfxMode.
void gfxSetMode(GfxMode mode);
/// Controls whether a vertical-flip is done when determining the pixel-offset within the actual framebuffer. By default this is enabled.
void gfxSetDrawFlip(bool flip);
/// Configures transform. See the NATIVE_WINDOW_TRANSFORM_* enums in buffer_producer.h. The default is NATIVE_WINDOW_TRANSFORM_FLIP_V.
void gfxConfigureTransform(u32 transform);
/// Flushes the framebuffer in the data cache. When \ref GfxMode is GfxMode_LinearDouble, this also transfers the linear-framebuffer to the actual framebuffer.
void gfxFlushBuffers(void);
/// Use this to get the pixel-offset in the framebuffer. Returned value is in pixels, not bytes.
/// This implements tegra blocklinear, with hard-coded constants etc.
/// Do not use this when \ref GfxMode is GfxMode_LinearDouble.
static inline u32 gfxGetFramebufferDisplayOffset(u32 x, u32 y) {
u32 tmp_pos;
extern size_t g_gfx_framebuf_aligned_width;
extern size_t g_gfx_framebuf_display_height;
extern bool g_gfx_drawflip;
//if (x >= g_gfx_framebuf_width || y >= g_gfx_framebuf_display_height) return (gfxGetFramebufferSize()-4)/4;//Return the last pixel-offset in the buffer, the data located here is not displayed due to alignment. (Disabled for perf)
if (g_gfx_drawflip) y = g_gfx_framebuf_display_height-1-y;
tmp_pos = ((y & 127) / 16) + (x/16*8) + ((y/16/8)*(g_gfx_framebuf_aligned_width/16*8));
tmp_pos *= 16*16 * 4;
tmp_pos += ((y%16)/8)*512 + ((x%16)/8)*256 + ((y%8)/2)*64 + ((x%8)/4)*32 + (y%2)*16 + (x%4)*4;//This line is a modified version of code from the Tegra X1 datasheet.
return tmp_pos / 4;
}

View file

@ -1,47 +0,0 @@
#pragma once
//The below defines are based on Linux kernel ioctl.h.
#define _NV_IOC_NRBITS 8
#define _NV_IOC_TYPEBITS 8
#define _NV_IOC_SIZEBITS 14
#define _NV_IOC_DIRBITS 2
#define _NV_IOC_NRMASK ((1 << _NV_IOC_NRBITS)-1)
#define _NV_IOC_TYPEMASK ((1 << _NV_IOC_TYPEBITS)-1)
#define _NV_IOC_SIZEMASK ((1 << _NV_IOC_SIZEBITS)-1)
#define _NV_IOC_DIRMASK ((1 << _NV_IOC_DIRBITS)-1)
#define _NV_IOC_NRSHIFT 0
#define _NV_IOC_TYPESHIFT (_NV_IOC_NRSHIFT+_NV_IOC_NRBITS)
#define _NV_IOC_SIZESHIFT (_NV_IOC_TYPESHIFT+_NV_IOC_TYPEBITS)
#define _NV_IOC_DIRSHIFT (_NV_IOC_SIZESHIFT+_NV_IOC_SIZEBITS)
/*
* Direction bits.
*/
#define _NV_IOC_NONE 0U
#define _NV_IOC_WRITE 1U
#define _NV_IOC_READ 2U
#define _NV_IOC(dir,type,nr,size) \
(((dir) << _NV_IOC_DIRSHIFT) | \
((type) << _NV_IOC_TYPESHIFT) | \
((nr) << _NV_IOC_NRSHIFT) | \
((size) << _NV_IOC_SIZESHIFT))
/* used to create numbers */
#define _NV_IO(type,nr) _NV_IOC(_NV_IOC_NONE,(type),(nr),0)
#define _NV_IOR(type,nr,size) _NV_IOC(_NV_IOC_READ,(type),(nr),sizeof(size))
#define _NV_IOW(type,nr,size) _NV_IOC(_NV_IOC_WRITE,(type),(nr),sizeof(size))
#define _NV_IOWR(type,nr,size) _NV_IOC(_NV_IOC_READ|_NV_IOC_WRITE,(type),(nr),sizeof(size))
/* used to decode ioctl numbers.. */
#define _NV_IOC_DIR(nr) (((nr) >> _NV_IOC_DIRSHIFT) & _NV_IOC_DIRMASK)
#define _NV_IOC_TYPE(nr) (((nr) >> _NV_IOC_TYPESHIFT) & _NV_IOC_TYPEMASK)
#define _NV_IOC_NR(nr) (((nr) >> _NV_IOC_NRSHIFT) & _NV_IOC_NRMASK)
#define _NV_IOC_SIZE(nr) (((nr) >> _NV_IOC_SIZESHIFT) & _NV_IOC_SIZEMASK)
#define __nv_in
#define __nv_out
#define __nv_inout

View file

@ -1,8 +0,0 @@
#pragma once
#include "../types.h"
Result nvgfxInitialize(void);
void nvgfxExit(void);
Result nvgfxEventWait(u32 syncpt_id, u32 threshold, s32 timeout);
Result nvgfxSubmitGpfifo(void);
Result nvgfxGetFramebuffer(u8 **buffer, size_t *size);

View file

@ -1,110 +0,0 @@
#pragma once
#include "../types.h"
typedef struct {
u32 arch; // 0x120 (NVGPU_GPU_ARCH_GM200)
u32 impl; // 0xB (NVGPU_GPU_IMPL_GM20B)
u32 rev; // 0xA1 (Revision A1)
u32 num_gpc; // 0x1
u64 L2_cache_size; // 0x40000
u64 on_board_video_memory_size; // 0x0 (not used)
u32 num_tpc_per_gpc; // 0x2
u32 bus_type; // 0x20 (NVGPU_GPU_BUS_TYPE_AXI)
u32 big_page_size; // 0x20000
u32 compression_page_size; // 0x20000
u32 pde_coverage_bit_count; // 0x1B
u32 available_big_page_sizes; // 0x30000
u32 gpc_mask; // 0x1
u32 sm_arch_sm_version; // 0x503 (Maxwell Generation 5.0.3?)
u32 sm_arch_spa_version; // 0x503 (Maxwell Generation 5.0.3?)
u32 sm_arch_warp_count; // 0x80
u32 gpu_va_bit_count; // 0x28
u32 reserved; // NULL
u64 flags; // 0x55
u32 twod_class; // 0x902D (FERMI_TWOD_A)
u32 threed_class; // 0xB197 (MAXWELL_B)
u32 compute_class; // 0xB1C0 (MAXWELL_COMPUTE_B)
u32 gpfifo_class; // 0xB06F (MAXWELL_CHANNEL_GPFIFO_A)
u32 inline_to_memory_class; // 0xA140 (KEPLER_INLINE_TO_MEMORY_B)
u32 dma_copy_class; // 0xB0B5 (MAXWELL_DMA_COPY_A)
u32 max_fbps_count; // 0x1
u32 fbp_en_mask; // 0x0 (disabled)
u32 max_ltc_per_fbp; // 0x2
u32 max_lts_per_ltc; // 0x1
u32 max_tex_per_tpc; // 0x0 (not supported)
u32 max_gpc_count; // 0x1
u32 rop_l2_en_mask_0; // 0x21D70 (fuse_status_opt_rop_l2_fbp_r)
u32 rop_l2_en_mask_1; // 0x0
u64 chipname; // 0x6230326D67 ("gm20b")
u64 gr_compbit_store_base_hw; // 0x0 (not supported)
} gpu_characteristics;
typedef struct {
u64 offset;
u32 page_size;
u32 pad;
u64 pages;
} nvioctl_va_region;
typedef struct {
u32 mask; // always 0x07
u32 flush; // active flush bit field
} nvioctl_l2_state;
typedef struct {
u32 id;
u32 value;
} nvioctl_fence;
typedef struct {
u32 entry0;
u32 entry1;
} nvioctl_gpfifo_entry;
//Used with nvioctlChannel_AllocObjCtx().
enum nvioctl_channel_obj_classnum {
NvChannelObjClassNum_2D = 0x902D,
NvChannelObjClassNum_3D = 0xB197,
NvChannelObjClassNum_Compute = 0xB1C0,
NvChannelObjClassNum_Kepler = 0xA140,
NvChannelObjClassNum_DMA = 0xB0B5,
NvChannelObjClassNum_ChannelGpfifo = 0xB06F
};
//Used with nvioctlChannel_SetPriority().
enum nvioctl_channel_priority {
NvChannelPriority_Low = 0x32,
NvChannelPriority_Medium = 0x64,
NvChannelPriority_High = 0x96
};
Result nvioctlNvhostCtrl_EventSignal(u32 fd, u32 event_id);
Result nvioctlNvhostCtrl_EventWait(u32 fd, u32 syncpt_id, u32 threshold, s32 timeout, u32 event_id, u32 *out);
Result nvioctlNvhostCtrl_EventRegister(u32 fd, u32 event_id);
Result nvioctlNvhostCtrlGpu_ZCullGetCtxSize(u32 fd, u32 *out);
Result nvioctlNvhostCtrlGpu_ZCullGetInfo(u32 fd, u32 out[40>>2]);
Result nvioctlNvhostCtrlGpu_GetCharacteristics(u32 fd, gpu_characteristics *out);
Result nvioctlNvhostCtrlGpu_GetTpcMasks(u32 fd, u32 inval, u32 out[24>>2]);
Result nvioctlNvhostCtrlGpu_GetL2State(u32 fd, nvioctl_l2_state *out);
Result nvioctlNvhostAsGpu_BindChannel(u32 fd, u32 channel_fd);
Result nvioctlNvhostAsGpu_AllocSpace(u32 fd, u32 pages, u32 page_size, u32 flags, u64 align, u64 *offset);
Result nvioctlNvhostAsGpu_MapBufferEx(u32 fd, u32 flags, u32 kind, u32 nvmap_handle, u32 page_size, u64 buffer_offset, u64 mapping_size, u64 input_offset, u64 *offset);
Result nvioctlNvhostAsGpu_GetVARegions(u32 fd, nvioctl_va_region regions[2]);
Result nvioctlNvhostAsGpu_InitializeEx(u32 fd, u32 big_page_size, u32 flags);
Result nvioctlNvmap_Create(u32 fd, u32 size, u32 *nvmap_handle);
Result nvioctlNvmap_FromId(u32 fd, u32 id, u32 *nvmap_handle);
Result nvioctlNvmap_Alloc(u32 fd, u32 nvmap_handle, u32 heapmask, u32 flags, u32 align, u8 kind, void* addr);
Result nvioctlNvmap_GetId(u32 fd, u32 nvmap_handle, u32 *id);
Result nvioctlChannel_SetNvmapFd(u32 fd, u32 nvmap_fd);
Result nvioctlChannel_SubmitGpfifo(u32 fd, nvioctl_gpfifo_entry *entries, u32 num_entries, u32 flags, nvioctl_fence *fence_out);
Result nvioctlChannel_AllocObjCtx(u32 fd, u32 class_num, u32 flags);
Result nvioctlChannel_ZCullBind(u32 fd, u64 gpu_va, u32 mode);
Result nvioctlChannel_SetErrorNotifier(u32 fd, u64 offset, u64 size, u32 nvmap_handle);
Result nvioctlChannel_SetPriority(u32 fd, u32 priority);
Result nvioctlChannel_AllocGpfifoEx2(u32 fd, u32 num_entries, u32 flags, u32 unk0, u32 unk1, u32 unk2, u32 unk3, nvioctl_fence *fence_out);
Result nvioctlChannel_SetUserData(u32 fd, void* addr);

View file

@ -1,31 +0,0 @@
#pragma once
#include "../result.h"
#include "../gfx/binder.h"
typedef struct {
u8 payload[0x400];
u32 capacity;
u32 size;
u32 pos;
u8 *ParcelObjects;
u32 ParcelObjectsSize;
} Parcel;
void parcelInitialize(Parcel *ctx);
Result parcelTransact(Binder *session, u32 code, Parcel *in_parcel, Parcel *reply_parcel);
void* parcelWriteData(Parcel *ctx, void* data, size_t data_size);
void* parcelReadData(Parcel *ctx, void* data, size_t data_size);
void parcelWriteInt32(Parcel *ctx, s32 val);
void parcelWriteUInt32(Parcel *ctx, u32 val);
void parcelWriteString16(Parcel *ctx, const char *str);
s32 parcelReadInt32(Parcel *ctx);
u32 parcelReadUInt32(Parcel *ctx);
void parcelWriteInterfaceToken(Parcel *ctx, const char *str);
void* parcelReadFlattenedObject(Parcel *ctx, size_t *size);
void* parcelWriteFlattenedObject(Parcel *ctx, void* data, size_t size);

View file

@ -1,69 +0,0 @@
/**
* @file condvar.h
* @brief Condition variable synchronization primitive.
* @author plutoo
* @copyright libnx Authors
*/
#include "../types.h"
#include "../kernel/mutex.h"
/// Condition variable structure.
typedef struct {
u32 tag;
Mutex* mutex;
} CondVar;
/**
* @brief Initializes a condition variable.
* @param[in] c Condition variable object.
* @param[in] m Mutex object to use inside the condition variable.
*/
void condvarInit(CondVar* c, Mutex* m);
/**
* @brief Waits on a condition variable with a timeout.
* @param[in] c Condition variable object.
* @param[in] timeout Timeout in nanoseconds.
* @return Result code (0xEA01 on timeout).
* @remark On function return, the underlying mutex is acquired.
*/
Result condvarWaitTimeout(CondVar* c, u64 timeout);
/**
* @brief Waits on a condition variable.
* @param[in] c Condition variable object.
* @return Result code.
* @remark On function return, the underlying mutex is acquired.
*/
static inline Result condvarWait(CondVar* c)
{
return condvarWaitTimeout(c, -1ull);
}
/**
* @brief Wakes up up to the specified number of threads waiting on a condition variable.
* @param[in] c Condition variable object.
* @param[in] num Maximum number of threads to wake up (or -1 to wake them all up).
* @return Result code.
*/
Result condvarWake(CondVar* c, int num);
/**
* @brief Wakes up a single thread waiting on a condition variable.
* @param[in] c Condition variable object.
* @return Result code.
*/
static inline Result condvarWakeOne(CondVar* c)
{
return condvarWake(c, 1);
}
/**
* @brief Wakes up all thread waiting on a condition variable.
* @param[in] c Condition variable object.
* @return Result code.
*/
static inline Result condvarWakeAll(CondVar* c)
{
return condvarWake(c, -1);
}

View file

@ -1,19 +0,0 @@
/**
* @file detect.h
* @brief Kernel version detection
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/// Returns true if the kernel version is equal to or above 2.0.0.
bool kernelAbove200(void);
/// Returns true if the kernel version is equal to or above 3.0.0.
bool kernelAbove300(void);
/// Returns true if the kernel version is equal to or above 4.0.0.
bool kernelAbove400(void);
/// Returns true if the kernel version is equal to or above 5.0.0.
bool kernelAbove500(void);
/// Returns true if the process has a debugger attached.
bool detectDebugger(void);

View file

@ -1,674 +0,0 @@
/**
* @file ipc.h
* @brief Inter-process communication handling
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../result.h"
#include "../arm/tls.h"
#include "../kernel/svc.h"
/// IPC input header magic
#define SFCI_MAGIC 0x49434653
/// IPC output header magic
#define SFCO_MAGIC 0x4f434653
/// IPC invalid object ID
#define IPC_INVALID_OBJECT_ID UINT32_MAX
///@name IPC request building
///@{
/// IPC command (request) structure.
#define IPC_MAX_BUFFERS 8
#define IPC_MAX_OBJECTS 8
typedef enum {
BufferType_Normal=0, ///< Regular buffer.
BufferType_Type1=1, ///< Allows ProcessMemory and shared TransferMemory.
BufferType_Invalid=2,
BufferType_Type3=3 ///< Same as Type1 except remote process is not allowed to use device-mapping.
} BufferType;
typedef enum {
BufferDirection_Send=0,
BufferDirection_Recv=1,
BufferDirection_Exch=2,
} BufferDirection;
typedef enum {
IpcCommandType_Invalid = 0,
IpcCommandType_LegacyRequest = 1,
IpcCommandType_Close = 2,
IpcCommandType_LegacyControl = 3,
IpcCommandType_Request = 4,
IpcCommandType_Control = 5,
IpcCommandType_RequestWithContext = 6,
IpcCommandType_ControlWithContext = 7,
} IpcCommandType;
typedef enum {
DomainMessageType_Invalid = 0,
DomainMessageType_SendMessage = 1,
DomainMessageType_Close = 2,
} DomainMessageType;
/// IPC domain message header.
typedef struct {
u8 Type;
u8 NumObjectIds;
u16 Length;
u32 ThisObjectId;
u32 Pad[2];
} DomainMessageHeader;
typedef struct {
size_t NumSend; // A
size_t NumRecv; // B
size_t NumExch; // W
const void* Buffers[IPC_MAX_BUFFERS];
size_t BufferSizes[IPC_MAX_BUFFERS];
BufferType BufferTypes[IPC_MAX_BUFFERS];
size_t NumStaticIn; // X
size_t NumStaticOut; // C
const void* Statics[IPC_MAX_BUFFERS];
size_t StaticSizes[IPC_MAX_BUFFERS];
u8 StaticIndices[IPC_MAX_BUFFERS];
bool SendPid;
size_t NumHandlesCopy;
size_t NumHandlesMove;
Handle Handles[IPC_MAX_OBJECTS];
size_t NumObjectIds;
u32 ObjectIds[IPC_MAX_OBJECTS];
} IpcCommand;
/**
* @brief Initializes an IPC command structure.
* @param cmd IPC command structure.
*/
static inline void ipcInitialize(IpcCommand* cmd) {
*cmd = (IpcCommand){0};
}
/// IPC buffer descriptor.
typedef struct {
u32 Size; ///< Size of the buffer.
u32 Addr; ///< Lower 32-bits of the address of the buffer
u32 Packed; ///< Packed data (including higher bits of the address)
} IpcBufferDescriptor;
/// IPC static send-buffer descriptor.
typedef struct {
u32 Packed; ///< Packed data (including higher bits of the address)
u32 Addr; ///< Lower 32-bits of the address
} IpcStaticSendDescriptor;
/// IPC static receive-buffer descriptor.
typedef struct {
u32 Addr; ///< Lower 32-bits of the address of the buffer
u32 Packed; ///< Packed data (including higher bits of the address)
} IpcStaticRecvDescriptor;
/**
* @brief Adds a buffer to an IPC command structure.
* @param cmd IPC command structure.
* @param buffer Address of the buffer.
* @param size Size of the buffer.
* @param type Buffer type.
*/
static inline void ipcAddSendBuffer(IpcCommand* cmd, const void* buffer, size_t size, BufferType type) {
size_t off = cmd->NumSend;
cmd->Buffers[off] = buffer;
cmd->BufferSizes[off] = size;
cmd->BufferTypes[off] = type;
cmd->NumSend++;
}
/**
* @brief Adds a receive-buffer to an IPC command structure.
* @param cmd IPC command structure.
* @param buffer Address of the buffer.
* @param size Size of the buffer.
* @param type Buffer type.
*/
static inline void ipcAddRecvBuffer(IpcCommand* cmd, void* buffer, size_t size, BufferType type) {
size_t off = cmd->NumSend + cmd->NumRecv;
cmd->Buffers[off] = buffer;
cmd->BufferSizes[off] = size;
cmd->BufferTypes[off] = type;
cmd->NumRecv++;
}
/**
* @brief Adds an exchange-buffer to an IPC command structure.
* @param cmd IPC command structure.
* @param buffer Address of the buffer.
* @param size Size of the buffer.
* @param type Buffer type.
*/
static inline void ipcAddExchBuffer(IpcCommand* cmd, void* buffer, size_t size, BufferType type) {
size_t off = cmd->NumSend + cmd->NumRecv + cmd->NumExch;
cmd->Buffers[off] = buffer;
cmd->BufferSizes[off] = size;
cmd->BufferTypes[off] = type;
cmd->NumExch++;
}
/**
* @brief Adds a static-buffer to an IPC command structure.
* @param cmd IPC command structure.
* @param buffer Address of the buffer.
* @param size Size of the buffer.
* @param index Index of buffer.
*/
static inline void ipcAddSendStatic(IpcCommand* cmd, const void* buffer, size_t size, u8 index) {
size_t off = cmd->NumStaticIn;
cmd->Statics[off] = buffer;
cmd->StaticSizes[off] = size;
cmd->StaticIndices[off] = index;
cmd->NumStaticIn++;
}
/**
* @brief Adds a static-receive-buffer to an IPC command structure.
* @param cmd IPC command structure.
* @param buffer Address of the buffer.
* @param size Size of the buffer.
* @param index Index of buffer.
*/
static inline void ipcAddRecvStatic(IpcCommand* cmd, void* buffer, size_t size, u8 index) {
size_t off = cmd->NumStaticIn + cmd->NumStaticOut;
cmd->Statics[off] = buffer;
cmd->StaticSizes[off] = size;
cmd->StaticIndices[off] = index;
cmd->NumStaticOut++;
}
/**
* @brief Adds a smart-buffer (buffer + static-buffer pair) to an IPC command structure.
* @param cmd IPC command structure.
* @param ipc_buffer_size IPC buffer size.
* @param buffer Address of the buffer.
* @param size Size of the buffer.
* @param index Index of buffer.
*/
static inline void ipcAddSendSmart(IpcCommand* cmd, size_t ipc_buffer_size, const void* buffer, size_t size, u8 index) {
if (ipc_buffer_size != 0 && size <= ipc_buffer_size) {
ipcAddSendBuffer(cmd, NULL, 0, BufferType_Normal);
ipcAddSendStatic(cmd, buffer, size, index);
} else {
ipcAddSendBuffer(cmd, buffer, size, BufferType_Normal);
ipcAddSendStatic(cmd, NULL, 0, index);
}
}
/**
* @brief Adds a smart-receive-buffer (buffer + static-receive-buffer pair) to an IPC command structure.
* @param cmd IPC command structure.
* @param ipc_buffer_size IPC buffer size.
* @param buffer Address of the buffer.
* @param size Size of the buffer.
* @param index Index of buffer.
*/
static inline void ipcAddRecvSmart(IpcCommand* cmd, size_t ipc_buffer_size, void* buffer, size_t size, u8 index) {
if (ipc_buffer_size != 0 && size <= ipc_buffer_size) {
ipcAddRecvBuffer(cmd, NULL, 0, BufferType_Normal);
ipcAddRecvStatic(cmd, buffer, size, index);
} else {
ipcAddRecvBuffer(cmd, buffer, size, BufferType_Normal);
ipcAddRecvStatic(cmd, NULL, 0, index);
}
}
/**
* @brief Tags an IPC command structure to send the PID.
* @param cmd IPC command structure.
*/
static inline void ipcSendPid(IpcCommand* cmd) {
cmd->SendPid = true;
}
/**
* @brief Adds a copy-handle to be sent through an IPC command structure.
* @param cmd IPC command structure.
* @param h Handle to send.
* @remark The receiving process gets a copy of the handle.
*/
static inline void ipcSendHandleCopy(IpcCommand* cmd, Handle h) {
cmd->Handles[cmd->NumHandlesCopy++] = h;
}
/**
* @brief Adds a move-handle to be sent through an IPC command structure.
* @param cmd IPC command structure.
* @param h Handle to send.
* @remark The sending process loses ownership of the handle, which is transferred to the receiving process.
*/
static inline void ipcSendHandleMove(IpcCommand* cmd, Handle h) {
cmd->Handles[cmd->NumHandlesCopy + cmd->NumHandlesMove++] = h;
}
/**
* @brief Prepares the header of an IPC command structure.
* @param cmd IPC command structure.
* @param sizeof_raw Size in bytes of the raw data structure to embed inside the IPC request
* @return Pointer to the raw embedded data structure in the request, ready to be filled out.
*/
static inline void* ipcPrepareHeader(IpcCommand* cmd, size_t sizeof_raw) {
u32* buf = (u32*)armGetTls();
size_t i;
*buf++ = IpcCommandType_Request | (cmd->NumStaticIn << 16) | (cmd->NumSend << 20) | (cmd->NumRecv << 24) | (cmd->NumExch << 28);
u32* fill_in_size_later = buf;
if (cmd->NumStaticOut > 0) {
*buf = (cmd->NumStaticOut + 2) << 10;
}
else {
*buf = 0;
}
if (cmd->SendPid || cmd->NumHandlesCopy > 0 || cmd->NumHandlesMove > 0) {
*buf++ |= 0x80000000;
*buf++ = (!!cmd->SendPid) | (cmd->NumHandlesCopy << 1) | (cmd->NumHandlesMove << 5);
if (cmd->SendPid)
buf += 2;
for (i=0; i<(cmd->NumHandlesCopy + cmd->NumHandlesMove); i++)
*buf++ = cmd->Handles[i];
}
else {
buf++;
}
for (i=0; i<cmd->NumStaticIn; i++, buf+=2) {
IpcStaticSendDescriptor* desc = (IpcStaticSendDescriptor*) buf;
uintptr_t ptr = (uintptr_t) cmd->Statics[i];
desc->Addr = ptr;
desc->Packed = cmd->StaticIndices[i] | (cmd->StaticSizes[i] << 16) |
(((ptr >> 32) & 15) << 12) | (((ptr >> 36) & 15) << 6);
}
for (i=0; i<(cmd->NumSend + cmd->NumRecv + cmd->NumExch); i++, buf+=3) {
IpcBufferDescriptor* desc = (IpcBufferDescriptor*) buf;
desc->Size = cmd->BufferSizes[i];
uintptr_t ptr = (uintptr_t) cmd->Buffers[i];
desc->Addr = ptr;
desc->Packed = cmd->BufferTypes[i] |
(((ptr >> 32) & 15) << 28) | ((ptr >> 36) << 2);
}
u32 padding = ((16 - (((uintptr_t) buf) & 15)) & 15) / 4;
u32* raw = (u32*) (buf + padding);
size_t raw_size = (sizeof_raw/4) + 4;
buf += raw_size;
u16* buf_u16 = (u16*) buf;
for (i=0; i<cmd->NumStaticOut; i++) {
size_t off = cmd->NumStaticIn + i;
size_t sz = (uintptr_t) cmd->StaticSizes[off];
buf_u16[i] = (sz > 0xFFFF) ? 0 : sz;
}
size_t u16s_size = ((2*cmd->NumStaticOut) + 3)/4;
buf += u16s_size;
raw_size += u16s_size;
*fill_in_size_later |= raw_size;
for (i=0; i<cmd->NumStaticOut; i++, buf+=2) {
IpcStaticRecvDescriptor* desc = (IpcStaticRecvDescriptor*) buf;
size_t off = cmd->NumStaticIn + i;
uintptr_t ptr = (uintptr_t) cmd->Statics[off];
desc->Addr = ptr;
desc->Packed = (ptr >> 32) | (cmd->StaticSizes[off] << 16);
}
return (void*) raw;
}
/**
* @brief Dispatches an IPC request.
* @param session IPC session handle.
* @return Result code.
*/
static inline Result ipcDispatch(Handle session) {
return svcSendSyncRequest(session);
}
///@}
///@name IPC response parsing
///@{
/// IPC parsed command (response) structure.
typedef struct {
IpcCommandType CommandType; ///< Type of the command
bool HasPid; ///< true if the 'Pid' field is filled out.
u64 Pid; ///< PID included in the response (only if HasPid is true)
size_t NumHandles; ///< Number of handles copied.
Handle Handles[IPC_MAX_OBJECTS]; ///< Handles.
bool WasHandleCopied[IPC_MAX_OBJECTS]; ///< true if the handle was moved, false if it was copied.
bool IsDomainMessage; ///< true if the the message is a Domain message.
DomainMessageType MessageType; ///< Type of the domain message.
u32 MessageLength; ///< Size of rawdata (for domain messages).
u32 ThisObjectId; ///< Object ID to call the command on (for domain messages).
size_t NumObjectIds; ///< Number of object IDs (for domain messages).
u32 ObjectIds[IPC_MAX_OBJECTS]; ///< Object IDs (for domain messages).
size_t NumBuffers; ///< Number of buffers in the response.
void* Buffers[IPC_MAX_BUFFERS]; ///< Pointers to the buffers.
size_t BufferSizes[IPC_MAX_BUFFERS]; ///< Sizes of the buffers.
BufferType BufferTypes[IPC_MAX_BUFFERS]; ///< Types of the buffers.
BufferDirection BufferDirections[IPC_MAX_BUFFERS]; ///< Direction of each buffer.
size_t NumStatics; ///< Number of statics in the response.
void* Statics[IPC_MAX_BUFFERS]; ///< Pointers to the statics.
size_t StaticSizes[IPC_MAX_BUFFERS]; ///< Sizes of the statics.
u8 StaticIndices[IPC_MAX_BUFFERS]; ///< Indices of the statics.
size_t NumStaticsOut; ///< Number of output statics available in the response.
void* Raw; ///< Pointer to the raw embedded data structure in the response.
void* RawWithoutPadding; ///< Pointer to the raw embedded data structure, without padding.
size_t RawSize; ///< Size of the raw embedded data.
} IpcParsedCommand;
/**
* @brief Parse an IPC command response into an IPC parsed command structure.
* @param IPC parsed command structure to fill in.
* @return Result code.
*/
static inline Result ipcParse(IpcParsedCommand* r) {
u32* buf = (u32*)armGetTls();
u32 ctrl0 = *buf++;
u32 ctrl1 = *buf++;
size_t i;
r->IsDomainMessage = false;
r->CommandType = (IpcCommandType) (ctrl0 & 0xffff);
r->HasPid = false;
r->RawSize = (ctrl1 & 0x1ff) * 4;
r->NumHandles = 0;
r->NumStaticsOut = (ctrl1 >> 10) & 15;
if (r->NumStaticsOut >> 1) r->NumStaticsOut--; // Value 2 -> Single descriptor
if (r->NumStaticsOut >> 1) r->NumStaticsOut--; // Value 3+ -> (Value - 2) descriptors
if (ctrl1 & 0x80000000) {
u32 ctrl2 = *buf++;
if (ctrl2 & 1) {
r->HasPid = true;
r->Pid = *buf++;
r->Pid |= ((u64)(*buf++)) << 32;
}
size_t num_handles_copy = ((ctrl2 >> 1) & 15);
size_t num_handles_move = ((ctrl2 >> 5) & 15);
size_t num_handles = num_handles_copy + num_handles_move;
u32* buf_after_handles = buf + num_handles;
if (num_handles > IPC_MAX_OBJECTS)
num_handles = IPC_MAX_OBJECTS;
for (i=0; i<num_handles; i++)
{
r->Handles[i] = *(buf+i);
r->WasHandleCopied[i] = (i < num_handles_copy);
}
r->NumHandles = num_handles;
buf = buf_after_handles;
}
size_t num_statics = (ctrl0 >> 16) & 15;
u32* buf_after_statics = buf + num_statics*2;
if (num_statics > IPC_MAX_BUFFERS)
num_statics = IPC_MAX_BUFFERS;
for (i=0; i<num_statics; i++, buf+=2) {
IpcStaticSendDescriptor* desc = (IpcStaticSendDescriptor*) buf;
u64 packed = (u64) desc->Packed;
r->Statics[i] = (void*) (desc->Addr | (((packed >> 12) & 15) << 32) | (((packed >> 6) & 15) << 36));
r->StaticSizes[i] = packed >> 16;
r->StaticIndices[i] = packed & 63;
}
r->NumStatics = num_statics;
buf = buf_after_statics;
size_t num_bufs_send = (ctrl0 >> 20) & 15;
size_t num_bufs_recv = (ctrl0 >> 24) & 15;
size_t num_bufs_exch = (ctrl0 >> 28) & 15;
size_t num_bufs = num_bufs_send + num_bufs_recv + num_bufs_exch;
r->Raw = (void*)(((uintptr_t)(buf + num_bufs*3) + 15) &~ 15);
r->RawWithoutPadding = (void*)((uintptr_t)(buf + num_bufs*3));
if (num_bufs > IPC_MAX_BUFFERS)
num_bufs = IPC_MAX_BUFFERS;
for (i=0; i<num_bufs; i++, buf+=3) {
IpcBufferDescriptor* desc = (IpcBufferDescriptor*) buf;
u64 packed = (u64) desc->Packed;
r->Buffers[i] = (void*) (desc->Addr | ((packed >> 28) << 32) | (((packed >> 2) & 15) << 36));
r->BufferSizes[i] = desc->Size;
r->BufferTypes[i] = (BufferType) (packed & 3);
if (i < num_bufs_send)
r->BufferDirections[i] = BufferDirection_Send;
else if (i < (num_bufs_send + num_bufs_recv))
r->BufferDirections[i] = BufferDirection_Recv;
else
r->BufferDirections[i] = BufferDirection_Exch;
}
r->NumBuffers = num_bufs;
return 0;
}
/**
* @brief Queries the size of an IPC pointer buffer.
* @param session IPC session handle.
* @param size Output variable in which to store the size.
* @return Result code.
*/
static inline Result ipcQueryPointerBufferSize(Handle session, size_t *size) {
u32* buf = (u32*)armGetTls();
buf[0] = IpcCommandType_Control;
buf[1] = 8;
buf[2] = 0;
buf[3] = 0;
buf[4] = SFCI_MAGIC;
buf[5] = 0;
buf[6] = 3;
buf[7] = 0;
Result rc = ipcDispatch(session);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
ipcParse(&r);
struct ipcQueryPointerBufferSizeResponse {
u64 magic;
u64 result;
u32 size;
} *raw = (struct ipcQueryPointerBufferSizeResponse*)r.Raw;
rc = raw->result;
if (R_SUCCEEDED(rc)) {
*size = raw->size & 0xffff;
}
}
return rc;
}
/**
* @brief Closes the IPC session with proper clean up.
* @param session IPC session handle.
* @return Result code.
*/
static inline Result ipcCloseSession(Handle session) {
u32* buf = (u32*)armGetTls();
buf[0] = IpcCommandType_Close;
buf[1] = 0;
return ipcDispatch(session);
}
///@}
///@name IPC domain handling
///@{
/**
* @brief Converts an IPC session handle into a domain.
* @param session IPC session handle.
* @param object_id_out Output variable in which to store the object ID.
* @return Result code.
*/
static inline Result ipcConvertSessionToDomain(Handle session, u32* object_id_out) {
u32* buf = (u32*)armGetTls();
buf[0] = IpcCommandType_Control;
buf[1] = 8;
buf[4] = SFCI_MAGIC;
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
Result rc = ipcDispatch(session);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
ipcParse(&r);
struct ipcConvertSessionToDomainResponse {
u64 magic;
u64 result;
u32 object_id;
} *raw = (struct ipcConvertSessionToDomainResponse*)r.Raw;
rc = raw->result;
if (R_SUCCEEDED(rc)) {
*object_id_out = raw->object_id;
}
}
return rc;
}
/**
* @brief Adds an object ID to be sent through an IPC domain command structure.
* @param cmd IPC domain command structure.
* @param object_id Object ID to send.
*/
static inline void ipcSendObjectId(IpcCommand* cmd, u32 object_id) {
cmd->ObjectIds[cmd->NumObjectIds++] = object_id;
}
/**
* @brief Prepares the header of an IPC command structure (domain version).
* @param cmd IPC command structure.
* @param sizeof_raw Size in bytes of the raw data structure to embed inside the IPC request
* @oaram object_id Domain object ID.
* @return Pointer to the raw embedded data structure in the request, ready to be filled out.
*/
static inline void* ipcPrepareHeaderForDomain(IpcCommand* cmd, size_t sizeof_raw, u32 object_id) {
void* raw = ipcPrepareHeader(cmd, sizeof_raw + sizeof(DomainMessageHeader));
DomainMessageHeader* hdr = (DomainMessageHeader*) raw;
u32 *object_ids = (u32*)(((uintptr_t) raw) + sizeof(DomainMessageHeader) + sizeof_raw);
hdr->Type = DomainMessageType_SendMessage;
hdr->NumObjectIds = (u8)cmd->NumObjectIds;
hdr->Length = sizeof_raw;
hdr->ThisObjectId = object_id;
hdr->Pad[0] = hdr->Pad[1] = 0;
for(size_t i = 0; i < cmd->NumObjectIds; i++)
object_ids[i] = cmd->ObjectIds[i];
return (void*)(((uintptr_t) raw) + sizeof(DomainMessageHeader));
}
/**
* @brief Parse an IPC command response into an IPC parsed command structure (domain version).
* @param IPC parsed command structure to fill in.
* @return Result code.
*/
static inline Result ipcParseForDomain(IpcParsedCommand* r) {
Result rc = ipcParse(r);
DomainMessageHeader *hdr;
u32 *object_ids;
if(R_FAILED(rc))
return rc;
hdr = (DomainMessageHeader*) r->Raw;
object_ids = (u32*)(((uintptr_t) hdr) + sizeof(DomainMessageHeader) + hdr->Length);
r->Raw = (void*)(((uintptr_t) r->Raw) + sizeof(DomainMessageHeader));
r->IsDomainMessage = true;
r->MessageType = (DomainMessageType)(hdr->Type);
switch (r->MessageType) {
case DomainMessageType_SendMessage:
case DomainMessageType_Close:
break;
default:
return MAKERESULT(Module_Libnx, LibnxError_DomainMessageUnknownType);
}
r->ThisObjectId = hdr->ThisObjectId;
r->NumObjectIds = hdr->NumObjectIds > 8 ? 8 : hdr->NumObjectIds;
if ((uintptr_t)object_ids + sizeof(u32) * r->NumObjectIds - (uintptr_t)armGetTls() >= 0x100) {
return MAKERESULT(Module_Libnx, LibnxError_DomainMessageTooManyObjectIds);
}
for(size_t i = 0; i < r->NumObjectIds; i++)
r->ObjectIds[i] = object_ids[i];
return rc;
}
/**
* @brief Closes a domain object by ID.
* @param session IPC session handle.
* @param object_id ID of the object to close.
* @return Result code.
*/
static inline Result ipcCloseObjectById(Handle session, u32 object_id) {
IpcCommand c;
DomainMessageHeader* hdr;
ipcInitialize(&c);
hdr = (DomainMessageHeader*)ipcPrepareHeader(&c, sizeof(DomainMessageHeader));
hdr->Type = 2;
hdr->NumObjectIds = 0;
hdr->Length = 0;
hdr->ThisObjectId = object_id;
hdr->Pad[0] = hdr->Pad[1] = 0;
return ipcDispatch(session); // this command has no associated response
}
///@}

View file

@ -1,68 +0,0 @@
/**
* @file jit.h
* @brief Just-in-time compilation support.
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/// JIT implementation type.
typedef enum {
JitType_CodeMemory, ///< JIT supported using svcSetProcessMemoryPermission
JitType_JitMemory, ///< JIT supported using 4.0.0+ code-memory syscalls (this isn't usable on 5.0.0+ so JitType_CodeMemory is used instead).
} JitType;
/// JIT buffer object.
typedef struct {
JitType type;
size_t size;
void* src_addr;
void* rx_addr;
void* rw_addr;
bool is_executable;
Handle handle;
} Jit;
/**
* @brief Creates a JIT buffer.
* @param j JIT buffer.
* @param size Size of the JIT buffer.
* @return Result code.
*/
Result jitCreate(Jit* j, size_t size);
/**
* @brief Transition a JIT buffer to have writable permission.
* @param j JIT buffer.
* @return Result code.
*/
Result jitTransitionToWritable(Jit* j);
/**
* @brief Transition a JIT buffer to have executable permission.
* @param j JIT buffer.
* @return Result code.
*/
Result jitTransitionToExecutable(Jit* j);
/**
* @brief Destroys a JIT buffer.
* @param j JIT buffer.
* @return Result code.
*/
Result jitClose(Jit* j);
/**
* @brief Gets the address of the writable memory alias of a JIT buffer.
* @param j JIT buffer.
* @return Pointer to alias of the JIT buffer that can be written to.
*/
void* jitGetRwAddr(Jit* j);
/**
* @brief Gets the address of the executable memory alias of a JIT buffer.
* @param j JIT buffer.
* @return Pointer to alias of the JIT buffer that can be executed.
*/
void* jitGetRxAddr(Jit* j);

View file

@ -1,74 +0,0 @@
/**
* @file mutex.h
* @brief Mutex synchronization primitive.
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include <sys/lock.h>
#include "../types.h"
/// Mutex datatype, defined in newlib.
typedef _LOCK_T Mutex;
/// Recursive mutex datatype, defined in newlib.
typedef _LOCK_RECURSIVE_T RMutex;
/**
* @brief Initializes a mutex.
* @param m Mutex object.
* @note A mutex can also be statically initialized by assigning 0 to it.
*/
static inline void mutexInit(Mutex* m)
{
*m = 0;
}
/**
* @brief Locks a mutex.
* @param m Mutex object.
*/
void mutexLock(Mutex* m);
/**
* @brief Attempts to lock a mutex without waiting.
* @param m Mutex object.
* @return 1 if the mutex has been acquired successfully, and 0 on contention.
*/
bool mutexTryLock(Mutex* m);
/**
* @brief Unlocks a mutex.
* @param m Mutex object.
*/
void mutexUnlock(Mutex* m);
/**
* @brief Initializes a recursive mutex.
* @param m Recursive mutex object.
* @note A recursive mutex can also be statically initialized by assigning {0,0,0} to it.
*/
static inline void rmutexInit(RMutex* m)
{
m->lock = 0;
m->thread_tag = 0;
m->counter = 0;
}
/**
* @brief Locks a recursive mutex.
* @param m Recursive mutex object.
*/
void rmutexLock(RMutex* m);
/**
* @brief Attempts to lock a recursive mutex without waiting.
* @param m Recursive mutex object.
* @return 1 if the mutex has been acquired successfully, and 0 on contention.
*/
bool rmutexTryLock(RMutex* m);
/**
* @brief Unlocks a recursive mutex.
* @param m Recursive mutex object.
*/
void rmutexUnlock(RMutex* m);

View file

@ -1,21 +0,0 @@
/**
* @file random.h
* @brief OS-seeded pseudo-random number generation support (ChaCha algorithm).
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/**
* @brief Fills a buffer with random data.
* @param buf Pointer to the buffer.
* @param len Size of the buffer in bytes.
*/
void randomGet(void* buf, size_t len);
/**
* @brief Returns a random 64-bit value.
* @return Random value.
*/
u64 randomGet64(void);

View file

@ -1,39 +0,0 @@
/**
* @file rwlock.h
* @brief Read/write lock synchronization primitive.
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../kernel/mutex.h"
/// Read/write lock structure.
typedef struct {
RMutex r;
RMutex g;
u64 b;
} RwLock;
/**
* @brief Locks the read/write lock for reading.
* @param r Read/write lock object.
*/
void rwlockReadLock(RwLock* r);
/**
* @brief Unlocks the read/write lock for reading.
* @param r Read/write lock object.
*/
void rwlockReadUnlock(RwLock* r);
/**
* @brief Locks the read/write lock for writing.
* @param r Read/write lock object.
*/
void rwlockWriteLock(RwLock* r);
/**
* @brief Unlocks the read/write lock for writing.
* @param r Read/write lock object.
*/
void rwlockWriteUnlock(RwLock* r);

View file

@ -1,67 +0,0 @@
/**
* @file shmem.h
* @brief Shared memory object handling
* @author plutoo
* @copyright libnx Authors
* @remark Shared memory differs from transfer memory in the fact that the kernel (as opposed to the user process) allocates and owns its backing memory.
*/
#pragma once
#include "../types.h"
/// Shared memory information structure.
typedef struct {
Handle handle; ///< Kernel object handle.
size_t size; ///< Size of the shared memory object.
Permission perm; ///< Permissions.
void* map_addr; ///< Address to which the shared memory object is mapped.
} SharedMemory;
/**
* @brief Creates a shared memory object.
* @param s Shared memory information structure which will be filled in.
* @param size Size of the shared memory object to create.
* @param local_perm Permissions with which the shared memory object will be mapped in the local process.
* @param remote_perm Permissions with which the shared memory object will be mapped in the remote process (can be Perm_DontCare).
* @return Result code.
* @warning This is a privileged operation; in normal circumstances applications cannot use this function.
*/
Result shmemCreate(SharedMemory* s, size_t size, Permission local_perm, Permission remote_perm);
/**
* @brief Loads a shared memory object coming from a remote process.
* @param s Shared memory information structure which will be filled in.
* @param handle Handle of the shared memory object.
* @param size Size of the shared memory object that is being loaded.
* @param perm Permissions with which the shared memory object will be mapped in the local process.
*/
void shmemLoadRemote(SharedMemory* s, Handle handle, size_t size, Permission perm);
/**
* @brief Maps a shared memory object.
* @param s Shared memory information structure.
* @return Result code.
*/
Result shmemMap(SharedMemory* s);
/**
* @brief Unmaps a shared memory object.
* @param s Shared memory information structure.
* @return Result code.
*/
Result shmemUnmap(SharedMemory* s);
/**
* @brief Retrieves the mapped address of a shared memory object.
* @param s Shared memory information structure.
* @return Mapped address of the shared memory object.
*/
static inline void* shmemGetAddr(SharedMemory* s) {
return s->map_addr;
}
/**
* @brief Frees up resources used by a shared memory object, unmapping and closing handles, etc.
* @param s Shared memory information structure.
* @return Result code.
*/
Result shmemClose(SharedMemory* s);

File diff suppressed because it is too large Load diff

View file

@ -1,67 +0,0 @@
/**
* @file thread.h
* @brief Multi-threading support
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/// Thread information structure.
typedef struct {
Handle handle; ///< Thread handle.
void* stack_mem; ///< Pointer to stack memory.
void* stack_mirror; ///< Pointer to stack memory mirror.
size_t stack_sz; ///< Stack size.
} Thread;
/**
* @brief Creates a thread.
* @param t Thread information structure which will be filled in.
* @param entry Entrypoint of the thread.
* @param arg Argument to pass to the entrypoint.
* @param stack_sz Stack size (rounded up to page alignment).
* @param prio Thread priority (0x00~0x3F); 0x2C is the usual priority of the main thread.
* @param cpuid ID of the core on which to create the thread (0~3); or -2 to use the default core for the current process.
* @return Result code.
*/
Result threadCreate(
Thread* t, ThreadFunc entry, void* arg, size_t stack_sz, int prio,
int cpuid);
/**
* @brief Starts the execution of a thread.
* @param t Thread information structure.
* @return Result code.
*/
Result threadStart(Thread* t);
/**
* @brief Waits for a thread to finish executing.
* @param t Thread information structure.
* @return Result code.
*/
Result threadWaitForExit(Thread* t);
/**
* @brief Frees up resources associated with a thread.
* @param t Thread information structure.
* @return Result code.
*/
Result threadClose(Thread* t);
/**
* @brief Pauses the execution of a thread.
* @param t Thread information structure.
* @return Result code.
* @warning This is a privileged operation; in normal circumstances applications cannot use this function.
*/
Result threadPause(Thread* t);
/**
* @brief Resumes the execution of a thread, after having been paused.
* @param t Thread information structure.
* @return Result code.
* @warning This is a privileged operation; in normal circumstances applications cannot use this function.
*/
Result threadResume(Thread* t);

View file

@ -1,70 +0,0 @@
/**
* @file tmem.h
* @brief Transfer memory handling
* @author plutoo
* @copyright libnx Authors
* @remark Transfer memory differs from shared memory in the fact that the user process (as opposed to the kernel) allocates and owns its backing memory.
*/
#pragma once
#include "../types.h"
#include "../kernel/svc.h"
/// Transfer memory information structure.
typedef struct {
Handle handle; ///< Kernel object handle.
size_t size; ///< Size of the transfer memory object.
Permission perm; ///< Permissions of the transfer memory object.
void* src_addr; ///< Address of the source backing memory.
void* map_addr; ///< Address to which the transfer memory object is mapped.
} TransferMemory;
/**
* @brief Creates a transfer memory object.
* @param t Transfer memory information structure that will be filled in.
* @param size Size of the transfer memory object to create.
* @param perm Permissions with which to protect the transfer memory in the local process.
* @return Result code.
*/
Result tmemCreate(TransferMemory* t, size_t size, Permission perm);
/**
* @brief Loads a transfer memory object coming from a remote process.
* @param t Transfer memory information structure which will be filled in.
* @param handle Handle of the transfer memory object.
* @param size Size of the transfer memory object that is being loaded.
* @param perm Permissions which the transfer memory is expected to have in the process that owns the memory.
* @warning This is a privileged operation; in normal circumstances applications shouldn't use this function.
*/
void tmemLoadRemote(TransferMemory* t, Handle handle, size_t size, Permission perm);
/**
* @brief Maps a transfer memory object.
* @param t Transfer memory information structure.
* @return Result code.
* @warning This is a privileged operation; in normal circumstances applications cannot use this function.
*/
Result tmemMap(TransferMemory* t);
/**
* @brief Unmaps a transfer memory object.
* @param t Transfer memory information structure.
* @return Result code.
* @warning This is a privileged operation; in normal circumstances applications cannot use this function.
*/
Result tmemUnmap(TransferMemory* t);
/**
* @brief Retrieves the mapped address of a transfer memory object.
* @param t Transfer memory information structure.
* @return Mapped address of the transfer memory object.
*/
static inline void* tmemGetAddr(TransferMemory* t){
return t->map_addr;
}
/**
* @brief Frees up resources used by a transfer memory object, unmapping and closing handles, etc.
* @param t Transfer memory information structure.
* @return Result code.
*/
Result tmemClose(TransferMemory* t);

View file

@ -1,36 +0,0 @@
/**
* @file virtmem.h
* @brief Virtual memory mapping utilities
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/**
* @brief Reserves a slice of general purpose address space.
* @param size The size of the slice of address space that will be reserved (rounded up to page alignment).
* @return Pointer to the slice of address space, or NULL on failure.
*/
void* virtmemReserve(size_t size);
/**
* @brief Relinquishes a slice of address space reserved with virtmemReserve (currently no-op).
* @param addr Pointer to the slice.
* @param size Size of the slice.
*/
void virtmemFree(void* addr, size_t size);
/**
* @brief Reserves a slice of address space inside the alias memory mapping region(s) (for use with svcMapMemory).
* @param size The size of the slice of address space that will be reserved (rounded up to page alignment).
* @return Pointer to the slice of address space, or NULL on failure.
*/
void* virtmemReserveMap(size_t size);
/**
* @brief Relinquishes a slice of address space reserved with virtmemReserveMap (currently no-op).
* @param addr Pointer to the slice.
* @param size Size of the slice.
*/
void virtmemFreeMap(void* addr, size_t size);

View file

@ -1,51 +0,0 @@
/**
* @file nacp.h
* @brief Control.nacp structure / related code for nacp.
* @copyright libnx Authors
*/
#pragma once
/// Language entry. These strings are UTF-8.
typedef struct {
char name[0x200];
char author[0x100];
} NacpLanguageEntry;
typedef struct {
NacpLanguageEntry lang[16];
u8 x3000_unk[0x24];////Normally all-zero?
u32 x3024_unk;
u32 x3028_unk;
u32 x302C_unk;
u32 x3030_unk;
u32 x3034_unk;
u64 titleID0;
u8 x3040_unk[0x20];
char version[0x10];
u64 titleID_DlcBase;
u64 titleID1;
u32 x3080_unk;
u32 x3084_unk;
u32 x3088_unk;
u8 x308C_unk[0x24];//zeros?
u64 titleID2;
u64 titleIDs[7];//"Array of application titleIDs, normally the same as the above app-titleIDs. Only set for game-updates?"
u32 x30F0_unk;
u32 x30F4_unk;
u64 titleID3;//"Application titleID. Only set for game-updates?"
char bcatPassphrase[0x40];
u8 x3140_unk[0xEC0];//Normally all-zero?
} NacpStruct;
/// Get the NacpLanguageEntry from the input nacp corresponding to the current system language (this may fallback to other languages when needed). Output langentry is NULL if none found / content of entry is empty.
Result nacpGetLanguageEntry(NacpStruct* nacp, NacpLanguageEntry** langentry);

View file

@ -1,54 +0,0 @@
/**
* @file nro.h
* @brief NRO headers.
* @copyright libnx Authors
*/
#pragma once
#define NROHEADER_MAGIC 0x304f524e
#define NROASSETHEADER_MAGIC 0x54455341
#define NROASSETHEADER_VERSION 0
/// Entry for each segment in the codebin.
typedef struct {
u32 file_off;
u32 size;
} NroSegment;
/// Offset 0x0 in the NRO.
typedef struct {
u32 unused;
u32 mod_offset;
u8 padding[8];
} NroStart;
/// This follows NroStart, the actual nro-header.
typedef struct {
u32 magic;
u32 unk1;
u32 size;
u32 unk2;
NroSegment segments[3];
u32 bss_size;
u32 unk3;
u8 build_id[0x20];
u8 padding[0x20];
} NroHeader;
/// Custom asset section.
typedef struct {
u64 offset;
u64 size;
} NroAssetSection;
/// Custom asset header.
typedef struct {
u32 magic;
u32 version;
NroAssetSection icon;
NroAssetSection nacp;
NroAssetSection romfs;
} NroAssetHeader;

View file

@ -1,100 +0,0 @@
/**
* @file result.h
* @brief Switch result code tools.
* @copyright libnx Authors
*/
#pragma once
#include "types.h"
/// Checks whether a result code indicates success.
#define R_SUCCEEDED(res) ((res)==0)
/// Checks whether a result code indicates failure.
#define R_FAILED(res) ((res)!=0)
/// Returns the module ID of a result code.
#define R_MODULE(res) ((res)&0x1FF)
/// Returns the description of a result code.
#define R_DESCRIPTION(res) (((res)>>9)&0x1FFF)
/// Builds a result code from its constituent components.
#define MAKERESULT(module,description) \
((((module)&0x1FF)) | ((description)&0x1FFF)<<9)
/// Module values
enum {
Module_Kernel=1,
Module_Libnx=345,
Module_LibnxNvidia=348,
};
/// Kernel error codes
enum {
KernelError_Timeout=117,
};
/// libnx error codes
enum {
LibnxError_BadReloc=1,
LibnxError_OutOfMemory,
LibnxError_AlreadyMapped,
LibnxError_BadGetInfo_Stack,
LibnxError_BadGetInfo_Heap,
LibnxError_BadQueryMemory,
LibnxError_AlreadyInitialized,
LibnxError_NotInitialized,
LibnxError_NotFound,
LibnxError_IoError,
LibnxError_BadInput,
LibnxError_BadReent,
LibnxError_BufferProducerError,
LibnxError_HandleTooEarly,
LibnxError_HeapAllocFailed,
LibnxError_TooManyOverrides,
LibnxError_ParcelError,
LibnxError_BadGfxInit,
LibnxError_BadGfxEventWait,
LibnxError_BadGfxQueueBuffer,
LibnxError_BadGfxDequeueBuffer,
LibnxError_AppletCmdidNotFound,
LibnxError_BadAppletReceiveMessage,
LibnxError_BadAppletNotifyRunning,
LibnxError_BadAppletGetCurrentFocusState,
LibnxError_BadAppletGetOperationMode,
LibnxError_BadAppletGetPerformanceMode,
LibnxError_BadUsbCommsRead,
LibnxError_BadUsbCommsWrite,
LibnxError_InitFail_SM,
LibnxError_InitFail_AM,
LibnxError_InitFail_HID,
LibnxError_InitFail_FS,
LibnxError_BadGetInfo_Rng,
LibnxError_JitUnavailable,
LibnxError_WeirdKernel,
LibnxError_IncompatSysVer,
LibnxError_InitFail_Time,
LibnxError_TooManyDevOpTabs,
LibnxError_DomainMessageUnknownType,
LibnxError_DomainMessageTooManyObjectIds,
};
/// libnx nvidia error codes
enum {
LibnxNvidiaError_Unknown=1,
LibnxNvidiaError_NotImplemented, ///< Maps to Nvidia: 1
LibnxNvidiaError_NotSupported, ///< Maps to Nvidia: 2
LibnxNvidiaError_NotInitialized, ///< Maps to Nvidia: 3
LibnxNvidiaError_BadParameter, ///< Maps to Nvidia: 4
LibnxNvidiaError_Timeout, ///< Maps to Nvidia: 5
LibnxNvidiaError_InsufficientMemory, ///< Maps to Nvidia: 6
LibnxNvidiaError_ReadOnlyAttribute, ///< Maps to Nvidia: 7
LibnxNvidiaError_InvalidState, ///< Maps to Nvidia: 8
LibnxNvidiaError_InvalidAddress, ///< Maps to Nvidia: 9
LibnxNvidiaError_InvalidSize, ///< Maps to Nvidia: 10
LibnxNvidiaError_BadValue, ///< Maps to Nvidia: 11
LibnxNvidiaError_AlreadyAllocated, ///< Maps to Nvidia: 13
LibnxNvidiaError_Busy, ///< Maps to Nvidia: 14
LibnxNvidiaError_ResourceError, ///< Maps to Nvidia: 15
LibnxNvidiaError_CountMismatch, ///< Maps to Nvidia: 16
LibnxNvidiaError_SharedMemoryTooSmall, ///< Maps to Nvidia: 0x1000
LibnxNvidiaError_FileOperationFailed, ///< Maps to Nvidia: 0x30003
LibnxNvidiaError_IoctlFailed, ///< Maps to Nvidia: 0x3000F
};

View file

@ -1,167 +0,0 @@
/**
* @file console.h
* @brief Framebuffer text console.
* @author yellows8
* @author WinterMute
* @copyright libnx Authors
*
* Provides stdio integration for printing to the Switch screen as well as debug print
* functionality provided by stderr.
*
* General usage is to initialize the console by:
* @code
* consoleDemoInit()
* @endcode
* or to customize the console usage by:
* @code
* consoleInit()
* @endcode
*/
#pragma once
#include "../../types.h"
#define CONSOLE_ESC(x) "\x1b[" #x
#define CONSOLE_RESET CONSOLE_ESC(0m)
#define CONSOLE_BLACK CONSOLE_ESC(30m)
#define CONSOLE_RED CONSOLE_ESC(31;1m)
#define CONSOLE_GREEN CONSOLE_ESC(32;1m)
#define CONSOLE_YELLOW CONSOLE_ESC(33;1m)
#define CONSOLE_BLUE CONSOLE_ESC(34;1m)
#define CONSOLE_MAGENTA CONSOLE_ESC(35;1m)
#define CONSOLE_CYAN CONSOLE_ESC(36;1m)
#define CONSOLE_WHITE CONSOLE_ESC(37;1m)
/// A callback for printing a character.
typedef bool(*ConsolePrint)(void* con, int c);
/// A font struct for the console.
typedef struct ConsoleFont
{
u16* gfx; ///< A pointer to the font graphics
u16 asciiOffset; ///< Offset to the first valid character in the font table
u16 numChars; ///< Number of characters in the font graphics
}ConsoleFont;
/**
* @brief Console structure used to store the state of a console render context.
*
* Default values from consoleGetDefault();
* @code
* PrintConsole defaultConsole =
* {
* //Font:
* {
* (u16*)default_font_bin, //font gfx
* 0, //first ascii character in the set
* 128, //number of characters in the font set
* },
* 0,0, //cursorX cursorY
* 0,0, //prevcursorX prevcursorY
* 80, //console width
* 45, //console height
* 0, //window x
* 0, //window y
* 80, //window width
* 45, //window height
* 3, //tab size
* 0, //font character offset
* 0, //print callback
* false //console initialized
* };
* @endcode
*/
typedef struct PrintConsole
{
ConsoleFont font; ///< Font of the console
u32 *frameBuffer; ///< Framebuffer address
u32 *frameBuffer2; ///< Framebuffer address
int cursorX; ///< Current X location of the cursor (as a tile offset by default)
int cursorY; ///< Current Y location of the cursor (as a tile offset by default)
int prevCursorX; ///< Internal state
int prevCursorY; ///< Internal state
int consoleWidth; ///< Width of the console hardware layer in characters
int consoleHeight; ///< Height of the console hardware layer in characters
int windowX; ///< Window X location in characters (not implemented)
int windowY; ///< Window Y location in characters (not implemented)
int windowWidth; ///< Window width in characters (not implemented)
int windowHeight; ///< Window height in characters (not implemented)
int tabSize; ///< Size of a tab
int fg; ///< Foreground color
int bg; ///< Background color
int flags; ///< Reverse/bright flags
ConsolePrint PrintChar; ///< Callback for printing a character. Should return true if it has handled rendering the graphics (else the print engine will attempt to render via tiles).
bool consoleInitialised; ///< True if the console is initialized
}PrintConsole;
#define CONSOLE_COLOR_BOLD (1<<0) ///< Bold text
#define CONSOLE_COLOR_FAINT (1<<1) ///< Faint text
#define CONSOLE_ITALIC (1<<2) ///< Italic text
#define CONSOLE_UNDERLINE (1<<3) ///< Underlined text
#define CONSOLE_BLINK_SLOW (1<<4) ///< Slow blinking text
#define CONSOLE_BLINK_FAST (1<<5) ///< Fast blinking text
#define CONSOLE_COLOR_REVERSE (1<<6) ///< Reversed color text
#define CONSOLE_CONCEAL (1<<7) ///< Concealed text
#define CONSOLE_CROSSED_OUT (1<<8) ///< Crossed out text
/// Console debug devices supported by libnx.
typedef enum {
debugDevice_NULL, ///< Swallows prints to stderr
debugDevice_SVC, ///< Outputs stderr debug statements using svcOutputDebugString, which can then be captured by interactive debuggers
debugDevice_CONSOLE, ///< Directs stderr debug statements to Switch console window
debugDevice_3DMOO = debugDevice_SVC,
} debugDevice;
/**
* @brief Loads the font into the console.
* @param console Pointer to the console to update, if NULL it will update the current console.
* @param font The font to load.
*/
void consoleSetFont(PrintConsole* console, ConsoleFont* font);
/**
* @brief Sets the print window.
* @param console Console to set, if NULL it will set the current console window.
* @param x X location of the window.
* @param y Y location of the window.
* @param width Width of the window.
* @param height Height of the window.
*/
void consoleSetWindow(PrintConsole* console, int x, int y, int width, int height);
/**
* @brief Gets a pointer to the console with the default values.
* This should only be used when using a single console or without changing the console that is returned, otherwise use consoleInit().
* @return A pointer to the console with the default values.
*/
PrintConsole* consoleGetDefault(void);
/**
* @brief Make the specified console the render target.
* @param console A pointer to the console struct (must have been initialized with consoleInit(PrintConsole* console)).
* @return A pointer to the previous console.
*/
PrintConsole *consoleSelect(PrintConsole* console);
/**
* @brief Initialise the console.
* @param console A pointer to the console data to initialize (if it's NULL, the default console will be used).
* @return A pointer to the current console.
*/
PrintConsole* consoleInit(PrintConsole* console);
/**
* @brief Initializes debug console output on stderr to the specified device.
* @param device The debug device (or devices) to output debug print statements to.
*/
void consoleDebugInit(debugDevice device);
/// Clears the screan by using iprintf("\x1b[2J");
void consoleClear(void);

View file

@ -1,43 +0,0 @@
/**
* @file fs_dev.h
* @brief FS driver, using devoptab.
* @author yellows8
* @author mtheall
* @copyright libnx Authors
*/
#pragma once
#include <sys/types.h>
#include "../../services/fs.h"
#define FSDEV_DIRITER_MAGIC 0x66736476 ///< "fsdv"
/// Open directory struct
typedef struct
{
u32 magic; ///< "fsdv"
FsDir fd; ///< File descriptor
ssize_t index; ///< Current entry index
size_t size; ///< Current batch size
FsDirectoryEntry entry_data[32]; ///< Temporary storage for reading entries
} fsdev_dir_t;
/// Initializes and mounts the sdmc device if accessible. Also initializes current working directory to point to the folder containing the path to the executable (argv[0]), if it is provided by the environment.
Result fsdevMountSdmc(void);
/// Mounts the input fs with the specified device name. fsdev will handle closing the fs when required, including when fsdevMountDevice() fails.
/// Returns -1 when any errors occur.
int fsdevMountDevice(const char *name, FsFileSystem fs);
/// Unmounts the specified device.
int fsdevUnmountDevice(const char *name);
/// Uses fsFsCommit() with the specified device. This must be used after any savedata-write operations(not just file-write). This should be used after each file-close where file-writing was done.
/// This is not used automatically at device unmount.
Result fsdevCommitDevice(const char *name);
/// Returns the FsFileSystem for the default device (SD card), if mounted. Used internally by romfs_dev.
FsFileSystem* fsdevGetDefaultFileSystem(void);
/// Unmounts all devices and cleans up any resources used by the FS driver.
Result fsdevUnmountAll(void);

View file

@ -1,98 +0,0 @@
/**
* @file romfs_dev.h
* @brief RomFS driver.
* @author yellows8
* @author mtheall
* @author fincs
* @copyright libnx Authors
*/
#pragma once
#include "../../types.h"
#include "../../services/fs.h"
/// RomFS header.
typedef struct
{
u64 headerSize; ///< Size of the header.
u64 dirHashTableOff; ///< Offset of the directory hash table.
u64 dirHashTableSize; ///< Size of the directory hash table.
u64 dirTableOff; ///< Offset of the directory table.
u64 dirTableSize; ///< Size of the directory table.
u64 fileHashTableOff; ///< Offset of the file hash table.
u64 fileHashTableSize; ///< Size of the file hash table.
u64 fileTableOff; ///< Offset of the file table.
u64 fileTableSize; ///< Size of the file table.
u64 fileDataOff; ///< Offset of the file data.
} romfs_header;
/// RomFS directory.
typedef struct
{
u32 parent; ///< Offset of the parent directory.
u32 sibling; ///< Offset of the next sibling directory.
u32 childDir; ///< Offset of the first child directory.
u32 childFile; ///< Offset of the first file.
u32 nextHash; ///< Directory hash table pointer.
u32 nameLen; ///< Name length.
uint8_t name[]; ///< Name. (UTF-8)
} romfs_dir;
/// RomFS file.
typedef struct
{
u32 parent; ///< Offset of the parent directory.
u32 sibling; ///< Offset of the next sibling file.
u64 dataOff; ///< Offset of the file's data.
u64 dataSize; ///< Length of the file's data.
u32 nextHash; ///< File hash table pointer.
u32 nameLen; ///< Name length.
uint8_t name[]; ///< Name. (UTF-8)
} romfs_file;
struct romfs_mount;
/**
* @brief Mounts the Application's RomFS.
* @param mount Output mount handle
*/
Result romfsMount(struct romfs_mount **mount);
static inline Result romfsInit(void)
{
return romfsMount(NULL);
}
/**
* @brief Mounts RomFS from an open file.
* @param file FsFile of the RomFS image.
* @param offset Offset of the RomFS within the file.
* @param mount Output mount handle
*/
Result romfsMountFromFile(FsFile file, u64 offset, struct romfs_mount **mount);
static inline Result romfsInitFromFile(FsFile file, u64 offset)
{
return romfsMountFromFile(file, offset, NULL);
}
/**
* @brief Mounts RomFS from an open storage.
* @param storage FsStorage of the RomFS image.
* @param offset Offset of the RomFS within the storage.
* @param mount Output mount handle
*/
Result romfsMountFromStorage(FsStorage storage, u64 offset, struct romfs_mount **mount);
static inline Result romfsInitFromStorage(FsStorage storage, u64 offset)
{
return romfsMountFromStorage(storage, offset, NULL);
}
/// Bind the RomFS mount
Result romfsBind(struct romfs_mount *mount);
/// Unmounts the RomFS device.
Result romfsUnmount(struct romfs_mount *mount);
static inline Result romfsExit(void)
{
return romfsUnmount(NULL);
}

View file

@ -1,39 +0,0 @@
#pragma once
#include "../../types.h"
/// Configuration structure for socketInitalize
typedef struct {
u32 bsdsockets_version; ///< Observed 1 on 2.0 LibAppletWeb, 2 on 3.0.
u32 tcp_tx_buf_size; ///< Size of the TCP transfer (send) buffer (initial or fixed).
u32 tcp_rx_buf_size; ///< Size of the TCP recieve buffer (initial or fixed).
u32 tcp_tx_buf_max_size; ///< Maximum size of the TCP transfer (send) buffer. If it is 0, the size of the buffer is fixed to its initial value.
u32 tcp_rx_buf_max_size; ///< Maximum size of the TCP receive buffer. If it is 0, the size of the buffer is fixed to its initial value.
u32 udp_tx_buf_size; ///< Size of the UDP transfer (send) buffer (typically 0x2400 bytes).
u32 udp_rx_buf_size; ///< Size of the UDP receive buffer (typically 0xA500 bytes).
u32 sb_efficiency; ///< Number of buffers for each socket (standard values range from 1 to 8).
size_t serialized_out_addrinfos_max_size; ///< For getaddrinfo.
size_t serialized_out_hostent_max_size; ///< For gethostbyname/gethostbyaddr.
bool bypass_nsd; ///< For name gethostbyname/getaddrinfo: bypass the Name Server Daemon.
int dns_timeout; ///< For DNS requests: timeout or 0.
} SocketInitConfig;
/// Fetch the default configuration for the socket driver.
const SocketInitConfig *socketGetDefaultInitConfig(void);
/// Initalize the socket driver.
Result socketInitialize(const SocketInitConfig *config);
/// Fetch the last bsd:u/s Switch result code (thread-local).
Result socketGetLastBsdResult(void);
/// Fetch the last sfdnsres Switch result code (thread-local).
Result socketGetLastSfdnsresResult(void);
/// Deinitialize the socket driver.
void socketExit(void);
/// Initalize the socket driver using the default configuration.
static inline Result socketInitializeDefault(void) {
return socketInitialize(socketGetDefaultInitConfig());
}

View file

@ -1,31 +0,0 @@
/**
* @file usb_comms.h
* @brief USB comms.
* @author yellows8
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../../types.h"
Result usbCommsInitialize(void);
void usbCommsExit(void);
/// Same as usbCommsInitialize, except this can be used after usbCommsInitialize (or instead of usbCommsInitialize), for creating new interface(s).
/// bInterface* are the values for the same fields in usb.h \ref usb_interface_descriptor. \ref usbCommsInitialize uses USB_CLASS_VENDOR_SPEC for all of these internally.
Result usbCommsInitializeEx(u32 *interface, u8 bInterfaceClass, u8 bInterfaceSubClass, u8 bInterfaceProtocol);
/// Shutdown the specified interface. If no interfaces are remaining, this then uses \ref usbCommsExit internally.
void usbCommsExitEx(u32 interface);
/// Read data with the default interface.
size_t usbCommsRead(void* buffer, size_t size);
/// Write data with the default interface.
size_t usbCommsWrite(const void* buffer, size_t size);
/// Same as usbCommsRead except with the specified interface.
size_t usbCommsReadEx(void* buffer, size_t size, u32 interface);
/// Same as usbCommsWrite except with the specified interface.
size_t usbCommsWriteEx(const void* buffer, size_t size, u32 interface);

View file

@ -1,90 +0,0 @@
/**
* @file env.h
* @brief Homebrew environment definitions and utilities.
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/// Structure representing an entry in the homebrew environment configuration.
typedef struct {
u32 Key; ///< Type of entry
u32 Flags; ///< Entry flags
u64 Value[2]; ///< Entry arguments (type-specific)
} ConfigEntry;
/// Entry flags
enum {
EntryFlag_IsMandatory = BIT(0), ///< Specifies that the entry **must** be processed by the homebrew application.
};
///< Types of entry
enum {
EntryType_EndOfList=0, ///< Entry list terminator.
EntryType_MainThreadHandle=1, ///< Provides the handle to the main thread.
EntryType_NextLoadPath=2, ///< Provides a buffer containing information about the next homebrew application to load.
EntryType_OverrideHeap=3, ///< Provides heap override information.
EntryType_OverrideService=4, ///< Provides service override information.
EntryType_Argv=5, ///< Provides argv.
EntryType_SyscallAvailableHint=6, ///< Provides syscall availability hints.
EntryType_AppletType=7, ///< Provides APT applet type.
EntryType_AppletWorkaround=8, ///< Indicates that APT is broken and should not be used.
EntryType_StdioSockets=9, ///< Provides socket-based standard stream redirection information.
EntryType_ProcessHandle=10, ///< Provides the process handle.
EntryType_LastLoadResult=11 ///< Provides the last load result.
};
/// Loader return function.
typedef void NORETURN (*LoaderReturnFn)(int result_code);
/**
* @brief Parses the homebrew loader environment block (internally called).
* @param ctx Reserved.
* @param main_thread Reserved.
* @param saved_lr Reserved.
*/
void envSetup(void* ctx, Handle main_thread, LoaderReturnFn saved_lr);
/// Retrieves the handle to the main thread.
Handle envGetMainThreadHandle(void);
/// Returns true if the application is running as NSO, otherwise NRO.
bool envIsNso(void);
/// Returns true if the environment has a heap override.
bool envHasHeapOverride(void);
/// Returns the address of the overriden heap.
void* envGetHeapOverrideAddr(void);
/// Returns the size of the overriden heap.
u64 envGetHeapOverrideSize(void);
/// Returns true if the environment has an argv array.
bool envHasArgv(void);
/// Returns the pointer to the argv array.
void* envGetArgv(void);
/**
* @brief Returns whether a syscall is hinted to be available.
* @param svc Syscall number to test.
* @returns true if the syscall is available.
*/
bool envIsSyscallHinted(u8 svc);
/// Returns the handle to the running homebrew process.
Handle envGetOwnProcessHandle(void);
/// Returns the loader's return function, to be called on program exit.
LoaderReturnFn envGetExitFuncPtr(void);
/**
* @brief Configures the next homebrew application to load.
* @param path Path to the next homebrew application to load (.nro).
* @param argv Argument string to pass.
*/
Result envSetNextLoad(const char* path, const char* argv);
/// Returns true if the environment supports envSetNextLoad.
bool envHasNextLoad(void);
/// Returns the Result from the last NRO.
Result envGetLastLoadResult(void);

View file

@ -1,10 +0,0 @@
#pragma once
struct in_addr;
extern struct in_addr __nxlink_host;
#define NXLINK_SERVER_PORT 28280
#define NXLINK_CLIENT_PORT 28771
int nxlinkStdio(void);

View file

@ -1,157 +0,0 @@
/**
* @file utf.h
* @brief UTF conversion functions.
* @author mtheall
* @copyright libnx Authors
*/
#pragma once
#include <sys/types.h>
#include "../../types.h"
/** Convert a UTF-8 sequence into a UTF-32 codepoint
*
* @param[out] out Output codepoint
* @param[in] in Input sequence
*
* @returns number of input code units consumed
* @returns -1 for error
*/
ssize_t decode_utf8 (uint32_t *out, const uint8_t *in);
/** Convert a UTF-16 sequence into a UTF-32 codepoint
*
* @param[out] out Output codepoint
* @param[in] in Input sequence
*
* @returns number of input code units consumed
* @returns -1 for error
*/
ssize_t decode_utf16(uint32_t *out, const uint16_t *in);
/** Convert a UTF-32 codepoint into a UTF-8 sequence
*
* @param[out] out Output sequence
* @param[in] in Input codepoint
*
* @returns number of output code units produced
* @returns -1 for error
*
* @note \a out must be able to store 4 code units
*/
ssize_t encode_utf8 (uint8_t *out, uint32_t in);
/** Convert a UTF-32 codepoint into a UTF-16 sequence
*
* @param[out] out Output sequence
* @param[in] in Input codepoint
*
* @returns number of output code units produced
* @returns -1 for error
*
* @note \a out must be able to store 2 code units
*/
ssize_t encode_utf16(uint16_t *out, uint32_t in);
/** Convert a UTF-8 sequence into a UTF-16 sequence
*
* Fills the output buffer up to \a len code units.
* Returns the number of code units that the input would produce;
* if it returns greater than \a len, the output has been
* truncated.
*
* @param[out] out Output sequence
* @param[in] in Input sequence (null-terminated)
* @param[in] len Output length
*
* @returns number of output code units produced
* @returns -1 for error
*
* @note \a out is not null-terminated
*/
ssize_t utf8_to_utf16(uint16_t *out, const uint8_t *in, size_t len);
/** Convert a UTF-8 sequence into a UTF-32 sequence
*
* Fills the output buffer up to \a len code units.
* Returns the number of code units that the input would produce;
* if it returns greater than \a len, the output has been
* truncated.
*
* @param[out] out Output sequence
* @param[in] in Input sequence (null-terminated)
* @param[in] len Output length
*
* @returns number of output code units produced
* @returns -1 for error
*
* @note \a out is not null-terminated
*/
ssize_t utf8_to_utf32(uint32_t *out, const uint8_t *in, size_t len);
/** Convert a UTF-16 sequence into a UTF-8 sequence
*
* Fills the output buffer up to \a len code units.
* Returns the number of code units that the input would produce;
* if it returns greater than \a len, the output has been
* truncated.
*
* @param[out] out Output sequence
* @param[in] in Input sequence (null-terminated)
* @param[in] len Output length
*
* @returns number of output code units produced
* @returns -1 for error
*
* @note \a out is not null-terminated
*/
ssize_t utf16_to_utf8(uint8_t *out, const uint16_t *in, size_t len);
/** Convert a UTF-16 sequence into a UTF-32 sequence
*
* Fills the output buffer up to \a len code units.
* Returns the number of code units that the input would produce;
* if it returns greater than \a len, the output has been
* truncated.
*
* @param[out] out Output sequence
* @param[in] in Input sequence (null-terminated)
* @param[in] len Output length
*
* @returns number of output code units produced
* @returns -1 for error
*
* @note \a out is not null-terminated
*/
ssize_t utf16_to_utf32(uint32_t *out, const uint16_t *in, size_t len);
/** Convert a UTF-32 sequence into a UTF-8 sequence
*
* Fills the output buffer up to \a len code units.
* Returns the number of code units that the input would produce;
* if it returns greater than \a len, the output has been
* truncated.
*
* @param[out] out Output sequence
* @param[in] in Input sequence (null-terminated)
* @param[in] len Output length
*
* @returns number of output code units produced
* @returns -1 for error
*
* @note \a out is not null-terminated
*/
ssize_t utf32_to_utf8(uint8_t *out, const uint32_t *in, size_t len);
/** Convert a UTF-32 sequence into a UTF-16 sequence
*
* @param[out] out Output sequence
* @param[in] in Input sequence (null-terminated)
* @param[in] len Output length
*
* @returns number of output code units produced
* @returns -1 for error
*
* @note \a out is not null-terminated
*/
ssize_t utf32_to_utf16(uint16_t *out, const uint32_t *in, size_t len);

View file

@ -1,52 +0,0 @@
/**
* @file acc.h
* @brief Account (acc:*) service IPC wrapper.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "sm.h"
typedef struct {
Service s;
} AccountProfile;
typedef struct
{
u32 unk_x0;
u32 iconID; ///< Icon ID. 0 = Mii, the rest are character icon IDs.
u8 iconBackgroundColorID; ///< Profile icon background color ID
u8 unk_x9[0x7];
u8 miiID[0x10]; ///< Some ID related to the Mii? All zeros when a character icon is used.
u8 unk_x20[0x60]; ///< Usually zeros?
} PACKED AccountUserData;
typedef struct
{
u128 userID;
u64 lastEditTimestamp; ///< POSIX UTC timestamp, for the last account edit.
char username[0x20]; ///< UTF-8 Username.
} PACKED AccountProfileBase;
Result accountInitialize(void);
void accountExit(void);
Service* accountGetService(void);
/// Get the userID for the currently active user. The output userID is only valid when the output account_selected==1, otherwise no user is currently selected.
/// An user is only selected when the user-account selection applet was used to select an user at least once before.
Result accountGetActiveUser(u128 *userID, bool *account_selected);
/// Get an AccountProfile for the specified userID.
Result accountGetProfile(AccountProfile* out, u128 userID);
/// Get \ref AccountUserData and \ref AccountProfileBase for the specified profile, userdata is optional (can be NULL).
Result accountProfileGet(AccountProfile* profile, AccountUserData* userdata, AccountProfileBase* profilebase);
/// Get the icon image size.
Result accountProfileGetImageSize(AccountProfile* profile, size_t* image_size);
/// Load the JPEG profile icon, valid for both Miis and character icons. The output image_size is the same as the one from \ref accountProfileGetImageSize.
Result accountProfileLoadImage(AccountProfile* profile, void* buf, size_t len, size_t* image_size);
void accountProfileClose(AccountProfile* profile);

View file

@ -1,16 +0,0 @@
/**
* @file apm.h
* @brief Performance management (apm) service IPC wrapper.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/// These are used internally by applet.
Result apmInitialize(void);
void apmExit(void);
Result apmSetPerformanceConfiguration(u32 PerformanceMode, u32 PerformanceConfiguration);
Result apmGetPerformanceConfiguration(u32 PerformanceMode, u32 *PerformanceConfiguration);

View file

@ -1,88 +0,0 @@
/**
* @file applet.h
* @brief Applet (applet) service IPC wrapper.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
typedef enum {
AppletType_None = -2,
AppletType_Default = -1,
AppletType_Application = 0,
AppletType_SystemApplet = 1,
AppletType_LibraryApplet = 2,
AppletType_OverlayApplet = 3,
AppletType_SystemApplication = 4,
} AppletType;
typedef enum {
AppletOperationMode_Handheld = 0,
AppletOperationMode_Docked = 1,
} AppletOperationMode;
/// applet hook types.
typedef enum {
AppletHookType_OnFocusState = 0, ///< FocusState changed.
AppletHookType_OnOperationMode, ///< OperationMode changed.
AppletHookType_OnPerformanceMode, ///< PerformanceMode changed.
AppletHookType_Max, ///< Number of applet hook types.
} AppletHookType;
/// applet hook function.
typedef void (*AppletHookFn)(AppletHookType hook, void* param);
/// applet hook cookie.
typedef struct AppletHookCookie AppletHookCookie;
struct AppletHookCookie
{
AppletHookCookie* next; ///< Next cookie.
AppletHookFn callback; ///< Hook callback.
void* param; ///< Callback parameter.
};
Result appletInitialize(void);
void appletExit(void);
Result appletGetAppletResourceUserId(u64 *out);
void appletNotifyRunning(u8 *out);
Result appletCreateManagedDisplayLayer(u64 *out);
Result appletGetDesiredLanguage(u64 *LanguageCode);
/**
* @brief Controls whether screenshot-capture is allowed.
* @param val 0 = disable, 1 = enable.
*/
Result appletSetScreenShotPermission(s32 val);
Result appletSetScreenShotImageOrientation(s32 val);
/**
* @brief Processes the current applet status. Generally used within a main loop.
* @return Whether the application should continue running.
*/
bool appletMainLoop(void);
/**
* @brief Sets up an applet status hook.
* @param cookie Hook cookie to use.
* @param callback Function to call when applet's status changes.
* @param param User-defined parameter to pass to the callback.
*/
void appletHook(AppletHookCookie* cookie, AppletHookFn callback, void* param);
/**
* @brief Removes an applet status hook.
* @param cookie Hook cookie to remove.
*/
void appletUnhook(AppletHookCookie* cookie);
/// These return state which is updated by appletMainLoop() when notifications are received.
u8 appletGetOperationMode(void);
u32 appletGetPerformanceMode(void);
u8 appletGetFocusState(void);

View file

@ -1,60 +0,0 @@
/**
* @file audin.h
* @brief Audio input service.
* @author hexkyz
* @copyright libnx Authors
*/
#pragma once
#include "../audio/audio.h"
typedef enum {
AudioInState_Started = 0,
AudioInState_Stopped = 1,
} AudioInState;
/// Audio input buffer format
typedef struct AudioInBuffer AudioInBuffer;
struct AudioInBuffer
{
AudioInBuffer* next; ///< Next buffer. (Unused)
void* buffer; ///< Sample buffer (aligned to 0x1000 bytes).
u64 buffer_size; ///< Sample buffer size (aligned to 0x1000 bytes).
u64 data_size; ///< Size of data inside the buffer.
u64 data_offset; ///< Offset of data inside the buffer. (Unused?)
};
Result audinInitialize(void);
void audinExit(void);
Result audinListAudioIns(char *DeviceNames, u32 *DeviceNamesCount);
Result audinOpenAudioIn(const char *DeviceNameIn, char *DeviceNameOut, u32 SampleRateIn, u32 ChannelCountIn, u32 *SampleRateOut, u32 *ChannelCountOut, PcmFormat *Format, AudioInState *State);
Result audinGetAudioInState(AudioInState *State);
Result audinStartAudioIn(void);
Result audinStopAudioIn(void);
Result audinAppendAudioInBuffer(AudioInBuffer *Buffer);
Result audinGetReleasedAudioInBuffer(AudioInBuffer **Buffer, u32 *ReleasedBuffersCount);
Result audinContainsAudioInBuffer(AudioInBuffer *Buffer, bool *ContainsBuffer);
/**
* @brief Submits an audio sample data buffer for capturing and waits for it to finish capturing.
* @brief Uses \ref audinAppendAudioInBuffer and \ref audinWaitCaptureFinish internally.
* @param source AudioInBuffer containing the buffer to hold the captured sample data.
* @param released AudioInBuffer to receive the captured buffer after being released.
*/
Result audinCaptureBuffer(AudioInBuffer *source, AudioInBuffer **released);
/**
* @brief Waits for audio capture to finish.
* @param released AudioInBuffer to receive the first captured buffer after being released.
* @param released_count Pointer to receive the number of captured buffers.
* @param timeout Timeout value, use U64_MAX to wait until all finished.
*/
Result audinWaitCaptureFinish(AudioInBuffer **released, u32* released_count, u64 timeout);
/// These return the state associated with the currently active audio input device.
u32 audinGetSampleRate(void); ///< Supported sample rate (48000Hz).
u32 audinGetChannelCount(void); ///< Supported channel count (2 channels).
PcmFormat audinGetPcmFormat(void); ///< Supported PCM format (Int16).
AudioInState audinGetDeviceState(void); ///< Initial device state (stopped).

View file

@ -1,60 +0,0 @@
/**
* @file audout.h
* @brief Audio output service.
* @author hexkyz
* @copyright libnx Authors
*/
#pragma once
#include "../audio/audio.h"
typedef enum {
AudioOutState_Started = 0,
AudioOutState_Stopped = 1,
} AudioOutState;
/// Audio output buffer format
typedef struct AudioOutBuffer AudioOutBuffer;
struct AudioOutBuffer
{
AudioOutBuffer* next; ///< Next buffer. (Unused)
void* buffer; ///< Sample buffer (aligned to 0x1000 bytes).
u64 buffer_size; ///< Sample buffer size (aligned to 0x1000 bytes).
u64 data_size; ///< Size of data inside the buffer.
u64 data_offset; ///< Offset of data inside the buffer. (Unused?)
};
Result audoutInitialize(void);
void audoutExit(void);
Result audoutListAudioOuts(char *DeviceNames, u32 *DeviceNamesCount);
Result audoutOpenAudioOut(const char *DeviceNameIn, char *DeviceNameOut, u32 SampleRateIn, u32 ChannelCountIn, u32 *SampleRateOut, u32 *ChannelCountOut, PcmFormat *Format, AudioOutState *State);
Result audoutGetAudioOutState(AudioOutState *State);
Result audoutStartAudioOut(void);
Result audoutStopAudioOut(void);
Result audoutAppendAudioOutBuffer(AudioOutBuffer *Buffer);
Result audoutGetReleasedAudioOutBuffer(AudioOutBuffer **Buffer, u32 *ReleasedBuffersCount);
Result audoutContainsAudioOutBuffer(AudioOutBuffer *Buffer, bool *ContainsBuffer);
/**
* @brief Submits an audio sample data buffer for playing and waits for it to finish playing.
* @brief Uses \ref audoutAppendAudioOutBuffer and \ref audoutWaitPlayFinish internally.
* @param source AudioOutBuffer containing the source sample data to be played.
* @param released AudioOutBuffer to receive the played buffer after being released.
*/
Result audoutPlayBuffer(AudioOutBuffer *source, AudioOutBuffer **released);
/**
* @brief Waits for audio playback to finish.
* @param released AudioOutBuffer to receive the first played buffer after being released.
* @param released_count Pointer to receive the number of played buffers.
* @param timeout Timeout value, use U64_MAX to wait until all finished.
*/
Result audoutWaitPlayFinish(AudioOutBuffer **released, u32* released_count, u64 timeout);
/// These return the state associated with the currently active audio output device.
u32 audoutGetSampleRate(void); ///< Supported sample rate (48000Hz).
u32 audoutGetChannelCount(void); ///< Supported channel count (2 channels).
PcmFormat audoutGetPcmFormat(void); ///< Supported PCM format (Int16).
AudioOutState audoutGetDeviceState(void); ///< Initial device state (stopped).

View file

@ -1,77 +0,0 @@
/**
* @file bsd.h
* @brief BSD sockets (bsd:u/s) service IPC wrapper. Please use socket.c instead.
* @author plutoo
* @author TuxSH
* @copyright libnx Authors
*/
#pragma once
#include <sys/socket.h> // for socklen_t
#include <sys/select.h> // for fd_set
#include <poll.h> // for struct pollfd, ndfs_t
#include "../types.h"
#include "../kernel/tmem.h"
/// Configuration structure for bsdInitalize
typedef struct {
u32 version; ///< Observed 1 on 2.0 LibAppletWeb, 2 on 3.0.
u32 tcp_tx_buf_size; ///< Size of the TCP transfer (send) buffer (initial or fixed).
u32 tcp_rx_buf_size; ///< Size of the TCP recieve buffer (initial or fixed).
u32 tcp_tx_buf_max_size; ///< Maximum size of the TCP transfer (send) buffer. If it is 0, the size of the buffer is fixed to its initial value.
u32 tcp_rx_buf_max_size; ///< Maximum size of the TCP receive buffer. If it is 0, the size of the buffer is fixed to its initial value.
u32 udp_tx_buf_size; ///< Size of the UDP transfer (send) buffer (typically 0x2400 bytes).
u32 udp_rx_buf_size; ///< Size of the UDP receive buffer (typically 0xA500 bytes).
u32 sb_efficiency; ///< Number of buffers for each socket (standard values range from 1 to 8).
} BsdInitConfig;
extern __thread Result g_bsdResult; ///< Last Switch "result", per-thread
extern __thread int g_bsdErrno; ///< Last errno, per-thread
/// Fetch the default configuration for bsdInitialize.
const BsdInitConfig *bsdGetDefaultInitConfig(void);
/// Initialize the BSD service.
Result bsdInitialize(const BsdInitConfig *config);
/// Deinitialize the BSD service.
void bsdExit(void);
int bsdSocket(int domain, int type, int protocol);
/// Like @ref bsdSocket but the newly created socket is immediately shut down.
int bsdSocketExempt(int domain, int type, int protocol);
int bsdOpen(const char *pathname, int flags);
int bsdSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
int bsdPoll(struct pollfd *fds, nfds_t nfds, int timeout);
int bsdSysctl(const int *name, unsigned int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen);
ssize_t bsdRecv(int sockfd, void *buf, size_t len, int flags);
ssize_t bsdRecvFrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);
ssize_t bsdSend(int sockfd, const void* buf, size_t len, int flags);
ssize_t bsdSendTo(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
int bsdAccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int bsdBind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int bsdConnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int bsdGetPeerName(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int bsdGetSockName(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int bsdGetSockOpt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
int bsdListen(int sockfd, int backlog);
/// Made non-variadic for convenience.
int bsdIoctl(int fd, int request, void *data);
/// Made non-variadic for convenience.
int bsdFcntl(int fd, int cmd, int flags);
int bsdSetSockOpt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
int bsdShutdown(int sockfd, int how);
int bsdShutdownAllSockets(int how);
ssize_t bsdWrite(int fd, const void *buf, size_t count);
ssize_t bsdRead(int fd, void *buf, size_t count);
int bsdClose(int fd);
/// Duplicate a socket (bsd:s).
int bsdDuplicateSocket(int sockfd);
// TODO: Reverse-engineer GetResourceStatistics. Implement sendmmsg/recvmmsg (custom (un)serialization)
/// Initialize the BSD service using the default configuration.
static inline Result bsdInitializeDefault(void) {
return bsdInitialize(bsdGetDefaultInitConfig());
}

View file

@ -1,13 +0,0 @@
/**
* @file csrng.h
* @brief Cryptographically-Secure Random Number Generation (csrng) service IPC wrapper.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
Result csrngInitialize(void);
void csrngExit(void);
Result csrngGetRandomBytes(void *out, size_t out_size);

View file

@ -1,29 +0,0 @@
/**
* @file fatal.h
* @brief Fatal error (fatal:u) service IPC wrapper.
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
typedef enum {
FatalType_ErrorReportAndErrorScreen = 0,
FatalType_ErrorReport = 1,
FatalType_ErrorScreen = 2
} FatalType;
/**
* @brief Triggers a system fatal error.
* @param err[in] Result code to throw.
* @note This function does not return.
*/
void NORETURN fatalSimple(Result err);
/**
* @brief Triggers a system fatal error with a custom FatalType.
* @param err[in] Result code to throw.
* @param err[in] Type of fatal error to throw.
* @note This function does not return.
*/
void NORETURN fatalWithType(Result err, FatalType type);

View file

@ -1,213 +0,0 @@
/**
* @file fs.h
* @brief Filesystem (fsp-srv) service IPC wrapper.
* Normally applications should just use standard stdio not FS-serv directly. However this can be used if obtaining a FsFileSystem, FsFile, or FsStorage, for mounting with fs_dev/romfs_dev, etc.
* @author plutoo
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../services/sm.h"
// We use wrapped handles for type safety.
#define FS_MAX_PATH 0x301
/// For use with FsSave.
#define FS_SAVEDATA_CURRENT_TITLEID 0
/// For use with \ref FsSave and \ref FsSaveDataInfo.
#define FS_SAVEDATA_USERID_COMMONSAVE 0
typedef struct {
Service s;
} FsFileSystem;
typedef struct {
Service s;
} FsFile;
typedef struct {
Service s;
} FsDir;
typedef struct {
Service s;
} FsStorage;
typedef struct {
Service s;
} FsSaveDataIterator;
typedef struct {
Service s;
} FsEventNotifier;
typedef struct {
Service s;
} FsDeviceOperator;
/// Directory entry.
typedef struct
{
char name[FS_MAX_PATH]; ///< Entry name.
u8 pad[3];
s8 type; ///< See FsEntryType.
u8 pad2[3]; ///< ?
u64 fileSize; ///< File size.
} FsDirectoryEntry;
/// Save Struct
typedef struct
{
u64 titleID; ///< titleID of the savedata to access when accessing other titles' savedata via SaveData, otherwise FS_SAVEDATA_CURRENT_TITLEID.
u128 userID; ///< userID of the user-specific savedata to access, otherwise FS_SAVEDATA_USERID_COMMONSAVE. See account.h.
u64 saveID; ///< saveID, 0 for SaveData.
u64 SaveDataType; ///< See \ref FsSaveDataType.
u64 unk_x28; ///< 0 for SystemSaveData/SaveData.
u64 unk_x30; ///< 0 for SystemSaveData/SaveData.
u64 unk_x38; ///< 0 for SystemSaveData/SaveData.
} PACKED FsSave;
typedef struct
{
u64 saveID_unk;
u8 SaveDataSpaceId; ///< See \ref FsSaveDataSpaceId.
u8 SaveDataType; ///< See \ref FsSaveDataType.
u8 pad[6];
u128 userID; ///< See userID for \ref FsSave.
u64 saveID; ///< See saveID for \ref FsSave.
u64 titleID; ///< titleID for FsSaveDataType_SaveData.
u64 size; ///< Raw saveimage size.
u8 unk_x38[0x28]; ///< Unknown. Usually zeros?
} PACKED FsSaveDataInfo;
typedef enum {
ENTRYTYPE_DIR = 0,
ENTRYTYPE_FILE = 1
} FsEntryType;
typedef enum
{
FS_OPEN_READ = BIT(0), ///< Open for reading.
FS_OPEN_WRITE = BIT(1), ///< Open for writing.
FS_OPEN_APPEND = BIT(2), ///< Append file.
} FsFileFlags;
/// For use with fsFsOpenDirectory.
typedef enum
{
FS_DIROPEN_DIRECTORY = BIT(0), ///< Enable reading directory entries.
FS_DIROPEN_FILE = BIT(1), ///< Enable reading file entries.
} FsDirectoryFlags;
typedef enum
{
FsStorageId_None = 0,
FsStorageId_Host = 1,
FsStorageId_GameCard = 2,
FsStorageId_NandSystem = 3,
FsStorageId_NandUser = 4,
FsStorageId_SdCard = 5,
} FsStorageId;
typedef enum
{
FS_CONTENTSTORAGEID_NandSystem = 0,
FS_CONTENTSTORAGEID_NandUser = 1,
FS_CONTENTSTORAGEID_SdCard = 2,
} FsContentStorageId;
typedef enum
{
FsSaveDataSpaceId_NandSystem = 0,
FsSaveDataSpaceId_NandUser = 1,
FsSaveDataSpaceId_SdCard = 2,
FsSaveDataSpaceId_TemporaryStorage = 3,
FsSaveDataSpaceId_All = -1, ///< Pseudo value for fsOpenSaveDataIterator().
} FsSaveDataSpaceId;
typedef enum
{
FsSaveDataType_SystemSaveData = 0,
FsSaveDataType_SaveData = 1,
FsSaveDataType_BcatDeliveryCacheStorage = 2,
FsSaveDataType_DeviceSaveData = 3,
FsSaveDataType_TemporaryStorage = 4, ///< [3.0.0+]
FsSaveDataType_CacheStorage = 5, ///< [3.0.0+]
} FsSaveDataType;
Result fsInitialize(void);
void fsExit(void);
Service* fsGetServiceSession(void);
/// Do not call this directly, see fs_dev.h.
Result fsMountSdcard(FsFileSystem* out);
Result fsMountSaveData(FsFileSystem* out, u8 inval, FsSave *save);
Result fsMountSystemSaveData(FsFileSystem* out, u8 inval, FsSave *save);
Result fsOpenSaveDataIterator(FsSaveDataIterator* out, s32 SaveDataSpaceId);
Result fsOpenDataStorageByCurrentProcess(FsStorage* out);
Result fsOpenDeviceOperator(FsDeviceOperator* out);
Result fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out);
// todo: Rest of commands here
/// FsFileSystem can be mounted with fs_dev for use with stdio, see fs_dev.h.
/// Wrapper(s) for fsMountSaveData.
/// See FsSave for titleID and userID.
Result fsMount_SaveData(FsFileSystem* out, u64 titleID, u128 userID);
/// Wrapper for fsMountSystemSaveData.
/// WARNING: You can brick when writing to SystemSaveData, if the data is corrupted etc.
Result fsMount_SystemSaveData(FsFileSystem* out, u64 saveID);
// IFileSystem
Result fsFsCreateFile(FsFileSystem* fs, const char* path, size_t size, int flags);
Result fsFsDeleteFile(FsFileSystem* fs, const char* path);
Result fsFsCreateDirectory(FsFileSystem* fs, const char* path);
Result fsFsDeleteDirectory(FsFileSystem* fs, const char* path);
Result fsFsDeleteDirectoryRecursively(FsFileSystem* fs, const char* path);
Result fsFsRenameFile(FsFileSystem* fs, const char* path0, const char* path1);
Result fsFsRenameDirectory(FsFileSystem* fs, const char* path0, const char* path1);
Result fsFsGetEntryType(FsFileSystem* fs, const char* path, FsEntryType* out);
Result fsFsOpenFile(FsFileSystem* fs, const char* path, int flags, FsFile* out);
Result fsFsOpenDirectory(FsFileSystem* fs, const char* path, int flags, FsDir* out);
Result fsFsCommit(FsFileSystem* fs);
Result fsFsGetFreeSpace(FsFileSystem* fs, const char* path, u64* out);
Result fsFsGetTotalSpace(FsFileSystem* fs, const char* path, u64* out);
void fsFsClose(FsFileSystem* fs);
// IFile
Result fsFileRead(FsFile* f, u64 off, void* buf, size_t len, size_t* out);
Result fsFileWrite(FsFile* f, u64 off, const void* buf, size_t len);
Result fsFileFlush(FsFile* f);
Result fsFileSetSize(FsFile* f, u64 sz);
Result fsFileGetSize(FsFile* f, u64* out);
void fsFileClose(FsFile* f);
// IDirectory
Result fsDirRead(FsDir* d, u64 inval, size_t* total_entries, size_t max_entries, FsDirectoryEntry *buf);
Result fsDirGetEntryCount(FsDir* d, u64* count);
void fsDirClose(FsDir* d);
// IStorage
Result fsStorageRead(FsStorage* s, u64 off, void* buf, size_t len);
void fsStorageClose(FsStorage* s);
// ISaveDataInfoReader
/// Read FsSaveDataInfo data into the buf array.
Result fsSaveDataIteratorRead(FsSaveDataIterator *s, FsSaveDataInfo* buf, size_t max_entries, size_t* total_entries);
void fsSaveDataIteratorClose(FsSaveDataIterator *s);
// IEventNotifier
Result fsEventNotifierGetEventHandle(FsEventNotifier* e, Handle* out);
void fsEventNotifierClose(FsEventNotifier* e);
// IDeviceOperator
Result fsDeviceOperatorIsSdCardInserted(FsDeviceOperator* d, bool* out);
void fsDeviceOperatorClose(FsDeviceOperator* d);

View file

@ -1,17 +0,0 @@
/**
* @file fsldr.h
* @brief FilesystemProxy-ForLoader (fsp-ldr) service IPC wrapper.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../services/sm.h"
#include "../services/fs.h"
Result fsldrInitialize(void);
void fsldrExit(void);
Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out);
Result fsldrIsArchivedProgram(u64 pid, bool *out);
Result fsldrSetCurrentProcess();

View file

@ -1,18 +0,0 @@
/**
* @file fspr.h
* @brief FilesystemProxy-ProgramRegistry (fsp-pr) service IPC wrapper.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../services/sm.h"
#include "../services/fs.h"
Result fsprInitialize(void);
void fsprExit(void);
Result fsprRegisterProgram(u64 pid, u64 titleID, FsStorageId storageID, const void *fs_access_header, size_t fah_size, const void *fs_access_control, size_t fac_size);
Result fsprUnregisterProgram(u64 pid);
Result fsprSetCurrentProcess(void);
Result fsprSetEnabledProgramVerification(bool enabled);

View file

@ -1,627 +0,0 @@
/**
* @file hid.h
* @brief Human input device (hid) service IPC wrapper.
* @author shinyquagsire23
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include <assert.h>
#include "../types.h"
#include "../services/sm.h"
// Begin enums and output structs
typedef enum
{
MOUSE_LEFT = BIT(0),
MOUSE_RIGHT = BIT(1),
MOUSE_MIDDLE = BIT(2),
MOUSE_FORWARD = BIT(3),
MOUSE_BACK = BIT(4),
} HidMouseButton;
typedef enum
{
KBD_MOD_LCTRL = BIT(0),
KBD_MOD_LSHIFT = BIT(1),
KBD_MOD_LALT = BIT(2),
KBD_MOD_LMETA = BIT(3),
KBD_MOD_RCTRL = BIT(4),
KBD_MOD_RSHIFT = BIT(5),
KBD_MOD_RALT = BIT(6),
KBD_MOD_RMETA = BIT(7),
KBD_MOD_CAPSLOCK = BIT(8),
KBD_MOD_SCROLLLOCK = BIT(9),
KBD_MOD_NUMLOCK = BIT(10),
} HidKeyboardModifier;
typedef enum
{
KBD_NONE = 0x00,
KBD_ERR_OVF = 0x01,
KBD_A = 0x04,
KBD_B = 0x05,
KBD_C = 0x06,
KBD_D = 0x07,
KBD_E = 0x08,
KBD_F = 0x09,
KBD_G = 0x0a,
KBD_H = 0x0b,
KBD_I = 0x0c,
KBD_J = 0x0d,
KBD_K = 0x0e,
KBD_L = 0x0f,
KBD_M = 0x10,
KBD_N = 0x11,
KBD_O = 0x12,
KBD_P = 0x13,
KBD_Q = 0x14,
KBD_R = 0x15,
KBD_S = 0x16,
KBD_T = 0x17,
KBD_U = 0x18,
KBD_V = 0x19,
KBD_W = 0x1a,
KBD_X = 0x1b,
KBD_Y = 0x1c,
KBD_Z = 0x1d,
KBD_1 = 0x1e,
KBD_2 = 0x1f,
KBD_3 = 0x20,
KBD_4 = 0x21,
KBD_5 = 0x22,
KBD_6 = 0x23,
KBD_7 = 0x24,
KBD_8 = 0x25,
KBD_9 = 0x26,
KBD_0 = 0x27,
KBD_ENTER = 0x28,
KBD_ESC = 0x29,
KBD_BACKSPACE = 0x2a,
KBD_TAB = 0x2b,
KBD_SPACE = 0x2c,
KBD_MINUS = 0x2d,
KBD_EQUAL = 0x2e,
KBD_LEFTBRACE = 0x2f,
KBD_RIGHTBRACE = 0x30,
KBD_BACKSLASH = 0x31,
KBD_HASHTILDE = 0x32,
KBD_SEMICOLON = 0x33,
KBD_APOSTROPHE = 0x34,
KBD_GRAVE = 0x35,
KBD_COMMA = 0x36,
KBD_DOT = 0x37,
KBD_SLASH = 0x38,
KBD_CAPSLOCK = 0x39,
KBD_F1 = 0x3a,
KBD_F2 = 0x3b,
KBD_F3 = 0x3c,
KBD_F4 = 0x3d,
KBD_F5 = 0x3e,
KBD_F6 = 0x3f,
KBD_F7 = 0x40,
KBD_F8 = 0x41,
KBD_F9 = 0x42,
KBD_F10 = 0x43,
KBD_F11 = 0x44,
KBD_F12 = 0x45,
KBD_SYSRQ = 0x46,
KBD_SCROLLLOCK = 0x47,
KBD_PAUSE = 0x48,
KBD_INSERT = 0x49,
KBD_HOME = 0x4a,
KBD_PAGEUP = 0x4b,
KBD_DELETE = 0x4c,
KBD_END = 0x4d,
KBD_PAGEDOWN = 0x4e,
KBD_RIGHT = 0x4f,
KBD_LEFT = 0x50,
KBD_DOWN = 0x51,
KBD_UP = 0x52,
KBD_NUMLOCK = 0x53,
KBD_KPSLASH = 0x54,
KBD_KPASTERISK = 0x55,
KBD_KPMINUS = 0x56,
KBD_KPPLUS = 0x57,
KBD_KPENTER = 0x58,
KBD_KP1 = 0x59,
KBD_KP2 = 0x5a,
KBD_KP3 = 0x5b,
KBD_KP4 = 0x5c,
KBD_KP5 = 0x5d,
KBD_KP6 = 0x5e,
KBD_KP7 = 0x5f,
KBD_KP8 = 0x60,
KBD_KP9 = 0x61,
KBD_KP0 = 0x62,
KBD_KPDOT = 0x63,
KBD_102ND = 0x64,
KBD_COMPOSE = 0x65,
KBD_POWER = 0x66,
KBD_KPEQUAL = 0x67,
KBD_F13 = 0x68,
KBD_F14 = 0x69,
KBD_F15 = 0x6a,
KBD_F16 = 0x6b,
KBD_F17 = 0x6c,
KBD_F18 = 0x6d,
KBD_F19 = 0x6e,
KBD_F20 = 0x6f,
KBD_F21 = 0x70,
KBD_F22 = 0x71,
KBD_F23 = 0x72,
KBD_F24 = 0x73,
KBD_OPEN = 0x74,
KBD_HELP = 0x75,
KBD_PROPS = 0x76,
KBD_FRONT = 0x77,
KBD_STOP = 0x78,
KBD_AGAIN = 0x79,
KBD_UNDO = 0x7a,
KBD_CUT = 0x7b,
KBD_COPY = 0x7c,
KBD_PASTE = 0x7d,
KBD_FIND = 0x7e,
KBD_MUTE = 0x7f,
KBD_VOLUMEUP = 0x80,
KBD_VOLUMEDOWN = 0x81,
KBD_CAPSLOCK_ACTIVE = 0x82 ,
KBD_NUMLOCK_ACTIVE = 0x83 ,
KBD_SCROLLLOCK_ACTIVE = 0x84 ,
KBD_KPCOMMA = 0x85,
KBD_KPLEFTPAREN = 0xb6,
KBD_KPRIGHTPAREN = 0xb7,
KBD_LEFTCTRL = 0xe0,
KBD_LEFTSHIFT = 0xe1,
KBD_LEFTALT = 0xe2,
KBD_LEFTMETA = 0xe3,
KBD_RIGHTCTRL = 0xe4,
KBD_RIGHTSHIFT = 0xe5,
KBD_RIGHTALT = 0xe6,
KBD_RIGHTMETA = 0xe7,
KBD_MEDIA_PLAYPAUSE = 0xe8,
KBD_MEDIA_STOPCD = 0xe9,
KBD_MEDIA_PREVIOUSSONG = 0xea,
KBD_MEDIA_NEXTSONG = 0xeb,
KBD_MEDIA_EJECTCD = 0xec,
KBD_MEDIA_VOLUMEUP = 0xed,
KBD_MEDIA_VOLUMEDOWN = 0xee,
KBD_MEDIA_MUTE = 0xef,
KBD_MEDIA_WWW = 0xf0,
KBD_MEDIA_BACK = 0xf1,
KBD_MEDIA_FORWARD = 0xf2,
KBD_MEDIA_STOP = 0xf3,
KBD_MEDIA_FIND = 0xf4,
KBD_MEDIA_SCROLLUP = 0xf5,
KBD_MEDIA_SCROLLDOWN = 0xf6,
KBD_MEDIA_EDIT = 0xf7,
KBD_MEDIA_SLEEP = 0xf8,
KBD_MEDIA_COFFEE = 0xf9,
KBD_MEDIA_REFRESH = 0xfa,
KBD_MEDIA_CALC = 0xfb
} HidKeyboardScancode;
typedef enum
{
TYPE_PROCONTROLLER = BIT(0),
TYPE_HANDHELD = BIT(1),
TYPE_JOYCON_PAIR = BIT(2),
TYPE_JOYCON_LEFT = BIT(3),
TYPE_JOYCON_RIGHT = BIT(4),
} HidControllerType;
typedef enum
{
LAYOUT_PROCONTROLLER = 0, // Pro Controller or Hid gamepad
LAYOUT_HANDHELD = 1, // Two Joy-Con docked to rails
LAYOUT_SINGLE = 2, // Horizontal single Joy-Con or pair of Joy-Con, adjusted for orientation
LAYOUT_LEFT = 3, // Only raw left Joy-Con state, no orientation adjustment
LAYOUT_RIGHT = 4, // Only raw right Joy-Con state, no orientation adjustment
LAYOUT_DEFAULT_DIGITAL = 5, // Same as next, but sticks have 8-direction values only
LAYOUT_DEFAULT = 6, // Safe default, single Joy-Con have buttons/sticks rotated for orientation
} HidControllerLayoutType;
typedef enum
{
COLORS_NONEXISTENT = BIT(1),
} HidControllerColorDescription;
typedef enum
{
KEY_A = BIT(0), ///< A
KEY_B = BIT(1), ///< B
KEY_X = BIT(2), ///< X
KEY_Y = BIT(3), ///< Y
KEY_LSTICK = BIT(4), ///< Left Stick Button
KEY_RSTICK = BIT(5), ///< Right Stick Button
KEY_L = BIT(6), ///< L
KEY_R = BIT(7), ///< R
KEY_ZL = BIT(8), ///< ZL
KEY_ZR = BIT(9), ///< ZR
KEY_PLUS = BIT(10), ///< Plus
KEY_MINUS = BIT(11), ///< Minus
KEY_DLEFT = BIT(12), ///< D-Pad Left
KEY_DUP = BIT(13), ///< D-Pad Up
KEY_DRIGHT = BIT(14), ///< D-Pad Right
KEY_DDOWN = BIT(15), ///< D-Pad Down
KEY_LSTICK_LEFT = BIT(16), ///< Left Stick Left
KEY_LSTICK_UP = BIT(17), ///< Left Stick Up
KEY_LSTICK_RIGHT = BIT(18), ///< Left Stick Right
KEY_LSTICK_DOWN = BIT(19), ///< Left Stick Down
KEY_RSTICK_LEFT = BIT(20), ///< Right Stick Left
KEY_RSTICK_UP = BIT(21), ///< Right Stick Up
KEY_RSTICK_RIGHT = BIT(22), ///< Right Stick Right
KEY_RSTICK_DOWN = BIT(23), ///< Right Stick Down
KEY_SL = BIT(24), ///< SL
KEY_SR = BIT(25), ///< SR
// Pseudo-key for at least one finger on the touch screen
KEY_TOUCH = BIT(26),
// Buttons by orientation (for single Joy-Con), also works with Joy-Con pairs, Pro Controller
KEY_JOYCON_RIGHT = BIT(0),
KEY_JOYCON_DOWN = BIT(1),
KEY_JOYCON_UP = BIT(2),
KEY_JOYCON_LEFT = BIT(3),
// Generic catch-all directions, also works for single Joy-Con
KEY_UP = KEY_DUP | KEY_LSTICK_UP | KEY_RSTICK_UP, ///< D-Pad Up or Sticks Up
KEY_DOWN = KEY_DDOWN | KEY_LSTICK_DOWN | KEY_RSTICK_DOWN, ///< D-Pad Down or Sticks Down
KEY_LEFT = KEY_DLEFT | KEY_LSTICK_LEFT | KEY_RSTICK_LEFT, ///< D-Pad Left or Sticks Left
KEY_RIGHT = KEY_DRIGHT | KEY_LSTICK_RIGHT | KEY_RSTICK_RIGHT, ///< D-Pad Right or Sticks Right
} HidControllerKeys;
typedef enum
{
JOYSTICK_LEFT = 0,
JOYSTICK_RIGHT = 1,
JOYSTICK_NUM_STICKS = 2,
} HidControllerJoystick;
typedef enum
{
CONTROLLER_STATE_CONNECTED = BIT(0),
CONTROLLER_STATE_WIRED = BIT(1),
} HidControllerConnectionState;
typedef enum
{
CONTROLLER_PLAYER_1 = 0,
CONTROLLER_PLAYER_2 = 1,
CONTROLLER_PLAYER_3 = 2,
CONTROLLER_PLAYER_4 = 3,
CONTROLLER_PLAYER_5 = 4,
CONTROLLER_PLAYER_6 = 5,
CONTROLLER_PLAYER_7 = 6,
CONTROLLER_PLAYER_8 = 7,
CONTROLLER_HANDHELD = 8,
CONTROLLER_UNKNOWN = 9,
CONTROLLER_P1_AUTO = 10, /// Not an actual HID-sysmodule ID. Only for hidKeys*()/hidJoystickRead(). Automatically uses CONTROLLER_PLAYER_1 when connected, otherwise uses CONTROLLER_HANDHELD.
} HidControllerID;
typedef struct touchPosition
{
u32 px;
u32 py;
u32 dx;
u32 dy;
u32 angle;
} touchPosition;
typedef struct JoystickPosition
{
s32 dx;
s32 dy;
} JoystickPosition;
typedef struct MousePosition
{
u32 x;
u32 y;
u32 velocityX;
u32 velocityY;
u32 scrollVelocityX;
u32 scrollVelocityY;
} MousePosition;
#define JOYSTICK_MAX (0x8000)
#define JOYSTICK_MIN (-0x8000)
// End enums and output structs
// Begin HidTouchScreen
typedef struct HidTouchScreenHeader
{
u64 timestampTicks;
u64 numEntries;
u64 latestEntry;
u64 maxEntryIndex;
u64 timestamp;
} HidTouchScreenHeader;
static_assert(sizeof(HidTouchScreenHeader) == 0x28, "Hid touch screen header structure has incorrect size");
typedef struct HidTouchScreenEntryHeader
{
u64 timestamp;
u64 numTouches;
} HidTouchScreenEntryHeader;
static_assert(sizeof(HidTouchScreenEntryHeader) == 0x10, "Hid touch screen entry header structure has incorrect size");
typedef struct HidTouchScreenEntryTouch
{
u64 timestamp;
u32 padding;
u32 touchIndex;
u32 x;
u32 y;
u32 diameterX;
u32 diameterY;
u32 angle;
u32 padding_2;
} HidTouchScreenEntryTouch;
static_assert(sizeof(HidTouchScreenEntryTouch) == 0x28, "Hid touch screen touch structure has incorrect size");
typedef struct HidTouchScreenEntry
{
HidTouchScreenEntryHeader header;
HidTouchScreenEntryTouch touches[16];
u64 unk;
} HidTouchScreenEntry;
static_assert(sizeof(HidTouchScreenEntry) == 0x298, "Hid touch screen entry structure has incorrect size");
typedef struct HidTouchScreen
{
HidTouchScreenHeader header;
HidTouchScreenEntry entries[17];
u8 padding[0x3c0];
} HidTouchScreen;
static_assert(sizeof(HidTouchScreen) == 0x3000, "Hid touch screen structure has incorrect size");
// End HidTouchScreen
// Begin HidMouse
typedef struct HidMouseHeader
{
u64 timestampTicks;
u64 numEntries;
u64 latestEntry;
u64 maxEntryIndex;
} HidMouseHeader;
static_assert(sizeof(HidMouseHeader) == 0x20, "Hid mouse header structure has incorrect size");
typedef struct HidMouseEntry
{
u64 timestamp;
u64 timestamp_2;
MousePosition position;
u64 buttons;
} HidMouseEntry;
static_assert(sizeof(HidMouseEntry) == 0x30, "Hid mouse entry structure has incorrect size");
typedef struct HidMouse
{
HidMouseHeader header;
HidMouseEntry entries[17];
u8 padding[0xB0];
} HidMouse;
static_assert(sizeof(HidMouse) == 0x400, "Hid mouse structure has incorrect size");
// End HidMouse
// Begin HidKeyboard
typedef struct HidKeyboardHeader
{
u64 timestampTicks;
u64 numEntries;
u64 latestEntry;
u64 maxEntryIndex;
} HidKeyboardHeader;
static_assert(sizeof(HidKeyboardHeader) == 0x20, "Hid keyboard header structure has incorrect size");
typedef struct HidKeyboardEntry
{
u64 timestamp;
u64 timestamp_2;
u64 modifier;
u32 keys[8];
} HidKeyboardEntry;
static_assert(sizeof(HidKeyboardEntry) == 0x38, "Hid keyboard entry structure has incorrect size");
typedef struct HidKeyboard
{
HidKeyboardHeader header;
HidKeyboardEntry entries[17];
u8 padding[0x28];
} HidKeyboard;
static_assert(sizeof(HidKeyboard) == 0x400, "Hid keyboard structure has incorrect size");
// End HidKeyboard
// Begin HidController
typedef struct HidControllerMAC
{
u64 timestamp;
u8 mac[0x8];
u64 unk;
u64 timestamp_2;
} HidControllerMAC;
static_assert(sizeof(HidControllerMAC) == 0x20, "Hid controller MAC structure has incorrect size");
typedef struct HidControllerHeader
{
u32 type;
u32 isHalf;
u32 singleColorsDescriptor;
u32 singleColorBody;
u32 singleColorButtons;
u32 splitColorsDescriptor;
u32 leftColorBody;
u32 leftColorButtons;
u32 rightColorBody;
u32 rightColorbuttons;
} HidControllerHeader;
static_assert(sizeof(HidControllerHeader) == 0x28, "Hid controller header structure has incorrect size");
typedef struct HidControllerLayoutHeader
{
u64 timestampTicks;
u64 numEntries;
u64 latestEntry;
u64 maxEntryIndex;
} HidControllerLayoutHeader;
static_assert(sizeof(HidControllerLayoutHeader) == 0x20, "Hid controller layout header structure has incorrect size");
typedef struct HidControllerInputEntry
{
u64 timestamp;
u64 timestamp_2;
u64 buttons;
JoystickPosition joysticks[JOYSTICK_NUM_STICKS];
u64 connectionState;
} HidControllerInputEntry;
static_assert(sizeof(HidControllerInputEntry) == 0x30, "Hid controller input entry structure has incorrect size");
typedef struct HidControllerLayout
{
HidControllerLayoutHeader header;
HidControllerInputEntry entries[17];
} HidControllerLayout;
static_assert(sizeof(HidControllerLayout) == 0x350, "Hid controller layout structure has incorrect size");
typedef struct HidController
{
HidControllerHeader header;
HidControllerLayout layouts[7];
u8 unk_1[0x2A70];
HidControllerMAC macLeft;
HidControllerMAC macRight;
u8 unk_2[0xDF8];
} HidController;
static_assert(sizeof(HidController) == 0x5000, "Hid controller structure has incorrect size");
// End HidController
typedef struct HidSharedMemory
{
u8 header[0x400];
HidTouchScreen touchscreen;
HidMouse mouse;
HidKeyboard keyboard;
u8 unkSection1[0x400];
u8 unkSection2[0x400];
u8 unkSection3[0x400];
u8 unkSection4[0x400];
u8 unkSection5[0x200];
u8 unkSection6[0x200];
u8 unkSection7[0x200];
u8 unkSection8[0x800];
u8 controllerSerials[0x4000];
HidController controllers[10];
u8 unkSection9[0x4600];
} HidSharedMemory;
static_assert(sizeof(HidSharedMemory) == 0x40000, "Hid Shared Memory structure has incorrect size");
typedef struct HidVibrationDeviceInfo
{
u32 unk_x0;
u32 unk_x4; ///< 0x1 for left-joycon, 0x2 for right-joycon.
} HidVibrationDeviceInfo;
static_assert(sizeof(HidVibrationDeviceInfo) == 0x8, "Hid VibrationDeviceInfo structure has incorrect size");
typedef struct HidVibrationValue
{
float amp_low; ///< Low Band amplitude. 1.0f: Max amplitude.
float freq_low; ///< Low Band frequency in Hz.
float amp_high; ///< High Band amplitude. 1.0f: Max amplitude.
float freq_high; ///< High Band frequency in Hz.
} HidVibrationValue;
static_assert(sizeof(HidVibrationValue) == 0x10, "Hid VibrationValue structure has incorrect size");
Result hidInitialize(void);
void hidExit(void);
void hidReset(void);
Service* hidGetSessionService(void);
void* hidGetSharedmemAddr(void);
void hidSetControllerLayout(HidControllerID id, HidControllerLayoutType layoutType);
HidControllerLayoutType hidGetControllerLayout(HidControllerID id);
void hidScanInput(void);
u64 hidKeysHeld(HidControllerID id);
u64 hidKeysDown(HidControllerID id);
u64 hidKeysUp(HidControllerID id);
u64 hidMouseButtonsHeld(void);
u64 hidMouseButtonsDown(void);
u64 hidMouseButtonsUp(void);
void hidMouseRead(MousePosition *pos);
bool hidKeyboardModifierHeld(HidKeyboardModifier modifier);
bool hidKeyboardModifierDown(HidKeyboardModifier modifier);
bool hidKeyboardModifierUp(HidKeyboardModifier modifier);
bool hidKeyboardHeld(HidKeyboardScancode key);
bool hidKeyboardDown(HidKeyboardScancode key);
bool hidKeyboardUp(HidKeyboardScancode key);
u32 hidTouchCount(void);
void hidTouchRead(touchPosition *pos, u32 point_id);
void hidJoystickRead(JoystickPosition *pos, HidControllerID id, HidControllerJoystick stick);
/// This can be used to check what CONTROLLER_P1_AUTO uses.
/// Returns 0 when CONTROLLER_PLAYER_1 is connected, otherwise returns 1 for handheld-mode.
bool hidGetHandheldMode(void);
/// Use this if you want to use a single joy-con as a dedicated CONTROLLER_PLAYER_*.
/// When used, both joy-cons in a pair should be used with this (CONTROLLER_PLAYER_1 and CONTROLLER_PLAYER_2 for example).
/// id must be CONTROLLER_PLAYER_*.
Result hidSetNpadJoyAssignmentModeSingleByDefault(HidControllerID id);
/// Use this if you want to use a pair of joy-cons as a single CONTROLLER_PLAYER_*. Only necessary if you want to use this mode in your application after \ref hidSetNpadJoyAssignmentModeSingleByDefault was used with this pair of joy-cons.
/// Used automatically during app startup/exit for all controllers.
/// When used, both joy-cons in a pair should be used with this (CONTROLLER_PLAYER_1 and CONTROLLER_PLAYER_2 for example).
/// id must be CONTROLLER_PLAYER_*.
Result hidSetNpadJoyAssignmentModeDual(HidControllerID id);
/// Merge two single joy-cons into a dual-mode controller. Use this after \ref hidSetNpadJoyAssignmentModeDual, when \ref hidSetNpadJoyAssignmentModeSingleByDefault was previously used (this includes using this manually at application exit).
Result hidMergeSingleJoyAsDualJoy(HidControllerID id0, HidControllerID id1);
Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, size_t total_handles, HidControllerID id, HidControllerType type);
/// Gets HidVibrationDeviceInfo for the specified VibrationDeviceHandle.
Result hidGetVibrationDeviceInfo(u32 *VibrationDeviceHandle, HidVibrationDeviceInfo *VibrationDeviceInfo);
/// Send the VibrationValue to the specified VibrationDeviceHandle.
Result hidSendVibrationValue(u32 *VibrationDeviceHandle, HidVibrationValue *VibrationValue);
/// Gets the current HidVibrationValue for the specified VibrationDeviceHandle.
Result hidGetActualVibrationValue(u32 *VibrationDeviceHandle, HidVibrationValue *VibrationValue);
/// Sets whether vibration is allowed, this also affects the config displayed by System Settings.
Result hidPermitVibration(bool flag);
/// Gets whether vibration is allowed.
Result hidIsVibrationPermitted(bool *flag);
/// Send VibrationValues[index] to VibrationDeviceHandles[index], where count is the number of entries in the VibrationDeviceHandles/VibrationValues arrays.
Result hidSendVibrationValues(u32 *VibrationDeviceHandles, HidVibrationValue *VibrationValues, size_t count);

View file

@ -1,86 +0,0 @@
/**
* @file irs.h
* @brief HID IR sensor (irs) service IPC wrapper.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../services/sm.h"
#include "../services/hid.h"
typedef struct {
u64 unk_x0;
u8 unk_x8;
u8 unk_x9;
u8 unk_xa;
u8 pad[5];
u16 unk_x10;
u32 unk_x12;
u16 unk_x16;
u32 unk_constant;//offset 0x18
u8 unk_x1c;
u8 unk_x1d;
u8 pad2[2];
} PACKED IrsPackedMomentProcessorConfig;
typedef struct {
u64 exposure; ///< IR Sensor exposure time in nanoseconds.
u32 ir_leds; ///< Controls the IR leds. 0: All leds, 1: Bright group, 2: Dim group, 3: None.
u32 digital_gain; ///< IR sensor signal's digital gain.
u8 color_invert; ///< Inverts the colors of the captured image. 0: Normal image, 1: Negative image.
u8 pad[7];
u32 sensor_res; ///< IR Sensor resolution. 0: 240x320, 1: 120x160, 2: 60x80.
} IrsImageTransferProcessorConfig;
typedef struct {
u64 exposure; ///< IR Sensor exposure time in nanoseconds.
u8 ir_leds; ///< Controls the IR leds. 0: All leds, 1: Bright group, 2: Dim group, 3: None.
u8 digital_gain; ///< IR sensor signal's digital gain.
u8 color_invert; ///< Inverts the colors of the captured image. 0: Normal image, 1: Negative image.
u8 pad[5];
u32 unk_constant;//offset 0x10
u8 sensor_res; ///< IR Sensor resolution. 0: 240x320, 1: 120x160, 2: 60x80.
u8 pad2[3];
} IrsPackedImageTransferProcessorConfig;
typedef struct {
u8 unk_x0[0x10];
} PACKED IrsImageTransferProcessorState;
Result irsInitialize(void);
void irsExit(void);
Service* irsGetSessionService(void);
void* irsGetSharedmemAddr(void);
/// (De)activate the IR sensor, this is automatically used by irsExit(). Must be called after irsInitialize() to activate the IR sensor.
Result irsActivateIrsensor(bool activate);
Result irsGetIrCameraHandle(u32 *IrCameraHandle, HidControllerID id);
/**
* @brief Start ImageTransferProcessor.
* @param[in] IrCameraHandle Camera handle.
* @param[in] config Input config.
* @param[in] size Work-buffer size, must be 0x1000-byte aligned.
* @note Do not use if already started.
*/
Result irsRunImageTransferProcessor(u32 IrCameraHandle, IrsImageTransferProcessorConfig *config, size_t size);
Result irsGetImageTransferProcessorState(u32 IrCameraHandle, void* buffer, size_t size, IrsImageTransferProcessorState *state);
/// Stop ImageTransferProcessor. Do not use if already stopped.
/// \ref irsExit calls this with all IrCameraHandles which were not already used with \ref irsStopImageProcessor.
Result irsStopImageProcessor(u32 IrCameraHandle);
/// "Suspend" ImageTransferProcessor.
/// TODO: What does this really do?
Result irsSuspendImageProcessor(u32 IrCameraHandle);
/**
* Gets the default configuration for Image Transfer mode.
* Defaults are exposure 300us, IR LEDs all ON, 8x digital gain, normal image and resolution 240 x 320.
*/
void irsGetDefaultImageTransferProcessorConfig(IrsImageTransferProcessorConfig *config);

View file

@ -1,50 +0,0 @@
/**
* @file ldr.h
* @brief Loader (ldr*) service IPC wrapper.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../services/sm.h"
#include "../services/fs.h"
typedef struct {
u8 main_thread_priority;
u8 default_cpu_id;
u16 application_type;
u32 main_thread_stack_size;
u64 title_id;
u32 acid_sac_size;
u32 aci0_sac_size;
u32 acid_fac_size;
u32 aci0_fah_size;
u8 ac_buffer[0x3E0];
} LoaderProgramInfo;
typedef struct {
u64 base_address;
u64 size;
u8 build_id[0x20];
} LoaderNsoInfo;
Result ldrShellInitialize(void);
void ldrShellExit(void);
Result ldrDmntInitialize(void);
void ldrDmntExit(void);
Result ldrPmInitialize(void);
void ldrPmExit(void);
Result ldrShellAddTitleToLaunchQueue(u64 tid, const void *args, size_t args_size);
Result ldrShellClearLaunchQueue(void);
Result ldrDmntAddTitleToLaunchQueue(u64 tid, const void *args, size_t args_size);
Result ldrDmntClearLaunchQueue(void);
Result ldrDmntGetNsoInfos(u64 pid, LoaderNsoInfo *out_nso_infos, size_t out_size, u32 *num_out);
Result ldrPmCreateProcess(u64 flags, u64 launch_index, Handle reslimit_h, Handle *out_process_h);
Result ldrPmGetProgramInfo(u64 title_id, FsStorageId storage_id, LoaderProgramInfo *out_program_info);
Result ldrPmRegisterTitle(u64 title_id, FsStorageId storage_id, u64 *out_index);
Result ldrPmUnregisterTitle(u64 launch_index);

View file

@ -1,41 +0,0 @@
/**
* @file lr.h
* @brief Location Resolver (lr) service IPC wrapper.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../services/sm.h"
#include "../services/fs.h"
typedef struct {
Service s;
} LrLocationResolver;
typedef struct {
Service s;
} LrRegisteredLocationResolver;
Result lrInitialize(void);
void lrExit(void);
Result lrOpenLocationResolver(FsStorageId storage, LrLocationResolver* out);
Result lrOpenRegisteredLocationResolver(LrRegisteredLocationResolver* out);
// TODO: Other ILocationResolverManager commands
// ILocationResolver
Result lrLrResolveProgramPath(LrLocationResolver* lr, u64 tid, char *out);
Result lrLrRedirectProgramPath(LrLocationResolver* lr, u64 tid, const char *path);
Result lrLrResolveApplicationControlPath(LrLocationResolver* lr, u64 tid, char *out);
Result lrLrResolveApplicationHtmlDocumentPath(LrLocationResolver* lr, u64 tid, char *out);
Result lrLrResolveDataPath(LrLocationResolver* lr, u64 tid, char *out);
Result lrLrRedirectApplicationControlPath(LrLocationResolver* lr, u64 tid, const char *path);
Result lrLrRedirectApplicationHtmlDocumentPath(LrLocationResolver* lr, u64 tid, const char *path);
Result lrLrResolveLegalInformationPath(LrLocationResolver* lr, u64 tid, char *out);
Result lrLrRedirectLegalInformationPath(LrLocationResolver* lr, u64 tid, const char *path);
Result lrLrRefresh(LrLocationResolver* lr);
// IRegisteredLocationResolver
Result lrRegLrResolveProgramPath(LrRegisteredLocationResolver* reg, u64 tid, char *out);
// TODO: Other IRegisteredLocationResolver commands

View file

@ -1,18 +0,0 @@
/**
* @file nifm.h
* @brief Network interface service IPC wrapper.
* @author shadowninja108
* @copyright libnx Authors
*/
#pragma once
#include "../kernel/ipc.h"
#include "../kernel/detect.h"
#include "../services/sm.h"
Result nifmInitialize(void);
void nifmExit(void);
Result nifmGetCurrentIpAddress(u32* out);

View file

@ -1,47 +0,0 @@
/**
* @file ns.h
* @brief NS service IPC wrapper.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../nacp.h"
#include "../services/fs.h"
typedef struct {
NacpStruct nacp;
u8 icon[0x20000];//JPEG
} NsApplicationControlData;
Result nsInitialize(void);
void nsExit(void);
Result nsGetApplicationControlData(u8 flag, u64 titleID, NsApplicationControlData* buffer, size_t size, size_t* actual_size);
/**
* @brief Returns the total storage capacity (used + free) from content manager services.
* @param storage_id Specified FsStorageId. (Must be FsStorageId_SdCard)
* @param size Pointer to output the total storage size to.
*/
Result nsGetTotalSpaceSize(FsStorageId storage_id, u64 *size);
/**
* @brief Returns the available storage capacity from content manager services.
* @param storage_id Specified FsStorageId. (Must be FsStorageId_SdCard)
* @param size Pointer to output the free storage size to.
*/
Result nsGetFreeSpaceSize(FsStorageId storage_id, u64 *size);
Result nsvmInitialize(void);
void nsvmExit(void);
Result nsvmNeedsUpdateVulnerability(bool *out);
Result nsvmGetSafeSystemVersion(u16 *out);
/* ns:dev */
Result nsdevInitialize();
void nsdevExit();
Result nsdevTerminateProcess(u64 pid);
Result nsdevTerminateProgram(u64 tid);

View file

@ -1,26 +0,0 @@
/**
* @file nv.h
* @brief NVIDIA low level driver (nvdrv*) service IPC wrapper.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
typedef enum {
NVSERVTYPE_Default = -1,
NVSERVTYPE_Application = 0,
NVSERVTYPE_Applet = 1,
NVSERVTYPE_Sysmodule = 2,
NVSERVTYPE_T = 3,
} nvServiceType;
Result nvInitialize(nvServiceType servicetype, size_t sharedmem_size);
void nvExit(void);
Result nvOpen(u32 *fd, const char *devicepath);
Result nvIoctl(u32 fd, u32 request, void* argp);
Result nvClose(u32 fd);
Result nvQueryEvent(u32 fd, u32 event_id, Handle *handle_out);
Result nvConvertError(int rc);

View file

@ -1,37 +0,0 @@
/**
* @file pl.h
* @brief pl:u service IPC wrapper.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
typedef enum
{
PlSharedFontType_Standard = 0, ///< Japan, US and Europe
PlSharedFontType_ChineseSimplified = 1, ///< Chinese Simplified
PlSharedFontType_ExtChineseSimplified = 2, ///< Extended Chinese Simplified
PlSharedFontType_ChineseTraditional = 3, ///< Chinese Traditional
PlSharedFontType_KO = 4, ///< Korean (Hangul)
PlSharedFontType_NintendoExt = 5, ///< Nintendo Extended
PlSharedFontType_Total, ///< Total fonts supported by this enum.
} PlSharedFontType;
typedef struct {
u32 type;
u32 offset;
u32 size;
void* address;
} PlFontData;
Result plInitialize(void);
void plExit(void);
void* plGetSharedmemAddr(void);
///< Gets a specific shared-font via SharedFontType, see \ref PlSharedFontType.
Result plGetSharedFontByType(PlFontData* font, u32 SharedFontType);
///< Gets shared font(s).
Result plGetSharedFont(u64 LanguageCode, PlFontData* fonts, size_t max_fonts, size_t* total_fonts);

View file

@ -1,30 +0,0 @@
/**
* @file pm.h
* @brief Process management (pm*) service IPC wrapper.
* @author plutoo
* @author yellows8
* @author mdbell
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
Result pmdmntInitialize(void);
void pmdmntExit(void);
Result pminfoInitialize(void);
void pminfoExit(void);
Result pmshellInitialize(void);
void pmshellExit(void);
Result pmdmntStartProcess(u64 pid);
Result pmdmntGetTitlePid(u64* pid_out, u64 title_id);
Result pmdmntEnableDebugForTitleId(Handle* handle_out, u64 title_id);
Result pmdmntGetApplicationPid(u64* pid_out);
Result pmdmntEnableDebugForApplication(Handle* handle_out);
Result pminfoGetTitleId(u64* title_id_out, u64 pid);
Result pmshellLaunchProcess(u32 launch_flags, u64 titleID, u64 storageID, u64 *pid);
Result pmshellTerminateProcessByTitleId(u64 titleID);

View file

@ -1,133 +0,0 @@
/**
* @file set.h
* @brief Settings services IPC wrapper.
* @author plutoo
* @author yellows8
* @copyright libnx Authors
*/
#include "../result.h"
#define SET_MAX_NAME_SIZE 0x48
typedef enum {
ColorSetId_Light=0,
ColorSetId_Dark=1
} ColorSetId;
/// IDs for Language.
typedef enum
{
SetLanguage_JA = 0, ///< Japanese
SetLanguage_ENUS = 1, ///< US English ("AmericanEnglish")
SetLanguage_FR = 2, ///< French
SetLanguage_DE = 3, ///< German
SetLanguage_IT = 4, ///< Italian
SetLanguage_ES = 5, ///< Spanish
SetLanguage_ZHCN = 6, ///< Simplified Chinese ("Chinese")
SetLanguage_KO = 7, ///< Korean
SetLanguage_NL = 8, ///< Dutch
SetLanguage_PT = 9, ///< Portuguese
SetLanguage_RU = 10, ///< Russian
SetLanguage_ZHTW = 11, ///< Traditional Chinese ("Taiwanese")
SetLanguage_ENGB = 12, ///< GB English ("BritishEnglish")
SetLanguage_FRCA = 13, ///< CA French ("CanadianFrench")
SetLanguage_ES419 = 14, ///< "LatinAmericanSpanish"
SetLanguage_Total, ///< Total languages supported by this enum.
} SetLanguage;
/// Region codes.
typedef enum {
SetRegion_JPN = 0, ///< Japan
SetRegion_USA = 1, ///< The Americas
SetRegion_EUR = 2, ///< Europe
SetRegion_AUS = 3, ///< Australia/New Zealand
} SetRegion;
/// Command IDs for setsysGetFlag/setsysSetFlag.
typedef enum {
SetSysFlag_LockScreen = 7,
SetSysFlag_ConsoleInformationUpload = 25,
SetSysFlag_AutomaticApplicationDownload = 27,
SetSysFlag_Quest = 47,
SetSysFlag_Usb30Enable = 65,
SetSysFlag_NfcEnable = 69,
SetSysFlag_WirelessLanEnable = 73,
SetSysFlag_BluetoothEnable = 88,
SetSysFlag_AutoUpdateEnable = 95,
SetSysFlag_BatteryPercentage = 99,
SetSysFlag_ExternalRtcReset = 101,
SetSysFlag_UsbFullKeyEnable = 103,
SetSysFlag_BluetoothAfhEnable = 111,
SetSysFlag_BluetoothBoostEnable = 113,
SetSysFlag_InRepairProcessEnable = 115,
SetSysFlag_HeadphoneVolumeUpdate = 117,
} SetSysFlag;
Result setInitialize(void);
void setExit(void);
/// Converts LanguageCode to Language.
Result setMakeLanguage(u64 LanguageCode, s32 *Language);
/// Converts Language to LanguageCode.
Result setMakeLanguageCode(s32 Language, u64 *LanguageCode);
/// Gets the current system LanguageCode.
/// Normally this should be used instead of \ref setGetLanguageCode.
/// LanguageCode is a string, see here: http://switchbrew.org/index.php?title=Settings_services#LanguageCode
Result setGetSystemLanguage(u64 *LanguageCode);
/// Gets the current LanguageCode, \ref setGetSystemLanguage should be used instead normally.
Result setGetLanguageCode(u64 *LanguageCode);
/// Gets available LanguageCodes.
/// On system-version <4.0.0, max_entries is set to the output from \ref setGetAvailableLanguageCodeCount if max_entries is larger than that.
Result setGetAvailableLanguageCodes(s32 *total_entries, u64 *LanguageCodes, size_t max_entries);
/// Gets total available LanguageCodes.
/// Output total is overridden with value 0 if the total is <0.
Result setGetAvailableLanguageCodeCount(s32 *total);
/// Gets the RegionCode.
Result setGetRegionCode(SetRegion *out);
Result setsysInitialize(void);
void setsysExit(void);
/// Gets the current system theme.
Result setsysGetColorSetId(ColorSetId *out);
/// Sets the current system theme.
Result setsysSetColorSetId(ColorSetId id);
/**
* @brief Gets the size of a settings item value.
* @param out Pointer to output the size to.
*/
Result setsysGetSettingsItemValueSize(const char *name, const char *item_key, u64 *size_out);
/**
* @brief Gets the value of a settings item.
* @param out Pointer to output the value to.
*/
Result setsysGetSettingsItemValue(const char *name, const char *item_key, void *value_out, size_t value_out_size);
/**
* @brief Gets the system's serial number.
* @param serial Pointer to output the serial to. (The buffer size needs to be at least 0x19 bytes)
*/
Result setsysGetSerialNumber(char *serial);
/**
* @brief Gets the status of the specified settings flag.
* @param flag The specified settings flag.
* @param out Output pointer for the status.
*/
Result setsysGetFlag(SetSysFlag flag, bool *out);
/**
* @brief Enables/disables the specified settings flag.
* @param flag The specified settings flag.
* @param enable To enable/disable the flag.
*/
Result setsysSetFlag(SetSysFlag flag, bool enable);

View file

@ -1,48 +0,0 @@
/**
* @file sfdnsres.h
* @brief Domain name resolution service IPC wrapper. Please use socket.c instead.
* @author TuxSH
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include <sys/socket.h> // For socklen_t, etc.
/// Configuration structure for sfdnsres.
typedef struct {
size_t serialized_out_addrinfos_max_size; ///< For getaddrinfo.
size_t serialized_out_hostent_max_size; ///< For gethostbyname/gethostbyaddr.
bool bypass_nsd; ///< For name gethostbyname/getaddrinfo: bypass the Name Server Daemon.
int timeout; ///< For DNS requests: timeout or 0.
} SfdnsresConfig;
/// Result values returned by the DNS request commands.
typedef struct {
int ret; ///< Return value (error code).
int errno_; ///< Errno.
ssize_t out_serialized_size; ///< Size of the serialized output buffer or -1 (?).
} SfdnsresRequestResults;
// SetDnsAddressesPrivate & GetDnsAddressPrivate are stubbed
Result sfdnsresGetHostByName(SfdnsresRequestResults *ret, const SfdnsresConfig *config, void *out_he_serialized, const char *name);
Result sfdnsresGetHostByAddr(SfdnsresRequestResults *ret, const SfdnsresConfig *config, void *out_he_serialized, const void *addr, socklen_t len, int type);
Result sfdnsresGetHostStringError(int err, char *str, size_t str_size);
Result sfdnsresGetGaiStringError(int err, char *str, size_t str_size);
Result sfdnsresGetAddrInfo(SfdnsresRequestResults *ret, const SfdnsresConfig *config, const char *node, const char *service,
const void *hints_serialized, size_t hints_serialized_size, void *res_serialized);
Result sfdnsresGetNameInfo(SfdnsresRequestResults *ret, const SfdnsresConfig *config,
const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen,
char *serv, size_t servlen, int flags);
/// Requests an handle for use with @ref sfdnsresCancelSocketCall.
Result sfdnsresRequestCancelHandle(u32 *out_handle);
/// Cancels a DNS request (how? which requests?). Bug: always sets errno?
Result sfdnsresCancelSocketCall(SfdnsresRequestResults *ret, u32 handle);
/// Cancels all DNS requests made by the current process (how? which requests?). Bug: always sets errno?
Result sfdnsresCancelAllSocketCalls(SfdnsresRequestResults *ret);
/// Clears up to 4 DNS server IPs registered by bsdcfg (DHCP client, etc.).
Result sfdnsresClearDnsIpServerAddressArray(void);

View file

@ -1,228 +0,0 @@
/**
* @file sm.h
* @brief Service manager (sm) IPC wrapper.
* @author plutoo
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../kernel/svc.h"
#include "../kernel/ipc.h"
/// Service type.
typedef enum {
ServiceType_Uninitialized, ///< Uninitialized service.
ServiceType_Normal, ///< Normal service.
ServiceType_Domain, ///< Domain.
ServiceType_DomainSubservice, ///< Domain subservice;
ServiceType_Override ///< Service overriden in the homebrew environment.
} ServiceType;
/// Service object structure.
typedef struct {
Handle handle;
u32 object_id;
ServiceType type;
} Service;
/**
* @brief Returns whether a service is overriden in the homebrew environment.
* @param[in] s Service object.
* @return true if overriden.
*/
static inline bool serviceIsOverride(Service* s) {
return s->type == ServiceType_Override;
}
/**
* @brief Returns whether a service has been initialized.
* @param[in] s Service object.
* @return true if initialized.
*/
static inline bool serviceIsActive(Service* s) {
return s->type != ServiceType_Uninitialized;
}
/**
* @brief Returns whether a service is a domain.
* @param[in] s Service object.
* @return true if a domain.
*/
static inline bool serviceIsDomain(Service* s) {
return s->type == ServiceType_Domain;
}
/**
* @brief Returns whether a service is a domain subservice.
* @param[in] s Service object.
* @return true if a domain subservice.
*/
static inline bool serviceIsDomainSubservice(Service* s) {
return s->type == ServiceType_DomainSubservice;
}
/**
* @brief For a domain/domain subservice, return the associated object ID.
* @param[in] s Service object, necessarily a domain or domain subservice.
* @return The object ID.
*/
static inline u32 serviceGetObjectId(Service* s) {
return s->object_id;
}
/**
* @brief Closes a domain object by ID.
* @param[in] s Service object, necessarily a domain or domain subservice.
* @param object_id ID of the object to close.
* @return Result code.
*/
static inline Result serviceCloseObjectById(Service* s, u32 object_id) {
return ipcCloseObjectById(s->handle, object_id);
}
/**
* @brief Dispatches an IPC request to a service.
* @param[in] s Service object.
* @return Result code.
*/
static inline Result serviceIpcDispatch(Service* s) {
return ipcDispatch(s->handle);
}
/**
* @brief Creates a service object from an IPC session handle.
* @param[out] s Service object.
* @param[in] h IPC session handle.
*/
static inline void serviceCreate(Service* s, Handle h) {
s->handle = h;
s->type = ServiceType_Normal;
s->object_id = IPC_INVALID_OBJECT_ID;
}
/**
* @brief Creates a domain subservice object from a parent service.
* @param[out] s Service object.
* @param[in] parent Parent service, necessarily a domain or domain subservice.
* @param[in] object_id Object ID for this subservice.
*/
static inline void serviceCreateDomainSubservice(Service* s, Service* parent, u32 object_id) {
s->handle = parent->handle;
s->type = ServiceType_DomainSubservice;
s->object_id = object_id;
}
/**
* @brief Converts a regular service to a domain.
* @param[in] s Service object.
* @return Result code.
*/
static inline Result serviceConvertToDomain(Service* s) {
Result rc = ipcConvertSessionToDomain(s->handle, &s->object_id);
if(R_SUCCEEDED(rc))
s->type = ServiceType_Domain;
return rc;
}
/**
* @brief Closes a service.
* @param[in] s Service object.
*/
static inline void serviceClose(Service* s) {
switch (s->type) {
case ServiceType_Normal:
case ServiceType_Domain:
ipcCloseSession(s->handle);
svcCloseHandle(s->handle);
break;
case ServiceType_DomainSubservice:
serviceCloseObjectById(s, s->object_id);
break;
case ServiceType_Override:
// Don't close because we don't own the overridden handle.
break;
case ServiceType_Uninitialized:
break;
}
s->type = ServiceType_Uninitialized;
}
/**
* @brief Initializes SM.
* @return Result code.
* @note This function is already called in the default application startup code (before main() is called).
*/
Result smInitialize(void);
/**
* @brief Uninitializes SM.
* @return Result code.
* @note This function is already handled in the default application exit code (after main() returns).
*/
void smExit(void);
/**
* @brief Requests a service from SM.
* @param[out] service_out Service structure which will be filled in.
* @param[in] name Name of the service to request.
* @return Result code.
*/
Result smGetService(Service* service_out, const char* name);
/**
* @brief Requests a service from SM, as an IPC session handle directly
* @param[out] handle_out Variable containing IPC session handle.
* @param[in] name Name of the service to request.
* @return Result code.
*/
Result smGetServiceOriginal(Handle* handle_out, u64 name);
/**
* @brief Retrieves an overriden service in the homebrew environment.
* @param[in] name Name of the service to request (as 64-bit integer).
* @return IPC session handle.
*/
Handle smGetServiceOverride(u64 name);
/**
* @brief Creates and registers a new service within SM.
* @param[out] handle_out Variable containing IPC port handle.
* @param[in] name Name of the service.
* @param[in] is_light "Is light"
* @param[in] max_sessions Maximum number of concurrent sessions that the service will accept.
* @return Result code.
*/
Result smRegisterService(Handle* handle_out, const char* name, bool is_light, int max_sessions);
/**
* @brief Unregisters a previously registered service in SM.
* @param[in] name Name of the service.
* @return Result code.
*/
Result smUnregisterService(const char* name);
/**
* @brief Check whether SM is initialized.
* @return true if initialized.
*/
bool smHasInitialized(void);
/**
* @brief Encodes a service name as a 64-bit integer.
* @param[in] name Name of the service.
* @return Encoded name.
*/
u64 smEncodeName(const char* name);
/**
* @brief Overrides a service with a custom IPC service handle.
* @param[in] name Name of the service (as 64-bit integer).
* @param[in] handle IPC session handle.
*/
void smAddOverrideHandle(u64 name, Handle handle);

View file

@ -1,16 +0,0 @@
/**
* @file smm.h
* @brief ServiceManager-IManager (sm:m) service IPC wrapper.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../services/sm.h"
#include "../services/fs.h"
Result smManagerInitialize(void);
void smManagerExit(void);
Result smManagerRegisterProcess(u64 pid, const void *acid_sac, size_t acid_sac_size, const void *aci0_sac, size_t aci0_sac_size);
Result smManagerUnregisterProcess(u64 pid);

Some files were not shown because too many files have changed in this diff Show more