void * OS2_create_msg_fifo (void) { msg_fifo_t * fifo = (OS_malloc (sizeof (msg_fifo_t))); (fifo -> start) = 0; (fifo -> end) = 0; (fifo -> count) = 0; (fifo -> buffer_length) = BUFFER_MIN_LENGTH; (fifo -> buffer) = (OS_malloc ((fifo -> buffer_length) * (sizeof (void *)))); return (fifo); }
void RplNode_TestHeap() { void* p1 = malloc(50); void* p2 = OS_malloc(50); C_NLOG ("RplNode_TestHeap: p1=%p p2=%p",p1,p2); }
/***************************************************************************** * Function - AllocBlock * DESCRIPTION: Allocates one block of bytes and put it in the chain. * * Return: True if 'bytes' were allocated, false otherwise * *****************************************************************************/ bool TestAlloc::AllocBlock(int bytes) { #define MALLOC_OVERHEAD 8 if (bytes < sizeof(BLOCK)+MALLOC_OVERHEAD) { bytes = sizeof(BLOCK)+MALLOC_OVERHEAD; } #if defined TEST_USING_NEW_DELETE char* p_block = new char[bytes-MALLOC_OVERHEAD]; #elif defined TEST_USING_C_MALLOC_FREE char* p_block = (char*)malloc(bytes-MALLOC_OVERHEAD); #elif defined TEST_USING_OS_MALLOC_FREE char* p_block = (char*)OS_malloc(bytes-MALLOC_OVERHEAD); #endif if (p_block != NULL) { if (mFirstBlock == NULL) //nothing allocated yet { mFirstBlock = (BLOCK*)p_block; mLastBlock = mFirstBlock; } else { mLastBlock->next_block = (BLOCK*)p_block; mLastBlock = mLastBlock->next_block; //extend the chain } mLastBlock->next_block = NULL; mLastBlock->memory_used = bytes; } return (p_block != NULL); }
static size_t allocate_context_entry (void) { size_t i = (search_context_table (0)); if (i < context_table_length) return (i); if (i == 0) { context_table_length = 256; context_table = (OS_malloc ((sizeof (context_entry)) * context_table_length)); } else { context_table_length *= 2; context_table = (OS_realloc (context_table, ((sizeof (context_entry)) * context_table_length))); } { size_t j; for (j = i; (j < context_table_length); j += 1) ((context_table[j]) . context) = 0; } return (i); }
tqueue_t * OS2_make_std_tqueue (void) { tqueue_t * tqueue = (OS_malloc (sizeof (std_tqueue_t))); (TQUEUE_TYPE (tqueue)) = tqt_std; (STD_TQUEUE_FIFO (tqueue)) = (OS2_create_queue (QUE_FIFO)); (STD_TQUEUE_EVENT (tqueue)) = (OS2_create_event_semaphore (0, 0)); return (tqueue); }
tqueue_t * OS2_make_std_tqueue (void) { tqueue_t * tqueue = (OS_malloc (sizeof (std_tqueue_t))); (TQUEUE_TYPE (tqueue)) = tqt_std; (STD_TQUEUE_FIFO (tqueue)) = (OS2_create_msg_fifo ()); (STD_TQUEUE_N_BLOCKED (tqueue)) = 0; (STD_TQUEUE_MUTEX (tqueue)) = (OS2_create_mutex_semaphore (0, 0)); (STD_TQUEUE_EVENT (tqueue)) = (OS2_create_event_semaphore (0, 0)); return (tqueue); }
const char * OS_canonical_host_name (const char * host_name) { struct hostent * entry = (gethostbyname (host_name)); if (entry == 0) return (0); { char * result = (OS_malloc ((strlen (entry -> h_name)) + 1)); strcpy (result, (entry -> h_name)); return (result); } }
SButton_dev * Button_initButtonDev() { UCHAR i = 0; buttons_info = (SButton_dev*)OS_malloc(sizeof(SButton_dev)); if(!buttons_info) { printk("buttonDev: kmalloc memory failed !\n"); } OS_memset(buttons_info, 0, sizeof(SButton_dev)); buttons_info->Buttoninfo_Queue = (SButtonCmdQueue *)OS_malloc(sizeof( SButtonCmdQueue)); OS_memset( buttons_info->Buttoninfo_Queue, 0, sizeof(SButtonCmd) * BUTTON_INFO_QUEUE_SIZE); buttons_info->Buttoninfo_Queue->front = 0; buttons_info->Buttoninfo_Queue->rear = 0; OS_AllocateSpinLock(&(buttons_info->lock)); OS_InitWaitQueueHead(&(buttons_info->lowerpart_Wait_Queue)); buttons_info->condition_for_lowpart = FALSE; buttons_info->globalIrqDesc = button_irqs; buttons_info->irqDescNum = sizeof(button_irqs)/sizeof(button_irqs[0]); printk(KERN_INFO "irqDescNum = %d\n", buttons_info->irqDescNum); for(i=0;i<buttons_info->irqDescNum;i++) { buttons_info->globalIrqDesc[i].buttonDevPtr = (void *)buttons_info; } return buttons_info; }
void *osAllocMem(size_t size) { void *p; //Allocate a memory block p = OS_malloc(size); //Debug message TRACE_DEBUG("Allocating %" PRIuSIZE " bytes at 0x%08" PRIXPTR "\r\n", size, (uintptr_t) p); //Return a pointer to the newly allocated memory block return p; }
const char * OS_get_host_by_address (const char * host_addr) { struct hostent * entry = (gethostbyaddr (host_addr, (OS_host_address_length ()), AF_INET)); if (entry == 0) return (0); { char * result = (OS_malloc ((strlen (entry -> h_name)) + 1)); strcpy (result, (entry -> h_name)); return (result); } }
/*----------------------------------------------------------------------* _rtp_malloc *----------------------------------------------------------------------*/ void * _rtp_malloc (unsigned long size) { void *retVal; if (size >= 0x80000000) { return 0; } retVal = OS_malloc ((size_t) size); if(!retVal) exit(0); return retVal; }
/*----------------------------------------------------------------------* _rtp_calloc *----------------------------------------------------------------------*/ void * _rtp_calloc (unsigned long num, unsigned long size) { void *retVal; if (size >= 0x80000000) { return 0; } //return (calloc ((size_t) num, (size_t) size)); retVal = OS_malloc ((size_t) num * (size_t) size); if(retVal) memset(retVal, 0, num * size); if(!retVal) exit(0); return retVal; }
static void initialize_hashid_map (void) { if (hashid_map == 0) { size_t i = 0; size_t j = 0; hashid_count = (mhash_count ()); hashid_map = (OS_malloc ((sizeof (hashid)) * hashid_count)); while (i <= hashid_count) { if ((mhash_get_block_size (i)) != 0) (hashid_map[j++]) = ((hashid) i); i += 1; } } }
const char * OS_get_host_name (void) { unsigned int name_length = 128; char * name = (OS_malloc (name_length)); while (1) { if ((gethostname (name, name_length)) != SOCKET_ERROR) break; { DWORD code = (WSAGetLastError ()); if (code != WSAEFAULT) { OS_free (name); NT_error_api_call (code, apicall_gethostname); } } name_length *= 2; name = (OS_realloc (name, name_length)); } return (OS_realloc (name, ((strlen (name)) + 1))); }
static unsigned int allocate_table_index (struct allocation_table * table, void * item) { unsigned int length = (table -> length); unsigned int new_length; void ** items = (table -> items); void ** new_items; void ** scan; void ** end; if (length == 0) { new_length = 4; new_items = (OS_malloc ((sizeof (void *)) * new_length)); } else { scan = items; end = (scan + length); while (scan < end) if ((*scan++) == 0) { (*--scan) = item; return (scan - items); } new_length = (length * 2); new_items = (OS_realloc (items, ((sizeof (void *)) * new_length))); } scan = (new_items + length); end = (new_items + new_length); (*scan++) = item; while (scan < end) (*scan++) = 0; (table -> items) = new_items; (table -> length) = new_length; return (length); }
/*----------------------------------------------------------------------* _rtp_malloc *----------------------------------------------------------------------*/ void * _rtp_malloc (unsigned long size) { return (OS_malloc ((size_t) size)); }