Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/sysinfo/sysinfo.c

    rda1bafb r311bc25  
    4040#include <arch/asm.h>
    4141#include <errno.h>
     42#include <macros.h>
    4243
    4344/** Maximal sysinfo path length */
     
    5859 *
    5960 */
    60 static int sysinfo_item_constructor(void *obj, unsigned int kmflag)
     61NO_TRACE static int sysinfo_item_constructor(void *obj, unsigned int kmflag)
    6162{
    6263        sysinfo_item_t *item = (sysinfo_item_t *) obj;
     
    7879 *
    7980 */
    80 static size_t sysinfo_item_destructor(void *obj)
     81NO_TRACE static size_t sysinfo_item_destructor(void *obj)
    8182{
    8283        sysinfo_item_t *item = (sysinfo_item_t *) obj;
     
    120121 *
    121122 */
    122 static sysinfo_item_t *sysinfo_find_item(const char *name,
     123NO_TRACE static sysinfo_item_t *sysinfo_find_item(const char *name,
    123124    sysinfo_item_t *subtree, sysinfo_return_t **ret, bool dry_run)
    124125{
     
    180181 *
    181182 */
    182 static sysinfo_item_t *sysinfo_create_path(const char *name,
     183NO_TRACE static sysinfo_item_t *sysinfo_create_path(const char *name,
    183184    sysinfo_item_t **psubtree)
    184185{
     
    296297 */
    297298void sysinfo_set_item_val(const char *name, sysinfo_item_t **root,
    298     unative_t val)
     299    sysarg_t val)
    299300{
    300301        /* Protect sysinfo tree consistency */
     
    458459 *
    459460 */
    460 static void sysinfo_indent(unsigned int depth)
     461NO_TRACE static void sysinfo_indent(unsigned int depth)
    461462{
    462463        unsigned int i;
     
    473474 *
    474475 */
    475 static void sysinfo_dump_internal(sysinfo_item_t *root, unsigned int depth)
     476NO_TRACE static void sysinfo_dump_internal(sysinfo_item_t *root, unsigned int depth)
    476477{
    477478        sysinfo_item_t *cur = root;
     
    481482                sysinfo_indent(depth);
    482483               
    483                 unative_t val;
     484                sysarg_t val;
    484485                size_t size;
    485486               
     
    494495                        break;
    495496                case SYSINFO_VAL_DATA:
    496                         printf("+ %s (%" PRIs" bytes)\n", cur->name,
     497                        printf("+ %s (%zu bytes)\n", cur->name,
    497498                            cur->val.data.size);
    498499                        break;
     
    505506                        /* N.B.: No data was actually returned (only a dry run) */
    506507                        (void) cur->val.fn_data(cur, &size, true);
    507                         printf("+ %s (%" PRIs" bytes) [generated]\n", cur->name,
     508                        printf("+ %s (%zu bytes) [generated]\n", cur->name,
    508509                            size);
    509510                        break;
     
    567568 *
    568569 */
    569 static sysinfo_return_t sysinfo_get_item(const char *name,
     570NO_TRACE static sysinfo_return_t sysinfo_get_item(const char *name,
    570571    sysinfo_item_t **root, bool dry_run)
    571572{
     
    622623 *
    623624 */
    624 static sysinfo_return_t sysinfo_get_item_uspace(void *ptr, size_t size,
     625NO_TRACE static sysinfo_return_t sysinfo_get_item_uspace(void *ptr, size_t size,
    625626    bool dry_run)
    626627{
     
    660661 *
    661662 */
    662 unative_t sys_sysinfo_get_tag(void *path_ptr, size_t path_size)
     663sysarg_t sys_sysinfo_get_tag(void *path_ptr, size_t path_size)
    663664{
    664665        /*
     
    679680                ret.tag = SYSINFO_VAL_DATA;
    680681       
    681         return (unative_t) ret.tag;
     682        return (sysarg_t) ret.tag;
    682683}
    683684
     
    696697 *
    697698 */
    698 unative_t sys_sysinfo_get_value(void *path_ptr, size_t path_size,
     699sysarg_t sys_sysinfo_get_value(void *path_ptr, size_t path_size,
    699700    void *value_ptr)
    700701{
     
    715716                rc = EINVAL;
    716717       
    717         return (unative_t) rc;
     718        return (sysarg_t) rc;
    718719}
    719720
     
    732733 *
    733734 */
    734 unative_t sys_sysinfo_get_data_size(void *path_ptr, size_t path_size,
     735sysarg_t sys_sysinfo_get_data_size(void *path_ptr, size_t path_size,
    735736    void *size_ptr)
    736737{
     
    752753                rc = EINVAL;
    753754       
    754         return (unative_t) rc;
     755        return (sysarg_t) rc;
    755756}
    756757
     
    761762 * character must be null).
    762763 *
    763  * The user space buffer must be sized exactly according
    764  * to the size of the binary data, otherwise the request
    765  * fails.
     764 * If the user space buffer size does not equal
     765 * the actual size of the returned data, the data
     766 * is truncated. Whether this is actually a fatal
     767 * error or the data can be still interpreted as valid
     768 * depends on the nature of the data and has to be
     769 * decided by the user space.
     770 *
     771 * The actual size of data returned is stored to
     772 * size_ptr.
    766773 *
    767774 * @param path_ptr    Sysinfo path in the user address space.
     
    770777 *                    to store the binary data.
    771778 * @param buffer_size User space buffer size.
     779 * @param size_ptr    User space pointer where to store the
     780 *                    binary data size.
    772781 *
    773782 * @return Error code (EOK in case of no error).
    774783 *
    775784 */
    776 unative_t sys_sysinfo_get_data(void *path_ptr, size_t path_size,
    777     void *buffer_ptr, size_t buffer_size)
     785sysarg_t sys_sysinfo_get_data(void *path_ptr, size_t path_size,
     786    void *buffer_ptr, size_t buffer_size, size_t *size_ptr)
    778787{
    779788        int rc;
    780789       
    781790        /* Get the item */
    782         sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, false);
    783 
     791        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size,
     792            false);
     793       
    784794        /* Only constant or generated binary data is considered */
    785         if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) {
    786                 /* Check destination buffer size */
    787                 if (ret.data.size == buffer_size)
    788                         rc = copy_to_uspace(buffer_ptr, ret.data.data,
    789                             ret.data.size);
    790                 else
    791                         rc = ENOMEM;
     795        if ((ret.tag == SYSINFO_VAL_DATA) ||
     796            (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) {
     797                size_t size = min(ret.data.size, buffer_size);
     798                rc = copy_to_uspace(buffer_ptr, ret.data.data, size);
     799                if (rc == EOK)
     800                        rc = copy_to_uspace(size_ptr, &size, sizeof(size));
    792801        } else
    793802                rc = EINVAL;
     
    797806                free(ret.data.data);
    798807       
    799         return (unative_t) rc;
     808        return (sysarg_t) rc;
    800809}
    801810
Note: See TracChangeset for help on using the changeset viewer.