Changeset 15439


Ignore:
Timestamp:
Aug 14, 2012, 3:04:37 AM (7 years ago)
Author:
gb
Message:

In the new code that allocates memory for TCRs on 64-bit Darwin, don't
use MAP_FIXED (and therefore avoid the thread-safety problems that
using it introduced.) As of OSX 10.5, mmap() will use the supplied
address if it doesn't confict with a mapped region and as of 10.6
it's documented to do so.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/memory.c

    r15437 r15439  
    989989  allocate substantially more than we need.
    990990
    991   The bulk allocation works by scanning the task's mapped memory regions
    992   until a free region of appropriate size is found, then mapping that
    993   region.  There is no way that I know of to prevent a foreign thread
    994   from trying to map this region while we're doing so.
     991  The bulk allocation works by scanning the task's mapped memory
     992  regions until a free region of appropriate size is found, then
     993  mapping that region (without the dangerous use of MAP_FIXED).  This
     994  will win if OSX's mmap() tries to honor the suggested address if it
     995  doesn't conflict with a mapped region (as it seems to in practice
     996  since at least 10.5 and as it's documented to in 10.6.)
    995997*/
    996998
     
    10011003#define TCR_CLUSTER_COUNT 1024   /* Enough that we allocate clusters rarely,
    10021004but not so much that we waste lots of 32-bit memory. */
     1005
     1006#define LIMIT_32_BIT (natural)(1L<<32L)
    10031007
    10041008void
     
    10081012  int i;
    10091013  vm_address_t addr = (vm_address_t)0, nextaddr;
    1010 
     1014  void *p;
    10111015  vm_size_t request_size = align_to_power_of_2((TCR_CLUSTER_COUNT*sizeof(TCR)),log2_page_size), vm_size;
    10121016  vm_region_basic_info_data_64_t vm_info;
     
    10291033    }
    10301034    if (addr && ((nextaddr - addr) > request_size)) {
    1031       if ((addr + request_size) > (1L << 32L)) {
     1035      if ((addr + request_size) > LIMIT_32_BIT) {
    10321036        break;
    10331037      }
    1034       if (mmap((void *)addr,
     1038      p = mmap((void *)addr,
    10351039               request_size,
    10361040               PROT_READ|PROT_WRITE,
    1037                MAP_PRIVATE|MAP_ANON|MAP_FIXED,
     1041               MAP_PRIVATE|MAP_ANON,
    10381042               -1,
    1039                0) != (void *)addr) {
     1043               0);
     1044      if (p == MAP_FAILED) {
    10401045        break;
     1046      } else {
     1047        if (((natural)p > LIMIT_32_BIT) ||
     1048            ((((natural)p)+request_size) > LIMIT_32_BIT)) {
     1049          munmap(p, request_size);
     1050          nextaddr = 0;
     1051          vm_size = 0;
     1052        } else {
     1053          work = (TCR *) p;
     1054          break;
     1055        }
    10411056      }
    1042       work = (TCR *)addr;
    1043       break;
    10441057    }
    10451058    addr = nextaddr + vm_size;   
Note: See TracChangeset for help on using the changeset viewer.