paging_on_demand_and_memory_protection_demo(): store uspace map in process
#include <sys/thread.h>
#include <sys/ktest.h>
#include <sys/sched.h>
+#include <sys/proc.h>
#ifdef __mips__
#define TOO_MUCH 0x40000000
#endif
static int paging_on_demand_and_memory_protection_demo(void) {
- /* This test mustn't be preempted since PCPU's user-space vm_map will not be
- * restored while switching back. */
SCOPED_NO_PREEMPTION();
+ proc_t *p = proc_self();
vm_map_t *orig = vm_map_user();
- vm_map_activate(vm_map_new());
+ /* XXX: We can't guarantee that we won't switch to another process,
+ * so we need to store the temporary userspace map in our process.
+ * This is fine as long as there are no concurrent threads in our
+ * process that use p_uspace or read/write any userspace addresses. */
+ p->p_uspace = vm_map_new();
+ vm_map_activate(p->p_uspace);
vm_map_t *kmap = vm_map_kernel();
vm_map_t *umap = vm_map_user();
@@ -81,6 +86,7 @@ static int paging_on_demand_and_memory_protection_demo(void) {
vm_map_delete(umap);
/* Restore original vm_map */
+ p->p_uspace = orig;
vm_map_activate(orig);
return KTEST_SUCCESS;
