...
 
Commits (8)
image: devkitpro/devkita64:latest
stages:
- package
- create image
package:
stage: package
before_script:
- 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
......@@ -33,7 +33,7 @@ INCLUDES := include external/bsd/include
#---------------------------------------------------------------------------------
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) \
......@@ -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
......
......@@ -58,6 +58,7 @@ extern "C" {
#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 switch/runtime/devices/socket.h instead
......
......@@ -301,6 +301,22 @@ Result appletHomeButtonReaderLockAccessorGetEvent(Event *out_event);
*/
Result appletPushToGeneralChannel(AppletStorage *s);
/**
* @brief Gets whether VrMode is enabled.
* @note Only available with [3.0.0+].
* @param out Output flag
*/
Result appletIsVrModeEnabled(bool *out);
/**
* @brief Sets whether VrMode is enabled.
* @note This is only fully usable system-side with [6.0.0+].
* @note For checking Parental Controls, see \ref pctlIsStereoVisionPermitted.
* @note On pre-7.0.0 this uses cmd SetVrModeEnabled internally, while on [7.0.0+] this uses cmds BeginVrModeEx/EndVrModeEx.
* @param flag Flag
*/
Result appletSetVrModeEnabled(bool flag);
/**
* @brief Sets the \ref ApmCpuBoostMode.
* @note Only available with [7.0.0+] (not fully usable system-side with 6.x).
......
/**
* @file clkrst.h
* @brief Clkrst service IPC wrapper.
* @author p-sam
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../services/sm.h"
#include "../services/pcv.h"
typedef struct {
Service s;
} ClkrstSession;
Result clkrstInitialize(void);
void clkrstExit(void);
/// Opens a ClkrstSession for the requested PcvModuleId, unk is set to 3 in official sysmodules.
Result clkrstOpenSession(ClkrstSession* session_out, PcvModuleId module_id, u32 unk);
void clkrstCloseSession(ClkrstSession* session);
Result clkrstSetClockRate(ClkrstSession* session, u32 hz);
Result clkrstGetClockRate(ClkrstSession* session, u32 *out_hz);
......@@ -42,7 +42,7 @@ Result ldrShellClearLaunchQueue(void);
Result ldrDmntAddTitleToLaunchQueue(u64 tid, const void *args, size_t args_size);
Result ldrDmntClearLaunchQueue(void);
Result ldrDmntGetModuleInfos(u64 pid, LoaderModuleInfo *out_module_infos, size_t out_size, u32 *num_out);
Result ldrDmntGetModuleInfos(u64 pid, LoaderModuleInfo *out_module_infos, size_t max_out_modules, 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);
......
......@@ -12,9 +12,15 @@
Result pctlInitialize(void);
void pctlExit(void);
/// Confirm whether VrMode is allowed. Only available with [4.0.0+].
Result pctlConfirmStereoVisionPermission(void);
/// Gets whether Parental Controls are enabled.
Result pctlIsRestrictionEnabled(bool *flag);
/// Reset the confirmation done by \ref pctlConfirmStereoVisionPermission. Only available with [5.0.0+].
Result pctlResetConfirmedStereoVisionPermission(void);
/// Gets whether VrMode is allowed. Only available with [5.0.0+].
Result pctlIsStereoVisionPermitted(bool *flag);
......@@ -13,6 +13,93 @@ typedef enum {
PcvModule_Emc = 56,
} PcvModule;
/// Module id returned by [8.0.0+] pcv services
/// See also: https://switchbrew.org/wiki/PCV_services#Modules
typedef enum {
PcvModuleId_CpuBus = 0x40000001,
PcvModuleId_GPU = 0x40000002,
PcvModuleId_I2S1 = 0x40000003,
PcvModuleId_I2S2 = 0x40000004,
PcvModuleId_I2S3 = 0x40000005,
PcvModuleId_PWM = 0x40000006,
PcvModuleId_I2C1 = 0x02000001,
PcvModuleId_I2C2 = 0x02000002,
PcvModuleId_I2C3 = 0x02000003,
PcvModuleId_I2C4 = 0x02000004,
PcvModuleId_I2C5 = 0x02000005,
PcvModuleId_I2C6 = 0x02000006,
PcvModuleId_SPI1 = 0x07000000,
PcvModuleId_SPI2 = 0x07000001,
PcvModuleId_SPI3 = 0x07000002,
PcvModuleId_SPI4 = 0x07000003,
PcvModuleId_DISP1 = 0x40000011,
PcvModuleId_DISP2 = 0x40000012,
PcvModuleId_SDMMC1 = 0x40000015,
PcvModuleId_SDMMC2 = 0x40000016,
PcvModuleId_SDMMC3 = 0x40000017,
PcvModuleId_SDMMC4 = 0x40000018,
PcvModuleId_CSITE = 0x4000001A,
PcvModuleId_TSEC = 0x4000001B,
PcvModuleId_MSELECT = 0x4000001C,
PcvModuleId_HDA2CODEC_2X = 0x4000001D,
PcvModuleId_ACTMON = 0x4000001E,
PcvModuleId_I2C_SLOW = 0x4000001F,
PcvModuleId_SOR1 = 0x40000020,
PcvModuleId_HDA = 0x40000022,
PcvModuleId_XUSB_CORE_HOST = 0x40000023,
PcvModuleId_XUSB_FALCON = 0x40000024,
PcvModuleId_XUSB_FS = 0x40000025,
PcvModuleId_XUSB_CORE_DEV = 0x40000026,
PcvModuleId_XUSB_SS_HOSTDEV = 0x40000027,
PcvModuleId_UARTA = 0x03000001,
PcvModuleId_UARTB = 0x35000405,
PcvModuleId_UARTC = 0x3500040F,
PcvModuleId_UARTD = 0x37000001,
PcvModuleId_HOST1X = 0x4000002C,
PcvModuleId_ENTROPY = 0x4000002D,
PcvModuleId_SOC_THERM = 0x4000002E,
PcvModuleId_VIC = 0x4000002F,
PcvModuleId_NVENC = 0x40000030,
PcvModuleId_NVJPG = 0x40000031,
PcvModuleId_NVDEC = 0x40000032,
PcvModuleId_QSPI = 0x40000033,
PcvModuleId_TSECB = 0x40000035,
PcvModuleId_APE = 0x40000036,
PcvModuleId_ACLK = 0x40000037,
PcvModuleId_UARTAPE = 0x40000038,
PcvModuleId_EMC = 0x40000039,
PcvModuleId_PLLE0_0 = 0x4000003A,
PcvModuleId_PLLE0_1 = 0x4000003B,
PcvModuleId_DSI = 0x4000003C,
PcvModuleId_MAUD = 0x4000003D,
PcvModuleId_DPAUX1 = 0x4000003E,
PcvModuleId_MIPI_CAL = 0x4000003F,
PcvModuleId_UART_FST_MIPI_CAL = 0x40000040,
PcvModuleId_OSC = 0x40000041,
PcvModuleId_SCLK = 0x40000042,
PcvModuleId_SOR_SAFE = 0x40000043,
PcvModuleId_XUSB_SS = 0x40000044,
PcvModuleId_XUSB_HOST = 0x40000045,
PcvModuleId_XUSB_DEV = 0x40000046,
PcvModuleId_EXTPERIPH1 = 0x40000047,
PcvModuleId_AHUB = 0x40000048,
PcvModuleId_HDA2HDMICODEC = 0x40000049,
PcvModuleId_PLLP5 = 0x4000004A,
PcvModuleId_USBD = 0x4000004B,
PcvModuleId_USB2 = 0x4000004C,
PcvModuleId_PCIE = 0x4000004D,
PcvModuleId_AFI = 0x4000004E,
PcvModuleId_PCIEXCLK = 0x4000004F,
PcvModuleId_PEX_USB_UPHY = 0x40000050,
PcvModuleId_XUSB_PADCTL = 0x40000051,
PcvModuleId_APBDMA = 0x40000052,
PcvModuleId_USB2_TRK = 0x40000053,
PcvModuleId_PLLE0_2 = 0x40000054,
PcvModuleId_PLLE0_3 = 0x40000055,
PcvModuleId_CEC = 0x40000056,
PcvModuleId_EXTPERIPH2 = 0x40000057,
} PcvModuleId;
Result pcvInitialize(void);
void pcvExit(void);
......@@ -20,4 +107,3 @@ Result pcvGetClockRate(PcvModule module, u32 *out_hz);
Result pcvSetClockRate(PcvModule module, u32 hz);
Result pcvSetVoltageEnabled(bool state, u32 voltage);
Result pcvGetVoltageEnabled(bool *isEnabled, u32 voltage);
......@@ -12,6 +12,9 @@
Result ldrRoInitialize(void);
void ldrRoExit(void);
Result ro1Initialize(void);
void ro1Exit(void);
Result roDmntInitialize(void);
void roDmntExit(void);
......@@ -19,5 +22,12 @@ Result ldrRoLoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_add
Result ldrRoUnloadNro(u64 nro_address);
Result ldrRoLoadNrr(u64 nrr_address, u64 nrr_size);
Result ldrRoUnloadNrr(u64 nrr_address);
Result ldrRoLoadNrrEx(u64 nrr_address, u64 nrr_size);
Result ro1LoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size);
Result ro1UnloadNro(u64 nro_address);
Result ro1LoadNrr(u64 nrr_address, u64 nrr_size);
Result ro1UnloadNrr(u64 nrr_address);
Result ro1LoadNrrEx(u64 nrr_address, u64 nrr_size);
Result roDmntGetModuleInfos(u64 pid, LoaderModuleInfo *out_module_infos, size_t out_size, u32 *num_out);
Result roDmntGetModuleInfos(u64 pid, LoaderModuleInfo *out_module_infos, size_t max_out_modules, u32 *num_out);
......@@ -1670,6 +1670,23 @@ Result appletPushToGeneralChannel(AppletStorage *s) {
return _appletCmdInStorage(&g_appletICommonStateGetter, s, 20);
}
Result appletIsVrModeEnabled(bool *out) {
if (hosversionBefore(3,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _appletCmdNoInOutBool(&g_appletICommonStateGetter, out, 50);
}
Result appletSetVrModeEnabled(bool flag) {
if (hosversionBefore(6,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
if (hosversionBefore(7,0,0))
return _appletCmdInBool(&g_appletICommonStateGetter, flag, 51);
return _appletCmdNoIO(&g_appletICommonStateGetter, flag ? 53 : 54);
}
Result appletSetCpuBoostMode(ApmCpuBoostMode mode) {
Result rc=0;
if (hosversionBefore(7,0,0))
......
#include "types.h"
#include "result.h"
#include "arm/atomics.h"
#include "kernel/ipc.h"
#include "services/pcv.h"
#include "runtime/hosversion.h"
#include "services/sm.h"
#include "services/clkrst.h"
static Service g_clkrstSrv;
static u64 g_refCnt;
Result clkrstInitialize(void) {
if(hosversionBefore(8,0,0)) {
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
}
atomicIncrement64(&g_refCnt);
if (serviceIsActive(&g_clkrstSrv)) {
return 0;
}
Result rc = smGetService(&g_clkrstSrv, "clkrst");
if (R_FAILED(rc)) {
clkrstExit();
}
return rc;
}
void clkrstExit(void) {
if (atomicDecrement64(&g_refCnt) == 0) {
serviceClose(&g_clkrstSrv);
}
}
Result clkrstOpenSession(ClkrstSession* session_out, PcvModuleId module_id, u32 unk) {
IpcCommand c;
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
u32 module_id;
u32 unk;
} *raw;
raw = ipcPrepareHeader(&c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 0;
raw->module_id = module_id;
raw->unk = unk;
Result rc = serviceIpcDispatch(&g_clkrstSrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
ipcParse(&r);
struct {
u64 magic;
u64 result;
} *resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc)) {
serviceCreate(&session_out->s, r.Handles[0]);
}
}
return rc;
}
void clkrstCloseSession(ClkrstSession* session) {
serviceClose(&session->s);
}
Result clkrstSetClockRate(ClkrstSession* session, u32 hz) {
IpcCommand c;
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
u32 hz;
} *raw;
raw = serviceIpcPrepareHeader(&session->s, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 7;
raw->hz = hz;
Result rc = serviceIpcDispatch(&session->s);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
} *resp;
serviceIpcParse(&session->s, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
}
return rc;
}
Result clkrstGetClockRate(ClkrstSession* session, u32 *out_hz) {
IpcCommand c;
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
} *raw;
raw = serviceIpcPrepareHeader(&session->s, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 8;
Result rc = serviceIpcDispatch(&session->s);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
u32 hz;
} *resp;
serviceIpcParse(&session->s, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc)) {
*out_hz = resp->hz;
}
}
return rc;
}
......@@ -132,11 +132,11 @@ Result ldrDmntClearLaunchQueue(void) {
return _ldrClearLaunchQueue(&g_dmntSrv);
}
Result ldrDmntGetModuleInfos(u64 pid, LoaderModuleInfo *out_module_infos, size_t out_size, u32 *num_out) {
Result ldrDmntGetModuleInfos(u64 pid, LoaderModuleInfo *out_module_infos, size_t max_out_modules, u32 *num_out) {
IpcCommand c;
ipcInitialize(&c);
ipcAddRecvStatic(&c, out_module_infos, out_size, 0);
ipcAddRecvStatic(&c, out_module_infos, max_out_modules * sizeof(*out_module_infos), 0);
struct {
u64 magic;
......
......@@ -150,10 +150,24 @@ static Result _pctlNoInputOutBool(u64 cmd_id, bool *flag) {
return rc;
}
Result pctlConfirmStereoVisionPermission(void) {
if (hosversionBefore(4,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _pctlNoIO(1013);
}
Result pctlIsRestrictionEnabled(bool *flag) {
return _pctlNoInputOutBool(1031, flag);
}
Result pctlResetConfirmedStereoVisionPermission(void) {
if (hosversionBefore(5,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _pctlNoIO(1064);
}
Result pctlIsStereoVisionPermitted(bool *flag) {
if (hosversionBefore(5,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
......
......@@ -2,6 +2,7 @@
#include "result.h"
#include "arm/atomics.h"
#include "kernel/ipc.h"
#include "runtime/hosversion.h"
#include "services/pcv.h"
#include "services/sm.h"
......@@ -30,6 +31,10 @@ void pcvExit(void) {
}
Result pcvSetClockRate(PcvModule module, u32 hz) {
if(hosversionAtLeast(8,0,0)) {
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
}
IpcCommand c;
ipcInitialize(&c);
......@@ -66,6 +71,10 @@ Result pcvSetClockRate(PcvModule module, u32 hz) {
}
Result pcvGetClockRate(PcvModule module, u32 *out_hz) {
if(hosversionAtLeast(8,0,0)) {
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
}
IpcCommand c;
ipcInitialize(&c);
......@@ -105,6 +114,10 @@ Result pcvGetClockRate(PcvModule module, u32 *out_hz) {
}
Result pcvSetVoltageEnabled(bool state, u32 voltage) {
if(hosversionAtLeast(8,0,0)) {
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
}
IpcCommand c;
ipcInitialize(&c);
......@@ -141,6 +154,10 @@ Result pcvSetVoltageEnabled(bool state, u32 voltage) {
}
Result pcvGetVoltageEnabled(bool *isEnabled, u32 voltage) {
if(hosversionAtLeast(8,0,0)) {
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
}
IpcCommand c;
ipcInitialize(&c);
......
......@@ -8,10 +8,14 @@
#include "services/ro.h"
#include "services/sm.h"
static Service g_roSrv, g_dmntSrv;
static u64 g_roRefCnt, g_dmntRefCnt;
static Service g_roSrv, g_ro1Srv, g_dmntSrv;
static u64 g_roRefCnt, g_ro1RefCnt, g_dmntRefCnt;
static Result _ldrRoInitialize(void);
static Result _rosrvInitialize(Service* srv);
static Result _rosrvLoadNro(Service* srv, u64* out_address, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size);
static Result _rosrvUnloadNro(Service* srv, u64 nro_address);
static Result _rosrvLoadNrr(Service* srv, u64 cmd_id, u64 nrr_address, u64 nrr_size);
static Result _rosrvUnloadNrr(Service* srv, u64 nrr_address);
Result ldrRoInitialize(void) {
atomicIncrement64(&g_roRefCnt);
......@@ -22,7 +26,7 @@ Result ldrRoInitialize(void) {
Result rc = smGetService(&g_roSrv, "ldr:ro");
if (R_SUCCEEDED(rc)) {
rc = _ldrRoInitialize();
rc = _rosrvInitialize(&g_roSrv);
}
return rc;
......@@ -33,6 +37,28 @@ void ldrRoExit(void) {
serviceClose(&g_roSrv);
}
Result ro1Initialize(void) {
if (hosversionBefore(7,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
atomicIncrement64(&g_ro1RefCnt);
if (serviceIsActive(&g_ro1Srv))
return 0;
Result rc = smGetService(&g_ro1Srv, "ro:1");
if (R_SUCCEEDED(rc)) {
rc = _rosrvInitialize(&g_ro1Srv);
}
return rc;
}
void ro1Exit(void) {
if (atomicDecrement64(&g_ro1RefCnt) == 0)
serviceClose(&g_ro1Srv);
}
Result roDmntInitialize(void) {
if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
......@@ -49,7 +75,40 @@ void roDmntExit(void) {
serviceClose(&g_dmntSrv);
}
Result ldrRoLoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) {
Result _rosrvInitialize(Service* srv) {
IpcCommand c;
ipcInitialize(&c);
ipcSendHandleCopy(&c, CUR_PROCESS_HANDLE);
struct {
u64 magic;
u64 cmd_id;
} *raw;
raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 4;
Result rc = serviceIpcDispatch(srv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
} *resp;
serviceIpcParse(srv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
}
return rc;
}
Result _rosrvLoadNro(Service* srv, u64* out_address, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) {
IpcCommand c;
ipcInitialize(&c);
ipcSendPid(&c);
......@@ -64,7 +123,7 @@ Result ldrRoLoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_add
u64 bss_size;
} *raw;
raw = serviceIpcPrepareHeader(&g_roSrv, &c, sizeof(*raw));
raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 0;
......@@ -74,7 +133,7 @@ Result ldrRoLoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_add
raw->bss_address = bss_address;
raw->bss_size = bss_size;
Result rc = serviceIpcDispatch(&g_roSrv);
Result rc = serviceIpcDispatch(srv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
......@@ -84,7 +143,7 @@ Result ldrRoLoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_add
u64 out_address;
} *resp;
serviceIpcParse(&g_roSrv, &r, sizeof(*resp));
serviceIpcParse(srv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
......@@ -97,7 +156,7 @@ Result ldrRoLoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_add
return rc;
}
Result ldrRoUnloadNro(u64 nro_address) {
Result _rosrvUnloadNro(Service* srv, u64 nro_address) {
IpcCommand c;
ipcInitialize(&c);
ipcSendPid(&c);
......@@ -109,14 +168,14 @@ Result ldrRoUnloadNro(u64 nro_address) {
u64 nro_address;
} *raw;
raw = serviceIpcPrepareHeader(&g_roSrv, &c, sizeof(*raw));
raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 1;
raw->pid = 0;
raw->nro_address = nro_address;
Result rc = serviceIpcDispatch(&g_roSrv);
Result rc = serviceIpcDispatch(srv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
......@@ -125,7 +184,7 @@ Result ldrRoUnloadNro(u64 nro_address) {
u64 result;
} *resp;
serviceIpcParse(&g_roSrv, &r, sizeof(*resp));
serviceIpcParse(srv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
......@@ -134,7 +193,7 @@ Result ldrRoUnloadNro(u64 nro_address) {
return rc;
}
Result ldrRoLoadNrr(u64 nrr_address, u64 nrr_size) {
Result _rosrvLoadNrr(Service* srv, u64 cmd_id, u64 nrr_address, u64 nrr_size) {
IpcCommand c;
ipcInitialize(&c);
ipcSendPid(&c);
......@@ -147,15 +206,15 @@ Result ldrRoLoadNrr(u64 nrr_address, u64 nrr_size) {
u64 nrr_size;
} *raw;
raw = serviceIpcPrepareHeader(&g_roSrv, &c, sizeof(*raw));
raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 2;
raw->cmd_id = cmd_id;
raw->pid = 0;
raw->nrr_address = nrr_address;
raw->nrr_size = nrr_size;
Result rc = serviceIpcDispatch(&g_roSrv);
Result rc = serviceIpcDispatch(srv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
......@@ -164,7 +223,7 @@ Result ldrRoLoadNrr(u64 nrr_address, u64 nrr_size) {
u64 result;
} *resp;
serviceIpcParse(&g_roSrv, &r, sizeof(*resp));
serviceIpcParse(srv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
......@@ -173,7 +232,7 @@ Result ldrRoLoadNrr(u64 nrr_address, u64 nrr_size) {
return rc;
}
Result ldrRoUnloadNrr(u64 nrr_address) {
Result _rosrvUnloadNrr(Service* srv, u64 nrr_address) {
IpcCommand c;
ipcInitialize(&c);
ipcSendPid(&c);
......@@ -185,14 +244,14 @@ Result ldrRoUnloadNrr(u64 nrr_address) {
u64 nrr_address;
} *raw;
raw = serviceIpcPrepareHeader(&g_roSrv, &c, sizeof(*raw));
raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 3;
raw->pid = 0;
raw->nrr_address = nrr_address;
Result rc = serviceIpcDispatch(&g_roSrv);
Result rc = serviceIpcDispatch(srv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
......@@ -201,7 +260,7 @@ Result ldrRoUnloadNrr(u64 nrr_address) {
u64 result;
} *resp;
serviceIpcParse(&g_roSrv, &r, sizeof(*resp));
serviceIpcParse(srv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
......@@ -210,44 +269,54 @@ Result ldrRoUnloadNrr(u64 nrr_address) {
return rc;
}
Result _ldrRoInitialize(void) {
IpcCommand c;
ipcInitialize(&c);
ipcSendHandleCopy(&c, CUR_PROCESS_HANDLE);
Result ldrRoLoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) {
return _rosrvLoadNro(&g_roSrv, out_address, nro_address, nro_size, bss_address, bss_size);
}
struct {
u64 magic;
u64 cmd_id;
} *raw;
Result ldrRoUnloadNro(u64 nro_address) {
return _rosrvUnloadNro(&g_roSrv, nro_address);
}
raw = serviceIpcPrepareHeader(&g_roSrv, &c, sizeof(*raw));
Result ldrRoLoadNrr(u64 nrr_address, u64 nrr_size) {
return _rosrvLoadNrr(&g_roSrv, 2, nrr_address, nrr_size);
}
raw->magic = SFCI_MAGIC;
raw->cmd_id = 4;
Result ldrRoUnloadNrr(u64 nrr_address) {
return _rosrvUnloadNrr(&g_roSrv, nrr_address);
}
Result rc = serviceIpcDispatch(&g_roSrv);
Result ldrRoLoadNrrEx(u64 nrr_address, u64 nrr_size) {
if (hosversionBefore(7,0,0)) {
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
}
return _rosrvLoadNrr(&g_roSrv, 10, nrr_address, nrr_size);
}
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
} *resp;
Result ro1LoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) {
return _rosrvLoadNro(&g_ro1Srv, out_address, nro_address, nro_size, bss_address, bss_size);
}
serviceIpcParse(&g_roSrv, &r, sizeof(*resp));
resp = r.Raw;
Result ro1UnloadNro(u64 nro_address) {
return _rosrvUnloadNro(&g_ro1Srv, nro_address);
}
rc = resp->result;
}
Result ro1LoadNrr(u64 nrr_address, u64 nrr_size) {
return _rosrvLoadNrr(&g_ro1Srv, 2, nrr_address, nrr_size);
}
return rc;
Result ro1UnloadNrr(u64 nrr_address) {
return _rosrvUnloadNrr(&g_ro1Srv, nrr_address);
}
Result ro1LoadNrrEx(u64 nrr_address, u64 nrr_size) {
return _rosrvLoadNrr(&g_ro1Srv, 10, nrr_address, nrr_size);
}
Result roDmntGetModuleInfos(u64 pid, LoaderModuleInfo *out_module_infos, size_t out_size, u32 *num_out) {
Result roDmntGetModuleInfos(u64 pid, LoaderModuleInfo *out_module_infos, size_t max_out_modules, u32 *num_out) {
IpcCommand c;
ipcInitialize(&c);
ipcAddRecvStatic(&c, out_module_infos, out_size, 0);
ipcAddRecvBuffer(&c, out_module_infos, max_out_modules * sizeof(*out_module_infos), BufferType_Normal);
struct {
u64 magic;
......