source: branches/minix3-book/servers/pm/signal.c@ 4

Last change on this file since 4 was 4, checked in by Mattia Monga, 13 years ago

Importazione sorgenti libro

File size: 21.7 KB
Line 
1/* This file handles signals, which are asynchronous events and are generally
2 * a messy and unpleasant business. Signals can be generated by the KILL
3 * system call, or from the keyboard (SIGINT) or from the clock (SIGALRM).
4 * In all cases control eventually passes to check_sig() to see which processes
5 * can be signaled. The actual signaling is done by sig_proc().
6 *
7 * The entry points into this file are:
8 * do_sigaction: perform the SIGACTION system call
9 * do_sigpending: perform the SIGPENDING system call
10 * do_sigprocmask: perform the SIGPROCMASK system call
11 * do_sigreturn: perform the SIGRETURN system call
12 * do_sigsuspend: perform the SIGSUSPEND system call
13 * do_kill: perform the KILL system call
14 * do_alarm: perform the ALARM system call by calling set_alarm()
15 * set_alarm: tell the clock task to start or stop a timer
16 * do_pause: perform the PAUSE system call
17 * ksig_pending: the kernel notified about pending signals
18 * sig_proc: interrupt or terminate a signaled process
19 * check_sig: check which processes to signal with sig_proc()
20 * check_pending: check if a pending signal can now be delivered
21 */
22
23#include "pm.h"
24#include <sys/stat.h>
25#include <sys/ptrace.h>
26#include <minix/callnr.h>
27#include <minix/com.h>
28#include <signal.h>
29#include <sys/sigcontext.h>
30#include <string.h>
31#include "mproc.h"
32#include "param.h"
33
34#define CORE_MODE 0777 /* mode to use on core image files */
35#define DUMPED 0200 /* bit set in status when core dumped */
36
37FORWARD _PROTOTYPE( void dump_core, (struct mproc *rmp) );
38FORWARD _PROTOTYPE( void unpause, (int pro) );
39FORWARD _PROTOTYPE( void handle_sig, (int proc_nr, sigset_t sig_map) );
40FORWARD _PROTOTYPE( void cause_sigalrm, (struct timer *tp) );
41
42/*===========================================================================*
43 * do_sigaction *
44 *===========================================================================*/
45PUBLIC int do_sigaction()
46{
47 int r;
48 struct sigaction svec;
49 struct sigaction *svp;
50
51 if (m_in.sig_nr == SIGKILL) return(OK);
52 if (m_in.sig_nr < 1 || m_in.sig_nr > _NSIG) return (EINVAL);
53 svp = &mp->mp_sigact[m_in.sig_nr];
54 if ((struct sigaction *) m_in.sig_osa != (struct sigaction *) NULL) {
55 r = sys_datacopy(PM_PROC_NR,(vir_bytes) svp,
56 who, (vir_bytes) m_in.sig_osa, (phys_bytes) sizeof(svec));
57 if (r != OK) return(r);
58 }
59
60 if ((struct sigaction *) m_in.sig_nsa == (struct sigaction *) NULL)
61 return(OK);
62
63 /* Read in the sigaction structure. */
64 r = sys_datacopy(who, (vir_bytes) m_in.sig_nsa,
65 PM_PROC_NR, (vir_bytes) &svec, (phys_bytes) sizeof(svec));
66 if (r != OK) return(r);
67
68 if (svec.sa_handler == SIG_IGN) {
69 sigaddset(&mp->mp_ignore, m_in.sig_nr);
70 sigdelset(&mp->mp_sigpending, m_in.sig_nr);
71 sigdelset(&mp->mp_catch, m_in.sig_nr);
72 sigdelset(&mp->mp_sig2mess, m_in.sig_nr);
73 } else if (svec.sa_handler == SIG_DFL) {
74 sigdelset(&mp->mp_ignore, m_in.sig_nr);
75 sigdelset(&mp->mp_catch, m_in.sig_nr);
76 sigdelset(&mp->mp_sig2mess, m_in.sig_nr);
77 } else if (svec.sa_handler == SIG_MESS) {
78 if (! (mp->mp_flags & PRIV_PROC)) return(EPERM);
79 sigdelset(&mp->mp_ignore, m_in.sig_nr);
80 sigaddset(&mp->mp_sig2mess, m_in.sig_nr);
81 sigdelset(&mp->mp_catch, m_in.sig_nr);
82 } else {
83 sigdelset(&mp->mp_ignore, m_in.sig_nr);
84 sigaddset(&mp->mp_catch, m_in.sig_nr);
85 sigdelset(&mp->mp_sig2mess, m_in.sig_nr);
86 }
87 mp->mp_sigact[m_in.sig_nr].sa_handler = svec.sa_handler;
88 sigdelset(&svec.sa_mask, SIGKILL);
89 mp->mp_sigact[m_in.sig_nr].sa_mask = svec.sa_mask;
90 mp->mp_sigact[m_in.sig_nr].sa_flags = svec.sa_flags;
91 mp->mp_sigreturn = (vir_bytes) m_in.sig_ret;
92 return(OK);
93}
94
95/*===========================================================================*
96 * do_sigpending *
97 *===========================================================================*/
98PUBLIC int do_sigpending()
99{
100 mp->mp_reply.reply_mask = (long) mp->mp_sigpending;
101 return OK;
102}
103
104/*===========================================================================*
105 * do_sigprocmask *
106 *===========================================================================*/
107PUBLIC int do_sigprocmask()
108{
109/* Note that the library interface passes the actual mask in sigmask_set,
110 * not a pointer to the mask, in order to save a copy. Similarly,
111 * the old mask is placed in the return message which the library
112 * interface copies (if requested) to the user specified address.
113 *
114 * The library interface must set SIG_INQUIRE if the 'act' argument
115 * is NULL.
116 */
117
118 int i;
119
120 mp->mp_reply.reply_mask = (long) mp->mp_sigmask;
121
122 switch (m_in.sig_how) {
123 case SIG_BLOCK:
124 sigdelset((sigset_t *)&m_in.sig_set, SIGKILL);
125 for (i = 1; i <= _NSIG; i++) {
126 if (sigismember((sigset_t *)&m_in.sig_set, i))
127 sigaddset(&mp->mp_sigmask, i);
128 }
129 break;
130
131 case SIG_UNBLOCK:
132 for (i = 1; i <= _NSIG; i++) {
133 if (sigismember((sigset_t *)&m_in.sig_set, i))
134 sigdelset(&mp->mp_sigmask, i);
135 }
136 check_pending(mp);
137 break;
138
139 case SIG_SETMASK:
140 sigdelset((sigset_t *) &m_in.sig_set, SIGKILL);
141 mp->mp_sigmask = (sigset_t) m_in.sig_set;
142 check_pending(mp);
143 break;
144
145 case SIG_INQUIRE:
146 break;
147
148 default:
149 return(EINVAL);
150 break;
151 }
152 return OK;
153}
154
155/*===========================================================================*
156 * do_sigsuspend *
157 *===========================================================================*/
158PUBLIC int do_sigsuspend()
159{
160 mp->mp_sigmask2 = mp->mp_sigmask; /* save the old mask */
161 mp->mp_sigmask = (sigset_t) m_in.sig_set;
162 sigdelset(&mp->mp_sigmask, SIGKILL);
163 mp->mp_flags |= SIGSUSPENDED;
164 check_pending(mp);
165 return(SUSPEND);
166}
167
168/*===========================================================================*
169 * do_sigreturn *
170 *===========================================================================*/
171PUBLIC int do_sigreturn()
172{
173/* A user signal handler is done. Restore context and check for
174 * pending unblocked signals.
175 */
176
177 int r;
178
179 mp->mp_sigmask = (sigset_t) m_in.sig_set;
180 sigdelset(&mp->mp_sigmask, SIGKILL);
181
182 r = sys_sigreturn(who, (struct sigmsg *) m_in.sig_context);
183 check_pending(mp);
184 return(r);
185}
186
187/*===========================================================================*
188 * do_kill *
189 *===========================================================================*/
190PUBLIC int do_kill()
191{
192/* Perform the kill(pid, signo) system call. */
193
194 return check_sig(m_in.pid, m_in.sig_nr);
195}
196
197/*===========================================================================*
198 * ksig_pending *
199 *===========================================================================*/
200PUBLIC int ksig_pending()
201{
202/* Certain signals, such as segmentation violations originate in the kernel.
203 * When the kernel detects such signals, it notifies the PM to take further
204 * action. The PM requests the kernel to send messages with the process
205 * slot and bit map for all signaled processes. The File System, for example,
206 * uses this mechanism to signal writing on broken pipes (SIGPIPE).
207 *
208 * The kernel has notified the PM about pending signals. Request pending
209 * signals until all signals are handled. If there are no more signals,
210 * NONE is returned in the process number field.
211 */
212 int proc_nr;
213 sigset_t sig_map;
214
215 while (TRUE) {
216 sys_getksig(&proc_nr, &sig_map); /* get an arbitrary pending signal */
217 if (NONE == proc_nr) { /* stop if no more pending signals */
218 break;
219 } else {
220 handle_sig(proc_nr, sig_map); /* handle the received signal */
221 sys_endksig(proc_nr); /* tell kernel it's done */
222 }
223 }
224 return(SUSPEND); /* prevents sending reply */
225}
226
227/*===========================================================================*
228 * handle_sig *
229 *===========================================================================*/
230PRIVATE void handle_sig(proc_nr, sig_map)
231int proc_nr;
232sigset_t sig_map;
233{
234 register struct mproc *rmp;
235 int i;
236 pid_t proc_id, id;
237
238 rmp = &mproc[proc_nr];
239 if ((rmp->mp_flags & (IN_USE | ZOMBIE)) != IN_USE) return;
240 proc_id = rmp->mp_pid;
241 mp = &mproc[0]; /* pretend signals are from PM */
242 mp->mp_procgrp = rmp->mp_procgrp; /* get process group right */
243
244 /* Check each bit in turn to see if a signal is to be sent. Unlike
245 * kill(), the kernel may collect several unrelated signals for a
246 * process and pass them to PM in one blow. Thus loop on the bit
247 * map. For SIGINT and SIGQUIT, use proc_id 0 to indicate a broadcast
248 * to the recipient's process group. For SIGKILL, use proc_id -1 to
249 * indicate a systemwide broadcast.
250 */
251 for (i = 1; i <= _NSIG; i++) {
252 if (!sigismember(&sig_map, i)) continue;
253 switch (i) {
254 case SIGINT:
255 case SIGQUIT:
256 id = 0; break; /* broadcast to process group */
257 case SIGKILL:
258 id = -1; break; /* broadcast to all except INIT */
259 default:
260 id = proc_id;
261 break;
262 }
263 check_sig(id, i);
264 }
265}
266
267/*===========================================================================*
268 * do_alarm *
269 *===========================================================================*/
270PUBLIC int do_alarm()
271{
272/* Perform the alarm(seconds) system call. */
273 return(set_alarm(who, m_in.seconds));
274}
275
276/*===========================================================================*
277 * set_alarm *
278 *===========================================================================*/
279PUBLIC int set_alarm(proc_nr, sec)
280int proc_nr; /* process that wants the alarm */
281int sec; /* how many seconds delay before the signal */
282{
283/* This routine is used by do_alarm() to set the alarm timer. It is also used
284 * to turn the timer off when a process exits with the timer still on.
285 */
286 clock_t ticks; /* number of ticks for alarm */
287 clock_t exptime; /* needed for remaining time on previous alarm */
288 clock_t uptime; /* current system time */
289 int remaining; /* previous time left in seconds */
290 int s;
291
292 /* First determine remaining time of previous alarm, if set. */
293 if (mproc[proc_nr].mp_flags & ALARM_ON) {
294 if ( (s=getuptime(&uptime)) != OK)
295 panic(__FILE__,"set_alarm couldn't get uptime", s);
296 exptime = *tmr_exp_time(&mproc[proc_nr].mp_timer);
297 remaining = (int) ((exptime - uptime + (HZ-1))/HZ);
298 if (remaining < 0) remaining = 0;
299 } else {
300 remaining = 0;
301 }
302
303 /* Tell the clock task to provide a signal message when the time comes.
304 *
305 * Large delays cause a lot of problems. First, the alarm system call
306 * takes an unsigned seconds count and the library has cast it to an int.
307 * That probably works, but on return the library will convert "negative"
308 * unsigneds to errors. Presumably no one checks for these errors, so
309 * force this call through. Second, If unsigned and long have the same
310 * size, converting from seconds to ticks can easily overflow. Finally,
311 * the kernel has similar overflow bugs adding ticks.
312 *
313 * Fixing this requires a lot of ugly casts to fit the wrong interface
314 * types and to avoid overflow traps. ALRM_EXP_TIME has the right type
315 * (clock_t) although it is declared as long. How can variables like
316 * this be declared properly without combinatorial explosion of message
317 * types?
318 */
319 ticks = (clock_t) (HZ * (unsigned long) (unsigned) sec);
320 if ( (unsigned long) ticks / HZ != (unsigned) sec)
321 ticks = LONG_MAX; /* eternity (really TMR_NEVER) */
322
323 if (ticks != 0) {
324 pm_set_timer(&mproc[proc_nr].mp_timer, ticks, cause_sigalrm, proc_nr);
325 mproc[proc_nr].mp_flags |= ALARM_ON;
326 } else if (mproc[proc_nr].mp_flags & ALARM_ON) {
327 pm_cancel_timer(&mproc[proc_nr].mp_timer);
328 mproc[proc_nr].mp_flags &= ~ALARM_ON;
329 }
330 return(remaining);
331}
332
333/*===========================================================================*
334 * cause_sigalrm *
335 *===========================================================================*/
336PRIVATE void cause_sigalrm(tp)
337struct timer *tp;
338{
339 int proc_nr;
340 register struct mproc *rmp;
341
342 proc_nr = tmr_arg(tp)->ta_int; /* get process from timer */
343 rmp = &mproc[proc_nr];
344
345 if ((rmp->mp_flags & (IN_USE | ZOMBIE)) != IN_USE) return;
346 if ((rmp->mp_flags & ALARM_ON) == 0) return;
347 rmp->mp_flags &= ~ALARM_ON;
348 check_sig(rmp->mp_pid, SIGALRM);
349}
350
351/*===========================================================================*
352 * do_pause *
353 *===========================================================================*/
354PUBLIC int do_pause()
355{
356/* Perform the pause() system call. */
357
358 mp->mp_flags |= PAUSED;
359 return(SUSPEND);
360}
361
362/*===========================================================================*
363 * sig_proc *
364 *===========================================================================*/
365PUBLIC void sig_proc(rmp, signo)
366register struct mproc *rmp; /* pointer to the process to be signaled */
367int signo; /* signal to send to process (1 to _NSIG) */
368{
369/* Send a signal to a process. Check to see if the signal is to be caught,
370 * ignored, tranformed into a message (for system processes) or blocked.
371 * - If the signal is to be transformed into a message, request the KERNEL to
372 * send the target process a system notification with the pending signal as an
373 * argument.
374 * - If the signal is to be caught, request the KERNEL to push a sigcontext
375 * structure and a sigframe structure onto the catcher's stack. Also, KERNEL
376 * will reset the program counter and stack pointer, so that when the process
377 * next runs, it will be executing the signal handler. When the signal handler
378 * returns, sigreturn(2) will be called. Then KERNEL will restore the signal
379 * context from the sigcontext structure.
380 * If there is insufficient stack space, kill the process.
381 */
382
383 vir_bytes new_sp;
384 int s;
385 int slot;
386 int sigflags;
387 struct sigmsg sm;
388
389 slot = (int) (rmp - mproc);
390 if ((rmp->mp_flags & (IN_USE | ZOMBIE)) != IN_USE) {
391 printf("PM: signal %d sent to %s process %d\n",
392 signo, (rmp->mp_flags & ZOMBIE) ? "zombie" : "dead", slot);
393 panic(__FILE__,"", NO_NUM);
394 }
395 if ((rmp->mp_flags & TRACED) && signo != SIGKILL) {
396 /* A traced process has special handling. */
397 unpause(slot);
398 stop_proc(rmp, signo); /* a signal causes it to stop */
399 return;
400 }
401 /* Some signals are ignored by default. */
402 if (sigismember(&rmp->mp_ignore, signo)) {
403 return;
404 }
405 if (sigismember(&rmp->mp_sigmask, signo)) {
406 /* Signal should be blocked. */
407 sigaddset(&rmp->mp_sigpending, signo);
408 return;
409 }
410 sigflags = rmp->mp_sigact[signo].sa_flags;
411 if (sigismember(&rmp->mp_catch, signo)) {
412 if (rmp->mp_flags & SIGSUSPENDED)
413 sm.sm_mask = rmp->mp_sigmask2;
414 else
415 sm.sm_mask = rmp->mp_sigmask;
416 sm.sm_signo = signo;
417 sm.sm_sighandler = (vir_bytes) rmp->mp_sigact[signo].sa_handler;
418 sm.sm_sigreturn = rmp->mp_sigreturn;
419 if ((s=get_stack_ptr(slot, &new_sp)) != OK)
420 panic(__FILE__,"couldn't get new stack pointer",s);
421 sm.sm_stkptr = new_sp;
422
423 /* Make room for the sigcontext and sigframe struct. */
424 new_sp -= sizeof(struct sigcontext)
425 + 3 * sizeof(char *) + 2 * sizeof(int);
426
427 if (adjust(rmp, rmp->mp_seg[D].mem_len, new_sp) != OK)
428 goto doterminate;
429
430 rmp->mp_sigmask |= rmp->mp_sigact[signo].sa_mask;
431 if (sigflags & SA_NODEFER)
432 sigdelset(&rmp->mp_sigmask, signo);
433 else
434 sigaddset(&rmp->mp_sigmask, signo);
435
436 if (sigflags & SA_RESETHAND) {
437 sigdelset(&rmp->mp_catch, signo);
438 rmp->mp_sigact[signo].sa_handler = SIG_DFL;
439 }
440
441 if (OK == (s=sys_sigsend(slot, &sm))) {
442
443 sigdelset(&rmp->mp_sigpending, signo);
444 /* If process is hanging on PAUSE, WAIT, SIGSUSPEND, tty,
445 * pipe, etc., release it.
446 */
447 unpause(slot);
448 return;
449 }
450 panic(__FILE__, "warning, sys_sigsend failed", s);
451 }
452 else if (sigismember(&rmp->mp_sig2mess, signo)) {
453 if (OK != (s=sys_kill(slot,signo)))
454 panic(__FILE__, "warning, sys_kill failed", s);
455 return;
456 }
457
458doterminate:
459 /* Signal should not or cannot be caught. Take default action. */
460 if (sigismember(&ign_sset, signo)) return;
461
462 rmp->mp_sigstatus = (char) signo;
463 if (sigismember(&core_sset, signo)) {
464 /* Switch to the user's FS environment and dump core. */
465 tell_fs(CHDIR, slot, FALSE, 0);
466 dump_core(rmp);
467 }
468 pm_exit(rmp, 0); /* terminate process */
469}
470
471/*===========================================================================*
472 * check_sig *
473 *===========================================================================*/
474PUBLIC int check_sig(proc_id, signo)
475pid_t proc_id; /* pid of proc to sig, or 0 or -1, or -pgrp */
476int signo; /* signal to send to process (0 to _NSIG) */
477{
478/* Check to see if it is possible to send a signal. The signal may have to be
479 * sent to a group of processes. This routine is invoked by the KILL system
480 * call, and also when the kernel catches a DEL or other signal.
481 */
482
483 register struct mproc *rmp;
484 int count; /* count # of signals sent */
485 int error_code;
486
487 if (signo < 0 || signo > _NSIG) return(EINVAL);
488
489 /* Return EINVAL for attempts to send SIGKILL to INIT alone. */
490 if (proc_id == INIT_PID && signo == SIGKILL) return(EINVAL);
491
492 /* Search the proc table for processes to signal. (See forkexit.c about
493 * pid magic.)
494 */
495 count = 0;
496 error_code = ESRCH;
497 for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
498 if (!(rmp->mp_flags & IN_USE)) continue;
499 if ((rmp->mp_flags & ZOMBIE) && signo != 0) continue;
500
501 /* Check for selection. */
502 if (proc_id > 0 && proc_id != rmp->mp_pid) continue;
503 if (proc_id == 0 && mp->mp_procgrp != rmp->mp_procgrp) continue;
504 if (proc_id == -1 && rmp->mp_pid <= INIT_PID) continue;
505 if (proc_id < -1 && rmp->mp_procgrp != -proc_id) continue;
506
507 /* Check for permission. */
508 if (mp->mp_effuid != SUPER_USER
509 && mp->mp_realuid != rmp->mp_realuid
510 && mp->mp_effuid != rmp->mp_realuid
511 && mp->mp_realuid != rmp->mp_effuid
512 && mp->mp_effuid != rmp->mp_effuid) {
513 error_code = EPERM;
514 continue;
515 }
516
517 count++;
518 if (signo == 0) continue;
519
520 /* 'sig_proc' will handle the disposition of the signal. The
521 * signal may be caught, blocked, ignored, or cause process
522 * termination, possibly with core dump.
523 */
524 sig_proc(rmp, signo);
525
526 if (proc_id > 0) break; /* only one process being signaled */
527 }
528
529 /* If the calling process has killed itself, don't reply. */
530 if ((mp->mp_flags & (IN_USE | ZOMBIE)) != IN_USE) return(SUSPEND);
531 return(count > 0 ? OK : error_code);
532}
533
534/*===========================================================================*
535 * check_pending *
536 *===========================================================================*/
537PUBLIC void check_pending(rmp)
538register struct mproc *rmp;
539{
540 /* Check to see if any pending signals have been unblocked. The
541 * first such signal found is delivered.
542 *
543 * If multiple pending unmasked signals are found, they will be
544 * delivered sequentially.
545 *
546 * There are several places in this file where the signal mask is
547 * changed. At each such place, check_pending() should be called to
548 * check for newly unblocked signals.
549 */
550
551 int i;
552
553 for (i = 1; i <= _NSIG; i++) {
554 if (sigismember(&rmp->mp_sigpending, i) &&
555 !sigismember(&rmp->mp_sigmask, i)) {
556 sigdelset(&rmp->mp_sigpending, i);
557 sig_proc(rmp, i);
558 break;
559 }
560 }
561}
562
563/*===========================================================================*
564 * unpause *
565 *===========================================================================*/
566PRIVATE void unpause(pro)
567int pro; /* which process number */
568{
569/* A signal is to be sent to a process. If that process is hanging on a
570 * system call, the system call must be terminated with EINTR. Possible
571 * calls are PAUSE, WAIT, READ and WRITE, the latter two for pipes and ttys.
572 * First check if the process is hanging on an PM call. If not, tell FS,
573 * so it can check for READs and WRITEs from pipes, ttys and the like.
574 */
575
576 register struct mproc *rmp;
577
578 rmp = &mproc[pro];
579
580 /* Check to see if process is hanging on a PAUSE, WAIT or SIGSUSPEND call. */
581 if (rmp->mp_flags & (PAUSED | WAITING | SIGSUSPENDED)) {
582 rmp->mp_flags &= ~(PAUSED | WAITING | SIGSUSPENDED);
583 setreply(pro, EINTR);
584 return;
585 }
586
587 /* Process is not hanging on an PM call. Ask FS to take a look. */
588 tell_fs(UNPAUSE, pro, 0, 0);
589}
590
591/*===========================================================================*
592 * dump_core *
593 *===========================================================================*/
594PRIVATE void dump_core(rmp)
595register struct mproc *rmp; /* whose core is to be dumped */
596{
597/* Make a core dump on the file "core", if possible. */
598
599 int s, fd, seg, slot;
600 vir_bytes current_sp;
601 long trace_data, trace_off;
602
603 slot = (int) (rmp - mproc);
604
605 /* Can core file be written? We are operating in the user's FS environment,
606 * so no special permission checks are needed.
607 */
608 if (rmp->mp_realuid != rmp->mp_effuid) return;
609 if ( (fd = open(core_name, O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK,
610 CORE_MODE)) < 0) return;
611 rmp->mp_sigstatus |= DUMPED;
612
613 /* Make sure the stack segment is up to date.
614 * We don't want adjust() to fail unless current_sp is preposterous,
615 * but it might fail due to safety checking. Also, we don't really want
616 * the adjust() for sending a signal to fail due to safety checking.
617 * Maybe make SAFETY_BYTES a parameter.
618 */
619 if ((s=get_stack_ptr(slot, &current_sp)) != OK)
620 panic(__FILE__,"couldn't get new stack pointer",s);
621 adjust(rmp, rmp->mp_seg[D].mem_len, current_sp);
622
623 /* Write the memory map of all segments to begin the core file. */
624 if (write(fd, (char *) rmp->mp_seg, (unsigned) sizeof rmp->mp_seg)
625 != (unsigned) sizeof rmp->mp_seg) {
626 close(fd);
627 return;
628 }
629
630 /* Write out the whole kernel process table entry to get the regs. */
631 trace_off = 0;
632 while (sys_trace(T_GETUSER, slot, trace_off, &trace_data) == OK) {
633 if (write(fd, (char *) &trace_data, (unsigned) sizeof (long))
634 != (unsigned) sizeof (long)) {
635 close(fd);
636 return;
637 }
638 trace_off += sizeof (long);
639 }
640
641 /* Loop through segments and write the segments themselves out. */
642 for (seg = 0; seg < NR_LOCAL_SEGS; seg++) {
643 rw_seg(1, fd, slot, seg,
644 (phys_bytes) rmp->mp_seg[seg].mem_len << CLICK_SHIFT);
645 }
646 close(fd);
647}
648
Note: See TracBrowser for help on using the repository browser.