From 2e992926e35672b37d0d0fc157f90f0f9ca670c2 Mon Sep 17 00:00:00 2001 From: "KJK::Hyperion" Date: Sun, 10 Mar 2002 17:09:46 +0000 Subject: [PATCH] finally (and hopefully) functional __PdxSpawnPosixProcess. To be tested svn path=/trunk/; revision=2693 --- posix/lib/psxdll/misc/spawn.c | 304 +--------------------------------- 1 file changed, 2 insertions(+), 302 deletions(-) diff --git a/posix/lib/psxdll/misc/spawn.c b/posix/lib/psxdll/misc/spawn.c index 4c14f009371..3be347376fc 100644 --- a/posix/lib/psxdll/misc/spawn.c +++ b/posix/lib/psxdll/misc/spawn.c @@ -1,4 +1,4 @@ -/* $Id: spawn.c,v 1.2 2002/03/07 06:08:00 hyperion Exp $ +/* $Id: spawn.c,v 1.3 2002/03/10 17:09:46 hyperion Exp $ */ /* * COPYRIGHT: See COPYING in the top level directory @@ -32,307 +32,7 @@ #include #include -VOID -__PdxSerializeProcessData -( - IN __PPDX_PDATA ProcessData, - OUT __PPDX_SERIALIZED_PDATA *SerializedProcessData -) -{ - __PPDX_SERIALIZED_PDATA pspdProcessData = 0; - NTSTATUS nErrCode; - PBYTE pBufferTail; - ULONG ulAllocSize = sizeof(__PDX_SERIALIZED_PDATA) - 1; - size_t *pnArgLengths; - size_t *pnEnvVarsLengths; - int nEnvVarsCount; - int i; - - /* calculate buffer length */ - /* FIXME please! this is the most inefficient way to do it */ - - /* argv */ - pnArgLengths = __malloc(ProcessData->ArgCount * sizeof(size_t)); - - for(i = 0; i < ProcessData->ArgCount; i ++) - { - int nStrLen = strlen(ProcessData->ArgVect[i]) + 1; - ulAllocSize += nStrLen; - pnArgLengths[i] = nStrLen; - - INFO - ( - "argument %d: \"%s\", length %d\n", - i, - ProcessData->ArgVect[i], - nStrLen - ); - } - - /* environ */ - pnEnvVarsLengths = 0; - nEnvVarsCount = 0; - - for(i = 0; *(ProcessData->Environment)[i] != 0; i++) - { - int nStrLen = strlen(*(ProcessData->Environment)[i]) + 1; - ulAllocSize += nStrLen; - - nEnvVarsCount ++; - __realloc(pnEnvVarsLengths, nEnvVarsCount * sizeof(size_t)); - pnEnvVarsLengths[i] = nStrLen; - - INFO - ( - "environment variable %d: \"%s\", length %d\n", - i, - *(ProcessData->Environment)[i], - nStrLen - ); - } - - INFO("(%d environment variables were found)\n", nEnvVarsCount); - - /* current directory */ - ulAllocSize += ProcessData->CurDir.Length; - INFO - ( - "current directory: \"%Z\", length %d\n", - &ProcessData->CurDir, - ProcessData->CurDir.Length - ); - - /* root directory */ - ulAllocSize += ProcessData->RootPath.Length; - INFO - ( - "root directory: \"%Z\", length %d\n", - &ProcessData->RootPath, - ProcessData->RootPath.Length - ); - - /* file descriptors table */ - ulAllocSize += sizeof(__fildes_t) * ProcessData->FdTable.AllocatedDescriptors; - INFO - ( - "descriptors table contains %d allocated descriptors, combined length %d\n", - ProcessData->FdTable.AllocatedDescriptors, - sizeof(__fildes_t) * ProcessData->FdTable.AllocatedDescriptors - ); - - /* extra descriptors data */ - for(i = 0; ProcessData->FdTable.AllocatedDescriptors; i ++) - if(ProcessData->FdTable.Descriptors[i].ExtraData != NULL) - { - ulAllocSize += ProcessData->FdTable.Descriptors[i].ExtraDataSize; - - INFO - ( - "descriptor %d has %d bytes of associated data\n", - i, - ProcessData->FdTable.Descriptors[i].ExtraDataSize - ); - - } - - /* allocate return block */ - INFO("about to allocate %d bytes\n", ulAllocSize); - - nErrCode = NtAllocateVirtualMemory - ( - NtCurrentProcess(), - (PVOID *)&pspdProcessData, - 0, - &ulAllocSize, - MEM_COMMIT, - PAGE_READWRITE - ); - - /* failure */ - if(!NT_SUCCESS(nErrCode)) - { - ERR("NtAllocateVirtualMemory() failed with status 0x%08X\n", nErrCode); - __free(pnArgLengths); - __free(pnEnvVarsLengths); - *SerializedProcessData = 0; - return; - } - - INFO("%d bytes actually allocated\n", ulAllocSize); - pspdProcessData->AllocSize = ulAllocSize; - - /* copy data */ - /* static data */ - memcpy(&pspdProcessData->ProcessData, ProcessData, sizeof(__PDX_PDATA)); - - /* buffers */ - pBufferTail = &pspdProcessData->Buffer[0]; - INFO("buffer tail begins at 0x%08X\n", pBufferTail); - - /* argv */ - pspdProcessData->ProcessData.ArgVect = 0; - - for(i = 0; i < ProcessData->ArgCount; i ++) - { - INFO - ( - "copying %d bytes of argument %d (\"%s\") to 0x%08X\n", - pnArgLengths[i], - i, - ProcessData->ArgVect[i], - pBufferTail - ); - - strncpy(pBufferTail, ProcessData->ArgVect[i], pnArgLengths[i]); - pBufferTail += pnArgLengths[i]; - - INFO - ( - "buffer tail increased by %d bytes, new tail at 0x%08X\n", - pnArgLengths[i], - pBufferTail - ); - - } - - __free(pnArgLengths); - - /* environ */ - pspdProcessData->ProcessData.Environment = (char ***)nEnvVarsCount; - - for(i = 0; i < nEnvVarsCount; i ++) - { - INFO - ( - "copying %d bytes of environment variable %d (\"%s\") to 0x%08X\n", - pnEnvVarsLengths[i], - i, - ProcessData->Environment[i], - pBufferTail - ); - - strncpy(pBufferTail, *ProcessData->Environment[i], pnEnvVarsLengths[i]); - pBufferTail += pnEnvVarsLengths[i]; - - INFO - ( - "buffer tail increased by %d bytes, new tail at 0x%08X\n", - pnEnvVarsLengths[i], - pBufferTail - ); - } - - __free(pnEnvVarsLengths); - - /* current directory */ - INFO - ( - "copying %d bytes of current directory (\"%Z\") to 0x%08X\n", - ProcessData->CurDir.Length, - &ProcessData->CurDir, - pBufferTail - ); - - memcpy(pBufferTail, ProcessData->CurDir.Buffer, ProcessData->CurDir.Length); - pBufferTail += ProcessData->CurDir.Length; - - INFO - ( - "buffer tail increased by %d bytes, new tail at 0x%08X\n", - ProcessData->CurDir.Length, - pBufferTail - ); - - /* root directory */ - INFO - ( - "copying %d bytes of root directory (\"%Z\") to 0x%08X\n", - ProcessData->RootPath.Length, - &ProcessData->RootPath, - pBufferTail - ); - - memcpy - ( - pBufferTail, - ProcessData->RootPath.Buffer, - ProcessData->RootPath.Length - ); - - pBufferTail += ProcessData->RootPath.Length; - - INFO - ( - "buffer tail increased by %d bytes, new tail at 0x%08X\n", - ProcessData->RootPath.Length, - pBufferTail - ); - - /* file descriptors table */ - /* save the offset to the descriptors array */ - pspdProcessData->ProcessData.FdTable.Descriptors = - (PVOID)((ULONG)pBufferTail - (ULONG)pspdProcessData); - - INFO - ( - "descriptors table contains %d allocated descriptors, combined length %d\n", - ProcessData->FdTable.AllocatedDescriptors, - sizeof(__fildes_t) * ProcessData->FdTable.AllocatedDescriptors - ); - - memcpy - ( - pBufferTail, - ProcessData->FdTable.Descriptors, - sizeof(__fildes_t) * ProcessData->FdTable.AllocatedDescriptors - ); - - pBufferTail += - sizeof(__fildes_t) * ProcessData->FdTable.AllocatedDescriptors; - - INFO - ( - "buffer tail increased by %d bytes, new tail at 0x%08X\n", - sizeof(__fildes_t) * ProcessData->FdTable.AllocatedDescriptors, - pBufferTail - ); - - /* extra descriptors data */ - for(i = 0; ProcessData->FdTable.AllocatedDescriptors; i ++) - if(ProcessData->FdTable.Descriptors[i].ExtraData != 0) - { - INFO - ( - "descriptor %d has %d bytes of associated data\n", - i, - ProcessData->FdTable.Descriptors[i].ExtraDataSize - ); - - memcpy - ( - pBufferTail, - ProcessData->FdTable.Descriptors[i].ExtraData, - ProcessData->FdTable.Descriptors[i].ExtraDataSize - ); - - pBufferTail += ProcessData->FdTable.Descriptors[i].ExtraDataSize; - - INFO - ( - "buffer tail increased by %d bytes, new tail at 0x%08X\n", - ProcessData->FdTable.Descriptors[i].ExtraDataSize, - pBufferTail - ); - } - - /* success */ - *SerializedProcessData = pspdProcessData; -} - -NTSYSAPI -NTSTATUS -NTAPI -__PdxSpawnPosixProcess +NTSTATUS STDCALL __PdxSpawnPosixProcess ( OUT PHANDLE ProcessHandle, OUT PHANDLE ThreadHandle,