mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[msvc] this commit is required for a multithreaded program to work with CRT in Visual C++
Signed-off-by: germanaizek <GermanAizek@yandex.ru>
This commit is contained in:
		
							parent
							
								
									3407d3d5f4
								
							
						
					
					
						commit
						c284f8f333
					
				
					 9 changed files with 126 additions and 3 deletions
				
			
		|  | @ -1134,7 +1134,11 @@ DWORD WINAPI SumThread(void* param) | |||
| 	int num_checksums = CHECKSUM_MAX - (enable_extra_hashes ? 0 : 1); | ||||
| 
 | ||||
| 	if ((image_path == NULL) || (thread_affinity == NULL)) | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 		_endthreadex(r); | ||||
| #else | ||||
| 		ExitThread(r); | ||||
| #endif | ||||
| 
 | ||||
| 	uprintf("\r\nComputing checksum for '%s'...", image_path); | ||||
| 
 | ||||
|  | @ -1155,7 +1159,11 @@ DWORD WINAPI SumThread(void* param) | |||
| 			uprintf("Unable to create checksum thread event: %s", WindowsErrorString()); | ||||
| 			goto out; | ||||
| 		} | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 		sum_thread[i] = (HANDLE)_beginthreadex(NULL, 0, &IndividualSumThread, (LPVOID)(uintptr_t)i, 0, NULL); | ||||
| #else | ||||
| 		sum_thread[i] = CreateThread(NULL, 0, IndividualSumThread, (LPVOID)(uintptr_t)i, 0, NULL); | ||||
| #endif | ||||
| 		if (sum_thread[i] == NULL) { | ||||
| 			uprintf("Unable to start checksum thread #%d", i); | ||||
| 			goto out; | ||||
|  | @ -1250,7 +1258,11 @@ out: | |||
| 	PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); | ||||
| 	if (r == 0) | ||||
| 		MyDialogBox(hMainInstance, IDD_CHECKSUM, hMainDialog, ChecksumCallback); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex(r); | ||||
| #else | ||||
| 	ExitThread(r); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
|  |  | |||
|  | @ -2419,7 +2419,11 @@ out: | |||
| 		} | ||||
| 	} | ||||
| 	PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)TRUE, 0); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex(0); | ||||
| #else | ||||
| 	ExitThread(0); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| DWORD WINAPI SaveImageThread(void* param) | ||||
|  | @ -2542,5 +2546,9 @@ out: | |||
| 	safe_closehandle(hDestImage); | ||||
| 	safe_unlockclose(hPhysicalDrive); | ||||
| 	PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)TRUE, 0); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex(0); | ||||
| #else | ||||
| 	ExitThread(0); | ||||
| #endif | ||||
| } | ||||
|  |  | |||
							
								
								
									
										28
									
								
								src/net.c
									
										
									
									
									
								
							
							
						
						
									
										28
									
								
								src/net.c
									
										
									
									
									
								
							|  | @ -594,7 +594,11 @@ typedef struct { | |||
| static DWORD WINAPI DownloadSignedFileThread(LPVOID param) | ||||
| { | ||||
| 	DownloadSignedFileThreadArgs* args = (DownloadSignedFileThreadArgs*)param; | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex(DownloadSignedFile(args->url, args->file, args->hProgressDialog, args->bPromptOnError)); | ||||
| #else | ||||
| 	ExitThread(DownloadSignedFile(args->url, args->file, args->hProgressDialog, args->bPromptOnError)); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| HANDLE DownloadSignedFileThreaded(const char* url, const char* file, HWND hProgressDialog, BOOL bPromptOnError) | ||||
|  | @ -604,7 +608,11 @@ HANDLE DownloadSignedFileThreaded(const char* url, const char* file, HWND hProgr | |||
| 	args.file = file; | ||||
| 	args.hProgressDialog = hProgressDialog; | ||||
| 	args.bPromptOnError = bPromptOnError; | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	return (HANDLE)_beginthreadex(NULL, 0, &DownloadSignedFileThread, &args, 0, NULL); | ||||
| #else | ||||
| 	return CreateThread(NULL, 0, DownloadSignedFileThread, &args, 0, NULL); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| static __inline uint64_t to_uint64_t(uint16_t x[4]) { | ||||
|  | @ -865,7 +873,11 @@ out: | |||
| 	force_update_check = FALSE; | ||||
| 	update_check_thread = NULL; | ||||
| 	CoUninitialize(); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex(0); | ||||
| #else | ||||
| 	ExitThread(0); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
|  | @ -877,7 +889,11 @@ BOOL CheckForUpdates(BOOL force) | |||
| 	if (update_check_thread != NULL) | ||||
| 		return FALSE; | ||||
| 
 | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	update_check_thread = (HANDLE)_beginthreadex(NULL, 0, &CheckForUpdatesThread, NULL, 0, NULL); | ||||
| #else | ||||
| 	update_check_thread = CreateThread(NULL, 0, CheckForUpdatesThread, NULL, 0, NULL); | ||||
| #endif | ||||
| 	if (update_check_thread == NULL) { | ||||
| 		uprintf("Unable to start update check thread"); | ||||
| 		return FALSE; | ||||
|  | @ -1071,12 +1087,22 @@ out: | |||
| 	SendMessage(hMainDialog, UM_ENABLE_CONTROLS, 0, 0); | ||||
| 	dialog_showing--; | ||||
| 	CoUninitialize(); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex(dwExitCode); | ||||
| #else | ||||
| 	ExitThread(dwExitCode); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| BOOL DownloadISO() | ||||
| { | ||||
| 	if (CreateThread(NULL, 0, DownloadISOThread, NULL, 0, NULL) == NULL) { | ||||
| 	HANDLE hDownloadIso; | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	hDownloadIso = (HANDLE)_beginthreadex(NULL, 0, &DownloadISOThread, NULL, 0, NULL); | ||||
| #else | ||||
| 	hDownloadIso = CreateThread(NULL, 0, DownloadISOThread, NULL, 0, NULL); | ||||
| #endif | ||||
| 	if (hDownloadIso == NULL) { | ||||
| 		uprintf("Unable to start Windows ISO download thread"); | ||||
| 		FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); | ||||
| 		SendMessage(hMainDialog, UM_ENABLE_CONTROLS, 0, 0); | ||||
|  |  | |||
|  | @ -641,7 +641,11 @@ out: | |||
| 	PhFree(buffer); | ||||
| 	PhFree(handles); | ||||
| 	PhDestroyHeap(); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex(0); | ||||
| #else | ||||
| 	ExitThread(0); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -669,7 +673,11 @@ BYTE SearchProcess(char* HandleName, DWORD dwTimeOut, BOOL bPartialMatch, BOOL b | |||
| 
 | ||||
| 	assert(_wHandleName != NULL); | ||||
| 
 | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	handle = (HANDLE)_beginthreadex(NULL, 0, &SearchProcessThread, NULL, 0, NULL); | ||||
| #else | ||||
| 	handle = CreateThread(NULL, 0, SearchProcessThread, NULL, 0, NULL); | ||||
| #endif | ||||
| 	if (handle == NULL) { | ||||
| 		uprintf("Warning: Unable to create conflicting process search thread"); | ||||
| 		goto out; | ||||
|  |  | |||
							
								
								
									
										40
									
								
								src/rufus.c
									
										
									
									
									
								
							
							
						
						
									
										40
									
								
								src/rufus.c
									
										
									
									
									
								
							|  | @ -1399,7 +1399,11 @@ DWORD WINAPI ImageScanThread(LPVOID param) | |||
| out: | ||||
| 	dont_display_image_name = FALSE; | ||||
| 	PrintInfo(0, MSG_210); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex(0); | ||||
| #else | ||||
| 	ExitThread(0); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| // Likewise, boot check will block message processing => use a thread
 | ||||
|  | @ -1799,7 +1803,11 @@ uefi_target: | |||
| 
 | ||||
| out: | ||||
| 	PostMessage(hMainDialog, UM_FORMAT_START, ret, 0); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex((DWORD)ret); | ||||
| #else | ||||
| 	ExitThread((DWORD)ret); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| static __inline const char* IsAlphaOrBeta(void) | ||||
|  | @ -2047,7 +2055,11 @@ static void SaveVHD(void) | |||
| 			EnableControls(FALSE, FALSE); | ||||
| 			FormatStatus = 0; | ||||
| 			InitProgress(TRUE); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 			format_thread = (HANDLE)_beginthreadex(NULL, 0, &SaveImageThread, &img_save, 0, NULL); | ||||
| #else | ||||
| 			format_thread = CreateThread(NULL, 0, SaveImageThread, &img_save, 0, NULL); | ||||
| #endif | ||||
| 			if (format_thread != NULL) { | ||||
| 				uprintf("\r\nSave to VHD operation started"); | ||||
| 				PrintInfo(0, -1); | ||||
|  | @ -2102,7 +2114,11 @@ static void SaveISO(void) | |||
| 	// Disable all controls except cancel
 | ||||
| 	EnableControls(FALSE, FALSE); | ||||
| 	InitProgress(TRUE); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	format_thread = (HANDLE)_beginthreadex(NULL, 0, &SaveImageThread, &img_save, 0, NULL); | ||||
| #else | ||||
| 	format_thread = CreateThread(NULL, 0, SaveImageThread, &img_save, 0, NULL); | ||||
| #endif | ||||
| 	if (format_thread != NULL) { | ||||
| 		uprintf("\r\nSave to ISO operation started"); | ||||
| 		PrintInfo(0, -1); | ||||
|  | @ -2584,7 +2600,13 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA | |||
| 					} | ||||
| 				} | ||||
| 				FormatStatus = 0; | ||||
| 				if (CreateThread(NULL, 0, ImageScanThread, NULL, 0, NULL) == NULL) { | ||||
| 				HANDLE hImgScanThread; | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 				hImgScanThread = (HANDLE)_beginthreadex(NULL, 0, &ImageScanThread, NULL, 0, NULL); | ||||
| #else | ||||
| 				hImgScanThread = CreateThread(NULL, 0, ImageScanThread, NULL, 0, NULL); | ||||
| #endif | ||||
| 				if (hImgScanThread == NULL) { | ||||
| 					uprintf("Unable to start ISO scanning thread"); | ||||
| 					FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); | ||||
| 				} | ||||
|  | @ -2621,7 +2643,13 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA | |||
| 			selection_default = (int)ComboBox_GetCurItemData(hBootType); | ||||
| 			// Create a thread to validate options and download files as needed (so that we can update the UI).
 | ||||
| 			// On exit, this thread sends message UM_FORMAT_START back to this dialog.
 | ||||
| 			if (CreateThread(NULL, 0, BootCheckThread, NULL, 0, NULL) == NULL) { | ||||
| 			HANDLE hBootCheck; | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 			hBootCheck = (HANDLE)_beginthreadex(NULL, 0, &BootCheckThread, NULL, 0, NULL); | ||||
| #else | ||||
| 			hBootCheck = CreateThread(NULL, 0, BootCheckThread, NULL, 0, NULL); | ||||
| #endif | ||||
| 			if (hBootCheck == NULL) { | ||||
| 				uprintf("Unable to start boot check thread"); | ||||
| 				FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); | ||||
| 				PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); | ||||
|  | @ -2646,7 +2674,11 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA | |||
| 				EnableControls(FALSE, FALSE); | ||||
| 				InitProgress(FALSE); | ||||
| 				SetThreadAffinity(thread_affinity, CHECKSUM_MAX + 1); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 				format_thread = (HANDLE)_beginthreadex(NULL, 0, &SumThread, (LPVOID)thread_affinity, 0, NULL); | ||||
| #else | ||||
| 				format_thread = CreateThread(NULL, 0, SumThread, (LPVOID)thread_affinity, 0, NULL); | ||||
| #endif | ||||
| 				if (format_thread != NULL) { | ||||
| 					SetThreadPriority(format_thread, default_thread_priority); | ||||
| 					PrintInfo(0, -1); | ||||
|  | @ -3025,7 +3057,11 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA | |||
| 		nDeviceIndex = ComboBox_GetCurSel(hDeviceList); | ||||
| 		DeviceNum = (DWORD)ComboBox_GetItemData(hDeviceList, nDeviceIndex); | ||||
| 		InitProgress(zero_drive || write_as_image); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 		format_thread = (HANDLE)_beginthreadex(NULL, 0, &FormatThread, (LPVOID)(uintptr_t)DeviceNum, 0, NULL); | ||||
| #else | ||||
| 		format_thread = CreateThread(NULL, 0, FormatThread, (LPVOID)(uintptr_t)DeviceNum, 0, NULL); | ||||
| #endif | ||||
| 		if (format_thread == NULL) { | ||||
| 			uprintf("Unable to start formatting thread"); | ||||
| 			FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ | |||
| #include <inttypes.h> | ||||
| 
 | ||||
| #if defined(_MSC_VER) | ||||
| #include <process.h> | ||||
| // Disable some VS Code Analysis warnings
 | ||||
| #pragma warning(disable: 4996)		// Ignore deprecated
 | ||||
| #pragma warning(disable: 6258)		// I know what I'm using TerminateThread for
 | ||||
|  |  | |||
|  | @ -927,7 +927,11 @@ BOOL SetLGP(BOOL bRestore, BOOL* bExistingKey, const char* szPath, const char* s | |||
| 		return FALSE; | ||||
| 	} | ||||
| 
 | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	thread_id = (HANDLE)_beginthreadex(NULL, 0, &SetLGPThread, (LPVOID)¶ms, 0, NULL); | ||||
| #else | ||||
| 	thread_id = CreateThread(NULL, 0, SetLGPThread, (LPVOID)¶ms, 0, NULL); | ||||
| #endif | ||||
| 	if (thread_id == NULL) { | ||||
| 		ubprintf("SetLGP: Unable to start thread"); | ||||
| 		return FALSE; | ||||
|  |  | |||
|  | @ -1574,7 +1574,11 @@ void SetFidoCheck(void) | |||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_beginthreadex(NULL, 0, &CheckForFidoThread, NULL, 0, NULL); | ||||
| #else | ||||
| 	CreateThread(NULL, 0, CheckForFidoThread, NULL, 0, NULL); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
|  |  | |||
							
								
								
									
										24
									
								
								src/vhd.c
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								src/vhd.c
									
										
									
									
									
								
							|  | @ -567,7 +567,11 @@ static DWORD WINAPI WimMountImageThread(LPVOID param) | |||
| out: | ||||
| 	wfree(temp_dir); | ||||
| 	safe_free(wimage); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex((DWORD)r); | ||||
| #else | ||||
| 	ExitThread((DWORD)r); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| // Returns the temporary mount path on success, NULL on error.
 | ||||
|  | @ -578,7 +582,11 @@ char* WimMountImage(const char* image, int index) | |||
| 	_image = image; | ||||
| 	_index = index; | ||||
| 
 | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	wim_thread = (HANDLE)_beginthreadex(NULL, 0, &WimMountImageThread, NULL, 0, NULL); | ||||
| #else | ||||
| 	wim_thread = CreateThread(NULL, 0, WimMountImageThread, NULL, 0, NULL); | ||||
| #endif | ||||
| 	if (wim_thread == NULL) { | ||||
| 		uprintf("Unable to start mount-image thread"); | ||||
| 		return NULL; | ||||
|  | @ -630,7 +638,11 @@ static DWORD WINAPI WimUnmountImageThread(LPVOID param) | |||
| 	wmount_path[0] = 0; | ||||
| out: | ||||
| 	safe_free(wimage); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex((DWORD)r); | ||||
| #else | ||||
| 	ExitThread((DWORD)r); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| BOOL WimUnmountImage(const char* image, int index) | ||||
|  | @ -639,7 +651,11 @@ BOOL WimUnmountImage(const char* image, int index) | |||
| 	_image = image; | ||||
| 	_index = index; | ||||
| 
 | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	wim_thread = (HANDLE)_beginthreadex(NULL, 0, &WimUnmountImageThread, NULL, 0, NULL); | ||||
| #else | ||||
| 	wim_thread = CreateThread(NULL, 0, WimUnmountImageThread, NULL, 0, NULL); | ||||
| #endif | ||||
| 	if (wim_thread == NULL) { | ||||
| 		uprintf("Unable to start unmount-image thread"); | ||||
| 		return FALSE; | ||||
|  | @ -905,7 +921,11 @@ out: | |||
| 		pfWIMUnregisterMessageCallback(NULL, (FARPROC)WimProgressCallback); | ||||
| 	safe_free(wimage); | ||||
| 	safe_free(wdst); | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	_endthreadex((DWORD)r); | ||||
| #else | ||||
| 	ExitThread((DWORD)r); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| BOOL WimApplyImage(const char* image, int index, const char* dst) | ||||
|  | @ -915,7 +935,11 @@ BOOL WimApplyImage(const char* image, int index, const char* dst) | |||
| 	_index = index; | ||||
| 	_dst = dst; | ||||
| 
 | ||||
| #if _MSC_VER && !__INTEL_COMPILER | ||||
| 	wim_thread = (HANDLE)_beginthreadex(NULL, 0, &WimApplyImageThread, NULL, 0, NULL); | ||||
| #else | ||||
| 	wim_thread = CreateThread(NULL, 0, WimApplyImageThread, NULL, 0, NULL); | ||||
| #endif | ||||
| 	if (wim_thread == NULL) { | ||||
| 		uprintf("Unable to start apply-image thread"); | ||||
| 		return FALSE; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue