mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-23 14:43:38 +00:00
nuke a ton of winapi stubs
This commit is contained in:
parent
559b207ee2
commit
0e6a6cc537
|
|
@ -1,64 +0,0 @@
|
|||
// #ifndef D3D11STUBS_H
|
||||
// #define D3D11STUBS_H
|
||||
|
||||
// #pragma once
|
||||
|
||||
// #include "winapi_stubs.h"
|
||||
|
||||
// typedef struct _RECT {
|
||||
// LONG left;
|
||||
// LONG top;
|
||||
// LONG right;
|
||||
// LONG bottom;
|
||||
// } RECT, *PRECT;
|
||||
|
||||
// // stole- i mean borrowed from OrbisStubs.h
|
||||
// typedef void ID3D11Device;
|
||||
// typedef void ID3D11DeviceContext;
|
||||
// typedef void IDXGISwapChain;
|
||||
// typedef RECT D3D11_RECT;
|
||||
// typedef void ID3D11RenderTargetView;
|
||||
// typedef void ID3D11DepthStencilView;
|
||||
// typedef void ID3D11Buffer;
|
||||
// // typedef DWORD (*PTHREAD_START_ROUTINE)( void* lpThreadParameter);
|
||||
// // typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;
|
||||
|
||||
// // Used only by windows/durango gdraw and UIController. Will be unnecessary once
|
||||
// // we have our own UIController stubs.
|
||||
// typedef void ID3D11ShaderResourceView;
|
||||
// typedef void ID3D11Resource;
|
||||
// typedef void ID3D11Texture2D;
|
||||
// typedef void D3D11_TEXTURE2D_DESC;
|
||||
|
||||
// enum D3D11_BLEND {
|
||||
// D3D11_BLEND_ZERO = 1,
|
||||
// D3D11_BLEND_ONE = 2,
|
||||
// D3D11_BLEND_SRC_COLOR = 3,
|
||||
// D3D11_BLEND_INV_SRC_COLOR = 4,
|
||||
// D3D11_BLEND_SRC_ALPHA = 5,
|
||||
// D3D11_BLEND_INV_SRC_ALPHA = 6,
|
||||
// D3D11_BLEND_DEST_ALPHA = 7,
|
||||
// D3D11_BLEND_INV_DEST_ALPHA = 8,
|
||||
// D3D11_BLEND_DEST_COLOR = 9,
|
||||
// D3D11_BLEND_INV_DEST_COLOR = 10,
|
||||
// D3D11_BLEND_SRC_ALPHA_SAT = 11,
|
||||
// D3D11_BLEND_BLEND_FACTOR = 14,
|
||||
// D3D11_BLEND_INV_BLEND_FACTOR = 15,
|
||||
// D3D11_BLEND_SRC1_COLOR = 16,
|
||||
// D3D11_BLEND_INV_SRC1_COLOR = 17,
|
||||
// D3D11_BLEND_SRC1_ALPHA = 18,
|
||||
// D3D11_BLEND_INV_SRC1_ALPHA = 19
|
||||
// };
|
||||
|
||||
// enum D3D11_COMPARISON_FUNC {
|
||||
// D3D11_COMPARISON_NEVER = 1,
|
||||
// D3D11_COMPARISON_LESS = 2,
|
||||
// D3D11_COMPARISON_EQUAL = 3,
|
||||
// D3D11_COMPARISON_LESS_EQUAL = 4,
|
||||
// D3D11_COMPARISON_GREATER = 5,
|
||||
// D3D11_COMPARISON_NOT_EQUAL = 6,
|
||||
// D3D11_COMPARISON_GREATER_EQUAL = 7,
|
||||
// D3D11_COMPARISON_ALWAYS = 8
|
||||
// };
|
||||
|
||||
// #endif // D3D11STUBS_H
|
||||
|
|
@ -62,102 +62,10 @@ typedef float FLOAT;
|
|||
#define ERROR_IO_PENDING 997L // dderror
|
||||
#define ERROR_CANCELLED 1223L
|
||||
|
||||
#define INFINITE 0xFFFFFFFF // Infinite timeout
|
||||
|
||||
#define PAGE_READWRITE 0x04
|
||||
#define MEM_LARGE_PAGES 0x20000000
|
||||
#define MAXULONG_PTR ((ULONG_PTR)~0UL)
|
||||
#define MAX_PATH 260
|
||||
|
||||
#define GENERIC_READ 0x80000000UL
|
||||
#define GENERIC_WRITE 0x40000000UL
|
||||
#define GENERIC_EXECUTE 0x20000000UL
|
||||
#define GENERIC_ALL 0x10000000UL
|
||||
|
||||
#define FILE_SHARE_READ 0x00000001
|
||||
#define FILE_SHARE_WRITE 0x00000002
|
||||
#define FILE_SHARE_DELETE 0x00000004
|
||||
|
||||
#define CREATE_NEW 1
|
||||
#define CREATE_ALWAYS 2
|
||||
#define OPEN_EXISTING 3
|
||||
#define OPEN_ALWAYS 4
|
||||
#define TRUNCATE_EXISTING 5
|
||||
#define WAIT_TIMEOUT 258
|
||||
|
||||
#define FILE_FLAG_WRITE_THROUGH 0x80000000
|
||||
#define FILE_FLAG_OVERLAPPED 0x40000000
|
||||
#define FILE_FLAG_NO_BUFFERING 0x20000000
|
||||
#define FILE_FLAG_RANDOM_ACCESS 0x10000000
|
||||
#define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000
|
||||
#define FILE_FLAG_DELETE_ON_CLOSE 0x04000000
|
||||
#define FILE_FLAG_BACKUP_SEMANTICS 0x02000000
|
||||
|
||||
#define FILE_ATTRIBUTE_READONLY 0x00000001
|
||||
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
|
||||
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
|
||||
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
|
||||
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
|
||||
#define FILE_ATTRIBUTE_NORMAL 0x00000080
|
||||
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
|
||||
#define INVALID_FILE_ATTRIBUTES ((DWORD) - 1)
|
||||
#define INVALID_FILE_SIZE ((DWORD) - 1)
|
||||
#define INVALID_SET_FILE_POINTER ((DWORD) - 1)
|
||||
|
||||
#define FILE_BEGIN SEEK_SET
|
||||
#define FILE_CURRENT SEEK_CUR
|
||||
#define FILE_END SEEK_END
|
||||
|
||||
#define PAGE_NOACCESS 0x01
|
||||
#define PAGE_READONLY 0x02
|
||||
#define PAGE_READWRITE 0x04
|
||||
#define PAGE_WRITECOPY 0x08
|
||||
#define PAGE_EXECUTE 0x10
|
||||
#define PAGE_EXECUTE_READ 0x20
|
||||
#define PAGE_EXECUTE_READWRITE 0x40
|
||||
#define PAGE_EXECUTE_WRITECOPY 0x80
|
||||
#define PAGE_GUARD 0x100
|
||||
#define PAGE_NOCACHE 0x200
|
||||
#define PAGE_WRITECOMBINE 0x400
|
||||
#define PAGE_USER_READONLY 0x1000
|
||||
#define PAGE_USER_READWRITE 0x2000
|
||||
#define MEM_COMMIT 0x1000
|
||||
#define MEM_RESERVE 0x2000
|
||||
#define MEM_DECOMMIT 0x4000
|
||||
#define MEM_RELEASE 0x8000
|
||||
#define MEM_FREE 0x10000
|
||||
#define MEM_PRIVATE 0x20000
|
||||
#define MEM_RESET 0x80000
|
||||
#define MEM_TOP_DOWN 0x100000
|
||||
#define MEM_NOZERO 0x800000
|
||||
#define MEM_LARGE_PAGES 0x20000000
|
||||
#define MEM_HEAP 0x40000000
|
||||
#define MEM_16MB_PAGES 0x80000000
|
||||
|
||||
#define THREAD_BASE_PRIORITY_LOWRT \
|
||||
15 // value that gets a thread to LowRealtime-1
|
||||
#define THREAD_BASE_PRIORITY_MAX 2 // maximum thread base priority boost
|
||||
#define THREAD_BASE_PRIORITY_MIN -2 // minimum thread base priority boost
|
||||
#define THREAD_BASE_PRIORITY_IDLE -15 // value that gets a thread to idle
|
||||
|
||||
#define THREAD_PRIORITY_LOWEST THREAD_BASE_PRIORITY_MIN
|
||||
#define THREAD_PRIORITY_BELOW_NORMAL (THREAD_PRIORITY_LOWEST + 1)
|
||||
#define THREAD_PRIORITY_NORMAL 0
|
||||
#define THREAD_PRIORITY_HIGHEST THREAD_BASE_PRIORITY_MAX
|
||||
#define THREAD_PRIORITY_ABOVE_NORMAL (THREAD_PRIORITY_HIGHEST - 1)
|
||||
#define THREAD_PRIORITY_ERROR_RETURN (MAXLONG)
|
||||
|
||||
#define THREAD_PRIORITY_TIME_CRITICAL THREAD_BASE_PRIORITY_LOWRT
|
||||
#define THREAD_PRIORITY_IDLE THREAD_BASE_PRIORITY_IDLE
|
||||
|
||||
#define IGNORE 0 // Ignore signal
|
||||
#define INFINITE 0xFFFFFFFF // Infinite timeout
|
||||
#define STATUS_WAIT_0 ((DWORD)0x00000000L)
|
||||
#define WAIT_OBJECT_0 ((STATUS_WAIT_0) + 0)
|
||||
#define STATUS_PENDING ((DWORD)0x00000103L)
|
||||
#define STILL_ACTIVE STATUS_PENDING
|
||||
|
||||
#define INVALID_HANDLE_VALUE ((HANDLE)(ULONG_PTR) - 1)
|
||||
#define PAGE_READWRITE 0x04
|
||||
|
||||
// https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime
|
||||
typedef struct _FILETIME {
|
||||
|
|
@ -255,110 +163,6 @@ static inline FILETIME _TimeToFileTime(time_t t) {
|
|||
return ft;
|
||||
}
|
||||
|
||||
static inline HANDLE CreateFileA(const char* lpFileName, DWORD dwDesiredAccess,
|
||||
DWORD dwShareMode, void* lpSecurityAttributes,
|
||||
DWORD dwCreationDisposition,
|
||||
DWORD dwFlagsAndAttributes,
|
||||
HANDLE hTemplateFile) {
|
||||
int flags = 0;
|
||||
if ((dwDesiredAccess & GENERIC_READ) && (dwDesiredAccess & GENERIC_WRITE))
|
||||
flags = O_RDWR;
|
||||
else if (dwDesiredAccess & GENERIC_WRITE)
|
||||
flags = O_WRONLY;
|
||||
else
|
||||
flags = O_RDONLY;
|
||||
|
||||
switch (dwCreationDisposition) {
|
||||
case CREATE_NEW:
|
||||
flags |= O_CREAT | O_EXCL;
|
||||
break;
|
||||
case CREATE_ALWAYS:
|
||||
flags |= O_CREAT | O_TRUNC;
|
||||
break;
|
||||
case OPEN_EXISTING:
|
||||
break;
|
||||
case OPEN_ALWAYS:
|
||||
flags |= O_CREAT;
|
||||
break;
|
||||
case TRUNCATE_EXISTING:
|
||||
flags |= O_TRUNC;
|
||||
break;
|
||||
}
|
||||
|
||||
int fd = open(lpFileName, flags, 0644);
|
||||
return fd == -1 ? INVALID_HANDLE_VALUE : (HANDLE)(intptr_t)fd;
|
||||
}
|
||||
|
||||
static inline HANDLE CreateFileW(const wchar_t* lpFileName,
|
||||
DWORD dwDesiredAccess, DWORD dwShareMode,
|
||||
void* lpSecurityAttributes,
|
||||
DWORD dwCreationDisposition,
|
||||
DWORD dwFlagsAndAttributes,
|
||||
HANDLE hTemplateFile) {
|
||||
char narrowBuf[1024];
|
||||
wcstombs(narrowBuf, lpFileName, sizeof(narrowBuf));
|
||||
narrowBuf[sizeof(narrowBuf) - 1] = '\0';
|
||||
return CreateFileA(narrowBuf, dwDesiredAccess, dwShareMode,
|
||||
lpSecurityAttributes, dwCreationDisposition,
|
||||
dwFlagsAndAttributes, hTemplateFile);
|
||||
}
|
||||
|
||||
static inline HANDLE CreateFile(const char* lpFileName, DWORD dwDesiredAccess,
|
||||
DWORD dwShareMode, void* lpSecurityAttributes,
|
||||
DWORD dwCreationDisposition,
|
||||
DWORD dwFlagsAndAttributes,
|
||||
HANDLE hTemplateFile) {
|
||||
return CreateFileA(lpFileName, dwDesiredAccess, dwShareMode,
|
||||
lpSecurityAttributes, dwCreationDisposition,
|
||||
dwFlagsAndAttributes, hTemplateFile);
|
||||
}
|
||||
|
||||
static inline HANDLE CreateFile(const wchar_t* lpFileName,
|
||||
DWORD dwDesiredAccess, DWORD dwShareMode,
|
||||
void* lpSecurityAttributes,
|
||||
DWORD dwCreationDisposition,
|
||||
DWORD dwFlagsAndAttributes,
|
||||
HANDLE hTemplateFile) {
|
||||
return CreateFileW(lpFileName, dwDesiredAccess, dwShareMode,
|
||||
lpSecurityAttributes, dwCreationDisposition,
|
||||
dwFlagsAndAttributes, hTemplateFile);
|
||||
}
|
||||
|
||||
static inline bool CloseHandle(HANDLE hObject) {
|
||||
if (hObject == INVALID_HANDLE_VALUE) return false;
|
||||
return close((int)(intptr_t)hObject) == 0;
|
||||
}
|
||||
|
||||
static inline DWORD GetFileSize(HANDLE hFile, DWORD* lpFileSizeHigh) {
|
||||
struct stat st{};
|
||||
if (fstat((int)(intptr_t)hFile, &st) != 0) {
|
||||
if (lpFileSizeHigh) *lpFileSizeHigh = 0;
|
||||
return INVALID_FILE_SIZE;
|
||||
}
|
||||
if (lpFileSizeHigh)
|
||||
*lpFileSizeHigh = (DWORD)((st.st_size >> 32) & 0xFFFFFFFF);
|
||||
return (DWORD)(st.st_size & 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
static inline bool GetFileSizeEx(HANDLE hFile, LARGE_INTEGER* lpFileSize) {
|
||||
struct stat st{};
|
||||
if (fstat((int)(intptr_t)hFile, &st) != 0) return false;
|
||||
if (lpFileSize) {
|
||||
lpFileSize->QuadPart = st.st_size;
|
||||
lpFileSize->LowPart = (DWORD)(st.st_size & 0xFFFFFFFF);
|
||||
lpFileSize->HighPart = (LONG)(st.st_size >> 32);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool ReadFile(HANDLE hFile, void* lpBuffer,
|
||||
DWORD nNumberOfBytesToRead,
|
||||
DWORD* lpNumberOfBytesRead, void* lpOverlapped) {
|
||||
ssize_t n = read((int)(intptr_t)hFile, lpBuffer, nNumberOfBytesToRead);
|
||||
if (lpNumberOfBytesRead) *lpNumberOfBytesRead = n >= 0 ? (DWORD)n : 0;
|
||||
return n >= 0;
|
||||
}
|
||||
|
||||
// internal helper: convert FILETIME (100ns since 1601) to time_t (seconds since
|
||||
// 1970)
|
||||
static inline time_t _FileTimeToTimeT(const FILETIME& ft) {
|
||||
|
|
@ -433,268 +237,6 @@ static inline void OutputDebugString(const char* lpOutputString) {
|
|||
return OutputDebugStringA(lpOutputString);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
int signaled;
|
||||
int manual_reset;
|
||||
} Event;
|
||||
|
||||
static inline HANDLE CreateEvent(int manual_reset, int initial_state) {
|
||||
Event* ev = (Event*)malloc(sizeof(Event));
|
||||
pthread_mutex_init(&ev->mutex, nullptr);
|
||||
pthread_cond_init(&ev->cond, nullptr);
|
||||
ev->signaled = initial_state;
|
||||
ev->manual_reset = manual_reset;
|
||||
return (HANDLE)ev;
|
||||
}
|
||||
|
||||
static inline HANDLE CreateEvent(void*, bool manual_reset, bool initial_state,
|
||||
void*) {
|
||||
return CreateEvent(manual_reset, initial_state);
|
||||
}
|
||||
|
||||
static inline bool SetEvent(HANDLE hEvent) {
|
||||
Event* ev = (Event*)hEvent;
|
||||
if (!ev) return false;
|
||||
pthread_mutex_lock(&ev->mutex);
|
||||
ev->signaled = 1;
|
||||
if (ev->manual_reset)
|
||||
pthread_cond_broadcast(&ev->cond);
|
||||
else
|
||||
pthread_cond_signal(&ev->cond);
|
||||
pthread_mutex_unlock(&ev->mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool ResetEvent(HANDLE hEvent) {
|
||||
Event* ev = (Event*)hEvent;
|
||||
if (!ev) return false;
|
||||
pthread_mutex_lock(&ev->mutex);
|
||||
ev->signaled = 0;
|
||||
pthread_mutex_unlock(&ev->mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
#define WAIT_FAILED ((DWORD)0xFFFFFFFF)
|
||||
#define INFINITE 0xFFFFFFFF
|
||||
#define HANDLE_TYPE_THREAD 0x54485200
|
||||
|
||||
static inline DWORD _WaitForEvent(Event* ev, DWORD dwMilliseconds) {
|
||||
pthread_mutex_lock(&ev->mutex);
|
||||
if (dwMilliseconds == INFINITE) {
|
||||
while (!ev->signaled) pthread_cond_wait(&ev->cond, &ev->mutex);
|
||||
} else if (dwMilliseconds > 0) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
ts.tv_sec += dwMilliseconds / 1000;
|
||||
ts.tv_nsec += (dwMilliseconds % 1000) * 1000000;
|
||||
if (ts.tv_nsec >= 1000000000) {
|
||||
ts.tv_sec++;
|
||||
ts.tv_nsec -= 1000000000;
|
||||
}
|
||||
while (!ev->signaled) {
|
||||
if (pthread_cond_timedwait(&ev->cond, &ev->mutex, &ts) != 0) {
|
||||
pthread_mutex_unlock(&ev->mutex);
|
||||
return WAIT_TIMEOUT;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!ev->signaled) {
|
||||
pthread_mutex_unlock(&ev->mutex);
|
||||
return WAIT_TIMEOUT;
|
||||
}
|
||||
}
|
||||
if (!ev->manual_reset) ev->signaled = 0;
|
||||
pthread_mutex_unlock(&ev->mutex);
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
struct LinuxThread;
|
||||
static inline DWORD _WaitForThread(struct LinuxThread* lt,
|
||||
DWORD dwMilliseconds);
|
||||
|
||||
static inline DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) {
|
||||
if (!hHandle) return WAIT_FAILED;
|
||||
// Check if this is a thread handle (LinuxThread has magic number as first
|
||||
// field)
|
||||
if (*(int*)hHandle == HANDLE_TYPE_THREAD) {
|
||||
return _WaitForThread((struct LinuxThread*)hHandle, dwMilliseconds);
|
||||
}
|
||||
return _WaitForEvent((Event*)hHandle, dwMilliseconds);
|
||||
}
|
||||
|
||||
static inline DWORD WaitForMultipleObjects(DWORD nCount,
|
||||
const HANDLE* lpHandles,
|
||||
bool bWaitAll,
|
||||
DWORD dwMilliseconds) {
|
||||
if (bWaitAll) {
|
||||
for (DWORD i = 0; i < nCount; i++)
|
||||
WaitForSingleObject(lpHandles[i], dwMilliseconds);
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
for (int pass = 0; pass < 1000; pass++) {
|
||||
for (DWORD i = 0; i < nCount; i++) {
|
||||
if (WaitForSingleObject(lpHandles[i], 0) == WAIT_OBJECT_0)
|
||||
return WAIT_OBJECT_0 + i;
|
||||
}
|
||||
usleep(1000);
|
||||
}
|
||||
return WAIT_TIMEOUT;
|
||||
}
|
||||
|
||||
static inline void CloseHandle_Event(HANDLE hEvent) {
|
||||
Event* ev = (Event*)hEvent;
|
||||
if (!ev) return;
|
||||
pthread_mutex_destroy(&ev->mutex);
|
||||
pthread_cond_destroy(&ev->cond);
|
||||
free(ev);
|
||||
}
|
||||
|
||||
#define CREATE_SUSPENDED 0x00000004
|
||||
|
||||
typedef DWORD (*LPTHREAD_START_ROUTINE)(void*);
|
||||
|
||||
struct LinuxThread {
|
||||
int handleType;
|
||||
pthread_t thread;
|
||||
LPTHREAD_START_ROUTINE func;
|
||||
void* param;
|
||||
DWORD threadId;
|
||||
DWORD exitCode;
|
||||
int suspended;
|
||||
pthread_mutex_t suspendMutex;
|
||||
pthread_cond_t suspendCond;
|
||||
pthread_mutex_t completionMutex;
|
||||
pthread_cond_t completionCond;
|
||||
int completed;
|
||||
};
|
||||
|
||||
static inline void* _linux_thread_entry(void* arg) {
|
||||
LinuxThread* lt = (LinuxThread*)arg;
|
||||
pthread_mutex_lock(<->suspendMutex);
|
||||
while (lt->suspended)
|
||||
pthread_cond_wait(<->suspendCond, <->suspendMutex);
|
||||
pthread_mutex_unlock(<->suspendMutex);
|
||||
lt->exitCode = lt->func(lt->param);
|
||||
// Signal completion
|
||||
pthread_mutex_lock(<->completionMutex);
|
||||
lt->completed = 1;
|
||||
pthread_cond_broadcast(<->completionCond);
|
||||
pthread_mutex_unlock(<->completionMutex);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static inline DWORD _WaitForThread(struct LinuxThread* lt,
|
||||
DWORD dwMilliseconds) {
|
||||
pthread_mutex_lock(<->completionMutex);
|
||||
if (lt->completed) {
|
||||
pthread_mutex_unlock(<->completionMutex);
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
if (dwMilliseconds == 0) {
|
||||
pthread_mutex_unlock(<->completionMutex);
|
||||
return WAIT_TIMEOUT;
|
||||
}
|
||||
if (dwMilliseconds == INFINITE) {
|
||||
while (!lt->completed)
|
||||
pthread_cond_wait(<->completionCond, <->completionMutex);
|
||||
} else {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
ts.tv_sec += dwMilliseconds / 1000;
|
||||
ts.tv_nsec += (dwMilliseconds % 1000) * 1000000;
|
||||
if (ts.tv_nsec >= 1000000000) {
|
||||
ts.tv_sec++;
|
||||
ts.tv_nsec -= 1000000000;
|
||||
}
|
||||
while (!lt->completed) {
|
||||
if (pthread_cond_timedwait(<->completionCond,
|
||||
<->completionMutex, &ts) != 0) {
|
||||
pthread_mutex_unlock(<->completionMutex);
|
||||
return WAIT_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(<->completionMutex);
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
static DWORD g_nextThreadId = 1000;
|
||||
|
||||
static inline HANDLE CreateThread(void*, size_t stackSize,
|
||||
LPTHREAD_START_ROUTINE lpStartAddress,
|
||||
void* lpParameter, DWORD dwCreationFlags,
|
||||
DWORD* lpThreadId) {
|
||||
LinuxThread* lt = (LinuxThread*)calloc(1, sizeof(LinuxThread));
|
||||
lt->handleType = HANDLE_TYPE_THREAD;
|
||||
lt->func = lpStartAddress;
|
||||
lt->param = lpParameter;
|
||||
lt->exitCode = STILL_ACTIVE;
|
||||
lt->suspended = (dwCreationFlags & CREATE_SUSPENDED) ? 1 : 0;
|
||||
lt->completed = 0;
|
||||
lt->threadId = __sync_fetch_and_add(&g_nextThreadId, 1);
|
||||
pthread_mutex_init(<->suspendMutex, nullptr);
|
||||
pthread_cond_init(<->suspendCond, nullptr);
|
||||
pthread_mutex_init(<->completionMutex, nullptr);
|
||||
pthread_cond_init(<->completionCond, nullptr);
|
||||
if (lpThreadId) *lpThreadId = lt->threadId;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
if (stackSize > 0) pthread_attr_setstacksize(&attr, stackSize);
|
||||
pthread_create(<->thread, &attr, _linux_thread_entry, lt);
|
||||
pthread_attr_destroy(&attr);
|
||||
return (HANDLE)lt;
|
||||
}
|
||||
|
||||
static inline DWORD ResumeThread(HANDLE hThread) {
|
||||
LinuxThread* lt = (LinuxThread*)hThread;
|
||||
if (!lt) return (DWORD)-1;
|
||||
pthread_mutex_lock(<->suspendMutex);
|
||||
lt->suspended = 0;
|
||||
pthread_cond_signal(<->suspendCond);
|
||||
pthread_mutex_unlock(<->suspendMutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline bool SetThreadPriority(HANDLE hThread, int nPriority) {
|
||||
(void)hThread;
|
||||
(void)nPriority;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool GetExitCodeThread(HANDLE hThread, DWORD* lpExitCode) {
|
||||
LinuxThread* lt = (LinuxThread*)hThread;
|
||||
if (!lt || !lpExitCode) return false;
|
||||
*lpExitCode = lt->exitCode;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline DWORD GetCurrentThreadId() {
|
||||
return (DWORD)(unsigned long)pthread_self();
|
||||
}
|
||||
|
||||
static inline HANDLE GetCurrentThread() {
|
||||
return (HANDLE)(unsigned long)pthread_self();
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
static inline int swprintf_s(wchar_t (&buf)[N], const wchar_t* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int ret = vswprintf(buf, N, fmt, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline int swprintf_s(wchar_t* buf, size_t sz, const wchar_t* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int ret = vswprintf(buf, sz, fmt, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline HMODULE GetModuleHandle(const char* lpModuleName) { return 0; }
|
||||
|
||||
static inline void* VirtualAlloc(void* lpAddress, size_t dwSize,
|
||||
|
|
@ -735,6 +277,4 @@ static inline bool VirtualFree(void* lpAddress, size_t dwSize,
|
|||
return true;
|
||||
}
|
||||
|
||||
#define _wcsicmp wcscasecmp
|
||||
|
||||
#endif // WINAPISTUBS_H
|
||||
|
|
|
|||
Loading…
Reference in a new issue