Blame src/internal/ntapi_impl.h

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
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)))
f96e1d
#define __NT_IS_MISALIGNED_INT_BUFFER(x)((!(uintptr_t)x) || ((uintptr_t)x % sizeof(int)))
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
1717a8
/* boolean definitions */
1717a8
#define true				(1)
1717a8
#define false				(0)
1717a8
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
30d28d
30d28d
#ifndef __NT_IPC_PAGES
cc20b3
#define __NT_IPC_PAGES			512
30d28d
#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
30d28d
#define __NT_BSS_RESERVED_PAGES		10
dd89bb
#endif
dd89bb
dd89bb
/* runtime buffers */
dd89bb
#define __NT_BSS_ARGV_BUFFER_SIZE	__NT_INTERNAL_PAGE_SIZE * 2
dd89bb
30d28d
#define __NT_BSS_IPC_BUFFER_SIZE	__NT_INTERNAL_PAGE_SIZE * 2
30d28d
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 \
30d28d
					- __NT_BSS_ARGV_BUFFER_SIZE \
30d28d
					- __NT_BSS_IPC_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];
30d28d
	size_t		ipc_buffer[__NT_BSS_IPC_BUFFER_SIZE / sizeof(size_t)];
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;
0a8487
	nt_sid_any					sid_buffer[2];
0a8487
	nt_sid *					user;
0a8487
	nt_sid *					admin;
80b89c
	void *						hprocess;
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];
30d28d
	struct dalist_ex				ipc_conns;
ef6024
	void *    volatile				ipc_pages[__NT_IPC_PAGES];
ef6024
	int32_t   volatile				ipc_page;
ef6024
	intptr_t  volatile				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
30d28d
/* ipc internals */
30d28d
typedef struct _nt_ipc_conn {
30d28d
	nt_port_attr	attr;
30d28d
	void *		hsection;
30d28d
	void *		secaddr;
30d28d
	size_t		secsize;
30d28d
} nt_ipc_conn;
30d28d
30d28d
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 */
919f42
extern	__attr_protected__ ntapi_vtbl   ___ntapi;
919f42
extern	__attr_protected__ ntapi_vtbl   ___ntapi_shadow;
919f42
#define	__ntapi                         (&___ntapi)
dd89bb
dd89bb
dd89bb
/* access to library internals */
c30fbc
__attr_protected__ ntapi_internals * __cdecl __ntapi_internals(void);
dd89bb
dd89bb
d37adb
/* helper functions */
c30fbc
__attr_protected__ int32_t __ntapi_tt_open_file_utf8(void ** hfile, void * hat, const char * arg, int fprivate, wchar16_t *, uint32_t);
c30fbc
__attr_protected__ int32_t __ntapi_tt_open_dir_utf8(void ** hfile, void * hat, const char * arg, int fprivate, wchar16_t *, uint32_t);
d37adb
ad58de
/* daemon internals */
c30fbc
__attr_protected__ int32_t __ntapi_dsr_connect_internal_client(nt_daemon_params *);
c30fbc
__attr_protected__ int32_t __ntapi_dsr_internal_client_connect(nt_daemon_params *);
ad58de
dd89bb
/* debug */
a73815
#define __ntidx(x) __offsetof(ntapi_vtbl,x) / sizeof(size_t)
dd89bb
dd89bb
dd89bb
#endif