]> rtime.felk.cvut.cz Git - l4.git/blobdiff - kernel/fiasco/src/kern/ux/mem_space-ux.cpp
Update
[l4.git] / kernel / fiasco / src / kern / ux / mem_space-ux.cpp
index 55d34bfbae7db930102b34835b3664b3724b3b34..7d92780628fe8cc9d76f663a43fed26f6856d30e 100644 (file)
@@ -19,7 +19,7 @@ thread_page_fault(Address, Mword, Address, Mword, Return_frame *);
 EXTENSION class Mem_space
 {
 protected:
-  void sync_kernel() const {}
+  int sync_kernel() const { return 0; }
 
   pid_t _pid;
 };
@@ -70,7 +70,7 @@ Mem_space::set_pid(pid_t pid)
 
 IMPLEMENT inline NEEDS["logdefs.h"]
 void
-Mem_space::switchin_context(Mem_space *from)
+Mem_space::switchin_context(Mem_space *from, unsigned)
 {
   if (this == from)
     return;
@@ -83,15 +83,15 @@ IMPLEMENT inline NEEDS [<asm/unistd.h>, <sys/mman.h>, "boot_info.h",
                         "cpu_lock.h", "lock_guard.h", "mem_layout.h",
                         "trampoline.h"]
 void
-Mem_space::page_map(Address phys, Address virt, Address size, unsigned attr)
+Mem_space::page_map(Address phys, Address virt, Address size, Attr attr)
 {
-  Lock_guard<Cpu_lock> guard(&cpu_lock);
+  auto guard = lock_guard(cpu_lock);
 
   Mword *trampoline = (Mword *)Mem_layout::kernel_trampoline_page;
 
   *(trampoline + 1) = virt;
   *(trampoline + 2) = size;
-  *(trampoline + 3) = PROT_READ | (attr & Page_writable ? PROT_WRITE : 0);
+  *(trampoline + 3) = PROT_READ | (attr.rights & Page::Rights::W() ? PROT_WRITE : 0);
   *(trampoline + 4) = MAP_SHARED | MAP_FIXED;
   *(trampoline + 5) = Boot_info::fd();
 
@@ -111,7 +111,7 @@ IMPLEMENT inline NEEDS [<asm/unistd.h>, "cpu_lock.h", "lock_guard.h",
 void
 Mem_space::page_unmap(Address virt, Address size)
 {
-  Lock_guard<Cpu_lock> guard(&cpu_lock);
+  auto guard = lock_guard(cpu_lock);
 
   Trampoline::syscall(pid(), __NR_munmap, virt, size);
 }
@@ -121,7 +121,7 @@ IMPLEMENT inline NEEDS [<asm/unistd.h>, "cpu_lock.h", "lock_guard.h",
 void
 Mem_space::page_protect(Address virt, Address size, unsigned attr)
 {
-  Lock_guard<Cpu_lock> guard(&cpu_lock);
+  auto guard = lock_guard(cpu_lock);
 
   Trampoline::syscall(pid(), __NR_mprotect, virt, size,
                       PROT_READ | (attr & Page_writable ? PROT_WRITE : 0));
@@ -141,9 +141,10 @@ T *
 Mem_space::user_to_kernel(T const *addr, bool write)
 {
   Phys_addr phys;
-  Addr virt = Addr::create((Address) addr);
-  unsigned attr, error = 0;
-  Size size;
+  Virt_addr virt = Virt_addr((Address) addr);
+  Attr attr;
+  unsigned error = 0;
+  Page_order size;
 
   for (;;)
     {
@@ -151,12 +152,12 @@ Mem_space::user_to_kernel(T const *addr, bool write)
       if (v_lookup(virt, &phys, &size, &attr))
         {
           // Add offset to frame
-          phys = phys | virt.offset(size);
+          phys = phys | cxx::get_lsb(virt, size);
 
           // See if we want to write and are not allowed to
           // Generic check because INTEL_PTE_WRITE == INTEL_PDE_WRITE
-          if (!write || (attr & Pt_entry::Writable))
-            return (T*)Mem_layout::phys_to_pmem(phys.value());
+          if (!write || (attr.rights & Page::Rights::W()))
+            return (T*)Mem_layout::phys_to_pmem(Phys_addr::val(phys));
 
           error |= PF_ERR_PRESENT;
         }
@@ -174,7 +175,7 @@ Mem_space::user_to_kernel(T const *addr, bool write)
       // Pretend open interrupts, we restore the current state afterwards.
       Cpu_lock::Status was_locked = cpu_lock.test();
 
-      thread_page_fault(virt.value(), error, 0, Proc::processor_state() | EFLAGS_IF, 0);
+      thread_page_fault(Virt_addr::val(virt), error, 0, Proc::processor_state() | EFLAGS_IF, 0);
 
       cpu_lock.set (was_locked);
     }
@@ -191,7 +192,7 @@ Mem_space::peek_user(T const *addr)
   if (((Address)addr                   & Config::PAGE_MASK) ==
      (((Address)addr + sizeof (T) - 1) & Config::PAGE_MASK))
     {
-      Lock_guard<Cpu_lock> guard(&cpu_lock);
+      auto guard = lock_guard(cpu_lock);
       value = *user_to_kernel(addr, false);
     }
   else
@@ -209,7 +210,7 @@ Mem_space::poke_user(T *addr, T value)
   if (((Address)addr                   & Config::PAGE_MASK) ==
      (((Address)addr + sizeof (T) - 1) & Config::PAGE_MASK))
     {
-      Lock_guard<Cpu_lock> guard(&cpu_lock);
+      auto guard = lock_guard(cpu_lock);
       *user_to_kernel(addr, true) = value;
     }
   else
@@ -221,7 +222,7 @@ template< typename T >
 void
 Mem_space::copy_from_user(T *kdst, T const *usrc, size_t n)
 {
-  Lock_guard<Cpu_lock> guard(&cpu_lock);
+  auto guard = lock_guard(cpu_lock);
 
   char *ptr = (char *)usrc;
   char *dst = (char *)kdst;
@@ -244,7 +245,7 @@ template< typename T >
 void
 Mem_space::copy_to_user(T *udst, T const *ksrc, size_t n)
 {
-  Lock_guard<Cpu_lock> guard(&cpu_lock);
+  auto guard = lock_guard(cpu_lock);
 
   char *ptr = (char *)udst;
   char *src = (char *)ksrc;