8#ifndef ZEPHYR_INCLUDE_SYSCALL_HANDLER_H_
9#define ZEPHYR_INCLUDE_SYSCALL_HANDLER_H_
11#ifdef CONFIG_USERSPACE
20extern const _k_syscall_handler_t _k_syscall_table[K_SYSCALL_LIMIT];
49static inline bool z_is_in_user_syscall(
void)
57 return !
k_is_in_isr() && _current->syscall_frame != NULL;
81int z_object_validate(
struct z_object *ko,
enum k_objects otype,
82 enum _obj_init_check init);
92extern void z_dump_object_error(
int retval,
const void *obj,
93 struct z_object *ko,
enum k_objects otype);
105extern struct z_object *z_object_find(
const void *obj);
107typedef void (*_wordlist_cb_func_t)(
struct z_object *ko,
void *context);
115extern void z_object_wordlist_foreach(_wordlist_cb_func_t func,
void *context);
123extern void z_thread_perms_inherit(
struct k_thread *parent,
132extern void z_thread_perms_set(
struct z_object *ko,
struct k_thread *
thread);
140extern void z_thread_perms_clear(
struct z_object *ko,
struct k_thread *
thread);
160void z_object_uninit(
const void *obj);
179void z_object_recycle(
const void *obj);
204static inline size_t z_user_string_nlen(
const char *src,
size_t maxlen,
225extern void *z_user_alloc_from_copy(
const void *src,
size_t size);
240extern int z_user_from_copy(
void *dst,
const void *src,
size_t size);
255extern int z_user_to_copy(
void *dst,
const void *src,
size_t size);
271extern char *z_user_string_alloc_copy(
const char *src,
size_t maxlen);
289extern int z_user_string_copy(
char *dst,
const char *src,
size_t maxlen);
291#define Z_OOPS(expr) \
294 arch_syscall_oops(_current->syscall_frame); \
311#define Z_SYSCALL_VERIFY_MSG(expr, fmt, ...) ({ \
312 bool expr_copy = !(expr); \
314 LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); \
315 LOG_ERR("syscall %s failed check: " fmt, \
316 __func__, ##__VA_ARGS__); \
330#define Z_SYSCALL_VERIFY(expr) Z_SYSCALL_VERIFY_MSG(expr, #expr)
348#define Z_SYSCALL_MEMORY(ptr, size, write) \
349 Z_SYSCALL_VERIFY_MSG(arch_buffer_validate((void *)ptr, size, write) \
351 "Memory region %p (size %zu) %s access denied", \
352 (void *)(ptr), (size_t)(size), \
353 write ? "write" : "read")
368#define Z_SYSCALL_MEMORY_READ(ptr, size) \
369 Z_SYSCALL_MEMORY(ptr, size, 0)
384#define Z_SYSCALL_MEMORY_WRITE(ptr, size) \
385 Z_SYSCALL_MEMORY(ptr, size, 1)
387#define Z_SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, write) \
390 Z_SYSCALL_VERIFY_MSG(!size_mul_overflow((size_t)(nmemb), \
393 "%zux%zu array is too large", \
394 (size_t)(nmemb), (size_t)(size)) || \
395 Z_SYSCALL_MEMORY(ptr, product, write); \
410#define Z_SYSCALL_MEMORY_ARRAY_READ(ptr, nmemb, size) \
411 Z_SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, 0)
425#define Z_SYSCALL_MEMORY_ARRAY_WRITE(ptr, nmemb, size) \
426 Z_SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, 1)
428static inline int z_obj_validation_check(
struct z_object *ko,
431 enum _obj_init_check init)
435 ret = z_object_validate(ko, otype, init);
439 z_dump_object_error(
ret, obj, ko, otype);
448#define Z_SYSCALL_IS_OBJ(ptr, type, init) \
449 Z_SYSCALL_VERIFY_MSG(z_obj_validation_check( \
450 z_object_find((const void *)ptr), \
452 type, init) == 0, "access denied")
464#define Z_SYSCALL_DRIVER_OP(ptr, api_name, op) \
466 struct api_name *__device__ = (struct api_name *) \
467 ((const struct device *)ptr)->api; \
468 Z_SYSCALL_VERIFY_MSG(__device__->op != NULL, \
469 "Operation %s not defined for driver " \
492#define Z_SYSCALL_SPECIFIC_DRIVER(_device, _dtype, _api) \
494 const struct device *_dev = (const struct device *)_device; \
495 Z_SYSCALL_OBJ(_dev, _dtype) || \
496 Z_SYSCALL_VERIFY_MSG(_dev->api == _api, \
497 "API structure mismatch"); \
511#define Z_SYSCALL_OBJ(ptr, type) \
512 Z_SYSCALL_IS_OBJ(ptr, type, _OBJ_INIT_TRUE)
525#define Z_SYSCALL_OBJ_INIT(ptr, type) \
526 Z_SYSCALL_IS_OBJ(ptr, type, _OBJ_INIT_ANY)
541#define Z_SYSCALL_OBJ_NEVER_INIT(ptr, type) \
542 Z_SYSCALL_IS_OBJ(ptr, type, _OBJ_INIT_FALSE)
544#include <driver-validation.h>
static struct k_thread thread[2]
Definition: atomic.c:22
void
Definition: eswifi_shell.c:15
size_t arch_user_string_nlen(const char *s, size_t maxsize, int *err)
Safely take the length of a potentially bad string.
bool k_is_in_isr(void)
Determine if code is running at interrupt level.
k_objects
Kernel Object Types.
Definition: kobject.h:27
static ZTEST_BMEM volatile int ret
Definition: k_float_disable.c:28