source: rtems/cpukit/libcsupport/src/newlibc_exit.c @ 6de36ed

4.115
Last change on this file since 6de36ed was 1f3585d1, checked in by Sebastian Huber <sebastian.huber@…>, on 08/15/11 at 08:23:49

2011-08-15 Sebastian Huber <sebastian.huber@…>

  • libcsupport/src/newlibc_exit.c, score/src/threadhandler.c: Added init/fini array support for ARM EABI. The libc_init_array() and libc_fini_array() functions are provided by Newlib.
  • 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/* FIXME: These defines are a blatant hack */
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    #elif defined(__ARM_EABI__)
132      #define FINI_SYMBOL __libc_fini_array
133    #else
134      #define FINI_SYMBOL _fini
135    #endif
136
137    extern void FINI_SYMBOL( void );
138  #endif
139
140void EXIT_SYMBOL(int status)
141{
142  /*
143   *  If the toolset uses init/fini sections, then we need to
144   *  run the global destructors now.
145   */
146  #if defined(FINI_SYMBOL)
147    FINI_SYMBOL();
148  #endif
149
150  /*
151   *  We need to do the exit processing on the global reentrancy structure.
152   *  This has already been done on the per task reentrancy structure
153   *  associated with this task.
154   */
155
156  libc_wrapup();
157  rtems_shutdown_executive(status);
158  for (;;) ; /* to avoid warnings */
159}
160
161
162#endif
Note: See TracBrowser for help on using the repository browser.