Blame include/ntapi/nt_thread.h

dd89bb
#ifndef _NT_THREAD_H_
dd89bb
#define _NT_THREAD_H_
dd89bb
414ad3
#include "nt_abi.h"
5bfd34
#include "nt_compiler.h"
dd89bb
#include "nt_object.h"
52d044
#include "bits/nt32/nt_thread_i386.h"
52d044
#include "bits/nt64/nt_thread_x86_64.h"
dd89bb
dd89bb
typedef enum _nt_thread_info_class {
dd89bb
	NT_THREAD_BASIC_INFORMATION,
dd89bb
	NT_THREAD_TIMES,
dd89bb
	NT_THREAD_PRIORITY,
dd89bb
	NT_THREAD_BASE_PRIORITY,
dd89bb
	NT_THREAD_AFFINITY_MASK,
dd89bb
	NT_THREAD_IMPERSONATION_TOKEN,
dd89bb
	NT_THREAD_DESCRIPTOR_TABLE_ENTRY,
dd89bb
	NT_THREAD_ENABLE_ALIGNMENT_FAULT_FIXUP,
dd89bb
	NT_THREAD_EVENT_PAIR,
dd89bb
	NT_THREAD_QUERY_SET_WIN32_START_ADDRESS,
dd89bb
	NT_THREAD_ZERO_TLS_CELL,
dd89bb
	NT_THREAD_PERFORMANCE_COUNT,
dd04b7
	NT_THREAD_AM_I_LAST_THREAD,
dd89bb
	NT_THREAD_IDEAL_PROCESSOR,
dd89bb
	NT_THREAD_PRIORITY_BOOST,
dd89bb
	NT_THREAD_SET_TLS_ARRAY_ADDRESS,
dd89bb
	NT_THREAD_IS_IO_PENDING,
dd89bb
	NT_THREAD_HIDE_FROM_DEBUGGER
dd89bb
} nt_thread_info_class;
dd89bb
dd89bb
typedef enum _nt_exception_disposition {
dd89bb
	NT_EXCEPTION_CONTINUE_EXECUTION,
dd89bb
	NT_EXCEPTION_CONTINUE_SEARCH,
dd89bb
	NT_EXCEPTION_NESTED_EXCEPTION,
dd89bb
	NT_EXCEPTION_COLLIDED_UNWIND
dd89bb
} nt_exception_disposition;
dd89bb
dd89bb
dd89bb
/* special handles */
dd89bb
#define NT_CURRENT_THREAD_HANDLE (void *)(uintptr_t)-2
dd89bb
dd89bb
/* thread access bits */
dd89bb
#define NT_THREAD_TERMINATE			0x00000001
dd89bb
#define NT_THREAD_SUSPEND_RESUME		0x00000002
dd89bb
#define NT_THREAD_ALERT				0x00000004 /* fits right in the middle... */
dd89bb
#define NT_THREAD_GET_CONTEXT			0x00000008
dd89bb
#define NT_THREAD_SET_CONTEXT			0x00000010
dd89bb
#define NT_THREAD_SET_INFORMATION		0x00000020
dd89bb
#define NT_THREAD_QUERY_INFORMATION		0x00000040
dd89bb
#define NT_THREAD_SET_THREAD_TOKEN		0x00000080
dd89bb
#define NT_THREAD_IMPERSONATE			0x00000100
dd89bb
#define NT_THREAD_DIRECT_IMPERSONATION		0x00000200
dd89bb
#define NT_THREAD_SYNCHRONIZE			0x00100000
dd89bb
dd89bb
#define NT_THREAD_ALL_ACCESS			NT_THREAD_TERMINATE \
dd89bb
						| NT_THREAD_SUSPEND_RESUME \
dd89bb
						| NT_THREAD_ALERT \
dd89bb
						| NT_THREAD_GET_CONTEXT \
dd89bb
						| NT_THREAD_SET_CONTEXT \
dd89bb
						| NT_THREAD_SET_INFORMATION \
