Exemple #1
0
int main(int argc, char *argv[])
{
  dynmem_init(&Dm);
  dynmem_add_pool(&Dm, Memory1, sizeof(Memory1));
  tlsf_init(&Tlsf);
  tlsf_add_pool(&Tlsf, Memory2, sizeof(Memory2));

  printf("\n\n");
  HEAD
  TEST(free(malloc(16)))
  TEST(free(malloc(200)))
  TEST(free(malloc(550)))
  TEST(free(malloc(65536)))
  TEST(free(malloc(65586)))
  TEST(dynmem_free(&Dm, dynmem_malloc(&Dm, 16)))
  TEST(dynmem_free(&Dm, dynmem_malloc(&Dm, 200)))
  TEST(dynmem_free(&Dm, dynmem_malloc(&Dm, 550)))
  TEST(dynmem_free(&Dm, dynmem_malloc(&Dm, 65536)))
  TEST(dynmem_free(&Dm, dynmem_malloc(&Dm, 65586)))
  TEST(tlsf_free(&Tlsf, tlsf_malloc(&Tlsf, 16)))
  TEST(tlsf_free(&Tlsf, tlsf_malloc(&Tlsf, 200)))
  TEST(tlsf_free(&Tlsf, tlsf_malloc(&Tlsf, 550)))
  TEST(tlsf_free(&Tlsf, tlsf_malloc(&Tlsf, 65536)))
  TEST(tlsf_free(&Tlsf, tlsf_malloc(&Tlsf, 65586)))

  return 0;
}
Exemple #2
0
static ssize_t proc_write(struct file *filp, const char __user *buff,
			unsigned long len, void *data)
{
	unsigned int page_no = 0, clen = 0;
	unsigned long used_size;
	
	if (copy_from_user(&buffer, buff, len)) {
		pr_info("Error copying buffer from user: len=%lu\n", len);
		return -EFAULT;
	}
	//pr_info("buffer=[%s]\n", buffer);
	sscanf(buffer, "%u %u", &page_no, &clen);

	//temp
	//buffer[len] = '\0';

	if (table[page_no])
		tlsf_free(table[page_no], mem_pool);
	if (!(table[page_no] = tlsf_malloc(clen, mem_pool)))
		pr_info("Error allocating mem for page: %u\n", page_no);
	used_size = (unsigned long)tlsf_get_used_size(mem_pool);

	count++;
        //spin_lock(&write_lock);
	//sprintf(buffer, "%lu\n", used_size);
	sprintf(buffer, "%lu %lu %lu\n", count, used_size, used_size >> 10);
	relay_write(relay, buffer, strlen(buffer));
        //relay_write(relay, &used_size, sizeof(unsigned long));
        //spin_unlock(&write_lock);
	return len;
}
Exemple #3
0
//----------------------------------------------------------------//
void* zipfs_malloc ( size_t size ) {

	if ( sTlsfPool ) {
		return tlsf_malloc ( sTlsfPool->mPool, size );
	}
	return malloc ( size );
}
Exemple #4
0
/**
 * Allocate a block of size "bytes"
 */
