Ticket #514: ldt_keeper_darwin.2.patch

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

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

  • ldt_keeper.c

    old new  
    102102#define       LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3)
    103103
    104104/* i got this value from wine sources, it's the first free LDT entry */
    105 #if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC)
     105#if (defined(__FreeBSD__) || defined(CONFIG_DARWIN)) && defined(LDT_AUTO_ALLOC)
    106106#define       TEB_SEL_IDX     LDT_AUTO_ALLOC
    107107#endif
    108108
     
    167167#endif
    168168#endif
    169169
    170 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
     170#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(CONFIG_DARWIN) || defined(__OpenBSD__) || defined(__DragonFly__)
    171171static void LDT_EntryToBytes( unsigned long *buffer, const struct modify_ldt_ldt_s *content )
    172172{
    173173    *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
     
    193193
    194194    if (!ldt_fs)
    195195        return NULL;
    196 
    197     ldt_fs->fd = -1;
     196#ifndef CONFIG_DARWIN
     197    ldt_fs->fd = open("/dev/zero", O_RDWR);
     198    if(ldt_fs->fd<0){
     199        perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: ");
     200        return NULL;
     201    }
     202    fs_seg=
     203    ldt_fs->fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
     204                          ldt_fs->fd, 0);
     205#else
    198206    fs_seg=
    199207    ldt_fs->fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
     208#endif /* CONFIG_DARWIN */
    200209    if (ldt_fs->fs_seg == (void*)-1)
    201210    {
    202211        perror("ERROR: Couldn't allocate memory for fs segment");
     
    224233    }
    225234#endif /*linux*/
    226235
    227 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
     236#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(CONFIG_DARWIN) || defined(__OpenBSD__) || defined(__DragonFly__)
    228237    {
    229238        unsigned long d[2];
    230239
    231240        LDT_EntryToBytes( d, &array );
    232 #if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC)
     241#if (defined(__FreeBSD__) || defined(CONFIG_DARWIN)) && defined(LDT_AUTO_ALLOC)
    233242        ret = i386_set_ldt(LDT_AUTO_ALLOC, (union descriptor *)d, 1);
    234243        array.entry_number = ret;
    235244        fs_ldt = ret;