Skip to content

Commit

Permalink
Improve IPC handling
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts committed Apr 19, 2023
1 parent 7baf119 commit 88650a8
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 33 deletions.
4 changes: 2 additions & 2 deletions ios/ios_kernel/source/pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ void run_ios_pad_patches(void)
// hook security procedures
*(volatile uint32_t *) 0x11f14f00 = ARM_B(0x11f14f00, btm_sec_execute_procedure_hook);

// hook btrm messages so we can have custom ipc calls
*(volatile uint32_t *) 0x11f0274c = ARM_BL(0x11f0274c, btrm_receive_message_hook);
// hook btrm lib handling so we can have custom ipc calls
*(volatile uint32_t *) 0x11f03428 = ARM_B(0x11f03428, _btrmCustomLibHook);

#ifdef MORE_LOGS
/******************************************************************************
Expand Down
37 changes: 10 additions & 27 deletions ios/ios_pad/source/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "ipc.h"
#include "info_store.h"
#include "bloopair_ipc.h"
#include <bloopair/ipc.h>

static int bloopairFunc(BtrmRequest* request, BtrmResponse* response)
{
Expand Down Expand Up @@ -63,34 +63,17 @@ static int bloopairFunc(BtrmRequest* request, BtrmResponse* response)
return -1;
}

int btrm_receive_message_hook(int queueid, IPCMessage_t **p_message, uint32_t flags)
int btrmCustomLibHook(BtrmRequest* request, BtrmResponse* response)
{
int res = IOS_ReceiveMessage(queueid, (uint32_t*) p_message, flags);
if (res != 0) {
return res;
}

IPCMessage_t* message = *p_message;

// there are some event messages which aren't ipcmessage pointers
if (message < (IPCMessage_t*) 0x1000) {
return res;
}

if (message->command == IOS_IOCTLV && message->ioctlv.command == 0 &&
message->ioctlv.num_in == 1 && message->ioctlv.num_out == 1 &&
message->ioctlv.vecs[0].len == sizeof(BtrmRequest) &&
message->ioctlv.vecs[1].len == sizeof(BtrmResponse)) {

BtrmRequest* request = (BtrmRequest*) message->ioctlv.vecs[0].ptr;
BtrmResponse* response = (BtrmResponse*) message->ioctlv.vecs[1].ptr;
return bloopairFunc(request, response);
}

if (request->lib == BLOOPAIR_LIB) {
// if this was a bloopair command reply and wait for the next message
IOS_ResourceReply(message, bloopairFunc(request, response));
return btrm_receive_message_hook(queueid, p_message, flags);
}
// return non-0 if btrmCustomLibHook should be called for this lib
int btrmCheckCustomLib(uint8_t lib)
{
if (lib == BLOOPAIR_LIB) {
return 1;
}

return res;
return 0;
}
23 changes: 23 additions & 0 deletions ios/ios_pad/source/ipc_asm.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.arm

.extern btrmCustomLibHook
.extern btrmCheckCustomLib

.global _btrmCustomLibHook
_btrmCustomLibHook:
@ check if this is a supported lib
mov r0, r1
bl btrmCheckCustomLib

@ if not branch to fail
cmp r0, #0
ldreq pc, =0x11f03974

@ call custom lib impl
mov r0, r6
mov r1, r11
bl btrmCustomLibHook

@ proceed with response
mov r1, r0
ldr pc, =0x11f028a8
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#pragma once

#include "bloopair_ipc.h"
#include "ipc.h"
#include <coreinit/ios.h>

#ifdef __cplusplus
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion libbloopair/source/bloopair.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "bloopair.h"
#include "bloopair/bloopair.h"

#include <stdlib.h>
#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion loader/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <bloopair.h>
#include <bloopair/bloopair.h>

#include <stdio.h>
#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion pair_menu/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <bloopair.h>
#include <bloopair/bloopair.h>

#include <unistd.h>
#include <cstring>
Expand Down

0 comments on commit 88650a8

Please sign in to comment.