fix race condition on GetLastError() call
This commit is contained in:
parent
5cb1a844fb
commit
d74793a5f9
|
@ -65,6 +65,12 @@
|
||||||
(define-kernel32 GetLastError (_wfun -> _DWORD))
|
(define-kernel32 GetLastError (_wfun -> _DWORD))
|
||||||
|
|
||||||
(define (failed who)
|
(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)"
|
(error who "call failed (~s)"
|
||||||
(GetLastError)))
|
(GetLastError)))
|
||||||
|
|
||||||
|
|
|
@ -243,7 +243,7 @@
|
||||||
(cpointer-push-tag! p 'HBRUSH)
|
(cpointer-push-tag! p 'HBRUSH)
|
||||||
p))
|
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 ERROR_INSUFFICIENT_BUFFER 122)
|
||||||
(define-shell32 ExtractIconW (_wfun _HINSTANCE _string/utf-16 _UINT -> (r : _HICON)
|
(define-shell32 ExtractIconW (_wfun _HINSTANCE _string/utf-16 _UINT -> (r : _HICON)
|
||||||
-> (or r (failed 'ExtractIconW))))
|
-> (or r (failed 'ExtractIconW))))
|
||||||
|
@ -255,7 +255,7 @@
|
||||||
(let ([r (GetModuleFileNameW #f p size)])
|
(let ([r (GetModuleFileNameW #f p size)])
|
||||||
(cond
|
(cond
|
||||||
[(and (or (zero? r) (= r size))
|
[(and (or (zero? r) (= r size))
|
||||||
(= (GetLastError) ERROR_INSUFFICIENT_BUFFER))
|
(= (saved-errno) ERROR_INSUFFICIENT_BUFFER))
|
||||||
(loop (* size 2))]
|
(loop (* size 2))]
|
||||||
[(zero? r) (failed 'GetModuleFileNameW)]
|
[(zero? r) (failed 'GetModuleFileNameW)]
|
||||||
[else (cast p _gcpointer _string/utf-16)]))))])
|
[else (cast p _gcpointer _string/utf-16)]))))])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user