Victor Stinner avatar Victor Stinner committed a98608a

Support FreeBSD on x86_64

Comments (0)

Files changed (4)

 -------------------
 
  * Fix os_tools.RUNNING_LINUX for Python 2.x compiled on Linux kernel 3.x
+ * Support FreeBSD on x86_64
 
 python-ptrace 0.6.5 (2013-06-06)
 --------------------------------

ptrace/binding/freebsd_struct.py

-from ctypes import Structure, c_int, c_uint, c_ulong, c_void_p
+from ctypes import (Structure,
+    c_int, c_uint, c_ulong, c_void_p,
+    c_uint16, c_uint32, c_size_t)
+from ptrace.cpu_info import CPU_X86_64
 
 PIOD_READ_D = 1
 PIOD_WRITE_D = 2
 PIOD_READ_I = 3
 PIOD_WRITE_I = 4
 
-size_t = c_ulong
-
 # /usr/include/machine/reg.h
-class reg(Structure):
-    _fields_ = (
-        ("fs", c_uint),
-        ("es", c_uint),
-        ("ds", c_uint),
-        ("edi", c_uint),
-        ("esi", c_uint),
-        ("ebp", c_uint),
-        ("isp", c_uint),
-        ("ebx", c_uint),
-        ("edx", c_uint),
-        ("ecx", c_uint),
-        ("eax", c_uint),
-        ("trapno", c_uint),
-        ("err", c_uint),
-        ("eip", c_uint),
-        ("cs", c_uint),
-        ("eflags", c_uint),
-        ("esp", c_uint),
-        ("ss", c_uint),
-        ("gs", c_uint),
-    )
+if CPU_X86_64:
+    register_t = c_ulong
+    class reg(Structure):
+        _fields_ = (
+	    ("r15", register_t),
+	    ("r14", register_t),
+	    ("r13", register_t),
+	    ("r12", register_t),
+	    ("r11", register_t),
+	    ("r10", register_t),
+	    ("r9", register_t),
+	    ("r8", register_t),
+	    ("rdi", register_t),
+	    ("rsi", register_t),
+	    ("rbp", register_t),
+	    ("rbx", register_t),
+	    ("rdx", register_t),
+	    ("rcx", register_t),
+	    ("rax", register_t),
+	    ("trapno", c_uint32),
+	    ("fs", c_uint16),
+	    ("gs", c_uint16),
+	    ("err", c_uint32),
+	    ("es", c_uint16),
+	    ("ds", c_uint16),
+	    ("rip", register_t),
+	    ("cs", register_t),
+	    ("rflags", register_t),
+	    ("rsp", register_t),
+	    ("ss", register_t),
+        )
+else:
+    class reg(Structure):
+        _fields_ = (
+            ("fs", c_uint),
+            ("es", c_uint),
+            ("ds", c_uint),
+            ("edi", c_uint),
+            ("esi", c_uint),
+            ("ebp", c_uint),
+            ("isp", c_uint),
+            ("ebx", c_uint),
+            ("edx", c_uint),
+            ("ecx", c_uint),
+            ("eax", c_uint),
+            ("trapno", c_uint),
+            ("err", c_uint),
+            ("eip", c_uint),
+            ("cs", c_uint),
+            ("eflags", c_uint),
+            ("esp", c_uint),
+            ("ss", c_uint),
+            ("gs", c_uint),
+        )
 
 class ptrace_io_desc(Structure):
     _fields_ = (
         ("piod_op", c_int),
         ("piod_offs", c_void_p),
         ("piod_addr", c_void_p),
-        ("piod_len", size_t),
+        ("piod_len", c_size_t),
     )
 

ptrace/cpu_info.py

     CPU_PPC32 = (_machine == 'ppc')
     CPU_PPC64 = (_machine == 'ppc64')
     CPU_I386 = (_machine in ("i386", "i686"))    # compatible Intel 32 bits
-    CPU_X86_64 = (_machine == "x86_64")  # compatible Intel 64 bits
+    CPU_X86_64 = (_machine in ("x86_64", "amd64"))  # compatible Intel 64 bits
     del _machine
 else:
     # uname() fallback for Windows

ptrace/syscall/ptrace_syscall.py

             else:
                 self.syscall = regs.orig_eax
         else:
-            self.syscall = regs.eax
+            if CPU_X86_64:
+                self.syscall = regs.rax
+            else:
+                self.syscall = regs.eax
 
         # Get syscall variables
         self.name = SYSCALL_NAMES.get(self.syscall, "syscall<%s>" % self.syscall)
 
     def readArgumentValues(self, regs):
+        if CPU_X86_64:
+            return (regs.rdi, regs.rsi, regs.rdx, regs.r10, regs.r8, regs.r9)
         if RUNNING_BSD:
             sp = self.process.getStackPointer()
             return [ self.process.readWord(sp + index*CPU_WORD_SIZE)
                 for index in xrange(1, 6+1) ]
         if CPU_I386:
             return (regs.ebx, regs.ecx, regs.edx, regs.esi, regs.edi, regs.ebp)
-        if CPU_X86_64:
-            return (regs.rdi, regs.rsi, regs.rdx, regs.r10, regs.r8, regs.r9)
         if CPU_POWERPC:
             return (regs.gpr3, regs.gpr4, regs.gpr5, regs.gpr6, regs.gpr7, regs.gpr8)
         raise NotImplementedError()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.