Bug 17032 - No rand_s on Windows 2000 -> crash
Summary: No rand_s on Windows 2000 -> crash
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Windows 2000
: P4 Minor
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-27 12:04 PST by eu4bbt12phas4ek
Modified: 2012-09-06 17:30 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description eu4bbt12phas4ek 2008-01-27 12:04:02 PST
There is no rand_s on Windows 2000.
Safari crashes with first html request.

Related files:
http://trac.webkit.org/projects/webkit/browser/trunk/JavaScriptCore/kjs/config.h
http://trac.webkit.org/projects/webkit/browser/trunk/JavaScriptCore/wtf/MathExtras.h
Comment 2 Mark Rowe (bdash) 2008-01-27 18:02:29 PST
http://www.apple.com/safari/download/ states that Safari is only supported on Windows XP and Vista.  Windows XP has been the minimum officially supported version since the initial beta release.
Comment 3 Adam Roben (:aroben) 2008-01-28 08:50:04 PST
(In reply to comment #2)
> http://www.apple.com/safari/download/ states that Safari is only supported on
> Windows XP and Vista.  Windows XP has been the minimum officially supported
> version since the initial beta release.

That's not to say this bug can't be fixed, though! We'll gladly accept a patch to fix this that doesn't regress other platforms.
Comment 4 eu4bbt12phas4ek 2008-02-04 13:05:30 PST
(In reply to comment #3)
> That's not to say this bug can't be fixed, though! We'll gladly accept a patch
> to fix this that doesn't regress other platforms.

I've found the bug through Qt's webkit integration, and I assume they wanna
support win2k. 

The solution is to not use rand_s on win2k. 
But to have only one binary excludes a macro solution.
It must be checked for rand_s at runtime:

somewhere in a cpp file:

#include <windows.h>

bool checkFor_rand_s()
{
	HMODULE dll = LoadLibrary("ADVAPI32.DLL");
	if (dll && GetProcAddress(dll, "RtlGenRandom") ) {
		FreeLibrary(dll);
		return true;
	}
	FreeLibrary(dll);
	return false;
}


And a dynamic switch in wtf_random_init/wtf_random,

static bool do_check = true;		
static bool rand_s_exists = false;
if (do_check) {
    rand_s_exists = checkFor_rand_s();
}
if (rand_s_exists) {
....
}


The only problem I see is that it is ugly and that it eventually
breaks the inlining of the rand functions.

Comment 5 eu4bbt12phas4ek 2008-02-04 13:08:37 PST
correction:

if (do_check) {
    do_check = false;
    rand_s_exists = checkFor_rand_s();
}
Comment 6 Simon Hausmann 2008-04-07 03:47:36 PDT
A more complete patch can also be found at

http://lists.trolltech.com/qt4-preview-feedback/2008-04/thread00028-0.html
Comment 7 Alexey Proskuryakov 2008-07-15 15:10:22 PDT
(In reply to comment #6)
> http://lists.trolltech.com/qt4-preview-feedback/2008-04/thread00028-0.html

+void check_for_rand_s()
+{
+    if (!already_checked) {

There is no need for this check - check_for_rand_s() is called from wtf_random_init(), which is guaranteed to be called once.
Comment 8 Nils Jeisecke 2010-09-06 06:15:25 PDT
Nobody interested in Windows 2000 any more?

The code seems to have been moved to JavaScriptCore/wtf/RandomNumber.cpp but the idea of the patch should still solve the problem.
Comment 9 Gavin Barraclough 2012-09-06 17:30:26 PDT
We don't appear to call rand_s any more.