summaryrefslogtreecommitdiffhomepage
path: root/src/ipc
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2017-08-14 22:19:28 +0000
committermidipix <writeonce@midipix.org>2017-08-18 03:04:29 -0400
commit842d0f7290d2ac08f9e3a149363477274b9b95cd (patch)
tree0083321c5c29e83734c54e0b7c006710c63a6076 /src/ipc
parent41ce6f4707be1a49abf52b38f96436a0c96ec873 (diff)
downloadntapi-842d0f7290d2ac08f9e3a149363477274b9b95cd.tar.bz2
ntapi-842d0f7290d2ac08f9e3a149363477274b9b95cd.tar.xz
__ntapi_ipc_create_pipe(): refine, change polling strategy.
The canonical way of polling an i/o handle by requesting a zero-byte read/write operation and then waiting on the event (or apc routine) that was specified for that i/o operation fails to work on the writing end of a byte-stream pipe. Specifically, the request completes immediately, therefore not allowing us to employ it for a controlled poll operation. Following this patch, the writing end of the pipe is opened with the NT_FILE_SYNCHRONOUS_IO_ALERT flag set. With this flag set, zero-byte writes block, which makes them perfectly suitable for a polling operation, but less so for non-blocking i/o. With some effort, however, the latter can be achieved and be both robust and reliable.
Diffstat (limited to 'src/ipc')
-rw-r--r--src/ipc/ntapi_tt_create_pipe_v1.c18
-rw-r--r--src/ipc/ntapi_tt_create_pipe_v2.c20
2 files changed, 18 insertions, 20 deletions
diff --git a/src/ipc/ntapi_tt_create_pipe_v1.c b/src/ipc/ntapi_tt_create_pipe_v1.c
index a1ef92c..53dbd7e 100644
--- a/src/ipc/ntapi_tt_create_pipe_v1.c
+++ b/src/ipc/ntapi_tt_create_pipe_v1.c
@@ -34,7 +34,7 @@ typedef struct __attr_ptr_size_aligned__ _nt_tty_pipe_name {
int32_t __stdcall __ntapi_ipc_create_pipe_v1(
__out void ** hpipe_read,
__out void ** hpipe_write,
- __in uint32_t advisory_buffer_size __optional)
+ __in uint32_t advisory_buffer_size)
{
int32_t status;
@@ -110,8 +110,8 @@ int32_t __stdcall __ntapi_ipc_create_pipe_v1(
/* init security structure */
sqos.length = sizeof(sqos);
- sqos.impersonation_level = NT_SECURITY_IMPERSONATION;
- sqos.context_tracking_mode = NT_SECURITY_TRACKING_DYNAMIC;
+ sqos.impersonation_level = NT_SECURITY_ANONYMOUS;
+ sqos.context_tracking_mode = NT_SECURITY_TRACKING_STATIC;
sqos.effective_only = 1;
/* oa */
@@ -134,12 +134,12 @@ int32_t __stdcall __ntapi_ipc_create_pipe_v1(
NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
NT_FILE_CREATE,
NT_FILE_ASYNCHRONOUS_IO,
- 0,
- 0,
- 0,
+ NT_FILE_PIPE_BYTE_STREAM_TYPE,
+ NT_FILE_PIPE_BYTE_STREAM_MODE,
+ NT_FILE_PIPE_QUEUE_OPERATION,
1,
- 0x2000,
- 0x2000,
+ advisory_buffer_size,
+ advisory_buffer_size,
&timeout);
if (status != NT_STATUS_SUCCESS) {
@@ -153,7 +153,7 @@ int32_t __stdcall __ntapi_ipc_create_pipe_v1(
&oa,
&iosb,
NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
- NT_FILE_WRITE_THROUGH | NT_FILE_ASYNCHRONOUS_IO | NT_FILE_NON_DIRECTORY_FILE);
+ NT_FILE_WRITE_THROUGH | NT_FILE_SYNCHRONOUS_IO_ALERT | NT_FILE_NON_DIRECTORY_FILE);
if (status != NT_STATUS_SUCCESS) {
__ntapi->zw_close(hread);
diff --git a/src/ipc/ntapi_tt_create_pipe_v2.c b/src/ipc/ntapi_tt_create_pipe_v2.c
index 61142f6..a61036b 100644
--- a/src/ipc/ntapi_tt_create_pipe_v2.c
+++ b/src/ipc/ntapi_tt_create_pipe_v2.c
@@ -14,7 +14,7 @@
int32_t __stdcall __ntapi_ipc_create_pipe_v2(
__out void ** hpipe_read,
__out void ** hpipe_write,
- __in uint32_t advisory_buffer_size __optional)
+ __in uint32_t advisory_buffer_size)
{
int32_t status;
@@ -33,8 +33,6 @@ int32_t __stdcall __ntapi_ipc_create_pipe_v2(
'\\','N','a','m','e','d','P','i','p','e','\\',0
};
- (void)advisory_buffer_size;
-
/* nt_name: pipe device directory */
nt_name.strlen = (uint16_t)(sizeof(pipe_dir) - sizeof(wchar16_t));
nt_name.maxlen = 0;
@@ -42,8 +40,8 @@ int32_t __stdcall __ntapi_ipc_create_pipe_v2(
/* init security structure */
sqos.length = sizeof(sqos);
- sqos.impersonation_level = NT_SECURITY_IMPERSONATION;
- sqos.context_tracking_mode = NT_SECURITY_TRACKING_DYNAMIC;
+ sqos.impersonation_level = NT_SECURITY_ANONYMOUS;
+ sqos.context_tracking_mode = NT_SECURITY_TRACKING_STATIC;
sqos.effective_only = 1;
/* oa */
@@ -79,12 +77,12 @@ int32_t __stdcall __ntapi_ipc_create_pipe_v2(
NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
NT_FILE_CREATE,
NT_FILE_ASYNCHRONOUS_IO,
- 0,
- 0,
- 0,
+ NT_FILE_PIPE_BYTE_STREAM_TYPE,
+ NT_FILE_PIPE_BYTE_STREAM_MODE,
+ NT_FILE_PIPE_QUEUE_OPERATION,
1,
- 0X2000,
- 0x2000,
+ advisory_buffer_size,
+ advisory_buffer_size,
&timeout);
__ntapi->zw_close(
@@ -102,7 +100,7 @@ int32_t __stdcall __ntapi_ipc_create_pipe_v2(
&oa,
&iosb,
NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
- NT_FILE_WRITE_THROUGH | NT_FILE_ASYNCHRONOUS_IO | NT_FILE_NON_DIRECTORY_FILE);
+ NT_FILE_WRITE_THROUGH | NT_FILE_SYNCHRONOUS_IO_ALERT | NT_FILE_NON_DIRECTORY_FILE);
if (status) {
__ntapi->zw_close(hread);