Beispiel #1
0
SysComMsg *SysComCreateMsg(MsgType_t msgtype, u16 sizeofmsg, u16 transid, SthreadId sender, SthreadId receiver)
{
    SysComMsg* msg = NULL;
    void* payload = NULL;
    
    mico_rtos_lock_mutex(&SysComMutex);
    
    msg = (SysComMsg*)MemMalloc(SIZEOF_STRUCT_SYSCOM);
    if(msg == NULL) {
        SysCom_ERR("SysComCreateMsg: msg malloc failed");
    }
    else {
        SysCom_DBG("SysComCreateMsg: malloc msg(addr: 0x%08X) successfully", (addP_t)msg);
        payload = MemMalloc(sizeofmsg);
        if(payload == NULL) {
            SysCom_ERR("SysComCreateMsg: malloc payload failed");
            SysComDestroyMsg(msg);
            SysCom_DBG("SysComCreateMsg: msg destroyed");
            msg = NULL;
        }
        else {
            SysCom_DBG("SysComCreateMsg: malloc payload(addr: 0x%08X) successfully", (addP_t)payload);
            msg->sender = sender;
            msg->receiver = receiver;
            msg->msgType = msgtype;
            msg->transId = transid;
            msg->payload = payload;
        }
    }
    
    mico_rtos_unlock_mutex(&SysComMutex);
    
    return (SysComMsg*)msg;
}
Beispiel #2
0
//==============================================================
void *MemRealloc(int area, void *ptr, size_t size, const char *name)
//--------------------------------------------------------------
// 指定領域を変更
//--------------------------------------------------------------
// in:	area = 領域識別子(enmMEM_AREA)
//		ptr  = 領域(NULL の時は、area 領域から確保)
//		size = 確保するメモリサイズ
//		name = 領域名
//--------------------------------------------------------------
// out:	見つかったメモリ領域の先頭アドレス
//==============================================================
{
    Header *p;

    if(!ptr)
    {
        return MemMalloc(area, size, name);
    }
    else
    {
        p = (Header *)ptr;
        area = (p - 1)->s.area;
        p = (Header *)bsRealloc(&gMem.mem_hdr[area], ptr, size, name);

        return p;
    }
}
Beispiel #3
0
//==============================================================
void *_MmFileLoadB(const char *file, int area)
//--------------------------------------------------------------
// malloc して読み込む
// ※ブロックタイプ
//--------------------------------------------------------------
// in:	file = ファイル名
//		area = 読み込みエリア
//--------------------------------------------------------------
// out:	読み込みアドレス
//==============================================================
{
	sFILE *fp;
	size_t len;
	void *p;

	fp = FsOpen(file);
	ASSERT(fp);
	len = FsGetSizeOrig(fp);
	p = MemMalloc(area, len, GetFileBaseName(file));
	ASSERT(p);
	FsRead(fp, p, len);
	FsClose(fp);

	mn_read_size = len;							// FIXME:実ファイルサイズを返すべきか?

//	PRINTF("File '%s' Loaded.(%d bytes)\n", file, len);

	return p;
}
Beispiel #4
0
INT8U *content_advisory_desc_parse(INT8U *ptrData)
{
#if 0
	INT32U i;
	INT8U rating_region_count;
	INT8U rating_desc_length;
	INT8U rating_dimentions;
//	INT8U rating_region; 
	INT8U *ptr = ptrData;
	INT8U *str;
	
	rating_region_count  = RatingRegionCount(ptr);
	ptr += 3;
	for(i=0; i<rating_region_count; i++)
	{
		ptr++;
		rating_dimentions = *ptr;
		ptr += rating_dimentions * 2;

		rating_desc_length = *ptr;
		// test 
		ptr++;
		str = MemMalloc(rating_desc_length);
		parse_multiple_string(ptr, str);
		ptr += rating_desc_length;
		AM_TRACE("%s\n", str);
	}
#endif
	return NULL;
}
Beispiel #5
0
static char *
GetFilename(const char *tzid)
{
    int len;
    char *ret;
    int i;
    char *dest;

    len = strlen(tzid);

    assert(strncmp(tzid, "/bongo/", strlen("/bongo/")) == 0);
    
    ret = MemMalloc(len * 3 + 4 + 1);

    dest = ret;

    i = strlen("/bongo/");

    for (; i < len; i++) {
        if (tzid[i] == '/') {
            *dest++ = '-';
        } else {
            *dest++ = tzid[i];
        }
    }
    strcpy(dest, ".zone");

    return ret;
}
Beispiel #6
0
List *NewList( unsigned size ) {
/*******************************/
    List        *ret;

    ret = MemMalloc( sizeof( List ) );
    memset( ret, 0, sizeof( List ) );
    ret->itemsize = size;
    return( ret );
}
Beispiel #7
0
CalCmdCommand *
CalCmdNew(char *command, BongoCalTimezone *tz)
{
    CalCmdCommand *cmd = MemMalloc(sizeof(CalCmdCommand));
    if (CalCmdParseCommand(command, cmd, tz)) {
        return cmd;
    }

    return NULL;
}
Beispiel #8
0
PRIVATE
void 
ListGlobalAlloc( void )
{
   int   i;

   ALLOC_UNIT * new_unit = NULL;
   ALLOC_UNIT * old_unit = NULL;

   WAIT_FOR_LOCK( LIST_MUTEX, INFINITE );

   #ifdef USE_SH_POOLS
   new_unit = (ALLOC_UNIT *)MemAllocPtr( gResmmgrMemPool, sizeof( ALLOC_UNIT ), 0 );
   #else
   new_unit = (ALLOC_UNIT *)MemMalloc( sizeof( ALLOC_UNIT ), "LIST_MEM" );
   #endif

   if( !new_unit )
      KEVS_FATAL_ERROR( "No memory for list pool." );

   if( GLOBAL_ALLOC_TABLE )
   {
      old_unit = GLOBAL_ALLOC_TABLE;

      while( old_unit -> next )
         old_unit = old_unit -> next;
      
      old_unit -> next = new_unit;
      new_unit -> prev = old_unit;
      new_unit -> next = NULL;

      old_unit -> sleeping = TRUE;
   }
   else
   {
      new_unit -> next = NULL;
      new_unit -> prev = NULL;
   }

   new_unit -> sleeping = FALSE;

   new_unit -> avail = ALLOC_UNITS;
   new_unit -> index = 0;
   new_unit -> timer = TIME_COUNT;

   new_unit -> min = &new_unit -> unit[0].ptr_a;
   new_unit -> max = &new_unit -> unit[ALLOC_UNITS].ptr_a;

   for( i=0; i<ALLOC_UNITS; i++ )
      new_unit -> unit[i].check = ALLOC_FREE_FLAG;

   GLOBAL_ALLOC_TABLE = new_unit;

   RELEASE_LOCK( LIST_MUTEX );
}
Beispiel #9
0
static statement *mkStatement( char *stmt ) {
/*******************************************/

    statement   *ret;

    assert( stmt );

    ret = MemMalloc( sizeof( statement ) + strlen( stmt ) + 1 );
    memset( ret, 0, sizeof( statement ) );
    strcpy( ret->stmt, stmt );
    return( ret );
}
Beispiel #10
0
_WJElement * _WJENew(_WJElement *parent, char *name, size_t len, const char *file, int line)
{
	_WJElement	*result;
	WJElement	prev;

	if (parent) {
		_WJEChanged((WJElement) parent);

		if (WJR_TYPE_ARRAY == parent->pub.type) {
			/* Children of an array can not have a name */
			name	= NULL;
			len		= 0;
		} else if (WJR_TYPE_OBJECT != parent->pub.type || !name || !*name) {
			/*
				Only arrays and objects can contain children, and elements in an
				object MUST be named.
			*/
			return(NULL);
		}
	}

	if ((result = MemMalloc(sizeof(_WJElement) + len + 1))) {
		memset(result, 0, sizeof(_WJElement));

		MemUpdateOwner(result, file, line);

		if (name) {
			strncpy(result->_name, name, len);
			result->pub.name = result->_name;
		}
		result->_name[len] = '\0';

		if (parent) {
			result->pub.parent = (WJElement) parent;

			if (!parent->pub.child) {
				parent->pub.child = (WJElement) result;
			} else {
				/* Find the last child so it can be added at the end */
				for (prev = parent->pub.child; prev && prev->next; prev = prev->next);

				prev->next = (WJElement) result;
				result->pub.prev = prev;
			}

			parent->pub.count++;
		}

		result->pub.type = WJR_TYPE_OBJECT;
	}

	return(result);
}
Beispiel #11
0
void AddParm( TypeInfo *typ, char *tname, ArrayInfo *array ) {
/*************************************************************/

/* add parameter to current function's list */

    var_rec     *ptmp;

    if( inSubPgm ) {
         return;
    }

    assert( tname );
    assert( typ );

    ptmp = MemMalloc( sizeof( var_rec ) );
    memset( ptmp, 0, sizeof( var_rec ) );
    if( SRU.curr.sp.last_parm ) {
        SRU.curr.sp.last_parm->next = ptmp;
    } else {
        SRU.curr.sp.parm_list = ptmp;
    }
    SRU.curr.sp.last_parm = ptmp;
    copyTypeInfo( &ptmp->type, typ );
    ptmp->typ_id = isTypeKnown( typ );
    if( !ptmp->typ_id ) {
        ptmp->fake = TRUE;
    }
    ptmp->next = NULL;
    ptmp->name = MemStrDup( tname );
    if( array == NULL ) {
        ptmp->array = NULL;
    } else {
        ptmp->array = MemMalloc( sizeof( ArrayInfo ) );
        memcpy( ptmp->array, array, sizeof( ArrayInfo ) );
    }
}
Beispiel #12
0
static void mkConsDesNames( void ) {
/**********************************/

/* puts together SRU constructor and destructor names */

    int         len;
    char        *classname;

    classname = GetClass();
    assert( classname );

    if( SRU.con_name ) {
        MemFree( SRU.con_name );
    }
    if( SRU.des_name ) {
        MemFree( SRU.des_name );
    }

    len = strlen(classname);
    SRU.con_name = MemMalloc( PB_NAME_LEN + 1 );
    GetConstructor( classname, SRU.con_name );
    SRU.des_name = MemMalloc( PB_NAME_LEN + 1 );
    GetDestructor( classname, SRU.des_name );
}
Beispiel #13
0
u_char *InputCreateRecData(int mem_area)
{
	u_char *ptr = NULL;

	if(record != NULL)
	{
		ptr = (u_char *)MemMalloc(mem_area, 4 + sizeof(sInputRecord) * record_ofs, "record");
		ASSERT(ptr);
		*(u_int *)ptr = htonl(record_ofs);
		memcpy(ptr + sizeof(u_int), record, sizeof(sInputRecord) * record_ofs);
		/* FIXME:頭の4バイトにデータサイズを書きこんでいる…が、他に良い実装を思い付かず */
	}
	
	return ptr;
}
Beispiel #14
0
AlarmDBHandle * 
AlarmDBOpen(BongoMemStack *memstack)
{
    char path[XPL_MAX_PATH + 1];
    AlarmDBHandle *handle = NULL;
    int create = 0;
    struct stat sb;

    if (stat(StoreAgent.store.systemDir, &sb)) {
        if (XplMakeDir(StoreAgent.store.systemDir)) {
            printf("Error creating system store: %s\n", strerror(errno));
            return NULL;
        }
    }

    snprintf(path, sizeof(path), "%s/alarms.db", StoreAgent.store.systemDir);
    path[sizeof(path)-1] = 0;

    create = access(path, 0);

    if (!(handle = MemMalloc(sizeof(struct _AlarmDBHandle)))   ||
         (memset(handle, 0, sizeof(struct _AlarmDBHandle)), 0) ||
         (SQLITE_OK != sqlite3_open(path, &handle->db)))
    {
        printf("bongostore: Failed to open alarm store \"%s\".\r\n", path);
        goto fail;
    }

    handle->memstack = memstack;

    if (create && CreateAlarmDB(handle)) {
        printf("Couldn't open db");
        goto fail;
    }

    return handle;

fail:
    if (handle) {
        if (handle->db) {
            sqlite3_close(handle->db);
        }

        MemFree(handle);
    }
    return NULL;
}
Beispiel #15
0
int
BongoThreadPoolAddWork(BongoThreadPool *pool,
                      BongoThreadPoolHandler handler,
                      void *data)
{
    BongoWorkItem *item;
    int ret;
    BOOL spawnThread = FALSE;

    item = MemMalloc(sizeof(BongoWorkItem));
    item->handler = handler;
    item->data = data;

    XplMutexLock(pool->lock);

    item->next = NULL;
    if (pool->tail) {
        pool->tail->next = item;
    }

    if (pool->idle == 0) {
        spawnThread = TRUE;     
    }
    
    pool->tail = item;
    if(pool->head == NULL) {
        pool->head = item;
    }

    /* Possibly spawn a worker */
    if (spawnThread && (pool->total < pool->maximum)) {
        XplThreadID id;
        pool->total++;
        XplBeginThread(&(id), Worker, pool->stackSize, pool, ret);
    } else {
        ret = 0;
    }

    XplMutexUnlock(pool->lock);
    XplSignalLocalSemaphore(pool->todo);

    return ret;
}
Beispiel #16
0
/**
 * Finalise the hash, and return the hash encoded in string format
 * See XplHashFinalBytes()
 * \param	context	Hash context to be used
 * \param 	strcase	Whether or not the string should use upper case
 * \param	buffer	Buffer into which the hash will be written
 * \param	length	Amount of data from buffer to be written
 */
