Blob Blame History Raw
#ifndef TOKSVC_DRIVER_IMPL_H
#define TOKSVC_DRIVER_IMPL_H

#include <psxtypes/psxtypes.h>
#include <ntapi/ntapi.h>

#include <stdint.h>
#include <stdio.h>

#include <toksvc/toksvc.h>
#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,
	TAG_UUID,
};

struct toks_ticks {
	nt_filetime	pcfreq;
	int32_t		(*qpc)(nt_filetime *);
};

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;
	struct toks_ticks	ticks;
	void *			hevent;
	void *			hsvcdir;
	void *			hsvclink;
	nt_guid			uuid;
};

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;
}

static inline nt_rtdata * toks_get_driver_rtdata(const struct toks_driver_ctx * dctx)
{
	struct toks_driver_ctx_impl * ictx;
	ictx = toks_get_driver_ictx(dctx);
	return ictx->rtdata;
}

static inline void * toks_get_driver_hevent(const struct toks_driver_ctx * dctx)
{
	struct toks_driver_ctx_impl * ictx;
	ictx = toks_get_driver_ictx(dctx);
	return ictx->hevent;
}

static inline void * toks_get_driver_hsvcdir(const struct toks_driver_ctx * dctx)
{
	struct toks_driver_ctx_impl * ictx;
	ictx = toks_get_driver_ictx(dctx);
	return ictx->hsvcdir;
}

static inline void toks_set_driver_hsvcdir(const struct toks_driver_ctx * dctx, void * hsvcdir)
{
	struct toks_driver_ctx_impl * ictx;
	ictx = toks_get_driver_ictx(dctx);
	ictx->hsvcdir = hsvcdir;
}

static inline void * toks_get_driver_hsvclink(const struct toks_driver_ctx * dctx)
{
	struct toks_driver_ctx_impl * ictx;
	ictx = toks_get_driver_ictx(dctx);
	return ictx->hsvclink;
}

static inline void toks_set_driver_hsvclink(const struct toks_driver_ctx * dctx, void * hsvclink)
{
	struct toks_driver_ctx_impl * ictx;
	ictx = toks_get_driver_ictx(dctx);
	ictx->hsvclink = hsvclink;
}

static inline const nt_guid * toks_get_driver_uuid(const struct toks_driver_ctx * dctx)
{
	struct toks_driver_ctx_impl * ictx;
	ictx = toks_get_driver_ictx(dctx);
	return &ictx->uuid;
}

static inline void toks_query_performance_counters(const struct toks_driver_ctx * dctx, nt_filetime * ticks)
{
	struct toks_driver_ctx_impl * ictx;
	ictx = toks_get_driver_ictx(dctx);

	if (!(ictx->ticks.qpc(ticks)))
		ticks->quad = 0;
}

int32_t toks_open_file(void ** hfile, void * hat, const char * arg, bool fprivate);
int32_t toks_open_dir(void ** hfile, void * hat, const char * arg, bool fprivate);

#endif