Replaced WINPR_HANDLE_DEF with a struct type

This commit is contained in:
Armin Novak 2022-04-27 15:56:39 +02:00 committed by akallabeth
parent dfe89737a0
commit e1b4b4aee0
26 changed files with 128 additions and 261 deletions

View File

@ -295,15 +295,9 @@ BOOL GetCommProperties(HANDLE hFile, LPCOMMPROP lpCommProp)
WINPR_COMM* pComm = (WINPR_COMM*)hFile;
DWORD bytesReturned;
if (!CommInitialized())
if (!CommIsHandleValid(hFile))
return FALSE;
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_PROPERTIES, NULL, 0, lpCommProp,
sizeof(COMMPROP), &bytesReturned, NULL))
{
@ -330,15 +324,9 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
WINPR_COMM* pComm = (WINPR_COMM*)hFile;
DWORD bytesReturned;
if (!CommInitialized())
if (!CommIsHandleValid(hFile))
return FALSE;
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
if (!lpDCB)
{
SetLastError(ERROR_INVALID_DATA);
@ -490,15 +478,9 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
/* FIXME: validate changes according GetCommProperties? */
if (!CommInitialized())
if (!CommIsHandleValid(hFile))
return FALSE;
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
if (!lpDCB)
{
SetLastError(ERROR_INVALID_DATA);
@ -716,15 +698,9 @@ BOOL GetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
WINPR_COMM* pComm = (WINPR_COMM*)hFile;
DWORD bytesReturned;
if (!CommInitialized())
if (!CommIsHandleValid(hFile))
return FALSE;
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
/* as of today, SERIAL_TIMEOUTS and COMMTIMEOUTS structures are identical */
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, lpCommTimeouts,
@ -746,15 +722,9 @@ BOOL SetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
WINPR_COMM* pComm = (WINPR_COMM*)hFile;
DWORD bytesReturned;
if (!CommInitialized())
if (!CommIsHandleValid(hFile))
return FALSE;
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
/* as of today, SERIAL_TIMEOUTS and COMMTIMEOUTS structures are identical */
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_TIMEOUTS, lpCommTimeouts, sizeof(COMMTIMEOUTS),
@ -867,15 +837,9 @@ BOOL PurgeComm(HANDLE hFile, DWORD dwFlags)
WINPR_COMM* pComm = (WINPR_COMM*)hFile;
DWORD bytesReturned = 0;
if (!CommInitialized())
if (!CommIsHandleValid(hFile))
return FALSE;
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_PURGE, &dwFlags, sizeof(DWORD), NULL, 0,
&bytesReturned, NULL))
{
@ -892,15 +856,9 @@ BOOL SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)
SERIAL_QUEUE_SIZE queueSize;
DWORD bytesReturned = 0;
if (!CommInitialized())
if (!CommIsHandleValid(hFile))
return FALSE;
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
queueSize.InSize = dwInQueue;
queueSize.OutSize = dwOutQueue;
@ -1285,7 +1243,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
}
WINPR_HANDLE_SET_TYPE_AND_MODE(pComm, HANDLE_TYPE_COMM, WINPR_FD_READ);
pComm->ops = &ops;
pComm->common.ops = &ops;
/* error_handle */
pComm->fd = open(devicePath, O_RDWR | O_NOCTTY | O_NONBLOCK);
@ -1393,37 +1351,32 @@ error_handle:
BOOL CommIsHandled(HANDLE handle)
{
WINPR_COMM* pComm;
if (!CommInitialized())
return FALSE;
pComm = (WINPR_COMM*)handle;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_COMM, TRUE);
}
if (!pComm || (pComm->Type != HANDLE_TYPE_COMM) || (pComm == INVALID_HANDLE_VALUE))
BOOL CommIsHandleValid(HANDLE handle)
{
WINPR_COMM* pComm = (WINPR_COMM*)handle;
if (!CommIsHandled(handle))
return FALSE;
if (pComm->fd <= 0)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
}
BOOL CommCloseHandle(HANDLE handle)
{
WINPR_COMM* pComm;
WINPR_COMM* pComm = (WINPR_COMM*)handle;
if (!CommInitialized())
if (!CommIsHandled(handle))
return FALSE;
pComm = (WINPR_COMM*)handle;
if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
if (pComm->PendingEvents & SERIAL_EV_WINPR_WAITING)
{
ULONG WaitMask = 0;

View File

@ -33,7 +33,7 @@
struct winpr_comm
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
int fd;
@ -97,6 +97,7 @@ typedef struct winpr_comm WINPR_COMM;
void CommLog_Print(DWORD wlog_level, ...);
BOOL CommIsHandled(HANDLE handle);
BOOL CommIsHandleValid(HANDLE handle);
BOOL CommCloseHandle(HANDLE handle);
HANDLE_CREATOR* GetCommHandleCreator(void);

View File

@ -36,17 +36,8 @@ BOOL _comm_set_permissive(HANDLE hDevice, BOOL permissive)
{
WINPR_COMM* pComm = (WINPR_COMM*)hDevice;
if (hDevice == INVALID_HANDLE_VALUE)
{
SetLastError(ERROR_INVALID_HANDLE);
if (!CommIsHandled(hDevice))
return FALSE;
}
if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
pComm->permissive = permissive;
return TRUE;
@ -91,17 +82,8 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
struct termios currentTermios;
EnterCriticalSection(&pComm->ReadLock); /* KISSer by the function's beginning */
if (hDevice == INVALID_HANDLE_VALUE)
{
SetLastError(ERROR_INVALID_HANDLE);
if (!CommIsHandled(hDevice))
goto return_false;
}
if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
{
SetLastError(ERROR_INVALID_HANDLE);
goto return_false;
}
if (lpOverlapped != NULL)
{
@ -383,17 +365,8 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
struct timeval tmaxTimeout, *pTmaxTimeout;
EnterCriticalSection(&pComm->WriteLock); /* KISSer by the function's beginning */
if (hDevice == INVALID_HANDLE_VALUE)
{
SetLastError(ERROR_INVALID_HANDLE);
if (!CommIsHandled(hDevice))
goto return_false;
}
if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
{
SetLastError(ERROR_INVALID_HANDLE);
goto return_false;
}
if (lpOverlapped != NULL)
{

View File

@ -66,24 +66,15 @@ const char* _comm_serial_ioctl_name(ULONG number)
return "(unknown ioctl name)";
}
static BOOL _CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer,
DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize,
LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)
static BOOL s_CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer,
DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize,
LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)
{
WINPR_COMM* pComm = (WINPR_COMM*)hDevice;
SERIAL_DRIVER* pServerSerialDriver = NULL;
if (hDevice == INVALID_HANDLE_VALUE)
{
SetLastError(ERROR_INVALID_HANDLE);
if (!CommIsHandleValid(hDevice))
return FALSE;
}
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
if (lpOverlapped)
{
@ -656,14 +647,17 @@ BOOL CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffe
return FALSE;
}
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
if (!CommIsHandled(hDevice))
return FALSE;
if (!pComm->fd)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
result = _CommDeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer,
nOutBufferSize, lpBytesReturned, lpOverlapped);
result = s_CommDeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer,
nOutBufferSize, lpBytesReturned, lpOverlapped);
if (lpBytesReturned && *lpBytesReturned != nOutBufferSize)
{

View File

@ -61,15 +61,7 @@
static BOOL FileIsHandled(HANDLE handle)
{
WINPR_FILE* pFile = (WINPR_FILE*)handle;
if (!pFile || (pFile->Type != HANDLE_TYPE_FILE))
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_FILE, FALSE);
}
static int FileGetFd(HANDLE handle)
@ -809,7 +801,7 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw
}
WINPR_HANDLE_SET_TYPE_AND_MODE(pFile, HANDLE_TYPE_FILE, WINPR_FD_READ);
pFile->ops = &fileOps;
pFile->common.ops = &fileOps;
pFile->lpFileName = _strdup(lpFileName);
if (!pFile->lpFileName)
@ -951,7 +943,7 @@ HANDLE_CREATOR* GetFileHandleCreator(void)
static WINPR_FILE* FileHandle_New(FILE* fp)
{
WINPR_FILE* pFile;
char name[MAX_PATH];
char name[MAX_PATH] = { 0 };
_snprintf(name, sizeof(name), "device_%d", fileno(fp));
pFile = (WINPR_FILE*)calloc(1, sizeof(WINPR_FILE));
@ -961,7 +953,7 @@ static WINPR_FILE* FileHandle_New(FILE* fp)
return NULL;
}
pFile->fp = fp;
pFile->ops = &shmOps;
pFile->common.ops = &shmOps;
pFile->lpFileName = _strdup(name);
WINPR_HANDLE_SET_TYPE_AND_MODE(pFile, HANDLE_TYPE_FILE, WINPR_FD_READ);

