1 /* This file contains some utility routines for PM.
3 * The entry points are:
4 * get_free_pid: get a free process or group id
5 * no_sys: called for invalid system call numbers
6 * find_param: look up a boot monitor parameter
7 * find_proc: return process pointer from pid number
8 * nice_to_priority convert nice level to priority queue
9 * pm_isokendpt: check the validity of an endpoint
10 * tell_vfs: send a request to VFS on behalf of a process
14 #include <sys/resource.h>
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 <machine/archtypes.h>
28 #include "kernel/const.h"
29 #include "kernel/config.h"
30 #include "kernel/type.h"
31 #include "kernel/proc.h"
33 /*===========================================================================*
35 *===========================================================================*/
38 static pid_t next_pid
= INIT_PID
+ 1; /* next pid to be assigned */
39 register struct mproc
*rmp
; /* check process table */
40 int t
; /* zero if pid still free */
42 /* Find a free pid for the child and put it in the table. */
45 next_pid
= (next_pid
< NR_PIDS
? next_pid
+ 1 : INIT_PID
+ 1);
46 for (rmp
= &mproc
[0]; rmp
< &mproc
[NR_PROCS
]; rmp
++)
47 if (rmp
->mp_pid
== next_pid
|| rmp
->mp_procgrp
== next_pid
) {
51 } while (t
); /* 't' = 0 means pid free */
56 /*===========================================================================*
58 *===========================================================================*/
61 /* A system call number not implemented by PM has been requested. */
65 /*===========================================================================*
67 *===========================================================================*/
68 char *find_param(name
)
71 register const char *namep
;
74 for (envp
= (char *) monitor_params
; *envp
!= 0;) {
75 for (namep
= name
; *namep
!= 0 && *namep
== *envp
; namep
++, envp
++)
77 if (*namep
== '\0' && *envp
== '=')
85 /*===========================================================================*
87 *===========================================================================*/
88 struct mproc
*find_proc(lpid
)
91 register struct mproc
*rmp
;
93 for (rmp
= &mproc
[0]; rmp
< &mproc
[NR_PROCS
]; rmp
++)
94 if ((rmp
->mp_flags
& IN_USE
) && rmp
->mp_pid
== lpid
)
100 /*===========================================================================*
102 *===========================================================================*/
103 int nice_to_priority(int nice
, unsigned* new_q
)
105 if (nice
< PRIO_MIN
|| nice
> PRIO_MAX
) return(EINVAL
);
107 *new_q
= MAX_USER_Q
+ (nice
-PRIO_MIN
) * (MIN_USER_Q
-MAX_USER_Q
+1) /
108 (PRIO_MAX
-PRIO_MIN
+1);
110 /* Neither of these should ever happen. */
111 if ((signed) *new_q
< MAX_USER_Q
) *new_q
= MAX_USER_Q
;
112 if (*new_q
> MIN_USER_Q
) *new_q
= MIN_USER_Q
;
117 /*===========================================================================*
119 *===========================================================================*/
120 int pm_isokendpt(int endpoint
, int *proc
)
122 *proc
= _ENDPOINT_P(endpoint
);
123 if(*proc
< -NR_TASKS
|| *proc
>= NR_PROCS
)
125 if(*proc
>= 0 && endpoint
!= mproc
[*proc
].mp_endpoint
)
127 if(*proc
>= 0 && !(mproc
[*proc
].mp_flags
& IN_USE
))
132 /*===========================================================================*
134 *===========================================================================*/
135 void tell_vfs(rmp
, m_ptr
)
139 /* Send a request to VFS, without blocking.
143 if (rmp
->mp_flags
& VFS_CALL
)
144 panic("tell_vfs: not idle: %d", m_ptr
->m_type
);
146 r
= asynsend3(VFS_PROC_NR
, m_ptr
, AMF_NOREPLY
);
148 panic("unable to send to VFS: %d", r
);
150 rmp
->mp_flags
|= VFS_CALL
;