Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make it compile on 32bits, to please @degomme
[simgrid.git] / tools / stack-cleaner / clean-stack-filter
index 8c5c01c..64e7990 100755 (executable)
@@ -1,9 +1,10 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
 # Transform assembly in order to clean each stack frame for X86_64.
 
 use strict;
-$SIG{__WARN__} = sub { die @_ };
+use warnings;
 
+$SIG{__WARN__} = sub { die @_ };
 
 # Whether we are still scanning the content of a function:
 our $scanproc = 0;
@@ -23,11 +24,20 @@ sub emit_code {
     my $offset = - $size - 8;
 
     if($size != 0) {
+      # This is a crude hack to disable the stack cleaning on the main
+      # stack.  It relies on the fact that the main stack is high in
+      # the address space and the other stacks are in the heap (lower).
+      print("\tmovq \$0x7fff00000000, %r11\n");
+      print("\tcmpq %r11, %rsp\n");
+      print("\tjae .Lstack_cleaner_done$id\n");
+
+      # Loop over the stack frame quadwords and zero it:
       print("\tmovabsq \$$qsize, %r11\n");
       print(".Lstack_cleaner_loop$id:\n");
       print("\tmovq    \$0, $offset(%rsp,%r11,8)\n");
       print("\tsubq    \$1, %r11\n");
       print("\tjne     .Lstack_cleaner_loop$id\n");
+      print(".Lstack_cleaner_done$id:\n");
     }
 
     print $lines;