Milestone 5: deliver embedded RDP sessions and lifecycle hardening
This commit is contained in:
22
third_party/FreeRDP/winpr/libwinpr/error/CMakeLists.txt
vendored
Normal file
22
third_party/FreeRDP/winpr/libwinpr/error/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
# WinPR: Windows Portable Runtime
|
||||
# libwinpr-error 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.
|
||||
|
||||
winpr_module_add(error.c)
|
||||
|
||||
if(BUILD_TESTING_INTERNAL OR BUILD_TESTING)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
9
third_party/FreeRDP/winpr/libwinpr/error/ModuleOptions.cmake
vendored
Normal file
9
third_party/FreeRDP/winpr/libwinpr/error/ModuleOptions.cmake
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
set(MINWIN_LAYER "1")
|
||||
set(MINWIN_GROUP "core")
|
||||
set(MINWIN_MAJOR_VERSION "1")
|
||||
set(MINWIN_MINOR_VERSION "1")
|
||||
set(MINWIN_SHORT_NAME "errorhandling")
|
||||
set(MINWIN_LONG_NAME "Error Handling Functions")
|
||||
set(MODULE_LIBRARY_NAME
|
||||
"api-ms-win-${MINWIN_GROUP}-${MINWIN_SHORT_NAME}-l${MINWIN_LAYER}-${MINWIN_MAJOR_VERSION}-${MINWIN_MINOR_VERSION}"
|
||||
)
|
||||
115
third_party/FreeRDP/winpr/libwinpr/error/error.c
vendored
Normal file
115
third_party/FreeRDP/winpr/libwinpr/error/error.c
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Error Handling 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.
|
||||
*/
|
||||
|
||||
#include <winpr/config.h>
|
||||
|
||||
#include <winpr/error.h>
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <winpr/nt.h>
|
||||
|
||||
UINT GetErrorMode(void)
|
||||
{
|
||||
WLog_ERR("TODO", "TOdO: implement");
|
||||
return 0;
|
||||
}
|
||||
|
||||
UINT SetErrorMode(WINPR_ATTR_UNUSED UINT uMode)
|
||||
{
|
||||
WLog_ERR("TODO", "TOdO: implement");
|
||||
return 0;
|
||||
}
|
||||
|
||||
DWORD GetLastError(VOID)
|
||||
{
|
||||
PTEB pt = NtCurrentTeb();
|
||||
if (pt)
|
||||
{
|
||||
return pt->LastErrorValue;
|
||||
}
|
||||
return ERROR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
VOID SetLastError(DWORD dwErrCode)
|
||||
{
|
||||
PTEB pt = NtCurrentTeb();
|
||||
if (pt)
|
||||
{
|
||||
pt->LastErrorValue = dwErrCode;
|
||||
}
|
||||
}
|
||||
|
||||
VOID RestoreLastError(WINPR_ATTR_UNUSED DWORD dwErrCode)
|
||||
{
|
||||
WLog_ERR("TODO", "TOdO: implement");
|
||||
}
|
||||
|
||||
VOID RaiseException(WINPR_ATTR_UNUSED DWORD dwExceptionCode,
|
||||
WINPR_ATTR_UNUSED DWORD dwExceptionFlags,
|
||||
WINPR_ATTR_UNUSED DWORD nNumberOfArguments,
|
||||
WINPR_ATTR_UNUSED CONST ULONG_PTR* lpArguments)
|
||||
{
|
||||
WLog_ERR("TODO", "TOdO: implement");
|
||||
}
|
||||
|
||||
LONG UnhandledExceptionFilter(WINPR_ATTR_UNUSED PEXCEPTION_POINTERS ExceptionInfo)
|
||||
{
|
||||
WLog_ERR("TODO", "TOdO: implement");
|
||||
return 0;
|
||||
}
|
||||
|
||||
LPTOP_LEVEL_EXCEPTION_FILTER
|
||||
SetUnhandledExceptionFilter(
|
||||
WINPR_ATTR_UNUSED LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
|
||||
{
|
||||
WLog_ERR("TODO", "TOdO: implement");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PVOID AddVectoredExceptionHandler(WINPR_ATTR_UNUSED ULONG First,
|
||||
WINPR_ATTR_UNUSED PVECTORED_EXCEPTION_HANDLER Handler)
|
||||
{
|
||||
WLog_ERR("TODO", "TOdO: implement");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ULONG RemoveVectoredExceptionHandler(WINPR_ATTR_UNUSED PVOID Handle)
|
||||
{
|
||||
WLog_ERR("TODO", "TOdO: implement");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PVOID AddVectoredContinueHandler(WINPR_ATTR_UNUSED ULONG First,
|
||||
WINPR_ATTR_UNUSED PVECTORED_EXCEPTION_HANDLER Handler)
|
||||
{
|
||||
WLog_ERR("TODO", "TOdO: implement");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ULONG RemoveVectoredContinueHandler(WINPR_ATTR_UNUSED PVOID Handle)
|
||||
{
|
||||
WLog_ERR("TODO", "TOdO: implement");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
23
third_party/FreeRDP/winpr/libwinpr/error/test/CMakeLists.txt
vendored
Normal file
23
third_party/FreeRDP/winpr/libwinpr/error/test/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
set(MODULE_NAME "TestError")
|
||||
set(MODULE_PREFIX "TEST_ERROR")
|
||||
|
||||
disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
|
||||
|
||||
set(${MODULE_PREFIX}_TESTS TestErrorSetLastError.c)
|
||||
|
||||
create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS})
|
||||
|
||||
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
|
||||
|
||||
target_link_libraries(${MODULE_NAME} winpr)
|
||||
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
|
||||
|
||||
foreach(test ${${MODULE_PREFIX}_TESTS})
|
||||
get_filename_component(TestName ${test} NAME_WE)
|
||||
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
|
||||
endforeach()
|
||||
|
||||
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")
|
||||
151
third_party/FreeRDP/winpr/libwinpr/error/test/TestErrorSetLastError.c
vendored
Normal file
151
third_party/FreeRDP/winpr/libwinpr/error/test/TestErrorSetLastError.c
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* CTest for winpr's SetLastError/GetLastError
|
||||
*
|
||||
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
* Copyright 2013 Thincast Technologies GmbH
|
||||
* Copyright 2013 Norbert Federa <norbert.federa@thincast.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.
|
||||
*/
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
#include <winpr/wlog.h>
|
||||
#include <winpr/synch.h>
|
||||
#include <winpr/thread.h>
|
||||
#include <winpr/interlocked.h>
|
||||
|
||||
#include <winpr/error.h>
|
||||
|
||||
static int status = 0;
|
||||
|
||||
static LONG* pLoopCount = nullptr;
|
||||
static BOOL bStopTest = FALSE;
|
||||
|
||||
static UINT32 prand(UINT32 max)
|
||||
{
|
||||
UINT32 tmp = 0;
|
||||
if (max <= 1)
|
||||
return 1;
|
||||
if (winpr_RAND(&tmp, sizeof(tmp)) < 0)
|
||||
{
|
||||
(void)fprintf(stderr, "winpr_RAND failing, retry...\n");
|
||||
// NOLINTNEXTLINE(concurrency-mt-unsafe)
|
||||
exit(-1);
|
||||
}
|
||||
return tmp % (max - 1) + 1;
|
||||
}
|
||||
|
||||
static DWORD WINAPI test_error_thread(LPVOID arg)
|
||||
{
|
||||
int id = 0;
|
||||
DWORD dwErrorSet = 0;
|
||||
DWORD dwErrorGet = 0;
|
||||
|
||||
id = (int)(size_t)arg;
|
||||
|
||||
do
|
||||
{
|
||||
dwErrorSet = prand(UINT32_MAX - 1) + 1;
|
||||
SetLastError(dwErrorSet);
|
||||
if ((dwErrorGet = GetLastError()) != dwErrorSet)
|
||||
{
|
||||
printf("GetLastError() failure (thread %d): Expected: 0x%08" PRIX32
|
||||
", Actual: 0x%08" PRIX32 "\n",
|
||||
id, dwErrorSet, dwErrorGet);
|
||||
if (!status)
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
InterlockedIncrement(pLoopCount);
|
||||
} while (!status && !bStopTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TestErrorSetLastError(int argc, char* argv[])
|
||||
{
|
||||
DWORD error = 0;
|
||||
HANDLE threads[4];
|
||||
|
||||
WINPR_UNUSED(argc);
|
||||
WINPR_UNUSED(argv);
|
||||
|
||||
/* We must initialize WLog here. It will check for settings
|
||||
* in the environment and if the variables are not set, the last
|
||||
* error state is changed... */
|
||||
WLog_GetRoot();
|
||||
|
||||
SetLastError(ERROR_ACCESS_DENIED);
|
||||
|
||||
error = GetLastError();
|
||||
|
||||
if (error != ERROR_ACCESS_DENIED)
|
||||
{
|
||||
printf("GetLastError() failure: Expected: 0x%08X, Actual: 0x%08" PRIX32 "\n",
|
||||
ERROR_ACCESS_DENIED, error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pLoopCount = winpr_aligned_malloc(sizeof(LONG), sizeof(LONG));
|
||||
if (!pLoopCount)
|
||||
{
|
||||
printf("Unable to allocate memory\n");
|
||||
return -1;
|
||||
}
|
||||
*pLoopCount = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (!(threads[i] =
|
||||
CreateThread(nullptr, 0, test_error_thread, (void*)(size_t)0, 0, nullptr)))
|
||||
{
|
||||
printf("Failed to create thread #%d\n", i);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// let the threads run for at least 0.2 seconds
|
||||
Sleep(200);
|
||||
bStopTest = TRUE;
|
||||
|
||||
(void)WaitForSingleObject(threads[0], INFINITE);
|
||||
(void)WaitForSingleObject(threads[1], INFINITE);
|
||||
(void)WaitForSingleObject(threads[2], INFINITE);
|
||||
(void)WaitForSingleObject(threads[3], INFINITE);
|
||||
|
||||
(void)CloseHandle(threads[0]);
|
||||
(void)CloseHandle(threads[1]);
|
||||
(void)CloseHandle(threads[2]);
|
||||
(void)CloseHandle(threads[3]);
|
||||
|
||||
error = GetLastError();
|
||||
|
||||
if (error != ERROR_ACCESS_DENIED)
|
||||
{
|
||||
printf("GetLastError() failure: Expected: 0x%08X, Actual: 0x%08" PRIX32 "\n",
|
||||
ERROR_ACCESS_DENIED, error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*pLoopCount < 4)
|
||||
{
|
||||
printf("Error: unexpected loop count\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Completed %" PRId32 " iterations.\n", *pLoopCount);
|
||||
winpr_aligned_free(pLoopCount);
|
||||
|
||||
return status;
|
||||
}
|
||||
Reference in New Issue
Block a user