Fixing bugs. bsdInitialize currently fails with 0xe401, probably due to ipc bug

This commit is contained in:
plutoo 2017-09-11 04:38:38 +02:00
parent d8eb347247
commit 6c2d06f9a8
7 changed files with 27 additions and 10 deletions

View File

@ -100,23 +100,23 @@ static inline void ipcSendHandleMove(IpcCommand* cmd, Handle h) {
static inline void* ipcPrepareHeader(IpcCommand* cmd, size_t sizeof_raw) {
u32* buf = armGetTls();
size_t i;
*buf++ = 4 | (cmd->NumStaticIn << 16) | (cmd->NumSend << 20) | (cmd->NumRecv << 24) | (cmd->NumTransfer << 28);
if (cmd->SendPid || cmd->NumHandlesCopy > 0 || cmd->NumHandlesMove > 0) {
*buf++ = (sizeof_raw/4) | 0x80000000;
*buf++ = (!!cmd->SendPid) | (cmd->NumHandlesCopy << 1) | (cmd->NumHandlesMove << 1);
*buf++ = (!!cmd->SendPid) | (cmd->NumHandlesCopy << 1) | (cmd->NumHandlesMove << 5);
if (cmd->SendPid)
buf += 2;
buf += cmd->NumHandlesCopy;
buf += cmd->NumHandlesMove;
for (i=0; i<(cmd->NumHandlesCopy + cmd->NumHandlesMove); i++)
*buf++ = cmd->Handles[i];
}
else {
*buf++ = sizeof_raw/4;
}
size_t i;
for (i=0; i<cmd->NumStaticIn; i++, buf+=2) {
IpcStaticSendDescriptor* desc = (IpcStaticSendDescriptor*) buf;
uintptr_t ptr = (uintptr_t) cmd->Statics[i];

View File

@ -8,3 +8,7 @@ typedef enum {
PERM_R = 1,
PERM_RW = 3
} Permission;
Result tmemCreate(TransferMemory* t, size_t size, Permission perm);
Result tmemClose(TransferMemory* t);

View File

@ -18,6 +18,7 @@ static inline void* armGetTls(void) {
return ret;
}
Result svcSetHeapSize(void** out_addr, u64 size);
Result svcQueryMemory(u32 *meminfo_ptr, u32 *pageinfo, u64 addr);
Result svcCloseHandle(Handle handle);
Result svcCreateTransferMemory(Handle* out, void* addr, size_t size, u32 perm);

View File

@ -19,7 +19,6 @@ struct HeapHeader {
static HeapHeader g_LastFree;
void heapInit(void* base, size_t size) {
// Called by crt0.
HeapHeader* hdr = (HeapHeader*) base;
hdr->Next = &g_LastFree;
@ -32,8 +31,10 @@ void heapInit(void* base, size_t size) {
}
void heapSetup() {
static u8 g_Heap[0x20000];
heapInit(g_Heap, sizeof(g_Heap));
// Called by crt0.
#define HEAP_SIZE 0x20000
static u8 g_Heap[HEAP_SIZE];
heapInit(&g_Heap[0], HEAP_SIZE);
}
void* heapAllocPages(size_t size) {

View File

@ -11,6 +11,14 @@
.cfi_endproc
.endm
SVC_BEGIN svcSetHeapSize
str x0, [sp, #-16]!
svc 1
ldr x2, [sp], #16
str x1, [x2]
ret
SVC_END
SVC_BEGIN svcQueryMemory
str x1, [sp, #-16]!
svc 0x6

View File

@ -33,6 +33,8 @@ Result bsdInitialize(TransferMemory* tmem) {
raw->unk[3] = 0;
raw->unk[4] = 0;
raw->tmem_sz = tmem->Size;
rc = ipcDispatch(g_bsdHandle);
}
return rc;

View File

@ -5,8 +5,9 @@ static Handle g_smHandle = -1;
Result smInitialize() {
Result rc = svcConnectToNamedPort(&g_smHandle, "sm:");
Handle tmp;
if (R_SUCCEEDED(rc)) {
if (R_SUCCEEDED(rc) && smGetService(&tmp, "") == 0x415) {
IpcCommand c;
ipcInitialize(&c);
ipcSendPid(&c);
@ -47,10 +48,10 @@ Result smGetService(Handle* handle_out, const char* name) {
size_t i;
for (i=0; i<8; i++) {
name_encoded = (name_encoded >> 8) | (((u64) name[i]) << 56);
if (name[i] == '\0')
break;
name_encoded |= ((u64) name[i]) << (8*i);
}
IpcCommand c;