dd89bb
						| NT_THREAD_QUERY_INFORMATION \
dd89bb
						| NT_THREAD_SET_THREAD_TOKEN \
dd89bb
						| NT_THREAD_IMPERSONATE \
dd89bb
						| NT_THREAD_DIRECT_IMPERSONATION \
dd89bb
						| NT_THREAD_SYNCHRONIZE
dd89bb
dd89bb
/* library-specific thread creation flags */
dd89bb
#define NT_THREAD_RUN_IMMEDIATELY		0x00000000
dd89bb
#define NT_CREATE_SUSPENDED			0x00000004
dd89bb
#define NT_CREATE_FIRST_THREAD_OF_PROCESS	0x00008000
dd89bb
#define NT_CREATE_LOCAL_THREAD			0x00010000
dd89bb
#define NT_STACK_SIZE_PARAM_IS_A_RESERVATION	0x00800000
dd89bb
#define NT_CLOSE_THREAD_HANDLE			0x01000000
dd89bb
dd89bb
dd89bb
/* thread context */
604059
#define NT_CONTEXT_JUST_EVERYTHING		(uint32_t)-1
dd89bb
dd89bb
/* source mark: arch-specific code: begin */
5bfd34
#if (__SIZEOF_POINTER__ == 4)
5bfd34
typedef struct _nt_thread_context_i386  nt_thread_context;
5bfd34
#endif
5bfd34
5bfd34
#if (__SIZEOF_POINTER__ == 8)
5bfd34
typedef nt_mcontext_x86_64_t            nt_thread_context;
5bfd34
typedef nt_mcontext_x86_64_t            nt_mcontext_t;
dd89bb
#endif
dd89bb
/* source mark: arch-specific code: end */
dd89bb
dd89bb
dd89bb
typedef struct _nt_user_stack {
dd89bb
	void * fixed_stack_base;
dd89bb
	void * fixed_stack_limit;
dd89bb
	void * expandable_stack_base;
dd89bb
	void * expandable_stack_limit;
dd89bb
	void * expandable_stack_bottom;
dd89bb
} nt_user_stack;
dd89bb
dd89bb
dd89bb
typedef struct _nt_exception_registration_record {
dd89bb
	struct _nt_exception_registration_record *	next;
dd89bb
	nt_exception_disposition *			handler;
dd89bb
} nt_exception_registration_record;
dd89bb
dd89bb
dd89bb
typedef struct _nt_tib {
dd89bb
	nt_exception_registration_record * 	exception_list;
dd89bb
	void * 					stack_base;
dd89bb
	void * 					stack_limit;
dd89bb
	void * 					sub_system_tib;
dd89bb
dd89bb
	union {
dd89bb
		void * 		fiber_data;
dd89bb
		uint32_t 	version;
dd89bb
	};
dd89bb
dd89bb
	void * 					arbitrary_user_pointer;
dd89bb
	struct _nt_tib * 			self;
dd89bb
} nt_tib;
dd89bb
dd89bb
dd89bb
typedef struct _nt_thread_basic_information {
dd89bb
	int32_t		exit_status;
dd89bb
	nt_tib *	teb_base_address;
dd89bb
	nt_client_id	cid;
dd89bb
	intptr_t	affinity_mask;
dd89bb
	int32_t		priority;
dd89bb
	int32_t		base_priority;
dd89bb
} nt_thread_basic_information;
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall nt_thread_start_routine(void * context);
dd89bb
dd89bb
dd89bb
typedef struct _nt_thread_params {
dd89bb
	__in	void *				hprocess;
dd89bb
	__out	void *				hthread;
dd89bb
	__in	nt_thread_start_routine *	start;
dd89bb
	__in	void *				arg			__optional;
dd89bb
	__in	void *				ext_ctx			__optional;
dd89bb
	__in	size_t				ext_ctx_size;
dd89bb
	__in	nt_object_attributes *		obj_attr		__optional;
dd89bb
	__in	uint32_t			creation_flags;
dd89bb
	__in	uint32_t			stack_zero_bits;
dd89bb
	__in	size_t				stack_size_commit;
dd89bb
	__in	size_t				stack_size_reserve;
dd89bb
	__in	nt_user_stack *			stack_info		__optional;
dd89bb
	__in	nt_thread_context *		reg_context		__optional;
dd89bb
	__out	int32_t				csrss_status;
dd89bb
	__out	uint32_t			thread_id;
dd89bb
	__in	void *				reserved[2];
dd89bb
} nt_thread_params;
dd89bb
dd89bb
dd89bb
typedef void    __stdcall nt_knormal_routine(
dd89bb
	void *	apc_context,
dd89bb
	void *	arg_1st,
dd89bb
	void *	arg_2nd);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_create_thread(
dd89bb
	__out	void **			hthread,
dd89bb
	__in	uintptr_t		desired_access,
dd89bb
	__in	nt_object_attributes *	obj_attr,
dd89bb
	__in	void *			hprocess,
dd89bb
	__out	nt_client_id *		hclient_id,
dd89bb
	__in	nt_thread_context *	context,
dd89bb
	__in	nt_user_stack *		user_stack,
dd89bb
	__in	uintptr_t		suspended_flag);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_open_thread(
dd89bb
	__out	void **			hthread,
dd89bb
	__in	uint32_t		desired_access,
dd89bb
	__in	nt_object_attributes *	obj_attr,
dd89bb
	__in	nt_client_id *		hclient_id);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_terminate_thread(
dd89bb
	__in	void *	hthread,
dd89bb
	__in	int32_t	exit_status);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_query_information_thread(
dd89bb
	__in	void *			hthread,
dd89bb
	__in	nt_thread_info_class	thread_info_class,
dd89bb
	__out	void *			thread_info,
dd89bb
	__in	size_t			thread_info_length,
dd89bb
	__out	size_t *		returned_length		__optional);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_set_information_thread(
dd89bb
	__in	void *			hthread,
dd89bb
	__in	nt_thread_info_class	thread_info_class,
dd89bb
	__in	void *			thread_info,
dd89bb
	__in	size_t			thread_info_length);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_suspend_thread(
dd89bb
	__in	void *		hthread,
dd89bb
	__out	uint32_t *	prev_suspend_count __optional);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_resume_thread(
dd89bb
	__in	void *		hthread,
dd89bb
	__out	uint32_t *	prev_suspend_count __optional);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_get_context_thread(
dd89bb
	__in	void *	hthread,
dd89bb
	__out	void *	context);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_set_context_thread(
dd89bb
	__in	void *	hthread,
dd89bb
	__in	void *	context);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_queue_apc_thread(
dd89bb
	__in	void *			hthread,
dd89bb
	__in	nt_knormal_routine *	apc_routine,
dd89bb
	__in	void *			apc_context,
dd89bb
	__in	void *			arg_1st,
dd89bb
	__in	void *			arg_2nd);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_test_alert(void);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_alert_thread(
dd89bb
	__in	void *	hthread);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_alert_resume_thread(
dd89bb
	__in	void *		hthread,
dd89bb
	__out	uint32_t *	prev_suspend_count __optional);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_register_thread_terminate_port(
dd89bb
	__in	void *	port_handle);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_impersonate_thread(
dd89bb
	__in	void *					hthread,
dd89bb
	__in	void *					target_thread_handle,
dd89bb
	__in	nt_security_quality_of_service *	sec_qos);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_zw_impersonate_anonymous_token(
dd89bb
	__in	void *	hthread);
dd89bb
dd89bb
dd89bb
/* extension functions */
dd89bb
typedef int32_t __stdcall ntapi_tt_create_local_thread(
dd89bb
	__in_out	nt_thread_params *	params);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_tt_create_remote_thread(
dd89bb
	__in_out	nt_thread_params *	params);
dd89bb
dd89bb
dd89bb
typedef int32_t __stdcall ntapi_tt_create_thread(
dd89bb
	__in_out	nt_thread_params *	params);
dd89bb
dd89bb
#endif