-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathexit.c
More file actions
103 lines (87 loc) · 2.15 KB
/
Copy pathexit.c
File metadata and controls
103 lines (87 loc) · 2.15 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
*/
/**
* @file
* exit - Termination functions for libkernel.
*/
#include "kernel.h"
#include "string.h"
extern char **_kExecArg;
const char *SetArg(const char *filename, int argc, char *argv[]);
#ifdef F__exit_internals
char **_kExecArg;
#endif
#ifdef F_SetArg
struct SyscallData
{
int syscall;
void *function;
};
static const struct SyscallData SysEntry = {
0x5A,
&kCopyBytes};
#define SETARG_MAX_ARGS 15
const char *SetArg(const char *filename, int argc, char *argv[])
{
const char *filenameOut;
char *ptr;
int len, i;
ptr = (char *)(_kExecArg + 16);
filenameOut = ptr;
setup(SysEntry.syscall, SysEntry.function);
argc = (argc > SETARG_MAX_ARGS) ? SETARG_MAX_ARGS : argc;
Copy(&_kExecArg[0], &ptr, 4);
len = strlen(filename) + 1;
Copy(ptr, filename, len);
ptr += len;
for (i = 0; i < argc; i++) {
Copy(&_kExecArg[1 + i], &ptr, 4);
len = strlen(argv[i]) + 1;
Copy(ptr, argv[i], len);
ptr += len;
}
return filenameOut;
}
#endif
#ifdef F_Exit
__attribute__((weak))
void Exit(s32 exit_code)
{
TerminateLibrary();
KExit(exit_code);
}
#endif
#ifdef F_ExecPS2
__attribute__((weak))
s32 ExecPS2(void *entry, void *gp, int num_args, char *args[])
{
SetArg("", num_args, args);
TerminateLibrary();
return _ExecPS2(entry, gp, num_args, &_kExecArg[1]);
}
#endif
#ifdef F_LoadExecPS2
__attribute__((weak))
void LoadExecPS2(const char *filename, s32 num_args, char *args[])
{
const char *pFilename;
pFilename = SetArg(filename, num_args, args);
TerminateLibrary();
_LoadExecPS2(pFilename, num_args, &_kExecArg[1]);
}
#endif
#ifdef F_ExecOSD
__attribute__((weak))
void ExecOSD(int num_args, char *args[])
{
SetArg("", num_args, args);
TerminateLibrary();
_ExecOSD(num_args, &_kExecArg[1]);
}
#endif