Skip to content

Commit

Permalink
Use arc4random instead of x86/powerpc specific cpu time counters as a
Browse files Browse the repository at this point in the history
random seed.
Unbreaks all non-x86 architectures.

ok daniel@, post-ports-lock ok from sthen@
  • Loading branch information
tobiasu committed Aug 5, 2015
1 parent 4370182 commit 8030557
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
4 changes: 3 additions & 1 deletion devel/csmith/Makefile
@@ -1,8 +1,10 @@
# $OpenBSD: Makefile,v 1.1.1.1 2015/05/01 00:38:29 daniel Exp $
# $OpenBSD: Makefile,v 1.2 2015/08/05 22:49:59 tobiasu Exp $

COMMENT= fuzzer for C compilers

DISTNAME= csmith-2.2.0
REVISION= 0

CATEGORIES= devel

MAINTAINER= Daniel Dickman <daniel@openbsd.org>
Expand Down
58 changes: 53 additions & 5 deletions devel/csmith/patches/patch-src_platform_cpp
@@ -1,14 +1,62 @@
$OpenBSD: patch-src_platform_cpp,v 1.1.1.1 2015/05/01 00:38:29 daniel Exp $
$OpenBSD: patch-src_platform_cpp,v 1.2 2015/08/05 22:49:59 tobiasu Exp $

No sys/timeb.h on OpenBSD.
- No sys/timeb.h on OpenBSD
- Generate a seed more portably.

--- src/platform.cpp.orig Thu Jan 15 19:36:30 2015
+++ src/platform.cpp Thu Jan 15 19:36:38 2015
@@ -40,7 +40,6 @@
--- src/platform.cpp.orig Wed Dec 31 16:46:24 2014
+++ src/platform.cpp Fri Jul 31 22:24:40 2015
@@ -40,50 +40,15 @@
// Platform-Specific code to get a unique seed value (usually from the tick counter, etc)
//
#include <sys/types.h>
-#include <sys/timeb.h>
+#include <stdlib.h>

#include "platform.h"

-#if (TARGET_CPU_powerpc == 1 || TARGET_CPU_powerpc64 == 1)
-/*For PPC, got from:
-http://lists.ozlabs.org/pipermail/linuxppc-dev/1999-October/003889.html
-*/
-static unsigned long long read_time(void) {
- unsigned long long retval;
- unsigned long junk;
- __asm__ __volatile__ ("\n\
-1: mftbu %1\n\
- mftb %L0\n\
- mftbu %0\n\
- cmpw %0,%1\n\
- bne 1b"
- : "=r" (retval), "=r" (junk));
- return retval;
-}
-#else
-#ifdef WIN32
-static unsigned __int64 read_time(void) {
- unsigned l, h;
- _asm {rdtsc
- mov l, eax
- mov h, edx
- }
- return (h << 32) + l ;
-}
-#else
-static long long read_time(void) {
- long long l;
- asm volatile( "rdtsc\n\t"
- : "=A" (l)
- );
- return l;
-}
-#endif
-#endif
-
unsigned long platform_gen_seed()
{
- return (long) read_time();
+ unsigned long seed;
+ arc4random_buf(&seed, sizeof(unsigned long));
+ return seed;
}

//////////// platform specific mkdir /////////////////

0 comments on commit 8030557

Please sign in to comment.