ATTR_MALLOC void *malloc(size_t bytes)
{
    unsigned old_state = irq_disable();
    void *result = tlsf_malloc(gheap, bytes);

    irq_restore(old_state);
    return result;
}
Exemple #5
0
void *Allocator::alloc_mem(size_t mem_size)
{
    impl->totalAlloced += mem_size;
    void *mem = tlsf_malloc(impl->tlsf, mem_size);
    //printf("Allocator.malloc(%p, %d) = %p\n", impl, mem_size, mem);
    //void *mem = malloc(mem_size);
    //printf("Allocator result = %p\n", mem);
    return mem;
}
Exemple #6
0
//----------------------------------------------------------------//
void* zipfs_calloc ( size_t num, size_t size ) {

	if ( sTlsfPool ) {
		void* ptr = tlsf_malloc ( sTlsfPool->mPool, num * size );
		if ( ptr ) {
			memset ( ptr, 0, num * size );
		}
		return ptr;
	}
	return calloc ( num, size );
}
Exemple #7
0
void *kmalloc(size_t bytes)
{
    uint32_t flags;
    void *ptr;

    save_flags_cli(flags);
    ptr = tlsf_malloc(g_kheap, bytes);
    restore_flags(flags);

    return ptr;
}
void *malloc(size_t bytes)
{
	/*
	 * tlsf_malloc returns NULL for zero bytes, we instead want
	 * to have a valid pointer.
	 */
	if (!bytes)
		bytes = 1;

	return tlsf_malloc(tlsf_mem_pool, bytes);
}
Exemple #9
0
int main(int argc, char** argv) {
	size_t alloc_size = 2642080;
	size_t size = alloc_size + tlsf_size() + tlsf_pool_overhead() + tlsf_alloc_overhead();
	void* memory = ::malloc(size);
	tlsf_t tlsf = tlsf_create_with_pool(memory,size);
	tlsf_walk_pool(tlsf_get_pool(tlsf),0,0);
	std::cout << "try alloc " << std::hex << alloc_size << std::endl;
	void* ptr = tlsf_malloc(tlsf,alloc_size);
	assert(ptr);
	::free(memory);
	return 0;
}
Exemple #10
0
void* _malloc_impl( size_t size, int krn)
{
	if (krn == 1){	// kernel
		if (tlsf_check(kernel_heap))
			krn_debugLogf("TLSF: check failed");
		
		int8_t* ptr = tlsf_malloc(kernel_heap, size);
		if (tlsf_check_pool(kernel_heap))
			krn_debugLogf("TLSFk: check failed");
		//show_mem_info(kernel_heap, krn);
		return ptr;
	} else {		// processes
		void* heapStart = sdk_prc_getHeapPointer();		
		if (tlsf_check_pool(heapStart))
			krn_debugLogf("TLSFa: check failed");
		uint8_t* ptr = tlsf_malloc(heapStart, size);
		tlsf_check(heapStart);
		if (ptr == NULL)
			sdk_debug_logf("Failed to allocate %d bytes.", size);
		//show_mem_info(heapStart, krn);
		return ptr;
	}
}
Exemple #11
0
static void *l_alloc (void *ud, void *ptr, size_t osize,
                                            size_t nsize) {
  void* ret = 0;
   (void)osize;  /* not used */
   if (nsize == 0) {
    //terminal_writeln("");
     tlsf_free(ud, ptr);
     return NULL;
   }
   else {
    if(ptr == 0) {
      ret = tlsf_malloc(ud, nsize);
      //terminal_writehexln(ret);
      return ret;
    }else{
      void* new_mem = tlsf_malloc(ud, nsize);
      memcpy(new_mem, ptr, osize);
      tlsf_free(ud, ptr);
      //terminal_writehexln(new_mem);
      return new_mem;
    }
   }
 }
Exemple #12
0
void *malloc(size_t bytes)
{
  void *r;
  if(bytes == 0)
    return NULL;

  hts_lwmutex_lock(&mutex);
  r = tlsf_malloc(gpool, bytes);
  hts_lwmutex_unlock(&mutex);
  if(r == NULL) {
    memtrace();
    panic("OOM: malloc(%d)", (int)bytes);
  }
  return r;
}
Exemple #13
0
int main(void)
{
	void *mem, *pool;
	pool = tlsf_create_memory_pool(get_mem, put_mem,
				INIT_SIZE, MAX_SIZE, GROW_SIZE);
	mem = tlsf_malloc(4033, pool);
	if (mem == NULL) {
		printf("test: error allocating memory\n");
		return 0;
	}
	memset(mem, 0x0, 4033);
	tlsf_free(mem, pool);
	tlsf_destroy_memory_pool(pool);
	return 0;
}
Exemple #14
0
u64 simMalloc(u32 size)
{
	void *ptr;

	countAlloc++;

	ptr = tlsf_malloc(size, pool);
	if (!ptr) {
		return 0;
	}

	showStats(pool);

	return (u64)((size_t)(ptr));
}
Exemple #15
0
bool Allocator::lowMemory(unsigned n, size_t chunk_size)
{
    //This should stay on the stack
    void *buf[n];
    for(unsigned i=0; i<n; ++i)
        buf[i] = tlsf_malloc(impl->tlsf, chunk_size);
    bool outOfMem = false;
    for(unsigned i=0; i<n; ++i)
        outOfMem |= (buf[i] == nullptr);
    for(unsigned i=0; i<n; ++i)
        if(buf[i])
            tlsf_free(impl->tlsf, buf[i]);

    return outOfMem;
}
Exemple #16
0
void *
mymalloc(size_t bytes)
{
  if(bytes == 0)
    return NULL;

  hts_lwmutex_lock(&mutex);
  void *r = tlsf_malloc(gpool, bytes);
  hts_lwmutex_unlock(&mutex);

  if(r == NULL) {
    memtrace();
    tracelog(TRACE_NO_PROP, TRACE_ERROR, "MEMORY",
          "malloc(%d) failed", (int)bytes);
    errno = ENOMEM;
  }
  return r;
}
Exemple #17
0
		void push_back(T const &e) {
			assert(toCopy <= used);
			assert(used < capacity);
			// Incrementally copy elements from container to nextContainer:
			if(toCopy <= (used - 1)) {
				nextContainer[toCopy] = container[toCopy];
				++toCopy;
			}
			// Actually push back new element to both containers:
			container[used] = e;
			nextContainer[used] = e;
			++used;
			if(used == capacity) {
				tlsf_free(static_cast< void * >(container));
				container = nextContainer;
				capacity *= 2;
				nextContainer = static_cast< T * >(tlsf_malloc(2 * capacity * sizeof(T)));
				toCopy = 0;
			}
		}
