Complete the code to identify the cause of a page fault.
if (error_code & [1]) { // Page fault caused by a write operation }
The error code bit 1 (0x2) indicates if the page fault was caused by a write operation.
Complete the code to check if the page fault was caused by a protection violation on a present page.
if (error_code & [1]) { // Page present: protection fault }
The error code bit 0 (0x1) indicates if the page was present (protection violation).
Fix the error in the code to correctly handle a page fault caused by user mode access.
if (error_code & [1]) { // Fault caused in user mode }
The error code bit 2 (0x4) indicates if the fault happened in user mode.
Fill both blanks to create a dictionary comprehension that maps page numbers to their status if the page is present and accessed in user mode.
page_status = {page_num: status for page_num, status in pages.items() if (status & [1]) and (status & [2])}Bit 0 (0x1) checks if the page is present, and bit 2 (0x4) checks if it was accessed in user mode.
Fill all three blanks to create a dictionary comprehension that maps virtual addresses to page numbers for pages that are present, writable, and accessed in user mode.
virtual_to_page = {va: pa for va, (pa, flags) in memory_map.items() if (flags & [1]) and (flags & [2]) and (flags & [3])}Bit 0 (0x1) means page present, bit 1 (0x2) means writable, and bit 2 (0x4) means accessed in user mode.