Exemple #1
0
void
free(void *x)
{
    sylvester(x);
    *(gulong *)x = MAGIC2;
    __libc_free((char *)x - sizeof(struct header));
}
Exemple #2
0
void free(void* addr) {
  printf("free wrapper\n");

  if (addr == 0){
    return;
  }

  void* block = addr-8;

  /* to be able to read the tag*/
  lmem_unprotect(block+0);
  lmem_unprotect(block+1);
  lmem_unprotect(block+2);
  lmem_unprotect(block+3);
  lmem_unprotect(block+4);
  lmem_unprotect(block+5);
  lmem_unprotect(block+6);
  lmem_unprotect(block+7);

  unsigned tag = *((unsigned*)block);
  if (tag != 0xdeadbeef){
    printf("WARNING: WAS NOT ALLOCATED BY US: IGNORING\n");
    return;
  }

  size_t size = *(((unsigned*)block)+1);
  void* res_end = block + 8 + size;

  lmem_unprotect(res_end);
  lmem_unprotect(res_end+1);
  lmem_unprotect(res_end+2);
  lmem_unprotect(res_end+3);

  __libc_free(block);
}
Exemple #3
0
void free(void *ptr)
{
        static int      in_progress = 0;
        void __libc_free(void *ptr);
        
        if (in_progress) return;
        in_progress = 1;
        __libc_free(ptr);
        in_progress = 0;
}
Exemple #4
0
void free(void* ptr)
{
	pfunc();
	VirtioQCArg arg;
	ptr(arg.pA, ptr, 0);
	send_cmd_to_device(VIRTQC_CMD_MMAPRELEASE, &arg);

#ifdef USER_KERNEL_COPY
	if((int)arg.cmd == -1)
		__libc_free(ptr);
#endif
}
extern "C" void free(void* in)
{
    size_t oldsize = (D && in) ? malloc_usable_size(in) : 0;
    REF;
    __libc_free(in);
    if (D && oldsize) {
        D->now_usable.fetchAndAddOrdered(-oldsize);
        D->now_overhead.fetchAndAddOrdered(-CHUNK_OVERHEAD);
        D->updatePeak();
    }
    DEREF;
}
Exemple #6
0
void
free(__ptr_t p)
{
    if (p) {
        /* In glibc-2.2.4, malloc uses a two word block header: the
           second word -- modulo the low bit -- is the size of the
           current block. */
        size_t sz = *(((size_t *) p) - 1) & ~0x1;
        memset(p, 0xdd, sz - 4 /* XXX shrug! */);
    }

    --live_blocks;
    __libc_free(p);
}
Exemple #7
0
void free (void *mem)
{
  gpointer real;

  if (mem == NULL)
    return;

  real = ((char*)mem) - HEADER_SPACE;

  g_assert (current_allocation >= 0);
  current_allocation -= GPOINTER_TO_INT (*(void**)real);
  g_assert (current_allocation >= 0);

  __libc_free (real);
}
void free(void* ptr)
{
  if( ! ptr ) return;
  if( DEBUG_REPLACE_MALLOC ) 
    printf("in free(%p)\n", ptr);
  // check to see if we're freeing a pointer that was allocated
  // before the our allocator came up.
  if( !chpl_mem_inited() || is_system_allocated(ptr, NULL) ) {
    if( DEBUG_REPLACE_MALLOC ) 
      printf("calling system free\n");
    __libc_free(ptr);
    return;
  }

  if( DEBUG_REPLACE_MALLOC ) 
    printf("calling chpl_free\n");
  chpl_free(ptr);
}
void* realloc(void* ptr, size_t size)
{
  if( !chpl_mem_inited() ) {
    void* ret = __libc_realloc(ptr, size);
    if( DEBUG_REPLACE_MALLOC ) 
      printf("in early realloc %p = system realloc(%p,%#x)\n",
             ret, ptr, (int) size);
    track_system_allocated(ret, size, __libc_malloc);
    return ret;
  } else {
    void* ret = NULL;
    size_t allocated_len = 0;
    size_t copy_size;

    if( DEBUG_REPLACE_MALLOC )
      printf("in realloc(%p,%#x)\n", ptr, (int) size);

    // check to see if we're realloc'ing a pointer that was allocated
    // before the our allocator came up.
    if( is_system_allocated(ptr, &allocated_len) ) {
      if( DEBUG_REPLACE_MALLOC ) {
        printf("in realloc, ptr %p was system allocated to size %#x\n",
               ptr, (int) allocated_len);
      }

      // allocate some new memory on the Chapel heap
      ret = chpl_malloc(size);

      // copy the minimum of allocated_len and size
      // to handle realloc expanding or shrinking the allocation
      copy_size = allocated_len;
      if( size < copy_size ) copy_size = size;

      memcpy(ret, ptr, copy_size);

      // free the old pointer from the system heap.
      __libc_free(ptr);
      return ret;
    } else {
      return chpl_realloc(ptr, size);
    }
  }
}
static void
mem_return_memory(void *data,
		  size_t alloc_size,
		  mem_alloc_hdr_t *mh)
{
    mem_slot_queue_t *pslot = mh->pslot;
    size_t sn;
    size_t align = mh->align_log2;
    int ispool   = mh->flags;

    if (!nkn_pool_enable || align || (alloc_size > SIZE_MAX_SLOT))
	goto ret_poolmiss;

    SIZE_TO_SLOT(alloc_size, sn);

    // Must be an exact size match to add to the pool.
    if (alloc_size != SLOT_TO_SIZE(sn))
	goto ret_poolmiss;

    if (ispool && !mem_slot_put(pslot, data))
	return;
#ifdef MEM_DEBUG

    /*
     * Because we bump 'miss' on a 'get' which can not find an obj
     * but whose size fits the pool, we must bump 'free' when we
     * free an obj which never calls mem_slot_put but should fit
     * into the pool
     */
    SLOT_LOCK(pslot);
    pslot->free++;
    SLOT_UNLOCK(pslot);
#endif


 ret_poolmiss:
    __libc_free(data);
    return;
}
Exemple #11
0
static gpointer
record_bytes (gpointer mem, gsize bytes)
{
  if (mem == NULL ||
      (current_allocation + bytes) > max_allocation)
    {
      if (mem)
        __libc_free (mem);

      return NULL;
    }
  
  *(void **)mem = GINT_TO_POINTER (bytes);

  g_assert (GPOINTER_TO_INT (*(void**)mem) == bytes);
  
  g_assert (current_allocation >= 0);
  current_allocation += bytes;
  g_assert (current_allocation >= 0);
  
  g_assert ( mem == (void*) ((((char*)mem) + HEADER_SPACE) - HEADER_SPACE) );
  return ((char*)mem) + HEADER_SPACE;
}
Exemple #12
0
void free(void *ptr)
{
	wrap_log("free(%p)\n", ptr);
	__libc_free(ptr);
}
Exemple #13
0
// check that such kind of free/realloc overload works correctly
void free(void *ptr)
{
    __libc_free(ptr);
}