L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
thread.h File Reference

Low-level Thread Functions. More...

#include <l4/sys/compiler.h>
#include <l4/sys/types.h>
#include <l4/sys/scheduler.h>
#include <l4/util/arch/thread.h>
Include dependency graph for thread.h:

Go to the source code of this file.

Macros

#define __L4UTIL_THREAD_FUNC(name)
 Defines a wrapper function that sets up the registers according to the calling conventions for the architecture.
#define _L4UTIL_THREAD_CXX_FUNC_IMPL_(suffix, class, fn_name, from_asm_name, ...)
 Implement stub and handler.
#define L4UTIL_THREAD_CXX_FUNC_PROTO(fn_name, ...)
 Declare static C++ class method which can be called as handler were only stack and instruction pointer are in a well-defined state.
#define L4UTIL_THREAD_CXX_FUNC_IMPL(class, fn_name, ...)
 Implement static C++ class method which can be called as handler were only stack and instruction pointer are in a well-defined state.
#define L4UTIL_THREAD_CXX_FUNC_INTERRUPT_IMPL(class, fn_name, ...)
 Implement static C++ class method which can be called as handler were only stack and instruction pointer are in a well-defined state.

Detailed Description

Low-level Thread Functions.

Date
1997
Author
Sebastian Schönberg

Definition in file thread.h.

Macro Definition Documentation

◆ __L4UTIL_THREAD_FUNC

#define __L4UTIL_THREAD_FUNC ( name)
Value:
void L4_NORETURN name(void)
#define L4_NORETURN
Noreturn function attribute.
Definition compiler.h:207

Defines a wrapper function that sets up the registers according to the calling conventions for the architecture.

Use this as a function header when starting a low-level thread where only stack and instruction pointer are in a well-defined state.

Example:

L4UTIL_THREAD_FUNC(helper_thread)
{
}
thread_cap->ex_regs((l4_umword_t)helper_thread, stack_addr);
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
L4_NORETURN void l4_infinite_loop(void)
Infinite loop.
Definition compiler.h:358

Definition at line 74 of file thread.h.

◆ _L4UTIL_THREAD_CXX_FUNC_IMPL_

#define _L4UTIL_THREAD_CXX_FUNC_IMPL_ ( suffix,
class,
fn_name,
from_asm_name,
... )
Value:
asm (".global " L4_stringify(fn_name ## _stub) "\n" \
".type " L4_stringify(fn_name ## _stub) " STT_FUNC \n" \
L4_stringify(fn_name ## _stub) ": \n" \
L4UTIL_THREAD_CXX_FUNC_IMPL ## suffix ## _STUB(from_asm_name) \
); \
\
[[noreturn]] void __attribute__((used)) class::from_asm_name(__VA_ARGS__)
#define L4_stringify(x)
stringify.
Definition compiler.h:312
#define L4UTIL_THREAD_CXX_FUNC_IMPL(class, fn_name,...)
Implement static C++ class method which can be called as handler were only stack and instruction poin...
Definition thread.h:176

Implement stub and handler.

For 'Foo::foo(int a, int b)' this macro expands into:

asm (".global foo_stub \n"
"foo_stub: \n"
... align stack pointer ...
"<call> foo_from_asm \n");
[[noreturn]] static void __attribute__((used))
Foo::foo(int a, int b) asm ("foo_from_asm")

Definition at line 102 of file thread.h.

◆ L4UTIL_THREAD_CXX_FUNC_IMPL

#define L4UTIL_THREAD_CXX_FUNC_IMPL ( class,
fn_name,
... )
Value:
[[noreturn]] void class::fn_name(__VA_ARGS__)

Implement static C++ class method which can be called as handler were only stack and instruction pointer are in a well-defined state.

This is important for certain architectures defining global registers or for architectures like AMD64 defining a "red zone" (a reserved fixed-size area below the current stack pointer to be used for temporary data).

The first two parameters of this macro define class name and method name, followed by up to three function parameters.

Use these macros like follows:

class Foo
{
L4UTIL_THREAD_CXX_FUNC_PROTO(handler, int param1, long param2);
};
L4UTIL_THREAD_CXX_FUNC_IMPL(Foo, handler, int param1, long param2)
{
printf("param1 = %d, param2 = %ld\n", param1, param2);
}
#define L4UTIL_THREAD_CXX_FUNC_PROTO(fn_name,...)
Declare static C++ class method which can be called as handler were only stack and instruction pointe...
Definition thread.h:127

to declare the method

[[noreturn]] void Foo::handler(int param1, long param2);
Note
Use together with L4UTIL_THREAD_CXX_FUNC_PROTO().

Definition at line 176 of file thread.h.

◆ L4UTIL_THREAD_CXX_FUNC_INTERRUPT_IMPL

#define L4UTIL_THREAD_CXX_FUNC_INTERRUPT_IMPL ( class,
fn_name,
... )
Value:
_L4UTIL_THREAD_CXX_FUNC_IMPL(_INTERRUPT, class, fn_name, ##__VA_ARGS__)

Implement static C++ class method which can be called as handler were only stack and instruction pointer are in a well-defined state.

In contrast to L4UTIL_THREAD_CXX_FUNC_IMPL(), assume that this function may interrupt code executed at another user-level context and there are adaptions required to the stack pointer (alignment, consider the "red zone" on AMD64, etc.)

Definition at line 194 of file thread.h.

◆ L4UTIL_THREAD_CXX_FUNC_PROTO

#define L4UTIL_THREAD_CXX_FUNC_PROTO ( fn_name,
... )
Value:
[[noreturn]] static void fn_name(__VA_ARGS__) \
asm (L4_stringify(fn_name ## _stub)); \
[[noreturn]] static void fn_name ## _from_asm(__VA_ARGS__) \
asm (L4_stringify(fn_name ## _from_asm))

Declare static C++ class method which can be called as handler were only stack and instruction pointer are in a well-defined state.

Architecture-specific implementations may override this macro to use certain function attributes (e.g. attribute((regparm(3))) on x86).

Note
Use together with L4UTIL_THREAD_CXX_FUNC_IMPL() or L4UTIL_THREAD_CXX_FUNC_IMPL_SAME_STACK().

Definition at line 127 of file thread.h.