+ if (pte != NULL && *pte != 0)
+ {
+ *pte = 0;
+
+ if (active_pd () == pd)
+ {
+ /* We cleared a page-table entry in the active page
+ table, so we have to invalidate the TLB. See
+ [IA32-v3], section 3.11. */
+ pagedir_activate (pd);
+ }
+ }
+
+}
+
+/* Returns true if the PTE for user virtual page UPAGE in PD is
+ dirty, that is, if the page has been modified since the PTE
+ was installed.
+ Returns false if PD contains no PDE for UPAGE. */
+bool
+pagedir_test_dirty (uint32_t *pd, const void *upage)
+{
+ uint32_t *pte = lookup_page (pd, (void *) upage, false);
+ return pte != NULL && (*pte & PG_D) != 0;
+}
+
+/* Returns true if the PTE for user virtual page UPAGE in PD has
+ been accessed recently, that is, between the time the PTE was
+ installed and the last time it was cleared.
+ Returns false if PD contains no PDE for UPAGE. */
+bool
+pagedir_test_accessed (uint32_t *pd, const void *upage)
+{
+ uint32_t *pte = lookup_page (pd, (void *) upage, false);
+ return pte != NULL && (*pte & PG_A) != 0;
+}
+
+/* Resets the accessed bit in the PTE for user virtual page UPAGE
+ in PD. */
+void
+pagedir_clear_accessed (uint32_t *pd, const void *upage)
+{
+ uint32_t *pte = lookup_page (pd, (void *) upage, false);
+ if (pte != NULL)
+ *pte &= ~(uint32_t) PG_A;