base/asm-common.h, *.S: Include metadata for 64-bit Windows stack unwinding.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 13 Jul 2016 22:19:03 +0000 (23:19 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 13 Jul 2016 22:19:03 +0000 (23:19 +0100)
There are (annoyingly undocumented) assembler directives, which make
this fairly straightforward.  I've manually verified that they're
setting up the expected data structures correctly.  Under normal
circumstances, we don't expect these leaf functions to throw exceptions.

Note that the `endswap_block' subroutine of `rijndael_setup_x86ish_-
aesni' is not currently properly described.

base/asm-common.h
symm/chacha-x86ish-sse2.S
symm/rijndael-x86ish-aesni.S
symm/salsa20-x86ish-sse2.S

index 0b5f223..0d32ccf 100644 (file)
@@ -100,6 +100,14 @@ name:
 // Set the function hooks.
 #define FUNC_PREHOOK(_) .balign 16
 
+// On Windows, arrange to install stack-unwinding data.
+#if CPUFAM_AMD64 && ABI_WIN
+#  define FUNC_POSTHOOK(name) .seh_proc name
+#  define ENDFUNC_HOOK(_) .seh_endproc
+// Procedures are expected to invoke `.seh_setframe' if necessary, and
+// `.seh_pushreg' and friends, and `.seh_endprologue'.
+#endif
+
 // Don't use the wretched AT&T syntax.  It's festooned with pointless
 // punctuation, and all of the data movement is backwards.  Ugh!
        .intel_syntax noprefix
index 641ad65..4209153 100644 (file)
@@ -110,6 +110,8 @@ FUNC(chacha_core_x86ish_sse2)
 #  define SAVE3 [rsp + 32]
 
        sub     rsp, 48 + 8
+         .seh_stackalloc 48 + 8
+  .seh_endprologue
 #endif
 
        // First job is to slurp the matrix into XMM registers.  Be careful:
index 3dcdfc5..27f09bc 100644 (file)
@@ -165,7 +165,10 @@ FUNC(rijndael_setup_x86ish_aesni)
        // We'll need the index registers, which belong to the caller in this
        // ABI.
        push    rsi
+         .seh_pushreg rsi
        push    rdi
+         .seh_pushreg rdi
+  .seh_endprologue
 
        // Move arguments to more useful places.
        mov     SI, r8                  // key material
@@ -420,6 +423,7 @@ ENDFUNC
 #  define SRC rdx
 #  define DST r8
 #  define NR eax
+  .seh_endprologue
 #endif
 
        // Find the magic endianness-swapping table.
index 47401b7..6da6b24 100644 (file)
@@ -111,8 +111,12 @@ FUNC(salsa20_core_x86ish_sse2)
 #  define SAVE3 [rsp + 48]
 
        sub     rsp, 64 + 8
+         .seh_stackalloc 64 + 8
        movdqa  [rsp +  0], xmm6
+         .seh_savexmm xmm6, 0
        movdqa  [rsp + 16], xmm7
+         .seh_savexmm xmm7, 16
+  .seh_endprologue
 #endif
 
        // First job is to slurp the matrix into XMM registers.  The words