Blame src/internal/toksvc_driver_impl.h

c0069e
#ifndef TOKSVC_DRIVER_IMPL_H
c0069e
#define TOKSVC_DRIVER_IMPL_H
c0069e
c0069e
#include <psxtypes/psxtypes.h>
c0069e
#include <ntapi/ntapi.h>
c0069e
c0069e
#include <stdint.h>
c0069e
#include <stdio.h>
c0069e
c0069e
#include <toksvc/toksvc.h>
c0069e
#include "argv/argv.h"
c0069e
c0069e
#define TOKS_OPTV_ELEMENTS 64
d73408
#define TOKS_MAX_WAITERS   4000
c0069e
c0069e
extern   const struct argv_option toks_default_options[];
c0069e
extern   const ntapi_vtbl * toks_ntapi;
c0069e
c0069e
#define  ntapi toks_ntapi
c0069e
c0069e
enum app_tags {
c0069e
	TAG_HELP,
c0069e
	TAG_VERSION,
c0069e
	TAG_DAEMON,
c0069e
	TAG_SYSROOT,
618937
	TAG_UUID,
486fcd
	TAG_CONNECT,
c847e3
	TAG_TOKENS,
02451d
	TAG_ACQUIRE,
867b30
	TAG_RELEASE,
e3e583
	TAG_PID,
c0069e
};
c0069e
2f270e
struct toks_ticks {
2f270e
	nt_filetime	pcfreq;
2f270e
	int32_t		(*qpc)(nt_filetime *);
2f270e
};
2f270e
c0069e
struct toks_driver_ctx_impl {
c0069e
	nt_rtdata *		rtdata;
c0069e
	struct toks_common_ctx	cctx;
c0069e
	struct toks_driver_ctx	ctx;
2f270e
	struct toks_ticks	ticks;
c847e3
	struct toks_token *	tokens;
d73408
	struct toks_waiter *	waiters;
02451d
	struct _nt_port_keys    keys;
2f270e
	void *			hevent;
00069c
	void *			hsvcdir;
500bc3
	void *			hpiddir;
00069c
	void *			hsvclink;
486fcd
	void *			hservice;
d73408
	int			nwaiters;
c847e3
	int			ntokens;
e3e583
	int			tokpid;
618937
	nt_guid			uuid;
c0069e
};
c0069e
c0069e
static inline struct toks_driver_ctx_impl * toks_get_driver_ictx(const struct toks_driver_ctx * dctx)
c0069e
{
c0069e
	uintptr_t addr;
c0069e
c0069e
	if (dctx) {
c0069e
		addr = (uintptr_t)dctx - offsetof(struct toks_driver_ctx_impl,ctx);
c0069e
		return (struct toks_driver_ctx_impl *)addr;
c0069e
	}
c0069e
c0069e
	return 0;
c0069e
}
c0069e
618937
static inline nt_rtdata * toks_get_driver_rtdata(const struct toks_driver_ctx * dctx)
618937
{
618937
	struct toks_driver_ctx_impl * ictx;
618937
	ictx = toks_get_driver_ictx(dctx);
618937
	return ictx->rtdata;
618937
}
618937
2f270e
static inline void * toks_get_driver_hevent(const struct toks_driver_ctx * dctx)
2f270e
{
2f270e
	struct toks_driver_ctx_impl * ictx;
2f270e
	ictx = toks_get_driver_ictx(dctx);
2f270e
	return ictx->hevent;
2f270e
}
2f270e
00069c
static inline void * toks_get_driver_hsvcdir(const struct toks_driver_ctx * dctx)
00069c
{
00069c
	struct toks_driver_ctx_impl * ictx;
00069c
	ictx = toks_get_driver_ictx(dctx);
00069c
	return ictx->hsvcdir;
00069c
}
00069c
00069c
static inline void toks_set_driver_hsvcdir(const struct toks_driver_ctx * dctx, void * hsvcdir)
00069c
{
00069c
	struct toks_driver_ctx_impl * ictx;
00069c
	ictx = toks_get_driver_ictx(dctx);
00069c
	ictx->hsvcdir = hsvcdir;
00069c
}
00069c
500bc3
static inline void * toks_get_driver_hpiddir(const struct toks_driver_ctx * dctx)
500bc3
{
500bc3
	struct toks_driver_ctx_impl * ictx;
500bc3
	ictx = toks_get_driver_ictx(dctx);
500bc3
	return ictx->hpiddir;
500bc3
}
500bc3
500bc3
static inline void toks_set_driver_hpiddir(const struct toks_driver_ctx * dctx, void * hpiddir)
500bc3
{
500bc3
	struct toks_driver_ctx_impl * ictx;
500bc3
	ictx = toks_get_driver_ictx(dctx);
500bc3
	ictx->hpiddir = hpiddir;
500bc3
}
500bc3
00069c
static inline void * toks_get_driver_hsvclink(const struct toks_driver_ctx * dctx)
00069c
{
00069c
	struct toks_driver_ctx_impl * ictx;
00069c
	ictx = toks_get_driver_ictx(dctx);
00069c
	return ictx->hsvclink;
00069c
}
00069c
00069c
static inline void toks_set_driver_hsvclink(const struct toks_driver_ctx * dctx, void * hsvclink)
00069c
{
00069c
	struct toks_driver_ctx_impl * ictx;
00069c
	ictx = toks_get_driver_ictx(dctx);
00069c
	ictx->hsvclink = hsvclink;
00069c
}
00069c
486fcd
static inline void * toks_get_driver_hservice(const struct toks_driver_ctx * dctx)
486fcd
{
486fcd
	struct toks_driver_ctx_impl * ictx;
486fcd
	ictx = toks_get_driver_ictx(dctx);
486fcd
	return ictx->hservice;
486fcd
}
486fcd
486fcd
static inline void toks_set_driver_hservice(const struct toks_driver_ctx * dctx, void * hservice)
486fcd
{
486fcd
	struct toks_driver_ctx_impl * ictx;
486fcd
	ictx = toks_get_driver_ictx(dctx);
486fcd
	ictx->hservice = hservice;
486fcd
}
486fcd
02451d
static inline struct _nt_port_keys * toks_get_driver_keys(const struct toks_driver_ctx * dctx)
02451d
{
02451d
	struct toks_driver_ctx_impl * ictx;
02451d
	ictx = toks_get_driver_ictx(dctx);
02451d
	return &ictx->keys;
02451d
}
02451d
618937
static inline const nt_guid * toks_get_driver_uuid(const struct toks_driver_ctx * dctx)
618937
{
618937
	struct toks_driver_ctx_impl * ictx;
618937
	ictx = toks_get_driver_ictx(dctx);
618937
	return &ictx->uuid;
618937
}
618937
d73408
static inline int toks_get_driver_nwaiters(const struct toks_driver_ctx * dctx)
d73408
{
d73408
	struct toks_driver_ctx_impl * ictx;
d73408
	ictx = toks_get_driver_ictx(dctx);
d73408
	return ictx->nwaiters;
d73408
}
d73408
d73408
static inline void toks_set_driver_nwaiters(const struct toks_driver_ctx * dctx, int nwaiters)
d73408
{
d73408
	struct toks_driver_ctx_impl * ictx;
d73408
	ictx = toks_get_driver_ictx(dctx);
d73408
	ictx->nwaiters = nwaiters;
d73408
}
d73408
c847e3
static inline struct toks_token * toks_get_driver_tokens(const struct toks_driver_ctx * dctx)
c847e3
{
c847e3
	struct toks_driver_ctx_impl * ictx;
c847e3
	ictx = toks_get_driver_ictx(dctx);
c847e3
	return ictx->tokens;
c847e3
}
c847e3
c847e3
static inline int toks_get_driver_ntokens(const struct toks_driver_ctx * dctx)
c847e3
{
c847e3
	struct toks_driver_ctx_impl * ictx;
c847e3
	ictx = toks_get_driver_ictx(dctx);
c847e3
	return ictx->ntokens;
c847e3
}
c847e3
e3e583
static inline int toks_get_driver_tokpid(const struct toks_driver_ctx * dctx)
e3e583
{
e3e583
	struct toks_driver_ctx_impl * ictx;
e3e583
	ictx = toks_get_driver_ictx(dctx);
e3e583
	return ictx->tokpid;
e3e583
}
e3e583
2f270e
static inline void toks_query_performance_counters(const struct toks_driver_ctx * dctx, nt_filetime * ticks)
2f270e
{
2f270e
	struct toks_driver_ctx_impl * ictx;
2f270e
	ictx = toks_get_driver_ictx(dctx);
2f270e
2f270e
	if (!(ictx->ticks.qpc(ticks)))
2f270e
		ticks->quad = 0;
2f270e
}
2f270e
2a7aec
int32_t toks_open_file(void ** hfile, void * hat, const char * arg, bool fprivate);
2a7aec
int32_t toks_open_dir(void ** hfile, void * hat, const char * arg, bool fprivate);
2a7aec
c0069e
#endif