View File

@ -39,7 +39,7 @@
struct winpr_file
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
FILE* fp;

View File

@ -48,15 +48,7 @@ static HANDLE_CREATOR _NamedPipeClientHandleCreator;
static BOOL NamedPipeClientIsHandled(HANDLE handle)
{
WINPR_NAMED_PIPE* pFile = (WINPR_NAMED_PIPE*)handle;
if (!pFile || (pFile->Type != HANDLE_TYPE_NAMED_PIPE) || (pFile == INVALID_HANDLE_VALUE))
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_NAMED_PIPE, TRUE);
}
static BOOL NamedPipeClientCloseHandle(HANDLE handle)
@ -208,7 +200,7 @@ static HANDLE NamedPipeClientCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAcces
s.sun_family = AF_UNIX;
sprintf_s(s.sun_path, ARRAYSIZE(s.sun_path), "%s", pNamedPipe->lpFilePath);
status = connect(pNamedPipe->clientfd, (struct sockaddr*)&s, sizeof(struct sockaddr_un));
pNamedPipe->ops = &ops;
pNamedPipe->common.ops = &ops;
if (status != 0)
{
@ -301,10 +293,9 @@ int GetNamePipeFileDescriptor(HANDLE hNamedPipe)
{
#ifndef _WIN32
int fd;
WINPR_NAMED_PIPE* pNamedPipe;
pNamedPipe = (WINPR_NAMED_PIPE*)hNamedPipe;
WINPR_NAMED_PIPE* pNamedPipe = (WINPR_NAMED_PIPE*)hNamedPipe;
if (!pNamedPipe || pNamedPipe->Type != HANDLE_TYPE_NAMED_PIPE)
if (!NamedPipeClientIsHandled(hNamedPipe))
return -1;
fd = (pNamedPipe->ServerMode) ? pNamedPipe->serverfd : pNamedPipe->clientfd;

View File

@ -40,11 +40,6 @@
#define HANDLE_TYPE_TIMER_QUEUE_TIMER 12
#define HANDLE_TYPE_COMM 13
#define WINPR_HANDLE_DEF() \
ULONG Type; \
ULONG Mode; \
HANDLE_OPS* ops
typedef BOOL (*pcIsHandled)(HANDLE handle);
typedef BOOL (*pcCloseHandle)(HANDLE handle);
typedef int (*pcGetFd)(HANDLE handle);
@ -111,11 +106,32 @@ typedef struct
pcGetFileInformationByHandle GetFileInformationByHandle;
} HANDLE_OPS;
struct winpr_handle
typedef struct
{
WINPR_HANDLE_DEF();
};
typedef struct winpr_handle WINPR_HANDLE;
ULONG Type;
ULONG Mode;
HANDLE_OPS* ops;
} WINPR_HANDLE;
static INLINE BOOL WINPR_HANDLE_IS_HANDLED(HANDLE handle, ULONG type, BOOL invalidValue)
{
WINPR_HANDLE* pWinprHandle = (WINPR_HANDLE*)handle;
BOOL invalid = !pWinprHandle;
if (invalidValue)
{
if (INVALID_HANDLE_VALUE == pWinprHandle)
invalid = TRUE;
}
if (invalid || (pWinprHandle->Type != type))
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
}
static INLINE void WINPR_HANDLE_SET_TYPE_AND_MODE(void* _handle, ULONG _type, ULONG _mode)
{

View File

@ -35,15 +35,7 @@ static BOOL NoneHandleCloseHandle(HANDLE handle)
static BOOL NoneHandleIsHandle(HANDLE handle)
{
WINPR_NONE_HANDLE* none = (WINPR_NONE_HANDLE*)handle;
if (!none || none->Type != HANDLE_TYPE_NONE)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_NONE, FALSE);
}
static int NoneHandleGetFd(HANDLE handle)
@ -76,15 +68,14 @@ static HANDLE_OPS ops = { NoneHandleIsHandle,
NULL,
NULL };
HANDLE CreateNoneHandle()
HANDLE CreateNoneHandle(void)
{
WINPR_NONE_HANDLE* none;
none = (WINPR_NONE_HANDLE*)calloc(1, sizeof(WINPR_NONE_HANDLE));
WINPR_NONE_HANDLE* none = (WINPR_NONE_HANDLE*)calloc(1, sizeof(WINPR_NONE_HANDLE));
if (!none)
return NULL;
none->ops = &ops;
none->common.ops = &ops;
return (HANDLE)none;
}

View File

@ -28,7 +28,7 @@
struct winpr_none_handle
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
};
typedef struct winpr_none_handle WINPR_NONE_HANDLE;

View File

@ -66,7 +66,7 @@ VOID _InitializeObjectAttributes(POBJECT_ATTRIBUTES InitializedAttributes,
struct winpr_nt_file
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
ACCESS_MASK DesiredAccess;
OBJECT_ATTRIBUTES ObjectAttributes;

View File

@ -80,15 +80,7 @@ typedef struct
static BOOL PipeIsHandled(HANDLE handle)
{
WINPR_PIPE* pPipe = (WINPR_PIPE*)handle;
if (!pPipe || (pPipe->Type != HANDLE_TYPE_ANONYMOUS_PIPE))
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_ANONYMOUS_PIPE, FALSE);
}
static int PipeGetFd(HANDLE handle)
@ -209,7 +201,8 @@ static HANDLE_OPS ops = { PipeIsHandled,
static BOOL NamedPipeIsHandled(HANDLE handle)
{
WINPR_NAMED_PIPE* pPipe = (WINPR_NAMED_PIPE*)handle;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_NAMED_PIPE, TRUE);
WINPR_HANDLE* pPipe = (WINPR_HANDLE*)handle;
if (!pPipe || (pPipe->Type != HANDLE_TYPE_NAMED_PIPE) || (pPipe == INVALID_HANDLE_VALUE))
{
@ -509,10 +502,10 @@ BOOL CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpP
pReadPipe->fd = pipe_fd[0];
pWritePipe->fd = pipe_fd[1];
WINPR_HANDLE_SET_TYPE_AND_MODE(pReadPipe, HANDLE_TYPE_ANONYMOUS_PIPE, WINPR_FD_READ);
pReadPipe->ops = &ops;
pReadPipe->common.ops = &ops;
*((ULONG_PTR*)hReadPipe) = (ULONG_PTR)pReadPipe;
WINPR_HANDLE_SET_TYPE_AND_MODE(pWritePipe, HANDLE_TYPE_ANONYMOUS_PIPE, WINPR_FD_READ);
pWritePipe->ops = &ops;
pWritePipe->common.ops = &ops;
*((ULONG_PTR*)hWritePipe) = (ULONG_PTR)pWritePipe;
return TRUE;
}
@ -616,7 +609,7 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD
pNamedPipe->dwFlagsAndAttributes = dwOpenMode;
pNamedPipe->clientfd = -1;
pNamedPipe->ServerMode = TRUE;
pNamedPipe->ops = &namedOps;
pNamedPipe->common.ops = &namedOps;
for (index = 0; index < ArrayList_Count(g_NamedPipeServerSockets); index++)
{

View File

@ -29,7 +29,7 @@
struct winpr_pipe
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
int fd;
};
@ -41,7 +41,7 @@ typedef void (*fnUnrefNamedPipe)(WINPR_NAMED_PIPE* pNamedPipe);
struct winpr_named_pipe
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
int clientfd;
int serverfd;

View File

@ -27,6 +27,8 @@
#include <winpr/security.h>
#include "../handle/handle.h"
/**
* api-ms-win-security-base-l1-2-0.dll:
*
@ -210,3 +212,15 @@ BOOL SetSecurityDescriptorSacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bS
}
#endif
BOOL AccessTokenIsValid(HANDLE handle)
{
WINPR_HANDLE* h = (WINPR_HANDLE*)handle;
if (!h || (h->Type != HANDLE_TYPE_ACCESS_TOKEN))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return TRUE;
}

View File

@ -28,7 +28,7 @@
struct winpr_access_token
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
LPSTR Username;
LPSTR Domain;
@ -38,6 +38,8 @@ struct winpr_access_token
};
typedef struct winpr_access_token WINPR_ACCESS_TOKEN;
BOOL AccessTokenIsValid(HANDLE handle);
#endif
#endif /* WINPR_SECURITY_PRIVATE_H */

View File

@ -54,7 +54,10 @@ BOOL GetUserProfileDirectoryA(HANDLE hToken, LPSTR lpProfileDir, LPDWORD lpcchSi
WINPR_ACCESS_TOKEN* token;
token = (WINPR_ACCESS_TOKEN*)hToken;
if (!token || (token->Type != HANDLE_TYPE_ACCESS_TOKEN) || !lpcchSize)
if (!AccessTokenIsValid(hToken))
return FALSE;
if (!lpcchSize)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;

View File

@ -78,15 +78,7 @@ static BOOL LogonUserCloseHandle(HANDLE handle);
static BOOL LogonUserIsHandled(HANDLE handle)
{
WINPR_ACCESS_TOKEN* pLogonUser = (WINPR_ACCESS_TOKEN*)handle;
if (!pLogonUser || (pLogonUser->Type != HANDLE_TYPE_ACCESS_TOKEN))
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_ACCESS_TOKEN, FALSE);
}
static int LogonUserGetFd(HANDLE handle)
@ -151,7 +143,7 @@ BOOL LogonUserA(LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword, DWO
return FALSE;
WINPR_HANDLE_SET_TYPE_AND_MODE(token, HANDLE_TYPE_ACCESS_TOKEN, WINPR_FD_READ);
token->ops = &ops;
token->common.ops = &ops;
token->Username = _strdup(lpszUsername);
if (!token->Username)

View File

@ -183,15 +183,7 @@ static BOOL EventCloseHandle(HANDLE handle);
static BOOL EventIsHandled(HANDLE handle)
{
WINPR_TIMER* pEvent = (WINPR_TIMER*)handle;
if (!pEvent || (pEvent->Type != HANDLE_TYPE_EVENT))
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_EVENT, FALSE);
}
static int EventGetFd(HANDLE handle)
@ -304,7 +296,7 @@ HANDLE CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset,
event->impl.fds[1] = -1;
event->bAttached = FALSE;
event->bManualReset = bManualReset;
event->ops = &ops;
event->common.ops = &ops;
WINPR_HANDLE_SET_TYPE_AND_MODE(event, HANDLE_TYPE_EVENT, FD_READ);
if (!event->bManualReset)
@ -440,7 +432,7 @@ HANDLE CreateFileDescriptorEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL
event->bAttached = TRUE;
event->bManualReset = bManualReset;
winpr_event_init_from_fd(&event->impl, FileDescriptor);
event->ops = &ops;
event->common.ops = &ops;
WINPR_HANDLE_SET_TYPE_AND_MODE(event, HANDLE_TYPE_EVENT, mode);
handle = (HANDLE)event;
}
@ -510,7 +502,7 @@ int SetEventFileDescriptor(HANDLE hEvent, int FileDescriptor, ULONG mode)
close(event->impl.fds[0]);
event->bAttached = TRUE;
event->Mode = mode;
event->common.Mode = mode;
event->impl.fds[0] = FileDescriptor;
return 0;
#else

