[a074b4f] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup taskmon
|
---|
| 30 | * @brief
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /**
|
---|
| 34 | * @file
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <stdio.h>
|
---|
| 38 | #include <ipc/ipc.h>
|
---|
| 39 | #include <async.h>
|
---|
| 40 | #include <ipc/services.h>
|
---|
| 41 | #include <task.h>
|
---|
| 42 | #include <event.h>
|
---|
| 43 | #include <macros.h>
|
---|
| 44 | #include <errno.h>
|
---|
| 45 |
|
---|
| 46 | #define NAME "taskmon"
|
---|
| 47 |
|
---|
| 48 | static void fault_event(ipc_callid_t callid, ipc_call_t *call)
|
---|
| 49 | {
|
---|
| 50 | char *argv[5];
|
---|
| 51 | char *fname;
|
---|
| 52 | char *s_taskid;
|
---|
| 53 |
|
---|
| 54 | task_id_t taskid;
|
---|
| 55 | uintptr_t thread;
|
---|
| 56 |
|
---|
| 57 | taskid = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
|
---|
| 58 | thread = IPC_GET_ARG3(*call);
|
---|
| 59 |
|
---|
| 60 | if (asprintf(&s_taskid, "%lld", taskid) < 0) {
|
---|
| 61 | printf("Memory allocation failed.\n");
|
---|
| 62 | return;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | printf(NAME ": Task %lld fault in thread 0x%lx.\n", taskid, thread);
|
---|
| 66 |
|
---|
| 67 | argv[0] = fname = "/app/taskdump";
|
---|
| 68 |
|
---|
| 69 | #ifdef CONFIG_VERBOSE_DUMPS
|
---|
| 70 | argv[1] = "-m";
|
---|
| 71 | argv[2] = "-t";
|
---|
| 72 | argv[3] = s_taskid;
|
---|
| 73 | argv[4] = NULL;
|
---|
| 74 |
|
---|
| 75 | printf(NAME ": Executing %s %s %s %s\n", argv[0], argv[1], argv[2],
|
---|
| 76 | argv[3]);
|
---|
| 77 | #else
|
---|
| 78 | argv[1] = "-t";
|
---|
| 79 | argv[2] = s_taskid;
|
---|
| 80 | argv[3] = NULL;
|
---|
| 81 |
|
---|
| 82 | printf(NAME ": Executing %s %s %s\n", argv[0], argv[1], argv[2]);
|
---|
| 83 | #endif
|
---|
| 84 |
|
---|
| 85 | if (!task_spawn(fname, argv))
|
---|
| 86 | printf(NAME ": Error spawning taskdump.\n", fname);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | int main(int argc, char *argv[])
|
---|
| 90 | {
|
---|
| 91 | printf(NAME ": Task Monitoring Service\n");
|
---|
| 92 |
|
---|
| 93 | if (event_subscribe(EVENT_FAULT, 0) != EOK) {
|
---|
| 94 | printf(NAME ": Error registering fault notifications.\n");
|
---|
| 95 | return -1;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | async_set_interrupt_received(fault_event);
|
---|
| 99 | async_manager();
|
---|
| 100 |
|
---|
| 101 | return 0;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /** @}
|
---|
| 105 | */
|
---|