native_simulator: Get latest from upstream

Align with native_simulator's upstream main
26524aa55198807a37e012e5847f3975750d1716

Which includes:
* 26524aa Add new nsi_errno optional component
* 007a1c8 nsi_utils.h: Add NSI_ARRAY_SIZE() macro

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2025-02-24 13:11:07 +01:00 committed by Benjamin Cabé
commit 83c65e9d07
3 changed files with 241 additions and 0 deletions

View file

@ -0,0 +1,109 @@
/**
* Copyright (c) 2023-2024 Marcin Niestroj
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NSI_COMMON_SRC_NSI_ERRNO_H
#define NSI_COMMON_SRC_NSI_ERRNO_H
/*
* Optional utility module to convert errno values from one libC to another,
* where one libC would normally be the embedded libC used to build the embedded code and the other
* the host libC.
*
* It works by converting the errno values from/to either libC into an intermediate set of values
* (NSI_ERRNO_MID_E*).
* When two components would like to exchange errors, they should include nsi_errno.h and build and
* link to nsi_errno.c in their context. And convert to/from these intermediate error values
* before passing them to/after receiving them from the other side by using
* nsi_errno_to_mid() / nsi_errno_from_mid().
*/
#include <errno.h>
#define NSI_ERRNO_MID_EPERM 1 /**< Not owner */
#define NSI_ERRNO_MID_ENOENT 2 /**< No such file or directory */
#define NSI_ERRNO_MID_ESRCH 3 /**< No such context */
#define NSI_ERRNO_MID_EINTR 4 /**< Interrupted system call */
#define NSI_ERRNO_MID_EIO 5 /**< I/O error */
#define NSI_ERRNO_MID_ENXIO 6 /**< No such device or address */
#define NSI_ERRNO_MID_E2BIG 7 /**< Arg list too long */
#define NSI_ERRNO_MID_ENOEXEC 8 /**< Exec format error */
#define NSI_ERRNO_MID_EBADF 9 /**< Bad file number */
#define NSI_ERRNO_MID_ECHILD 10 /**< No children */
#define NSI_ERRNO_MID_EAGAIN 11 /**< No more contexts */
#define NSI_ERRNO_MID_ENOMEM 12 /**< Not enough core */
#define NSI_ERRNO_MID_EACCES 13 /**< Permission denied */
#define NSI_ERRNO_MID_EFAULT 14 /**< Bad address */
#define NSI_ERRNO_MID_ENOTBLK 15 /**< Block device required */
#define NSI_ERRNO_MID_EBUSY 16 /**< Mount device busy */
#define NSI_ERRNO_MID_EEXIST 17 /**< File exists */
#define NSI_ERRNO_MID_EXDEV 18 /**< Cross-device link */
#define NSI_ERRNO_MID_ENODEV 19 /**< No such device */
#define NSI_ERRNO_MID_ENOTDIR 20 /**< Not a directory */
#define NSI_ERRNO_MID_EISDIR 21 /**< Is a directory */
#define NSI_ERRNO_MID_EINVAL 22 /**< Invalid argument */
#define NSI_ERRNO_MID_ENFILE 23 /**< File table overflow */
#define NSI_ERRNO_MID_EMFILE 24 /**< Too many open files */
#define NSI_ERRNO_MID_ENOTTY 25 /**< Not a typewriter */
#define NSI_ERRNO_MID_ETXTBSY 26 /**< Text file busy */
#define NSI_ERRNO_MID_EFBIG 27 /**< File too large */
#define NSI_ERRNO_MID_ENOSPC 28 /**< No space left on device */
#define NSI_ERRNO_MID_ESPIPE 29 /**< Illegal seek */
#define NSI_ERRNO_MID_EROFS 30 /**< Read-only file system */
#define NSI_ERRNO_MID_EMLINK 31 /**< Too many links */
#define NSI_ERRNO_MID_EPIPE 32 /**< Broken pipe */
#define NSI_ERRNO_MID_EDOM 33 /**< Argument too large */
#define NSI_ERRNO_MID_ERANGE 34 /**< Result too large */
#define NSI_ERRNO_MID_ENOMSG 35 /**< Unexpected message type */
#define NSI_ERRNO_MID_EDEADLK 45 /**< Resource deadlock avoided */
#define NSI_ERRNO_MID_ENOLCK 46 /**< No locks available */
#define NSI_ERRNO_MID_ENOSTR 60 /**< STREAMS device required */
#define NSI_ERRNO_MID_ENODATA 61 /**< Missing expected message data */
#define NSI_ERRNO_MID_ETIME 62 /**< STREAMS timeout occurred */
#define NSI_ERRNO_MID_ENOSR 63 /**< Insufficient memory */
#define NSI_ERRNO_MID_EPROTO 71 /**< Generic STREAMS error */
#define NSI_ERRNO_MID_EBADMSG 77 /**< Invalid STREAMS message */
#define NSI_ERRNO_MID_ENOSYS 88 /**< Function not implemented */
#define NSI_ERRNO_MID_ENOTEMPTY 90 /**< Directory not empty */
#define NSI_ERRNO_MID_ENAMETOOLONG 91 /**< File name too long */
#define NSI_ERRNO_MID_ELOOP 92 /**< Too many levels of symbolic links */
#define NSI_ERRNO_MID_EOPNOTSUPP 95 /**< Operation not supported on socket */
#define NSI_ERRNO_MID_EPFNOSUPPORT 96 /**< Protocol family not supported */
#define NSI_ERRNO_MID_ECONNRESET 104 /**< Connection reset by peer */
#define NSI_ERRNO_MID_ENOBUFS 105 /**< No buffer space available */
#define NSI_ERRNO_MID_EAFNOSUPPORT 106 /**< Addr family not supported */
#define NSI_ERRNO_MID_EPROTOTYPE 107 /**< Protocol wrong type for socket */
#define NSI_ERRNO_MID_ENOTSOCK 108 /**< Socket operation on non-socket */
#define NSI_ERRNO_MID_ENOPROTOOPT 109 /**< Protocol not available */
#define NSI_ERRNO_MID_ESHUTDOWN 110 /**< Can't send after socket shutdown */
#define NSI_ERRNO_MID_ECONNREFUSED 111 /**< Connection refused */
#define NSI_ERRNO_MID_EADDRINUSE 112 /**< Address already in use */
#define NSI_ERRNO_MID_ECONNABORTED 113 /**< Software caused connection abort */
#define NSI_ERRNO_MID_ENETUNREACH 114 /**< Network is unreachable */
#define NSI_ERRNO_MID_ENETDOWN 115 /**< Network is down */
#define NSI_ERRNO_MID_ETIMEDOUT 116 /**< Connection timed out */
#define NSI_ERRNO_MID_EHOSTDOWN 117 /**< Host is down */
#define NSI_ERRNO_MID_EHOSTUNREACH 118 /**< No route to host */
#define NSI_ERRNO_MID_EINPROGRESS 119 /**< Operation now in progress */
#define NSI_ERRNO_MID_EALREADY 120 /**< Operation already in progress */
#define NSI_ERRNO_MID_EDESTADDRREQ 121 /**< Destination address required */
#define NSI_ERRNO_MID_EMSGSIZE 122 /**< Message size */
#define NSI_ERRNO_MID_EPROTONOSUPPORT 123 /**< Protocol not supported */
#define NSI_ERRNO_MID_ESOCKTNOSUPPORT 124 /**< Socket type not supported */
#define NSI_ERRNO_MID_EADDRNOTAVAIL 125 /**< Can't assign requested address */
#define NSI_ERRNO_MID_ENETRESET 126 /**< Network dropped connection on reset */
#define NSI_ERRNO_MID_EISCONN 127 /**< Socket is already connected */
#define NSI_ERRNO_MID_ENOTCONN 128 /**< Socket is not connected */
#define NSI_ERRNO_MID_ETOOMANYREFS 129 /**< Too many references: can't splice */
#define NSI_ERRNO_MID_ENOTSUP 134 /**< Unsupported value */
#define NSI_ERRNO_MID_EILSEQ 138 /**< Illegal byte sequence */
#define NSI_ERRNO_MID_EOVERFLOW 139 /**< Value overflow */
#define NSI_ERRNO_MID_ECANCELED 140 /**< Operation canceled */
int nsi_errno_to_mid(int err);
int nsi_errno_from_mid(int err);
#endif /* NSI_COMMON_SRC_NSI_ERRNO_H */

