mirror of
https://github.com/autc04/Retro68.git
synced 2024-09-07 13:54:33 +00:00
31 lines
795 B
D
31 lines
795 B
D
import core.runtime;
|
|
import core.atomic;
|
|
import core.stdc.string;
|
|
import core.sys.posix.dlfcn;
|
|
|
|
shared uint tlsDtor, dtor;
|
|
void staticDtorHook() { atomicOp!"+="(tlsDtor, 1); }
|
|
void sharedStaticDtorHook() { atomicOp!"+="(dtor, 1); }
|
|
|
|
void runTest(string name)
|
|
{
|
|
auto h = Runtime.loadLibrary(name);
|
|
assert(h !is null);
|
|
|
|
*cast(void function()*).dlsym(h, "_D9lib_1341414staticDtorHookOPFZv") = &staticDtorHook;
|
|
*cast(void function()*).dlsym(h, "_D9lib_1341420sharedStaticDtorHookOPFZv") = &sharedStaticDtorHook;
|
|
|
|
Runtime.unloadLibrary(h);
|
|
assert(tlsDtor == 1);
|
|
assert(dtor == 1);
|
|
}
|
|
|
|
void main(string[] args)
|
|
{
|
|
auto name = args[0] ~ '\0';
|
|
const pathlen = strrchr(name.ptr, '/') - name.ptr + 1;
|
|
name = name[0 .. pathlen] ~ "lib_13414.so";
|
|
|
|
runTest(name);
|
|
}
|