summaryrefslogtreecommitdiffhomepage
path: root/include/ntapi/nt_tty.h
blob: 95e1715ae9dda8140fda0559f6bfc4fa88b7a70d (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
#ifndef _NT_TTY_H_
#define _NT_TTY_H_

/**
 *  tty api:
 *  -----------
 *  this header describes the tty interfaces that are used
 *  by native applications and libraries to communicate with
 *  ntctty, the project's native subsystem and pty server.
**/

#include "nt_abi.h"
#include "nt_compiler.h"
#include "nt_object.h"
#include "nt_process.h"
#include "nt_port.h"
#include "nt_termios.h"
#include "nt_sem.h"
#include "nt_msq.h"
#include "nt_afl.h"

/* tty affiliation */
typedef struct _nt_tty_affiliation {
	char	group1[8];
	char	group2[4];
	char	group3[4];
	char	group4[4];
	char	group5[12];
} nt_tty_affiliation;

#define NT_TTY_AFFILIATION_GUID_DEFAULT	{0xeb564abf, 0x0714,0x4cc9,{0x83,0x55,0xf9,0x89,0xdb,0xab,0x49,0x5c}}
#define NT_TTY_AFFILIATION_GUID_POSIX	{0xe35ed272, 0x9e55,0x46c1,{0x82,0x51,0x02,0x2a,0x59,0xe6,0xc4,0x80}}

#define NT_TTY_AFFILIATION_DEFAULT {				\
	{'e','b','5','6','4','a','b','f'},			\
	{'0','7','1','4'},					\
	{'4','c','c','9'},					\
	{'8','3','5','5'},					\
	{'f','9','8','9','d','b','a','b','4','9','5','c'}}

#define NT_TTY_AFFILIATION_POSIX {				\
	{'e','3','5','e','d','2','7','2'},			\
	{'9','e','5','5'},					\
	{'4','6','c','1'},					\
	{'8','2','5','1'},					\
	{'0','2','2','a','5','9','e','6','c','4','8','0'}}