Exemple #18
0
static void *g_realloc(void *ptr, size_t osize, size_t size)
{
    void* p = NULL;

    if (ptr && size == 0)
    {
        g_free(ptr);
    }
    else if (ptr == NULL)
    {
        if (size <= 256)
            p = tlsf_malloc(memory_pool, size);

        if (p == NULL)
            p = ::malloc(size);
    }
    else
    {
        if (memory_pool <= ptr && ptr < memory_pool_end)
        {
            if (size <= 256)
                p = tlsf_realloc(memory_pool, ptr, size);

            if (p == NULL)
            {
                p = ::malloc(size);
                memcpy(p, ptr, osize);
                tlsf_free(memory_pool, ptr);
            }
        }
        else
        {
            p = ::realloc(ptr, size);
        }
    }

    return p;
}
int heapobj_pkg_init_private(void)
{
	size_t size;
	void *mem;

	/*
	 * We want to know how many bytes from a memory pool TLSF will
	 * use for its own internal use. We get the probe memory from
	 * tlsf_malloc(), so that the main pool will be set up in the
	 * same move.
	 */
	mem = tlsf_malloc(__this_node.mem_pool);
	size = init_memory_pool(__this_node.mem_pool, mem);
	if (size == (size_t)-1)
		panic("cannot initialize TLSF memory manager");

	destroy_memory_pool(mem);
	tlsf_pool_overhead = __this_node.mem_pool - size;
	tlsf_pool_overhead = (tlsf_pool_overhead + 15) & ~15;
	tlsf_free(mem);

	return 0;
}
int heapobj_init_private(struct heapobj *hobj, const char *name,
			 size_t size, void *mem)
{
	if (mem == NULL) {
		/*
		 * When the memory area is unspecified, obtain it from
		 * the main pool, accounting for the TLSF overhead.
		 */
		size += tlsf_pool_overhead;
		mem = tlsf_malloc(size);
		if (mem == NULL)
			return __bt(-ENOMEM);
	}

	if (name)
		snprintf(hobj->name, sizeof(hobj->name), "%s", name);
	else
		snprintf(hobj->name, sizeof(hobj->name), "%p", hobj);
#ifdef CONFIG_XENO_PSHARED
	hobj->ops = &tlsf_ops;
#endif
	hobj->pool = mem;
	/* Make sure to wipe out tlsf's signature. */
	memset(mem, 0, size);
	hobj->size = init_memory_pool(size, mem);
	if (hobj->size == (size_t)-1)
		return __bt(-EINVAL);

	/*
	 * TLSF does not lock around so-called extended calls aimed at
	 * specific pools, which is definitely braindamage. So DIY.
	 */
	__RT(pthread_mutex_init(&hobj->lock, NULL));

	return 0;
}
Exemple #21
0
			void* malloc( size_t size )
			{
				return tlsf_malloc( g_tlsfPool, size );
			}
void * pvPortMalloc( size_t xWantedSize ){
	vTaskSuspendAll();
	void * res = tlsf_malloc(xWantedSize);
	xTaskResumeAll();
	return res;
}
Exemple #23
0
void *malloc(size_t bytes)
{
	return tlsf_malloc(tlsf_mem_pool, bytes);
}
Exemple #24
0
		vector_const_tlsf() : capacity(1), used(0), toCopy(0) {
			container = static_cast< T * >(tlsf_malloc(1 * sizeof(T)));
			nextContainer = static_cast< T * >(tlsf_malloc(2 * sizeof(T)));
		}
void *pvmalloc(size_t size)
{
	return tlsf_malloc(size);
}