source: rtems/cpukit/libcsupport/src/newlibc_reent.c @ ae75429

4.115
Last change on this file since ae75429 was ae75429, checked in by Sebastian Huber <sebastian.huber@…>, on Aug 6, 2013 at 2:10:26 PM

PR766: Delete RTEMS_VIOLATE_KERNEL_VISIBILITY

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Newlib Support
5 *  @ingroup libcsupport
6 */
7
8/*
9 *  COPYRIGHT (c) 1994 by Division Incorporated
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems.h>
22
23#if defined(RTEMS_NEWLIB)
24
25#include <sys/reent.h>
26#include <stdlib.h>
27#include <string.h>
28
29#include <rtems/libcsupport.h>
30#include <rtems/score/threadimpl.h>
31#include <rtems/score/wkspace.h>
32
33bool newlib_create_hook(
34  rtems_tcb *current_task __attribute__((unused)),
35  rtems_tcb *creating_task
36)
37{
38  struct _reent *ptr;
39  bool ok;
40
41#if !defined(__DYNAMIC_REENT__)
42  if (_Thread_libc_reent == 0)
43  {
44    _REENT = _GLOBAL_REENT;
45
46    _Thread_Set_libc_reent (&_REENT);
47  }
48#endif
49
50  /* It is OK to allocate from the workspace because these
51   * hooks run with thread dispatching disabled.
52   */
53  ptr = (struct _reent *) _Workspace_Allocate(sizeof(*ptr));
54  creating_task->libc_reent = ptr;
55  ok = ptr != NULL;
56
57  if (ok) {
58    _REENT_INIT_PTR((ptr)); /* GCC extension: structure constants */
59  }
60
61  return ok;
62}
63
64void newlib_delete_hook(
65  rtems_tcb *current_task,
66  rtems_tcb *deleted_task
67)
68{
69  struct _reent *ptr;
70
71  ptr = deleted_task->libc_reent;
72  deleted_task->libc_reent = NULL;
73
74  _reclaim_reent(ptr);
75  _Workspace_Free(ptr);
76}
77
78#endif
Note: See TracBrowser for help on using the repository browser.