Subversion Repositories shark

Rev

Rev 564 | Rev 590 | Go to most recent revision | 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
 ------------
567 giacomo 21
 CVS :        $Id: exchand.c,v 1.6 2004-04-18 20:18:21 giacomo Exp $
38 pj 22
 
23
 File:        $File$
567 giacomo 24
 Revision:    $Revision: 1.6 $
25
 Last update: $Date: 2004-04-18 20:18:21 $
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
 
83
static char shutdown_message_buffer[500];
84
static int myflag_shutdown = 0;
85
 
38 pj 86
/*
87
   This exception handler should be good for text applications that do NOT
88
   use graphics
89
*/
90
int set_default_exception_handler(void)
91
{
92
  struct sigaction action;
564 giacomo 93
  int i;
38 pj 94
 
95
  myflag = 0;
96
 
564 giacomo 97
  for(i=0;i<500;i++) shutdown_message_buffer[i] = 0;
98
 
38 pj 99
  sys_atrunlevel(theend, NULL, RUNLEVEL_AFTER_EXIT);
100
 
101
  /* Init the standard S.Ha.R.K. exception handler */
102
  action.sa_flags = SA_SIGINFO;            /* Set the signal action */
103
  action.sa_sigaction = thehandler;
104
  action.sa_handler = 0;
105
  sigfillset(&action.sa_mask); /* we block all the other signals... */
106
 
107
  return sigaction(SIGHEXC, &action, NULL); /* set the signal */
108
}
109
 
567 giacomo 110
int remove_default_exception_handler(void)
111
{
112
  struct sigaction action;
113
 
114
  action.sa_flags = SA_SIGINFO;
115
  action.sa_sigaction = NULL;
116
  action.sa_handler = SIG_IGN;
117
  sigfillset(&action.sa_mask);
118
 
119
  return sigaction(SIGHEXC, &action, NULL); /* set the signal */
120
}
121
 
157 pj 122
int sys_shutdown_message(char *fmt,...)
123
{
124
  va_list parms;
125
  int result = -1;
126
 
564 giacomo 127
  myflag_shutdown = 1;
128
  va_start(parms,fmt);
129
  result = vsprintf(shutdown_message_buffer+strlen(shutdown_message_buffer),fmt,parms);
130
  va_end(parms);
131
 
157 pj 132
  return(result);
564 giacomo 133
 
157 pj 134
}
135
 
38 pj 136
static void thehandler(int signo, siginfo_t *info, void *extra)
137
{
138
  if (!myflag) {
139
    myflag = 1;
140
    myinfo = *info;
141
    sys_gettime(&mytime),
142
    sys_abort(AHEXC);
143
  }
144
}
145
 
146
static void theend(void *arg)
147
{
445 giacomo 148
 
38 pj 149
  if (myflag) {
157 pj 150
    cprintf("S.Ha.R.K. Exception raised!!!\n");
151
    cprintf("Time (s:ns)     :%ld:%ld\n", mytime.tv_sec, mytime.tv_nsec);
152
    cprintf("Exception number:%d (%s)\n", myinfo.si_value.sival_int,
153
            _sys_exclist[myinfo.si_value.sival_int]);
154
    cprintf("PID             :%d (%s)\n", myinfo.si_task,
155
            proc_table[myinfo.si_task].name);
156
    cprintf("Avail time      : %d\n", proc_table[myinfo.si_task].avail_time);
445 giacomo 157
 
38 pj 158
  }
157 pj 159
  if (myflag_shutdown) {
160
    cprintf("\nShutdown message:\n%s\n", shutdown_message_buffer);
161
  }
162
 
38 pj 163
}
164
 
165
 
166