Ticket #514: ldt_keeper_darwin.3.patch

File ldt_keeper_darwin.3.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 (proper diff

  • 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 
     196#ifndef CONFIG_DARWIN
    197197    ldt_fs->fd = open("/dev/zero", O_RDWR);
    198198    if(ldt_fs->fd<0){
    199199        perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: ");
     
    202202    fs_seg=
    203203    ldt_fs->fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
    204204                          ldt_fs->fd, 0);
     205#else
     206    fs_seg=
     207    ldt_fs->fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
     208#endif /* CONFIG_DARWIN */
    205209    if (ldt_fs->fs_seg == (void*)-1)
    206210    {
    207211        perror("ERROR: Couldn't allocate memory for fs segment");
     
    229233    }
    230234#endif /*linux*/
    231235
    232 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
     236#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(CONFIG_DARWIN) || defined(__OpenBSD__) || defined(__DragonFly__)
    233237    {
    234238        unsigned long d[2];
    235239
    236240        LDT_EntryToBytes( d, &array );
    237 #if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC)
     241#if (defined(__FreeBSD__) || defined(CONFIG_DARWIN)) && defined(LDT_AUTO_ALLOC)
    238242        ret = i386_set_ldt(LDT_AUTO_ALLOC, (union descriptor *)d, 1);
    239243        array.entry_number = ret;
    240244        fs_ldt = ret;