summaryrefslogtreecommitdiffhomepage
path: root/src/internal/ntapi_impl.h
blob: 7bc010a7a64d942f9f7bc15225b21b358641b33e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2016  Z. Gilboa                 */
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
/********************************************************/

#ifndef ___NTAPI_IMPL_H_
#define ___NTAPI_IMPL_H_

#include <psxtypes/psxtypes.h>
#include <ntapi/nt_object.h>
#include <ntapi/nt_sysinfo.h>
#include <ntapi/nt_thread.h>
#include <ntapi/nt_process.h>
#include <ntapi/ntapi.h>
#include "ntapi_hash_table.h"
#include "ntapi_context.h"
#include "ntapi_fnapi.h"

#define __NT_BASED_NAMED_OBJECTS	{'\\','B','a','s','e', \
					'N','a','m','e','d', \
					'O','b','j','e','c','t','s'}

/* helper macros */
#define __NT_ROUND_UP_TO_POWER_OF_2(x,y)(x + (y-1)) & ~(y-1)
#define __NT_IS_MISALIGNED_BUFFER(x)	((!(uintptr_t)x) || ((uintptr_t)x % sizeof(size_t)))
#define __NT_IS_MISALIGNED_LENGTH(x)	(x % sizeof(size_t))
#define __NT_FILE_SYNC_IO		(NT_FILE_SYNCHRONOUS_IO_ALERT|NT_FILE_SYNCHRONOUS_IO_NONALERT)

/* user-defined options: head */
#ifndef __NT_TTY_MONITORS
#define __NT_TTY_MONITORS		0x10
#endif

#ifndef __NT_FORK_CHILD_WAIT_MILLISEC
#define __NT_FORK_CHILD_WAIT_MILLISEC	60000
#endif

#ifndef __NT_SYNC_BLOCK_LOCK_TRIES
#define __NT_SYNC_BLOCK_LOCK_TRIES	1024
#endif
/* user-defined options: tail */

/* internal page size */
#ifndef __NT_INTERNAL_PAGE_SIZE
#define __NT_INTERNAL_PAGE_SIZE		4096
#endif

/* .bss section */
#ifndef __NT_BSS_RESERVED_PAGES
#define __NT_BSS_RESERVED_PAGES		8
#endif

/* runtime buffers */
#define __NT_BSS_ARGV_BUFFER_SIZE	__NT_INTERNAL_PAGE_SIZE * 2

#define __NT_BSS_ARGV_MAX_IDX		__NT_BSS_ARGV_BUFFER_SIZE \
					/ sizeof(uintptr_t)

#define __NT_BSS_ARGS_BUFFER_SIZE	__NT_INTERNAL_PAGE_SIZE \
					* __NT_BSS_RESERVED_PAGES \
					- __NT_BSS_ARGV_BUFFER_SIZE

/* ntapi .bss section structure */
typedef struct ___ntapi_img_sec_bss {
	wchar16_t *	argv_envp_array[__NT_BSS_ARGV_MAX_IDX];
	char		args_envs_buffer[__NT_BSS_ARGS_BUFFER_SIZE];
} __ntapi_img_sec_bss;


/* ntapi library internals */
typedef struct __attr_ptr_size_aligned__ _ntapi_internals {
	nt_runtime_data *				rtdata;
	nt_port_name *					subsystem;
	void *						htoken;
	void *						hport_tty_session;
	void *						hport_tty_daemon;
	void *						hport_tty_debug;
	void *						hport_tty_monitor[__NT_TTY_MONITORS];
	size_t						nt_mem_page_size;
	size_t						nt_mem_allocation_granularity;
	size_t						ntapi_internals_alloc_size;
	void **						csr_port_handle_addr;
	void *						hdev_mount_point_mgr;
	void *						hany[8];
	intptr_t					hlock;
	uintptr_t					v1_pipe_counter;
	ntapi_tt_get_csr_port_handle_addr_by_logic *	tt_get_csr_port_handle_addr_by_logic;
	__ntapi_img_sec_bss *				ntapi_img_sec_bss;
} ntapi_internals;


/* __ntapi_img_sec_data */
typedef struct __attr_ptr_size_aligned__ ___ntapi_img_sec_rdata {
	ntapi_hashed_symbol	__ntapi_import_table[__NT_IMPORTED_SYMBOLS_ARRAY_SIZE];
	ntapi_vtbl * 		__ntapi;
	nt_port_name		__session_name;
	ntapi_internals *	__internals;
} __ntapi_img_sec_rdata;

union __ntapi_img_rdata {
	__ntapi_img_sec_rdata	img_sec_data;
	char			buffer[__NT_INTERNAL_PAGE_SIZE];
};


/* accessor table */
extern	ntapi_vtbl	___ntapi;
extern	ntapi_vtbl	___ntapi_shadow;
#define	__ntapi		(&___ntapi)


/* access to library internals */
ntapi_internals * __cdecl __ntapi_internals(void);


/* helper functions */
int32_t __ntapi_tt_open_file_utf8(void ** hfile, void * hat, const char * arg, int fprivate, wchar16_t *, uint32_t);
int32_t __ntapi_tt_open_dir_utf8(void ** hfile, void * hat, const char * arg, int fprivate, wchar16_t *, uint32_t);


/* debug */
#define __ntidx(x) (&(((ntapi_vtbl *)0)->x)) / sizeof(size_t)


#endif