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 <archconst.h>
26 #include <archtypes.h>
27 #include "../../kernel/const.h"
28 #include "../../kernel/config.h"
29 #include "../../kernel/type.h"
30 #include "../../kernel/proc.h"
32 #define munmap _munmap
33 #define munmap_text _munmap_text
38 /*===========================================================================*
40 *===========================================================================*/
41 PUBLIC pid_t
get_free_pid()
43 static pid_t next_pid
= INIT_PID
+ 1; /* next pid to be assigned */
44 register struct mproc
*rmp
; /* check process table */
45 int t
; /* zero if pid still free */
47 /* Find a free pid for the child and put it in the table. */
50 next_pid
= (next_pid
< NR_PIDS
? next_pid
+ 1 : INIT_PID
+ 1);
51 for (rmp
= &mproc
[0]; rmp
< &mproc
[NR_PROCS
]; rmp
++)
52 if (rmp
->mp_pid
== next_pid
|| rmp
->mp_procgrp
== next_pid
) {
56 } while (t
); /* 't' = 0 means pid free */
61 /*===========================================================================*
63 *===========================================================================*/
66 /* A system call number not implemented by PM has been requested. */
67 printf("PM: in no_sys, call nr %d from %d\n", call_nr
, who_e
);
71 /*===========================================================================*
73 *===========================================================================*/
74 PUBLIC
char *find_param(name
)
77 register const char *namep
;
80 for (envp
= (char *) monitor_params
; *envp
!= 0;) {
81 for (namep
= name
; *namep
!= 0 && *namep
== *envp
; namep
++, envp
++)
83 if (*namep
== '\0' && *envp
== '=')
91 /*===========================================================================*
93 *===========================================================================*/
94 PUBLIC
struct mproc
*find_proc(lpid
)
97 register struct mproc
*rmp
;
99 for (rmp
= &mproc
[0]; rmp
< &mproc
[NR_PROCS
]; rmp
++)
100 if ((rmp
->mp_flags
& IN_USE
) && rmp
->mp_pid
== lpid
)
106 /*===========================================================================*
108 *===========================================================================*/
109 PUBLIC
int pm_isokendpt(int endpoint
, int *proc
)
111 *proc
= _ENDPOINT_P(endpoint
);
112 if(*proc
< -NR_TASKS
|| *proc
>= NR_PROCS
)
114 if(*proc
>= 0 && endpoint
!= mproc
[*proc
].mp_endpoint
)
116 if(*proc
>= 0 && !(mproc
[*proc
].mp_flags
& IN_USE
))
121 /*===========================================================================*
123 *===========================================================================*/
124 PUBLIC
void tell_fs(rmp
, m_ptr
)
128 /* Send a request to VFS, without blocking.
132 if (rmp
->mp_flags
& FS_CALL
)
133 panic("tell_fs: not idle: %d", m_ptr
->m_type
);
135 r
= asynsend3(FS_PROC_NR
, m_ptr
, AMF_NOREPLY
);
137 panic("unable to send to FS: %d", r
);
139 rmp
->mp_flags
|= FS_CALL
;
144 PUBLIC
int munmap(void *addrstart
, vir_bytes len
)
149 return _munmap(addrstart
, len
);
152 PUBLIC
int munmap_text(void *addrstart
, vir_bytes len
)
157 return _munmap_text(addrstart
, len
);