delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/08/12/09:29:59

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type; q=dns; s=default; b=ff5Zad
zJBbgL2zxRIt4JaKb9XhPFYjzgUxNJJgPDvnYKD5Xgiuj646Yfm0/pq9pcgan1ph
wnOuOH9qa36vCmblO5zEwbG5A+kPDIGgsGV7v3bl9fFO4kBxRAN+f8CQ/Jf6hoZr
v67HsVfss/tGtb+ZFuYbPbL4u7curnk4bu5fE=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type; s=default; bh=CJKDHJ+ZGQdE
o/wVKCSAZ9DwE4E=; b=M+1v4iW99JYsEWq/VnduIH/REGRzdL0N414O/AvCOT+E
awCxgWBFkrZbCzCQbyeEkBdffjEj+nYNzCP7JkPgbnnFXgHgiJO7kWWFsVeuYz7y
AnvMPbvUDF3qIhJC6IASEwQ3umFXj98+APYq2GWGs6YlrDQTa8eHhkWwBxtfPqI=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=0.7 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS,URIBL_BLACK autolearn=no version=3.3.2
X-HELO: mail.lysator.liu.se
Message-ID: <53EA16B9.5020402@lysator.liu.se>
Date: Tue, 12 Aug 2014 15:29:29 +0200
From: Peter Rosin <peda AT lysator DOT liu DOT se>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: [ANNOUNCEMENT] New package: rng-tools-5-1
References: <announce DOT 20140809143722 DOT GH13601 AT calimero DOT vinschen DOT de>
In-Reply-To: <announce.20140809143722.GH13601@calimero.vinschen.de>

--------------090007000904030509090202
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

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


--------------090007000904030509090202
Content-Type: text/x-patch;
 name="cygwin-rng-tools-5-peda.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="cygwin-rng-tools-5-peda.patch"

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)


--------------090007000904030509090202
Content-Type: text/plain; charset=us-ascii

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019