public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Peter Rosin <peda@lysator.liu.se>
To: cygwin@cygwin.com
Subject: Re: [ANNOUNCEMENT] New package: rng-tools-5-1
Date: Tue, 12 Aug 2014 13:29:00 -0000	[thread overview]
Message-ID: <53EA16B9.5020402@lysator.liu.se> (raw)
In-Reply-To: <announce.20140809143722.GH13601@calimero.vinschen.de>

[-- Attachment #1: Type: text/plain, Size: 1340 bytes --]

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


[-- Attachment #2: cygwin-rng-tools-5-peda.patch --]
[-- Type: text/x-patch, Size: 3464 bytes --]

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)


[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

--
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

  reply	other threads:[~2014-08-12 13:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-09 14:50 Corinna Vinschen
2014-08-12 13:29 ` Peter Rosin [this message]
2014-08-12 14:11   ` Corinna Vinschen
2014-08-12 14:26     ` Corinna Vinschen
2014-08-13  8:55     ` Peter Rosin
2014-08-13  9:43       ` Corinna Vinschen
2014-08-14 10:09         ` Peter Rosin
2014-08-14 11:25           ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53EA16B9.5020402@lysator.liu.se \
    --to=peda@lysator.liu.se \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).