View File

@ -36,7 +36,7 @@ typedef struct winpr_event_impl WINPR_EVENT_IMPL;
struct winpr_event
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
WINPR_EVENT_IMPL impl;
BOOL bAttached;

View File

@ -39,15 +39,7 @@ static BOOL MutexCloseHandle(HANDLE handle);
static BOOL MutexIsHandled(HANDLE handle)
{
WINPR_TIMER* pMutex = (WINPR_TIMER*)handle;
if (!pMutex || (pMutex->Type != HANDLE_TYPE_MUTEX))
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_MUTEX, FALSE);
}
static int MutexGetFd(HANDLE handle)
@ -159,7 +151,7 @@ HANDLE CreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner,
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mutex->mutex, &attr);
WINPR_HANDLE_SET_TYPE_AND_MODE(mutex, HANDLE_TYPE_MUTEX, WINPR_FD_READ);
mutex->ops = &ops;
mutex->common.ops = &ops;
handle = (HANDLE)mutex;
if (bInitialOwner)

View File

@ -38,15 +38,7 @@ static BOOL SemaphoreCloseHandle(HANDLE handle);
static BOOL SemaphoreIsHandled(HANDLE handle)
{
WINPR_TIMER* pSemaphore = (WINPR_TIMER*)handle;
if (!pSemaphore || (pSemaphore->Type != HANDLE_TYPE_SEMAPHORE))
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_SEMAPHORE, FALSE);
}
static int SemaphoreGetFd(HANDLE handle)
@ -145,7 +137,7 @@ HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lIniti
semaphore->pipe_fd[0] = -1;
semaphore->pipe_fd[1] = -1;
semaphore->sem = (winpr_sem_t*)NULL;
semaphore->ops = &ops;
semaphore->common.ops = &ops;
#ifdef WINPR_PIPE_SEMAPHORE
if (pipe(semaphore->pipe_fd) < 0)

