Rev 920 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
38 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | ------------ |
||
920 | pj | 21 | CVS : $Id: exchand.c,v 1.9 2005-01-08 14:48:59 pj Exp $ |
38 | pj | 22 | |
23 | File: $File$ |
||
920 | pj | 24 | Revision: $Revision: 1.9 $ |
25 | Last update: $Date: 2005-01-08 14:48:59 $ |
||
38 | pj | 26 | ------------ |
27 | **/ |
||
28 | |||
29 | /* |
||
157 | pj | 30 | * Copyright (C) 2000-2003 Paolo Gai |
38 | pj | 31 | * |
32 | * This program is free software; you can redistribute it and/or modify |
||
33 | * it under the terms of the GNU General Public License as published by |
||
34 | * the Free Software Foundation; either version 2 of the License, or |
||
35 | * (at your option) any later version. |
||
36 | * |
||
37 | * This program is distributed in the hope that it will be useful, |
||
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
40 | * GNU General Public License for more details. |
||
41 | * |
||
42 | * You should have received a copy of the GNU General Public License |
||
43 | * along with this program; if not, write to the Free Software |
||
44 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
45 | * |
||
46 | */ |
||
47 | |||
48 | #include <kernel/kern.h> |
||
445 | giacomo | 49 | #include <stdlib.h> |
564 | giacomo | 50 | #include <string.h> |
445 | giacomo | 51 | #include <tracer.h> |
38 | pj | 52 | |
53 | static int myflag; |
||
54 | static siginfo_t myinfo; |
||
55 | static struct timespec mytime; |
||
56 | |||
57 | static void thehandler(int signo, siginfo_t *info, void *extra); |
||
58 | static void theend(void *arg); |
||
59 | |||
157 | pj | 60 | const char *const _sys_exclist[] = { |
61 | "not used", |
||
62 | "not used", |
||
63 | "invalid kill of a task with a shadow pointer set", /* 2 */ |
||
64 | "cleanup push: no more cleanups handlers", |
||
65 | "invalid operation for a task", |
||
66 | "not used", |
||
67 | "no more OSLib events posted (see oslib/kl/event.c)", |
||
68 | "deadline miss", |
||
69 | "wcet violation", |
||
70 | "task activated at a wrong time (too early?)", |
||
71 | "mutex owner killed", /* 10 */ |
||
72 | "SRP: invalid lock", |
||
73 | "Dummy task: invalid operation", |
||
74 | "Sporadic Server: invalid replenishment", |
||
75 | "ARP: table full", |
||
76 | "Netbuff: init", |
||
77 | "Netbuff: get", |
||
78 | "Netbuff: already free", |
||
79 | "Netbuff: release", |
||
80 | "UDP: Bad checksum" |
||
81 | }; |
||
82 | |||
590 | giacomo | 83 | #define SHUTDOWN_BUFFER 1000 |
84 | |||
85 | static char shutdown_message_buffer[SHUTDOWN_BUFFER]; |
||
157 | pj | 86 | static int myflag_shutdown = 0; |
87 | |||
38 | pj | 88 | /* |
89 | This exception handler should be good for text applications that do NOT |
||
90 | use graphics |
||
91 | */ |
||
92 | int set_default_exception_handler(void) |
||
93 | { |
||
94 | struct sigaction action; |
||
564 | giacomo | 95 | int i; |
38 | pj | 96 | |
97 | myflag = 0; |
||
98 | |||
590 | giacomo | 99 | for(i=0;i<SHUTDOWN_BUFFER;i++) shutdown_message_buffer[i] = 0; |
564 | giacomo | 100 | |
38 | pj | 101 | sys_atrunlevel(theend, NULL, RUNLEVEL_AFTER_EXIT); |
102 | |||
103 | /* Init the standard S.Ha.R.K. exception handler */ |
||
104 | action.sa_flags = SA_SIGINFO; /* Set the signal action */ |
||
105 | action.sa_sigaction = thehandler; |
||
106 | action.sa_handler = 0; |
||
107 | sigfillset(&action.sa_mask); /* we block all the other signals... */ |
||
108 | |||
109 | return sigaction(SIGHEXC, &action, NULL); /* set the signal */ |
||
110 | } |
||
111 | |||
567 | giacomo | 112 | int remove_default_exception_handler(void) |
113 | { |
||
114 | struct sigaction action; |
||
115 | |||
596 | giacomo | 116 | action.sa_flags = 0; |
567 | giacomo | 117 | action.sa_sigaction = NULL; |
118 | action.sa_handler = SIG_IGN; |
||
119 | sigfillset(&action.sa_mask); |
||
120 | |||
121 | return sigaction(SIGHEXC, &action, NULL); /* set the signal */ |
||
122 | } |
||
123 | |||
157 | pj | 124 | int sys_shutdown_message(char *fmt,...) |
125 | { |
||
590 | giacomo | 126 | char temp[100]; |
157 | pj | 127 | va_list parms; |
128 | int result = -1; |
||
129 | |||
564 | giacomo | 130 | myflag_shutdown = 1; |
131 | va_start(parms,fmt); |
||
590 | giacomo | 132 | result = vsprintf(temp,fmt,parms); |
564 | giacomo | 133 | va_end(parms); |
590 | giacomo | 134 | |
135 | if ((strlen(shutdown_message_buffer) + strlen(temp)) < SHUTDOWN_BUFFER) |
||
136 | strcat(shutdown_message_buffer,temp); |
||
564 | giacomo | 137 | |
157 | pj | 138 | return(result); |
564 | giacomo | 139 | |
157 | pj | 140 | } |
141 | |||
38 | pj | 142 | static void thehandler(int signo, siginfo_t *info, void *extra) |
143 | { |
||
144 | if (!myflag) { |
||
145 | myflag = 1; |
||
146 | myinfo = *info; |
||
147 | sys_gettime(&mytime), |
||
920 | pj | 148 | exit(AHEXC); |
38 | pj | 149 | } |
150 | } |
||
151 | |||
152 | static void theend(void *arg) |
||
153 | { |
||
445 | giacomo | 154 | |
38 | pj | 155 | if (myflag) { |
157 | pj | 156 | cprintf("S.Ha.R.K. Exception raised!!!\n"); |
157 | cprintf("Time (s:ns) :%ld:%ld\n", mytime.tv_sec, mytime.tv_nsec); |
||
158 | cprintf("Exception number:%d (%s)\n", myinfo.si_value.sival_int, |
||
159 | _sys_exclist[myinfo.si_value.sival_int]); |
||
160 | cprintf("PID :%d (%s)\n", myinfo.si_task, |
||
161 | proc_table[myinfo.si_task].name); |
||
162 | cprintf("Avail time : %d\n", proc_table[myinfo.si_task].avail_time); |
||
445 | giacomo | 163 | |
38 | pj | 164 | } |
157 | pj | 165 | if (myflag_shutdown) { |
166 | cprintf("\nShutdown message:\n%s\n", shutdown_message_buffer); |
||
167 | } |
||
168 | |||
38 | pj | 169 | } |
170 | |||
171 | |||
172 |