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 * pm_isokendpt: check the validity of an endpoint
9 * tell_fs: send a request to FS on behalf of a process
14 #include <minix/callnr.h>
15 #include <minix/com.h>
16 #include <minix/endpoint.h>
18 #include <signal.h> /* needed only because mproc.h needs it */
22 #include <minix/config.h>
25 #include <machine/archtypes.h>
26 #include "kernel/const.h"
27 #include "kernel/config.h"
28 #include "kernel/type.h"
29 #include "kernel/proc.h"
31 #define munmap _munmap
32 #define munmap_text _munmap_text
37 /*===========================================================================*
39 *===========================================================================*/
40 PUBLIC pid_t
get_free_pid()
42 static pid_t next_pid
= INIT_PID
+ 1; /* next pid to be assigned */
43 register struct mproc
*rmp
; /* check process table */
44 int t
; /* zero if pid still free */
46 /* Find a free pid for the child and put it in the table. */
49 next_pid
= (next_pid
< NR_PIDS
? next_pid
+ 1 : INIT_PID
+ 1);
50 for (rmp
= &mproc
[0]; rmp
< &mproc
[NR_PROCS
]; rmp
++)
51 if (rmp
->mp_pid
== next_pid
|| rmp
->mp_procgrp
== next_pid
) {
55 } while (t
); /* 't' = 0 means pid free */
60 /*===========================================================================*
62 *===========================================================================*/
65 /* A system call number not implemented by PM has been requested. */
66 printf("PM: in no_sys, call nr %d from %d\n", call_nr
, who_e
);
70 /*===========================================================================*
72 *===========================================================================*/
73 PUBLIC
char *find_param(name
)
76 register const char *namep
;
79 for (envp
= (char *) monitor_params
; *envp
!= 0;) {
80 for (namep
= name
; *namep
!= 0 && *namep
== *envp
; namep
++, envp
++)
82 if (*namep
== '\0' && *envp
== '=')
90 /*===========================================================================*
92 *===========================================================================*/
93 PUBLIC
struct mproc
*find_proc(lpid
)
96 register struct mproc
*rmp
;
98 for (rmp
= &mproc
[0]; rmp
< &mproc
[NR_PROCS
]; rmp
++)
99 if ((rmp
->mp_flags
& IN_USE
) && rmp
->mp_pid
== lpid
)
105 /*===========================================================================*
107 *===========================================================================*/
108 PUBLIC
int pm_isokendpt(int endpoint
, int *proc
)
110 *proc
= _ENDPOINT_P(endpoint
);
111 if(*proc
< -NR_TASKS
|| *proc
>= NR_PROCS
)
113 if(*proc
>= 0 && endpoint
!= mproc
[*proc
].mp_endpoint
)
115 if(*proc
>= 0 && !(mproc
[*proc
].mp_flags
& IN_USE
))
120 /*===========================================================================*
122 *===========================================================================*/
123 PUBLIC
void tell_fs(rmp
, m_ptr
)
127 /* Send a request to VFS, without blocking.
131 if (rmp
->mp_flags
& FS_CALL
)
132 panic("tell_fs: not idle: %d", m_ptr
->m_type
);
134 r
= asynsend3(FS_PROC_NR
, m_ptr
, AMF_NOREPLY
);
136 panic("unable to send to FS: %d", r
);
138 rmp
->mp_flags
|= FS_CALL
;
143 PUBLIC
int munmap(void *addrstart
, vir_bytes len
)
148 return _munmap(addrstart
, len
);
151 PUBLIC
int munmap_text(void *addrstart
, vir_bytes len
)
156 return _munmap_text(addrstart
, len
);