typedef enum _nt_tty_opcode {
	NT_TTY_CLIENT_OPCODE_BASE	= 0x40000,
	/* primary connection */
	NT_TTY_CLIENT_SESSION_CONNECT	= NT_TTY_CLIENT_OPCODE_BASE,
	NT_TTY_CLIENT_SESSION_DISCONNECT,
	NT_TTY_CLIENT_SESSION_QUERY,
	NT_TTY_CLIENT_SESSION_SET,
	/* server-to-server coordination */
	NT_TTY_CLIENT_SESSION_SYNCHRONIZE,
	NT_TTY_CLIENT_SESSION_TRANSFER,
	/* process registration */
	NT_TTY_CLIENT_PROCESS_REGISTER,
	NT_TTY_CLIENT_PROCESS_UNREGISTER,
	/* session information */
	NT_TTY_QUERY_INFORMATION_SERVER,
	NT_TTY_QUERY_INFORMATION_SERVICE,
	NT_TTY_QUERY_INFORMATION_SESSION,
	NT_TTY_QUERY_INFORMATION_PROCESS,
	NT_TTY_QUERY_INFORMATION_THREAD,
	NT_TTY_QUERY_INFORMATION_SECTION,
	NT_TTY_QUERY_INFORMATION_PTY,
	NT_TTY_QUERY_INFORMATION_SEMAPHORE,
	NT_TTY_QUERY_INFORMATION_MSGQUEUE,
	NT_TTY_QUERY_INFORMATION_AFLOCK,
	/* network information */
	NT_TTY_QUERY_INFORMATION_NETWORK,
	NT_TTY_QUERY_INFORMATION_CLUSTER,
	NT_TTY_QUERY_INFORMATION_HOST,
	NT_TTY_QUERY_INFORMATION_SHARE,
	NT_TTY_QUERY_INFORMATION_USER,
	NT_TTY_QUERY_INFORMATION_GROUP,
	NT_TTY_QUERY_INFORMATION_LOGON,
	NT_TTY_QUERY_INFORMATION_POLICY,
	/* session log */
	NT_TTY_LOG_ENTRY,
	NT_TTY_LOG_QUERY,
	/* peer daemon calls */
	NT_TTY_REQUEST_PEER,
	NT_TTY_SIGNAL_PEER,
	/* pty */
	NT_TTY_PTY_OPEN,
	NT_TTY_PTY_CLOSE,
	NT_TTY_PTY_READ,
	NT_TTY_PTY_WRITE,
	NT_TTY_PTY_QUERY,
	NT_TTY_PTY_SET,
	NT_TTY_PTY_FCNTL,
	NT_TTY_PTY_IOCTL,
	NT_TTY_PTY_CANCEL,
	NT_TTY_PTY_PEEK,
	/* semaphore */
	NT_TTY_SEM_ALLOC,
	NT_TTY_SEM_FREE,
	NT_TTY_SEM_OPEN,
	NT_TTY_SEM_CLOSE,
	NT_TTY_SEM_QUERY,
	NT_TTY_SEM_SET,
	NT_TTY_SEM_FCNTL,
	NT_TTY_SEM_IOCTL,
	NT_TTY_SEM_CANCEL,
	NT_TTY_SEM_TRACE,
	NT_TTY_SEM_TRANSFER,
	NT_TTY_SEM_WAIT,
	/* msgqueue */
	NT_TTY_MSQ_ALLOC,
	NT_TTY_MSQ_FREE,
	NT_TTY_MSQ_OPEN,
	NT_TTY_MSQ_CLOSE,
	NT_TTY_MSQ_SEND,
	NT_TTY_MSQ_RECV,
	NT_TTY_MSQ_QUERY,
	NT_TTY_MSQ_SET,
	NT_TTY_MSQ_FCNTL,
	NT_TTY_MSQ_IOCTL,
	NT_TTY_MSQ_CANCEL,
	NT_TTY_MSQ_TRACE,
	NT_TTY_MSQ_TRANSFER,
	NT_TTY_MSQ_WAIT,
	/* aflock */
	NT_TTY_AFL_ALLOC,
	NT_TTY_AFL_FREE,
	NT_TTY_AFL_OPEN,
	NT_TTY_AFL_CLOSE,
	NT_TTY_AFL_QUERY,
	NT_TTY_AFL_SET,
	NT_TTY_AFL_FCNTL,
	NT_TTY_AFL_IOCTL,
	NT_TTY_AFL_CANCEL,
	NT_TTY_AFL_TRACE,
	NT_TTY_AFL_TRANSFER,
	NT_TTY_AFL_WAIT,
	/* exclusive upper limit */
	NT_TTY_CLIENT_OPCODE_CAP
} nt_tty_opcode;


typedef enum _nt_tty_session_type {
	NT_TTY_SESSION_PRIMARY,
	NT_TTY_SESSION_SECONDARY,
	NT_TTY_SESSION_PRIVATE
} nt_tty_session_type;


typedef enum _nt_tty_session_subtype {
	NT_TTY_SESSION_SUBTYPE_DEFAULT,
	NT_TTY_SESSION_SUBTYPE_CAP,
} nt_tty_session_subtype;


typedef enum _nt_tty_server_info_class {
	NT_TTY_SERVER_BASIC_INFORMATION,
	NT_TTY_SERVER_PTM_SLOT_INFORMATION,
	NT_TTY_SERVER_PTS_SLOT_INFORMATION,
	NT_TTY_SERVER_DBM_SLOT_INFORMATION,
	NT_TTY_SERVER_DBG_SLOT_INFORMATION,
	NT_TTY_SERVER_SEM_SLOT_INFORMATION,
	NT_TTY_SERVER_MSQ_SLOT_INFORMATION,
	NT_TTY_SERVER_AFL_SLOT_INFORMATION,
	NT_TTY_SERVER_INFORMATION_CAP
} nt_tty_server_info_class;


typedef enum _nt_pty_info_class {
	NT_PTY_BASIC_INFORMATION,
	NT_PTY_SLOT_INFORMATION,
	NT_PTY_CLIENT_INFORMATION,
	NT_PTY_CONTEXT_INFORMATION,
	NT_PTY_INHERIT_INFORMATION,
	NT_PTY_OFD_INFORMATION,
	NT_PTY_INFORMATION_CAP
} nt_pty_info_class;


