]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/server/src/fault_handlers/trap_limit.cc
update
[l4.git] / l4 / pkg / plr / server / src / fault_handlers / trap_limit.cc
1 /*
2  * trap_limit.cc --
3  *
4  *      Observer counting traps and terminating the
5  *      application after a specified amount of calls.
6  *
7  * (c) 2012-2013 Björn Döbel <doebel@os.inf.tu-dresden.de>,
8  *     economic rights: Technische Universität Dresden (Germany)
9  * This file is part of TUD:OS and distributed under the terms of the
10  * GNU General Public License 2.
11  * Please see the COPYING-GPL-2 file for details.
12  */
13
14 #include "../app_loading"
15 #include "observers.h"
16
17 namespace Romain
18 {
19 class TrapLimitObserver_priv : public TrapLimitObserver
20 {
21         int _limit;
22         int _callcount;
23
24         bool limitIsValid() { return _limit != -1; }
25         int  count()        { return _callcount; }
26         int  limit()        { return _limit; }
27         void increment()    { ++_callcount; }
28
29         public:
30                 TrapLimitObserver_priv()
31                         : _callcount(0)
32                 {
33                         _limit = ConfigIntValue("general:max_traps");
34                         INFO() << "Limit: " << _limit;
35                 }
36
37                 DECLARE_OBSERVER("trap_limit");
38 };
39 }
40
41 DEFINE_EMPTY_STARTUP(TrapLimitObserver_priv)
42
43 void Romain::TrapLimitObserver_priv::status() const
44 {
45         switch(_limit) {
46                 case -1:
47                         break;
48                 default:
49                         INFO() << "Trap Limit: " << _callcount
50                                << " / " << _limit;
51                         break;
52         }
53 }
54
55 Romain::Observer::ObserverReturnVal
56 Romain::TrapLimitObserver_priv::notify(Romain::App_instance *inst,
57                                        Romain::App_thread *t,
58                                        Romain::Thread_group *tg,
59                                        Romain::App_model *a)
60 {
61         if (limitIsValid()) {
62                 increment();
63                 //status();
64                 if (count() >= limit()) {
65                         enter_kdebug("*#^");
66                 }
67         }
68
69         // Replicatable, so that we only count this once
70         return Romain::Observer::Continue;
71 }
72
73 Romain::TrapLimitObserver*
74 Romain::TrapLimitObserver::Create()
75 {
76         return new TrapLimitObserver_priv();
77 }