i wonder about linux memory alignment and layout -


two strange looks code example below not make sense.

  1. why distance between foo , argv[0] different?
  2. why not aligned 4? although expected result multiple of 4 , not

i know detailed reasons strange looks.

and know not relate aslr

[root@localhost ~]# cat /etc/fedora-release  fedora release 14 (laughlin) [root@localhost ~]# cat poc.c #include <stdio.h> int main(int argc, char *argv[]){ int foo;     printf("%d\n",  (int)argv[0] - (int)&foo); } [root@localhost ~]# ./poc 5345 [root@localhost ~]# ./poc 8465 [root@localhost ~]# ./poc 4641 [root@localhost ~]# ./poc 1201 [root@localhost ~]# ./poc 2881 [root@localhost ~]# ./poc 7073 [root@localhost ~]# ./poc 5905 [root@localhost ~]# ./poc 2225 [root@localhost ~]# ./poc 2465 [root@localhost ~]# ./poc 6017 [root@localhost ~]# ./poc 8657 [root@localhost ~]# ./poc 8401 [root@localhost ~]# ./poc 5073 [root@localhost ~]# ./poc 5505 [root@localhost ~]# ./poc 1761 [root@localhost ~]# ./poc 8609 [root@localhost ~]# ./poc 3665 [root@localhost ~]# ./poc 3633 [root@localhost ~]# ./poc 6257 [root@localhost ~]# ./poc 3441 [root@localhost ~]# ./poc 4961 [root@localhost ~]# ./poc 5233 [root@localhost ~]# ./poc 561 [root@localhost ~]# ./poc 3441 [root@localhost ~]# ./poc 2097 [root@localhost ~]# ./poc 1729 [root@localhost ~]# ./poc 1841 [root@localhost ~]# ./poc 2241 [root@localhost ~]# ./poc 2145 [root@localhost ~]# ./poc 6593 [root@localhost ~]# ./poc 5681 [root@localhost ~]# ./poc 737 [root@localhost ~]# ./poc 8353 [root@localhost ~]# ./poc 1937 [root@localhost ~]# ./poc 3937 [root@localhost ~]# ./poc 4769 [root@localhost ~]# ./poc 3441 [root@localhost ~]# ./poc 6097 [root@localhost ~]# ./poc 6673 [root@localhost ~]# ./poc 1857 [root@localhost ~]# ./poc 5617 [root@localhost ~]# ./poc 5473 [root@localhost ~]# ./poc 7313 [root@localhost ~]# ./poc 3921 [root@localhost ~]# ./poc 2369 [root@localhost ~]# ./poc 4609 [root@localhost ~]# ./poc 5569 [root@localhost ~]# ./poc 6209 [root@localhost ~]# ./poc 3457 [root@localhost ~]# ./poc 3665 [root@localhost ~]# ./poc 3297 [root@localhost ~]# ./poc 4465 [root@localhost ~]# ./poc 5281 [root@localhost ~]# ./poc 6017 [root@localhost ~]# ./poc 2705 [root@localhost ~]# ./poc 1601 [root@localhost ~]# ./poc 7457 [root@localhost ~]# ./poc 4145 [root@localhost ~]# ./poc 2353 [root@localhost ~]# ./poc 5537 [root@localhost ~]# ./poc 7873 [root@localhost ~]# ./poc 6449 [root@localhost ~]# ./poc 3297 

1. why distance between foo , argv[0] different?

because of aslr.

and know not relate aslr

are sure that? kernel's virtual addresses space randomization parameter value (randomize_va_space) ? should 0.

2. why not aligned 4? although expected result multiple of 4 , not

what want demonstrate that? code computes distance first string in argv local variable foo. what's point of this?

how & parameters , local variables handled os , compilers dependent. have @ following post : where c/c++ main functions parameters


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -