/*********************************************************************** * server_init_thread * * Send an init thread request. Return 0 if OK. */ size_t server_init_thread( int unix_pid, int unix_tid, void *entry_point ) { int ret; int reply_pipe[2]; struct sigaction sig_act; size_t info_size; sig_act.sa_handler = SIG_IGN; sig_act.sa_flags = 0; sigemptyset( &sig_act.sa_mask ); /* ignore SIGPIPE so that we get an EPIPE error instead */ sigaction( SIGPIPE, &sig_act, NULL ); /* automatic child reaping to avoid zombies */ #ifdef SA_NOCLDWAIT sig_act.sa_flags |= SA_NOCLDWAIT; #endif sigaction( SIGCHLD, &sig_act, NULL ); /* create the server->client communication pipes */ if (pipe( reply_pipe ) == -1) server_protocol_perror( "pipe" ); if (pipe( ntdll_get_thread_data()->wait_fd ) == -1) server_protocol_perror( "pipe" ); wine_server_send_fd( reply_pipe[1] ); wine_server_send_fd( ntdll_get_thread_data()->wait_fd[1] ); ntdll_get_thread_data()->reply_fd = reply_pipe[0]; close( reply_pipe[1] ); /* set close on exec flag */ fcntl( ntdll_get_thread_data()->reply_fd, F_SETFD, 1 ); fcntl( ntdll_get_thread_data()->wait_fd[0], F_SETFD, 1 ); fcntl( ntdll_get_thread_data()->wait_fd[1], F_SETFD, 1 ); SERVER_START_REQ( init_thread ) { req->unix_pid = unix_pid; req->unix_tid = unix_tid; req->teb = wine_server_client_ptr( NtCurrentTeb() ); req->peb = wine_server_client_ptr( NtCurrentTeb()->Peb ); req->entry = wine_server_client_ptr( entry_point ); req->reply_fd = reply_pipe[1]; req->wait_fd = ntdll_get_thread_data()->wait_fd[1]; req->debug_level = (TRACE_ON(server) != 0); ret = wine_server_call( req ); NtCurrentTeb()->ClientId.UniqueProcess = ULongToHandle(reply->pid); NtCurrentTeb()->ClientId.UniqueThread = ULongToHandle(reply->tid); info_size = reply->info_size; server_start_time = reply->server_start; } SERVER_END_REQ; if (ret) server_protocol_error( "init_thread failed with status %x\n", ret ); return info_size; }
static BOOLEAN NTAPI PhpPreviousInstancesCallback( _In_ PPH_STRINGREF Name, _In_ PPH_STRINGREF TypeName, _In_opt_ PVOID Context ) { ULONG64 processId64; PH_STRINGREF firstPart; PH_STRINGREF secondPart; if ( PhStartsWithStringRef2(Name, L"PhMutant_", TRUE) && PhSplitStringRefAtChar(Name, L'_', &firstPart, &secondPart) && PhStringToInteger64(&secondPart, 10, &processId64) ) { HANDLE processHandle; if (NT_SUCCESS(PhOpenProcess( &processHandle, SYNCHRONIZE | PROCESS_TERMINATE, ULongToHandle((ULONG)processId64) ))) { NtTerminateProcess(processHandle, 1); NtClose(processHandle); } } return TRUE; }
static void initialize_display_settings( HWND desktop ) { static const WCHAR display_device_guid_propW[] = { '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_', 'd','e','v','i','c','e','_','g','u','i','d',0 }; GUID guid; RPC_CSTR guid_str; ATOM guid_atom; DEVMODEW dmW; UuidCreate( &guid ); UuidToStringA( &guid, &guid_str ); WINE_TRACE( "display guid %s\n", guid_str ); guid_atom = GlobalAddAtomA( (LPCSTR)guid_str ); SetPropW( desktop, display_device_guid_propW, ULongToHandle(guid_atom) ); RpcStringFreeA( &guid_str ); /* Store current display mode in the registry */ if (EnumDisplaySettingsExW( NULL, ENUM_CURRENT_SETTINGS, &dmW, 0 )) { WINE_TRACE( "Current display mode %ux%u %u bpp %u Hz\n", dmW.dmPelsWidth, dmW.dmPelsHeight, dmW.dmBitsPerPel, dmW.dmDisplayFrequency ); ChangeDisplaySettingsExW( NULL, &dmW, 0, CDS_GLOBAL | CDS_NORESET | CDS_UPDATEREGISTRY, NULL ); } }
HRESULT STDMETHODCALLTYPE DnCLRDataTarget_GetThreadContext( __in ICLRDataTarget *This, __in ULONG32 threadID, __in ULONG32 contextFlags, __in ULONG32 contextSize, __out BYTE *context ) { NTSTATUS status; HANDLE threadHandle; CONTEXT buffer; if (contextSize < sizeof(CONTEXT)) return E_INVALIDARG; memset(&buffer, 0, sizeof(CONTEXT)); buffer.ContextFlags = contextFlags; if (NT_SUCCESS(status = PhOpenThread(&threadHandle, THREAD_GET_CONTEXT, ULongToHandle(threadID)))) { status = PhGetThreadContext(threadHandle, &buffer); NtClose(threadHandle); } if (NT_SUCCESS(status)) { memcpy(context, &buffer, sizeof(CONTEXT)); return S_OK; } else { return HRESULT_FROM_WIN32(RtlNtStatusToDosError(status)); } }
/*********************************************************************** * USER_CheckNotLock * * Make sure that we don't hold the user lock. */ void USER_CheckNotLock(void) { if (user_section.OwningThread == ULongToHandle(GetCurrentThreadId()) && user_section.RecursionCount) { ERR( "BUG: holding USER lock\n" ); DebugBreak(); } }
static int wine_pthread_mutex_unlock(pthread_mutex_t *mutex) { CRITICAL_SECTION *crit = ((wine_mutex)mutex)->critsect; if (!crit) return 0; if (crit->OwningThread != ULongToHandle(GetCurrentThreadId())) return EPERM; RtlLeaveCriticalSection( crit ); return 0; }
// Set the drag image cursor and text according to the drop effect and redraw. // Cursor and description text (if enabled) are shown according to the passed drop effect // when dwEffect is valid and a DropDescription data object does not exist or has the // DROPIMAGE_INVALID image type set. // // DDWM_SETCURSOR (WM_USER + 2) // WPARAM: Cursor type // 0 = Get type and text from DropDescription data object (behaviour is identical to DDWM_UPDATEWINDOW message) // 1 = Can't drop (Stop sign) // 2 = Move (Arrow) // 3 = Copy (Plus sign) // 4 = Link (Curved arrow) // LPARAM: 0 // Set the drag image cursor and use the associated default text if no drop description // present or it has the invalid image type. // NOTE: When a drop description object is present and has not the DROPIMAGE_INVALID type // set, it is used regardless of the WPARAM value. bool COleDropSourceEx::SetDragImageCursor(DROPEFFECT dwEffect) { // Stored data is always a DWORD even with 64-bit apps. HWND hWnd = (HWND)ULongToHandle(CDragDropHelper::GetGlobalDataDWord(m_pIDataObj, _T("DragWindow"))); if (hWnd) { WPARAM wParam = 0; // Use DropDescription to get type and optional text switch (dwEffect & ~DROPEFFECT_SCROLL) { case DROPEFFECT_NONE : wParam = 1; break; case DROPEFFECT_COPY : wParam = 3; break; // The order is not as for DROPEEFECT values! case DROPEFFECT_MOVE : wParam = 2; break; case DROPEFFECT_LINK : wParam = 4; break; } ::SendMessage(hWnd, DDWM_SETCURSOR, wParam, 0); } return NULL != hWnd; }
/* * CreateTreeView - creates a tree view control. * Returns the handle to the new control if successful, or NULL otherwise. * hwndParent - handle to the control's parent window. */ HWND CreateTreeView(HWND hwndParent, LPWSTR pHostName, UINT id) { RECT rcClient; HWND hwndTV; WCHAR TreeView[] = {'T','r','e','e',' ','V','i','e','w',0}; /* Get the dimensions of the parent window's client area, and create the tree view control. */ GetClientRect(hwndParent, &rcClient); hwndTV = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW, TreeView, WS_VISIBLE | WS_CHILD | WS_TABSTOP | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_EDITLABELS, 0, 0, rcClient.right, rcClient.bottom, hwndParent, ULongToHandle(id), hInst, NULL); SendMessageW(hwndTV, TVM_SETUNICODEFORMAT, TRUE, 0); /* Initialize the image list, and add items to the control. */ if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pHostName)) { DestroyWindow(hwndTV); return NULL; } return hwndTV; }
static void AddTextButton(HWND hRebarWnd, UINT string, UINT command, UINT id) { REBARBANDINFOW rb; HINSTANCE hInstance = GetModuleHandleW(0); WCHAR text[MAX_STRING_LEN]; HWND hButton; LoadStringW(hInstance, string, text, MAX_STRING_LEN); hButton = CreateWindowW(WC_BUTTONW, text, WS_VISIBLE | WS_CHILD, 5, 5, 100, 15, hRebarWnd, ULongToHandle(command), hInstance, NULL); rb.cbSize = REBARBANDINFOW_V6_SIZE; rb.fMask = RBBIM_SIZE | RBBIM_CHILDSIZE | RBBIM_STYLE | RBBIM_CHILD | RBBIM_IDEALSIZE | RBBIM_ID; rb.fStyle = RBBS_NOGRIPPER | RBBS_VARIABLEHEIGHT; rb.hwndChild = hButton; rb.cyChild = rb.cyMinChild = 22; rb.cx = rb.cxMinChild = 90; rb.cxIdeal = 100; rb.wID = id; SendMessageW(hRebarWnd, RB_INSERTBANDW, -1, (LPARAM)&rb); }
/*********************************************************************** * OpenThread [KERNEL32.@] Retrieves a handle to a thread from its thread id */ HANDLE WINAPI OpenThread( DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId ) { NTSTATUS status; HANDLE handle; OBJECT_ATTRIBUTES attr; CLIENT_ID cid; attr.Length = sizeof(attr); attr.RootDirectory = 0; attr.Attributes = bInheritHandle ? OBJ_INHERIT : 0; attr.ObjectName = NULL; attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; cid.UniqueProcess = 0; /* FIXME */ cid.UniqueThread = ULongToHandle(dwThreadId); status = NtOpenThread( &handle, dwDesiredAccess, &attr, &cid ); if (status) { SetLastError( RtlNtStatusToDosError(status) ); handle = 0; } return handle; }
/***************************************************************** * CreateCaret (USER32.@) */ BOOL WINAPI CreateCaret( HWND hwnd, HBITMAP bitmap, INT width, INT height ) { BOOL ret; RECT r; int old_state = 0; int hidden = 0; HBITMAP hBmp = 0; HWND prev = 0; TRACE("hwnd=%p\n", hwnd); if (!hwnd) return FALSE; if (bitmap && (bitmap != (HBITMAP)1)) { BITMAP bmp; if (!GetObjectA( bitmap, sizeof(bmp), &bmp )) return FALSE; width = bmp.bmWidth; height = bmp.bmHeight; bmp.bmBits = NULL; hBmp = CreateBitmapIndirect(&bmp); if (hBmp) { /* copy the bitmap */ LPBYTE buf = HeapAlloc(GetProcessHeap(), 0, bmp.bmWidthBytes * bmp.bmHeight); GetBitmapBits(bitmap, bmp.bmWidthBytes * bmp.bmHeight, buf); SetBitmapBits(hBmp, bmp.bmWidthBytes * bmp.bmHeight, buf); HeapFree(GetProcessHeap(), 0, buf); } } else { HDC hdc; if (!width) width = GetSystemMetrics(SM_CXBORDER); if (!height) height = GetSystemMetrics(SM_CYBORDER); /* create the uniform bitmap on the fly */ hdc = GetDC(hwnd); if (hdc) { HDC hMemDC = CreateCompatibleDC(hdc); if (hMemDC) { if ((hBmp = CreateCompatibleBitmap(hMemDC, width, height ))) { HBITMAP hPrevBmp = SelectObject(hMemDC, hBmp); SetRect( &r, 0, 0, width, height ); FillRect(hMemDC, &r, ULongToHandle((bitmap ? COLOR_GRAYTEXT : COLOR_WINDOW) + 1)); SelectObject(hMemDC, hPrevBmp); } DeleteDC(hMemDC); } ReleaseDC(hwnd, hdc); } } if (!hBmp) return FALSE; SERVER_START_REQ( set_caret_window ) { req->handle = wine_server_user_handle( hwnd ); req->width = width; req->height = height; if ((ret = !wine_server_call_err( req ))) { prev = wine_server_ptr_handle( reply->previous ); r.left = reply->old_rect.left; r.top = reply->old_rect.top; r.right = reply->old_rect.right; r.bottom = reply->old_rect.bottom; old_state = reply->old_state; hidden = reply->old_hide; } } SERVER_END_REQ; if (!ret) return FALSE; if (prev && !hidden) /* hide the previous one */ { /* FIXME: won't work if prev belongs to a different process */ KillSystemTimer( prev, TIMERID ); if (old_state) CARET_DisplayCaret( prev, &r ); } if (Caret.hBmp) DeleteObject( Caret.hBmp ); Caret.hBmp = hBmp; Caret.timeout = GetProfileIntA( "windows", "CursorBlinkRate", 500 ); return TRUE; }
/*********************************************************************** * server_init_thread * * Send an init thread request. Return 0 if OK. */ size_t server_init_thread( void *entry_point ) { static const int is_win64 = (sizeof(void *) > sizeof(int)); const char *arch = getenv( "WINEARCH" ); int ret; int reply_pipe[2]; struct sigaction sig_act; size_t info_size; sig_act.sa_handler = SIG_IGN; sig_act.sa_flags = 0; sigemptyset( &sig_act.sa_mask ); /* ignore SIGPIPE so that we get an EPIPE error instead */ sigaction( SIGPIPE, &sig_act, NULL ); /* create the server->client communication pipes */ if (server_pipe( reply_pipe ) == -1) server_protocol_perror( "pipe" ); if (server_pipe( ntdll_get_thread_data()->wait_fd ) == -1) server_protocol_perror( "pipe" ); wine_server_send_fd( reply_pipe[1] ); wine_server_send_fd( ntdll_get_thread_data()->wait_fd[1] ); ntdll_get_thread_data()->reply_fd = reply_pipe[0]; close( reply_pipe[1] ); SERVER_START_REQ( init_thread ) { req->unix_pid = getpid(); req->unix_tid = get_unix_tid(); req->teb = wine_server_client_ptr( NtCurrentTeb() ); req->entry = wine_server_client_ptr( entry_point ); req->reply_fd = reply_pipe[1]; req->wait_fd = ntdll_get_thread_data()->wait_fd[1]; req->debug_level = (TRACE_ON(server) != 0); req->cpu = client_cpu; ret = wine_server_call( req ); NtCurrentTeb()->ClientId.UniqueProcess = ULongToHandle(reply->pid); NtCurrentTeb()->ClientId.UniqueThread = ULongToHandle(reply->tid); info_size = reply->info_size; server_start_time = reply->server_start; server_cpus = reply->all_cpus; } SERVER_END_REQ; is_wow64 = !is_win64 && (server_cpus & (1 << CPU_x86_64)) != 0; ntdll_get_thread_data()->wow64_redir = is_wow64; switch (ret) { case STATUS_SUCCESS: if (arch) { if (!strcmp( arch, "win32" ) && (is_win64 || is_wow64)) fatal_error( "WINEARCH set to win32 but '%s' is a 64-bit installation.\n", wine_get_config_dir() ); if (!strcmp( arch, "win64" ) && !is_win64 && !is_wow64) fatal_error( "WINEARCH set to win64 but '%s' is a 32-bit installation.\n", wine_get_config_dir() ); } return info_size; case STATUS_NOT_REGISTRY_FILE: fatal_error( "'%s' is a 32-bit installation, it cannot support 64-bit applications.\n", wine_get_config_dir() ); case STATUS_NOT_SUPPORTED: if (is_win64) fatal_error( "wineserver is 32-bit, it cannot support 64-bit applications.\n" ); else fatal_error( "'%s' is a 64-bit installation, it cannot be used with a 32-bit wineserver.\n", wine_get_config_dir() ); default: server_protocol_error( "init_thread failed with status %x\n", ret ); } }
//----------------------------------------------------------------------------- // Name: Initialize3DEnvironment() // Desc: Usually this function is not overridden. Here's what this function does: // - Sets the windowed flag to be either windowed or fullscreen // - Sets parameters for z-buffer depth and back buffer // - Creates the D3D device // - Sets the window position (if windowed, that is) // - Makes some determinations as to the abilites of the driver (HAL, etc) // - Sets up some cursor stuff // - Calls InitDeviceObjects() // - Calls RestoreDeviceObjects() // - If all goes well, m_bActive is set to TRUE, and the function returns // - Otherwise, initialization is reattempted using the reference device //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::Initialize3DEnvironment() { HRESULT hr; D3DAdapterInfo* pAdapterInfo = m_d3dSettings.PAdapterInfo(); D3DDeviceInfo* pDeviceInfo = m_d3dSettings.PDeviceInfo(); m_bWindowed = m_d3dSettings.IsWindowed; // Prepare window for possible windowed/fullscreen change AdjustWindowForChange(); // Set up the presentation parameters BuildPresentParamsFromSettings(); if( pDeviceInfo->Caps.PrimitiveMiscCaps & D3DPMISCCAPS_NULLREFERENCE ) { // Warn user about null ref device that can't render anything DisplayErrorMsg( D3DAPPERR_NULLREFDEVICE, 0 ); } DWORD behaviorFlags; if (m_d3dSettings.GetVertexProcessingType() == SOFTWARE_VP) behaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; else if (m_d3dSettings.GetVertexProcessingType() == MIXED_VP) behaviorFlags = D3DCREATE_MIXED_VERTEXPROCESSING; else if (m_d3dSettings.GetVertexProcessingType() == HARDWARE_VP) behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; else if (m_d3dSettings.GetVertexProcessingType() == PURE_HARDWARE_VP) behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE; else behaviorFlags = 0; // TODO: throw exception // Add multithreaded flag if requested by app if( m_bCreateMultithreadDevice ) behaviorFlags |= D3DCREATE_MULTITHREADED; // Create the device hr = m_pD3D->CreateDevice( m_d3dSettings.AdapterOrdinal(), pDeviceInfo->DevType, m_hWndFocus, behaviorFlags, &m_d3dpp, &m_pd3dDevice ); if( SUCCEEDED(hr) ) { // When moving from fullscreen to windowed mode, it is important to // adjust the window size after recreating the device rather than // beforehand to ensure that you get the window size you want. For // example, when switching from 640x480 fullscreen to windowed with // a 1000x600 window on a 1024x768 desktop, it is impossible to set // the window size to 1000x600 until after the display mode has // changed to 1024x768, because windows cannot be larger than the // desktop. if( m_bWindowed ) { SetWindowPos( m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top, ( m_rcWindowBounds.right - m_rcWindowBounds.left ), ( m_rcWindowBounds.bottom - m_rcWindowBounds.top ), SWP_HIDEWINDOW ); } // Store device Caps m_pd3dDevice->GetDeviceCaps( &m_d3dCaps ); m_dwCreateFlags = behaviorFlags; // Store device description if( pDeviceInfo->DevType == D3DDEVTYPE_REF ) lstrcpy( m_strDeviceStats, TEXT("REF") ); else if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcpy( m_strDeviceStats, TEXT("HAL") ); else if( pDeviceInfo->DevType == D3DDEVTYPE_SW ) lstrcpy( m_strDeviceStats, TEXT("SW") ); if( behaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING && behaviorFlags & D3DCREATE_PUREDEVICE ) { if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcat( m_strDeviceStats, TEXT(" (pure hw vp)") ); else lstrcat( m_strDeviceStats, TEXT(" (simulated pure hw vp)") ); } else if( behaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING ) { if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcat( m_strDeviceStats, TEXT(" (hw vp)") ); else lstrcat( m_strDeviceStats, TEXT(" (simulated hw vp)") ); } else if( behaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING ) { if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcat( m_strDeviceStats, TEXT(" (mixed vp)") ); else lstrcat( m_strDeviceStats, TEXT(" (simulated mixed vp)") ); } else if( behaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING ) { lstrcat( m_strDeviceStats, TEXT(" (sw vp)") ); } if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) { // Be sure not to overflow m_strDeviceStats when appending the adapter // description, since it can be long. Note that the adapter description // is initially CHAR and must be converted to TCHAR. lstrcat( m_strDeviceStats, TEXT(": ") ); const int cchDesc = sizeof(pAdapterInfo->AdapterIdentifier.Description); TCHAR szDescription[cchDesc]; DXUtil_ConvertAnsiStringToGenericCch( szDescription, pAdapterInfo->AdapterIdentifier.Description, cchDesc ); int maxAppend = sizeof(m_strDeviceStats) / sizeof(TCHAR) - lstrlen( m_strDeviceStats ) - 1; _tcsncat( m_strDeviceStats, szDescription, maxAppend ); } // Store render target surface desc LPDIRECT3DSURFACE9 pBackBuffer = NULL; m_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); pBackBuffer->GetDesc( &m_d3dsdBackBuffer ); pBackBuffer->Release(); // Set up the fullscreen cursor if( m_bShowCursorWhenFullscreen && !m_bWindowed ) { HCURSOR hCursor; #ifdef _WIN64 hCursor = (HCURSOR)GetClassLongPtr( m_hWnd, GCLP_HCURSOR ); #else hCursor = (HCURSOR)ULongToHandle( GetClassLong( m_hWnd, GCL_HCURSOR ) ); #endif D3DUtil_SetDeviceCursor( m_pd3dDevice, hCursor, true ); m_pd3dDevice->ShowCursor( true ); } // Confine cursor to fullscreen window if( m_bClipCursorWhenFullscreen ) { if (!m_bWindowed ) { RECT rcWindow; GetWindowRect( m_hWnd, &rcWindow ); ClipCursor( &rcWindow ); } else { ClipCursor( NULL ); } } // Initialize the app's device-dependent objects hr = InitDeviceObjects(); if( FAILED(hr) ) { DeleteDeviceObjects(); } else { m_bDeviceObjectsInited = true; hr = RestoreDeviceObjects(); if( FAILED(hr) ) { InvalidateDeviceObjects(); } else { m_bDeviceObjectsRestored = true; return S_OK; } } // Cleanup before we try again Cleanup3DEnvironment(); } // If that failed, fall back to the reference rasterizer if( hr != D3DAPPERR_MEDIANOTFOUND && hr != HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) && pDeviceInfo->DevType == D3DDEVTYPE_HAL ) { if (FindBestWindowedMode(false, true)) { m_bWindowed = true; AdjustWindowForChange(); // Make sure main window isn't topmost, so error message is visible SetWindowPos( m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top, ( m_rcWindowBounds.right - m_rcWindowBounds.left ), ( m_rcWindowBounds.bottom - m_rcWindowBounds.top ), SWP_SHOWWINDOW ); // Let the user know we are switching from HAL to the reference rasterizer DisplayErrorMsg( hr, MSGWARN_SWITCHEDTOREF ); hr = Initialize3DEnvironment(); } } return hr; }
VOID NTAPI RefreshSandboxieInfo( __in_opt PVOID Context, __in BOOLEAN TimerOrWaitFired ) { LONG index; WCHAR boxName[34]; ULONG pids[512]; PBOX_INFO boxInfo; if (!SbieApi_QueryBoxPath || !SbieApi_EnumBoxes || !SbieApi_EnumProcessEx) return; PhAcquireQueuedLockExclusive(&BoxedProcessesLock); PhClearHashtable(BoxedProcessesHashtable); BoxInfoCount = 0; index = -1; while ((index = SbieApi_EnumBoxes(index, boxName)) != -1) { if (SbieApi_EnumProcessEx(boxName, TRUE, 0, pids) == 0) { ULONG count; PULONG pid; count = pids[0]; pid = &pids[1]; while (count != 0) { BOXED_PROCESS boxedProcess; boxedProcess.ProcessId = ULongToHandle(*pid); memcpy(boxedProcess.BoxName, boxName, sizeof(boxName)); PhAddEntryHashtable(BoxedProcessesHashtable, &boxedProcess); count--; pid++; } } if (BoxInfoCount < 16) { ULONG filePathLength = 0; ULONG keyPathLength = 0; ULONG ipcPathLength = 0; boxInfo = &BoxInfo[BoxInfoCount++]; memcpy(boxInfo->BoxName, boxName, sizeof(boxName)); SbieApi_QueryBoxPath( boxName, NULL, NULL, NULL, &filePathLength, &keyPathLength, &ipcPathLength ); if (ipcPathLength < sizeof(boxInfo->IpcRootBuffer)) { boxInfo->IpcRootBuffer[0] = 0; SbieApi_QueryBoxPath( boxName, NULL, NULL, boxInfo->IpcRootBuffer, NULL, NULL, &ipcPathLength ); if (boxInfo->IpcRootBuffer[0] != 0) { PhInitializeStringRef(&boxInfo->IpcRoot, boxInfo->IpcRootBuffer); } else { BoxInfoCount--; } } else { BoxInfoCount--; } } } BoxedProcessesUpdated = TRUE; PhReleaseQueuedLockExclusive(&BoxedProcessesLock); }
/*********************************************************************** * server_init_thread * * Send an init thread request. Return 0 if OK. */ size_t server_init_thread( int unix_pid, int unix_tid, void *entry_point ) { int version, ret; int reply_pipe[2]; struct sigaction sig_act; size_t info_size; sig_act.sa_handler = SIG_IGN; sig_act.sa_flags = 0; sigemptyset( &sig_act.sa_mask ); /* ignore SIGPIPE so that we get an EPIPE error instead */ sigaction( SIGPIPE, &sig_act, NULL ); /* automatic child reaping to avoid zombies */ #ifdef SA_NOCLDWAIT sig_act.sa_flags |= SA_NOCLDWAIT; #endif sigaction( SIGCHLD, &sig_act, NULL ); /* create the server->client communication pipes */ if (pipe( reply_pipe ) == -1) server_protocol_perror( "pipe" ); if (pipe( ntdll_get_thread_data()->wait_fd ) == -1) server_protocol_perror( "pipe" ); wine_server_send_fd( reply_pipe[1] ); wine_server_send_fd( ntdll_get_thread_data()->wait_fd[1] ); ntdll_get_thread_data()->reply_fd = reply_pipe[0]; close( reply_pipe[1] ); /* set close on exec flag */ fcntl( ntdll_get_thread_data()->reply_fd, F_SETFD, 1 ); fcntl( ntdll_get_thread_data()->wait_fd[0], F_SETFD, 1 ); fcntl( ntdll_get_thread_data()->wait_fd[1], F_SETFD, 1 ); SERVER_START_REQ( init_thread ) { req->unix_pid = unix_pid; req->unix_tid = unix_tid; req->teb = NtCurrentTeb(); req->peb = NtCurrentTeb()->Peb; req->entry = entry_point; req->ldt_copy = &wine_ldt_copy; req->reply_fd = reply_pipe[1]; req->wait_fd = ntdll_get_thread_data()->wait_fd[1]; req->debug_level = (TRACE_ON(server) != 0); ret = wine_server_call( req ); NtCurrentTeb()->ClientId.UniqueProcess = ULongToHandle(reply->pid); NtCurrentTeb()->ClientId.UniqueThread = ULongToHandle(reply->tid); info_size = reply->info_size; version = reply->version; server_start_time = reply->server_start; } SERVER_END_REQ; if (ret) server_protocol_error( "init_thread failed with status %x\n", ret ); if (version != SERVER_PROTOCOL_VERSION) server_protocol_error( "version mismatch %d/%d.\n" "Your %s binary was not upgraded correctly,\n" "or you have an older one somewhere in your PATH.\n" "Or maybe the wrong wineserver is still running?\n", version, SERVER_PROTOCOL_VERSION, (version > SERVER_PROTOCOL_VERSION) ? "wine" : "wineserver" ); return info_size; }
NTSTATUS ConSrvInsertObject(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PHANDLE Handle, IN PCONSOLE_IO_OBJECT Object, IN ULONG Access, IN BOOLEAN Inheritable, IN ULONG ShareMode) { #define IO_HANDLES_INCREMENT 2 * 3 ULONG i = 0; PCONSOLE_IO_HANDLE Block; // NOTE: Commented out because calling code always lock HandleTableLock before. // RtlEnterCriticalSection(&ProcessData->HandleTableLock); ASSERT( (ProcessData->HandleTable == NULL && ProcessData->HandleTableSize == 0) || (ProcessData->HandleTable != NULL && ProcessData->HandleTableSize != 0) ); if (ProcessData->HandleTable) { for (i = 0; i < ProcessData->HandleTableSize; i++) { if (ProcessData->HandleTable[i].Object == NULL) break; } } if (i >= ProcessData->HandleTableSize) { /* Allocate a new handles table */ Block = ConsoleAllocHeap(HEAP_ZERO_MEMORY, (ProcessData->HandleTableSize + IO_HANDLES_INCREMENT) * sizeof(CONSOLE_IO_HANDLE)); if (Block == NULL) { // RtlLeaveCriticalSection(&ProcessData->HandleTableLock); return STATUS_UNSUCCESSFUL; } /* If we previously had a handles table, free it and use the new one */ if (ProcessData->HandleTable) { /* Copy the handles from the old table to the new one */ RtlCopyMemory(Block, ProcessData->HandleTable, ProcessData->HandleTableSize * sizeof(CONSOLE_IO_HANDLE)); ConsoleFreeHeap(ProcessData->HandleTable); } ProcessData->HandleTable = Block; ProcessData->HandleTableSize += IO_HANDLES_INCREMENT; } ProcessData->HandleTable[i].Object = Object; ProcessData->HandleTable[i].Access = Access; ProcessData->HandleTable[i].Inheritable = Inheritable; ProcessData->HandleTable[i].ShareMode = ShareMode; AdjustHandleCounts(&ProcessData->HandleTable[i], +1); *Handle = ULongToHandle((i << 2) | 0x3); // RtlLeaveCriticalSection(&ProcessData->HandleTableLock); return STATUS_SUCCESS; }
static HANDLE modify_handle(HANDLE handle, DWORD modify) { DWORD tmp = HandleToULong(handle); tmp |= modify; return ULongToHandle(tmp); }
_Check_return_ BOOLEAN ProcessHackerShutdown( VOID ) { HWND WindowHandle; WindowHandle = FindWindow(L"ProcessHacker", NULL); if (WindowHandle) { HANDLE processHandle; ULONG processID = 0; ULONG threadID = GetWindowThreadProcessId(WindowHandle, &processID); SendMessageTimeout(WindowHandle, WM_QUIT, 0, 0, SMTO_ABORTIFHUNG | SMTO_BLOCK, 5000, NULL); if (NT_SUCCESS(PhOpenProcess(&processHandle, SYNCHRONIZE | PROCESS_TERMINATE, ULongToHandle(processID)))) { //PostMessage(WindowHandle, WM_QUIT, 0, 0); // Wait on the process handle, if we timeout, kill it. //if (WaitForSingleObject(processHandle, 10000) != WAIT_OBJECT_0) NtTerminateProcess(processHandle, 1); NtClose(processHandle); } } return FALSE; }
/*********************************************************************** * RtlCreateUserThread (NTDLL.@) */ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR *descr, BOOLEAN suspended, PVOID stack_addr, SIZE_T stack_reserve, SIZE_T stack_commit, PRTL_THREAD_START_ROUTINE start, void *param, HANDLE *handle_ptr, CLIENT_ID *id ) { sigset_t sigset; pthread_t pthread_id; pthread_attr_t attr; struct ntdll_thread_data *thread_data; struct startup_info *info = NULL; HANDLE handle = 0, actctx = 0; TEB *teb = NULL; DWORD tid = 0; int request_pipe[2]; NTSTATUS status; if (process != NtCurrentProcess()) { apc_call_t call; apc_result_t result; memset( &call, 0, sizeof(call) ); call.create_thread.type = APC_CREATE_THREAD; call.create_thread.func = wine_server_client_ptr( start ); call.create_thread.arg = wine_server_client_ptr( param ); call.create_thread.reserve = stack_reserve; call.create_thread.commit = stack_commit; call.create_thread.suspend = suspended; status = server_queue_process_apc( process, &call, &result ); if (status != STATUS_SUCCESS) return status; if (result.create_thread.status == STATUS_SUCCESS) { if (id) id->UniqueThread = ULongToHandle(result.create_thread.tid); if (handle_ptr) *handle_ptr = wine_server_ptr_handle( result.create_thread.handle ); else NtClose( wine_server_ptr_handle( result.create_thread.handle )); } return result.create_thread.status; } if (server_pipe( request_pipe ) == -1) return STATUS_TOO_MANY_OPENED_FILES; wine_server_send_fd( request_pipe[0] ); SERVER_START_REQ( new_thread ) { req->access = THREAD_ALL_ACCESS; req->attributes = 0; /* FIXME */ req->suspend = suspended; req->request_fd = request_pipe[0]; if (!(status = wine_server_call( req ))) { handle = wine_server_ptr_handle( reply->handle ); tid = reply->tid; } close( request_pipe[0] ); } SERVER_END_REQ; if (status) { close( request_pipe[1] ); return status; } pthread_sigmask( SIG_BLOCK, &server_block_set, &sigset ); if ((status = signal_alloc_thread( &teb ))) goto error; teb->Peb = NtCurrentTeb()->Peb; teb->ClientId.UniqueProcess = ULongToHandle(GetCurrentProcessId()); teb->ClientId.UniqueThread = ULongToHandle(tid); teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer; teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer); /* create default activation context frame for new thread */ RtlGetActiveActivationContext(&actctx); if (actctx) { RTL_ACTIVATION_CONTEXT_STACK_FRAME *frame; frame = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(*frame)); frame->Previous = NULL; frame->ActivationContext = actctx; frame->Flags = 0; teb->ActivationContextStack.ActiveFrame = frame; RtlAddRefActivationContext(actctx); } info = (struct startup_info *)(teb + 1); info->teb = teb; info->entry_point = start; info->entry_arg = param; thread_data = (struct ntdll_thread_data *)teb->SpareBytes1; thread_data->request_fd = request_pipe[1]; thread_data->reply_fd = -1; thread_data->wait_fd[0] = -1; thread_data->wait_fd[1] = -1; if ((status = virtual_alloc_thread_stack( teb, stack_reserve, stack_commit ))) goto error; pthread_attr_init( &attr ); pthread_attr_setstack( &attr, teb->DeallocationStack, (char *)teb->Tib.StackBase - (char *)teb->DeallocationStack ); pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ); /* force creating a kernel thread */ interlocked_xchg_add( &nb_threads, 1 ); if (pthread_create( &pthread_id, &attr, (void * (*)(void *))start_thread, info )) { interlocked_xchg_add( &nb_threads, -1 ); pthread_attr_destroy( &attr ); status = STATUS_NO_MEMORY; goto error; } pthread_attr_destroy( &attr ); pthread_sigmask( SIG_SETMASK, &sigset, NULL ); if (id) id->UniqueThread = ULongToHandle(tid); if (handle_ptr) *handle_ptr = handle; else NtClose( handle ); return STATUS_SUCCESS; error: if (teb) signal_free_thread( teb ); if (handle) NtClose( handle ); pthread_sigmask( SIG_SETMASK, &sigset, NULL ); close( request_pipe[1] ); return status; }
HRESULT WINAPI ObjectFromLresult( LRESULT result, REFIID riid, WPARAM wParam, void **ppObject ) { WCHAR atom_str[sizeof(lresult_atom_prefix)/sizeof(WCHAR)+3*8+3]; HANDLE server_proc, server_mapping, mapping; DWORD proc_id, size; IStream *stream; HGLOBAL data; void *view; HRESULT hr; WCHAR *p; TRACE("%ld %s %ld %p\n", result, debugstr_guid(riid), wParam, ppObject ); if(wParam) FIXME("unsupported wParam = %lx\n", wParam); if(!ppObject) return E_INVALIDARG; *ppObject = NULL; if(result != (ATOM)result) return E_FAIL; if(!GlobalGetAtomNameW(result, atom_str, sizeof(atom_str)/sizeof(WCHAR))) return E_FAIL; if(memcmp(atom_str, lresult_atom_prefix, sizeof(lresult_atom_prefix))) return E_FAIL; p = atom_str + sizeof(lresult_atom_prefix)/sizeof(WCHAR); proc_id = strtoulW(p, &p, 16); if(*p != ':') return E_FAIL; server_mapping = ULongToHandle( strtoulW(p+1, &p, 16) ); if(*p != ':') return E_FAIL; size = strtoulW(p+1, &p, 16); if(*p != 0) return E_FAIL; server_proc = OpenProcess(PROCESS_DUP_HANDLE, FALSE, proc_id); if(!server_proc) return E_FAIL; if(!DuplicateHandle(server_proc, server_mapping, GetCurrentProcess(), &mapping, 0, FALSE, DUPLICATE_CLOSE_SOURCE|DUPLICATE_SAME_ACCESS)) return E_FAIL; CloseHandle(server_proc); GlobalDeleteAtom(result); view = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0); CloseHandle(mapping); if(!view) return E_FAIL; data = GlobalAlloc(GMEM_FIXED, size); if(!data) { UnmapViewOfFile(view); return E_OUTOFMEMORY; } memcpy(data, view, size); UnmapViewOfFile(view); hr = CreateStreamOnHGlobal(data, TRUE, &stream); if(FAILED(hr)) { GlobalFree(data); return hr; } hr = CoUnmarshalInterface(stream, riid, ppObject); IStream_Release(stream); return hr; }