2018-04-18 10:30:34 +01:00
|
|
|
#include <switch.h>
|
|
|
|
#include <algorithm>
|
2018-04-18 23:24:40 +01:00
|
|
|
#include <cstdio>
|
2018-04-18 00:41:57 +01:00
|
|
|
#include "ldr_launch_queue.hpp"
|
|
|
|
|
|
|
|
|
2018-04-18 01:04:41 +01:00
|
|
|
namespace LaunchQueue {
|
|
|
|
static LaunchItem g_launch_queue[LAUNCH_QUEUE_SIZE];
|
2018-04-18 01:05:19 +01:00
|
|
|
|
2018-04-18 10:30:34 +01:00
|
|
|
Result add(u64 tid, const char *args, u64 arg_size) {
|
|
|
|
if(arg_size > LAUNCH_QUEUE_ARG_SIZE_MAX) {
|
|
|
|
return 0x209;
|
|
|
|
}
|
|
|
|
|
|
|
|
int idx = get_free_index(tid);
|
|
|
|
if(idx == LAUNCH_QUEUE_FULL)
|
|
|
|
return 0x409;
|
|
|
|
|
|
|
|
g_launch_queue[idx].tid = tid;
|
|
|
|
g_launch_queue[idx].arg_size = arg_size;
|
2018-04-18 23:24:40 +01:00
|
|
|
|
|
|
|
fprintf(stderr, "TID: %016llx, args: %p, size: %016llx\n", tid, args, arg_size);
|
|
|
|
fprintf(stderr, "Args: %s\n", args);
|
|
|
|
|
2018-04-18 10:30:34 +01:00
|
|
|
std::copy(args, args + arg_size, g_launch_queue[idx].args);
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result add_item(const LaunchItem *item) {
|
2018-04-18 01:05:19 +01:00
|
|
|
if(item->arg_size > LAUNCH_QUEUE_ARG_SIZE_MAX) {
|
|
|
|
return 0x209;
|
|
|
|
}
|
|
|
|
|
|
|
|
int idx = get_free_index(item->tid);
|
|
|
|
if(idx == LAUNCH_QUEUE_FULL)
|
|
|
|
return 0x409;
|
2018-04-18 01:04:41 +01:00
|
|
|
|
2018-04-18 01:05:19 +01:00
|
|
|
g_launch_queue[idx] = *item;
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:04:41 +01:00
|
|
|
int get_index(u64 tid) {
|
|
|
|
for(unsigned int i = 0; i < LAUNCH_QUEUE_SIZE; i++) {
|
|
|
|
if(g_launch_queue[i].tid == tid) {
|
|
|
|
return i;
|
|
|
|
}
|
2018-04-18 00:41:57 +01:00
|
|
|
}
|
2018-04-18 01:04:41 +01:00
|
|
|
return LAUNCH_QUEUE_FULL;
|
2018-04-18 00:41:57 +01:00
|
|
|
}
|
2018-04-18 01:04:41 +01:00
|
|
|
|
|
|
|
int 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;
|
|
|
|
}
|
2018-04-18 00:41:57 +01:00
|
|
|
}
|
2018-04-18 01:04:41 +01:00
|
|
|
return LAUNCH_QUEUE_FULL;
|
2018-04-18 00:41:57 +01:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:04:41 +01:00
|
|
|
bool contains(u64 tid) {
|
|
|
|
return get_index(tid) != LAUNCH_QUEUE_FULL;
|
|
|
|
}
|
2018-04-18 00:41:57 +01:00
|
|
|
|
2018-04-18 01:04:41 +01:00
|
|
|
void clear() {
|
|
|
|
for (unsigned int i = 0; i < LAUNCH_QUEUE_SIZE; i++) {
|
|
|
|
g_launch_queue[i].tid = 0;
|
|
|
|
}
|
2018-04-18 00:41:57 +01:00
|
|
|
}
|
|
|
|
}
|