From 8030557cd10b7f7ab6f2aac7140c50d9d09aa916 Mon Sep 17 00:00:00 2001 From: tobiasu Date: Wed, 5 Aug 2015 22:49:59 +0000 Subject: [PATCH] Use arc4random instead of x86/powerpc specific cpu time counters as a random seed. Unbreaks all non-x86 architectures. ok daniel@, post-ports-lock ok from sthen@ --- devel/csmith/Makefile | 4 +- devel/csmith/patches/patch-src_platform_cpp | 58 +++++++++++++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/devel/csmith/Makefile b/devel/csmith/Makefile index f5e2da949033..309bbd73b287 100644 --- a/devel/csmith/Makefile +++ b/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 diff --git a/devel/csmith/patches/patch-src_platform_cpp b/devel/csmith/patches/patch-src_platform_cpp index 21155493bf97..d07be92f607d 100644 --- a/devel/csmith/patches/patch-src_platform_cpp +++ b/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 -#include ++#include #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 /////////////////