From 25aa68cf956209302c80adcfe1466b336616e488 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 2 Mar 2012 11:03:57 -0700 Subject: [PATCH] fix race condition on GetLastError() call original commit: d74793a5f9956c44ff9ec4dbcdcf5b1ec17515f0 --- collects/mred/private/wx/win32/utils.rkt | 6 ++++++ collects/mred/private/wx/win32/wndclass.rkt | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/collects/mred/private/wx/win32/utils.rkt b/collects/mred/private/wx/win32/utils.rkt index f9a28895..b209ef09 100644 --- a/collects/mred/private/wx/win32/utils.rkt +++ b/collects/mred/private/wx/win32/utils.rkt @@ -65,6 +65,12 @@ (define-kernel32 GetLastError (_wfun -> _DWORD)) (define (failed who) + ;; There's a race condition between this use of GetLastError() + ;; and other Racket threads that may have run since + ;; the call in this thread that we're reporting as failed. + ;; In the rare case that we lose a race, though, it just + ;; means a bad report for an error that shouldn't have happened + ;;; anyway. (error who "call failed (~s)" (GetLastError))) diff --git a/collects/mred/private/wx/win32/wndclass.rkt b/collects/mred/private/wx/win32/wndclass.rkt index 485b4a1f..06f239bd 100644 --- a/collects/mred/private/wx/win32/wndclass.rkt +++ b/collects/mred/private/wx/win32/wndclass.rkt @@ -243,7 +243,7 @@ (cpointer-push-tag! p 'HBRUSH) p)) -(define-kernel32 GetModuleFileNameW (_wfun _pointer _pointer _DWORD -> _DWORD)) +(define-kernel32 GetModuleFileNameW (_wfun #:save-errno 'windows _pointer _pointer _DWORD -> _DWORD)) (define ERROR_INSUFFICIENT_BUFFER 122) (define-shell32 ExtractIconW (_wfun _HINSTANCE _string/utf-16 _UINT -> (r : _HICON) -> (or r (failed 'ExtractIconW)))) @@ -255,7 +255,7 @@ (let ([r (GetModuleFileNameW #f p size)]) (cond [(and (or (zero? r) (= r size)) - (= (GetLastError) ERROR_INSUFFICIENT_BUFFER)) + (= (saved-errno) ERROR_INSUFFICIENT_BUFFER)) (loop (* size 2))] [(zero? r) (failed 'GetModuleFileNameW)] [else (cast p _gcpointer _string/utf-16)]))))])