mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
Protected the handle table.
svn path=/trunk/; revision=15526
This commit is contained in:
parent
7d4d22763c
commit
deab50cb8b
3 changed files with 26 additions and 19 deletions
|
@ -123,8 +123,10 @@ CsrReleaseObject(PCSRSS_PROCESS_DATA ProcessData,
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = CsrReleaseObjectByPointer(ProcessData->HandleTable[h]);
|
Status = CsrReleaseObjectByPointer(ProcessData->HandleTable[h]);
|
||||||
ProcessData->HandleTable[h] = 0;
|
|
||||||
|
|
||||||
|
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
|
||||||
|
ProcessData->HandleTable[h] = 0;
|
||||||
|
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,22 +140,23 @@ NTSTATUS STDCALL CsrInsertObject( PCSRSS_PROCESS_DATA ProcessData, PHANDLE Handl
|
||||||
return STATUS_INVALID_PARAMETER;
|
return STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
|
||||||
|
|
||||||
for (i = 0; i < ProcessData->HandleTableSize; i++)
|
for (i = 0; i < ProcessData->HandleTableSize; i++)
|
||||||
{
|
{
|
||||||
if (ProcessData->HandleTable[i] == NULL)
|
if (ProcessData->HandleTable[i] == NULL)
|
||||||
{
|
{
|
||||||
ProcessData->HandleTable[i] = Object;
|
break;
|
||||||
*Handle = (HANDLE)(((i + 1) << 2) | 0x3);
|
|
||||||
InterlockedIncrement( &Object->ReferenceCount );
|
|
||||||
return(STATUS_SUCCESS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (i >= ProcessData->HandleTableSize)
|
||||||
|
{
|
||||||
NewBlock = RtlAllocateHeap(CsrssApiHeap,
|
NewBlock = RtlAllocateHeap(CsrssApiHeap,
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
(ProcessData->HandleTableSize + 64) *
|
(ProcessData->HandleTableSize + 64) * sizeof(HANDLE));
|
||||||
sizeof(HANDLE));
|
|
||||||
if (NewBlock == NULL)
|
if (NewBlock == NULL)
|
||||||
{
|
{
|
||||||
|
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
|
||||||
return(STATUS_UNSUCCESSFUL);
|
return(STATUS_UNSUCCESSFUL);
|
||||||
}
|
}
|
||||||
RtlCopyMemory(NewBlock,
|
RtlCopyMemory(NewBlock,
|
||||||
|
@ -161,10 +164,12 @@ NTSTATUS STDCALL CsrInsertObject( PCSRSS_PROCESS_DATA ProcessData, PHANDLE Handl
|
||||||
ProcessData->HandleTableSize * sizeof(HANDLE));
|
ProcessData->HandleTableSize * sizeof(HANDLE));
|
||||||
RtlFreeHeap( CsrssApiHeap, 0, ProcessData->HandleTable );
|
RtlFreeHeap( CsrssApiHeap, 0, ProcessData->HandleTable );
|
||||||
ProcessData->HandleTable = (Object_t **)NewBlock;
|
ProcessData->HandleTable = (Object_t **)NewBlock;
|
||||||
|
ProcessData->HandleTableSize += 64;
|
||||||
|
}
|
||||||
ProcessData->HandleTable[i] = Object;
|
ProcessData->HandleTable[i] = Object;
|
||||||
*Handle = (HANDLE)(((i + 1) << 2) | 0x3);
|
*Handle = (HANDLE)(((i + 1) << 2) | 0x3);
|
||||||
InterlockedIncrement( &Object->ReferenceCount );
|
InterlockedIncrement( &Object->ReferenceCount );
|
||||||
ProcessData->HandleTableSize = ProcessData->HandleTableSize + 64;
|
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,7 @@ PCSRSS_PROCESS_DATA STDCALL CsrCreateProcessData(HANDLE ProcessId)
|
||||||
RtlFreeHeap(CsrssApiHeap, 0, pProcessData);
|
RtlFreeHeap(CsrssApiHeap, 0, pProcessData);
|
||||||
pProcessData = NULL;
|
pProcessData = NULL;
|
||||||
}
|
}
|
||||||
|
RtlInitializeCriticalSection(&pProcessData->HandleTableLock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -160,6 +161,7 @@ NTSTATUS STDCALL CsrFreeProcessData(HANDLE Pid)
|
||||||
}
|
}
|
||||||
RtlFreeHeap(CsrssApiHeap, 0, pProcessData->HandleTable);
|
RtlFreeHeap(CsrssApiHeap, 0, pProcessData->HandleTable);
|
||||||
}
|
}
|
||||||
|
RtlDeleteCriticalSection(&pProcessData->HandleTableLock);
|
||||||
if (pProcessData->Console)
|
if (pProcessData->Console)
|
||||||
{
|
{
|
||||||
CsrReleaseObjectByPointer((Object_t *) pProcessData->Console);
|
CsrReleaseObjectByPointer((Object_t *) pProcessData->Console);
|
||||||
|
@ -254,7 +256,6 @@ CSR_API(CsrCreateProcess)
|
||||||
if( !NT_SUCCESS( Status ) )
|
if( !NT_SUCCESS( Status ) )
|
||||||
{
|
{
|
||||||
DbgPrint( "CSR: NtDuplicateObject() failed: %x\n", Status );
|
DbgPrint( "CSR: NtDuplicateObject() failed: %x\n", Status );
|
||||||
InterlockedDecrement( &(NewProcessData->Console->Header.ReferenceCount) );
|
|
||||||
CsrFreeProcessData( NewProcessData->ProcessId );
|
CsrFreeProcessData( NewProcessData->ProcessId );
|
||||||
Reply->Status = Status;
|
Reply->Status = Status;
|
||||||
return Status;
|
return Status;
|
||||||
|
|
|
@ -34,6 +34,7 @@ typedef struct tagCSRSS_CONSOLE *PCSRSS_CONSOLE;
|
||||||
typedef struct _CSRSS_PROCESS_DATA
|
typedef struct _CSRSS_PROCESS_DATA
|
||||||
{
|
{
|
||||||
PCSRSS_CONSOLE Console;
|
PCSRSS_CONSOLE Console;
|
||||||
|
RTL_CRITICAL_SECTION HandleTableLock;
|
||||||
ULONG HandleTableSize;
|
ULONG HandleTableSize;
|
||||||
Object_t ** HandleTable;
|
Object_t ** HandleTable;
|
||||||
HANDLE ProcessId;
|
HANDLE ProcessId;
|
||||||
|
|
Loading…
Reference in a new issue