Udai F.mHd
Udai F.mHd

Reputation: 92

how virtual addresses assigned?

Take this C code for example

#include <stdio.h>
#include <stdlib.h>

int main() {

    int x;
    int* y = (int *) malloc(10*sizeof(int));

    printf("%p\n",&x);
    printf("%p\n",y);
    printf("%p\n",&(y[1]));

    while(1);

    return 0;
}

Which will print virtual addresses that look something like this

0x7ffd4e96d214

0x908010

0x908014

The virtual addresses will be different every time you run the binary file which made me think how the virtual address are actually decided for a program ?

Upvotes: 4

Views: 119

Answers (1)

makadev
makadev

Reputation: 1054

This is - probably - the effect of ASLR.

The decision should - as the name Address Space Layout Randomization tells - be random.

Upvotes: 4

Related Questions