void AddressSpace::delRMem(VAddr begVAddr, VAddr endVAddr){ begVAddr=alignDown(begVAddr,getPageSize()); endVAddr=alignUp(endVAddr,getPageSize()); RAddr begRAddr=pageTable[getVPage(begVAddr)]; free((void *)begRAddr); for(VAddr pageNum=getVPage(begVAddr);pageNum!=getVPage(endVAddr);pageNum++){ if(pageTable[pageNum]!=begRAddr+(pageNum*getPageSize()-begVAddr)) fatal("AddressSpace::delRMem region not allocated contiguously"); pageTable[pageNum]=0; } }
void AddressSpace::newRMem(VAddr begVAddr, VAddr endVAddr){ begVAddr=alignDown(begVAddr,getPageSize()); endVAddr=alignUp(endVAddr,getPageSize()); void *realMem; if(posix_memalign(&realMem,getPageSize(),endVAddr-begVAddr)) fatal("AddressSpace::newRMem could not allocate memory\n"); for(size_t pageNum=getVPage(begVAddr);pageNum!=getVPage(endVAddr);pageNum++){ if(pageTable[pageNum]) fatal("AddressSpace::newRMem region overlaps with existing memory"); pageTable[pageNum]=(RAddr)realMem+(pageNum*getPageSize()-begVAddr); } }
int FilePageStore::_determinePageCount() { if(_fseeki64(_pageFile, 0, SEEK_END) == 0) { __int64 fileSize64 = _ftelli64(_pageFile); assert(fileSize64 % (__int64)getPageSize() == 0); return (int)(fileSize64 / (__int64)getPageSize()); } else { throw Tgs::Exception(_getError("Error in determining page count")); } return 0; }
qreal ReportPageOptions::heightPx() { int pageHeight; if (isPortrait()) { pageHeight = KoPageFormat::height(KoPageFormat::formatFromString(getPageSize()), KoPageFormat::Portrait); } else { pageHeight = KoPageFormat::height(KoPageFormat::formatFromString(getPageSize()), KoPageFormat::Landscape); } KoUnit pageUnit(KoUnit::Millimeter); pageHeight = KoUnit::toInch(pageUnit.fromUserValue(pageHeight)) * KoDpi::dpiY(); return pageHeight; }
VAddr AddressSpace::findVMemLow(size_t memSize){ size_t needPages=alignUp(memSize,getPageSize())/getPageSize(); size_t foundPages=0; // Skip the first (zero) page, to avoid making null pointers valid size_t pageNum=1; while(foundPages<needPages){ if(pageTable[pageNum]) foundPages=0; else foundPages++; pageNum++; if(pageNum==pageTable.size()) fatal("AddressSpace::findVMemLow not enough available virtual memory\n"); } return (pageNum-needPages)*getPageSize(); }
bool IOMapper::start(IOService *provider) { OSObject * obj; if (!super::start(provider)) return false; if (!initHardware(provider)) return false; fPageSize = getPageSize(); if (fIsSystem) { sMapperLock.lock(); IOMapper::gSystem = this; sMapperLock.wakeup(&IOMapper::gSystem); sMapperLock.unlock(); } if (provider) { obj = provider->getProperty("iommu-id"); if (!obj) obj = provider->getProperty("AAPL,phandle"); if (obj) setProperty(gIOMapperIDKey, obj); } return true; }
boolean RingBuffer::read(uint8_t page[], size_t size) { uint16_t head = getHead(); uint16_t tail = getTail(); uint16_t pageSize = getPageSize(); boolean retVal = false; if (getFlipMarker() == 0) { if (tail < head) { readPage(tail,pageSize,page,size); retVal = true; } } else { if (tail + pageSize > bootSectorStart) { tail = startData; setTail(tail); setFlipMarker(0x00); if (tail < head) { readPage(tail,pageSize,page,size); retVal = true; } } else { readPage(tail,pageSize,page,size); retVal = true; } } return retVal; }
boolean RingBuffer::write(uint8_t page[], size_t size) { uint16_t head = getHead(); uint16_t tail = getTail(); uint16_t pageSize = getPageSize(); boolean retVal = false; // check, if we wrapped if (getFlipMarker() == 0) { if (head + pageSize > bootSectorStart) { // we reached the end of the memory, go to start and flip marker head = startData; setHead(head); setFlipMarker(0xFF); if (head + pageSize < tail) { // there is some space, write the page writePage(head,pageSize,page,size); retVal = true; } } else { // there is some space, write the page writePage(head,pageSize,page,size); retVal = true; } } else { if (head < tail) { // we have some sapace left writePage(head,pageSize,page,size); retVal = true; } } return retVal; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU_DUMPINFO2, "_dmsStorageUnit::dumpInfo" ) void _dmsStorageUnit::dumpInfo ( set<_monStorageUnit> &storageUnitList, BOOLEAN sys ) { monStorageUnit su ; const dmsStorageUnitHeader *dataHeader = _pDataSu->getHeader() ; PD_TRACE_ENTRY ( SDB__DMSSU_DUMPINFO2 ) ; if ( !sys && dmsIsSysCSName( CSName() ) ) { goto done ; } ossMemset ( su._name, 0, sizeof ( su._name ) ) ; ossStrncpy ( su._name, CSName(), DMS_SU_NAME_SZ ) ; su._pageSize = getPageSize() ; su._lobPageSize = getLobPageSize() ; su._sequence = CSSequence() ; su._numCollections = dataHeader->_numMB ; su._collectionHWM = dataHeader->_MBHWM ; su._size = totalSize() ; su._CSID = CSID() ; su._logicalCSID = LogicalCSID() ; storageUnitList.insert ( su ) ; done : PD_TRACE_EXIT ( SDB__DMSSU_DUMPINFO2 ) ; }
/* Returns 0 if physical memory size cannot be identified */ StgWord64 getPhysicalMemorySize (void) { static StgWord64 physMemSize = 0; if (!physMemSize) { #if defined(darwin_HOST_OS) || defined(ios_HOST_OS) /* So, darwin doesn't support _SC_PHYS_PAGES, but it does support getting the raw memory size in bytes through sysctlbyname(hw.memsize); */ size_t len = sizeof(physMemSize); int ret = -1; /* Note hw.memsize is in bytes, so no need to multiply by page size. */ ret = sysctlbyname("hw.memsize", &physMemSize, &len, NULL, 0); if (ret == -1) { physMemSize = 0; return 0; } #else /* We'll politely assume we have a system supporting _SC_PHYS_PAGES * otherwise. */ W_ pageSize = getPageSize(); long ret = sysconf(_SC_PHYS_PAGES); if (ret == -1) { #if defined(DEBUG) errorBelch("warning: getPhysicalMemorySize: cannot get " "physical memory size"); #endif return 0; } physMemSize = ret * pageSize; #endif /* darwin_HOST_OS */ } return physMemSize; }
void Scrollbar::setValue(int value) { XOJ_CHECK_TYPE(Scrollbar); if (value < gtk_adjustment_get_lower(this->adj)) { value = gtk_adjustment_get_lower(this->adj); } if (value > getMax() - getPageSize()) { value = getMax() - getPageSize(); } gtk_adjustment_set_value(this->adj, value); this->value = value; gtk_widget_set_visible(this->getWidget(), this->getPageSize() < this->getMax()); }
bool ProcessInfo::blockInMemory(const void* start) { unsigned char x = 0; if (mincore(const_cast<void*>(alignToStartOfPage(start)), getPageSize(), &x)) { log() << "mincore failed: " << errnoWithDescription() << endl; return 1; } return x & 0x1; }
VAddr AddressSpace::findVMemHigh(size_t memSize){ size_t needPages=alignUp(memSize,getPageSize())/getPageSize(); size_t foundPages=0; // Skip the last page, it creates addressing problems // becasue its upper-bound address is 0 due to wrap-around size_t pageNum=pageTable.size()-1; while(foundPages<needPages){ pageNum--; // Can not use page zero because that would make the null pointer valid if(pageNum==0) fatal("AddressSpace::findVMemLow not enough available virtual memory\n"); if(pageTable[pageNum]){ foundPages=0; }else{ foundPages++; } } return pageNum*getPageSize(); }
int _start(int argc, void* argv) { printf("Free memory information\n"); MEM_LOC free_frames = getNumberOfFreeFrames(); MEM_LOC page_size = getPageSize(); printf("%i free frames of memory\n", free_frames); printf("Each frame is %i bytes of memory\n", page_size); printf("Therefore there are %i MBs of memory left\n", (free_frames * page_size) / 1024 / 1024); exit(0); }
bool ProcessInfo::pagesInMemory(const void* start, size_t numPages, vector<char>* out) { out->resize(numPages); if (mincore(alignToStartOfPage(start), numPages * getPageSize(), &out->front())) { log() << "mincore failed: " << errnoWithDescription() << endl; return false; } for (size_t i = 0; i < numPages; ++i) { (*out)[i] &= 0x1; } return true; }
ChunkAllocator(size_t chunkSize) : m_ChunkSize(chunkSize), m_AvailableSlots(ChunkAllocatorBlocks), m_pData((char*) malloc(getAllocationSize(chunkSize))) { assert(PAGE_SIZE == (size_t) getPageSize()); memset(m_UsedSlot, false, ChunkAllocatorBlocks); char* pBlockStart = reinterpret_cast<char*>(upperPage(reinterpret_cast<size_t>(m_pData))); const size_t realChunkSize = getChunkSize(chunkSize); for (int i = 0; i < ChunkAllocatorBlocks; ++i) { m_SlotData[i] = pBlockStart; Sentinel *pSentinel = getSentinelFromBlockStart(pBlockStart); pSentinel->pAllocator = this; pSentinel->magic = 0xDEADC0DE; pBlockStart += realChunkSize; } }
void AssemblerBuffer::reserve(uint32_t size) { if (size > allocatedSize) { void* oldAllocatedMemory = allocatedMemory; uint32_t oldAllocatedSize = allocatedSize; uint32_t alignment = getPageSize(); allocatedSize = std::max<uint32_t>(1024, std::max(2 * allocatedSize, ((size + alignment - 1) / alignment) * alignment)); allocatedMemory = allocateMemory(allocatedSize); if (oldAllocatedMemory) { memcpy(allocatedMemory, oldAllocatedMemory, usedSize); freeMemory(oldAllocatedMemory, oldAllocatedSize); } } }
void setExecutable (void *p, W_ len, rtsBool exec) { StgWord pageSize = getPageSize(); /* malloced memory isn't executable by default on OpenBSD */ StgWord mask = ~(pageSize - 1); StgWord startOfFirstPage = ((StgWord)p ) & mask; StgWord startOfLastPage = ((StgWord)p + len - 1) & mask; StgWord size = startOfLastPage - startOfFirstPage + pageSize; if (mprotect((void*)startOfFirstPage, (size_t)size, (exec ? PROT_EXEC : 0) | PROT_READ | PROT_WRITE) != 0) { barf("setExecutable: failed to protect 0x%p\n", p); } }
boolean RingBuffer::isFull() { uint16_t head = getHead(); uint16_t tail = getTail(); uint16_t pageSize = getPageSize(); boolean retVal = false; if (getFlipMarker() == 0) { if (head + pageSize > bootSectorStart && startData + pageSize >= tail) { retVal = false; } } else{ retVal = head >= tail; } return retVal; }
void AP_UnixDialog_PageSetup::runModal (XAP_Frame *pFrame) { UT_return_if_fail(pFrame); // snarf the parent pagesize. m_PageSize = getPageSize(); m_pFrame = pFrame; // Build the window's widgets and arrange them GtkWidget * mainWindow = _constructWindow(); UT_return_if_fail(mainWindow); m_PageSize = getPageSize(); _updatePageSizeList(); switch(abiRunModalDialog(GTK_DIALOG(mainWindow), pFrame, this, BUTTON_CANCEL, false)) { case BUTTON_OK: event_OK() ; break; default: event_Cancel() ; break ; } abiDestroyWidget ( mainWindow ) ; }
void VMHeap::initialize() { // Get the page size. pageSize = getPageSize(); // Allocate the virtual address space. maxCapacity = DefaultMaxVMHeapSize; capacity = 0; size = 0; addressSpace = reserveVirtualAddressSpace(maxCapacity); if(!addressSpace) { fprintf(stderr, "Failed to reserve the VM heap memory address space.\n"); abort(); } }
bool ProcessInfo::pagesInMemory(const void* start, size_t numPages, vector<char>* out) { out->resize(numPages); scoped_array<PSAPI_WORKING_SET_EX_INFORMATION> wsinfo( new PSAPI_WORKING_SET_EX_INFORMATION[numPages]); const void* startOfFirstPage = alignToStartOfPage(start); for (size_t i = 0; i < numPages; i++) { wsinfo[i].VirtualAddress = reinterpret_cast<void*>( reinterpret_cast<unsigned long long>(startOfFirstPage) + i * getPageSize()); } BOOL result = psapiGlobal->QueryWSEx(GetCurrentProcess(), wsinfo.get(), sizeof(PSAPI_WORKING_SET_EX_INFORMATION) * numPages); if (!result) return false; for (size_t i = 0; i < numPages; ++i) { (*out)[i] = wsinfo[i].VirtualAttributes.Valid ? 1 : 0; } return true; }
AdjustorWritable allocateExec (W_ bytes, AdjustorExecutable *exec_ret) { void *ret; W_ n; ACQUIRE_SM_LOCK; // round up to words. n = (bytes + sizeof(W_) + 1) / sizeof(W_); if (n+1 > BLOCK_SIZE_W) { barf("allocateExec: can't handle large objects"); } if (exec_block == NULL || exec_block->free + n + 1 > exec_block->start + BLOCK_SIZE_W) { bdescr *bd; W_ pagesize = getPageSize(); bd = allocGroup(stg_max(1, pagesize / BLOCK_SIZE)); debugTrace(DEBUG_gc, "allocate exec block %p", bd->start); bd->gen_no = 0; bd->flags = BF_EXEC; bd->link = exec_block; if (exec_block != NULL) { exec_block->u.back = bd; } bd->u.back = NULL; setExecutable(bd->start, bd->blocks * BLOCK_SIZE, rtsTrue); exec_block = bd; } *(exec_block->free) = n; // store the size of this chunk exec_block->gen_no += n; // gen_no stores the number of words allocated ret = exec_block->free + 1; exec_block->free += n + 1; RELEASE_SM_LOCK *exec_ret = ret; return ret; }
/********************************************************** * Verify that the flash is cleared. To save time * we only check the first word on every page. * this could be modified to check every word. **********************************************************/ void verifyFlashIsErased(void) { printf("Verifying that flash is erased\n"); uint32_t addr = 0; uint32_t value; /* Get flash page size and total size from the target DI page */ int flashSize = getFlashSize(); int pageSize = getPageSize(); while ( addr < flashSize ) { value = readMem(addr); if ( value != 0xFFFFFFFF ) { printf("Error at address 0x%.8x\n" "Value should be 0xFFFFFFFF, is 0x%.8x\n", addr, value); RAISE(SWD_ERROR_DEVICE_ERASE_FAILED); } addr += pageSize; } }
AddressSpace::AddressSpace(void) // Allocate the entire page table and zero it out : pageTable((1<<2)*((1<<(8*sizeof(VAddr)-2))/getPageSize()),0){ }
int TerrainPage::getNumberOfSegmentsPerAxis() const { return (getPageSize() - 1) / 64; }
int TerrainPage::getVerticeCount() const { return (getPageSize() * getPageSize()); }
TerrainPage::TerrainPage(const TerrainIndex& index, int pageSize, ICompilerTechniqueProvider& compilerTechniqueProvider) : mIndex(index), mPageSize(pageSize), mPosition(index.first, index.second), mTerrainSurface(new TerrainPageSurface(*this, compilerTechniqueProvider)), mExtent(WFMath::Point<2>(mPosition.x() * (getPageSize() - 1), (mPosition.y() - 1) * (getPageSize() - 1)), WFMath::Point<2>((mPosition.x() + 1) * (getPageSize() - 1), (mPosition.y()) * (getPageSize() - 1))) { S_LOG_VERBOSE("Creating TerrainPage at position " << index.first << ":" << index.second); }
char* MemoryMapping::map(char* buffer, int buffersize, FILE* file, int offset) { #ifdef _MSC_VER HANDLE filehandle = (HANDLE) _get_osfhandle(FILENO(file)); HANDLE filemapping = ::CreateFileMappingA( filehandle, &MMAP_SECURITY_ATTRIBUTES, PAGE_READONLY | SEC_COMMIT, 0, 0, 0); if (0 == filemapping) return MAP_FAILED; DWORD alignedoffset = (offset / getPageSize()) * getPageSize(); DWORD alignment = offset - alignedoffset; LPVOID mappedmemory = ::MapViewOfFile( filemapping, FILE_MAP_READ, 0, alignedoffset, 0); ::CloseHandle(filemapping); if (0 != mappedmemory) { return ((char*) mappedmemory) + alignment; } else { return 0; } #else int filehandle = FILENO(file); int protection = PROT_READ; int flags = MAP_PRIVATE; int alignedoffset = (offset / getpagesize()) * getpagesize(); int alignment = offset - alignedoffset; int alignedlength = ((buffersize / getpagesize()) + 1) * getpagesize(); char* result = (char*) ::mmap( (void*) buffer, alignedlength, protection, flags, filehandle, alignedoffset); return ((char*) -1) == result ? 0 : result + alignment; #endif }
void julia_init(char *imageFile) { jl_page_size = getPageSize(); jl_find_stack_bottom(); jl_dl_handle = jl_load_dynamic_library(NULL); #ifdef __WIN32__ uv_dlopen("ntdll.dll",jl_ntdll_handle); //bypass julia's pathchecking for system dlls uv_dlopen("Kernel32.dll",jl_kernel32_handle); uv_dlopen("msvcrt.dll",jl_crtdll_handle); uv_dlopen("Ws2_32.dll",jl_winsock_handle); _jl_exe_handle.handle = GetModuleHandleA(NULL); #endif jl_io_loop = uv_default_loop(); //this loop will internal events (spawining process etc.) init_stdio(); #if defined(__linux__) int ncores = jl_cpu_cores(); if (ncores > 1) { cpu_set_t cpumask; CPU_ZERO(&cpumask); for(int i=0; i < ncores; i++) { CPU_SET(i, &cpumask); } sched_setaffinity(0, sizeof(cpu_set_t), &cpumask); } #endif #ifdef JL_GC_MARKSWEEP jl_gc_init(); jl_gc_disable(); #endif jl_init_frontend(); jl_init_types(); jl_init_tasks(jl_stack_lo, jl_stack_hi-jl_stack_lo); jl_init_codegen(); jl_an_empty_cell = (jl_value_t*)jl_alloc_cell_1d(0); jl_init_serializer(); if (!imageFile) { jl_main_module = jl_new_module(jl_symbol("Main")); jl_main_module->parent = jl_main_module; jl_core_module = jl_new_module(jl_symbol("Core")); jl_core_module->parent = jl_main_module; jl_set_const(jl_main_module, jl_symbol("Core"), (jl_value_t*)jl_core_module); jl_module_using(jl_main_module, jl_core_module); jl_current_module = jl_core_module; jl_init_intrinsic_functions(); jl_init_primitives(); jl_load("boot.jl"); jl_get_builtin_hooks(); jl_boot_file_loaded = 1; jl_init_box_caches(); } if (imageFile) { JL_TRY { jl_restore_system_image(imageFile); } JL_CATCH { JL_PRINTF(JL_STDERR, "error during init:\n"); jl_show(jl_stderr_obj(), jl_exception_in_transit); JL_PRINTF(JL_STDOUT, "\n"); jl_exit(1); } } // set module field of primitive types int i; void **table = jl_core_module->bindings.table; for(i=1; i < jl_core_module->bindings.size; i+=2) { if (table[i] != HT_NOTFOUND) { jl_binding_t *b = (jl_binding_t*)table[i]; if (b->value && jl_is_some_tag_type(b->value)) { jl_tag_type_t *tt = (jl_tag_type_t*)b->value; tt->name->module = jl_core_module; } } } // the Main module is the one which is always open, and set as the // current module for bare (non-module-wrapped) toplevel expressions. // it does "using Base" if Base is available. if (jl_base_module != NULL) { jl_add_standard_imports(jl_main_module); } // eval() uses Main by default, so Main.eval === Core.eval jl_module_import(jl_main_module, jl_core_module, jl_symbol("eval")); jl_current_module = jl_main_module; #ifndef __WIN32__ struct sigaction actf; memset(&actf, 0, sizeof(struct sigaction)); sigemptyset(&actf.sa_mask); actf.sa_handler = fpe_handler; actf.sa_flags = 0; if (sigaction(SIGFPE, &actf, NULL) < 0) { JL_PRINTF(JL_STDERR, "sigaction: %s\n", strerror(errno)); jl_exit(1); } stack_t ss; ss.ss_flags = 0; ss.ss_size = SIGSTKSZ; ss.ss_sp = malloc(ss.ss_size); if (sigaltstack(&ss, NULL) < 0) { JL_PRINTF(JL_STDERR, "sigaltstack: %s\n", strerror(errno)); jl_exit(1); } struct sigaction act; memset(&act, 0, sizeof(struct sigaction)); sigemptyset(&act.sa_mask); act.sa_sigaction = segv_handler; act.sa_flags = SA_ONSTACK | SA_SIGINFO; if (sigaction(SIGSEGV, &act, NULL) < 0) { JL_PRINTF(JL_STDERR, "sigaction: %s\n", strerror(errno)); jl_exit(1); } #else if (signal(SIGFPE, (void (__cdecl *)(int))fpe_handler) == SIG_ERR) { JL_PRINTF(JL_STDERR, "Couldn't set SIGFPE\n"); jl_exit(1); } #endif #ifdef JL_GC_MARKSWEEP jl_gc_enable(); #endif }