Exemplo n.º 1
0
bool
VolatileBuffer::Init(size_t aSize, size_t aAlignment)
{
  MOZ_ASSERT(!mSize && !mBuf, "Init called twice");
  MOZ_ASSERT(!(aAlignment % sizeof(void *)),
             "Alignment must be multiple of pointer size");

  mSize = aSize;

  kern_return_t ret = 0;
  if (aSize < MIN_VOLATILE_ALLOC_SIZE) {
    goto heap_alloc;
  }

  ret = vm_allocate(mach_task_self(),
                    (vm_address_t*)&mBuf,
                    mSize,
                    VM_FLAGS_PURGABLE | VM_FLAGS_ANYWHERE);
  if (ret == KERN_SUCCESS) {
    return true;
  }

heap_alloc:
#if(0)
  (void)moz_posix_memalign(&mBuf, aAlignment, aSize);
#else
  // 10.4 doesn't have memalign, but our malloc()s are always aligned to
  // 16 bytes anyway, and that's all we need to support right now.
  if(MOZ_UNLIKELY(aAlignment > 16))
	fprintf(stderr, "Warning: volatile alignment %i.\n", aAlignment);
  mBuf = malloc(aSize);
#endif
  mHeap = true;
  return !!mBuf;
}
Exemplo n.º 2
0
bool
VolatileBuffer::Init(size_t aSize, size_t aAlignment)
{
  MOZ_ASSERT(!mSize && !mBuf, "Init called twice");
  MOZ_ASSERT(!(aAlignment % sizeof(void *)),
             "Alignment must be multiple of pointer size");

  mSize = aSize;

  kern_return_t ret = 0;
  if (aSize < MIN_VOLATILE_ALLOC_SIZE) {
    goto heap_alloc;
  }

  ret = vm_allocate(mach_task_self(),
                    (vm_address_t*)&mBuf,
                    mSize,
                    VM_FLAGS_PURGABLE | VM_FLAGS_ANYWHERE);
  if (ret == KERN_SUCCESS) {
    return true;
  }

heap_alloc:
  (void)moz_posix_memalign(&mBuf, aAlignment, aSize);
  mHeap = true;
  return !!mBuf;
}
Exemplo n.º 3
0
bool VolatileBuffer::Init(size_t aSize, size_t aAlignment)
{
  MOZ_ASSERT(!mSize && !mBuf, "Init called twice");
  MOZ_ASSERT(!(aAlignment % sizeof(void *)),
             "Alignment must be multiple of pointer size");

  mSize = aSize;
#if defined(MOZ_MEMORY)
  posix_memalign(&mBuf, aAlignment, aSize);
#elif defined(HAVE_POSIX_MEMALIGN)
  (void)moz_posix_memalign(&mBuf, aAlignment, aSize);
#else
#error "No memalign implementation found"
#endif
  return !!mBuf;
}
Exemplo n.º 4
0
int
moz_posix_memalign(void **ptr, size_t alignment, size_t size)
{
    int code = posix_memalign(ptr, alignment, size);
    if (code)
        return code;

#if defined(XP_MACOSX)
    // Workaround faulty OSX posix_memalign, which provides memory with the
    // incorrect alignment sometimes, but returns 0 as if nothing was wrong.
    size_t mask = alignment - 1;
    if (((size_t)(*ptr) & mask) != 0) {
        void* old = *ptr;
        code = moz_posix_memalign(ptr, alignment, size);
        free(old);
    }
#endif

    return code;

}