UNIX> fb4 sbrk(0) = 0x70f8 Allocated 4 bytes. buf = 0x61a8, buf[-1] = 0, buf[-2] = 16, buf[0] = 1000 Allocated 8 bytes. buf = 0x61b8, buf[-1] = 0, buf[-2] = 16, buf[0] = 1001 Allocated 12 bytes. buf = 0x61c8, buf[-1] = 0, buf[-2] = 24, buf[0] = 1002 Allocated 16 bytes. buf = 0x61e0, buf[-1] = 0, buf[-2] = 24, buf[0] = 1003 Allocated 20 bytes. buf = 0x61f8, buf[-1] = 0, buf[-2] = 32, buf[0] = 1004 Allocated 24 bytes. buf = 0x6218, buf[-1] = 0, buf[-2] = 32, buf[0] = 1005 Allocated 28 bytes. buf = 0x6238, buf[-1] = 0, buf[-2] = 40, buf[0] = 1006 Allocated 100 bytes. buf = 0x6260, buf[-1] = 0, buf[-2] = 112, buf[0] = 1007 sbrk(0) = 0x70f8 UNIX>This was the output on one of the cetus machines in 1996. In 1999, I get the following output on cetus1a:
UNIX> fb4 sbrk(0) = 0x20b08 Allocated 4 bytes. buf = 0x20b18, buf[-1] = 0, buf[-2] = 9, buf[0] = 1000 Allocated 8 bytes. buf = 0x20b28, buf[-1] = 0, buf[-2] = 9, buf[0] = 1001 Allocated 12 bytes. buf = 0x20f20, buf[-1] = 0, buf[-2] = 17, buf[0] = 1002 Allocated 16 bytes. buf = 0x20f38, buf[-1] = 0, buf[-2] = 17, buf[0] = 1003 Allocated 20 bytes. buf = 0x21528, buf[-1] = 0, buf[-2] = 25, buf[0] = 1004 Allocated 24 bytes. buf = 0x21548, buf[-1] = 0, buf[-2] = 25, buf[0] = 1005 Allocated 28 bytes. buf = 0x21d30, buf[-1] = 0, buf[-2] = 33, buf[0] = 1006 Allocated 100 bytes. buf = 0x22730, buf[-1] = 0, buf[-2] = 105, buf[0] = 1007 sbrk(0) = 0x22b08 UNIX>This is different from the example output above, but as you can see, it is functionally equivalent -- the value in the word two words before the returned pointer is seven less than the number of bytes allocated. Why? I don't know -- but all you have to do is add seven to it to get.
The Pentium box on my desk runs Linux 2.2.10, and it has the following output:
UNIX> fb4 sbrk(0) = 0x8049778 Allocated 4 bytes. buf = 0x8049780, buf[-1] = 17, buf[-2] = 0, buf[0] = 1000 Allocated 8 bytes. buf = 0x8049790, buf[-1] = 17, buf[-2] = 0, buf[0] = 1001 Allocated 12 bytes. buf = 0x80497a0, buf[-1] = 17, buf[-2] = 0, buf[0] = 1002 Allocated 16 bytes. buf = 0x80497b0, buf[-1] = 25, buf[-2] = 0, buf[0] = 1003 Allocated 20 bytes. buf = 0x80497c8, buf[-1] = 25, buf[-2] = 0, buf[0] = 1004 Allocated 24 bytes. buf = 0x80497e0, buf[-1] = 33, buf[-2] = 0, buf[0] = 1005 Allocated 28 bytes. buf = 0x8049800, buf[-1] = 33, buf[-2] = 0, buf[0] = 1006 Allocated 100 bytes. buf = 0x8049820, buf[-1] = 105, buf[-2] = 0, buf[0] = 1007 sbrk(0) = 0x804a000So now the size minus seven is in the first word before the pointer.
Here's the output on a DECstation running Ultrix:
UNIX> fb4 sbrk(0) = 0x10001100 Allocated 4 bytes. buf = 0x10005000, buf[-1] = 268435695, buf[-2] = 0, buf[0] = 1000 Allocated 8 bytes. buf = 0x10006000, buf[-1] = 268435951, buf[-2] = 0, buf[0] = 1001 Allocated 12 bytes. buf = 0x10006010, buf[-1] = 268435951, buf[-2] = 0, buf[0] = 1002 Allocated 16 bytes. buf = 0x10007000, buf[-1] = 268436207, buf[-2] = 0, buf[0] = 1003 Allocated 20 bytes. buf = 0x10007020, buf[-1] = 268436207, buf[-2] = 0, buf[0] = 1004 Allocated 24 bytes. buf = 0x10007040, buf[-1] = 268436207, buf[-2] = 0, buf[0] = 1005 Allocated 28 bytes. buf = 0x10007060, buf[-1] = 268436207, buf[-2] = 0, buf[0] = 1006 Allocated 100 bytes. buf = 0x10008000, buf[-1] = 268436719, buf[-2] = 0, buf[0] = 1007 sbrk(0) = 0x10008ffc UNIX>There's an odd one -- Any clues? When I turn the int's into shorts in fb5.c, I get:
UNIX> fb5 sbrk(0) = 0x10001100 Allocated 4 bytes. buf = 0x10005000, buf[-1] = 4096, buf[-2] = 239, buf[0] = 1000 Allocated 8 bytes. buf = 0x10006000, buf[-1] = 4096, buf[-2] = 495, buf[0] = 1001 Allocated 12 bytes. buf = 0x10006010, buf[-1] = 4096, buf[-2] = 495, buf[0] = 1002 Allocated 16 bytes. buf = 0x10007000, buf[-1] = 4096, buf[-2] = 751, buf[0] = 1003 Allocated 20 bytes. buf = 0x10007020, buf[-1] = 4096, buf[-2] = 751, buf[0] = 1004 Allocated 24 bytes. buf = 0x10007040, buf[-1] = 4096, buf[-2] = 751, buf[0] = 1005 Allocated 28 bytes. buf = 0x10007060, buf[-1] = 4096, buf[-2] = 751, buf[0] = 1006 Allocated 100 bytes. buf = 0x10008000, buf[-1] = 4096, buf[-2] = 1263, buf[0] = 1007 sbrk(0) = 0x10008ffc UNIX>Odd indeed. Can you guess at an explanation? I think I can, but it will take a little probing. Stay tuned....