Pointer dereferencing at a lower level in C

When malloc returns a pointer (virtual address of a data block),

char *p = malloc (10);

p has a virtual address (say x). A pcontains a virtual address block of 10 addresses. Say these virtual addresses are from y to y + 10.

These 10 addresses belong to the page, and virtual β†’ physical mapping is placed in the page table.

When the processor searches for pointer p, let's say printf("%c", *p);how does the processor know that it needs to access address in y?

Is the page table available twice to dereference the pointer, in other words, to print the address indicated p? How exactly is this done, can anyone explain?

Also, in order to access the stack variables, should the processor access it through the page table? Isn't the stack pointer (SP) pointing to the stack already?

+3
source share
2 answers

I think there is a confusion of different layers.

First of all, page tables . This is a data structure that uses some memory to provide pointers with more memory. Given a specific virtual address, it can deconstruct it into indexes on a table. Right now, this is happening under the cover in the core, but it's possible to implement the same idea in user space.

. , , . , ? cr3. ; , cr3 .

: ? , (MIPs ) , . x86 ( ) . , . , , , , .

, , : , , , , . , , , , .


, , , , .

+3

p 10 .

. p - , 10- ; , .

-1

All Articles