即使我正在使用 /dev/urandom,在调用该函数 4 次后,我仍然获得相同的地址位置。这是为什么 ?为什么 /dev/urandom 提供的数字非常低或非常高?
104 0x7fffb128de78 0x7f9e3c565000 4294967192 0x7fffb128de78 0x7f9e3c564000 97 0x7fffb128de78 0x7f9e3c563000 4294967139 0x7fffb128de78 0x7f9e3c562000
void test(void){
char random[4];
int filedescriptor = open("/dev/urandom", O_RDONLY);
read(filedescriptor, random, 4);
close(filedescriptor);
unsigned int hintmemoryaddress = (unsigned int)random;
printf("%u\n", hintmemoryaddress);
char *p = (char *)hintmemoryaddress;
p += hintmemoryaddress;
printf("%p\n", &p);
char *x = (char *)mmap((void *)&p, 1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
printf("%p\n", x);
}
int main(void){
test();
test();
test();
test();
return 0;
}