/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ void GetRemoteEnv(IN RPC_BINDING_HANDLE hBinding, unsigned long *nNumLines, str **psEnvironmentBlock) { int nIdx = 0; // Loop counter TCHAR *pcTemp, // Temporary pointer to the environment block *pcEnv; // Pointer to the environment block // Get pointer to environment block pcEnv = (TCHAR *) GetEnvironmentStrings(); // First count how many lines, must know how much memory to allocate *nNumLines = 0; // Initialize number of lines to 0 pcTemp = pcEnv; // Set tempptr equal to envptr while (*pcTemp != NULL_CHAR) { // Don't count the lines that starts with IGNORE_CHAR if(*pcTemp != IGNORE_CHAR) { (*nNumLines)++; // Increase the number of lines } // Increment the string pointer. Each line ends in \0, and // \0\0 means end of block pcTemp += (_tcslen(pcTemp) + 1); } // Allocate the memory needed for the line pointer if(NULL == (*psEnvironmentBlock = (str *) midl_user_allocate((*nNumLines) * sizeof(str)))) { _tprintf_s(TEXT("REMOTE.C : Memory allocation error\n")); return; } // Iterate through all the environment strings, allocate memory, // and copy them while (*pcEnv != NULL_CHAR) { // Don't count the lines that starts with IGNORE_CHAR if(*pcEnv != IGNORE_CHAR) { // Allocate the space needed for the strings (*psEnvironmentBlock)[nIdx] = (str) midl_user_allocate( sizeof(TCHAR) * (_tcslen(pcEnv) + 1)); // Copy the environment string to the allocated memory _tcscpy_s((*psEnvironmentBlock)[nIdx++],sizeof(TCHAR) * (_tcslen(pcEnv) + 1), pcEnv); } // Increment the string pointer. Each line ends in \0, and // \0\0 means end of block pcEnv += (_tcslen(pcEnv) + 1); } }
/* Function 24 */ NET_API_STATUS __stdcall NetrServerStatisticsGet( SRVSVC_HANDLE ServerName, WCHAR *Service, DWORD Level, DWORD Options, LPSTAT_SERVER_0 *InfoStruct) { PSTAT_SERVER_0 pStatBuffer; TRACE("NetrServerStatisticsGet(%p %p %lu 0x%lx %p)\n", ServerName, Service, Level, Options, InfoStruct); if (Level != 0) return ERROR_INVALID_LEVEL; if (Options != 0) return ERROR_INVALID_PARAMETER; pStatBuffer = midl_user_allocate(sizeof(STAT_SERVER_0)); if (pStatBuffer == NULL) return ERROR_NOT_ENOUGH_MEMORY; ZeroMemory(pStatBuffer, sizeof(STAT_SERVER_0)); // FIXME: Return the actual statistcs data! *InfoStruct = pStatBuffer; return NERR_Success; }
void s_get_numbers_struct(numbers_struct_t **ns) { int i; *ns = midl_user_allocate(FIELD_OFFSET(numbers_struct_t, numbers[5])); if (!*ns) return; (*ns)->length = 5; (*ns)->size = 5; for (i = 0; i < (*ns)->length; i++) { (*ns)->numbers[i].pi = NULL; (*ns)->numbers[i].ppi = NULL; (*ns)->numbers[i].pppi = NULL; } (*ns)->numbers[0].pi = midl_user_allocate(sizeof(*(*ns)->numbers[i].pi)); *(*ns)->numbers[0].pi = 5; }
void s_get_numbers(int length, int size, pints_t n[]) { int i; for (i = 0; i < length; i++) { n[i].pi = midl_user_allocate(sizeof(*n[i].pi)); *n[i].pi = i; n[i].ppi = NULL; n[i].pppi = NULL; } }
// targetAddr: target address // targetStartAddr: target start address, some fied might reference to middle of another data chunk, like outParamOffsets // startAddress: current data start address // addrToFixup: address that currently pointing to dataAddr, which need to be updated void NativeCodeData::AddFixupEntry(void* targetAddr, void* targetStartAddr, void* addrToFixup, void* startAddress, DataChunk * chunkList) { Assert(addrToFixup >= startAddress); Assert(((__int64)addrToFixup) % sizeof(void*) == 0); if (targetAddr == nullptr) { return; } Assert(targetStartAddr); unsigned int inDataOffset = (unsigned int)((char*)targetAddr - (char*)targetStartAddr); DataChunk* targetChunk = NativeCodeData::GetDataChunk(targetStartAddr); Assert(targetChunk->len >= inDataOffset); #if DBG bool foundTargetChunk = false; while (chunkList) { foundTargetChunk |= (chunkList == targetChunk); chunkList = chunkList->next; } AssertMsg(foundTargetChunk, "current pointer is not allocated with NativeCodeData allocator?"); // change to valid check instead of assertion? #endif DataChunk* chunk = NativeCodeData::GetDataChunk(startAddress); NativeDataFixupEntry* entry = (NativeDataFixupEntry*)midl_user_allocate(sizeof(NativeDataFixupEntry)); if (!entry) { Js::Throw::OutOfMemory(); } __analysis_assume(entry); entry->addrOffset = (unsigned int)((__int64)addrToFixup - (__int64)startAddress); Assert(entry->addrOffset <= chunk->len - sizeof(void*)); entry->targetTotalOffset = targetChunk->offset + inDataOffset; entry->next = chunk->fixupList; chunk->fixupList = entry; #if DBG if (PHASE_TRACE1(Js::NativeCodeDataPhase)) { Output::Print(L"NativeCodeData Add Fixup: %p(%p+%d, chunk:%p) --> %p(chunk:%p) %S\n", addrToFixup, startAddress, entry->addrOffset, (void*)chunk, targetAddr, (void*)targetChunk, chunk->dataType); } #endif }
void NativeCodeData::AddFixupEntryForPointerArray(void* startAddress, DataChunk * chunkList) { DataChunk* chunk = NativeCodeData::GetDataChunk(startAddress); Assert(chunk->len % sizeof(void*) == 0); for (unsigned int i = 0; i < chunk->len / sizeof(void*); i++) { size_t offset = i * sizeof(void*); void* targetAddr = *(void**)((char*)startAddress + offset); if (targetAddr == nullptr) { continue; } DataChunk* targetChunk = NativeCodeData::GetDataChunk(targetAddr); #if DBG bool foundTargetChunk = false; DataChunk* chunk1 = chunkList; while (chunk1 && !foundTargetChunk) { foundTargetChunk = (chunk1 == targetChunk); chunk1 = chunk1->next; } AssertMsg(foundTargetChunk, "current pointer is not allocated with NativeCodeData allocator?"); // change to valid check instead of assertion? #endif NativeDataFixupEntry* entry = (NativeDataFixupEntry*)midl_user_allocate(sizeof(NativeDataFixupEntry)); if (!entry) { Js::Throw::OutOfMemory(); } __analysis_assume(entry); entry->addrOffset = (unsigned int)offset; entry->targetTotalOffset = targetChunk->offset; entry->next = chunk->fixupList; chunk->fixupList = entry; #if DBG if (PHASE_TRACE1(Js::NativeCodeDataPhase)) { Output::Print(L"NativeCodeData Add Fixup: %p[%d](+%d, chunk:%p) --> %p(chunk:%p) %S\n", startAddress, i, entry->addrOffset, (void*)chunk, targetAddr, (void*)targetChunk, chunk->dataType); } #endif } }
/* This remote procedure opens a file on the server. */ short RemoteOpen(PCONTEXT_HANDLE_TYPE *pphContext, unsigned char *pszFileName ) { FILE *hFile; FILE_CONTEXT_TYPE *pFileContext; if (fopen_s(&hFile,pszFileName, "r")) { *pphContext = (PCONTEXT_HANDLE_TYPE) NULL; return(-1); } else { pFileContext = (FILE_CONTEXT_TYPE *) midl_user_allocate(sizeof(FILE_CONTEXT_TYPE)); pFileContext->hFile = hFile; strncpy_s(pFileContext->achFile, sizeof(pFileContext->achFile),pszFileName, 255); *pphContext = (PCONTEXT_HANDLE_TYPE) pFileContext; return(0); } }
/* Function 28 */ NET_API_STATUS __stdcall NetrRemoteTOD( SRVSVC_HANDLE ServerName, LPTIME_OF_DAY_INFO *BufferPtr) { SYSTEMTIME SystemTime; LARGE_INTEGER Time; TIME_ZONE_INFORMATION TimeZoneInfo; DWORD TimeZoneId; LPTIME_OF_DAY_INFO lpTod; TRACE("NetrRemoteTOD(%p %p)\n", ServerName, BufferPtr); *BufferPtr = midl_user_allocate(sizeof(TIME_OF_DAY_INFO)); if (*BufferPtr == NULL) return ERROR_NOT_ENOUGH_MEMORY; lpTod = *BufferPtr; /* Set the seconds since 1970 */ NtQuerySystemTime(&Time); RtlTimeToSecondsSince1970(&Time, &lpTod->tod_elapsedt); /* Set the tick count */ lpTod->tod_msecs = GetTickCount(); /* Set the timezone */ TimeZoneId = GetTimeZoneInformation(&TimeZoneInfo); switch (TimeZoneId) { case TIME_ZONE_ID_UNKNOWN: lpTod->tod_timezone = TimeZoneInfo.Bias; break; case TIME_ZONE_ID_STANDARD: lpTod->tod_timezone = TimeZoneInfo.Bias + TimeZoneInfo.StandardBias; break; case TIME_ZONE_ID_DAYLIGHT: lpTod->tod_timezone = TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias; break; default: lpTod->tod_timezone = 0; } /* Set the ??? */ lpTod->tod_tinterval = 310; /* Set the date and time */ GetSystemTime(&SystemTime); lpTod->tod_hours = SystemTime.wHour; lpTod->tod_mins = SystemTime.wMinute; lpTod->tod_secs = SystemTime.wSecond; lpTod->tod_hunds = SystemTime.wMilliseconds / 10; lpTod->tod_day = SystemTime.wDay; lpTod->tod_month = SystemTime.wMonth; lpTod->tod_year = SystemTime.wYear; lpTod->tod_weekday = SystemTime.wDayOfWeek; return NERR_Success; }
HRESULT ServerRemoteCodeGen( /* [in] */ handle_t binding, /* [in] */ intptr_t scriptContextInfoAddress, /* [in] */ __RPC__in CodeGenWorkItemIDL *workItemData, /* [out] */ __RPC__out JITOutputIDL *jitData) { AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow)); LARGE_INTEGER start_time = { 0 }; if (PHASE_TRACE1(Js::BackEndPhase)) { QueryPerformanceCounter(&start_time); } memset(jitData, 0, sizeof(JITOutputIDL)); ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer((void*)scriptContextInfoAddress); if (scriptContextInfo == nullptr) { Assert(false); return RPC_S_INVALID_ARG; } if (!ServerContextManager::IsScriptContextAlive(scriptContextInfo)) { Assert(false); return E_ACCESSDENIED; } AutoReleaseContext<ServerScriptContext> autoScriptContext(scriptContextInfo); return ServerCallWrapper(scriptContextInfo, [&]() ->HRESULT { scriptContextInfo->UpdateGlobalObjectThisAddr(workItemData->globalThisAddr); ServerThreadContext * threadContextInfo = scriptContextInfo->GetThreadContext(); NoRecoverMemoryJitArenaAllocator jitArena(L"JITArena", threadContextInfo->GetPageAllocator(), Js::Throw::OutOfMemory); JITTimeWorkItem * jitWorkItem = Anew(&jitArena, JITTimeWorkItem, workItemData); if (PHASE_VERBOSE_TRACE_RAW(Js::BackEndPhase, jitWorkItem->GetJITTimeInfo()->GetSourceContextId(), jitWorkItem->GetJITTimeInfo()->GetLocalFunctionId())) { LARGE_INTEGER freq; LARGE_INTEGER end_time; QueryPerformanceCounter(&end_time); QueryPerformanceFrequency(&freq); Output::Print( L"BackendMarshalIn - function: %s time:%8.6f mSec\r\n", jitWorkItem->GetJITFunctionBody()->GetDisplayName(), (((double)((end_time.QuadPart - workItemData->startTime)* (double)1000.0 / (double)freq.QuadPart))) / (1)); Output::Flush(); } auto profiler = scriptContextInfo->GetCodeGenProfiler(); #ifdef PROFILE_EXEC if (profiler && !profiler->IsInitialized()) { profiler->Initialize(threadContextInfo->GetPageAllocator(), nullptr); } #endif if (jitWorkItem->GetWorkItemData()->xProcNumberPageSegment) { jitData->numberPageSegments = (XProcNumberPageSegment*)midl_user_allocate(sizeof(XProcNumberPageSegment)); if (!jitData->numberPageSegments) { return E_OUTOFMEMORY; } __analysis_assume(jitData->numberPageSegments); memcpy_s(jitData->numberPageSegments, sizeof(XProcNumberPageSegment), jitWorkItem->GetWorkItemData()->xProcNumberPageSegment, sizeof(XProcNumberPageSegment)); } Func::Codegen( &jitArena, jitWorkItem, threadContextInfo, scriptContextInfo, jitData, nullptr, nullptr, jitWorkItem->GetPolymorphicInlineCacheInfo(), threadContextInfo->GetCodeGenAllocators(), #if !FLOATVAR nullptr, // number allocator #endif profiler, true); #ifdef PROFILE_EXEC if (profiler && profiler->IsInitialized()) { profiler->ProfilePrint(Js::Configuration::Global.flags.Profile.GetFirstPhase()); } #endif if (PHASE_VERBOSE_TRACE_RAW(Js::BackEndPhase, jitWorkItem->GetJITTimeInfo()->GetSourceContextId(), jitWorkItem->GetJITTimeInfo()->GetLocalFunctionId())) { LARGE_INTEGER freq; LARGE_INTEGER end_time; QueryPerformanceCounter(&end_time); QueryPerformanceFrequency(&freq); Output::Print( L"EndBackEndInner - function: %s time:%8.6f mSec\r\n", jitWorkItem->GetJITFunctionBody()->GetDisplayName(), (((double)((end_time.QuadPart - start_time.QuadPart)* (double)1000.0 / (double)freq.QuadPart))) / (1)); Output::Flush(); } LARGE_INTEGER out_time = { 0 }; if (PHASE_TRACE1(Js::BackEndPhase)) { QueryPerformanceCounter(&out_time); jitData->startTime = out_time.QuadPart; } return S_OK; }); }
void __cdecl main(int argc, char **argv) { RPC_STATUS status; unsigned char * pbPicklingBuffer = NULL; char * pszStyle = NULL; char * pszFileName = "pickle.dat"; int i; int fEncode = 1; int fFixedStyle = 1; /* allow the user to override settings with command line switches */ for (i = 1; i < argc; i++) { if ((*argv[i] == '-') || (*argv[i] == '/')) { switch (tolower(*(argv[i]+1))) { case 'd': fEncode = 0; break; case 'e': fEncode = 1; break; case 'i': fFixedStyle = 0; break; case 'f': pszFileName = argv[i] + 2; break; case 'h': case '?': default: Usage(argv[0]); } } else Usage(argv[0]); } /* Fixed buffer style: the buffer should be big enough. */ /* Please note that the buffer has to be aligned at 8. */ pbPicklingBuffer = (unsigned char *) midl_user_allocate( BUFSIZE * sizeof(unsigned char)); if ( pbPicklingBuffer == NULL ) { printf_s("Cannot allocate the pickling buffer\n"); exit(1); } else memset( pbPicklingBuffer, 0xdd, BUFSIZE ); /* Set the pickling handle that will be used for data serialization. The global ImplicitPicHandle is used, but it has to be set up. */ if ( fEncode ) { unsigned char * pszNameId; OBJECT1 Object1; OBJECT2 * pObject2; unsigned long ulEncodedSize = 0; printf_s("\nEncoding run: use -d for decoding\n\n"); if ( fFixedStyle ) { printf_s("Creating a fixed buffer encoding handle\n"); status = MesEncodeFixedBufferHandleCreate( pbPicklingBuffer, BUFSIZE, & ulEncodedSize, & ImplicitPicHandle ); printf_s("MesEncodeFixedBufferHandleCreate returned 0x%x\n", status); if (status) { exit(status); } } else { pUserState->LastSize = 0; pUserState->pMemBuffer = (char *)pbPicklingBuffer; pUserState->pBufferStart = (char *)pbPicklingBuffer; printf_s("Creating an incremental encoding handle\n"); status = MesEncodeIncrementalHandleCreate( pUserState, PicAlloc, PicWrite, & ImplicitPicHandle ); printf_s("MesEncodeIncrementalHandleCreate returned 0x%x\n", status); if (status) { exit(status); } } /* Creating objects to manipulate */ pszNameId = "Procedure pickling sample"; for (i = 0; i < ARR_SIZE; i++) Object1.al[i] = 0x37370000 + i; Object1.s = 0x4646; pObject2 = midl_user_allocate( sizeof(OBJECT2) + ARR_SIZE*sizeof(short) ); if (pObject2 == NULL ) { printf_s("Out of memory for Object2\n"); exit(1); } pObject2->sSize = ARR_SIZE; for (i = 0; i < ARR_SIZE; i++) pObject2->as[i] = 0x7700 + i; DumpData( "Data to be encoded", pszNameId, &Object1, pObject2 ); printf_s("\nEncoding all the arguments to the buffer\n\n"); ProcPickle( pszNameId, & Object1, pObject2 ); printf_s("Writing the data to the file: %s\n", pszFileName); WriteDataToFile( pszFileName, pbPicklingBuffer, fFixedStyle ? ulEncodedSize : pUserState->LastSize); midl_user_free( pObject2 ); } else { char acNameBuffer[50]; OBJECT1 Object1; OBJECT2 * pObject2; printf_s("\nDecoding run: use -e for encoding\n\n"); printf_s("Reading the data from the file: %s\n\n", pszFileName ); ReadDataFromFile( pszFileName, pbPicklingBuffer, BUFSIZE ); if ( fFixedStyle ) { printf_s("Creating a decoding handle\n"); status = MesDecodeBufferHandleCreate( pbPicklingBuffer, BUFSIZE, & ImplicitPicHandle ); printf_s("MesDecodeFixedBufferHandleCreate returned 0x%x\n", status); if (status) { exit(status); } } else { pUserState->LastSize = 0; pUserState->pMemBuffer = (char *)pbPicklingBuffer; pUserState->pBufferStart = (char *)pbPicklingBuffer; printf_s("Creating an incremental decoding handle\n"); status = MesDecodeIncrementalHandleCreate( pUserState, PicRead, & ImplicitPicHandle ); printf_s("MesDecodeIncrementalHandleCreate returned 0x%x\n", status); if (status) { exit(status); } } /* Creating objects to manipulate */ pObject2 = midl_user_allocate( sizeof(OBJECT2) + ARR_SIZE*sizeof(short)); if (pObject2 == NULL ) { printf_s("Out of memory for Object2\n"); exit(1); } printf_s("\nDecoding all the arguments from the buffer\n"); ProcPickle( acNameBuffer, & Object1, pObject2 ); DumpData( "Decoded data", acNameBuffer, &Object1, pObject2 ); midl_user_free( pObject2 ); } printf_s("\nData serialization done.\n"); midl_user_free( pbPicklingBuffer ); printf_s("\nFreeing the serialization handle.\n"); status = MesHandleFree( ImplicitPicHandle ); printf_s("MesHandleFree returned 0x%x\n", status); exit(0); } // end main()
Js::JavascriptNumber* XProcNumberPageSegmentImpl::AllocateNumber(HANDLE hProcess, double value, Js::StaticType* numberTypeStatic, void* javascriptNumberVtbl) { XProcNumberPageSegmentImpl* tail = this; if (this->pageAddress != 0) { while (tail->nextSegment) { tail = (XProcNumberPageSegmentImpl*)tail->nextSegment; } if (tail->pageAddress + tail->committedEnd - tail->allocEndAddress >= GetSizeCat()) { auto number = tail->allocEndAddress; tail->allocEndAddress += GetSizeCat(); Js::JavascriptNumber localNumber(value, numberTypeStatic #if DBG , true #endif ); // change vtable to the remote one *(void**)&localNumber = javascriptNumberVtbl; // initialize number by WriteProcessMemory SIZE_T bytesWritten; WriteProcessMemory(hProcess, (void*)number, &localNumber, sizeof(localNumber), &bytesWritten); return (Js::JavascriptNumber*) number; } // alloc blocks if ((void*)tail->committedEnd < tail->GetEndAddress()) { Assert((unsigned int)((char*)tail->GetEndAddress() - (char*)tail->committedEnd) >= BlockSize); // TODO: implement guard pages (still necessary for OOP JIT?) auto ret = ::VirtualAllocEx(hProcess, tail->GetCommitEndAddress(), BlockSize, MEM_COMMIT, PAGE_READWRITE); if (!ret) { Js::Throw::OutOfMemory(); } tail->committedEnd += BlockSize; return AllocateNumber(hProcess, value, numberTypeStatic, javascriptNumberVtbl); } } // alloc new segment void* pages = ::VirtualAllocEx(hProcess, nullptr, PageCount * AutoSystemInfo::PageSize, MEM_RESERVE, PAGE_READWRITE); if (pages == nullptr) { Js::Throw::OutOfMemory(); } if (tail->pageAddress == 0) { tail = new (tail) XProcNumberPageSegmentImpl(); tail->pageAddress = (intptr_t)pages; tail->allocStartAddress = this->pageAddress; tail->allocEndAddress = this->pageAddress; tail->nextSegment = nullptr; return AllocateNumber(hProcess, value, numberTypeStatic, javascriptNumberVtbl); } else { XProcNumberPageSegmentImpl* seg = (XProcNumberPageSegmentImpl*)midl_user_allocate(sizeof(XProcNumberPageSegment)); if (seg == nullptr) { Js::Throw::OutOfMemory(); } seg = new (seg) XProcNumberPageSegmentImpl(); tail->nextSegment = seg; return seg->AllocateNumber(hProcess, value, numberTypeStatic, javascriptNumberVtbl); } }
NTSTATUS SampGetMembersInAlias(IN PSAM_DB_OBJECT AliasObject, OUT PULONG MemberCount, OUT PSAMPR_SID_INFORMATION *MemberArray) { HANDLE MembersKeyHandle = NULL; PSAMPR_SID_INFORMATION Members = NULL; ULONG Count = 0; ULONG DataLength; ULONG Index; NTSTATUS Status; /* Open the members key of the alias object */ Status = SampRegOpenKey(AliasObject->KeyHandle, L"Members", KEY_READ, &MembersKeyHandle); if (!NT_SUCCESS(Status)) { ERR("SampRegOpenKey failed with status 0x%08lx\n", Status); goto done; } /* Get the number of members */ Status = SampRegQueryKeyInfo(MembersKeyHandle, NULL, &Count); if (!NT_SUCCESS(Status)) { ERR("SampRegQueryKeyInfo failed with status 0x%08lx\n", Status); goto done; } /* Allocate the member array */ Members = midl_user_allocate(Count * sizeof(SAMPR_SID_INFORMATION)); if (Members == NULL) { Status = STATUS_INSUFFICIENT_RESOURCES; goto done; } /* Enumerate the members */ Index = 0; while (TRUE) { /* Get the size of the next SID */ DataLength = 0; Status = SampRegEnumerateValue(MembersKeyHandle, Index, NULL, NULL, NULL, NULL, &DataLength); if (!NT_SUCCESS(Status)) { if (Status == STATUS_NO_MORE_ENTRIES) Status = STATUS_SUCCESS; break; } /* Allocate a buffer for the SID */ Members[Index].SidPointer = midl_user_allocate(DataLength); if (Members[Index].SidPointer == NULL) { Status = STATUS_INSUFFICIENT_RESOURCES; goto done; } /* Read the SID into the buffer */ Status = SampRegEnumerateValue(MembersKeyHandle, Index, NULL, NULL, NULL, (PVOID)Members[Index].SidPointer, &DataLength); if (!NT_SUCCESS(Status)) { goto done; } Index++; } if (NT_SUCCESS(Status)) { *MemberCount = Count; *MemberArray = Members; } done: return Status; }