Files
wine-access/menu_host32.c
T
deedra 3474bb39c7 Bound native hook stack use and scope hooks to foreground threads
Ignored and reentrant Edit messages previously entered a callback whose
large text buffers increased stack use on every nested call. Menu hook
forwarding also reserved payload buffers for unrelated messages. The
64-bit helper additionally installed desktop-wide hooks, allowing
background UI threads to acquire subclasses and introducing synchronous
traffic through Wine's mixed-architecture global hook chain.

Move Edit processing and menu payload construction into non-inlined
handlers. Keep the forwarding callbacks small, retain the busy-state and
destruction guards, and preserve application subclass chaining and ANSI/
Unicode text handling.

Share foreground hook ownership between the Winelib helper and 32-bit
host. Attach both hooks only to the matching foreground UI thread,
release them when that thread changes, and retry incomplete attachment
as a pair. Preserve existing Edit subclasses across foreground changes
and release host hooks during shutdown.

Add native 32-bit and 64-bit stack-budget fixtures covering ignored and
busy reentrant messages, menu forwarding, nested text queries, application
subclasses before and after attachment, text input, and destruction during
a text change. Add a foreground-scope integration fixture that verifies
background exclusion, thread switching, detachment, and reattachment.
Keep hook debug symbols and frame pointers for native crash diagnosis,
and document installation and live acceptance requirements.

Validation:
- CMake configure and parallel build; git diff --check.
- Hook-safety CTest and foreground-scope fixtures for both architectures.
- Existing menu fixtures and Edit late-attachment/restart checks for both
  architectures, plus the 32-bit list fixture and reader-timeout test.

These checks exercise specific stack and hook-scope defects; they do not
establish the cause of the live MUSHclient stack overflow. Audible speech,
physical braille, and live MUSHclient acceptance remain separate checks.
2026-10-19 18:35:57 -07:00

54 lines
2.2 KiB
C

// SPDX-License-Identifier: LGPL-2.1-or-later
#include "menu_bridge.h"
#include "foreground_hooks.h"
#include <stdlib.h>
#include <stdio.h>
// Hook DLLs must match the application's architecture. This small PE host
// supplies 32-bit menu/editor hooks without requiring 32-bit Linux GLib/Winelib.
int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR args, int show) {
(void)instance; (void)previous; (void)show;
char *end;
DWORD parentId = strtoul(args, &end, 10);
HWND bridge = (HWND)(UINT_PTR)strtoul(end, &end, 10);
DWORD bridgeProcess = 0;
GetWindowThreadProcessId(bridge, &bridgeProcess);
if (!parentId || bridgeProcess != parentId) return 1;
HANDLE parent = OpenProcess(SYNCHRONIZE, FALSE, parentId);
if (!parent) return 1;
WCHAR path[4096] = {0};
DWORD length = GetModuleFileNameW(NULL, path, 4096);
WCHAR *name = NULL;
for (DWORD i = 0; i < length && i < 4096; ++i)
if (path[i] == L'\\' || path[i] == L'/') name = path + i + 1;
if (!length || length >= 4096 || !name ||
name - path + lstrlenW(L"wine-access-menu32.dll") >= 4096) {
CloseHandle(parent);
return 1;
}
lstrcpyW(name, L"wine-access-menu32.dll");
HMODULE module = LoadLibraryW(path);
HOOKPROC callback = module ? (HOOKPROC)GetProcAddress(module, "WineAccessMenuHook") : NULL;
HOOKPROC inputCallback = module ? (HOOKPROC)GetProcAddress(module, "WineAccessInputHook") : NULL;
WineAccessForegroundHooks hooks = {module, callback, inputCallback, NULL, NULL, 0};
if (!callback || !inputCallback)
fprintf(stderr, "wine-access: 32-bit menu/editor hooks unavailable (error %lu)\n", GetLastError());
if (callback && inputCallback) {
while (IsWindow(bridge)) {
wine_access_update_hooks(&hooks, TRUE);
DWORD result = MsgWaitForMultipleObjects(1, &parent, FALSE, 100, QS_ALLINPUT);
if (result == WAIT_OBJECT_0 || result == WAIT_FAILED) break;
MSG message;
while (PeekMessageW(&message, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&message);
DispatchMessageW(&message);
}
}
wine_access_release_hooks(&hooks);
}
if (module) FreeLibrary(module);
CloseHandle(parent);
return callback && inputCallback ? 0 : 1;
}