From cfc59b1713a9d9fc9a7e6f51952d2b584a3842e4 Mon Sep 17 00:00:00 2001 From: midipix Date: Tue, 5 Jul 2016 02:14:54 -0400 Subject: driver: added native console accessor table. --- project/extras.mk | 2 +- src/driver/ptyc_driver_ctx.c | 50 +++++++++++++++++++++++++++++++++++++++ src/internal/ptycon_driver_impl.h | 4 ++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/project/extras.mk b/project/extras.mk index 6f6d5db..6f23834 100644 --- a/project/extras.mk +++ b/project/extras.mk @@ -5,7 +5,7 @@ CFLAGS_APP_ATTR += -DPTYC_APP src/driver/ptyc_driver_ctx.o: version.tag src/driver/ptyc_driver_ctx.lo: version.tag -LDFLAGS_COMMON += -nostdlib -lntapi -lpemagine -ldalist +LDFLAGS_COMMON += -nostdlib -lntapi -lpemagine -ldalist -lntcon LDFLAGS_COMMON += -Wl,--entry -Wl,$(HOST_UNDERSCORE)$(PACKAGE)_entry_point LDFLAGS_SHARED += -Wl,--exclude-all-symbols diff --git a/src/driver/ptyc_driver_ctx.c b/src/driver/ptyc_driver_ctx.c index cc50e36..78ffb54 100644 --- a/src/driver/ptyc_driver_ctx.c +++ b/src/driver/ptyc_driver_ctx.c @@ -4,7 +4,10 @@ /* Released under GPLv2 and GPLv3; see COPYING.PTYCON. */ /*********************************************************/ +#include #include +#include + #include #include @@ -20,6 +23,10 @@ /* ntapi accessor table */ const ntapi_vtbl * ptyc_ntapi; +/* ntcon accessor table */ +static ntcon_vtbl ptyc_ntcon_vtbl; +const ntcon_vtbl * const ptyc_ntcon = &ptyc_ntcon_vtbl; + /* package info */ static const struct ptyc_source_version ptyc_src_version = { PTYC_TAG_VER_MAJOR, @@ -35,6 +42,43 @@ struct ptyc_driver_ctx_alloc { const char * units[]; }; +static int32_t ptyc_ntcon_once = 0; + +static int32_t ptyc_ntcon_init(void) +{ + int32_t status; + nt_timeout timeout; + + switch (at_locked_cas_32(&ptyc_ntcon_once,0,1)) { + case 0: + if ((status = ntcon_vtbl_init(&ptyc_ntcon_vtbl))) { + at_locked_add_32(&ptyc_ntcon_once,2); + return status; + } else { + at_locked_inc_32(&ptyc_ntcon_once); + return 0; + } + + case 1: + timeout.quad = -10; + + for (; (at_locked_cas_32(&ptyc_ntcon_once,0,1) == 1); ) + ntapi->zw_delay_execution( + NT_SYNC_ALERTABLE, + &timeout); + + return (ptyc_ntcon_once == 2) + ? 0 : -1; + + case 2: + return 0; + + case 3: + default: + return -1; + } +} + static uint32_t ptyc_argv_flags(uint32_t flags) { uint32_t ret = 0; @@ -122,6 +166,9 @@ int ptyc_get_driver_ctx( if (ptyc_init()) return -1; + if (ptyc_ntcon_init()) + return -1; + options = ptyc_default_options; if (!(meta = argv_get(argv,options,ptyc_argv_flags(flags)))) @@ -172,6 +219,9 @@ int ptyc_create_driver_ctx( if (ptyc_init()) return -1; + if (ptyc_ntcon_init()) + return -1; + if (!(meta = argv_get(argv,ptyc_default_options,0))) return -1; diff --git a/src/internal/ptycon_driver_impl.h b/src/internal/ptycon_driver_impl.h index dbc3278..3576cd4 100644 --- a/src/internal/ptycon_driver_impl.h +++ b/src/internal/ptycon_driver_impl.h @@ -2,6 +2,8 @@ #define PTYCON_DRIVER_IMPL_H #include +#include + #include #include @@ -10,8 +12,10 @@ extern const struct argv_option ptyc_default_options[]; extern const ntapi_vtbl * ptyc_ntapi; +extern const ntcon_vtbl * const ptyc_ntcon; #define ntapi ptyc_ntapi +#define ntcon ptyc_ntcon enum app_tags { TAG_HELP, -- cgit v1.2.3