misc/libphysfs/platform_macosx.c
changeset 12213 bb5522e88ab2
parent 10017 de822cd3df3a
equal deleted inserted replaced
12212:ea891871f481 12213:bb5522e88ab2
    27 #endif
    27 #endif
    28 
    28 
    29 #include "physfs_internal.h"
    29 #include "physfs_internal.h"
    30 
    30 
    31 
    31 
    32 #if defined(__APPLE__)
       
    33 #if defined(TARGET_OS_MAC) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
       
    34 /* __eprintf shouldn't have been made visible from libstdc++, or anywhere, but
       
    35    on Mac OS X 10.4 it was defined in libstdc++.6.0.3.dylib; so on that platform
       
    36    we have to keep defining it to keep binary compatibility.
       
    37    We can't just put the libgcc version in the export list, because that
       
    38    doesn't work; once a symbol is marked as hidden, it stays that way.  */
       
    39 
       
    40 void __eprintf (const char *string, const char *expression,
       
    41             unsigned int line, const char *filename)
       
    42 {
       
    43     fprintf(stderr, string, expression, line, filename);
       
    44     fflush(stderr);
       
    45     abort();
       
    46 }
       
    47 
       
    48 
       
    49 /* apparently libssp is missing from 10.4 SDK
       
    50    code from http://wiki.osdev.org/GCC_Stack_Smashing_Protector */
       
    51 void * __stack_chk_guard = NULL;
       
    52 
       
    53 void __stack_chk_guard_setup()
       
    54 {
       
    55     unsigned char * p;
       
    56     p = (unsigned char *) &__stack_chk_guard;
       
    57 
       
    58     /* If you have the ability to generate random numbers in your kernel then use them,
       
    59        otherwise for 32-bit code: *p = 0x00000aff; */
       
    60     *p = random();
       
    61 }
       
    62 
       
    63 void __attribute__((noreturn)) __stack_chk_fail()
       
    64 {
       
    65     /* put your panic function or similar in here */
       
    66     unsigned char * vid = (unsigned char *)0xB8000;
       
    67     vid[1] = 7;
       
    68     for(;;)
       
    69     vid[0]++;
       
    70 }
       
    71 
       
    72 #endif
       
    73 #endif /* __APPLE__ */
       
    74 
       
    75 
       
    76 /* Wrap PHYSFS_Allocator in a CFAllocator... */
    32 /* Wrap PHYSFS_Allocator in a CFAllocator... */
    77 static CFAllocatorRef cfallocator = NULL;
    33 static CFAllocatorRef cfallocator = NULL;
    78 
    34 
    79 static CFStringRef cfallocDesc(const void *info)
    35 static CFStringRef cfallocCopyDesc(const void *info)
    80 {
    36 {
    81     return CFStringCreateWithCString(cfallocator, "PhysicsFS",
    37     return CFStringCreateWithCString(cfallocator, "PhysicsFS",
    82                                      kCFStringEncodingASCII);
    38                                      kCFStringEncodingASCII);
    83 } /* cfallocDesc */
    39 } /* cfallocCopyDesc */
    84 
    40 
    85 
    41 
    86 static void *cfallocMalloc(CFIndex allocSize, CFOptionFlags hint, void *info)
    42 static void *cfallocMalloc(CFIndex allocSize, CFOptionFlags hint, void *info)
    87 {
    43 {
    88     return allocator.Malloc(allocSize);
    44     return allocator.Malloc(allocSize);
   107 int __PHYSFS_platformInit(void)
    63 int __PHYSFS_platformInit(void)
   108 {
    64 {
   109     /* set up a CFAllocator, so Carbon can use the physfs allocator, too. */
    65     /* set up a CFAllocator, so Carbon can use the physfs allocator, too. */
   110     CFAllocatorContext ctx;
    66     CFAllocatorContext ctx;
   111     memset(&ctx, '\0', sizeof (ctx));
    67     memset(&ctx, '\0', sizeof (ctx));
   112     ctx.copyDescription = cfallocDesc;
    68     ctx.copyDescription = cfallocCopyDesc;
   113     ctx.allocate = cfallocMalloc;
    69     ctx.allocate = cfallocMalloc;
   114     ctx.reallocate = cfallocRealloc;
    70     ctx.reallocate = cfallocRealloc;
   115     ctx.deallocate = cfallocFree;
    71     ctx.deallocate = cfallocFree;
   116     cfallocator = CFAllocatorCreate(kCFAllocatorUseContext, &ctx);
    72     cfallocator = CFAllocatorCreate(kCFAllocatorUseContext, &ctx);
   117     BAIL_IF_MACRO(!cfallocator, PHYSFS_ERR_OUT_OF_MEMORY, 0);
    73     BAIL_IF_MACRO(!cfallocator, PHYSFS_ERR_OUT_OF_MEMORY, 0);
   130 
    86 
   131 /* CD-ROM detection code... */
    87 /* CD-ROM detection code... */
   132 
    88 
   133 /*
    89 /*
   134  * Code based on sample from Apple Developer Connection:
    90  * Code based on sample from Apple Developer Connection:
   135  *  http://developer.apple.com/samplecode/Sample_Code/Devices_and_Hardware/Disks/VolumeToBSDNode/VolumeToBSDNode.c.htm
    91  *  https://developer.apple.com/samplecode/Sample_Code/Devices_and_Hardware/Disks/VolumeToBSDNode/VolumeToBSDNode.c.htm
   136  */
    92  */
   137 
    93 
   138 #if !defined(PHYSFS_NO_CDROM_SUPPORT)
    94 #if !defined(PHYSFS_NO_CDROM_SUPPORT)
   139 
    95 
   140 static int darwinIsWholeMedia(io_service_t service)
    96 static int darwinIsWholeMedia(io_service_t service)
   142     int retval = 0;
    98     int retval = 0;
   143     CFTypeRef wholeMedia;
    99     CFTypeRef wholeMedia;
   144 
   100 
   145     if (!IOObjectConformsTo(service, kIOMediaClass))
   101     if (!IOObjectConformsTo(service, kIOMediaClass))
   146         return 0;
   102         return 0;
   147 
   103         
   148     wholeMedia = IORegistryEntryCreateCFProperty(service,
   104     wholeMedia = IORegistryEntryCreateCFProperty(service,
   149                                                  CFSTR(kIOMediaWholeKey),
   105                                                  CFSTR(kIOMediaWholeKey),
   150                                                  cfallocator, 0);
   106                                                  cfallocator, 0);
   151     if (wholeMedia == NULL)
   107     if (wholeMedia == NULL)
   152         return 0;
   108         return 0;
   178     if (!service)
   134     if (!service)
   179         return 0;
   135         return 0;
   180 
   136 
   181     rc = IORegistryEntryCreateIterator(service, kIOServicePlane,
   137     rc = IORegistryEntryCreateIterator(service, kIOServicePlane,
   182              kIORegistryIterateRecursively | kIORegistryIterateParents, &iter);
   138              kIORegistryIterateRecursively | kIORegistryIterateParents, &iter);
   183 
   139     
   184     if (!iter)
   140     if (!iter)
   185         return 0;
   141         return 0;
   186 
   142 
   187     if (rc != KERN_SUCCESS)
   143     if (rc != KERN_SUCCESS)
   188     {
   144     {
   202                 retval = 1;
   158                 retval = 1;
   203             } /* if */
   159             } /* if */
   204         } /* if */
   160         } /* if */
   205         IOObjectRelease(service);
   161         IOObjectRelease(service);
   206     } while ((service = IOIteratorNext(iter)) && (!retval));
   162     } while ((service = IOIteratorNext(iter)) && (!retval));
   207 
   163                 
   208     IOObjectRelease(iter);
   164     IOObjectRelease(iter);
   209     IOObjectRelease(service);
   165     IOObjectRelease(service);
   210 
   166 
   211     return retval;
   167     return retval;
   212 } /* darwinIsMountedDisc */
   168 } /* darwinIsMountedDisc */