mirror of
https://github.com/ps5-payload-dev/elfldr.git
synced 2026-10-19 02:19:52 -05:00
wait for payloads to terminate, and deal with fatal signals
This commit is contained in:
1 parent
18f989dba7
commit
e2e389fc1c
5 files changed
+50
-20
No files matched your search
@@ -24,7 +24,7 @@ PS5_PORT ?= 9020
|
||||
CC := $(PS5_PAYLOAD_SDK)/host/x86_64-ps5-payload-cc
|
||||
LD := $(PS5_PAYLOAD_SDK)/host/x86_64-ps5-payload-ld
|
||||
|
||||
CFLAGS := -O2 -Wall -Werror
|
||||
CFLAGS := -g -Wall -Werror
|
||||
|
||||
all: bootstrap.elf
|
||||
|
||||
|
||||
@@ -456,7 +456,7 @@ elfldr_spawn(uint8_t *elf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(pt_continue(pid)) {
|
||||
if(pt_continue(pid, SIGCONT)) {
|
||||
perror("[elfldr.elf] pt_continue");
|
||||
pt_detach(pid);
|
||||
return -1;
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program; see the file COPYING. If not, see
|
||||
#include <fcntl.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <netinet/in.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
@@ -27,10 +28,12 @@ along with this program; see the file COPYING. If not, see
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <ps5/kernel.h>
|
||||
|
||||
#include "elfldr.h"
|
||||
#include "pt.h"
|
||||
|
||||
|
||||
/**
|
||||
@@ -99,6 +102,45 @@ readsock(int fd) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
**/
|
||||
static void*
|
||||
serve_thread(void* args) {
|
||||
int fd = (int)(long)args;
|
||||
uint8_t* elf;
|
||||
int status;
|
||||
pid_t pid;
|
||||
|
||||
if(!(elf=readsock(fd))) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(memcmp(elf, "\x7f\x45\x4c\x46", 4)) {
|
||||
close(fd);
|
||||
free(elf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if((pid=elfldr_spawn(elf)) < 0) {
|
||||
close(fd);
|
||||
free(elf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
free(elf);
|
||||
|
||||
waitpid(pid, &status, WTRAPPED | WUNTRACED);
|
||||
if(WIFSTOPPED(status)) {
|
||||
printf("PID %d received the fatal POSIX signal %d\n", pid, WSTOPSIG(status));
|
||||
pt_continue(pid, SIGKILL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
**/
|
||||
@@ -110,7 +152,7 @@ serve_elfldr(uint16_t port) {
|
||||
struct ifaddrs *ifaddr;
|
||||
int ifaddr_wait = 1;
|
||||
socklen_t socklen;
|
||||
uint8_t* elf;
|
||||
pthread_t trd;
|
||||
int connfd;
|
||||
int srvfd;
|
||||
|
||||
@@ -143,7 +185,7 @@ serve_elfldr(uint16_t port) {
|
||||
}
|
||||
ifaddr_wait = 0;
|
||||
|
||||
notify("Serving ELF loader on %s:%d (%s)\n", ip, port, ifa->ifa_name);
|
||||
notify("Serving ELF loader on %s:%d (%s)", ip, port, ifa->ifa_name);
|
||||
}
|
||||
|
||||
freeifaddrs(ifaddr);
|
||||
@@ -183,19 +225,7 @@ serve_elfldr(uint16_t port) {
|
||||
perror("[elfldr.elf] accept");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!(elf=readsock(connfd))) {
|
||||
close(connfd);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!memcmp(elf, "\x7f\x45\x4c\x46", 4)) {
|
||||
elfldr_spawn(elf);
|
||||
} else {
|
||||
write(connfd, "Not an ELF file\n", 16);
|
||||
}
|
||||
free(elf);
|
||||
close(connfd);
|
||||
pthread_create(&trd, NULL, serve_thread, (void*)(long)connfd);
|
||||
}
|
||||
|
||||
return close(srvfd);
|
||||
|
||||
@@ -118,8 +118,8 @@ pt_step(int pid) {
|
||||
|
||||
|
||||
int
|
||||
pt_continue(pid_t pid) {
|
||||
if(sys_ptrace(PT_CONTINUE, pid, (caddr_t)1, SIGCONT) == -1) {
|
||||
pt_continue(pid_t pid, int sig) {
|
||||
if(sys_ptrace(PT_CONTINUE, pid, (caddr_t)1, sig) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ along with this program; see the file COPYING. If not, see
|
||||
int pt_attach(pid_t pid);
|
||||
int pt_detach(pid_t pid);
|
||||
int pt_step(pid_t pid);
|
||||
int pt_continue(pid_t pid);
|
||||
int pt_continue(pid_t pid, int sig);
|
||||
|
||||
int pt_getregs(pid_t pid, struct reg *r);
|
||||
int pt_setregs(pid_t pid, const struct reg *r);
|
||||
|
||||
Reference in new issue
Block a user