Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
570 changes: 293 additions & 277 deletions CMakeLists.txt

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions include/nn/diag.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ namespace detail {
// LOG
void LogImpl(nn::diag::LogMetaData const&, char const*, ...);
void AbortImpl(char const*, char const*, char const*, s32);
void AbortImpl(char const*, char const*, char const*, int, Result);

void OnAssertionFailure(nn::diag::AssertionType, char const*, char const*, char const*, int);
[[gnu::format(printf, 6, 7)]] [[noreturn]] void AbortImpl(char const*, char const*, char const*,
s32, const Result*, const char*, ...);

void OnAssertionFailure(nn::diag::AssertionType, char const*, char const*, char const*, s32);
} // namespace detail

// MODULE / SYMBOL
Expand Down
60 changes: 35 additions & 25 deletions include/nn/err.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
#pragma once

#include <nn/err/ApplicationErrorArg.h>
#include <nn/err/ErrorCode.h>
#include <nn/err/ErrorResultVariant.h>
#include <nn/err/ResultBacktrace.h>
#include <nn/err/SystemErrorArg.h>
#include <nn/settings.h>
#include <nn/time.h>
#include <nn/types.h>

namespace nn {
namespace err {
enum ErrorCodeCategoryType : u32 {
unk1,
unk2,
};
namespace nn::err {
class ErrorMessageDatabaseVersion;
// TODO
class EulaData;
class ErrorViewerJumpDestination {};

class ApplicationErrorArg {
public:
ApplicationErrorArg();
ApplicationErrorArg(u32 error_code, const char* dialog_message, const char* fullscreen_message,
const nn::settings::LanguageCode& languageCode);
void SetApplicationErrorCodeNumber(u32 error_code);
void SetDialogMessage(const char* message);
void SetFullScreenMessage(const char* message);

u64 unk;
u32 error_code;
nn::settings::LanguageCode language_code;
char dialog_message[2048];
char fullscreen_message[2048];
};

u32 MakeErrorCode(ErrorCodeCategoryType err_category_type, u32 errorCodeNumber);
ErrorCode ConvertResultToErrorCode(const Result& result);
bool CreateErrorViewerStartupParamForRecordedError(void*, u64*, u64, const char*, const char*,
time::PosixTime);
void ExecuteJump(ErrorViewerJumpDestination destination);
void GetErrorCodeString(char* outErrorCodeString, size_t errorCodeStrBufferSize,
ErrorCode errorCode);
void* GetErrorMessageDatabaseVersion(ErrorMessageDatabaseVersion* outVersion);
ErrorCode MakeErrorCode(u32 category, u32 number);
void ShowApplicationError(const ApplicationErrorArg& arg);
} // namespace err
} // namespace nn
void ShowError(Result result);
void ShowError(ErrorCode errorCode);
void ShowError(const ErrorResultVariant& errorResultVariant);
void ShowError(Result result, ResultBacktrace& backtrace);
void ShowErrorRecord(Result result, time::PosixTime timestamp);
void ShowErrorRecord(ErrorCode errorCode, time::PosixTime timestamp);
void ShowErrorRecord(const void*, u64);
void ShowErrorWithoutJump(Result result);
void ShowErrorWithoutJump(ErrorCode errorCode);
void ShowEula(settings::system::RegionCode regionCode);
void ShowSystemError(const SystemErrorArg& arg);
void ShowSystemUpdateEula(settings::system::RegionCode regionCode, EulaData& data);
void ShowUnacceptableAddOnContentVersionError();
void ShowUnacceptableApplicationVersionError();
} // namespace nn::err
32 changes: 32 additions & 0 deletions include/nn/err/ApplicationErrorArg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <nn/settings.h>
#include <nn/types.h>

namespace nn::err {
class ApplicationErrorArg {
public:
ApplicationErrorArg();
ApplicationErrorArg(u32 errorCode, const char* dialogMessage, const char* fullScreenMessage,
const settings::LanguageCode& languageCode);

u32 GetApplicationErrorCodeNumber() const;
const char* GetDialogMessage() const;
const char* GetFullScreenMessage() const;
settings::LanguageCode GetLanguageCode() const;

void SetApplicationErrorCodeNumber(u32 errorCode);
void SetDialogMessage(const char* message);
void SetFullScreenMessage(const char* message);
void SetLanguageCode(const settings::LanguageCode& languageCode);

private:
u8 _0 = 2;
u8 _1 = 1;
u8 padding[6];
u32 mErrorCode = 0;
settings::LanguageCode mLanguageCode;
char mDialogMessage[2048];
char mFullScreenMessage[2048];
};
} // namespace nn::err
22 changes: 22 additions & 0 deletions include/nn/err/ErrorCode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <nn/types.h>