void 
XplHashFinal(xpl_hash_context *context, xpl_hash_stringcase strcase, char *buffer, size_t length) 
{
	char format[5];
	unsigned char *digest;
	char *p;
	unsigned int i;
	
	memcpy(format, "%02X\0", 5);
	if (strcase == XPLHASH_LOWERCASE) 
		format[3] = 'x';
	
	digest = MemMalloc(context->buffer_size);
	memcpy(digest, gcry_md_read(context->gcrypt_context, 0), context->buffer_size);
	gcry_md_close(context->gcrypt_context);
	
	for (i = 0, p = buffer; i < context->buffer_size && p < buffer+length-1; i++, p += 2) {
		sprintf((char *)p, format, digest[i]);
   	}
   	buffer[length-1] = 0;
	
	MemFree(digest);
}
Beispiel #17
0
BongoThreadPool *
BongoThreadPoolNew(const char *name, 
                  int stackSize,
                  int minimum,
                  int maximum,
                  int minSleep) 
{
    BongoThreadPool *pool;

    /* FIXME: do we want a private mempool for work items? */
    
    pool = MemMalloc(sizeof(BongoThreadPool));
    memset(pool, 0, sizeof(BongoThreadPool));
    
    XplMutexInit(pool->lock);
    XplOpenLocalSemaphore(pool->todo, 0);
    pool->minimum = minimum;
    pool->maximum = maximum;
    pool->minSleep = minSleep;
    pool->name = MemStrdup(name);
    pool->stackSize = stackSize;

    return pool;
}