mirror of
https://github.com/pspdev/pspsdk.git
synced 2025-10-04 09:08:30 +00:00
Improve exit flow
This commit is contained in:
@@ -37,8 +37,6 @@ INIT_OBJS = \
|
|||||||
__libcglue_init.o \
|
__libcglue_init.o \
|
||||||
__gprof_cleanup.o \
|
__gprof_cleanup.o \
|
||||||
__libcglue_deinit.o \
|
__libcglue_deinit.o \
|
||||||
_exit.o \
|
|
||||||
abort.o \
|
|
||||||
exit.o
|
exit.o
|
||||||
|
|
||||||
LOCK_OBJS = \
|
LOCK_OBJS = \
|
||||||
|
@@ -29,8 +29,6 @@ void __deinit_mutex();
|
|||||||
void __locks_init();
|
void __locks_init();
|
||||||
void __locks_deinit();
|
void __locks_deinit();
|
||||||
|
|
||||||
extern int sce_newlib_nocreate_thread_in_start __attribute__((weak));
|
|
||||||
|
|
||||||
#ifdef F___gprof_cleanup
|
#ifdef F___gprof_cleanup
|
||||||
/* Note: This function is being called from _exit and it is overrided when compiling with -pg */
|
/* Note: This function is being called from _exit and it is overrided when compiling with -pg */
|
||||||
__attribute__((weak))
|
__attribute__((weak))
|
||||||
@@ -91,6 +89,7 @@ void __libcglue_init(int argc, char *argv[])
|
|||||||
__attribute__((weak))
|
__attribute__((weak))
|
||||||
void __libcglue_deinit()
|
void __libcglue_deinit()
|
||||||
{
|
{
|
||||||
|
__gprof_cleanup();
|
||||||
__psp_free_heap();
|
__psp_free_heap();
|
||||||
__deinit_mutex();
|
__deinit_mutex();
|
||||||
__locks_deinit();
|
__locks_deinit();
|
||||||
@@ -99,34 +98,6 @@ void __libcglue_deinit()
|
|||||||
void __libcglue_deinit();
|
void __libcglue_deinit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef F__exit
|
|
||||||
__attribute__((__noreturn__))
|
|
||||||
void _exit (int __status)
|
|
||||||
{
|
|
||||||
__gprof_cleanup();
|
|
||||||
__libcglue_deinit();
|
|
||||||
|
|
||||||
if (&sce_newlib_nocreate_thread_in_start != NULL) {
|
|
||||||
sceKernelSelfStopUnloadModule(1, 0, NULL);
|
|
||||||
} else {
|
|
||||||
sceKernelExitGame();
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1); // Avoid warning
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
__attribute__((__noreturn__))
|
|
||||||
void _exit (int __status);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef F_abort
|
|
||||||
__attribute__((weak))
|
|
||||||
void abort()
|
|
||||||
{
|
|
||||||
_exit(1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef F_exit
|
#ifdef F_exit
|
||||||
__attribute__((weak))
|
__attribute__((weak))
|
||||||
void exit(int retval)
|
void exit(int retval)
|
||||||
|
@@ -9,11 +9,14 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <pspkerneltypes.h>
|
#include <pspkerneltypes.h>
|
||||||
#include <pspmoduleinfo.h>
|
#include <pspmoduleinfo.h>
|
||||||
#include <pspthreadman.h>
|
#include <pspthreadman.h>
|
||||||
#include <stdlib.h>
|
#include <psploadexec.h>
|
||||||
#include <string.h>
|
#include <pspmodulemgr.h>
|
||||||
|
|
||||||
/* The maximum number of arguments that can be passed to main(). */
|
/* The maximum number of arguments that can be passed to main(). */
|
||||||
#define ARG_MAX 19
|
#define ARG_MAX 19
|
||||||
@@ -39,6 +42,7 @@ extern SceModuleInfo module_info __attribute__((weak));
|
|||||||
|
|
||||||
/* Allow to provide a libc init hook to be called before main */
|
/* Allow to provide a libc init hook to be called before main */
|
||||||
extern void __libcglue_init(int argc, char *argv[]);
|
extern void __libcglue_init(int argc, char *argv[]);
|
||||||
|
extern void __libcglue_deinit();
|
||||||
extern void _init(void);
|
extern void _init(void);
|
||||||
extern void _fini(void);
|
extern void _fini(void);
|
||||||
extern int main(int argc, char *argv[]);
|
extern int main(int argc, char *argv[]);
|
||||||
@@ -78,16 +82,31 @@ void _main(SceSize args, void *argp)
|
|||||||
/* Init can contain C++ constructors that require working threading */
|
/* Init can contain C++ constructors that require working threading */
|
||||||
_init();
|
_init();
|
||||||
|
|
||||||
/* Make sure _fini() is called when the program ends. */
|
|
||||||
atexit((void *) _fini);
|
|
||||||
|
|
||||||
/* Call main(). */
|
/* Call main(). */
|
||||||
int res = main(argc, argv);
|
int res = main(argc, argv);
|
||||||
|
|
||||||
/* Return control to the operating system. */
|
/* Return control to the operating system. This will end calling `_exit`*/
|
||||||
exit(res);
|
exit(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((__noreturn__))
|
||||||
|
void _exit(int status)
|
||||||
|
{
|
||||||
|
/* call global destructors*/
|
||||||
|
_fini();
|
||||||
|
|
||||||
|
// uninitialize libcglue
|
||||||
|
__libcglue_deinit();
|
||||||
|
|
||||||
|
if (&sce_newlib_nocreate_thread_in_start != NULL) {
|
||||||
|
sceKernelSelfStopUnloadModule(1, 0, NULL);
|
||||||
|
} else {
|
||||||
|
sceKernelExitGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1); // Avoid warning
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Startup thread
|
* Startup thread
|
||||||
*
|
*
|
||||||
|
@@ -9,11 +9,14 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <pspkerneltypes.h>
|
#include <pspkerneltypes.h>
|
||||||
#include <pspmoduleinfo.h>
|
#include <pspmoduleinfo.h>
|
||||||
#include <pspthreadman.h>
|
#include <pspthreadman.h>
|
||||||
#include <stdlib.h>
|
#include <psploadexec.h>
|
||||||
#include <string.h>
|
#include <pspmodulemgr.h>
|
||||||
|
|
||||||
/* The maximum number of arguments that can be passed to main(). */
|
/* The maximum number of arguments that can be passed to main(). */
|
||||||
#define ARG_MAX 19
|
#define ARG_MAX 19
|
||||||
@@ -39,6 +42,7 @@ extern SceModuleInfo module_info __attribute__((weak));
|
|||||||
|
|
||||||
/* Allow to provide a libc init hook to be called before main */
|
/* Allow to provide a libc init hook to be called before main */
|
||||||
extern void __libcglue_init(int argc, char *argv[]);
|
extern void __libcglue_init(int argc, char *argv[]);
|
||||||
|
extern void __libcglue_deinit();
|
||||||
extern void _init(void);
|
extern void _init(void);
|
||||||
extern void _fini(void);
|
extern void _fini(void);
|
||||||
extern int main(int argc, char *argv[]);
|
extern int main(int argc, char *argv[]);
|
||||||
@@ -78,16 +82,31 @@ void _main(SceSize args, void *argp)
|
|||||||
/* Init can contain C++ constructors that require working threading */
|
/* Init can contain C++ constructors that require working threading */
|
||||||
_init();
|
_init();
|
||||||
|
|
||||||
/* Make sure _fini() is called when the program ends. */
|
|
||||||
atexit((void *) _fini);
|
|
||||||
|
|
||||||
/* Call main(). */
|
/* Call main(). */
|
||||||
int res = main(argc, argv);
|
int res = main(argc, argv);
|
||||||
|
|
||||||
/* Return control to the operating system. */
|
/* Return control to the operating system. This will end calling `_exit`*/
|
||||||
exit(res);
|
exit(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((__noreturn__))
|
||||||
|
void _exit(int status)
|
||||||
|
{
|
||||||
|
/* call global destructors*/
|
||||||
|
_fini();
|
||||||
|
|
||||||
|
// uninitialize libcglue
|
||||||
|
__libcglue_deinit();
|
||||||
|
|
||||||
|
if (&sce_newlib_nocreate_thread_in_start != NULL) {
|
||||||
|
sceKernelSelfStopUnloadModule(1, 0, NULL);
|
||||||
|
} else {
|
||||||
|
sceKernelExitGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1); // Avoid warning
|
||||||
|
}
|
||||||
|
|
||||||
int module_start(SceSize args, void *argp) __attribute__((alias("_start")));
|
int module_start(SceSize args, void *argp) __attribute__((alias("_start")));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user