This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ANNOUNCEMENT] New package: rng-tools-5-1


On 2014-08-09 16:37, Corinna Vinschen wrote:
> I just uploaded rng-tools-5-1.
> 
> The Cygwin release only comes with the rngtest tool for now.
> 
> The rngd daemon requires porting assembler code to COFF and the
> Microsoft calling convention.  Any help porting this code would
> be greatly appreciated.

Ok, I took a stab at it. The problems I identified in the assembly
are ELF debug info, different register use for the x86-64 calls and
a missing underscore prefix for the i686 symbols.

I'm unsure if used registers (and which) have to be saved in the
MS x86-64 ABI, but that shouldn't be too hard to fix if that's the
case.

I also moved up the AC_SEARCH_LIBS hunk in configure.ac since
the existing AC_CHECK_LIB is buried inside some other construct
(AC_CHECK_HEADER is possibly the culprit) which causes this:

checking for library containing argp_parse... /usr/src/rng-tools-5-1.src/rng-tools-5-1.i686/src/rng-tools-5/configure: line 4335: ac_fn_c_try_link: command not found
/usr/src/rng-tools-5-1.src/rng-tools-5-1.i686/src/rng-tools-5/configure: line 4335: ac_fn_c_try_link: command not found
no

Anyway, with the attached patch instead of the one included in the
src package, it builds for both arches, but my cpu appears to lack
the rdrand instruction, so I have a hard time taking this any
further.   Bummer.

Cheers,
Peter

diff -rup origsrc/rng-tools-5/configure.ac src/rng-tools-5/configure.ac
--- origsrc/rng-tools-5/configure.ac	2014-08-12 10:33:32.064585400 +0200
+++ src/rng-tools-5/configure.ac	2014-08-12 11:18:44.431782000 +0200
@@ -56,6 +56,8 @@ dnl ------------------------------------
 dnl Checks for optional library functions
 dnl -------------------------------------
 
+AC_SEARCH_LIBS([argp_parse],[argp])
+
 dnl -------------------------------------
 dnl Check for libgcrypt support
 dnl -------------------------------------
diff -rup origsrc/rng-tools-5/rdrand_asm.S src/rng-tools-5/rdrand_asm.S
--- origsrc/rng-tools-5/rdrand_asm.S	2014-08-12 10:33:32.066585400 +0200
+++ src/rng-tools-5/rdrand_asm.S	2014-08-12 11:26:27.429381800 +0200
@@ -20,20 +20,41 @@
 
 #if defined(__i386__) || defined(__x86_64__)
 
-#define ENTRY(x)	  \
-	.balign	64	; \
-	.globl	x	; \
-x:
+#if defined __CYGWIN__
+# if defined __x86_64__
+#  define MS_x86_64_ABI
+# else
+#  define SYMBOL(name) _ ## name
+# endif
+#else
+# define ELF_DEBUG_INFO
+#endif
+#if !defined SYMBOL
+# define SYMBOL(name) name
+#endif
+
+#define ENTRY(x)		  \
+	.balign	64		; \
+	.globl	SYMBOL(x)	; \
+SYMBOL(x):
 
+#if defined ELF_DEBUG_INFO
 #define ENDPROC(x)		  \
 	.size	x, .-x		; \
 	.type	x, @function
+#else
+#define ENDPROC(x)
+#endif
 
 #define RDRAND_RETRY_LIMIT	10
 
 #ifdef __x86_64__
 
 ENTRY(x86_rdrand_bytes)
+#if defined MS_x86_64_ABI
+	mov	%rcx, %rdi
+	mov	%rdx, %rsi
+#endif
 	mov	%esi, %eax
 1:
 	mov	$RDRAND_RETRY_LIMIT, %ecx
@@ -55,6 +76,12 @@
 ENDPROC(x86_rdrand_bytes)
 
 ENTRY(x86_rdseed_or_rdrand_bytes)
+#if defined MS_x86_64_ABI
+	mov	%rcx, %rdi
+	mov	%rdx, %rsi
+	mov	%r8, %rdx
+	mov	%r9, %rcx
+#endif
 	mov	(%rsi), %r8d		/* RDSEED count */
 	mov	(%rcx), %r9d		/* RDRAND count */
 1:
@@ -191,6 +218,10 @@
 	movl	12(%ebp), %edx
 	push	%esi
 #endif
+#if defined MS_x86_64_ABI
+	mov	%rcx, %rdi
+	mov	%rdx, %rsi
+#endif
 	movl	$512, CTR3	/* Number of rounds */
 	
 	movdqa	(0*16)(PTR1), %xmm0
@@ -295,6 +326,9 @@
 	mov	%esp, %ebp
 	movl	8(%ebp), %eax
 #endif
+#if defined MS_x86_64_ABI
+	mov	%rcx, %rdi
+#endif
 
 	SETPTR(aes_round_keys, PTR1)
 	movdqu	(PTR0), %xmm0
@@ -347,12 +381,16 @@
 	.balign 64
 aes_round_keys:
 	.space	11*16
+#if defined ELF_DEBUG_INFO
 	.size	aes_round_keys, .-aes_round_keys
+#endif /* ELF_DEBUG_INFO */
 
 #endif /* i386 or x86_64 */
 
+#if defined ELF_DEBUG_INFO
 /*
  * This is necessary to keep the whole executable
  * from needing a writable stack.
  */
                 .section        .note.GNU-stack,"",%progbits
+#endif /* ELF_DEBUG_INFO */
diff -rup origsrc/rng-tools-5/rngd_linux.c src/rng-tools-5/rngd_linux.c
--- origsrc/rng-tools-5/rngd_linux.c	2012-08-06 19:04:12.000000000 +0200
+++ src/rng-tools-5/rngd_linux.c	2014-08-09 15:09:21.081616358 +0200
@@ -39,8 +39,10 @@
 #include <fcntl.h>
 #include <sys/time.h>
 #include <time.h>
+#ifndef __CYGWIN__
 #include <linux/types.h>
 #include <linux/random.h>
+#endif
 #include <string.h>
 
 #include "rngd.h"
@@ -130,11 +132,19 @@ void random_add_entropy(void *buf, size_
 	entropy.size = size;
 	memcpy(entropy.data, buf, size);
 
+#ifdef __CYGWIN__
+	if (write(random_fd, entropy.data, size) != size) {
+		message(LOG_DAEMON|LOG_ERR, "Add Entropy failed: %s\n",
+			strerror(errno));
+		exit(1);
+	}
+#else
 	if (ioctl(random_fd, RNDADDENTROPY, &entropy) != 0) {
 		message(LOG_DAEMON|LOG_ERR, "RNDADDENTROPY failed: %s\n",
 			strerror(errno));
 		exit(1);
 	}
+#endif
 }
 
 void random_sleep(void)

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]