source: rtems/cpukit/libcsupport/src/malloc.c @ 1c6926c1

5
Last change on this file since 1c6926c1 was 9d1f3943, checked in by Sebastian Huber <sebastian.huber@…>, on 02/25/16 at 08:02:43

malloc: Add _Malloc_System_state()

Replace malloc_is_system_state_OK() with _Malloc_System_state() to allow
early allocations, e.g. in bsp_start(). Here the _Thread_Executing is
NULL, thus an _API_Mutex_Lock() would lead to a NULL pointer access.

Move malloc() support code to general case
rtems_heap_allocate_aligned_with_boundary(). Use
rtems_heap_allocate_aligned_with_boundary() to avoid duplicated code.

  • Property mode set to 100644
File size: 792 bytes
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Malloc Family Implementation
5 *  @ingroup libcsupport
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#ifdef RTEMS_NEWLIB
22#include <stdlib.h>
23#include <errno.h>
24
25#include "malloc_p.h"
26
27void *malloc(
28  size_t  size
29)
30{
31  void        *return_this;
32
33  /*
34   * Validate the parameters
35   */
36  if ( !size )
37    return (void *) 0;
38
39  return_this = rtems_heap_allocate_aligned_with_boundary( size, 0, 0 );
40  if ( !return_this ) {
41    errno = ENOMEM;
42    return (void *) 0;
43  }
44
45  return return_this;
46}
47
48#endif
Note: See TracBrowser for help on using the repository browser.