ZeroMemory(&pi, sizeof(pi));
+#if TARGET_UNIX
+ const unsigned cmdLen = (unsigned)strlen(commandLine) + 1;
+ WCHAR* cmdLineW = new WCHAR[cmdLen];
+ MultiByteToWideChar(CP_UTF8, 0, commandLine, cmdLen, cmdLineW, cmdLen);
+#endif
// Start the child process.
if (!CreateProcess(NULL, // No module name (use command line)
+#if TARGET_UNIX
+ cmdLineW, // Command line
+#else
commandLine, // Command line
+#endif
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
TRUE, // Set handle inheritance to TRUE (required to use STARTF_USESTDHANDLES)
{
LogError("CreateProcess failed (%d). CommandLine: %s", GetLastError(), commandLine);
*hProcess = INVALID_HANDLE_VALUE;
+#if TARGET_UNIX
+ delete[] cmdLineW;
+#endif
return false;
}
*hProcess = pi.hProcess;
+
+#if TARGET_UNIX
+ delete[] cmdLineW;
+#endif
return true;
}
#sscanf_s
#CopyFileW
-#CreateFileMappingA
#CreateFileMappingW
#CreateFileA
#CreateFileW
PAL_GetPALDirectoryW(
OUT LPWSTR lpDirectoryName,
IN OUT UINT* cchDirectoryName);
-#ifdef UNICODE
+
#define PAL_GetPALDirectory PAL_GetPALDirectoryW
-#else
-#define PAL_GetPALDirectory PAL_GetPALDirectoryA
-#endif
PALIMPORT
VOID
OUT LPWSTR lpBuffer,
OUT LPWSTR *lpFilePart
);
-#ifdef UNICODE
-#define SearchPath SearchPathW
-#else
-#define SearchPath SearchPathA
-#endif // !UNICODE
-
+#define SearchPath SearchPathW
PALIMPORT
BOOL
#define CopyFile CopyFileA
#endif
-
PALIMPORT
BOOL
PALAPI
#define DeleteFile DeleteFileA
#endif
-
-
#define MOVEFILE_REPLACE_EXISTING 0x00000001
#define MOVEFILE_COPY_ALLOWED 0x00000002
-
PALIMPORT
BOOL
PALAPI
HANDLE hStdError;
} STARTUPINFOW, *LPSTARTUPINFOW;
-typedef struct _STARTUPINFOA {
- DWORD cb;
- LPSTR lpReserved_PAL_Undefined;
- LPSTR lpDesktop_PAL_Undefined;
- LPSTR lpTitle_PAL_Undefined;
- DWORD dwX_PAL_Undefined;
- DWORD dwY_PAL_Undefined;
- DWORD dwXSize_PAL_Undefined;
- DWORD dwYSize_PAL_Undefined;
- DWORD dwXCountChars_PAL_Undefined;
- DWORD dwYCountChars_PAL_Undefined;
- DWORD dwFillAttribute_PAL_Undefined;
- DWORD dwFlags;
- WORD wShowWindow_PAL_Undefined;
- WORD cbReserved2_PAL_Undefined;
- LPBYTE lpReserved2_PAL_Undefined;
- HANDLE hStdInput;
- HANDLE hStdOutput;
- HANDLE hStdError;
-} STARTUPINFOA, *LPSTARTUPINFOA;
-
-#ifdef UNICODE
typedef STARTUPINFOW STARTUPINFO;
typedef LPSTARTUPINFOW LPSTARTUPINFO;
-#else
-typedef STARTUPINFOA STARTUPINFO;
-typedef LPSTARTUPINFOW LPSTARTUPINFO;
-#endif
#define CREATE_NEW_CONSOLE 0x00000010
IN LPSTARTUPINFOW lpStartupInfo,
OUT LPPROCESS_INFORMATION lpProcessInformation);
-#ifdef UNICODE
#define CreateProcess CreateProcessW
-#else
-#define CreateProcess CreateProcessA
-#endif
PALIMPORT
PAL_NORETURN
IN DWORD dwMaximumSizeLow,
IN LPCWSTR lpName);
-#ifdef UNICODE
#define CreateFileMapping CreateFileMappingW
-#else
-#define CreateFileMapping CreateFileMappingA
-#endif
#define SECTION_QUERY 0x0001
#define SECTION_MAP_WRITE 0x0002
IN BOOL bInheritHandle,
IN LPCWSTR lpName);
-#ifdef UNICODE
#define OpenFileMapping OpenFileMappingW
-#else
-#define OpenFileMapping OpenFileMappingA
-#endif
typedef INT_PTR (PALAPI_NOEXPORT *FARPROC)();
PALAPI
GetEnvironmentStringsW();
-#ifdef UNICODE
#define GetEnvironmentStrings GetEnvironmentStringsW
-#else
-#define GetEnvironmentStrings GetEnvironmentStringsA
-#endif
PALIMPORT
BOOL
FreeEnvironmentStringsW(
IN LPWSTR);
-#ifdef UNICODE
#define FreeEnvironmentStrings FreeEnvironmentStringsW
-#else
-#define FreeEnvironmentStrings FreeEnvironmentStringsA
-#endif
PALIMPORT
BOOL
IN LPCSTR lpName);
PALIMPORT
-BOOL
-PALAPI
-CreateProcessA(
- IN LPCSTR lpApplicationName,
- IN LPSTR lpCommandLine,
- IN LPSECURITY_ATTRIBUTES lpProcessAttributes,
- IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
- IN BOOL bInheritHandles,
- IN DWORD dwCreationFlags,
- IN LPVOID lpEnvironment,
- IN LPCSTR lpCurrentDirectory,
- IN LPSTARTUPINFOA lpStartupInfo,
- OUT LPPROCESS_INFORMATION lpProcessInformation);
-
-PALIMPORT
-HANDLE
-PALAPI
-CreateFileMappingA(
- IN HANDLE hFile,
- IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
- IN DWORD flProtect,
- IN DWORD dwMaximumSizeHigh,
- IN DWORD dwMaximumSizeLow,
- IN LPCSTR lpName);
-
-PALIMPORT
-HANDLE
-PALAPI
-OpenFileMappingA(
- IN DWORD dwDesiredAccess,
- IN BOOL bInheritHandle,
- IN LPCSTR lpName);
-
-PALIMPORT
HMODULE
PALAPI
LoadLibraryA(
OUT LPSTR lpFileName,
IN DWORD nSize);
-
-PALIMPORT
-LPSTR
-PALAPI
-GetEnvironmentStringsA();
-
PALIMPORT
BOOL
PALAPI
PALIMPORT
BOOL
PALAPI
-FreeEnvironmentStringsA(
- IN LPSTR);
-
-PALIMPORT
-BOOL
-PALAPI
-RemoveDirectoryA(
- IN LPCSTR lpPathName);
-
-PALIMPORT
-BOOL
-PALAPI
RemoveDirectoryW(
IN LPCWSTR lpPathName);
PALIMPORT
-BOOL
-PALAPI
-PAL_GetPALDirectoryA(
- OUT LPSTR lpDirectoryName,
- IN UINT* cchDirectoryName);
-
-PALIMPORT
LONG
PALAPI
CompareFileTime(
/*++
Function:
- RemoveDirectoryA
-
-See MSDN doc.
---*/
-BOOL
-PALAPI
-RemoveDirectoryA(
- IN LPCSTR lpPathName)
-{
- DWORD dwLastError = 0;
- BOOL bRet = FALSE;
- PathCharString mb_dirPathString;
-
- PERF_ENTRY(RemoveDirectoryA);
- ENTRY("RemoveDirectoryA(lpPathName=%p (%s))\n",
- lpPathName,
- lpPathName);
-
- if (lpPathName == NULL)
- {
- dwLastError = ERROR_PATH_NOT_FOUND;
- goto done;
- }
-
- if (!mb_dirPathString.Set(lpPathName, strlen(lpPathName)))
- {
- WARN("Set failed !\n");
- dwLastError = ERROR_NOT_ENOUGH_MEMORY;
- goto done;
- }
-
- bRet = RemoveDirectoryHelper (mb_dirPathString, &dwLastError);
-
-done:
- if( dwLastError )
- {
- SetLastError( dwLastError );
- }
-
- LOGEXIT("RemoveDirectoryA returns BOOL %d\n", bRet);
- PERF_EXIT(RemoveDirectoryA);
- return bRet;
-}
-
-/*++
-Function:
RemoveDirectoryW
See MSDN doc.
BOOL
PAL_GetPALDirectoryW(
PathWCharString& lpDirectoryName);
-BOOL
-PAL_GetPALDirectoryA(
- PathCharString& lpDirectoryName);
+
DWORD
GetCurrentDirectoryA(
PathCharString& lpBuffer);
/*++
Function:
- CreateFileMappingA
-
-Note:
- File mapping are used to do inter-process communication.
-
-See MSDN doc.
---*/
-HANDLE
-PALAPI
-CreateFileMappingA(
- IN HANDLE hFile,
- IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
- IN DWORD flProtect,
- IN DWORD dwMaximumSizeHigh,
- IN DWORD dwMaximumSizeLow,
- IN LPCSTR lpName)
-{
- HANDLE hFileMapping = NULL;
- CPalThread *pThread = NULL;
- PAL_ERROR palError = NO_ERROR;
-
- PERF_ENTRY(CreateFileMappingA);
- ENTRY("CreateFileMappingA(hFile=%p, lpAttributes=%p, flProtect=%#x, "
- "dwMaxSizeH=%d, dwMaxSizeL=%d, lpName=%p (%s))\n",
- hFile, lpFileMappingAttributes, flProtect,
- dwMaximumSizeHigh, dwMaximumSizeLow,
- lpName?lpName:"NULL",
- lpName?lpName:"NULL");
-
- pThread = InternalGetCurrentThread();
-
- if (lpName != nullptr)
- {
- ASSERT("lpName: Cross-process named objects are not supported in PAL");
- palError = ERROR_NOT_SUPPORTED;
- }
- else
- {
- palError = InternalCreateFileMapping(
- pThread,
- hFile,
- lpFileMappingAttributes,
- flProtect,
- dwMaximumSizeHigh,
- dwMaximumSizeLow,
- NULL,
- &hFileMapping
- );
- }
-
-
- //
- // We always need to set last error, even on success:
- // we need to protect ourselves from the situation
- // where last error is set to ERROR_ALREADY_EXISTS on
- // entry to the function
- //
-
- pThread->SetLastError(palError);
-
- LOGEXIT( "CreateFileMappingA returns HANDLE %p. \n", hFileMapping );
- PERF_EXIT(CreateFileMappingA);
- return hFileMapping;
-}
-
-/*++
-Function:
CreateFileMappingW
Note:
/*++
Function:
- OpenFileMappingA
-
-See MSDN doc.
---*/
-HANDLE
-PALAPI
-OpenFileMappingA(
- IN DWORD dwDesiredAccess,
- IN BOOL bInheritHandle,
- IN LPCSTR lpName)
-{
- HANDLE hFileMapping = NULL;
- CPalThread *pThread = NULL;
- PAL_ERROR palError = NO_ERROR;
-
- PERF_ENTRY(OpenFileMappingA);
- ENTRY("OpenFileMappingA(dwDesiredAccess=%u, bInheritHandle=%d, lpName=%p (%s)\n",
- dwDesiredAccess, bInheritHandle, lpName?lpName:"NULL", lpName?lpName:"NULL");
-
- pThread = InternalGetCurrentThread();
-
- if (lpName == nullptr)
- {
- ERROR("name is NULL\n");
- palError = ERROR_INVALID_PARAMETER;
- }
- else
- {
- ASSERT("lpName: Cross-process named objects are not supported in PAL");
- palError = ERROR_NOT_SUPPORTED;
- }
-
- if (NO_ERROR != palError)
- {
- pThread->SetLastError(palError);
- }
- LOGEXIT( "OpenFileMappingA returning %p\n", hFileMapping );
- PERF_EXIT(OpenFileMappingA);
- return hFileMapping;
-}
-
-
-/*++
-Function:
OpenFileMappingW
See MSDN doc.
// Ensure address and offset arguments mmap() are page-aligned.
_ASSERTE(OffsetWithinPage(offset - adjust) == 0);
_ASSERTE(OffsetWithinPage((off_t)pvBaseAddress) == 0);
-
+
#ifdef __APPLE__
if ((prot & PROT_EXEC) != 0 && IsRunningOnMojaveHardenedRuntime())
{
/*++
Function:
- GetEnvironmentStringsA
-
-See GetEnvironmentStringsW.
-
---*/
-LPSTR
-PALAPI
-GetEnvironmentStringsA(
- VOID)
-{
- char *environ = nullptr, *tempEnviron;
- int i, len, envNum;
-
- PERF_ENTRY(GetEnvironmentStringsA);
- ENTRY("GetEnvironmentStringsA()\n");
-
- CPalThread * pthrCurrent = InternalGetCurrentThread();
- InternalEnterCriticalSection(pthrCurrent, &gcsEnvironment);
-
- envNum = 0;
- len = 0;
-
- /* get total length of the bytes that we need to allocate */
- for (i = 0; palEnvironment[i] != 0; i++)
- {
- len = strlen(palEnvironment[i]) + 1;
- envNum += len;
- }
-
- environ = (char *)PAL_malloc(envNum + 1);
- if (environ == nullptr)
- {
- ERROR("malloc failed\n");
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- goto EXIT;
- }
-
- len = 0;
- tempEnviron = environ;
- for (i = 0; palEnvironment[i] != 0; i++)
- {
- len = strlen(palEnvironment[i]) + 1;
- memcpy(tempEnviron, palEnvironment[i], len);
- tempEnviron += len;
- envNum -= len;
- }
-
- *tempEnviron = 0; /* Put an extra null at the end */
-
- EXIT:
- InternalLeaveCriticalSection(pthrCurrent, &gcsEnvironment);
-
- LOGEXIT("GetEnvironmentStringsA returning %p\n", environ);
- PERF_EXIT(GetEnvironmentStringsA);
- return environ;
-}
-
-/*++
-Function:
FreeEnvironmentStringsW
The FreeEnvironmentStrings function frees a block of environment strings.
/*++
Function:
- FreeEnvironmentStringsA
-
-See FreeEnvironmentStringsW.
-
---*/
-BOOL
-PALAPI
-FreeEnvironmentStringsA(
- IN LPSTR lpValue)
-{
- PERF_ENTRY(FreeEnvironmentStringsA);
- ENTRY("FreeEnvironmentStringsA(lpValue=%p (%s))\n", lpValue ? lpValue : "NULL", lpValue ? lpValue : "NULL");
-
- if (lpValue != nullptr)
- {
- PAL_free(lpValue);
- }
-
- LOGEXIT("FreeEnvironmentStringA returning BOOL TRUE\n");
- PERF_EXIT(FreeEnvironmentStringsA);
- return TRUE;
-}
-
-/*++
-Function:
SetEnvironmentVariableA
The SetEnvironmentVariable function sets the value of an environment
{
if (*name == '\0')
return nullptr;
-
+
for (int i = 0; palEnvironment[i] != nullptr; ++i)
{
const char* pch = name;
char* p = palEnvironment[i];
- do
+ do
{
- if (*pch == '\0')
+ if (*pch == '\0')
{
if (*p == '=')
return p + 1;
-
+
if (*p == '\0') // no = sign -> empty value
return p;
-
+
break;
}
}
while (*pch++ == *p++);
}
-
+
return nullptr;
}
{
CPalThread * pthrCurrent = InternalGetCurrentThread();
InternalEnterCriticalSection(pthrCurrent, &gcsEnvironment);
-
+
char* retValue = FindEnvVarValue(name);
-
+
if ((retValue != nullptr) && copyValue)
{
retValue = strdup(retValue);
return bRet;
}
-BOOL
-PAL_GetPALDirectoryA(PathCharString& lpDirectoryName)
-{
- BOOL bRet;
- PathWCharString directory;
-
- PERF_ENTRY(PAL_GetPALDirectoryA);
-
- bRet = PAL_GetPALDirectoryW(directory);
-
- if (bRet)
- {
-
- int length = WideCharToMultiByte(CP_ACP, 0, directory.GetString(), -1, NULL, 0, NULL, 0);
- LPSTR DirectoryName = lpDirectoryName.OpenStringBuffer(length);
- if (NULL == DirectoryName)
- {
- SetLastError( ERROR_INSUFFICIENT_BUFFER );
- bRet = FALSE;
- }
-
- length = WideCharToMultiByte(CP_ACP, 0, directory.GetString(), -1, DirectoryName, length, NULL, 0);
-
- if (0 == length)
- {
- bRet = FALSE;
- length++;
- }
-
- lpDirectoryName.CloseBuffer(length - 1);
- }
-
- PERF_EXIT(PAL_GetPALDirectoryA);
- return bRet;
-}
-
/*++
Function :
}
-PALIMPORT
-BOOL
-PALAPI
-PAL_GetPALDirectoryA(
- OUT LPSTR lpDirectoryName,
- IN UINT* cchDirectoryName)
-{
- BOOL bRet;
- PathCharString directory;
-
- PERF_ENTRY(PAL_GetPALDirectoryA);
- ENTRY( "PAL_GetPALDirectoryA( %p, %d )\n", lpDirectoryName, *cchDirectoryName );
-
- bRet = PAL_GetPALDirectoryA(directory);
-
- if (bRet)
- {
- if (directory.GetCount() > *cchDirectoryName)
- {
- SetLastError( ERROR_INSUFFICIENT_BUFFER );
- bRet = FALSE;
- *cchDirectoryName = directory.GetCount();
- }
- else if (strcpy_s(lpDirectoryName, directory.GetCount(), directory.GetString()) == SAFECRT_SUCCESS)
- {
- }
- else
- {
- bRet = FALSE;
- }
- }
-
- LOGEXIT( "PAL_GetPALDirectoryA returns BOOL %d.\n", bRet);
- PERF_EXIT(PAL_GetPALDirectoryA);
- return bRet;
-}
-
VOID
PALAPI
PAL_Random(
/*++
Function:
- CreateProcessA
-
-Note:
- Only Standard handles need to be inherited.
- Security attributes parameters are not used.
-
-See MSDN doc.
---*/
-BOOL
-PALAPI
-CreateProcessA(
- IN LPCSTR lpApplicationName,
- IN LPSTR lpCommandLine,
- IN LPSECURITY_ATTRIBUTES lpProcessAttributes,
- IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
- IN BOOL bInheritHandles,
- IN DWORD dwCreationFlags,
- IN LPVOID lpEnvironment,
- IN LPCSTR lpCurrentDirectory,
- IN LPSTARTUPINFOA lpStartupInfo,
- OUT LPPROCESS_INFORMATION lpProcessInformation)
-{
- PAL_ERROR palError = NO_ERROR;
- CPalThread *pThread;
- STARTUPINFOW StartupInfoW;
- LPWSTR CommandLineW = NULL;
- LPWSTR ApplicationNameW = NULL;
- LPWSTR CurrentDirectoryW = NULL;
-
- int n;
-
- PERF_ENTRY(CreateProcessA);
- ENTRY("CreateProcessA(lpAppName=%p (%s), lpCmdLine=%p (%s), lpProcessAttr=%p, "
- "lpThreadAttr=%p, bInherit=%d, dwFlags=%#x, lpEnv=%p, "
- "lpCurrentDir=%p (%s), lpStartupInfo=%p, lpProcessInfo=%p)\n",
- lpApplicationName?lpApplicationName:"NULL",
- lpApplicationName?lpApplicationName:"NULL",
- lpCommandLine?lpCommandLine:"NULL",
- lpCommandLine?lpCommandLine:"NULL",
- lpProcessAttributes, lpThreadAttributes, bInheritHandles,
- dwCreationFlags, lpEnvironment,
- lpCurrentDirectory?lpCurrentDirectory:"NULL",
- lpCurrentDirectory?lpCurrentDirectory:"NULL",
- lpStartupInfo, lpProcessInformation);
-
- pThread = InternalGetCurrentThread();
-
- if(lpStartupInfo == NULL)
- {
- ASSERT("lpStartupInfo is NULL!\n");
- palError = ERROR_INVALID_PARAMETER;
- goto done;
- }
-
- /* convert parameters to Unicode */
-
- if(lpApplicationName)
- {
- n = MultiByteToWideChar(CP_ACP, 0, lpApplicationName, -1, NULL, 0);
- if(0 == n)
- {
- ASSERT("MultiByteToWideChar failed!\n");
- palError = ERROR_INTERNAL_ERROR;
- goto done;
- }
- ApplicationNameW = (LPWSTR)InternalMalloc(sizeof(WCHAR)*n);
- if(!ApplicationNameW)
- {
- ERROR("malloc() failed!\n");
- palError = ERROR_NOT_ENOUGH_MEMORY;
- goto done;
- }
- MultiByteToWideChar(CP_ACP, 0, lpApplicationName, -1, ApplicationNameW,
- n);
- }
-
- if(lpCommandLine)
- {
- n = MultiByteToWideChar(CP_ACP, 0, lpCommandLine, -1, NULL, 0);
- if(0 == n)
- {
- ASSERT("MultiByteToWideChar failed!\n");
- palError = ERROR_INTERNAL_ERROR;
- goto done;
- }
- CommandLineW = (LPWSTR)InternalMalloc(sizeof(WCHAR)*n);
- if(!CommandLineW)
- {
- ERROR("malloc() failed!\n");
- palError = ERROR_NOT_ENOUGH_MEMORY;
- goto done;
- }
- MultiByteToWideChar(CP_ACP, 0, lpCommandLine, -1, CommandLineW, n);
- }
-
- if(lpCurrentDirectory)
- {
- n = MultiByteToWideChar(CP_ACP, 0, lpCurrentDirectory, -1, NULL, 0);
- if(0 == n)
- {
- ASSERT("MultiByteToWideChar failed!\n");
- palError = ERROR_INTERNAL_ERROR;
- goto done;
- }
- CurrentDirectoryW = (LPWSTR)InternalMalloc(sizeof(WCHAR)*n);
- if(!CurrentDirectoryW)
- {
- ERROR("malloc() failed!\n");
- palError = ERROR_NOT_ENOUGH_MEMORY;
- goto done;
- }
- MultiByteToWideChar(CP_ACP, 0, lpCurrentDirectory, -1,
- CurrentDirectoryW, n);
- }
-
- // lpEnvironment should remain ansi on the call to CreateProcessW
-
- StartupInfoW.cb = sizeof StartupInfoW;
- StartupInfoW.dwFlags = lpStartupInfo->dwFlags;
- StartupInfoW.hStdError = lpStartupInfo->hStdError;
- StartupInfoW.hStdInput = lpStartupInfo->hStdInput;
- StartupInfoW.hStdOutput = lpStartupInfo->hStdOutput;
- /* all other members are PAL_Undefined, we can ignore them */
-
- palError = InternalCreateProcess(
- pThread,
- ApplicationNameW,
- CommandLineW,
- lpProcessAttributes,
- lpThreadAttributes,
- dwCreationFlags,
- lpEnvironment,
- CurrentDirectoryW,
- &StartupInfoW,
- lpProcessInformation
- );
-done:
- free(ApplicationNameW);
- free(CommandLineW);
- free(CurrentDirectoryW);
-
- if (NO_ERROR != palError)
- {
- pThread->SetLastError(palError);
- }
-
- LOGEXIT("CreateProcessA returns BOOL %d\n", NO_ERROR == palError);
- PERF_EXIT(CreateProcessA);
- return NO_ERROR == palError;
-}
-
-
-/*++
-Function:
CreateProcessW
Note:
**
** Source: test1.c
**
-** Purpose: Debugs the helper application. Checks that certain events, in
+** Purpose: Debugs the helper application. Checks that certain events, in
** particular the OUTPUT_DEBUG_STRING_EVENT, is generated correctly
** and gives the correct values.
**
const int DELAY_MS = 2000;
-struct OutputCheck
+struct OutputCheck
{
DWORD ExpectedEventCode;
DWORD ExpectedUnicode;
int __cdecl main(int argc, char *argv[])
{
-
+
PROCESS_INFORMATION pi;
STARTUPINFO si;
-
+
if(0 != (PAL_Initialize(argc, argv)))
{
return FAIL;
}
-
+
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
-
+
+ WCHAR name[] = {'h','e','l', 'p', 'e', 'r', '\0'};
/* Create a new process. This is the process to be Debugged */
- if(!CreateProcess( NULL, "helper", NULL, NULL,
- FALSE, 0, NULL, NULL, &si, &pi))
+ if(!CreateProcessW( NULL, name, NULL, NULL,
+ FALSE, 0, NULL, NULL, &si, &pi))
{
+ DWORD dwError = GetLastError();
+ free(name);
Fail("ERROR: CreateProcess failed to load executable 'helper'. "
- "GetLastError() returned %d.\n",GetLastError());
+ "GetLastError() returned %d.\n", dwError);
}
+ free(name);
+
/* This is the main loop. It exits when the process which is being
debugged is finished executing.
*/
-
+
while(1)
- {
+ {
DWORD dwRet = 0;
dwRet = WaitForSingleObject(pi.hProcess,
DELAY_MS /* Wait for 2 seconds max*/
);
-
+
if (dwRet != WAIT_OBJECT_0)
{
Trace("WaitForSingleObjectTest:WaitForSingleObject "
dwError = GetLastError();
CloseHandle ( pi.hProcess );
CloseHandle ( pi.hThread );
- Fail( "GetExitCodeProcess call failed with error code %d\n",
- dwError );
+ Fail( "GetExitCodeProcess call failed with error code %d\n",
+ dwError );
}
if(dwExitCode != STILL_ACTIVE) {
break;
}
Trace("still executing %d..\n", dwExitCode);
- }
+ }
}
-
+
PAL_Terminate();
return PASS;
}
if(!SetFileAttributesA (szFindName, FILE_ATTRIBUTE_NORMAL))
{
result = FALSE;
- Trace("ERROR:%d: Error setting attributes [%s][%d]\n", szFindName, FILE_ATTRIBUTE_NORMAL);
- }
+ Trace("ERROR:%d: Error setting attributes [%s][%d]\n", szFindName, FILE_ATTRIBUTE_NORMAL);
+ }
if(!DeleteFileA (szFindName))
{
result = FALSE;
- Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szFindName, dwAtt);
+ Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szFindName, dwAtt);
}
}
dwAtt = GetFileAttributesA(szDirName);
if( dwAtt != INVALID_FILE_ATTRIBUTES )
{
- if(!RemoveDirectoryA (szDirName))
+ LPWSTR szDirNameW = convert(szDirName);
+ if(!RemoveDirectoryW (szDirNameW))
{
result = FALSE;
- Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szDirName, dwAtt);
+ Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szDirName, dwAtt);
}
+ free(szDirNameW);
}
return result;
if (bRc == FALSE)
{
Fail("FindFirstFileA: ERROR -> Failed to create the directory "
- "\"%s\"\n",
+ "\"%s\"\n",
szDirName);
}
hFind = FindFirstFileA(szDirName, &findFileData);
- if (hFind == INVALID_HANDLE_VALUE)
+ if (hFind == INVALID_HANDLE_VALUE)
{
Fail ("FindFirstFileA: ERROR. Unable to find \"%s\"\n", szDirName);
}
// find a directory using a trailing '\' on the directory name: should fail
//
hFind = FindFirstFileA(szDirNameSlash, &findFileData);
- if (hFind != INVALID_HANDLE_VALUE)
+ if (hFind != INVALID_HANDLE_VALUE)
{
Fail ("FindFirstFileA: ERROR -> Able to find \"%s\": trailing "
- "slash should have failed.\n",
+ "slash should have failed.\n",
szDirNameSlash);
}
// find a file using wild cards
hFind = FindFirstFileA(szFindNameWldCard_01, &findFileData);
- if (hFind == INVALID_HANDLE_VALUE)
+ if (hFind == INVALID_HANDLE_VALUE)
{
- Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n",
+ Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n",
szFindNameWldCard_01);
}
hFind = FindFirstFileA(szFindNameWldCard_02, &findFileData);
- if (hFind == INVALID_HANDLE_VALUE)
+ if (hFind == INVALID_HANDLE_VALUE)
{
Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", szFindNameWldCard_02);
}
// find a directory using wild cards
//
hFind = FindFirstFileA(szDirNameWldCard_01, &findFileData);
- if (hFind == INVALID_HANDLE_VALUE)
+ if (hFind == INVALID_HANDLE_VALUE)
{
Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", szDirNameWldCard_01);
}
hFind = FindFirstFileA(szDirNameWldCard_02, &findFileData);
- if (hFind == INVALID_HANDLE_VALUE)
+ if (hFind == INVALID_HANDLE_VALUE)
{
Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", szDirNameWldCard_02);
}
Fail("FindFirstFileW: ERROR : Final Clean Up failed\n");
}
- PAL_Terminate();
+ PAL_Terminate();
return PASS;
}
if(!SetFileAttributesA (szFindName, FILE_ATTRIBUTE_NORMAL))
{
result = FALSE;
- Trace("ERROR:%d: Error setting attributes [%s][%d]\n", szFindName, FILE_ATTRIBUTE_NORMAL);
- }
+ Trace("ERROR:%d: Error setting attributes [%s][%d]\n", szFindName, FILE_ATTRIBUTE_NORMAL);
+ }
if(!DeleteFileA (szFindName))
{
result = FALSE;
- Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szFindName, dwAtt);
+ Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szFindName, dwAtt);
}
}
dwAtt = GetFileAttributesA(szDirName);
if( dwAtt != INVALID_FILE_ATTRIBUTES )
{
- if(!RemoveDirectoryA (szDirName))
+ LPWSTR szDirNameW = convert(szDirName);
+ if(!RemoveDirectoryW (szDirNameW))
{
result = FALSE;
- Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szDirName, dwAtt);
+ Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szDirName, dwAtt);
}
+ free(szDirNameW);
}
return result;
if (hFind != INVALID_HANDLE_VALUE)
{
Fail("FindFirstFileW: ERROR -> Able to find \"%s\": trailing "
- "slash should have failed.\n",
+ "slash should have failed.\n",
szDirNameSlash);
}
free(pTemp);
if (hFind == INVALID_HANDLE_VALUE)
{
- Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n",
+ Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n",
szFindNameWldCard_01);
}
free(pTemp);
if (hFind == INVALID_HANDLE_VALUE)
{
- Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n",
+ Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n",
szFindNameWldCard_02);
}
free(pTemp);
if (hFind == INVALID_HANDLE_VALUE)
{
- Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n",
+ Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n",
szDirNameWldCard_01);
}
free(pTemp);
if (hFind == INVALID_HANDLE_VALUE)
{
- Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n",
+ Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n",
szDirNameWldCard_02);
}
Fail("FindFirstFileW: ERROR : Final Clean Up failed\n");
}
- PAL_Terminate();
+ PAL_Terminate();
return PASS;
}
** - a normal directory and file
** - a read only directory and file
** - a read write directory and file
-** - a hidden directory and file
+** - a hidden directory and file
** - a read only hidden directory and file
** - a directory and a file with no attributes
** - an invalid file name
const int TYPE_DIR = 0;
const int TYPE_FILE = 1;
/* Structure defining a test case */
-typedef struct
+typedef struct
{
char *name; /* name of the file/directory */
DWORD expectedAttribs; /* expected attributes */
int isFile; /* is file (1) or dir (0) */
}TestCaseFile;
-typedef struct
+typedef struct
{
char *name; /* name of the file/directory */
DWORD expectedAttribs; /* expected attributes */
for (i = 0; i < numFileTests -1 ; i++ )
{
dwAtt = GetFileAttributesA(gfaTestsFile[i].name);
-
+
if( dwAtt != INVALID_FILE_ATTRIBUTES )
{
//Trace("Files iteration %d\n", i);
if(!SetFileAttributesA (gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL))
{
result = FALSE;
- Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL);
- }
+ Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL);
+ }
if(!DeleteFileA (gfaTestsFile[i].name))
{
result = FALSE;
- Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, dwAtt);
+ Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, dwAtt);
}
-
+
}
}
// Trace("Value of result is %d\n", result);
if(!SetFileAttributesA (gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs))
{
result = FALSE;
- Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs);
- }
+ Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs);
+ }
}
return result;
for (i = 0; i < numDirTests -1 ; i++ )
{
dwAtt = GetFileAttributesA(gfaTestsDir[i].name);
-
+
if( dwAtt != INVALID_FILE_ATTRIBUTES )
{
-
+
if(!SetFileAttributesA (gfaTestsDir[i].name, FILE_ATTRIBUTE_DIRECTORY))
{
result = FALSE;
- Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY));
- }
+ Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY));
+ }
- if(!RemoveDirectoryA (gfaTestsDir[i].name))
+ LPWSTR nameW = convert(gfaTestsDir[i].name);
+ if(!RemoveDirectoryW (nameW))
{
result = FALSE;
- Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, dwAtt);
+ Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, dwAtt);
}
-
+
+ free(nameW);
}
}
if(!SetFileAttributesA (gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs))
{
result = FALSE;
- Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs);
- }
+ Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs);
+ }
ret = GetFileAttributesA (gfaTestsDir[i].name);
if(ret != gfaTestsDir[i].expectedAttribs)
{
result = FALSE;
- Trace("ERROR: Error setting attributes [%s][%d]\n", gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs);
- }
+ Trace("ERROR: Error setting attributes [%s][%d]\n", gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs);
+ }
//Trace("Setup Dir setting attr [%d], returned [%d]\n", gfaTestsDir[i].expectedAttribs, ret);
}
char * NoDirectoryName = "no_directory";
char * NormalFileName = "normal_test_file";
- char * ReadOnlyFileName = "ro_test_file";
+ char * ReadOnlyFileName = "ro_test_file";
char * ReadWriteFileName = "rw_file";
char * HiddenFileName = ".hidden_file";
char * HiddenReadOnlyFileName = ".hidden_ro_file";
gfaTestsDir[0].name = NormalDirectoryName;
gfaTestsDir[0].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY;
gfaTestsDir[0].isFile = TYPE_DIR;
-
+
gfaTestsDir[1].name = ReadOnlyDirectoryName;
- gfaTestsDir[1].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY |
+ gfaTestsDir[1].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY |
FILE_ATTRIBUTE_READONLY;
gfaTestsDir[1].isFile = TYPE_DIR;
gfaTestsDir[2].isFile = TYPE_DIR;
gfaTestsDir[3].name = HiddenDirectoryName;
- gfaTestsDir[3].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; //|
+ gfaTestsDir[3].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; //|
//FILE_ATTRIBUTE_HIDDEN;
gfaTestsDir[3].isFile = TYPE_DIR;
-
+
gfaTestsDir[4].name = HiddenReadOnlyDirectoryName;
- gfaTestsDir[4].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY |
+ gfaTestsDir[4].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY |
FILE_ATTRIBUTE_READONLY; //|
//FILE_ATTRIBUTE_HIDDEN;
gfaTestsDir[4].isFile = TYPE_DIR;
gfaTestsFile[5].name = NotReallyAFileName;
gfaTestsFile[5].expectedAttribs = INVALID_FILE_ATTRIBUTES;
- gfaTestsFile[5].isFile = TYPE_FILE;
+ gfaTestsFile[5].isFile = TYPE_FILE;
/* Initialize PAL environment */
if (0 != PAL_Initialize(argc,argv))
Fail("GetFileAttributesA: SetUp Directories Failed\n");
}
- /*
+ /*
* Go through all the test cases above,
* call GetFileAttributesA on the name and
* make sure the return value is the one expected
** - a normal directory and file
** - a read only directory and file
** - a read write directory and file
-** - a hidden directory and file
+** - a hidden directory and file
** - a read only hidden directory and file
** - a directory and a file with no attributes
** - an invalid file name
const int TYPE_DIR = 0;
const int TYPE_FILE = 1;
/* Structure defining a test case */
-typedef struct
+typedef struct
{
char *name; /* name of the file/directory */
DWORD expectedAttribs; /* expected attributes */
int isFile; /* is file (1) or dir (0) */
}TestCaseFile;
-typedef struct
+typedef struct
{
char *name; /* name of the file/directory */
DWORD expectedAttribs; /* expected attributes */
for (i = 0; i < numFileTests - 1 ; i++ )
{
dwAtt = GetFileAttributesA(gfaTestsFile[i].name);
-
+
if( dwAtt != INVALID_FILE_ATTRIBUTES )
{
//Trace("Files iteration %d\n", i);
if(!SetFileAttributesA (gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL))
{
result = FALSE;
- Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL);
- }
+ Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL);
+ }
if(!DeleteFileA (gfaTestsFile[i].name))
{
result = FALSE;
- Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, dwAtt);
+ Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, dwAtt);
}
-
+
}
}
// Trace("Value of result is %d\n", result);
if(!SetFileAttributesA (gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs))
{
result = FALSE;
- Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs);
- }
+ Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs);
+ }
}
return result;
for (i = 0; i < numDirTests - 1; i++ )
{
dwAtt = GetFileAttributesA(gfaTestsDir[i].name);
-
+
if( dwAtt != INVALID_FILE_ATTRIBUTES )
{
-
+
if(!SetFileAttributesA (gfaTestsDir[i].name, FILE_ATTRIBUTE_DIRECTORY))
{
result = FALSE;
- Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY));
- }
+ Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY));
+ }
- if(!RemoveDirectoryA (gfaTestsDir[i].name))
+ LPWSTR nameW = convert(gfaTestsDir[i].name);
+ if(!RemoveDirectoryW (nameW))
{
result = FALSE;
- Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, dwAtt);
+ Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, dwAtt);
}
-
+
+ free(nameW);
}
}
if(!SetFileAttributesA (gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs))
{
result = FALSE;
- Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs);
- }
+ Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs);
+ }
ret = GetFileAttributesA (gfaTestsDir[i].name);
if(ret != gfaTestsDir[i].expectedAttribs)
{
result = FALSE;
- Trace("ERROR: Error setting attributes [%s][%d]\n", gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs);
- }
+ Trace("ERROR: Error setting attributes [%s][%d]\n", gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs);
+ }
// Trace("Setup Dir setting attr [%d], returned [%d]\n", gfaTestsDir[i].expectedAttribs, ret);
}
char * NoDirectoryName = "no_directory";
char * NormalFileName = "normal_test_file";
- char * ReadOnlyFileName = "ro_test_file";
+ char * ReadOnlyFileName = "ro_test_file";
char * ReadWriteFileName = "rw_file";
char * HiddenFileName = ".hidden_file";
char * HiddenReadOnlyFileName = ".hidden_ro_file";
gfaTestsDir[0].name = NormalDirectoryName;
gfaTestsDir[0].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY;
gfaTestsDir[0].isFile = TYPE_DIR;
-
+
gfaTestsDir[1].name = ReadOnlyDirectoryName;
- gfaTestsDir[1].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY |
+ gfaTestsDir[1].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY |
FILE_ATTRIBUTE_READONLY;
gfaTestsDir[1].isFile = TYPE_DIR;
gfaTestsDir[2].isFile = TYPE_DIR;
gfaTestsDir[3].name = HiddenDirectoryName;
- gfaTestsDir[3].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; //|
+ gfaTestsDir[3].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; //|
//FILE_ATTRIBUTE_HIDDEN;
gfaTestsDir[3].isFile = TYPE_DIR;
-
+
gfaTestsDir[4].name = HiddenReadOnlyDirectoryName;
- gfaTestsDir[4].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY |
+ gfaTestsDir[4].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY |
FILE_ATTRIBUTE_READONLY; //|
//FILE_ATTRIBUTE_HIDDEN;
gfaTestsDir[4].isFile = TYPE_DIR;
gfaTestsFile[5].name = NotReallyAFileName;
gfaTestsFile[5].expectedAttribs = INVALID_FILE_ATTRIBUTES;
- gfaTestsFile[5].isFile = TYPE_FILE;
+ gfaTestsFile[5].isFile = TYPE_FILE;
/* Initialize PAL environment */
if (0 != PAL_Initialize(argc,argv))
Fail("GetFileAttributesW: SetUp Directories Failed\n");
}
- /*
+ /*
* Go through all the test cases above,
* call GetFileAttributesW on the name and
* make sure the return value is the one expected
#include <palsuite.h>
-LPSTR lpSource[4] = {
+LPSTR lpSource[4] = {
"src_existing.tmp",
"src_non-existant.tmp",
"src_dir_existing",
"dst_dir_non-existant\\test01.tmp",
"dst_dir_non-existant\\test02.tmp"
};
-
+
DWORD dwFlag[2] = {MOVEFILE_COPY_ALLOWED, MOVEFILE_REPLACE_EXISTING};
HANDLE tempFile2 = NULL;
/* create the src_existing file and dst_existing file */
- tempFile = CreateFileA(lpSource[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
+ tempFile = CreateFileA(lpSource[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, 0);
tempFile2 = CreateFileA(lpDestination[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, 0);
if ((tempFile == NULL) || (tempFile2 == NULL))
{
- Trace("ERROR[%ul]: couldn't create %S or %S\n", GetLastError(), lpSource[0],
+ Trace("ERROR[%ul]: couldn't create %S or %S\n", GetLastError(), lpSource[0],
lpDestination[0]);
- return FAIL;
+ return FAIL;
}
/* create the src_dir_existing and dst_dir_existing directory and files */
}
void removeDirectoryHelper(LPSTR dir, int location)
-{
+{
DWORD dwAtt = GetFileAttributesA(dir);
if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) )
{
- if(!RemoveDirectoryA(dir))
+ LPWSTR dirW = convert(dir);
+ if(!RemoveDirectoryW(dirW))
{
- Fail("ERROR: Failed to remove Directory [%s], Error Code [%d], location [%d]\n", dir, GetLastError(), location);
+ DWORD dwError = GetLastError();
+ free(dirW);
+ Fail("ERROR: Failed to remove Directory [%s], Error Code [%d], location [%d]\n", dir, dwError, location);
}
+
+ free(dirW);
}
}
void removeFileHelper(LPSTR pfile, int location)
-{
+{
FILE *fp;
fp = fopen( pfile, "r");
{
if(fclose(fp))
{
- Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location);
+ Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location);
}
if(!DeleteFileA(pfile))
{
- Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location);
+ Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location);
}
}
{
DWORD dwAtt;
/* get rid of destination dirs and files */
- removeFileHelper(lpSource[0], 11);
+ removeFileHelper(lpSource[0], 11);
removeFileHelper(lpSource[1], 12);
removeFileHelper(lpFiles[0], 13);
removeFileHelper(lpFiles[1], 14);
{
removeFileHelper(lpDestination[1], 19);
}
-
+
dwAtt = GetFileAttributesA(lpDestination[2]);
if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) )
{
}
else
{
- removeFileHelper(lpDestination[2], 23);
+ removeFileHelper(lpDestination[2], 23);
}
dwAtt = GetFileAttributesA(lpDestination[3]);
if (createExisting() != PASS)
{
goto EXIT;
- }
+ }
/* lpSource loop */
for (i = 0; i < 4; i++)
bRc = MoveFileExA(lpSource[i], lpDestination[j], dwFlag[k]);
if (!(
- ((bRc == TRUE) && (results[nCounter] == '1'))
- ||
+ ((bRc == TRUE) && (results[nCounter] == '1'))
+ ||
((bRc == FALSE ) && (results[nCounter] == '0')) )
)
{
- Trace("MoveFileExA(%s, %s, %s): Values of i[%d], j[%d], k [%d] and results[%d]=%c LastError[%d]Flag[%d]FAILED\n",
- lpSource[i], lpDestination[j],
- k == 1 ?
+ Trace("MoveFileExA(%s, %s, %s): Values of i[%d], j[%d], k [%d] and results[%d]=%c LastError[%d]Flag[%d]FAILED\n",
+ lpSource[i], lpDestination[j],
+ k == 1 ?
"MOVEFILE_REPLACE_EXISTING":"MOVEFILE_COPY_ALLOWED", i, j, k, nCounter, results[nCounter], GetLastError(), bRc);
goto EXIT;
}
}
/* create the temp source file */
- hFile = CreateFileA(tempSource, GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
+ hFile = CreateFileA(tempSource, GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, 0);
if( hFile == INVALID_HANDLE_VALUE )
"create the file correctly.\n");
goto EXIT;
}
-
+
bRc = CloseHandle(hFile);
if(!bRc)
{
Trace("MoveFileExA: GetFileAttributes failed to get "
"the file's attributes.\n");
goto EXIT;
- }
+ }
if((result & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY)
{
//);
//
//Parameters
-//lpPath
-//[in] Pointer to a null-terminated string that specifies the path to be searched for the file. If this parameter is NULL, the function searches for a matching file in the following directories in the following sequence:
-//The directory from which the application loaded.
-//The current directory.
-//The system directory. Use the GetSystemDirectory function to get the path of this directory.
-//The 16-bit system directory. There is no function that retrieves the path of this directory, but it is searched.
-//The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
-//The directories that are listed in the PATH environment variable.
-
-//lpFileName
-//[in] Pointer to a null-terminated string that specifies the name of the file to search for.
-
-//lpExtension
-//[in] Pointer to a null-terminated string that specifies an extension to be added to the file name when searching for the file. The first character of the file name extension must be a period (.). The extension is added only if the specified file name does not end with an extension.
+//lpPath
+//[in] Pointer to a null-terminated string that specifies the path to be searched for the file. If this parameter is NULL, the function searches for a matching file in the following directories in the following sequence:
+//The directory from which the application loaded.
+//The current directory.
+//The system directory. Use the GetSystemDirectory function to get the path of this directory.
+//The 16-bit system directory. There is no function that retrieves the path of this directory, but it is searched.
+//The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
+//The directories that are listed in the PATH environment variable.
+
+//lpFileName
+//[in] Pointer to a null-terminated string that specifies the name of the file to search for.
+
+//lpExtension
+//[in] Pointer to a null-terminated string that specifies an extension to be added to the file name when searching for the file. The first character of the file name extension must be a period (.). The extension is added only if the specified file name does not end with an extension.
//If a file name extension is not required or if the file name contains an extension, this parameter can be NULL.
//
-//nBufferLength
-//[in] Size of the buffer that receives the valid path and file name, in TCHARs.
+//nBufferLength
+//[in] Size of the buffer that receives the valid path and file name, in TCHARs.
-//lpBuffer
-//[out] Pointer to the buffer that receives the path and file name of the file found.
+//lpBuffer
+//[out] Pointer to the buffer that receives the path and file name of the file found.
-//lpFilePart
-//[out] Pointer to the variable that receives the address (within lpBuffer) of the last component of the valid path and file name, which is the address of the character immediately following the final backslash (\) in the path.
+//lpFilePart
+//[out] Pointer to the variable that receives the address (within lpBuffer) of the last component of the valid path and file name, which is the address of the character immediately following the final backslash (\) in the path.
//Return Values
//If the function succeeds, the value returned is the length, in TCHARs, of the string copied to the buffer, not including the terminating null character. If the return value is greater than nBufferLength, the value returned is the size of the buffer required to hold the path.
char fileloc[_MAX_PATH];
void removeFileHelper(LPSTR pfile, int location)
-{
+{
FILE *fp;
fp = fopen( pfile, "r");
{
if(fclose(fp))
{
- Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location);
+ Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location);
}
if(!DeleteFileA(pfile))
{
- Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location);
+ Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location);
}
else
{
- // Trace("Success: deleted file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location);
+ // Trace("Success: deleted file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location);
}
}
RemoveAll();
- hsearchfile = CreateFileA(fileloc, GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
+ hsearchfile = CreateFileA(fileloc, GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, 0);
if (hsearchfile == NULL)
{
Trace("ERROR[%ul]: couldn't create %s\n", GetLastError(), fileloc);
- return FAIL;
+ return FAIL;
}
CloseHandle(hsearchfile);
error = GetLastError();
free(lpPath);
free(lpFileName);
- Fail ("SearchPathA: ERROR2 -> Did not Find valid file[%s][%s][%d]\n", lpPath, szFileNameExistsWithExt, error);
+ Fail ("SearchPathW: ERROR2 -> Did not Find valid file[%s][%s][%d]\n", lpPath, szFileNameExistsWithExt, error);
}
free(lpPath);
RemoveAll();
PAL_Terminate();
- return PASS;
+ return PASS;
}
-add_subdirectory(CreateFileMappingA)
add_subdirectory(CreateFileMappingW)
add_subdirectory(FreeLibrary)
add_subdirectory(FreeLibraryAndExitThread)
add_subdirectory(LocalAlloc)
add_subdirectory(LocalFree)
add_subdirectory(MapViewOfFile)
-add_subdirectory(OpenFileMappingA)
add_subdirectory(OpenFileMappingW)
add_subdirectory(ProbeMemory)
add_subdirectory(UnmapViewOfFile)
+++ /dev/null
-add_subdirectory(test1)
-add_subdirectory(test3)
-add_subdirectory(test4)
-add_subdirectory(test5)
-add_subdirectory(test6)
-add_subdirectory(test7)
-add_subdirectory(test8)
-add_subdirectory(test9)
-
+++ /dev/null
-set(SOURCES
- CreateFileMapping.cpp
-)
-
-add_executable(paltest_createfilemappinga_test1
- ${SOURCES}
-)
-
-add_dependencies(paltest_createfilemappinga_test1 coreclrpal)
-
-target_link_libraries(paltest_createfilemappinga_test1
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=============================================================
-**
-** Source: createfilemapping.c (test 1)
-**
-** Purpose: Positive test the CreateFileMapping API.
-** Call CreateFileMapping with access PAGE_READONLY.
-**
-**
-**============================================================*/
-#include <palsuite.h>
-
-const int MAPPINGSIZE = 2048;
-
-int __cdecl main(int argc, char *argv[])
-{
-
- HANDLE hFile;
- char buf[] = "this is a test string";
- char ch[2048];
- char lpFileName[] = "test.tmp";
- DWORD dwBytesWritten;
- BOOL err;
- int RetVal = PASS;
-
- HANDLE hFileMapping;
- LPVOID lpMapViewAddress;
-
- /* Initialize the PAL environment.
- */
- if(0 != PAL_Initialize(argc, argv))
- {
- return FAIL;
- }
-
- /* Create a file handle with CreateFile.
- */
- hFile = CreateFile( lpFileName,
- GENERIC_WRITE|GENERIC_READ,
- FILE_SHARE_READ|FILE_SHARE_WRITE,
- NULL,
- CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
-
- if (hFile == INVALID_HANDLE_VALUE)
- {
- Fail("ERROR: %u :unable to create file \"%s\".\n",
- GetLastError(),
- lpFileName);
- }
-
- /* Initialize the buffers.
- */
- memset(ch, 0, MAPPINGSIZE);
-
- /* Write to the File handle.
- */
- err = WriteFile(hFile,
- buf,
- strlen(buf),
- &dwBytesWritten,
- NULL);
-
- if (err == FALSE)
- {
- Trace("ERROR: %u :unable to write to file handle "
- "hFile=0x%lx\n",
- GetLastError(),
- hFile);
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
- /* Flush to the hard-drive.
- */
- FlushFileBuffers(hFile);
-
- /* Create a unnamed file-mapping object with file handle FileHandle
- * and with PAGE_READWRITE protection.
- */
- hFileMapping = CreateFileMapping(
- hFile,
- NULL, /*not inherited*/
- PAGE_READONLY, /*read and wite*/
- 0, /*high-order size*/
- 0, /*low-order size*/
- NULL); /*unnamed object*/
-
- if(NULL == hFileMapping)
- {
- Trace("ERROR:%u: Failed to create File Mapping.\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
- /* maps a view of a file into the address space of the calling process.
- */
- lpMapViewAddress = MapViewOfFile(
- hFileMapping,
- FILE_MAP_READ, /* access code */
- 0, /*high order offset*/
- 0, /*low order offset*/
- 0); /* number of bytes for map */
-
- if(NULL == lpMapViewAddress)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpTwo;
- }
-
- /* Copy the MapViewOfFile to buffer, so we can
- * compare with value read from file directly.
- */
- memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
- if (memcmp(ch, buf, strlen(buf))!= 0)
- {
- Trace("ERROR: MapViewOfFile not equal to file contents "
- "retrieved \"%s\", expected \"%s\".\n",
- ch, buf);
- RetVal = FAIL;
- goto CleanUpThree;
- }
-
-CleanUpThree:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewAddress);
- RetVal = FAIL;
- }
-
-CleanUpTwo:
-
- /* Close Handle to opend file mapping.
- */
- if ( CloseHandle(hFileMapping) == FALSE )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- hFileMapping);
- RetVal = FAIL;
- }
-
-CleanUpOne:
-
- /* Close Handle to create file mapping.
- */
- if ( CloseHandle(hFile) == FALSE )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- hFile);
- RetVal = FAIL;
- }
-
- /* Terminate the PAL.
- */
- PAL_TerminateEx(RetVal);
- return RetVal;
-}
-
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = Filemapping_memmgt
-Function = CreateFileMapping
-Name = CreateFileMappingA with PAGE_READONLY
-TYPE = DEFAULT
-EXE1 = createfilemapping
-Description
-=Test the CreateFileMapping to create a named file-mapping object
-=and with PAGE_READONLY protection
+++ /dev/null
-set(SOURCES
- CreateFileMapping.cpp
-)
-
-add_executable(paltest_createfilemappinga_test3
- ${SOURCES}
-)
-
-add_dependencies(paltest_createfilemappinga_test3 coreclrpal)
-
-target_link_libraries(paltest_createfilemappinga_test3
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=============================================================
-**
-** Source: createfilemapping.c (test 3)
-**
-** Purpose: Positive test the CreateFileMapping API.
-** Call CreateFileMapping with access PAGE_READWRITE.
-**
-**
-**============================================================*/
-#include <palsuite.h>
-
-const int MAPPINGSIZE = 2048;
-
-int __cdecl main(int argc, char *argv[])
-{
-
- HANDLE hFile;
- char buf[] = "this is a test string";
- char ch[2048];
- char lpFileName[] = "test.tmp";
- HANDLE hFileMapping;
- LPVOID lpMapViewAddress;
- int RetVal = PASS;
-
- /* Initialize the PAL environment.
- */
- if(0 != PAL_Initialize(argc, argv))
- {
- return FAIL;
- }
-
- /* Create a file handle with CreateFile.
- */
- hFile = CreateFile( lpFileName,
- GENERIC_WRITE|GENERIC_READ,
- FILE_SHARE_READ|FILE_SHARE_WRITE,
- NULL,
- CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
-
- if (hFile == INVALID_HANDLE_VALUE)
- {
- Fail("ERROR: %u :unable to create file \"%s\".\n",
- GetLastError(),
- lpFileName);
- }
-
- /* Initialize the buffers.
- */
- memset(ch, 0, MAPPINGSIZE);
-
- /* Create a unnamed file-mapping object with file handle FileHandle
- * and with PAGE_READWRITE protection.
- */
- hFileMapping = CreateFileMapping(
- hFile,
- NULL, /*not inherited*/
- PAGE_READWRITE, /*read and wite*/
- 0, /*high-order size*/
- MAPPINGSIZE, /*low-order size*/
- NULL); /*unnamed object*/
-
- if(NULL == hFileMapping)
- {
- Trace("ERROR:%u: Failed to create File Mapping.\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
- /* maps a view of a file into the address space of the calling process.
- */
- lpMapViewAddress = MapViewOfFile(
- hFileMapping,
- FILE_MAP_ALL_ACCESS, /* access code */
- 0, /*high order offset*/
- 0, /*low order offset*/
- MAPPINGSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewAddress)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpTwo;
- }
-
- /* Write to the Map view.
- */
- memcpy(lpMapViewAddress, buf, strlen(buf));
-
- /* Read from the Map view.
- */
- memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
-
- /* Copy the MapViewOfFile to buffer, so we can
- * compare with value read from file directly.
- */
- if (memcmp(ch, buf, strlen(buf))!= 0)
- {
- Trace("ERROR: MapViewOfFile not equal to file contents "
- "retrieved \"%s\", expected \"%s\".\n",
- ch, buf);
- RetVal = FAIL;
- goto CleanUpThree;
- }
-
-CleanUpThree:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewAddress);
- RetVal = FAIL;
- }
-
-CleanUpTwo:
-
- /* Close Handle to opend file mapping.
- */
- if ( CloseHandle(hFileMapping) == FALSE )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- hFileMapping);
- RetVal = FAIL;
- }
-
-CleanUpOne:
-
- /* Close Handle to create file mapping.
- */
- if ( CloseHandle(hFile) == FALSE )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- hFile);
- RetVal = FAIL;
- }
-
- /* Terminate the PAL.
- */
- PAL_TerminateEx(RetVal);
- return RetVal;
-}
-
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = Filemapping_memmgt
-Function = CreateFileMapping
-Name = CreateFileMappingA with PAGE_READWRITE
-TYPE = DEFAULT
-EXE1 = createfilemapping
-Description
-=Test the CreateFileMapping to create a unnamed file-mapping object
-=and with PAGE_READWRITE protection
+++ /dev/null
-set(SOURCES
- CreateFileMapping.cpp
-)
-
-add_executable(paltest_createfilemappinga_test4
- ${SOURCES}
-)
-
-add_dependencies(paltest_createfilemappinga_test4 coreclrpal)
-
-target_link_libraries(paltest_createfilemappinga_test4
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=============================================================
-**
-** Source: createfilemapping.c (test 4)
-**
-** Purpose: Positive test the CreateFileMapping API.
-** Call CreateFileMapping with access PAGE_WRITECOPY.
-**
-**
-**============================================================*/
-#include <palsuite.h>
-
-const int MAPPINGSIZE = 2048;
-
-int __cdecl main(int argc, char *argv[])
-{
-
- HANDLE hFile;
- char buf[] = "this is a test string";
- char ch[2048];
- char lpFileName[] = "test.tmp";
- HANDLE hFileMapping;
- LPVOID lpMapViewAddress;
- int RetVal = PASS;
- int err;
- DWORD dwBytesWritten;
-
-
- /* Initialize the PAL environment.
- */
- if(0 != PAL_Initialize(argc, argv))
- {
- return FAIL;
- }
-
- /* Create a file handle with CreateFile.
- */
- hFile = CreateFile( lpFileName,
- GENERIC_WRITE|GENERIC_READ,
- FILE_SHARE_READ|FILE_SHARE_WRITE,
- NULL,
- CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
-
- if (hFile == INVALID_HANDLE_VALUE)
- {
- Fail("ERROR: %u :unable to create file \"%s\".\n",
- GetLastError(),
- lpFileName);
- }
-
- /* Write to the File handle.
- */
- err = WriteFile(hFile,
- buf,
- strlen(buf),
- &dwBytesWritten,
- NULL);
-
- if (err == FALSE)
- {
- Trace("ERROR: %u :unable to write to file handle "
- "hFile=0x%lx\n",
- GetLastError(),
- hFile);
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
- /* Flush to the hard-drive.
- */
- FlushFileBuffers(hFile);
-
- /* Initialize the buffers.
- */
- memset(ch, 0, MAPPINGSIZE);
-
- /* Create a unnamed file-mapping object with file handle FileHandle
- * and with PAGE_WRITECOPY protection.
- */
- hFileMapping = CreateFileMapping(
- hFile,
- NULL, /*not inherited*/
- PAGE_WRITECOPY, /*write copy*/
- 0, /*high-order size*/
- 0, /*low-order size*/
- NULL); /*unnamed object*/
-
- if(NULL == hFileMapping)
- {
- Trace("ERROR:%u: Failed to create File Mapping.\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
- /* maps a view of a file into the address space of the calling process.
- */
- lpMapViewAddress = MapViewOfFile(
- hFileMapping,
- FILE_MAP_COPY, /* access code */
- 0, /* high order offset*/
- 0, /* low order offset*/
- 0); /* number of bytes for map */
-
- if(NULL == lpMapViewAddress)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpTwo;
- }
-
- /* Write to the Map view.3
- */
- memcpy(lpMapViewAddress, buf, strlen(buf));
-
- /* Read from the Map view.
- */
- memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
-
- /* Copy the MapViewOfFile to buffer, so we can
- * compare with value read from file directly.
- */
- if (memcmp(ch, buf, strlen(buf))!= 0)
- {
- Trace("ERROR: MapViewOfFile not equal to file contents "
- "retrieved \"%s\", expected \"%s\".\n",
- ch, buf);
- RetVal = FAIL;
- goto CleanUpThree;
- }
-
-CleanUpThree:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewAddress);
- RetVal = FAIL;
- }
-
-CleanUpTwo:
-
- /* Close Handle to opend file mapping.
- */
- if ( CloseHandle(hFileMapping) == FALSE )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- hFileMapping);
- RetVal = FAIL;
- }
-
-CleanUpOne:
-
- /* Close Handle to create file mapping.
- */
- if ( CloseHandle(hFile) == FALSE )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- hFile);
- RetVal = FAIL;
- }
-
- /* Terminate the PAL.
- */
- PAL_TerminateEx(RetVal);
- return RetVal;
-}
-
-
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = Filemapping_memmgt
-Function = CreateFileMapping
-Name = CreateFileMappingA with PAGE_WRITECOPY.
-TYPE = DEFAULT
-EXE1 = createfilemapping
-Description
-= Positive test the CreateFileMapping API.
-= Call CreateFileMapping with access PAGE_WRITECOPY.
+++ /dev/null
-set(SOURCES
- CreateFileMapping.cpp
-)
-
-add_executable(paltest_createfilemappinga_test5
- ${SOURCES}
-)
-
-add_dependencies(paltest_createfilemappinga_test5 coreclrpal)
-
-target_link_libraries(paltest_createfilemappinga_test5
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=============================================================
-**
-** Source: createfilemapping.c (test 5)
-**
-** Purpose: Positive test the CreateFileMapping API.
-** Test CreateFileMapping to a "swap" handle with
-** access PAGE_READONLY.
-**
-**
-**============================================================*/
-#include <palsuite.h>
-
-const int MAPPINGSIZE = 2048;
-HANDLE SWAP_HANDLE = ((VOID *)(-1));
-
-int __cdecl main(int argc, char *argv[])
-{
- char testString[] = "this is a test string";
- char lpObjectName[] = "myMappingObject";
- int RetVal = FAIL;
- char results[2048];
-
- HANDLE hFileMapRO;
- HANDLE hFileMapRW;
- LPVOID lpMapViewRO;
- LPVOID lpMapViewRW;
-
- /* Initialize the PAL environment.
- */
- if(0 != PAL_Initialize(argc, argv))
- {
- return FAIL;
- }
-
- /* Initialize the buffers.
- */
- memset(results, 0, MAPPINGSIZE);
-
- /* Create a named file-mapping object with file handle FileHandle
- * and with PAGE_READWRITE protection.
- */
- hFileMapRW = CreateFileMapping(
- SWAP_HANDLE,
- NULL, /*not inherited*/
- PAGE_READWRITE, /*read only*/
- 0, /*high-order size*/
- MAPPINGSIZE, /*low-order size*/
- lpObjectName); /*named object*/
-
- if(NULL == hFileMapRW)
- {
- Fail("ERROR:%u: Failed to create File Mapping.\n",
- GetLastError());
- }
-
- /* maps a view of a file into the address space of the calling process.
- */
- lpMapViewRW = MapViewOfFile(
- hFileMapRW,
- FILE_MAP_ALL_ACCESS, /* access code */
- 0, /* high order offset*/
- 0, /* low order offset*/
- MAPPINGSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewRW)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
-
- hFileMapRO = CreateFileMapping(
- SWAP_HANDLE,
- NULL, /*not inherited*/
- PAGE_READONLY, /*read and write*/
- 0, /*high-order size*/
- MAPPINGSIZE, /*low-order size*/
- lpObjectName); /*named object*/
-
- if(NULL == hFileMapRO)
- {
- Trace("ERROR:%u: Failed to create File Mapping.\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpTwo;
- }
-
- /* maps a view of a file into the address space of the calling process.
- */
- lpMapViewRO = MapViewOfFile(
- hFileMapRO,
- FILE_MAP_READ, /* access code */
- 0, /* high order offset*/
- 0, /* low order offset*/
- MAPPINGSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewRO)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpThree;
- }
-
- /* Write the test string to the Map view.
- */
- memcpy(lpMapViewRW, testString, strlen(testString));
-
- /* Read from the second Map view.
- */
- memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE);
-
- /* Verify the contents of the file mapping,
- * by comparing what was written to what was read.
- */
- if (memcmp(results, testString, strlen(testString))!= 0)
- {
- Trace("ERROR: MapViewOfFile not equal to file contents "
- "retrieved \"%s\", expected \"%s\".\n",
- results,
- testString);
- RetVal = FAIL;
- goto CleanUpFour;
- }
-
- /* Test was successful.
- */
- RetVal = PASS;
-
-CleanUpFour:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewRO) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewRO);
- RetVal = FAIL;
- }
-
-CleanUpThree:
-
- /* Close Handle to opend file mapping.
- */
- if ( CloseHandle(hFileMapRO) == FALSE )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- hFileMapRO);
- RetVal = FAIL;
- }
-
-
-CleanUpTwo:
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewRW) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewRW);
- RetVal = FAIL;
- }
-
-
-CleanUpOne:
-
- /* Close Handle to opend file mapping.
- */
- if ( CloseHandle(hFileMapRW) == FALSE )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- hFileMapRW);
- RetVal = FAIL;
- }
-
-
- /* Terminate the PAL.
- */
- PAL_TerminateEx(RetVal);
- return RetVal;
-}
-
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = Filemapping_memmgt
-Function = CreateFileMapping
-Name = CreateFileMappingA - with PAGE_READWRITE and INVALID_HANDLE_VALUE file handle
-TYPE = DEFAULT
-EXE1 = createfilemapping
-Description
-=Test the CreateFileMapping to create a unnamed file-mapping object
-=and with PAGE_READWRITE protection by passing INVALID_HANDLE_VALUE
-=file handle
+++ /dev/null
-set(SOURCES
- CreateFileMapping.cpp
-)
-
-add_executable(paltest_createfilemappinga_test6
- ${SOURCES}
-)
-
-add_dependencies(paltest_createfilemappinga_test6 coreclrpal)
-
-target_link_libraries(paltest_createfilemappinga_test6
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=============================================================
-**
-** Source: createfilemapping.c (test 6)
-**
-** Purpose: Positive test the CreateFileMapping API.
-** Test CreateFileMapping to a "swap" handle with
-** access PAGE_READWRITE.
-**
-**
-**============================================================*/
-#include <palsuite.h>
-
-const int MAPPINGSIZE = 2048;
-HANDLE SWAP_HANDLE = ((VOID *)(-1));
-
-int __cdecl main(int argc, char *argv[])
-{
- char testString[] = "this is a test string";
- char lpObjectName[] = "myMappingObject";
- char results[2048];
- int RetVal = PASS;
-
- HANDLE hFileMapRW;
- LPVOID lpMapViewRW;
- LPVOID lpMapViewRW2;
-
- /* Initialize the PAL environment.
- */
- if(0 != PAL_Initialize(argc, argv))
- {
- return FAIL;
- }
-
- /* Initialize the buffers.
- */
- memset(results, 0, MAPPINGSIZE);
-
- /* Create a named file-mapping object with file handle FileHandle
- * and with PAGE_READWRITE protection.
- */
- hFileMapRW = CreateFileMapping(
- SWAP_HANDLE,
- NULL, /*not inherited*/
- PAGE_READWRITE, /*read write*/
- 0, /*high-order size*/
- MAPPINGSIZE, /*low-order size*/
- lpObjectName); /*unnamed object*/
-
- if(NULL == hFileMapRW)
- {
- Fail("ERROR:%u: Failed to create File Mapping.\n",
- GetLastError());
- }
-
- /* Create a map view of the READWRITE file mapping.
- */
- lpMapViewRW = MapViewOfFile(
- hFileMapRW,
- FILE_MAP_ALL_ACCESS,/* access code */
- 0, /* high order offset*/
- 0, /* low order offset*/
- MAPPINGSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewRW)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
-
- /* maps a view of a file into the address space of the calling process.
- */
- lpMapViewRW2 = MapViewOfFile(
- hFileMapRW,
- FILE_MAP_ALL_ACCESS, /* access code */
- 0, /* high order offset*/
- 0, /* low order offset*/
- MAPPINGSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewRW2)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpTwo;
- }
-
- /* Write the test string to the Map view.
- */
- memcpy(lpMapViewRW, testString, strlen(testString));
-
- /* Read from the second Map view.
- */
- memcpy(results, (LPCSTR)lpMapViewRW2, MAPPINGSIZE);
-
- /* Verify the contents of the file mapping,
- * by comparing what was written to what was read.
- */
- if (memcmp(results, testString, strlen(testString))!= 0)
- {
- Trace("ERROR: MapViewOfFile not equal to file contents "
- "retrieved \"%s\", expected \"%s\".\n",
- results,
- testString);
- RetVal = FAIL;
- goto CleanUpThree;
- }
-
- /* Test successful.
- */
- RetVal = PASS;
-
-CleanUpThree:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewRW2) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewRW2);
- RetVal = FAIL;
- }
-
-CleanUpTwo:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewRW) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewRW);
- RetVal = FAIL;
- }
-
-
-CleanUpOne:
-
- /* Close Handle to create file mapping.
- */
- if ( CloseHandle(hFileMapRW) == FALSE )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- hFileMapRW);
- RetVal = FAIL;
- }
-
-
- /* Terminate the PAL.
- */
- PAL_TerminateEx(RetVal);
- return RetVal;
-}
-
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = Filemapping_memmgt
-Function = CreateFileMapping
-Name = CreateFileMappingA - with PAGE_READONLY
-TYPE = DEFAULT
-EXE1 = createfilemapping
-Description
-=Test the CreateFileMapping to create a named file-mapping object
-=and with PAGE_READONLY protection
+++ /dev/null
-set(SOURCES
- createfilemapping.cpp
-)
-
-add_executable(paltest_createfilemappinga_test7
- ${SOURCES}
-)
-
-add_dependencies(paltest_createfilemappinga_test7 coreclrpal)
-
-target_link_libraries(paltest_createfilemappinga_test7
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=============================================================
-**
-** Source: createfilemapping.c (test 7)
-**
-** Purpose: Positive test the CreateFileMapping API.
-** Test CreateFileMapping to a "swap" handle with
-** access PAGE_READWRITE.
-**
-**
-**============================================================*/
-#include <palsuite.h>
-
-const int MAPPINGSIZE = 2048;
-HANDLE SWAP_HANDLE = ((VOID *)(-1));
-
-int __cdecl main(int argc, char *argv[])
-{
- char testString[] = "this is a test string";
- char lpObjectName[] = "myMappingObject";
- char results[2048];
- int RetVal = PASS;
-
- HANDLE hFileMapRW;
- LPVOID lpMapViewRW;
- LPVOID lpMapViewRO;
-
- /* Initialize the PAL environment.
- */
- if(0 != PAL_Initialize(argc, argv))
- {
- return FAIL;
- }
-
- /* Initialize the buffers.
- */
- memset(results, 0, MAPPINGSIZE);
-
- /* Create a named file-mapping object with file handle FileHandle
- * and with PAGE_READWRITE protection.
- */
- hFileMapRW = CreateFileMapping(
- SWAP_HANDLE,
- NULL, /*not inherited*/
- PAGE_READWRITE, /*read write*/
- 0, /*high-order size*/
- MAPPINGSIZE, /*low-order size*/
- lpObjectName); /*unnamed object*/
-
- if(NULL == hFileMapRW)
- {
- Fail("ERROR:%u: Failed to create File Mapping.\n",
- GetLastError());
- }
-
- /* Create a map view to the READWRITE file mapping.
- */
- lpMapViewRW = MapViewOfFile(
- hFileMapRW,
- FILE_MAP_ALL_ACCESS,/* access code */
- 0, /* high order offset*/
- 0, /* low order offset*/
- MAPPINGSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewRW)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
-
- /* Create a map view to the READWRITE file mapping.
- */
- lpMapViewRO = MapViewOfFile(
- hFileMapRW,
- FILE_MAP_READ, /* access code */
- 0, /* high order offset*/
- 0, /* low order offset*/
- MAPPINGSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewRO)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpTwo;
- }
-
- /* Write the test string to the Map view.
- */
- memcpy(lpMapViewRW, testString, strlen(testString));
-
- /* Read from the second Map view.
- */
- memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE);
-
- /* Verify the contents of the file mapping,
- * by comparing what was written to what was read.
- */
- if (memcmp(results, testString, strlen(testString))!= 0)
- {
- Trace("ERROR: MapViewOfFile not equal to file contents "
- "retrieved \"%s\", expected \"%s\".\n",
- results,
- testString);
- RetVal = FAIL;
- goto CleanUpThree;
- }
-
- /* Test successful.
- */
- RetVal = PASS;
-
-CleanUpThree:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewRO) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewRO);
- RetVal = FAIL;
- }
-
-CleanUpTwo:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewRW) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewRW);
- RetVal = FAIL;
- }
-
-
-CleanUpOne:
-
- /* Close Handle to create file mapping.
- */
- if ( CloseHandle(hFileMapRW) == FALSE )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- hFileMapRW);
- RetVal = FAIL;
- }
-
-
- /* Terminate the PAL.
- */
- PAL_TerminateEx(RetVal);
- return RetVal;
-}
-
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = Filemapping_memmgt
-Function = CreateFileMapping
-Name = CreateFileMappingA - with PAGE_COPYWRITE
-TYPE = DEFAULT
-EXE1 = createfilemapping
-Description
-=Test the CreateFileMapping to create a named file-mapping object
-=and with PAGE_READONLY protection
+++ /dev/null
-set(SOURCES
- createfilemapping.cpp
-)
-
-add_executable(paltest_createfilemappinga_test8
- ${SOURCES}
-)
-
-add_dependencies(paltest_createfilemappinga_test8 coreclrpal)
-
-target_link_libraries(paltest_createfilemappinga_test8
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=============================================================
-**
-** Source: createfilemapping.c (test 8)
-**
-** Purpose: Positive test the CreateFileMapping API.
-** Test the un-verifiable parameter combinations.
-**
-**
-**============================================================*/
-#include <palsuite.h>
-
-const int MAPPINGSIZE = 2048;
-HANDLE SWAP_HANDLE = ((VOID *)(-1));
-
-int __cdecl main(int argc, char *argv[])
-{
- HANDLE hFileMap;
-
- /* Initialize the PAL environment.
- */
- if(0 != PAL_Initialize(argc, argv))
- {
- return FAIL;
- }
-
- /* Create a READONLY, "swap", un-named file mapping.
- * This test is unverifiable since there is no hook back to the file map
- * because it is un-named. As well, since it resides in "swap", and is
- * initialized to zero, there is nothing to read.
- */
- hFileMap = CreateFileMapping(
- SWAP_HANDLE,
- NULL, /*not inherited*/
- PAGE_READONLY, /*read only*/
- 0, /*high-order size*/
- MAPPINGSIZE, /*low-order size*/
- NULL); /*un-named object*/
-
- if(NULL == hFileMap)
- {
- Fail("ERROR:%u: Failed to create File Mapping.\n",
- GetLastError());
- }
-
-
- /* Create a COPYWRITE, "swap", un-named file mapping.
- * This test is unverifiable, here is a quote from MSDN:
- *
- * Copy on write access. If you create the map with PAGE_WRITECOPY and
- * the view with FILE_MAP_COPY, you will receive a view to file. If you
- * write to it, the pages are automatically swappable and the modifications
- * you make will not go to the original data file.
- *
- */
- hFileMap = CreateFileMapping(
- SWAP_HANDLE,
- NULL, /*not inherited*/
- PAGE_WRITECOPY, /*read only*/
- 0, /*high-order size*/
- MAPPINGSIZE, /*low-order size*/
- NULL); /*unnamed object*/
-
- if(NULL == hFileMap)
- {
- Fail("ERROR:%u: Failed to create File Mapping.\n",
- GetLastError());
- }
-
-
- /* Terminate the PAL.
- */
- PAL_Terminate();
- return PASS;
-}
-
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = Filemapping_memmgt
-Function = CreateFileMapping
-Name = CreateFileMappingA - unnamed swap, READWRITE.
-TYPE = DEFAULT
-EXE1 = createfilemapping
-Description
-= Positive test the CreateFileMapping API.
-= Test an unnamed File Mapping to a "swap"
-= handle with access PAGE_READWRITE.
+++ /dev/null
-set(SOURCES
- createfilemapping.cpp
-)
-
-add_executable(paltest_createfilemappinga_test9
- ${SOURCES}
-)
-
-add_dependencies(paltest_createfilemappinga_test9 coreclrpal)
-
-target_link_libraries(paltest_createfilemappinga_test9
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=============================================================
-**
-** Source: createfilemapping.c (test 9)
-**
-** Purpose: Negative test the CreateFileMapping API.
-**
-**
-**============================================================*/
-#include <palsuite.h>
-
-const int MAPPINGSIZE = 2048;
-
-int __cdecl main(int argc, char *argv[])
-{
-
- HANDLE hFile;
- char lpFileName[] = "test.tmp";
-
- HANDLE hFileMapping;
-
- /* Initialize the PAL environment.
- */
- if(0 != PAL_Initialize(argc, argv))
- {
- return FAIL;
- }
-
- /* Create a file handle with CreateFile, as READONLY
- */
- hFile = CreateFile( lpFileName,
- GENERIC_READ,
- FILE_SHARE_READ,
- NULL,
- CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
-
- if (hFile == INVALID_HANDLE_VALUE)
- {
- Fail("ERROR: %u :unable to create file \"%s\".\n",
- GetLastError(),
- lpFileName);
- }
-
- /* Attempt to create a unnamed file-mapping object to a READONLY file
- * as READWRITE access.
- */
- hFileMapping = CreateFileMapping(
- hFile,
- NULL, /*not inherited*/
- PAGE_READWRITE, /*read and write*/
- 0, /*high-order size*/
- MAPPINGSIZE, /*low-order size*/
- NULL); /*unnamed object*/
-
- if(NULL != hFileMapping)
- {
- Trace("ERROR: Able to create READWRITE mapping to a "
- "READONLY file.\n" );
- if( 0 == CloseHandle(hFile) )
- {
- Trace("Unexpected Error: Unable to close file handle\n");
- }
- Fail("");
- }
-
- /* Attempt to create a unnamed file-mapping object to a zero lenght
- * file.
- */
- hFileMapping = CreateFileMapping(
- hFile,
- NULL, /*not inherited*/
- PAGE_READWRITE, /*read and write*/
- 0, /*high-order size*/
- 0, /*low-order size*/
- NULL); /*unnamed object*/
-
- if( NULL != hFileMapping )
- {
- Trace("ERROR: Able to create READWRITE mapping to a "
- "READONLY file.\n" );
- if( 0 == CloseHandle(hFile) )
- {
- Trace("Unexpected Error: Unable to close file handle\n");
- }
- Fail("");
- }
- if(GetLastError() != ERROR_ACCESS_DENIED)
- {
- Trace("ERROR: Expected GetLastError() to return "
- "ERROR_FILE_INVALID (%d), it returned %u.\n",
- ERROR_FILE_INVALID,
- GetLastError());
- if( 0 == CloseHandle(hFile) )
- {
- Trace("Unexpected Error: Unable to close file handle\n");
- }
- Fail("");
- }
-
- /* Attempt to create a file mapping that is larger than
- * the file.
- */
- hFileMapping = CreateFileMapping(
- hFile,
- NULL, /*not inherited*/
- PAGE_READONLY, /*read only*/
- 0, /*high-order size*/
- MAPPINGSIZE, /*low-order size*/
- NULL); /*unnamed object*/
- if(NULL != hFileMapping)
- {
- Trace("ERROR: Able to create file mapping of size %d to "
- "file of size 0.\n",
- MAPPINGSIZE);
- if( 0 == CloseHandle(hFile) )
- {
- Trace("Unexpected Error: Unable to close file handle\n");
- }
- Fail("");
- }
-
- if(GetLastError() != ERROR_NOT_ENOUGH_MEMORY )
- {
- Trace("ERROR: Expected GetLastError() to return "
- "ERROR_NOT_ENOUGH_MEMORY (%d), it returned %u.\n",
- ERROR_NOT_ENOUGH_MEMORY,
- GetLastError());
- if( 0 == CloseHandle(hFile) )
- {
- Trace("Unexpected Error: Unable to close file handle\n");
- }
- Fail("");
- }
-
- if( 0 == CloseHandle(hFile) )
- {
- Fail("Unexpected Error: Unable to close file handle\n");
- }
-
- /* Terminate the PAL.
- */
- PAL_Terminate();
- return PASS;
-}
-
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = Filemapping_memmgt
-Function = CreateFileMapping
-Name = CreateFileMappingA negative testing
-TYPE = DEFAULT
-EXE1 = createfilemapping
-Description
-= Negative test the CreateFileMapping API.
Version = 1.0
Section = Filemapping_memmgt
Function = CreateFileMapping
-Name = CreateFileMappingA - with PAGE_READONLY
+Name = CreateFileMappingW - with PAGE_READONLY
TYPE = DEFAULT
EXE1 = createfilemappingw
Description
+++ /dev/null
-add_subdirectory(test1)
-add_subdirectory(test2)
-add_subdirectory(test3)
-
+++ /dev/null
-set(SOURCES
- OpenFileMappingA.cpp
-)
-
-add_executable(paltest_openfilemappinga_test1
- ${SOURCES}
-)
-
-add_dependencies(paltest_openfilemappinga_test1 coreclrpal)
-
-target_link_libraries(paltest_openfilemappinga_test1
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=============================================================
-**
-** Source: openfilemappinga.c (test 1)
-**
-** Purpose: Positive test the OpenFileMapping API.
-** Call OpenFileMapping to open a named file-mapping
-** object with FILE_MAP_ALL_ACCESS access
-**
-**
-**============================================================*/
-#include <palsuite.h>
-
-int __cdecl main(int argc, char *argv[])
-{
- HANDLE FileMappingHandle;
- HANDLE OpenFileMappingHandle;
- HANDLE lpMapViewAddress;
- const int LOWORDERSIZE = 1024;
- char buf[] = "this is a test";
- char MapObject[] = "myMappingObject";
- char ch[1024];
- int err;
- int RetVal = PASS;
-
- /* Initialize the PAL environment.
- */
- err = PAL_Initialize(argc, argv);
- if(0 != err)
- {
- return FAIL;
- }
-
-
- /* Create a named file-mapping object with
- * file handle FileHandle.
- */
- FileMappingHandle = CreateFileMapping(
- INVALID_HANDLE_VALUE,
- NULL, /* not inherited */
- PAGE_READWRITE, /* read and write */
- 0, /* high-order size */
- LOWORDERSIZE, /* low-order size */
- MapObject); /* named object */
-
- if(NULL == FileMappingHandle)
- {
- Fail("ERROR:%u:Failed to call CreateFileMapping to "
- "create a mapping object.\n",
- GetLastError());
- }
- if(GetLastError() == ERROR_ALREADY_EXISTS)
- {
- Trace("ERROR:File mapping object already exists\n");
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
- /* Open a named file-mapping object with
- * FILE_MAP_ALL_ACCESS access.
- */
- OpenFileMappingHandle = OpenFileMapping(
- FILE_MAP_ALL_ACCESS,
- TRUE,
- MapObject );
-
- if(NULL == OpenFileMappingHandle)
- {
- Trace("ERROR:%u:Failed to Call OpenFileMapping API!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
- /* Test the opened map view.
- */
- lpMapViewAddress = MapViewOfFile(
- OpenFileMappingHandle,
- FILE_MAP_ALL_ACCESS, /* access code */
- 0, /* high order offset */
- 0, /* low order offset */
- LOWORDERSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewAddress)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpTwo;
- }
-
- /* Write to the Map View.
- */
- memcpy(lpMapViewAddress, buf, strlen(buf));
-
- /* Read from the Map View.
- */
- memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE);
-
- /* Compare what was written to the Map View,
- * to what was read.
- */
- if (memcmp(ch, buf, strlen(buf))!= 0)
- {
- Trace("ERROR: MapViewOfFile not equal to file contents "
- "retrieved \"%s\", expected \"%s\".\n",
- ch, buf);
- RetVal = FAIL;
- goto CleanUpThree;
-
- }
-
-CleanUpThree:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewAddress);
- RetVal = FAIL;
- }
-
-CleanUpTwo:
-
- /* Close Handle to opend file mapping.
- */
- if ( CloseHandle(OpenFileMappingHandle) == 0 )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- OpenFileMappingHandle);
- RetVal = FAIL;
- }
-
-CleanUpOne:
-
- /* Close Handle to create file mapping.
- */
- if ( CloseHandle(FileMappingHandle) == 0 )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- FileMappingHandle);
- RetVal = FAIL;
- }
-
-
- /* Terminat the PAL.*/
- PAL_TerminateEx(RetVal);
- return RetVal;
-}
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = Filemapping_memmgt
-Function = OpenFileMappingA
-Name = Positive test for OpenFileMappingA API with FILE_MAP_ALL_ACCESS access
-TYPE = DEFAULT
-EXE1 = openfilemappinga
-Description
-=Test the OpenFileMappingA with FILE_MAP_ALL_ACCESS access
+++ /dev/null
-set(SOURCES
- OpenFileMappingA.cpp
-)
-
-add_executable(paltest_openfilemappinga_test2
- ${SOURCES}
-)
-
-add_dependencies(paltest_openfilemappinga_test2 coreclrpal)
-
-target_link_libraries(paltest_openfilemappinga_test2
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=============================================================
-**
-** Source: openfilemappinga.c (test 2)
-**
-** Purpose: Positive test the OpenFileMapping API.
-** Call OpenFileMapping to open a named file-mapping
-** object with FILE_MAP_WRITE access
-**
-**
-**============================================================*/
-#include <palsuite.h>
-
-int __cdecl main(int argc, char *argv[])
-{
- HANDLE FileMappingHandle;
- HANDLE OpenFileMappingHandle;
- HANDLE lpMapViewAddress;
- HANDLE OpenFileMappingHandle2;
- HANDLE lpMapViewAddress2;
- const int LOWORDERSIZE = 1024;
- char MapObject[] = "myMappingObject";
- char buf[] = "this is a test";
- char ch[1024];
- int RetVal = PASS;
-
-
- /* Initialize the PAL environment.
- */
- if(0 != PAL_Initialize(argc, argv))
- {
- return FAIL;
- }
-
- /* Create a named file-mapping object with file handle FileHandle.
- */
- FileMappingHandle = CreateFileMapping(
- INVALID_HANDLE_VALUE,
- NULL, /* not inherited */
- PAGE_READWRITE, /* read and write */
- 0, /* high-order size */
- LOWORDERSIZE, /* low-order size */
- MapObject); /* named object */
-
-
- if(NULL == FileMappingHandle)
- {
- Fail("\nFailed to call CreateFileMapping to create "
- "a mapping object!\n");
- }
- if(GetLastError() == ERROR_ALREADY_EXISTS)
- {
- Trace("\nFile mapping object already exists!\n");
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
- /* Open a named file-mapping object with FILE_MAP_WRITE access.
- */
- OpenFileMappingHandle = OpenFileMapping(
- FILE_MAP_WRITE,
- FALSE,
- MapObject);
-
- if(NULL == OpenFileMappingHandle)
- {
- Trace("\nFailed to Call OpenFileMapping API!\n");
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
- /* Open a named file-mapping object with
- * FILE_MAP_ALL_ACCESS access, to verify
- * the FILE_MAP_WRITE access map.
- */
- OpenFileMappingHandle2 = OpenFileMapping(
- FILE_MAP_ALL_ACCESS,
- FALSE,
- MapObject);
-
- if(NULL == OpenFileMappingHandle2)
- {
- Trace("\nFailed to Call OpenFileMapping API!\n");
- RetVal = FAIL;
- goto CleanUpTwo;
- }
-
- /* Create map view of the open mapping that has
- * FILE_MAP_WRITE access.
- */
- lpMapViewAddress = MapViewOfFile(
- OpenFileMappingHandle,
- FILE_MAP_WRITE, /* access code */
- 0, /* high order offset */
- 0, /* low order offset */
- LOWORDERSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewAddress)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpThree;
- }
-
- /* Create map view of the open mapping that has
- * FILE_MAP_ALL_ACCESS access.
- */
- lpMapViewAddress2 = MapViewOfFile(
- OpenFileMappingHandle2,
- FILE_MAP_ALL_ACCESS, /* access code */
- 0, /* high order offset */
- 0, /* low order offset */
- LOWORDERSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewAddress2)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpFour;
- }
-
- /* Write to the Map View.
- */
- memcpy(lpMapViewAddress, buf, strlen(buf));
-
- /* Read from the Map View.
- */
- memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE);
-
- /* Compare what was written to the Map View,
- * to what was read.
- */
- if (memcmp(ch, buf, strlen(buf))!= 0)
- {
- Fail("ERROR: MapViewOfFile not equal to file contents "
- "retrieved \"%s\", expected \"%s\".\n",
- ch, buf);
- RetVal = FAIL;
- goto CleanUpFive;
- }
-
-CleanUpFive:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewAddress2);
- RetVal = FAIL;
- }
-
-CleanUpFour:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewAddress);
- RetVal = FAIL;
- }
-
-CleanUpThree:
-
- /* Close Handle to opened file mapping.
- */
- if ( CloseHandle(OpenFileMappingHandle2) == 0 )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- OpenFileMappingHandle2);
- RetVal = FAIL;
- }
-
-CleanUpTwo:
-
- /* Close Handle to opened file mapping.
- */
- if ( CloseHandle(OpenFileMappingHandle) == 0 )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- OpenFileMappingHandle);
- RetVal = FAIL;
- }
-
-CleanUpOne:
-
- /* Close Handle to create file mapping.
- */
- if ( CloseHandle(FileMappingHandle) == 0 )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- FileMappingHandle);
- RetVal = FAIL;
- }
-
-
- /* Terminate the PAL.
- */
- PAL_TerminateEx(RetVal);
- return RetVal;
-}
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = Filemapping_memmgt
-Function = OpenFileMappingA
-Name = Positive test for OpenFileMappingA API with FILE_MAP_WRITE access
-TYPE = DEFAULT
-EXE1 = openfilemappinga
-Description
-=Test the OpenFileMappingA with FILE_MAP_WRITE access
+++ /dev/null
-set(SOURCES
- OpenFileMappingA.cpp
-)
-
-add_executable(paltest_openfilemappinga_test3
- ${SOURCES}
-)
-
-add_dependencies(paltest_openfilemappinga_test3 coreclrpal)
-
-target_link_libraries(paltest_openfilemappinga_test3
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=============================================================
-**
-** Source: openfilemappinga.c
-**
-** Purpose: Positive test the OpenFileMapping API.
-** Call OpenFileMapping to open a named file-mapping
-** object with FILE_MAP_READ access
-**
-**
-**============================================================*/
-#include <palsuite.h>
-
-
-int __cdecl main(int argc, char *argv[])
-{
-
- HANDLE FileMappingHandle;
- HANDLE OpenFileMappingHandle;
- HANDLE OpenFileMappingHandle2;
- HANDLE lpMapViewAddress;
- HANDLE lpMapViewAddress2;
- const int LOWORDERSIZE = 1024;
- char buf[] = "this is a test";
- char MapObject[] = "myMappingObject";
- char ch[1024];
- int RetVal = PASS;
-
- /* Initialize the PAL environment.
- */
- if(0 != PAL_Initialize(argc, argv))
- {
- return FAIL;
- }
-
- /* Create a named file-mapping object with file handle FileHandle.
- */
- FileMappingHandle = CreateFileMapping(
- INVALID_HANDLE_VALUE,
- NULL, /* Not inherited */
- PAGE_READWRITE, /* Read only */
- 0, /* High-order size */
- LOWORDERSIZE, /* Must be none 0 */
- MapObject); /* Named object */
-
-
- if(NULL == FileMappingHandle)
- {
- Fail("ERROR:%u:Failed to call CreateFileMapping to create "
- "mapping object = \"%s\".\n",
- GetLastError(),
- MapObject);
- }
- if(GetLastError() == ERROR_ALREADY_EXISTS)
- {
- Trace("ERROR:File mapping object \"%s\" already exists!\n",
- MapObject);
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
- /* Open a named file-mapping object with
- * FILE_MAP_READ access.
- */
- OpenFileMappingHandle = OpenFileMapping(
- FILE_MAP_READ,
- 0,
- MapObject);
-
- if(NULL == OpenFileMappingHandle)
- {
- Trace("ERROR:%u: Failed to Call OpenFileMapping API.\n");
- RetVal = FAIL;
- goto CleanUpOne;
- }
-
- /* Open a named file-mapping object with
- * FILE_MAP_ALL_ACCESS access, to verify the
- * READ-ONLY Map view.
- */
- OpenFileMappingHandle2 = OpenFileMapping(
- FILE_MAP_ALL_ACCESS,
- 0,
- MapObject);
-
- if(NULL == OpenFileMappingHandle2)
- {
- Trace("Failed to Call OpenFileMapping API!\n");
- RetVal = FAIL;
- goto CleanUpTwo;
- }
-
- /* Test the opened map view.
- */
- lpMapViewAddress = MapViewOfFile(
- OpenFileMappingHandle,
- FILE_MAP_READ, /* access code */
- 0, /* high order offset */
- 0, /* low order offset */
- LOWORDERSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewAddress)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpThree;
- }
-
- /* Open the second Map view to verify the writing
- * of the READ-ONLY Map view.
- */
- lpMapViewAddress2 = MapViewOfFile(
- OpenFileMappingHandle2,
- FILE_MAP_ALL_ACCESS, /* access code */
- 0, /* high order offset */
- 0, /* low order offset */
- LOWORDERSIZE); /* number of bytes for map */
-
- if(NULL == lpMapViewAddress2)
- {
- Trace("ERROR:%u: Failed to call MapViewOfFile "
- "API to map a view of file!\n",
- GetLastError());
- RetVal = FAIL;
- goto CleanUpFour;
- }
-
- /* Write to the ALL_ACCESS Map View.
- */
- memcpy(lpMapViewAddress2, buf, strlen(buf));
-
- /* Read from the READ-ONLY Map View.
- */
- memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE);
-
- /* Compare what was written to the Map View,
- * to what was read.
- */
- if (memcmp(ch, buf, strlen(buf))!= 0)
- {
- Trace("ERROR: MapViewOfFile not equal to file contents "
- "retrieved \"%s\", expected \"%s\".\n",
- ch, buf);
- RetVal = FAIL;
- goto CleanUpFive;
- }
-
-CleanUpFive:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewAddress2);
- RetVal = FAIL;
- }
-
-CleanUpFour:
-
- /* Unmap the view of file.
- */
- if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
- {
- Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
- GetLastError(),
- lpMapViewAddress);
- RetVal = FAIL;
- }
-
-CleanUpThree:
-
- /* Close Handle to opened file mapping.
- */
- if ( CloseHandle(OpenFileMappingHandle2) == 0 )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- OpenFileMappingHandle2);
- RetVal = FAIL;
- }
-
-CleanUpTwo:
-
- /* Close Handle to opened file mapping.
- */
- if ( CloseHandle(OpenFileMappingHandle) == 0 )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- OpenFileMappingHandle);
- RetVal = FAIL;
- }
-
-CleanUpOne:
-
- /* Close Handle to create file mapping.
- */
- if ( CloseHandle(FileMappingHandle) == 0 )
- {
- Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
- GetLastError(),
- FileMappingHandle);
- RetVal = FAIL;
- }
-
- /* Terminate the PAL.
- */
- PAL_TerminateEx(RetVal);
- return RetVal;
-}
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = Filemapping_memmgt
-Function = OpenFileMappingA
-Name = Positive test for OpenFileMappingA API with FILE_MAP_READ access
-TYPE = DEFAULT
-EXE1 = openfilemappinga
-Description
-=Test the OpenFileMappingA with FILE_MAP_READ access
exception_handling/RaiseException/test2/paltest_raiseexception_test2
exception_handling/RaiseException/test3/paltest_raiseexception_test3
exception_handling/pal_sxs/test1/paltest_pal_sxs_test1
-filemapping_memmgt/CreateFileMappingA/test1/paltest_createfilemappinga_test1
-filemapping_memmgt/CreateFileMappingA/test3/paltest_createfilemappinga_test3
-filemapping_memmgt/CreateFileMappingA/test4/paltest_createfilemappinga_test4
-filemapping_memmgt/CreateFileMappingA/test8/paltest_createfilemappinga_test8
-filemapping_memmgt/CreateFileMappingA/test9/paltest_createfilemappinga_test9
filemapping_memmgt/CreateFileMappingW/test1/paltest_createfilemappingw_test1
filemapping_memmgt/CreateFileMappingW/test3/paltest_createfilemappingw_test3
filemapping_memmgt/CreateFileMappingW/test4/paltest_createfilemappingw_test4
threading/CreateEventW/test1/paltest_createeventw_test1
threading/CreateEventW/test2/paltest_createeventw_test2
threading/CreateMutexW_ReleaseMutex/test1/paltest_createmutexw_releasemutex_test1
-threading/CreateProcessA/test1/paltest_createprocessa_test1
-threading/CreateProcessA/test2/paltest_createprocessa_test2
threading/CreateProcessW/test1/paltest_createprocessw_test1
threading/CreateProcessW/test2/paltest_createprocessw_test2
threading/CreateSemaphoreW_ReleaseSemaphore/test1/paltest_createsemaphorew_releasesemaphore_test1
exception_handling/PAL_TRY_EXCEPT_EX/test2/paltest_pal_try_except_ex_test2
exception_handling/PAL_TRY_EXCEPT_EX/test3/paltest_pal_try_except_ex_test3
exception_handling/PAL_TRY_LEAVE_FINALLY/test1/paltest_pal_try_leave_finally_test1
-filemapping_memmgt/CreateFileMappingA/test5/paltest_createfilemappinga_test5
-filemapping_memmgt/CreateFileMappingA/test6/paltest_createfilemappinga_test6
-filemapping_memmgt/CreateFileMappingA/test7/paltest_createfilemappinga_test7
filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/paltest_createfilemappingw_createfilemapping_neg1
filemapping_memmgt/CreateFileMappingW/test2/paltest_createfilemappingw_test2
filemapping_memmgt/CreateFileMappingW/test5/paltest_createfilemappingw_test5
filemapping_memmgt/GetModuleFileNameW/test1/paltest_getmodulefilenamew_test1
filemapping_memmgt/GetProcAddress/test1/paltest_getprocaddress_test1
filemapping_memmgt/GetProcAddress/test2/paltest_getprocaddress_test2
-filemapping_memmgt/OpenFileMappingA/test1/paltest_openfilemappinga_test1
-filemapping_memmgt/OpenFileMappingA/test2/paltest_openfilemappinga_test2
-filemapping_memmgt/OpenFileMappingA/test3/paltest_openfilemappinga_test3
filemapping_memmgt/OpenFileMappingW/test1/paltest_openfilemappingw_test1
filemapping_memmgt/OpenFileMappingW/test2/paltest_openfilemappingw_test2
filemapping_memmgt/OpenFileMappingW/test3/paltest_openfilemappingw_test3
add_subdirectory(CreateEventW)
add_subdirectory(CreateMutexW_ReleaseMutex)
-add_subdirectory(CreateProcessA)
add_subdirectory(CreateProcessW)
add_subdirectory(CreateSemaphoreW_ReleaseSemaphore)
add_subdirectory(CreateThread)
+++ /dev/null
-add_subdirectory(test1)
-add_subdirectory(test2)
-
+++ /dev/null
-set(TESTSOURCES
- parentProcess.cpp
-)
-
-add_executable(paltest_createprocessa_test1
- ${TESTSOURCES}
-)
-
-add_dependencies(paltest_createprocessa_test1 coreclrpal)
-
-target_link_libraries(paltest_createprocessa_test1
- ${COMMON_TEST_LIBRARIES}
-)
-
-
-set(HELPERSOURCES
- childProcess.cpp
-)
-
-add_executable(paltest_createprocessa_test1_child
- ${HELPERSOURCES}
-)
-
-add_dependencies(paltest_createprocessa_test1_child coreclrpal)
-
-target_link_libraries(paltest_createprocessa_test1_child
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*============================================================
-**
-** Source: CreateProcessA/test1/childprocess.c
-**
-** Purpose: Test to ensure CreateProcessA starts a new process. This test
-** launches a child process, and examines a file written by the child.
-** This code is the child code.
-**
-** Dependencies: GetCurrentDirectory
-** strlen
-** fopen
-** fclose
-** fprintf
-**
-
-**
-**=========================================================*/
-
-#include <palsuite.h>
-
-const char *szCommonFileA = "childdata.tmp";
-
-const char *szPathDelimA = "\\";
-
-const char *szCommonStringA = "058d2d057111a313aa82401c2e856002\0";
-
-/*
- * Take two wide strings representing file and directory names
- * (dirName, fileName), join the strings with the appropriate path
- * delimiter and populate a wide character buffer (absPathName) with
- * the resulting string.
- *
- * Returns: The number of wide characters in the resulting string.
- * 0 is returned on Error.
- */
-int
-mkAbsoluteFilenameA (
- LPSTR dirName,
- DWORD dwDirLength,
- LPCSTR fileName,
- DWORD dwFileLength,
- LPSTR absPathName )
-{
- extern const char *szPathDelimA;
-
- DWORD sizeDN, sizeFN, sizeAPN;
-
- sizeDN = strlen( dirName );
- sizeFN = strlen( fileName );
- sizeAPN = (sizeDN + 1 + sizeFN + 1);
-
- /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */
- if ( sizeAPN > _MAX_PATH )
- {
- return ( 0 );
- }
-
- strncpy(absPathName, dirName, dwDirLength +1);
- strncpy(absPathName, szPathDelimA, 2);
- strncpy(absPathName, fileName, dwFileLength +1);
-
- return (sizeAPN);
-
-}
-
-int __cdecl main( int argc, char **argv )
-{
-
- static FILE * fp;
-
- DWORD dwFileLength;
- DWORD dwDirLength;
- DWORD dwSize;
-
- char szDirNameA[_MAX_DIR];
- char szAbsPathNameA[_MAX_PATH];
-
- if(0 != (PAL_Initialize(argc, argv)))
- {
- return ( FAIL );
- }
-
- dwDirLength = GetCurrentDirectory( _MAX_PATH, szDirNameA );
-
- if (0 == dwDirLength)
- {
- Fail ("GetCurrentDirectory call failed. Could not get "
- "current working directory\n. Exiting.\n");
- }
-
- dwFileLength = strlen( szCommonFileA );
-
- dwSize = mkAbsoluteFilenameA( szDirNameA, dwDirLength, szCommonFileA,
- dwFileLength, szAbsPathNameA );
-
- if (0 == dwSize)
- {
- Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could "
- "not build absolute path name to file\n. Exiting.\n");
- }
-
- if ( NULL == ( fp = fopen ( szAbsPathNameA , "w+" ) ) )
- {
- /*
- * A return value of NULL indicates an error condition or an
- * EOF condition
- */
- Fail ("%s unable to open %s for writing. Exiting.\n", argv[0]
- , szAbsPathNameA );
- }
-
- if ( 0 >= ( fprintf ( fp, "%s", szCommonStringA )))
- {
- Fail("%s unable to write to %s. Exiting.\n", argv[0]
- , szAbsPathNameA );
- }
-
- if (0 != (fclose ( fp )))
- {
- Fail ("%s unable to close file %s. Pid may not be "
- "written to file. Exiting.\n", argv[0], szAbsPathNameA );
- }
-
- PAL_Terminate();
- return ( PASS );
-
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*============================================================
-**
-** Source: CreateProcessA/test1/parentprocess.c
-**
-** Purpose: Test to ensure CreateProcessA starts a new process. This test
-** launches a child process, and examines a file written by the child.
-** This process (the parent process) reads the file created by the child and
-** compares the value the child wrote to the file. (a const char *)
-**
-** Dependencies: GetCurrentDirectory
-** strlen
-** WaitForSingleObject
-** fopen
-** fclose
-** Fail
-**
-
-**
-**=========================================================*/
-
-#include <palsuite.h>
-
-const char *szCommonFileA = "childdata.tmp";
-
-const char *szChildFileA = "paltest_createprocessa_test1_child";
-
-const char *szPathDelimA = "\\";
-
-const char *szCommonStringA = "058d2d057111a313aa82401c2e856002\0";
-
-/*
- * Take two wide strings representing file and directory names
- * (dirName, fileName), join the strings with the appropriate path
- * delimiter and populate a wide character buffer (absPathName) with
- * the resulting string.
- *
- * Returns: The number of wide characters in the resulting string.
- * 0 is returned on Error.
- */
-int
-mkAbsoluteFilenameA (
- LPSTR dirName,
- DWORD dwDirLength,
- LPCSTR fileName,
- DWORD dwFileLength,
- LPSTR absPathName )
-{
- extern const char *szPathDelimA;
-
- DWORD sizeDN, sizeFN, sizeAPN;
-
- sizeDN = strlen( dirName );
- sizeFN = strlen( fileName );
- sizeAPN = (sizeDN + 1 + sizeFN + 1);
-
- /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */
- if ( sizeAPN > _MAX_PATH )
- {
- return ( 0 );
- }
-
- strncpy(absPathName, dirName, dwDirLength +1);
- strncpy(absPathName, szPathDelimA, 2);
- strncpy(absPathName, fileName, dwFileLength +1);
-
- return (sizeAPN);
-
-}
-
-int __cdecl main( int argc, char **argv )
-
-{
-
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
-
- static FILE * fp;
-
- DWORD dwFileLength;
- DWORD dwDirLength;
- DWORD dwSize;
-
- size_t cslen;
-
- char szReadStringA[256];
-
- char szDirNameA[_MAX_DIR];
- char absPathBuf[_MAX_PATH];
- char *szAbsPathNameA;
-
-
- if(0 != (PAL_Initialize(argc, argv)))
- {
- return ( FAIL );
- }
-
- ZeroMemory ( &si, sizeof(si) );
- si.cb = sizeof(si);
- ZeroMemory ( &pi, sizeof(pi) );
-
- szAbsPathNameA=&absPathBuf[0];
- dwFileLength = strlen( szChildFileA );
-
- dwDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameA);
-
- if (0 == dwDirLength)
- {
- Fail ("GetCurrentDirectory call failed. Could not get "
- "current working directory\n. Exiting.\n");
- }
-
- dwSize = mkAbsoluteFilenameA( szDirNameA, dwDirLength, szChildFileA,
- dwFileLength, szAbsPathNameA );
-
- if (0 == dwSize)
- {
- Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could "
- "not build absolute path name to file\n. Exiting.\n");
- }
-
- if ( !CreateProcessA ( NULL,
- szAbsPathNameA,
- NULL,
- NULL,
- FALSE,
- CREATE_NEW_CONSOLE,
- NULL,
- NULL,
- &si,
- &pi )
- )
- {
- Fail ( "CreateProcess call failed. GetLastError returned %d\n",
- GetLastError() );
- }
-
- WaitForSingleObject ( pi.hProcess, INFINITE );
-
- szAbsPathNameA=&absPathBuf[0];
-
- dwFileLength = strlen( szCommonFileA );
-
- dwSize = mkAbsoluteFilenameA( szDirNameA, dwDirLength, szCommonFileA,
- dwFileLength, szAbsPathNameA );
-
- /* set the string length for the open call*/
-
- if (0 == dwSize)
- {
- Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could "
- "not build absolute path name to file\n. Exiting.\n");
- }
-
- if ( NULL == ( fp = fopen ( szAbsPathNameA , "r" ) ) )
- {
- Fail ("%s\nunable to open %s\nfor reading. Exiting.\n", argv[0],
- szAbsPathNameA );
- }
-
- cslen = strlen ( szCommonStringA );
-
- if ( NULL == fgets( szReadStringA, (cslen + 1), fp ))
- {
- /*
- * A return value of NULL indicates an error condition or an
- * EOF condition
- */
- Fail ("%s\nunable to read file\n%s\nszReadStringA is %s\n"
- "Exiting.\n", argv[0], szAbsPathNameA,
- szReadStringA );
-
- }
- if ( 0 != strncmp( szReadStringA, szCommonStringA, cslen ))
- {
- Fail ("string comparison failed.\n szReadStringA is %s and\n"
- "szCommonStringA is %s\n", szReadStringA,
- szCommonStringA );
- }
- else
- {
- Trace ("string comparison passed.\n");
- }
-
- if (0 != (fclose ( fp )))
- {
- Trace ("%s unable to close file %s. This may cause a file pointer "
- "leak. Continuing.\n", argv[0], szAbsPathNameA );
- }
-
- /* Close process and thread handle */
- CloseHandle ( pi.hProcess );
- CloseHandle ( pi.hThread );
-
- PAL_Terminate();
- return ( PASS );
-
-}
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = threading
-Function = CreateProcessA
-Name = Positive Test for CreateProcessA
-TYPE = DEFAULT
-EXE1 = parentprocess
-EXE2 = childprocess
-Description
-= Test the CreateProcessA function. The test executes the childprocess
-= program. The childprocess program launches and writes a const char string
-= to a file childdata. The parent waits for the completion of childprocess
-= and then reads the string from the childdata file. If the string in the
-= file matches it's copy of the const char string, then the test succeeds.
+++ /dev/null
-set(TESTSOURCES
- parentprocess.cpp
-)
-
-add_executable(paltest_createprocessa_test2
- ${TESTSOURCES}
-)
-
-add_dependencies(paltest_createprocessa_test2 coreclrpal)
-
-target_link_libraries(paltest_createprocessa_test2
- ${COMMON_TEST_LIBRARIES}
-)
-
-
-set(HELPERSOURCES
- childprocess.cpp
-)
-
-add_executable(paltest_createprocessa_test2_child
- ${HELPERSOURCES}
-)
-
-add_dependencies(paltest_createprocessa_test2_child coreclrpal)
-
-target_link_libraries(paltest_createprocessa_test2_child
- ${COMMON_TEST_LIBRARIES}
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*============================================================
-**
-** Source: createprocessa/test2/childprocess.c
-**
-** Purpose: This child process reads a string from stdin
-** and writes it out to stdout & stderr
-**
-** Dependencies: memset
-** fgets
-** gputs
-**
-
-**
-**=========================================================*/
-
-#include <palsuite.h>
-#include "test2.h"
-
-
-
-int __cdecl main( int argc, char **argv )
-{
- int iRetCode = EXIT_OK_CODE; /* preset exit code to OK */
- char szBuf[BUF_LEN];
-
-
- if(0 != (PAL_Initialize(argc, argv)))
- {
- return FAIL;
- }
-
- if (argc != 4)
- {
- return EXIT_ERR_CODE3;
- }
-
- if (strcmp(argv[1], szArg1) != 0
- || strcmp(argv[2], szArg2) != 0
- || strcmp(argv[3], szArg3) != 0)
- {
- return EXIT_ERR_CODE4;
- }
-
-
- memset(szBuf, 0, BUF_LEN);
-
- /* Read the string that was written by the parent */
- if (fgets(szBuf, BUF_LEN, stdin) == NULL)
- {
- return EXIT_ERR_CODE1;
- }
-
- /* Write the string out to the stdout & stderr pipes */
- if (fputs(szBuf, stdout) == EOF
- || fputs(szBuf, stderr) == EOF)
- {
- return EXIT_ERR_CODE2;
- }
-
- /* The exit code will indicate success or failure */
- PAL_TerminateEx(iRetCode);
-
- /* Return special exit code to indicate success or failure */
- return iRetCode;
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*============================================================
-**
-** Source: createprocessa/test2/parentprocess.c
-**
-** Purpose: Test the following features of CreateProcessA:
-** - Check to see if hProcess & hThread are set in
-** return PROCESS_INFORMATION structure
-** - Check to see if stdin, stdout, & stderr handles
-** are used when STARTF_USESTDHANDLES is specified
-** in STARUPINFO flags and bInheritHandles = TRUE
-** - Check to see that proper arguments are passed to
-** child process
-**
-** Dependencies: CreatePipe
-** strcpy, strlen, strncmp, memset
-** WaitForSingleObject
-** WriteFile, ReadFile
-** GetExitCodeProcess
-**
-
-**
-**=========================================================*/
-
-#include <palsuite.h>
-#include "test2.h"
-
-
-
-int __cdecl main( int argc, char **argv )
-{
-
- /*******************************************
- * Declarations
- *******************************************/
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
-
- HANDLE hTestStdInR = NULL;
- HANDLE hTestStdInW = NULL;
- HANDLE hTestStdOutR = NULL;
- HANDLE hTestStdOutW = NULL;
- HANDLE hTestStdErrR = NULL;
- HANDLE hTestStdErrW = NULL;
-
- BOOL bRetVal = FALSE;
- DWORD dwBytesWritten = 0;
- DWORD dwBytesRead = 0;
- DWORD dwExitCode = 0;
-
- SECURITY_ATTRIBUTES pipeAttributes;
-
- char szStdOutBuf[BUF_LEN];
- char szStdErrBuf[BUF_LEN];
- char szFullPathNameA[_MAX_PATH];
-
-
- /*******************************************
- * Initialization
- *******************************************/
-
- if(0 != (PAL_Initialize(argc, argv)))
- {
- return ( FAIL );
- }
-
- /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/
- pipeAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
- pipeAttributes.lpSecurityDescriptor = NULL;
- pipeAttributes.bInheritHandle = TRUE;
-
-
- /*Create a StdIn pipe for child*/
- bRetVal = CreatePipe(&hTestStdInR, /* read handle*/
- &hTestStdInW, /* write handle */
- &pipeAttributes, /* security attributes*/
- 1024); /* pipe size*/
-
- if (bRetVal == FALSE)
- {
- Fail("ERROR: %ld :Unable to create stdin pipe\n", GetLastError());
- }
-
-
- /*Create a StdOut pipe for child*/
- bRetVal = CreatePipe(&hTestStdOutR, /* read handle*/
- &hTestStdOutW, /* write handle */
- &pipeAttributes, /* security attributes*/
- 0); /* pipe size*/
-
- if (bRetVal == FALSE)
- {
- Fail("ERROR: %ld :Unable to create stdout pipe\n", GetLastError());
- }
-
-
- /*Create a StdErr pipe for child*/
- bRetVal = CreatePipe(&hTestStdErrR, /* read handle*/
- &hTestStdErrW, /* write handle */
- &pipeAttributes, /* security attributes*/
- 0); /* pipe size*/
-
- if (bRetVal == FALSE)
- {
- Fail("ERROR: %ld :Unable to create stderr pipe\n", GetLastError());
- }
-
- /* Zero the data structure space */
- ZeroMemory ( &pi, sizeof(pi) );
- ZeroMemory ( &si, sizeof(si) );
-
- /* Set the process flags and standard io handles */
- si.cb = sizeof(si);
- si.dwFlags = STARTF_USESTDHANDLES;
- si.hStdInput = hTestStdInR;
- si.hStdOutput = hTestStdOutW;
- si.hStdError = hTestStdErrW;
-
- strcpy(szFullPathNameA, szChildFileA);
- strcat(szFullPathNameA, szArgs);
-
- /*******************************************
- * Start Testing
- *******************************************/
-
- /* Launch the child */
- if ( !CreateProcessA (NULL, szFullPathNameA, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi ))
- {
- Fail("ERROR: CreateProcess call failed. GetLastError returned %d\n",
- GetLastError() );
- }
-
- /* Check the returned process information for validity */
- if (pi.hProcess == 0 || pi.hThread == 0)
- {
- Fail("ERROR: CreateProcess Error: Process Handle = %u, Thread Handle = %u\n",
- pi.hProcess, pi.hThread);
- }
-
- /* Write the Constructed string to stdin pipe for the child process */
- if (WriteFile(hTestStdInW, szTestString, strlen(szTestString), &dwBytesWritten, NULL) == FALSE
- || WriteFile(hTestStdInW, "\n", strlen("\n"), &dwBytesWritten, NULL) == FALSE)
- {
- Fail("ERROR: %ld :unable to write to write pipe handle "
- "hTestStdInW=0x%lx\n", GetLastError(), hTestStdInW);
- }
-
- /* Wait for the child to finish, Max 20 seconds */
- dwExitCode = WaitForSingleObject(pi.hProcess, 20000);
-
- /* If the child failed then whole thing fails */
- if (dwExitCode != WAIT_OBJECT_0)
- {
- TerminateProcess(pi.hProcess, 0);
- Fail("ERROR: The child failed to run properly.\n");
- }
-
- /* Check for problems in the child process */
- if (GetExitCodeProcess(pi.hProcess, &dwExitCode) == FALSE)
- {
- Fail("ERROR: Call to GetExitCodeProcess failed.\n");
- }
- else if (dwExitCode == EXIT_ERR_CODE1)
- {
- Fail("ERROR: The Child process could not reead the string "
- "written to the stdin pipe.\n");
- }
- else if (dwExitCode == EXIT_ERR_CODE2)
- {
- Fail("ERROR: The Child process could not write the string "
- "the stdout pipe or stderr pipe.\n");
- }
- else if (dwExitCode == EXIT_ERR_CODE3)
- {
- Fail("ERROR: The Child received the wrong number of "
- "command line arguments.\n");
- }
- else if (dwExitCode == EXIT_ERR_CODE4)
- {
- Fail("ERROR: The Child received the wrong "
- "command line arguments.\n");
- }
- else if (dwExitCode != EXIT_OK_CODE)
- {
- Fail("ERROR: Unexpected exit code returned: %u. Child process "
- "did not complete its part of the test.\n", dwExitCode);
- }
-
-
- /* The child ran ok, so check to see if we received the proper */
- /* strings through the pipes. */
-
- /* clear our buffers */
- memset(szStdOutBuf, 0, BUF_LEN);
- memset(szStdErrBuf, 0, BUF_LEN);
-
- /* Read the data back from the child process stdout */
- bRetVal = ReadFile(hTestStdOutR, /* handle to read pipe*/
- szStdOutBuf, /* buffer to write to*/
- BUF_LEN, /* number of bytes to read*/
- &dwBytesRead, /* number of bytes read*/
- NULL); /* overlapped buffer*/
-
- /*Read the data back from the child process stderr */
- bRetVal = ReadFile(hTestStdErrR, /* handle to read pipe*/
- szStdErrBuf, /* buffer to write to*/
- BUF_LEN, /* number of bytes to read*/
- &dwBytesRead, /* number of bytes read*/
- NULL); /* overlapped buffer*/
-
-
- /* Confirm that we recieved the same string that we originally */
- /* wrote to the child and was received on both stdout & stderr.*/
- if (strncmp(szTestString, szStdOutBuf, strlen(szTestString)) != 0
- || strncmp(szTestString, szStdErrBuf, strlen(szTestString)) != 0)
- {
- Fail("ERROR: The data read back from child does not match "
- "what was written. STDOUT: %s STDERR: %s\n",
- szStdOutBuf, szStdErrBuf);
- }
-
-
- /*******************************************
- * Clean Up
- *******************************************/
-
- /* Close process and thread handle */
- CloseHandle ( pi.hProcess );
- CloseHandle ( pi.hThread );
-
- CloseHandle(hTestStdInR);
- CloseHandle(hTestStdInW);
- CloseHandle(hTestStdOutR);
- CloseHandle(hTestStdOutW);
- CloseHandle(hTestStdErrR);
- CloseHandle(hTestStdErrW);
-
- PAL_Terminate();
- return ( PASS );
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*============================================================
-**
-** Source: test2.h
-**
-
-**
-**===========================================================*/
-
-
-const char *szChildFileA = "paltest_createprocessa_test2_child";
-const char *szArgs = " A B C";
-const char *szArg1 = "A";
-const char *szArg2 = "B";
-const char *szArg3 = "C";
-
-const char *szPathDelimA = "\\";
-
-const char *szTestString = "Copyright (c) Microsoft";
-
-const DWORD EXIT_OK_CODE = 100;
-const DWORD EXIT_ERR_CODE1 = 101;
-const DWORD EXIT_ERR_CODE2 = 102;
-const DWORD EXIT_ERR_CODE3 = 103;
-const DWORD EXIT_ERR_CODE4 = 104;
-const DWORD EXIT_ERR_CODE5 = 105;
-
-#define BUF_LEN 64
-
-/*
- * Take two wide strings representing file and directory names
- * (dirName, fileName), join the strings with the appropriate path
- * delimiter and populate a wide character buffer (absPathName) with
- * the resulting string.
- *
- * Returns: The number of wide characters in the resulting string.
- * 0 is returned on Error.
- */
-int
-mkAbsoluteFilenameA (
- LPSTR dirName,
- DWORD dwDirLength,
- LPCSTR fileName,
- DWORD dwFileLength,
- LPSTR absPathName )
-{
- extern const char *szPathDelimA;
-
- DWORD sizeDN;
- DWORD sizeFN;
- DWORD sizeAPN;
-
- sizeDN = strlen( dirName );
- sizeFN = strlen( fileName );
- sizeAPN = (sizeDN + 1 + sizeFN + 1);
-
- /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */
- if ( sizeAPN > _MAX_PATH )
- {
- return ( 0 );
- }
-
- strncpy(absPathName, dirName, dwDirLength +1);
- strcat(absPathName, szPathDelimA);
- strcat(absPathName, fileName);
-
- return (sizeAPN);
-
-}
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-
-Version = 1.0
-Section = threading
-Function = CreateProcessA
-Name = PROCESS_INFORMATION and HANDLE Inheritance
-TYPE = DEFAULT
-EXE1 = parentprocess
-EXE2 = childprocess
-Description
-= Test the following features of CreateProcessA:
-= - Check to see if hProcess & hThread are set in
-= return PROCESS_INFORMATION structure
-= - Check to see if stdin, stdout, & stderr handles
-= are used when STARTF_USESTDHANDLES is specified
-= in STARUPINFO flags and bInheritHandles = TRUE
-= - Check to see that proper arguments are passed to
-= child process
"not build absolute path name to file\n. Exiting.\n" );
}
+ LPWSTR rgchAbsPathNameW = convert(rgchAbsPathName);
/* launch the child process */
if( !CreateProcess( NULL, /* module name to execute */
- rgchAbsPathName, /* command line */
+ rgchAbsPathNameW, /* command line */
NULL, /* process handle not */
/* inheritable */
NULL, /* thread handle not */
)
{
dwError = GetLastError();
+ free(rgchAbsPathNameW);
if( ReleaseMutex( hMutex ) == 0 )
{
Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() );
dwError );
}
+ free(rgchAbsPathNameW);
+
/* open another handle to the child process */
hChildProcess = OpenProcess( PROCESS_ALL_ACCESS, /* access */
FALSE, /* inheritable */
** Purpose: Test to ensure ExitThread() called from the last thread of
** a process shuts down that process and returns the proper
** exit code as specified in the ExitThread() call.
-**
+**
** Dependencies: PAL_Initialize
** PAL_Terminate
** Fail
** GetLastError
** strlen
** strncpy
-**
+**
**
**===========================================================================*/
static const char* rgchPathDelim = "\\";
-int
-mkAbsoluteFilename( LPSTR dirName,
- DWORD dwDirLength,
- LPCSTR fileName,
+int
+mkAbsoluteFilename( LPSTR dirName,
+ DWORD dwDirLength,
+ LPCSTR fileName,
DWORD dwFileLength,
LPSTR absPathName )
{
{
return ( 0 );
}
-
+
strncpy( absPathName, dirName, dwDirLength +1 );
strncpy( absPathName, rgchPathDelim, 2 );
strncpy( absPathName, fileName, dwFileLength +1 );
return (sizeAPN);
-
-}
+
+}
-int __cdecl main( int argc, char **argv )
+int __cdecl main( int argc, char **argv )
{
const char* rgchChildFile = "childprocess";
-
+
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD dwDirLength;
DWORD dwSize;
DWORD dwExpected = TEST_EXIT_CODE;
-
- char rgchDirName[_MAX_DIR];
+
+ char rgchDirName[_MAX_DIR];
char absPathBuf[_MAX_PATH];
char* rgchAbsPathName;
{
return( FAIL );
}
-
+
/* zero our process and startup info structures */
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof( si );
ZeroMemory( &pi, sizeof(pi) );
-
+
/* build the absolute path to the child process */
rgchAbsPathName = &absPathBuf[0];
dwFileLength = strlen( rgchChildFile );
-
+
dwDirLength = GetCurrentDirectory( _MAX_PATH, rgchDirName );
- if( dwDirLength == 0 )
+ if( dwDirLength == 0 )
{
dwError = GetLastError();
- Fail( "GetCurrentDirectory call failed with error code %d\n",
- dwError );
+ Fail( "GetCurrentDirectory call failed with error code %d\n",
+ dwError );
}
dwSize = mkAbsoluteFilename( rgchDirName,
dwDirLength,
- rgchChildFile,
+ rgchChildFile,
dwFileLength,
rgchAbsPathName );
if( dwSize == 0 )
{
- Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ",
- "not build absolute path name to file\n. Exiting.\n" );
+ Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ",
+ "not build absolute path name to file\n. Exiting.\n" );
}
+ LPWSTR rgchAbsPathNameW = convert(rgchAbsPathName);
/* launch the child process */
if( !CreateProcess( NULL, /* module name to execute */
- rgchAbsPathName, /* command line */
+ rgchAbsPathNameW, /* command line */
NULL, /* process handle not */
/* inheritable */
NULL, /* thread handle not */
)
{
dwError = GetLastError();
- Fail( "CreateProcess call failed with error code %d\n",
- dwError );
+ free(rgchAbsPathNameW);
+ Fail( "CreateProcess call failed with error code %d\n",
+ dwError );
}
-
+
+ free(rgchAbsPathNameW);
+
/* wait for the child process to complete */
WaitForSingleObject ( pi.hProcess, INFINITE );
dwError = GetLastError();
CloseHandle ( pi.hProcess );
CloseHandle ( pi.hThread );
- Fail( "GetExitCodeProcess call failed with error code %d\n",
- dwError );
+ Fail( "GetExitCodeProcess call failed with error code %d\n",
+ dwError );
}
-
+
/* close process and thread handle */
CloseHandle ( pi.hProcess );
CloseHandle ( pi.hThread );
-
+
/* check for the expected exit code */
/* exit code for some systems is as small as a char, so that's all */
/* we'll compare for checking success */
if( LOBYTE(LOWORD(dwExitCode)) != LOBYTE(LOWORD(dwExpected)) )
{
Fail( "GetExitCodeProcess returned an incorrect exit code %d, "
- "expected value is %d\n",
- LOWORD(dwExitCode), dwExpected );
+ "expected value is %d\n",
+ LOWORD(dwExitCode), dwExpected );
}
/* terminate the PAL */
PAL_Terminate();
-
+
/* return success */
- return PASS;
+ return PASS;
}
** Source: test1.c
**
** Purpose: Test to ensure GetExitCodeProcess works properly.
-**
+**
** Dependencies: PAL_Initialize
** PAL_Terminate
** Fail
** GetLastError
** strlen
** strncpy
-**
+**
**
**===========================================================================*/
static const char* rgchPathDelim = "\\";
-int
-mkAbsoluteFilename( LPSTR dirName,
- DWORD dwDirLength,
- LPCSTR fileName,
+int
+mkAbsoluteFilename( LPSTR dirName,
+ DWORD dwDirLength,
+ LPCSTR fileName,
DWORD dwFileLength,
LPSTR absPathName )
{
{
return ( 0 );
}
-
+
strncpy( absPathName, dirName, dwDirLength +1 );
strncpy( absPathName, rgchPathDelim, 2 );
strncpy( absPathName, fileName, dwFileLength +1 );
return (sizeAPN);
-
-}
+
+}
-int __cdecl main( int argc, char **argv )
+int __cdecl main( int argc, char **argv )
{
const char* rgchChildFile = "childprocess";
-
+
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD dwFileLength;
DWORD dwDirLength;
DWORD dwSize;
-
- char rgchDirName[_MAX_DIR];
+
+ char rgchDirName[_MAX_DIR];
char absPathBuf[_MAX_PATH];
char* rgchAbsPathName;
{
return( FAIL );
}
-
+
/* zero our process and startup info structures */
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof( si );
ZeroMemory( &pi, sizeof(pi) );
-
+
/* build the absolute path to the child process */
rgchAbsPathName = &absPathBuf[0];
dwFileLength = strlen( rgchChildFile );
-
+
dwDirLength = GetCurrentDirectory( _MAX_PATH, rgchDirName );
- if( dwDirLength == 0 )
+ if( dwDirLength == 0 )
{
dwError = GetLastError();
- Fail( "GetCurrentDirectory call failed with error code %d\n",
- dwError );
+ Fail( "GetCurrentDirectory call failed with error code %d\n",
+ dwError );
}
dwSize = mkAbsoluteFilename( rgchDirName,
dwDirLength,
- rgchChildFile,
+ rgchChildFile,
dwFileLength,
rgchAbsPathName );
if( dwSize == 0 )
{
- Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ",
- "not build absolute path name to file\n. Exiting.\n" );
+ Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ",
+ "not build absolute path name to file\n. Exiting.\n" );
}
+ LPWSTR rgchAbsPathNameW = convert(rgchAbsPathName);
/* launch the child process */
if( !CreateProcess( NULL, /* module name to execute */
- rgchAbsPathName, /* command line */
+ rgchAbsPathNameW, /* command line */
NULL, /* process handle not */
/* inheritable */
NULL, /* thread handle not */
)
{
dwError = GetLastError();
- Fail( "CreateProcess call failed with error code %d\n",
- dwError );
+ free(rgchAbsPathNameW);
+ Fail( "CreateProcess call failed with error code %d\n",
+ dwError );
}
-
+
+ free(rgchAbsPathNameW);
+
/* wait for the child process to complete */
WaitForSingleObject ( pi.hProcess, INFINITE );
dwError = GetLastError();
CloseHandle ( pi.hProcess );
CloseHandle ( pi.hThread );
- Fail( "GetExitCodeProcess call failed with error code %d\n",
- dwError );
+ Fail( "GetExitCodeProcess call failed with error code %d\n",
+ dwError );
}
-
+
/* close process and thread handle */
CloseHandle ( pi.hProcess );
CloseHandle ( pi.hThread );
-
+
/* check for the expected exit code */
if( dwExitCode != TEST_EXIT_CODE )
{
Fail( "GetExitCodeProcess returned an incorrect exit code %d, "
- "expected value is %d\n",
- dwExitCode, TEST_EXIT_CODE );
+ "expected value is %d\n",
+ dwExitCode, TEST_EXIT_CODE );
}
/* terminate the PAL */
PAL_Terminate();
-
+
/* return success */
- return PASS;
+ return PASS;
}
void TestCreateMutex(AutoCloseMutexHandle &m, const char *name, bool initiallyOwned = false)
{
m.Close();
- m = CreateMutex(nullptr, initiallyOwned, convert(name));
+ LPWSTR nameW = convert(name);
+ m = CreateMutex(nullptr, initiallyOwned, nameW);
+ free(nameW);
}
HANDLE TestOpenMutex(const char *name)
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
memset(&pi, 0, sizeof(pi));
- if (!CreateProcessA(nullptr, g_processCommandLinePath, nullptr, nullptr, false, 0, nullptr, nullptr, &si, &pi))
+ LPWSTR nameW = convert(g_processCommandLinePath);
+ if (!CreateProcessW(nullptr, nameW, nullptr, nullptr, false, 0, nullptr, nullptr, &si, &pi))
{
+ free(nameW);
return false;
}
+
+ free(nameW);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return true;
Fail ("Error: Insufficient lpCommandline for\n");
}
+ LPWSTR lpCommandLineW = convert(lpCommandLine);
/* launch the child process */
if( !CreateProcess( NULL, /* module name to execute */
- lpCommandLine, /* command line */
+ lpCommandLineW, /* command line */
NULL, /* process handle not */
/* inheritable */
NULL, /* thread handle not */
&pi ) /* process info struct */
)
{
+ DWORD dwError = GetLastError();
+ free(lpCommandLineW);
Fail( "ERROR:%lu:CreateProcess call failed\n",
- GetLastError() );
+ dwError);
}
+ free(lpCommandLineW);
+
/* verify that the event is signalled by the child process */
dwRet = WaitForSingleObject( hEvent, TIMEOUT );
if( dwRet != WAIT_OBJECT_0 )
"not build absolute path name to file\n. Exiting.\n" );
}
+ LPWSTR rgchAbsPathNameW = convert(rgchAbsPathName);
/* launch the child process */
if( !CreateProcess( NULL, /* module name to execute */
- rgchAbsPathName, /* command line */
+ rgchAbsPathNameW, /* command line */
NULL, /* process handle not */
/* inheritable */
NULL, /* thread handle not */
)
{
dwError = GetLastError();
+ free(rgchAbsPathNameW);
if( ReleaseMutex( hMutex ) == 0 )
{
Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() );
dwError );
}
+ free(rgchAbsPathNameW);
+
/* open another handle to the child process */
hChildProcess = OpenProcess( PROCESS_ALL_ACCESS, /* access */
FALSE, /* inheritable */
sprintf_s (szCmd, 128, "child6 -event %s", szTestName);
szCmd[127] = 0;
- bRet = CreateProcessA(NULL, szCmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
+ LPWSTR szCmdW = convert(szCmd);
+ bRet = CreateProcessW(NULL, szCmdW, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
+ free(szCmdW);
if (FALSE == bRet)
{
- Fail("CreateProcess failed [GetLastError()=%u]\n",
+ Fail("CreateProcessW failed [GetLastError()=%u]\n",
GetLastError());
}
sprintf_s (szCmd, 128, "child6 -semaphore %s", szTestName);
szCmd[127] = 0;
- bRet = CreateProcessA(NULL, szCmd, NULL, NULL, FALSE,
+ LPWSTR szCmdW = convert(szCmd);
+ bRet = CreateProcessW(NULL, szCmdW, NULL, NULL, FALSE,
0, NULL, NULL, &si, &pi);
+ free(szCmdW);
if (FALSE == bRet)
{
- Fail("CreateProcessA failed [GetLastError()=%u]\n",
+ Fail("CreateProcessW failed [GetLastError()=%u]\n",
GetLastError());
}
+
Trace("Setting event %s\n", szEventName);
bRet = SetEvent(hNamedEvent);
if (FALSE == bRet)
sprintf_s (szCmd, 128, "child6 -mutex %s -exitcode %d", szTestName, iDesiredExitCode);
szCmd[127] = 0;
- bRet = CreateProcessA(NULL, szCmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
+ LPWSTR szCmdW = convert(szCmd);
+ bRet = CreateProcessW(NULL, szCmdW, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
+ free(szCmdW);
if (FALSE == bRet)
{
- Fail("CreateProcess failed [GetLastError()=%u]\n",
+ Fail("CreateProcessW failed [GetLastError()=%u]\n",
GetLastError());
}
sprintf_s (szCmd, 128, "child6 -mutex_and_named_event %s", szTestName);
szCmd[127] = 0;
- bRet = CreateProcessA(NULL, szCmd, NULL, NULL, FALSE,
+ LPWSTR szCmdW = convert(szCmd);
+ bRet = CreateProcessW(NULL, szCmdW, NULL, NULL, FALSE,
0, NULL, NULL, &si, &pi);
+ free(szCmdW);
if (FALSE == bRet)
{
- Fail("CreateProcess failed [GetLastError()=%u]\n",
+ Fail("CreateProcessW failed [GetLastError()=%u]\n",
GetLastError());
}
/*============================================================
**
-** Source: WFSOProcessTest.c
+** Source: WFSOProcessTest.c
**
-** Purpose: Test for WaitForSingleObjectTest.
+** Purpose: Test for WaitForSingleObjectTest.
** Create One Process and do some work
-** Use WFSO For the Process to finish
-**
+** Use WFSO For the Process to finish
+**
** Test Passes if the above operations are successful
-**
+**
**
**
**=========================================================*/
STARTUPINFO si;
PROCESS_INFORMATION pi;
-DWORD dwWaitResult=0;
+DWORD dwWaitResult=0;
-//Initialize PAL
+//Initialize PAL
if(0 != (PAL_Initialize(argc, argv)))
{
return ( FAIL );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
-// Start the child process.
-if( !CreateProcess( NULL, // No module name (use command line).
- "childprocess", // Command line.
- NULL, // Process handle not inheritable.
- NULL, // Thread handle not inheritable.
- FALSE, // Set handle inheritance to FALSE.
- 0, // No creation flags.
- NULL, // Use parent's environment block.
- NULL, // Use parent's starting directory.
+LPWSTR nameW = convert("childprocess");
+// Start the child process.
+if( !CreateProcess( NULL, // No module name (use command line).
+ nameW, // Command line.
+ NULL, // Process handle not inheritable.
+ NULL, // Thread handle not inheritable.
+ FALSE, // Set handle inheritance to FALSE.
+ 0, // No creation flags.
+ NULL, // Use parent's environment block.
+ NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
-)
+)
{
+DWORD dwError = GetLastError();
+free(nameW);
Fail ( "Create Process Failed. Failing test.\n"
- "GetLastError returned %d\n", GetLastError());
+ "GetLastError returned %d\n", GetLastError());
}
+free(nameW);
+
// Wait until child process exits.
dwWaitResult = WaitForSingleObject( pi.hProcess, INFINITE );
-switch (dwWaitResult)
+switch (dwWaitResult)
{
// The Process wait was successful
- case WAIT_OBJECT_0:
+ case WAIT_OBJECT_0:
{
Trace("Wait for Process was successful\n");
- break;
- }
+ break;
+ }
// Time-out.
- case WAIT_TIMEOUT:
+ case WAIT_TIMEOUT:
{
Fail ( "Time -out. Failing test.\n"
- "GetLastError returned %d\n", GetLastError());
+ "GetLastError returned %d\n", GetLastError());
return FALSE;
}
// Got ownership of the abandoned process object.
- case WAIT_ABANDONED:
+ case WAIT_ABANDONED:
{
Fail ( "Got ownership of the abandoned Process object. Failing test.\n"
- "GetLastError returned %d\n", GetLastError());
- return FALSE;
+ "GetLastError returned %d\n", GetLastError());
+ return FALSE;
}
//Error condition
case WAIT_FAILED:
{
Fail ( "Wait for Process Failed. Failing test.\n"
- "GetLastError returned %d\n", GetLastError());
- return FALSE;
+ "GetLastError returned %d\n", GetLastError());
+ return FALSE;
}
}
// Close process handle
if (0==CloseHandle(pi.hProcess))
{
- Trace("Could not close process handle\n");
- Fail ( "GetLastError returned %d\n", GetLastError());
+ Trace("Could not close process handle\n");
+ Fail ( "GetLastError returned %d\n", GetLastError());
}
}
_ASSERTE(dwHighSize == 0);
- hMapFile = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
+ hMapFile = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
CloseHandle(hFile);
if (!hMapFile)
- MDInfo::Error("CreateFileMappingA failed!");
+ MDInfo::Error("CreateFileMappingW failed!");
*ppbMap = (PBYTE) MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);
CloseHandle(hMapFile);
#ifndef CROSSGEN_COMPILE
// Cross-process named objects are not supported in PAL
- // (see CorUnix::InternalCreateEvent - src/pal/src/synchobj/event.cpp.272)
+ // (see CorUnix::InternalCreateEvent - src/pal/src/synchobj/event.cpp)
#if !defined(TARGET_UNIX)
// Initialize the sweeper thread.
if (g_pConfig->GetZapBBInstr() != NULL)
#ifndef CROSSGEN_COMPILE
InitializeGarbageCollector();
-
+
if (!GCHandleUtilities::GetGCHandleManager()->Initialize())
{
IfFailGo(E_OUTOFMEMORY);
[DllImport(Interop.Libraries.Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
internal static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, int dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, IntPtr dwNumberOfBytesToMap);
- // OpenFileMappingA contains a security venerability, in the unicode->ansi conversion
- // Its possible to spoof the directory and construct ../ sequeences, See FxCop Warrning
- // Specify marshaling for pinvoke string arguments
- [DllImport(Interop.Libraries.Kernel32, CharSet = System.Runtime.InteropServices.CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
- // [DllImport(Interop.Libraries.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Ansi)]
- internal static extern IntPtr OpenFileMappingA(int dwDesiredAccess, bool bInheritHandle, [MarshalAs(UnmanagedType.LPStr)] string lpName);
-
- // CreateFileMappingA contains a security venerability, in the unicode->ansi conversion
- // Its possible to spoof the directory and construct ../ sequeences, See FxCop Warrning
- // Specify marshaling for pinvoke string arguments
- [DllImport(Interop.Libraries.Kernel32, CharSet = System.Runtime.InteropServices.CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
- // [DllImport(Interop.Libraries.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Ansi)]
- internal static extern IntPtr CreateFileMappingA(IntPtr hFile, IntPtr pAttr, int flProtect, int dwMaximumSizeHigh, int dwMaximumSizeLow, [MarshalAs(UnmanagedType.LPStr)] string lpName);
-
[DllImport(Interop.Libraries.Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
internal static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);