forked from emkey1/ish-AOK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
68 lines (56 loc) · 1.68 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdlib.h>
#include <string.h>
#include "kernel/calls.h"
#include "kernel/task.h"
#include "xX_main_Xx.h"
#include <stdio.h>
#include <signal.h>
#include <pthread.h>
#include <unistd.h>
#include "util/list.h"
#include <mach/task.h>
#include <mach/mach_init.h>
#include <mach/mach_port.h>
static void handler(int signo, siginfo_t *sigaction, void *context) {
printk("ERROR: in exception handler.\n");
signal(signo, SIG_DFL);
}
static void gen_exception(void) {
printk("WARNING: gen_exception in.\n");
*(int *)0 = 0;
printk("WARNING: gen_exception out.\n");
}
void *gen_exception_thread(void *parg) {
gen_exception();
return 0;
}
int main(int argc, char *const argv[]) {
char envp[100] = {0};
if (getenv("TERM"))
strcpy(envp, getenv("TERM") - strlen("TERM") - 1);
int err = xX_main_Xx(argc, argv, envp);
if (err < 0) {
fprintf(stderr, "xX_main_Xx: %s\n", strerror(-err));
return err;
}
do_mount(&procfs, "proc", "/proc", "", 0);
do_mount(&devptsfs, "devpts", " ", "", 0);
task_set_exception_ports(
mach_task_self(),
EXC_MASK_BAD_ACCESS,
MACH_PORT_NULL,//m_exception_port,
EXCEPTION_DEFAULT,
0);
struct sigaction sa;
sa.sa_sigaction = handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
if(sigaction(/*SIGBUS*/SIGSEGV, &sa, NULL) == -1) {
printf("sigaction fails.\n");
return 0;
}
pthread_t id;
pthread_create(&id, NULL, gen_exception_thread, NULL);
pthread_join(id, NULL);
task_run_current();
}