From df9428991a14d4aaf6bbdd30b94ba9e3a6456555 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Wed, 27 Sep 2023 10:43:36 +0000 Subject: [PATCH] syscall: Z_SYSCALL_MEMORY_ARRAY -> K_SYSCALL_MEMORY_ARRAY Rename macros and do not use Z_ for internal APIs. Signed-off-by: Anas Nashif --- doc/kernel/usermode/syscalls.rst | 10 +++++----- drivers/i2c/i2c_handlers.c | 2 +- drivers/i3c/i3c_handlers.c | 10 +++++----- drivers/serial/uart_handlers.c | 4 ++-- drivers/spi/spi_handlers.c | 2 +- include/zephyr/internal/syscall_handler.h | 10 +++++----- lib/libc/minimal/source/stdout/stdout_console.c | 2 +- subsys/net/lib/sockets/getaddrinfo.c | 2 +- subsys/rtio/rtio_handlers.c | 4 ++-- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/doc/kernel/usermode/syscalls.rst b/doc/kernel/usermode/syscalls.rst index 42dd7dfa06..07629589a4 100644 --- a/doc/kernel/usermode/syscalls.rst +++ b/doc/kernel/usermode/syscalls.rst @@ -299,14 +299,14 @@ Several macros exist to validate arguments: :c:macro:`Z_SYSCALL_MEMORY_READ()` but the calling thread must additionally have write permissions. -* :c:macro:`Z_SYSCALL_MEMORY_ARRAY_READ()` validates an array whose total size +* :c:macro:`K_SYSCALL_MEMORY_ARRAY_READ()` validates an array whose total size is expressed as separate arguments for the number of elements and the element size. This macro correctly accounts for multiplication overflow when computing the total size. The calling thread must have read permissions on the total size. -* :c:macro:`Z_SYSCALL_MEMORY_ARRAY_WRITE()` is the same as - :c:macro:`Z_SYSCALL_MEMORY_ARRAY_READ()` but the calling thread must +* :c:macro:`K_SYSCALL_MEMORY_ARRAY_WRITE()` is the same as + :c:macro:`K_SYSCALL_MEMORY_ARRAY_READ()` but the calling thread must additionally have write permissions. * :c:macro:`K_SYSCALL_VERIFY_MSG()` does a runtime check of some boolean @@ -638,8 +638,8 @@ Helper macros for creating system call verification functions are provided in * :c:macro:`Z_OOPS()` * :c:macro:`Z_SYSCALL_MEMORY_READ()` * :c:macro:`Z_SYSCALL_MEMORY_WRITE()` -* :c:macro:`Z_SYSCALL_MEMORY_ARRAY_READ()` -* :c:macro:`Z_SYSCALL_MEMORY_ARRAY_WRITE()` +* :c:macro:`K_SYSCALL_MEMORY_ARRAY_READ()` +* :c:macro:`K_SYSCALL_MEMORY_ARRAY_WRITE()` * :c:macro:`K_SYSCALL_VERIFY_MSG()` * :c:macro:`Z_SYSCALL_VERIFY` diff --git a/drivers/i2c/i2c_handlers.c b/drivers/i2c/i2c_handlers.c index 1e5a5ee5d7..b1e9906fc6 100644 --- a/drivers/i2c/i2c_handlers.c +++ b/drivers/i2c/i2c_handlers.c @@ -62,7 +62,7 @@ static inline int z_vrfy_i2c_transfer(const struct device *dev, Z_OOPS(Z_SYSCALL_VERIFY(num_msgs >= 1 && num_msgs < 32)); /* We need to be able to read the overall array of messages */ - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_READ(msgs, num_msgs, + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_READ(msgs, num_msgs, sizeof(struct i2c_msg))); return copy_msgs_and_transfer((const struct device *)dev, diff --git a/drivers/i3c/i3c_handlers.c b/drivers/i3c/i3c_handlers.c index 2fa8cff161..9d5cbd4880 100644 --- a/drivers/i3c/i3c_handlers.c +++ b/drivers/i3c/i3c_handlers.c @@ -16,19 +16,19 @@ static inline int z_vrfy_i3c_do_ccc(const struct device *dev, Z_OOPS(Z_SYSCALL_MEMORY_WRITE(payload, sizeof(*payload))); if (payload->ccc.data != NULL) { - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_READ(payload->ccc.data, + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_READ(payload->ccc.data, payload->ccc.data_len, sizeof(*payload->ccc.data))); - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_WRITE(payload->ccc.data, + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_WRITE(payload->ccc.data, payload->ccc.data_len, sizeof(*payload->ccc.data))); } if (payload->targets.payloads != NULL) { - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_READ(payload->targets.payloads, + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_READ(payload->targets.payloads, payload->targets.num_targets, sizeof(*payload->targets.payloads))); - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_WRITE(payload->targets.payloads, + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_WRITE(payload->targets.payloads, payload->targets.num_targets, sizeof(*payload->targets.payloads))); } @@ -72,7 +72,7 @@ static inline int z_vrfy_i3c_transfer(struct i3c_device_desc *target, Z_OOPS(Z_SYSCALL_VERIFY(num_msgs >= 1 && num_msgs < 32)); /* We need to be able to read the overall array of messages */ - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_READ(msgs, num_msgs, + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_READ(msgs, num_msgs, sizeof(struct i3c_msg))); return copy_i3c_msgs_and_transfer((struct i3c_device_desc *)target, diff --git a/drivers/serial/uart_handlers.c b/drivers/serial/uart_handlers.c index 4f2ac834f7..6ce3107cab 100644 --- a/drivers/serial/uart_handlers.c +++ b/drivers/serial/uart_handlers.c @@ -102,7 +102,7 @@ static inline int z_vrfy_uart_tx_u16(const struct device *dev, size_t len, int32_t timeout) { Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, tx)); - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_READ(buf, len, sizeof(uint16_t))); + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_READ(buf, len, sizeof(uint16_t))); return z_impl_uart_tx_u16(dev, buf, len, timeout); } #include @@ -127,7 +127,7 @@ static inline int z_vrfy_uart_rx_enable_u16(const struct device *dev, size_t len, int32_t timeout) { Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, rx_enable)); - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_WRITE(buf, len, sizeof(uint16_t))); + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_WRITE(buf, len, sizeof(uint16_t))); return z_impl_uart_rx_enable_u16(dev, buf, len, timeout); } #include diff --git a/drivers/spi/spi_handlers.c b/drivers/spi/spi_handlers.c index dd1a1eb7d6..1ae5d69f37 100644 --- a/drivers/spi/spi_handlers.c +++ b/drivers/spi/spi_handlers.c @@ -23,7 +23,7 @@ static struct spi_buf_set *copy_and_check(struct spi_buf_set *bufs, } /* Validate the array of struct spi_buf instances */ - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_READ(bufs->buffers, + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_READ(bufs->buffers, bufs->count, sizeof(struct spi_buf))); diff --git a/include/zephyr/internal/syscall_handler.h b/include/zephyr/internal/syscall_handler.h index adb4f1cbb7..557437c023 100644 --- a/include/zephyr/internal/syscall_handler.h +++ b/include/zephyr/internal/syscall_handler.h @@ -386,7 +386,7 @@ int z_user_string_copy(char *dst, const char *src, size_t maxlen); #define Z_SYSCALL_MEMORY_WRITE(ptr, size) \ Z_SYSCALL_MEMORY(ptr, size, 1) -#define Z_SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, write) \ +#define K_SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, write) \ ({ \ size_t product; \ K_SYSCALL_VERIFY_MSG(!size_mul_overflow((size_t)(nmemb), \ @@ -409,8 +409,8 @@ int z_user_string_copy(char *dst, const char *src, size_t maxlen); * @param size Size of each array element * @return 0 on success, nonzero on failure */ -#define Z_SYSCALL_MEMORY_ARRAY_READ(ptr, nmemb, size) \ - Z_SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, 0) +#define K_SYSCALL_MEMORY_ARRAY_READ(ptr, nmemb, size) \ + K_SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, 0) /** * @brief Validate user thread has read/write permission for sized array @@ -424,8 +424,8 @@ int z_user_string_copy(char *dst, const char *src, size_t maxlen); * @param size Size of each array element * @return 0 on success, nonzero on failure */ -#define Z_SYSCALL_MEMORY_ARRAY_WRITE(ptr, nmemb, size) \ - Z_SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, 1) +#define K_SYSCALL_MEMORY_ARRAY_WRITE(ptr, nmemb, size) \ + K_SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, 1) static inline int z_obj_validation_check(struct k_object *ko, const void *obj, diff --git a/lib/libc/minimal/source/stdout/stdout_console.c b/lib/libc/minimal/source/stdout/stdout_console.c index fd09b87110..ab3777fbf9 100644 --- a/lib/libc/minimal/source/stdout/stdout_console.c +++ b/lib/libc/minimal/source/stdout/stdout_console.c @@ -101,7 +101,7 @@ static inline size_t z_vrfy_zephyr_fwrite(const void *ZRESTRICT ptr, FILE *ZRESTRICT stream) { - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_READ(ptr, nitems, size)); + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_READ(ptr, nitems, size)); return z_impl_zephyr_fwrite((const void *ZRESTRICT)ptr, size, nitems, (FILE *ZRESTRICT)stream); } diff --git a/subsys/net/lib/sockets/getaddrinfo.c b/subsys/net/lib/sockets/getaddrinfo.c index 2acee2734e..5bb3f6c012 100644 --- a/subsys/net/lib/sockets/getaddrinfo.c +++ b/subsys/net/lib/sockets/getaddrinfo.c @@ -284,7 +284,7 @@ static inline int z_vrfy_z_zsock_getaddrinfo_internal(const char *host, Z_OOPS(z_user_from_copy(&hints_copy, (void *)hints, sizeof(hints_copy))); } - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_WRITE(res, AI_ARR_MAX, sizeof(struct zsock_addrinfo))); + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_WRITE(res, AI_ARR_MAX, sizeof(struct zsock_addrinfo))); if (service) { service_copy = z_user_string_alloc_copy((char *)service, 64); diff --git a/subsys/rtio/rtio_handlers.c b/subsys/rtio/rtio_handlers.c index 39ead48300..f49d9488b8 100644 --- a/subsys/rtio/rtio_handlers.c +++ b/subsys/rtio/rtio_handlers.c @@ -81,7 +81,7 @@ static inline int z_vrfy_rtio_sqe_copy_in_get_handles(struct rtio *r, const stru { Z_OOPS(Z_SYSCALL_OBJ(r, K_OBJ_RTIO)); - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_READ(sqes, sqe_count, sizeof(struct rtio_sqe))); + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_READ(sqes, sqe_count, sizeof(struct rtio_sqe))); struct rtio_sqe *sqe; uint32_t acquirable = rtio_sqe_acquirable(r); @@ -116,7 +116,7 @@ static inline int z_vrfy_rtio_cqe_copy_out(struct rtio *r, { Z_OOPS(Z_SYSCALL_OBJ(r, K_OBJ_RTIO)); - Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_WRITE(cqes, cqe_count, sizeof(struct rtio_cqe))); + Z_OOPS(K_SYSCALL_MEMORY_ARRAY_WRITE(cqes, cqe_count, sizeof(struct rtio_cqe))); return z_impl_rtio_cqe_copy_out(r, cqes, cqe_count, timeout); }