[Issue 21656] [REG2.091] Wrong file read during exception stringification leads to SIGBUS
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Feb 23 08:59:03 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21656
--- Comment #8 from Jacob Carlborg <doob at me.com> ---
You are right that the file descriptor (AT_EXECFD) won't work, I just tested
that, it doesn't return a valid value. But, perhaps even better, it's possible
to access the address of the program headers of the executable (AT_PHDR) [1].
Here's an experiment I did on Linux:
# cat main.d
import core.stdc.stdio;
import core.internal.elf.dl;
extern (C) ulong getauxval(ulong type);
void main()
{
const aux = cast(void*) getauxval(3);
const baseAddress = SharedObject.thisExecutable.baseAddress;
printf("aux=%p baseAddress=%p diff=%ld\n", aux, baseAddress, aux -
baseAddress);
}
# dmd -run main.d
aux=0x55eb0f1e4040 baseAddress=0x55eb0f1e4000 diff=64
It returns a slightly different address than
`SharedObject.thisExecutable.baseAddress`, but it's close enough that it cannot
be a coincident. Perhaps someone with more knowledge of `core.internal.efl` can
explain why the difference.
[1] https://man7.org/linux/man-pages/man3/getauxval.3.html
--
More information about the Digitalmars-d-bugs
mailing list