mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 12:21:18 +00:00
spl: Start skeletoning spl.
This commit is contained in:
parent
f6645387b0
commit
9858d6fc95
10 changed files with 763 additions and 0 deletions
160
stratosphere/spl/Makefile
Normal file
160
stratosphere/spl/Makefile
Normal file
|
@ -0,0 +1,160 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||
endif
|
||||
|
||||
TOPDIR ?= $(CURDIR)
|
||||
include $(DEVKITPRO)/libnx/switch_rules
|
||||
|
||||
AMSBRANCH := $(shell git symbolic-ref --short HEAD)
|
||||
AMSREV := $(AMSBRANCH)-$(shell git rev-parse --short HEAD)
|
||||
|
||||
ifneq (, $(strip $(shell git status --porcelain 2>/dev/null)))
|
||||
AMSREV := $(AMSREV)-dirty
|
||||
endif
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
# EXEFS_SRC is the optional input directory containing data copied into exefs, if anything this normally should only contain "main.npdm".
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
DATA := data
|
||||
INCLUDES := include ../../common/include
|
||||
EXEFS_SRC := exefs_src
|
||||
|
||||
DEFINES := -DDISABLE_IPC -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\"
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
|
||||
|
||||
CFLAGS := -g -Wall -O2 -ffunction-sections \
|
||||
$(ARCH) $(DEFINES)
|
||||
|
||||
CFLAGS += $(INCLUDE) -D__SWITCH__
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS := -lstratosphere -lnx
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../libstratosphere
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)
|
||||
|
||||
ifeq ($(strip $(CONFIG_JSON)),)
|
||||
jsons := $(wildcard *.json)
|
||||
ifneq (,$(findstring $(TARGET).json,$(jsons)))
|
||||
export APP_JSON := $(TOPDIR)/$(TARGET).json
|
||||
else
|
||||
ifneq (,$(findstring config.json,$(jsons)))
|
||||
export APP_JSON := $(TOPDIR)/config.json
|
||||
endif
|
||||
endif
|
||||
else
|
||||
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
|
||||
endif
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(TARGET).kip $(TARGET).elf
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
.PHONY: all
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
all : $(OUTPUT).kip
|
||||
|
||||
$(OUTPUT).kip : $(OUTPUT).elf
|
||||
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
48
stratosphere/spl/source/spl_general_service.cpp
Normal file
48
stratosphere/spl/source/spl_general_service.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "spl_general_service.hpp"
|
||||
|
||||
Result GeneralService::GetConfig(Out<u64> out, u32 which) {
|
||||
return this->secmon_wrapper->GetConfig(out.GetPointer(), static_cast<SplConfigItem>(which));
|
||||
}
|
||||
|
||||
Result GeneralService::ExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> exp, InPointer<u8> mod) {
|
||||
return this->secmon_wrapper->ExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, exp.pointer, exp.num_elements, mod.pointer, mod.num_elements);
|
||||
}
|
||||
|
||||
Result GeneralService::SetConfig(u32 which, u64 value) {
|
||||
return this->secmon_wrapper->SetConfig(static_cast<SplConfigItem>(which), value);
|
||||
}
|
||||
|
||||
Result GeneralService::GenerateRandomBytes(OutPointerWithClientSize<u8> out) {
|
||||
return this->secmon_wrapper->GenerateRandomBytes(out.pointer, out.num_elements);
|
||||
}
|
||||
|
||||
Result GeneralService::IsDevelopment(Out<bool> is_dev) {
|
||||
return this->secmon_wrapper->IsDevelopment(is_dev.GetPointer());
|
||||
}
|
||||
|
||||
Result GeneralService::SetBootReason(BootReasonValue boot_reason) {
|
||||
return this->secmon_wrapper->SetBootReason(boot_reason);
|
||||
}
|
||||
|
||||
Result GeneralService::GetBootReason(Out<BootReasonValue> out) {
|
||||
return this->secmon_wrapper->GetBootReason(out.GetPointer());
|
||||
}
|
52
stratosphere/spl/source/spl_general_service.hpp
Normal file
52
stratosphere/spl/source/spl_general_service.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "spl_types.hpp"
|
||||
#include "spl_secmon_wrapper.hpp"
|
||||
|
||||
class GeneralService final : public IServiceObject {
|
||||
private:
|
||||
SecureMonitorWrapper *secmon_wrapper;
|
||||
public:
|
||||
GeneralService(SecureMonitorWrapper *sw) : secmon_wrapper(sw) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
virtual ~GeneralService() { /* ... */ }
|
||||
private:
|
||||
/* Actual commands. */
|
||||
virtual Result GetConfig(Out<u64> out, u32 which);
|
||||
virtual Result ExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> exp, InPointer<u8> mod);
|
||||
virtual Result SetConfig(u32 which, u64 value);
|
||||
virtual Result GenerateRandomBytes(OutPointerWithClientSize<u8> out);
|
||||
virtual Result IsDevelopment(Out<bool> is_dev);
|
||||
virtual Result SetBootReason(BootReasonValue boot_reason);
|
||||
virtual Result GetBootReason(Out<BootReasonValue> out);
|
||||
public:
|
||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||
MakeServiceCommandMeta<Spl_Cmd_GetConfig, &GeneralService::GetConfig>(),
|
||||
MakeServiceCommandMeta<Spl_Cmd_ExpMod, &GeneralService::ExpMod>(),
|
||||
MakeServiceCommandMeta<Spl_Cmd_SetConfig, &GeneralService::SetConfig>(),
|
||||
MakeServiceCommandMeta<Spl_Cmd_GenerateRandomBytes, &GeneralService::GenerateRandomBytes>(),
|
||||
MakeServiceCommandMeta<Spl_Cmd_IsDevelopment, &GeneralService::IsDevelopment>(),
|
||||
MakeServiceCommandMeta<Spl_Cmd_SetBootReason, &GeneralService::SetBootReason, FirmwareVersion_300>(),
|
||||
MakeServiceCommandMeta<Spl_Cmd_GetBootReason, &GeneralService::GetBootReason, FirmwareVersion_300>(),
|
||||
};
|
||||
};
|
110
stratosphere/spl/source/spl_main.cpp
Normal file
110
stratosphere/spl/source/spl_main.cpp
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "spl_random_service.hpp"
|
||||
#include "spl_general_service.hpp"
|
||||
|
||||
extern "C" {
|
||||
extern u32 __start__;
|
||||
|
||||
u32 __nx_applet_type = AppletType_None;
|
||||
|
||||
#define INNER_HEAP_SIZE 0x28000
|
||||
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
|
||||
char nx_inner_heap[INNER_HEAP_SIZE];
|
||||
|
||||
void __libnx_initheap(void);
|
||||
void __appInit(void);
|
||||
void __appExit(void);
|
||||
|
||||
/* Exception handling. */
|
||||
alignas(16) u8 __nx_exception_stack[0x1000];
|
||||
u64 __nx_exception_stack_size = sizeof(__nx_exception_stack);
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx);
|
||||
u64 __stratosphere_title_id = TitleId_Spl;
|
||||
void __libstratosphere_exception_handler(AtmosphereFatalErrorContext *ctx);
|
||||
}
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
||||
StratosphereCrashHandler(ctx);
|
||||
}
|
||||
|
||||
|
||||
void __libnx_initheap(void) {
|
||||
void* addr = nx_inner_heap;
|
||||
size_t size = nx_inner_heap_size;
|
||||
|
||||
/* Newlib */
|
||||
extern char* fake_heap_start;
|
||||
extern char* fake_heap_end;
|
||||
|
||||
fake_heap_start = (char*)addr;
|
||||
fake_heap_end = (char*)addr + size;
|
||||
}
|
||||
|
||||
void __appInit(void) {
|
||||
SetFirmwareVersionForLibnx();
|
||||
|
||||
/* SPL doesn't really access any services... */
|
||||
}
|
||||
|
||||
void __appExit(void) {
|
||||
/* SPL doesn't really access any services... */
|
||||
}
|
||||
|
||||
struct SplServerOptions {
|
||||
static constexpr size_t PointerBufferSize = 0x800;
|
||||
static constexpr size_t MaxDomains = 0;
|
||||
static constexpr size_t MaxDomainObjects = 0;
|
||||
};
|
||||
|
||||
/* Single secure monitor wrapper singleton. */
|
||||
static SecureMonitorWrapper s_secmon_wrapper;
|
||||
|
||||
/* Helpers for creating services. */
|
||||
static const auto MakeRandomService = []() { return std::make_shared<RandomService>(&s_secmon_wrapper); };
|
||||
static const auto MakeGeneralService = []() { return std::make_shared<GeneralService>(&s_secmon_wrapper); };
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
consoleDebugInit(debugDevice_SVC);
|
||||
|
||||
/* Create server manager. */
|
||||
static auto s_server_manager = WaitableManager<SplServerOptions>(1);
|
||||
|
||||
/* Create services. */
|
||||
s_server_manager.AddWaitable(new ServiceServer<RandomService, +MakeRandomService>("csrng", 9));
|
||||
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_400) {
|
||||
s_server_manager.AddWaitable(new ServiceServer<GeneralService, +MakeGeneralService>("spl:", 9));
|
||||
/* TODO: Other services. */
|
||||
} else {
|
||||
/* TODO, DeprecatedGeneralService */
|
||||
}
|
||||
|
||||
/* Loop forever, servicing our services. */
|
||||
s_server_manager.Process();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
24
stratosphere/spl/source/spl_random_service.cpp
Normal file
24
stratosphere/spl/source/spl_random_service.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "spl_random_service.hpp"
|
||||
|
||||
Result RandomService::GenerateRandomBytes(OutBuffer<u8> out) {
|
||||
return this->secmon_wrapper->GenerateRandomBytes(out.buffer, out.num_elements);
|
||||
}
|
40
stratosphere/spl/source/spl_random_service.hpp
Normal file
40
stratosphere/spl/source/spl_random_service.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "spl_types.hpp"
|
||||
#include "spl_secmon_wrapper.hpp"
|
||||
|
||||
class RandomService final : public IServiceObject {
|
||||
private:
|
||||
SecureMonitorWrapper *secmon_wrapper;
|
||||
public:
|
||||
RandomService(SecureMonitorWrapper *sw) : secmon_wrapper(sw) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
virtual ~RandomService() { /* ... */ }
|
||||
private:
|
||||
/* Actual commands. */
|
||||
virtual Result GenerateRandomBytes(OutBuffer<u8> out);
|
||||
public:
|
||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||
MakeServiceCommandMeta<Spl_Cmd_GenerateRandomBytes, &RandomService::GenerateRandomBytes>(),
|
||||
};
|
||||
};
|
80
stratosphere/spl/source/spl_secmon_wrapper.cpp
Normal file
80
stratosphere/spl/source/spl_secmon_wrapper.cpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "spl_secmon_wrapper.hpp"
|
||||
|
||||
Result SecureMonitorWrapper::ConvertToSplResult(SmcResult result) {
|
||||
if (result == SmcResult_Success) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
if (result < SmcResult_Max) {
|
||||
return MAKERESULT(Module_Spl, static_cast<u32>(result));
|
||||
}
|
||||
return ResultSplUnknownSmcResult;
|
||||
}
|
||||
|
||||
Result SecureMonitorWrapper::GetConfig(u64 *out, SplConfigItem which) {
|
||||
/* TODO */
|
||||
return ResultKernelConnectionClosed;
|
||||
}
|
||||
|
||||
Result SecureMonitorWrapper::ExpMod(void *out, size_t out_size, const void *base, size_t base_size, const void *exp, size_t exp_size, const void *mod, size_t mod_size) {
|
||||
/* TODO */
|
||||
return ResultKernelConnectionClosed;
|
||||
}
|
||||
|
||||
Result SecureMonitorWrapper::SetConfig(SplConfigItem which, u64 value) {
|
||||
/* TODO */
|
||||
return ResultKernelConnectionClosed;
|
||||
}
|
||||
|
||||
Result SecureMonitorWrapper::GenerateRandomBytes(void *out, size_t size) {
|
||||
/* TODO */
|
||||
return ResultKernelConnectionClosed;
|
||||
}
|
||||
|
||||
Result SecureMonitorWrapper::IsDevelopment(bool *out) {
|
||||
u64 is_retail;
|
||||
Result rc = this->GetConfig(&is_retail, SplConfigItem_IsRetail);
|
||||
if (R_FAILED(rc)) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
*out = (is_retail == 0);
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result SecureMonitorWrapper::SetBootReason(BootReasonValue boot_reason) {
|
||||
if (this->IsBootReasonSet()) {
|
||||
return ResultSplBootReasonAlreadySet;
|
||||
}
|
||||
|
||||
this->boot_reason = boot_reason;
|
||||
this->boot_reason_set = true;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result SecureMonitorWrapper::GetBootReason(BootReasonValue *out) {
|
||||
if (!this->IsBootReasonSet()) {
|
||||
return ResultSplBootReasonNotSet;
|
||||
}
|
||||
|
||||
*out = GetBootReason();
|
||||
return ResultSuccess;
|
||||
}
|
53
stratosphere/spl/source/spl_secmon_wrapper.hpp
Normal file
53
stratosphere/spl/source/spl_secmon_wrapper.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "spl_types.hpp"
|
||||
|
||||
class SecureMonitorWrapper {
|
||||
public:
|
||||
static constexpr size_t MaxAesKeyslots = 6;
|
||||
static constexpr size_t MaxAesKeyslotsDeprecated = 4;
|
||||
private:
|
||||
uintptr_t keyslot_owners[MaxAesKeyslots] = {};
|
||||
BootReasonValue boot_reason = {};
|
||||
bool boot_reason_set = false;
|
||||
private:
|
||||
static size_t GetMaxKeyslots() {
|
||||
return (GetRuntimeFirmwareVersion() >= FirmwareVersion_600) ? MaxAesKeyslots : MaxAesKeyslotsDeprecated;
|
||||
}
|
||||
private:
|
||||
BootReasonValue GetBootReason() const {
|
||||
return this->boot_reason;
|
||||
}
|
||||
bool IsBootReasonSet() const {
|
||||
return this->boot_reason_set;
|
||||
}
|
||||
static Result ConvertToSplResult(SmcResult result);
|
||||
public:
|
||||
void Initialize();
|
||||
public:
|
||||
Result GetConfig(u64 *out, SplConfigItem which);
|
||||
Result ExpMod(void *out, size_t out_size, const void *base, size_t base_size, const void *exp, size_t exp_size, const void *mod, size_t mod_size);
|
||||
Result SetConfig(SplConfigItem which, u64 value);
|
||||
Result GenerateRandomBytes(void *out, size_t size);
|
||||
Result IsDevelopment(bool *out);
|
||||
Result SetBootReason(BootReasonValue boot_reason);
|
||||
Result GetBootReason(BootReasonValue *out);
|
||||
};
|
122
stratosphere/spl/source/spl_types.hpp
Normal file
122
stratosphere/spl/source/spl_types.hpp
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
enum SmcResult : u32 {
|
||||
SmcResult_Success = 0,
|
||||
SmcResult_NotImplemented = 1,
|
||||
SmcResult_InvalidArgument = 2,
|
||||
SmcResult_InProgress = 3,
|
||||
SmcResult_NoAsyncOperation = 4,
|
||||
SmcResult_InvalidAsyncOperation = 5,
|
||||
SmcResult_Blacklisted = 6,
|
||||
|
||||
SmcResult_Max = 99,
|
||||
};
|
||||
|
||||
enum SmcCipherMode : u32 {
|
||||
SmcCipherMode_CbcEncrypt = 0,
|
||||
SmcCipherMode_CbcDecrypt = 1,
|
||||
SmcCipherMode_Ctr = 2,
|
||||
SmcCipherMode_Cmac = 3,
|
||||
};
|
||||
|
||||
enum EsKeyType : u32 {
|
||||
EsKeyType_TitleKey = 0,
|
||||
EsKeyType_ElicenseKey = 1,
|
||||
};
|
||||
|
||||
struct AsyncOperationKey {
|
||||
u64 value;
|
||||
};
|
||||
|
||||
struct BootReasonValue {
|
||||
u8 power_intr;
|
||||
u8 rtc_intr;
|
||||
u8 _0x3;
|
||||
u8 boot_reason;
|
||||
};
|
||||
static_assert(sizeof(BootReasonValue) == sizeof(u32), "BootReasonValue definition!");
|
||||
|
||||
struct AesKey {
|
||||
u8 data[AES_128_KEY_SIZE];
|
||||
};
|
||||
|
||||
struct IvCtr {
|
||||
u8 data[AES_128_KEY_SIZE];
|
||||
};
|
||||
|
||||
struct Cmac {
|
||||
u8 data[AES_128_KEY_SIZE];
|
||||
};
|
||||
|
||||
struct AccessKey {
|
||||
u8 data[AES_128_KEY_SIZE];
|
||||
};
|
||||
|
||||
struct KeySource {
|
||||
u8 data[AES_128_KEY_SIZE];
|
||||
};
|
||||
|
||||
enum SplServiceCmd {
|
||||
/* 1.0.0+ */
|
||||
Spl_Cmd_GetConfig = 0,
|
||||
Spl_Cmd_ExpMod = 1,
|
||||
Spl_Cmd_GenerateAesKek = 2,
|
||||
Spl_Cmd_LoadAesKey = 3,
|
||||
Spl_Cmd_GenerateAesKey = 4,
|
||||
Spl_Cmd_SetConfig = 5,
|
||||
Spl_Cmd_GenerateRandomBytes = 7,
|
||||
Spl_Cmd_ImportLotusKey = 9,
|
||||
Spl_Cmd_DecryptLotusMessage = 10,
|
||||
Spl_Cmd_IsDevelopment = 11,
|
||||
Spl_Cmd_GenerateSpecificAesKey = 12,
|
||||
Spl_Cmd_DecryptRsaPrivateKey = 13,
|
||||
Spl_Cmd_DecryptAesKey = 14,
|
||||
Spl_Cmd_CryptAesCtr = 15,
|
||||
Spl_Cmd_ComputeCmac = 16,
|
||||
Spl_Cmd_ImportEsKey = 17,
|
||||
Spl_Cmd_UnwrapTitleKey = 18,
|
||||
Spl_Cmd_LoadTitleKey = 19,
|
||||
|
||||
/* 2.0.0+ */
|
||||
Spl_Cmd_UnwrapCommonTitleKey = 20,
|
||||
Spl_Cmd_AllocateAesKeyslot = 21,
|
||||
Spl_Cmd_FreeAesKeyslot = 22,
|
||||
Spl_Cmd_GetAesKeyslotEvent = 23,
|
||||
|
||||
/* 3.0.0+ */
|
||||
Spl_Cmd_SetBootReason = 24,
|
||||
Spl_Cmd_GetBootReason = 25,
|
||||
|
||||
/* 5.0.0+ */
|
||||
Spl_Cmd_ImportSslKey = 26,
|
||||
Spl_Cmd_SslExpMod = 27,
|
||||
Spl_Cmd_ImportDrmKey = 28,
|
||||
Spl_Cmd_DrmExpMod = 29,
|
||||
Spl_Cmd_ReEncryptRsaPrivateKey = 30,
|
||||
Spl_Cmd_GetPackage2Hash = 31,
|
||||
|
||||
/* 6.0.0+ */
|
||||
Spl_Cmd_UnwrapElicenseKey = 31, /* re-used command id :( */
|
||||
Spl_Cmd_LoadElicenseKey = 32,
|
||||
};
|
74
stratosphere/spl/spl.json
Normal file
74
stratosphere/spl/spl.json
Normal file
|
@ -0,0 +1,74 @@
|
|||
{
|
||||
"name": "spl",
|
||||
"title_id": "0x0100000000000028",
|
||||
"main_thread_stack_size": "0x00002000",
|
||||
"main_thread_priority": 27,
|
||||
"default_cpu_id": 3,
|
||||
"process_category": 1,
|
||||
"kernel_capabilities": [{
|
||||
"type": "handle_table_size",
|
||||
"value": 128
|
||||
}, {
|
||||
"type": "irq_pair",
|
||||
"value": [44, null]
|
||||
}, {
|
||||
"type": "syscalls",
|
||||
"value": {
|
||||
"svcSetHeapSize": "0x01",
|
||||
"svcSetMemoryPermission": "0x02",
|
||||
"svcSetMemoryAttribute": "0x03",
|
||||
"svcMapMemory": "0x04",
|
||||
"svcUnmapMemory": "0x05",
|
||||
"svcQueryMemory": "0x06",
|
||||
"svcExitProcess": "0x07",
|
||||
"svcCreateThread": "0x08",
|
||||
"svcStartThread": "0x09",
|
||||
"svcExitThread": "0x0a",
|
||||
"svcSleepThread": "0x0b",
|
||||
"svcGetThreadPriority": "0x0c",
|
||||
"svcSetThreadPriority": "0x0d",
|
||||
"svcGetThreadCoreMask": "0x0e",
|
||||
"svcSetThreadCoreMask": "0x0f",
|
||||
"svcGetCurrentProcessorNumber": "0x10",
|
||||
"svcSignalEvent": "0x11",
|
||||
"svcClearEvent": "0x12",
|
||||
"svcMapSharedMemory": "0x13",
|
||||
"svcUnmapSharedMemory": "0x14",
|
||||
"svcCreateTransferMemory": "0x15",
|
||||
"svcCloseHandle": "0x16",
|
||||
"svcResetSignal": "0x17",
|
||||
"svcWaitSynchronization": "0x18",
|
||||
"svcCancelSynchronization": "0x19",
|
||||
"svcArbitrateLock": "0x1a",
|
||||
"svcArbitrateUnlock": "0x1b",
|
||||
"svcWaitProcessWideKeyAtomic": "0x1c",
|
||||
"svcSignalProcessWideKey": "0x1d",
|
||||
"svcGetSystemTick": "0x1e",
|
||||
"svcConnectToNamedPort": "0x1f",
|
||||
"svcSendSyncRequestLight": "0x20",
|
||||
"svcSendSyncRequest": "0x21",
|
||||
"svcSendSyncRequestWithUserBuffer": "0x22",
|
||||
"svcSendAsyncRequestWithUserBuffer": "0x23",
|
||||
"svcGetProcessId": "0x24",
|
||||
"svcGetThreadId": "0x25",
|
||||
"svcBreak": "0x26",
|
||||
"svcOutputDebugString": "0x27",
|
||||
"svcReturnFromException": "0x28",
|
||||
"svcGetInfo": "0x29",
|
||||
"svcWaitForAddress": "0x34",
|
||||
"svcSignalToAddress": "0x35",
|
||||
"svcCreateSession": "0x40",
|
||||
"svcAcceptSession": "0x41",
|
||||
"svcReplyAndReceiveLight": "0x42",
|
||||
"svcReplyAndReceive": "0x43",
|
||||
"svcReplyAndReceiveWithUserBuffer": "0x44",
|
||||
"svcCreateEvent": "0x45",
|
||||
"svcCreateInterruptEvent": "0x53",
|
||||
"svcCreateDeviceAddressSpace": "0x56",
|
||||
"svcAttachDeviceAddressSpace": "0x57",
|
||||
"svcMapDeviceAddressSpaceAligned": "0x5a",
|
||||
"svcUnmapDeviceAddressSpace": "0x5c",
|
||||
"svcCallSecureMonitor": "0x7f"
|
||||
}
|
||||
}]
|
||||
}
|
Loading…
Reference in a new issue