Ticket #514: mp.patch

File mp.patch, 13.0 KB (added by wxprojects@…, 13 years ago)

MPlayer intel mac dll fix patch ("cleaned up" version of Valtteri Vuorikoski's)

  • help/help_mp-en.h

    diff -rNbu MPlayer-1.0pre82/help/help_mp-en.h MPlayer-1.0pre8/help/help_mp-en.h
    old new  
    18141814// libvo/vo_xv.c
    18151815
    18161816#define MSGTR_LIBVO_XV_DrawFrameCalled "[VO_XV] draw_frame() called!!!!!!\n"
     1817
     1818// loader/ldt_keeper.c
     1819
     1820#define MSGTR_LOADER_DYLD_Warning "WARNING: Attempting to use DLL codecs but environment variable DYLD_BIND_AT_LAUNCH not set.\nThis will likely crash.\n"
  • loader/Makefile

    diff -rNbu MPlayer-1.0pre82/loader/Makefile MPlayer-1.0pre8/loader/Makefile
    old new  
    99else
    1010LIB_OBJECTS= ldt_keeper.o pe_image.o module.o ext.o win32.o \
    1111             driver.o pe_resource.o resource.o registry.o \
    12              elfdll.o afl.o vfl.o wrapper.o
     12             elfdll.o afl.o vfl.o mmap_anon.o
     13
     14# QTX emulation is not supported in Darwin
     15ifneq ($(TARGET_OS),Darwin)
     16LIB_OBJECTS+=wrapper.o
     17endif
     18
     19endif
     20
     21# stubs_bsd.s for OpenBSD and Darwin, and stubs.s for the rest
     22ifeq ($(TARGET_OS),Darwin)
     23LIB_OBJECTS+=stubs_bsd.o
     24else
     25ifeq ($(TARGET_OS),OpenBSD)
     26LIB_OBJECTS+=stubs_bsd.o
     27else
     28LIB_OBJECTS+=stubs.o
     29endif
    1330endif
    1431
    1532# gcc-3.0 produces buggy code for acmStreamOpen() with
     
    3451.c.o:
    3552        $(CC) $(CFLAGS) $(DEFINES) -c $<
    3653
    37 libloader.a:  $(LIB_OBJECTS) stubs.s
    38         $(CC) -c ./stubs.s -o stubs.o
    39 ifeq ($(TARGET_OS),OpenBSD)
    40         ./loader_objfix.sh
    41 endif
    42         $(AR) -r libloader.a $(LIB_OBJECTS) stubs.o
     54libloader.a:  $(LIB_OBJECTS)
     55        $(AR) -r libloader.a $(LIB_OBJECTS)
    4356        $(RANLIB) libloader.a
    4457
    4558dep:
  • loader/ext.c

    diff -rNbu MPlayer-1.0pre82/loader/ext.c MPlayer-1.0pre8/loader/ext.c
    old new  
    2626#include <stdarg.h>
    2727#include <ctype.h>
    2828
     29#include <mmap_anon.h>
     30
    2931#include "wine/windef.h"
    3032#include "wine/winbase.h"
    3133#include "wine/debugtools.h"
     
    233235
    234236//#define MAP_PRIVATE
    235237//#define MAP_SHARED
    236 #undef MAP_ANON
    237238LPVOID FILE_dommap( int unix_handle, LPVOID start,
    238239                    DWORD size_high, DWORD size_low,
    239240                    DWORD offset_high, DWORD offset_low,
     
    248249
    249250    if (unix_handle == -1)
    250251    {
    251 #ifdef MAP_ANON
    252 //      printf("Anonymous\n");
    253         flags |= MAP_ANON;
    254 #else
    255         static int fdzero = -1;
    256 
    257         if (fdzero == -1)
    258         {
    259             if ((fdzero = open( "/dev/zero", O_RDONLY )) == -1)
    260             {
    261                 perror( "Cannot open /dev/zero for READ. Check permissions! error: " );
    262                 exit(1);
     252        ret = mmap_anon( start, size_low, prot, flags, offset_low, &fd );
    263253            }
     254    else {
     255        fd = unix_handle;
     256        ret = mmap( start, size_low, prot, flags, fd, offset_low );
    264257        }
    265         fd = fdzero;
    266 #endif  /* MAP_ANON */
    267         /* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
    268 #ifdef MAP_SHARED
    269         flags &= ~MAP_SHARED;
    270 #endif
    271 #ifdef MAP_PRIVATE
    272         flags |= MAP_PRIVATE;
    273 #endif
    274     }
    275     else fd = unix_handle;
    276 //    printf("fd %x, start %x, size %x, pos %x, prot %x\n",fd,start,size_low, offset_low, prot);
    277 //    if ((ret = mmap( start, size_low, prot,
    278 //                     flags, fd, offset_low )) != (LPVOID)-1)
    279     if ((ret = mmap( start, size_low, prot,
    280                      MAP_PRIVATE | MAP_FIXED, fd, offset_low )) != (LPVOID)-1)
     258
     259    if (ret != (LPVOID)-1)
    281260    {
    282261//          printf("address %08x\n", *(int*)ret);
    283262//      printf("%x\n", ret);
     
    370349    LPVOID answer;
    371350    int anon=0;
    372351    int mmap_access=0;
     352
    373353    if(hFile<0)
    374     {
    375354        anon=1;
    376         hFile=open("/dev/zero", O_RDWR);
    377         if(hFile<0){
    378             perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: " );
    379             return 0;
    380         }
    381     }
     355
    382356    if(!anon)
    383357    {
    384358        len=lseek(hFile, 0, SEEK_END);
     
    391365    else
    392366        mmap_access |=PROT_READ|PROT_WRITE;
    393367
    394     answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0);
    395368    if(anon)
     369      answer=mmap_anon(NULL, len, mmap_access, MAP_PRIVATE, 0, &hFile);
     370    else
     371      answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0);
     372
     373    if(anon && hFile != -1)
    396374        close(hFile);
    397375    if(answer!=(LPVOID)-1)
    398376    {
     
    418396            fm->name=NULL;
    419397        fm->mapping_size=len;
    420398
    421         if(anon)
     399        if(anon && hFile != -1)
    422400            close(hFile);
    423401        return (HANDLE)answer;
    424402    }
     
    471449
    472450    if ((type&(MEM_RESERVE|MEM_COMMIT)) == 0) return NULL;
    473451
    474     fd=open("/dev/zero", O_RDWR);
    475     if(fd<0){
    476         perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: " );
    477         return NULL;
    478     }
    479 
    480452    if (type&MEM_RESERVE && (unsigned)address&0xffff) {
    481453        size += (unsigned)address&0xffff;
    482454        address = (unsigned)address&~0xffff;
     
    513485                   && ((unsigned)address+size<=(unsigned)str->address+str->mapping_size)
    514486                   && (type & MEM_COMMIT))
    515487                {
    516                     close(fd);
    517488                    return address; //returning previously reserved memory
    518489                }
    519490                //printf(" VirtualAlloc(...) does not commit or not entirely within reserved, and\n");
    520491            }
    521492            /*printf(" VirtualAlloc(...) (0x%08X, %u) overlaps with (0x%08X, %u, state=%d)\n",
    522493                   (unsigned)address, size, (unsigned)str->address, str->mapping_size, str->state);*/
    523             close(fd);
    524494            return NULL;
    525495        }
    526496    }
    527497
    528     answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
    529                 MAP_PRIVATE, fd, 0);
     498    answer=mmap_anon(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
     499                    MAP_PRIVATE, 0, &fd);
     500
    530501//    answer=FILE_dommap(-1, address, 0, size, 0, 0,
    531502//      PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
     503    if (fd != -1)
    532504    close(fd);
    533505    if (answer != (void *)-1 && address && answer != address) {
    534506        /* It is dangerous to try mmap() with MAP_FIXED since it does not
  • loader/ldt_keeper.c

    diff -rNbu MPlayer-1.0pre82/loader/ldt_keeper.c MPlayer-1.0pre8/loader/ldt_keeper.c
    old new  
    2828#include <sys/types.h>
    2929#include <stdio.h>
    3030#include <unistd.h>
     31
     32#include <mmap_anon.h>
     33#include <mp_msg.h>
     34#include <help_mp.h>
     35
    3136#ifdef __linux__
    3237#include <asm/unistd.h>
    3338#include <asm/ldt.h>
     
    102107#define       LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3)
    103108
    104109/* i got this value from wine sources, it's the first free LDT entry */
    105 #if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC)
     110#if (defined(__APPLE__) || defined(__FreeBSD__)) && defined(LDT_AUTO_ALLOC)
    106111#define       TEB_SEL_IDX     LDT_AUTO_ALLOC
     112#define       USE_LDT_AA
    107113#endif
    108114
    109115#ifndef       TEB_SEL_IDX
     
    167173#endif
    168174#endif
    169175
    170 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
     176#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
    171177static void LDT_EntryToBytes( unsigned long *buffer, const struct modify_ldt_ldt_s *content )
    172178{
    173179    *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
     
    194200    if (!ldt_fs)
    195201        return NULL;
    196202
    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     }
     203#ifdef __APPLE__
     204    if (getenv("DYLD_BIND_AT_LAUNCH") == NULL)
     205        mp_msg(MSGT_LOADER, MSGL_WARN, MSGTR_LOADER_DYLD_Warning);
     206#endif /* __APPLE__ */
     207
    202208    fs_seg=
    203     ldt_fs->fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
    204                           ldt_fs->fd, 0);
     209    ldt_fs->fs_seg = mmap_anon(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
     210                               0, &ldt_fs->fd);
    205211    if (ldt_fs->fs_seg == (void*)-1)
    206212    {
    207213        perror("ERROR: Couldn't allocate memory for fs segment");
     
    229235    }
    230236#endif /*linux*/
    231237
    232 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
     238#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
    233239    {
    234240        unsigned long d[2];
    235241
    236242        LDT_EntryToBytes( d, &array );
    237 #if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC)
     243#ifdef USE_LDT_AA
    238244        ret = i386_set_ldt(LDT_AUTO_ALLOC, (union descriptor *)d, 1);
    239245        array.entry_number = ret;
    240246        fs_ldt = ret;
     
    251257#endif
    252258        }
    253259    }
    254 #endif  /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ */
     260#endif  /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __APPLE__ */
    255261
    256262#if defined(__svr4__)
    257263    {
     
    286292        free(ldt_fs->prev_struct);
    287293    munmap((char*)ldt_fs->fs_seg, getpagesize());
    288294    ldt_fs->fs_seg = 0;
     295    if (ldt_fs->fd != -1)
    289296    close(ldt_fs->fd);
    290297    free(ldt_fs);
    291298}
  • loader/mmap_anon.c

    diff -rNbu MPlayer-1.0pre82/loader/mmap_anon.c MPlayer-1.0pre8/loader/mmap_anon.c
    old new  
     1/*
     2 * mmap_anon.c: provide a compatible anonymous space mapping function
     3 */
     4
     5#include <sys/mman.h>
     6#include <stdio.h>
     7#include <unistd.h>
     8#include <fcntl.h>
     9
     10/*
     11 * mmap() anonymous space, depending on the system's mmap() style. On systems
     12 * that use the /dev/zero mapping idiom, zerofd will be set to the file descriptor
     13 * of the opened /dev/zero.
     14 */
     15void *mmap_anon(void *addr, size_t len, int prot, int flags, off_t offset, int *zerofd)
     16{
     17    int fd;
     18    void *result;
     19
     20     /* From loader/ext.c:
     21      * "Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap"
     22      * Therefore we preserve the same behavior on all platforms, ie. no
     23      * shared mappings of anon space (if the concepts are supported). */
     24#if defined(MAP_SHARED) && defined(MAP_PRIVATE)
     25     flags = (flags & ~MAP_SHARED) | MAP_PRIVATE;
     26#endif /* defined(MAP_SHARED) && defined(MAP_PRIVATE) */
     27
     28#ifdef __APPLE__
     29    /* BSD-style anonymous mapping */
     30    fd = -1;
     31    result = mmap(addr, len, prot, flags | MAP_ANON, -1, offset);
     32#else
     33    /* SysV-style anonymous mapping */
     34    fd = open("/dev/zero", O_RDWR);
     35    if(fd < 0){
     36        perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: ");
     37        return NULL;
     38    }
     39
     40    result = mmap(addr, len, prot, flags, fd, offset);
     41#endif /* __APPLE__ */
     42
     43    if (zerofd)
     44        *zerofd = fd;
     45
     46    return result;
     47}
     48
  • loader/mmap_anon.h

    diff -rNbu MPlayer-1.0pre82/loader/mmap_anon.h MPlayer-1.0pre8/loader/mmap_anon.h
    old new  
     1#ifndef _OSDEP_MMAP_ANON_H_
     2#define _OSDEP_MMAP_ANON_H_
     3
     4#include <sys/types.h>
     5
     6void *mmap_anon(void *, size_t, int, int, off_t, int *);
     7
     8#endif /* _OSDEP_MMAP_ANON_H_ */
  • loader/module.c

    diff -rNbu MPlayer-1.0pre82/loader/module.c MPlayer-1.0pre8/loader/module.c
    old new  
    1010 */
    1111
    1212// define for quicktime calls debugging and/or MacOS-level emulation:
     13// (not supported on OS X yet)
     14#ifndef __APPLE__
    1315#define EMU_QTX_API
     16#endif /* __APPLE__ */
    1417
    1518// define for quicktime debugging (verbose logging):
    1619//#define DEBUG_QTX_API
  • loader/stubs_bsd.s

    diff -rNbu MPlayer-1.0pre82/loader/stubs_bsd.s MPlayer-1.0pre8/loader/stubs_bsd.s
    old new  
     1        .data
     2.LC0:   .asciz  "Called unk_%s\n"
     3       .p2align 2
     4.globl _unk_exp1
     5_unk_exp1:
     6        pushl %ebp
     7        movl %esp,%ebp
     8        subl $4,%esp
     9        movl $1,-4(%ebp)
     10        movl -4(%ebp),%eax
     11        movl %eax,%ecx
     12        movl %ecx,%edx
     13        sall $4,%edx
     14        subl %eax,%edx
     15        leal 0(,%edx,2),%eax
     16        movl %eax,%edx
     17        addl $_export_names,%edx
     18        pushl %edx
     19        pushl $.LC0
     20        call _printf
     21        addl $8,%esp
     22        xorl %eax,%eax
     23        leave
     24        ret
     25.globl _exp_EH_prolog
     26_exp_EH_prolog:
     27        pushl $0xff
     28        pushl %eax
     29        pushl %fs:0
     30        movl  %esp, %fs:0
     31        movl  12(%esp), %eax
     32        movl  %ebp, 12(%esp)
     33        leal  12(%esp), %ebp
     34        pushl %eax
     35        ret
  • loader/wine/poppack.h

    diff -rNbu MPlayer-1.0pre82/loader/wine/poppack.h MPlayer-1.0pre8/loader/wine/poppack.h
    old new  
    11#ifdef __WINE_PSHPACK_H
    22#undef __WINE_PSHPACK_H
    33
    4 #if defined(__GNUC__) || defined(__SUNPRO_C)
     4#if (defined(__GNUC__) || defined(__SUNPRO_C)) && !defined(__APPLE__)
    55#pragma pack()
    6 #elif defined(__SUNPRO_CC)
     6#elif defined(__SUNPRO_CC) || defined(__APPLE__)
    77#warning "Assumes default alignment is 4"
    88#pragma pack(4)
    99#elif !defined(RC_INVOKED)
  • MPlayer-1.

    diff -rNbu MPlayer-1.0pre82/mp_msg.h MPlayer-1.0pre8/mp_msg.h
    old new  
    9797
    9898#define MSGT_IDENTIFY 41  // -identify output
    9999
     100#define MSGT_LOADER 42 // dll loader messages
     101
    100102#define MSGT_MAX 64
    101103
    102104void mp_msg_init(void);