diff --git a/include/net/socket.h b/include/net/socket.h index 63228c022e6..1cebc807364 100644 --- a/include/net/socket.h +++ b/include/net/socket.h @@ -382,7 +382,7 @@ int zsock_setsockopt(int sock, int level, int optname, * if :option:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined. * @endrststar */ -int zsock_gethostname(char *buf, size_t len); +__syscall int zsock_gethostname(char *buf, size_t len); /** * @brief Convert network address from internal to numeric ASCII form diff --git a/subsys/net/lib/sockets/sockets_misc.c b/subsys/net/lib/sockets/sockets_misc.c index c950c71e688..c2778839dca 100644 --- a/subsys/net/lib/sockets/sockets_misc.c +++ b/subsys/net/lib/sockets/sockets_misc.c @@ -6,8 +6,9 @@ #include #include +#include -int zsock_gethostname(char *buf, size_t len) +int z_impl_zsock_gethostname(char *buf, size_t len) { const char *p = net_hostname_get(); @@ -15,3 +16,11 @@ int zsock_gethostname(char *buf, size_t len) return 0; } + +#ifdef CONFIG_USERSPACE +Z_SYSCALL_HANDLER(zsock_gethostname, buf, len) +{ + Z_OOPS(Z_SYSCALL_MEMORY_WRITE(buf, len)); + return z_impl_zsock_gethostname((char *)buf, len); +} +#endif diff --git a/tests/net/socket/misc/prj.conf b/tests/net/socket/misc/prj.conf index 0747f020fec..98700fa762a 100644 --- a/tests/net/socket/misc/prj.conf +++ b/tests/net/socket/misc/prj.conf @@ -23,7 +23,6 @@ CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" CONFIG_MAIN_STACK_SIZE=2048 CONFIG_ZTEST=y -CONFIG_TEST_USERSPACE=n # User mode requirements CONFIG_HEAP_MEM_POOL_SIZE=128 diff --git a/tests/net/socket/misc/src/main.c b/tests/net/socket/misc/src/main.c index 779e1f1618a..58651da3148 100644 --- a/tests/net/socket/misc/src/main.c +++ b/tests/net/socket/misc/src/main.c @@ -16,7 +16,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL); void test_gethostname(void) { - static char buf[80]; + static ZTEST_BMEM char buf[80]; int res; res = gethostname(buf, sizeof(buf));