diff options
author | Andrew Kaster <andrewdkaster@gmail.com> | 2020-05-15 21:38:03 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-20 08:37:50 +0200 |
commit | cdbbe14062ea49f9a9d9b0e5627aba9efd07659a (patch) | |
tree | cc65775010ad3b4fdefdbd44ac88ee7e922a6afb /Kernel | |
parent | 4361a502255e409f04c9325ef73f3cd10f9cafdb (diff) | |
download | serenity-cdbbe14062ea49f9a9d9b0e5627aba9efd07659a.zip |
LibC: Implement Itanium C++ ABI for static variable guards
This is __cxa_guard_acquire, __cxa_guard_release, and __cxa_guard_abort.
We put these symbols in a 'fake' libstdc++ to trick gcc into thinking it
has libstdc++. These symbols are necessary for C++ programs and not C
programs, so, seems file. There's no way to tell gcc that, for example,
the standard lib it should use is libc++ or libc. So, this is what we
have for now.
When threaded code enters a block that is trying to call the constructor
for a block-scope static, the compiler will emit calls to these methods
to handle the "call_once" nature of block-scope statics.
The compiler creates a 64-bit guard variable, which it checks the first
byte of to determine if the variable should be intialized or not.
If the compiler-generated code reads that byte as a 0, it will call
__cxa_guard_acquire to try and be the thread to call the constructor for
the static variable. If the first byte is 1, it will assume that the
variable's constructor was called, and go on to access it.
__cxa_guard_acquire uses one of the 7 implementation defined bytes of
the guard variable as an atomic 8 bit variable. To control a state
machine that lets each entering thread know if they gained
'initialization rights', someone is working on the varaible, someone is
working on the varaible and there's at least one thread waiting for it
to be intialized, or if the variable was initialized and it's time to
access it. We only store a 1 to the byte the compiler looks at in
__cxa_guard_release, and use a futex to handle waiting.
Diffstat (limited to 'Kernel')
0 files changed, 0 insertions, 0 deletions