typedef enum _nt_tty_log_info_type {
	NT_TTY_LOG_INFO_BINARY_DATA,
	NT_TTY_LOG_INFO_STRING_DATA,
	NT_TTY_LOG_INFO_INTEGER_ARRAY,
	NT_TTY_LOG_INFO_POINTER_ARRAY,
	NT_TTY_LOG_INFO_EXCEPTION_RECORD,
	NT_TTY_LOG_INFO_EXCEPTION_ENTRY,
	NT_TTY_LOG_INFO_FLOW_ENTRY,
	NT_TTY_LOG_INFO_ERROR_ENTRY,
	NT_TTY_LOG_INFO_IPC_ENTRY,
	NT_TTY_LOG_INFO_SIGNAL_ENTRY,
	NT_TTY_LOG_INFO_CAP,
} nt_tty_log_info_type;

/*************************************************************/
/* log entry data passing, populating loginfo.data[]         */
/*                                                           */
/* + start with structure-based elements;                    */
/* + continue with 8-byte elements;                          */
/* + continue with pointer-size elements                     */
/* + continue with 4-byte elements;                          */
/* + end with null-terminated utf-8 strings                  */
/*                                                           */
/* + use loginfo.meta to indicate which elements are present */
/*************************************************************/


/* log info entry data elements */
#define NT_TTY_LOG_INFO_ENTRY_INTERPRETATION(x) ((x) & 0xff)

#define NT_TTY_LOG_INFO_ENTRY_POINTER_ELEMENT_1 (1 << 12)
#define NT_TTY_LOG_INFO_ENTRY_POINTER_ELEMENT_2 (1 << 13)
#define NT_TTY_LOG_INFO_ENTRY_POINTER_ELEMENT_3 (1 << 14)
#define NT_TTY_LOG_INFO_ENTRY_POINTER_ELEMENT_4 (1 << 15)

#define NT_TTY_LOG_INFO_ENTRY_STRUCT_ELEMENT_1  (1 << 16)
#define NT_TTY_LOG_INFO_ENTRY_STRUCT_ELEMENT_2  (1 << 17)
#define NT_TTY_LOG_INFO_ENTRY_STRUCT_ELEMENT_3  (1 << 18)
#define NT_TTY_LOG_INFO_ENTRY_STRUCT_ELEMENT_4  (1 << 19)

#define NT_TTY_LOG_INFO_ENTRY_UINT64_ELEMENT_1  (1 << 20)
#define NT_TTY_LOG_INFO_ENTRY_UINT64_ELEMENT_2  (1 << 21)
#define NT_TTY_LOG_INFO_ENTRY_UINT64_ELEMENT_3  (1 << 22)
#define NT_TTY_LOG_INFO_ENTRY_UINT64_ELEMENT_4  (1 << 23)

#define NT_TTY_LOG_INFO_ENTRY_UINT32_ELEMENT_1  (1 << 24)
#define NT_TTY_LOG_INFO_ENTRY_UINT32_ELEMENT_2  (1 << 25)
#define NT_TTY_LOG_INFO_ENTRY_UINT32_ELEMENT_3  (1 << 26)
#define NT_TTY_LOG_INFO_ENTRY_UINT32_ELEMENT_4  (1 << 27)

#define NT_TTY_LOG_INFO_ENTRY_STRING_ELEMENT_1  (1 << 28)
#define NT_TTY_LOG_INFO_ENTRY_STRING_ELEMENT_2  (1 << 29)
#define NT_TTY_LOG_INFO_ENTRY_STRING_ELEMENT_3  (1 << 30)
#define NT_TTY_LOG_INFO_ENTRY_STRING_ELEMENT_4  (1 << 31)

/* client process registration flags */
#define NT_TTY_INHERIT_HANDLES 	0x0001


typedef struct __attr_ptr_size_aligned__ _nt_tty_msg_info {
	uintptr_t	opdata;
	uint32_t	opcode;
	int32_t		status;
	void *		exarg;
} nt_tty_msg_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_register_info {
	uintptr_t	process_id;
	uintptr_t	thread_id;
	uintptr_t	flags;
	uintptr_t	reserved;
} nt_tty_register_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_server_basic_info {
	nt_port_attr	attr;
	intptr_t	pid;
	intptr_t	tid;
} nt_tty_server_basic_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_pts_slot_info {
	int32_t		blkidx;
	int32_t		blkpts;
	int32_t		blkcnt;
	int32_t		blkcap;
	uint32_t	ptsmap[32];
} nt_tty_pts_slot_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_server_info {
	nt_tty_server_info_class	info_class;
	uint32_t			info_length;
	uintptr_t			info_buffer[];
} nt_tty_server_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_service_info {
	nt_port_attr	attr;
	uint32_t	key;
	uint32_t	id;
} nt_tty_service_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_section_info {
	nt_port_attr	attr;
	void *		section;
	void *		section_addr;
	size_t		section_size;
} nt_tty_section_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_peer_info {
	uint32_t	opcode;
	uint32_t	flags;
	nt_guid		service;
	nt_port_attr	peer;
} nt_tty_peer_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_sigctl_info {
	void *			hpty;
	nt_guid			guid;
	nt_luid			luid;
	uint32_t		ctlcode;
	int32_t			cccode;
	nt_client_id		cid;
	uintptr_t		ctxarg[4];
	struct tty_termios	terminfo;
	struct tty_winsize	winsize;
	nt_iosb			iosb;
} nt_tty_sigctl_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_log_info {
	int32_t		type;
	uint32_t	meta;
	nt_cid		cid;
	uint32_t	data[0x30];
} nt_tty_log_info;


typedef struct __attr_ptr_size_aligned__ _nt_pty_fd_info {
	void *		hpty;
	void *		section;
	void *		section_addr;
	size_t		section_size;
	nt_guid		guid;
	nt_luid		luid;
	uint32_t	access;
	uint32_t	flags;
	uint32_t	share;
	uint32_t	options;
	intptr_t	state;
	void *		hevent[2];
} nt_pty_fd_info;


typedef struct __attr_ptr_size_aligned__ _nt_pty_context_info {
	void *		hpty;
	nt_guid		guid;
	nt_luid		luid;
	uintptr_t	ctxarg[4];
} nt_pty_context_info;


typedef struct __attr_ptr_size_aligned__ _nt_pty_io_info {
	void *		hpty;
	void *		hevent;
	void *		reserved;
	void *		apc_routine;
	void *		apc_context;
	nt_iosb *	riosb;
	void *		raddr;
	nt_iosb		iosb;
	off_t		offset;
	size_t		nbytes;
	uint32_t	key;
	uint32_t	npending;
	nt_guid		guid;
	nt_luid		luid;
} nt_pty_io_info;


typedef struct __attr_ptr_size_aligned__ _nt_pty_client_info {
	uintptr_t	any[4];
} nt_pty_client_info;


typedef struct __attr_ptr_size_aligned__ _nt_pty_inherit_info {
	void *		hpty;
	nt_guid		guid;
	nt_luid		luid;
	uint32_t	access;
	uint32_t	flags;
	uint32_t	share;
	uint32_t	options;
} nt_pty_inherit_info;

typedef struct __attr_ptr_size_aligned__ _nt_tty_session_info {
	int32_t		pid;
	int32_t		pgid;
	int32_t		sid;
	int32_t		syspid;
} nt_tty_session_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_ipc_info {
	nt_port_attr	ctrlsvc;
	uint32_t	ipckeys[6];
	void *		hevent;
	void *		apc_routine;
	void *		apc_context;
	nt_iosb *	riosb;
} nt_tty_ipc_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_sync_info {
	nt_client_id	cid;
	nt_port_attr	ipcsvc;
	uint32_t	ipckeys[6];
	void *		hevent;
	void *		apc_routine;
	void *		apc_context;
	nt_iosb *	riosb;
} nt_tty_sync_info;



typedef struct __attr_ptr_size_aligned__ _nt_tty_transfer_info {
	nt_client_id	ccid;
	nt_client_id	tcid;
	uint32_t	ipckeys[6];
	void *		hevent;
	void *		apc_routine;
	void *		apc_context;
	nt_iosb *	riosb;
} nt_tty_transfer_info;


typedef struct __attr_ptr_size_aligned__ _nt_tty_register_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_tty_register_info	reginfo;
	} data;
} nt_tty_register_msg;


typedef struct __attr_ptr_size_aligned__ _nt_tty_server_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_tty_server_info	srvinfo;
	} data;
} nt_tty_server_msg;


typedef struct __attr_ptr_size_aligned__ _nt_tty_service_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_tty_service_info	svcinfo;
	} data;
} nt_tty_service_msg;


typedef struct __attr_ptr_size_aligned__ _nt_tty_section_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_tty_section_info	secinfo;
	} data;
} nt_tty_section_msg;


typedef struct __attr_ptr_size_aligned__ _nt_tty_peer_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_tty_peer_info	peerinfo;
	} data;
} nt_tty_peer_msg;


typedef struct __attr_ptr_size_aligned__ _nt_tty_pid_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_user_process_info	pidinfo;
	} data;
} nt_tty_pid_msg;


typedef struct __attr_ptr_size_aligned__ _nt_tty_ipc_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_tty_ipc_info		ipcinfo;
	} data;
} nt_tty_ipc_msg;


typedef struct __attr_ptr_size_aligned__ _nt_tty_sync_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_tty_sync_info	syncinfo;
	} data;
} nt_tty_sync_msg;


typedef struct __attr_ptr_size_aligned__ _nt_tty_transfer_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_tty_transfer_info	transferinfo;
	} data;
} nt_tty_transfer_msg;


typedef struct __attr_ptr_size_aligned__ _nt_tty_log_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_tty_log_info		loginfo;
	} data;
} nt_tty_log_msg;


typedef struct __attr_ptr_size_aligned__ _nt_pty_fd_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_pty_fd_info		fdinfo;
	} data;
} nt_pty_fd_msg;


typedef struct __attr_ptr_size_aligned__ _nt_pty_io_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_pty_io_info		ioinfo;
	} data;
} nt_pty_io_msg;


typedef struct __attr_ptr_size_aligned__ _nt_pty_sigctl_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_tty_sigctl_info	ctlinfo;
	} data;
} nt_pty_sigctl_msg;


typedef struct __attr_ptr_size_aligned__ _nt_sem_info_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_sem_info		seminfo;
	} data;
} nt_sem_info_msg;


typedef struct __attr_ptr_size_aligned__ _nt_msq_info_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_msq_info		msqinfo;
	} data;
} nt_msq_info_msg;


typedef struct __attr_ptr_size_aligned__ _nt_afl_info_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_afl_info		aflinfo;
	} data;
} nt_afl_info_msg;


typedef struct __attr_ptr_size_aligned__ _nt_tty_session_msg {
	nt_port_message			header;
	struct {
		nt_tty_msg_info		ttyinfo;
		nt_tty_session_info	sessioninfo;
	} data;
} nt_tty_session_msg;


typedef struct __attr_ptr_size_aligned__ _nt_tty_port_msg {
	nt_port_message			header;
	nt_tty_msg_info			ttyinfo;
	union {
		nt_tty_register_info	reginfo;
		nt_tty_peer_info	peerinfo;
		nt_tty_sigctl_info	ctlinfo;
		nt_tty_ipc_info		ipcinfo;
		nt_tty_sync_info	syncinfo;
		nt_tty_log_info		loginfo;
		nt_user_process_info	pidinfo;
		nt_tty_transfer_info	transferinfo;
		nt_pty_fd_info		fdinfo;
		nt_pty_io_info		ioinfo;
		nt_pty_client_info	clientinfo;
		nt_tty_session_info	sessioninfo;
		nt_tty_service_info	svcinfo;
		nt_tty_section_info	secinfo;
		nt_sem_info		seminfo;
		nt_msq_info		msqinfo;
		nt_afl_info		aflinfo;
	};
} nt_tty_port_msg;


