[abb18dc] | 1 | /* |
---|
| 2 | * BASED UPON SOURCE IN RTEMS, MODIFIED FOR SIMULATOR |
---|
| 3 | * |
---|
| 4 | * Workspace Handler |
---|
| 5 | * |
---|
[a2aad55] | 6 | * COPYRIGHT (c) 1989-2013. |
---|
[abb18dc] | 7 | * On-Line Applications Research Corporation (OAR). |
---|
| 8 | * |
---|
| 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
| 11 | * http://www.rtems.com/license/LICENSE. |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | #if HAVE_CONFIG_H |
---|
| 15 | #include "config.h" |
---|
| 16 | #endif |
---|
| 17 | |
---|
| 18 | #include <rtems/system.h> |
---|
| 19 | #include <rtems/score/wkspace.h> |
---|
| 20 | #include <rtems/score/interr.h> |
---|
| 21 | |
---|
| 22 | #include <stdlib.h> |
---|
[726b27c] | 23 | #include <malloc.h> |
---|
[abb18dc] | 24 | |
---|
[b1b31c0] | 25 | // #define DEBUG_WORKSPACE |
---|
[abb18dc] | 26 | #if defined(DEBUG_WORKSPACE) |
---|
| 27 | #include <stdio.h> |
---|
| 28 | #endif |
---|
| 29 | |
---|
| 30 | /* |
---|
| 31 | * _Workspace_Handler_initialization |
---|
| 32 | */ |
---|
[957ce33] | 33 | void _Workspace_Handler_initialization( |
---|
| 34 | Heap_Area *areas, |
---|
| 35 | size_t area_count, |
---|
| 36 | Heap_Initialization_or_extend_handler extend |
---|
| 37 | ) |
---|
[abb18dc] | 38 | { |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | /* |
---|
| 42 | * _Workspace_Allocate |
---|
| 43 | */ |
---|
| 44 | void *_Workspace_Allocate( |
---|
| 45 | size_t size |
---|
| 46 | ) |
---|
| 47 | { |
---|
| 48 | void *memory; |
---|
| 49 | |
---|
| 50 | memory = calloc( 1, size ); |
---|
| 51 | #if defined(DEBUG_WORKSPACE) |
---|
| 52 | fprintf( |
---|
| 53 | stderr, |
---|
| 54 | "Workspace_Allocate(%d) from %p/%p -> %p\n", |
---|
| 55 | size, |
---|
| 56 | __builtin_return_address( 0 ), |
---|
| 57 | __builtin_return_address( 1 ), |
---|
| 58 | memory |
---|
| 59 | ); |
---|
| 60 | #endif |
---|
| 61 | return memory; |
---|
| 62 | } |
---|
| 63 | |
---|
[726b27c] | 64 | void *_Workspace_Allocate_aligned( size_t size, size_t alignment ) |
---|
| 65 | { |
---|
| 66 | void *memory; |
---|
| 67 | int sc; |
---|
| 68 | |
---|
| 69 | memory = memalign( alignment, size ); |
---|
| 70 | #if defined(DEBUG_WORKSPACE) |
---|
| 71 | fprintf( |
---|
| 72 | stderr, |
---|
| 73 | "Workspace_Allocate_aligned(%d, %d) from %p/%p -> %p\n", |
---|
| 74 | size, |
---|
| 75 | alignment, |
---|
| 76 | __builtin_return_address( 0 ), |
---|
| 77 | __builtin_return_address( 1 ), |
---|
| 78 | memory |
---|
| 79 | ); |
---|
| 80 | #endif |
---|
| 81 | return memory; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
[abb18dc] | 85 | /* |
---|
| 86 | * _Workspace_Free |
---|
| 87 | */ |
---|
| 88 | void _Workspace_Free( |
---|
| 89 | void *block |
---|
| 90 | ) |
---|
| 91 | { |
---|
| 92 | #if defined(DEBUG_WORKSPACE) |
---|
| 93 | fprintf( |
---|
| 94 | stderr, |
---|
| 95 | block, |
---|
| 96 | __builtin_return_address( 0 ), |
---|
| 97 | __builtin_return_address( 1 ) |
---|
| 98 | ); |
---|
| 99 | #endif |
---|
| 100 | free( block ); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /* |
---|
| 104 | * _Workspace_Allocate_or_fatal_error |
---|
| 105 | */ |
---|
| 106 | void *_Workspace_Allocate_or_fatal_error( |
---|
| 107 | size_t size |
---|
| 108 | ) |
---|
| 109 | { |
---|
| 110 | void *memory; |
---|
| 111 | |
---|
| 112 | memory = calloc( 1, size ); |
---|
| 113 | #if defined(DEBUG_WORKSPACE) |
---|
| 114 | fprintf( |
---|
| 115 | stderr, |
---|
| 116 | "Workspace_Allocate_or_fatal_error(%d) from %p/%p -> %p\n", |
---|
| 117 | size, |
---|
| 118 | __builtin_return_address( 0 ), |
---|
| 119 | __builtin_return_address( 1 ), |
---|
| 120 | memory |
---|
| 121 | ); |
---|
| 122 | #endif |
---|
| 123 | |
---|
| 124 | return memory; |
---|
| 125 | } |
---|