...
 
Commits (917)
......@@ -5,15 +5,13 @@
"buildenv": "docker:devkitpro/devkita64",
"buildcmd": [
"sudo -E make -j${PARALLEL} -C nx install",
"git clone --depth 1 https://github.com/switchbrew/switch-examples",
"make -C switch-examples/"
"sudo -E make -j${PARALLEL} -C nx install"
]
},
"docs": {
// Only invoke docs target when building from master branch
"branch": "master",
// This target build and upload docs and will be trigged from doozer's CD script
"auto": false,
"buildenv": "xenial-amd64",
"builddeps": [
......
image: devkitpro/devkita64:latest
stages:
- package
- create image
package:
stage: package
before_script:
- dkp-pacman -Syy
- dkp-pacman -S --noconfirm devkitARM
- export DEVKITPRO=/opt/devkitpro
- export DEVKITARM=/opt/devkitpro/devkitARM
script:
- make -j10
- make install
- rm -rf libnx/
- mv /opt/devkitpro/libnx libnx/
artifacts:
name: libnx
paths:
- libnx/
docker image:
stage: create image
script:
- "curl -X POST -F token=$TOKEN_DOCKER_IMAGE -F ref=master https://git.m4xw.net/api/v4/projects/103/trigger/pipeline"
when: on_success
only:
- master
nightly image:
stage: create image
script:
- "curl -X POST -F token=$TOKEN_DOCKER_IMAGE -F ref=develop https://git.m4xw.net/api/v4/projects/103/trigger/pipeline"
when: on_success
only:
- develop
- cicd/updates
This diff is collapsed.
......@@ -4,4 +4,4 @@ Based on libctru.
[![Build status](https://doozer.io/badge/switchbrew/libnx/buildstatus/master)](https://doozer.io/switchbrew/libnx)
# Install instructions
See [Switchbrew](http://switchbrew.org/index.php?title=Setting_up_Development_Environment).
See [Switchbrew](https://switchbrew.org/wiki/Setting_up_Development_Environment).
......@@ -8,9 +8,9 @@ endif
include $(DEVKITPRO)/devkitA64/base_rules
export LIBNX_MAJOR := 1
export LIBNX_MINOR := 3
export LIBNX_PATCH := 1
export LIBNX_MAJOR := 2
export LIBNX_MINOR := 5
export LIBNX_PATCH := 0
VERSION := $(LIBNX_MAJOR).$(LIBNX_MINOR).$(LIBNX_PATCH)
......@@ -24,22 +24,22 @@ VERSION := $(LIBNX_MAJOR).$(LIBNX_MINOR).$(LIBNX_PATCH)
#---------------------------------------------------------------------------------
TARGET := nx
#BUILD := build
SOURCES := source/arm source/runtime source/kernel source/runtime/devices source/services source/gfx source/gfx/ioctl source/runtime/util/utf
SOURCES := source/arm source/kernel source/sf source/services source/crypto source/nvidia source/nvidia/ioctl source/display source/audio source/applets source/runtime source/runtime/devices source/runtime/util source/runtime/util/utf
DATA := data
INCLUDES := include external/bsd/include
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec
CFLAGS := -g -Wall -Werror \
CFLAGS := -g -Wall \
-ffunction-sections \
-fdata-sections \
$(ARCH) \
$(BUILD_CFLAGS)
CFLAGS += $(INCLUDE) -DSWITCH
CFLAGS += $(INCLUDE) -D__SWITCH__ -DLIBNX_NO_DEPRECATION
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
......@@ -96,7 +96,7 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
all: lib/libnx.a lib/libnxd.a
dist-bin: all
@tar --exclude=*~ -cjf libnx-$(VERSION).tar.bz2 include lib default_icon.jpg switch_rules switch.ld switch.specs -C external/bsd include
@tar --exclude=*~ -cjf libnx-$(VERSION).tar.bz2 include lib default_icon.jpg switch_rules switch.ld switch.specs -C external/bsd include
dist-src:
@tar --exclude=*~ -cjf libnx-src-$(VERSION).tar.bz2 include source data external Makefile default_icon.jpg switch_rules switch.ld switch.specs
......@@ -122,7 +122,7 @@ debug:
lib/libnx.a : lib release $(SOURCES) $(INCLUDES)
@$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \
BUILD_CFLAGS="-DNDEBUG=1 -O2" \
BUILD_CFLAGS="-DNDEBUG=1 -O3 -ffast-math" \
DEPSDIR=$(CURDIR)/release \
--no-print-directory -C release \
-f $(CURDIR)/Makefile
......
......@@ -373,7 +373,8 @@ struct ifreq {
struct sockaddr ifr_dstaddr; /* other end of p-to-p link */
struct sockaddr ifr_broadaddr; /* broadcast address */
struct ifreq_buffer ifr_buffer; /* user supplied buffer with its length */
short ifr_flags[2]; /* flags (low 16 bits) */
short ifr_flags; /* flags (low 16 bits) */
short ifr_flagshigh; /* flags (high 16 bits) */
short ifr_index; /* interface index */
int ifr_jid; /* jail/vnet */
int ifr_metric; /* metric */
......
......@@ -45,6 +45,15 @@
#include <sys/types.h>
#include <machine/endian.h>
#ifndef _IN_ADDR_T_DECLARED
typedef __uint32_t in_addr_t;
#define _IN_ADDR_T_DECLARED
#endif
#ifndef _IN_PORT_T_DECLARED
typedef __uint16_t in_port_t;
#define _IN_PORT_T_DECLARED
#endif
/* Protocols common to RFC 1700, POSIX, and X/Open. */
#define IPPROTO_IP 0 /* dummy for IP */
#define IPPROTO_ICMP 1 /* control message protocol */
......
......@@ -17,11 +17,17 @@ extern "C" {
#include "switch/arm/tls.h"
#include "switch/arm/cache.h"
#include "switch/arm/atomics.h"
#include "switch/arm/counter.h"
#include "switch/kernel/svc.h"
#include "switch/kernel/wait.h"
#include "switch/kernel/tmem.h"
#include "switch/kernel/shmem.h"
#include "switch/kernel/mutex.h"
#include "switch/kernel/event.h"
#include "switch/kernel/uevent.h"
#include "switch/kernel/utimer.h"
#include "switch/kernel/rwlock.h"
#include "switch/kernel/condvar.h"
#include "switch/kernel/thread.h"
......@@ -30,7 +36,13 @@ extern "C" {
#include "switch/kernel/detect.h"
#include "switch/kernel/random.h"
#include "switch/kernel/jit.h"
#include "switch/kernel/ipc.h"
#include "switch/kernel/ipc.h" // Deprecated
#include "switch/kernel/barrier.h"
#include "switch/sf/hipc.h"
#include "switch/sf/cmif.h"
#include "switch/sf/service.h"
#include "switch/sf/sessionmgr.h"
#include "switch/services/sm.h"
#include "switch/services/smm.h"
......@@ -40,14 +52,31 @@ extern "C" {
#include "switch/services/acc.h"
#include "switch/services/apm.h"
#include "switch/services/applet.h"
#include "switch/services/async.h"
#include "switch/services/audin.h"
#include "switch/services/audout.h"
#include "switch/services/audren.h"
#include "switch/services/auddev.h"
#include "switch/services/hwopus.h"
#include "switch/services/csrng.h"
//#include "switch/services/bsd.h" Use switch/runtime/devices/socket.h instead
#include "switch/services/lbl.h"
#include "switch/services/i2c.h"
#include "switch/services/gpio.h"
#include "switch/services/bpc.h"
#include "switch/services/pcv.h"
#include "switch/services/clkrst.h"
#include "switch/services/psm.h"
#include "switch/services/spsm.h"
//#include "switch/services/bsd.h" Use <sys/socket.h> instead
//#include "switch/services/sfdnsres.h" Use <netdb.h> instead
#include "switch/services/fatal.h"
#include "switch/services/time.h"
#include "switch/services/usb.h"
#include "switch/services/usbds.h"
#include "switch/services/usbhs.h"
#include "switch/services/hid.h"
#include "switch/services/hiddbg.h"
#include "switch/services/hidsys.h"
#include "switch/services/irs.h"
#include "switch/services/pl.h"
#include "switch/services/vi.h"
......@@ -55,22 +84,55 @@ extern "C" {
#include "switch/services/nifm.h"
#include "switch/services/ns.h"
#include "switch/services/ldr.h"
#include "switch/services/ro.h"
#include "switch/services/ts.h"
#include "switch/services/pm.h"
#include "switch/services/set.h"
#include "switch/services/lr.h"
#include "switch/services/spl.h"
#include "switch/services/ncm.h"
#include "switch/services/psc.h"
#include "switch/services/caps.h"
#include "switch/services/capsu.h"
#include "switch/services/capssc.h"
#include "switch/services/capssu.h"
#include "switch/services/nfc.h"
#include "switch/services/wlaninf.h"
#include "switch/services/pctl.h"
#include "switch/services/pdm.h"
#include "switch/services/grc.h"
#include "switch/services/friends.h"
#include "switch/services/notif.h"
#include "switch/display/binder.h"
#include "switch/display/parcel.h"
#include "switch/display/buffer_producer.h"
#include "switch/display/native_window.h"
#include "switch/display/framebuffer.h"
#include "switch/nvidia/ioctl.h"
#include "switch/nvidia/graphic_buffer.h"
#include "switch/nvidia/fence.h"
#include "switch/nvidia/map.h"
#include "switch/nvidia/address_space.h"
#include "switch/nvidia/channel.h"
#include "switch/nvidia/gpu.h"
#include "switch/nvidia/gpu_channel.h"
#include "switch/audio/driver.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/applets/libapplet.h"
#include "switch/applets/album_la.h"
#include "switch/applets/friends_la.h"
#include "switch/applets/pctlauth.h"
#include "switch/applets/error.h"
#include "switch/applets/swkbd.h"
#include "switch/applets/web.h"
#include "switch/runtime/env.h"
#include "switch/runtime/hosversion.h"
#include "switch/runtime/nxlink.h"
#include "switch/runtime/resolver.h"
#include "switch/runtime/util/utf.h"
......@@ -80,6 +142,18 @@ extern "C" {
#include "switch/runtime/devices/romfs_dev.h"
#include "switch/runtime/devices/socket.h"
#include "switch/crypto/aes.h"
#include "switch/crypto/aes_cbc.h"
#include "switch/crypto/aes_ctr.h"
#include "switch/crypto/aes_xts.h"
#include "switch/crypto/cmac.h"
#include "switch/crypto/sha256.h"
#include "switch/crypto/sha1.h"
#include "switch/crypto/hmac.h"
#include "switch/crypto/crc.h"
#ifdef __cplusplus
}
#endif
......
/**
* @file album_la.h
* @brief Wrapper for using the Album LibraryApplet.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/// Arg type values pushed for the applet input storage, stored as an u8.
typedef enum {
AlbumLaArg_ShowAlbumFiles = 0, ///< ShowAlbumFiles. Only displays AlbumFiles associated with the application which launched the Album applet, with the filter button disabled.
AlbumLaArg_ShowAllAlbumFiles = 1, ///< ShowAllAlbumFiles. Displays all AlbumFiles, with filtering allowed.
AlbumLaArg_ShowAllAlbumFilesForHomeMenu = 2, ///< ShowAllAlbumFilesForHomeMenu. Similar to ::AlbumLaArg_ShowAllAlbumFiles.
} AlbumLaArg;
/**
* @brief Launches the applet with ::AlbumLaArg_ShowAlbumFiles and playStartupSound=false.
*/
Result albumLaShowAlbumFiles(void);
/**
* @brief Launches the applet with ::AlbumLaArg_ShowAllAlbumFiles and playStartupSound=false.
*/
Result albumLaShowAllAlbumFiles(void);
/**
* @brief Launches the applet with ::AlbumLaArg_ShowAllAlbumFilesForHomeMenu and playStartupSound=true.
*/
Result albumLaShowAllAlbumFilesForHomeMenu(void);
This diff is collapsed.
This diff is collapsed.
/**
* @file libapplet.h
* @brief LibraryApplet wrapper.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../services/applet.h"
/// CommonArguments
typedef struct {
u32 CommonArgs_version; ///< \ref libappletArgsCreate sets this to 1, and \ref libappletArgsPop requires value 1. v0 is not supported.
u32 CommonArgs_size; ///< Size of this struct.
u32 LaVersion; ///< LibraryApplet API version.
s32 ExpectedThemeColor; ///< Set to the output from \ref appletGetThemeColorType by \ref libappletArgsCreate.
u8 PlayStartupSound; ///< bool flag, default is false.
u8 pad[7]; ///< Padding.
u64 tick; ///< System tick. Set to the output from \ref armGetSystemTick during \ref libappletArgsPush.
} LibAppletArgs;
/**
* @brief Creates a LibAppletArgs struct.
* @param a LibAppletArgs struct.
* @param version LaVersion for \ref LibAppletArgs.
*/
void libappletArgsCreate(LibAppletArgs* a, u32 version);
/**
* @brief Sets the PlayStartupSound field in \ref LibAppletArgs.
* @param a LibAppletArgs struct.
* @param flag Value for \ref LibAppletArgs PlayStartupSound.
*/
void libappletArgsSetPlayStartupSound(LibAppletArgs* a, bool flag);
/**
* @brief Creates an AppletStorage with the specified size and writes the buffer contents to that storage at offset 0.
* @param[out] s Storage object.
* @param buffer Input buffer.
* @param size Size to write.
*/
Result libappletCreateWriteStorage(AppletStorage* s, const void* buffer, size_t size);
/**
* @brief Reads data from offset 0 from the specified storage into the buffer. If the storage-size is smaller than the size param, the storage-size is used instead.
* @param s Storage object.
* @param buffer Output buffer.
* @param size Size to read.
* @param transfer_size Optional output size field for the actual size used for the read, can be NULL.
*/
Result libappletReadStorage(AppletStorage* s, void* buffer, size_t size, size_t *transfer_size);
/**
* @brief Sets the tick field in LibAppletArgs, then creates a storage with it which is pushed to the AppletHolder via \ref appletHolderPushInData.
* @param a LibAppletArgs struct.
* @param h AppletHolder object.
*/
Result libappletArgsPush(LibAppletArgs* a, AppletHolder *h);
/**
* @brief Uses \ref appletPopInData and reads it to the specified LibAppletArgs. The LibAppletArgs is validated, an error is thrown when invalid.
* @param[out] a LibAppletArgs struct.
*/
Result libappletArgsPop(LibAppletArgs* a);
/**
* @brief Creates a storage using the input buffer which is pushed to the AppletHolder via \ref appletHolderPushInData.
* @param h AppletHolder object.
* @param buffer Input data buffer.
* @param size Input data size.
*/
Result libappletPushInData(AppletHolder *h, const void* buffer, size_t size);
/**
* @brief Pops a storage via \ref appletHolderPopOutData, uses \ref libappletReadStorage, then closes the storage.
* @param h AppletHolder object.
* @param buffer Output buffer.
* @param size Size to read.
* @param transfer_size Optional output size field for the actual size used for the read, can be NULL.
*/
Result libappletPopOutData(AppletHolder *h, void* buffer, size_t size, size_t *transfer_size);
/**
* @brief Sets whether \ref libappletStart uses \ref appletHolderJump.
* @param flag Flag. Value true should not be used unless running as AppletType_LibraryApplet.
*/
void libappletSetJumpFlag(bool flag);
/**
* @brief If the flag from \ref libappletSetJumpFlag is set, this just uses \ref appletHolderJump. Otherwise, starts the applet and waits for it to finish, then checks the \ref LibAppletExitReason.
* @note Uses \ref appletHolderStart and \ref appletHolderJoin.
* @param h AppletHolder object.
*/
Result libappletStart(AppletHolder *h);
/**
* @brief Creates a LibraryApplet with the specified input storage data, uses \ref libappletStart, and reads the output storage reply data via \ref libappletPopOutData.
* @param id \ref AppletId
* @param commonargs \ref LibAppletArgs struct.
* @param arg Input storage data buffer. Optional, can be NULL.
* @param arg_size Size of the arg buffer.
* @param reply Output storage data buffer. Optional, can be NULL.
* @param reply_size Size to read for the reply buffer.
* @param out_reply_size Actual read reply data size, see \ref libappletPopOutData.
*/
Result libappletLaunch(AppletId id, LibAppletArgs *commonargs, const void* arg, size_t arg_size, void* reply, size_t reply_size, size_t *out_reply_size);
/// Wrapper for \ref appletPushToGeneralChannel, see appletPushToGeneralChannel regarding the requirements for using this.
/// Returns to the main Home Menu, equivalent to pressing the HOME button.
Result libappletRequestHomeMenu(void);
/// Wrapper for \ref appletPushToGeneralChannel, see appletPushToGeneralChannel regarding the requirements for using this.
/// Equivalent to entering "System Update" under System Settings. When leaving this, it returns to the main Home Menu.
Result libappletRequestJumpToSystemUpdate(void);
/**
* @file pctlauth.h
* @brief Wrapper for using the Parental Controls authentication LibraryApplet. This applet is used by qlaunch.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/// Type values for PctlAuthArg::type.
typedef enum {
PctlAuthType_Show = 0, ///< ShowParentalAuthentication
PctlAuthType_RegisterPasscode = 1, ///< RegisterParentalPasscode
PctlAuthType_ChangePasscode = 2, ///< ChangeParentalPasscode
} PctlAuthType;
/// Input arg storage for the applet.
typedef struct {
u32 unk_x0; ///< Always set to 0 by the user-process.
PctlAuthType type; ///< \ref PctlAuthType
u8 arg0; ///< Arg0
u8 arg1; ///< Arg1
u8 arg2; ///< Arg2
u8 pad; ///< Padding
} PctlAuthArg;
/**
* @brief Launches the applet.
* @note Should not be used if a PIN is not already registered. See \ref pctlIsRestrictionEnabled.
* @param flag Input flag. false = temporarily disable Parental Controls. true = validate the input PIN.
*/
Result pctlauthShow(bool flag);
/**
* @brief Launches the applet. Only available with [4.0.0+].
* @param arg0 Value for PctlAuthArg.arg0.
* @param arg1 Value for PctlAuthArg.arg1.
* @param arg2 Value for PctlAuthArg.arg2.
*/
Result pctlauthShowEx(u8 arg0, u8 arg1, u8 arg2);
/**
* @brief Just calls: pctlauthShowEx(1, 0, 1). Launches the applet for checking the PIN, used when changing system-settings.
* @note Should not be used if a PIN is not already registered. See \ref pctlIsRestrictionEnabled.
*/
Result pctlauthShowForConfiguration(void);
/**
* @brief Launches the applet for registering the Parental Controls PIN.
*/
Result pctlauthRegisterPasscode(void);
/**
* @brief Launches the applet for changing the Parental Controls PIN.
* @note Should not be used if a PIN is not already registered. See \ref pctlIsRestrictionEnabled.
*/
Result pctlauthChangePasscode(void);
This diff is collapsed.
This diff is collapsed.
/**
* @file atomics.h
* @brief AArch64 atomic operations.
* @author plutoo
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/// Atomically increments a 32-bit value.
static inline u32 atomicIncrement32(u32* p) {
return __atomic_fetch_add(p, 1, __ATOMIC_SEQ_CST);
}
/// Atomically decrements a 32-bit value.
static inline u32 atomicDecrement32(u32* p) {
return __atomic_sub_fetch(p, 1, __ATOMIC_SEQ_CST);
}
/// Atomically increments a 64-bit value.
static inline u64 atomicIncrement64(u64* p) {
return __atomic_fetch_add(p, 1, __ATOMIC_SEQ_CST);
}
/// Atomically decrements a 64-bit value.
static inline u64 atomicDecrement64(u64* p) {
return __atomic_sub_fetch(p, 1, __ATOMIC_SEQ_CST);
}
/**
* @file counter.h
* @brief AArch64 system counter-timer.
* @author fincs
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/**
* @brief Gets the current system tick.
* @return The current system tick.
*/
static inline u64 armGetSystemTick(void) {
u64 ret;
__asm__ __volatile__ ("mrs %x[data], cntpct_el0" : [data] "=r" (ret));
return ret;
}
/**
* @brief Gets the system counter-timer frequency
* @return The system counter-timer frequency, in Hz.
*/
static inline u64 armGetSystemTickFreq(void) {
u64 ret;
__asm__ ("mrs %x[data], cntfrq_el0" : [data] "=r" (ret));
return ret;
}
/**
* @brief Converts from nanoseconds to CPU ticks unit.
* @param ns Time in nanoseconds.
* @return Time in CPU ticks.
*/
static inline u64 armNsToTicks(u64 ns) {
return (ns * 12) / 625;
}
/**
* @brief Converts from CPU ticks unit to nanoseconds.
* @param tick Time in ticks.
* @return Time in nanoseconds.
*/
static inline u64 armTicksToNs(u64 tick) {
return (tick * 625) / 12;
}
/**
* @file thread_context.h
* @brief AArch64 register dump format and related definitions.
* @author TuxSH
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/// Armv8 CPU register.
typedef union {
u64 x; ///< 64-bit AArch64 register view.
u32 w; ///< 32-bit AArch64 register view.
u32 r; ///< AArch32 register view.
} CpuRegister;
/// Armv8 NEON register.
typedef union {
u128 v; ///< 128-bit vector view.
double d; ///< 64-bit double-precision view.
float s; ///< 32-bit single-precision view.
} FpuRegister;
/// Armv8 register group. @ref svcGetThreadContext3 uses @ref RegisterGroup_All.
typedef enum {
RegisterGroup_CpuGprs = BIT(0), ///< General-purpose CPU registers (x0..x28 or r0..r10,r12).
RegisterGroup_CpuSprs = BIT(1), ///< Special-purpose CPU registers (fp, lr, sp, pc, PSTATE or cpsr, TPIDR_EL0).
RegisterGroup_FpuGprs = BIT(2), ///< General-purpose NEON registers.
RegisterGroup_FpuSprs = BIT(3), ///< Special-purpose NEON registers.
RegisterGroup_CpuAll = RegisterGroup_CpuGprs | RegisterGroup_CpuSprs, ///< All CPU registers.
RegisterGroup_FpuAll = RegisterGroup_FpuGprs | RegisterGroup_FpuSprs, ///< All NEON registers.
RegisterGroup_All = RegisterGroup_CpuAll | RegisterGroup_FpuAll, ///< All registers.
} RegisterGroup;
/// This is for \ref ThreadExceptionDump error_desc.
typedef enum {
ThreadExceptionDesc_InstructionAbort = 0x100, ///< Instruction abort
ThreadExceptionDesc_MisalignedPC = 0x102, ///< Misaligned PC
ThreadExceptionDesc_MisalignedSP = 0x103, ///< Misaligned SP
ThreadExceptionDesc_SError = 0x106, ///< SError [not in 1.0.0?]
ThreadExceptionDesc_BadSVC = 0x301, ///< Bad SVC
ThreadExceptionDesc_Trap = 0x104, ///< Uncategorized, CP15RTTrap, CP15RRTTrap, CP14RTTrap, CP14RRTTrap, IllegalState, SystemRegisterTrap
ThreadExceptionDesc_Other = 0x101, ///< None of the above, EC <= 0x34 and not a breakpoint
} ThreadExceptionDesc;
/// Thread context structure (register dump)
typedef struct {
CpuRegister cpu_gprs[29]; ///< GPRs 0..28. Note: also contains AArch32 SPRs.
u64 fp; ///< Frame pointer (x29) (AArch64). For AArch32, check r11.
u64 lr; ///< Link register (x30) (AArch64). For AArch32, check r14.
u64 sp; ///< Stack pointer (AArch64). For AArch32, check r13.
CpuRegister pc; ///< Program counter.
u32 psr; ///< PSTATE or cpsr.
FpuRegister fpu_gprs[32]; ///< 32 general-purpose NEON registers.
u32 fpcr; ///< Floating-point control register.
u32 fpsr; ///< Floating-point status register.
u64 tpidr; ///< EL0 Read/Write Software Thread ID Register.
} ThreadContext;
/// Thread exception dump structure.
typedef struct {
u32 error_desc; ///< See \ref ThreadExceptionDesc.
u32 pad[3];
CpuRegister cpu_gprs[29]; ///< GPRs 0..28. Note: also contains AArch32 registers.
CpuRegister fp; ///< Frame pointer.
CpuRegister lr; ///< Link register.
CpuRegister sp; ///< Stack pointer.
CpuRegister pc; ///< Program counter (elr_el1).
u64 padding;
FpuRegister fpu_gprs[32]; ///< 32 general-purpose NEON registers.
u32 pstate; ///< pstate & 0xFF0FFE20
u32 afsr0;
u32 afsr1;
u32 esr;
CpuRegister far; ///< Fault Address Register.
} ThreadExceptionDump;
typedef struct {
u64 cpu_gprs[9]; ///< GPRs 0..8.
u64 lr;
u64 sp;
u64 elr_el1;
u32 pstate; ///< pstate & 0xFF0FFE20
u32 afsr0;
u32 afsr1;
u32 esr;
u64 far;
} ThreadExceptionFrameA64;
typedef struct {
u32 cpu_gprs[8]; ///< GPRs 0..7.
u32 sp;
u32 lr;
u32 elr_el1;
u32 tpidr_el0; ///< tpidr_el0 = 1
u32 cpsr; ///< cpsr & 0xFF0FFE20
u32 afsr0;
u32 afsr1;
u32 esr;
u32 far;
} ThreadExceptionFrameA32;
/**
* @brief Determines whether a thread context belong to an AArch64 process based on the PSR.
* @param[in] ctx Thread context to which PSTATE/cspr has been dumped to.
* @return true if and only if the thread context belongs to an AArch64 process.
*/
static inline bool threadContextIsAArch64(const ThreadContext *ctx)
{
return (ctx->psr & 0x10) == 0;
}
/**
* @brief Determines whether a ThreadExceptionDump belongs to an AArch64 process based on the PSTATE.
* @param[in] ctx ThreadExceptionDump.
* @return true if and only if the ThreadExceptionDump belongs to an AArch64 process.
*/
static inline bool threadExceptionIsAArch64(const ThreadExceptionDump *ctx)
{
return (ctx->pstate & 0x10) == 0;
}
......@@ -8,6 +8,7 @@
#include "../types.h"
/// PcmFormat
typedef enum {
PcmFormat_Invalid = 0,
PcmFormat_Int8 = 1,
......@@ -17,3 +18,8 @@ typedef enum {
PcmFormat_Float = 5,
PcmFormat_Adpcm = 6,
} PcmFormat;
/// AudioDeviceName
typedef struct {
char name[0x100];
} AudioDeviceName;
/**
* @file driver.h
* @brief Audio driver (audren wrapper).
* @author fincs
* @copyright libnx Authors
*/
#pragma once
#include "../services/audren.h"
typedef struct AudioDriverEtc AudioDriverEtc;
typedef struct {
AudioDriverEtc* etc;
AudioRendererConfig config;
AudioRendererMemPoolInfoIn* in_mempools;
AudioRendererChannelInfoIn* in_channels;
AudioRendererVoiceInfoIn* in_voices;
AudioRendererMixInfoIn* in_mixes;
AudioRendererSinkInfoIn* in_sinks;
} AudioDriver;
Result audrvCreate(AudioDriver* d, const AudioRendererConfig* config, int num_final_mix_channels);
Result audrvUpdate(AudioDriver* d);
void audrvClose(AudioDriver* d);
//-----------------------------------------------------------------------------
int audrvMemPoolAdd(AudioDriver* d, void* buffer, size_t size);
bool audrvMemPoolRemove(AudioDriver* d, int id);
bool audrvMemPoolAttach(AudioDriver* d, int id);
bool audrvMemPoolDetach(AudioDriver* d, int id);
//-----------------------------------------------------------------------------
typedef enum {
AudioDriverWaveBufState_Free,
AudioDriverWaveBufState_Waiting,
AudioDriverWaveBufState_Queued,
AudioDriverWaveBufState_Playing,
AudioDriverWaveBufState_Done,
} AudioDriverWaveBufState;
typedef struct AudioDriverWaveBuf AudioDriverWaveBuf;
struct AudioDriverWaveBuf {
union {
s16* data_pcm16;
u8* data_adpcm;
const void* data_raw;
};
u64 size;
s32 start_sample_offset;
s32 end_sample_offset;
const void* context_addr;
u64 context_sz;
AudioDriverWaveBufState state : 8;
bool is_looping;
u32 sequence_id;
AudioDriverWaveBuf* next;
};
bool audrvVoiceInit(AudioDriver* d, int id, int num_channels, PcmFormat format, int sample_rate);
void audrvVoiceDrop(AudioDriver* d, int id);
void audrvVoiceStop(AudioDriver* d, int id);
bool audrvVoiceIsPlaying(AudioDriver* d, int id);
bool audrvVoiceAddWaveBuf(AudioDriver* d, int id, AudioDriverWaveBuf* wavebuf);
u32 audrvVoiceGetWaveBufSeq(AudioDriver* d, int id);
u32 audrvVoiceGetPlayedSampleCount(AudioDriver* d, int id);
u32 audrvVoiceGetVoiceDropsCount(AudioDriver* d, int id);
void audrvVoiceSetBiquadFilter(AudioDriver* d, int id, int biquad_id, float a0, float a1, float a2, float b0, float b1, float b2);
static inline void audrvVoiceSetExtraParams(AudioDriver* d, int id, const void* params, size_t params_size)
{
d->in_voices[id].extra_params_ptr = params;
d->in_voices[id].extra_params_sz = params_size;
}
static inline void audrvVoiceSetDestinationMix(AudioDriver* d, int id, int mix_id)
{
d->in_voices[id].dest_mix_id = mix_id;
d->in_voices[id].dest_splitter_id = AUDREN_UNUSED_SPLITTER_ID;
}
static inline void audrvVoiceSetMixFactor(AudioDriver* d, int id, float factor, int src_channel_id, int dest_channel_id)
{
int channel_id = d->in_voices[id].channel_ids[src_channel_id];
d->in_channels[channel_id].mix[dest_channel_id] = factor;
}
static inline void audrvVoiceSetVolume(AudioDriver* d, int id, float volume)
{
d->in_voices[id].volume = volume;
}
static inline void audrvVoiceSetPitch(AudioDriver* d, int id, float pitch)
{
d->in_voices[id].pitch = pitch;
}
static inline void audrvVoiceSetPriority(AudioDriver* d, int id, int priority)
{
d->in_voices[id].priority = priority;
}
static inline void audrvVoiceClearBiquadFilter(AudioDriver* d, int id, int biquad_id)
{
d->in_voices[id].biquads[biquad_id].enable = false;
}
static inline void audrvVoiceSetPaused(AudioDriver* d, int id, bool paused)
{
d->in_voices[id].state = paused ? AudioRendererVoicePlayState_Paused : AudioRendererVoicePlayState_Started;
}
static inline void audrvVoiceStart(AudioDriver* d, int id)
{
audrvVoiceSetPaused(d, id, false);
}
//-----------------------------------------------------------------------------
int audrvMixAdd(AudioDriver* d, int sample_rate, int num_channels);
void audrvMixRemove(AudioDriver* d, int id);
static inline void audrvMixSetDestinationMix(AudioDriver* d, int id, int mix_id)
{
d->in_mixes[id].dest_mix_id = mix_id;
d->in_mixes[id].dest_splitter_id = AUDREN_UNUSED_SPLITTER_ID;
}
static inline void audrvMixSetMixFactor(AudioDriver* d, int id, float factor, int src_channel_id, int dest_channel_id)
{
d->in_mixes[id].mix[src_channel_id][dest_channel_id] = factor;
}
static inline void audrvMixSetVolume(AudioDriver* d, int id, float volume)
{
d->in_mixes[id].volume = volume;
}
//-----------------------------------------------------------------------------
int audrvDeviceSinkAdd(AudioDriver* d, const char* device_name, int num_channels, const u8* channel_ids);
void audrvSinkRemove(AudioDriver* d, int id);
/**
* @file aes.h
* @brief Hardware accelerated AES-ECB implementation.
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#ifndef AES_BLOCK_SIZE
#define AES_BLOCK_SIZE 0x10
#endif
#ifndef AES_128_KEY_SIZE
#define AES_128_KEY_SIZE 0x10
#endif
#ifndef AES_128_U32_PER_KEY
#define AES_128_U32_PER_KEY (AES_128_KEY_SIZE / sizeof(u32))
#endif
#ifndef AES_128_NUM_ROUNDS
#define AES_128_NUM_ROUNDS 10
#endif
#ifndef AES_192_KEY_SIZE
#define AES_192_KEY_SIZE 0x18
#endif
#ifndef AES_192_U32_PER_KEY
#define AES_192_U32_PER_KEY (AES_192_KEY_SIZE / sizeof(u32))
#endif
#ifndef AES_192_NUM_ROUNDS
#define AES_192_NUM_ROUNDS 12
#endif
#ifndef AES_256_KEY_SIZE
#define AES_256_KEY_SIZE 0x20
#endif
#ifndef AES_256_U32_PER_KEY
#define AES_256_U32_PER_KEY (AES_256_KEY_SIZE / sizeof(u32))
#endif
#ifndef AES_256_NUM_ROUNDS
#define AES_256_NUM_ROUNDS 14
#endif
/// Context for AES-128 operations.
typedef struct {
u8 round_keys[AES_128_NUM_ROUNDS+1][AES_BLOCK_SIZE];
} Aes128Context;
/// Context for AES-192 operations.
typedef struct {
u8 round_keys[AES_192_NUM_ROUNDS+1][AES_BLOCK_SIZE];
} Aes192Context;
/// Context for AES-256 operations.
typedef struct {
u8 round_keys[AES_256_NUM_ROUNDS+1][AES_BLOCK_SIZE];
} Aes256Context;
/// Initialize a 128-bit AES context.
void aes128ContextCreate(Aes128Context *out, const void *key, bool is_encryptor);
/// Encrypt using an AES context (Requires is_encryptor when initializing)
void aes128EncryptBlock(const Aes128Context *ctx, void *dst, const void *src);
/// Decrypt using an AES context (Requires !is_encryptor when initializing)
void aes128DecryptBlock(const Aes128Context *ctx, void *dst, const void *src);
/// Initialize a 192-bit AES context.
void aes192ContextCreate(Aes192Context *out, const void *key, bool is_encryptor);
/// Encrypt using an AES context (Requires is_encryptor when initializing)
void aes192EncryptBlock(const Aes192Context *ctx, void *dst, const void *src);
/// Decrypt using an AES context (Requires !is_encryptor when initializing)
void aes192DecryptBlock(const Aes192Context *ctx, void *dst, const void *src);
/// Initialize a 256-bit AES context.
void aes256ContextCreate(Aes256Context *out, const void *key, bool is_encryptor);
/// Encrypt using an AES context (Requires is_encryptor when initializing)
void aes256EncryptBlock(const Aes256Context *ctx, void *dst, const void *src);
/// Decrypt using an AES context (Requires !is_encryptor when initializing)
void aes256DecryptBlock(const Aes256Context *ctx, void *dst, const void *src);
/**
* @file aes_cbc.h
* @brief Hardware accelerated AES-CBC implementation.
* @copyright libnx Authors
*/
#pragma once
#include "aes.h"
/// Context for AES-128 CBC.
typedef struct {
Aes128Context aes_ctx;
u8 iv[AES_BLOCK_SIZE];
u8 buffer[AES_BLOCK_SIZE];
size_t num_buffered;
} Aes128CbcContext;
/// Context for AES-192 CBC.
typedef struct {
Aes192Context aes_ctx;
u8 iv[AES_BLOCK_SIZE];
u8 buffer[AES_BLOCK_SIZE];
size_t num_buffered;
} Aes192CbcContext;
/// Context for AES-256 CBC.
typedef struct {
Aes256Context aes_ctx;
u8 iv[AES_BLOCK_SIZE];
u8 buffer[AES_BLOCK_SIZE];
size_t num_buffered;
} Aes256CbcContext;
/// 128-bit CBC API.
void aes128CbcContextCreate(Aes128CbcContext *out, const void *key, const void *iv, bool is_encryptor);
void aes128CbcContextResetIv(Aes128CbcContext *ctx, const void *iv);
size_t aes128CbcEncrypt(Aes128CbcContext *ctx, void *dst, const void *src, size_t size);
size_t aes128CbcDecrypt(Aes128CbcContext *ctx, void *dst, const void *src, size_t size);
/// 192-bit CBC API.
void aes192CbcContextCreate(Aes192CbcContext *out, const void *key, const void *iv, bool is_encryptor);
void aes192CbcContextResetIv(Aes192CbcContext *ctx, const void *iv);
size_t aes192CbcEncrypt(Aes192CbcContext *ctx, void *dst, const void *src, size_t size);
size_t aes192CbcDecrypt(Aes192CbcContext *ctx, void *dst, const void *src, size_t size);
/// 256-bit CBC API.
void aes256CbcContextCreate(Aes256CbcContext *out, const void *key, const void *iv, bool is_encryptor);
void aes256CbcContextResetIv(Aes256CbcContext *ctx, const void *iv);
size_t aes256CbcEncrypt(Aes256CbcContext *ctx, void *dst, const void *src, size_t size);
size_t aes256CbcDecrypt(Aes256CbcContext *ctx, void *dst, const void *src, size_t size);
/**
* @file aes_ctr.h
* @brief Hardware accelerated AES-CTR implementation.
* @copyright libnx Authors
*/
#pragma once
#include "aes.h"
/// Context for AES-128 CTR.
typedef struct {
Aes128Context aes_ctx;
u8 ctr[AES_BLOCK_SIZE];
u8 enc_ctr_buffer[AES_BLOCK_SIZE];
size_t buffer_offset;
} Aes128CtrContext;
/// Context for AES-192 CTR.
typedef struct {
Aes192Context aes_ctx;
u8 ctr[AES_BLOCK_SIZE];
u8 enc_ctr_buffer[AES_BLOCK_SIZE];
size_t buffer_offset;
} Aes192CtrContext;
/// Context for AES-256 CTR.
typedef struct {
Aes256Context aes_ctx;
u8 ctr[AES_BLOCK_SIZE];
u8 enc_ctr_buffer[AES_BLOCK_SIZE];
size_t buffer_offset;
} Aes256CtrContext;
/// 128-bit CTR API.
void aes128CtrContextCreate(Aes128CtrContext *out, const void *key, const void *ctr);
void aes128CtrContextResetCtr(Aes128CtrContext *ctx, const void *ctr);
void aes128CtrCrypt(Aes128CtrContext *ctx, void *dst, const void *src, size_t size);
/// 192-bit CTR API.
void aes192CtrContextCreate(Aes192CtrContext *out, const void *key, const void *ctr);
void aes192CtrContextResetCtr(Aes192CtrContext *ctx, const void *ctr);
void aes192CtrCrypt(Aes192CtrContext *ctx, void *dst, const void *src, size_t size);
/// 256-bit CTR API.
void aes256CtrContextCreate(Aes256CtrContext *out, const void *key, const void *ctr);
void aes256CtrContextResetCtr(Aes256CtrContext *ctx, const void *ctr);
void aes256CtrCrypt(Aes256CtrContext *ctx, void *dst, const void *src, size_t size);
/**
* @file aes_xts.h
* @brief Hardware accelerated AES-XTS implementation.
* @copyright libnx Authors
*/
#pragma once
#include "aes.h"
/// Context for AES-128 XTS.
typedef struct {
Aes128Context aes_ctx;
Aes128Context tweak_ctx;
u8 tweak[AES_BLOCK_SIZE];
u8 buffer[AES_BLOCK_SIZE];
size_t num_buffered;
} Aes128XtsContext;
/// Context for AES-192 XTS.
typedef struct {
Aes192Context aes_ctx;
Aes192Context tweak_ctx;
u8 tweak[AES_BLOCK_SIZE];
u8 buffer[AES_BLOCK_SIZE];
size_t num_buffered;
} Aes192XtsContext;
/// Context for AES-256 XTS.
typedef struct {
Aes256Context aes_ctx;
Aes256Context tweak_ctx;
u8 tweak[AES_BLOCK_SIZE];
u8 buffer[AES_BLOCK_SIZE];
size_t num_buffered;
} Aes256XtsContext;
/// 128-bit XTS API.
void aes128XtsContextCreate(Aes128XtsContext *out, const void *key0, const void *key1, bool is_encryptor);
void aes128XtsContextResetTweak(Aes128XtsContext *ctx, const void *tweak);
void aes128XtsContextResetSector(Aes128XtsContext *ctx, uint64_t sector, bool is_nintendo);
size_t aes128XtsEncrypt(Aes128XtsContext *ctx, void *dst, const void *src, size_t size);
size_t aes128XtsDecrypt(Aes128XtsContext *ctx, void *dst, const void *src, size_t size);
/// 192-bit XTS API.
void aes192XtsContextCreate(Aes192XtsContext *out, const void *key0, const void *key1, bool is_encryptor);
void aes192XtsContextResetTweak(Aes192XtsContext *ctx, const void *tweak);
void aes192XtsContextResetSector(Aes192XtsContext *ctx, uint64_t sector, bool is_nintendo);
size_t aes192XtsEncrypt(Aes192XtsContext *ctx, void *dst, const void *src, size_t size);
size_t aes192XtsDecrypt(Aes192XtsContext *ctx, void *dst, const void *src, size_t size);
/// 256-bit XTS API.
void aes256XtsContextCreate(Aes256XtsContext *out, const void *key0, const void *key1, bool is_encryptor);
void aes256XtsContextResetTweak(Aes256XtsContext *ctx, const void *tweak);
void aes256XtsContextResetSector(Aes256XtsContext *ctx, uint64_t sector, bool is_nintendo);
size_t aes256XtsEncrypt(Aes256XtsContext *ctx, void *dst, const void *src, size_t size);
size_t aes256XtsDecrypt(Aes256XtsContext *ctx, void *dst, const void *src, size_t size);
/**
* @file cmac.h
* @brief Hardware accelerated AES-CMAC implementation.
* @copyright libnx Authors
*/
#pragma once
#include "aes.h"
/// Context for AES-128 CMAC.
typedef struct {
Aes128Context ctx;
u8 subkey[AES_BLOCK_SIZE];
u8 mac[AES_BLOCK_SIZE];
u8 buffer[AES_BLOCK_SIZE];
size_t num_buffered;
bool finalized;
} Aes128CmacContext;
/// Context for AES-192 CMAC.
typedef struct {
Aes192Context ctx;
u8 subkey[AES_BLOCK_SIZE];
u8 mac[AES_BLOCK_SIZE];
u8 buffer[AES_BLOCK_SIZE];
size_t num_buffered;
bool finalized;
} Aes192CmacContext;
/// Context for AES-256 CMAC.
typedef struct {
Aes256Context ctx;
u8 subkey[AES_BLOCK_SIZE];
u8 mac[AES_BLOCK_SIZE];
u8 buffer[AES_BLOCK_SIZE];
size_t num_buffered;
bool finalized;
} Aes256CmacContext;
/// Initialize an AES-128-CMAC context.
void cmacAes128ContextCreate(Aes128CmacContext *out, const void *key);
/// Updates AES-128-CMAC context with data to hash
void cmacAes128ContextUpdate(Aes128CmacContext *ctx, const void *src, size_t size);
/// Gets the context's output mac, finalizes the context.
void cmacAes128ContextGetMac(Aes128CmacContext *ctx, void *dst);
/// Simple all-in-one AES-128-CMAC calculator.
void cmacAes128CalculateMac(void *dst, const void *key, const void *src, size_t size);
/// Initialize an AES-192-CMAC context.
void cmacAes192ContextCreate(Aes192CmacContext *out, const void *key);
/// Updates AES-192-CMAC context with data to hash
void cmacAes192ContextUpdate(Aes192CmacContext *ctx, const void *src, size_t size);
/// Gets the context's output mac, finalizes the context.
void cmacAes192ContextGetMac(Aes192CmacContext *ctx, void *dst);
/// Simple all-in-one AES-192-CMAC calculator.
void cmacAes192CalculateMac(void *dst, const void *key, const void *src, size_t size);
/// Initialize an AES-256-CMAC context.
void cmacAes256ContextCreate(Aes256CmacContext *out, const void *key);
/// Updates AES-256-CMAC context with data to hash
void cmacAes256ContextUpdate(Aes256CmacContext *ctx, const void *src, size_t size);
/// Gets the context's output mac, finalizes the context.
void cmacAes256ContextGetMac(Aes256CmacContext *ctx, void *dst);
/// Simple all-in-one AES-256-CMAC calculator.
void cmacAes256CalculateMac(void *dst, const void *key, const void *src, size_t size);
/**
* @file crc.h
* @brief Hardware accelerated CRC32 implementation.
* @copyright libnx Authors
*/
#pragma once
#include <arm_acle.h>
#include "../types.h"
#define _CRC_ALIGN(sz, insn) \
do { \
if (((uintptr_t)src_u8 & sizeof(sz)) && (u64)len >= sizeof(sz)) { \
crc = __crc32##insn(crc, *((const sz *)src_u8)); \
src_u8 += sizeof(sz); \
len -= sizeof(sz); \
} \
} while (0)
#define _CRC_REMAINDER(sz, insn) \
do { \
if (len & sizeof(sz)) { \
crc = __crc32##insn(crc, *((const sz *)src_u8)); \
src_u8 += sizeof(sz); \
} \
} while (0)
/// Calculate a CRC32 over data.
static inline u32 crc32Calculate(const void *src, size_t size) {
const u8 *src_u8 = (const u8 *)src;
u32 crc = 0xFFFFFFFF;
s64 len = size;
_CRC_ALIGN(u8, b);
_CRC_ALIGN(u16, h);
_CRC_ALIGN(u32, w);
while ((len -= sizeof(u64)) >= 0) {
crc = __crc32d(crc, *((const u64 *)src_u8));
src_u8 += sizeof(