Win32OperatingSystem.st
branchjv
changeset 17754 5322906cdb6a
parent 17751 b2273fa8d59f
child 17757 73caeb68bf1f
--- a/Win32OperatingSystem.st	Thu Feb 25 22:58:21 2010 +0000
+++ b/Win32OperatingSystem.st	Mon Mar 08 21:39:02 2010 +0000
@@ -5025,21 +5025,14 @@
         do {
             __threadErrno = 0;
             ret = STX_API_NOINT_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName);
-        } while ((ret < 0) && (__threadErrno == EINTR));
+        } while ((ret == -1) && (__threadErrno == EINTR));
 #else
         ret = GetFileAttributesA((char *) __stringVal(aPathName));
-        if (ret < 0) {
+        if (ret == -1) {
             __threadErrno = __WIN32_ERR(GetLastError());
         }
 #endif
-        if (ret < 0) {
-            @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
-            RETURN ( false );
-        }
-        RETURN ( (ret & FILE_ATTRIBUTE_DIRECTORY) ? true : false);
-    }
-
-    if (__isUnicode16String(aPathName)) {
+    } else if (__isUnicode16String(aPathName)) {
         wchar_t _wPathName[MAXPATHLEN+1];
         int i, l;
 
@@ -5053,19 +5046,22 @@
         do {
             __threadErrno = 0;
             ret = STX_API_NOINT_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName);
-        } while ((ret < 0) && (__threadErrno == EINTR));
+        } while ((ret == -1) && (__threadErrno == EINTR));
 #else
         ret = GetFileAttributesW(_wPathName);
-        if (ret < 0) {
+        if (ret == -1) {
             __threadErrno = __WIN32_ERR(GetLastError());
         }
 #endif
-        if (ret < 0) {
-            @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
-            RETURN ( false );
-        }
-        RETURN ( (ret & FILE_ATTRIBUTE_DIRECTORY) ? true : false);
-    }
+    } else
+        goto err;
+
+    if (ret < 0) {
+        @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
+        RETURN ( false );
+    }
+    RETURN ( (ret & FILE_ATTRIBUTE_DIRECTORY) ? true : false);
+err:;
 %}.
     ^ self primitiveFailed
 
@@ -5213,21 +5209,14 @@
         do {
             __threadErrno = 0;
             ret = STX_API_NOINT_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName);
-        } while ((ret < 0) && (__threadErrno == EINTR));
+        } while ((ret == -1) && (__threadErrno == EINTR));
 #else
         ret = GetFileAttributesA((char *) __stringVal(aPathName));
-        if (ret < 0) {
+        if (ret == -1) {
             __threadErrno = __WIN32_ERR(GetLastError());
         }
 #endif
-        if (ret < 0) {
-            @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
-            RETURN ( false );
-        }
-        RETURN (true);
-    }
-
-    if (__isUnicode16String(aPathName)) {
+    } else  if (__isUnicode16String(aPathName)) {
         wchar_t _wPathName[MAXPATHLEN+1];
         int i, l;
 
@@ -5241,19 +5230,23 @@
         do {
             __threadErrno = 0;
             ret = STX_API_NOINT_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName);
-        } while ((ret < 0) && (__threadErrno == EINTR));
+        } while ((ret == -1) && (__threadErrno == EINTR));
 #else
         ret = GetFileAttributesW(_wPathName);
-        if (ret < 0) {
+        if (ret == -1) {
             __threadErrno = __WIN32_ERR(GetLastError());
         }
 #endif
-        if (ret < 0) {
-            @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
-            RETURN ( false );
-        }
-        RETURN (true);
-    }
+    } else
+        goto err;
+
+    if (ret == -1) {
+        @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
+        RETURN ( false );
+    }
+    RETURN (true);
+
+err:;
 %}.
     ^ self primitiveFailed
 
@@ -6144,12 +6137,12 @@
 
 blockingTest2
     "this is a test method;