namespace nn::err {
class ErrorCode {
public:
static ErrorCode GetInvalidErrorCode();

ErrorCode() {}
ErrorCode(u32 category, u32 number) : mCategory(category), mNumber(number) {}

bool IsValid() const;

u32 GetCategory() const { return mCategory; }
u32 GetNumber() const { return mNumber; }

private:
u32 mCategory = 0;
u32 mNumber = 0;
};
} // namespace nn::err
13 changes: 13 additions & 0 deletions include/nn/err/ErrorMessageDatabaseVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <nn/types.h>

namespace nn::err {
class ErrorMessageDatabaseVersion {
public:
private:
s32 mVersion;
};

static_assert(sizeof(ErrorMessageDatabaseVersion) == 4);
} // namespace nn::err
34 changes: 34 additions & 0 deletions include/nn/err/ErrorResultVariant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <nn/err/ErrorCode.h>
#include <nn/types.h>

namespace nn::err {
class ErrorResultVariant {
public:
enum class State : u32 {
Undefined,
Result,
ErrorCode,
};

ErrorResultVariant();
ErrorResultVariant(const Result& result);
ErrorResultVariant(const ErrorCode& errorCode);

State GetState() const;

operator ErrorCode() const;
operator Result() const;

void operator=(const Result& result);
void operator=(const ErrorCode& errorCode);

private:
State mState = State::Undefined;
union {
Result mResult;
ErrorCode mErrorCode;
} mValue;
};
} // namespace nn::err
13 changes: 13 additions & 0 deletions include/nn/err/ResultBacktrace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <nn/types.h>

namespace nn::err {
class ResultBacktrace {
public:
static void Make(ResultBacktrace* outBackTrace, const Result*, s32);

private:
// TODO
};
} // namespace nn::err
38 changes: 38 additions & 0 deletions include/nn/err/SystemErrorArg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <nn/err/ErrorCode.h>
#include <nn/settings.h>
#include <nn/types.h>

namespace nn::err {
class SystemErrorArg {
public:
SystemErrorArg();
SystemErrorArg(ErrorCode errorCode, const char* dialogMessage, const char* fullScreenMessage,
const settings::LanguageCode& languageCode);

void SetErrorCode(ErrorCode errorCode);
void SetDialogMessage(const char* message);
void SetFullScreenMessage(const char* message);
void SetLanguageCode(const settings::LanguageCode& languageCode);
ErrorCode GetErrorCode() const;
const char* GetDialogMessage() const;
const char* GetFullScreenMessage() const;
settings::LanguageCode GetLanguageCode() const;
void GetStartupParam() const;

private:
s8 _0 = 1;
s8 _1 = 0;
s8 _2 = 0;
s8 _3 = 0;
s8 _4 = 0;
s8 _5 = 0;
s8 _6 = 0;
s8 _7 = 0;
ErrorCode mErrorCode;
settings::LanguageCode mLanguageCode;
char mDialogMessage[2048];
char mFullScreenMessage[2048];
};
} // namespace nn::err
58 changes: 58 additions & 0 deletions include/nn/err/detail.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once

#include <nn/err.h>
#include <nn/err/ErrorCode.h>
#include <nn/err/detail/MessageKind.h>
#include <nn/settings.h>
#include <nn/types.h>

namespace nn::ns {
// TODO: move
class ApplicationErrorCodeCategory {
public:
const char* GetCategory() const { return mCategory; }

private:
char mCategory[8];
};
} // namespace nn::ns

namespace nn::err {
class ErrorMessageDatabaseVersion;
} // namespace nn::err

