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
79252f
size_t   toks_strlen(const char * ch);
79252f
char *   toks_strcpy(char * dst, const char * src);
79252f
79252f
void *   toks_calloc(size_t n, size_t size);
79252f
void     toks_free(void *);
79252f
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,
520f51
	TAG_ABORT,
02451d
	TAG_ACQUIRE,
867b30
	TAG_RELEASE,
b27e56
	TAG_TIMEOUT,
79252f
	TAG_REFSTR,
e3e583
	TAG_PID,
201fd7
	TAG_SYSPID,
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;
b27e56
	int64_t                 timeout;
79252f
	char *			refstr;
2f270e
	void *			hevent;
00069c
	void *			hsvcdir;
500bc3
	void *			hpiddir;
00069c
	void *			hsvclink;
486fcd
	void *			hservice;
83e502
	void *			hserver;
d73408
	int			nwaiters;
c847e3
	int			ntokens;
e3e583
	int			tokpid;
201fd7
	int			tsyspid;
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
b27e56
static inline int64_t toks_get_driver_timeout(const struct toks_driver_ctx * dctx)
b27e56
{
b27e56
	struct toks_driver_ctx_impl * ictx;
b27e56
	ictx = toks_get_driver_ictx(dctx);
b27e56
	return ictx->timeout;
b27e56
}
b27e56
b27e56
static inline void toks_set_driver_timeout(const struct toks_driver_ctx * dctx, int64_t timeout)
b27e56
{
b27e56
	struct toks_driver_ctx_impl * ictx;
b27e56
	ictx = toks_get_driver_ictx(dctx);
b27e56
	ictx->timeout = timeout;
b27e56
}
b27e56
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
83e502
static inline void * toks_get_driver_hserver(const struct toks_driver_ctx * dctx)
83e502
{
83e502
	struct toks_driver_ctx_impl * ictx;
83e502
	ictx = toks_get_driver_ictx(dctx);
83e502
	return ictx->hserver;
83e502
}
83e502
83e502
static inline void toks_set_driver_hserver(const struct toks_driver_ctx * dctx, void * hserver)
83e502
{
83e502
	struct toks_driver_ctx_impl * ictx;
83e502
	ictx = toks_get_driver_ictx(dctx);
83e502
	ictx->hserver = hserver;
83e502
}
83e502
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
201fd7
static inline int toks_get_driver_tsyspid(const struct toks_driver_ctx * dctx)
201fd7
{
201fd7
	struct toks_driver_ctx_impl * ictx;
201fd7
	ictx = toks_get_driver_ictx(dctx);
201fd7
	return ictx->tsyspid;
201fd7
}
201fd7
79252f
static inline char * toks_get_driver_refstr(const struct toks_driver_ctx * dctx)
79252f
{
79252f
	struct toks_driver_ctx_impl * ictx;
79252f
	ictx = toks_get_driver_ictx(dctx);
79252f
	return ictx->refstr;
79252f
}
79252f
79252f
static inline void toks_set_driver_refstr(const struct toks_driver_ctx * dctx, const char * refstr)
79252f
{
79252f
	struct toks_driver_ctx_impl * ictx;
79252f
	ictx = toks_get_driver_ictx(dctx);
79252f
79252f
	if (ictx->refstr) {
79252f
		toks_free(ictx->refstr);
79252f
		ictx->refstr = 0;
79252f
	}
79252f
79252f
	if (refstr && (ictx->refstr = toks_calloc(1,toks_strlen(refstr)+1)))
79252f
		toks_strcpy(ictx->refstr,refstr);
79252f
}
79252f
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