PS2SDK
PS2 Homebrew Libraries
exit.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Licenced under Academic Free License version 2.0
7 # Review ps2sdk README & LICENSE files for further details.
8 */
9 
15 #include "kernel.h"
16 #include "string.h"
17 
18 extern char **_kExecArg;
19 const char *SetArg(const char *filename, int argc, char *argv[]);
20 
21 #ifdef F__exit_internals
22 char **_kExecArg;
23 #endif
24 
25 #ifdef F_SetArg
26 struct SyscallData
27 {
28  int syscall;
29  void *function;
30 };
31 
32 struct SyscallData SysEntry = {
33  0x5A,
34  &kCopyBytes};
35 
36 #define SETARG_MAX_ARGS 15
37 
38 const char *SetArg(const char *filename, int argc, char *argv[])
39 {
40  const char *filenameOut;
41  char *ptr;
42  int len, i;
43 
44  ptr = (char *)(_kExecArg + 16);
45  filenameOut = ptr;
46  setup(SysEntry.syscall, SysEntry.function);
47  argc = (argc > SETARG_MAX_ARGS) ? SETARG_MAX_ARGS : argc;
48  Copy(&_kExecArg[0], &ptr, 4);
49  len = strlen(filename) + 1;
50  Copy(ptr, filename, len);
51  ptr += len;
52 
53  for (i = 0; i < argc; i++) {
54  Copy(&_kExecArg[1 + i], &ptr, 4);
55  len = strlen(argv[i]) + 1;
56  Copy(ptr, argv[i], len);
57  ptr += len;
58  }
59 
60  return filenameOut;
61 }
62 #endif
63 
64 #ifdef F_Exit
65 __attribute__((weak))
66 void Exit(s32 exit_code)
67 {
68  TerminateLibrary();
69  KExit(exit_code);
70 }
71 #endif
72 
73 #ifdef F_ExecPS2
74 __attribute__((weak))
75 s32 ExecPS2(void *entry, void *gp, int num_args, char *args[])
76 {
77  SetArg("", num_args, args);
78  TerminateLibrary();
79  return _ExecPS2(entry, gp, num_args, &_kExecArg[1]);
80 }
81 #endif
82 
83 #ifdef F_LoadExecPS2
84 __attribute__((weak))
85 void LoadExecPS2(const char *filename, s32 num_args, char *args[])
86 {
87  const char *pFilename;
88 
89  pFilename = SetArg(filename, num_args, args);
90  TerminateLibrary();
91  _LoadExecPS2(pFilename, num_args, &_kExecArg[1]);
92 }
93 #endif
94 
95 #ifdef F_ExecOSD
96 __attribute__((weak))
97 void ExecOSD(int num_args, char *args[])
98 {
99  SetArg("", num_args, args);
100  TerminateLibrary();
101  _ExecOSD(num_args, &_kExecArg[1]);
102 }
103 #endif
kernel.h
SyscallData
Definition: alarm.c:22
__attribute__
typedef __attribute__
Definition: tlbfunc.c:60