OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [mm0/] [mm/] [exit.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * exit()
3
 *
4
 * Copyright (C) 2008 Bahadir Balban
5
 */
6
#include <shm.h>
7
#include <task.h>
8
#include <file.h>
9
#include <exit.h>
10
#include <test.h>
11
#include <utcb.h>
12
#include <vm_area.h>
13
#include <syscalls.h>
14
#include <l4lib/exregs.h>
15
#include <l4lib/ipcdefs.h>
16
#include <malloc/malloc.h>
17
#include <l4/api/space.h>
18
#include L4LIB_INC_ARCH(syslib.h)
19
#include L4LIB_INC_ARCH(syscalls.h)
20
 
21
 
22
/* Closes all file descriptors of a task */
23
int task_close_files(struct tcb *task)
24
{
25
        int err = 0;
26
 
27
        /* Flush all file descriptors */
28
        for (int fd = 0; fd < TASK_FILES_MAX; fd++)
29
                if (task->files->fd[fd].vmfile)
30
                        if ((err = sys_close(task, fd)) < 0) {
31
                                printf("File close error. Tid: %d,"
32
                                       " fd: %d, error: %d\n",
33
                                       task->tid, fd, err);
34
                                break;
35
                        }
36
        return err;
37
}
38
 
39
/* Prepare old task's environment for new task */
40
int execve_recycle_task(struct tcb *new, struct tcb *orig)
41
{
42
        int err;
43
        struct task_ids ids = {
44
                .tid = orig->tid,
45
                .spid = orig->spid,
46
                .tgid = orig->tgid,
47
        };
48
 
49
        /*
50
         * Copy data to new task that is
51
         * to be retained from original
52
         */
53
 
54
        /* Copy ids */
55
        new->tid = orig->tid;
56
        new->spid = orig->spid;
57
        new->tgid = orig->tgid;
58
        new->pagerid = orig->pagerid;
59
 
60
        /* Copy shared page */
61
        /*
62
         * FIXME: Make sure to take care of this.
63
         */
64
        //new->shared_page = orig->shared_page;
65
 
66
        /* Copy parent relationship */
67
        BUG_ON(new->parent);
68
        new->parent = orig->parent;
69
        list_insert(&new->child_ref, &orig->parent->children);
70
 
71
        /* Flush all IO on task's files and close fds */
72
        task_close_files(orig);
73
 
74
        /* Destroy task's utcb slot */
75
        task_destroy_utcb(orig);
76
 
77
        /* Vfs still knows the thread */
78
 
79
        /* Keep the shared page on vfs */
80
 
81
        /* Ask the kernel to recycle the thread */
82
        if ((err = l4_thread_control(THREAD_RECYCLE, &ids)) < 0) {
83
                printf("%s: Suspending thread %d failed with %d.\n",
84
                       __FUNCTION__, orig->tid, err);
85
                return err;
86
        }
87
 
88
        /* Destroy the locally known tcb */
89
        tcb_destroy(orig);
90
 
91
        return 0;
92
}
93
 
94
void do_exit(struct tcb *task, int status)
95
{
96
        struct task_ids ids = {
97
                .tid = task->tid,
98
                .spid = task->spid,
99
                .tgid = task->tgid,
100
        };
101
 
102
        /* Flush all IO on task's files and close fds */
103
        task_close_files(task);
104
 
105
        /* Destroy task's utcb slot */
106
        task_destroy_utcb(task);
107
 
108
        /* Remove default shared page shm areas from vfs */
109
        // printf("Unmapping 0x%p from vfs as shared-page of %d\n", task->shared_page, task->tid);
110
        //shpage_unmap_from_task(task, find_task(VFS_TID));
111
 
112
        /* Free task's local tcb */
113
        tcb_destroy(task);
114
 
115
        /* Ask the kernel to delete the thread from its records */
116
        l4_thread_control(THREAD_DESTROY, &ids);
117
 
118
        /* TODO: Wake up any waiters about task's destruction */
119
#if 0
120
        struct tcb *parent = find_task(task->parentid);
121
        if (parent->waiting) {
122
                exregs_set_mr_return(status);
123
                l4_exchange_registers(parent->tid);
124
                l4_thread_control(THREAD_RUN, parent->tid);
125
        }
126
#endif
127
}
128
 
129
void sys_exit(struct tcb *task, int status)
130
{
131
        do_exit(task, status);
132
}
133
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.