mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-28 09:30:58 +01:00
Stratosphere: Add Registration Management to Loader
This commit is contained in:
parent
c5b7f39a67
commit
30e401d125
@ -7,10 +7,6 @@ Result DebugMonitorService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32
|
||||
|
||||
Result rc = 0xF601;
|
||||
|
||||
fprintf(stderr, "TLS: %p\n", armGetTls());
|
||||
|
||||
/* TODO: Prepare SFCO. */
|
||||
|
||||
switch ((DebugMonitorServiceCmd)cmd_id) {
|
||||
case Dmnt_Cmd_AddTitleToLaunchQueue:
|
||||
/* Validate arguments. */
|
||||
@ -25,7 +21,7 @@ Result DebugMonitorService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32
|
||||
|
||||
rc = add_title_to_launch_queue(((u64 *)in_rawdata)[0], (const char *)r->Statics[0], r->StaticSizes[0]);
|
||||
|
||||
*out_raw_data_count = 4;
|
||||
*out_raw_data_count = 0;
|
||||
|
||||
break;
|
||||
case Dmnt_Cmd_ClearLaunchQueue:
|
||||
@ -34,7 +30,7 @@ Result DebugMonitorService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32
|
||||
}
|
||||
|
||||
rc = clear_launch_queue();
|
||||
*out_raw_data_count = 4;
|
||||
*out_raw_data_count = 0;
|
||||
|
||||
break;
|
||||
case Dmnt_Cmd_GetNsoInfo:
|
||||
|
@ -3,11 +3,9 @@
|
||||
#include <cstdio>
|
||||
#include "ldr_launch_queue.hpp"
|
||||
|
||||
static LaunchQueue::LaunchItem g_launch_queue[LAUNCH_QUEUE_SIZE] = {0};
|
||||
|
||||
namespace LaunchQueue {
|
||||
static LaunchItem g_launch_queue[LAUNCH_QUEUE_SIZE];
|
||||
|
||||
Result add(u64 tid, const char *args, u64 arg_size) {
|
||||
Result LaunchQueue::add(u64 tid, const char *args, u64 arg_size) {
|
||||
if(arg_size > LAUNCH_QUEUE_ARG_SIZE_MAX) {
|
||||
return 0x209;
|
||||
}
|
||||
@ -19,14 +17,11 @@ namespace LaunchQueue {
|
||||
g_launch_queue[idx].tid = tid;
|
||||
g_launch_queue[idx].arg_size = arg_size;
|
||||
|
||||
fprintf(stderr, "TID: %016llx, args: %p, size: %016llx\n", tid, args, arg_size);
|
||||
fprintf(stderr, "Args: %s\n", args);
|
||||
|
||||
std::copy(args, args + arg_size, g_launch_queue[idx].args);
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
Result add_item(const LaunchItem *item) {
|
||||
Result LaunchQueue::add_item(const LaunchItem *item) {
|
||||
if(item->arg_size > LAUNCH_QUEUE_ARG_SIZE_MAX) {
|
||||
return 0x209;
|
||||
}
|
||||
@ -39,7 +34,7 @@ namespace LaunchQueue {
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
int get_index(u64 tid) {
|
||||
int LaunchQueue::get_index(u64 tid) {
|
||||
for(unsigned int i = 0; i < LAUNCH_QUEUE_SIZE; i++) {
|
||||
if(g_launch_queue[i].tid == tid) {
|
||||
return i;
|
||||
@ -48,7 +43,7 @@ namespace LaunchQueue {
|
||||
return LAUNCH_QUEUE_FULL;
|
||||
}
|
||||
|
||||
int get_free_index(u64 tid) {
|
||||
int LaunchQueue::get_free_index(u64 tid) {
|
||||
for(unsigned int i = 0; i < LAUNCH_QUEUE_SIZE; i++) {
|
||||
if(g_launch_queue[i].tid == tid || g_launch_queue[i].tid == 0x0) {
|
||||
return i;
|
||||
@ -57,13 +52,12 @@ namespace LaunchQueue {
|
||||
return LAUNCH_QUEUE_FULL;
|
||||
}
|
||||
|
||||
bool contains(u64 tid) {
|
||||
bool LaunchQueue::contains(u64 tid) {
|
||||
return get_index(tid) != LAUNCH_QUEUE_FULL;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
void LaunchQueue::clear() {
|
||||
for (unsigned int i = 0; i < LAUNCH_QUEUE_SIZE; i++) {
|
||||
g_launch_queue[i].tid = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,17 +6,18 @@
|
||||
|
||||
#define LAUNCH_QUEUE_ARG_SIZE_MAX (0x8000)
|
||||
|
||||
namespace LaunchQueue {
|
||||
class LaunchQueue {
|
||||
public:
|
||||
struct LaunchItem {
|
||||
u64 tid;
|
||||
u64 arg_size;
|
||||
char args[LAUNCH_QUEUE_ARG_SIZE_MAX];
|
||||
};
|
||||
|
||||
Result add(u64 tid, const char *args, u64 arg_size);
|
||||
Result add_item(const LaunchItem *item);
|
||||
int get_index(u64 tid);
|
||||
int get_free_index(u64 tid);
|
||||
bool contains(u64 tid);
|
||||
void clear();
|
||||
}
|
||||
static Result add(u64 tid, const char *args, u64 arg_size);
|
||||
static Result add_item(const LaunchItem *item);
|
||||
static int get_index(u64 tid);
|
||||
static int get_free_index(u64 tid);
|
||||
static bool contains(u64 tid);
|
||||
static void clear();
|
||||
};
|
80
stratosphere/loader/source/ldr_registration.cpp
Normal file
80
stratosphere/loader/source/ldr_registration.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include <switch.h>
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include "ldr_registration.hpp"
|
||||
|
||||
static Registration::List g_registration_list = {0};
|
||||
static u64 g_num_registered = 1;
|
||||
|
||||
Registration::Process *get_free_process() {
|
||||
unsigned int i;
|
||||
for (i = 0; i < REGISTRATION_LIST_MAX; i++) {
|
||||
if (!g_registration_list.processes[i].in_use) {
|
||||
return &g_registration_list.processes[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Registration::Process *get_process(u64 index) {
|
||||
unsigned int i;
|
||||
for (i = 0; !g_registration_list.processes[i].in_use || g_registration_list.processes[i].index != index; i++) {
|
||||
if (i >= REGISTRATION_LIST_MAX) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return &g_registration_list.processes[i];
|
||||
}
|
||||
|
||||
bool Registration::register_tid_sid(const TidSid *tid_sid, u64 *out_index) {
|
||||
Registration::Process *free_process = get_free_process();
|
||||
if (free_process == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Reset the process. */
|
||||
*free_process = {0};
|
||||
free_process->tid_sid = *tid_sid;
|
||||
free_process->in_use = true;
|
||||
free_process->index = g_num_registered++;
|
||||
*out_index = free_process->index;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Registration::unregister_index(u64 index) {
|
||||
Registration::Process *target_process = get_process(index);
|
||||
if (target_process == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Reset the process. */
|
||||
*target_process = {0};
|
||||
return true;
|
||||
}
|
||||
|
||||
void Registration::set_process_id_and_tid_min(u64 index, u64 process_id, u64 tid_min) {
|
||||
Registration::Process *target_process = get_process(index);
|
||||
if (target_process == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
target_process->process_id = process_id;
|
||||
target_process->title_id_min = tid_min;
|
||||
}
|
||||
|
||||
void Registration::add_nso_info(u64 index, u64 base_address, u64 size, const unsigned char *build_id) {
|
||||
Registration::Process *target_process = get_process(index);
|
||||
if (target_process == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < NSO_INFO_MAX; i++) {
|
||||
if (!target_process->nso_infos[i].in_use) {
|
||||
target_process->nso_infos[i].base_address = base_address;
|
||||
target_process->nso_infos[i].size = size;
|
||||
std::copy(build_id, build_id + sizeof(target_process->nso_infos[i].build_id), target_process->nso_infos[i].build_id);
|
||||
target_process->nso_infos[i].in_use = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
43
stratosphere/loader/source/ldr_registration.hpp
Normal file
43
stratosphere/loader/source/ldr_registration.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
|
||||
#define REGISTRATION_LIST_MAX (0x40)
|
||||
|
||||
#define NSO_INFO_MAX (0x20)
|
||||
|
||||
class Registration {
|
||||
public:
|
||||
struct NsoInfo {
|
||||
bool in_use;
|
||||
u64 base_address;
|
||||
u64 size;
|
||||
unsigned char build_id[0x20];
|
||||
};
|
||||
|
||||
struct TidSid {
|
||||
u64 title_id;
|
||||
FsStorageId storage_id;
|
||||
};
|
||||
|
||||
struct Process {
|
||||
bool in_use;
|
||||
u64 index;
|
||||
u64 process_id;
|
||||
u64 title_id_min;
|
||||
Registration::TidSid tid_sid;
|
||||
Registration::NsoInfo nso_infos[NSO_INFO_MAX];
|
||||
u64 _0x730;
|
||||
};
|
||||
|
||||
struct List {
|
||||
Registration::Process processes[REGISTRATION_LIST_MAX];
|
||||
u64 num_processes;
|
||||
};
|
||||
|
||||
static Registration::Process *get_free_process();
|
||||
static Registration::Process *get_process(u64 index);
|
||||
static bool register_tid_sid(const TidSid *tid_sid, u64 *out_index);
|
||||
static bool unregister_index(u64 index);
|
||||
static void set_process_id_and_tid_min(u64 index, u64 process_id, u64 tid_min);
|
||||
static void add_nso_info(u64 index, u64 base_address, u64 size, const unsigned char *build_id);
|
||||
};
|
@ -6,8 +6,6 @@ Result ShellService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32 *cmd_b
|
||||
|
||||
Result rc = 0xF601;
|
||||
|
||||
/* TODO: Prepare SFCO. */
|
||||
|
||||
switch ((ShellServiceCmd)cmd_id) {
|
||||
case Cmd_AddTitleToLaunchQueue:
|
||||
/* Validate arguments. */
|
||||
@ -15,6 +13,11 @@ Result ShellService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32 *cmd_b
|
||||
break;
|
||||
}
|
||||
|
||||
if (r->Statics[0] == NULL) {
|
||||
rc = 0xCE01;
|
||||
break;
|
||||
}
|
||||
|
||||
rc = add_title_to_launch_queue(((u64 *)in_rawdata)[0], (const char *)r->Statics[0], r->StaticSizes[0]);
|
||||
|
||||
*out_raw_data_count = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user