Example #1
0
static int __wind_msgq_receive(struct task_struct *curr, struct pt_regs *regs)
{
	xnhandle_t handle = __xn_reg_arg1(regs);
	char tmp_buf[128], *msgbuf;
	wind_msgq_t *msgq;
	int timeout, err;
	unsigned nbytes;

	nbytes = __xn_reg_arg3(regs);
	timeout = __xn_reg_arg4(regs);

	if (!__xn_access_ok(curr, VERIFY_WRITE, __xn_reg_arg2(regs), nbytes))
		return -EFAULT;

	if (!__xn_access_ok
	    (curr, VERIFY_WRITE, __xn_reg_arg5(regs), sizeof(nbytes)))
		return -EFAULT;

	msgq = (wind_msgq_t *)xnregistry_fetch(handle);

	if (!msgq)
		return S_objLib_OBJ_ID_ERROR;

	if (nbytes <= sizeof(tmp_buf))
		msgbuf = tmp_buf;
	else {
		msgbuf = (char *)xnmalloc(nbytes);

		if (!msgbuf)
			return S_memLib_NOT_ENOUGH_MEMORY;
	}

	/* This is sub-optimal since we end up copying the data twice. */

	err = msgQReceive((MSG_Q_ID)msgq, msgbuf, nbytes, timeout);

	if (err != ERROR) {
		__xn_copy_to_user(curr, (void __user *)__xn_reg_arg2(regs),
				  msgbuf, err);
		__xn_copy_to_user(curr, (void __user *)__xn_reg_arg5(regs),
				  &err, sizeof(err));
		err = 0;
	} else
		err = wind_errnoget();

	if (msgbuf != tmp_buf)
		xnfree(msgbuf);

	return err;
}
Example #2
0
static int __wind_wd_start(struct task_struct *curr, struct pt_regs *regs)
{
	wind_rholder_t *rh;
	long start_server;
	xnhandle_t handle;
	wind_wd_t *wd;
	int timeout;
	spl_t s;

	if (!__xn_access_ok(curr, VERIFY_WRITE, __xn_reg_arg5(regs), sizeof(start_server)))
		return -EFAULT;

	handle = __xn_reg_arg1(regs);

	wd = (wind_wd_t *)xnregistry_fetch(handle);

	if (!wd)
		return S_objLib_OBJ_ID_ERROR;

	rh = wind_get_rholder();

	if (wd->rh != rh)
		/*
		 * User may not fiddle with watchdogs created from
		 * other processes.
		 */
		return S_objLib_OBJ_UNAVAILABLE;

	timeout = __xn_reg_arg2(regs);

	xnlock_get_irqsave(&nklock, s);

	if (wdStart
	    ((WDOG_ID)wd, timeout, (wind_timer_t) & __wind_wd_handler,
	     (long)wd) == ERROR) {
		xnlock_put_irqrestore(&nklock, s);
		return wind_errnoget();
	}

	wd->wdt.handler = (wind_timer_t) __xn_reg_arg3(regs);
	wd->wdt.arg = (long)__xn_reg_arg4(regs);
	start_server = rh->wdcount++ == 0;

	xnlock_put_irqrestore(&nklock, s);

	__xn_copy_to_user(curr, (void __user *)__xn_reg_arg5(regs), &start_server,
			  sizeof(start_server));

	return 0;
}
Example #3
0
static int __ui_twai_flg(struct pt_regs *regs)
{
	UINT flgptn, waiptn, wfmode;
	TMO tmout;
	ID flgid;
	ER err;

	flgid = __xn_reg_arg2(regs);
	waiptn = __xn_reg_arg3(regs);
	wfmode = __xn_reg_arg4(regs);
	tmout = __xn_reg_arg5(regs);

	err = twai_flg(&flgptn, flgid, waiptn, wfmode, tmout);

	if (err == E_OK) {
		if (__xn_safe_copy_to_user((void __user *)__xn_reg_arg1(regs), &flgptn,
					   sizeof(flgptn)))
			return -EFAULT;
	} else if (err == E_RLWAI) {
		uitask_t *task = ui_current_task();
		if (!xnthread_test_info(&task->threadbase, uITRON_TASK_RLWAIT))
			err = -EINTR;
	}

	return err;
}
Example #4
0
static int __rt_shm_heap_open(struct task_struct *curr, struct pt_regs *regs)
{
    unsigned long name;
    int size;
    int suprt, in_kheap;

    unsigned long off;
    unsigned long opaque;
    void *ret;
    extern void *_shm_alloc(unsigned long name, int size, int suprt,
                            int in_kheap, unsigned long *opaque);

    if (!__xn_access_ok
            (curr, VERIFY_WRITE, __xn_reg_arg2(regs), sizeof(size))
            || !__xn_access_ok(curr, VERIFY_WRITE, __xn_reg_arg5(regs),
                               sizeof(off)))
        return 0;

    name = (unsigned long)__xn_reg_arg1(regs);
    /* Size of heap space. */
    __xn_copy_from_user(curr, &size, (void __user *)__xn_reg_arg2(regs),
                        sizeof(size));
    /* Creation mode. */
    suprt = (int)__xn_reg_arg3(regs);
    in_kheap = (int)__xn_reg_arg4(regs);

    ret = _shm_alloc(name, size, suprt, in_kheap, &opaque);

    if (!ret)
        goto free_and_fail;

    off = xnheap_mapped_offset((xnheap_t *)opaque, ret);

    size = (int)((xnheap_t *)opaque)->extentsize;
    __xn_copy_to_user(curr, (void __user *)__xn_reg_arg2(regs), &size,
                      sizeof(size));
    __xn_copy_to_user(curr, (void __user *)__xn_reg_arg5(regs), &off,
                      sizeof(off));

    return (int)opaque;

free_and_fail:

    return 0;
}
Example #5
0
static int __sc_fpend(struct task_struct *curr, struct pt_regs *regs)
{
	int fid, mask, mask_r, opt, err;
	long timeout;

	if (!__xn_access_ok
	    (curr, VERIFY_WRITE, __xn_reg_arg5(regs), sizeof(mask_r)))
		return -EFAULT;

	fid = __xn_reg_arg1(regs);
	timeout = __xn_reg_arg2(regs);
	mask = __xn_reg_arg3(regs);
	opt = __xn_reg_arg4(regs);
	mask_r = sc_fpend(fid, timeout, mask, opt, &err);

	if (!err)
		__xn_copy_to_user(curr, (void __user *)__xn_reg_arg5(regs),
				  &mask_r, sizeof(mask_r));
	return err;
}
Example #6
0
static int __wind_msgq_send(struct pt_regs *regs)
{
	xnhandle_t handle = __xn_reg_arg1(regs);
	char tmp_buf[128], *msgbuf;
	wind_msgq_t *msgq;
	int timeout, prio;
	unsigned nbytes;
	STATUS err;

	nbytes = __xn_reg_arg3(regs);
	timeout = __xn_reg_arg4(regs);
	prio = __xn_reg_arg5(regs);

	if (timeout != NO_WAIT && !xnpod_primary_p())
		return -EPERM;

	msgq = (wind_msgq_t *)xnregistry_fetch(handle);

	if (!msgq)
		return S_objLib_OBJ_ID_ERROR;

	if (nbytes > msgq->msg_length)
		return S_msgQLib_INVALID_MSG_LENGTH;

	if (nbytes <= sizeof(tmp_buf))
		msgbuf = tmp_buf;
	else {
		msgbuf = (char *)xnmalloc(nbytes);

		if (!msgbuf)
			return S_memLib_NOT_ENOUGH_MEMORY;
	}

	/* This is sub-optimal since we end up copying the data twice. */

	if (__xn_safe_copy_from_user(msgbuf, (void __user *)__xn_reg_arg2(regs), nbytes))
		err = -EFAULT;
	else {
		if (msgQSend((MSG_Q_ID)msgq, msgbuf, nbytes, timeout, prio) == ERROR)
			err = wind_errnoget();
		else
			err = 0;
	}

	if (msgbuf != tmp_buf)
		xnfree(msgbuf);

	return err;
}