Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2787 | decky | 1 | /** @addtogroup tdebug |
2 | * @{ |
||
3 | */ |
||
4 | |||
5 | /** |
||
6 | * @file |
||
7 | * @brief Task Debugging Syscalls. |
||
8 | */ |
||
9 | |||
10 | #include <proc/task.h> |
||
11 | #include <syscall/sysarg64.h> |
||
12 | #include <syscall/copy.h> |
||
13 | #include <console/klog.h> |
||
14 | #include <tdebug/tdebug.h> |
||
15 | #include <tdebug/systdebug.h> |
||
16 | |||
17 | /** |
||
18 | * Syscall to start debugging a task. |
||
19 | * |
||
20 | * The specified task (target) is attached to the current task (monitor). |
||
21 | * The monitoring task will be informed of debug events in the |
||
22 | * target task through IPC notifications with the specified method number. |
||
23 | */ |
||
24 | unative_t sys_tdebug_attach_task(sysarg64_t *uspace_taskid_arg, |
||
25 | unative_t method) |
||
26 | { |
||
27 | sysarg64_t taskid_arg; |
||
28 | int rc; |
||
29 | |||
30 | rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t)); |
||
31 | if (rc != 0) |
||
32 | return (unative_t) rc; |
||
33 | |||
34 | klog_printf("sys_tdebug_attach_task(%lld, %d)", taskid_arg.value, method); |
||
35 | |||
36 | return tdebug_attach_task(taskid_arg.value, method); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Syscall to stop debugging a task. |
||
41 | */ |
||
42 | unative_t sys_tdebug_detach_task(sysarg64_t *uspace_taskid_arg) |
||
43 | { |
||
44 | sysarg64_t taskid_arg; |
||
45 | int rc; |
||
46 | |||
47 | rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t)); |
||
48 | if (rc != 0) |
||
49 | return (unative_t) rc; |
||
50 | |||
51 | klog_printf("sys_tdebug_detach_task(%lld)", taskid_arg.value); |
||
52 | |||
53 | return tdebug_detach_task(taskid_arg.value); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Syscall to resume a thread stopped in a debugging event. |
||
58 | */ |
||
59 | unative_t sys_tdebug_continue_thread(sysarg64_t *uspace_threadid_arg) |
||
60 | { |
||
61 | sysarg64_t threadid_arg; |
||
62 | int rc; |
||
63 | |||
64 | rc = copy_from_uspace(&threadid_arg, uspace_threadid_arg, |
||
65 | sizeof(sysarg64_t)); |
||
66 | |||
67 | if (rc != 0) |
||
68 | return (unative_t) rc; |
||
69 | |||
70 | klog_printf("sys_tdebug_continue_thread(%lld)", threadid_arg.value); |
||
71 | |||
72 | return tdebug_continue_thread(threadid_arg.value); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Syscall to retrieve the arguments of a syscall. |
||
77 | * |
||
78 | * When a thread is stopped in a TDEBUG_EV_SYSCALL event, |
||
79 | * this function may be used to retrieve the arguments of the |
||
80 | * corresponding syscall. |
||
81 | */ |
||
82 | unative_t sys_tdebug_get_syscall_args(sysarg64_t *uspace_threadid_arg, |
||
83 | uintptr_t *uspace_buffer, unative_t *uspace_len_arg) |
||
84 | { |
||
85 | sysarg64_t threadid_arg; |
||
86 | unative_t len_arg; |
||
87 | unative_t sc_args[6]; |
||
88 | int rc; |
||
89 | |||
90 | rc = copy_from_uspace(&threadid_arg, uspace_threadid_arg, |
||
91 | sizeof(sysarg64_t)); |
||
92 | |||
93 | if (rc != 0) |
||
94 | return (unative_t) rc; |
||
95 | |||
96 | rc = copy_from_uspace(&len_arg, uspace_len_arg, sizeof(unative_t)); |
||
97 | |||
98 | if (rc != 0) |
||
99 | return (unative_t) rc; |
||
100 | |||
101 | klog_printf("sys_tdebug_get_syscall_args(%lld,...)", threadid_arg.value); |
||
102 | |||
103 | /* number of args to be copied */ |
||
104 | if (len_arg > 6) len_arg = 6; |
||
105 | |||
106 | rc = tdebug_get_syscall_args(threadid_arg.value, sc_args); |
||
107 | if (rc != 0) |
||
108 | return (unative_t) rc; |
||
109 | |||
110 | rc = copy_to_uspace(uspace_buffer, sc_args, len_arg * sizeof(unative_t)); |
||
111 | |||
112 | if (rc != 0) |
||
113 | return (unative_t) rc; |
||
114 | |||
115 | /* actual number of syscall args */ |
||
116 | len_arg = 6; |
||
117 | |||
118 | rc = copy_to_uspace(uspace_len_arg, &len_arg, sizeof(unative_t)); |
||
119 | |||
120 | if (rc != 0) |
||
121 | return (unative_t) rc; |
||
122 | |||
123 | klog_printf("success\n"); |
||
124 | return 0; |
||
125 | } |
||
126 | |||
127 | unative_t sys_tdebug_set_event_mask(sysarg64_t *uspace_threadid_arg, |
||
128 | unative_t ev_mask) |
||
129 | { |
||
130 | sysarg64_t threadid_arg; |
||
131 | int rc; |
||
132 | |||
133 | rc = copy_from_uspace(&threadid_arg, uspace_threadid_arg, |
||
134 | sizeof(sysarg64_t)); |
||
135 | |||
136 | if (rc != 0) |
||
137 | return (unative_t) rc; |
||
138 | |||
139 | klog_printf("sys_tdebug_set_event_mask(%lld)", threadid_arg.value); |
||
140 | |||
141 | return tdebug_set_event_mask(threadid_arg.value, ev_mask); |
||
142 | } |
||
143 | |||
144 | unative_t sys_tdebug_stop_thread(sysarg64_t *uspace_threadid_arg) |
||
145 | { |
||
146 | sysarg64_t threadid_arg; |
||
147 | int rc; |
||
148 | |||
149 | rc = copy_from_uspace(&threadid_arg, uspace_threadid_arg, |
||
150 | sizeof(sysarg64_t)); |
||
151 | |||
152 | if (rc != 0) |
||
153 | return (unative_t) rc; |
||
154 | |||
155 | klog_printf("sys_tdebug_stop_thread(%lld)", threadid_arg.value); |
||
156 | |||
157 | return tdebug_stop_thread(threadid_arg.value); |
||
158 | } |
||
159 | |||
160 | unative_t sys_tdebug_stop_task(sysarg64_t *uspace_taskid_arg) |
||
161 | { |
||
162 | sysarg64_t taskid_arg; |
||
163 | int rc; |
||
164 | |||
165 | rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t)); |
||
166 | if (rc != 0) |
||
167 | return (unative_t) rc; |
||
168 | |||
169 | klog_printf("sys_tdebug_stop_task(%lld)", taskid_arg.value); |
||
170 | |||
171 | return tdebug_stop_task(taskid_arg.value); |
||
172 | } |