1 /* This file contains some utility routines for PM.
3 * The entry points are:
4 * find_param: look up a boot monitor parameter
5 * get_free_pid: get a free process or group id
6 * allowed: see if an access is permitted
7 * no_sys: called for invalid system call numbers
8 * panic: PM has run aground of a fatal error
9 * get_mem_map: get memory map of given process
10 * get_stack_ptr: get stack pointer of given process
11 * proc_from_pid: return process pointer from pid number
16 #include <minix/callnr.h>
17 #include <minix/com.h>
18 #include <minix/endpoint.h>
20 #include <signal.h> /* needed only because mproc.h needs it */
24 #include <minix/config.h>
27 #include <archconst.h>
28 #include <archtypes.h>
29 #include "../../kernel/const.h"
30 #include "../../kernel/config.h"
31 #include "../../kernel/type.h"
32 #include "../../kernel/proc.h"
34 /*===========================================================================*
36 *===========================================================================*/
37 PUBLIC pid_t
get_free_pid()
39 static pid_t next_pid
= INIT_PID
+ 1; /* next pid to be assigned */
40 register struct mproc
*rmp
; /* check process table */
41 int t
; /* zero if pid still free */
43 /* Find a free pid for the child and put it in the table. */
46 next_pid
= (next_pid
< NR_PIDS
? next_pid
+ 1 : INIT_PID
+ 1);
47 for (rmp
= &mproc
[0]; rmp
< &mproc
[NR_PROCS
]; rmp
++)
48 if (rmp
->mp_pid
== next_pid
|| rmp
->mp_procgrp
== next_pid
) {
52 } while (t
); /* 't' = 0 means pid free */
57 /*===========================================================================*
59 *===========================================================================*/
62 /* A system call number not implemented by PM has been requested. */
63 printf("PM: in no_sys, call nr %d from %d\n", call_nr
, who_e
);
67 /*===========================================================================*
69 *===========================================================================*/
70 PUBLIC
void panic(who
, mess
, num
)
71 char *who
; /* who caused the panic */
72 char *mess
; /* panic message string */
73 int num
; /* number to go with it */
75 /* An unrecoverable error has occurred. Panics are caused when an internal
76 * inconsistency is detected, e.g., a programming error or illegal value of a
77 * defined constant. The process manager decides to exit.
79 printf("PM panic (%s): %s", who
, mess
);
80 if (num
!= NO_NUM
) printf(": %d",num
);
88 /*===========================================================================*
90 *===========================================================================*/
91 PUBLIC
char *find_param(name
)
94 register const char *namep
;
97 for (envp
= (char *) monitor_params
; *envp
!= 0;) {
98 for (namep
= name
; *namep
!= 0 && *namep
== *envp
; namep
++, envp
++)
100 if (*namep
== '\0' && *envp
== '=')
108 /*===========================================================================*
110 *===========================================================================*/
111 PUBLIC
int get_mem_map(proc_nr
, mem_map
)
112 int proc_nr
; /* process to get map of */
113 struct mem_map
*mem_map
; /* put memory map here */
118 if ((s
=sys_getproc(&p
, proc_nr
)) != OK
)
120 memcpy(mem_map
, p
.p_memmap
, sizeof(p
.p_memmap
));
124 /*===========================================================================*
126 *===========================================================================*/
127 PUBLIC
int get_stack_ptr(proc_nr_e
, sp
)
128 int proc_nr_e
; /* process to get sp of */
129 vir_bytes
*sp
; /* put stack pointer here */
134 if ((s
=sys_getproc(&p
, proc_nr_e
)) != OK
)
140 /*===========================================================================*
142 *===========================================================================*/
143 PUBLIC
int proc_from_pid(mp_pid
)
148 for (rmp
= 0; rmp
< NR_PROCS
; rmp
++)
149 if (mproc
[rmp
].mp_pid
== mp_pid
)
155 /*===========================================================================*
157 *===========================================================================*/
158 PUBLIC
int pm_isokendpt(int endpoint
, int *proc
)
160 *proc
= _ENDPOINT_P(endpoint
);
161 if(*proc
< -NR_TASKS
|| *proc
>= NR_PROCS
)
163 if(*proc
>= 0 && endpoint
!= mproc
[*proc
].mp_endpoint
)
165 if(*proc
>= 0 && !(mproc
[*proc
].mp_flags
& IN_USE
))