From 526807c33b6688faca2419fb5fa91d20a15f4c08 Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Thu, 28 Mar 2019 15:17:31 -0700 Subject: [PATCH] userspace: add const qualifiers to user copy fns The source data is never modified. Signed-off-by: Andrew Boie --- kernel/include/syscall_handler.h | 10 +++++----- kernel/userspace.c | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/kernel/include/syscall_handler.h b/kernel/include/syscall_handler.h index a206c3ff06..5ce456470c 100644 --- a/kernel/include/syscall_handler.h +++ b/kernel/include/syscall_handler.h @@ -189,7 +189,7 @@ static inline size_t z_user_string_nlen(const char *src, size_t maxlen, * @return An allocated buffer with the data copied within it, or NULL * if some error condition occurred */ -extern void *z_user_alloc_from_copy(void *src, size_t size); +extern void *z_user_alloc_from_copy(const void *src, size_t size); /** * @brief Copy data from user mode @@ -204,7 +204,7 @@ extern void *z_user_alloc_from_copy(void *src, size_t size); * @retval 0 On success * @retval EFAULT On memory access error */ -extern int z_user_from_copy(void *dst, void *src, size_t size); +extern int z_user_from_copy(void *dst, const void *src, size_t size); /** * @brief Copy data to user mode @@ -219,7 +219,7 @@ extern int z_user_from_copy(void *dst, void *src, size_t size); * @retval 0 On success * @retval EFAULT On memory access error */ -extern int z_user_to_copy(void *dst, void *src, size_t size); +extern int z_user_to_copy(void *dst, const void *src, size_t size); /** * @brief Copy a C string from userspace into a resource pool allocation @@ -235,7 +235,7 @@ extern int z_user_to_copy(void *dst, void *src, size_t size); * @param maxlen Maximum size of the string including trailing NULL * @return The duplicated string, or NULL if an error occurred. */ -extern char *z_user_string_alloc_copy(char *src, size_t maxlen); +extern char *z_user_string_alloc_copy(const char *src, size_t maxlen); /** * @brief Copy a C string from userspace into a provided buffer @@ -253,7 +253,7 @@ extern char *z_user_string_alloc_copy(char *src, size_t maxlen); * to maxlen * @retval EFAULT On memory access error */ -extern int z_user_string_copy(char *dst, char *src, size_t maxlen); +extern int z_user_string_copy(char *dst, const char *src, size_t maxlen); #define Z_OOPS(expr) \ do { \ diff --git a/kernel/userspace.c b/kernel/userspace.c index 5c95ae745e..8e1611fca5 100644 --- a/kernel/userspace.c +++ b/kernel/userspace.c @@ -632,7 +632,7 @@ void z_object_uninit(void *obj) /* * Copy to/from helper functions used in syscall handlers */ -void *z_user_alloc_from_copy(void *src, size_t size) +void *z_user_alloc_from_copy(const void *src, size_t size) { void *dst = NULL; k_spinlock_key_t key = k_spin_lock(&ucopy_lock); @@ -654,7 +654,7 @@ out_err: return dst; } -static int user_copy(void *dst, void *src, size_t size, bool to_user) +static int user_copy(void *dst, const void *src, size_t size, bool to_user) { int ret = EFAULT; k_spinlock_key_t key = k_spin_lock(&ucopy_lock); @@ -672,17 +672,17 @@ out_err: return ret; } -int z_user_from_copy(void *dst, void *src, size_t size) +int z_user_from_copy(void *dst, const void *src, size_t size) { return user_copy(dst, src, size, false); } -int z_user_to_copy(void *dst, void *src, size_t size) +int z_user_to_copy(void *dst, const void *src, size_t size) { return user_copy(dst, src, size, true); } -char *z_user_string_alloc_copy(char *src, size_t maxlen) +char *z_user_string_alloc_copy(const char *src, size_t maxlen) { unsigned long actual_len; int err; @@ -709,7 +709,7 @@ out: return ret; } -int z_user_string_copy(char *dst, char *src, size_t maxlen) +int z_user_string_copy(char *dst, const char *src, size_t maxlen) { unsigned long actual_len; int ret, err;