ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ns3::UcontextFiberManager Class Reference

#include <ucontext-fiber-manager.h>

+ Inheritance diagram for ns3::UcontextFiberManager:
+ Collaboration diagram for ns3::UcontextFiberManager:

Public Member Functions

 UcontextFiberManager ()
virtual ~UcontextFiberManager ()
virtual struct FiberCreate (void(*callback)(void *), void *context, uint32_t stackSize)
virtual struct FiberCreateFromCaller (void)
virtual void Delete (struct Fiber *fiber)
virtual uint32_t GetStackSize (struct Fiber *fiber) const
virtual void SetSwitchNotification (void(*fn)(void))
virtual void SwitchTo (struct Fiber *from, const struct Fiber *to)
- Public Member Functions inherited from ns3::FiberManager
virtual ~FiberManager ()
virtual struct FiberClone (struct Fiber *fiber)

Private Member Functions

uint8_t * AllocateStack (uint32_t stackSize)
uint32_t CalcStackSize (uint32_t size)
void DeallocateStack (uint8_t *buffer, uint32_t stackSize)
void SetupSignalHandler (void)

Static Private Member Functions

static void FreeAlternateSignalStack (void)
static void SegfaultHandler (int sig, siginfo_t *si, void *unused)
static void Trampoline (int a0, int a1, int a2, int a3)

Private Attributes

void(* m_notifySwitch )(void)

Static Private Attributes

static void * g_alternateSignalStack = 0
static std::list< unsigned long > g_guardPages

Detailed Description

Definition at line 10 of file ucontext-fiber-manager.h.

Constructor & Destructor Documentation

ns3::UcontextFiberManager::UcontextFiberManager ( )

Definition at line 177 of file ucontext-fiber-manager.cc.

ns3::UcontextFiberManager::~UcontextFiberManager ( )
virtual

Definition at line 181 of file ucontext-fiber-manager.cc.

Member Function Documentation

uint8_t * ns3::UcontextFiberManager::AllocateStack ( uint32_t  stackSize)
private

Definition at line 131 of file ucontext-fiber-manager.cc.

References CalcStackSize(), errno, g_guardPages, and SetupSignalHandler().

Referenced by Create().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32_t ns3::UcontextFiberManager::CalcStackSize ( uint32_t  size)
private

Definition at line 112 of file ucontext-fiber-manager.cc.

Referenced by AllocateStack(), and DeallocateStack().

+ Here is the caller graph for this function:

struct Fiber * ns3::UcontextFiberManager::Create ( void(*)(void *)  callback,
void *  context,
uint32_t  stackSize 
)
readvirtual
Parameters
callbackfunction to use as main loop for the newly-created fiber
stackSizesize of the stack to allocate for this fiber.
Returns
a newly-created fiber context.

Implements ns3::FiberManager.

Definition at line 203 of file ucontext-fiber-manager.cc.

References AllocateStack(), ns3::UcontextFiber::context, ns3::UcontextFiber::stack, ns3::UcontextFiber::stackSize, Trampoline(), VALGRIND_STACK_REGISTER, and ns3::UcontextFiber::vgId.

+ Here is the call graph for this function:

struct Fiber * ns3::UcontextFiberManager::CreateFromCaller ( void  )
readvirtual
Returns
an empty context

Create a fiber context which can be used as a from argument to the SwitchTo method This method is usually used to create a context which references the main 'normal' thread. i.e., the thread initially managed by the underlying kernel which runs on the kernel-managed stack.

Implements ns3::FiberManager.

Definition at line 236 of file ucontext-fiber-manager.cc.

References ns3::UcontextFiber::stack, and ns3::UcontextFiber::stackSize.

void ns3::UcontextFiberManager::DeallocateStack ( uint8_t *  buffer,
uint32_t  stackSize 
)
private

Definition at line 159 of file ucontext-fiber-manager.cc.

References CalcStackSize(), errno, and g_guardPages.

Referenced by Delete().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::UcontextFiberManager::Delete ( struct Fiber fiber)
virtual
Parameters
contextto delete

Release any ressource associated to this context. Obviously, this method must be called from another context than the one which is being deleted.

Implements ns3::FiberManager.

Definition at line 245 of file ucontext-fiber-manager.cc.

References DeallocateStack(), ns3::UcontextFiber::stack, ns3::UcontextFiber::stackSize, VALGRIND_STACK_DEREGISTER, and ns3::UcontextFiber::vgId.

+ Here is the call graph for this function:

void ns3::UcontextFiberManager::FreeAlternateSignalStack ( void  )
staticprivate

Definition at line 63 of file ucontext-fiber-manager.cc.

References g_alternateSignalStack.

Referenced by SetupSignalHandler().

+ Here is the caller graph for this function:

uint32_t ns3::UcontextFiberManager::GetStackSize ( struct Fiber fiber) const
virtual
Returns
size of stack allocated in fiber.

Implements ns3::FiberManager.

Definition at line 272 of file ucontext-fiber-manager.cc.

References ns3::UcontextFiber::stackSize.

void ns3::UcontextFiberManager::SegfaultHandler ( int  sig,
siginfo_t *  si,
void *  unused 
)
staticprivate

Definition at line 38 of file ucontext-fiber-manager.cc.

References g_guardPages.

Referenced by SetupSignalHandler().

+ Here is the caller graph for this function:

void ns3::UcontextFiberManager::SetSwitchNotification ( void(*)(void)  fn)
virtual
Parameters
fna function which will be invoked whenever SwitchTo is invoked, just before it returns to the destination fiber.

Implements ns3::FiberManager.

Definition at line 279 of file ucontext-fiber-manager.cc.

References m_notifySwitch.

void ns3::UcontextFiberManager::SetupSignalHandler ( void  )
private

We need to setup an alternate signal stack because the kernel will refuse to deliver a SIGSEGV signal to our process while it is on the stack which triggered this same error. This kind of makes sense so, we cannot blame the kernel for this.

Definition at line 69 of file ucontext-fiber-manager.cc.

References errno, FreeAlternateSignalStack(), g_alternateSignalStack, and SegfaultHandler().

Referenced by AllocateStack().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::UcontextFiberManager::SwitchTo ( struct Fiber from,
const struct Fiber to 
)
virtual
Parameters
fromfrom context
toto context

This function saves the caller's context into the from context and restores the current context from the to context. The first time this function is called, it is usually called with a from set to a context obtained through CreateFromCaller and with a to set to a context obtained through Create.

Implements ns3::FiberManager.

Definition at line 259 of file ucontext-fiber-manager.cc.

References ns3::UcontextFiber::context, and m_notifySwitch.

void ns3::UcontextFiberManager::Trampoline ( int  a0,
int  a1,
int  a2,
int  a3 
)
staticprivate

Definition at line 186 of file ucontext-fiber-manager.cc.

Referenced by Create().

+ Here is the caller graph for this function:

Member Data Documentation

void * ns3::UcontextFiberManager::g_alternateSignalStack = 0
staticprivate

Definition at line 38 of file ucontext-fiber-manager.h.

Referenced by FreeAlternateSignalStack(), and SetupSignalHandler().

std::list< unsigned long > ns3::UcontextFiberManager::g_guardPages
staticprivate

Definition at line 39 of file ucontext-fiber-manager.h.

Referenced by AllocateStack(), DeallocateStack(), and SegfaultHandler().

void(* ns3::UcontextFiberManager::m_notifySwitch)(void)
private

Definition at line 37 of file ucontext-fiber-manager.h.

Referenced by SetSwitchNotification(), and SwitchTo().


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