Changeset 371bd7d in mainline for kernel/generic/src/proc


Ignore:
Timestamp:
2010-03-27T09:22:17Z (16 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
36a75a2
Parents:
cd82bb1 (diff), eaf22d4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
kernel/generic/src/proc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/program.c

    rcd82bb1 r371bd7d  
    3434/**
    3535 * @file
    36  * @brief       Running userspace programs.
     36 * @brief Running userspace programs.
    3737 */
    3838
     
    6666/** Create a program using an existing address space.
    6767 *
    68  * @param as            Address space containing a binary program image.
    69  * @param entry_addr    Program entry-point address in program address space.
    70  * @param name          Name to set for the program's task.
    71  * @param p             Buffer for storing program information.
    72  */
    73 void program_create(as_t *as, uintptr_t entry_addr, char *name, program_t *p)
    74 {
    75         as_area_t *a;
     68 * @param as         Address space containing a binary program image.
     69 * @param entry_addr Program entry-point address in program address space.
     70 * @param name       Name to set for the program's task.
     71 * @param prg        Buffer for storing program information.
     72 *
     73 * @return EOK on success or negative error code.
     74 *
     75 */
     76int program_create(as_t *as, uintptr_t entry_addr, char *name, program_t *prg)
     77{
    7678        uspace_arg_t *kernel_uarg;
    77 
     79       
    7880        kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0);
    7981        kernel_uarg->uspace_entry = (void *) entry_addr;
     
    8385        kernel_uarg->uspace_uarg = NULL;
    8486       
    85         p->task = task_create(as, name);
    86         ASSERT(p->task);
    87 
     87        prg->task = task_create(as, name);
     88        if (!prg->task)
     89                return ELIMIT;
     90       
    8891        /*
    89          * Create the data as_area.
     92         * Create the data address space area.
    9093         */
    91         a = as_area_create(as, AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
     94        as_area_t *area = as_area_create(as,
     95            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
    9296            LOADED_PROG_STACK_PAGES_NO * PAGE_SIZE, USTACK_ADDRESS,
    9397            AS_AREA_ATTR_NONE, &anon_backend, NULL);
    94 
     98        if (!area)
     99                return ENOMEM;
     100       
    95101        /*
    96102         * Create the main thread.
    97103         */
    98         p->main_thread = thread_create(uinit, kernel_uarg, p->task,
     104        prg->main_thread = thread_create(uinit, kernel_uarg, prg->task,
    99105            THREAD_FLAG_USPACE, "uinit", false);
    100         ASSERT(p->main_thread);
     106        if (!prg->main_thread)
     107                return ELIMIT;
     108       
     109        return EOK;
    101110}
    102111
     
    107116 * executable image. The task is returned in *task.
    108117 *
    109  * @param image_addr    Address of an executable program image.
    110  * @param name          Name to set for the program's task.
    111  * @param p             Buffer for storing program info. If image_addr
    112  *                      points to a loader image, p->task will be set to
    113  *                      NULL and EOK will be returned.
     118 * @param image_addr Address of an executable program image.
     119 * @param name       Name to set for the program's task.
     120 * @param prg        Buffer for storing program info. If image_addr
     121 *                   points to a loader image, p->task will be set to
     122 *                   NULL and EOK will be returned.
    114123 *
    115124 * @return EOK on success or negative error code.
    116  */
    117 int program_create_from_image(void *image_addr, char *name, program_t *p)
    118 {
    119         as_t *as;
    120         unsigned int rc;
    121 
    122         as = as_create(0);
    123         ASSERT(as);
    124 
    125         rc = elf_load((elf_header_t *) image_addr, as, 0);
     125 *
     126 */
     127int program_create_from_image(void *image_addr, char *name, program_t *prg)
     128{
     129        as_t *as = as_create(0);
     130        if (!as)
     131                return ENOMEM;
     132       
     133        unsigned int rc = elf_load((elf_header_t *) image_addr, as, 0);
    126134        if (rc != EE_OK) {
    127135                as_destroy(as);
    128                 p->task = NULL;
    129                 p->main_thread = NULL;
     136                prg->task = NULL;
     137                prg->main_thread = NULL;
     138               
    130139                if (rc != EE_LOADER)
    131140                        return ENOTSUP;
    132141               
    133142                /* Register image as the program loader */
    134                 ASSERT(program_loader == NULL);
     143                if (program_loader != NULL)
     144                        return ELIMIT;
     145               
    135146                program_loader = image_addr;
    136147                LOG("Registered program loader at 0x%" PRIp "\n",
    137148                    image_addr);
     149               
    138150                return EOK;
    139151        }
    140 
    141         program_create(as, ((elf_header_t *) image_addr)->e_entry, name, p);
    142 
    143         return EOK;
     152       
     153        return program_create(as, ((elf_header_t *) image_addr)->e_entry,
     154            name, prg);
    144155}
    145156
    146157/** Create a task from the program loader image.
    147158 *
    148  * @param p     Buffer for storing program info.
    149  * @param name  Name to set for the program's task.
     159 * @param prg  Buffer for storing program info.
     160 * @param name Name to set for the program's task.
    150161 *
    151162 * @return EOK on success or negative error code.
    152  */
    153 int program_create_loader(program_t *p, char *name)
    154 {
    155         as_t *as;
    156         unsigned int rc;
    157         void *loader;
    158 
    159         as = as_create(0);
    160         ASSERT(as);
    161 
    162         loader = program_loader;
     163 *
     164 */
     165int program_create_loader(program_t *prg, char *name)
     166{
     167        as_t *as = as_create(0);
     168        if (!as)
     169                return ENOMEM;
     170       
     171        void *loader = program_loader;
    163172        if (!loader) {
    164173                printf("Cannot spawn loader as none was registered\n");
    165174                return ENOENT;
    166175        }
    167 
    168         rc = elf_load((elf_header_t *) program_loader, as, ELD_F_LOADER);
     176       
     177        unsigned int rc = elf_load((elf_header_t *) program_loader, as,
     178            ELD_F_LOADER);
    169179        if (rc != EE_OK) {
    170180                as_destroy(as);
    171181                return ENOENT;
    172182        }
    173 
    174         program_create(as, ((elf_header_t *) program_loader)->e_entry,
    175             name, p);
    176 
    177         return EOK;
     183       
     184        return program_create(as, ((elf_header_t *) program_loader)->e_entry,
     185            name, prg);
    178186}
    179187
     
    182190 * Switch program's main thread to the ready state.
    183191 *
    184  * @param p Program to make ready.
    185  */
    186 void program_ready(program_t *p)
    187 {
    188         thread_ready(p->main_thread);
     192 * @param prg Program to make ready.
     193 *
     194 */
     195void program_ready(program_t *prg)
     196{
     197        thread_ready(prg->main_thread);
    189198}
    190199
     
    194203 * the task name.
    195204 *
    196  * @param name                  Name to set on the new task (typically the same
    197  *                              as the command used to execute it).
    198  *
    199  * @return 0 on success or an error code from @ref errno.h.
     205 * @param uspace_name Name to set on the new task (typically the same
     206 *                    as the command used to execute it).
     207 * @param name_len    Length of the name.
     208 *
     209 * @return EOK on success or an error code from @ref errno.h.
     210 *
    200211 */
    201212unative_t sys_program_spawn_loader(char *uspace_name, size_t name_len)
    202213{
    203         program_t p;
    204         int rc;
    205         char namebuf[TASK_NAME_BUFLEN];
    206 
    207214        /* Cap length of name and copy it from userspace. */
    208 
    209215        if (name_len > TASK_NAME_BUFLEN - 1)
    210216                name_len = TASK_NAME_BUFLEN - 1;
    211 
    212         rc = copy_from_uspace(namebuf, uspace_name, name_len);
     217       
     218        char namebuf[TASK_NAME_BUFLEN];
     219        int rc = copy_from_uspace(namebuf, uspace_name, name_len);
    213220        if (rc != 0)
    214221                return (unative_t) rc;
    215 
     222       
    216223        namebuf[name_len] = 0;
    217 
     224       
    218225        /* Spawn the new task. */
    219 
    220         rc = program_create_loader(&p, namebuf);
     226        program_t prg;
     227        rc = program_create_loader(&prg, namebuf);
    221228        if (rc != 0)
    222229                return rc;
    223 
     230       
    224231        // FIXME: control the capabilities
    225         cap_set(p.task, cap_get(TASK));
    226 
    227         program_ready(&p);
    228 
     232        cap_set(prg.task, cap_get(TASK));
     233        program_ready(&prg);
     234       
    229235        return EOK;
    230236}
  • kernel/generic/src/proc/scheduler.c

    rcd82bb1 r371bd7d  
    542542{
    543543        thread_t *t;
    544         int count, average, j, k = 0;
     544        int count;
     545        atomic_count_t average;
    545546        unsigned int i;
     547        int j;
     548        int k = 0;
    546549        ipl_t ipl;
    547550
  • kernel/generic/src/proc/task.c

    rcd82bb1 r371bd7d  
    5353#include <errno.h>
    5454#include <func.h>
    55 #include <string.h>
     55#include <str.h>
     56#include <memstr.h>
    5657#include <syscall/copy.h>
    5758#include <macros.h>
     
    170171 *
    171172 */
    172 task_t *task_create(as_t *as, char *name)
     173task_t *task_create(as_t *as, const char *name)
    173174{
    174175        ipl_t ipl;
  • kernel/generic/src/proc/thread.c

    rcd82bb1 r371bd7d  
    7676
    7777/** Thread states */
    78 char *thread_states[] = {
     78const char *thread_states[] = {
    7979        "Invalid",
    8080        "Running",
     
    264264
    265265        atomic_inc(&nrdy);
     266        // FIXME: Why is the avg value never read?
    266267        avg = atomic_get(&nrdy) / config.cpu_active;
    267268        atomic_inc(&cpu->nrdy);
     
    288289 */
    289290thread_t *thread_create(void (* func)(void *), void *arg, task_t *task,
    290     int flags, char *name, bool uncounted)
     291    int flags, const char *name, bool uncounted)
    291292{
    292293        thread_t *t;
     
    501502void thread_sleep(uint32_t sec)
    502503{
    503         thread_usleep(sec * 1000000);
     504        /* Sleep in 1000 second steps to support
     505           full argument range */
     506        while (sec > 0) {
     507                uint32_t period = (sec > 1000) ? 1000 : sec;
     508       
     509                thread_usleep(period * 1000000);
     510                sec -= period;
     511        }
    504512}
    505513
     
    575583{
    576584        waitq_t wq;
    577                                  
     585       
    578586        waitq_initialize(&wq);
    579 
     587       
    580588        (void) waitq_sleep_timeout(&wq, usec, SYNCH_FLAGS_NON_BLOCKING);
    581589}
     
    812820}
    813821
     822/** Syscall wrapper for sleeping. */
     823unative_t sys_thread_usleep(uint32_t usec)
     824{
     825        thread_usleep(usec);
     826        return 0;
     827}
     828
    814829/** @}
    815830 */
Note: See TracChangeset for help on using the changeset viewer.