Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. \item \textbf{Stack Growth}
  2.  
  3. We will allocate just one page for the user-stack every time a new process is created. When this process wants to have more memory, we should give more memory to the user. When this happens, the user will actually try to access a virtual memory that is not mapped in its current page table. This will cause a page fault exception. When a page fault exception is raised, in the page fault handler (i.e., VmmSolvePageFault) we will determine if the address requested by the process is a valid one and we will allocate a new page for the proces.
  4.  
  5. \bigskip
  6.  
  7. The following addresses will be considered invalid:
  8. \begin{itemize}
  9. \item a NULL pointer
  10. \item a kernel address
  11. \item an address below the user stack
  12. \item an address that does not appear to be a stack access, i.e. the requested virtual address does not appear to be the next contiguous memory page address of the stack
  13. \end{itemize}
  14.  
  15. HAL9000 already validates that the address is not null and that it is not a kernel address inside \textit{VmmSolvePageFault()}, therefore we will only have to add validations for the last two cases. In order to check if the address is below the user stack, we simply compare the requested address with the current thread's \textit{UserStackBase} field. Finally, we can check that requested address is the next contiguous memory page using the macros \textit{AlignAddressLower()} and \textit{AlignAddressUpper()}. If we align up the address of the top of the user stack by 4KB and align down the requested address by the same amount, we should get the same result if the addresses are contiguous.
  16.  
  17. \bigskip
  18.  
  19. If the requested address is invalid we should let the page fault handler kill the process. On the other hand, if we determine that the requested address is valid, we should proceed as normal and allocate a new page for the user stack. Provided we still have space for an additional page (i.e. the maximum stack size was not reached), the allocation will be successful.
  20.  
  21. Once it is confirmed that the requested address is a valid address, we would want to acquire a new frame from the physical memory and set this frame as part of the process' paging data. HAL9000 will reserve a frame of physical memory through \textit{PmmReserveMemory()}. Finally, this newly reserved frame must be mapped to a virtual address through \textit{MmuMapMemoryInternal()}.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement