Skip to content

Commit

Permalink
libc: Implement call gate for I/O, FILE and stream flushing
Browse files Browse the repository at this point in the history
nxtask_exit_cleanup performs the cleanup functions, but it needs
a call gate for BUILD_PROTECTED/BUILD_KERNEL.
  • Loading branch information
pussuw committed May 4, 2022
1 parent f67cafa commit 3de7365
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
16 changes: 16 additions & 0 deletions include/nuttx/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,22 @@ void nxtask_starthook(FAR struct task_tcb_s *tcb, starthook_t starthook,
void nxtask_startup(main_t entrypt, int argc, FAR char *argv[]);
#endif

/****************************************************************************
* Name: nxtask_exit_cleanup
*
* Description:
* Perform cleanup before task is closed.
*
* If SCHED_ATEXIT or SCHED_ONEXIT are defined, all functions registered
* with atexit() and on_exit() are called, in the reverse order of their
* registration.
*
* All open streams are flushed and closed.
*
****************************************************************************/

void nxtask_exit_cleanup(int status);

/****************************************************************************
* Internal vfork support. The overall sequence is:
*
Expand Down
4 changes: 4 additions & 0 deletions include/sys/syscall_lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ SYSCALL_LOOKUP(futimens, 2)
SYSCALL_LOOKUP(nx_mkfifo, 3)
#endif

#ifndef CONFIG_BUILD_FLAT
SYSCALL_LOOKUP(nxtask_exit_cleanup, 1)
#endif

#ifdef CONFIG_FILE_STREAM
SYSCALL_LOOKUP(fs_fdopen, 4)
SYSCALL_LOOKUP(nxsched_get_streams, 0)
Expand Down
11 changes: 1 addition & 10 deletions libs/libc/stdlib/lib_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,10 @@

#include <nuttx/config.h>

#include <stdlib.h>
#include <unistd.h>
#include "libc.h"

#include "atexit.h"

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

void nxtask_exit_cleanup(int status);

/****************************************************************************
* Public Functions
****************************************************************************/
Expand All @@ -43,8 +36,6 @@ void exit(int status)
{
__atexit_call_exitfuncs(status);

/* REVISIT: Need to flush files and streams */

nxtask_exit_cleanup(status);

_exit(status);
Expand Down
1 change: 1 addition & 0 deletions syscall/syscall.csv
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"nx_vsyslog","nuttx/syslog/syslog.h","","int","int","FAR const IPTR char *","FAR va_list *"
"nxsched_get_stackinfo","nuttx/sched.h","","int","pid_t","FAR struct stackinfo_s *"
"nxsched_get_streams","nuttx/sched.h","defined(CONFIG_FILE_STREAM)","FAR struct streamlist *"
"nxtask_exit_cleanup","nuttx/sched.h","","void","int"
"open","fcntl.h","","int","FAR const char *","int","...","mode_t"
"opendir","dirent.h","","FAR DIR *","FAR const char *"
"pgalloc", "nuttx/arch.h", "defined(CONFIG_BUILD_KERNEL)", "uintptr_t", "uintptr_t", "unsigned int"
Expand Down

0 comments on commit 3de7365

Please sign in to comment.