namespace nn::err::detail {
bool CategoryExists(u32 category);
bool DefaultErrorMessageDataExists(u32 category);
bool ErrorMessageDataExists(ErrorCode errorCode);
bool IsApplicationErrorCodeString(const char* errorCodeString);
void MakeApplicationErrorCodeString(
char* outErrorCodeString, size_t errorCodeStringBufferSize,
const ns::ApplicationErrorCodeCategory& applicationErrorCodeCategory, u32 errorCodeNumber);
void MakeErrorCodeString(char* outErrorCodeString, size_t errorCodeStringBufferSize,
ErrorCode errorCode);
void MakeErrorInfoCommonFilePath(char* outErrorInfoCommonFilePath,
size_t errorInfoCommonFilePathBufferSize, ErrorCode errorCode);
void MakeErrorInfoDirectoryPath(char* outErrorInfoDirectoryPath,
size_t errorInfoDirectoryPathBufferSize, ErrorCode errorCode);
void MakeErrorInfoMessageFilePath(char* outErrorInfoMessageFilePath,
size_t errorInfoMessageFilePathBufferSize, ErrorCode errorCode,
settings::LanguageCode languageCode, MessageKind messageKind);
void MakeErrorInfoModuleDirectoryPath(char* outErrorInfoModuleDirectoryPath,
size_t errorInfoModuleDirectoryPathBufferSize,
u32 errorCodeCategory);
void ParseApplicationErrorCodeString(
ns::ApplicationErrorCodeCategory* outApplicationErrorCodeCategory,
u32* outErrorCodeCategoryNumber, const char* errorCodeString);
void ParseErrorCodeString(ErrorCode* outErrorCode, const char* errorCodeString);
void* ReadMessageFile(char16* outBuffer, s32* outMessageLength, size_t messageBufferSize,
ErrorCode errorCode, settings::LanguageCode languageCode,
MessageKind messageKind);
void ReadMessageFile(char16* outBuffer, size_t bufferSize, const char* errorCodeString,
const settings::LanguageCode& languageCode);
void ReadVersion(ErrorMessageDatabaseVersion* outVersion);
bool TryParseApplicationErrorCodeString(
ns::ApplicationErrorCodeCategory* outApplicationErrorCodeCategory,
u32* outErrorCodeCategoryNumber, const char* errorCodeString);
bool TryParseErrorCodeString(ErrorCode* outErrorCode, const char* errorCodeString);
} // namespace nn::err::detail
8 changes: 8 additions & 0 deletions include/nn/err/detail/MessageKind.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <nn/types.h>

namespace nn::err::detail {
// What does Flv stand for?
enum class MessageKind : u8 { DialogueMessage, DialogueButton, FlvMessage, FlvButton };
} // namespace nn::err::detail
5 changes: 5 additions & 0 deletions include/nn/fs/fs_mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <nn/fs/fs_types.h>

namespace nn::ncm {
enum class SystemDataId { Err = 0x801 };
} // namespace nn::ncm

namespace nn::fs {

/*
Expand All @@ -11,6 +15,7 @@ namespace nn::fs {
bool MountSdCardForDebug(const char* mount);

Result MountSdCard(const char* mountPoint);
Result MountSystemData(const char* mountPoint, ncm::SystemDataId id);
bool IsSdCardInserted();
Result FormatSdCard();
Result FormatSdCardDryRun();
Expand Down
4 changes: 4 additions & 0 deletions include/nn/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ struct FirmwareVersion {
}
};

struct RegionCode {
s32 code;
};

Result GetFirmwareVersion(FirmwareVersion*);
} // namespace system

Expand Down
6 changes: 4 additions & 2 deletions include/nn/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ CharacterEncodingResult ConvertCharacterUtf8ToUtf32(u32* dest, char const* src);
CharacterEncodingResult ConvertStringUtf16NativeToUtf8(char*, s32, u16 const*, s32);
CharacterEncodingResult ConvertStringUtf8ToUtf16Native(u16*, s32, char const*, s32);

s32 SNPrintf(char* s, ulong n, const char* format, ...);
s32 VSNPrintf(char* s, ulong n, const char* format, va_list arg);
[[gnu::format(printf, 3, 4)]] s32 SNPrintf(char* s, size_t n, const char* format, ...);
s32 VSNPrintf(char* s, size_t n, const char* format, va_list arg);
[[gnu::format(printf, 3, 4)]] s32 TSNPrintf(char* s, size_t n, const char* format, ...);
s32 TVSNPrintf(char* s, size_t n, const char* format, va_list arg);

void ReferSymbol(const void*);
} // namespace util
Expand Down
Loading
Loading