-     For testing double CTRL-C in blocking primitives"
+     For testing single CTRL-C in blocking primitives"
 
 %{
     while(1) {
-	console_printf("blocking...");
-	STX_API_CALL1("Sleep", Sleep, 50);
+        console_printf("blocking...");
+        STX_API_CALL1("Sleep", Sleep, 50);
     }
 %}.
     "
@@ -6157,6 +6150,40 @@
     "
 !
 
+blockingTest3
+    "this is a test method;
+     For testing single CTRL-C in non-interruptable blocking primitives.
+     This one should continue after typing continue in the debugger"
+
+%{
+    int ret;
+
+    do {
+        ret = STX_API_NOINT_CALL1("Sleep", Sleep, 60000);
+    } while (ret < 0 && __threadErrno == EINTR);
+%}.
+    "
+     OperatingSystem blockingTest3
+    "
+!
+
+blockingTest4
+    "this is a test method;
+     For testing single CTRL-C in non-interruptable blocking primitives.
+     This one start a new sleep after typing continue in the debugger"
+
+%{
+    int ret;
+
+    do {
+        ret = STX_API_CALL1("Sleep", Sleep, 60000);
+    } while (ret < 0 && __threadErrno == EINTR);
+%}.
+    "
+     OperatingSystem blockingTest4
+    "
+!
+
 defaultSignal:signalNumber
     "revert to the default action on arrival of a (Unix-)signal.
      Dont confuse Unix signals with smalltalk signals.
@@ -8334,6 +8361,57 @@
     "
 !
 
+primRtlGenRandomInto:buffer
+    "fill a given buffer with random bytes from the RtlGenRandom function"
+
+%{
+//    BOOLEAN RtlGenRandom(
+//      __out  PVOID RandomBuffer,
+//      __in   ULONG RandomBufferLength
+//    );
+    static BOOL (__stdcall *P_RtlGenRandom)(PVOID , ULONG) = 0;
+    unsigned char *__buffer;
+    int __bufferSize;
+
+    if (__isString(buffer)) {
+        __buffer = __stringVal(buffer);
+        __bufferSize = __stringSize(buffer);
+    } else {
+        if (__isByteArray(buffer)) {
+            __buffer = __byteArrayVal(buffer);
+            __bufferSize = __byteArraySize(buffer);
+        } else {
+            goto error;
+        }
+    }
+
+    if (P_RtlGenRandom == 0) {
+        HINSTANCE hAdvapi32 = LoadLibrary("advapi32.dll");
+        // console_printf("hAdvapi32: %x\n", hAdvapi32);
+        console_printf("hAdvapi32: %x\n", hAdvapi32);
+        if (hAdvapi32) {
+            P_RtlGenRandom = (BOOL (__stdcall *)(PVOID , ULONG))
+                                GetProcAddress(hAdvapi32, "SystemFunction036");
+            console_printf("P_RtlGenRandom: %x\n", P_RtlGenRandom);
+            if (P_RtlGenRandom == 0) {
+                goto error;
+            }
+        }
+    }
+    if ((*P_RtlGenRandom)(__buffer, __bufferSize)) {
+        RETURN (buffer);
+    }
+error: ;
+%}.
+    self primitiveFailed.
+    ^ nil
+
+    "
+     Win32OperatingSystem 
+        primRtlGenRandomInto:(ByteArray new:4)
+    "
+!
+
 setEnvironment:aStringOrSymbol to:newValueString
     "set an environment variable"
 
@@ -16419,11 +16497,11 @@
 !Win32OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Id: Win32OperatingSystem.st 10501 2010-02-13 23:34:44Z vranyj1 $'
+    ^ '$Id: Win32OperatingSystem.st 10505 2010-03-08 21:39:02Z vranyj1 $'
 !
 
 version_CVS
-    ^ '§Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.389 2010/02/09 18:34:45 sr Exp §'
+    ^ '§Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.391 2010/03/08 12:43:38 cg Exp §'
 ! !
 
 Win32OperatingSystem initialize!
@@ -16436,3 +16514,4 @@
 
 
 
+