From c0069e184011d49e510ef4735c85d260ea5db2c8 Mon Sep 17 00:00:00 2001 From: midipix Date: Jun 08 2020 01:00:09 +0000 Subject: driver: added rudimentary internal headers and library api headers. --- diff --git a/include/empty.dir b/include/empty.dir deleted file mode 100644 index e69de29..0000000 --- a/include/empty.dir +++ /dev/null diff --git a/include/toksvc/toksvc.h b/include/toksvc/toksvc.h new file mode 100644 index 0000000..5733b84 --- /dev/null +++ b/include/toksvc/toksvc.h @@ -0,0 +1,122 @@ +#ifndef TOKSVC_H +#define TOKSVC_H + +#include +#include + +#include "toksvc_api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* pre-alpha */ +#ifndef TOKS_APP +#ifndef TOKS_PRE_ALPHA +#error libtoks: pre-alpha: ABI is not final! +#error to use the library, compile with -DTOKS_PRE_ALPHA. +#endif +#endif + +/* status codes */ +#define TOKS_OK 0x00 +#define TOKS_USAGE 0x01 +#define TOKS_ERROR 0x02 + +/* driver flags */ +#define TOKS_DRIVER_VERBOSITY_NONE 0x0000 +#define TOKS_DRIVER_VERBOSITY_ERRORS 0x0001 +#define TOKS_DRIVER_VERBOSITY_STATUS 0x0002 +#define TOKS_DRIVER_VERBOSITY_USAGE 0x0004 +#define TOKS_DRIVER_CLONE_VECTOR 0x0008 + +#define TOKS_DRIVER_VERSION 0x0010 +#define TOKS_DRIVER_DRY_RUN 0x0020 + +#define TOKS_DRIVER_ANNOTATE_ALWAYS 0x1000 +#define TOKS_DRIVER_ANNOTATE_NEVER 0x2000 +#define TOKS_DRIVER_ANNOTATE_FULL 0x4000 + +/* error flags */ +#define TOKS_ERROR_TOP_LEVEL 0x0001 +#define TOKS_ERROR_NESTED 0x0002 +#define TOKS_ERROR_CHILD 0x0004 +#define TOKS_ERROR_CUSTOM 0x0008 + +enum toks_custom_error { + TOKS_ERR_FLOW_ERROR, + TOKS_ERR_FLEE_ERROR, + TOKS_ERR_NULL_CONTEXT, + TOKS_ERR_BAD_DATA, + TOKS_ERR_CAP, +}; + +enum toks_warning_level { + TOKS_WARNING_LEVEL_UNKNOWN, + TOKS_WARNING_LEVEL_ALL, + TOKS_WARNING_LEVEL_ERROR, + TOKS_WARNING_LEVEL_NONE, +}; + +struct toks_source_version { + int major; + int minor; + int revision; + const char * commit; +}; + +struct toks_error_info { + const struct toks_driver_ctx * edctx; + const struct toks_unit_ctx * euctx; + const char * eunit; + int esyscode; + int elibcode; + const char * efunction; + int eline; + unsigned eflags; + void * eany; +}; + +struct toks_common_ctx { + uint64_t drvflags; + uint64_t actflags; + uint64_t fmtflags; + void * hroot; + const char * sysroot; + char ** eargv; +}; + +struct toks_driver_ctx { + const char ** units; + const char * program; + const char * module; + const struct toks_common_ctx * cctx; + struct toks_error_info ** errv; + void * any; +}; + +/* driver api */ +toks_api int toks_get_driver_ctx (char ** argv, char ** envp, uint32_t flags, + struct toks_driver_ctx **); + +toks_api void toks_free_driver_ctx (struct toks_driver_ctx *); + +/* core api */ + +/* helper api */ + +/* utility api */ +toks_api int toks_main (char **, char **); + +/* error trace api */ +toks_api int toks_output_error_record (const struct toks_driver_ctx *, const struct toks_error_info *); +toks_api int toks_output_error_vector (const struct toks_driver_ctx *); + +/* package info */ +toks_api const struct toks_source_version * toks_source_version(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/toksvc/toksvc_api.h b/include/toksvc/toksvc_api.h new file mode 100644 index 0000000..3a28ce0 --- /dev/null +++ b/include/toksvc/toksvc_api.h @@ -0,0 +1,35 @@ +#ifndef TOKS_API_H +#define TOKS_API_H + +#include + +/* toks_export */ +#if defined(__dllexport) +#define toks_export __dllexport +#else +#define toks_export +#endif + +/* toks_import */ +#if defined(__dllimport) +#define toks_import __dllimport +#else +#define toks_import +#endif + +/* toks_api */ +#ifndef TOKS_APP +#if defined (TOKS_EXPORT) +#define toks_api toks_export +#elif defined (TOKS_IMPORT) +#define toks_api toks_import +#elif defined (TOKS_STATIC) +#define toks_api +#else +#define toks_api +#endif +#else +#define toks_api +#endif + +#endif diff --git a/project/headers.mk b/project/headers.mk index 61f548e..19d613e 100644 --- a/project/headers.mk +++ b/project/headers.mk @@ -1,4 +1,6 @@ API_HEADERS = \ + $(SOURCE_DIR)/include/$(PACKAGE)/toksvc.h \ + $(SOURCE_DIR)/include/$(PACKAGE)/toksvc_api.h \ INTERNAL_HEADERS = \ $(SOURCE_DIR)/src/internal/argv/argv.h \ diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h new file mode 100644 index 0000000..12f9b14 --- /dev/null +++ b/src/internal/toksvc_driver_impl.h @@ -0,0 +1,53 @@ +#ifndef TOKSVC_DRIVER_IMPL_H +#define TOKSVC_DRIVER_IMPL_H + +#include +#include + +#include +#include + +#include +#include "argv/argv.h" + +#define TOKS_OPTV_ELEMENTS 64 + +extern const struct argv_option toks_default_options[]; +extern const ntapi_vtbl * toks_ntapi; + +#define ntapi toks_ntapi + +enum app_tags { + TAG_HELP, + TAG_VERSION, + TAG_DAEMON, + TAG_SYSROOT, +}; + +struct toks_client_ctx { + void * hprocess; + void * hthread; + nt_cid cid; + nt_pty_client_info clinfo; +}; + +struct toks_driver_ctx_impl { + nt_rtdata * rtdata; + struct toks_client_ctx clctx; + struct toks_common_ctx cctx; + struct toks_driver_ctx ctx; +}; + +static inline struct toks_driver_ctx_impl * toks_get_driver_ictx(const struct toks_driver_ctx * dctx) +{ + uintptr_t addr; + + if (dctx) { + addr = (uintptr_t)dctx - offsetof(struct toks_driver_ctx_impl,ctx); + return (struct toks_driver_ctx_impl *)addr; + } + + return 0; +} + +#endif