void PixelBuffer::fill ( const vec2& pos, const vec2& size, const vec4& color ) { cgeAssert( S ); SDL_Rect r; unmap(pos,r.x,r.y); unmap(size,r.w,r.h); SDL_FillRect(S,&r,col2int_(color)); }
void resolve_derived_copies(CommPtr comm, Read<GO> verts2globs, Int deg, LOs* p_ent_verts2verts, Remotes* p_ents2owners) { auto ev2v = *p_ent_verts2verts; auto ev2vg = unmap(ev2v, verts2globs, 1); auto canon_codes = get_codes_to_canonical(deg, ev2vg); auto ev2v_canon = align_ev2v(deg, ev2v, canon_codes); *p_ent_verts2verts = ev2v_canon; auto ev2vg_canon = align_ev2v(deg, ev2vg, canon_codes); auto e2fv = get_component(ev2v_canon, deg, 0); auto total_verts = find_total_globals(comm, verts2globs); auto v2ov = globals_to_linear_owners(comm, verts2globs, total_verts); auto e2ov = unmap(e2fv, v2ov); auto linsize = linear_partition_size(comm, total_verts); auto in_dist = Dist(comm, e2ov, linsize); auto sev2vg = in_dist.exch(ev2vg_canon, deg); auto out_dist = in_dist.invert(); auto sv2svse = out_dist.roots2items(); auto nse = out_dist.nitems(); auto svse2se = LOs(nse, 0, 1); auto sv2se_codes = Read<I8>(nse, make_code(false, 0, 0)); auto sv2se = Adj(sv2svse, svse2se, sv2se_codes); auto se2fsv = invert_fan(sv2svse); LOs se2ose; Read<I8> se2ose_codes; find_matches_ex(deg, se2fsv, sev2vg, sev2vg, sv2se, &se2ose, &se2ose_codes); auto ose2oe = out_dist.items2dests(); auto se2oe = unmap(se2ose, ose2oe); out_dist.set_roots2items(LOs()); auto e2oe = out_dist.exch(se2oe, 1); *p_ents2owners = e2oe; }
void Bus::updateBiosGG() { unmap(0x00, 0x03, 0); unmap(0x00, 0x03, 1); if ( ( (port_3e & 0x08) == 0 ) && biosDetected ) { map(0x00, 0x03, *slot[S_Bios].access); } else if (romDetected) { map(0x00, 0x03, *slot[S_Cartridge].access); } }
void GRectMapper::unmap(GRect &rect) { unmap(rect.xmin, rect.ymin); unmap(rect.xmax, rect.ymax); if (rect.xmin >= rect.xmax) iswap(rect.xmin, rect.xmax); if (rect.ymin >= rect.ymax) iswap(rect.ymin, rect.ymax); }
Remotes unmap_owners( Mesh* old_mesh, Int ent_dim, LOs new_ents2old_ents, LOs old_ents2new_ents) { auto old_copies2old_owners = old_mesh->ask_dist(ent_dim); auto old_owners2old_copies = old_copies2old_owners.invert(); auto old_copies2new_owners = old_owners2old_copies.exch(old_ents2new_ents, 1); auto new_ents2new_owners = unmap(new_ents2old_ents, old_copies2new_owners, 1); auto old_own_ranks = old_mesh->ask_owners(ent_dim).ranks; auto new_own_ranks = unmap(new_ents2old_ents, old_own_ranks, 1); return Remotes(new_own_ranks, new_ents2new_owners); }
//most likely same bug as in test_strange_map, but looked different in fuzzer (sefault instead of assertion fail) static void test_assertion_fail(void **state){ uc_engine *uc = *state; map(uc,0x2000,0x4000); //5 unmap(uc,0x3000,0x2000); //11 map(uc,0x0,0x2000); //23 map(uc,0x3000,0x2000); //24 map(uc,0x9000,0x4000); //32 map(uc,0x8000,0x1000); //34 unmap(uc,0x1000,0x4000); //35 }
static void test_bad_offset(void **state){ uc_engine *uc = *state; map(uc,0x9000,0x4000); //17 map(uc,0x4000,0x2000); //32 unmap(uc,0x5000,0x1000); //35 map(uc,0x0,0x1000); //42 map(uc,0x5000,0x4000); //51 map(uc,0x2000,0x1000); //53 map(uc,0x1000,0x1000); //55 unmap(uc,0x7000,0x3000); //58 unmap(uc,0x5000,0x1000); //59 unmap(uc,0x4000,0x2000); //70 }
int main(int argc, char ** argv) { int base_nr; test_init(argc, argv); hpage_size = check_hugepagesize(); saved_nr_hugepages = get_huge_page_counter(hpage_size, HUGEPAGES_TOTAL); verify_dynamic_pool_support(); check_must_be_root(); if ((private_resv = kernel_has_private_reservations()) == -1) FAIL("kernel_has_private_reservations() failed\n"); /* * This test case should require a maximum of 3 huge pages. * Run through the battery of tests multiple times, with an increasing * base pool size. This alters the circumstances under which surplus * pages need to be allocated and increases the corner cases tested. */ for (base_nr = 0; base_nr <= 3; base_nr++) { verbose_printf("Base pool size: %i\n", base_nr); /* Run the tests with a clean slate */ run_test("Clean", base_nr); /* Now with a pre-existing untouched, shared mmap */ map(SL_SETUP, 1, MAP_SHARED); run_test("Untouched, shared", base_nr); unmap(SL_SETUP, 1, MAP_SHARED); /* Now with a pre-existing untouched, private mmap */ map(SL_SETUP, 1, MAP_PRIVATE); run_test("Untouched, private", base_nr); unmap(SL_SETUP, 1, MAP_PRIVATE); /* Now with a pre-existing touched, shared mmap */ map(SL_SETUP, 1, MAP_SHARED); touch(SL_SETUP, 1, MAP_SHARED); run_test("Touched, shared", base_nr); unmap(SL_SETUP, 1, MAP_SHARED); /* Now with a pre-existing touched, private mmap */ map(SL_SETUP, 1, MAP_PRIVATE); touch(SL_SETUP, 1, MAP_PRIVATE); run_test("Touched, private", base_nr); unmap(SL_SETUP, 1, MAP_PRIVATE); } PASS(); }
void unmap_down(Mesh* old_mesh, Mesh* new_mesh, Int ent_dim, LOs new_ents2old_ents, LOs old_lows2new_lows) { auto deg = simplex_degrees[ent_dim][ent_dim - 1]; auto old_ents2old_lows = old_mesh->ask_down(ent_dim, ent_dim - 1); auto oel2ol = old_ents2old_lows.ab2b; auto oe2l_codes = old_ents2old_lows.codes; auto nel2ol = unmap(new_ents2old_ents, oel2ol, deg); auto nel2nl = compound_maps(nel2ol, old_lows2new_lows); auto new_ents2new_lows = Adj(nel2nl); if (oe2l_codes.exists()) { auto ne2l_codes = unmap(new_ents2old_ents, oe2l_codes, deg); new_ents2new_lows.codes = ne2l_codes; } new_mesh->set_ents(ent_dim, new_ents2new_lows); }
void Image11::loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, const void *input) { ASSERT(xoffset % 4 == 0); ASSERT(yoffset % 4 == 0); D3D11_MAPPED_SUBRESOURCE mappedImage; ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); D3D11_MAP mapType = D3D11_MAP_WRITE; if (dxContext->GetType() == D3D11_DEVICE_CONTEXT_DEFERRED) { mapType = D3D11_MAP_WRITE_DISCARD; } HRESULT result = map(mapType, &mappedImage); if (FAILED(result)) { ERR("Could not map image for loading."); return; } // Size computation assumes a 4x4 block compressed texture format size_t blockSize = d3d11::ComputeBlockSizeBits(mDXGIFormat) / 8; void* offsetMappedData = (void*)((BYTE *)mappedImage.pData + ((yoffset / 4) * mappedImage.RowPitch + (xoffset / 4) * blockSize)); GLsizei inputSize = gl::ComputeCompressedSize(width, height, mInternalFormat); GLsizei inputPitch = gl::ComputeCompressedPitch(width, mInternalFormat); int rows = inputSize / inputPitch; for (int i = 0; i < rows; ++i) { memcpy((void*)((BYTE*)offsetMappedData + i * mappedImage.RowPitch), (void*)((BYTE*)input + i * inputPitch), inputPitch); } unmap(); }
void Bus::mapSram(u8 bankLo, u8 bankHi, Slot _slot, unsigned offset) { if (_slot == S_Cartridge && sram.size() != 0) { map(bankLo, bankHi, sram, offset ); } else { unmap( bankLo, bankHi, _slot == S_Cartridge ? 0 : 1 ); } }
/** * Releases the mapping by calling unmap(). Will never throw. * Call unmap() instead if you want to be notified of any error. */ ~MemoryMapping() noexcept { try { unmap(); } catch (const std::system_error&) { // Ignore any exceptions because destructor must not throw. } }
~CLBuffer() { if (map_count != 0) { unmap(); } clReleaseMemObject(mem); }
void video_gbuffer::update() { if (!has_new_buffer_) return; EnterCriticalSection(&cs_); { if (external_callback_) { DirectX::XMFLOAT2 s = target(RT_VIDEO_COLOR)->size(); external_callback_(&temp_buffer_[0], static_cast<size_t>(s.x), static_cast<size_t>(s.y)); } auto rtarget = target(RT_VIDEO_COLOR); void* p = rtarget->map(context_); if (p) { // TODO: if pitch is negative, flip BYTE* out = reinterpret_cast<BYTE*>(p); std::memcpy(out, &temp_buffer_[0], temp_buffer_.size()); rtarget->unmap(context_); } } has_new_buffer_ = false; LeaveCriticalSection(&cs_); }
void* GLVertexBuffer::map() { if(access() == None) { log_error("GLVertexBuffer: trying to map buffer with access = None"); return 0; } if(mMaped) unmap(); GLenum gl_acess = GL_READ_ONLY; switch (access()) { case GraphicBuffer::ReadOnly: gl_acess = GL_READ_ONLY; break; case GraphicBuffer::ReadWrite: gl_acess = GL_READ_WRITE; break; case GraphicBuffer::WriteOnly: gl_acess = GL_WRITE_ONLY; break; default: break; } glBindBuffer(GL_ARRAY_BUFFER, mId); void* p = CHECK_GL_CALL(glMapBuffer(GL_ARRAY_BUFFER, gl_acess)); if(p) mMaped = true; return p; }
void block_free(byte *block, size_t size) { unsigned int space_nr = SPACE(block); unsigned int block_nr = BLOCK_NR(block); size_t blocks = BLOCKS(size); byte *block_map = SPACE_MAP(space_nr); int i; int ok = 1; for(i=0; i<blocks; ++i) block_map[block_nr+i] = TYPE_FREE; /* See if we can free the entire space */ for (i=0; i<BLOCKS_PER_SPACE; i++) { if (block_map[i] != TYPE_FREE) { ok = 0; break; } } unmap(block, GRAINROUND(page_size, size)); if (ok) { /* Free the entire space */ release_arena_space(space_nr); } }
Process:: ~Process() { #ifdef VERBOSE esReport("Process::~Process %p\n", this); #endif setInput(0); setOutput(0); setError(0); setRoot(0); for (SyscallProxy* proxy(syscallTable); proxy < &syscallTable[INTERFACE_POINTER_MAX]; ++proxy) { proxy->addRef(); while (0 < proxy->release()) ; } while (!upcallList.isEmpty()) { upcallCount.decrement(); UpcallRecord* record(upcallList.removeFirst()); delete record; } ASSERT(upcallCount == 0); ASSERT(threadList.isEmpty()); unmap(USER_MIN, static_cast<u8*>(USER_MAX) - static_cast<u8*>(USER_MIN)); ASSERT(mmu); delete mmu; }
bool LLPluginSharedMemory::destroy(void) { unmap(); close(); return true; }
// Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input // into the target pixel rectangle. gl::Error Image11::loadData(const gl::Box &area, const gl::PixelUnpackState &unpack, GLenum type, const void *input) { const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(mInternalFormat); GLsizei inputRowPitch = formatInfo.computeRowPitch(type, area.width, unpack.alignment, unpack.rowLength); GLsizei inputDepthPitch = formatInfo.computeDepthPitch( type, area.width, area.height, unpack.alignment, unpack.rowLength, unpack.imageHeight); GLsizei inputSkipBytes = formatInfo.computeSkipPixels( inputRowPitch, inputDepthPitch, unpack.skipImages, unpack.skipRows, unpack.skipPixels); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mDXGIFormat); GLuint outputPixelSize = dxgiFormatInfo.pixelBytes; const d3d11::TextureFormat &d3dFormatInfo = d3d11::GetTextureFormatInfo(mInternalFormat, mRenderer->getRenderer11DeviceCaps()); LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions.at(type).loadFunction; D3D11_MAPPED_SUBRESOURCE mappedImage; gl::Error error = map(D3D11_MAP_WRITE, &mappedImage); if (error.isError()) { return error; } uint8_t *offsetMappedData = (reinterpret_cast<uint8_t*>(mappedImage.pData) + (area.y * mappedImage.RowPitch + area.x * outputPixelSize + area.z * mappedImage.DepthPitch)); loadFunction(area.width, area.height, area.depth, reinterpret_cast<const uint8_t *>(input) + inputSkipBytes, inputRowPitch, inputDepthPitch, offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch); unmap(); return gl::Error(GL_NO_ERROR); }
// Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input // into the target pixel rectangle. gl::Error Image11::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLint unpackAlignment, GLenum type, const void *input) { const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(mInternalFormat); GLsizei inputRowPitch = formatInfo.computeRowPitch(type, width, unpackAlignment); GLsizei inputDepthPitch = formatInfo.computeDepthPitch(type, width, height, unpackAlignment); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mDXGIFormat); GLuint outputPixelSize = dxgiFormatInfo.pixelBytes; const d3d11::TextureFormat &d3dFormatInfo = d3d11::GetTextureFormatInfo(mInternalFormat); LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions.at(type); D3D11_MAPPED_SUBRESOURCE mappedImage; gl::Error error = map(D3D11_MAP_WRITE, &mappedImage); if (error.isError()) { return error; } uint8_t* offsetMappedData = (reinterpret_cast<uint8_t*>(mappedImage.pData) + (yoffset * mappedImage.RowPitch + xoffset * outputPixelSize + zoffset * mappedImage.DepthPitch)); loadFunction(width, height, depth, reinterpret_cast<const uint8_t*>(input), inputRowPitch, inputDepthPitch, offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch); unmap(); return gl::Error(GL_NO_ERROR); }
void GpuPixelBuffer::upload(uint32_t x, uint32_t y, uint32_t width, uint32_t height, int offset) { // If the buffer is not mapped, unmap() will not bind it mCaches.bindPixelBuffer(mBuffer); unmap(); glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, mFormat, GL_UNSIGNED_BYTE, (void*) offset); }
void tr_natpmpRemoveForwarding( tr_natpmp_t * pmp ) { tr_inf( "nat-pmp unset port" ); pmp->newport = -1; unmap( pmp ); }
bool MemoryMap::map( int length ) { // FIXME hacky shit. if(_map) unmap(); _length = length; // check if we are writing if(_flags == MMAP_READWRITE) { // write end char to end of file char endchar='\0'; lseek(_handle, length-1, SEEK_SET); write(_handle, &endchar, 1); if((_map = (char*)mmap(0, length, PROT_WRITE, MAP_SHARED, _handle, 0)) == (char *)-1) { debugPrint( "Could not map output file\n"); return false; } return true; } _map = (char *)mmap(0, length, PROT_READ, MAP_SHARED, _handle, 0); if (_map == MAP_FAILED) return false; _length = length; return true; }
void test_spec3(Map *maps, int map_n) { for (int i = 0; i < map_n; i++) init(&maps[i]); int cmds, mid, cmd, key; char val[128]; int keylist[1024]; scanf("%d", &cmds); for (int i = 0; i < cmds; i++) { scanf("%d", &cmd); if (cmd == 1) { scanf("%d", &mid); print(&maps[mid]); } else if (cmd == 2) { scanf("%d %d %s", &mid, &key, val); int f = map(&maps[mid], key, val); printf("mf %d\n", f); } else if (cmd == 3) { scanf("%d %d", &mid, &key); int f = unmap(&maps[mid], key); printf("uf %d\n", f); } else if (cmd == 4) { scanf("%d %s", &mid, val); int keylist_n = reverseMap(&maps[mid], val, keylist); printf("list"); for (int i = 0; i < keylist_n; i++) printf(" %d", keylist[i]); puts(""); } else { assert(false); } } }
static void do_ops(union mm_context *mmu, struct host_vm_op *ops, int last) { struct host_vm_op *op; int i; for(i = 0; i <= last; i++){ op = &ops[i]; switch(op->type){ case MMAP: map(&mmu->skas.id, op->u.mmap.addr, op->u.mmap.len, op->u.mmap.r, op->u.mmap.w, op->u.mmap.x, op->u.mmap.fd, op->u.mmap.offset); break; case MUNMAP: unmap(&mmu->skas.id, (void *) op->u.munmap.addr, op->u.munmap.len); break; case MPROTECT: protect(&mmu->skas.id, op->u.mprotect.addr, op->u.mprotect.len, op->u.mprotect.r, op->u.mprotect.w, op->u.mprotect.x); break; default: printk("Unknown op type %d in do_ops\n", op->type); break; } } }
static Read<GO> get_local_conn(Mesh* mesh, Int dim, bool full) { auto low_dim = ((full) ? (dim - 1) : (VERT)); auto h2l = mesh->ask_down(dim, low_dim); auto l_globals = mesh->ask_globals(low_dim); auto hl2l_globals = unmap(h2l.ab2b, l_globals, 1); return hl2l_globals; }
static int do_ops(struct host_vm_change *hvc, int end, int finished) { struct host_vm_op *op; int i, ret = 0; for (i = 0; i < end && !ret; i++) { op = &hvc->ops[i]; switch (op->type) { case MMAP: ret = map(hvc->id, op->u.mmap.addr, op->u.mmap.len, op->u.mmap.prot, op->u.mmap.fd, op->u.mmap.offset, finished, &hvc->data); break; case MUNMAP: ret = unmap(hvc->id, op->u.munmap.addr, op->u.munmap.len, finished, &hvc->data); break; case MPROTECT: ret = protect(hvc->id, op->u.mprotect.addr, op->u.mprotect.len, op->u.mprotect.prot, finished, &hvc->data); break; default: printk(KERN_ERR "Unknown op type %d in do_ops\n", op->type); break; } } return ret; }
// Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input // into the target pixel rectangle. void Image11::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLint unpackAlignment, GLenum type, const void *input) { GLsizei inputRowPitch = gl::GetRowPitch(mInternalFormat, type, width, unpackAlignment); GLsizei inputDepthPitch = gl::GetDepthPitch(mInternalFormat, type, width, height, unpackAlignment); GLuint outputPixelSize = d3d11::GetFormatPixelBytes(mDXGIFormat); LoadImageFunction loadFunction = d3d11::GetImageLoadFunction(mInternalFormat, type); ASSERT(loadFunction != NULL); D3D11_MAPPED_SUBRESOURCE mappedImage; HRESULT result = map(D3D11_MAP_WRITE, &mappedImage); if (FAILED(result)) { ERR("Could not map image for loading."); return; } uint8_t* offsetMappedData = (reinterpret_cast<uint8_t*>(mappedImage.pData) + (yoffset * mappedImage.RowPitch + xoffset * outputPixelSize + zoffset * mappedImage.DepthPitch)); loadFunction(width, height, depth, reinterpret_cast<const uint8_t*>(input), inputRowPitch, inputDepthPitch, offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch); unmap(); }
int MmapFile::mapByOffset(const int startOffset) { if (-1 == m_fd) return -1; if (startOffset != m_startOffset && m_ptr && unmap() != 0) return -1; int ret = -1; m_startOffset = startOffset; m_endOffset = startOffset + m_pageSize; if (m_fileSize < m_endOffset && (ret = setSize(m_endOffset))) { ERRORLOG1("file %s setSize failed", m_fileName); return -1; } if (0 == ret) m_fileSize = m_endOffset; m_ptr = (uint8_t *)mmap(NULL, m_pageSize, m_prot, MAP_SHARED, m_fd, m_startOffset); if (MAP_FAILED != m_ptr) return 0; m_ptr = NULL; ERRORLOG2("mmap file %s failed, err %s", m_fileName, strerror(errno)); return -1; }
void Image11::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, const void *input) { GLsizei inputRowPitch = gl::GetRowPitch(mInternalFormat, GL_UNSIGNED_BYTE, width, 1); GLsizei inputDepthPitch = gl::GetDepthPitch(mInternalFormat, GL_UNSIGNED_BYTE, width, height, 1); GLuint outputPixelSize = d3d11::GetFormatPixelBytes(mDXGIFormat); GLuint outputBlockWidth = d3d11::GetBlockWidth(mDXGIFormat); GLuint outputBlockHeight = d3d11::GetBlockHeight(mDXGIFormat); ASSERT(xoffset % outputBlockWidth == 0); ASSERT(yoffset % outputBlockHeight == 0); LoadImageFunction loadFunction = d3d11::GetImageLoadFunction(mInternalFormat, GL_UNSIGNED_BYTE); ASSERT(loadFunction != NULL); D3D11_MAPPED_SUBRESOURCE mappedImage; HRESULT result = map(D3D11_MAP_WRITE, &mappedImage); if (FAILED(result)) { ERR("Could not map image for loading."); return; } uint8_t* offsetMappedData = reinterpret_cast<uint8_t*>(mappedImage.pData) + ((yoffset / outputBlockHeight) * mappedImage.RowPitch + (xoffset / outputBlockWidth) * outputPixelSize + zoffset * mappedImage.DepthPitch); loadFunction(width, height, depth, reinterpret_cast<const uint8_t*>(input), inputRowPitch, inputDepthPitch, offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch); unmap(); }