[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 | {
|
---|
[03333bc] | 50 | char *argv[11];
|
---|
[a074b4f] | 51 | char *fname;
|
---|
[03333bc] | 52 | char *dump_fname;
|
---|
[a074b4f] | 53 | char *s_taskid;
|
---|
[03333bc] | 54 | char **s;
|
---|
[a074b4f] | 55 |
|
---|
| 56 | task_id_t taskid;
|
---|
| 57 | uintptr_t thread;
|
---|
| 58 |
|
---|
| 59 | taskid = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
|
---|
| 60 | thread = IPC_GET_ARG3(*call);
|
---|
| 61 |
|
---|
| 62 | if (asprintf(&s_taskid, "%lld", taskid) < 0) {
|
---|
| 63 | printf("Memory allocation failed.\n");
|
---|
| 64 | return;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[03333bc] | 67 | if (asprintf(&dump_fname, "/scratch/d%lld.txt", taskid) < 0) {
|
---|
| 68 | printf("Memory allocation failed.\n");
|
---|
| 69 | return;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[fb6f1a5] | 72 | printf(NAME ": Task %lld fault in thread %p.\n", taskid, thread);
|
---|
[a074b4f] | 73 |
|
---|
[f0bdfb7] | 74 | #ifdef CONFIG_VERBOSE_DUMPS
|
---|
| 75 | argv[0] = "/app/redir";
|
---|
[03333bc] | 76 | argv[1] = "-i";
|
---|
| 77 | argv[2] = "/readme";
|
---|
| 78 | argv[3] = "-o";
|
---|
| 79 | argv[4] = dump_fname;
|
---|
| 80 | argv[5] = "--";
|
---|
| 81 | argv[6] = "/app/taskdump";
|
---|
| 82 | argv[7] = "-m";
|
---|
| 83 | argv[8] = "-t";
|
---|
| 84 | argv[9] = s_taskid;
|
---|
| 85 | argv[10] = NULL;
|
---|
[a074b4f] | 86 | #else
|
---|
[f0bdfb7] | 87 | argv[0] = "/app/taskdump";
|
---|
| 88 | argv[1] = "-t";
|
---|
| 89 | argv[2] = s_taskid;
|
---|
| 90 | argv[3] = NULL;
|
---|
[a074b4f] | 91 | #endif
|
---|
[f0bdfb7] | 92 | fname = argv[0];
|
---|
| 93 |
|
---|
[03333bc] | 94 | printf(NAME ": Executing");
|
---|
| 95 | s = argv;
|
---|
| 96 | while (*s != NULL) {
|
---|
| 97 | printf(" %s", *s);
|
---|
| 98 | ++s;
|
---|
| 99 | }
|
---|
| 100 | putchar('\n');
|
---|
[a074b4f] | 101 |
|
---|
| 102 | if (!task_spawn(fname, argv))
|
---|
| 103 | printf(NAME ": Error spawning taskdump.\n", fname);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | int main(int argc, char *argv[])
|
---|
| 107 | {
|
---|
| 108 | printf(NAME ": Task Monitoring Service\n");
|
---|
| 109 |
|
---|
| 110 | if (event_subscribe(EVENT_FAULT, 0) != EOK) {
|
---|
| 111 | printf(NAME ": Error registering fault notifications.\n");
|
---|
| 112 | return -1;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | async_set_interrupt_received(fault_event);
|
---|
| 116 | async_manager();
|
---|
| 117 |
|
---|
| 118 | return 0;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | /** @}
|
---|
| 122 | */
|
---|