From a413b19842c240e4b9e43c1eb2a097a765f5c134 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Tue, 16 Sep 2008 20:11:24 +0300 Subject: [PATCH] Moved all find_task(sender) calls into topmost ipc handler. System calls now need not search for the tcb they are serving for. --- tasks/mm0/include/file.h | 12 +++++------- tasks/mm0/include/syscalls.h | 11 ++++++----- tasks/mm0/include/task.h | 2 +- tasks/mm0/include/utcb.h | 2 +- tasks/mm0/include/vm_area.h | 2 +- tasks/mm0/main.c | 11 +++++++++-- tasks/mm0/src/clone.c | 18 +++--------------- tasks/mm0/src/fault.c | 8 ++------ tasks/mm0/src/file.c | 31 +++++-------------------------- tasks/mm0/src/mmap.c | 8 ++------ tasks/mm0/src/shm.c | 25 ++++++++----------------- tasks/mm0/src/task.c | 9 ++++----- tasks/mm0/src/utcb.c | 12 ++++-------- 13 files changed, 51 insertions(+), 100 deletions(-) diff --git a/tasks/mm0/include/file.h b/tasks/mm0/include/file.h index b031fd9..f25317e 100644 --- a/tasks/mm0/include/file.h +++ b/tasks/mm0/include/file.h @@ -9,17 +9,15 @@ void vmfile_init(void); struct vm_file *vmfile_alloc_init(void); -int vfs_receive_sys_open(l4id_t sender, l4id_t opener, int fd, - unsigned long vnum, unsigned long size); int vfs_read(unsigned long vnum, unsigned long f_offset, unsigned long npages, void *pagebuf); int vfs_write(unsigned long vnum, unsigned long f_offset, unsigned long npages, void *pagebuf); -int sys_read(l4id_t sender, int fd, void *buf, int count); -int sys_write(l4id_t sender, int fd, void *buf, int count); -int sys_lseek(l4id_t sender, int fd, off_t offset, int whence); -int sys_close(l4id_t sender, int fd); -int sys_fsync(l4id_t sender, int fd); +int sys_read(struct tcb *sender, int fd, void *buf, int count); +int sys_write(struct tcb *sender, int fd, void *buf, int count); +int sys_lseek(struct tcb *sender, int fd, off_t offset, int whence); +int sys_close(struct tcb *sender, int fd); +int sys_fsync(struct tcb *sender, int fd); int file_open(struct tcb *opener, int fd); struct vfs_file_data { diff --git a/tasks/mm0/include/syscalls.h b/tasks/mm0/include/syscalls.h index d2d0daf..2f8bb02 100644 --- a/tasks/mm0/include/syscalls.h +++ b/tasks/mm0/include/syscalls.h @@ -11,6 +11,7 @@ #include #include +#include /* For reading argument data from a system call */ struct sys_mmap_args { @@ -22,10 +23,10 @@ struct sys_mmap_args { off_t offset; }; -void *sys_mmap(l4id_t sender, void *start, size_t length, int prot, +void *sys_mmap(struct tcb *sender, void *start, size_t length, int prot, int flags, int fd, off_t offset); -int sys_munmap(l4id_t sender, void *vaddr, unsigned long size); +int sys_munmap(struct tcb *sender, void *vaddr, unsigned long size); struct sys_shmat_args { l4id_t shmid; @@ -33,8 +34,8 @@ struct sys_shmat_args { int shmflg; }; -void *sys_shmat(l4id_t requester, l4id_t shmid, const void *shmaddr, int shmflg); -int sys_shmdt(l4id_t requester, const void *shmaddr); +void *sys_shmat(struct tcb *requester, l4id_t shmid, const void *shmaddr, int shmflg); +int sys_shmdt(struct tcb *requester, const void *shmaddr); struct sys_shmget_args { key_t key; @@ -44,7 +45,7 @@ struct sys_shmget_args { int sys_shmget(key_t key, int size, int shmflg); -int sys_fork(l4id_t parent); +int sys_fork(struct tcb *parent); #endif /* __MM0_SYSARGS_H__ */ diff --git a/tasks/mm0/include/task.h b/tasks/mm0/include/task.h index 939583f..87023c8 100644 --- a/tasks/mm0/include/task.h +++ b/tasks/mm0/include/task.h @@ -113,7 +113,7 @@ struct task_data_head { struct tcb *find_task(int tid); void task_add_global(struct tcb *t); -int send_task_data(l4id_t requester); +int send_task_data(struct tcb *requester); void task_map_prefault_utcb(struct tcb *mapper, struct tcb *owner); int task_mmap_regions(struct tcb *task, struct vm_file *file); int task_setup_regions(struct vm_file *file, struct tcb *task, diff --git a/tasks/mm0/include/utcb.h b/tasks/mm0/include/utcb.h index d003fed..6e22eda 100644 --- a/tasks/mm0/include/utcb.h +++ b/tasks/mm0/include/utcb.h @@ -8,7 +8,7 @@ int utcb_pool_init(void); /* IPC to send utcb address information to tasks */ -void *task_send_utcb_address(l4id_t sender, l4id_t taskid); +void *task_send_utcb_address(struct tcb *sender, l4id_t taskid); /* Prefault an *mmaped* utcb */ int utcb_prefault(struct tcb *task, unsigned int vmflags); diff --git a/tasks/mm0/include/vm_area.h b/tasks/mm0/include/vm_area.h index c9ee7fe..56a64b0 100644 --- a/tasks/mm0/include/vm_area.h +++ b/tasks/mm0/include/vm_area.h @@ -252,6 +252,6 @@ static inline void task_add_vma(struct tcb *task, struct vm_area *vma) } /* Main page fault entry point */ -int page_fault_handler(l4id_t tid, fault_kdata_t *fkdata); +int page_fault_handler(struct tcb *faulty_task, fault_kdata_t *fkdata); #endif /* __VM_AREA_H__ */ diff --git a/tasks/mm0/main.c b/tasks/mm0/main.c index 1bdce11..c0f580d 100644 --- a/tasks/mm0/main.c +++ b/tasks/mm0/main.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -26,7 +27,8 @@ void handle_requests(void) { /* Generic ipc data */ u32 mr[MR_UNUSED_TOTAL]; - l4id_t sender; + l4id_t senderid; + struct tcb *sender; u32 tag; int ret; @@ -39,7 +41,12 @@ void handle_requests(void) /* Syslib conventional ipc data which uses first few mrs. */ tag = l4_get_tag(); - sender = l4_get_sender(); + senderid = l4_get_sender(); + + if (!(sender = find_task(senderid))) { + l4_ipc_return(-ESRCH); + return; + } /* Read mrs not used by syslib */ for (int i = 0; i < MR_UNUSED_TOTAL; i++) diff --git a/tasks/mm0/src/clone.c b/tasks/mm0/src/clone.c index 66cea56..41a34e8 100755 --- a/tasks/mm0/src/clone.c +++ b/tasks/mm0/src/clone.c @@ -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; diff --git a/tasks/mm0/src/fault.c b/tasks/mm0/src/fault.c index 49ce44b..1df2984 100644 --- a/tasks/mm0/src/fault.c +++ b/tasks/mm0/src/fault.c @@ -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); diff --git a/tasks/mm0/src/file.c b/tasks/mm0/src/file.c index 7126a89..5d27e47 100644 --- a/tasks/mm0/src/file.c +++ b/tasks/mm0/src/file.c @@ -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) diff --git a/tasks/mm0/src/mmap.c b/tasks/mm0/src/mmap.c index fa67175..f871146 100644 --- a/tasks/mm0/src/mmap.c +++ b/tasks/mm0/src/mmap.c @@ -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; } diff --git a/tasks/mm0/src/shm.c b/tasks/mm0/src/shm.c index 2d09be5..b47a1d6 100644 --- a/tasks/mm0/src/shm.c +++ b/tasks/mm0/src/shm.c @@ -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; diff --git a/tasks/mm0/src/task.c b/tasks/mm0/src/task.c index 12720fc..ec23593 100644 --- a/tasks/mm0/src/task.c +++ b/tasks/mm0/src/task.c @@ -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); diff --git a/tasks/mm0/src/utcb.c b/tasks/mm0/src/utcb.c index 11c9f9d..39225d2 100644 --- a/tasks/mm0/src/utcb.c +++ b/tasks/mm0/src/utcb.c @@ -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