AllocSpace(ulen mem_len) { mem_len=AlignDown(mem_len); mem=MemAlloc(mem_len); len=mem_len; }
MemoryRegion::MemoryRegion(bool fine_grain, const core::Agent& owner, const HsaMemoryProperties& mem_props) : core::MemoryRegion(fine_grain), owner_(&owner), mem_props_(mem_props), max_single_alloc_size_(0), virtual_size_(0) { virtual_size_ = GetPhysicalSize(); mem_flag_.Value = 0; if (IsLocalMemory()) { mem_flag_.ui32.PageSize = HSA_PAGE_SIZE_4KB; mem_flag_.ui32.NoSubstitute = 1; mem_flag_.ui32.HostAccess = 0; mem_flag_.ui32.NonPaged = 1; char* char_end = NULL; HSAuint64 max_alloc_size = static_cast<HSAuint64>(strtoull( os::GetEnvVar("HSA_LOCAL_MEMORY_MAX_ALLOC").c_str(), &char_end, 10)); max_alloc_size = std::max(max_alloc_size, GetPhysicalSize() / 4); max_alloc_size = std::min(max_alloc_size, GetPhysicalSize()); max_single_alloc_size_ = AlignDown(static_cast<size_t>(max_alloc_size), kPageSize_); static const HSAuint64 kGpuVmSize = (1ULL << 40); virtual_size_ = kGpuVmSize; } else if (IsSystem()) { mem_flag_.ui32.PageSize = HSA_PAGE_SIZE_4KB; mem_flag_.ui32.NoSubstitute = 1; mem_flag_.ui32.HostAccess = 1; mem_flag_.ui32.CachePolicy = HSA_CACHING_CACHED; max_single_alloc_size_ = AlignDown(static_cast<size_t>(GetPhysicalSize()), kPageSize_); virtual_size_ = os::GetUserModeVirtualMemorySize(); } assert(GetVirtualSize() != 0); assert(GetPhysicalSize() <= GetVirtualSize()); assert(IsMultipleOf(max_single_alloc_size_, kPageSize_)); }
COUNT_T ZapBlobWithRelocs::GetCountOfStraddlerRelocations(DWORD dwPos) { if (m_pRelocs == NULL) return 0; // Straddlers can exist only if the node is crossing page boundary if (AlignDown(dwPos, RELOCATION_PAGE_SIZE) == AlignDown(dwPos + GetSize() - 1, RELOCATION_PAGE_SIZE)) return 0; COUNT_T nStraddlers = 0; for (ZapReloc * pReloc = m_pRelocs; pReloc->m_type != IMAGE_REL_INVALID; pReloc++) { if (pReloc->m_type == IMAGE_REL_BASED_PTR) { if (AlignmentTrim(dwPos + pReloc->m_offset, RELOCATION_PAGE_SIZE) > RELOCATION_PAGE_SIZE - sizeof(TADDR)) nStraddlers++; } } return nStraddlers; }
void ZapBaseRelocs::WriteReloc(PVOID pSrc, int offset, ZapNode * pTarget, int targetOffset, ZapRelocationType type) { _ASSERTE(pTarget != NULL); PBYTE pLocation = (PBYTE)pSrc + offset; DWORD rva = m_pImage->GetCurrentRVA() + offset; TADDR pActualTarget = (TADDR)m_pImage->GetBaseAddress() + pTarget->GetRVA() + targetOffset; #ifdef REDHAWK PDB_NoticeReloc(type, rva, pTarget, targetOffset); #endif switch (type) { case IMAGE_REL_BASED_ABSOLUTE: *(UNALIGNED DWORD *)pLocation = pTarget->GetRVA() + targetOffset; // IMAGE_REL_BASED_ABSOLUTE does not need base reloc entry return; case IMAGE_REL_BASED_ABSOLUTE_TAGGED: _ASSERTE(targetOffset == 0); *(UNALIGNED DWORD *)pLocation = (DWORD)CORCOMPILE_TAG_TOKEN(pTarget->GetRVA()); // IMAGE_REL_BASED_ABSOLUTE_TAGGED does not need base reloc entry return; case IMAGE_REL_BASED_PTR: #ifdef _TARGET_ARM_ // Misaligned relocs disable ASLR on ARM. We should never ever emit them. _ASSERTE(IS_ALIGNED(rva, sizeof(TADDR))); #endif *(UNALIGNED TADDR *)pLocation = pActualTarget; break; case IMAGE_REL_BASED_RELPTR: { TADDR pSite = (TADDR)m_pImage->GetBaseAddress() + rva; *(UNALIGNED TADDR *)pLocation = (INT32)(pActualTarget - pSite); } // neither IMAGE_REL_BASED_RELPTR nor IMAGE_REL_BASED_MD_METHODENTRY need base reloc entry return; case IMAGE_REL_BASED_RELPTR32: { TADDR pSite = (TADDR)m_pImage->GetBaseAddress() + rva; *(UNALIGNED INT32 *)pLocation = (INT32)(pActualTarget - pSite); } // IMAGE_REL_BASED_RELPTR32 does not need base reloc entry return; #if defined(_TARGET_X86_) || defined(_TARGET_AMD64_) case IMAGE_REL_BASED_REL32: { TADDR pSite = (TADDR)m_pImage->GetBaseAddress() + rva; *(UNALIGNED INT32 *)pLocation = (INT32)(pActualTarget - (pSite + sizeof(INT32))); } // IMAGE_REL_BASED_REL32 does not need base reloc entry return; #endif // _TARGET_X86_ || _TARGET_AMD64_ #if defined(_TARGET_ARM_) case IMAGE_REL_BASED_THUMB_MOV32: { PutThumb2Mov32((UINT16 *)pLocation, (UINT32)pActualTarget); break; } case IMAGE_REL_BASED_THUMB_BRANCH24: { TADDR pSite = (TADDR)m_pImage->GetBaseAddress() + rva; // Kind of a workaround: make this reloc work both for calls (which have the thumb bit set), // and for relative jumps used for hot/cold splitting (which don't). pActualTarget &= ~THUMB_CODE; // Calculate the reloffset without the ThumbBit set so that it can be correctly encoded. _ASSERTE(!(pActualTarget & THUMB_CODE));// we expect pActualTarget not to have the thumb bit set _ASSERTE(!(pSite & THUMB_CODE)); // we expect pSite not to have the thumb bit set INT32 relOffset = (INT32)(pActualTarget - (pSite + sizeof(INT32))); if (!FitsInThumb2BlRel24(relOffset)) { // Retry the compilation with IMAGE_REL_BASED_THUMB_BRANCH24 relocations disabled // (See code:ZapInfo::getRelocTypeHint) ThrowHR(COR_E_OVERFLOW); } PutThumb2BlRel24((UINT16 *)pLocation, relOffset); } // IMAGE_REL_BASED_THUMB_BRANCH24 does not need base reloc entry return; #endif #if defined(_TARGET_ARM64_) case IMAGE_REL_ARM64_BRANCH26: { TADDR pSite = (TADDR)m_pImage->GetBaseAddress() + rva; INT64 relOffset = (INT64)(pActualTarget - (pSite + sizeof(INT64))); if (!FitsInRel28(relOffset)) { ThrowHR(COR_E_OVERFLOW); } PutArm64Rel28((UINT32 *)pLocation,(INT32)relOffset); } return; #endif default: _ASSERTE(!"Unknown relocation type"); break; } DWORD page = AlignDown(rva, RELOCATION_PAGE_SIZE); if (page != m_page) { FlushWriter(); m_page = page; m_pageIndex = m_SerializedRelocs.GetCount(); // Reserve space for IMAGE_BASE_RELOCATION for (size_t iSpace = 0; iSpace < sizeof(IMAGE_BASE_RELOCATION) / sizeof(USHORT); iSpace++) m_SerializedRelocs.Append(0); } m_SerializedRelocs.Append((USHORT)(AlignmentTrim(rva, RELOCATION_PAGE_SIZE) | (type << 12))); }
print_disasm_ = js_new<PrintDisassembler>(stream_); set_coloured_trace(false); trace_parameters_ = LOG_NONE; ResetState(); // Allocate and set up the simulator stack. stack_ = (byte*)js_malloc(stack_size_); stack_limit_ = stack_ + stack_protection_size_; // Configure the starting stack pointer. // - Find the top of the stack. byte * tos = stack_ + stack_size_; // - There's a protection region at both ends of the stack. tos -= stack_protection_size_; // - The stack pointer must be 16-byte aligned. tos = AlignDown(tos, 16); set_sp(tos); // Set the sample period to 10, as the VIXL examples and tests are short. instrumentation_ = js_new<Instrument>("vixl_stats.csv", 10); // Print a warning about exclusive-access instructions, but only the first // time they are encountered. This warning can be silenced using // SilenceExclusiveAccessWarning(). print_exclusive_access_warning_ = true; lock_ = PR_NewLock(); if (!lock_) MOZ_CRASH("Could not allocate simulator lock."); #ifdef DEBUG lockOwner_ = nullptr;
void CPullPin::Process(void) { // is there anything to do? if (m_tStop <= m_tStart) { EndOfStream(); return; } BOOL bDiscontinuity = TRUE; // if there is more than one sample at the allocator, // then try to queue 2 at once in order to overlap. // -- get buffer count and required alignment ALLOCATOR_PROPERTIES Actual; HRESULT hr = m_pAlloc->GetProperties(&Actual); // align the start position downwards REFERENCE_TIME tStart = AlignDown(m_tStart / UNITS, Actual.cbAlign) * UNITS; REFERENCE_TIME tCurrent = tStart; REFERENCE_TIME tStop = m_tStop; if (tStop > m_tDuration) { tStop = m_tDuration; } // align the stop position - may be past stop, but that // doesn't matter REFERENCE_TIME tAlignStop = AlignUp(tStop / UNITS, Actual.cbAlign) * UNITS; DWORD dwRequest; if (!m_bSync) { // Break out of the loop either if we get to the end or we're asked // to do something else while (tCurrent < tAlignStop) { // Break out without calling EndOfStream if we're asked to // do something different if (CheckRequest(&dwRequest)) { return; } // queue a first sample if (Actual.cBuffers > 1) { hr = QueueSample(tCurrent, tAlignStop, TRUE); bDiscontinuity = FALSE; if (FAILED(hr)) { return; } } // loop queueing second and waiting for first.. while (tCurrent < tAlignStop) { hr = QueueSample(tCurrent, tAlignStop, bDiscontinuity); bDiscontinuity = FALSE; if (FAILED(hr)) { return; } hr = CollectAndDeliver(tStart, tStop); if (S_OK != hr) { // stop if error, or if downstream filter said // to stop. return; } } if (Actual.cBuffers > 1) { hr = CollectAndDeliver(tStart, tStop); if (FAILED(hr)) { return; } } } } else { // sync version of above loop while (tCurrent < tAlignStop) { // Break out without calling EndOfStream if we're asked to // do something different if (CheckRequest(&dwRequest)) { return; } IMediaSample* pSample; hr = m_pAlloc->GetBuffer(&pSample, NULL, NULL, 0); if (FAILED(hr)) { OnError(hr); return; } LONGLONG tStopThis = tCurrent + (pSample->GetSize() * UNITS); if (tStopThis > tAlignStop) { tStopThis = tAlignStop; } pSample->SetTime(&tCurrent, &tStopThis); tCurrent = tStopThis; if (bDiscontinuity) { pSample->SetDiscontinuity(TRUE); bDiscontinuity = FALSE; } hr = m_pReader->SyncReadAligned(pSample); if (FAILED(hr)) { pSample->Release(); OnError(hr); return; } hr = DeliverSample(pSample, tStart, tStop); if (hr != S_OK) { if (FAILED(hr)) { OnError(hr); } return; } } } EndOfStream(); }
static VOID ScanForUnpartitionedDiskSpace( PDISKENTRY DiskEntry) { ULONGLONG LastStartSector; ULONGLONG LastSectorCount; ULONGLONG LastUnusedSectorCount; PPARTENTRY PartEntry; PPARTENTRY NewPartEntry; PLIST_ENTRY Entry; DPRINT("ScanForUnpartitionedDiskSpace()\n"); if (IsListEmpty(&DiskEntry->PrimaryPartListHead)) { DPRINT1("No primary partition!\n"); /* Create a partition table that represents the empty disk */ NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); if (NewPartEntry == NULL) return; NewPartEntry->DiskEntry = DiskEntry; NewPartEntry->IsPartitioned = FALSE; NewPartEntry->StartSector.QuadPart = (ULONGLONG)DiskEntry->SectorAlignment; NewPartEntry->SectorCount.QuadPart = AlignDown(DiskEntry->SectorCount.QuadPart, DiskEntry->SectorAlignment) - NewPartEntry->StartSector.QuadPart; DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart); DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1); DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; InsertTailList(&DiskEntry->PrimaryPartListHead, &NewPartEntry->ListEntry); return; } /* Start partition at head 1, cylinder 0 */ LastStartSector = DiskEntry->SectorAlignment; LastSectorCount = 0ULL; LastUnusedSectorCount = 0ULL; Entry = DiskEntry->PrimaryPartListHead.Flink; while (Entry != &DiskEntry->PrimaryPartListHead) { PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry); if (PartEntry->PartitionType != PARTITION_ENTRY_UNUSED || PartEntry->SectorCount.QuadPart != 0ULL) { LastUnusedSectorCount = PartEntry->StartSector.QuadPart - (LastStartSector + LastSectorCount); if (PartEntry->StartSector.QuadPart > (LastStartSector + LastSectorCount) && LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment) { DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount); NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); if (NewPartEntry == NULL) return; NewPartEntry->DiskEntry = DiskEntry; NewPartEntry->IsPartitioned = FALSE; NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount; NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) - NewPartEntry->StartSector.QuadPart; DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart); DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1); DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; /* Insert the table into the list */ InsertTailList(&PartEntry->ListEntry, &NewPartEntry->ListEntry); } LastStartSector = PartEntry->StartSector.QuadPart; LastSectorCount = PartEntry->SectorCount.QuadPart; } Entry = Entry->Flink; } /* Check for trailing unpartitioned disk space */ if ((LastStartSector + LastSectorCount) < DiskEntry->SectorCount.QuadPart) { LastUnusedSectorCount = AlignDown(DiskEntry->SectorCount.QuadPart - (LastStartSector + LastSectorCount), DiskEntry->SectorAlignment); if (LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment) { DPRINT1("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount); NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); if (NewPartEntry == NULL) return; NewPartEntry->DiskEntry = DiskEntry; NewPartEntry->IsPartitioned = FALSE; NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount; NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) - NewPartEntry->StartSector.QuadPart; DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart); DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1); DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; /* Append the table to the list */ InsertTailList(&DiskEntry->PrimaryPartListHead, &NewPartEntry->ListEntry); } } if (DiskEntry->ExtendedPartition != NULL) { if (IsListEmpty(&DiskEntry->LogicalPartListHead)) { DPRINT1("No logical partition!\n"); /* Create a partition table entry that represents the empty extended partition */ NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); if (NewPartEntry == NULL) return; NewPartEntry->DiskEntry = DiskEntry; NewPartEntry->LogicalPartition = TRUE; NewPartEntry->IsPartitioned = FALSE; NewPartEntry->StartSector.QuadPart = DiskEntry->ExtendedPartition->StartSector.QuadPart + (ULONGLONG)DiskEntry->SectorAlignment; NewPartEntry->SectorCount.QuadPart = DiskEntry->ExtendedPartition->SectorCount.QuadPart - (ULONGLONG)DiskEntry->SectorAlignment; DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart); DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1); DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; InsertTailList(&DiskEntry->LogicalPartListHead, &NewPartEntry->ListEntry); return; } /* Start partition at head 1, cylinder 0 */ LastStartSector = DiskEntry->ExtendedPartition->StartSector.QuadPart + (ULONGLONG)DiskEntry->SectorAlignment; LastSectorCount = 0ULL; LastUnusedSectorCount = 0ULL; Entry = DiskEntry->LogicalPartListHead.Flink; while (Entry != &DiskEntry->LogicalPartListHead) { PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry); if (PartEntry->PartitionType != PARTITION_ENTRY_UNUSED || PartEntry->SectorCount.QuadPart != 0ULL) { LastUnusedSectorCount = PartEntry->StartSector.QuadPart - (ULONGLONG)DiskEntry->SectorAlignment - (LastStartSector + LastSectorCount); if ((PartEntry->StartSector.QuadPart - (ULONGLONG)DiskEntry->SectorAlignment) > (LastStartSector + LastSectorCount) && LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment) { DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount); NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); if (NewPartEntry == NULL) return; NewPartEntry->DiskEntry = DiskEntry; NewPartEntry->LogicalPartition = TRUE; NewPartEntry->IsPartitioned = FALSE; NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount; NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) - NewPartEntry->StartSector.QuadPart; DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart); DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1); DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; /* Insert the table into the list */ InsertTailList(&PartEntry->ListEntry, &NewPartEntry->ListEntry); } LastStartSector = PartEntry->StartSector.QuadPart; LastSectorCount = PartEntry->SectorCount.QuadPart; } Entry = Entry->Flink; } /* Check for trailing unpartitioned disk space */ if ((LastStartSector + LastSectorCount) < DiskEntry->ExtendedPartition->StartSector.QuadPart + DiskEntry->ExtendedPartition->SectorCount.QuadPart) { LastUnusedSectorCount = AlignDown(DiskEntry->ExtendedPartition->StartSector.QuadPart + DiskEntry->ExtendedPartition->SectorCount.QuadPart - (LastStartSector + LastSectorCount), DiskEntry->SectorAlignment); if (LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment) { DPRINT("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount); NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); if (NewPartEntry == NULL) return; NewPartEntry->DiskEntry = DiskEntry; NewPartEntry->LogicalPartition = TRUE; NewPartEntry->IsPartitioned = FALSE; NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount; NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) - NewPartEntry->StartSector.QuadPart; DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart); DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1); DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; /* Append the table to the list */ InsertTailList(&DiskEntry->LogicalPartListHead, &NewPartEntry->ListEntry); } } } DPRINT("ScanForUnpartitionedDiskSpace() done\n"); }