mmap

mmap for write under MacOSX 10.8.2 with XCode 4.6 will make program crash

偶尔善良 提交于 2019-12-10 18:04:40
问题 I try to run a simple test of mmap under MacOSX 10.8.2, with XCode 4.6. This program is as follows, the file mapped for read is OK while the access to the write pointer "target" will make the program crash. Error message is "EXC_BAD_ACCESS". Does anyone have the same case with me ? Thanks a lot. #include <stdio.h> #include <string.h> #include <sys/mman.h> #include <fcntl.h> #include <unistd.h> int main(int argc, const char * argv[]) { int input, output; size_t size; char *source, *target;

Lazily Reading a File in D

拈花ヽ惹草 提交于 2019-12-10 18:03:29
问题 I'm writing a directory tree scanning function in D that tries to combine tools such as grep and file and conditionally grep for things in a file only if it's not matching a set of magic bytes indicating filetypes such as ELF, images, etc. What is the best approach to making such an exclusion logic run as fast as possible with regards to minimizing file io? I typically don't want to read in the whole file if I only need to read some magic bytes in the beginning. However to make the code more

Accessing a memory-mapped file using Python

£可爱£侵袭症+ 提交于 2019-12-10 16:12:32
问题 I am looking to take use of a memory mapped file from Guild Wars 2, which is designed to link into Mumble for positional audio. The file contains information on the characters coordinates and other useful information. I have been able to access the coordinate information using this script, import mmap import struct last=[] while True: shmem = mmap.mmap(0, 20, "MumbleLink", mmap.ACCESS_READ) coord=struct.unpack("IL3f", shmem)[2:5] shmem.close() if last!=coord: print(coord) last = coord X =

Access mmap memory from another process

柔情痞子 提交于 2019-12-10 15:29:50
问题 I've started playing with mmap. I'm trying to create an example workspace that will be then extended to the real case. This is what I want to achieve: PROCESS 1: mmap a file (actually a device, but it's okay to generate an example with a text file) PROCESS 2: (not foked from process 1; just an independent process) read the memory mapped by process 1 change some bits write it to a new file I've read several examples and documentations, but I still didn't find how to achieve this. What I'm

mmap returns can not allocate memory, even though there is enough

ε祈祈猫儿з 提交于 2019-12-10 15:24:21
问题 I'm performing a pressure test with leveldb. In util/env_poisx.cc : NewRandomAccessFile() void* base = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); after 3 million data (each 100k) insert. The errno says Cannot allocate memory . why? More details: top: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 19794 root 20 0 290g 4.9g 4.7g S 98.6 7.8 2348:00 ldb free -m: total used free shared buffers cached Mem: 64350 60623 3726 0 179 59353 -/+ buffers/cache: 1090 63259 Swap: 996 0 996 ulimit

Read and write process' memory through /dev/mem, text segment works but data segment can not, why?

允我心安 提交于 2019-12-10 15:15:03
问题 I want to read to and write from process' memory through /dev/mem . First , I get process' memory map through a linux kernel module coded by myself, output is like this: start_code_segment 4000000000000000 end_code_segment 4000000000019c38 start_data_segment 6000000000009c38 end_data_segment 600000000000b21d start_brk 6000000000010000 brk 6000000000034000 start_stack 60000fffffde7b00 Second , I can convert virtual address(VA) to PA thorough the linux kernel module, for example, I can convert

Two C++ apps sharing a read-only region of memory on Linux

大城市里の小女人 提交于 2019-12-10 14:53:35
问题 I have two processes P1 and P2. I have this large read-only resource, called "R" that I want both P1 and P2 to have access to. R is not just a "flat" group of bytes; it's a bunch of C++ objects that point to each other. I would prefer that P1 and P2 only share one copy of R -- somehow have P1 load R into a region in memory (that's mmaped in P1 and P2 at the same address), then P1 and P2 can both access the objects in R as C++ objects (no race conditions since all is read only). Anyone

mmap() returns EINVAL

杀马特。学长 韩版系。学妹 提交于 2019-12-10 13:56:56
问题 I can't get the mmap function to work. It returns the EINVAL error code. void* mapped = mmap((void*)(map_addr + slide), map_size, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANON, bprm->file, map_offset); I've checked the documentation for this function on my platform ( Darwin ) and there doesn't seem to be anything wrong. The man page for mmap presents four cases under which EINVAL would be returned. [EINVAL] MAP_FIXED was specified and the addr argument was not page aligned, or part of the

mremap function failed to allocate new memory

╄→尐↘猪︶ㄣ 提交于 2019-12-10 12:13:54
问题 I have write the following code , but the code is still fiven me EEERROR message , which tells that the mremap failed to extend the memory. int main() { int size_of_mem = 1024 int fd = shm_open("/myregion", O_CREAT | O_RDWR, S_IRWXO | S_IRUSR | S_IWUSR); if (fd == -1) printf("ERROR in shm_open \n") ; if (ftruncate(fd, size_of_mem) == -1) printf("ERROR in ftruncate \n") ; int shm_address = mmap(0 , size_of_mem , PROT_READ | PROT_WRITE | PROT_EXEC ,MAP_SHARED , fd , 0) ; if (shm_address == MAP

Python: ctypes hashable c_char array replacement without tripping over '\0' bytes

与世无争的帅哥 提交于 2019-12-10 11:46:14
问题 For illustration purposes, this script creates a file mapfile containing the content of the files, given as arguments, prepended by a binary header with a sha1 checksum, that allows for duplication detection on subsequent runs. What's needed here is a hashable ctypes.c_char replacement, that can hold sha1 checksums with minimum fuzz, but not choking on '\0' bytes. # -*- coding: utf8 -* import io import mmap import ctypes import hashlib import logging from collections import OrderedDict log =