2005-04-21 16:53:53 +02:00
|
|
|
/* this file contains the interface of the network software with the file
|
|
|
|
* system.
|
|
|
|
*
|
|
|
|
* Copyright 1995 Philip Homburg
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "inet.h"
|
|
|
|
|
|
|
|
#include "mq.h"
|
2005-06-28 17:19:58 +02:00
|
|
|
#include "qp.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "proto.h"
|
|
|
|
#include "generic/type.h"
|
|
|
|
|
|
|
|
#include "generic/assert.h"
|
|
|
|
#include "generic/buf.h"
|
2005-06-28 17:19:58 +02:00
|
|
|
#include "generic/event.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "generic/sr.h"
|
2005-06-28 17:19:58 +02:00
|
|
|
#include "sr_int.h"
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
THIS_FILE
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
sr_fd_t sr_fd_table[FD_NR];
|
|
|
|
|
|
|
|
static struct vscp_vec s_cp_req[SCPVEC_NR];
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
static int sr_open(devminor_t minor, int access, endpoint_t user_endpt);
|
|
|
|
static int sr_close(devminor_t minor);
|
|
|
|
static ssize_t sr_read(devminor_t minor, u64_t position, endpoint_t endpt,
|
|
|
|
cp_grant_id_t grant, size_t size, int flags, cdev_id_t id);
|
|
|
|
static ssize_t sr_write(devminor_t minor, u64_t position, endpoint_t endpt,
|
|
|
|
cp_grant_id_t grant, size_t size, int flags, cdev_id_t id);
|
|
|
|
static int sr_ioctl(devminor_t minor, unsigned long request, endpoint_t endpt,
|
|
|
|
cp_grant_id_t grant, int flags, endpoint_t user_endpt, cdev_id_t id);
|
|
|
|
static int sr_rwio(sr_req_t *req);
|
2012-03-25 20:25:53 +02:00
|
|
|
static int sr_restart_read(sr_fd_t *fdp);
|
|
|
|
static int sr_restart_write(sr_fd_t *fdp);
|
|
|
|
static int sr_restart_ioctl(sr_fd_t *fdp);
|
2013-09-09 16:53:28 +02:00
|
|
|
static int sr_cancel(devminor_t minor, endpoint_t endpt, cdev_id_t id);
|
|
|
|
static int sr_select(devminor_t minor, unsigned int ops, endpoint_t endpt);
|
2012-03-25 20:25:53 +02:00
|
|
|
static sr_fd_t *sr_getchannel(int minor);
|
|
|
|
static acc_t *sr_get_userdata(int fd, size_t offset, size_t count, int
|
2012-03-24 16:16:34 +01:00
|
|
|
for_ioctl);
|
2012-03-25 20:25:53 +02:00
|
|
|
static int sr_put_userdata(int fd, size_t offset, acc_t *data, int
|
2012-03-24 16:16:34 +01:00
|
|
|
for_ioctl);
|
2012-03-25 20:25:53 +02:00
|
|
|
static void sr_select_res(int fd, unsigned ops);
|
2013-09-09 16:53:28 +02:00
|
|
|
static int walk_queue(sr_fd_t *sr_fd, mq_t **q_head_ptr, mq_t **q_tail_ptr,
|
|
|
|
int type, endpoint_t endpt, cdev_id_t id, int first_flag);
|
2012-03-25 20:25:53 +02:00
|
|
|
static void sr_event(event_t *evp, ev_arg_t arg);
|
|
|
|
static int cp_u2b(endpoint_t proc, cp_grant_id_t gid, vir_bytes offset,
|
2012-03-24 16:16:34 +01:00
|
|
|
acc_t **var_acc_ptr, int size);
|
2012-03-25 20:25:53 +02:00
|
|
|
static int cp_b2u(acc_t *acc_ptr, endpoint_t proc, cp_grant_id_t gid,
|
2012-03-24 16:16:34 +01:00
|
|
|
vir_bytes offset);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
static struct chardriver inet_tab = {
|
|
|
|
.cdr_open = sr_open,
|
|
|
|
.cdr_close = sr_close,
|
|
|
|
.cdr_read = sr_read,
|
|
|
|
.cdr_write = sr_write,
|
|
|
|
.cdr_ioctl = sr_ioctl,
|
|
|
|
.cdr_cancel = sr_cancel,
|
|
|
|
.cdr_select = sr_select
|
|
|
|
};
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
void sr_init()
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<FD_NR; i++)
|
2005-06-28 17:19:58 +02:00
|
|
|
{
|
2005-04-21 16:53:53 +02:00
|
|
|
sr_fd_table[i].srf_flags= SFF_FREE;
|
2005-06-28 17:19:58 +02:00
|
|
|
ev_init(&sr_fd_table[i].srf_ioctl_ev);
|
|
|
|
ev_init(&sr_fd_table[i].srf_read_ev);
|
|
|
|
ev_init(&sr_fd_table[i].srf_write_ev);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
void sr_rec(message *m, int ipc_status)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2013-09-09 16:53:28 +02:00
|
|
|
chardriver_process(&inet_tab, m, ipc_status);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
void sr_add_minor(minor, port, openf, closef, readf, writef,
|
2005-06-28 17:19:58 +02:00
|
|
|
ioctlf, cancelf, selectf)
|
2005-04-21 16:53:53 +02:00
|
|
|
int minor;
|
|
|
|
int port;
|
|
|
|
sr_open_t openf;
|
|
|
|
sr_close_t closef;
|
|
|
|
sr_read_t readf;
|
|
|
|
sr_write_t writef;
|
|
|
|
sr_ioctl_t ioctlf;
|
|
|
|
sr_cancel_t cancelf;
|
2005-06-28 17:19:58 +02:00
|
|
|
sr_select_t selectf;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
sr_fd_t *sr_fd;
|
|
|
|
|
|
|
|
assert (minor>=0 && minor<FD_NR);
|
|
|
|
|
|
|
|
sr_fd= &sr_fd_table[minor];
|
|
|
|
|
|
|
|
assert(!(sr_fd->srf_flags & SFF_INUSE));
|
|
|
|
|
|
|
|
sr_fd->srf_flags= SFF_INUSE | SFF_MINOR;
|
|
|
|
sr_fd->srf_port= port;
|
|
|
|
sr_fd->srf_open= openf;
|
|
|
|
sr_fd->srf_close= closef;
|
|
|
|
sr_fd->srf_write= writef;
|
|
|
|
sr_fd->srf_read= readf;
|
|
|
|
sr_fd->srf_ioctl= ioctlf;
|
|
|
|
sr_fd->srf_cancel= cancelf;
|
2005-06-28 17:19:58 +02:00
|
|
|
sr_fd->srf_select= selectf;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
static int sr_open(devminor_t minor, int UNUSED(access),
|
|
|
|
endpoint_t UNUSED(user_endpt))
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
sr_fd_t *sr_fd;
|
|
|
|
int i, fd;
|
|
|
|
|
|
|
|
if (minor<0 || minor>FD_NR)
|
|
|
|
{
|
|
|
|
DBLOCK(1, printf("replying EINVAL\n"));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
if (!(sr_fd_table[minor].srf_flags & SFF_MINOR))
|
|
|
|
{
|
|
|
|
DBLOCK(1, printf("replying ENXIO\n"));
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
for (i=0; i<FD_NR && (sr_fd_table[i].srf_flags & SFF_INUSE); i++);
|
|
|
|
|
|
|
|
if (i>=FD_NR)
|
|
|
|
{
|
|
|
|
DBLOCK(1, printf("replying ENFILE\n"));
|
|
|
|
return ENFILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sr_fd= &sr_fd_table[i];
|
|
|
|
*sr_fd= sr_fd_table[minor];
|
|
|
|
sr_fd->srf_flags= SFF_INUSE;
|
|
|
|
fd= (*sr_fd->srf_open)(sr_fd->srf_port, i, sr_get_userdata,
|
2005-06-28 17:19:58 +02:00
|
|
|
sr_put_userdata, 0 /* no put_pkt */, sr_select_res);
|
2005-04-21 16:53:53 +02:00
|
|
|
if (fd<0)
|
|
|
|
{
|
|
|
|
sr_fd->srf_flags= SFF_FREE;
|
|
|
|
DBLOCK(1, printf("replying %d\n", fd));
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
sr_fd->srf_fd= fd;
|
2013-09-10 20:25:01 +02:00
|
|
|
return CDEV_CLONED | i;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
static int sr_close(devminor_t minor)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
sr_fd_t *sr_fd;
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
sr_fd= sr_getchannel(minor);
|
2005-04-21 16:53:53 +02:00
|
|
|
assert (sr_fd);
|
|
|
|
|
2005-06-28 17:19:58 +02:00
|
|
|
if (sr_fd->srf_flags & SFF_BUSY)
|
|
|
|
ip_panic(("close on busy channel"));
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
assert (!(sr_fd->srf_flags & SFF_MINOR));
|
|
|
|
(*sr_fd->srf_close)(sr_fd->srf_fd);
|
|
|
|
sr_fd->srf_flags= SFF_FREE;
|
2013-09-09 16:53:28 +02:00
|
|
|
|
|
|
|
return OK;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
static int sr_rwio(sr_req_t *req)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
sr_fd_t *sr_fd;
|
2013-09-09 16:53:28 +02:00
|
|
|
mq_t *m, **q_head_ptr = NULL, **q_tail_ptr = NULL;
|
2012-08-25 19:42:05 +02:00
|
|
|
int ip_flag = 0, susp_flag = 0, first_flag = 0;
|
|
|
|
int r = OK;
|
2005-04-21 16:53:53 +02:00
|
|
|
ioreq_t request;
|
|
|
|
size_t size;
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
if (!(m = mq_get()))
|
|
|
|
ip_panic(("out of messages"));
|
|
|
|
m->mq_req = *req;
|
|
|
|
|
|
|
|
sr_fd= sr_getchannel(m->mq_req.srr_minor);
|
2006-06-26 13:17:19 +02:00
|
|
|
assert (sr_fd);
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
switch(m->mq_req.srr_type)
|
2006-06-26 13:17:19 +02:00
|
|
|
{
|
2013-09-09 16:53:28 +02:00
|
|
|
case SRR_READ:
|
2006-06-26 13:17:19 +02:00
|
|
|
q_head_ptr= &sr_fd->srf_read_q;
|
|
|
|
q_tail_ptr= &sr_fd->srf_read_q_tail;
|
|
|
|
ip_flag= SFF_READ_IP;
|
|
|
|
susp_flag= SFF_READ_SUSP;
|
|
|
|
first_flag= SFF_READ_FIRST;
|
|
|
|
break;
|
2013-09-09 16:53:28 +02:00
|
|
|
case SRR_WRITE:
|
2006-06-26 13:17:19 +02:00
|
|
|
q_head_ptr= &sr_fd->srf_write_q;
|
|
|
|
q_tail_ptr= &sr_fd->srf_write_q_tail;
|
|
|
|
ip_flag= SFF_WRITE_IP;
|
|
|
|
susp_flag= SFF_WRITE_SUSP;
|
|
|
|
first_flag= SFF_WRITE_FIRST;
|
|
|
|
break;
|
2013-09-09 16:53:28 +02:00
|
|
|
case SRR_IOCTL:
|
2006-06-26 13:17:19 +02:00
|
|
|
q_head_ptr= &sr_fd->srf_ioctl_q;
|
|
|
|
q_tail_ptr= &sr_fd->srf_ioctl_q_tail;
|
|
|
|
ip_flag= SFF_IOCTL_IP;
|
|
|
|
susp_flag= SFF_IOCTL_SUSP;
|
|
|
|
first_flag= SFF_IOCTL_FIRST;
|
|
|
|
break;
|
|
|
|
default:
|
2013-09-09 16:53:28 +02:00
|
|
|
ip_panic(("illegal request type"));
|
2006-06-26 13:17:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sr_fd->srf_flags & ip_flag)
|
|
|
|
{
|
|
|
|
assert(sr_fd->srf_flags & susp_flag);
|
|
|
|
assert(*q_head_ptr);
|
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
if (m->mq_req.srr_flags & CDEV_NONBLOCK) {
|
2013-09-09 16:53:28 +02:00
|
|
|
mq_free(m);
|
2013-08-30 10:48:34 +02:00
|
|
|
return EAGAIN;
|
2013-09-09 16:53:28 +02:00
|
|
|
}
|
2013-08-30 10:48:34 +02:00
|
|
|
|
2006-06-26 13:17:19 +02:00
|
|
|
(*q_tail_ptr)->mq_next= m;
|
|
|
|
*q_tail_ptr= m;
|
2013-09-09 16:53:28 +02:00
|
|
|
return EDONTREPLY;
|
2006-06-26 13:17:19 +02:00
|
|
|
}
|
|
|
|
assert(!*q_head_ptr);
|
|
|
|
|
|
|
|
*q_tail_ptr= *q_head_ptr= m;
|
|
|
|
sr_fd->srf_flags |= ip_flag;
|
|
|
|
assert(!(sr_fd->srf_flags & first_flag));
|
|
|
|
sr_fd->srf_flags |= first_flag;
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
switch(m->mq_req.srr_type)
|
2006-06-26 13:17:19 +02:00
|
|
|
{
|
2013-09-09 16:53:28 +02:00
|
|
|
case SRR_READ:
|
|
|
|
r= (*sr_fd->srf_read)(sr_fd->srf_fd, m->mq_req.srr_size);
|
2006-06-26 13:17:19 +02:00
|
|
|
break;
|
2013-09-09 16:53:28 +02:00
|
|
|
case SRR_WRITE:
|
|
|
|
r= (*sr_fd->srf_write)(sr_fd->srf_fd, m->mq_req.srr_size);
|
2006-06-26 13:17:19 +02:00
|
|
|
break;
|
2013-09-09 16:53:28 +02:00
|
|
|
case SRR_IOCTL:
|
|
|
|
request= m->mq_req.srr_req;
|
2006-06-26 13:17:19 +02:00
|
|
|
size= (request >> 16) & _IOCPARM_MASK;
|
|
|
|
if (size>MAX_IOCTL_S)
|
|
|
|
{
|
|
|
|
DBLOCK(1, printf("replying EINVAL\n"));
|
|
|
|
r= sr_put_userdata(sr_fd-sr_fd_table, EINVAL,
|
|
|
|
NULL, 1);
|
|
|
|
assert(r == OK);
|
|
|
|
assert(sr_fd->srf_flags & first_flag);
|
|
|
|
sr_fd->srf_flags &= ~first_flag;
|
2013-09-09 16:53:28 +02:00
|
|
|
return EDONTREPLY;
|
2006-06-26 13:17:19 +02:00
|
|
|
}
|
|
|
|
r= (*sr_fd->srf_ioctl)(sr_fd->srf_fd, request);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ip_panic(("illegal case entry"));
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(sr_fd->srf_flags & first_flag);
|
|
|
|
sr_fd->srf_flags &= ~first_flag;
|
|
|
|
|
|
|
|
assert(r == OK || r == SUSPEND ||
|
|
|
|
(printf("r= %d\n", r), 0));
|
2013-08-30 10:48:34 +02:00
|
|
|
if (r == SUSPEND) {
|
2006-06-26 13:17:19 +02:00
|
|
|
sr_fd->srf_flags |= susp_flag;
|
2013-09-10 20:25:01 +02:00
|
|
|
if (m->mq_req.srr_flags & CDEV_NONBLOCK) {
|
2013-09-09 16:53:28 +02:00
|
|
|
r= sr_cancel(m->mq_req.srr_minor, m->mq_req.srr_endpt,
|
|
|
|
m->mq_req.srr_id);
|
|
|
|
assert(r == EDONTREPLY); /* head of the queue */
|
2013-08-30 10:48:34 +02:00
|
|
|
}
|
|
|
|
} else
|
2006-06-26 13:17:19 +02:00
|
|
|
mq_free(m);
|
2013-09-09 16:53:28 +02:00
|
|
|
return EDONTREPLY; /* request already completed */
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t sr_read(devminor_t minor, u64_t UNUSED(position),
|
|
|
|
endpoint_t endpt, cp_grant_id_t grant, size_t size, int flags,
|
|
|
|
cdev_id_t id)
|
|
|
|
{
|
|
|
|
sr_req_t req;
|
|
|
|
|
|
|
|
req.srr_type = SRR_READ;
|
|
|
|
req.srr_minor = minor;
|
|
|
|
req.srr_endpt = endpt;
|
|
|
|
req.srr_grant = grant;
|
|
|
|
req.srr_size = size;
|
|
|
|
req.srr_flags = flags;
|
|
|
|
req.srr_id = id;
|
|
|
|
|
|
|
|
return sr_rwio(&req);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t sr_write(devminor_t minor, u64_t UNUSED(position),
|
|
|
|
endpoint_t endpt, cp_grant_id_t grant, size_t size, int flags,
|
|
|
|
cdev_id_t id)
|
|
|
|
{
|
|
|
|
sr_req_t req;
|
|
|
|
|
|
|
|
req.srr_type = SRR_WRITE;
|
|
|
|
req.srr_minor = minor;
|
|
|
|
req.srr_endpt = endpt;
|
|
|
|
req.srr_grant = grant;
|
|
|
|
req.srr_size = size;
|
|
|
|
req.srr_flags = flags;
|
|
|
|
req.srr_id = id;
|
|
|
|
|
|
|
|
return sr_rwio(&req);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sr_ioctl(devminor_t minor, unsigned long request, endpoint_t endpt,
|
|
|
|
cp_grant_id_t grant, int flags, endpoint_t UNUSED(user_endpt),
|
|
|
|
cdev_id_t id)
|
|
|
|
{
|
|
|
|
sr_req_t req;
|
|
|
|
|
|
|
|
req.srr_type = SRR_IOCTL;
|
|
|
|
req.srr_minor = minor;
|
|
|
|
req.srr_req = request;
|
|
|
|
req.srr_endpt = endpt;
|
|
|
|
req.srr_grant = grant;
|
|
|
|
req.srr_flags = flags;
|
|
|
|
req.srr_id = id;
|
|
|
|
|
|
|
|
return sr_rwio(&req);
|
2006-06-26 13:17:19 +02:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int sr_restart_read(sr_fd)
|
2005-06-28 17:19:58 +02:00
|
|
|
sr_fd_t *sr_fd;
|
|
|
|
{
|
|
|
|
mq_t *mp;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
mp= sr_fd->srf_read_q;
|
|
|
|
assert(mp);
|
|
|
|
|
|
|
|
if (sr_fd->srf_flags & SFF_READ_IP)
|
|
|
|
{
|
|
|
|
assert(sr_fd->srf_flags & SFF_READ_SUSP);
|
|
|
|
return SUSPEND;
|
|
|
|
}
|
|
|
|
sr_fd->srf_flags |= SFF_READ_IP;
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
r= (*sr_fd->srf_read)(sr_fd->srf_fd, mp->mq_req.srr_size);
|
2005-06-28 17:19:58 +02:00
|
|
|
|
|
|
|
assert(r == OK || r == SUSPEND ||
|
|
|
|
(printf("r= %d\n", r), 0));
|
|
|
|
if (r == SUSPEND)
|
|
|
|
sr_fd->srf_flags |= SFF_READ_SUSP;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int sr_restart_write(sr_fd)
|
2005-06-28 17:19:58 +02:00
|
|
|
sr_fd_t *sr_fd;
|
|
|
|
{
|
|
|
|
mq_t *mp;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
mp= sr_fd->srf_write_q;
|
|
|
|
assert(mp);
|
|
|
|
|
|
|
|
if (sr_fd->srf_flags & SFF_WRITE_IP)
|
|
|
|
{
|
|
|
|
assert(sr_fd->srf_flags & SFF_WRITE_SUSP);
|
|
|
|
return SUSPEND;
|
|
|
|
}
|
|
|
|
sr_fd->srf_flags |= SFF_WRITE_IP;
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
r= (*sr_fd->srf_write)(sr_fd->srf_fd, mp->mq_req.srr_size);
|
2005-06-28 17:19:58 +02:00
|
|
|
|
|
|
|
assert(r == OK || r == SUSPEND ||
|
|
|
|
(printf("r= %d\n", r), 0));
|
|
|
|
if (r == SUSPEND)
|
|
|
|
sr_fd->srf_flags |= SFF_WRITE_SUSP;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int sr_restart_ioctl(sr_fd)
|
2005-06-28 17:19:58 +02:00
|
|
|
sr_fd_t *sr_fd;
|
|
|
|
{
|
|
|
|
mq_t *mp;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
mp= sr_fd->srf_ioctl_q;
|
|
|
|
assert(mp);
|
|
|
|
|
|
|
|
if (sr_fd->srf_flags & SFF_IOCTL_IP)
|
|
|
|
{
|
|
|
|
assert(sr_fd->srf_flags & SFF_IOCTL_SUSP);
|
|
|
|
return SUSPEND;
|
|
|
|
}
|
|
|
|
sr_fd->srf_flags |= SFF_IOCTL_IP;
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
r= (*sr_fd->srf_ioctl)(sr_fd->srf_fd, mp->mq_req.srr_req);
|
2005-06-28 17:19:58 +02:00
|
|
|
|
|
|
|
assert(r == OK || r == SUSPEND ||
|
|
|
|
(printf("r= %d\n", r), 0));
|
|
|
|
if (r == SUSPEND)
|
|
|
|
sr_fd->srf_flags |= SFF_IOCTL_SUSP;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
static int sr_cancel(devminor_t minor, endpoint_t endpt, cdev_id_t id)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
sr_fd_t *sr_fd;
|
2005-06-28 17:19:58 +02:00
|
|
|
int result;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
sr_fd= sr_getchannel(minor);
|
2005-04-21 16:53:53 +02:00
|
|
|
assert (sr_fd);
|
|
|
|
|
2010-01-05 20:39:27 +01:00
|
|
|
result= walk_queue(sr_fd, &sr_fd->srf_ioctl_q,
|
|
|
|
&sr_fd->srf_ioctl_q_tail, SR_CANCEL_IOCTL,
|
2013-09-09 16:53:28 +02:00
|
|
|
endpt, id, SFF_IOCTL_FIRST);
|
2010-01-05 20:39:27 +01:00
|
|
|
if (result != EAGAIN)
|
2013-09-09 16:53:28 +02:00
|
|
|
return (result == OK) ? EDONTREPLY : EINTR;
|
2010-01-05 20:39:27 +01:00
|
|
|
|
|
|
|
result= walk_queue(sr_fd, &sr_fd->srf_read_q,
|
|
|
|
&sr_fd->srf_read_q_tail, SR_CANCEL_READ,
|
2013-09-09 16:53:28 +02:00
|
|
|
endpt, id, SFF_READ_FIRST);
|
2010-01-05 20:39:27 +01:00
|
|
|
if (result != EAGAIN)
|
2013-09-09 16:53:28 +02:00
|
|
|
return (result == OK) ? EDONTREPLY : EINTR;
|
2010-01-05 20:39:27 +01:00
|
|
|
|
|
|
|
result= walk_queue(sr_fd, &sr_fd->srf_write_q,
|
|
|
|
&sr_fd->srf_write_q_tail, SR_CANCEL_WRITE,
|
2013-09-09 16:53:28 +02:00
|
|
|
endpt, id, SFF_WRITE_FIRST);
|
2010-01-05 20:39:27 +01:00
|
|
|
if (result != EAGAIN)
|
2013-09-09 16:53:28 +02:00
|
|
|
return (result == OK) ? EDONTREPLY : EINTR;
|
2010-01-05 20:39:27 +01:00
|
|
|
|
2013-08-30 11:14:03 +02:00
|
|
|
/* We already replied to the request, so don't reply to the CANCEL. */
|
2013-09-09 16:53:28 +02:00
|
|
|
return EDONTREPLY;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
static int sr_select(devminor_t minor, unsigned int ops, endpoint_t endpt)
|
2005-06-28 17:19:58 +02:00
|
|
|
{
|
|
|
|
sr_fd_t *sr_fd;
|
2013-09-09 16:53:28 +02:00
|
|
|
int r, m_ops;
|
|
|
|
unsigned int i_ops;
|
2005-06-28 17:19:58 +02:00
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
sr_fd= sr_getchannel(minor);
|
2005-06-28 17:19:58 +02:00
|
|
|
assert (sr_fd);
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
sr_fd->srf_select_proc= endpt;
|
2005-06-28 17:19:58 +02:00
|
|
|
|
|
|
|
i_ops= 0;
|
2013-09-10 20:25:01 +02:00
|
|
|
if (ops & CDEV_OP_RD) i_ops |= SR_SELECT_READ;
|
|
|
|
if (ops & CDEV_OP_WR) i_ops |= SR_SELECT_WRITE;
|
|
|
|
if (ops & CDEV_OP_ERR) i_ops |= SR_SELECT_EXCEPTION;
|
|
|
|
if (!(ops & CDEV_NOTIFY)) i_ops |= SR_SELECT_POLL;
|
2005-06-28 17:19:58 +02:00
|
|
|
|
|
|
|
r= (*sr_fd->srf_select)(sr_fd->srf_fd, i_ops);
|
2013-08-30 11:14:03 +02:00
|
|
|
if (r < 0) {
|
|
|
|
m_ops= r;
|
|
|
|
} else {
|
2005-07-27 18:35:16 +02:00
|
|
|
m_ops= 0;
|
2013-09-10 20:25:01 +02:00
|
|
|
if (r & SR_SELECT_READ) m_ops |= CDEV_OP_RD;
|
|
|
|
if (r & SR_SELECT_WRITE) m_ops |= CDEV_OP_WR;
|
|
|
|
if (r & SR_SELECT_EXCEPTION) m_ops |= CDEV_OP_ERR;
|
2005-07-27 18:35:16 +02:00
|
|
|
}
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
return m_ops;
|
2005-07-27 18:35:16 +02:00
|
|
|
}
|
2005-06-28 17:19:58 +02:00
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
static int walk_queue(sr_fd, q_head_ptr, q_tail_ptr, type, endpt, id,
|
2005-07-27 18:35:16 +02:00
|
|
|
first_flag)
|
2005-04-21 16:53:53 +02:00
|
|
|
sr_fd_t *sr_fd;
|
2005-08-08 17:49:16 +02:00
|
|
|
mq_t **q_head_ptr;
|
|
|
|
mq_t **q_tail_ptr;
|
2005-04-21 16:53:53 +02:00
|
|
|
int type;
|
2013-09-09 16:53:28 +02:00
|
|
|
endpoint_t endpt;
|
|
|
|
cdev_id_t id;
|
2005-07-27 18:35:16 +02:00
|
|
|
int first_flag;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
mq_t *q_ptr_prv, *q_ptr;
|
|
|
|
int result;
|
|
|
|
|
2005-08-08 17:49:16 +02:00
|
|
|
for(q_ptr_prv= NULL, q_ptr= *q_head_ptr; q_ptr;
|
2005-04-21 16:53:53 +02:00
|
|
|
q_ptr_prv= q_ptr, q_ptr= q_ptr->mq_next)
|
|
|
|
{
|
2013-09-09 16:53:28 +02:00
|
|
|
if (q_ptr->mq_req.srr_endpt != endpt)
|
2005-04-21 16:53:53 +02:00
|
|
|
continue;
|
2013-09-09 16:53:28 +02:00
|
|
|
if (q_ptr->mq_req.srr_id != id)
|
2006-06-26 13:17:19 +02:00
|
|
|
continue;
|
2005-04-21 16:53:53 +02:00
|
|
|
if (!q_ptr_prv)
|
|
|
|
{
|
2005-07-27 18:35:16 +02:00
|
|
|
assert(!(sr_fd->srf_flags & first_flag));
|
|
|
|
sr_fd->srf_flags |= first_flag;
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
/* This will also send a reply. */
|
2005-04-21 16:53:53 +02:00
|
|
|
result= (*sr_fd->srf_cancel)(sr_fd->srf_fd, type);
|
|
|
|
assert(result == OK);
|
2005-07-27 18:35:16 +02:00
|
|
|
|
2005-08-08 17:49:16 +02:00
|
|
|
*q_head_ptr= q_ptr->mq_next;
|
|
|
|
mq_free(q_ptr);
|
|
|
|
|
2005-07-27 18:35:16 +02:00
|
|
|
assert(sr_fd->srf_flags & first_flag);
|
|
|
|
sr_fd->srf_flags &= ~first_flag;
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
q_ptr_prv->mq_next= q_ptr->mq_next;
|
|
|
|
mq_free(q_ptr);
|
|
|
|
if (!q_ptr_prv->mq_next)
|
|
|
|
*q_tail_ptr= q_ptr_prv;
|
|
|
|
return EINTR;
|
|
|
|
}
|
|
|
|
return EAGAIN;
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static sr_fd_t *sr_getchannel(minor)
|
2005-04-21 16:53:53 +02:00
|
|
|
int minor;
|
|
|
|
{
|
|
|
|
sr_fd_t *loc_fd;
|
|
|
|
|
|
|
|
compare(minor, >=, 0);
|
|
|
|
compare(minor, <, FD_NR);
|
|
|
|
|
|
|
|
loc_fd= &sr_fd_table[minor];
|
|
|
|
|
|
|
|
assert (!(loc_fd->srf_flags & SFF_MINOR) &&
|
|
|
|
(loc_fd->srf_flags & SFF_INUSE));
|
|
|
|
|
|
|
|
return loc_fd;
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static acc_t *sr_get_userdata (fd, offset, count, for_ioctl)
|
2005-04-21 16:53:53 +02:00
|
|
|
int fd;
|
2009-11-28 14:28:55 +01:00
|
|
|
size_t offset;
|
|
|
|
size_t count;
|
2005-04-21 16:53:53 +02:00
|
|
|
int for_ioctl;
|
|
|
|
{
|
|
|
|
sr_fd_t *loc_fd;
|
2005-06-28 17:19:58 +02:00
|
|
|
mq_t **head_ptr, *m, *mq;
|
2010-01-05 20:39:27 +01:00
|
|
|
int ip_flag, susp_flag, first_flag;
|
2005-07-27 18:35:16 +02:00
|
|
|
int result, suspended, is_revive;
|
2005-04-21 16:53:53 +02:00
|
|
|
acc_t *acc;
|
2005-06-28 17:19:58 +02:00
|
|
|
event_t *evp;
|
|
|
|
ev_arg_t arg;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
loc_fd= &sr_fd_table[fd];
|
|
|
|
|
|
|
|
if (for_ioctl)
|
|
|
|
{
|
|
|
|
head_ptr= &loc_fd->srf_ioctl_q;
|
2005-06-28 17:19:58 +02:00
|
|
|
evp= &loc_fd->srf_ioctl_ev;
|
2005-04-21 16:53:53 +02:00
|
|
|
ip_flag= SFF_IOCTL_IP;
|
|
|
|
susp_flag= SFF_IOCTL_SUSP;
|
2005-07-27 18:35:16 +02:00
|
|
|
first_flag= SFF_IOCTL_FIRST;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
head_ptr= &loc_fd->srf_write_q;
|
2005-06-28 17:19:58 +02:00
|
|
|
evp= &loc_fd->srf_write_ev;
|
2005-04-21 16:53:53 +02:00
|
|
|
ip_flag= SFF_WRITE_IP;
|
|
|
|
susp_flag= SFF_WRITE_SUSP;
|
2005-07-27 18:35:16 +02:00
|
|
|
first_flag= SFF_WRITE_FIRST;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2010-01-05 20:39:27 +01:00
|
|
|
assert (loc_fd->srf_flags & ip_flag);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
if (!count)
|
|
|
|
{
|
|
|
|
m= *head_ptr;
|
|
|
|
mq= m->mq_next;
|
2005-06-28 17:19:58 +02:00
|
|
|
*head_ptr= mq;
|
2005-04-21 16:53:53 +02:00
|
|
|
result= (int)offset;
|
2005-07-27 18:35:16 +02:00
|
|
|
is_revive= !(loc_fd->srf_flags & first_flag);
|
2013-09-09 16:53:28 +02:00
|
|
|
chardriver_reply_task(m->mq_req.srr_endpt, m->mq_req.srr_id,
|
|
|
|
result);
|
|
|
|
if (is_revive)
|
|
|
|
mq_free(m);
|
2005-04-21 16:53:53 +02:00
|
|
|
suspended= (loc_fd->srf_flags & susp_flag);
|
|
|
|
loc_fd->srf_flags &= ~(ip_flag|susp_flag);
|
|
|
|
if (suspended)
|
|
|
|
{
|
2005-06-28 17:19:58 +02:00
|
|
|
if (mq)
|
|
|
|
{
|
|
|
|
arg.ev_ptr= loc_fd;
|
|
|
|
ev_enqueue(evp, sr_event, arg);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
result= cp_u2b ((*head_ptr)->mq_req.srr_endpt,
|
|
|
|
(*head_ptr)->mq_req.srr_grant, offset, &acc, count);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
return result<0 ? NULL : acc;
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int sr_put_userdata (fd, offset, data, for_ioctl)
|
2005-04-21 16:53:53 +02:00
|
|
|
int fd;
|
2009-11-28 14:28:55 +01:00
|
|
|
size_t offset;
|
2005-04-21 16:53:53 +02:00
|
|
|
acc_t *data;
|
|
|
|
int for_ioctl;
|
|
|
|
{
|
|
|
|
sr_fd_t *loc_fd;
|
2005-06-28 17:19:58 +02:00
|
|
|
mq_t **head_ptr, *m, *mq;
|
2010-01-05 20:39:27 +01:00
|
|
|
int ip_flag, susp_flag, first_flag;
|
2005-07-27 18:35:16 +02:00
|
|
|
int result, suspended, is_revive;
|
2005-06-28 17:19:58 +02:00
|
|
|
event_t *evp;
|
|
|
|
ev_arg_t arg;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
loc_fd= &sr_fd_table[fd];
|
|
|
|
|
|
|
|
if (for_ioctl)
|
|
|
|
{
|
|
|
|
head_ptr= &loc_fd->srf_ioctl_q;
|
2005-06-28 17:19:58 +02:00
|
|
|
evp= &loc_fd->srf_ioctl_ev;
|
2005-04-21 16:53:53 +02:00
|
|
|
ip_flag= SFF_IOCTL_IP;
|
|
|
|
susp_flag= SFF_IOCTL_SUSP;
|
2005-07-27 18:35:16 +02:00
|
|
|
first_flag= SFF_IOCTL_FIRST;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
head_ptr= &loc_fd->srf_read_q;
|
2005-06-28 17:19:58 +02:00
|
|
|
evp= &loc_fd->srf_read_ev;
|
2005-04-21 16:53:53 +02:00
|
|
|
ip_flag= SFF_READ_IP;
|
|
|
|
susp_flag= SFF_READ_SUSP;
|
2005-07-27 18:35:16 +02:00
|
|
|
first_flag= SFF_READ_FIRST;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert (loc_fd->srf_flags & ip_flag);
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
m= *head_ptr;
|
|
|
|
mq= m->mq_next;
|
2005-06-28 17:19:58 +02:00
|
|
|
*head_ptr= mq;
|
2005-04-21 16:53:53 +02:00
|
|
|
result= (int)offset;
|
2005-07-27 18:35:16 +02:00
|
|
|
is_revive= !(loc_fd->srf_flags & first_flag);
|
2013-09-09 16:53:28 +02:00
|
|
|
chardriver_reply_task(m->mq_req.srr_endpt, m->mq_req.srr_id,
|
|
|
|
result);
|
|
|
|
if (is_revive)
|
|
|
|
mq_free(m);
|
2005-04-21 16:53:53 +02:00
|
|
|
suspended= (loc_fd->srf_flags & susp_flag);
|
|
|
|
loc_fd->srf_flags &= ~(ip_flag|susp_flag);
|
|
|
|
if (suspended)
|
|
|
|
{
|
2005-06-28 17:19:58 +02:00
|
|
|
if (mq)
|
|
|
|
{
|
|
|
|
arg.ev_ptr= loc_fd;
|
|
|
|
ev_enqueue(evp, sr_event, arg);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
return cp_b2u (data, (*head_ptr)->mq_req.srr_endpt,
|
|
|
|
(*head_ptr)->mq_req.srr_grant, offset);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static void sr_select_res(int fd, unsigned ops)
|
2005-06-28 17:19:58 +02:00
|
|
|
{
|
|
|
|
sr_fd_t *sr_fd;
|
2013-08-30 11:14:03 +02:00
|
|
|
unsigned int m_ops;
|
2005-06-28 17:19:58 +02:00
|
|
|
|
|
|
|
sr_fd= &sr_fd_table[fd];
|
|
|
|
|
2013-08-30 11:14:03 +02:00
|
|
|
m_ops= 0;
|
2013-09-10 20:25:01 +02:00
|
|
|
if (ops & SR_SELECT_READ) m_ops |= CDEV_OP_RD;
|
|
|
|
if (ops & SR_SELECT_WRITE) m_ops |= CDEV_OP_WR;
|
|
|
|
if (ops & SR_SELECT_EXCEPTION) m_ops |= CDEV_OP_ERR;
|
2013-08-30 11:14:03 +02:00
|
|
|
|
2013-09-09 16:53:28 +02:00
|
|
|
chardriver_reply_select(sr_fd->srf_select_proc, fd, m_ops);
|
2005-06-28 17:19:58 +02:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static void sr_event(evp, arg)
|
2005-06-28 17:19:58 +02:00
|
|
|
event_t *evp;
|
|
|
|
ev_arg_t arg;
|
|
|
|
{
|
|
|
|
sr_fd_t *sr_fd;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
sr_fd= arg.ev_ptr;
|
|
|
|
if (evp == &sr_fd->srf_write_ev)
|
|
|
|
{
|
|
|
|
while(sr_fd->srf_write_q)
|
|
|
|
{
|
|
|
|
r= sr_restart_write(sr_fd);
|
|
|
|
if (r == SUSPEND)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (evp == &sr_fd->srf_read_ev)
|
|
|
|
{
|
|
|
|
while(sr_fd->srf_read_q)
|
|
|
|
{
|
|
|
|
r= sr_restart_read(sr_fd);
|
|
|
|
if (r == SUSPEND)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (evp == &sr_fd->srf_ioctl_ev)
|
|
|
|
{
|
|
|
|
while(sr_fd->srf_ioctl_q)
|
|
|
|
{
|
|
|
|
r= sr_restart_ioctl(sr_fd);
|
|
|
|
if (r == SUSPEND)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2010-01-05 20:39:27 +01:00
|
|
|
ip_panic(("sr_event: unknown event\n"));
|
2005-06-28 17:19:58 +02:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int cp_u2b(proc, gid, offset, var_acc_ptr, size)
|
2010-03-30 16:07:15 +02:00
|
|
|
endpoint_t proc;
|
|
|
|
cp_grant_id_t gid;
|
2006-06-26 16:20:11 +02:00
|
|
|
vir_bytes offset;
|
2006-06-26 13:17:19 +02:00
|
|
|
acc_t **var_acc_ptr;
|
|
|
|
int size;
|
|
|
|
{
|
|
|
|
acc_t *acc;
|
2006-06-26 16:20:11 +02:00
|
|
|
int i, r;
|
2006-06-26 13:17:19 +02:00
|
|
|
|
|
|
|
acc= bf_memreq(size);
|
|
|
|
|
|
|
|
*var_acc_ptr= acc;
|
|
|
|
i=0;
|
|
|
|
|
|
|
|
while (acc)
|
|
|
|
{
|
|
|
|
size= (vir_bytes)acc->acc_length;
|
|
|
|
|
2006-06-26 16:20:11 +02:00
|
|
|
s_cp_req[i].v_from= proc;
|
|
|
|
s_cp_req[i].v_to= SELF;
|
|
|
|
s_cp_req[i].v_gid= gid;
|
|
|
|
s_cp_req[i].v_offset= offset;
|
|
|
|
s_cp_req[i].v_addr= (vir_bytes) ptr2acc_data(acc);
|
|
|
|
s_cp_req[i].v_bytes= size;
|
2006-06-26 13:17:19 +02:00
|
|
|
|
2006-06-26 16:20:11 +02:00
|
|
|
offset += size;
|
2006-06-26 13:17:19 +02:00
|
|
|
acc= acc->acc_next;
|
|
|
|
i++;
|
|
|
|
|
2006-06-26 16:20:11 +02:00
|
|
|
if (acc == NULL && i == 1)
|
2006-06-26 13:17:19 +02:00
|
|
|
{
|
2006-06-26 16:20:11 +02:00
|
|
|
r= sys_safecopyfrom(s_cp_req[0].v_from,
|
|
|
|
s_cp_req[0].v_gid, s_cp_req[0].v_offset,
|
2012-06-16 03:46:15 +02:00
|
|
|
s_cp_req[0].v_addr, s_cp_req[0].v_bytes);
|
2006-06-26 16:20:11 +02:00
|
|
|
if (r <0)
|
2006-06-26 13:17:19 +02:00
|
|
|
{
|
2006-06-26 16:20:11 +02:00
|
|
|
printf("sys_safecopyfrom failed: %d\n", r);
|
2006-06-26 13:17:19 +02:00
|
|
|
bf_afree(*var_acc_ptr);
|
|
|
|
*var_acc_ptr= 0;
|
2006-06-26 16:20:11 +02:00
|
|
|
return r;
|
2006-06-26 13:17:19 +02:00
|
|
|
}
|
|
|
|
i= 0;
|
2006-06-26 16:20:11 +02:00
|
|
|
continue;
|
2006-06-26 13:17:19 +02:00
|
|
|
}
|
2010-01-05 20:39:27 +01:00
|
|
|
if (i == SCPVEC_NR || acc == NULL)
|
2006-06-26 13:17:19 +02:00
|
|
|
{
|
2006-06-26 16:20:11 +02:00
|
|
|
r= sys_vsafecopy(s_cp_req, i);
|
2006-06-26 13:17:19 +02:00
|
|
|
|
2006-06-26 16:20:11 +02:00
|
|
|
if (r <0)
|
|
|
|
{
|
2010-01-05 20:39:27 +01:00
|
|
|
printf("cp_u2b: sys_vsafecopy failed: %d\n",
|
2006-06-26 16:20:11 +02:00
|
|
|
r);
|
|
|
|
bf_afree(*var_acc_ptr);
|
|
|
|
*var_acc_ptr= 0;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
i= 0;
|
|
|
|
}
|
2006-06-26 13:17:19 +02:00
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int cp_b2u(acc_ptr, proc, gid, offset)
|
2006-06-26 13:17:19 +02:00
|
|
|
acc_t *acc_ptr;
|
2010-03-30 16:07:15 +02:00
|
|
|
endpoint_t proc;
|
|
|
|
cp_grant_id_t gid;
|
2006-06-26 13:17:19 +02:00
|
|
|
vir_bytes offset;
|
|
|
|
{
|
|
|
|
acc_t *acc;
|
2006-06-26 16:20:11 +02:00
|
|
|
int i, r, size;
|
2006-06-26 13:17:19 +02:00
|
|
|
|
|
|
|
acc= acc_ptr;
|
|
|
|
i=0;
|
|
|
|
|
|
|
|
while (acc)
|
|
|
|
{
|
|
|
|
size= (vir_bytes)acc->acc_length;
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
{
|
2006-06-26 16:20:11 +02:00
|
|
|
s_cp_req[i].v_from= SELF;
|
|
|
|
s_cp_req[i].v_to= proc;
|
|
|
|
s_cp_req[i].v_gid= gid;
|
|
|
|
s_cp_req[i].v_offset= offset;
|
|
|
|
s_cp_req[i].v_addr= (vir_bytes) ptr2acc_data(acc);
|
|
|
|
s_cp_req[i].v_bytes= size;
|
|
|
|
|
2006-06-26 13:17:19 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2006-06-26 16:20:11 +02:00
|
|
|
offset += size;
|
2006-06-26 13:17:19 +02:00
|
|
|
acc= acc->acc_next;
|
|
|
|
|
2006-06-26 16:20:11 +02:00
|
|
|
if (acc == NULL && i == 1)
|
2006-06-26 13:17:19 +02:00
|
|
|
{
|
2006-06-26 16:20:11 +02:00
|
|
|
r= sys_safecopyto(s_cp_req[0].v_to,
|
|
|
|
s_cp_req[0].v_gid, s_cp_req[0].v_offset,
|
2012-06-16 03:46:15 +02:00
|
|
|
s_cp_req[0].v_addr, s_cp_req[0].v_bytes);
|
2006-06-26 16:20:11 +02:00
|
|
|
if (r <0)
|
2006-06-26 13:17:19 +02:00
|
|
|
{
|
2006-06-26 16:20:11 +02:00
|
|
|
printf("sys_safecopyto failed: %d\n", r);
|
2006-06-26 13:17:19 +02:00
|
|
|
bf_afree(acc_ptr);
|
2006-06-26 16:20:11 +02:00
|
|
|
return r;
|
2006-06-26 13:17:19 +02:00
|
|
|
}
|
|
|
|
i= 0;
|
2006-06-26 16:20:11 +02:00
|
|
|
continue;
|
2006-06-26 13:17:19 +02:00
|
|
|
}
|
2010-01-05 20:39:27 +01:00
|
|
|
if (i == SCPVEC_NR || acc == NULL)
|
2006-06-26 13:17:19 +02:00
|
|
|
{
|
2006-06-26 16:20:11 +02:00
|
|
|
r= sys_vsafecopy(s_cp_req, i);
|
|
|
|
|
|
|
|
if (r <0)
|
2006-06-26 13:17:19 +02:00
|
|
|
{
|
2010-01-05 20:39:27 +01:00
|
|
|
printf("cp_b2u: sys_vsafecopy failed: %d\n",
|
2006-06-26 13:17:19 +02:00
|
|
|
r);
|
|
|
|
bf_afree(acc_ptr);
|
|
|
|
return r;
|
|
|
|
}
|
2006-06-26 16:20:11 +02:00
|
|
|
i= 0;
|
2006-06-26 13:17:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bf_afree(acc_ptr);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*
|
2005-06-28 17:19:58 +02:00
|
|
|
* $PchId: sr.c,v 1.17 2005/06/28 14:26:16 philip Exp $
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|