Blame src/internal/ntapi_impl.h

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
4256e2
/*  Copyright (C) 2013--2016  Z. Gilboa                 */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#ifndef ___NTAPI_IMPL_H_
dd89bb
#define ___NTAPI_IMPL_H_
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_object.h>
dd89bb
#include <ntapi/nt_sysinfo.h>
dd89bb
#include <ntapi/nt_thread.h>
dd89bb
#include <ntapi/nt_process.h>
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include "ntapi_hash_table.h"
dd89bb
#include "ntapi_context.h"
dd89bb
#include "ntapi_fnapi.h"
dd89bb
dd89bb
#define __NT_BASED_NAMED_OBJECTS	{'\\','B','a','s','e', \
dd89bb
					'N','a','m','e','d', \
dd89bb
					'O','b','j','e','c','t','s'}
dd89bb
dd89bb
/* helper macros */
dd89bb
#define __NT_ROUND_UP_TO_POWER_OF_2(x,y)(x + (y-1)) & ~(y-1)
dd89bb
#define __NT_IS_MISALIGNED_BUFFER(x)	((!(uintptr_t)x) || ((uintptr_t)x % sizeof(size_t)))
dd89bb
#define __NT_IS_MISALIGNED_LENGTH(x)	(x % sizeof(size_t))
dd89bb
#define __NT_FILE_SYNC_IO		(NT_FILE_SYNCHRONOUS_IO_ALERT|NT_FILE_SYNCHRONOUS_IO_NONALERT)
dd89bb
dd89bb
/* user-defined options: head */
dd89bb
#ifndef __NT_TTY_MONITORS
dd89bb
#define __NT_TTY_MONITORS		0x10
dd89bb
#endif
dd89bb
dd89bb
#ifndef __NT_FORK_CHILD_WAIT_MILLISEC
dd89bb
#define __NT_FORK_CHILD_WAIT_MILLISEC	60000
dd89bb
#endif
dd89bb
dd89bb
#ifndef __NT_SYNC_BLOCK_LOCK_TRIES
dd89bb
#define __NT_SYNC_BLOCK_LOCK_TRIES	1024
dd89bb
#endif
dd89bb
/* user-defined options: tail */
dd89bb
dd89bb
/* internal page size */
dd89bb
#ifndef __NT_INTERNAL_PAGE_SIZE
dd89bb
#define __NT_INTERNAL_PAGE_SIZE		4096
dd89bb
#endif
dd89bb
dd89bb
/* .bss section */
dd89bb
#ifndef __NT_BSS_RESERVED_PAGES
dd89bb
#define __NT_BSS_RESERVED_PAGES		8
dd89bb
#endif
dd89bb
dd89bb
/* runtime buffers */
dd89bb
#define __NT_BSS_ARGV_BUFFER_SIZE	__NT_INTERNAL_PAGE_SIZE * 2
dd89bb
dd89bb
#define __NT_BSS_ARGV_MAX_IDX		__NT_BSS_ARGV_BUFFER_SIZE \
dd89bb
					/ sizeof(uintptr_t)
dd89bb
dd89bb
#define __NT_BSS_ARGS_BUFFER_SIZE	__NT_INTERNAL_PAGE_SIZE \
dd89bb
					* __NT_BSS_RESERVED_PAGES \
dd89bb
					- __NT_BSS_ARGV_BUFFER_SIZE
dd89bb
dd89bb
/* ntapi .bss section structure */
dd89bb
typedef struct ___ntapi_img_sec_bss {
dd89bb
	wchar16_t *	argv_envp_array[__NT_BSS_ARGV_MAX_IDX];
dd89bb
	char		args_envs_buffer[__NT_BSS_ARGS_BUFFER_SIZE];
dd89bb
} __ntapi_img_sec_bss;
dd89bb
dd89bb
dd89bb
/* ntapi library internals */
dd89bb
typedef struct __attr_ptr_size_aligned__ _ntapi_internals {
dd89bb
	nt_runtime_data *				rtdata;
dd89bb
	nt_port_name *					subsystem;
72fe5e
	nt_security_descriptor				seq_desc;
72fe5e
	nt_security_quality_of_service			seq_qos;
a3e9aa
	void *						htoken;
dd89bb
	void *						hport_tty_session;
dd89bb
	void *						hport_tty_daemon;
dd89bb
	void *						hport_tty_debug;
dd89bb
	void *						hport_tty_monitor[__NT_TTY_MONITORS];
dd89bb
	size_t						nt_mem_page_size;
dd89bb
	size_t						nt_mem_allocation_granularity;
dd89bb
	size_t						ntapi_internals_alloc_size;
dd89bb
	void **						csr_port_handle_addr;
dd89bb
	void *						hdev_mount_point_mgr;
dd89bb
	void *						hany[8];
dd89bb
	intptr_t					hlock;
dd89bb
	uintptr_t					v1_pipe_counter;
dd89bb
	ntapi_tt_get_csr_port_handle_addr_by_logic *	tt_get_csr_port_handle_addr_by_logic;
dd89bb
	__ntapi_img_sec_bss *				ntapi_img_sec_bss;
dd89bb
} ntapi_internals;
dd89bb
dd89bb
dd89bb
/* __ntapi_img_sec_data */
dd89bb
typedef struct __attr_ptr_size_aligned__ ___ntapi_img_sec_rdata {
dd89bb
	ntapi_hashed_symbol	__ntapi_import_table[__NT_IMPORTED_SYMBOLS_ARRAY_SIZE];
dd89bb
	ntapi_vtbl * 		__ntapi;
dd89bb
	nt_port_name		__session_name;
dd89bb
	ntapi_internals *	__internals;
dd89bb
} __ntapi_img_sec_rdata;
dd89bb
dd89bb
union __ntapi_img_rdata {
dd89bb
	__ntapi_img_sec_rdata	img_sec_data;
dd89bb
	char			buffer[__NT_INTERNAL_PAGE_SIZE];
dd89bb
};
dd89bb
dd89bb
dd89bb
/* accessor table */
dd89bb
extern	ntapi_vtbl	___ntapi;
dd89bb
extern	ntapi_vtbl	___ntapi_shadow;
dd89bb
#define	__ntapi		(&___ntapi)
dd89bb
dd89bb
dd89bb
/* access to library internals */
dd89bb
ntapi_internals * __cdecl __ntapi_internals(void);
dd89bb
dd89bb
d37adb
/* helper functions */
d37adb
int32_t __ntapi_tt_open_file_utf8(void ** hfile, void * hat, const char * arg, int fprivate, wchar16_t *, uint32_t);
d37adb
int32_t __ntapi_tt_open_dir_utf8(void ** hfile, void * hat, const char * arg, int fprivate, wchar16_t *, uint32_t);
d37adb
d37adb
dd89bb
/* debug */
dd89bb
#define __ntidx(x) (&(((ntapi_vtbl *)0)->x)) / sizeof(size_t)
dd89bb
dd89bb
dd89bb
#endif