Statistics
| Branch: | Revision:

scoutos / prex-0.9.0 / usr / server / proc / proc.h @ 03e9c04a

History | View | Annotate | Download (4.59 KB)

1
/*
2
 * Copyright (c) 2005-2007, Kohsuke Ohtani
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. Neither the name of the author nor the names of any co-contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 */
29

    
30
#ifndef _PROC_H
31
#define _PROC_H
32

    
33
#include <sys/cdefs.h>
34
#include <sys/param.h>
35
#include <sys/types.h>
36
#include <sys/list.h>
37
#include <ipc/proc.h>
38
#include <ipc/ipc.h>
39
#include <sys/capability.h>
40

    
41
#include <unistd.h>
42
#include <stdio.h>
43
#include <assert.h>
44

    
45
/* #define DEBUG_PROC 1 */
46

    
47
#ifdef DEBUG_PROC
48
#define DPRINTF(a)        dprintf a
49
#define ASSERT(e)        dassert(e)
50
#else
51
#define DPRINTF(a)
52
#define ASSERT(e)
53
#endif
54

    
55
#define PID_MAX                0x8000                /* max number for PID */
56

    
57
#define ID_MAXBUCKETS        32
58
#define IDHASH(x)        ((x) & (ID_MAXBUCKETS - 1))
59

    
60
struct proc;
61

    
62
/*
63
 * Session
64
 */
65
struct session {
66
        int                s_refcnt;        /* reference count */
67
        struct proc        *s_leader;        /* session leader */
68
        int                s_ttyhold;        /* true if hold tty */
69
};
70

    
71

    
72
/*
73
 * Process group
74
 */
75
struct pgrp {
76
        struct list        pg_link;        /* link for pgid hash */
77
        struct list        pg_members;        /* list head of processes */
78
        struct session        *pg_session;        /* pointer to session */
79
        pid_t                pg_pgid;        /* pgrp id */
80
};
81

    
82
/*
83
 * Description of a process
84
 */
85
struct proc {
86
        struct list        p_link;                /* link for all processes */
87
        struct proc         *p_parent;        /* pointer to parent process */
88
        struct list         p_children;        /* list head of child processes */
89
        struct list         p_sibling;        /* link for sibling processes */
90
        struct list         p_pid_link;        /* link for pid hash */
91
        struct list         p_task_link;        /* link for task hash */
92
        struct list         p_pgrp_link;        /* link for process group */
93
        struct pgrp         *p_pgrp;        /* pointer to process group */
94
        int                p_stat;                /* process status S* */
95
        int                p_flag;                /* P_* flags */
96
        int                p_exitcode;        /* exit code to send to parrent */
97
        int                p_vforked;        /* true while processing vfork() */
98
        int                p_invfork;        /* true if child of vfork() */
99
        pid_t                p_pid;                /* process id */
100
        task_t                p_task;                /* task id */
101
        void                *p_stackbase;        /* pointer to stack */
102
        void                *p_stacksaved;        /* pointer to saved stack */
103
};
104

    
105
/* Status values. */
106
#define SRUN        1        /* running */
107
#define SZOMB        2        /* process terminated but not waited for */
108
#define SSTOP        3        /* proces stopped */
109

    
110
/* These flags are kept in p_flags. */
111
#define        P_TRACED        0x00001                /* debugged process being traced. */
112

    
113
/*
114
 * Global variables.
115
 */
116
extern struct proc initproc;                /* process slot for init */
117
extern struct list allproc;                /* list of all processes */
118
extern struct proc *curproc;                /* current (caller) process */
119
extern int perrno;                        /* errno */
120

    
121
__BEGIN_DECLS
122

    
123
/* pid.c */
124
pid_t        sys_getpid(void);
125
pid_t        sys_getppid(void);
126
int        sys_getpgid(pid_t, pid_t *);
127
int        sys_setpgid(pid_t, pid_t);
128
int        sys_getsid(pid_t, pid_t *);
129
int        sys_setsid(pid_t *);
130

    
131
/* fork.c */
132
int        newproc(struct proc *, pid_t, task_t);
133
int        sys_fork(task_t, int, pid_t *);
134
void        cleanup(struct proc *);
135
void        vfork_end(struct proc *);
136

    
137
/* exit.c */
138
int        sys_exit(int);
139
int        stop(int);
140
int        sys_waitpid(pid_t, int *, int, pid_t *);
141

    
142
/* kill.c */
143
int        sys_kill(pid_t pid, int sig);
144
int        kill_pg(pid_t, int);
145

    
146
/* hash.c */
147
struct proc *p_find(pid_t);
148
struct pgrp *pg_find(pid_t);
149
struct proc *task_to_proc(task_t);
150
void        p_add(struct proc *);
151
void        p_remove(struct proc *);
152
void        pg_add(struct pgrp *);
153
void        pg_remove(struct pgrp *);
154
void        table_init(void);
155

    
156
/* tty.c */
157
void        tty_init(void);
158

    
159
__END_DECLS
160

    
161
#endif /* !_PROC_H */