__assert_aligned_size(nt_tty_msg_info,		__SIZEOF_POINTER__);
__assert_aligned_size(nt_tty_register_info,	__SIZEOF_POINTER__);
__assert_aligned_size(nt_tty_peer_info,		__SIZEOF_POINTER__);
__assert_aligned_size(nt_tty_sigctl_info,	__SIZEOF_POINTER__);
__assert_aligned_size(nt_pty_fd_info,		__SIZEOF_POINTER__);
__assert_aligned_size(nt_pty_io_info,		__SIZEOF_POINTER__);
__assert_aligned_size(nt_tty_register_msg,	__SIZEOF_POINTER__);
__assert_aligned_size(nt_tty_peer_msg,		__SIZEOF_POINTER__);
__assert_aligned_size(nt_pty_sigctl_msg,	__SIZEOF_POINTER__);
__assert_aligned_size(nt_pty_fd_msg,		__SIZEOF_POINTER__);
__assert_aligned_size(nt_pty_io_msg,		__SIZEOF_POINTER__);
__assert_aligned_size(nt_tty_port_msg,		__SIZEOF_POINTER__);
__assert_aligned_size(nt_tty_ipc_msg,		__SIZEOF_POINTER__);
__assert_aligned_size(nt_tty_sync_msg,		__SIZEOF_POINTER__);
__assert_aligned_size(nt_tty_transfer_msg,	__SIZEOF_POINTER__);


/* tty session */
typedef int32_t __stdcall	ntapi_tty_create_session(
	__out	void **			hport,
	__out	nt_port_name *		port_name,
	__in	nt_tty_session_type	type,
	__in	nt_tty_session_subtype	subtype,
	__in	const nt_guid *		guid		__optional,
	__in	wchar16_t *		image_name,
	__in	void *			htty		__optional);


typedef int32_t __stdcall	ntapi_tty_join_session(
	__out	void **			hport,
	__out	nt_port_name *		port_name,
	__in	nt_port_attr *		port_attr,
	__in	nt_tty_session_type	type);


typedef int32_t __stdcall	ntapi_tty_connect(
	__out	void **			hport,
	__in	wchar16_t *		tty_port_name,
	__in	int32_t			impersonation_level);


typedef int32_t __stdcall	ntapi_tty_client_session_disconnect(
	__in	void *			hport);


typedef int32_t __stdcall	ntapi_tty_client_session_query(
	__in	void *			hport,
	__out	nt_tty_session_info *	sessioninfo);


typedef int32_t __stdcall	ntapi_tty_client_session_set(
	__in	void *			hport,
	__in	nt_tty_session_info *	sessioninfo);


typedef int32_t __stdcall	ntapi_tty_client_process_register(
	__in	void *			hport,
	__in	uintptr_t		process_id,
	__in	uintptr_t		thread_id,
	__in	uintptr_t		flags,
	__in	nt_large_integer *	reserved);


typedef int32_t __stdcall ntapi_tty_query_information_section(
	__in	void *			hport,
	__out	nt_io_status_block *	iosb,
	__out	nt_tty_section_info *	secinfo,
	__in	const nt_guid *		guid);


typedef int32_t __stdcall ntapi_tty_query_information_server(
	__in	void *			hport,
	__out	nt_io_status_block *	iosb,
	__out	void *			tty_info,
	__in	uint32_t		tty_info_length,
	__in	int			tty_info_class);


typedef int32_t __stdcall ntapi_tty_query_information_service(
	__in	void *			hport,
	__out	nt_io_status_block *	iosb,
	__out	nt_tty_service_info *	svcinfo,
	__in	const nt_guid *		guid,
	__in	uint32_t		key,
	__in	uint32_t		id);


typedef int32_t __stdcall ntapi_tty_query_server_pts_slot_info(
	__in	void *			hport,
	__out	nt_tty_pts_slot_info *	pts_slot_info,
	__in	intptr_t		blkidx);


/* pty api */
typedef struct nt_pty_context nt_pty;

typedef int32_t	__stdcall ntapi_pty_open(
	__in	void *			hport,
	__out	nt_pty **		pty,
	__in	uint32_t		desired_access,
	__in	nt_object_attributes*	obj_attr,
	__out	nt_iosb *		iosb,
	__in	uint32_t		share_access,
	__in	uint32_t		open_options);


