diff options
author | midipix <writeonce@midipix.org> | 2016-07-05 17:00:06 -0400 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-07-21 03:47:25 -0400 |
commit | 538c8a5109b56d1d0a26631fa93913341214501d (patch) | |
tree | 72933385600f4524afc6e7a96e9f62a9d3dd069f | |
parent | 4695532805c24af1965ef1407720c8db086e14b3 (diff) | |
download | ptycon-538c8a5109b56d1d0a26631fa93913341214501d.tar.bz2 ptycon-538c8a5109b56d1d0a26631fa93913341214501d.tar.xz |
pty layer: added ptyc_alloc_pty(), ptyc_free_pty().
-rw-r--r-- | include/ptycon/ptycon.h | 8 | ||||
-rw-r--r-- | project/common.mk | 1 | ||||
-rw-r--r-- | project/headers.mk | 1 | ||||
-rw-r--r-- | project/tree.mk | 1 | ||||
-rw-r--r-- | src/driver/ptyc_amain.c | 3 | ||||
-rw-r--r-- | src/driver/ptyc_driver_ctx.c | 1 | ||||
-rw-r--r-- | src/internal/ptycon_ioctl_impl.h | 22 | ||||
-rw-r--r-- | src/pty/ptyc_pty_ctx.c | 92 |
8 files changed, 129 insertions, 0 deletions
diff --git a/include/ptycon/ptycon.h b/include/ptycon/ptycon.h index 9d10ff9..6309f27 100644 --- a/include/ptycon/ptycon.h +++ b/include/ptycon/ptycon.h @@ -34,6 +34,8 @@ extern "C" { #define PTYC_DRIVER_VERSION 0x0010 #define PTYC_DRIVER_DRY_RUN 0x0020 +#define PTYC_DRIVER_DBG_OVEN 0x0040 +#define PTYC_DRIVER_DBG_RAW 0x0080 struct ptyc_source_version { int major; @@ -46,6 +48,8 @@ struct ptyc_common_ctx { uint64_t drvflags; uint64_t actflags; uint64_t fmtflags; + nt_pty * hpts; + nt_pty * hptm; }; struct ptyc_driver_ctx { @@ -66,6 +70,10 @@ ptyc_api int ptyc_get_driver_ctx (char ** argv, char ** envp, uint32_t flags, s ptyc_api int ptyc_create_driver_ctx (const struct ptyc_common_ctx *, struct ptyc_driver_ctx **); ptyc_api void ptyc_free_driver_ctx (struct ptyc_driver_ctx *); +/* pty api */ +ptyc_api int ptyc_alloc_pty (struct ptyc_driver_ctx *); +ptyc_api void ptyc_free_pty (struct ptyc_driver_ctx *); + /* utility api */ ptyc_api int ptyc_main (int, char **, char **); diff --git a/project/common.mk b/project/common.mk index 07ea4ed..c0cf2a7 100644 --- a/project/common.mk +++ b/project/common.mk @@ -5,6 +5,7 @@ COMMON_SRCS = \ src/internal/ptycon_memfn_impl.c \ src/internal/ptycon_nolibc_impl.c \ src/internal/ptycon_ntaio_impl.c \ + src/pty/ptyc_pty_ctx.c \ src/skin/ptyc_skin_default.c \ APP_SRCS = \ diff --git a/project/headers.mk b/project/headers.mk index ed442e4..84041cc 100644 --- a/project/headers.mk +++ b/project/headers.mk @@ -6,6 +6,7 @@ INTERNAL_HEADERS = \ $(PROJECT_DIR)/src/internal/argv/argv.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_driver_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_init_impl.h \ + $(PROJECT_DIR)/src/internal/$(PACKAGE)_ioctl_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_memfn_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_nolibc_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_status_impl.h \ diff --git a/project/tree.mk b/project/tree.mk index d352c5b..46818f8 100644 --- a/project/tree.mk +++ b/project/tree.mk @@ -5,5 +5,6 @@ tree.tag: mkdir -p src/internal/nolibc mkdir -p src/logic mkdir -p src/output + mkdir -p src/pty mkdir -p src/skin touch tree.tag diff --git a/src/driver/ptyc_amain.c b/src/driver/ptyc_amain.c index 4762d3a..3a5ca68 100644 --- a/src/driver/ptyc_amain.c +++ b/src/driver/ptyc_amain.c @@ -70,5 +70,8 @@ int ptyc_main(int argc, char ** argv, char ** envp) if ((ptyc_version(dctx)) < 0) return ptyc_exit(dctx,2); + if (ptyc_alloc_pty(dctx)) + return ptyc_exit(dctx,2); + return ptyc_exit(dctx,ret); } diff --git a/src/driver/ptyc_driver_ctx.c b/src/driver/ptyc_driver_ctx.c index 78ffb54..d403a98 100644 --- a/src/driver/ptyc_driver_ctx.c +++ b/src/driver/ptyc_driver_ctx.c @@ -236,6 +236,7 @@ int ptyc_create_driver_ctx( static void ptyc_free_driver_ctx_impl(struct ptyc_driver_ctx_alloc * ictx) { + ptyc_free_pty(&ictx->ctx.ctx); argv_free(ictx->meta); free(ictx); } diff --git a/src/internal/ptycon_ioctl_impl.h b/src/internal/ptycon_ioctl_impl.h new file mode 100644 index 0000000..dacd689 --- /dev/null +++ b/src/internal/ptycon_ioctl_impl.h @@ -0,0 +1,22 @@ +#ifndef PTYCON_IOCTL_IMPL_H +#define PTYCON_IOCTL_IMPL_H + +#include <ntapi/ntapi.h> + +static int32_t ptyc_grant(nt_pty * hptm) +{ + nt_tty_sigctl_info ctlinfo; + nt_iosb iosb; + + ntapi->tt_aligned_block_memset( + &ctlinfo,0,sizeof(ctlinfo)); + + return ntapi->pty_ioctl( + hptm, + 0,0,0, + &iosb,TTY_TIOCSPTLCK, + &ctlinfo,sizeof(ctlinfo), + &ctlinfo,sizeof(ctlinfo)); +} + +#endif diff --git a/src/pty/ptyc_pty_ctx.c b/src/pty/ptyc_pty_ctx.c new file mode 100644 index 0000000..31a9c26 --- /dev/null +++ b/src/pty/ptyc_pty_ctx.c @@ -0,0 +1,92 @@ +/*********************************************************/ +/* ptycon: a pty-console bridge */ +/* Copyright (C) 2016 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.PTYCON. */ +/*********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/ntapi.h> +#include <ptycon/ptycon.h> +#include "ptycon_driver_impl.h" +#include "ptycon_ioctl_impl.h" +#include "ptycon_status_impl.h" + +static int32_t ptyc_pty_open(nt_pty * hptm, nt_guid * pty_guid, nt_pty ** hpty) +{ + nt_vfd_dev_name pty_name; + nt_oa oa = {sizeof(oa),0,0,0,0,0}; + + ntapi->vfd_dev_name_init( + &pty_name,pty_guid); + + oa.obj_name = &pty_name.name; + oa.root_dir = hptm; + + return ntapi->pty_open( + 0,hpty, + NT_FILE_ALL_ACCESS, + &oa,0,0,0); +} + +static int32_t ptyc_ptm_open(const struct ptyc_common_ctx * cctx) +{ + nt_guid pty_guid = TTY_PTM_GUID; + return ptyc_pty_open( + 0,&pty_guid, + (nt_pty **)&cctx->hptm); +} + +static int32_t ptyc_pts_open(const struct ptyc_common_ctx * cctx) +{ + int32_t status; + nt_guid pty_guid = TTY_PTS_GUID; + + if ((status = ptyc_grant(cctx->hptm))) + return status; + + return ptyc_pty_open( + cctx->hptm,&pty_guid, + (nt_pty **)&cctx->hpts); +} + +int ptyc_alloc_pty(struct ptyc_driver_ctx * dctx) +{ + int32_t status; + + if (dctx->cctx->hpts || dctx->cctx->hptm) + return ptyc_set_status( + dctx,NT_STATUS_DEVICE_ALREADY_ATTACHED); + + if ((status = ptyc_ptm_open(dctx->cctx))) + return ptyc_set_status( + dctx,status); + + if (!(dctx->cctx->drvflags & PTYC_DRIVER_DBG_OVEN) + && !(dctx->cctx->drvflags & PTYC_DRIVER_DBG_RAW)) + return ptyc_set_status( + dctx,NT_STATUS_SUCCESS); + + if ((status = ptyc_pts_open(dctx->cctx))) + return ptyc_set_status( + dctx,status); + + return ptyc_set_status( + dctx,NT_STATUS_SUCCESS); +} + +void ptyc_free_pty(struct ptyc_driver_ctx * dctx) +{ + struct ptyc_common_ctx * cctx; + + cctx = (struct ptyc_common_ctx *)dctx->cctx; + + if (cctx->hpts) { + ntapi->pty_close(cctx->hpts); + cctx->hpts = 0; + } + + if (cctx->hptm) { + ntapi->pty_close(cctx->hptm); + cctx->hptm = 0; + } +} |