summaryrefslogtreecommitdiffhomepage
path: root/src/internal
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-05-20 21:59:12 +0000
committermidipix <writeonce@midipix.org>2018-05-21 02:23:31 -0400
commitda20d860b28d7b3c1085964b784f58772c7ba263 (patch)
treeb16570e9188530ddd04537e0486542a64dc8102e /src/internal
parentc59ae6812f148839a5d07e1dd266c12fa7f3b2f5 (diff)
downloadntux-da20d860b28d7b3c1085964b784f58772c7ba263.tar.bz2
ntux-da20d860b28d7b3c1085964b784f58772c7ba263.tar.xz
driver & output: error info vector, error strings: initial implementation.
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/ntux_driver_impl.h28
-rw-r--r--src/internal/ntux_errinfo_impl.c66
-rw-r--r--src/internal/ntux_errinfo_impl.h96
-rw-r--r--src/internal/ntux_nolibc_impl.h2
-rw-r--r--src/internal/ntux_ntaio_impl.c5
-rw-r--r--src/internal/ntux_strerr_impl.c165
-rw-r--r--src/internal/ntux_strerr_impl.h6
7 files changed, 368 insertions, 0 deletions
diff --git a/src/internal/ntux_driver_impl.h b/src/internal/ntux_driver_impl.h
index 6c635de..38d10cc 100644
--- a/src/internal/ntux_driver_impl.h
+++ b/src/internal/ntux_driver_impl.h
@@ -26,11 +26,39 @@ struct ntux_driver_ctx_impl {
struct ntux_common_ctx cctx;
struct ntux_driver_ctx ctx;
struct __psx_context xctx;
+ const struct ntux_unit_ctx *euctx;
const char * eunit;
struct ntux_error_info ** errinfp;
struct ntux_error_info ** erricap;
struct ntux_error_info * erriptr[64];
struct ntux_error_info erribuf[64];
+ char errsbuf[28];
+ int errcode;
};
+
+static inline struct ntux_driver_ctx_impl * ntux_get_driver_ictx(const struct ntux_driver_ctx * dctx)
+{
+ uintptr_t addr;
+
+ if (dctx) {
+ addr = (uintptr_t)dctx - offsetof(struct ntux_driver_ctx_impl,ctx);
+ return (struct ntux_driver_ctx_impl *)addr;
+ }
+
+ return 0;
+}
+
+static inline void ntux_driver_set_ectx(
+ const struct ntux_driver_ctx * dctx,
+ const struct ntux_unit_ctx * uctx,
+ const char * unit)
+{
+ struct ntux_driver_ctx_impl * ictx;
+
+ ictx = ntux_get_driver_ictx(dctx);
+ ictx->euctx = uctx;
+ ictx->eunit = unit;
+}
+
#endif
diff --git a/src/internal/ntux_errinfo_impl.c b/src/internal/ntux_errinfo_impl.c
new file mode 100644
index 0000000..2c21663
--- /dev/null
+++ b/src/internal/ntux_errinfo_impl.c
@@ -0,0 +1,66 @@
+/***********************************************************/
+/* ntux: native translation und extension */
+/* Copyright (C) 2016--2018 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.NTUX. */
+/***********************************************************/
+
+#include <ntux/ntux.h>
+#include "ntux_driver_impl.h"
+#include "ntux_errinfo_impl.h"
+
+int ntux_errno(const struct ntux_driver_ctx * dctx)
+{
+ struct ntux_driver_ctx_impl * ictx;
+ ictx = ntux_get_driver_ictx(dctx);
+ return ictx->errcode;
+}
+
+int ntux_errno_set(
+ const struct ntux_driver_ctx * dctx,
+ int esyscode)
+{
+ struct ntux_driver_ctx_impl * ictx;
+
+ ictx = ntux_get_driver_ictx(dctx);
+ ictx->errcode = (esyscode < 0)
+ ? -esyscode
+ : esyscode;
+
+ return esyscode;
+}
+
+int ntux_record_error(
+ const struct ntux_driver_ctx * dctx,
+ int esyscode,
+ int elibcode,
+ const char * efunction,
+ int eline,
+ unsigned eflags,
+ void * eany)
+{
+ struct ntux_driver_ctx_impl * ictx;
+ struct ntux_error_info * erri;
+
+ ictx = ntux_get_driver_ictx(dctx);
+
+ if (ictx->errinfp == ictx->erricap)
+ return -1;
+
+ *ictx->errinfp = &ictx->erribuf[ictx->errinfp - ictx->erriptr];
+ erri = *ictx->errinfp;
+
+ erri->euctx = ictx->euctx;
+ erri->eunit = ictx->eunit;
+
+ erri->edctx = dctx;
+ erri->esyscode = esyscode;
+ erri->elibcode = elibcode;
+ erri->efunction = efunction;
+ erri->eline = eline;
+ erri->eflags = eflags;
+ erri->eany = eany;
+
+ ictx->errinfp++;
+
+ return -1;
+}
diff --git a/src/internal/ntux_errinfo_impl.h b/src/internal/ntux_errinfo_impl.h
new file mode 100644
index 0000000..1d3b527
--- /dev/null
+++ b/src/internal/ntux_errinfo_impl.h
@@ -0,0 +1,96 @@
+/***********************************************************/
+/* ntux: native translation und extension */
+/* Copyright (C) 2016--2018 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.NTUX. */
+/***********************************************************/
+
+#include <ntux/ntux.h>
+
+int ntux_errno(const struct ntux_driver_ctx *);
+
+int ntux_errno_set(
+ const struct ntux_driver_ctx *,
+ int esyscode);
+
+int ntux_record_error(
+ const struct ntux_driver_ctx *,
+ int esyscode,
+ int elibcode,
+ const char * efunction,
+ int eline,
+ unsigned eflags,
+ void * eany);
+
+#define NTUX_SYSTEM_ERROR(dctx) \
+ ntux_record_error( \
+ dctx, \
+ ntux_errno(dctx), \
+ 0, \
+ __func__, \
+ __LINE__, \
+ NTUX_ERROR_TOP_LEVEL, \
+ 0)
+
+#define NTUX_BUFFER_ERROR(dctx) \
+ ntux_record_error( \
+ dctx, \
+ ENOBUFS, \
+ 0, \
+ __func__, \
+ __LINE__, \
+ NTUX_ERROR_TOP_LEVEL, \
+ 0)
+
+#define NTUX_SPAWN_ERROR(dctx) \
+ ntux_record_error( \
+ dctx, \
+ ntux_errno(dctx), \
+ 0, \
+ __func__, \
+ __LINE__, \
+ NTUX_ERROR_TOP_LEVEL \
+ | (ntux_errno(dctx) ? 0 \
+ : NTUX_ERROR_CHILD), \
+ 0)
+
+#define NTUX_FILE_ERROR(dctx) \
+ ntux_record_error( \
+ dctx, \
+ EIO, \
+ 0, \
+ __func__, \
+ __LINE__, \
+ NTUX_ERROR_TOP_LEVEL, \
+ 0)
+
+#define NTUX_CUSTOM_ERROR(dctx,elibcode) \
+ ntux_record_error( \
+ dctx, \
+ 0, \
+ elibcode, \
+ __func__, \
+ __LINE__, \
+ NTUX_ERROR_TOP_LEVEL \
+ | NTUX_ERROR_CUSTOM, \
+ 0)
+
+#define NTUX_NATIVE_ERROR(dctx,elibcode) \
+ ntux_record_error( \
+ dctx, \
+ 0, \
+ elibcode, \
+ __func__, \
+ __LINE__, \
+ NTUX_ERROR_TOP_LEVEL \
+ | NTUX_ERROR_NATIVE, \
+ 0)
+
+#define NTUX_NESTED_ERROR(dctx) \
+ ntux_record_error( \
+ dctx, \
+ 0, \
+ 0, \
+ __func__, \
+ __LINE__, \
+ NTUX_ERROR_NESTED, \
+ 0)
diff --git a/src/internal/ntux_nolibc_impl.h b/src/internal/ntux_nolibc_impl.h
index d048bd4..a12b848 100644
--- a/src/internal/ntux_nolibc_impl.h
+++ b/src/internal/ntux_nolibc_impl.h
@@ -5,6 +5,7 @@
#define fileno ntux_fileno
#define fputs ntux_fputs
+#define fflush ntux_fflush
#define fprintf ntux_fprintf
#define sprintf ntux_sprintf
#define snprintf ntux_snprintf
@@ -35,6 +36,7 @@ int ntux_sprintf(char * str, const char * fmt, ...);
int ntux_snprintf(char * str, size_t n, const char * fmt, ...);
int ntux_fprintf(FILE *__restrict, const char *__restrict, ...);
int ntux_fputs(const char * str, FILE * file);
+int ntux_fflush(FILE *);
void * ntux_memcpy(void * dst, const void * src, size_t n);
void * memset(void * ch, int c, size_t n);
diff --git a/src/internal/ntux_ntaio_impl.c b/src/internal/ntux_ntaio_impl.c
index 377a833..850a7d7 100644
--- a/src/internal/ntux_ntaio_impl.c
+++ b/src/internal/ntux_ntaio_impl.c
@@ -112,3 +112,8 @@ int ntux_fileno(void * any)
{
return (int)(intptr_t)any;
}
+
+int ntux_fflush(FILE * file)
+{
+ return __sys_fsync((int)(intptr_t)file);
+}
diff --git a/src/internal/ntux_strerr_impl.c b/src/internal/ntux_strerr_impl.c
new file mode 100644
index 0000000..6cb4853
--- /dev/null
+++ b/src/internal/ntux_strerr_impl.c
@@ -0,0 +1,165 @@
+/***********************************************************/
+/* ntux: native translation und extension */
+/* Copyright (C) 2016--2018 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.NTUX. */
+/***********************************************************/
+
+#include <psxabi/sys_errno.h>
+
+#include <ntux/ntux.h>
+#include "ntux_driver_impl.h"
+#include "ntux_nolibc_impl.h"
+
+const char * ntux_posix_error_strs[] = {
+ [0] = "EOK",
+ [EPERM] = "EPERM",
+ [ENOENT] = "ENOENT",
+ [ESRCH] = "ESRCH",
+ [EINTR] = "EINTR",
+ [EIO] = "EIO",
+ [ENXIO] = "ENXIO",
+ [E2BIG] = "E2BIG",
+ [ENOEXEC] = "ENOEXEC",
+ [EBADF] = "EBADF",
+ [ECHILD] = "ECHILD",
+ [EAGAIN] = "EAGAIN",
+ [ENOMEM] = "ENOMEM",
+ [EACCES] = "EACCES",
+ [EFAULT] = "EFAULT",
+ [ENOTBLK] = "ENOTBLK",
+ [EBUSY] = "EBUSY",
+ [EEXIST] = "EEXIST",
+ [EXDEV] = "EXDEV",
+ [ENODEV] = "ENODEV",
+ [ENOTDIR] = "ENOTDIR",
+ [EISDIR] = "EISDIR",
+ [EINVAL] = "EINVAL",
+ [ENFILE] = "ENFILE",
+ [EMFILE] = "EMFILE",
+ [ENOTTY] = "ENOTTY",
+ [ETXTBSY] = "ETXTBSY",
+ [EFBIG] = "EFBIG",
+ [ENOSPC] = "ENOSPC",
+ [ESPIPE] = "ESPIPE",
+ [EROFS] = "EROFS",
+ [EMLINK] = "EMLINK",
+ [EPIPE] = "EPIPE",
+ [EDOM] = "EDOM",
+ [ERANGE] = "ERANGE",
+ [EDEADLK] = "EDEADLK",
+ [ENAMETOOLONG] = "ENAMETOOLONG",
+ [ENOLCK] = "ENOLCK",
+ [ENOSYS] = "ENOSYS",
+ [ENOTEMPTY] = "ENOTEMPTY",
+ [ELOOP] = "ELOOP",
+ [ENOMSG] = "ENOMSG",
+ [EIDRM] = "EIDRM",
+ [ECHRNG] = "ECHRNG",
+ [EL2NSYNC] = "EL2NSYNC",
+ [EL3HLT] = "EL3HLT",
+ [EL3RST] = "EL3RST",
+ [ELNRNG] = "ELNRNG",
+ [EUNATCH] = "EUNATCH",
+ [ENOCSI] = "ENOCSI",
+ [EL2HLT] = "EL2HLT",
+ [EBADE] = "EBADE",
+ [EBADR] = "EBADR",
+ [EXFULL] = "EXFULL",
+ [ENOANO] = "ENOANO",
+ [EBADRQC] = "EBADRQC",
+ [EBADSLT] = "EBADSLT",
+ [EBFONT] = "EBFONT",
+ [ENOSTR] = "ENOSTR",
+ [ENODATA] = "ENODATA",
+ [ETIME] = "ETIME",
+ [ENOSR] = "ENOSR",
+ [ENONET] = "ENONET",
+ [ENOPKG] = "ENOPKG",
+ [EREMOTE] = "EREMOTE",
+ [ENOLINK] = "ENOLINK",
+ [EADV] = "EADV",
+ [ESRMNT] = "ESRMNT",
+ [ECOMM] = "ECOMM",
+ [EPROTO] = "EPROTO",
+ [EMULTIHOP] = "EMULTIHOP",
+ [EDOTDOT] = "EDOTDOT",
+ [EBADMSG] = "EBADMSG",
+ [EOVERFLOW] = "EOVERFLOW",
+ [ENOTUNIQ] = "ENOTUNIQ",
+ [EBADFD] = "EBADFD",
+ [EREMCHG] = "EREMCHG",
+ [ELIBACC] = "ELIBACC",
+ [ELIBBAD] = "ELIBBAD",
+ [ELIBSCN] = "ELIBSCN",
+ [ELIBMAX] = "ELIBMAX",
+ [ELIBEXEC] = "ELIBEXEC",
+ [EILSEQ] = "EILSEQ",
+ [ERESTART] = "ERESTART",
+ [ESTRPIPE] = "ESTRPIPE",
+ [EUSERS] = "EUSERS",
+ [ENOTSOCK] = "ENOTSOCK",
+ [EDESTADDRREQ] = "EDESTADDRREQ",
+ [EMSGSIZE] = "EMSGSIZE",
+ [EPROTOTYPE] = "EPROTOTYPE",
+ [ENOPROTOOPT] = "ENOPROTOOPT",
+ [EPROTONOSUPPORT] = "EPROTONOSUPPORT",
+ [ESOCKTNOSUPPORT] = "ESOCKTNOSUPPORT",
+ [EOPNOTSUPP] = "EOPNOTSUPP",
+ [EPFNOSUPPORT] = "EPFNOSUPPORT",
+ [EAFNOSUPPORT] = "EAFNOSUPPORT",
+ [EADDRINUSE] = "EADDRINUSE",
+ [EADDRNOTAVAIL] = "EADDRNOTAVAIL",
+ [ENETDOWN] = "ENETDOWN",
+ [ENETUNREACH] = "ENETUNREACH",
+ [ENETRESET] = "ENETRESET",
+ [ECONNABORTED] = "ECONNABORTED",
+ [ECONNRESET] = "ECONNRESET",
+ [ENOBUFS] = "ENOBUFS",
+ [EISCONN] = "EISCONN",
+ [ENOTCONN] = "ENOTCONN",
+ [ESHUTDOWN] = "ESHUTDOWN",
+ [ETOOMANYREFS] = "ETOOMANYREFS",
+ [ETIMEDOUT] = "ETIMEDOUT",
+ [ECONNREFUSED] = "ECONNREFUSED",
+ [EHOSTDOWN] = "EHOSTDOWN",
+ [EHOSTUNREACH] = "EHOSTUNREACH",
+ [EALREADY] = "EALREADY",
+ [EINPROGRESS] = "EINPROGRESS",
+ [ESTALE] = "ESTALE",
+ [EUCLEAN] = "EUCLEAN",
+ [ENOTNAM] = "ENOTNAM",
+ [ENAVAIL] = "ENAVAIL",
+ [EISNAM] = "EISNAM",
+ [EREMOTEIO] = "EREMOTEIO",
+ [EDQUOT] = "EDQUOT",
+ [ENOMEDIUM] = "ENOMEDIUM",
+ [EMEDIUMTYPE] = "EMEDIUMTYPE",
+ [ECANCELED] = "ECANCELED",
+ [ENOKEY] = "ENOKEY",
+ [EKEYEXPIRED] = "EKEYEXPIRED",
+ [EKEYREVOKED] = "EKEYREVOKED",
+ [EKEYREJECTED] = "EKEYREJECTED",
+ [EOWNERDEAD] = "EOWNERDEAD",
+ [ENOTRECOVERABLE] = "ENOTRECOVERABLE",
+ [ERFKILL] = "ERFKILL",
+ [EHWPOISON] = "EHWPOISON",
+ [EERRORS] = 0};
+
+const char * ntux_strerror(
+ const struct ntux_driver_ctx * dctx,
+ int errno)
+{
+ struct ntux_driver_ctx_impl * ictx;
+
+ if ((errno >= 0) && (errno < EERRORS))
+ return ntux_posix_error_strs[errno];
+
+ ictx = ntux_get_driver_ictx(dctx);
+
+ ntux_sprintf(
+ ictx->errsbuf,
+ "Unknown error %d",
+ errno);
+
+ return ictx->errsbuf;
+}
diff --git a/src/internal/ntux_strerr_impl.h b/src/internal/ntux_strerr_impl.h
new file mode 100644
index 0000000..3f317a7
--- /dev/null
+++ b/src/internal/ntux_strerr_impl.h
@@ -0,0 +1,6 @@
+#ifndef NTUX_STRERR_IMPL_H
+#define NTUX_STRERR_IMPL_H
+
+const char * ntux_strerror(const struct ntux_driver_ctx *, int);
+
+#endif