Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2896 → Rev 2897

/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;
}