Skip to content

Commit

Permalink
Merge pull request #1757 from ccoffing/elksemu-syscall-fixes
Browse files Browse the repository at this point in the history
Elksemu syscall fixes
  • Loading branch information
tkchia authored Nov 26, 2023
2 parents 5f5f53d + 4269ea3 commit 0b9a693
Show file tree
Hide file tree
Showing 3 changed files with 667 additions and 574 deletions.
9 changes: 5 additions & 4 deletions elksemu/elks.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ struct elks_stat
uint16_t est_gid;
uint16_t est_rdev;
int32_t est_size;
int32_t est_atime;
int32_t est_mtime;
int32_t est_ctime;
uint32_t est_atime;
uint32_t est_mtime;
uint32_t est_ctime;
} __attribute__((packed));


Expand Down Expand Up @@ -169,7 +169,8 @@ extern unsigned char * elks_base, *elks_data_base;
extern uint16_t brk_at;
extern volatile struct elks_cpu_s elks_cpu;

void db_printf(const char *, ...);
void db_printf(const char *, ...)
__attribute__((format(printf,1,2)));
int elks_syscall(void);
void minix_syscall(void);
void elks_pid_init(void);
Expand Down
79 changes: 44 additions & 35 deletions elksemu/elks_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,55 @@
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include "elks.h"
#include "elks.h"

static int elks_sigtrap_ip = -1, elks_sigtrap_cs = -1;

void sig_trap(int signo)
void
sig_trap(int signo)
{
pid_t child = elks_cpu.child, pid;
int status;
kill(elks_cpu.child, SIGSTOP);
while (ptrace(PTRACE_GETREGS, child, NULL, &elks_cpu.regs) != 0) {
if (errno != ESRCH)
return;
}
elks_cpu.regs.xsp -= 2;
ELKS_POKE(unsigned short, elks_cpu.regs.xsp, signo);
elks_cpu.regs.xsp -= 2;
ELKS_POKE(unsigned short, elks_cpu.regs.xsp, elks_cpu.regs.xcs);
elks_cpu.regs.xsp -= 2;
ELKS_POKE(unsigned short, elks_cpu.regs.xsp, elks_cpu.regs.xip);
elks_cpu.regs.xip = elks_sigtrap_ip;
elks_cpu.regs.xcs = elks_sigtrap_cs;
if (ptrace(PTRACE_SETREGS, child, NULL, &elks_cpu.regs) != 0)
return;
kill(elks_cpu.child, SIGCONT);
pid_t child = elks_cpu.child, pid;
int status;
kill(elks_cpu.child, SIGSTOP);
while (ptrace(PTRACE_GETREGS, child, NULL, &elks_cpu.regs) != 0) {
if (errno != ESRCH)
return;
}
elks_cpu.regs.xsp -= 2;
ELKS_POKE(unsigned short, elks_cpu.regs.xsp, signo);
elks_cpu.regs.xsp -= 2;
ELKS_POKE(unsigned short, elks_cpu.regs.xsp, elks_cpu.regs.xcs);
elks_cpu.regs.xsp -= 2;
ELKS_POKE(unsigned short, elks_cpu.regs.xsp, elks_cpu.regs.xip);
elks_cpu.regs.xip = elks_sigtrap_ip;
elks_cpu.regs.xcs = elks_sigtrap_cs;
if (ptrace(PTRACE_SETREGS, child, NULL, &elks_cpu.regs) != 0)
return;
kill(elks_cpu.child, SIGCONT);
}

int elks_signal(int bx,int cx,int dx,int di,int si)
int
elks_signal(int bx, int cx, int dx, int di, int si)
{
void (*oldsig)(int) = 0;
if( bx < 0 || bx >= NSIG ) { errno = EINVAL; return -1; }
if( cx == 0 && dx == 0 ) oldsig = signal(bx, SIG_DFL);
else if( cx == 1 && dx == 0 ) oldsig = signal(bx, SIG_IGN);
else
{
elks_sigtrap_ip = cx;
elks_sigtrap_cs = dx;
oldsig = signal(bx, sig_trap);
}
if( oldsig == SIG_ERR) return -1;
if( oldsig == SIG_DFL) return 0;
if( oldsig == SIG_IGN) return 1;
return 2;
void (*oldsig) (int)= 0;
if (bx < 0 || bx >= NSIG) {
errno = EINVAL;
return -1;
}
if (cx == 0 && dx == 0)
oldsig = signal(bx, SIG_DFL);
else if (cx == 1 && dx == 0)
oldsig = signal(bx, SIG_IGN);
else {
elks_sigtrap_ip = cx;
elks_sigtrap_cs = dx;
oldsig = signal(bx, sig_trap);
}
if (oldsig == SIG_ERR)
return -1;
if (oldsig == SIG_DFL)
return 0;
if (oldsig == SIG_IGN)
return 1;
return 2;
}
Loading

0 comments on commit 0b9a693

Please sign in to comment.