Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/udebug/udebug_ops.c

    ra074b4f r41df2827  
    209209
    210210                mutex_lock(&t->udebug.lock);
    211                 if ((t->flags & THREAD_FLAG_USPACE) != 0) {
     211                if ((t->flags & THREAD_FLAG_USPACE) != 0)
    212212                        t->udebug.active = true;
    213                         mutex_unlock(&t->udebug.lock);
    214                         condvar_broadcast(&t->udebug.active_cv);
    215                 } else {
    216                         mutex_unlock(&t->udebug.lock);
    217                 }
     213                mutex_unlock(&t->udebug.lock);
    218214        }
    219215
     
    359355 *
    360356 * If the sequence is longer than @a buf_size bytes, only as much hashes
    361  * as can fit are copied. The number of bytes copied is stored in @a stored.
    362  * The total number of thread bytes that could have been saved had there been
    363  * enough space is stored in @a needed.
     357 * as can fit are copied. The number of thread hashes copied is stored
     358 * in @a n.
    364359 *
    365360 * The rationale for having @a buf_size is that this function is only
     
    369364 * @param buffer        The buffer for storing thread hashes.
    370365 * @param buf_size      Buffer size in bytes.
    371  * @param stored        The actual number of bytes copied will be stored here.
    372  * @param needed        Total number of hashes that could have been saved.
    373  */
    374 int udebug_thread_read(void **buffer, size_t buf_size, size_t *stored,
    375     size_t *needed)
     366 * @param n             The actual number of hashes copied will be stored here.
     367 */
     368int udebug_thread_read(void **buffer, size_t buf_size, size_t *n)
    376369{
    377370        thread_t *t;
    378371        link_t *cur;
    379372        unative_t tid;
    380         size_t copied_ids;
    381         size_t extra_ids;
     373        unsigned copied_ids;
    382374        ipl_t ipl;
    383375        unative_t *id_buffer;
     
    388380
    389381        /* Allocate a buffer to hold thread IDs */
    390         id_buffer = malloc(buf_size + 1, 0);
     382        id_buffer = malloc(buf_size, 0);
    391383
    392384        mutex_lock(&TASK->udebug.lock);
     
    404396        max_ids = buf_size / sizeof(unative_t);
    405397        copied_ids = 0;
    406         extra_ids = 0;
    407398
    408399        /* FIXME: make sure the thread isn't past debug shutdown... */
    409400        for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) {
     401                /* Do not write past end of buffer */
     402                if (copied_ids >= max_ids) break;
     403
    410404                t = list_get_instance(cur, thread_t, th_link);
    411405
     
    415409
    416410                /* Not interested in kernel threads. */
    417                 if ((flags & THREAD_FLAG_USPACE) == 0)
    418                         continue;
    419 
    420                 if (copied_ids < max_ids) {
     411                if ((flags & THREAD_FLAG_USPACE) != 0) {
    421412                        /* Using thread struct pointer as identification hash */
    422413                        tid = (unative_t) t;
    423414                        id_buffer[copied_ids++] = tid;
    424                 } else {
    425                         extra_ids++;
    426415                }
    427416        }
     
    433422
    434423        *buffer = id_buffer;
    435         *stored = copied_ids * sizeof(unative_t);
    436         *needed = (copied_ids + extra_ids) * sizeof(unative_t);
     424        *n = copied_ids * sizeof(unative_t);
    437425
    438426        return 0;
Note: See TracChangeset for help on using the changeset viewer.