[x264-devel] Fix crash when using libx264.dll compiled with ICL for X86_64

Anton Mitrofanov git at videolan.org
Wed Jan 9 19:32:21 CET 2013


x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Sun Nov 11 03:44:02 2012 +0400| [a632fe1a57baccdf1bcb340197fe48281cd3117f] | committer: Jason Garrett-Glaser

Fix crash when using libx264.dll compiled with ICL for X86_64

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=a632fe1a57baccdf1bcb340197fe48281cd3117f
---

 common/cpu.h         |    1 +
 common/osdep.c       |   15 ++++++++++++++-
 common/x86/cpu-a.asm |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/common/cpu.h b/common/cpu.h
index c92f93e..ed1a8bc 100644
--- a/common/cpu.h
+++ b/common/cpu.h
@@ -46,6 +46,7 @@ void     x264_cpu_sfence( void );
 #endif
 #define x264_sfence x264_cpu_sfence
 void     x264_cpu_mask_misalign_sse( void );
+void     x264_safe_intel_cpu_indicator_init( void );
 
 /* kluge:
  * gcc can't give variables any greater alignment than the stack frame has.
diff --git a/common/osdep.c b/common/osdep.c
index 0a97bc7..97911d0 100644
--- a/common/osdep.c
+++ b/common/osdep.c
@@ -90,6 +90,7 @@ int x264_threading_init( void )
 }
 #endif
 
+#if HAVE_MMX
 #ifdef __INTEL_COMPILER
 /* Agner's patch to Intel's CPU dispatcher from pages 131-132 of
  * http://agner.org/optimize/optimizing_cpp.pdf (2011-01-30)
@@ -98,7 +99,7 @@ int x264_threading_init( void )
 // Global variable indicating cpu
 int __intel_cpu_indicator = 0;
 // CPU dispatcher function
-void __intel_cpu_indicator_init( void )
+void x264_intel_cpu_indicator_init( void )
 {
     unsigned int cpu = x264_cpu_detect();
     if( cpu&X264_CPU_AVX )
@@ -120,4 +121,16 @@ void __intel_cpu_indicator_init( void )
     else
         __intel_cpu_indicator = 1;
 }
+
+/* __intel_cpu_indicator_init appears to have a non-standard calling convention that
+ * assumes certain registers aren't preserved, so we'll route it through a function
+ * that backs up all the registers. */
+void __intel_cpu_indicator_init( void )
+{
+    x264_safe_intel_cpu_indicator_init();
+}
+#else
+void x264_intel_cpu_indicator_init( void )
+{}
+#endif
 #endif
diff --git a/common/x86/cpu-a.asm b/common/x86/cpu-a.asm
index 0712447..ba4040d 100644
--- a/common/x86/cpu-a.asm
+++ b/common/x86/cpu-a.asm
@@ -139,3 +139,50 @@ cglobal cpu_mask_misalign_sse
     ldmxcsr [rsp]
     add   rsp, 4
     ret
+
+cextern intel_cpu_indicator_init
+
+;-----------------------------------------------------------------------------
+; void safe_intel_cpu_indicator_init( void );
+;-----------------------------------------------------------------------------
+cglobal safe_intel_cpu_indicator_init
+    push r0
+    push r1
+    push r2
+    push r3
+    push r4
+    push r5
+    push r6
+%if ARCH_X86_64
+    push r7
+    push r8
+    push r9
+    push r10
+    push r11
+    push r12
+    push r13
+    push r14
+%endif
+    push rbp
+    mov  rbp, rsp
+    and  rsp, ~15
+    call intel_cpu_indicator_init
+    leave
+%if ARCH_X86_64
+    pop r14
+    pop r13
+    pop r12
+    pop r11
+    pop r10
+    pop r9
+    pop r8
+    pop r7
+%endif
+    pop r6
+    pop r5
+    pop r4
+    pop r3
+    pop r2
+    pop r1
+    pop r0
+    ret



More information about the x264-devel mailing list