typedef int32_t	__stdcall ntapi_pty_open_pair(
	__in	void *			hport,
	__out	nt_pty **		pty,
	__in	uint32_t		desired_access,
	__in	nt_object_attributes*	obj_attr,
	__out	nt_iosb *		iosb,
	__in	uint32_t		share_access,
	__in	uint32_t		open_options);


typedef int32_t	__stdcall ntapi_pty_reopen(
	__in	void *			hport,
	__in	nt_pty *		pty);


typedef int32_t	__stdcall ntapi_pty_inherit(
	__in	void *			hport,
	__out	nt_pty **		pty,
	__in 	nt_pty_client_info * 	client_info);


typedef int32_t	__stdcall ntapi_pty_inherit_runtime_ctty(
	__in	void *			hport,
     __in_out	nt_runtime_data *	rtdata);


typedef int32_t __stdcall ntapi_pty_close(
	__in	nt_pty *		pty);


typedef int32_t	__stdcall ntapi_pty_read(
	__in	nt_pty *		pty,
	__in	void *			hevent		__optional,
	__in	nt_io_apc_routine *	apc_routine	__optional,
	__in	void *			apc_context	__optional,
	__out	nt_iosb *		iosb,
	__out	void *			buffer,
	__in	uint32_t		nbytes,
	__in	nt_large_integer *	offset		__optional,
	__in	uint32_t *		key		__optional);


typedef int32_t __stdcall ntapi_pty_write(
	__in	nt_pty *		pty,
	__in 	void *			hevent		__optional,
	__in	nt_io_apc_routine *	apc_routine	__optional,
	__in	void * 			apc_context	__optional,
	__out	nt_iosb *		iosb,
	__in	void * 			buffer,
	__in	uint32_t		nbytes,
	__in	nt_large_integer *	offset		__optional,
	__in	uint32_t *		key		__optional);


typedef int32_t	__stdcall ntapi_pty_fcntl(
	__in	nt_pty *		pty,
	__in	void *			hevent			__optional,
	__in	nt_io_apc_routine *	apc_routine		__optional,
	__in	void *			apc_context		__optional,
	__out	nt_iosb *		iosb,
	__in	uint32_t		fs_control_code,
	__in	void *			input_buffer		__optional,
	__in	uint32_t		input_buffer_length,
	__out	void *			output_buffer		__optional,
	__in	uint32_t		output_buffer_length);


typedef int32_t	__stdcall ntapi_pty_ioctl(
	__in	nt_pty *		pty,
	__in	void *			hevent			__optional,
	__in	nt_io_apc_routine *	apc_routine		__optional,
	__in	void *			apc_context		__optional,
	__out	nt_iosb *		iosb,
	__in	uint32_t		io_control_code,
	__in	void *			input_buffer		__optional,
	__in	uint32_t		input_buffer_length,
	__out	void *			output_buffer		__optional,
	__in	uint32_t		output_buffer_length);


typedef int32_t	__stdcall ntapi_pty_query(
	__in	nt_pty *		pty,
	__out	nt_io_status_block *	iosb,
	__out	void *			pty_info,
	__in	uint32_t		pty_info_length,
	__in	nt_pty_info_class	pty_info_class);


typedef int32_t	__stdcall ntapi_pty_xquery(
	__in	void *			hport,
	__out	nt_io_status_block *	iosb,
	__out	void *			pty_info,
	__in	uint32_t		pty_info_length,
	__in	nt_pty_info_class	pty_info_class,
	__in	nt_pty_client_info *	pty_client_info);


typedef int32_t	__stdcall ntapi_pty_set(
	__in	nt_pty *		hfile,
	__out	nt_io_status_block *	iosb,
	__in	void *			pty_info,
	__in	uint32_t		pty_info_length,
	__in	nt_pty_info_class	pty_info_class);


typedef int32_t	__stdcall ntapi_pty_cancel(
	__in	nt_pty *		pty,
	__out	nt_iosb *		iosb);


/* peer daemon calls */
typedef int32_t __stdcall ntapi_tty_request_peer(
	__in	void *		hport,
	__in	int32_t		opcode,
	__in	uint32_t	flags,
	__in	const nt_guid *	service,
	__in	nt_port_attr *	peer);


#endif