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

4.104.115
Last change on this file since bd59b348 was bd59b348, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 20, 2008 at 7:42:41 PM

2008-11-20 Joel Sherrill <joel.sherrill@…>

  • libcsupport/src/newlibc_exit.c, score/src/threadhandler.c: Do not think about running init/fini on AVR. We do not know what mechanism it uses but this is not it.
  • 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 *  $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(__AVR__)
126    #undef __USE_INIT_FINI__
127  #endif
128  #if defined(__USE_INIT_FINI__)
129    #if defined(__m32r__)
130      #define FINI_SYMBOL __fini
131    #else
132      #define FINI_SYMBOL _fini
133    #endif
134 
135    extern void FINI_SYMBOL( void );
136  #endif
137#else
138  #define EXIT_SYMBOL exit
139#endif
140
141void EXIT_SYMBOL(int status)
142{
143  /*
144   *  If the toolset uses init/fini sections, then we need to
145   *  run the global destructors now.
146   */
147  #if defined(__USE_INIT_FINI__)
148    FINI_SYMBOL();
149  #endif
150
151  /*
152   *  We need to do the exit processing on the global reentrancy structure.
153   *  This has already been done on the per task reentrancy structure
154   *  associated with this task.
155   */
156
157  libc_wrapup();
158  rtems_shutdown_executive(status);
159  for (;;) ; /* to avoid warnings */
160}
161
162
163#endif
Note: See TracBrowser for help on using the repository browser.