scrypt-jane icon indicating copy to clipboard operation
scrypt-jane copied to clipboard

Add Cygwin support

Open llamasoft opened this issue 8 years ago • 0 comments

To the preprocessor, Cygwin looks like OS_NIX which is mostly true. Cygwin is meant to look and feel like Unix but Cygwin applications run on Windows and require Windows-like naked assembly definitions. Otherwise, the application will segfault in ChunkMix.

Example:

$ gcc -O3 -ggdb -DSCRYPT_SALSA -DSCRYPT_SHA256 scrypt-jane-test.c -o scrypt-test

$ gdb ./scrypt-test

(gdb) set disassembly-flavor intel

(gdb) run
Starting program: scrypt-test
[New Thread 10828.0x2f08]
[New Thread 10828.0x2c0c]
[New Thread 10828.0x1824]
[New Thread 10828.0x2b20]

Program received signal SIGSEGV, Segmentation fault.
0x000000010040143c in scrypt_ChunkMix_sse2 ()

(gdb) backtrace
#0  0x000000010040143c in scrypt_ChunkMix_sse2 ()
#1  0x0000000100402790 in scrypt_test_mix_instance (mixfn=0x100401420 <scrypt_ChunkMix_sse2>,
    prefn=prefn@entry=0x100401b40 <salsa_core_tangle_sse2>, postfn=postfn@entry=0x100401b40 <salsa_core_tangle_sse2>,
    expected=0x1004070f0 <expected> "snipped")
    at code/scrypt-jane-romix-basic.h:53
#2  0x0000000100404576 in scrypt_test_mix () at code/scrypt-jane-salsa.h:126
#3  scrypt_power_on_self_test () at scrypt-jane.c:52
#4  0x000000010040558f in main () at scrypt-jane-test.c:5

(gdb) disassemble 0x000000010040143c
Dump of assembler code for function scrypt_ChunkMix_sse2:
   0x0000000100401420 <+0>:     lea    rcx,[ecx*2+0x0]
   0x0000000100401429 <+9>:     shl    rcx,0x6
   0x000000010040142d <+13>:    lea    r9,[rcx-0x40]
   0x0000000100401431 <+17>:    lea    rax,[rsi+r9*1]
   0x0000000100401435 <+21>:    lea    r9,[rdx+r9*1]
   0x0000000100401439 <+25>:    and    rdx,rdx
=> 0x000000010040143c <+28>:    movdqa xmm0,XMMWORD PTR [rax]
   0x0000000100401440 <+32>:    movdqa xmm1,XMMWORD PTR [rax+0x10]
   0x0000000100401445 <+37>:    movdqa xmm2,XMMWORD PTR [rax+0x20]
   0x000000010040144a <+42>:    movdqa xmm3,XMMWORD PTR [rax+0x30]
   0x000000010040144f <+47>:    je     0x100401468 <scrypt_ChunkMix_sse2_no_xor1>
   0x0000000100401451 <+49>:    pxor   xmm0,XMMWORD PTR [r9]
   0x0000000100401456 <+54>:    pxor   xmm1,XMMWORD PTR [r9+0x10]
   0x000000010040145c <+60>:    pxor   xmm2,XMMWORD PTR [r9+0x20]
   0x0000000100401462 <+66>:    pxor   xmm3,XMMWORD PTR [r9+0x30]
End of assembler dump.

Lumping Cygwin in with OS_WINDOWS would be incorrect, so instead I've added an extra check when defining asm_naked_fn to treat Cygwin as OS_WINDOWS for only that one block. This causes all tests to compile and run successfully.

P.S. My editor stripped trailing whitespace which added a few extra lines to the commit. Sorry about that.

llamasoft avatar Nov 14 '16 16:11 llamasoft