1.5.21s mmap error

Brian Ford Brian.Ford@flightsafety.com
Thu Jul 13 19:52:00 GMT 2006


On 2006年7月13日, Brian Ford wrote:
> On 2006年7月13日, Corinna Vinschen wrote:
> > I added an (hopefully) appropriate patch, which commits a page within a
> > MAP_NORESERVE area when memory in this page is accessed by the
> > application. If commiting the memory fails, SIGBUS is generated. Please
> > test CVS HEAD or the next developer snapshot from
> > http://cygwin.com/snapshots/
>> Wow! Thanks. Given my limited Windows API knowledge, that sounded
> difficult to accomplish properly. I'll test it for you shortly.

One problem found. If the memory is not touched before using it as a
buffer to a read call, the read returns -1 with errno set to ISDIR. STC
attached.
Thanks again for looking at this.
-- 
Brian Ford
Lead Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
the best safety device in any aircraft is a well-trained crew...
.
-------------- next part --------------
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int
main(int argc, char * argv[])
{
 int virt_size, fd;
 void *addr;
 addr = NULL;
 virt_size = 0x18000000;
 addr = mmap(addr, virt_size, (PROT_READ|PROT_WRITE),
		(MAP_NORESERVE|MAP_PRIVATE|MAP_ANON), -1, 0);
 if (addr == MAP_FAILED)
 {
	perror("mapping VM scratch space");
	return -1;
 }
 fd = open("/proc/self/exe", O_RDONLY);
 if (fd < 0)
 {
	perror("open self");
	return -1;
 }
#ifdef PRE_TOUCH
 memset(addr, -1, sysconf(_SC_PAGESIZE));
#endif
 if (read(fd, addr, sysconf(_SC_PAGESIZE)) < 0)
 {
	perror("read");
	close(fd);
	return -1;
 }
 close(fd);
 return 0;
}
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /