Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2896 → Rev 2897

/branches/tracing/kernel/generic/src/udebug/udebug_ipc.c
175,7 → 175,14
size_t n;
int rc;
 
rc = udebug_thread_read(&buffer, &n);
uspace_addr = IPC_GET_ARG2(call->data); /* Destination address */
buf_size = IPC_GET_ARG3(call->data); /* Dest. buffer size */
 
/*
* Read thread list. Variable n will be filled with actual number
* of threads times thread-id size.
*/
rc = udebug_thread_read(&buffer, buf_size, &n);
if (rc < 0) {
IPC_SET_RETVAL(call->data, rc);
ipc_answer(&TASK->kernel_box, call);
182,20 → 189,19
return;
}
 
/*
* Make use of call->buffer to transfer data to caller's userspace
*/
total_bytes = n;
 
uspace_addr = IPC_GET_ARG2(call->data);
buf_size = IPC_GET_ARG3(call->data);
/* Copy MAX(buf_size, total_bytes) bytes */
 
total_bytes = n;
 
if (buf_size > total_bytes)
to_copy = total_bytes;
else
to_copy = buf_size;
 
/*
* Make use of call->buffer to transfer data to caller's userspace
*/
 
IPC_SET_RETVAL(call->data, 0);
/* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that
same code in process_answer() can be used
/branches/tracing/kernel/generic/src/udebug/udebug_ops.c
235,18 → 235,23
}
 
 
int udebug_thread_read(void **buffer, size_t *n)
int udebug_thread_read(void **buffer, size_t buf_size, size_t *n)
{
thread_t *t;
link_t *cur;
unative_t tid;
unsigned num_threads, copied_ids;
unsigned copied_ids;
ipl_t ipl;
unative_t *id_buffer;
int flags;
size_t max_ids;
 
klog_printf("udebug_thread_read()");
 
/* Allocate a buffer to hold thread IDs */
id_buffer = malloc(buf_size, 0);
if (!id_buffer) return ENOMEM;
 
ipl = interrupts_disable();
spinlock_lock(&TASK->lock);
 
258,26 → 263,15
return EINVAL;
}
 
/* Count the threads first */
/* Copy down the thread IDs */
 
num_threads = 0;
max_ids = buf_size / sizeof(unative_t);
copied_ids = 0;
 
for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) {
/* Count all threads, to be on the safe side */
++num_threads;
}
/* Do not write past end of buffer */
if (copied_ids >= max_ids) break;
 
/* Allocate a buffer and copy down the threads' ids */
//FIXME!!! must not malloc when locks are held
id_buffer = malloc(num_threads * sizeof(unative_t), 0);
if (!id_buffer) {
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
 
return ENOMEM;
}
 
copied_ids = 0;
for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) {
t = list_get_instance(cur, thread_t, th_link);
 
spinlock_lock(&t->lock);
286,7 → 280,7
 
/* Not interested in kernel threads */
if ((flags & THREAD_FLAG_USPACE) != 0) {
/* Using thread struct pointer for identification */
/* Using thread struct pointer as identification hash */
tid = (unative_t) t;
id_buffer[copied_ids++] = tid;
}