Ejemplo n.º 1
0
Archivo: utils.c Proyecto: atikinn/EOS
/*
 * malloc wrapper which checks for errors and fails immideately
 *
 * n - size to allocate
 *
 * returns void
 */
void 
*emalloc(size_t n) {
    void *rv;
    if ((rv = svc_malloc(n)) == NULL)
        eputs(STDOUT, "out of memory");
    return rv;
}
Ejemplo n.º 2
0
static int cmd_malloc(int argc, char *argv[])
/*
*   function definition for memory malloc command. Calls myMalloc() of memory
*   module with size of memory to be allocated passed as an argument. Prints
*	the memory location on standard output if allocated.
*   Parameters:
*       o int argc- number of arguments
*       o char *argv[] - array of arguments  
*   Return : 0 if successful, otherwise 1
*   sets my_errno to TOO_MANY_ARGUMENTS if more than two argument is passed,
*	sets my_errno to if less than two arguments are passed.
*/
{
	char tempstr[1024];
	if(argc > 2)
	{
		my_errno = TOO_MANY_ARGUMENTS;
		return 1;
	}
	if(argc < 2 )
	{
		my_errno = TOO_FEW_ARGUMENTS;
		return 1;
	}
	char *endPtr;
	unsigned long int size = strtoul(argv[1],&endPtr,0);
	if(endPtr == argv[1] || *endPtr != '\0')
 	{
		my_errno = NOT_VALID_ARGUMENT;
		return 1;
	}
	my_errno = NONE_ERROR;
	void *ptr = svc_malloc(size);
	if(my_errno != NONE_ERROR)
	{
		return 1;
	}
	sprintf(tempstr,"%p\r\n",ptr);uprintf(tempstr);
	return 0;
}
Ejemplo n.º 3
0
Task* usr_task_create_dynamic(const char* name, TASK_FUNCTION func,
		unsigned char priority, unsigned int stack_words)
{
	Task* task;

	//Allocate task control block and stack
	stack_words = (stack_words * 4) + sizeof(TASK_STRU);
	if (__get_CONTROL() & 2)
	{
		task = (Task*)((unsigned int)usr_malloc(stack_words+4) +4);
	} else
	{
		task = (Task*)((unsigned int)svc_malloc(stack_words+4)+4);
	}

	if(task)
	{
		TASK_STACKED_CTX ctx;
		ctx = (TASK_STACKED_CTX) (((unsigned int)task) + stack_words);
		ctx--;
		ctx->psr.as_int = 0x01000000; //thumb mode
		ctx->pc.as_voidptr = (void*) func;
		ctx->lr.as_voidptr = (void*) sys_task_return;

		task->sp = ctx;

		task->priority = priority;
		task->time = main_task.time;
		task->prev = task->next = task->tprev = task->tnext = task;
		task->signals = 0;
		task->aloc_sig = 0;
		task->state = TSKSTATE_SUSPEND;
		strcpy(task->name, name);
	}

	return (task);
}