Re: Format of Pointers in Unix

From: Måns Rullgård (mru_at_kth.se)
Date: 05/17/04


Date: Mon, 17 May 2004 09:26:33 +0200

OT for c.l.c, followup set.

Daniel Rudy <dcrudy@invalid.pacbell.nospam.net.0123456789> writes:

> Now here's an interesting peice of code that I wrote earlier today
> complete with the compile and run:

[...]

> /* Lets do a pointer programming error... */
> thing_ptr_2 = 7;
> printf("Address of thing_ptr is %x\n", &thing_ptr);
> printf("Contents of thing_ptr_2 %x\n\n", thing_ptr_2);
>
> /* This will probably seg_fault the program. */
> printf("Contents of thing via our blown ptr %d\n", **thing_ptr_2);

[...]

> Memory fault (core dumped)

[...]

> As you can see, the program cored because it did not like the address
> that I assigned to thing_ptr_2, which would suggest a segmented memory
> model?

Unix uses virtual memory. On every memory access the CPU will look up
the physical address corresponding to the virtual address being
accessed. This mapping has been set up by the OS for each process.
For efficiency the mapping is done in pages of typically 4k or 8k
bytes. If there is no mapping for the virtual address being accessed,
your program tries to access the CPU will signal an error, and the OS
will kill the process. This is what happened in your case.

-- 
Måns Rullgård
mru@kth.se


Relevant Pages

  • Re: Format of Pointers in Unix
    ... OT for c.l.c, followup set. ... Unix uses virtual memory. ... This mapping has been set up by the OS for each process. ... your program tries to access the CPU will signal an error, ...
    (comp.unix.programmer)
  • VMM: syscall for reordering pages in vm
    ... for virtual memory page exchange by modifying the physicalvirtual ... Moving pages in virtual memory without ... physicalvirtual mapping of these pages and the exchange would be done ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: RH30: Virtual Mem shot heavily by locale-archive...
    ... This mapping just reserves a slot of virtual memory ... Private mapping means copy-on-write. ... extra physical memory for each process mapping the file. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)