ReactOS 0.4.16-dev-1399-gaaed9f7
kernelbase.h File Reference
#include "windef.h"
#include "winbase.h"
Include dependency graph for kernelbase.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pseudo_console
 

Macros

#define HeapAlloc(heap, flags, size)   RtlAllocateHeap(heap, flags, size)
 
#define HeapReAlloc(heap, flags, ptr, size)   RtlReAllocateHeap(heap, flags, ptr, size)
 
#define HeapFree(heap, flags, ptr)   RtlFreeHeap(heap, flags, ptr)
 

Functions

WCHARfile_name_AtoW (LPCSTR name, BOOL alloc)
 
DWORD file_name_WtoA (LPCWSTR src, INT srclen, LPSTR dest, INT destlen)
 
void init_global_data (void)
 
void init_startup_info (RTL_USER_PROCESS_PARAMETERS *params)
 
void init_locale (HMODULE module)
 
void init_console (void)
 
static BOOL set_ntstatus (NTSTATUS status)
 

Variables

const WCHAR windows_dir []
 
const WCHAR system_dir []
 
static const BOOL is_win64 = (sizeof(void *) > sizeof(int))
 
BOOL is_wow64
 

Macro Definition Documentation

◆ HeapAlloc

#define HeapAlloc (   heap,
  flags,
  size 
)    RtlAllocateHeap(heap, flags, size)

Definition at line 59 of file kernelbase.h.

◆ HeapFree

#define HeapFree (   heap,
  flags,
  ptr 
)    RtlFreeHeap(heap, flags, ptr)

Definition at line 61 of file kernelbase.h.

◆ HeapReAlloc

#define HeapReAlloc (   heap,
  flags,
  ptr,
  size 
)    RtlReAllocateHeap(heap, flags, ptr, size)

Definition at line 60 of file kernelbase.h.

Function Documentation

◆ file_name_AtoW()

WCHAR * file_name_AtoW ( LPCSTR  name,
BOOL  alloc 
)

Definition at line 411 of file file.c.