View File

@ -50,7 +50,7 @@
struct winpr_mutex
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
char* name;
pthread_mutex_t mutex;
};
@ -58,7 +58,7 @@ typedef struct winpr_mutex WINPR_MUTEX;
struct winpr_semaphore
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
int pipe_fd[2];
winpr_sem_t* sem;
@ -85,7 +85,7 @@ typedef struct winpr_semaphore WINPR_SEMAPHORE;
struct winpr_timer
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
int fd;
BOOL bInit;
@ -120,7 +120,7 @@ typedef struct winpr_timer_queue_timer WINPR_TIMER_QUEUE_TIMER;
struct winpr_timer_queue
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
pthread_t thread;
pthread_attr_t attr;
@ -137,7 +137,7 @@ typedef struct winpr_timer_queue WINPR_TIMER_QUEUE;
struct winpr_timer_queue_timer
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
ULONG Flags;
DWORD DueTime;

View File

@ -49,15 +49,7 @@ static BOOL TimerCloseHandle(HANDLE handle);
static BOOL TimerIsHandled(HANDLE handle)
{
WINPR_TIMER* pTimer = (WINPR_TIMER*)handle;
if (!pTimer || (pTimer->Type != HANDLE_TYPE_TIMER))
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_TIMER, FALSE);
}
static int TimerGetFd(HANDLE handle)
@ -351,7 +343,7 @@ HANDLE CreateWaitableTimerA(LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManua
if (lpTimerName)
timer->name = strdup(lpTimerName);
timer->ops = &ops;
timer->common.ops = &ops;
#if defined(TIMER_IMPL_DISPATCH) || defined(TIMER_IMPL_POSIX)
if (!winpr_event_init(&timer->event))
goto fail;

View File

@ -484,15 +484,7 @@ static BOOL ProcessHandleCloseHandle(HANDLE handle)
static BOOL ProcessHandleIsHandle(HANDLE handle)
{
WINPR_PROCESS* process = (WINPR_PROCESS*)handle;
if (!process || process->Type != HANDLE_TYPE_PROCESS)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_PROCESS, FALSE);
}
static int ProcessGetFd(HANDLE handle)
@ -538,8 +530,8 @@ HANDLE CreateProcessHandle(pid_t pid)
return NULL;
process->pid = pid;
process->Type = HANDLE_TYPE_PROCESS;
process->ops = &ops;
process->common.Type = HANDLE_TYPE_PROCESS;
process->common.ops = &ops;
return (HANDLE)process;
}

