Changeset c6588ce in mainline for kernel/generic/src


Ignore:
Timestamp:
2012-05-05T08:12:17Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ee04c28
Parents:
2cc7f16 (diff), d21e935c (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
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/cmd.c

    r2cc7f16 rc6588ce  
    906906                   ((char *) argv->buffer)[0] <= '9') {
    907907                uint64_t value;
    908                 rc = str_uint64((char *) argv->buffer, NULL, 0, true, &value);
     908                rc = str_uint64_t((char *) argv->buffer, NULL, 0, true, &value);
    909909                if (rc == EOK)
    910910                        addr = (uintptr_t) value;
  • kernel/generic/src/console/console.c

    r2cc7f16 rc6588ce  
    5757
    5858/** Kernel log cyclic buffer */
    59 static wchar_t klog[KLOG_LENGTH] __attribute__ ((aligned (PAGE_SIZE)));
     59wchar_t klog[KLOG_LENGTH] __attribute__((aligned(PAGE_SIZE)));
    6060
    6161/** Kernel log initialized */
  • kernel/generic/src/console/kconsole.c

    r2cc7f16 rc6588ce  
    472472                /* It's a number - convert it */
    473473                uint64_t value;
    474                 int rc = str_uint64(text, NULL, 0, true, &value);
     474                int rc = str_uint64_t(text, NULL, 0, true, &value);
    475475                switch (rc) {
    476476                case EINVAL:
  • kernel/generic/src/ddi/ddi.c

    r2cc7f16 rc6588ce  
    166166        }
    167167       
    168         if (zones.info[znum].flags & ZONE_FIRMWARE) {
    169                 /*
    170                  * Frames are part of firmware
     168        if (zones.info[znum].flags & (ZONE_FIRMWARE | ZONE_RESERVED)) {
     169                /*
     170                 * Frames are part of firmware or reserved zone
    171171                 * -> allow mapping for privileged tasks.
    172172                 */
  • kernel/generic/src/ipc/sysipc.c

    r2cc7f16 rc6588ce  
    111111        switch (imethod) {
    112112        case IPC_M_CONNECTION_CLONE:
    113         case IPC_M_CONNECT_ME:
     113        case IPC_M_CLONE_ESTABLISH:
    114114        case IPC_M_PHONE_HUNGUP:
    115115                /* This message is meant only for the original recipient. */
     
    160160        switch (IPC_GET_IMETHOD(call->data)) {
    161161        case IPC_M_CONNECTION_CLONE:
    162         case IPC_M_CONNECT_ME:
     162        case IPC_M_CLONE_ESTABLISH:
    163163        case IPC_M_CONNECT_TO_ME:
    164164        case IPC_M_CONNECT_ME_TO:
     
    225225                        mutex_unlock(&phone->lock);
    226226                }
    227         } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_CONNECT_ME) {
     227        } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_CLONE_ESTABLISH) {
    228228                phone_t *phone = (phone_t *) IPC_GET_ARG5(*olddata);
    229229               
     
    459459                break;
    460460        }
    461         case IPC_M_CONNECT_ME:
     461        case IPC_M_CLONE_ESTABLISH:
    462462                IPC_SET_ARG5(call->data, (sysarg_t) phone);
    463463                break;
  • kernel/generic/src/lib/func.c

    r2cc7f16 rc6588ce  
    5353void halt()
    5454{
    55 #ifdef CONFIG_DEBUG
     55#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
    5656        bool rundebugger = false;
    5757       
  • kernel/generic/src/lib/str.c

    r2cc7f16 rc6588ce  
    111111#include <debug.h>
    112112#include <macros.h>
     113
     114/** Check the condition if wchar_t is signed */
     115#ifdef WCHAR_IS_UNSIGNED
     116        #define WCHAR_SIGNED_CHECK(cond)  (true)
     117#else
     118        #define WCHAR_SIGNED_CHECK(cond)  (cond)
     119#endif
    113120
    114121/** Byte mask consisting of lowest @n bits (out of 8) */
     
    206213 *
    207214 * @return EOK if the character was encoded successfully, EOVERFLOW if there
    208  *         was not enough space in the output buffer or EINVAL if the character
    209  *         code was invalid.
    210  */
    211 int chr_encode(wchar_t ch, char *str, size_t *offset, size_t size)
     215 *         was not enough space in the output buffer or EINVAL if the character
     216 *         code was invalid.
     217 */
     218int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size)
    212219{
    213220        if (*offset >= size)
     
    427434bool ascii_check(wchar_t ch)
    428435{
    429         if ((ch >= 0) && (ch <= 127))
     436        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))
    430437                return true;
    431438       
     
    440447bool chr_check(wchar_t ch)
    441448{
    442         if ((ch >= 0) && (ch <= 1114111))
     449        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))
    443450                return true;
    444451       
     
    893900 *
    894901 */
    895 int str_uint64(const char *nptr, char **endptr, unsigned int base,
     902int str_uint64_t(const char *nptr, char **endptr, unsigned int base,
    896903    bool strict, uint64_t *result)
    897904{
  • kernel/generic/src/main/main.c

    r2cc7f16 rc6588ce  
    221221        frame_init();
    222222        slab_cache_init();
    223         ra_init();     
     223        ra_init();
    224224        sysinfo_init();
    225225        btree_init();
     
    257257                for (i = 0; i < init.cnt; i++)
    258258                        LOG("init[%zu].addr=%p, init[%zu].size=%zu",
    259                             i, (void *) init.tasks[i].addr, i, init.tasks[i].size);
     259                            i, (void *) init.tasks[i].paddr, i, init.tasks[i].size);
    260260        } else
    261261                printf("No init binaries found.\n");
  • kernel/generic/src/main/version.c

    r2cc7f16 rc6588ce  
    3838
    3939static const char *project = "SPARTAN kernel";
    40 static const char *copyright = "Copyright (c) 2001-2011 HelenOS project";
     40static const char *copyright = STRING(COPYRIGHT);
    4141static const char *release = STRING(RELEASE);
    4242static const char *name = STRING(NAME);
  • kernel/generic/src/mm/page.c

    r2cc7f16 rc6588ce  
    168168int page_find_mapping(uintptr_t virt, void **phys)
    169169{
    170         mutex_lock(&AS->lock);
     170        page_table_lock(AS, true);
    171171       
    172172        pte_t *pte = page_mapping_find(AS, virt, false);
    173173        if ((!PTE_VALID(pte)) || (!PTE_PRESENT(pte))) {
    174                 mutex_unlock(&AS->lock);
     174                page_table_unlock(AS, true);
    175175                return ENOENT;
    176176        }
     
    179179            (virt - ALIGN_DOWN(virt, PAGE_SIZE));
    180180       
    181         mutex_unlock(&AS->lock);
     181        page_table_unlock(AS, true);
    182182       
    183183        return EOK;
  • kernel/generic/src/printf/printf_core.c

    r2cc7f16 rc6588ce  
    284284        /* Print leading spaces. */
    285285        size_t strw = str_length(str);
    286         if (precision == 0)
     286        if ((precision == 0) || (precision > strw))
    287287                precision = strw;
    288288       
     
    332332        /* Print leading spaces. */
    333333        size_t strw = wstr_length(str);
    334         if (precision == 0)
     334        if ((precision == 0) || (precision > strw))
    335335                precision = strw;
    336336       
  • kernel/generic/src/syscall/syscall.c

    r2cc7f16 rc6588ce  
    184184       
    185185        /* Sysinfo syscalls. */
     186        (syshandler_t) sys_sysinfo_get_keys_size,
     187        (syshandler_t) sys_sysinfo_get_keys,
    186188        (syshandler_t) sys_sysinfo_get_val_type,
    187189        (syshandler_t) sys_sysinfo_get_value,
  • kernel/generic/src/sysinfo/stats.c

    r2cc7f16 rc6588ce  
    8383 *
    8484 * @param item Sysinfo item (unused).
     85 * @param data Unused.
    8586 *
    8687 * @return System uptime (in secords).
    8788 *
    8889 */
    89 static sysarg_t get_stats_uptime(struct sysinfo_item *item)
     90static sysarg_t get_stats_uptime(struct sysinfo_item *item, void *data)
    9091{
    9192        /* This doesn't have to be very accurate */
     
    9899 * @param size    Size of the returned data.
    99100 * @param dry_run Do not get the data, just calculate the size.
     101 * @param data    Unused.
    100102 *
    101103 * @return Data containing several stats_cpu_t structures.
     
    104106 */
    105107static void *get_stats_cpus(struct sysinfo_item *item, size_t *size,
    106     bool dry_run)
     108    bool dry_run, void *data)
    107109{
    108110        *size = sizeof(stats_cpu_t) * config.cpu_count;
     
    249251        ASSERT(interrupts_disabled());
    250252        ASSERT(irq_spinlock_locked(&task->lock));
    251 
     253       
    252254        stats_task->task_id = task->taskid;
    253255        str_cpy(stats_task->name, TASK_NAME_BUFLEN, task->name);
     
    293295 * @param size    Size of the returned data.
    294296 * @param dry_run Do not get the data, just calculate the size.
     297 * @param data    Unused.
    295298 *
    296299 * @return Data containing several stats_task_t structures.
     
    299302 */
    300303static void *get_stats_tasks(struct sysinfo_item *item, size_t *size,
    301     bool dry_run)
     304    bool dry_run, void *data)
    302305{
    303306        /* Messing with task structures, avoid deadlock */
     
    350353        ASSERT(interrupts_disabled());
    351354        ASSERT(irq_spinlock_locked(&thread->lock));
    352 
     355       
    353356        stats_thread->thread_id = thread->tid;
    354357        stats_thread->task_id = thread->task->taskid;
     
    398401 * @param size    Size of the returned data.
    399402 * @param dry_run Do not get the data, just calculate the size.
     403 * @param data    Unused.
    400404 *
    401405 * @return Data containing several stats_task_t structures.
     
    404408 */
    405409static void *get_stats_threads(struct sysinfo_item *item, size_t *size,
    406     bool dry_run)
     410    bool dry_run, void *data)
    407411{
    408412        /* Messing with threads structures, avoid deadlock */
     
    451455 * @param name    Task ID (string-encoded number).
    452456 * @param dry_run Do not get the data, just calculate the size.
     457 * @param data    Unused.
    453458 *
    454459 * @return Sysinfo return holder. The type of the returned
     
    460465 *
    461466 */
    462 static sysinfo_return_t get_stats_task(const char *name, bool dry_run)
     467static sysinfo_return_t get_stats_task(const char *name, bool dry_run,
     468    void *data)
    463469{
    464470        /* Initially no return value */
     
    468474        /* Parse the task ID */
    469475        task_id_t task_id;
    470         if (str_uint64(name, NULL, 0, true, &task_id) != EOK)
     476        if (str_uint64_t(name, NULL, 0, true, &task_id) != EOK)
    471477                return ret;
    472478       
     
    520526 * @param name    Thread ID (string-encoded number).
    521527 * @param dry_run Do not get the data, just calculate the size.
     528 * @param data    Unused.
    522529 *
    523530 * @return Sysinfo return holder. The type of the returned
     
    529536 *
    530537 */
    531 static sysinfo_return_t get_stats_thread(const char *name, bool dry_run)
     538static sysinfo_return_t get_stats_thread(const char *name, bool dry_run,
     539    void *data)
    532540{
    533541        /* Initially no return value */
     
    537545        /* Parse the thread ID */
    538546        thread_id_t thread_id;
    539         if (str_uint64(name, NULL, 0, true, &thread_id) != EOK)
     547        if (str_uint64_t(name, NULL, 0, true, &thread_id) != EOK)
    540548                return ret;
    541549       
     
    586594 * @param size    Size of the returned data.
    587595 * @param dry_run Do not get the data, just calculate the size.
     596 * @param data    Unused.
    588597 *
    589598 * @return Data containing several stats_exc_t structures.
     
    592601 */
    593602static void *get_stats_exceptions(struct sysinfo_item *item, size_t *size,
    594     bool dry_run)
     603    bool dry_run, void *data)
    595604{
    596605        *size = sizeof(stats_exc_t) * IVT_ITEMS;
     
    634643 * @param name    Exception number (string-encoded number).
    635644 * @param dry_run Do not get the data, just calculate the size.
     645 * @param data    Unused.
    636646 *
    637647 * @return Sysinfo return holder. The type of the returned
     
    643653 *
    644654 */
    645 static sysinfo_return_t get_stats_exception(const char *name, bool dry_run)
     655static sysinfo_return_t get_stats_exception(const char *name, bool dry_run,
     656    void *data)
    646657{
    647658        /* Initially no return value */
     
    651662        /* Parse the exception number */
    652663        uint64_t excn;
    653         if (str_uint64(name, NULL, 0, true, &excn) != EOK)
     664        if (str_uint64_t(name, NULL, 0, true, &excn) != EOK)
    654665                return ret;
    655666       
     
    705716 * @param size    Size of the returned data.
    706717 * @param dry_run Do not get the data, just calculate the size.
     718 * @param data    Unused.
    707719 *
    708720 * @return Data containing stats_physmem_t.
     
    711723 */
    712724static void *get_stats_physmem(struct sysinfo_item *item, size_t *size,
    713     bool dry_run)
     725    bool dry_run, void *data)
    714726{
    715727        *size = sizeof(stats_physmem_t);
     
    735747 * @param size    Size of the returned data.
    736748 * @param dry_run Do not get the data, just calculate the size.
     749 * @param data    Unused.
    737750 *
    738751 * @return Data several load_t values.
     
    741754 */
    742755static void *get_stats_load(struct sysinfo_item *item, size_t *size,
    743     bool dry_run)
     756    bool dry_run, void *data)
    744757{
    745758        *size = sizeof(load_t) * LOAD_STEPS;
     
    810823        mutex_initialize(&load_lock, MUTEX_PASSIVE);
    811824       
    812         sysinfo_set_item_fn_val("system.uptime", NULL, get_stats_uptime);
    813         sysinfo_set_item_fn_data("system.cpus", NULL, get_stats_cpus);
    814         sysinfo_set_item_fn_data("system.physmem", NULL, get_stats_physmem);
    815         sysinfo_set_item_fn_data("system.load", NULL, get_stats_load);
    816         sysinfo_set_item_fn_data("system.tasks", NULL, get_stats_tasks);
    817         sysinfo_set_item_fn_data("system.threads", NULL, get_stats_threads);
    818         sysinfo_set_item_fn_data("system.exceptions", NULL, get_stats_exceptions);
    819         sysinfo_set_subtree_fn("system.tasks", NULL, get_stats_task);
    820         sysinfo_set_subtree_fn("system.threads", NULL, get_stats_thread);
    821         sysinfo_set_subtree_fn("system.exceptions", NULL, get_stats_exception);
     825        sysinfo_set_item_gen_val("system.uptime", NULL, get_stats_uptime, NULL);
     826        sysinfo_set_item_gen_data("system.cpus", NULL, get_stats_cpus, NULL);
     827        sysinfo_set_item_gen_data("system.physmem", NULL, get_stats_physmem, NULL);
     828        sysinfo_set_item_gen_data("system.load", NULL, get_stats_load, NULL);
     829        sysinfo_set_item_gen_data("system.tasks", NULL, get_stats_tasks, NULL);
     830        sysinfo_set_item_gen_data("system.threads", NULL, get_stats_threads, NULL);
     831        sysinfo_set_item_gen_data("system.exceptions", NULL, get_stats_exceptions, NULL);
     832        sysinfo_set_subtree_fn("system.tasks", NULL, get_stats_task, NULL);
     833        sysinfo_set_subtree_fn("system.threads", NULL, get_stats_thread, NULL);
     834        sysinfo_set_subtree_fn("system.exceptions", NULL, get_stats_exception, NULL);
    822835}
    823836
  • kernel/generic/src/sysinfo/sysinfo.c

    r2cc7f16 rc6588ce  
    11/*
    22 * Copyright (c) 2006 Jakub Vana
     3 * Copyright (c) 2012 Martin Decky
    34 * All rights reserved.
    45 *
     
    99100            sizeof(sysinfo_item_t), 0, sysinfo_item_constructor,
    100101            sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED);
    101 
     102       
    102103        mutex_initialize(&sysinfo_lock, MUTEX_ACTIVE);
    103104}
     
    110111 * @param subtree Current sysinfo (sub)tree root item.
    111112 * @param ret     If the return value is NULL, this argument
    112  *                can be either also NULL (i.e. no item was
     113 *                can be set either to NULL (i.e. no item was
    113114 *                found and no data was generated) or the
    114115 *                original pointer is used to store the value
     
    125126{
    126127        ASSERT(subtree != NULL);
    127         ASSERT(ret != NULL);
    128128       
    129129        sysinfo_item_t *cur = subtree;
     
    151151                        case SYSINFO_SUBTREE_FUNCTION:
    152152                                /* Get generated data */
    153                                 **ret = cur->subtree.get_data(name + i + 1, dry_run);
     153                                if (ret != NULL)
     154                                        **ret = cur->subtree.generator.fn(name + i + 1,
     155                                            dry_run, cur->subtree.generator.data);
     156                               
    154157                                return NULL;
    155158                        default:
    156159                                /* Not found, no data generated */
    157                                 *ret = NULL;
     160                                if (ret != NULL)
     161                                        *ret = NULL;
     162                               
    158163                                return NULL;
    159164                        }
     
    164169       
    165170        /* Not found, no data generated */
    166         *ret = NULL;
     171        if (ret != NULL)
     172                *ret = NULL;
     173       
    167174        return NULL;
    168175}
     
    352359 *             a new root item (NULL for global sysinfo root).
    353360 * @param fn   Numeric value generator function.
    354  *
    355  */
    356 void sysinfo_set_item_fn_val(const char *name, sysinfo_item_t **root,
    357     sysinfo_fn_val_t fn)
     361 * @param data Private data.
     362 *
     363 */
     364void sysinfo_set_item_gen_val(const char *name, sysinfo_item_t **root,
     365    sysinfo_fn_val_t fn, void *data)
    358366{
    359367        /* Protect sysinfo tree consistency */
     
    366374        if (item != NULL) {
    367375                item->val_type = SYSINFO_VAL_FUNCTION_VAL;
    368                 item->val.fn_val = fn;
     376                item->val.gen_val.fn = fn;
     377                item->val.gen_val.data = data;
    369378        }
    370379       
     
    383392 *             a new root item (NULL for global sysinfo root).
    384393 * @param fn   Binary data generator function.
    385  *
    386  */
    387 void sysinfo_set_item_fn_data(const char *name, sysinfo_item_t **root,
    388     sysinfo_fn_data_t fn)
     394 * @param data Private data.
     395 *
     396 */
     397void sysinfo_set_item_gen_data(const char *name, sysinfo_item_t **root,
     398    sysinfo_fn_data_t fn, void *data)
    389399{
    390400        /* Protect sysinfo tree consistency */
     
    397407        if (item != NULL) {
    398408                item->val_type = SYSINFO_VAL_FUNCTION_DATA;
    399                 item->val.fn_data = fn;
     409                item->val.gen_data.fn = fn;
     410                item->val.gen_data.data = data;
    400411        }
    401412       
     
    431442 *             a new root item (NULL for global sysinfo root).
    432443 * @param fn   Subtree generator function.
     444 * @param data Private data to be passed to the generator.
    433445 *
    434446 */
    435447void sysinfo_set_subtree_fn(const char *name, sysinfo_item_t **root,
    436     sysinfo_fn_subtree_t fn)
     448    sysinfo_fn_subtree_t fn, void *data)
    437449{
    438450        /* Protect sysinfo tree consistency */
     
    448460        if ((item != NULL) && (item->subtree_type != SYSINFO_SUBTREE_TABLE)) {
    449461                item->subtree_type = SYSINFO_SUBTREE_FUNCTION;
    450                 item->subtree.get_data = fn;
     462                item->subtree.generator.fn = fn;
     463                item->subtree.generator.data = data;
    451464        }
    452465       
     
    456469/** Sysinfo dump indentation helper routine
    457470 *
    458  * @param depth Number of indentation characters to print.
    459  *
    460  */
    461 NO_TRACE static void sysinfo_indent(unsigned int depth)
    462 {
    463         unsigned int i;
    464         for (i = 0; i < depth; i++)
    465                 printf("  ");
     471 * @param depth Number of spaces to print.
     472 *
     473 */
     474NO_TRACE static void sysinfo_indent(size_t spaces)
     475{
     476        for (size_t i = 0; i < spaces; i++)
     477                printf(" ");
    466478}
    467479
     
    470482 * Should be called with sysinfo_lock held.
    471483 *
    472  * @param root  Root item of the current (sub)tree.
    473  * @param depth Current depth in the sysinfo tree.
    474  *
    475  */
    476 NO_TRACE static void sysinfo_dump_internal(sysinfo_item_t *root, unsigned int depth)
    477 {
    478         sysinfo_item_t *cur = root;
    479        
     484 * @param root   Root item of the current (sub)tree.
     485 * @param spaces Current indentation level.
     486 *
     487 */
     488NO_TRACE static void sysinfo_dump_internal(sysinfo_item_t *root, size_t spaces)
     489{
    480490        /* Walk all siblings */
    481         while (cur != NULL) {
    482                 sysinfo_indent(depth);
     491        for (sysinfo_item_t *cur = root; cur; cur = cur->next) {
     492                size_t length;
     493               
     494                if (spaces == 0) {
     495                        printf("%s", cur->name);
     496                        length = str_length(cur->name);
     497                } else {
     498                        sysinfo_indent(spaces);
     499                        printf(".%s", cur->name);
     500                        length = str_length(cur->name) + 1;
     501                }
    483502               
    484503                sysarg_t val;
     
    488507                switch (cur->val_type) {
    489508                case SYSINFO_VAL_UNDEFINED:
    490                         printf("+ %s\n", cur->name);
     509                        printf(" [undefined]\n");
    491510                        break;
    492511                case SYSINFO_VAL_VAL:
    493                         printf("+ %s -> %" PRIun" (%#" PRIxn ")\n", cur->name,
    494                             cur->val.val, cur->val.val);
     512                        printf(" -> %" PRIun" (%#" PRIxn ")\n", cur->val.val,
     513                            cur->val.val);
    495514                        break;
    496515                case SYSINFO_VAL_DATA:
    497                         printf("+ %s (%zu bytes)\n", cur->name,
    498                             cur->val.data.size);
     516                        printf(" (%zu bytes)\n", cur->val.data.size);
    499517                        break;
    500518                case SYSINFO_VAL_FUNCTION_VAL:
    501                         val = cur->val.fn_val(cur);
    502                         printf("+ %s -> %" PRIun" (%#" PRIxn ") [generated]\n",
    503                             cur->name, val, val);
     519                        val = cur->val.gen_val.fn(cur, cur->val.gen_val.data);
     520                        printf(" -> %" PRIun" (%#" PRIxn ") [generated]\n", val,
     521                            val);
    504522                        break;
    505523                case SYSINFO_VAL_FUNCTION_DATA:
    506524                        /* N.B.: No data was actually returned (only a dry run) */
    507                         (void) cur->val.fn_data(cur, &size, true);
    508                         printf("+ %s (%zu bytes) [generated]\n", cur->name,
    509                             size);
     525                        (void) cur->val.gen_data.fn(cur, &size, true,
     526                            cur->val.gen_data.data);
     527                        printf(" (%zu bytes) [generated]\n", size);
    510528                        break;
    511529                default:
     
    518536                        break;
    519537                case SYSINFO_SUBTREE_TABLE:
    520                         sysinfo_dump_internal(cur->subtree.table, depth + 1);
     538                        sysinfo_dump_internal(cur->subtree.table, spaces + length);
    521539                        break;
    522540                case SYSINFO_SUBTREE_FUNCTION:
    523                         sysinfo_indent(depth + 1);
    524                         printf("+ [generated subtree]\n");
     541                        sysinfo_indent(spaces + length);
     542                        printf("<generated subtree>\n");
    525543                        break;
    526544                default:
    527                         sysinfo_indent(depth + 1);
    528                         printf("+ [unknown subtree]\n");
     545                        sysinfo_indent(spaces + length);
     546                        printf("<unknown subtree>\n");
    529547                }
    530                
    531                 cur = cur->next;
    532548        }
    533549}
     
    594610                        break;
    595611                case SYSINFO_VAL_FUNCTION_VAL:
    596                         ret.val = item->val.fn_val(item);
     612                        ret.val = item->val.gen_val.fn(item, item->val.gen_val.data);
    597613                        break;
    598614                case SYSINFO_VAL_FUNCTION_DATA:
    599                         ret.data.data = item->val.fn_data(item, &ret.data.size,
    600                             dry_run);
     615                        ret.data.data = item->val.gen_data.fn(item, &ret.data.size,
     616                            dry_run, item->val.gen_data.data);
    601617                        break;
    602618                }
     
    635651        ASSERT(path);
    636652       
    637         if ((copy_from_uspace(path, ptr, size + 1) == 0)
    638             && (path[size] == 0)) {
     653        if ((copy_from_uspace(path, ptr, size + 1) == 0) &&
     654            (path[size] == 0)) {
    639655                /*
    640656                 * Prevent other functions from messing with sysinfo while we
     
    645661                mutex_unlock(&sysinfo_lock);
    646662        }
     663       
    647664        free(path);
    648665        return ret;
     666}
     667
     668/** Return sysinfo keys determined by name
     669 *
     670 * Should be called with sysinfo_lock held.
     671 *
     672 * @param name    Sysinfo path.
     673 * @param root    Root item of the sysinfo (sub)tree.
     674 *                If it is NULL then consider the global
     675 *                sysinfo tree.
     676 * @param dry_run Do not actually get any generated
     677 *                binary data, just calculate the size.
     678 *
     679 * @return Item value (constant or generated).
     680 *
     681 */
     682NO_TRACE static sysinfo_return_t sysinfo_get_keys(const char *name,
     683    sysinfo_item_t **root, bool dry_run)
     684{
     685        if (root == NULL)
     686                root = &global_root;
     687       
     688        sysinfo_item_t *subtree = NULL;
     689       
     690        if (name[0] != 0) {
     691                /* Try to find the item */
     692                sysinfo_item_t *item =
     693                    sysinfo_find_item(name, *root, NULL, dry_run);
     694                if ((item != NULL) &&
     695                    (item->subtree_type == SYSINFO_SUBTREE_TABLE))
     696                        subtree = item->subtree.table;
     697        } else
     698                subtree = *root;
     699       
     700        sysinfo_return_t ret;
     701       
     702        if (subtree != NULL) {
     703                /*
     704                 * Calculate the size of subkeys.
     705                 */
     706                size_t size = 0;
     707                for (sysinfo_item_t *cur = subtree; cur; cur = cur->next)
     708                        size += str_size(cur->name) + 1;
     709               
     710                if (dry_run) {
     711                        ret.tag = SYSINFO_VAL_DATA;
     712                        ret.data.data = NULL;
     713                        ret.data.size = size;
     714                } else {
     715                        /* Allocate buffer for subkeys */
     716                        char *names = (char *) malloc(size, FRAME_ATOMIC);
     717                        if (names == NULL)
     718                                return ret;
     719                       
     720                        size_t pos = 0;
     721                        for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) {
     722                                str_cpy(names + pos, size - pos, cur->name);
     723                                pos += str_size(cur->name) + 1;
     724                        }
     725                       
     726                        /* Correct return value */
     727                        ret.tag = SYSINFO_VAL_DATA;
     728                        ret.data.data = (void *) names;
     729                        ret.data.size = size;
     730                }
     731        } else {
     732                /* No item in the fixed sysinfo tree */
     733                ret.tag = SYSINFO_VAL_UNDEFINED;
     734        }
     735       
     736        return ret;
     737}
     738
     739/** Return sysinfo keys determined by name from user space
     740 *
     741 * The path string passed from the user space has to be properly
     742 * null-terminated (the last passed character must be null).
     743 *
     744 * @param ptr     Sysinfo path in the user address space.
     745 * @param size    Size of the path string.
     746 * @param dry_run Do not actually get any generated
     747 *                binary data, just calculate the size.
     748 *
     749 */
     750NO_TRACE static sysinfo_return_t sysinfo_get_keys_uspace(void *ptr, size_t size,
     751    bool dry_run)
     752{
     753        sysinfo_return_t ret;
     754        ret.tag = SYSINFO_VAL_UNDEFINED;
     755       
     756        if (size > SYSINFO_MAX_PATH)
     757                return ret;
     758       
     759        char *path = (char *) malloc(size + 1, 0);
     760        ASSERT(path);
     761       
     762        if ((copy_from_uspace(path, ptr, size + 1) == 0) &&
     763            (path[size] == 0)) {
     764                /*
     765                 * Prevent other functions from messing with sysinfo while we
     766                 * are reading it.
     767                 */
     768                mutex_lock(&sysinfo_lock);
     769                ret = sysinfo_get_keys(path, NULL, dry_run);
     770                mutex_unlock(&sysinfo_lock);
     771        }
     772       
     773        free(path);
     774        return ret;
     775}
     776
     777/** Get the sysinfo keys size (syscall)
     778 *
     779 * The path string passed from the user space has
     780 * to be properly null-terminated (the last passed
     781 * character must be null).
     782 *
     783 * @param path_ptr  Sysinfo path in the user address space.
     784 * @param path_size Size of the path string.
     785 * @param size_ptr  User space pointer where to store the
     786 *                  keys size.
     787 *
     788 * @return Error code (EOK in case of no error).
     789 *
     790 */
     791sysarg_t sys_sysinfo_get_keys_size(void *path_ptr, size_t path_size,
     792    void *size_ptr)
     793{
     794        int rc;
     795       
     796        /*
     797         * Get the keys.
     798         *
     799         * N.B.: There is no need to free any potential keys
     800         * since we request a dry run.
     801         */
     802        sysinfo_return_t ret =
     803            sysinfo_get_keys_uspace(path_ptr, path_size, true);
     804       
     805        /* Check return data tag */
     806        if (ret.tag == SYSINFO_VAL_DATA)
     807                rc = copy_to_uspace(size_ptr, &ret.data.size,
     808                    sizeof(ret.data.size));
     809        else
     810                rc = EINVAL;
     811       
     812        return (sysarg_t) rc;
     813}
     814
     815/** Get the sysinfo keys (syscall)
     816 *
     817 * The path string passed from the user space has
     818 * to be properly null-terminated (the last passed
     819 * character must be null).
     820 *
     821 * If the user space buffer size does not equal
     822 * the actual size of the returned data, the data
     823 * is truncated.
     824 *
     825 * The actual size of data returned is stored to
     826 * size_ptr.
     827 *
     828 * @param path_ptr    Sysinfo path in the user address space.
     829 * @param path_size   Size of the path string.
     830 * @param buffer_ptr  User space pointer to the buffer where
     831 *                    to store the binary data.
     832 * @param buffer_size User space buffer size.
     833 * @param size_ptr    User space pointer where to store the
     834 *                    binary data size.
     835 *
     836 * @return Error code (EOK in case of no error).
     837 *
     838 */
     839sysarg_t sys_sysinfo_get_keys(void *path_ptr, size_t path_size,
     840    void *buffer_ptr, size_t buffer_size, size_t *size_ptr)
     841{
     842        int rc;
     843       
     844        /* Get the keys */
     845        sysinfo_return_t ret = sysinfo_get_keys_uspace(path_ptr, path_size,
     846            false);
     847       
     848        /* Check return data tag */
     849        if (ret.tag == SYSINFO_VAL_DATA) {
     850                size_t size = min(ret.data.size, buffer_size);
     851                rc = copy_to_uspace(buffer_ptr, ret.data.data, size);
     852                if (rc == EOK)
     853                        rc = copy_to_uspace(size_ptr, &size, sizeof(size));
     854               
     855                free(ret.data.data);
     856        } else
     857                rc = EINVAL;
     858       
     859        return (sysarg_t) rc;
    649860}
    650861
     
    672883       
    673884        /*
    674          * Map generated value types to constant types (user space does not care
    675          * whether the value is constant or generated).
     885         * Map generated value types to constant types (user space does
     886         * not care whether the value is constant or generated).
    676887         */
    677888        if (ret.tag == SYSINFO_VAL_FUNCTION_VAL)
     
    701912{
    702913        int rc;
    703 
     914       
    704915        /*
    705916         * Get the item.
    706917         *
    707          * N.B.: There is no need to free any potential generated binary data
    708          * since we request a dry run.
     918         * N.B.: There is no need to free any potential generated binary
     919         * data since we request a dry run.
    709920         */
    710921        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
     
    741952         * Get the item.
    742953         *
    743          * N.B.: There is no need to free any potential generated binary data
    744          * since we request a dry run.
     954         * N.B.: There is no need to free any potential generated binary
     955         * data since we request a dry run.
    745956         */
    746957        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
Note: See TracChangeset for help on using the changeset viewer.