| 1 | /* $Id: ntdll.cpp,v 1.6 2000-01-05 19:37:29 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * | 
|---|
| 5 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 6 | * Win32 NT Runtime / NTDLL for OS/2 | 
|---|
| 7 | * | 
|---|
| 8 | * Copyright 1998, 1999 Patrick Haller (phaller@gmx.net) | 
|---|
| 9 | * | 
|---|
| 10 | * @(#) ntdll.cpp  1.0.1   1999/05/08 SvL: Changes for compilation with Wine headers | 
|---|
| 11 | *                 1.0.0   1998/05/20 PH Start from WINE/NTDLL.C | 
|---|
| 12 | * | 
|---|
| 13 | * NT basis DLL | 
|---|
| 14 | * | 
|---|
| 15 | * Copyright 1996 Marcus Meissner | 
|---|
| 16 | * Copyright 1998 Patrick Haller (adapted for win32os2) | 
|---|
| 17 | */ | 
|---|
| 18 |  | 
|---|
| 19 | /* Changes to the original NTDLL.C from the WINE project | 
|---|
| 20 |  | 
|---|
| 21 | - includes replaced by the win32os2 standard includes | 
|---|
| 22 | - replaced WINAPI by WIN32API | 
|---|
| 23 | - moved in some string functions | 
|---|
| 24 | - replaced HANDLE32 by HANDLE | 
|---|
| 25 | - lstrlen32A -> OS2lstrlenA | 
|---|
| 26 | - lstrlen32W -> OS2lstrlenW | 
|---|
| 27 | */ | 
|---|
| 28 |  | 
|---|
| 29 | /***************************************************************************** | 
|---|
| 30 | * Includes                                                                  * | 
|---|
| 31 | *****************************************************************************/ | 
|---|
| 32 |  | 
|---|
| 33 | #include <os2win.h> | 
|---|
| 34 | #include <winnt.h> | 
|---|
| 35 | #include <ntdef.h> | 
|---|
| 36 | #include <builtin.h> | 
|---|
| 37 | #include <stdlib.h> | 
|---|
| 38 | #include <string.h> | 
|---|
| 39 | #include <ctype.h> | 
|---|
| 40 | #include <misc.h> | 
|---|
| 41 | #include "unicode.h" | 
|---|
| 42 |  | 
|---|
| 43 | #include "ntdll.h" | 
|---|
| 44 | #include <ntdllsec.h> | 
|---|
| 45 |  | 
|---|
| 46 | /***************************************************************************** | 
|---|
| 47 | * Types & Defines                                                           * | 
|---|
| 48 | *****************************************************************************/ | 
|---|
| 49 |  | 
|---|
| 50 | #define NTSTATUS DWORD | 
|---|
| 51 |  | 
|---|
| 52 | //SvL: per process heap for NTDLL | 
|---|
| 53 | HANDLE NTDLL_hHeap = 0; | 
|---|
| 54 |  | 
|---|
| 55 | PROCESSTHREAD_SECURITYINFO ProcSecInfo = {0}; | 
|---|
| 56 |  | 
|---|
| 57 | /***************************************************************************** | 
|---|
| 58 | * Name      : DbgPrint | 
|---|
| 59 | * Purpose   : print a debug line to somewhere? | 
|---|
| 60 | * Parameters: | 
|---|
| 61 | * Variables : | 
|---|
| 62 | * Result    : | 
|---|
| 63 | * Remark    : NTDLL.21 | 
|---|
| 64 | * Status    : UNTESTED STUB | 
|---|
| 65 | * | 
|---|
| 66 | * Author    : Patrick Haller [Tue, 1999/06/01 09:00] | 
|---|
| 67 | *****************************************************************************/ | 
|---|
| 68 | void __cdecl DbgPrint(LPCSTR lpcstrFormat,LPVOID args) | 
|---|
| 69 | { | 
|---|
| 70 | UCHAR   szBuffer[600]; // as in original NTDLL.DLL | 
|---|
| 71 | int     rc; | 
|---|
| 72 |  | 
|---|
| 73 | rc = wvsnprintfA((LPSTR)szBuffer, | 
|---|
| 74 | sizeof(szBuffer), | 
|---|
| 75 | lpcstrFormat, | 
|---|
| 76 | (va_list)args); | 
|---|
| 77 |  | 
|---|
| 78 | dprintf(("NTDLL: DbgPrint[%s]\n", | 
|---|
| 79 | szBuffer)); | 
|---|
| 80 |  | 
|---|
| 81 | //@@@PH raise debug exception if running in debugger | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 |  | 
|---|
| 85 | BOOL WINAPI NTDLL_LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) | 
|---|
| 86 | { | 
|---|
| 87 | dprintf(("NTDLL_LibMain: 0x%x 0x%lx %p\n", hinstDLL, fdwReason, lpvReserved)); | 
|---|
| 88 |  | 
|---|
| 89 | switch (fdwReason) { | 
|---|
| 90 | case DLL_PROCESS_ATTACH: | 
|---|
| 91 | { | 
|---|
| 92 | SID_IDENTIFIER_AUTHORITY sidIdAuth = {0}; | 
|---|
| 93 |  | 
|---|
| 94 | NTDLL_hHeap = HeapCreate(0, 0x10000, 0); | 
|---|
| 95 |  | 
|---|
| 96 | ProcSecInfo.dwType = SECTYPE_PROCESS | SECTYPE_INITIALIZED; | 
|---|
| 97 | RtlAllocateAndInitializeSid(&sidIdAuth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &ProcSecInfo.SidUser.User.Sid); | 
|---|
| 98 | ProcSecInfo.SidUser.User.Attributes = 0; //????????? | 
|---|
| 99 |  | 
|---|
| 100 | ProcSecInfo.pTokenGroups = (TOKEN_GROUPS*)Heap_Alloc(sizeof(TOKEN_GROUPS)); | 
|---|
| 101 | ProcSecInfo.pTokenGroups->GroupCount = 1; | 
|---|
| 102 | RtlAllocateAndInitializeSid(&sidIdAuth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &ProcSecInfo.PrimaryGroup.PrimaryGroup); | 
|---|
| 103 | ProcSecInfo.pTokenGroups->Groups[0].Sid = ProcSecInfo.PrimaryGroup.PrimaryGroup; | 
|---|
| 104 | ProcSecInfo.pTokenGroups->Groups[0].Attributes = 0; //???? | 
|---|
| 105 |  | 
|---|
| 106 | //        pPrivilegeSet   = NULL; | 
|---|
| 107 | //        pTokenPrivileges= NULL; | 
|---|
| 108 | //        TokenOwner      = {0}; | 
|---|
| 109 | //        DefaultDACL     = {0}; | 
|---|
| 110 | //        TokenSource     = {0}; | 
|---|
| 111 | ProcSecInfo.TokenType = TokenPrimary; | 
|---|
| 112 | break; | 
|---|
| 113 | } | 
|---|
| 114 | case DLL_PROCESS_DETACH: | 
|---|
| 115 | HeapDestroy(NTDLL_hHeap); | 
|---|
| 116 | NTDLL_hHeap = 0; | 
|---|
| 117 | break; | 
|---|
| 118 | case DLL_THREAD_ATTACH: | 
|---|
| 119 | break; | 
|---|
| 120 | case DLL_THREAD_DETACH: | 
|---|
| 121 | break; | 
|---|
| 122 | default: | 
|---|
| 123 | break; | 
|---|
| 124 | } | 
|---|
| 125 | return TRUE; | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|