source: rtems/cpukit/libcsupport/src/newlibc_exit.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 3.4 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 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
19#include <rtems.h>
20
21#if defined(RTEMS_NEWLIB)
22#include <rtems/libcsupport.h>
23
24/* Since we compile with strict ANSI we need to undef it to get
25 * prototypes for extensions
26 */
27#undef __STRICT_ANSI__
28
29#include <stdlib.h>             /* for free() */
30#include <string.h>             /* for memset() */
31
32#include <sys/reent.h>          /* for extern of _REENT (aka _impure_ptr) */
33#include <errno.h>
34
35#include <stdio.h>
36
37int _fwalk(struct _reent *ptr, int (*function) (FILE *) );
38
39/* do we think we are reentrant? */
40extern int             libc_reentrant;
41extern struct _reent * const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
42
43/*
44 * CYGNUS newlib routine that does atexit() processing and flushes
45 *      stdio streams
46 *      undocumented
47 */
48
49extern void _wrapup_reent(struct _reent *);
50extern void _reclaim_reent(struct _reent *);
51
52void libc_wrapup(void)
53{
54  /*
55   *  In case RTEMS is already down, don't do this.  It could be
56   *  dangerous.
57   */
58
59  if (!_System_state_Is_up(_System_state_Get()))
60     return;
61
62  /*
63   *  This was already done if the user called exit() directly .
64  _wrapup_reent(0);
65   */
66
67  if (_REENT != _global_impure_ptr) {
68      _wrapup_reent(_global_impure_ptr);
69#if 0
70      /*  Don't reclaim this one, just in case we do printfs
71       *  on the way out to ROM.
72       */
73      _reclaim_reent(&libc_global_reent);
74#endif
75      _REENT = _global_impure_ptr;
76  }
77
78  /*
79   * Try to drain output buffers.
80   *
81   * Should this be changed to do *all* file streams?
82   *    _fwalk (_REENT, fclose);
83   */
84
85  fclose (stdin);
86  fclose (stdout);
87  fclose (stderr);
88}
89
90/*
91 *  Function:   _exit
92 *  Created:    94/12/10
93 *
94 *  Description:
95 *      Called from exit() after it does atexit() processing and stdio fflush's
96 *
97 *      called from bottom of exit() to really delete the task.
98 *      If we are using reentrant libc, then let the delete extension
99 *      do all the work, otherwise if a shutdown is in progress,
100 *      then just do it.
101 *
102 *  Parameters:
103 *      exit status
104 *
105 *  Returns:
106 *      does not return
107 *
108 *  Side Effects:
109 *
110 *  Notes:
111 *
112 *
113 *  Deficiencies/ToDo:
114 *
115 *
116 */
117
118#include <unistd.h>
119
120/* FIXME: These defines are a blatant hack */
121  #define EXIT_SYMBOL _exit
122
123  #if defined(__USE_INIT_FINI__)
124    #if defined(__m32r__)
125      #define FINI_SYMBOL __fini
126    #elif defined(__ARM_EABI__)
127      #define FINI_SYMBOL __libc_fini_array
128    #else
129      #define FINI_SYMBOL _fini
130    #endif
131
132    extern void FINI_SYMBOL( void );
133  #endif
134
135void EXIT_SYMBOL(int status)
136{
137  /*
138   *  If the toolset uses init/fini sections, then we need to
139   *  run the global destructors now.
140   */
141  #if defined(FINI_SYMBOL)
142    FINI_SYMBOL();
143  #endif
144
145  /*
146   *  We need to do the exit processing on the global reentrancy structure.
147   *  This has already been done on the per task reentrancy structure
148   *  associated with this task.
149   */
150
151  libc_wrapup();
152  rtems_shutdown_executive(status);
153  for (;;) ; /* to avoid warnings */
154}
155
156
157#endif
Note: See TracBrowser for help on using the repository browser.