View file

@ -21,6 +21,8 @@
#define NSI_MAX(a, b) (((a) > (b)) ? (a) : (b))
#define NSI_MIN(a, b) (((a) < (b)) ? (a) : (b))
#define NSI_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#ifndef NSI_ARG_UNUSED
#define NSI_ARG_UNUSED(x) (void)(x)
#endif

View file

@ -0,0 +1,130 @@
/**
* Copyright (c) 2023-2024 Marcin Niestroj
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "nsi_errno.h"
#include "nsi_utils.h"
struct nsi_errno_mid_map {
/** Embedded/host error code */
int err;
/** NSI_errno middleground error code */
int mid_err;
};
#define ERR(_name) {_name, NSI_ERRNO_MID_##_name}
static const struct nsi_errno_mid_map map[] = {
ERR(EPERM),
ERR(ENOENT),
ERR(ESRCH),
ERR(EINTR),
ERR(EIO),
ERR(ENXIO),
ERR(E2BIG),
ERR(ENOEXEC),
ERR(EBADF),
ERR(ECHILD),
ERR(EAGAIN),
ERR(ENOMEM),
ERR(EACCES),
ERR(EFAULT),
ERR(ENOTBLK),
ERR(EBUSY),
ERR(EEXIST),
ERR(EXDEV),
ERR(ENODEV),
ERR(ENOTDIR),
ERR(EISDIR),
ERR(EINVAL),
ERR(ENFILE),
ERR(EMFILE),
ERR(ENOTTY),
ERR(ETXTBSY),
ERR(EFBIG),
ERR(ENOSPC),
ERR(ESPIPE),
ERR(EROFS),
ERR(EMLINK),
ERR(EPIPE),
ERR(EDOM),
ERR(ERANGE),
ERR(ENOMSG),
ERR(EDEADLK),
ERR(ENOLCK),
ERR(ENOSTR),
ERR(ENODATA),
ERR(ETIME),
ERR(ENOSR),
ERR(EPROTO),
ERR(EBADMSG),
ERR(ENOSYS),
ERR(ENOTEMPTY),
ERR(ENAMETOOLONG),
ERR(ELOOP),
ERR(EOPNOTSUPP),
ERR(EPFNOSUPPORT),
ERR(ECONNRESET),
ERR(ENOBUFS),
ERR(EAFNOSUPPORT),
ERR(EPROTOTYPE),
ERR(ENOTSOCK),
ERR(ENOPROTOOPT),
ERR(ESHUTDOWN),
ERR(ECONNREFUSED),
ERR(EADDRINUSE),
ERR(ECONNABORTED),
ERR(ENETUNREACH),
ERR(ENETDOWN),
ERR(ETIMEDOUT),
ERR(EHOSTDOWN),
ERR(EHOSTUNREACH),
ERR(EINPROGRESS),
ERR(EALREADY),
ERR(EDESTADDRREQ),
ERR(EMSGSIZE),
ERR(EPROTONOSUPPORT),
ERR(ESOCKTNOSUPPORT),
ERR(EADDRNOTAVAIL),
ERR(ENETRESET),
ERR(EISCONN),
ERR(ENOTCONN),
ERR(ETOOMANYREFS),
ERR(ENOTSUP),
ERR(EILSEQ),
ERR(EOVERFLOW),
ERR(ECANCELED),
};
int nsi_errno_to_mid(int err)
{
if (err == 0) {
return err;
}
for (int i = 0; i < NSI_ARRAY_SIZE(map); i++) {
if (map[i].err == err) {
return map[i].mid_err;
}
}
return err;
}
int nsi_errno_from_mid(int err)
{
if (err == 0) {
return err;
}
for (int i = 0; i < NSI_ARRAY_SIZE(map); i++) {
if (map[i].mid_err == err) {
return map[i].err;
}
}
return err;
}