source: rtems/cpukit/libcsupport/src/newlibc_exit.c @ 5365e60

4.104.115
Last change on this file since 5365e60 was 5365e60, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 3, 2008 at 7:42:30 PM

2008-10-03 Joel Sherrill <joel.sherrill@…>

  • configure.ac: Add m32r.
  • libcsupport/src/newlibc_exit.c: For some odd reason, the fini symbol for the m32r in C needs an extra leading _.
  • Property mode set to 100644
File size: 3.3 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    #if defined(__m32r__)
127      #define FINI_SYMBOL __fini
128    #else
129      #define FINI_SYMBOL _fini
130    #endif
131 
132    extern void FINI_SYMBOL( void );
133  #endif
134#else
135  #define EXIT_SYMBOL exit
136#endif
137
138void EXIT_SYMBOL(int status)
139{
140  /*
141   *  If the toolset uses init/fini sections, then we need to
142   *  run the global destructors now.
143   */
144  #if defined(__USE_INIT_FINI__)
145    FINI_SYMBOL();
146  #endif
147
148  /*
149   *  We need to do the exit processing on the global reentrancy structure.
150   *  This has already been done on the per task reentrancy structure
151   *  associated with this task.
152   */
153
154  libc_wrapup();
155  rtems_shutdown_executive(status);
156  for (;;) ; /* to avoid warnings */
157}
158
159
160#endif
Note: See TracBrowser for help on using the repository browser.