2017-06-05 02:02:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Luma3DS
|
2018-06-14 18:13:57 +02:00
|
|
|
* Copyright (C) 2016-2018 Aurora Wright, TuxSH
|
2017-06-05 02:02:04 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that 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/>.
|
|
|
|
*
|
|
|
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
|
|
* * Requiring preservation of specified reasonable legal notices or
|
|
|
|
* author attributions in that material or in the Appropriate Legal
|
|
|
|
* Notices displayed by works containing it.
|
|
|
|
* * Prohibiting misrepresentation of the origin of that material,
|
|
|
|
* or requiring that modified versions of such material be marked in
|
|
|
|
* reasonable ways as different from the original version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <3ds.h>
|
|
|
|
#include "memory.h"
|
|
|
|
#include "services.h"
|
|
|
|
#include "fsreg.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "errdisp.h"
|
|
|
|
#include "hbloader.h"
|
|
|
|
#include "utils.h"
|
2018-06-23 23:06:18 +02:00
|
|
|
#include "sleep.h"
|
2017-06-05 02:02:04 +02:00
|
|
|
#include "MyThread.h"
|
|
|
|
#include "menus/process_patches.h"
|
2017-06-18 22:31:21 +02:00
|
|
|
#include "menus/miscellaneous.h"
|
2018-11-15 13:38:19 +01:00
|
|
|
#include "plgloader.h"
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
// this is called before main
|
|
|
|
bool isN3DS;
|
|
|
|
void __appInit()
|
|
|
|
{
|
|
|
|
srvSysInit();
|
|
|
|
fsregInit();
|
2017-06-16 04:21:48 +02:00
|
|
|
|
2017-06-05 02:02:04 +02:00
|
|
|
fsSysInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is called after main exits
|
|
|
|
void __appExit()
|
|
|
|
{
|
2018-06-23 23:06:18 +02:00
|
|
|
acExit();
|
2017-06-05 02:02:04 +02:00
|
|
|
fsExit();
|
|
|
|
fsregExit();
|
|
|
|
srvSysExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Result __sync_init(void);
|
|
|
|
Result __sync_fini(void);
|
|
|
|
void __libc_init_array(void);
|
|
|
|
void __libc_fini_array(void);
|
|
|
|
|
|
|
|
void __ctru_exit()
|
|
|
|
{
|
|
|
|
__appExit();
|
|
|
|
__sync_fini();
|
|
|
|
__libc_fini_array();
|
2017-06-13 02:00:41 +02:00
|
|
|
for(;;) svcSleepThread(0); // kernel-loaded sysmodules except PXI are not supposed to terminate anyways
|
2017-06-05 02:02:04 +02:00
|
|
|
svcExitProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void initSystem()
|
|
|
|
{
|
2017-06-13 02:00:41 +02:00
|
|
|
__libc_init_array();
|
2017-06-18 22:31:21 +02:00
|
|
|
|
|
|
|
s64 out;
|
|
|
|
isN3DS = svcGetSystemInfo(&out, 0x10001, 0) == 0;
|
|
|
|
|
|
|
|
svcGetSystemInfo(&out, 0x10000, 0x100);
|
|
|
|
HBLDR_3DSX_TID = out == 0 ? HBLDR_DEFAULT_3DSX_TID : (u64)out;
|
|
|
|
|
|
|
|
svcGetSystemInfo(&out, 0x10000, 0x101);
|
|
|
|
menuCombo = out == 0 ? DEFAULT_MENU_COMBO : (u32)out;
|
|
|
|
|
|
|
|
miscellaneousMenu.items[0].title = HBLDR_3DSX_TID == HBLDR_DEFAULT_3DSX_TID ? "Switch the hb. title to the current app." :
|
|
|
|
"Switch the hb. title to hblauncher_loader";
|
2017-11-02 21:52:14 +01:00
|
|
|
|
|
|
|
ProcessPatchesMenu_PatchUnpatchFSDirectly();
|
2017-06-05 02:02:04 +02:00
|
|
|
__sync_init();
|
|
|
|
__appInit();
|
2018-01-15 02:27:07 +01:00
|
|
|
|
|
|
|
// ROSALINA HACKJOB BEGIN
|
|
|
|
// NORMAL APPS SHOULD NOT DO THIS, EVER
|
|
|
|
u32 *tls = (u32 *)getThreadLocalStorage();
|
|
|
|
memset(tls, 0, 0x80);
|
2018-06-14 18:13:57 +02:00
|
|
|
tls[0] = 0x21545624;
|
2018-01-15 02:27:07 +01:00
|
|
|
// ROSALINA HACKJOB END
|
|
|
|
|
|
|
|
// Rosalina specific:
|
|
|
|
srvSetBlockingPolicy(true); // GetServiceHandle nonblocking if service port is full
|
2017-06-05 02:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool terminationRequest = false;
|
|
|
|
Handle terminationRequestEvent;
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
Result res = 0;
|
|
|
|
Handle notificationHandle;
|
|
|
|
|
2018-11-15 13:38:19 +01:00
|
|
|
MyThread *menuThread = menuCreateThread(), *errDispThread = errDispCreateThread(),
|
|
|
|
*hbldrThread = hbldrCreateThread(), *plgloaderThread = PluginLoader__CreateThread();
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
if(R_FAILED(srvEnableNotification(¬ificationHandle)))
|
|
|
|
svcBreak(USERBREAK_ASSERT);
|
|
|
|
|
|
|
|
if(R_FAILED(svcCreateEvent(&terminationRequestEvent, RESET_STICKY)))
|
|
|
|
svcBreak(USERBREAK_ASSERT);
|
|
|
|
|
2018-06-23 23:06:18 +02:00
|
|
|
Sleep__Init();
|
|
|
|
|
2017-06-05 02:02:04 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
res = svcWaitSynchronization(notificationHandle, -1LL);
|
|
|
|
|
|
|
|
if(R_FAILED(res))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
u32 notifId = 0;
|
|
|
|
|
|
|
|
if(R_FAILED(srvReceiveNotification(¬ifId)))
|
|
|
|
svcBreak(USERBREAK_ASSERT);
|
|
|
|
|
|
|
|
if(notifId == 0x100)
|
|
|
|
{
|
|
|
|
// Termination request
|
|
|
|
terminationRequest = true;
|
|
|
|
svcSignalEvent(terminationRequestEvent);
|
|
|
|
}
|
2018-06-23 23:06:18 +02:00
|
|
|
|
|
|
|
Sleep__HandleNotification(notifId);
|
2017-06-05 02:02:04 +02:00
|
|
|
}
|
|
|
|
while(!terminationRequest);
|
|
|
|
|
|
|
|
MyThread_Join(menuThread, -1LL);
|
|
|
|
MyThread_Join(errDispThread, -1LL);
|
|
|
|
MyThread_Join(hbldrThread, -1LL);
|
2018-11-15 13:38:19 +01:00
|
|
|
MyThread_Join(plgloaderThread, -1LL);
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
svcCloseHandle(notificationHandle);
|
|
|
|
return 0;
|
|
|
|
}
|