4.115
Last change
on this file since e22af78 was
c499856,
checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47
|
Change all references of rtems.com to rtems.org.
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Extend Heap via Sbrk |
---|
5 | * @ingroup MallocSupport |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Copyright (c) 2012 embedded brains GmbH. All rights reserved. |
---|
10 | * |
---|
11 | * embedded brains GmbH |
---|
12 | * Obere Lagerstr. 30 |
---|
13 | * 82178 Puchheim |
---|
14 | * Germany |
---|
15 | * <rtems@embedded-brains.de> |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be |
---|
18 | * found in the file LICENSE in this distribution or at |
---|
19 | * http://www.rtems.org/license/LICENSE. |
---|
20 | */ |
---|
21 | |
---|
22 | #if HAVE_CONFIG_H |
---|
23 | #include "config.h" |
---|
24 | #endif |
---|
25 | |
---|
26 | #include <unistd.h> |
---|
27 | |
---|
28 | #include <rtems/malloc.h> |
---|
29 | |
---|
30 | #include "malloc_p.h" |
---|
31 | |
---|
32 | ptrdiff_t RTEMS_Malloc_Sbrk_amount; |
---|
33 | |
---|
34 | void *rtems_heap_extend_via_sbrk( |
---|
35 | Heap_Control *heap, |
---|
36 | size_t alloc_size |
---|
37 | ) |
---|
38 | { |
---|
39 | ptrdiff_t sbrk_amount = RTEMS_Malloc_Sbrk_amount; |
---|
40 | ptrdiff_t sbrk_size = (ptrdiff_t) alloc_size; |
---|
41 | ptrdiff_t misaligned = sbrk_amount != 0 ? sbrk_size % sbrk_amount : 0; |
---|
42 | void *return_this = NULL; |
---|
43 | |
---|
44 | if ( misaligned != 0 ) { |
---|
45 | sbrk_size += sbrk_amount - misaligned; |
---|
46 | } |
---|
47 | |
---|
48 | if ( sbrk_size > 0 && sbrk_amount > 0 ) { |
---|
49 | void *area_begin = sbrk( sbrk_size ); |
---|
50 | |
---|
51 | if ( area_begin != (void *) -1 ) { |
---|
52 | bool ok = _Protected_heap_Extend( heap, area_begin, sbrk_size ); |
---|
53 | |
---|
54 | if ( ok ) { |
---|
55 | MSBUMP( space_available, sbrk_size ); |
---|
56 | |
---|
57 | return_this = _Protected_heap_Allocate( heap, alloc_size ); |
---|
58 | } else { |
---|
59 | sbrk( -sbrk_size ); |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | return return_this; |
---|
65 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.