Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com X-Authentication-Warning: csd.cs.technion.ac.il: emild owned process doing -bs Date: Wed, 24 Jan 2001 02:41:00 +0200 (IST) From: Kohn Emil Dan X-Sender: emild AT csd To: cygwin AT cygwin DOT com Subject: mmap problem in cygwin 1.1.7 Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Hi all, It seems to me that there is a problem with the current implementation of mmap() in the 1.1.7 release of the cygwin dll. Whenever a non-zero offset is passed to mmap(), it will fail with EACCESS. Example: #include #include #include #include #ifndef PAGE_SIZE #define PAGE_SIZE 65536 #endif int main() { int fd; void *ptr; int rc; char c = 'a'; off_t new_off; fd = open("crap",O_RDWR|O_CREAT|O_BINARY); if (fd < 0) { perror("open"); goto bad_open; } new_off = lseek(fd,2*PAGE_SIZE,SEEK_CUR); if (new_off == (off_t)-1) { perror("lseek"); goto bad_lseek; } rc = write(fd,&c,1); if (rc <= 0) { perror("write"); goto bad_write; } ptr = mmap(NULL,PAGE_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED,fd,PAGE_SIZE); if (ptr == MAP_FAILED) { perror("mmap"); goto bad_mmap; } printf("mmap succeeded: ptr=%p\n",ptr); rc = munmap(ptr,PAGE_SIZE); rc = munmap(ptr,PAGE_SIZE); if (rc < 0) { perror("munmap2"); goto bad_munmap; } close(fd); printf("OK till now\n"); return 0; bad_mmap: bad_write: bad_lseek: bad_munmap: close(fd); bad_open: return 1; } the program will run OK if the last parameter is set to 0. I have traced the problem to the implementation of the mmap() file: mmap.cc line:451 HANDLE h = CreateFileMapping (get_handle(), &sec_none, protect, 0, len,NULL); The problem is that the file mapping object has *exactly* the size len. Now if an attempt is made to map the view at a non-zero offset, this will cause the mapped area to exceed the size of the file mapping object and Windows (NT 4.0 at least) will return ACCESS denied. The fix should be easy. Replace the len parameter passed to CreatefileMapping with 0. This will cause the entire file to be mapped. Regards, Emil -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple