[pypy-svn] r37665 - pypy/dist/pypy/jit/codegen/i386

arigo at codespeak.net arigo at codespeak.net
Wed Jan 31 13:06:10 CET 2007


Author: arigo
Date: Wed Jan 31 13:06:08 2007
New Revision: 37665

Modified:
   pypy/dist/pypy/jit/codegen/i386/regalloc.py
   pypy/dist/pypy/jit/codegen/i386/rgenop.py
Log:
Stack randomizing code, idea (c) mwh.


Modified: pypy/dist/pypy/jit/codegen/i386/regalloc.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/regalloc.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/regalloc.py	Wed Jan 31 13:06:08 2007
@@ -6,6 +6,8 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.jit.codegen.i386.operation import *
 
+DEBUG_STACK = False
+
 
 class StackOpCache:
     INITIAL_STACK_EBP_OFS = -4
@@ -236,8 +238,21 @@
             if self.operands[loc] != srcoperand:
                 self.mc.POP(self.operands[loc])
 
+    def randomize_stack(self):
+        import random
+        last_n = self.required_frame_depth - 1
+        for i in range(last_n+1, last_n+50):
+            self.mc.MOV(ecx, stack_op(i))
+            self.mc.LEA(ecx, mem(ecx, random.randrange(-sys.maxint,
+                                                       sys.maxint)))
+            self.mc.MOV(stack_op(i), ecx)
+        self.mc.LEA(ecx, mem(ecx, random.randrange(-sys.maxint,
+                                                   sys.maxint)))
+
     def generate_operations(self):
         for v in self.operations:
+            if DEBUG_STACK:
+                self.randomize_stack()
             v.generate(self)
             cc = v.cc_result
             if cc >= 0 and v in self.var2loc:
@@ -252,6 +267,8 @@
                 except FailedToImplement:
                     mc.MOVZX(ecx, cl)
                     mc.MOV(dstop, ecx)
+        if DEBUG_STACK:
+            self.randomize_stack()
 
     def force_stack_storage(self, lst):
         # this is called at the very beginning, so the 'loc' numbers

Modified: pypy/dist/pypy/jit/codegen/i386/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/rgenop.py	Wed Jan 31 13:06:08 2007
@@ -7,6 +7,7 @@
 from pypy.jit.codegen.i386.codebuf import CodeBlockOverflow
 from pypy.jit.codegen.i386.operation import *
 from pypy.jit.codegen.i386.regalloc import RegAllocator, StorageInStack, Place
+from pypy.jit.codegen.i386.regalloc import DEBUG_STACK
 from pypy.jit.codegen import conftest
 from pypy.rpython.annlowlevel import llhelper
 
@@ -525,7 +526,9 @@
     from pypy.jit.codegen.i386.codebuf import InMemoryCodeBuilder
 
     MC_SIZE = 65536
-    
+    if DEBUG_STACK:
+        MC_SIZE *= 16
+
     def __init__(self):
         self.mcs = []   # machine code blocks where no-one is currently writing
         self.keepalive_gc_refs = [] 



More information about the Pypy-commit mailing list