From b97ec2e9a6a21e677af52b1547c0e19fb5492db3 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 7 Mar 2019 03:02:12 +0100 Subject: syntax: lazily load ui library This way we don't have msftedit.dll loaded into the address space of the process doing real crypto. --- ui/syntax/confview.c | 6 ++++-- ui/syntax/confview.go | 5 +---- ui/syntax/syntaxedit.c | 6 ++++-- ui/syntax/syntaxedit.go | 5 +---- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ui/syntax/confview.c b/ui/syntax/confview.c index 32d100e8..b7e6657b 100644 --- a/ui/syntax/confview.c +++ b/ui/syntax/confview.c @@ -142,14 +142,16 @@ static LRESULT CALLBACK child_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lP return parent_proc(hWnd, Msg, wParam, lParam); } +static long has_loaded = 0; + bool register_conf_view(void) { WNDCLASSEXW class = { .cbSize = sizeof(WNDCLASSEXW) }; WNDPROC pp; HANDLE lib; - if (parent_proc) - return true; + if (InterlockedCompareExchange(&has_loaded, 1, 0) != 0) + return !!parent_proc; lib = LoadLibraryExW(L"msftedit.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); if (!lib) diff --git a/ui/syntax/confview.go b/ui/syntax/confview.go index b88a7702..ef1c4530 100644 --- a/ui/syntax/confview.go +++ b/ui/syntax/confview.go @@ -23,10 +23,6 @@ type ConfView struct { lastRtf string } -func init() { - C.register_conf_view() -} - func (cv *ConfView) LayoutFlags() walk.LayoutFlags { return walk.GrowableHorz | walk.GrowableVert | walk.GreedyHorz | walk.GreedyVert } @@ -138,6 +134,7 @@ func (cv *ConfView) SetConfiguration(conf *conf.Config) { } func NewConfView(parent walk.Container) (*ConfView, error) { + C.register_conf_view() cv := &ConfView{ lastRtf: "", } diff --git a/ui/syntax/syntaxedit.c b/ui/syntax/syntaxedit.c index 95356331..6c6de295 100644 --- a/ui/syntax/syntaxedit.c +++ b/ui/syntax/syntaxedit.c @@ -279,14 +279,16 @@ static LRESULT CALLBACK child_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lP return parent_proc(hWnd, Msg, wParam, lParam); } +static long has_loaded = 0; + bool register_syntax_edit(void) { WNDCLASSEXW class = { .cbSize = sizeof(WNDCLASSEXW) }; WNDPROC pp; HANDLE lib; - if (parent_proc) - return true; + if (InterlockedCompareExchange(&has_loaded, 1, 0) != 0) + return !!parent_proc; lib = LoadLibraryExW(L"msftedit.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); if (!lib) diff --git a/ui/syntax/syntaxedit.go b/ui/syntax/syntaxedit.go index ec1e54b8..95cf576c 100644 --- a/ui/syntax/syntaxedit.go +++ b/ui/syntax/syntaxedit.go @@ -59,10 +59,6 @@ type SyntaxEdit struct { privateKeyPublisher PrivateKeyPublisher } -func init() { - C.register_syntax_edit() -} - func (se *SyntaxEdit) LayoutFlags() walk.LayoutFlags { return walk.GrowableHorz | walk.GrowableVert | walk.GreedyHorz | walk.GreedyVert } @@ -122,6 +118,7 @@ func (se *SyntaxEdit) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) } func NewSyntaxEdit(parent walk.Container) (*SyntaxEdit, error) { + C.register_syntax_edit() se := &SyntaxEdit{} err := walk.InitWidget( se, -- cgit v1.2.3-59-g8ed1b