Ticket #514: ext_darwin.2.patch

File ext_darwin.2.patch, 2.2 KB (added by stephane.lapie@…, 13 years ago)

loader/ext.c patch, fixes mmap() feeding on /dev/zero, with mmap(MAP_ANON) with -DCONFIG_DARWIN

  • ext.c

    old new  
    233233
    234234//#define MAP_PRIVATE
    235235//#define MAP_SHARED
    236 #undef MAP_ANON
    237236LPVOID FILE_dommap( int unix_handle, LPVOID start,
    238237                    DWORD size_high, DWORD size_low,
    239238                    DWORD offset_high, DWORD offset_low,
     
    248247
    249248    if (unix_handle == -1)
    250249    {
    251 #ifdef MAP_ANON
     250#ifdef CONFIG_DARWIN
    252251//      printf("Anonymous\n");
    253252        flags |= MAP_ANON;
     253        fd = -1;
    254254#else
    255255        static int fdzero = -1;
    256256
     
    263263            }
    264264        }
    265265        fd = fdzero;
    266 #endif  /* MAP_ANON */
     266#endif  /* CONFIG_DARWIN */
    267267        /* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
    268268#ifdef MAP_SHARED
    269269        flags &= ~MAP_SHARED;
     
    276276//    printf("fd %x, start %x, size %x, pos %x, prot %x\n",fd,start,size_low, offset_low, prot);
    277277//    if ((ret = mmap( start, size_low, prot,
    278278//                     flags, fd, offset_low )) != (LPVOID)-1)
     279#ifndef CONFIG_DARWIN
    279280    if ((ret = mmap( start, size_low, prot,
    280281                     MAP_PRIVATE | MAP_FIXED, fd, offset_low )) != (LPVOID)-1)
     282#else
     283    if ((ret = mmap( start, size_low, prot, MAP_PRIVATE | MAP_FIXED | MAP_ANON, fd, offset_low )) != (LPVOID)-1)
     284#endif /* CONFIG_DARWIN */
    281285    {
    282286//          printf("address %08x\n", *(int*)ret);
    283287//      printf("%x\n", ret);
     
    471475
    472476    if ((type&(MEM_RESERVE|MEM_COMMIT)) == 0) return NULL;
    473477
     478#ifndef CONFIG_DARWIN
    474479    fd=open("/dev/zero", O_RDWR);
    475480    if(fd<0){
    476481        perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: " );
    477482        return NULL;
    478483    }
     484#endif /* CONFIG_DARWIN */
    479485
    480486    if (type&MEM_RESERVE && (unsigned)address&0xffff) {
    481487        size += (unsigned)address&0xffff;
     
    525531        }
    526532    }
    527533
     534#ifndef CONFIG_DARWIN
    528535    answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
    529536                MAP_PRIVATE, fd, 0);
     537#else
     538    /* mmap feeding from fd from /dev/zero doesn't work on darwin ! */
     539    answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0);
     540#endif /* CONFIG_DARWIN */
    530541//    answer=FILE_dommap(-1, address, 0, size, 0, 0,
    531542//      PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
    532543    close(fd);