Explanation for this assembly code

void* curbrk;

__asm__ __volatile__(
    "mov .curbrk, %%rax;"
    "mov %%rax, %0"
        : "=r" (curbrk)
        :: "%rax"
);

Can anyone explain what this simple assembler code does? Thank.

+3
source share
1 answer

It copies the value of the character .value, probably defined somewhere in the assembly or the linker of the script into the C variable curbrk, knocking down the case RAXin the process.

.curbrkprobably indicates the current end of the data segment. Glibc seems to define a similar character __curbrk, you are probably using some other libc (BSD?). In any case, there sbrk(0)will be a more portable way of accessing this value.

Crossreference FreeBSD, , : brk() sbrk(), HIDENAME, preend a ., amd64 System.map ( FreeBSD script?).

+3

All Articles