source: rtems/cpukit/score/src/tlsallocsize.c @ 9278f3d

Last change on this file since 9278f3d was 9278f3d, checked in by Sebastian Huber <sebastian.huber@…>, on 11/27/20 at 16:21:23

score: Canonicalize Doxygen @file comments

Use common phrases for the file brief descriptions.

Update #3706.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreTLS
7 *
8 * @brief This source file contains the implementation of
9 *   _TLS_Get_allocation_size().
10 */
11
12/*
13 * Copyright (C) 2014, 2020 embedded brains GmbH (http://www.embedded-brains.de)
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 *    notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the
22 *    documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifdef HAVE_CONFIG_H
38#include "config.h"
39#endif
40
41#include <rtems/score/tls.h>
42#include <rtems/score/interr.h>
43#include <rtems/score/thread.h>
44
45static uintptr_t _TLS_Allocation_size;
46
47uintptr_t _TLS_Get_allocation_size( void )
48{
49  uintptr_t size;
50  uintptr_t allocation_size;
51  uintptr_t alignment;
52
53  size = _TLS_Get_size();
54
55  if ( size == 0 ) {
56    return 0;
57  }
58
59  allocation_size = _TLS_Allocation_size;
60
61  if ( allocation_size == 0 ) {
62    allocation_size = _TLS_Heap_align_up( size );
63    alignment = _TLS_Heap_align_up( (uintptr_t) _TLS_Alignment );
64
65    /*
66     * The stack allocator does not support aligned allocations.  Allocate
67     * enough to do the alignment manually.
68     */
69    if ( alignment > CPU_HEAP_ALIGNMENT ) {
70      allocation_size += alignment;
71    }
72
73    allocation_size += _TLS_Get_thread_control_block_area_size( alignment );
74
75#ifndef __i386__
76    allocation_size += sizeof(TLS_Dynamic_thread_vector);
77#endif
78
79    if ( _Thread_Maximum_TLS_size != 0 ) {
80      if ( allocation_size <= _Thread_Maximum_TLS_size ) {
81        allocation_size = _Thread_Maximum_TLS_size;
82      } else {
83        _Internal_error( INTERNAL_ERROR_TOO_LARGE_TLS_SIZE );
84      }
85    }
86
87    _TLS_Allocation_size = allocation_size;
88  }
89
90  return allocation_size;
91}
Note: See TracBrowser for help on using the repository browser.