412{
414 UNICODE_STRING strW, *pstrW;
416
418 pstrW = alloc ? &strW : &NtCurrentTeb()->StaticUnicodeString;
419 if (oem_file_apis)
421 else
423 if (status == STATUS_SUCCESS) return pstrW->Buffer;
424
427 else
429 return NULL;
430}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define SetLastError(x)
Definition: compat.h:752
static BOOL oem_file_apis
Definition: file.c:70
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define NtCurrentTeb
WCHAR strW[12]
Definition: clipboard.c:2029
NTSYSAPI NTSTATUS NTAPI RtlOemStringToUnicodeString(PUNICODE_STRING DestinationString, PCOEM_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define alloc
Definition: rosglue.h:13
const WCHAR * str
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
Definition: name.c:39
Definition: ps.c:97
#define ERROR_FILENAME_EXCED_RANGE
Definition: winerror.h:263

Referenced by CreateDirectoryA(), CreateFileA(), CreateHardLinkA(), CreateProcessInternalA(), DeleteFileA(), FindFirstChangeNotificationA(), FindFirstFileExA(), GetCompressedFileSizeA(), GetDiskFreeSpaceA(), GetDiskFreeSpaceExA(), GetDriveTypeA(), GetFileAttributesA(), GetFileAttributesExA(), GetFullPathNameA(), GetLongPathNameA(), GetModuleHandleExA(), GetTempFileNameA(), GetVolumeInformationA(), LoadLibraryExA(), NeedCurrentDirectoryForExePathA(), RemoveDirectoryA(), SearchPathA(), SetCurrentDirectoryA(), and SetFileAttributesA().

◆ file_name_WtoA()

DWORD file_name_WtoA ( LPCWSTR  src,
INT  srclen,
LPSTR  dest,
INT  destlen 
)

Definition at line 438 of file file.c.

439{
440 DWORD ret;
441
442 if (srclen < 0) srclen = lstrlenW( src ) + 1;
443 if (!destlen)
444 {
445 if (oem_file_apis)
446 {
448 strW.Buffer = (WCHAR *)src;
449 strW.Length = srclen * sizeof(WCHAR);
451 }
452 else
454 }
455 else
456 {
457 if (oem_file_apis)
458 RtlUnicodeToOemN( dest, destlen, &ret, src, srclen * sizeof(WCHAR) );
459 else
460 RtlUnicodeToMultiByteN( dest, destlen, &ret, src, srclen * sizeof(WCHAR) );
461 }
462 return ret;
463}
#define lstrlenW
Definition: compat.h:750
return ret
Definition: mutex.c:146
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum src
Definition: glext.h:6340
static DWORD LPDWORD LPCSTR DWORD srclen
Definition: directory.c:52
static char * dest
Definition: rtl.c:135
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToOemN(_Out_ PCHAR OemString, _In_ ULONG OemSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:263
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToMultiByteN(_Out_ PCHAR MbString, _In_ ULONG MbSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:107
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToMultiByteSize(_Out_ PULONG MbSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:145
#define RtlUnicodeStringToOemSize(STRING)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by FindFirstFileExA(), FindNextFileA(), GetFinalPathNameByHandleA(), GetFullPathNameA(), GetMappedFileNameA(), GetModuleFileNameA(), GetTempFileNameA(), and GetVolumeInformationA().

◆ init_console()

void init_console ( void  )

Definition at line 2339 of file console.c.

2340{
2342
2343 if (params->ConsoleHandle == CONSOLE_HANDLE_SHELL)
2344 {
2345 HANDLE tty_in = NULL, tty_out = NULL, process = NULL;
2346 COORD size;
2347
2348 if (is_tty_handle( params->hStdInput ))
2349 {
2350 tty_in = params->hStdInput;
2351 params->hStdInput = NULL;
2352 }
2353 if (is_tty_handle( params->hStdOutput ))
2354 {
2355 tty_out = params->hStdOutput;
2356 params->hStdOutput = NULL;
2357 }
2358 if (is_tty_handle( params->hStdError ))
2359 {
2360 if (tty_out) CloseHandle( params->hStdError );
2361 else tty_out = params->hStdError;
2362 params->hStdError = NULL;
2363 }
2364
2365 size.X = params->dwXCountChars;
2366 size.Y = params->dwYCountChars;
2367 TRACE( "creating unix console (size %u %u)\n", size.X, size.Y );
2368 params->ConsoleHandle = create_pseudo_console( size, tty_in, tty_out, NULL, 0, &process );
2370 CloseHandle( tty_in );
2371 CloseHandle( tty_out );
2372
2373 if (params->ConsoleHandle && create_console_connection( params->ConsoleHandle ))
2374 {
2376 }
2377 }
2378 else if (params->ConsoleHandle == CONSOLE_HANDLE_ALLOC ||
2379 params->ConsoleHandle == CONSOLE_HANDLE_ALLOC_NO_WINDOW)
2380 {
2381 BOOL no_window = params->ConsoleHandle == CONSOLE_HANDLE_ALLOC_NO_WINDOW;
2383 params->ConsoleHandle = NULL;
2384 if (RtlImageNtHeader( mod )->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
2385 alloc_console( no_window );
2386 }
2387 else if (params->ConsoleHandle && params->ConsoleHandle != CONSOLE_HANDLE_SHELL_NO_WINDOW)
2388 create_console_connection( params->ConsoleHandle );
2389}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:66
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define RtlImageNtHeader
Definition: compat.h:806
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
static BOOL alloc_console(BOOL headless)
Definition: console.c:396
static HANDLE create_pseudo_console(COORD size, HANDLE input, HANDLE output, HANDLE signal, DWORD flags, HANDLE *process)
Definition: console.c:2186
static BOOL create_console_connection(HANDLE root)
Definition: console.c:265
static BOOL init_console_std_handles(BOOL override_all)
Definition: console.c:280
static BOOL is_tty_handle(HANDLE handle)
Definition: console.c:2334
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizeiptr size
Definition: glext.h:5919
GLenum const GLfloat * params
Definition: glext.h:5645
NTSYSAPI PEB *WINAPI RtlGetCurrentPeb(void)
Definition: libsupp.c:65
#define IMAGE_SUBSYSTEM_WINDOWS_CUI
Definition: ntimage.h:438
#define TRACE(s)
Definition: solgame.cpp:4
Definition: bl.h:1338
PRTL_USER_PROCESS_PARAMETERS ProcessParameters
Definition: btrfs_drv.h:1913

Referenced by DllMain().

◆ init_global_data()

void init_global_data ( void  )

Definition at line 931 of file memory.c.

932{
934 if (!(next_free_mem = global_data.mem_entries)) ERR( "Failed to allocate kernelbase global handle table\n" );
935 global_data.mem_entries_end = global_data.mem_entries + MAX_MEM_HANDLES;
936}
#define ERR(fmt,...)
Definition: precomp.h:57
LPVOID WINAPI DECLSPEC_HOTPATCH VirtualAlloc(void *addr, SIZE_T size, DWORD type, DWORD protect)
Definition: memory.c:415
#define MAX_MEM_HANDLES
Definition: memory.c:905
static struct kernelbase_global_data global_data
Definition: memory.c:907
static struct mem_entry * next_free_mem
Definition: memory.c:906
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define MEM_COMMIT
Definition: nt_native.h:1313
Definition: memory.c:890

Referenced by DllMain().

◆ init_locale()

void init_locale ( HMODULE  module)

Definition at line 1911 of file locale.c.

1912{
1913 USHORT utf8[2] = { 0, CP_UTF8 };
1914 USHORT *ansi_ptr, *oem_ptr;
1917 const WCHAR *user_locale_name;
1918 DWORD count;
1919 SIZE_T size;
1920 HKEY hkey;
1921
1925
1928
1930 if (!(user_locale = NlsValidateLocale( &user_lcid, 0 )))
1931 {
1932 if (GetEnvironmentVariableW( L"WINEUSERLOCALE", bufferW, ARRAY_SIZE(bufferW) ))
1935 }
1936 user_lcid = user_locale->ilanguage;
1938
1939 if (GetEnvironmentVariableW( L"WINEUNIXCP", bufferW, ARRAY_SIZE(bufferW) ))
1940 unix_cp = wcstoul( bufferW, NULL, 10 );
1941
1943
1944 ansi_ptr = NtCurrentTeb()->Peb->AnsiCodePageData ? NtCurrentTeb()->Peb->AnsiCodePageData : utf8;
1945 oem_ptr = NtCurrentTeb()->Peb->OemCodePageData ? NtCurrentTeb()->Peb->OemCodePageData : utf8;
1946 RtlInitCodePageTable( ansi_ptr, &ansi_cpinfo );
1947 RtlInitCodePageTable( oem_ptr, &oem_cpinfo );
1948
1949 RegCreateKeyExW( HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Nls",
1951 RegCreateKeyExW( HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1953 RegCreateKeyExW( HKEY_CURRENT_USER, L"Control Panel\\International",
1955
1957
1959 !RegCreateKeyExW( HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\TimeZoneInformation",
1961 {
1962 RegSetValueExW( hkey, L"StandardName", 0, REG_SZ, (BYTE *)timezone.StandardName,
1963 (lstrlenW(timezone.StandardName) + 1) * sizeof(WCHAR) );
1964 RegSetValueExW( hkey, L"TimeZoneKeyName", 0, REG_SZ, (BYTE *)timezone.TimeZoneKeyName,
1965 (lstrlenW(timezone.TimeZoneKeyName) + 1) * sizeof(WCHAR) );
1966 RegCloseKey( hkey );
1967 }
1968
1969 /* Update registry contents if the user locale has changed.
1970 * This simulates the action of the Windows control panel. */
1971
1972 user_locale_name = locale_strings + user_locale->sname + 1;
1973 count = sizeof(bufferW);
1974 if (!RegQueryValueExW( intl_key, L"LocaleName", NULL, NULL, (BYTE *)bufferW, &count ))
1975 {
1976 if (!wcscmp( bufferW, user_locale_name )) return; /* unchanged */
1977 TRACE( "updating registry, locale changed %s -> %s\n",
1978 debugstr_w(bufferW), debugstr_w(user_locale_name) );
1979 }
1980 else TRACE( "updating registry, locale changed none -> %s\n", debugstr_w(user_locale_name) );
1981
1983
1984 if (!RegCreateKeyExW( nls_key, L"Codepage",
1986 {
1987 count = swprintf( bufferW, ARRAY_SIZE(bufferW), L"%03d", GetACP() );
1988 RegSetValueExW( hkey, L"ACP", 0, REG_SZ, (BYTE *)bufferW, (count + 1) * sizeof(WCHAR) );
1989 count = swprintf( bufferW, ARRAY_SIZE(bufferW), L"%03d", GetOEMCP() );
1990 RegSetValueExW( hkey, L"OEMCP", 0, REG_SZ, (BYTE *)bufferW, (count + 1) * sizeof(WCHAR) );
1991 count = swprintf( bufferW, ARRAY_SIZE(bufferW), L"%03d", system_locale->idefaultmaccodepage );
1992 RegSetValueExW( hkey, L"MACCP", 0, REG_SZ, (BYTE *)bufferW, (count + 1) * sizeof(WCHAR) );
1993 RegCloseKey( hkey );
1994 }
1995}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define RegCloseKey(hKey)
Definition: registry.h:49
#define TRUE
Definition: types.h:120
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define LOCALE_NAME_USER_DEFAULT
Definition: locale.c:43
static HKEY tz_key
Definition: locale.c:310
static LCID system_lcid
Definition: locale.c:306
static void load_locale_nls(void)
Definition: locale.c:437
static HMODULE kernelbase_handle
Definition: locale.c:45
UINT WINAPI GetACP(void)
Definition: locale.c:5546
static CPTABLEINFO ansi_cpinfo
Definition: locale.c:303
static HKEY intl_key
Definition: locale.c:308
DWORD WINAPI DECLSPEC_HOTPATCH GetDynamicTimeZoneInformation(DYNAMIC_TIME_ZONE_INFORMATION *info)
Definition: locale.c:5665
static void load_sortdefault_nls(void)
Definition: locale.c:479
static const struct sortguid * get_language_sort(const WCHAR *name)
Definition: locale.c:662
const NLS_LOCALE_DATA *WINAPI NlsValidateLocale(LCID *lcid, ULONG flags)
Definition: locale.c:723
static const NLS_LOCALE_DATA * get_locale_by_name(const WCHAR *name, LCID *lcid)
Definition: locale.c:642
static const struct sortguid * current_locale_sort
Definition: locale.c:408
static HKEY nls_key
Definition: locale.c:309
static UINT unix_cp
Definition: locale.c:305
static const WCHAR * locale_strings
Definition: locale.c:314
static void update_locale_registry(void)
Definition: locale.c:1853
static const NLS_LOCALE_DATA * system_locale
Definition: locale.c:315
static CPTABLEINFO oem_cpinfo
Definition: locale.c:304
UINT WINAPI GetOEMCP(void)
Definition: locale.c:6153
static struct norm_table * norm_info
Definition: locale.c:321
static LCID user_lcid
Definition: locale.c:307
static const NLS_LOCALE_DATA * user_locale
Definition: locale.c:316
#define swprintf
Definition: precomp.h:40
#define L(x)
Definition: resources.c:13
GLuint GLuint GLsizei count
Definition: gl.h:1545
NTSYSAPI NTSTATUS WINAPI NtGetNlsSectionPtr(ULONG, ULONG, void *, void **, SIZE_T *)
#define debugstr_w
Definition: kernel32.h:32
#define REG_SZ
Definition: layer.c:22
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define LOCALE_NAME_MAX_LENGTH
#define LOCALE_CUSTOM_UNSPECIFIED
#define LOCALE_CUSTOM_DEFAULT
NTSTATUS NTAPI NtQueryDefaultLocale(IN BOOLEAN UserProfile, OUT PLCID DefaultLocaleId)
Definition: locale.c:396
unsigned short USHORT
Definition: pedump.c:61
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define MAKELANGID(p, s)
Definition: nls.h:15
#define LANG_ENGLISH
Definition: nls.h:52
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define CP_UTF8
Definition: nls.h:20
VOID NTAPI RtlInitCodePageTable(IN PUSHORT TableBase, OUT PCPTABLEINFO CodePageTable)
Definition: nls.c:155
Definition: fake.h:14
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define TIME_ZONE_ID_INVALID
Definition: winbase.h:319
@ NormalizationC
Definition: winnls.h:672
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11
unsigned char BYTE
Definition: xxhash.c:193

Referenced by DllMain().

◆ init_startup_info()

void init_startup_info ( RTL_USER_PROCESS_PARAMETERS params)

Definition at line 1306 of file process.c.

1307{
1309
1310 command_lineW = params->CommandLine.Buffer;
1311 if (!RtlUnicodeStringToAnsiString( &ansi, &params->CommandLine, TRUE )) command_lineA = ansi.Buffer;
1312}
static WCHAR * command_lineW
Definition: process.c:1301
static char * command_lineA
Definition: process.c:1300
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
static UINT WPARAM LPARAM BOOL ansi
Definition: misc.c:135

Referenced by DllMain().

◆ set_ntstatus()

static BOOL set_ntstatus ( NTSTATUS  status)
inlinestatic

Definition at line 52 of file kernelbase.h.

53{
55 return !status;
56}

Variable Documentation

◆ is_win64

◆ is_wow64

◆ system_dir

◆ windows_dir

const WCHAR windows_dir[]
extern