source: mainline/kernel/generic/include/sysinfo/sysinfo.h

Last change on this file was 5a5269d, checked in by GitHub <noreply@…>, 6 years ago

Change type of uspace pointers in kernel from pointer type to numeric (#170)

From kernel's perspective, userspace addresses are not valid pointers,
and can only be used in calls to copy_to/from_uspace().
Therefore, we change the type of those arguments and variables to
uspace_addr_t which is an alias for sysarg_t.

This allows the compiler to catch accidental direct accesses to
userspace addresses.

Additionally, to avoid losing the type information in code,
a macro uspace_ptr(type) is used that translates to uspace_addr_t.
I makes no functional difference, but allows keeping the type information
in code in case we implement some sort of static checking for it in the future.

However, ccheck doesn't like that, so instead of using uspace_ptr(char),
we use uspace_ptr_char which is defined as
#define uspace_ptr_char uspace_ptr(char).

  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[6326f5e6]1/*
[df4ed85]2 * Copyright (c) 2006 Jakub Vana
[196c253]3 * Copyright (c) 2012 Martin Decky
[6326f5e6]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
[174156fd]30/** @addtogroup kernel_generic
[b45c443]31 * @{
32 */
33/** @file
34 */
35
[06e1e95]36#ifndef KERN_SYSINFO_H_
37#define KERN_SYSINFO_H_
38
[d99c1d2]39#include <typedefs.h>
[525c5ac]40#include <stdbool.h>
[19f857a]41#include <str.h>
[9a426d1f]42#include <abi/sysinfo.h>
[2666daa]43
[80bfb601]44/** Framebuffer info exported flags */
[a71c158]45extern bool fb_exported;
46
[80bfb601]47/** Subtree type
48 *
49 */
[d9fae235]50typedef enum {
[80bfb601]51 SYSINFO_SUBTREE_NONE = 0, /**< No subtree (leaf item) */
52 SYSINFO_SUBTREE_TABLE = 1, /**< Fixed subtree */
53 SYSINFO_SUBTREE_FUNCTION = 2 /**< Generated subtree */
[d9fae235]54} sysinfo_subtree_type_t;
55
56struct sysinfo_item;
57
[196c253]58/** Generated numeric value function */
59typedef sysarg_t (*sysinfo_fn_val_t)(struct sysinfo_item *, void *);
60
61/** Sysinfo generated numberic value data
62 *
63 */
64typedef struct {
65 sysinfo_fn_val_t fn; /**< Generated value function */
66 void *data; /**< Private data */
67} sysinfo_gen_val_data_t;
[80bfb601]68
69/** Generated binary data function */
[196c253]70typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t *, bool,
71 void *);
72
73/** Sysinfo generated binary data data
74 *
75 */
76typedef struct {
77 sysinfo_fn_data_t fn; /**< Generated binary data function */
78 void *data; /**< Private data */
79} sysinfo_gen_data_data_t;
[d9fae235]80
[80bfb601]81/** Sysinfo item binary data
82 *
83 */
[d9fae235]84typedef struct {
[80bfb601]85 void *data; /**< Data */
86 size_t size; /**< Size (bytes) */
[d9fae235]87} sysinfo_data_t;
88
[80bfb601]89/** Sysinfo item value (union)
90 *
91 */
[d9fae235]92typedef union {
[196c253]93 sysarg_t val; /**< Constant numberic value */
94 sysinfo_data_t data; /**< Constant binary data */
95 sysinfo_gen_val_data_t gen_val; /**< Generated numeric value function */
96 sysinfo_gen_data_data_t gen_data; /**< Generated binary data function */
[42d3be3]97} sysinfo_item_val_t;
[2666daa]98
[80bfb601]99/** Sysinfo return holder
100 *
101 * This structure is generated from the constant
102 * items or by the generating functions. Note that
103 * the validity of the data is limited by the scope
104 * of single sysinfo invocation guarded by sysinfo_lock.
105 *
106 */
[9dae191e]107typedef struct {
[80bfb601]108 sysinfo_item_val_type_t tag; /**< Return value type */
[9dae191e]109 union {
[96b02eb9]110 sysarg_t val; /**< Numberic value */
[80bfb601]111 sysinfo_data_t data; /**< Binary data */
[9dae191e]112 };
113} sysinfo_return_t;
114
[80bfb601]115/** Generated subtree function */
[5869ce0]116typedef sysinfo_return_t (*sysinfo_fn_subtree_t)(const char *, bool, void *);
117
118/** Sysinfo generated subtree data
119 *
120 */
121typedef struct {
122 sysinfo_fn_subtree_t fn; /**< Generated subtree function */
123 void *data; /**< Private data */
[196c253]124} sysinfo_gen_subtree_data_t;
[9dae191e]125
[80bfb601]126/** Sysinfo subtree (union)
127 *
128 */
[d9fae235]129typedef union {
[196c253]130 struct sysinfo_item *table; /**< Fixed subtree (list of subitems) */
131 sysinfo_gen_subtree_data_t generator; /**< Generated subtree */
[d9fae235]132} sysinfo_subtree_t;
133
[80bfb601]134/** Sysinfo item
135 *
136 */
[42d3be3]137typedef struct sysinfo_item {
[80bfb601]138 char *name; /**< Item name */
[a35b458]139
[80bfb601]140 sysinfo_item_val_type_t val_type; /**< Item value type */
141 sysinfo_item_val_t val; /**< Item value */
[a35b458]142
[80bfb601]143 sysinfo_subtree_type_t subtree_type; /**< Subtree type */
144 sysinfo_subtree_t subtree; /**< Subtree */
[a35b458]145
[80bfb601]146 struct sysinfo_item *next; /**< Sibling item */
[42d3be3]147} sysinfo_item_t;
[2666daa]148
[96b02eb9]149extern void sysinfo_set_item_val(const char *, sysinfo_item_t **, sysarg_t);
[d9fae235]150extern void sysinfo_set_item_data(const char *, sysinfo_item_t **, void *,
151 size_t);
[196c253]152extern void sysinfo_set_item_gen_val(const char *, sysinfo_item_t **,
153 sysinfo_fn_val_t, void *);
154extern void sysinfo_set_item_gen_data(const char *, sysinfo_item_t **,
155 sysinfo_fn_data_t, void *);
[d9fae235]156extern void sysinfo_set_item_undefined(const char *, sysinfo_item_t **);
157
[9dae191e]158extern void sysinfo_set_subtree_fn(const char *, sysinfo_item_t **,
[5869ce0]159 sysinfo_fn_subtree_t, void *);
[9dae191e]160
161extern void sysinfo_init(void);
162extern void sysinfo_dump(sysinfo_item_t *);
[d9fae235]163
[5a5269d]164extern sys_errno_t sys_sysinfo_get_keys_size(uspace_addr_t, size_t, uspace_addr_t);
165extern sys_errno_t sys_sysinfo_get_keys(uspace_addr_t, size_t, uspace_addr_t, size_t, uspace_ptr_size_t);
166extern sysarg_t sys_sysinfo_get_val_type(uspace_addr_t, size_t);
167extern sys_errno_t sys_sysinfo_get_value(uspace_addr_t, size_t, uspace_addr_t);
168extern sys_errno_t sys_sysinfo_get_data_size(uspace_addr_t, size_t, uspace_addr_t);
169extern sys_errno_t sys_sysinfo_get_data(uspace_addr_t, size_t, uspace_addr_t, size_t, uspace_ptr_size_t);
[35a96cf]170
[06e1e95]171#endif
172
[42d3be3]173/** @}
[b45c443]174 */
Note: See TracBrowser for help on using the repository browser.