Reputation: 31
I currently try to access UIO shared memory via memcopy.
My approach is:
I tried also with ftruncate after Step 2 resulting in an error.
The memcopy / memset causes a bus error which is normaly a sign of writing out of the files boundaries.
Via cat /proc/'pid'/maps I'm able to see that there is a mapping for /dev/uioX Also /sys/class/uio/uioX/maps/ has two map directories, of which I try to access the second one (map1 therefore N = 1)
Am I missing out something? Would I have to mmap the full size of the memory specified in /sys/class/uio/uioX/maps/map1/size ?
I could not find any example for accessing the memory via memcopy, is there something that prevents memcopy on UIO mmaped memory?
unsigned char* GetMemPtr(const char *name, unsigned long Size)
{
long fd;
long truncret;
void* MemPtr;
unsigned long offst;
printf("Opening: %s with size %u\n" , name, Size);
fd = open(name, O_RDWR);
if (fd < 0) {
printf("Error: open : %u : %s\n", fd, strerror(errno));
}
offst = 1 * getpagesize();
/*truncret = ftruncate(fd, offst + Size);
if (truncret < 0)
{
printf("Error: ftruncate : %s : %d\n", strerror(errno), truncret);
}*/
MemPtr = mmap(0, Size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offst);
if (MemPtr == MAP_FAILED)
{
printf("Error: mmap : %p : %s\n", MemPtr, strerror(errno));
}
//MemPtr = MemPtr + offst;
printf("Mem pointer is %p\n", MemPtr);
memset(MemPtr, 0, Size);
printf("Pointer is : %p\n" , MemPtr);
return (unsigned char*) MemPtr;
}
Results in the output:
Opening: /dev/uio0 with size 4096
Mem pointer is 0xffff89232000
Bus error (core dumped)
Upvotes: 1
Views: 1425