Improve exit process

This commit is contained in:
Francisco Javier Trujillo Mata
2021-11-25 17:20:18 +01:00
parent af5e24ef06
commit cfb9b04954
4 changed files with 56 additions and 72 deletions

View File

@@ -30,7 +30,7 @@ GLUE_OBJS = __fill_stat.o __psp_heap_blockid.o __psp_free_heap.o _fork.o _wait.o
_isatty.o symlink.o truncate.o chmod.o fchmod.o fchmodat.o pathconf.o readlink.o utime.o fchown.o getentropy.o
INIT_OBJS = __libcglue_init.o
INIT_OBJS = __libcglue_init.o __libcglue_deinit.o _exit.o abort.o exit.o
MUTEXMAN_OBJS = __malloc_mutex.o __sbrk_mutex.o __fdman_mutex.o __init_mutex.o __deinit_mutex.o
@@ -46,8 +46,6 @@ SLEEP_OBJS = nanosleep.o
SOCKET_OBJS = socket.o __socket_close.o accept.o bind.o connect.o getsockopt.o listen.o recv.o recvfrom.o send.o sendto.o \
setsockopt.o shutdown.o getpeername.o getsockname.o inet_ntoa.o sendmsg.o recvmsg.o
TERMINATE_OBJS = _exit.o abort.o exit.o
TIMEZONE_OBJS = __timezone_update.o
lib_LIBRARIES = libcglue.a
@@ -75,11 +73,10 @@ libcglue_a_SOURCES = \
select.c \
sleep.c \
socket.c \
terminate.c \
timezone.c
libcglue_a_LIBADD = $(CWD_OBJS) $(ERRNO_OBJS) $(FDMAN_OBJS) $(INIT_OBJS) $(GLUE_OBJS) $(MUTEXMAN_OBJS) $(NETDB_OBJS) $(PIPE_OBJS) \
$(SELECT_OBJS) $(SOCKET_OBJS) $(SLEEP_OBJS) $(TERMINATE_OBJS) $(TIMEZONE_OBJS)
$(SELECT_OBJS) $(SOCKET_OBJS) $(SLEEP_OBJS) $(TIMEZONE_OBJS)
$(CWD_OBJS): cwd.c
$(AM_V_CC)$(COMPILE) -DF_$* $< -c -o $@
@@ -114,8 +111,5 @@ $(SLEEP_OBJS): sleep.c
$(SOCKET_OBJS): socket.c
$(AM_V_CC)$(COMPILE) -DF_$* $< -c -o $@
$(TERMINATE_OBJS): terminate.c
$(AM_V_CC)$(COMPILE) -DF_$* $< -c -o $@
$(TIMEZONE_OBJS): timezone.c
$(AM_V_CC)$(COMPILE) -DF_$* $< -c -o $@

View File

@@ -8,6 +8,7 @@
* Copyright (c) 2005 Marcus R. Brown <mrbrown@ocgnet.org>
* Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
* Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
* Copyright (c) 2021 Francisco Javier Trujillo Mata <fjtrujy@gmail.com>
*
*/
@@ -16,10 +17,16 @@
#include <string.h>
#include <sys/param.h>
#include <pspuser.h>
void __init_cwd(char *argv_0);
void __timezone_update();
void __fdman_init();
void __init_mutex();
void __psp_free_heap();
void __deinit_mutex();
extern int sce_newlib_nocreate_thread_in_start __attribute__((weak));
#ifdef F___libcglue_init
/* Note: This function is being called from crt0.c/crt0_prx.c.
@@ -44,4 +51,49 @@ void __libcglue_init(int argc, char *argv[])
/* Initialize timezone */
__timezone_update();
}
#endif
#ifdef F___libcglue_deinit
/* Note: This function is being called from terminate.c.
* It is a weak function because can be override by user program
*/
__attribute__((weak))
void __libcglue_deinit()
{
__psp_free_heap();
__deinit_mutex();
}
#else
void __libcglue_deinit();
#endif
#ifdef F__exit
void _exit(int status)
{
__libcglue_deinit();
if (&sce_newlib_nocreate_thread_in_start != NULL) {
sceKernelSelfStopUnloadModule(1, 0, NULL);
} else {
sceKernelExitGame();
}
}
#else
void _exit(int status);
#endif
#ifdef F_abort
__attribute__((weak))
void abort()
{
_exit(1);
}
#endif
#ifdef F_exit
__attribute__((weak))
void exit(int retval)
{
_exit(retval);
}
#endif

View File

@@ -1,63 +0,0 @@
/*
* PSP Software Development Kit - https://github.com/pspdev
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* terminate.c - Process exit functions.
*
* Copyright (c) 2005 Marcus R. Brown <mrbrown@ocgnet.org>
* Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
* Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
*
*/
#include <stdio.h>
#include <psptypes.h>
#include <pspkernel.h>
#ifdef F__exit
extern int sce_newlib_nocreate_thread_in_start __attribute__((weak));
int __psp_free_heap(void);
void __deinit_mutex(void);
void _exit(int status)
{
if (&sce_newlib_nocreate_thread_in_start != NULL) {
/* Free the heap created by _sbrk(). */
__psp_free_heap();
__deinit_mutex();
sceKernelSelfStopUnloadModule(1, 0, NULL);
} else {
if (status == 0) {
/* Free the heap created by _sbrk(). */
__psp_free_heap();
__deinit_mutex();
}
sceKernelExitThread(status);
}
while (1) ;
}
#else
void _exit(int status);
#endif
#ifdef F_abort
__attribute__((weak))
void abort()
{
while (1)
_exit(1);
}
#endif
#ifdef F_exit
__attribute__((weak))
void exit(int retval)
{
while (1)
_exit(retval);
}
#endif

View File

@@ -146,6 +146,7 @@ enum PspModuleInfoAttr
/* Disable the use of newlib, getting a minimal binary. */
#define PSP_DISABLE_NEWLIB() \
void __libcglue_init(int argc, char *argv[]) {}
void __libcglue_init(int argc, char *argv[]) {} \
void __libcglue_deinit() {}
#endif /* PSPMODULEINFO_H */