diff --git a/winpr/include/winpr/handle.h b/winpr/include/winpr/handle.h index 6ad4aa24d..ccbc27ece 100644 --- a/winpr/include/winpr/handle.h +++ b/winpr/include/winpr/handle.h @@ -29,9 +29,10 @@ #define HANDLE_TYPE_NONE 0 #define HANDLE_TYPE_THREAD 1 -#define HANDLE_TYPE_MUTEX 2 -#define HANDLE_TYPE_SEMAPHORE 3 -#define HANDLE_TYPE_EVENT 4 +#define HANDLE_TYPE_EVENT 2 +#define HANDLE_TYPE_MUTEX 3 +#define HANDLE_TYPE_SEMAPHORE 4 +#define HANDLE_TYPE_TIMER 5 WINPR_API HANDLE winpr_Handle_Insert(ULONG Type, PVOID Object); WINPR_API BOOL winpr_Handle_Remove(HANDLE handle); diff --git a/winpr/include/winpr/interlocked.h b/winpr/include/winpr/interlocked.h new file mode 100644 index 000000000..f163dade3 --- /dev/null +++ b/winpr/include/winpr/interlocked.h @@ -0,0 +1,91 @@ +/** + * WinPR: Windows Portable Runtime + * Interlocked Singly-Linked Lists + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WINPR_INTERLOCKED_H +#define WINPR_INTERLOCKED_H + +#include +#include +#include + +#ifndef _WIN32 + +#ifdef _AMD64_ + +typedef struct _SLIST_ENTRY *PSLIST_ENTRY; +typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY +{ + PSLIST_ENTRY Next; +} SLIST_ENTRY; + +#else /* _AMD64_ */ + +#define SLIST_ENTRY SINGLE_LIST_ENTRY +#define _SLIST_ENTRY _SINGLE_LIST_ENTRY +#define PSLIST_ENTRY PSINGLE_LIST_ENTRY + +#endif /* _AMD64_ */ + +#if defined(_AMD64_) + +typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER +{ + ULONGLONG Alignment; + ULONGLONG Region; +} SLIST_HEADER; +typedef struct _SLIST_HEADER *PSLIST_HEADER; + +#else /* _AMD64_ */ + +typedef union _SLIST_HEADER +{ + ULONGLONG Alignment; + + struct + { + SLIST_ENTRY Next; + WORD Depth; + WORD Sequence; + } DUMMYSTRUCTNAME; +} SLIST_HEADER, *PSLIST_HEADER; + +#endif /* _AMD64_ */ + +WINPR_API VOID InitializeSListHead(PSLIST_HEADER ListHead); + +WINPR_API PSLIST_ENTRY InterlockedPopEntrySList(PSLIST_HEADER ListHead); +WINPR_API PSLIST_ENTRY InterlockedPushEntrySList(PSLIST_HEADER ListHead, PSLIST_ENTRY ListEntry); +WINPR_API PSLIST_ENTRY InterlockedPushListSListEx(PSLIST_HEADER ListHead, PSLIST_ENTRY List, PSLIST_ENTRY ListEnd, ULONG Count); +WINPR_API PSLIST_ENTRY InterlockedFlushSList(PSLIST_HEADER ListHead); + +WINPR_API USHORT QueryDepthSList(PSLIST_HEADER ListHead); + +WINPR_API LONG InterlockedIncrement(LONG volatile *Addend); +WINPR_API LONG InterlockedDecrement(LONG volatile *Addend); + +WINPR_API LONG InterlockedExchange(LONG volatile *Target, LONG Value); +WINPR_API LONG InterlockedExchangeAdd(LONG volatile *Addend, LONG Value); + +WINPR_API LONG InterlockedCompareExchange(LONG volatile *Destination,LONG ExChange, LONG Comperand); +WINPR_API LONG64 InterlockedCompareExchange64(LONG64 volatile *Destination, LONG64 ExChange, LONG64 Comperand); + +#endif /* _WIN32 */ + +#endif /* WINPR_INTERLOCKED_H */ + diff --git a/winpr/include/winpr/spec.h b/winpr/include/winpr/spec.h new file mode 100644 index 000000000..8aa4f57cb --- /dev/null +++ b/winpr/include/winpr/spec.h @@ -0,0 +1,41 @@ +/** + * WinPR: Windows Portable Runtime + * Compiler Specification Strings + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WINPR_SPEC_H +#define WINPR_SPEC_H + +#if defined(__x86_64) && \ + !(defined(_X86_) || defined(__i386__) || defined(_IA64_)) +#if !defined(_AMD64_) +#define _AMD64_ +#endif +#endif /* _AMD64_ */ + +#ifndef DECLSPEC_ALIGN +#if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(MIDL_PASS) +#define DECLSPEC_ALIGN(x) __declspec(align(x)) +#elif defined(__GNUC__) +#define DECLSPEC_ALIGN(x) __attribute__ ((__aligned__ (x))) +#else +#define DECLSPEC_ALIGN(x) +#endif +#endif /* DECLSPEC_ALIGN */ + +#endif /* WINPR_SPEC_H */ + diff --git a/winpr/include/winpr/synch.h b/winpr/include/winpr/synch.h index 69b8d8620..1ace46090 100644 --- a/winpr/include/winpr/synch.h +++ b/winpr/include/winpr/synch.h @@ -58,19 +58,15 @@ WINPR_API BOOL ReleaseMutex(HANDLE hMutex); WINPR_API HANDLE CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCSTR lpName); WINPR_API HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCWSTR lpName); -#ifdef UNICODE -#define CreateSemaphore CreateSemaphoreW -#else -#define CreateSemaphore CreateSemaphoreA -#endif - WINPR_API HANDLE OpenSemaphoreA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName); WINPR_API HANDLE OpenSemaphoreW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName); #ifdef UNICODE -#define OpenSemaphore OpenSemaphoreW +#define CreateSemaphore CreateSemaphoreW +#define OpenSemaphore OpenSemaphoreW #else -#define OpenSemaphore OpenSemaphoreA +#define CreateSemaphore CreateSemaphoreA +#define OpenSemaphore OpenSemaphoreA #endif WINPR_API BOOL ReleaseSemaphore(HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount); @@ -94,6 +90,24 @@ WINPR_API HANDLE OpenEventW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR WINPR_API BOOL SetEvent(HANDLE hEvent); WINPR_API BOOL ResetEvent(HANDLE hEvent); +/* One-Time Initialization */ + +#define CALLBACK + +typedef union _RTL_RUN_ONCE +{ + PVOID Ptr; +} RTL_RUN_ONCE, *PRTL_RUN_ONCE; + +typedef PRTL_RUN_ONCE PINIT_ONCE; +typedef PRTL_RUN_ONCE LPINIT_ONCE; +typedef BOOL CALLBACK (*PINIT_ONCE_FN) (PINIT_ONCE InitOnce, PVOID Parameter, PVOID* Context); + +WINPR_API BOOL InitOnceBeginInitialize(LPINIT_ONCE lpInitOnce, DWORD dwFlags, PBOOL fPending, LPVOID* lpContext); +WINPR_API BOOL InitOnceComplete(LPINIT_ONCE lpInitOnce, DWORD dwFlags, LPVOID lpContext); +WINPR_API BOOL InitOnceExecuteOnce(PINIT_ONCE InitOnce, PINIT_ONCE_FN InitFn, PVOID Parameter, LPVOID* Context); +WINPR_API VOID InitOnceInitialize(PINIT_ONCE InitOnce); + /* Slim Reader/Writer (SRW) Lock */ typedef PVOID RTL_SRWLOCK; @@ -131,6 +145,7 @@ typedef PRTL_CRITICAL_SECTION PCRITICAL_SECTION; typedef PRTL_CRITICAL_SECTION LPCRITICAL_SECTION; WINPR_API VOID InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection); +WINPR_API BOOL InitializeCriticalSectionEx(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD Flags); WINPR_API BOOL InitializeCriticalSectionAndSpinCount(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount); WINPR_API DWORD SetCriticalSectionSpinCount(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount); @@ -156,12 +171,66 @@ WINPR_API BOOL DeleteSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrier) WINPR_API VOID Sleep(DWORD dwMilliseconds); WINPR_API DWORD SleepEx(DWORD dwMilliseconds, BOOL bAlertable); +/* Address */ + +WINPR_API VOID WakeByAddressAll(PVOID Address); +WINPR_API VOID WakeByAddressSingle(PVOID Address); + +WINPR_API BOOL WaitOnAddress(VOID volatile *Address, PVOID CompareAddress, SIZE_T AddressSize, DWORD dwMilliseconds); + /* Wait */ WINPR_API DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds); WINPR_API DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll, DWORD dwMilliseconds); WINPR_API DWORD WaitForMultipleObjectsEx(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll, DWORD dwMilliseconds, BOOL bAlertable); +WINPR_API DWORD SignalObjectAndWait(HANDLE hObjectToSignal, HANDLE hObjectToWaitOn, DWORD dwMilliseconds, BOOL bAlertable); + +/* Waitable Timer */ + +typedef struct _REASON_CONTEXT +{ + ULONG Version; + DWORD Flags; + + union + { + struct + { + HMODULE LocalizedReasonModule; + ULONG LocalizedReasonId; + ULONG ReasonStringCount; + LPWSTR* ReasonStrings; + } Detailed; + + LPWSTR SimpleReasonString; + } Reason; +} REASON_CONTEXT, *PREASON_CONTEXT; + +typedef VOID (*PTIMERAPCROUTINE)(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue, DWORD dwTimerHighValue); + +WINPR_API HANDLE CreateWaitableTimerExA(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess); +WINPR_API HANDLE CreateWaitableTimerExW(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCWSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess); + +WINPR_API BOOL SetWaitableTimer(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPeriod, + PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, BOOL fResume); + +WINPR_API BOOL SetWaitableTimerEx(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPeriod, + PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, PREASON_CONTEXT WakeContext, ULONG TolerableDelay); + +WINPR_API HANDLE OpenWaitableTimerA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpTimerName); +WINPR_API HANDLE OpenWaitableTimerW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpTimerName); + +WINPR_API BOOL CancelWaitableTimer(HANDLE hTimer); + +#ifdef UNICODE +#define CreateWaitableTimerEx CreateWaitableTimerExW +#define OpenWaitableTimer OpenWaitableTimerW +#else +#define CreateWaitableTimerEx CreateWaitableTimerExA +#define OpenWaitableTimer OpenWaitableTimerA +#endif + #endif #endif /* WINPR_SYNCH_H */ diff --git a/winpr/include/winpr/thread.h b/winpr/include/winpr/thread.h index 1957c83ba..a89bda05b 100644 --- a/winpr/include/winpr/thread.h +++ b/winpr/include/winpr/thread.h @@ -79,6 +79,8 @@ typedef STARTUPINFOA STARTUPINFO; typedef LPSTARTUPINFOA LPSTARTUPINFO; #endif +/* Process */ + WINPR_API BOOL CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation); @@ -87,12 +89,6 @@ WINPR_API BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, L LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation); -#ifdef UNICODE -#define CreateProcess CreateProcessW -#else -#define CreateProcess CreateProcessA -#endif - WINPR_API BOOL CreateProcessAsUserA(HANDLE hToken, LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation); @@ -102,24 +98,30 @@ WINPR_API BOOL CreateProcessAsUserW(HANDLE hToken, LPCWSTR lpApplicationName, LP LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation); #ifdef UNICODE +#define CreateProcess CreateProcessW #define CreateProcessAsUser CreateProcessAsUserW #else +#define CreateProcess CreateProcessA #define CreateProcessAsUser CreateProcessAsUserA #endif +WINPR_API VOID ExitProcess(UINT uExitCode); + +WINPR_API HANDLE GetCurrentProcess(VOID); +WINPR_API DWORD GetCurrentProcessId(VOID); + +WINPR_API BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode); + +/* Thread */ + WINPR_API HANDLE CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,LPVOID lpParameter,DWORD dwCreationFlags,LPDWORD lpThreadId); WINPR_API HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId); -WINPR_API VOID ExitProcess(UINT uExitCode); WINPR_API VOID ExitThread(DWORD dwExitCode); -WINPR_API HANDLE GetCurrentProcess(VOID); -WINPR_API DWORD GetCurrentProcessId(VOID); -WINPR_API DWORD GetCurrentProcessorNumber(VOID); - WINPR_API HANDLE GetCurrentThread(VOID); WINPR_API DWORD GetCurrentThreadId(VOID); @@ -127,9 +129,14 @@ WINPR_API DWORD ResumeThread(HANDLE hThread); WINPR_API DWORD SuspendThread(HANDLE hThread); WINPR_API BOOL SwitchToThread(VOID); -WINPR_API BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode); WINPR_API BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode); +/* Processor */ + +WINPR_API DWORD GetCurrentProcessorNumber(VOID); + +/* Thread-Local Storage */ + WINPR_API DWORD TlsAlloc(VOID); WINPR_API LPVOID TlsGetValue(DWORD dwTlsIndex); WINPR_API BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue); diff --git a/winpr/include/winpr/wtypes.h b/winpr/include/winpr/wtypes.h index 6600cb9f7..72a85d779 100644 --- a/winpr/include/winpr/wtypes.h +++ b/winpr/include/winpr/wtypes.h @@ -160,6 +160,23 @@ typedef union _ULARGE_INTEGER ULONGLONG QuadPart; } ULARGE_INTEGER, *PULARGE_INTEGER; +typedef union _LARGE_INTEGER +{ + struct + { + DWORD LowPart; + LONG HighPart; + }; + + struct + { + DWORD LowPart; + LONG HighPart; + } u; + + LONGLONG QuadPart; +} LARGE_INTEGER, *PLARGE_INTEGER; + typedef struct _FILETIME { DWORD dwLowDateTime; diff --git a/winpr/libwinpr/CMakeLists.txt b/winpr/libwinpr/CMakeLists.txt index 5b1472347..4a5478314 100644 --- a/winpr/libwinpr/CMakeLists.txt +++ b/winpr/libwinpr/CMakeLists.txt @@ -28,6 +28,7 @@ endif() add_subdirectory(crt) add_subdirectory(utils) add_subdirectory(heap) +add_subdirectory(interlocked) add_subdirectory(handle) add_subdirectory(synch) add_subdirectory(thread) @@ -46,6 +47,7 @@ if(WITH_MONOLITHIC_BUILD) $ $ $ + $ $ $ $ diff --git a/winpr/libwinpr/interlocked/CMakeLists.txt b/winpr/libwinpr/interlocked/CMakeLists.txt new file mode 100644 index 000000000..fa4e89f4d --- /dev/null +++ b/winpr/libwinpr/interlocked/CMakeLists.txt @@ -0,0 +1,34 @@ +# WinPR: Windows Portable Runtime +# libwinpr-interlocked cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(WINPR_INTERLOCKED_SRCS + interlocked.c) + +if(WITH_MONOLITHIC_BUILD) + add_library(winpr-interlocked OBJECT ${WINPR_INTERLOCKED_SRCS}) +else() + add_library(winpr-interlocked ${WINPR_INTERLOCKED_SRCS}) +endif() + +set_target_properties(winpr-interlocked PROPERTIES VERSION ${FREERDP_VERSION_FULL} SOVERSION ${FREERDP_VERSION} PREFIX "lib") + +if(WITH_MONOLITHIC_BUILD) + +else() + install(TARGETS winpr-interlocked DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif() + diff --git a/winpr/libwinpr/interlocked/interlocked.c b/winpr/libwinpr/interlocked/interlocked.c new file mode 100644 index 000000000..28d21f71e --- /dev/null +++ b/winpr/libwinpr/interlocked/interlocked.c @@ -0,0 +1,105 @@ +/** + * WinPR: Windows Portable Runtime + * Interlocked Singly-Linked Lists + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +/** + * api-ms-win-core-interlocked-l1-2-0.dll: + * + * InitializeSListHead + * InterlockedPopEntrySList + * InterlockedPushEntrySList + * InterlockedPushListSListEx + * InterlockedFlushSList + * QueryDepthSList + * InterlockedIncrement + * InterlockedDecrement + * InterlockedExchange + * InterlockedExchangeAdd + * InterlockedCompareExchange + * InterlockedCompareExchange64 + */ + +#ifndef _WIN32 + +VOID InitializeSListHead(PSLIST_HEADER ListHead) +{ + +} + +PSLIST_ENTRY InterlockedPopEntrySList(PSLIST_HEADER ListHead) +{ + return NULL; +} + +PSLIST_ENTRY InterlockedPushEntrySList(PSLIST_HEADER ListHead, PSLIST_ENTRY ListEntry) +{ + return NULL; +} + +PSLIST_ENTRY InterlockedPushListSListEx(PSLIST_HEADER ListHead, PSLIST_ENTRY List, PSLIST_ENTRY ListEnd, ULONG Count) +{ + return NULL; +} + +PSLIST_ENTRY InterlockedFlushSList(PSLIST_HEADER ListHead) +{ + return NULL; +} + +USHORT QueryDepthSList(PSLIST_HEADER ListHead) +{ + return 0; +} + +LONG InterlockedIncrement(LONG volatile *Addend) +{ + return 0; +} + +LONG InterlockedDecrement(LONG volatile *Addend) +{ + return 0; +} + +LONG InterlockedExchange(LONG volatile *Target, LONG Value) +{ + return 0; +} + +LONG InterlockedExchangeAdd(LONG volatile *Addend, LONG Value) +{ + return 0; +} + +LONG InterlockedCompareExchange(LONG volatile *Destination,LONG ExChange, LONG Comperand) +{ + return 0; +} + +LONG64 InterlockedCompareExchange64(LONG64 volatile *Destination, LONG64 ExChange, LONG64 Comperand) +{ + return 0; +} + +#endif diff --git a/winpr/libwinpr/synch/CMakeLists.txt b/winpr/libwinpr/synch/CMakeLists.txt index 41b3b39ff..32b55615a 100644 --- a/winpr/libwinpr/synch/CMakeLists.txt +++ b/winpr/libwinpr/synch/CMakeLists.txt @@ -19,16 +19,19 @@ set(CMAKE_THREAD_PREFER_PTHREAD) find_required_package(Threads) set(WINPR_SYNCH_SRCS + address.c barrier.c condition.c critical.c event.c + init.c mutex.c semaphore.c sleep.c srw.c synch.c synch.h + timer.c wait.c) if(WITH_MONOLITHIC_BUILD) @@ -57,3 +60,4 @@ else() target_link_libraries(winpr-synch ${WINPR_SYNCH_LIBS}) install(TARGETS winpr-synch DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() + diff --git a/winpr/libwinpr/synch/address.c b/winpr/libwinpr/synch/address.c new file mode 100644 index 000000000..5c225a492 --- /dev/null +++ b/winpr/libwinpr/synch/address.c @@ -0,0 +1,45 @@ +/** + * WinPR: Windows Portable Runtime + * Synchronization Functions + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +/** + * WakeByAddressAll + * WakeByAddressSingle + * WaitOnAddress + */ + +VOID WakeByAddressAll(PVOID Address) +{ + +} + +VOID WakeByAddressSingle(PVOID Address) +{ + +} + +BOOL WaitOnAddress(VOID volatile *Address, PVOID CompareAddress, SIZE_T AddressSize, DWORD dwMilliseconds) +{ + return TRUE; +} diff --git a/winpr/libwinpr/synch/critical.c b/winpr/libwinpr/synch/critical.c index 96de5ea41..94a8f6fa0 100644 --- a/winpr/libwinpr/synch/critical.c +++ b/winpr/libwinpr/synch/critical.c @@ -39,6 +39,11 @@ VOID InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection) } +BOOL InitializeCriticalSectionEx(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD Flags) +{ + return TRUE; +} + BOOL InitializeCriticalSectionAndSpinCount(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount) { return TRUE; diff --git a/winpr/libwinpr/synch/init.c b/winpr/libwinpr/synch/init.c new file mode 100644 index 000000000..b8f765a15 --- /dev/null +++ b/winpr/libwinpr/synch/init.c @@ -0,0 +1,51 @@ +/** + * WinPR: Windows Portable Runtime + * Synchronization Functions + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +/** + * InitOnceBeginInitialize + * InitOnceComplete + * InitOnceExecuteOnce + * InitOnceInitialize + */ + +BOOL InitOnceBeginInitialize(LPINIT_ONCE lpInitOnce, DWORD dwFlags, PBOOL fPending, LPVOID* lpContext) +{ + return TRUE; +} + +BOOL InitOnceComplete(LPINIT_ONCE lpInitOnce, DWORD dwFlags, LPVOID lpContext) +{ + return TRUE; +} + +BOOL InitOnceExecuteOnce(PINIT_ONCE InitOnce, PINIT_ONCE_FN InitFn, PVOID Parameter, LPVOID* Context) +{ + return TRUE; +} + +VOID InitOnceInitialize(PINIT_ONCE InitOnce) +{ + +} diff --git a/winpr/libwinpr/synch/synch.c b/winpr/libwinpr/synch/synch.c index c68cf65e3..d27a73f85 100644 --- a/winpr/libwinpr/synch/synch.c +++ b/winpr/libwinpr/synch/synch.c @@ -23,21 +23,3 @@ #include -/** - * api-ms-win-core-synch-l1-2-0.dll: - * - * CancelWaitableTimer - * CreateWaitableTimerExW - * InitOnceBeginInitialize - * InitOnceComplete - * InitOnceExecuteOnce - * InitOnceInitialize - * OpenWaitableTimerW - * SetWaitableTimer - * SetWaitableTimerEx - * SignalObjectAndWait - * WaitOnAddress - * WakeByAddressAll - * WakeByAddressSingle - */ - diff --git a/winpr/libwinpr/synch/timer.c b/winpr/libwinpr/synch/timer.c new file mode 100644 index 000000000..a0baaef4f --- /dev/null +++ b/winpr/libwinpr/synch/timer.c @@ -0,0 +1,69 @@ +/** + * WinPR: Windows Portable Runtime + * Synchronization Functions + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +/** + * CreateWaitableTimerExW + * OpenWaitableTimerW + * SetWaitableTimer + * SetWaitableTimerEx + * CancelWaitableTimer + */ + +HANDLE CreateWaitableTimerExA(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess) +{ + return NULL; +} + +HANDLE CreateWaitableTimerExW(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCWSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess) +{ + return NULL; +} + +BOOL SetWaitableTimer(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPeriod, + PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, BOOL fResume) +{ + return TRUE; +} + +BOOL SetWaitableTimerEx(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPeriod, + PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, PREASON_CONTEXT WakeContext, ULONG TolerableDelay) +{ + return TRUE; +} + +HANDLE OpenWaitableTimerA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpTimerName) +{ + return NULL; +} + +HANDLE OpenWaitableTimerW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpTimerName) +{ + return NULL; +} + +BOOL CancelWaitableTimer(HANDLE hTimer) +{ + return TRUE; +} diff --git a/winpr/libwinpr/synch/wait.c b/winpr/libwinpr/synch/wait.c index 7304fa88d..d03b6efed 100644 --- a/winpr/libwinpr/synch/wait.c +++ b/winpr/libwinpr/synch/wait.c @@ -29,6 +29,7 @@ * WaitForSingleObject * WaitForSingleObjectEx * WaitForMultipleObjectsEx + * SignalObjectAndWait */ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) @@ -51,3 +52,8 @@ DWORD WaitForMultipleObjectsEx(DWORD nCount, const HANDLE* lpHandles, BOOL bWait { return 0; } + +DWORD SignalObjectAndWait(HANDLE hObjectToSignal, HANDLE hObjectToWaitOn, DWORD dwMilliseconds, BOOL bAlertable) +{ + return 0; +} diff --git a/winpr/libwinpr/thread/CMakeLists.txt b/winpr/libwinpr/thread/CMakeLists.txt index b72e39feb..b3fbe810a 100644 --- a/winpr/libwinpr/thread/CMakeLists.txt +++ b/winpr/libwinpr/thread/CMakeLists.txt @@ -19,7 +19,10 @@ set(CMAKE_THREAD_PREFER_PTHREAD) find_required_package(Threads) set(WINPR_THREAD_SRCS - thread.c) + process.c + processor.c + thread.c + tls.c) if(WITH_MONOLITHIC_BUILD) add_library(winpr-thread OBJECT ${WINPR_THREAD_SRCS}) diff --git a/winpr/libwinpr/thread/process.c b/winpr/libwinpr/thread/process.c new file mode 100644 index 000000000..c786178f2 --- /dev/null +++ b/winpr/libwinpr/thread/process.c @@ -0,0 +1,112 @@ +/** + * WinPR: Windows Portable Runtime + * Process Thread Functions + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include + +/** + * CreateProcessA + * CreateProcessW + * CreateProcessAsUserA + * CreateProcessAsUserW + * ExitProcess + * GetCurrentProcess + * GetCurrentProcessId + * GetExitCodeProcess + * GetProcessHandleCount + * GetProcessId + * GetProcessIdOfThread + * GetProcessMitigationPolicy + * GetProcessTimes + * GetProcessVersion + * OpenProcess + * OpenProcessToken + * ProcessIdToSessionId + * SetProcessAffinityUpdateMode + * SetProcessMitigationPolicy + * SetProcessShutdownParameters + * TerminateProcess + */ + +#ifndef _WIN32 + +#include + +typedef void *(*pthread_start_routine)(void*); + +BOOL CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, + LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation) +{ + return TRUE; +} + +BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, + LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation) +{ + return TRUE; +} + +BOOL CreateProcessAsUserA(HANDLE hToken, LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, + LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation) +{ + return TRUE; +} + +BOOL CreateProcessAsUserW(HANDLE hToken, LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, + LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation) +{ + return TRUE; +} + +VOID ExitProcess(UINT uExitCode) +{ + +} + +HANDLE GetCurrentProcess(VOID) +{ + return NULL; +} + +DWORD GetCurrentProcessId(VOID) +{ + return 0; +} + +DWORD GetProcessId(HANDLE Process) +{ + return 0; +} + +BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode) +{ + return TRUE; +} + +#endif + diff --git a/winpr/libwinpr/thread/processor.c b/winpr/libwinpr/thread/processor.c new file mode 100644 index 000000000..9383cc208 --- /dev/null +++ b/winpr/libwinpr/thread/processor.c @@ -0,0 +1,44 @@ +/** + * WinPR: Windows Portable Runtime + * Process Thread Functions + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include + +/** + * GetCurrentProcessorNumber + * GetCurrentProcessorNumberEx + * GetThreadIdealProcessorEx + * SetThreadIdealProcessorEx + * IsProcessorFeaturePresent + */ + +#ifndef _WIN32 + +DWORD GetCurrentProcessorNumber(VOID) +{ + return 0; +} + +#endif + diff --git a/winpr/libwinpr/thread/thread.c b/winpr/libwinpr/thread/thread.c index 2168ae8f9..d3b6ed912 100644 --- a/winpr/libwinpr/thread/thread.c +++ b/winpr/libwinpr/thread/thread.c @@ -28,33 +28,18 @@ /** * api-ms-win-core-processthreads-l1-1-1.dll * - * CreateProcessA - * CreateProcessAsUserW - * CreateProcessW * CreateRemoteThread * CreateRemoteThreadEx * CreateThread * DeleteProcThreadAttributeList - * ExitProcess * ExitThread * FlushInstructionCache * FlushProcessWriteBuffers - * GetCurrentProcess - * GetCurrentProcessId - * GetCurrentProcessorNumber - * GetCurrentProcessorNumberEx * GetCurrentThread * GetCurrentThreadId * GetCurrentThreadStackLimits - * GetExitCodeProcess * GetExitCodeThread * GetPriorityClass - * GetProcessHandleCount - * GetProcessId - * GetProcessIdOfThread - * GetProcessMitigationPolicy - * GetProcessTimes - * GetProcessVersion * GetStartupInfoW * GetThreadContext * GetThreadId @@ -63,33 +48,20 @@ * GetThreadPriorityBoost * GetThreadTimes * InitializeProcThreadAttributeList - * IsProcessorFeaturePresent - * OpenProcess - * OpenProcessToken * OpenThread * OpenThreadToken - * ProcessIdToSessionId * QueryProcessAffinityUpdateMode * QueueUserAPC * ResumeThread * SetPriorityClass - * SetProcessAffinityUpdateMode - * SetProcessMitigationPolicy - * SetProcessShutdownParameters * SetThreadContext - * SetThreadIdealProcessorEx * SetThreadPriority * SetThreadPriorityBoost * SetThreadStackGuarantee * SetThreadToken * SuspendThread * SwitchToThread - * TerminateProcess * TerminateThread - * TlsAlloc - * TlsFree - * TlsGetValue - * TlsSetValue * UpdateProcThreadAttribute */ @@ -99,34 +71,6 @@ typedef void *(*pthread_start_routine)(void*); -BOOL CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, - LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, - LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation) -{ - return TRUE; -} - -BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, - LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, - LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation) -{ - return TRUE; -} - -BOOL CreateProcessAsUserA(HANDLE hToken, LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, - LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, - LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation) -{ - return TRUE; -} - -BOOL CreateProcessAsUserW(HANDLE hToken, LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, - LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, - LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation) -{ - return TRUE; -} - HANDLE CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,LPVOID lpParameter,DWORD dwCreationFlags,LPDWORD lpThreadId) { @@ -144,31 +88,11 @@ HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize return winpr_Handle_Insert(HANDLE_TYPE_THREAD, (void*) thread); } -VOID ExitProcess(UINT uExitCode) -{ - -} - VOID ExitThread(DWORD dwExitCode) { } -HANDLE GetCurrentProcess(VOID) -{ - return NULL; -} - -DWORD GetCurrentProcessId(VOID) -{ - return 0; -} - -DWORD GetCurrentProcessorNumber(VOID) -{ - return 0; -} - HANDLE GetCurrentThread(VOID) { return NULL; @@ -179,11 +103,6 @@ DWORD GetCurrentThreadId(VOID) return 0; } -DWORD GetProcessId(HANDLE Process) -{ - return 0; -} - DWORD ResumeThread(HANDLE hThread) { return 0; @@ -199,35 +118,10 @@ BOOL SwitchToThread(VOID) return TRUE; } -BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode) -{ - return TRUE; -} - BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode) { return TRUE; } -DWORD TlsAlloc(VOID) -{ - return 0; -} - -LPVOID TlsGetValue(DWORD dwTlsIndex) -{ - return NULL; -} - -BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) -{ - return TRUE; -} - -BOOL TlsFree(DWORD dwTlsIndex) -{ - return TRUE; -} - #endif diff --git a/winpr/libwinpr/thread/tls.c b/winpr/libwinpr/thread/tls.c new file mode 100644 index 000000000..491aabc33 --- /dev/null +++ b/winpr/libwinpr/thread/tls.c @@ -0,0 +1,58 @@ +/** + * WinPR: Windows Portable Runtime + * Process Thread Functions + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include + +/** + * TlsAlloc + * TlsFree + * TlsGetValue + * TlsSetValue + */ + +#ifndef _WIN32 + +DWORD TlsAlloc(VOID) +{ + return 0; +} + +LPVOID TlsGetValue(DWORD dwTlsIndex) +{ + return NULL; +} + +BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) +{ + return TRUE; +} + +BOOL TlsFree(DWORD dwTlsIndex) +{ + return TRUE; +} + +#endif +