Does any one know what tool to use to visualize how is memory layed out for C on linux systems. I mean how much stack portion is used in functional call.
I'm assuming you mean linux for 32-bit x86. PPC, for example, would be very different.
Quote:
Where exactly does the argument to function sit in memory?
It depends. I've seen gcc do a lot of 'cheating' to avoid writing to the stack, like passing floating point arguments in SSE registers. Compiling with -O0 ought to avoid stuff like that.
Quote:
I have written small program pasted below. But I am not able to infer anything with the output I am getting.
(attached is the c code)
Global variable 'add' is used to locate the stack's base.
I figured it out by brute force, reading upwards in memory until my program segfaulted. On 32-bit x86 linux, the base of the stack is at 0xffff000, which is exactly 4096 bytes less than the highest possible address(0xffffffff). This is probably not a coincidence, since 4096 bytes is is the page size on my system(yours might be 8192); this means it's precisely one memory page away from the bottom of memory.
If you mean base as in where the stack pointer is right at that moment, taking the address of a local variable would be pretty close.
Quote:
I don't know if this technique works ? waiting for your views
Well, what is in memory is just as important as where it's in memory. I don't think you'll be able to see the big picture without printing out whole parts of it and seeing what changes when you do what. Pick numbers you can easily recognize and you'll find them. This may be the world's only practical application of leet -- 0xACC01ADE, 0xB01DFACE, 0x1ABE11ED, 0xC0A1FACE, etc. are fairly easy to notice. Here's the first couple lines of output from my program:
Sure enough, see that "bebafeca" somewhere between 0xffffce80 and 0xffffce8f? That's 0xCAFEBABE with the bytes backwards. Also see that "44850408" starting at 0xffffcf20? That's part of main()'s address. The whole thing won't be the same since it's returning to somewhere in the middle of main instead of right at the beginning, but it's close.
There's a lot more than function calls on the stack, by the way. Suppose it's run like:
Sure enough, there they are, and after that, environment variables.
So, I can't give you a precise definition for your system, but you can piece some things together with eyesight.
What's the best way to find out how much memory is being used/available? I tried using free, but I didn't quite understand the output. Can someone explain it?
$ free
total used free shared buffers cached
Mem: 16304536 16256376 48160 0 ... (6 Replies)
Hi,
I having problem with my linux machine
it have 6Gb physical memory and somehow it always almost coming to the bottom neck and than it start writing to the swap memory
you can see that there is more than 4G in cahce, is there any way to clean the cache or to limit it to 2Gb?
host1... (6 Replies)
Hi
I have Fedora linux with XFCE desktop. I want to use Indic lanquage in that. I have installed unicode devnagri fonts. But I am not able to change my default keyboard layout. How can I change default keyboard layout in XFCE or through command line.
Thanks
NeeleshG (0 Replies)
Hi All,
We are using the linux servers and need to track the memory utilization of the box. Could anyone advice how the same can be achived.
:) (1 Reply)
I am trying to create an application that will be able to sniff memory of other applications.
I am not completely new to systems programming but I am not sure how to go about this task. I understand that accomplishing this mainly require these steps.
1: Get a list of processes
2: Find the... (2 Replies)
Hello, I am using Linux os.
$ df -k /dev/shm
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 2023256 1065000 958256 53% /dev/shm
$
Based on my google this, it is shared memory. What is this shared memory and where exactly it is used? Can you... (5 Replies)
In the following code, why the final result of "usC=cA+(char)ucB;" is 0xFF00?
In my opioion the memory layout of cA is "10000000" and
(char)cB is "10000000",usC type is unsigned short ,so the result should be "100000000" ,the 0x100.
Please help tell me what is wrong? Thanks!!;)
... (2 Replies)