Ejemplo n.º 1
0
 def _close_device(self):
     if hasattr(self, "bar2"):
         try: c.munmap(self.bar2, 64 * 1024)
         except: pass
     if hasattr(self, "barfd2"):
         try: os.close(self.barfd2)
         except: pass
     c.munmap(self.bar0, 64 * 1024)
     os.close(self.barfd)
     os.close(self.cfgfd)
Ejemplo n.º 2
0
 def _close_device(self):
     if hasattr(self, "bar2"):
         try: c.munmap(self.bar2, 64 * 1024)
         except: pass
     if hasattr(self, "barfd2"):
         try: os.close(self.barfd2)
         except: pass
     c.munmap(self.bar0, 64 * 1024)
     os.close(self.barfd)
     os.close(self.cfgfd)
Ejemplo n.º 3
0
 def __attempt_hugetlb(self):
     flags = c.MAP_ANONYMOUS | c.MAP_PRIVATE | c.MAP_LOCKED | c.MAP_HUGETLB
     flags |= (21 << c.MAP_HUGE_SHIFT)
     prot = c.PROT_READ | c.PROT_WRITE
     sz = 2048 * 1024
     a = c.mmap(0, sz, prot, flags, -1, 0)
     if a != c.MAP_FAILED:
         print "[+] huge pages available"
         c.munmap(a, sz)
         self._hugetlb_available = True
         self._hugetlb_pgsz = sz
     else:
         print "[-] huge pages unavailable"
         self._hugetlb_available = False
Ejemplo n.º 4
0
 def __attempt_hugetlb(self):
     try:
         with open("/proc/sys/vm/nr_hugepages", "r+") as hp:
             a = int(hp.read())
             if a < 20:
                 hp.seek(0)
                 hp.write('20')
     except: pass
     flags = c.MAP_ANONYMOUS | c.MAP_PRIVATE | c.MAP_LOCKED | c.MAP_HUGETLB | c.MAP_32BIT
     flags |= (21 << c.MAP_HUGE_SHIFT)
     prot = c.PROT_READ | c.PROT_WRITE
     sz = 2048 * 1024
     a = c.mmap(0, sz, prot, flags, -1, 0)
     if a != c.MAP_FAILED:
         print "[+] huge pages available"
         c.munmap(a, sz)
         self._hugetlb_available = True
         self._hugetlb_pgsz = sz
     else:
         print "[-] huge pages unavailable"
         self._hugetlb_available = False
Ejemplo n.º 5
0
 def __attempt_hugetlb(self):
     try:
         with open("/proc/sys/vm/nr_hugepages", "r+") as hp:
             a = int(hp.read())
             if a < 20:
                 hp.seek(0)
                 hp.write('20')
     except:
         pass
     flags = c.MAP_ANONYMOUS | c.MAP_PRIVATE | c.MAP_LOCKED | c.MAP_HUGETLB | c.MAP_32BIT
     flags |= (21 << c.MAP_HUGE_SHIFT)
     prot = c.PROT_READ | c.PROT_WRITE
     sz = 2048 * 1024
     a = c.mmap(0, sz, prot, flags, -1, 0)
     if a != c.MAP_FAILED:
         print "[+] huge pages available"
         c.munmap(a, sz)
         self._hugetlb_available = True
         self._hugetlb_pgsz = sz
     else:
         print "[-] huge pages unavailable"
         self._hugetlb_available = False
Ejemplo n.º 6
0
 def _dev_close(self):
     c.munmap(self.bar0, self.bar0_sz)
     os.close(self.device)
     ioctl(self.group, c.VFIO_GROUP_UNSET_CONTAINER, struct.pack("I", self.container))
     os.close(self.group)