libwinpr-thread: started stubbing threading API

This commit is contained in:
Marc-André Moreau 2012-09-17 19:17:19 -04:00
parent e40025b7fc
commit 6aabffa2cf
5 changed files with 420 additions and 0 deletions

View File

@ -0,0 +1,138 @@
/**
* WinPR: Windows Portable Runtime
* Process Thread Functions
*
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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_THREAD_H
#define WINPR_THREAD_H
#include <winpr/winpr.h>
#include <winpr/wtypes.h>
#include <winpr/handle.h>
#ifndef _WIN32
typedef struct _STARTUPINFOA
{
DWORD cb;
LPSTR lpReserved;
LPSTR lpDesktop;
LPSTR lpTitle;
DWORD dwX;
DWORD dwY;
DWORD dwXSize;
DWORD dwYSize;
DWORD dwXCountChars;
DWORD dwYCountChars;
DWORD dwFillAttribute;
DWORD dwFlags;
WORD wShowWindow;
WORD cbReserved2;
LPBYTE lpReserved2;
HANDLE hStdInput;
HANDLE hStdOutput;
HANDLE hStdError;
} STARTUPINFOA, *LPSTARTUPINFOA;
typedef struct _STARTUPINFOW
{
DWORD cb;
LPWSTR lpReserved;
LPWSTR lpDesktop;
LPWSTR lpTitle;
DWORD dwX;
DWORD dwY;
DWORD dwXSize;
DWORD dwYSize;
DWORD dwXCountChars;
DWORD dwYCountChars;
DWORD dwFillAttribute;
DWORD dwFlags;
WORD wShowWindow;
WORD cbReserved2;
LPBYTE lpReserved2;
HANDLE hStdInput;
HANDLE hStdOutput;
HANDLE hStdError;
} STARTUPINFOW, *LPSTARTUPINFOW;
#ifdef UNICODE
typedef STARTUPINFOW STARTUPINFO;
typedef LPSTARTUPINFOW LPSTARTUPINFO;
#else
typedef STARTUPINFOA STARTUPINFO;
typedef LPSTARTUPINFOA LPSTARTUPINFO;
#endif
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);
WINPR_API 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);
#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);
WINPR_API 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);
#ifdef UNICODE
#define CreateProcessAsUser CreateProcessAsUserW
#else
#define CreateProcessAsUser CreateProcessAsUserA
#endif
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);
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);
WINPR_API DWORD TlsAlloc(VOID);
WINPR_API LPVOID TlsGetValue(DWORD dwTlsIndex);
WINPR_API BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue);
WINPR_API BOOL TlsFree(DWORD dwTlsIndex);
#endif
#endif /* WINPR_THREAD_H */

View File

@ -208,6 +208,17 @@ typedef struct _SECURITY_ATTRIBUTES
BOOL bInheritHandle;
} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
typedef struct _PROCESS_INFORMATION
{
HANDLE hProcess;
HANDLE hThread;
DWORD dwProcessId;
DWORD dwThreadId;
} PROCESS_INFORMATION, *PPROCESS_INFORMATION, *LPPROCESS_INFORMATION;
typedef DWORD (*PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;
typedef void* HMODULE;
typedef void* FARPROC;

View File

@ -30,6 +30,7 @@ add_subdirectory(utils)
add_subdirectory(heap)
add_subdirectory(handle)
add_subdirectory(synch)
add_subdirectory(thread)
add_subdirectory(sysinfo)
add_subdirectory(bcrypt)
add_subdirectory(dsparse)
@ -47,6 +48,7 @@ if(WITH_MONOLITHIC_BUILD)
$<TARGET_OBJECTS:winpr-heap>
$<TARGET_OBJECTS:winpr-handle>
$<TARGET_OBJECTS:winpr-synch>
$<TARGET_OBJECTS:winpr-thread>
$<TARGET_OBJECTS:winpr-sysinfo>
$<TARGET_OBJECTS:winpr-bcrypt>
$<TARGET_OBJECTS:winpr-dsparse>

View File

@ -0,0 +1,50 @@
# WinPR: Windows Portable Runtime
# libwinpr-thread cmake build script
#
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
#
# 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(CMAKE_THREAD_PREFER_PTHREAD)
find_required_package(Threads)
set(WINPR_THREAD_SRCS
thread.c)
if(WITH_MONOLITHIC_BUILD)
add_library(winpr-thread OBJECT ${WINPR_THREAD_SRCS})
else()
add_library(winpr-thread ${WINPR_THREAD_SRCS})
endif()
set_target_properties(winpr-thread PROPERTIES VERSION ${FREERDP_VERSION_FULL} SOVERSION ${FREERDP_VERSION} PREFIX "lib")
set(WINPR_SYNCH_LIBS
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS})
if(${CMAKE_SYSTEM_NAME} MATCHES SunOS)
set(WINPR_SYNCH_LIBS ${WINPR_SYNCH_LIBS} rt)
endif()
if(WITH_MONOLITHIC_BUILD)
set(WINPR_LIBS ${WINPR_LIBS} ${WINPR_SYNCH_LIBS} PARENT_SCOPE)
else()
if(NOT WIN32)
set(WINPR_SYNCH_LIBS ${WINPR_SYNCH_LIBS} winpr-handle)
endif()
target_link_libraries(winpr-thread ${WINPR_SYNCH_LIBS})
install(TARGETS winpr-thread DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

View File

@ -0,0 +1,219 @@
/**
* WinPR: Windows Portable Runtime
* Process Thread Functions
*
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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 <winpr/thread.h>
/**
* 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
* GetThreadIdealProcessorEx
* GetThreadPriority
* 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
*/
#ifndef _WIN32
#include <pthread.h>
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 CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId)
{
pthread_t thread;
pthread_create(&thread, 0, (pthread_start_routine) lpStartAddress, lpParameter);
pthread_detach(thread);
return NULL;
}
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;
}
DWORD GetCurrentThreadId(VOID)
{
return 0;
}
DWORD ResumeThread(HANDLE hThread)
{
return 0;
}
DWORD SuspendThread(HANDLE hThread)
{
return 0;
}
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