Home | History | Annotate | Download | only in base
      1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "base/process_util_unittest_mac.h"
      6 
      7 #import <Foundation/Foundation.h>
      8 #include <CoreFoundation/CoreFoundation.h>
      9 
     10 #if !defined(ARCH_CPU_64_BITS)
     11 
     12 // In the 64-bit environment, the Objective-C 2.0 Runtime Reference states
     13 // that sizeof(anInstance) is constrained to 32 bits. That's not necessarily
     14 // "psychotically big" and in fact a 64-bit program is expected to be able to
     15 // successfully allocate an object that large, likely reserving a good deal of
     16 // swap space. The only way to test the behavior of memory exhaustion for
     17 // Objective-C allocation in this environment would be to loop over allocation
     18 // of these large objects, but that would slowly consume all available memory
     19 // and cause swap file proliferation. That's bad, so this behavior isn't
     20 // tested in the 64-bit environment.
     21 
     22 @interface PsychoticallyBigObjCObject : NSObject
     23 {
     24   // In the 32-bit environment, the compiler limits Objective-C objects to
     25   // < 2GB in size.
     26   int justUnder2Gigs_[(2U * 1024 * 1024 * 1024 - 1) / sizeof(int)];
     27 }
     28 
     29 @end
     30 
     31 @implementation PsychoticallyBigObjCObject
     32 
     33 @end
     34 
     35 namespace base {
     36 
     37 void* AllocatePsychoticallyBigObjCObject() {
     38   return [[PsychoticallyBigObjCObject alloc] init];
     39 }
     40 
     41 }  // namespace base
     42 
     43 #endif  // ARCH_CPU_64_BITS
     44 
     45 namespace base {
     46 
     47 void* AllocateViaCFAllocatorSystemDefault(ssize_t size) {
     48   return CFAllocatorAllocate(kCFAllocatorSystemDefault, size, 0);
     49 }
     50 
     51 void* AllocateViaCFAllocatorMalloc(ssize_t size) {
     52   return CFAllocatorAllocate(kCFAllocatorMalloc, size, 0);
     53 }
     54 
     55 void* AllocateViaCFAllocatorMallocZone(ssize_t size) {
     56   return CFAllocatorAllocate(kCFAllocatorMallocZone, size, 0);
     57 }
     58 
     59 }  // namespace base
     60