Changeset 311bc25 in mainline
- Timestamp:
- 2011-01-25T17:09:04Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a0ce870
- Parents:
- 8befd0a
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/sysinfo/sysinfo.h
r8befd0a r311bc25 148 148 extern sysarg_t sys_sysinfo_get_value(void *, size_t, void *); 149 149 extern sysarg_t sys_sysinfo_get_data_size(void *, size_t, void *); 150 extern sysarg_t sys_sysinfo_get_data(void *, size_t, void *, size_t );150 extern sysarg_t sys_sysinfo_get_data(void *, size_t, void *, size_t, size_t *); 151 151 152 152 #endif -
kernel/generic/src/sysinfo/sysinfo.c
r8befd0a r311bc25 40 40 #include <arch/asm.h> 41 41 #include <errno.h> 42 #include <macros.h> 42 43 43 44 /** Maximal sysinfo path length */ … … 761 762 * character must be null). 762 763 * 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. 766 773 * 767 774 * @param path_ptr Sysinfo path in the user address space. … … 770 777 * to store the binary data. 771 778 * @param buffer_size User space buffer size. 779 * @param size_ptr User space pointer where to store the 780 * binary data size. 772 781 * 773 782 * @return Error code (EOK in case of no error). … … 775 784 */ 776 785 sysarg_t sys_sysinfo_get_data(void *path_ptr, size_t path_size, 777 void *buffer_ptr, size_t buffer_size )786 void *buffer_ptr, size_t buffer_size, size_t *size_ptr) 778 787 { 779 788 int rc; 780 789 781 790 /* 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 784 794 /* 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)); 792 801 } else 793 802 rc = EINVAL; -
uspace/app/trace/syscalls.c
r8befd0a r311bc25 77 77 [SYS_SYSINFO_GET_VALUE] = { "sysinfo_get_value", 3, V_ERRNO }, 78 78 [SYS_SYSINFO_GET_DATA_SIZE] = { "sysinfo_get_data_size", 3, V_ERRNO }, 79 [SYS_SYSINFO_GET_DATA] = { "sysinfo_get_data", 4, V_ERRNO },79 [SYS_SYSINFO_GET_DATA] = { "sysinfo_get_data", 5, V_ERRNO }, 80 80 81 81 [SYS_DEBUG_ENABLE_CONSOLE] = { "debug_enable_console", 0, V_ERRNO }, -
uspace/lib/c/generic/stats.c
r8befd0a r311bc25 36 36 #include <stats.h> 37 37 #include <sysinfo.h> 38 #include <assert.h>39 38 #include <errno.h> 40 39 #include <stdio.h> 41 40 #include <inttypes.h> 41 #include <malloc.h> 42 42 43 43 #define SYSINFO_STATS_MAX_PATH 64 … … 71 71 (stats_cpu_t *) sysinfo_get_data("system.cpus", &size); 72 72 73 assert((size % sizeof(stats_cpu_t)) == 0); 73 if ((size % sizeof(stats_cpu_t)) != 0) { 74 if (stats_cpus != NULL) 75 free(stats_cpus); 76 *count = 0; 77 return NULL; 78 } 74 79 75 80 *count = size / sizeof(stats_cpu_t); … … 91 96 (stats_physmem_t *) sysinfo_get_data("system.physmem", &size); 92 97 93 assert((size == sizeof(stats_physmem_t)) || (size == 0)); 98 if (size != sizeof(stats_physmem_t)) { 99 if (stats_physmem != NULL) 100 free(stats_physmem); 101 return NULL; 102 } 94 103 95 104 return stats_physmem; … … 111 120 (stats_task_t *) sysinfo_get_data("system.tasks", &size); 112 121 113 assert((size % sizeof(stats_task_t)) == 0); 122 if ((size % sizeof(stats_task_t)) != 0) { 123 if (stats_tasks != NULL) 124 free(stats_tasks); 125 *count = 0; 126 return NULL; 127 } 114 128 115 129 *count = size / sizeof(stats_task_t); … … 135 149 (stats_task_t *) sysinfo_get_data(name, &size); 136 150 137 assert((size == sizeof(stats_task_t)) || (size == 0)); 151 if (size != sizeof(stats_task_t)) { 152 if (stats_task != NULL) 153 free(stats_task); 154 return NULL; 155 } 138 156 139 157 return stats_task; … … 155 173 (stats_thread_t *) sysinfo_get_data("system.threads", &size); 156 174 157 assert((size % sizeof(stats_thread_t)) == 0); 175 if ((size % sizeof(stats_thread_t)) != 0) { 176 if (stats_threads != NULL) 177 free(stats_threads); 178 *count = 0; 179 return NULL; 180 } 158 181 159 182 *count = size / sizeof(stats_thread_t); … … 179 202 (stats_thread_t *) sysinfo_get_data(name, &size); 180 203 181 assert((size == sizeof(stats_thread_t)) || (size == 0)); 204 if (size != sizeof(stats_thread_t)) { 205 if (stats_thread != NULL) 206 free(stats_thread); 207 return NULL; 208 } 182 209 183 210 return stats_thread; … … 199 226 (stats_exc_t *) sysinfo_get_data("system.exceptions", &size); 200 227 201 assert((size % sizeof(stats_exc_t)) == 0); 228 if ((size % sizeof(stats_exc_t)) != 0) { 229 if (stats_exceptions != NULL) 230 free(stats_exceptions); 231 *count = 0; 232 return NULL; 233 } 202 234 203 235 *count = size / sizeof(stats_exc_t); … … 217 249 { 218 250 char name[SYSINFO_STATS_MAX_PATH]; 219 snprintf(name, SYSINFO_STATS_MAX_PATH, "system.exceptions s.%u", excn);251 snprintf(name, SYSINFO_STATS_MAX_PATH, "system.exceptions.%u", excn); 220 252 221 253 size_t size = 0; … … 223 255 (stats_exc_t *) sysinfo_get_data(name, &size); 224 256 225 assert((size == sizeof(stats_exc_t)) || (size == 0)); 257 if (size != sizeof(stats_exc_t)) { 258 if (stats_exception != NULL) 259 free(stats_exception); 260 return NULL; 261 } 226 262 227 263 return stats_exception; … … 243 279 (load_t *) sysinfo_get_data("system.load", &size); 244 280 245 assert((size % sizeof(load_t)) == 0); 281 if ((size % sizeof(load_t)) != 0) { 282 if (load != NULL) 283 free(load); 284 *count = 0; 285 return NULL; 286 } 246 287 247 288 *count = size / sizeof(load_t); -
uspace/lib/c/generic/sysinfo.c
r8befd0a r311bc25 96 96 void *sysinfo_get_data(const char *path, size_t *size) 97 97 { 98 /* The binary data size might change during time. 99 Unfortunatelly we cannot allocate the buffer 100 and transfer the data as a single atomic operation. 98 /* 99 * The binary data size might change during time. 100 * Unfortunatelly we cannot allocate the buffer 101 * and transfer the data as a single atomic operation. 102 */ 101 103 102 Let's hope that the number of iterations is bounded 103 in common cases. */ 104 105 void *data = NULL; 106 107 while (true) { 108 /* Get the binary data size */ 109 int ret = sysinfo_get_data_size(path, size); 110 if ((ret != EOK) || (size == 0)) { 111 /* Not a binary data item 112 or an empty item */ 113 break; 114 } 115 116 data = realloc(data, *size); 117 if (data == NULL) 118 break; 119 120 /* Get the data */ 121 ret = __SYSCALL4(SYS_SYSINFO_GET_DATA, (sysarg_t) path, 122 (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size); 123 if (ret == EOK) 124 return data; 125 126 if (ret != ENOMEM) { 127 /* The failure to get the data was not caused 128 by wrong buffer size */ 129 break; 130 } 104 /* Get the binary data size */ 105 int ret = sysinfo_get_data_size(path, size); 106 if ((ret != EOK) || (size == 0)) { 107 /* 108 * Not a binary data item 109 * or an empty item. 110 */ 111 *size = 0; 112 return NULL; 131 113 } 132 114 133 if (data != NULL) 134 free(data); 115 void *data = malloc(*size); 116 if (data == NULL) { 117 *size = 0; 118 return NULL; 119 } 135 120 121 /* Get the data */ 122 size_t sz; 123 ret = __SYSCALL5(SYS_SYSINFO_GET_DATA, (sysarg_t) path, 124 (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size, 125 (sysarg_t) &sz); 126 if (ret == EOK) { 127 *size = sz; 128 return data; 129 } 130 131 free(data); 136 132 *size = 0; 137 133 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.