Exemplo n.º 1
0
static int handle_exception_message (RDebug *dbg, exc_msg *msg, int *ret_code) {
	int ret = R_DEBUG_REASON_UNKNOWN;
	kern_return_t kr;
	*ret_code = KERN_SUCCESS;
	switch (msg->exception) {
	case EXC_BAD_ACCESS:
		ret = R_DEBUG_REASON_SEGFAULT;
		*ret_code = KERN_FAILURE;
		kr = task_suspend (msg->task.name);
		if (kr != KERN_SUCCESS) {
			eprintf ("failed to suspend task bad access\n");
		}
		eprintf ("EXC_BAD_ACCESS\n");
		break;
	case EXC_BAD_INSTRUCTION:
		ret = R_DEBUG_REASON_ILLEGAL;
		*ret_code = KERN_FAILURE;
		kr = task_suspend (msg->task.name);
		if (kr != KERN_SUCCESS) {
			eprintf ("failed to suspend task bad instruction\n");
		}
		eprintf ("EXC_BAD_INSTRUCTION\n");
		break;
	case EXC_ARITHMETIC:
		eprintf ("EXC_ARITHMETIC\n");
		break;
	case EXC_EMULATION:
		eprintf ("EXC_EMULATION\n");
		break;
	case EXC_SOFTWARE:
		eprintf ("EXC_SOFTWARE\n");
		break;
	case EXC_BREAKPOINT:
		kr = task_suspend (msg->task.name);
		if (kr != KERN_SUCCESS) {
			eprintf ("failed to suspend task breakpoint\n");
		}
		ret = R_DEBUG_REASON_BREAKPOINT;
		break;
	default:
		eprintf ("UNKNOWN\n");
		break;
	}
	kr = mach_port_deallocate (mach_task_self (), msg->task.name);
	if (kr != KERN_SUCCESS) {
		eprintf ("failed to deallocate task port\n");
	}
	kr = mach_port_deallocate (mach_task_self (), msg->thread.name);
	if (kr != KERN_SUCCESS) {
		eprintf ("failed to deallocated task port\n");
	}
	return ret;
}
Exemplo n.º 2
0
int
proc_apply_resource_actions(void * bsdinfo, __unused int type, int action)
{
	proc_t p = (proc_t)bsdinfo;

	switch(action) {
		case PROC_POLICY_RSRCACT_THROTTLE:
			/* no need to do anything */
			break;

		case PROC_POLICY_RSRCACT_SUSPEND:
			task_suspend(p->task);
			break;

		case PROC_POLICY_RSRCACT_TERMINATE:
			psignal(p, SIGKILL);
			break;

		case PROC_POLICY_RSRCACT_NOTIFY_KQ:
			/* not implemented */
			break;
		
		case PROC_POLICY_RSRCACT_NOTIFY_EXC:
			panic("shouldn't be applying exception notification to process!");
			break;
	}

	return(0);
}
Exemplo n.º 3
0
/** The tilt display effect runs until explicitly cancelled. */
void tilt_deff (void)
{
	dmd_alloc_low_clean ();
	font_render_string_center (&font_cu17, 64, 13, "TILT");
	dmd_show_low ();
	task_suspend ();
}
Exemplo n.º 4
0
static void task_suspend_taskB()
{
	task_delay(50); 
	printf("msgB\n");
	task_suspend(task_suspendA);
	task_delay(150);
}
Exemplo n.º 5
0
int sys_poll_hdlr(uint32_t arg1, uint32_t arg2, uint32_t arg3)
{
    struct pollfd *pfd = (struct pollfd *)arg1;
    int i, n = (int)arg2;
    uint32_t timeout = jiffies + arg3;
    int ret = 0;
    struct fnode *f;

    /* TODO: Set process wakeup timer */

    while (jiffies < timeout) {
        for (i = 0; i < n; i++) {
            f = task_filedesc_get(pfd[i].fd);
            if (!f || !f->owner || !f->owner->ops.poll) {
                return -EOPNOTSUPP;
            }
            ret += f->owner->ops.poll(f, pfd[i].events, &pfd[i].revents);
        }
        if (ret > 0)
            return ret;
        task_suspend();
        return SYS_CALL_AGAIN;
    }
    return 0;
}
Exemplo n.º 6
0
void slam_tilt_deff (void)
{
	dmd_alloc_low_clean ();
	font_render_string_center (&font_fixed10, 64, 13, "SLAM TILT");
	dmd_show_low ();
	task_suspend ();
}
Exemplo n.º 7
0
static int pipe_read(struct fnode *f, void *buf, unsigned int len)
{
    struct pipe_priv *pp;
    int out, len_available;
    uint8_t *ptr = buf;

    if (f->owner != &mod_pipe)
        return -EINVAL;

    pp = (struct pipe_priv *)f->priv;
    if (!pp)
        return -EINVAL;

    if (pp->fno_r != f)
        return -EPERM;

    len_available =  cirbuf_bytesinuse(pp->cb);
    if (len_available <= 0) {
        pp->pid_r = scheduler_get_cur_pid();
        task_suspend();
        return SYS_CALL_AGAIN;
    }

    for(out = 0; out < len; out++) {
        /* read data */
        if (cirbuf_readbyte(pp->cb, ptr) != 0)
            break;
        ptr++;
    }
    pp->pid_r = 0;
    return out;
}
Exemplo n.º 8
0
EXPORT
mach_port_t suspend(mach_port_t task) {
    printf("SUSPENDING TASK!\n");
    task_suspend(task);

    return task;
}
Exemplo n.º 9
0
int BreakPoint::set(mach_port_t task, unsigned long address) {
	printf("Setting breakpoint at address: %lu\n", address);
	int err;
	if(task_suspend(task) != KERN_SUCCESS) {
		printf("Suspend: %s\n", mach_error_string(err));
		return -1;
	}
	vm_offset_t intermediary;
	mach_msg_type_number_t size = (size_t)1;
	//printf("%llu\n", size);
	//char orig = static_cast<char>(*address);
	if(KERN_SUCCESS != (err = vm_protect(task, (vm_offset_t)address, (size_t)1, false, VM_PROT_ALL))) {
		printf("Protect: %s\n", mach_error_string(err));
	}
	/*if (KERN_SUCCESS != (err = mach_vm_read(task, address, (mach_vm_size_t)1, (&intermediary), &size))) {
		printf("Read: %s\n", mach_error_string(err));
	}
	printf("Intermediary: %lu\n", intermediary);
	original_byte = intermediary;
	printf("Original Byte: %c\n", original_byte);
	char value = 0xCC;
	vm_offset_t break_trigger = (unsigned long)&value;
	*(char *)break_trigger = 0xCC;
	if(KERN_SUCCESS != (err = mach_vm_write(task, address, break_trigger, size))) {
		printf("Write: %s\n", mach_error_string(err));
	}*/
	if(task_resume(task) != KERN_SUCCESS) {
		printf("Resume: %s\n", mach_error_string(err));
		return -1;
	}
	return 0;
}
Exemplo n.º 10
0
Arquivo: pet.c Projeto: CptFrazz/xnu
/* given a list of tasks, sample all the threads in 'em */
static void
pet_sample_task_list( int taskc, task_array_t taskv  )
{
	int i;
	
	for( i = 0; i < taskc; i++ )
	{
		kern_return_t kr;
		task_t task = taskv[i];

		/* FIXME: necessary? old code did this, our hacky
		 * filtering code does, too
		 */
		if(!task) {
			continue;
		}
		
		/* try and stop any task other than the kernel task */
		if( task != kernel_task )
		{
			kr = task_suspend( task );

			/* try the next task */
			if( kr != KERN_SUCCESS )
				continue;
		}
		
		/* sample it */
		pet_sample_task( task );

		/* if it wasn't the kernel, resume it */
		if( task != kernel_task )
			task_resume(task);
	}
}
Exemplo n.º 11
0
// sets whether this task is running, suspended, or resumes a previous
// state if set to don't care.
// if set to run or suspend, effective immediately
void set_single_task_state(bool running, task_type_t task_id) {
	configASSERT(task_id < NUM_TASKS);
	if (running) {
		task_resume(task_id);
	} else {
		task_suspend(task_id);
	}
}
Exemplo n.º 12
0
void zombie(int sig, int code, struct sigcontext *scp) {
    memcpy(&OldContext, scp, (int)sizeof(struct sigcontext));
    LogMsg(0, 0, LogFile,  "****** INTERRUPTED BY SIGNAL %d CODE %d ******", sig, code);
    LogMsg(0, 0, LogFile,  "****** Aborting outstanding transactions, stand by...");
    
    LogMsg(0, 0, LogFile, "To debug via gdb: attach %d, setcontext OldContext", getpid());
    LogMsg(0, 0, LogFile, "Becoming a zombie now ........");
    task_suspend(task_self());
}
Exemplo n.º 13
0
void test_watchdog_reset_bat_charging(void) {
	TickType_t ms = xTaskGetTickCount();

	check_set_sat_state(INITIAL, INITIAL);
	if (ms > 2 * ATTITUDE_DATA_TASK_FREQ + TASK_EXECUTION_WINDOW_BUFFER_TIME) {
		task_suspend(BATTERY_CHARGING_TASK);
	}

	// watchdog should reset eventually
}
Exemplo n.º 14
0
s8int task_sleep( u32int tick ){
	task_t *task;
	task = current_task;
	
	task_suspend(task);
	
	timer_control(&task->timer, SET_TIME, tick);
	timer_start(&task->timer);
	
	return OK;
}
Exemplo n.º 15
0
void test_watchdog_reset_attitude_data(void) {
	TickType_t ms = xTaskGetTickCount();

	check_set_sat_state(INITIAL, INITIAL);
	check_set_sat_state(INITIAL, ANTENNA_DEPLOY);
	if (ms > 2 * ATTITUDE_DATA_TASK_FREQ + TASK_EXECUTION_WINDOW_BUFFER_TIME) {
		task_suspend(ATTITUDE_DATA_TASK);
	}

	// watchdog should reset eventually
}
Exemplo n.º 16
0
/* Semaphore: API */
int sem_wait(sem_t *s)
{
    if (!s)
        return -1;
    if(_sem_wait(s) != 0) {
        _add_listener(s);
        task_suspend();
        return SYS_CALL_AGAIN;
    }
    _del_listener(s);
    return 0;
}
Exemplo n.º 17
0
int mutex_lock(mutex_t *s)
{
    if (!s)
        return -1;
    if(_mutex_lock(s) != 0) {
        _add_listener(s);
        task_suspend();
        return SYS_CALL_AGAIN;
    }
    _del_listener(s);
    return 0;
}
Exemplo n.º 18
0
int
mach_init_doit(bool forkchild)
{
	/*
	 *	Get the important ports into the cached values,
	 *	as required by "mach_init.h".
	 */
	mach_task_self_ = task_self_trap();
	
	/*
	 *	Initialize the single mig reply port
	 */

	_pthread_set_self(0);
	_mig_init(0);

#if WE_REALLY_NEED_THIS_GDB_HACK
	/*
	 * Check to see if GDB wants us to stop
	 */
	{
	task_user_data_data_t	user_data;
	mach_msg_type_number_t	user_data_count = TASK_USER_DATA_COUNT;
	  
	user_data.user_data = 0;
	(void)task_info(mach_task_self_, TASK_USER_DATA,
		(task_info_t)&user_data, &user_data_count);
#define MACH_GDB_RUN_MAGIC_NUMBER 1
#ifdef	MACH_GDB_RUN_MAGIC_NUMBER	
	/* This magic number is set in mach-aware gdb 
	 *  for RUN command to allow us to suspend user's
	 *  executable (linked with this libmach!) 
	 *  with the code below.
	 * This hack should disappear when gdb improves.
	 */
	if ((int)user_data.user_data == MACH_GDB_RUN_MAGIC_NUMBER) {
	    kern_return_t ret;
	    user_data.user_data = 0;
	    
	    ret = task_suspend(mach_task_self_);
	    if (ret != KERN_SUCCESS) {
			while (1) {
				(void)task_terminate(mach_task_self_);
			}
	    }
	}
#undef MACH_GDB_RUN_MAGIC_NUMBER  
#endif /* MACH_GDB_RUN_MAGIC_NUMBER */
	}
#endif /* WE_REALLY_NEED_THIS_GDB_HACK */

	return 0;
}
Exemplo n.º 19
0
void test_watchdog_reset_antenna_deploy(void) {
	TickType_t ms = xTaskGetTickCount();

	check_set_sat_state(INITIAL, INITIAL);
	check_set_sat_state(INITIAL, ANTENNA_DEPLOY);
	// only once because otherwise it may check itself out
	if (ms > ANTENNA_DEPLOY_TASK_FREQ + TASK_EXECUTION_WINDOW_BUFFER_TIME) {
		task_suspend(ANTENNA_DEPLOY_TASK);
	}

	// watchdog should reset eventually
}
Exemplo n.º 20
0
void test_watchdog_reset_transmit_task(void) {
	TickType_t ms = xTaskGetTickCount();

	check_set_sat_state(INITIAL, INITIAL);
	check_set_sat_state(INITIAL, ANTENNA_DEPLOY);
	check_set_sat_state(ANTENNA_DEPLOY, HELLO_WORLD);
	if (ms > 2 * TRANSMIT_TASK_FREQ + TASK_EXECUTION_WINDOW_BUFFER_TIME) {
		task_suspend(TRANSMIT_TASK);
	}


	// watchdog should reset eventually
}
Exemplo n.º 21
0
void test_watchdog_reset_idle_data_task(void) {
	TickType_t ms = xTaskGetTickCount();

	check_set_sat_state(INITIAL, INITIAL);
	check_set_sat_state(INITIAL, ANTENNA_DEPLOY);
	check_set_sat_state(ANTENNA_DEPLOY, HELLO_WORLD);
	check_set_sat_state(HELLO_WORLD, IDLE_NO_FLASH);
	if (ms > 2 * IDLE_DATA_TASK_FREQ + TASK_EXECUTION_WINDOW_BUFFER_TIME){
		task_suspend(IDLE_DATA_TASK);
	}

	// watchdog should reset eventually
}
Exemplo n.º 22
0
static void task_timer (const char _name [], void *_p_arg)
{
    queue_handle_t queue = (queue_handle_t)_p_arg;
    timer_handle_t handle;

    for (;;) {
        if (0 != queue_message_receive (queue, 0, &handle)) {
            console_print ("Error: task \"%s\" cannot recieve message", _name);
            (void) task_suspend (task_self ());
        }
        handle->callback_(handle, handle->arg_);
    }
}
Exemplo n.º 23
0
static int klog_read(struct fnode *fno, void *buf, unsigned int len)
{
    int ret;
    if (len == 0)
        return len;
    if (!buf)
        return -EINVAL;

    ret = cirbuf_readbytes(klog.buf, buf, len);
    if (ret <= 0) {
        klog.task = this_task();
        task_suspend();
        return SYS_CALL_AGAIN;
    }
    return ret;
}
Exemplo n.º 24
0
/* Not called from probe context */
proc_t * 
sprlock(pid_t pid)
{
	proc_t* p;

	if ((p = proc_find(pid)) == PROC_NULL) {
		return PROC_NULL;
	}

	task_suspend(p->task);

	proc_lock(p);

	lck_mtx_lock(&p->p_dtrace_sprlock);

	return p;
}
kern_return_t next_inferior_suspend_mach (next_inferior_status *s)
{
  kern_return_t kret;

  CHECK (s != NULL);
  CHECK (next_task_valid (s->task));

  if (s->suspend_count == 0) {
    inferior_debug (2, "suspending task\n");
    kret = task_suspend (s->task);
    if (kret != KERN_SUCCESS) {
      return kret;
    }
    s->suspend_count++;
    inferior_debug (2, "suspended task (suspend count now %d)\n", s->suspend_count);
  }

  return KERN_SUCCESS;
}
Exemplo n.º 26
0
// s/inferior_task/port/
static int debug_attach(int pid) {
        task_t task = pid_to_task (pid);
        if (task == -1)
                return -1;
        eprintf ("pid: %d\ntask: %d\n", pid, task);
#if 0
	// TODO : move this code into debug
        if (task_threads (task, &inferior_threads, &inferior_thread_count)
			!= KERN_SUCCESS) {
                eprintf ("Failed to get list of task's threads.\n");
                return -1;
        }
        eprintf ("Thread count: %d\n", inferior_thread_count);
#endif

#if SUSPEND
	if (task_suspend (this->port) != KERN_SUCCESS) {
		eprintf ("cannot suspend task\n");
		return -1; // R_FALSE
	}
#endif
	/* is this required for arm ? */
#if EXCEPTION_PORT
	int exception_port;
        if (mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE,
			&exception_port) != KERN_SUCCESS) {
                eprintf ("Failed to create exception port.\n");
                return -1;
        }
        if (mach_port_insert_right(mach_task_self(), exception_port,
			exception_port, MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS) {
                eprintf ("Failed to acquire insertion rights on the port.\n");
                return -1;
        }
        if (task_set_exception_ports(inferior_task, EXC_MASK_ALL, exception_port,
			EXCEPTION_DEFAULT, THREAD_STATE_NONE) != KERN_SUCCESS) {
                eprintf ("Failed to set the inferior's exception ports.\n");
                return -1;
        }
#endif
        return task;
}
Exemplo n.º 27
0
static int pipe_write(struct fnode *f, const void *buf, unsigned int len)
{
    struct pipe_priv *pp;
    int out, len_available;
    const uint8_t *ptr = buf;

    if (f->owner != &mod_pipe)
        return -EINVAL;

    pp = (struct pipe_priv *)f->priv;
    if (!pp)
        return -EINVAL;

    if (pp->fno_w != f)
        return -EPERM;

    out = pp->w_off;

    len_available =  cirbuf_bytesfree(pp->cb);
    if (len_available > (len - out))
        len_available = (len - out);
    for(; out < len_available; out++) {
        /* write data */
        if (cirbuf_writebyte(pp->cb, *(ptr + out)) != 0)
            break;
    }

    if (out < len) {
        pp->pid_w = scheduler_get_cur_pid();
        pp->w_off = out;
        task_suspend();
        return SYS_CALL_AGAIN;
    }

    pp->w_off = 0;
    pp->pid_w = 0;
    return out;
}
Exemplo n.º 28
0
static void user_bootstrap(void)
{
  struct user_bootstrap_info *info = current_thread()->saved.other;
  exec_info_t boot_exec_info;
  int err;
  char **av;

  /* Load this task up from the executable file in the module.  */
  err = exec_load(boot_read, read_exec, info->mod, &boot_exec_info);
  if (err)
    panic ("Cannot load user executable module (error code %d): %s",
	   err, info->argv[0]);

  printf ("task loaded:");

  /* Set up the stack with arguments.  */
  build_args_and_stack(&boot_exec_info, info->argv, 0);

  for (av = info->argv; *av != 0; ++av)
    printf (" %s", *av);

  task_suspend (current_task());

  /* Tell the bootstrap thread running boot_script_exec_cmd
     that we are done looking at INFO.  */
  simple_lock (&info->lock);
  assert (!info->done);
  info->done = 1;
  thread_wakeup ((event_t) info);

  /*
   * Exit to user thread.
   */
  thread_bootstrap_return();
  /*NOTREACHED*/
}
Exemplo n.º 29
0
bool ZGSuspendTask(ZGMemoryMap processTask)
{
	return (task_suspend(processTask) == KERN_SUCCESS);
}
Exemplo n.º 30
0
void harness_block(void)
{
	task_suspend(NULL);
}