Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion arch/sim/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ ifeq ($(CONFIG_FS_LARGEFILE),y)
endif

HOSTSRCS = sim_hostirq.c sim_hostmemory.c sim_hostmisc.c sim_hosttime.c sim_hostuart.c
HOSTSRCS += sim_hostfs.c sim_errno.c
HOSTSRCS += sim_hostfs.c sim_hostsocket.c sim_errno.c
ifeq ($(CONFIG_HOST_LINUX),y)
HOSTSRCS += sim_hostepoll.c
endif

hostfs.h: $(TOPDIR)/include/nuttx/fs/hostfs.h
@echo "CP: $<"
Expand Down
18 changes: 18 additions & 0 deletions arch/sim/src/nuttx-names.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ NXSYMBOLS(closedir)
NXSYMBOLS(connect)
NXSYMBOLS(dlsym)
NXSYMBOLS(dup)
NXSYMBOLS(epoll_create1)
NXSYMBOLS(epoll_ctl)
NXSYMBOLS(epoll_wait)
NXSYMBOLS(exit)
NXSYMBOLS(fchmod)
NXSYMBOLS(fchown)
Expand All @@ -59,8 +62,11 @@ NXSYMBOLS(fdopen)
NXSYMBOLS(feof)
NXSYMBOLS(fopen)
NXSYMBOLS(fprintf)
NXSYMBOLS(fgets)
NXSYMBOLS(fread)
NXSYMBOLS(free)
NXSYMBOLS(freeaddrinfo)
NXSYMBOLS(freeifaddrs)
NXSYMBOLS(fseek)
NXSYMBOLS(fstat)
NXSYMBOLS(fsync)
Expand All @@ -71,9 +77,14 @@ NXSYMBOLS(fwrite)
NXSYMBOLS(getpeername)
NXSYMBOLS(getsockname)
NXSYMBOLS(getenv)
NXSYMBOLS(getaddrinfo)
NXSYMBOLS(getifaddrs)
NXSYMBOLS(getpid)
NXSYMBOLS(getsockopt)
NXSYMBOLS(htons)
NXSYMBOLS(if_nametoindex)
NXSYMBOLS(inet_ntop)
NXSYMBOLS(inet_pton)
NXSYMBOLS(ioctl)
NXSYMBOLS(listen)
NXSYMBOLS(longjmp)
Expand All @@ -83,11 +94,13 @@ NXSYMBOLS(malloc_size)
NXSYMBOLS(malloc_usable_size)
NXSYMBOLS(memchr)
NXSYMBOLS(memcpy)
NXSYMBOLS(memset)
NXSYMBOLS(memfd_create)
NXSYMBOLS(mkdir)
NXSYMBOLS(mmap)
NXSYMBOLS(mprotect)
NXSYMBOLS(munmap)
NXSYMBOLS(ntohs)
NXSYMBOLS(open)
NXSYMBOLS(opendir)
NXSYMBOLS(pclose)
Expand All @@ -97,6 +110,7 @@ NXSYMBOLS(poll)
NXSYMBOLS(popen)
NXSYMBOLS(posix_memalign)
NXSYMBOLS(posix_spawn)
NXSYMBOLS(pread)
NXSYMBOLS(pthread_attr_init)
NXSYMBOLS(pthread_attr_setstack)
NXSYMBOLS(pthread_attr_destroy)
Expand All @@ -120,18 +134,22 @@ NXSYMBOLS(pthread_setspecific)
#endif
NXSYMBOLS(pthread_self)
NXSYMBOLS(pthread_sigmask)
NXSYMBOLS(pwrite)
NXSYMBOLS(puts)
NXSYMBOLS(read)
NXSYMBOLS(readdir)
NXSYMBOLS(readlink)
NXSYMBOLS(readv)
NXSYMBOLS(realloc)
NXSYMBOLS(recv)
NXSYMBOLS(recvfrom)
NXSYMBOLS(remove)
NXSYMBOLS(rename)
NXSYMBOLS(rewinddir)
NXSYMBOLS(rmdir)
NXSYMBOLS(sched_yield)
NXSYMBOLS(select)
NXSYMBOLS(send)
NXSYMBOLS(sendmsg)
NXSYMBOLS(sendto)
NXSYMBOLS(setbuf)
Expand Down
116 changes: 116 additions & 0 deletions arch/sim/src/sim/posix/sim_hostepoll.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/****************************************************************************
* arch/sim/src/sim/posix/sim_hostepoll.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <sys/epoll.h>

#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "sim_internal.h"
#include "sim_hostepoll.h"

/****************************************************************************
* Public Functions
****************************************************************************/

int host_epoll_create1(int flags)
{
int hostflags = 0;
int ret;

if (flags & NUTTX_EPOLL_CLOEXEC)
{
hostflags |= EPOLL_CLOEXEC;
flags &= ~NUTTX_EPOLL_CLOEXEC;
}

if (flags != 0)
{
return -EINVAL;
}

ret = epoll_create1(hostflags);
return ret < 0 ? host_errno_convert(-errno) : ret;
}

int host_epoll_ctl(int epoll_fd, int op, int fd, uint32_t events,
uintptr_t data)
{
struct epoll_event event;
struct epoll_event *eventptr = NULL;
int ret;

memset(&event, 0, sizeof(event));

if (op != EPOLL_CTL_DEL)
{
event.events = events;
event.data.ptr = (void *)data;
eventptr = &event;
}

ret = epoll_ctl(epoll_fd, op, fd, eventptr);
return ret < 0 ? host_errno_convert(-errno) : ret;
}

int host_epoll_wait(int epoll_fd, struct host_epoll_event *events,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

epoll_wait will block the whole OS, not just the current thread, which is definitely not you want behaviour.

int maxevents, int timeout_ms)
{
struct epoll_event *hostevents;
int ret;
int i;

if (events == NULL || maxevents <= 0 ||
(size_t)maxevents > SIZE_MAX / sizeof(*hostevents))
{
return -EINVAL;
}

hostevents = malloc(maxevents * sizeof(*hostevents));
if (hostevents == NULL)
{
return -ENOMEM;
}

ret = epoll_wait(epoll_fd, hostevents, maxevents, timeout_ms);
if (ret < 0)
{
ret = host_errno_convert(-errno);
goto out;
}

for (i = 0; i < ret; i++)
{
events[i].events = hostevents[i].events;
events[i].data = (uintptr_t)hostevents[i].data.ptr;
}

out:
free(hostevents);
return ret;
}
Loading
Loading