~ chicken-core (chicken-5) 57b0827f4f5d81788e8de5bf3157403cadb91838
commit 57b0827f4f5d81788e8de5bf3157403cadb91838 Author: felix <felix.winkelmann@bevuta.com> AuthorDate: Wed Nov 8 15:27:04 2017 +0100 Commit: felix <felix.winkelmann@bevuta.com> CommitDate: Wed Nov 8 15:27:04 2017 +0100 obtain ptr to RtlGenRandom dynamically by loading adavpi32.dll (thanks to TheLemonMan); drop use of random in posixwin.scm diff --git a/Makefile.mingw b/Makefile.mingw index c6059a85..a1cd9266 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -59,7 +59,7 @@ LINKER_LINK_SHARED_LIBRARY_OPTIONS = -shared LIBRARIES = -lm -lws2_32 LINKER_OPTIONS += -Wl,--enable-auto-import LIBCHICKEN_SO_LINKER_OPTIONS = -Wl,--out-implib,lib$(PROGRAM_PREFIX)chicken$(PROGRAM_SUFFIX).dll.a -LIBCHICKEN_SO_LIBRARIES = -lm -lws2_32 +LIBCHICKEN_SO_LIBRARIES = -lm -lws2_32 LIBCHICKEN_IMPORT_LIBRARY = lib$(PROGRAM_PREFIX)chicken$(PROGRAM_SUFFIX).dll.a MAKEDIR_COMMAND_OPTIONS = GENERATE_DEBUGGER = type $< >$@ & echo wish $(DATADIR)\feathers.tcl %1 %2 %3 %4 %5 %6 %7 %8 %9 >>$@ diff --git a/csc.scm b/csc.scm index 7a957302..196aa4d5 100644 --- a/csc.scm +++ b/csc.scm @@ -664,7 +664,7 @@ EOF object-extension) object-files)) (set! link-options - (cons* "-lkernel32" "-luser32" "-lgdi32" "-ladvapi32" "-mwindows" + (cons* "-lkernel32" "-luser32" "-lgdi32" "-mwindows" link-options)))] ((-deployed) (set! deployed #t)) diff --git a/posixwin.scm b/posixwin.scm index fecfc4e4..ac8ffd27 100644 --- a/posixwin.scm +++ b/posixwin.scm @@ -595,8 +595,7 @@ static int set_file_mtime(char *filename, C_word atime, C_word mtime) <# -(import (only chicken.string string-intersperse) - (only chicken.random random)) +(import (only chicken.string string-intersperse)) ;;; Lo-level I/O: @@ -726,7 +725,8 @@ static int set_file_mtime(char *filename, C_word atime, C_word mtime) (let loop ((count 1)) (let suffix-loop ((index (fx- tmpl-len 1))) (when (fx>= index first-x) - (string-set! tmpl index (string-ref diz (random diz-len))) + (string-set! tmpl index + (string-ref diz (##core#inline "C_rand" diz-len))) (suffix-loop (fx- index 1)))) (let ((fd (##core#inline "C_open" (##sys#make-c-string tmpl 'file-open) diff --git a/runtime.c b/runtime.c index eee653f0..053a6b5a 100644 --- a/runtime.c +++ b/runtime.c @@ -12535,14 +12535,6 @@ C_i_pending_interrupt(C_word dummy) # include <sys/systm.h> #endif -#if defined(_WIN32) && !defined(__CYGWIN__) -# define RtlGenRandom SystemFunction036 -# if defined(__cplusplus) -extern "C" -# endif -BOOLEAN WINAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength); -#endif - #if !defined(_WIN32) static C_word random_urandom(C_word buf, int count) @@ -12603,6 +12595,18 @@ C_word C_random_bytes(C_word buf, C_word size) off += r; } #elif defined(_WIN32) && !defined(__CYGWIN__) + typedef BOOLEAN (*func)(PVOID, ULONG); + static func RtlGenRandom = NULL; + + if(RtlGenRandom == NULL) { + HMODULE mod = LoadLibrary("advapi32.dll"); + + if(mod == NULL) return C_SCHEME_FALSE; + + if((RtlGenRandom = (func)GetProcAddress(mod, "SystemFunction036")) == NULL) + return C_SCHEME_FALSE; + } + if(!RtlGenRandom((PVOID)C_data_pointer(buf), (LONG)count)) return C_SCHEME_FALSE; #elseTrap