second call to mmap() results in error
Steven Bardwell
SBardwell@lbmsys.com
Thu Jan 30 12:25:00 GMT 2014
> > On 29/01/2014 19:12, Corinna Vinschen wrote:
> > >On Jan 29 09:00, Steven Bardwell wrote:
> > >>My application needs several areas of shared memory, and I am getting
> an
> > >>error ("No such device") on the second call to mmap(). The first call
> works
> > >>fine.
>
> Sorry guys, but it still works fine for me. I tried your testcase on W7
> 32, W7 64 in 32 and 64 bit, and on Windows 8.1 64 in 32 and 64 bit. I
> tried it with Cygwin 1.7.27 and with the latest snapshot. I'm always
> getting the output "Shared memory initialized" and no error at all.
>
>
> Any chance one of you guys could debug this further, by stepping through
> the Cygwin mmap64 function, preferredly using the latest snapshot or,
> a self-built Cygwin DLL from?
>
>
> Corinna
I reinstalled Cygwin, rebooted and the error persisted. Running 'gdb' and
stepping through the program showed that the call to mmap() fails for /block1
also -- it is returning an invalid address. This simplification of the program
shows that error on my machine ('Bus error (core dumped)' ) occurs
when it tries to do the memcpy() to the mapped address.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <fcntl.h>
#include <sys/mman.h>
int main()
{
int shm_fd1;
char *mmap1;
shm_fd1 = shm_open("/block1", O_CREAT | O_RDWR, 0666);
if (shm_fd1 == -1) {
fprintf(stderr, "Couldn't get fd for block1 (%s)\n", strerror(errno));
exit(1);
}
ftruncate(shm_fd1, 524304);
mmap1 = mmap(NULL, 524304, PROT_WRITE | PROT_READ, MAP_SHARED, shm_fd1, 0);
if (mmap1 == (char *)-1) {
fprintf(stderr, "Couldn't map memory for /block1 (%s)\n", strerror(errno));
exit(1);
}
memcpy(mmap1, "ABCDEF\0", 7);
fprintf(stdout, mmap1);
fprintf(stdout, "Shared memory initialized\n");
exit(0);
}
Steve
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
More information about the Cygwin
mailing list