source: rtems/cpukit/score/src/threadstackallocate.c @ b72e847b

4.8
Last change on this file since b72e847b was 728a0bd3, checked in by Ralf Corsepius <ralf.corsepius@…>, on 05/08/07 at 10:43:06

Use size_t for stacksizes.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/score/apiext.h>
21#include <rtems/score/context.h>
22#include <rtems/score/interr.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/object.h>
25#include <rtems/score/priority.h>
26#include <rtems/score/states.h>
27#include <rtems/score/sysstate.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/threadq.h>
30#include <rtems/score/userext.h>
31#include <rtems/score/wkspace.h>
32
33/*PAGE
34 *
35 *  _Thread_Stack_Allocate
36 *
37 *  Allocate the requested stack space for the thread.
38 *  return the actual size allocated after any adjustment
39 *  or return zero if the allocation failed.
40 *  Set the Start.stack field to the address of the stack
41 */
42
43size_t _Thread_Stack_Allocate(
44  Thread_Control *the_thread,
45  size_t          stack_size
46)
47{
48  void *stack_addr = 0;
49  size_t the_stack_size = stack_size;
50
51  if ( !_Stack_Is_enough( the_stack_size ) )
52    the_stack_size = STACK_MINIMUM_SIZE;
53
54  /*
55   * Call ONLY the CPU table stack allocate hook, _or_ the
56   * the RTEMS workspace allocate.  This is so the stack free
57   * routine can call the correct deallocation routine.
58   */
59
60  if ( _CPU_Table.stack_allocate_hook ) {
61    stack_addr = (*_CPU_Table.stack_allocate_hook)( the_stack_size );
62  } else {
63
64    /*
65     *  First pad the requested size so we allocate enough memory
66     *  so the context initialization can align it properly.  The address
67     *  returned the workspace allocate must be directly stored in the
68     *  stack control block because it is later used in the free sequence.
69     *
70     *  Thus it is the responsibility of the CPU dependent code to
71     *  get and keep the stack adjust factor, the stack alignment, and
72     *  the context initialization sequence in sync.
73     */
74
75    the_stack_size = _Stack_Adjust_size( the_stack_size );
76    stack_addr = _Workspace_Allocate( the_stack_size );
77  }
78
79  if ( !stack_addr )
80    the_stack_size = 0;
81
82  the_thread->Start.stack = stack_addr;
83
84  return the_stack_size;
85}
Note: See TracBrowser for help on using the repository browser.