net: add missing syscall for gethostname()

We need all the socket APIs to work from user mode.
tests/net/socket/misc now runs in userspace.

Fixes: #15227

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2019-04-05 14:53:49 -07:00 committed by Anas Nashif
parent 1d0369f606
commit ce6b80470d
4 changed files with 12 additions and 4 deletions

View File

@ -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

View File

@ -6,8 +6,9 @@
#include <errno.h>
#include <net/socket.h>
#include <syscall_handler.h>
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

View File

@ -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

View File

@ -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));