View File

@ -106,15 +106,7 @@ static void cleanup_handle(void* obj);
static BOOL ThreadIsHandled(HANDLE handle)
{
WINPR_THREAD* pThread = (WINPR_THREAD*)handle;
if (!pThread || (pThread->Type != HANDLE_TYPE_THREAD))
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
return WINPR_HANDLE_IS_HANDLED(handle, HANDLE_TYPE_THREAD, FALSE);
}
static int ThreadGetFd(HANDLE handle)
@ -439,7 +431,7 @@ static BOOL initializeThreads(PINIT_ONCE InitOnce, PVOID Parameter, PVOID* Conte
goto out;
}
mainThread.Type = HANDLE_TYPE_THREAD;
mainThread.common.Type = HANDLE_TYPE_THREAD;
mainThreadId = pthread_self();
currentThreadTlsIndex = TlsAlloc();
@ -620,7 +612,7 @@ HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize
thread->lpParameter = lpParameter;
thread->lpStartAddress = lpStartAddress;
thread->lpThreadAttributes = lpThreadAttributes;
thread->ops = &ops;
thread->common.ops = &ops;
#if defined(WITH_DEBUG_THREADS)
thread->create_stack = winpr_backtrace(20);
dump_thread(thread);

View File

@ -54,7 +54,7 @@ typedef struct
struct winpr_thread
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
ALIGN64 BOOL started;
ALIGN64 WINPR_EVENT_IMPL event;
@ -82,7 +82,7 @@ WINPR_THREAD* winpr_GetCurrentThread(VOID);
typedef struct
{
WINPR_HANDLE_DEF();
WINPR_HANDLE common;
pid_t pid;
int status;