void CsrCleanupDefineDosDevice(void) { PLIST_ENTRY Entry, ListHead; PCSRSS_DOS_DEVICE_HISTORY_ENTRY HistoryEntry; (void) RtlDeleteCriticalSection(&Win32CsrDefineDosDeviceCritSec); ListHead = &DosDeviceHistory; Entry = ListHead->Flink; while (Entry != ListHead) { HistoryEntry = (PCSRSS_DOS_DEVICE_HISTORY_ENTRY) CONTAINING_RECORD(Entry, CSRSS_DOS_DEVICE_HISTORY_ENTRY, Entry); Entry = Entry->Flink; if (HistoryEntry) { if (HistoryEntry->Target.Buffer) (void) RtlFreeHeap(Win32CsrApiHeap, 0, HistoryEntry->Target.Buffer); if (HistoryEntry->Device.Buffer) (void) RtlFreeHeap(Win32CsrApiHeap, 0, HistoryEntry->Device.Buffer); (void) RtlFreeHeap(Win32CsrApiHeap, 0, HistoryEntry); } } }
VOID FreeInputHandle( IN PHANDLE_DATA HandleData ) { RtlDeleteCriticalSection(&HandleData->InputReadData->ReadCountLock); HeapFree(pConHeap,0,HandleData->InputReadData); }
/* * @implemented */ VOID WINAPI EngDeleteSemaphore ( IN HSEMAPHORE hsem ) { if (hsem) { RtlDeleteCriticalSection( (PRTL_CRITICAL_SECTION) hsem ); RtlFreeHeap( GetProcessHeap(), 0, hsem ); } }
static void mutex_real_init( pthread_mutex_t *mutex ) { CRITICAL_SECTION *critsect = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(CRITICAL_SECTION)); RtlInitializeCriticalSection(critsect); if (interlocked_cmpxchg_ptr((void**)&(((wine_mutex)mutex)->critsect),critsect,NULL) != NULL) { /* too late, some other thread already did it */ RtlDeleteCriticalSection(critsect); RtlFreeHeap(GetProcessHeap(), 0, critsect); } }
static int wine_pthread_cond_destroy(pthread_cond_t *cond) { wine_cond_detail *detail = ((wine_cond)cond)->cond; if (!detail) return 0; NtClose(detail->sema); RtlDeleteCriticalSection(&detail->waiters_count_lock); NtClose(detail->waiters_done); RtlFreeHeap(GetProcessHeap(), 0, detail); ((wine_cond)cond)->cond = NULL; return 0; }
//------------------------------------------------------------------------ // Destructor // //------------------------------------------------------------------------ CSocketMap::~CSocketMap() { NTSTATUS Status; if (m_pMap) { Status = RtlDeleteCriticalSection(&m_cs); delete m_pMap; } }
VOID WINAPI BasepUninitConsole(VOID) { /* Delete our critical section if we were initialized */ if (ConsoleInitialized == TRUE) { if (ConsoleLibrary) FreeLibrary(ConsoleLibrary); ConsoleInitialized = FALSE; RtlDeleteCriticalSection(&ConsoleLock); } }
static int wine_pthread_mutex_destroy(pthread_mutex_t *mutex) { if (!((wine_mutex)mutex)->critsect) return 0; if (((wine_mutex)mutex)->critsect->RecursionCount) { #if 0 /* there seems to be a bug in libc6 that makes this a bad idea */ return EBUSY; #else while (((wine_mutex)mutex)->critsect->RecursionCount) RtlLeaveCriticalSection(((wine_mutex)mutex)->critsect); #endif } RtlDeleteCriticalSection(((wine_mutex)mutex)->critsect); RtlFreeHeap(GetProcessHeap(), 0, ((wine_mutex)mutex)->critsect); ((wine_mutex)mutex)->critsect = NULL; return 0; }
static void wine_cond_real_init(pthread_cond_t *cond) { wine_cond_detail *detail = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(wine_cond_detail)); detail->waiters_count = 0; detail->was_broadcast = 0; NtCreateSemaphore( &detail->sema, SEMAPHORE_ALL_ACCESS, NULL, 0, 0x7fffffff ); NtCreateEvent( &detail->waiters_done, EVENT_ALL_ACCESS, NULL, FALSE, FALSE ); RtlInitializeCriticalSection (&detail->waiters_count_lock); if (interlocked_cmpxchg_ptr((void**)&(((wine_cond)cond)->cond), detail, NULL) != NULL) { /* too late, some other thread already did it */ P_OUTPUT("FIXME:pthread_cond_init:expect troubles...\n"); NtClose(detail->sema); RtlDeleteCriticalSection(&detail->waiters_count_lock); NtClose(detail->waiters_done); RtlFreeHeap(GetProcessHeap(), 0, detail); } }
VOID NTAPI ConSrvDisconnect(IN PCSR_PROCESS CsrProcess) { PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrProcess); /************************************************************************** * This function is called whenever a new process (GUI or CUI) is destroyed. **************************************************************************/ if ( ProcessData->ConsoleHandle != NULL || ProcessData->HandleTable != NULL ) { DPRINT("ConSrvDisconnect - calling ConSrvRemoveConsole\n"); ConSrvRemoveConsole(ProcessData); } RtlDeleteCriticalSection(&ProcessData->HandleTableLock); }
NTSTATUS WINAPI redirect_RtlDeleteCriticalSection(RTL_CRITICAL_SECTION* crit) { GET_NTDLL(RtlDeleteCriticalSection, (RTL_CRITICAL_SECTION *crit)); LOG(GLOBAL, LOG_LOADER, 2, "%s: "PFX"\n", __FUNCTION__, crit); IF_CLIENT_INTERFACE(ASSERT(get_own_teb()->ProcessEnvironmentBlock == get_private_peb() || standalone_library)); if (crit == NULL) return STATUS_INVALID_PARAMETER; if (crit->DebugInfo != NULL) { if (is_dynamo_address((byte *)crit->DebugInfo)) wrapped_dr_free((byte *)crit->DebugInfo); else { /* somehow a critsec created elsewhere is being destroyed here! */ ASSERT_NOT_REACHED(); return RtlDeleteCriticalSection(crit); } } close_handle(crit->LockSemaphore); memset(crit, 0, sizeof(*crit)); crit->LockCount = -1; return STATUS_SUCCESS; }
VOID BrDestroyNetworks( IN DWORD BrInitState ) { NET_API_STATUS status; RtlEnterCriticalSection(&NetworkLock); while (!IsListEmpty(&ServicedNetworks)) { PNETWORK Network = CONTAINING_RECORD(ServicedNetworks.Flink, NETWORK, NextNet); // // If this is an IPX transport, we need to manually unbind from the transport. // if (Network->Flags & NETWORK_IPX) { status = BrUnbindFromTransport(Network->NetworkName.Buffer); if (status != NERR_Success) { KdPrint(("Unable to unbind from IPX transport %wS\n", &Network->NetworkName)); } } BrDestroyNetwork(Network, NULL); } RtlLeaveCriticalSection(&NetworkLock); RtlDeleteCriticalSection(&NetworkLock); NumberOfServicedNetworks = 0; }
VOID BaseCleanupDefineDosDevice(VOID) { PLIST_ENTRY Entry, ListHead; PBASE_DOS_DEVICE_HISTORY_ENTRY HistoryEntry; RtlDeleteCriticalSection(&BaseDefineDosDeviceCritSec); ListHead = &DosDeviceHistory; Entry = ListHead->Flink; while (Entry != ListHead) { HistoryEntry = (PBASE_DOS_DEVICE_HISTORY_ENTRY) CONTAINING_RECORD(Entry, BASE_DOS_DEVICE_HISTORY_ENTRY, Entry); Entry = Entry->Flink; if (HistoryEntry) { if (HistoryEntry->Target.Buffer) { RtlFreeHeap(BaseSrvHeap, 0, HistoryEntry->Target.Buffer); } if (HistoryEntry->Device.Buffer) { RtlFreeHeap(BaseSrvHeap, 0, HistoryEntry->Device.Buffer); } RtlFreeHeap(BaseSrvHeap, 0, HistoryEntry); } } }
NET_API_STATUS BrDestroyNetwork( IN PNETWORK Network, IN PVOID Context ) /*++ Routine Description: This routine removes a reference to a network. If the network reference count goes to 0, remove the network. Arguments: Network - The network to remove Return Value: Status of operation (mostly status of allocations). --*/ { NTSTATUS Status; Status = RtlEnterCriticalSection(&NetworkLock); if (!NT_SUCCESS(Status)) { InternalError(("Unable to acquire browser critical section\n")); return BrMapStatus(Status); } RemoveEntryList(&Network->NextNet); Status = RtlLeaveCriticalSection(&NetworkLock); if (!NT_SUCCESS(Status)) { InternalError(("Unable to release browser critical section\n")); return BrMapStatus(Status); } if (Network->Role & ROLE_MASTER) { // // Stop being the master on this network. This means removing // our name from the bowser driver and forcing an election. // BrStopMaster(Network); } if (Network->Role & (ROLE_POTENTIAL_BACKUP | ROLE_BACKUP)) { // // Stop being a backup on this network. This means downgrading our // machine to idle. // BrStopBackup(Network); } // // Ensure that there are no browser related names active in the browser. // BrUpdateBrowserStatus(Network, 0); UninitializeInterimServerList(&Network->BrowseTable); UninitializeInterimServerList(&Network->DomainList); if (Network->BackupServerList != NULL) { MIDL_user_free(Network->BackupServerList); } if (Network->BackupDomainList != NULL) { MIDL_user_free(Network->BackupDomainList); } // RtlDeleteCriticalSection(&Network->Lock); RtlDeleteResource(&Network->Lock); RtlDeleteCriticalSection(&Network->MasterFlagsLock); BrDestroyTimer(&Network->MasterBrowserAnnouncementTimer); BrDestroyTimer(&Network->MasterBrowserTimer); BrDestroyTimer(&Network->BackupBrowserTimer); BrDestroyResponseCache(Network); RtlDeleteCriticalSection(&Network->ResponseCacheLock); MIDL_user_free(Network->NetworkName.Buffer); if (Network->MasterBrowserName.Buffer != NULL) { MIDL_user_free(Network->MasterBrowserName.Buffer); } MIDL_user_free(Network); return NERR_Success; UNREFERENCED_PARAMETER(Context); }
NET_API_STATUS BrCreateNetwork( PUNICODE_STRING TransportName, IN BOOLEAN Wannish, IN BOOLEAN Ras, IN PUNICODE_STRING AlternateTransportName OPTIONAL ) /*++ Routine Description: This routine allocates memory to hold a network structure, and initializes all of its associated data structures. Arguments: TransportName - The name of the transport to add. Return Value: Status of operation (mostly status of allocations). --*/ { NET_API_STATUS Status; PNETWORK Network; BOOLEAN NetworkLockInitialized = FALSE; BOOLEAN MasterFlagsInitialized = FALSE; BOOLEAN BackupBrowserTimerCreated = FALSE; BOOLEAN MasterBrowserTimerCreated =FALSE; BOOLEAN AnnouncementTimerCreated = FALSE; BOOLEAN ResponseCacheLockInitialized = FALSE; // // Check to see if the transport already exists. // if ((Network = BrFindNetwork(TransportName)) != NULL) { return NERR_AlreadyExists; } // // If this transport is explicitly on our list of transports to unbind, // simply ignore the transport. // if (BrInfo.UnboundBindings != NULL) { LPTSTR_ARRAY TStrArray = BrInfo.UnboundBindings; while (!NetpIsTStrArrayEmpty(TStrArray)) { LPWSTR NewTransportName; #define NAME_PREFIX L"\\Device\\" #define NAME_PREFIX_LENGTH 8 // // The transport name in the registry is only optionally prefixed with \device\ // if ( _wcsnicmp( NAME_PREFIX, TStrArray, NAME_PREFIX_LENGTH) == 0 ) { NewTransportName = TransportName->Buffer; } else { NewTransportName = TransportName->Buffer + NAME_PREFIX_LENGTH; } if ( _wcsicmp( TStrArray, NewTransportName ) == 0 ) { dprintf(INIT, ("Binding is marked as unbound: %s (Silently ignoring)\n", TransportName->Buffer )); return NERR_Success; } TStrArray = NetpNextTStrArrayEntry(TStrArray); } } // // If this transport isn't bound to the SMB server, // don't create the transport here. // we do announcments through the SMB server. // Status = I_NetServerSetServiceBits(NULL, TransportName->Buffer, 0, TRUE); if (Status == ERROR_PATH_NOT_FOUND ) { dprintf(INIT, ("SMB Server doesn't have this transport: %s (Silently unbinding)\n", TransportName->Buffer )); return NERR_Success; } // // Create the transport. // try { Network = MIDL_user_allocate(sizeof(NETWORK)); if (Network == NULL) { try_return(Status = ERROR_NOT_ENOUGH_MEMORY); } RtlInitializeResource(&Network->Lock); NetworkLockInitialized = TRUE; Network->LockCount = 0; Network->ReferenceCount = 1; Network->Role = BrDefaultRole; Network->NumberOfFailedBackupTimers = 0; Network->NumberOfFailedPromotions = 0; Network->NumberOfPromotionEventsLogged = 0; Network->LastBackupBrowserReturned = 0; Network->LastDomainControllerBrowserReturned = 0; Network->TimeStoppedBackup = 0; Network->BackupServerList = NULL; Network->BackupDomainList = NULL; Network->TotalBackupServerListEntries = 0; Network->TotalBackupDomainListEntries = 0; Network->NetworkName.Buffer = MIDL_user_allocate(TransportName->MaximumLength); if (Network->NetworkName.Buffer == NULL) { try_return(Status = ERROR_NOT_ENOUGH_MEMORY); } Network->NetworkName.MaximumLength = TransportName->MaximumLength; RtlCopyUnicodeString(&Network->NetworkName, TransportName); Network->Flags = 0; if (ARGUMENT_PRESENT(AlternateTransportName)) { PNETWORK AlternateNetwork = BrFindNetwork(AlternateTransportName); // // If we didn't find an alternate network, or if that network // already has an alternate network, return an error. // if (AlternateNetwork == NULL || AlternateNetwork->AlternateNetwork != NULL) { try_return(Status = NERR_InternalError); } Network->Flags |= NETWORK_IPX; // // Link the two networks together. // Network->AlternateNetwork = AlternateNetwork; AlternateNetwork->AlternateNetwork = Network; } else { Network->AlternateNetwork = NULL; } // // Null terminate the network name buffer. // Network->NetworkName.Buffer[Network->NetworkName.Length/sizeof(WCHAR)] = UNICODE_NULL; RtlInitUnicodeString(&Network->MasterBrowserName, NULL); if (Wannish) { Network->Flags |= NETWORK_WANNISH; } if (Ras) { Network->Flags |= NETWORK_RAS; } Network->LastBowserServerQueried = 0; RtlInitializeCriticalSection(&Network->MasterFlagsLock); MasterFlagsInitialized = TRUE; Network->MasterFlags = 0; InitializeInterimServerList(&Network->BrowseTable, BrBrowseTableInsertRoutine, BrBrowseTableUpdateRoutine, BrBrowseTableDeleteRoutine, BrBrowseTableAgeRoutine); Network->LastBowserDomainQueried = 0; InitializeInterimServerList(&Network->DomainList, BrDomainTableInsertRoutine, BrDomainTableUpdateRoutine, BrDomainTableDeleteRoutine, BrDomainTableAgeRoutine); InitializeListHead(&Network->OtherDomainsList); Status = BrCreateTimer(&Network->BackupBrowserTimer); if (Status != NERR_Success) { try_return(Status); } BackupBrowserTimerCreated = TRUE; Status = BrCreateTimer(&Network->MasterBrowserTimer); if (Status != NERR_Success) { try_return(Status); } MasterBrowserTimerCreated = TRUE; Status = BrCreateTimer(&Network->MasterBrowserAnnouncementTimer); if (Status != NERR_Success) { try_return(Status); } AnnouncementTimerCreated = TRUE; InitializeCriticalSection(&Network->ResponseCacheLock); ResponseCacheLockInitialized = TRUE; InitializeListHead(&Network->ResponseCache); Network->TimeCacheFlushed = 0; Network->NumberOfCachedResponses = 0; Status = RtlEnterCriticalSection(&NetworkLock); if (!NT_SUCCESS(Status)) { try_return(Status = BrMapStatus(Status)); } InsertHeadList(&ServicedNetworks, &Network->NextNet); Status = RtlLeaveCriticalSection(&NetworkLock); if (!NT_SUCCESS(Status)) { InternalError(("Unable to release browser critical section\n")); } try_exit:NOTHING; } finally { if (Status != NERR_Success) { if (Network != NULL) { if (ResponseCacheLockInitialized) { DeleteCriticalSection(&Network->ResponseCacheLock); } if (MasterFlagsInitialized) { RtlDeleteCriticalSection(&Network->MasterFlagsLock); } if (NetworkLockInitialized) { RtlDeleteResource(&Network->Lock); } if (AnnouncementTimerCreated) { BrDestroyTimer(&Network->MasterBrowserAnnouncementTimer); } if (MasterBrowserTimerCreated) { BrDestroyTimer(&Network->MasterBrowserTimer); } if (BackupBrowserTimerCreated) { BrDestroyTimer(&Network->BackupBrowserTimer); } if (Network->NetworkName.Buffer != NULL) { MIDL_user_free(Network->NetworkName.Buffer); } MIDL_user_free(Network); } } } return Status; }
VOID ElfpCleanUp ( ULONG EventFlags ) /*++ Routine Description: This routine cleans up before the service terminates. It cleans up based on the parameter passed in (which indicates what has been allocated and/or started. Arguments: Bit-mask indicating what needs to be cleaned up. Return Value: NONE Note: It is expected that the RegistryMonitor has already been notified of Shutdown prior to calling this routine. --*/ { DWORD status = NO_ERROR; ElfDbgPrint (("[ELF] ElfpCleanUp.\n")); // // Notify the Service Controller for the first time that we are // about to stop the service. // // *** STATUS UPDATE *** ElfStatusUpdate(STOPPING); // // Stop the RPC Server // if (EventFlags & ELF_STARTED_RPC_SERVER) { ElfDbgPrint (("[ELF] Stopping the RPC Server.\n")); status = ElfGlobalData->StopRpcServer(eventlog_ServerIfHandle); if (status != NO_ERROR) { ElfDbgPrint (("[ELF] Stopping RpcServer Failed %d\n",status)); } } // // Stop the LPC thread // if (EventFlags & ELF_STARTED_LPC_THREAD) StopLPCThread(); // // Tell service controller that we are making progress // // *** STATUS UPDATE *** ElfStatusUpdate(STOPPING); // // Flush all the log files to disk. // ElfDbgPrint (("[ELF] Flushing Files.\n")); ElfpFlushFiles(); // // Tell service controller that we are making progress // ElfStatusUpdate(STOPPING); // // Clean up any resources that were allocated // FreeModuleAndLogFileStructs(); // // Free up memory // if (LocalComputerName) { ElfpFreeBuffer(LocalComputerName); } // // If we queued up any events, flush them // ElfDbgPrint (("[ELF] Flushing QueuedEvents.\n")); FlushQueuedEvents(); // // Tell service controller of that we are making progress // ElfStatusUpdate(STOPPING); if (EventFlags & ELF_INIT_GLOBAL_RESOURCE) RtlDeleteResource ( &GlobalElfResource ); if (EventFlags & ELF_INIT_LOGHANDLE_CRIT_SEC) RtlDeleteCriticalSection((PRTL_CRITICAL_SECTION)&LogHandleCritSec); if (EventFlags & ELF_INIT_LOGFILE_CRIT_SEC) RtlDeleteCriticalSection((PRTL_CRITICAL_SECTION)&LogFileCritSec); if (EventFlags & ELF_INIT_QUEUED_EVENT_CRIT_SEC) RtlDeleteCriticalSection((PRTL_CRITICAL_SECTION)&QueuedEventCritSec); // *** STATUS UPDATE *** ElfDbgPrint(("[ELF] Leaving the Eventlog service\n")); ElfStatusUpdate(STOPPED); ElCleanupStatus(); return; }
BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved) { NTSTATUS Status; BASESRV_API_CONNECTINFO ConnectInfo; ULONG ConnectInfoSize = sizeof(ConnectInfo); WCHAR SessionDir[256]; DPRINT("DllMain(hInst %p, dwReason %lu)\n", hDll, dwReason); Basep8BitStringToUnicodeString = RtlAnsiStringToUnicodeString; /* Cache the PEB and Session ID */ Peb = NtCurrentPeb(); SessionId = Peb->SessionId; switch (dwReason) { case DLL_PROCESS_ATTACH: { /* Set no filter initially */ GlobalTopLevelExceptionFilter = RtlEncodePointer(NULL); /* Enable the Rtl thread pool and timer queue to use proper Win32 thread */ RtlSetThreadPoolStartFunc(BaseCreateThreadPoolThread, BaseExitThreadPoolThread); /* Register the manifest prober routine */ LdrSetDllManifestProber(BasepProbeForDllManifest); /* Don't bother us for each thread */ LdrDisableThreadCalloutsForDll((PVOID)hDll); /* Initialize default path to NULL */ RtlInitUnicodeString(&BaseDefaultPath, NULL); /* Setup the Object Directory path */ if (!SessionId) { /* Use the raw path */ wcscpy(SessionDir, WIN_OBJ_DIR); } else { /* Use the session path */ swprintf(SessionDir, L"%ws\\%ld%ws", SESSION_DIR, SessionId, WIN_OBJ_DIR); } /* Connect to the Base Server */ Status = CsrClientConnectToServer(SessionDir, BASESRV_SERVERDLL_INDEX, &ConnectInfo, &ConnectInfoSize, &BaseRunningInServerProcess); if (!NT_SUCCESS(Status)) { DPRINT1("Failed to connect to CSR (Status %lx)\n", Status); NtTerminateProcess(NtCurrentProcess(), Status); return FALSE; } /* Get the server data */ ASSERT(Peb->ReadOnlyStaticServerData); BaseStaticServerData = Peb->ReadOnlyStaticServerData[BASESRV_SERVERDLL_INDEX]; ASSERT(BaseStaticServerData); /* Check if we are running a CSR Server */ if (!BaseRunningInServerProcess) { /* Set the termination port for the thread */ DPRINT("Creating new thread for CSR\n"); CsrNewThread(); } /* Initialize heap handle table */ BaseDllInitializeMemoryManager(); /* Set HMODULE for our DLL */ kernel32_handle = hCurrentModule = hDll; /* Set the directories */ BaseWindowsDirectory = BaseStaticServerData->WindowsDirectory; BaseWindowsSystemDirectory = BaseStaticServerData->WindowsSystemDirectory; /* Construct the default path (using the static buffer) */ _snwprintf(BaseDefaultPathBuffer, sizeof(BaseDefaultPathBuffer) / sizeof(WCHAR), L".;%wZ;%wZ\\system;%wZ;", &BaseWindowsSystemDirectory, &BaseWindowsDirectory, &BaseWindowsDirectory); BaseDefaultPath.Buffer = BaseDefaultPathBuffer; BaseDefaultPath.Length = wcslen(BaseDefaultPathBuffer) * sizeof(WCHAR); BaseDefaultPath.MaximumLength = sizeof(BaseDefaultPathBuffer); /* Use remaining part of the default path buffer for the append path */ BaseDefaultPathAppend.Buffer = (PWSTR)((ULONG_PTR)BaseDefaultPathBuffer + BaseDefaultPath.Length); BaseDefaultPathAppend.Length = 0; BaseDefaultPathAppend.MaximumLength = BaseDefaultPath.MaximumLength - BaseDefaultPath.Length; /* Initialize command line */ InitCommandLines(); /* Initialize the DLL critical section */ RtlInitializeCriticalSection(&BaseDllDirectoryLock); /* Initialize the National Language Support routines */ if (!NlsInit()) { DPRINT1("NLS Init failed\n"); return FALSE; } /* Initialize Console Support */ if (!ConDllInitialize(dwReason, SessionDir)) { DPRINT1("Failed to set up console\n"); return FALSE; } /* Initialize application certification globals */ InitializeListHead(&BasepAppCertDllsList); RtlInitializeCriticalSection(&gcsAppCert); /* Insert more dll attach stuff here! */ DllInitialized = TRUE; break; } case DLL_PROCESS_DETACH: { if (DllInitialized != FALSE) { /* Uninitialize console support */ ConDllInitialize(dwReason, NULL); /* Insert more dll detach stuff here! */ NlsUninit(); /* Delete DLL critical section */ RtlDeleteCriticalSection(&BaseDllDirectoryLock); } break; } case DLL_THREAD_ATTACH: { /* ConDllInitialize sets the current console locale for the new thread */ return ConDllInitialize(dwReason, NULL); } default: break; } return TRUE; }
NTSTATUS NTAPI RtlDeleteHeapLock(IN OUT PHEAP_LOCK Lock) { return RtlDeleteCriticalSection(&Lock->CriticalSection); }
VOID RtlpDestroyAtomTableLock(PRTL_ATOM_TABLE AtomTable) { RtlDeleteCriticalSection(&AtomTable->CriticalSection); }
NTSTATUS AllocateConsole( IN HANDLE ConsoleHandle, IN LPWSTR Title, IN USHORT TitleLength, IN HANDLE ClientProcessHandle, OUT PHANDLE StdIn, OUT PHANDLE StdOut, OUT PHANDLE StdErr, OUT PCONSOLE_PER_PROCESS_DATA ProcessData, IN OUT PCONSOLE_INFO ConsoleInfo, IN BOOLEAN WindowVisible, IN DWORD dwConsoleThreadId, IN HDESK Desktop ) /*++ Routine Description: This routine allocates and initialized a console and its associated data - input buffer and screen buffer. Arguments: ConsoleHandle - Handle of console to allocate. dwWindowSize - Initial size of screen buffer window, in rows and columns. nFont - Initial number of font text is displayed in. dwScreenBufferSize - Initial size of screen buffer, in rows and columns. nInputBufferSize - Initial size of input buffer, in events. dwWindowFlags - StdIn - On return, contains handle to stdin. StdOut - On return, contains handle to stdout. StdErr - On return, contains handle to stderr. ProcessData - On return, contains the initialized per-process data. Return Value: Note: The console handle table lock must be held when calling this routine. --*/ { PCONSOLE_INFORMATION Console; NTSTATUS Status; BOOL Success; // // allocate console data // Console = (PCONSOLE_INFORMATION)HeapAlloc(pConHeap, MAKE_TAG( CONSOLE_TAG ) | HEAP_ZERO_MEMORY, sizeof(CONSOLE_INFORMATION)); if (Console == NULL) { return STATUS_NO_MEMORY; } ConsoleHandles[IndexFromHandle(ConsoleHandle)] = Console; Console->Flags = WindowVisible ? 0 : CONSOLE_NO_WINDOW; Console->hIcon = ConsoleInfo->hIcon; Console->iIconId = ConsoleInfo->iIconId; Console->dwHotKey = ConsoleInfo->dwHotKey; Console->CP = OEMCP; Console->OutputCP = ConsoleOutputCP; Console->ReserveKeys = CONSOLE_NOSHORTCUTKEY; Console->ConsoleHandle = ConsoleHandle; Console->bIconInit = TRUE; Console->VerticalClientToWindow = VerticalClientToWindow; Console->HorizontalClientToWindow = HorizontalClientToWindow; // // must wait for window to be destroyed or client impersonation won't // work. // Status = NtDuplicateObject(NtCurrentProcess(), CONSOLE_CLIENTTHREADHANDLE(CSR_SERVER_QUERYCLIENTTHREAD()), NtCurrentProcess(), &Console->ClientThreadHandle, 0, FALSE, DUPLICATE_SAME_ACCESS ); if (!NT_SUCCESS(Status)) { goto ErrorExit5; } #if DBG // // Make sure the handle isn't protected so we can close it later // UnProtectHandle(Console->ClientThreadHandle); #endif // DBG InitializeListHead(&Console->OutputQueue); InitializeListHead(&Console->ProcessHandleList); InitializeListHead(&Console->ExeAliasList); Status = NtCreateEvent(&Console->InitEvents[INITIALIZATION_SUCCEEDED], EVENT_ALL_ACCESS, NULL, NotificationEvent, FALSE); if (!NT_SUCCESS(Status)) { goto ErrorExit4a; } Status = NtCreateEvent(&Console->InitEvents[INITIALIZATION_FAILED], EVENT_ALL_ACCESS, NULL, NotificationEvent, FALSE); if (!NT_SUCCESS(Status)) { goto ErrorExit4; } Status = RtlInitializeCriticalSection(&Console->ConsoleLock); if (!NT_SUCCESS(Status)) { goto ErrorExit3a; } InitializeConsoleCommandData(Console); // // initialize input buffer // Status = CreateInputBuffer(ConsoleInfo->nInputBufferSize, &Console->InputBuffer); if (!NT_SUCCESS(Status)) { goto ErrorExit3; } Console->Title = (PWCHAR)HeapAlloc(pConHeap,MAKE_TAG( TITLE_TAG ),TitleLength+sizeof(WCHAR)); if (Console->Title == NULL) { Status = STATUS_NO_MEMORY; goto ErrorExit2; } RtlCopyMemory(Console->Title,Title,TitleLength); Console->Title[TitleLength/sizeof(WCHAR)] = (WCHAR)0; // NULL terminate Console->TitleLength = TitleLength; Console->OriginalTitle = (PWCHAR)HeapAlloc(pConHeap,MAKE_TAG( TITLE_TAG ),TitleLength+sizeof(WCHAR)); if (Console->OriginalTitle == NULL) { Status = STATUS_NO_MEMORY; goto ErrorExit1; } RtlCopyMemory(Console->OriginalTitle,Title,TitleLength); Console->OriginalTitle[TitleLength/sizeof(WCHAR)] = (WCHAR)0; // NULL terminate Console->OriginalTitleLength = TitleLength; Status = NtCreateEvent(&Console->TerminationEvent, EVENT_ALL_ACCESS, NULL, NotificationEvent, FALSE); if (!NT_SUCCESS(Status)) { goto ErrorExit1a; } // // initialize screen buffer. we don't call OpenConsole to do this // because we need to specify the font, windowsize, etc. // Status = DoCreateScreenBuffer(Console, ConsoleInfo, Console->Title); if (!NT_SUCCESS(Status)) { goto ErrorExit1b; } Console->CurrentScreenBuffer = Console->ScreenBuffers; Status = InitializeIoHandleTable(Console, ProcessData, StdIn, StdOut, StdErr ); if (!NT_SUCCESS(Status)) { goto ErrorExit0; } // // map event handles // if (!MapHandle(ClientProcessHandle, Console->InitEvents[INITIALIZATION_SUCCEEDED], &ConsoleInfo->InitEvents[INITIALIZATION_SUCCEEDED] )) { Status = STATUS_NO_MEMORY; goto ErrorExit0; } if (!MapHandle(ClientProcessHandle, Console->InitEvents[INITIALIZATION_FAILED], &ConsoleInfo->InitEvents[INITIALIZATION_FAILED] )) { Status = STATUS_NO_MEMORY; goto ErrorExit0; } if (!MapHandle(ClientProcessHandle, Console->InputBuffer.InputWaitEvent, &ConsoleInfo->InputWaitHandle )) { Status = STATUS_NO_MEMORY; goto ErrorExit0; } Success = PostThreadMessage(dwConsoleThreadId, CM_CREATE_CONSOLE_WINDOW, (DWORD)Console, (LONG)ClientProcessHandle ); if (!Success) { KdPrint(("CONSRV: PostThreadMessage failed %d\n",GetLastError())); Status = STATUS_UNSUCCESSFUL; goto ErrorExit0; } return STATUS_SUCCESS; ErrorExit0: Console->ScreenBuffers->RefCount = 0; FreeScreenBuffer(Console->ScreenBuffers); ErrorExit1b: NtClose(Console->TerminationEvent); ErrorExit1a: HeapFree(pConHeap,0,Console->OriginalTitle); ErrorExit1: HeapFree(pConHeap,0,Console->Title); ErrorExit2: Console->InputBuffer.RefCount = 0; FreeInputBuffer(&Console->InputBuffer); ErrorExit3: RtlDeleteCriticalSection(&Console->ConsoleLock); ErrorExit3a: NtClose(Console->InitEvents[INITIALIZATION_FAILED]); ErrorExit4: NtClose(Console->InitEvents[INITIALIZATION_SUCCEEDED]); ErrorExit4a: NtClose(Console->ClientThreadHandle); ErrorExit5: HeapFree(pConHeap,0,Console); return Status; }
/*********************************************************************** * UninitializeCriticalSection (KERNEL32.@) */ void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit ) { RtlDeleteCriticalSection( crit ); }