[IMM32][NETAPI32][SDK] Reduce Wine dependency (#7912)

Related to #7870. netapi32.dll uses NDK.
So, we have to reduce dependency on Wine.
JIRA issue: CORE-5743
- Introduce wine2ros module in
  sdk/lib/wine2ros/.
- Reduce Wine dependency.
This commit is contained in:
Katayama Hirofumi MZ 2025-05-06 09:59:47 +09:00 committed by GitHub
parent 45b928f8bc
commit 2c475add8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 367 additions and 97 deletions

View file

@ -56,6 +56,7 @@ add_subdirectory(ucrt)
add_subdirectory(udmihelp)
add_subdirectory(uuid)
add_subdirectory(vcruntime)
add_subdirectory(wine2ros)
add_subdirectory(wdmguid)
else()

View file

@ -0,0 +1,7 @@
list(APPEND SOURCE
wine2ros.c
)
add_library(wine2ros STATIC ${SOURCE})
add_dependencies(wine2ros psdk)
target_include_directories(wine2ros INTERFACE ${REACTOS_SOURCE_DIR}/sdk/lib/wine2ros)

235
sdk/lib/wine2ros/wine2ros.c Normal file
View file

@ -0,0 +1,235 @@
/*
* PROJECT: ReactOS Wine-To-ReactOS
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
* PURPOSE: Reducing dependency on Wine
* COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*/
#if DBG
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "wine2ros.h"
BOOL
IntIsDebugChannelEnabled(_In_ PCSTR channel)
{
CHAR szValue[MAX_PATH];
PCHAR pch0, pch1;
BOOL ret;
DWORD error;
error = GetLastError();
ret = GetEnvironmentVariableA("DEBUGCHANNEL", szValue, _countof(szValue));
SetLastError(error);
if (!ret)
return FALSE;
for (pch0 = szValue;; pch0 = pch1 + 1)
{
pch1 = strchr(pch0, ',');
if (pch1)
*pch1 = ANSI_NULL;
if (_stricmp(pch0, channel) == 0)
return TRUE;
if (!pch1)
return FALSE;
}
}
#define DEBUGSTR_HEX "0123456789ABCDEF"
#define DEBUGSTR_QUOTE_TAIL_LEN 8
static PSTR
debugstr_quote_a(
_Out_ PSTR pszBuf,
_In_ SIZE_T cchBuf,
_In_opt_ PCSTR pszSrc)
{
PCH pch = pszBuf;
PCCH pchSrc = pszSrc;
if (!pszSrc)
return "(null)";
if (!((ULONG_PTR)pszSrc >> 16))
{
snprintf(pszBuf, cchBuf, "%p", pszSrc);
return pszBuf;
}
*pch++ = '"';
--cchBuf;
for (; cchBuf > DEBUGSTR_QUOTE_TAIL_LEN; ++pchSrc)
{
switch (*pchSrc)
{
case '\'': case '\"': case '\\': case '\t': case '\r': case '\n':
*pch++ = '\\';
if (*pchSrc == '\t')
*pch++ = 't';
else if (*pchSrc == '\r')
*pch++ = 'r';
else if (*pchSrc == '\n')
*pch++ = 'n';
else
*pch++ = *pchSrc;
cchBuf -= 2;
break;
default:
{
if (*pchSrc >= ' ')
{
*pch++ = *pchSrc;
--cchBuf;
}
else
{
*pch++ = '\\';
*pch++ = 'x';
*pch++ = DEBUGSTR_HEX[(*pchSrc >> 4) & 0xF];
*pch++ = DEBUGSTR_HEX[*pchSrc & 0xF];
cchBuf -= 4;
}
break;
}
}
}
if (cchBuf <= DEBUGSTR_QUOTE_TAIL_LEN)
{
*pch++ = '.';
*pch++ = '.';
*pch++ = '.';
}
*pch++ = '"';
*pch = ANSI_NULL;
return pszBuf;
}
static PSTR
debugstr_quote_w(
_Out_ PSTR pszBuf,
_In_ SIZE_T cchBuf,
_In_opt_ PCWSTR pszSrc)
{
PCH pch = pszBuf;
PCWCH pchSrc = pszSrc;
if (!pszSrc)
return "(null)";
if (!((ULONG_PTR)pszSrc >> 16))
{
snprintf(pszBuf, cchBuf, "%p", pszSrc);
return pszBuf;
}
*pch++ = '"';
--cchBuf;
for (; cchBuf > DEBUGSTR_QUOTE_TAIL_LEN; ++pchSrc)
{
switch (*pchSrc)
{
case L'\'': case L'\"': case L'\\': case L'\t': case L'\r': case L'\n':
*pch++ = '\\';
if (*pchSrc == L'\t')
*pch++ = 't';
else if (*pchSrc == L'\r')
*pch++ = 'r';
else if (*pchSrc == L'\n')
*pch++ = 'n';
else
*pch++ = *pchSrc;
cchBuf -= 2;
break;
default:
{
if (*pchSrc >= L' ' && *pchSrc < 0x100)
{
*pch++ = (CHAR)*pchSrc;
--cchBuf;
}
else
{
*pch++ = '\\';
*pch++ = 'x';
*pch++ = DEBUGSTR_HEX[(*pchSrc >> 12) & 0xF];
*pch++ = DEBUGSTR_HEX[(*pchSrc >> 8) & 0xF];
*pch++ = DEBUGSTR_HEX[(*pchSrc >> 4) & 0xF];
*pch++ = DEBUGSTR_HEX[*pchSrc & 0xF];
cchBuf -= 6;
}
break;
}
}
}
if (cchBuf <= DEBUGSTR_QUOTE_TAIL_LEN)
{
*pch++ = '.';
*pch++ = '.';
*pch++ = '.';
}
*pch++ = '"';
*pch = ANSI_NULL;
return pszBuf;
}
#define DEBUGSTR_NUM_BUFFS 5
#define DEBUGSTR_BUFF_SIZE MAX_PATH
static LPSTR
debugstr_next_buff(void)
{
static CHAR s_bufs[DEBUGSTR_NUM_BUFFS][DEBUGSTR_BUFF_SIZE];
static SIZE_T s_index = 0;
PCHAR ptr = s_bufs[s_index];
s_index = (s_index + 1) % _countof(s_bufs);
return ptr;
}
PCSTR
debugstr_a(_In_opt_ PCSTR pszA)
{
return debugstr_quote_a(debugstr_next_buff(), DEBUGSTR_BUFF_SIZE, pszA);
}
PCSTR
debugstr_w(_In_opt_ PCWSTR pszW)
{
return debugstr_quote_w(debugstr_next_buff(), DEBUGSTR_BUFF_SIZE, pszW);
}
PCSTR
debugstr_guid(_In_opt_ const GUID *id)
{
PCHAR ptr;
if (!id)
return "(null)";
ptr = debugstr_next_buff();
if (!((ULONG_PTR)id >> 16))
{
snprintf(ptr, DEBUGSTR_BUFF_SIZE, "%p", id);
}
else
{
snprintf(ptr, DEBUGSTR_BUFF_SIZE,
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
id->Data1, id->Data2, id->Data3,
id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7]);
}
return ptr;
}
#endif /* DBG */

