Changeset 2902e1bb in mainline for kernel/generic/src


Ignore:
Timestamp:
2012-06-13T13:17:46Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1d4024cf, 375e501
Parents:
faba839
Message:

add support for variable uspace stack size
create individual address space areas for stacks of additional threads (instead of allocating the stack from heap)
avoid memory leaks in program_create()

Location:
kernel/generic/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/main/uinit.c

    rfaba839 r2902e1bb  
    5656void uinit(void *arg)
    5757{
    58         uspace_arg_t uarg;
    59        
    6058        /*
    6159         * So far, we don't have a use for joining userspace threads so we
     
    7270#endif
    7371       
    74         uarg.uspace_entry = ((uspace_arg_t *) arg)->uspace_entry;
    75         uarg.uspace_stack = ((uspace_arg_t *) arg)->uspace_stack;
    76         uarg.uspace_uarg = ((uspace_arg_t *) arg)->uspace_uarg;
    77         uarg.uspace_thread_function = NULL;
    78         uarg.uspace_thread_arg = NULL;
     72        uspace_arg_t *uarg = (uspace_arg_t *) arg;
     73        uspace_arg_t local_uarg;
    7974       
    80         free((uspace_arg_t *) arg);
     75        local_uarg.uspace_entry = uarg->uspace_entry;
     76        local_uarg.uspace_stack = uarg->uspace_stack;
     77        local_uarg.uspace_stack_size = uarg->uspace_stack_size;
     78        local_uarg.uspace_uarg = uarg->uspace_uarg;
     79        local_uarg.uspace_thread_function = NULL;
     80        local_uarg.uspace_thread_arg = NULL;
    8181       
    82         userspace(&uarg);
     82        free(uarg);
     83       
     84        userspace(&local_uarg);
    8385}
    8486
  • kernel/generic/src/proc/program.c

    rfaba839 r2902e1bb  
    7171int program_create(as_t *as, uintptr_t entry_addr, char *name, program_t *prg)
    7272{
    73         uspace_arg_t *kernel_uarg;
    74        
    75         kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0);
    76         kernel_uarg->uspace_entry = (void *) entry_addr;
    77         kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS;
    78         kernel_uarg->uspace_thread_function = NULL;
    79         kernel_uarg->uspace_thread_arg = NULL;
    80         kernel_uarg->uspace_uarg = NULL;
    81        
    8273        prg->loader_status = EE_OK;
    8374        prg->task = task_create(as, name);
     
    9283            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
    9384            STACK_SIZE, AS_AREA_ATTR_NONE, &anon_backend, NULL, &virt, 0);
    94         if (!area)
     85        if (!area) {
     86                task_destroy(prg->task);
    9587                return ENOMEM;
     88        }
     89       
     90        uspace_arg_t *kernel_uarg = (uspace_arg_t *)
     91            malloc(sizeof(uspace_arg_t), 0);
     92       
     93        kernel_uarg->uspace_entry = (void *) entry_addr;
     94        kernel_uarg->uspace_stack = (void *) virt;
     95        kernel_uarg->uspace_stack_size = STACK_SIZE;
     96        kernel_uarg->uspace_thread_function = NULL;
     97        kernel_uarg->uspace_thread_arg = NULL;
     98        kernel_uarg->uspace_uarg = NULL;
    9699       
    97100        /*
     
    100103        prg->main_thread = thread_create(uinit, kernel_uarg, prg->task,
    101104            THREAD_FLAG_USPACE, "uinit", false);
    102         if (!prg->main_thread)
     105        if (!prg->main_thread) {
     106                free(kernel_uarg);
     107                as_area_destroy(as, virt);
     108                task_destroy(prg->task);
    103109                return ELIMIT;
     110        }
    104111       
    105112        return EOK;
  • kernel/generic/src/proc/thread.c

    rfaba839 r2902e1bb  
    854854         * In case of failure, kernel_uarg will be deallocated in this function.
    855855         * In case of success, kernel_uarg will be freed in uinit().
    856          *
    857856         */
    858857        uspace_arg_t *kernel_uarg =
Note: See TracChangeset for help on using the changeset viewer.