Moved all find_task(sender) calls into topmost ipc handler.

System calls now need not search for the tcb they are serving for.
This commit is contained in:
Bahadir Balban
2008-09-16 20:11:24 +03:00
parent 2e94a78253
commit a413b19842
13 changed files with 51 additions and 100 deletions

View File

@@ -49,7 +49,7 @@ int vfs_notify_fork(struct tcb *child, struct tcb *parent)
}
int do_fork(struct tcb *parent)
int sys_fork(struct tcb *parent)
{
int err;
struct tcb *child;
@@ -111,23 +111,11 @@ int do_fork(struct tcb *parent)
return child->tid;
}
int sys_fork(l4id_t sender)
{
struct tcb *parent;
if (!(parent = find_task(sender)))
return -ESRCH;
return do_fork(parent);
}
int sys_clone(l4id_t sender, void *child_stack, unsigned int flags)
int sys_clone(struct tcb *parent, void *child_stack, unsigned int flags)
{
struct task_ids ids;
struct vm_file *utcb_shm;
struct tcb *parent, *child;
BUG_ON(!(parent = find_task(sender)));
struct tcb *child;
ids.tid = TASK_ID_INVALID;
ids.spid = parent->spid;

View File

@@ -681,19 +681,15 @@ int do_page_fault(struct fault_data *fault)
return __do_page_fault(fault);
}
int page_fault_handler(l4id_t sender, fault_kdata_t *fkdata)
int page_fault_handler(struct tcb *sender, fault_kdata_t *fkdata)
{
int err;
struct fault_data fault = {
/* Fault data from kernel */
.kdata = fkdata,
.task = sender,
};
BUG_ON(sender == 0);
/* Get pager specific task info */
BUG_ON(!(fault.task = find_task(sender)));
/* Extract fault reason, fault address etc. in generic format */
set_generic_fault_params(&fault);

View File

@@ -403,13 +403,9 @@ int do_close(struct tcb *task, int fd)
return 0;
}
int sys_close(l4id_t sender, int fd)
int sys_close(struct tcb *task, int fd)
{
int ret;
struct tcb *task;
if (!(task = find_task(sender)))
return -ESRCH;
/* Sync the file and update stats */
if ((ret = fsync_common(task, fd)) < 0)
@@ -419,13 +415,8 @@ int sys_close(l4id_t sender, int fd)
return do_close(task, fd);
}
int sys_fsync(l4id_t sender, int fd)
int sys_fsync(struct tcb *task, int fd)
{
struct tcb *task;
if (!(task = find_task(sender)))
return -ESRCH;
/* Sync the file and update stats */
return fsync_common(task, fd);
}
@@ -586,17 +577,13 @@ copy:
return count - left;
}
int sys_read(l4id_t sender, int fd, void *buf, int count)
int sys_read(struct tcb *task, int fd, void *buf, int count)
{
unsigned long pfn_start, pfn_end;
unsigned long cursor, byte_offset;
struct vm_file *vmfile;
struct tcb *task;
int ret = 0;
if (!(task = find_task(sender)))
return -ESRCH;
/* Check fd validity */
if (!task->files->fd[fd].vmfile)
if ((ret = file_open(task, fd)) < 0)
@@ -658,19 +645,15 @@ int sys_read(l4id_t sender, int fd, void *buf, int count)
* We find the page buffer is in, and then copy from the *start* of the page
* rather than buffer's offset in that page.
*/
int sys_write(l4id_t sender, int fd, void *buf, int count)
int sys_write(struct tcb *task, int fd, void *buf, int count)
{
unsigned long pfn_wstart, pfn_wend; /* Write start/end */
unsigned long pfn_fstart, pfn_fend; /* File start/end */
unsigned long pfn_nstart, pfn_nend; /* New pages start/end */
unsigned long cursor, byte_offset;
struct vm_file *vmfile;
struct tcb *task;
int ret = 0;
if (!(task = find_task(sender)))
return -ESRCH;
/* Check fd validity */
if (!task->files->fd[fd].vmfile)
if ((ret = file_open(task, fd)) < 0)
@@ -766,15 +749,11 @@ int sys_write(l4id_t sender, int fd, void *buf, int count)
}
/* FIXME: Check for invalid cursor values. Check for total, sometimes negative. */
int sys_lseek(l4id_t sender, int fd, off_t offset, int whence)
int sys_lseek(struct tcb *task, int fd, off_t offset, int whence)
{
struct tcb *task;
int retval = 0;
unsigned long long total, cursor;
if (!(task = find_task(sender)))
return -ESRCH;
/* Check fd validity */
if (!task->files->fd[fd].vmfile)
if ((retval = file_open(task, fd)) < 0)

View File

@@ -582,19 +582,15 @@ void *do_mmap(struct vm_file *mapfile, unsigned long file_offset,
}
/* mmap system call implementation */
void *sys_mmap(l4id_t sender, void *start, size_t length, int prot,
void *sys_mmap(struct tcb *task, void *start, size_t length, int prot,
int flags, int fd, unsigned long pfn)
{
unsigned long npages = __pfn(page_align_up(length));
unsigned long base = (unsigned long)start;
struct vm_file *file = 0;
unsigned int vmflags = 0;
struct tcb *task;
int err;
if (!(task = find_task(sender)))
return PTR_ERR(-ESRCH);
/* Check fd validity */
if (!(flags & MAP_ANONYMOUS))
if (!task->files->fd[fd].vmfile)
@@ -647,7 +643,7 @@ void *sys_mmap(l4id_t sender, void *start, size_t length, int prot,
}
/* Sets the end of data segment for sender */
int sys_brk(l4id_t sender, void *ds_end)
int sys_brk(struct tcb *sender, void *ds_end)
{
return 0;
}

View File

@@ -119,10 +119,9 @@ static void *do_shmat(struct vm_file *shm_file, void *shm_addr, int shmflg,
utcb_prefault(task, VM_READ | VM_WRITE);
*/
void *sys_shmat(l4id_t requester, l4id_t shmid, void *shmaddr, int shmflg)
void *sys_shmat(struct tcb *task, l4id_t shmid, void *shmaddr, int shmflg)
{
struct vm_file *shm_file, *n;
struct tcb *task = find_task(requester);
list_for_each_entry_safe(shm_file, n, &shm_file_list, list) {
if (shm_file_to_desc(shm_file)->shmid == shmid)
@@ -133,34 +132,26 @@ void *sys_shmat(l4id_t requester, l4id_t shmid, void *shmaddr, int shmflg)
return PTR_ERR(-EINVAL);
}
int do_shmdt(struct vm_file *shm, l4id_t tid)
int do_shmdt(struct tcb *task, struct vm_file *shm)
{
struct tcb *task = find_task(tid);
int err;
if (!task) {
printf("%s:%s: Internal error. Cannot find task with tid %d\n",
__TASKNAME__, __FUNCTION__, tid);
BUG();
}
if ((err = do_munmap(shm_file_to_desc(shm)->shm_addr,
shm_file_to_desc(shm)->npages, task)) < 0) {
printf("do_munmap: Unmapping shm segment failed with %d.\n",
err);
BUG();
}
shm_file_to_desc(shm)->npages,
task)) < 0)
return err;
return err;
return 0;
}
int sys_shmdt(l4id_t requester, const void *shmaddr)
int sys_shmdt(struct tcb *task, const void *shmaddr)
{
struct vm_file *shm_file, *n;
int err;
list_for_each_entry_safe(shm_file, n, &shm_file_list, list) {
if (shm_file_to_desc(shm_file)->shm_addr == shmaddr) {
if ((err = do_shmdt(shm_file, requester) < 0))
if ((err = do_shmdt(task, shm_file) < 0))
return err;
else
break;

View File

@@ -436,20 +436,19 @@ void task_map_prefault_utcb(struct tcb *mapper, struct tcb *owner)
* are running, and their tids, which includes itself. This function
* provides that information.
*/
int send_task_data(l4id_t requester)
int send_task_data(struct tcb *vfs)
{
int li = 0;
struct tcb *t, *vfs, *self;
struct tcb *t, *self;
struct task_data_head *tdata_head;
if (requester != VFS_TID) {
if (vfs->tid != VFS_TID) {
printf("%s: Task data requested by %d, which is not "
"FS0 id %d, ignoring.\n", __TASKNAME__, requester,
"FS0 id %d, ignoring.\n", __TASKNAME__, vfs->tid,
VFS_TID);
return 0;
}
BUG_ON(!(vfs = find_task(requester)));
BUG_ON(!(self = find_task(self_tid())));
BUG_ON(!vfs->utcb);

View File

@@ -39,17 +39,13 @@ void *utcb_vaddr_new(void)
* for its own. The requester then uses this address as a shm key and
* maps its own utcb via shmget/shmat.
*/
void *task_send_utcb_address(l4id_t sender, l4id_t taskid)
void *task_send_utcb_address(struct tcb *sender, l4id_t taskid)
{
struct tcb *task = find_task(taskid);
/* Is the task asking for its own utcb address */
if (sender == taskid) {
/*
* It hasn't got one allocated. We allocate one here,
* but only because the requester is requesting for its
* own utcb.
*/
if (sender->tid == taskid) {
/* It hasn't got one allocated. */
BUG_ON(!task->utcb);
/* Return it to requester */
@@ -58,7 +54,7 @@ void *task_send_utcb_address(l4id_t sender, l4id_t taskid)
/* A task is asking for someone else's utcb */
} else {
/* Only vfs is allowed to do so yet, because its a server */
if (sender == VFS_TID) {
if (sender->tid == VFS_TID) {
/*
* Return utcb address to requester. Note if there's
* none allocated so far, requester gets 0. We don't