View file

@ -0,0 +1,88 @@
/*
* PROJECT: ReactOS Wine-To-ReactOS
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
* PURPOSE: Reducing dependency on Wine
* COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*/
#pragma once
/* <wine/debug.h> */
#if DBG
#ifndef __RELFILE__
#define __RELFILE__ __FILE__
#endif
#define ERR_LEVEL 0x1
#define TRACE_LEVEL 0x8
#define WINE_DEFAULT_DEBUG_CHANNEL(x) static PCSTR DbgDefaultChannel = #x;
BOOL IntIsDebugChannelEnabled(_In_ PCSTR channel);
#define DBG_PRINT(ch, level, tag, fmt, ...) (void)( \
(((level) == ERR_LEVEL) || IntIsDebugChannelEnabled(ch)) ? \
(DbgPrint("(%s:%d) %s" fmt, __RELFILE__, __LINE__, (tag), ##__VA_ARGS__), FALSE) : TRUE \
)
#define ERR(fmt, ...) DBG_PRINT(DbgDefaultChannel, ERR_LEVEL, "err: ", fmt, ##__VA_ARGS__)
#define WARN(fmt, ...) DBG_PRINT(DbgDefaultChannel, ERR_LEVEL, "warn: ", fmt, ##__VA_ARGS__)
#define FIXME(fmt, ...) DBG_PRINT(DbgDefaultChannel, ERR_LEVEL, "fixme: ", fmt, ##__VA_ARGS__)
#define TRACE(fmt, ...) DBG_PRINT(DbgDefaultChannel, TRACE_LEVEL, "", fmt, ##__VA_ARGS__)
#define UNIMPLEMENTED FIXME("%s is unimplemented", __FUNCTION__);
PCSTR debugstr_a(_In_opt_ PCSTR pszA);
PCSTR debugstr_w(_In_opt_ PCWSTR pszW);
PCSTR debugstr_guid(_In_opt_ const GUID *id);
#else
#define WINE_DEFAULT_DEBUG_CHANNEL(x)
#define IntIsDebugChannelEnabled(channel) FALSE
#define DBG_PRINT(ch, level)
#define ERR(fmt, ...)
#define WARN(fmt, ...)
#define FIXME(fmt, ...)
#define TRACE(fmt, ...)
#define UNIMPLEMENTED
#define debugstr_a(pszA) ((PCSTR)NULL)
#define debugstr_w(pszW) ((PCSTR)NULL)
#define debugstr_guid(id) ((PCSTR)NULL)
#endif
/* <wine/unicode.h> */
#define memicmpW(s1,s2,n) _wcsnicmp((s1),(s2),(n))
#define strlenW(s) wcslen((s))
#define strcpyW(d,s) wcscpy((d),(s))
#define strcatW(d,s) wcscat((d),(s))
#define strcspnW(d,s) wcscspn((d),(s))
#define strstrW(d,s) wcsstr((d),(s))
#define strtolW(s,e,b) wcstol((s),(e),(b))
#define strchrW(s,c) wcschr((s),(c))
#define strrchrW(s,c) wcsrchr((s),(c))
#define strncmpW(s1,s2,n) wcsncmp((s1),(s2),(n))
#define strncpyW(s1,s2,n) wcsncpy((s1),(s2),(n))
#define strcmpW(s1,s2) wcscmp((s1),(s2))
#define strcmpiW(s1,s2) _wcsicmp((s1),(s2))
#define strncmpiW(s1,s2,n) _wcsnicmp((s1),(s2),(n))
#define strtoulW(s1,s2,b) wcstoul((s1),(s2),(b))
#define strspnW(str, accept) wcsspn((str),(accept))
#define strpbrkW(str, accept) wcspbrk((str),(accept))
#define tolowerW(n) towlower((n))
#define toupperW(n) towupper((n))
#define islowerW(n) iswlower((n))
#define isupperW(n) iswupper((n))
#define isalphaW(n) iswalpha((n))
#define isalnumW(n) iswalnum((n))
#define isdigitW(n) iswdigit((n))
#define isxdigitW(n) iswxdigit((n))
#define isspaceW(n) iswspace((n))
#define iscntrlW(n) iswcntrl((n))
#define atoiW(s) _wtoi((s))
#define atolW(s) _wtol((s))
#define strlwrW(s) _wcslwr((s))
#define struprW(s) _wcsupr((s))
#define sprintfW _swprintf
#define vsprintfW _vswprintf
#define snprintfW _snwprintf
#define vsnprintfW _vsnwprintf
#define isprintW iswprint