1 | /* |
---|
2 | * Thread Handler - Stack Allocate Helper |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2010. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #if HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/score/apiext.h> |
---|
18 | #include <rtems/score/context.h> |
---|
19 | #include <rtems/score/interr.h> |
---|
20 | #include <rtems/score/isr.h> |
---|
21 | #include <rtems/score/object.h> |
---|
22 | #include <rtems/score/priority.h> |
---|
23 | #include <rtems/score/states.h> |
---|
24 | #include <rtems/score/sysstate.h> |
---|
25 | #include <rtems/score/thread.h> |
---|
26 | #include <rtems/score/threadq.h> |
---|
27 | #include <rtems/score/userext.h> |
---|
28 | #include <rtems/score/wkspace.h> |
---|
29 | #include <rtems/config.h> |
---|
30 | |
---|
31 | /* |
---|
32 | * _Thread_Stack_Allocate |
---|
33 | * |
---|
34 | * Allocate the requested stack space for the thread. |
---|
35 | * return the actual size allocated after any adjustment |
---|
36 | * or return zero if the allocation failed. |
---|
37 | * Set the Start.stack field to the address of the stack |
---|
38 | */ |
---|
39 | |
---|
40 | size_t _Thread_Stack_Allocate( |
---|
41 | Thread_Control *the_thread, |
---|
42 | size_t stack_size |
---|
43 | ) |
---|
44 | { |
---|
45 | void *stack_addr = 0; |
---|
46 | size_t the_stack_size; |
---|
47 | rtems_stack_allocate_hook stack_allocate_hook = |
---|
48 | rtems_configuration_get_stack_allocate_hook(); |
---|
49 | |
---|
50 | the_stack_size = _Stack_Ensure_minimum( stack_size ); |
---|
51 | |
---|
52 | stack_addr = (*stack_allocate_hook)( the_stack_size ); |
---|
53 | |
---|
54 | if ( !stack_addr ) |
---|
55 | the_stack_size = 0; |
---|
56 | |
---|
57 | the_thread->Start.stack = stack_addr; |
---|
58 | |
---|
59 | return the_stack_size; |
---|
60 | } |
---|