Depending on the address of the initial pages allocated in setup_initmap(), the map_setup_2mbpages() function may not find an existing PDPT and or PDT in the page tables, and thus may need to use a new PDPT and/or a new PDT. However, the PDPT and PDT addresses passed to this function correspond to in-use pages, and as such cannot be reused and assigned to new PTEs. Moreover, when creating a new PTE, the map_setup_2mbpages() function is simply OR-ing the page address with the page flags, failing to set the USER flag and thereby preventing any pages referenced by this directory entry from being mapped for user space access; this may cause bogus segmentation fault signals to be delivered to the user process (https://github.com/nanovms/nanos/issues/1999#issuecomment-2072735021).
This change fixes the above issues by amending map_setup_2mbpages() so that it takes a physical memory region from which to allocate any new pages it may need, and calls new_level_pte() when creating a new PTE.
Depending on the address of the initial pages allocated in setup_initmap(), the map_setup_2mbpages() function may not find an existing PDPT and or PDT in the page tables, and thus may need to use a new PDPT and/or a new PDT. However, the PDPT and PDT addresses passed to this function correspond to in-use pages, and as such cannot be reused and assigned to new PTEs. Moreover, when creating a new PTE, the map_setup_2mbpages() function is simply OR-ing the page address with the page flags, failing to set the USER flag and thereby preventing any pages referenced by this directory entry from being mapped for user space access; this may cause bogus segmentation fault signals to be delivered to the user process (https://github.com/nanovms/nanos/issues/1999#issuecomment-2072735021).
This change fixes the above issues by amending map_setup_2mbpages() so that it takes a physical memory region from which to allocate any new pages it may need, and calls new_level_pte() when creating a new PTE.