source: rtems/cpukit/libcsupport/src/newlibc_exit.c @ ba3f9cf6

4.104.115
Last change on this file since ba3f9cf6 was d40da79b, checked in by Joel Sherrill <joel.sherrill@…>, on 09/17/08 at 16:12:04

2008-09-17 Miao Yan <yanmiaobest@…>

  • Makefile.am, preinstall.am, libcsupport/Makefile.am, libcsupport/include/rtems/libcsupport.h, libcsupport/include/rtems/libio.h, libcsupport/src/base_fs.c, libcsupport/src/libio_init.c, libcsupport/src/newlibc_exit.c, libcsupport/src/newlibc_init.c, libcsupport/src/sync.c, libfs/Makefile.am, libfs/src/imfs/deviceio.c, sapi/include/confdefs.h: Merge GSOC project code to add simple device only filesystem (devfs), optionally completely drop out filesystem, and to clean up disabling newlib reentrancy support. This dropped 17K from the minimum.exe for sparc/sis and arm/rtl22xx_t now has a 15K code space.
  • libcsupport/src/usrenv.c, libcsupport/src/newlibc_reent.c, libfs/src/devfs/devclose.c, libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_eval.c, libfs/src/devfs/devfs_init.c, libfs/src/devfs/devfs_mknod.c, libfs/src/devfs/devfs_node_type.c, libfs/src/devfs/devfs_show.c, libfs/src/devfs/devioctl.c, libfs/src/devfs/devopen.c, libfs/src/devfs/devread.c, libfs/src/devfs/devstat.c, libfs/src/devfs/devwrite.c, libfs/src/imfs/deviceerrno.c: New files.
  • libcsupport/src/newlibc.c: Removed.
  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 *  Implementation of hooks for the CYGNUS newlib libc
3 *  These hooks set things up so that:
4 *       + '_REENT' is switched at task switch time.
5 *
6 *  COPYRIGHT (c) 1994 by Division Incorporated
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 *
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
21#include <rtems.h>
22
23#if defined(RTEMS_NEWLIB)
24#include <rtems/libcsupport.h>
25
26/* Since we compile with strict ANSI we need to undef it to get
27 * prototypes for extensions
28 */
29#undef __STRICT_ANSI__
30
31#include <stdlib.h>             /* for free() */
32#include <string.h>             /* for memset() */
33
34#include <sys/reent.h>          /* for extern of _REENT (aka _impure_ptr) */
35#include <errno.h>
36
37#include <stdio.h>
38
39int _fwalk(struct _reent *ptr, int (*function) (FILE *) );
40
41/* do we think we are reentrant? */
42extern int             libc_reentrant;
43extern struct _reent * const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
44
45/*
46 * CYGNUS newlib routine that does atexit() processing and flushes
47 *      stdio streams
48 *      undocumented
49 */
50
51extern void _wrapup_reent(struct _reent *);
52extern void _reclaim_reent(struct _reent *);
53
54void libc_wrapup(void)
55{
56  /*
57   *  In case RTEMS is already down, don't do this.  It could be
58   *  dangerous.
59   */
60
61  if (!_System_state_Is_up(_System_state_Get()))
62     return;
63
64  /*
65   *  This was already done if the user called exit() directly .
66  _wrapup_reent(0);
67   */
68
69  if (_REENT != _global_impure_ptr) {
70      _wrapup_reent(_global_impure_ptr);
71#if 0
72      /*  Don't reclaim this one, just in case we do printfs
73       *  on the way out to ROM.
74       */
75      _reclaim_reent(&libc_global_reent);
76#endif
77      _REENT = _global_impure_ptr;
78  }
79
80  /*
81   * Try to drain output buffers.
82   *
83   * Should this be changed to do *all* file streams?
84   *    _fwalk (_REENT, fclose);
85   */
86
87  fclose (stdin);
88  fclose (stdout);
89  fclose (stderr);
90}
91
92/*
93 *  Function:   _exit
94 *  Created:    94/12/10
95 *
96 *  Description:
97 *      Called from exit() after it does atexit() processing and stdio fflush's
98 *
99 *      called from bottom of exit() to really delete the task.
100 *      If we are using reentrant libc, then let the delete extension
101 *      do all the work, otherwise if a shutdown is in progress,
102 *      then just do it.
103 *
104 *  Parameters:
105 *      exit status
106 *
107 *  Returns:
108 *      does not return
109 *
110 *  Side Effects:
111 *
112 *  Notes:
113 *
114 *
115 *  Deficiencies/ToDo:
116 *
117 *
118 */
119
120#include <unistd.h>
121
122#if !defined(RTEMS_UNIX)
123  #define EXIT_SYMBOL _exit
124
125  #if defined(__USE_INIT_FINI__)
126    extern void _fini( void );
127  #endif
128#else
129  #define EXIT_SYMBOL exit
130#endif
131
132void EXIT_SYMBOL(int status)
133{
134  /*
135   *  If the toolset uses init/fini sections, then we need to
136   *  run the global destructors now.
137   */
138  #if defined(__USE_INIT_FINI__)
139    _fini();
140  #endif
141
142  /*
143   *  We need to do the exit processing on the global reentrancy structure.
144   *  This has already been done on the per task reentrancy structure
145   *  associated with this task.
146   */
147
148  libc_wrapup();
149  rtems_shutdown_executive(status);
150  for (;;) ; /* to avoid warnings */
151}
152
153
154#endif
Note: See TracBrowser for help on using the repository browser.