System call invoked when writing into a heap memory

后端 未结 3 815
北荒
北荒 2021-01-26 20:44

I know for malloc sbrk is the system call invoked ,Similarly What is the system cal invoked when i write to a malloed memory(heap memory)

int main

{

  /* 10 by         


        
相关标签:
3条回答
  • 2021-01-26 21:19

    "operating system doesn't see every write that occurs: a write to memory corresponds simply to a STORE assembly instruction, not a system call. It is the hardware that takes care of the STORE and the necessary address translation. The only time the OS will see a memory write is when the address translation in the page tables fails, causing a trap to the OS. "

    Please read the below link for details

    http://pages.cs.wisc.edu/~dusseau/Classes/CS537-F04/Questions/sol12.html

    0 讨论(0)
  • 2021-01-26 21:20

    There are no system call involved in this case. Ask you compiler to generate assembly so that you can see that there is only some MOV instructions there. Or you can use a debugger to see the assembly

    0 讨论(0)
  • 2021-01-26 21:24

    Accessing memory does not require a system call. On the contrary, accessing memory is what most of your code does most of the time! On a modern OS, you have a flat view of a contiguous range of virtual memory, and you typically only need a system call to mark a particular region (a "page") of that memory as valid; other times, contiguously growing memory ranges such as the call stack don't even require any action on your program's part. It's solely the job of your operating system's memory manager to intercept accesses to memory that isn't mapped to physical memory (via a page fault), do some kernel magic to bring the desired memory into physical space and return control to your program.

    The only reason malloc occasionally needs to perform a system call is because it asks the operating system for a random piece of virtual memory somewhere in the middle. If your program were to only function with global and local variables (but no dynamic allocation), you wouldn't need any system calls for memory management.

    0 讨论(0)
提交回复
热议问题