Changeset 24345a5 in mainline


Ignore:
Timestamp:
2008-11-08T10:01:59Z (16 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
24d6efc
Parents:
7faabb7
Message:

Set meaningful names for loaded programs. Now 'tasks' kconsole command is much less obscure.

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/proc/program.h

    r7faabb7 r24345a5  
    5353extern void *program_loader;
    5454
    55 extern void program_create(as_t *as, uintptr_t entry_addr, program_t *p);
    56 extern int program_create_from_image(void *image_addr, program_t *p);
    57 extern int program_create_loader(program_t *p);
     55extern void program_create(as_t *as, uintptr_t entry_addr, char *name,
     56    program_t *p);
     57extern int program_create_from_image(void *image_addr, char *name,
     58    program_t *p);
     59extern int program_create_loader(program_t *p, char *name);
    5860extern void program_ready(program_t *p);
    5961
    60 extern unative_t sys_program_spawn_loader(int *uspace_phone_id);
     62extern unative_t sys_program_spawn_loader(int *uspace_phone_id,
     63    char *uspace_name, size_t name_len);
    6164
    6265#endif
  • kernel/generic/include/proc/task.h

    r7faabb7 r24345a5  
    5555#include <udebug/udebug.h>
    5656
     57#define TASK_NAME_BUFLEN        20
     58
    5759struct thread;
    5860
     
    6870         */
    6971        SPINLOCK_DECLARE(lock);
    70        
    71         char *name;
     72
     73        char name[TASK_NAME_BUFLEN];
    7274        /** List of threads contained in this task. */
    7375        link_t th_head;
  • kernel/generic/src/main/kinit.c

    r7faabb7 r24345a5  
    170170
    171171                int rc = program_create_from_image((void *) init.tasks[i].addr,
    172                     &programs[i]);
     172                    "init-bin", &programs[i]);
    173173
    174174                if (rc == 0 && programs[i].task != NULL) {
  • kernel/generic/src/proc/program.c

    r7faabb7 r24345a5  
    6868 * @param as            Address space containing a binary program image.
    6969 * @param entry_addr    Program entry-point address in program address space.
     70 * @param name          Name to set for the program's task.
    7071 * @param p             Buffer for storing program information.
    7172 */
    72 void program_create(as_t *as, uintptr_t entry_addr, program_t *p)
     73void program_create(as_t *as, uintptr_t entry_addr, char *name, program_t *p)
    7374{
    7475        as_area_t *a;
     
    8283        kernel_uarg->uspace_uarg = NULL;
    8384       
    84         p->task = task_create(as, "app");
     85        p->task = task_create(as, name);
    8586        ASSERT(p->task);
    8687
     
    107108 *
    108109 * @param image_addr    Address of an executable program image.
     110 * @param name          Name to set for the program's task.
    109111 * @param p             Buffer for storing program info. If image_addr
    110112 *                      points to a loader image, p->task will be set to
     
    113115 * @return EOK on success or negative error code.
    114116 */
    115 int program_create_from_image(void *image_addr, program_t *p)
     117int program_create_from_image(void *image_addr, char *name, program_t *p)
    116118{
    117119        as_t *as;
     
    137139        }
    138140
    139         program_create(as, ((elf_header_t *) image_addr)->e_entry, p);
     141        program_create(as, ((elf_header_t *) image_addr)->e_entry, name, p);
    140142
    141143        return EOK;
     
    144146/** Create a task from the program loader image.
    145147 *
    146  * @param p Buffer for storing program info.
     148 * @param p     Buffer for storing program info.
     149 * @param name  Name to set for the program's task.
     150 *
    147151 * @return EOK on success or negative error code.
    148152 */
    149 int program_create_loader(program_t *p)
     153int program_create_loader(program_t *p, char *name)
    150154{
    151155        as_t *as;
     
    168172        }
    169173
    170         program_create(as, ((elf_header_t *) program_loader)->e_entry, p);
     174        program_create(as, ((elf_header_t *) program_loader)->e_entry,
     175            name, p);
    171176
    172177        return EOK;
     
    189194 * to it and stores the phone id into the provided buffer.
    190195 *
    191  * @param uspace_phone_id Userspace address where to store the phone id.
     196 * @param uspace_phone_id       Userspace address where to store the phone id.
     197 * @param name                  Name to set on the new task (typically the same
     198 *                              as the command used to execute it).
    192199 *
    193200 * @return 0 on success or an error code from @ref errno.h.
    194201 */
    195 unative_t sys_program_spawn_loader(int *uspace_phone_id)
     202unative_t sys_program_spawn_loader(int *uspace_phone_id, char *uspace_name,
     203    size_t name_len)
    196204{
    197205        program_t p;
     
    199207        int rc;
    200208        int phone_id;
     209        char namebuf[TASK_NAME_BUFLEN];
    201210
    202211        fake_id = 0;
     
    208217                return rc;
    209218
     219        /* Cap length of name and copy it from userspace. */
     220
     221        if (name_len > THREAD_NAME_BUFLEN - 1)
     222                name_len = THREAD_NAME_BUFLEN - 1;
     223
     224        rc = copy_from_uspace(namebuf, uspace_name, name_len);
     225        if (rc != 0)
     226                return (unative_t) rc;
     227
     228        namebuf[name_len] = '\0';
     229
     230        /* Allocate the phone for communicating with the new task. */
     231
    210232        phone_id = phone_alloc();
    211233        if (phone_id < 0)
    212234                return ELIMIT;
    213235
    214         rc = program_create_loader(&p);
     236        /* Spawn the new task. */
     237
     238        rc = program_create_loader(&p, namebuf);
    215239        if (rc != 0)
    216240                return rc;
  • kernel/generic/src/proc/task.c

    r7faabb7 r24345a5  
    131131 *
    132132 * @param as            Task's address space.
    133  * @param name          Symbolic name.
     133 * @param name          Symbolic name (a copy is made).
    134134 *
    135135 * @return              New task's structure.
     
    149149        list_initialize(&ta->th_head);
    150150        ta->as = as;
    151         ta->name = name;
     151
     152        memcpy(ta->name, name, TASK_NAME_BUFLEN);
     153        ta->name[TASK_NAME_BUFLEN - 1] = '\0';
     154
    152155        atomic_set(&ta->refcount, 0);
    153156        atomic_set(&ta->lifecount, 0);
  • kernel/generic/src/proc/thread.c

    r7faabb7 r24345a5  
    280280 *                      call. The task's lock may not be held.
    281281 * @param flags         Thread flags.
    282  * @param name          Symbolic name.
     282 * @param name          Symbolic name (a copy is made).
    283283 * @param uncounted     Thread's accounting doesn't affect accumulated task
    284284 *                      accounting.
     
    317317       
    318318        memcpy(t->name, name, THREAD_NAME_BUFLEN);
     319        t->name[THREAD_NAME_BUFLEN - 1] = '\0';
    319320       
    320321        t->thread_code = func;
     
    716717        int rc;
    717718
    718         if (name_len >= THREAD_NAME_BUFLEN)
     719        if (name_len > THREAD_NAME_BUFLEN - 1)
    719720                name_len = THREAD_NAME_BUFLEN - 1;
    720721
  • uspace/app/trace/trace.c

    r7faabb7 r24345a5  
    517517
    518518        /* Spawn a program loader */   
    519         ldr = loader_spawn();
     519        ldr = loader_spawn(path);
    520520        if (ldr == NULL)
    521521                return 0;
  • uspace/lib/libc/generic/loader.c

    r7faabb7 r24345a5  
    4747 *
    4848 * Spawns a new program loader task and returns the connection structure.
     49 * @param name  Symbolic name to set on the newly created task.
    4950 * @return      Pointer to the loader connection structure (should be
    5051 *              de-allocated using free() after use).
    5152 */
    52 loader_t *loader_spawn(void)
     53loader_t *loader_spawn(char *name)
    5354{
    5455        int phone_id, rc;
     
    5859         * Ask kernel to spawn a new loader task.
    5960         */
    60         rc = __SYSCALL1(SYS_PROGRAM_SPAWN_LOADER, (sysarg_t) &phone_id);
     61        rc = __SYSCALL3(SYS_PROGRAM_SPAWN_LOADER, (sysarg_t) &phone_id,
     62                (sysarg_t) name, strlen(name));
    6163        if (rc != 0)
    6264                return NULL;
  • uspace/lib/libc/generic/task.c

    r7faabb7 r24345a5  
    6565
    6666        /* Spawn a program loader. */   
    67         ldr = loader_spawn();
     67        ldr = loader_spawn(path);
    6868        if (ldr == NULL)
    6969                return 0;
  • uspace/lib/libc/include/loader/loader.h

    r7faabb7 r24345a5  
    4545} loader_t;
    4646
    47 extern loader_t *loader_spawn(void);
     47extern loader_t *loader_spawn(char *name);
    4848extern int loader_get_task_id(loader_t *, task_id_t *);
    4949extern int loader_set_pathname(loader_t *, const char *);
Note: See TracChangeset for help on using the changeset viewer.