Skip to content

Commit

Permalink
Return error upon attemping to create named objects in PAL.
Browse files Browse the repository at this point in the history
Update PAL APIs that create named objects (mutex, semaphore, event, file mapping) to return a not-supported error code. It was decided to not support cross-process synchronization in PAL at present time due to complexities involved in reliably emulating Windows' behavior. @stephentoub has already made changes on the FX side to throw PlatformNotSupportedException in these cases.

Related to issue #1237.
  • Loading branch information
kouvel committed Aug 27, 2015
1 parent b7d38a0 commit 9684675
Show file tree
Hide file tree
Showing 27 changed files with 168 additions and 425 deletions.
11 changes: 3 additions & 8 deletions src/md/enc/stgio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ void StgIO::CtorInit()
m_cbBuff = 0;
m_rgPageMap = 0;
m_FileType = FILETYPE_UNKNOWN;
*m_rcShared = '\0';
m_cRef = 1;
m_mtMappedType = MTYPE_NOMAPPING;
}
Expand Down Expand Up @@ -787,10 +786,8 @@ HRESULT StgIO::MapFileToMem( // Return code.
// Check the size of the data we want to map. If it is small enough, then
// simply allocate a chunk of memory from a finer grained heap. This saves
// virtual memory space, page table entries, and should reduce overall working set.
// Note that any shared memory objects will require the handles to be in place
// and are not elligible. Also, open for read/write needs a full backing
// store.
if (!*m_rcShared && (m_cbData <= SMALL_ALLOC_MAP_SIZE) && (SMALL_ALLOC_MAP_SIZE > 0))
// Also, open for read/write needs a full backing store.
if ((m_cbData <= SMALL_ALLOC_MAP_SIZE) && (SMALL_ALLOC_MAP_SIZE > 0))
{
DWORD cbRead = m_cbData;
_ASSERTE(m_pData == 0);
Expand Down Expand Up @@ -854,8 +851,6 @@ HRESULT StgIO::MapFileToMem( // Return code.
// change for the life of the handle.
if ((m_fFlags & DBPROP_TMODEF_WRITE) == 0 && m_iType != STGIO_STREAM)
{
_ASSERTE(!*m_rcShared);

// Create a mapping object for the file.
_ASSERTE(m_hMapping == 0);

Expand All @@ -869,7 +864,7 @@ HRESULT StgIO::MapFileToMem( // Return code.
#endif

if ((m_hMapping = WszCreateFileMapping(m_hFile, pAttributes, dwProtectionFlags,
0, 0, *m_rcShared ? m_rcShared : 0)) == 0)
0, 0, nullptr)) == 0)
{
return (MapFileError(GetLastError()));
}
Expand Down
1 change: 0 additions & 1 deletion src/md/inc/stgio.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ class StgIO

// Flags and state data.
FILETYPE m_FileType; // Cached type of the file (based on extension).
WCHAR m_rcShared[MAXSHMEM]; // Name of shared memory segment.
LONG m_cRef; // Ref count on this object.
bool m_bWriteThrough : 1; // true for write through mode.
bool m_bRewrite : 1; // State check for rewrite mode.
Expand Down
97 changes: 23 additions & 74 deletions src/pal/src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ CreateFileMappingA(
IN LPCSTR lpName)
{
HANDLE hFileMapping = NULL;
WCHAR WideString[ MAX_PATH ];
CPalThread *pThread = NULL;
PAL_ERROR palError = NO_ERROR;

Expand All @@ -304,34 +303,10 @@ CreateFileMappingA(

pThread = InternalGetCurrentThread();

if ( lpName != NULL )
if (lpName != nullptr)
{
if ( 0 == MultiByteToWideChar(CP_ACP, 0, lpName, -1,
WideString, MAX_PATH ) )
{
palError = GetLastError();
if ( ERROR_INSUFFICIENT_BUFFER == palError )
{
ERROR("lpName is larger than MAX_PATH (%d)!\n", MAX_PATH);
}
else
{
ERROR("MultiByteToWideChar failure! (error=%d)\n",
palError);
}
goto ExitCreateFileMappingA;
}

palError = InternalCreateFileMapping(
pThread,
hFile,
lpFileMappingAttributes,
flProtect,
dwMaximumSizeHigh,
dwMaximumSizeLow,
WideString,
&hFileMapping
);
ASSERT("lpName: Cross-process named objects are not supported in PAL");
palError = ERROR_NOT_SUPPORTED;
}
else
{
Expand All @@ -348,8 +323,6 @@ CreateFileMappingA(
}


ExitCreateFileMappingA:

//
// We always need to set last error, even on success:
// we need to protect ourselves from the situation
Expand Down Expand Up @@ -452,6 +425,13 @@ CorUnix::InternalCreateFileMapping(
// Validate parameters
//

if (lpName != nullptr)
{
ASSERT("lpName: Cross-process named objects are not supported in PAL");
palError = ERROR_NOT_SUPPORTED;
goto ExitInternalCreateFileMapping;
}

if (0 != dwMaximumSizeHigh)
{
ASSERT("dwMaximumSizeHigh is always 0.\n");
Expand Down Expand Up @@ -823,7 +803,6 @@ OpenFileMappingA(
IN LPCSTR lpName)
{
HANDLE hFileMapping = NULL;
WCHAR WideString[ MAX_PATH ];
CPalThread *pThread = NULL;
PAL_ERROR palError = NO_ERROR;

Expand All @@ -833,40 +812,17 @@ OpenFileMappingA(

pThread = InternalGetCurrentThread();

if ( lpName != NULL )
if (lpName == nullptr)
{
if ( 0 == MultiByteToWideChar(CP_ACP, 0, lpName, -1,
WideString, MAX_PATH ) )
{
palError = GetLastError();
if ( ERROR_INSUFFICIENT_BUFFER == palError )
{
ERROR("lpName is larger than MAX_PATH (%d)!\n", MAX_PATH);
}
else
{
ERROR("MultiByteToWideChar failure! (error=%d)\n",
palError);
}
palError = ERROR_INVALID_PARAMETER;
goto ExitOpenFileMappingA;
}

palError = InternalOpenFileMapping(
pThread,
dwDesiredAccess,
bInheritHandle,
&WideString[0],
&hFileMapping
);
ERROR("name is NULL\n");
palError = ERROR_INVALID_PARAMETER;
}
else
{
ERROR("name is NULL\n");
palError = ERROR_INVALID_PARAMETER;
ASSERT("lpName: Cross-process named objects are not supported in PAL");
palError = ERROR_NOT_SUPPORTED;
}

ExitOpenFileMappingA:
if (NO_ERROR != palError)
{
pThread->SetLastError(palError);
Expand Down Expand Up @@ -901,29 +857,22 @@ OpenFileMappingW(
pThread = InternalGetCurrentThread();

/* validate parameters */
if (lpName == NULL)
if (lpName == nullptr)
{
ERROR("name is NULL\n");
pThread->SetLastError(ERROR_INVALID_PARAMETER);
goto ExitOpenFileMappingW;
palError = ERROR_INVALID_PARAMETER;
}
else
{
ASSERT("lpName: Cross-process named objects are not supported in PAL");
palError = ERROR_NOT_SUPPORTED;
}

palError = InternalOpenFileMapping(
pThread,
dwDesiredAccess,
bInheritHandle,
lpName,
&hFileMapping
);

if (NO_ERROR != palError)
{
pThread->SetLastError(palError);
}

ExitOpenFileMappingW:

LOGEXIT( "OpenFileMappingW returning %p.\n", hFileMapping );
LOGEXIT("OpenFileMappingW returning %p.\n", hFileMapping);
PERF_EXIT(OpenFileMappingW);
return hFileMapping;
}
Expand Down
50 changes: 17 additions & 33 deletions src/pal/src/synchobj/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ CreateEventA(
IN LPCSTR lpName)
{
HANDLE hEvent = NULL;
WCHAR pwName[c_cchMaxEvent];
CPalThread *pthr = NULL;
PAL_ERROR palError;

Expand All @@ -107,28 +106,10 @@ CreateEventA(

pthr = InternalGetCurrentThread();

if (lpName != NULL)
if (lpName != nullptr)
{
palError = InternalWszNameFromSzName(
pthr,
lpName,
pwName,
sizeof(pwName) / sizeof(pwName[0])
);

if (NO_ERROR != palError)
{
goto CreateEventAExit;
}

palError = InternalCreateEvent(
pthr,
lpEventAttributes,
bManualReset,
bInitialState,
pwName,
&hEvent
);
ASSERT("lpName: Cross-process named objects are not supported in PAL");
palError = ERROR_NOT_SUPPORTED;
}
else
{
Expand All @@ -142,8 +123,6 @@ CreateEventA(
);
}

CreateEventAExit:

//
// We always need to set last error, even on success:
// we need to protect ourselves from the situation
Expand Down Expand Up @@ -258,6 +237,13 @@ CorUnix::InternalCreateEvent(
phEvent
);

if (lpName != nullptr)
{
ASSERT("lpName: Cross-process named objects are not supported in PAL");
palError = ERROR_NOT_SUPPORTED;
goto InternalCreateEventExit;
}

palError = g_pObjectManager->AllocateObject(
pthr,
bManualReset ? &otManualResetEvent : &otAutoResetEvent,
Expand Down Expand Up @@ -471,6 +457,7 @@ CorUnix::InternalSetEvent(
return palError;
}

// TODO: Implementation of OpenEventA() doesn't exist, do we need it? More generally, do we need the A versions at all?

/*++
Function:
Expand Down Expand Up @@ -502,20 +489,17 @@ OpenEventW(
pthr = InternalGetCurrentThread();

/* validate parameters */
if (lpName == NULL)
if (lpName == nullptr)
{
ERROR("name is NULL\n");
palError = ERROR_INVALID_PARAMETER;
goto OpenEventWExit;
}

palError = InternalOpenEvent(
pthr,
dwDesiredAccess,
bInheritHandle,
lpName,
&hEvent
);
else
{
ASSERT("lpName: Cross-process named objects are not supported in PAL");
palError = ERROR_NOT_SUPPORTED;
}

OpenEventWExit:

Expand Down
Loading

0 comments on commit 9684675

Please sign in to comment.