distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
distortos::internal::Stack Class Reference

Stack class is an abstraction of architecture's stack. More...

#include <Stack.hpp>

Collaboration diagram for distortos::internal::Stack:
[legend]

Public Types

using StorageUniquePointer = std::unique_ptr< void, void(&)(void *)>
 unique_ptr (with deleter) to storage More...
 

Public Member Functions

 Stack (StorageUniquePointer &&storageUniquePointer, size_t size)
 Stack's constructor. More...
 
 Stack (void *storage, size_t size)
 Stack's constructor. More...
 
 ~Stack ()
 Stack's destructor. More...
 
bool checkStackGuard () const
 
bool checkStackPointer (const void *const stackPointer) const
 Checks whether stack pointer value is within range of this stack. More...
 
size_t getHighWaterMark () const
 
size_t getSize () const
 
void * getStackPointer () const
 Gets current value of stack pointer. More...
 
int initialize (Thread &thread, void(&run)(Thread &), void(*preTerminationHook)(Thread &), void(&terminationHook)(Thread &))
 Fills the stack with stack sentinel, initializes its contents and stack pointer value. More...
 
void setStackPointer (void *const stackPointer)
 Sets value of stack pointer. More...
 
 Stack (const Stack &)=delete
 
 Stack (Stack &&)=default
 
const Stackoperator= (const Stack &)=delete
 
Stackoperator= (Stack &&)=delete
 

Private Attributes

StorageUniquePointer storageUniquePointer_
 storage for stack More...
 
void *const adjustedStorage_
 adjusted address of stack's storage More...
 
const size_t adjustedSize_
 adjusted size of stack's storage More...
 
void * stackPointer_
 current value of stack pointer register More...
 

Static Private Attributes

static constexpr size_t stackGuardSize_
 size of "stack guard", bytes More...
 

Detailed Description

Stack class is an abstraction of architecture's stack.

Member Typedef Documentation

◆ StorageUniquePointer

using distortos::internal::Stack::StorageUniquePointer = std::unique_ptr<void, void(&)(void*)>

unique_ptr (with deleter) to storage

Constructor & Destructor Documentation

◆ Stack() [1/2]

distortos::internal::Stack::Stack ( StorageUniquePointer &&  storageUniquePointer,
size_t  size 
)

Stack's constructor.

Storage's address and size are adjusted to suit architecture's alignment requirements.

Parameters
[in]storageUniquePointeris a rvalue reference to StorageUniquePointer with storage for stack (size bytes long) and appropriate deleter
[in]sizeis the size of stack's storage, bytes
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stack() [2/2]

distortos::internal::Stack::Stack ( void *  storage,
size_t  size 
)

Stack's constructor.

This function adopts existing valid architecture-specific stack in provided storage. No adjustments are done, no stack frame is created and stack pointer register's value is not calculated.

This is meant to adopt main()'s stack.

Parameters
[in]storageis a pointer to stack's storage
[in]sizeis the size of stack's storage, bytes
Todo:
implement minimal size check

◆ ~Stack()

distortos::internal::Stack::~Stack ( )

Stack's destructor.

Member Function Documentation

◆ checkStackGuard()

bool distortos::internal::Stack::checkStackGuard ( ) const
Returns
true if "stack guard" contains unmodified sentinel values, false if stack overflowed into "stack guard"

◆ checkStackPointer()

bool distortos::internal::Stack::checkStackPointer ( const void *const  stackPointer) const
inline

Checks whether stack pointer value is within range of this stack.

Note
The "stack guard" area is not a valid range for stack pointer.
Parameters
[in]stackPointeris the value of stack pointer that will be checked
Returns
true if stackPointer is within range of this stack, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getHighWaterMark()

size_t distortos::internal::Stack::getHighWaterMark ( ) const
Returns
stack's "high water mark" (max usage), excluding "stack guard", bytes
Here is the caller graph for this function:

◆ getSize()

size_t distortos::internal::Stack::getSize ( ) const
inline
Returns
adjusted size of stack's storage, excluding "stack guard", bytes
Here is the caller graph for this function:

◆ getStackPointer()

void* distortos::internal::Stack::getStackPointer ( ) const
inline

Gets current value of stack pointer.

Returns
current value of stack pointer
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize()

int distortos::internal::Stack::initialize ( Thread thread,
void(&)(Thread &)  run,
void(*)(Thread &)  preTerminationHook,
void(&)(Thread &)  terminationHook 
)

Fills the stack with stack sentinel, initializes its contents and stack pointer value.

Parameters
[in]threadis a reference to Thread object passed to function
[in]runis a reference to Thread's "run" function
[in]preTerminationHookis a pointer to Thread's pre-termination hook, nullptr to skip
[in]terminationHookis a reference to Thread's termination hook
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setStackPointer()

void distortos::internal::Stack::setStackPointer ( void *const  stackPointer)
inline

Sets value of stack pointer.

Parameters
[in]stackPointeris the new value of stack pointer
Here is the call graph for this function:

Member Data Documentation

◆ adjustedSize_

const size_t distortos::internal::Stack::adjustedSize_
private

adjusted size of stack's storage

◆ adjustedStorage_

void* const distortos::internal::Stack::adjustedStorage_
private

adjusted address of stack's storage

◆ stackGuardSize_

constexpr size_t distortos::internal::Stack::stackGuardSize_
staticprivate
Initial value:
{(CONFIG_STACK_GUARD_SIZE + CONFIG_ARCHITECTURE_STACK_ALIGNMENT - 1) /
CONFIG_ARCHITECTURE_STACK_ALIGNMENT * CONFIG_ARCHITECTURE_STACK_ALIGNMENT}

size of "stack guard", bytes

◆ stackPointer_

void* distortos::internal::Stack::stackPointer_
private

current value of stack pointer register

◆ storageUniquePointer_

StorageUniquePointer distortos::internal::Stack::storageUniquePointer_
private

storage for stack


The documentation for this class was generated from the following files: