panic() cleanup.
[minix.git] / servers / pm / utility.c
blobf3058b3f62e3d01b6c551028f1ed78b709782297
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
12 #include "pm.h"
13 #include <sys/stat.h>
14 #include <minix/callnr.h>
15 #include <minix/com.h>
16 #include <minix/endpoint.h>
17 #include <fcntl.h>
18 #include <signal.h> /* needed only because mproc.h needs it */
19 #include "mproc.h"
20 #include "param.h"
22 #include <minix/config.h>
23 #include <timers.h>
24 #include <string.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
34 #include <sys/mman.h>
35 #undef munmap
36 #undef munmap_text
38 /*===========================================================================*
39 * get_free_pid *
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. */
48 do {
49 t = 0;
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) {
53 t = 1;
54 break;
56 } while (t); /* 't' = 0 means pid free */
57 return(next_pid);
61 /*===========================================================================*
62 * no_sys *
63 *===========================================================================*/
64 PUBLIC int no_sys()
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);
68 return(ENOSYS);
71 /*===========================================================================*
72 * find_param *
73 *===========================================================================*/
74 PUBLIC char *find_param(name)
75 const char *name;
77 register const char *namep;
78 register char *envp;
80 for (envp = (char *) monitor_params; *envp != 0;) {
81 for (namep = name; *namep != 0 && *namep == *envp; namep++, envp++)
83 if (*namep == '\0' && *envp == '=')
84 return(envp + 1);
85 while (*envp++ != 0)
88 return(NULL);
91 /*===========================================================================*
92 * find_proc *
93 *===========================================================================*/
94 PUBLIC struct mproc *find_proc(lpid)
95 pid_t 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)
101 return(rmp);
103 return(NIL_MPROC);
106 /*===========================================================================*
107 * pm_isokendpt *
108 *===========================================================================*/
109 PUBLIC int pm_isokendpt(int endpoint, int *proc)
111 *proc = _ENDPOINT_P(endpoint);
112 if(*proc < -NR_TASKS || *proc >= NR_PROCS)
113 return EINVAL;
114 if(*proc >= 0 && endpoint != mproc[*proc].mp_endpoint)
115 return EDEADSRCDST;
116 if(*proc >= 0 && !(mproc[*proc].mp_flags & IN_USE))
117 return EDEADSRCDST;
118 return OK;
121 /*===========================================================================*
122 * tell_fs *
123 *===========================================================================*/
124 PUBLIC void tell_fs(rmp, m_ptr)
125 struct mproc *rmp;
126 message *m_ptr;
128 /* Send a request to VFS, without blocking.
130 int r;
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);
136 if (r != OK)
137 panic("unable to send to FS: %d", r);
139 rmp->mp_flags |= FS_CALL;
142 int unmap_ok = 0;
144 PUBLIC int munmap(void *addrstart, vir_bytes len)
146 if(!unmap_ok)
147 return ENOSYS;
149 return _munmap(addrstart, len);
152 PUBLIC int munmap_text(void *addrstart, vir_bytes len)
154 if(!unmap_ok)
155 return ENOSYS;
157 return _munmap_text(addrstart, len);