2 * Server-side pipe management
4 * Copyright (C) 1998 Alexandre Julliard
5 * Copyright (C) 2001 Mike McCormack
6 * Copyright 2016 Jacek Caban for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
33 #define WIN32_NO_STATUS
49 struct list entry
; /* entry in message queue */
50 data_size_t read_pos
; /* already read bytes */
51 struct iosb
*iosb
; /* message iosb */
52 struct async
*async
; /* async of pending write */
57 struct object obj
; /* object header */
58 struct fd
*fd
; /* pipe file descriptor */
59 unsigned int flags
; /* pipe flags */
60 unsigned int state
; /* pipe state */
61 struct named_pipe
*pipe
;
62 struct pipe_end
*connection
; /* the other end of the pipe */
63 process_id_t client_pid
; /* process that created the client */
64 process_id_t server_pid
; /* process that created the server */
65 data_size_t buffer_size
;/* size of buffered data that doesn't block caller */
66 struct list message_queue
;
67 struct async_queue read_q
; /* read queue */
68 struct async_queue write_q
; /* write queue */
73 struct pipe_end pipe_end
; /* common header for pipe_client and pipe_server */
74 struct list entry
; /* entry in named pipe servers list */
75 unsigned int options
; /* pipe options */
76 struct async_queue listen_q
; /* listen queue */
81 struct pipe_end pipe_end
; /* common header for pipe_client and pipe_server */
82 unsigned int flags
; /* file flags */
87 struct object obj
; /* object header */
90 unsigned int maxinstances
;
93 unsigned int instances
;
95 struct list servers
; /* list of servers using this pipe */
96 struct async_queue waiters
; /* list of clients waiting to connect */
99 struct named_pipe_device
101 struct object obj
; /* object header */
102 struct fd
*fd
; /* pseudo-fd for ioctls */
103 struct namespace *pipes
; /* named pipe namespace */
106 static void named_pipe_dump( struct object
*obj
, int verbose
);
107 static unsigned int named_pipe_map_access( struct object
*obj
, unsigned int access
);
108 static int named_pipe_link_name( struct object
*obj
, struct object_name
*name
, struct object
*parent
);
109 static struct object
*named_pipe_open_file( struct object
*obj
, unsigned int access
,
110 unsigned int sharing
, unsigned int options
);
111 static void named_pipe_destroy( struct object
*obj
);
113 static const struct object_ops named_pipe_ops
=
115 sizeof(struct named_pipe
), /* size */
116 named_pipe_dump
, /* dump */
117 no_get_type
, /* get_type */
118 no_add_queue
, /* add_queue */
119 NULL
, /* remove_queue */
121 NULL
, /* satisfied */
122 no_signal
, /* signal */
123 no_get_fd
, /* get_fd */
124 named_pipe_map_access
, /* map_access */
125 default_get_sd
, /* get_sd */
126 default_set_sd
, /* set_sd */
127 no_lookup_name
, /* lookup_name */
128 named_pipe_link_name
, /* link_name */
129 default_unlink_name
, /* unlink_name */
130 named_pipe_open_file
, /* open_file */
131 no_close_handle
, /* close_handle */
132 named_pipe_destroy
/* destroy */
135 /* common server and client pipe end functions */
136 static void pipe_end_destroy( struct object
*obj
);
137 static struct object_type
*pipe_end_get_type( struct object
*obj
);
138 static enum server_fd_type
pipe_end_get_fd_type( struct fd
*fd
);
139 static struct fd
*pipe_end_get_fd( struct object
*obj
);
140 static struct security_descriptor
*pipe_end_get_sd( struct object
*obj
);
141 static int pipe_end_set_sd( struct object
*obj
, const struct security_descriptor
*sd
,
142 unsigned int set_info
);
143 static int pipe_end_read( struct fd
*fd
, struct async
*async
, file_pos_t pos
);
144 static int pipe_end_write( struct fd
*fd
, struct async
*async_data
, file_pos_t pos
);
145 static int pipe_end_flush( struct fd
*fd
, struct async
*async
);
146 static void pipe_end_get_volume_info( struct fd
*fd
, unsigned int info_class
);
147 static void pipe_end_reselect_async( struct fd
*fd
, struct async_queue
*queue
);
148 static void pipe_end_get_file_info( struct fd
*fd
, obj_handle_t handle
, unsigned int info_class
);
150 /* server end functions */
151 static void pipe_server_dump( struct object
*obj
, int verbose
);
152 static void pipe_server_destroy( struct object
*obj
);
153 static int pipe_server_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
);
155 static const struct object_ops pipe_server_ops
=
157 sizeof(struct pipe_server
), /* size */
158 pipe_server_dump
, /* dump */
159 pipe_end_get_type
, /* get_type */
160 add_queue
, /* add_queue */
161 remove_queue
, /* remove_queue */
162 default_fd_signaled
, /* signaled */
163 no_satisfied
, /* satisfied */
164 no_signal
, /* signal */
165 pipe_end_get_fd
, /* get_fd */
166 default_fd_map_access
, /* map_access */
167 pipe_end_get_sd
, /* get_sd */
168 pipe_end_set_sd
, /* set_sd */
169 no_lookup_name
, /* lookup_name */
170 no_link_name
, /* link_name */
171 NULL
, /* unlink_name */
172 no_open_file
, /* open_file */
173 fd_close_handle
, /* close_handle */
174 pipe_server_destroy
/* destroy */
177 static const struct fd_ops pipe_server_fd_ops
=
179 default_fd_get_poll_events
, /* get_poll_events */
180 default_poll_event
, /* poll_event */
181 pipe_end_get_fd_type
, /* get_fd_type */
182 pipe_end_read
, /* read */
183 pipe_end_write
, /* write */
184 pipe_end_flush
, /* flush */
185 pipe_end_get_file_info
, /* get_file_info */
186 pipe_end_get_volume_info
, /* get_volume_info */
187 pipe_server_ioctl
, /* ioctl */
188 no_fd_queue_async
, /* queue_async */
189 pipe_end_reselect_async
/* reselect_async */
192 /* client end functions */
193 static void pipe_client_dump( struct object
*obj
, int verbose
);
194 static int pipe_client_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
);
196 static const struct object_ops pipe_client_ops
=
198 sizeof(struct pipe_client
), /* size */
199 pipe_client_dump
, /* dump */
200 pipe_end_get_type
, /* get_type */
201 add_queue
, /* add_queue */
202 remove_queue
, /* remove_queue */
203 default_fd_signaled
, /* signaled */
204 no_satisfied
, /* satisfied */
205 no_signal
, /* signal */
206 pipe_end_get_fd
, /* get_fd */
207 default_fd_map_access
, /* map_access */
208 pipe_end_get_sd
, /* get_sd */
209 pipe_end_set_sd
, /* set_sd */
210 no_lookup_name
, /* lookup_name */
211 no_link_name
, /* link_name */
212 NULL
, /* unlink_name */
213 no_open_file
, /* open_file */
214 fd_close_handle
, /* close_handle */
215 pipe_end_destroy
/* destroy */
218 static const struct fd_ops pipe_client_fd_ops
=
220 default_fd_get_poll_events
, /* get_poll_events */
221 default_poll_event
, /* poll_event */
222 pipe_end_get_fd_type
, /* get_fd_type */
223 pipe_end_read
, /* read */
224 pipe_end_write
, /* write */
225 pipe_end_flush
, /* flush */
226 pipe_end_get_file_info
, /* get_file_info */
227 pipe_end_get_volume_info
, /* get_volume_info */
228 pipe_client_ioctl
, /* ioctl */
229 no_fd_queue_async
, /* queue_async */
230 pipe_end_reselect_async
/* reselect_async */
233 static void named_pipe_device_dump( struct object
*obj
, int verbose
);
234 static struct object_type
*named_pipe_device_get_type( struct object
*obj
);
235 static struct fd
*named_pipe_device_get_fd( struct object
*obj
);
236 static struct object
*named_pipe_device_lookup_name( struct object
*obj
,
237 struct unicode_str
*name
, unsigned int attr
);
238 static struct object
*named_pipe_device_open_file( struct object
*obj
, unsigned int access
,
239 unsigned int sharing
, unsigned int options
);
240 static void named_pipe_device_destroy( struct object
*obj
);
241 static enum server_fd_type
named_pipe_device_get_fd_type( struct fd
*fd
);
242 static int named_pipe_device_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
);
244 static const struct object_ops named_pipe_device_ops
=
246 sizeof(struct named_pipe_device
), /* size */
247 named_pipe_device_dump
, /* dump */
248 named_pipe_device_get_type
, /* get_type */
249 no_add_queue
, /* add_queue */
250 NULL
, /* remove_queue */
252 no_satisfied
, /* satisfied */
253 no_signal
, /* signal */
254 named_pipe_device_get_fd
, /* get_fd */
255 no_map_access
, /* map_access */
256 default_get_sd
, /* get_sd */
257 default_set_sd
, /* set_sd */
258 named_pipe_device_lookup_name
, /* lookup_name */
259 directory_link_name
, /* link_name */
260 default_unlink_name
, /* unlink_name */
261 named_pipe_device_open_file
, /* open_file */
262 fd_close_handle
, /* close_handle */
263 named_pipe_device_destroy
/* destroy */
266 static const struct fd_ops named_pipe_device_fd_ops
=
268 default_fd_get_poll_events
, /* get_poll_events */
269 default_poll_event
, /* poll_event */
270 named_pipe_device_get_fd_type
, /* get_fd_type */
271 no_fd_read
, /* read */
272 no_fd_write
, /* write */
273 no_fd_flush
, /* flush */
274 default_fd_get_file_info
, /* get_file_info */
275 no_fd_get_volume_info
, /* get_volume_info */
276 named_pipe_device_ioctl
, /* ioctl */
277 default_fd_queue_async
, /* queue_async */
278 default_fd_reselect_async
/* reselect_async */
281 static void named_pipe_dump( struct object
*obj
, int verbose
)
283 fputs( "Named pipe\n", stderr
);
286 static unsigned int named_pipe_map_access( struct object
*obj
, unsigned int access
)
288 if (access
& GENERIC_READ
) access
|= STANDARD_RIGHTS_READ
;
289 if (access
& GENERIC_WRITE
) access
|= STANDARD_RIGHTS_WRITE
| FILE_CREATE_PIPE_INSTANCE
;
290 if (access
& GENERIC_EXECUTE
) access
|= STANDARD_RIGHTS_EXECUTE
;
291 if (access
& GENERIC_ALL
) access
|= STANDARD_RIGHTS_ALL
;
292 return access
& ~(GENERIC_READ
| GENERIC_WRITE
| GENERIC_EXECUTE
| GENERIC_ALL
);
295 static void pipe_server_dump( struct object
*obj
, int verbose
)
297 struct pipe_server
*server
= (struct pipe_server
*) obj
;
298 assert( obj
->ops
== &pipe_server_ops
);
299 fprintf( stderr
, "Named pipe server pipe=%p state=%d\n", server
->pipe_end
.pipe
,
300 server
->pipe_end
.state
);
303 static void pipe_client_dump( struct object
*obj
, int verbose
)
305 struct pipe_client
*client
= (struct pipe_client
*) obj
;
306 assert( obj
->ops
== &pipe_client_ops
);
307 fprintf( stderr
, "Named pipe client server=%p\n", client
->pipe_end
.connection
);
310 static void named_pipe_destroy( struct object
*obj
)
312 struct named_pipe
*pipe
= (struct named_pipe
*) obj
;
314 assert( list_empty( &pipe
->servers
) );
315 assert( !pipe
->instances
);
316 free_async_queue( &pipe
->waiters
);
319 static struct object_type
*pipe_end_get_type( struct object
*obj
)
321 static const WCHAR name
[] = {'F','i','l','e'};
322 static const struct unicode_str str
= { name
, sizeof(name
) };
323 return get_object_type( &str
);
326 static struct fd
*pipe_end_get_fd( struct object
*obj
)
328 struct pipe_end
*pipe_end
= (struct pipe_end
*) obj
;
329 return (struct fd
*) grab_object( pipe_end
->fd
);
332 static struct pipe_message
*queue_message( struct pipe_end
*pipe_end
, struct iosb
*iosb
)
334 struct pipe_message
*message
;
336 if (!(message
= mem_alloc( sizeof(*message
) ))) return NULL
;
337 message
->iosb
= (struct iosb
*)grab_object( iosb
);
338 message
->async
= NULL
;
339 message
->read_pos
= 0;
340 list_add_tail( &pipe_end
->message_queue
, &message
->entry
);
344 static void wake_message( struct pipe_message
*message
)
346 struct async
*async
= message
->async
;
348 message
->async
= NULL
;
351 message
->iosb
->status
= STATUS_SUCCESS
;
352 message
->iosb
->result
= message
->iosb
->in_size
;
353 async_terminate( async
, message
->iosb
->result
? STATUS_ALERTED
: STATUS_SUCCESS
);
354 release_object( async
);
357 static void free_message( struct pipe_message
*message
)
359 list_remove( &message
->entry
);
360 if (message
->iosb
) release_object( message
->iosb
);
364 static void pipe_end_disconnect( struct pipe_end
*pipe_end
, unsigned int status
)
366 struct pipe_end
*connection
= pipe_end
->connection
;
367 struct pipe_message
*message
, *next
;
370 pipe_end
->connection
= NULL
;
372 pipe_end
->state
= status
== STATUS_PIPE_DISCONNECTED
373 ? FILE_PIPE_DISCONNECTED_STATE
: FILE_PIPE_CLOSING_STATE
;
374 fd_async_wake_up( pipe_end
->fd
, ASYNC_TYPE_WAIT
, status
);
375 async_wake_up( &pipe_end
->read_q
, status
);
376 LIST_FOR_EACH_ENTRY_SAFE( message
, next
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
378 async
= message
->async
;
379 if (async
|| status
== STATUS_PIPE_DISCONNECTED
) free_message( message
);
380 if (!async
) continue;
381 async_terminate( async
, status
);
382 release_object( async
);
384 if (status
== STATUS_PIPE_DISCONNECTED
) set_fd_signaled( pipe_end
->fd
, 0 );
388 connection
->connection
= NULL
;
389 pipe_end_disconnect( connection
, status
);
393 static void pipe_end_destroy( struct object
*obj
)
395 struct pipe_end
*pipe_end
= (struct pipe_end
*)obj
;
396 struct pipe_message
*message
;
398 pipe_end_disconnect( pipe_end
, STATUS_PIPE_BROKEN
);
400 while (!list_empty( &pipe_end
->message_queue
))
402 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
403 assert( !message
->async
);
404 free_message( message
);
407 free_async_queue( &pipe_end
->read_q
);
408 free_async_queue( &pipe_end
->write_q
);
409 if (pipe_end
->fd
) release_object( pipe_end
->fd
);
410 if (pipe_end
->pipe
) release_object( pipe_end
->pipe
);
413 static void pipe_server_destroy( struct object
*obj
)
415 struct pipe_server
*server
= (struct pipe_server
*)obj
;
416 struct named_pipe
*pipe
= server
->pipe_end
.pipe
;
418 assert( obj
->ops
== &pipe_server_ops
);
420 assert( pipe
->instances
);
421 if (!--pipe
->instances
) unlink_named_object( &pipe
->obj
);
422 list_remove( &server
->entry
);
424 free_async_queue( &server
->listen_q
);
425 pipe_end_destroy( obj
);
428 static void named_pipe_device_dump( struct object
*obj
, int verbose
)
430 fputs( "Named pipe device\n", stderr
);
433 static struct object_type
*named_pipe_device_get_type( struct object
*obj
)
435 static const WCHAR name
[] = {'D','e','v','i','c','e'};
436 static const struct unicode_str str
= { name
, sizeof(name
) };
437 return get_object_type( &str
);
440 static struct fd
*named_pipe_device_get_fd( struct object
*obj
)
442 struct named_pipe_device
*device
= (struct named_pipe_device
*)obj
;
443 return (struct fd
*)grab_object( device
->fd
);
446 static struct object
*named_pipe_device_lookup_name( struct object
*obj
, struct unicode_str
*name
,
449 struct named_pipe_device
*device
= (struct named_pipe_device
*)obj
;
450 struct object
*found
;
452 assert( obj
->ops
== &named_pipe_device_ops
);
453 assert( device
->pipes
);
455 if (!name
) return NULL
; /* open the device itself */
457 if ((found
= find_object( device
->pipes
, name
, attr
| OBJ_CASE_INSENSITIVE
)))
463 static struct object
*named_pipe_device_open_file( struct object
*obj
, unsigned int access
,
464 unsigned int sharing
, unsigned int options
)
466 return grab_object( obj
);
469 static void named_pipe_device_destroy( struct object
*obj
)
471 struct named_pipe_device
*device
= (struct named_pipe_device
*)obj
;
472 assert( obj
->ops
== &named_pipe_device_ops
);
473 if (device
->fd
) release_object( device
->fd
);
474 free( device
->pipes
);
477 static enum server_fd_type
named_pipe_device_get_fd_type( struct fd
*fd
)
479 return FD_TYPE_DEVICE
;
482 struct object
*create_named_pipe_device( struct object
*root
, const struct unicode_str
*name
)
484 struct named_pipe_device
*dev
;
486 if ((dev
= create_named_object( root
, &named_pipe_device_ops
, name
, 0, NULL
)) &&
487 get_error() != STATUS_OBJECT_NAME_EXISTS
)
490 if (!(dev
->fd
= alloc_pseudo_fd( &named_pipe_device_fd_ops
, &dev
->obj
, 0 )) ||
491 !(dev
->pipes
= create_namespace( 7 )))
493 release_object( dev
);
500 static int pipe_end_flush( struct fd
*fd
, struct async
*async
)
502 struct pipe_end
*pipe_end
= get_fd_user( fd
);
506 set_error( STATUS_PIPE_DISCONNECTED
);
510 if (pipe_end
->connection
&& !list_empty( &pipe_end
->connection
->message_queue
))
512 fd_queue_async( pipe_end
->fd
, async
, ASYNC_TYPE_WAIT
);
513 set_error( STATUS_PENDING
);
518 static void pipe_end_get_file_info( struct fd
*fd
, obj_handle_t handle
, unsigned int info_class
)
520 struct pipe_end
*pipe_end
= get_fd_user( fd
);
521 struct named_pipe
*pipe
= pipe_end
->pipe
;
525 case FileNameInformation
:
527 FILE_NAME_INFORMATION
*name_info
;
528 data_size_t name_len
, reply_size
;
531 if (get_reply_max_size() < sizeof(*name_info
))
533 set_error( STATUS_INFO_LENGTH_MISMATCH
);
537 /* FIXME: We should be able to return on unlinked pipe */
538 if (!pipe
|| !(name
= get_object_name( &pipe
->obj
, &name_len
)))
540 set_error( STATUS_PIPE_DISCONNECTED
);
544 reply_size
= offsetof( FILE_NAME_INFORMATION
, FileName
[name_len
/sizeof(WCHAR
) + 1] );
545 if (reply_size
> get_reply_max_size())
547 reply_size
= get_reply_max_size();
548 set_error( STATUS_BUFFER_OVERFLOW
);
551 if (!(name_info
= set_reply_data_size( reply_size
))) return;
552 name_info
->FileNameLength
= name_len
+ sizeof(WCHAR
);
553 name_info
->FileName
[0] = '\\';
554 reply_size
-= offsetof( FILE_NAME_INFORMATION
, FileName
[1] );
555 if (reply_size
) memcpy( &name_info
->FileName
[1], name
, reply_size
);
558 case FilePipeInformation
:
560 FILE_PIPE_INFORMATION
*pipe_info
;
562 if (!(get_handle_access( current
->process
, handle
) & FILE_READ_ATTRIBUTES
))
564 set_error( STATUS_ACCESS_DENIED
);
568 if (get_reply_max_size() < sizeof(*pipe_info
))
570 set_error( STATUS_INFO_LENGTH_MISMATCH
);
576 set_error( STATUS_PIPE_DISCONNECTED
);
580 if (!(pipe_info
= set_reply_data_size( sizeof(*pipe_info
) ))) return;
581 pipe_info
->ReadMode
= (pipe_end
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
)
582 ? FILE_PIPE_MESSAGE_MODE
: FILE_PIPE_BYTE_STREAM_MODE
;
583 pipe_info
->CompletionMode
= (pipe_end
->flags
& NAMED_PIPE_NONBLOCKING_MODE
)
584 ? FILE_PIPE_COMPLETE_OPERATION
: FILE_PIPE_QUEUE_OPERATION
;
587 case FilePipeLocalInformation
:
589 FILE_PIPE_LOCAL_INFORMATION
*pipe_info
;
591 if (!(get_handle_access( current
->process
, handle
) & FILE_READ_ATTRIBUTES
))
593 set_error( STATUS_ACCESS_DENIED
);
597 if (get_reply_max_size() < sizeof(*pipe_info
))
599 set_error( STATUS_INFO_LENGTH_MISMATCH
);
605 set_error( STATUS_PIPE_DISCONNECTED
);
609 if (!(pipe_info
= set_reply_data_size( sizeof(*pipe_info
) ))) return;
610 pipe_info
->NamedPipeType
= (pipe_end
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
) != 0;
611 switch (pipe
->sharing
)
613 case FILE_SHARE_READ
:
614 pipe_info
->NamedPipeConfiguration
= FILE_PIPE_OUTBOUND
;
616 case FILE_SHARE_WRITE
:
617 pipe_info
->NamedPipeConfiguration
= FILE_PIPE_INBOUND
;
619 case FILE_SHARE_READ
| FILE_SHARE_WRITE
:
620 pipe_info
->NamedPipeConfiguration
= FILE_PIPE_FULL_DUPLEX
;
623 pipe_info
->MaximumInstances
= pipe
->maxinstances
;
624 pipe_info
->CurrentInstances
= pipe
->instances
;
625 pipe_info
->InboundQuota
= pipe
->insize
;
626 pipe_info
->ReadDataAvailable
= 0; /* FIXME */
627 pipe_info
->OutboundQuota
= pipe
->outsize
;
628 pipe_info
->WriteQuotaAvailable
= 0; /* FIXME */
629 pipe_info
->NamedPipeState
= pipe_end
->state
;
630 pipe_info
->NamedPipeEnd
= pipe_end
->obj
.ops
== &pipe_server_ops
631 ? FILE_PIPE_SERVER_END
: FILE_PIPE_CLIENT_END
;
635 default_fd_get_file_info( fd
, handle
, info_class
);
639 static struct security_descriptor
*pipe_end_get_sd( struct object
*obj
)
641 struct pipe_end
*pipe_end
= (struct pipe_end
*) obj
;
642 if (pipe_end
->pipe
) return default_get_sd( &pipe_end
->pipe
->obj
);
643 set_error( STATUS_PIPE_DISCONNECTED
);
647 static int pipe_end_set_sd( struct object
*obj
, const struct security_descriptor
*sd
,
648 unsigned int set_info
)
650 struct pipe_end
*pipe_end
= (struct pipe_end
*) obj
;
651 if (pipe_end
->pipe
) return default_set_sd( &pipe_end
->pipe
->obj
, sd
, set_info
);
652 set_error( STATUS_PIPE_DISCONNECTED
);
656 static void pipe_end_get_volume_info( struct fd
*fd
, unsigned int info_class
)
660 case FileFsDeviceInformation
:
662 static const FILE_FS_DEVICE_INFORMATION device_info
=
664 FILE_DEVICE_NAMED_PIPE
,
665 FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
667 if (get_reply_max_size() >= sizeof(device_info
))
668 set_reply_data( &device_info
, sizeof(device_info
) );
670 set_error( STATUS_BUFFER_TOO_SMALL
);
674 set_error( STATUS_NOT_IMPLEMENTED
);
678 static void message_queue_read( struct pipe_end
*pipe_end
, struct iosb
*iosb
)
680 struct pipe_message
*message
;
682 if (pipe_end
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
)
684 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
685 iosb
->out_size
= min( iosb
->out_size
, message
->iosb
->in_size
- message
->read_pos
);
686 iosb
->status
= message
->read_pos
+ iosb
->out_size
< message
->iosb
->in_size
687 ? STATUS_BUFFER_OVERFLOW
: STATUS_SUCCESS
;
691 data_size_t avail
= 0;
692 LIST_FOR_EACH_ENTRY( message
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
694 avail
+= message
->iosb
->in_size
- message
->read_pos
;
695 if (avail
>= iosb
->out_size
) break;
697 iosb
->out_size
= min( iosb
->out_size
, avail
);
698 iosb
->status
= STATUS_SUCCESS
;
701 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
702 if (!message
->read_pos
&& message
->iosb
->in_size
== iosb
->out_size
) /* fast path */
704 iosb
->out_data
= message
->iosb
->in_data
;
705 message
->iosb
->in_data
= NULL
;
706 wake_message( message
);
707 free_message( message
);
711 data_size_t write_pos
= 0, writing
;
714 if (iosb
->out_size
&& !(buf
= iosb
->out_data
= malloc( iosb
->out_size
)))
717 iosb
->status
= STATUS_NO_MEMORY
;
723 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
724 writing
= min( iosb
->out_size
- write_pos
, message
->iosb
->in_size
- message
->read_pos
);
725 if (writing
) memcpy( buf
+ write_pos
, (const char *)message
->iosb
->in_data
+ message
->read_pos
, writing
);
726 write_pos
+= writing
;
727 message
->read_pos
+= writing
;
728 if (message
->read_pos
== message
->iosb
->in_size
)
730 wake_message(message
);
731 free_message(message
);
733 } while (write_pos
< iosb
->out_size
);
735 iosb
->result
= iosb
->out_size
;
738 /* We call async_terminate in our reselect implementation, which causes recursive reselect.
739 * We're not interested in such reselect calls, so we ignore them. */
740 static int ignore_reselect
;
742 static void reselect_write_queue( struct pipe_end
*pipe_end
);
744 static void reselect_read_queue( struct pipe_end
*pipe_end
)
751 while (!list_empty( &pipe_end
->message_queue
) && (async
= find_pending_async( &pipe_end
->read_q
)))
753 iosb
= async_get_iosb( async
);
754 message_queue_read( pipe_end
, iosb
);
755 async_terminate( async
, iosb
->result
? STATUS_ALERTED
: iosb
->status
);
756 release_object( async
);
757 release_object( iosb
);
762 if (pipe_end
->connection
)
764 if (list_empty( &pipe_end
->message_queue
))
765 fd_async_wake_up( pipe_end
->connection
->fd
, ASYNC_TYPE_WAIT
, STATUS_SUCCESS
);
767 reselect_write_queue( pipe_end
->connection
);
771 static void reselect_write_queue( struct pipe_end
*pipe_end
)
773 struct pipe_message
*message
, *next
;
774 struct pipe_end
*reader
= pipe_end
->connection
;
775 data_size_t avail
= 0;
781 LIST_FOR_EACH_ENTRY_SAFE( message
, next
, &reader
->message_queue
, struct pipe_message
, entry
)
783 if (message
->async
&& message
->iosb
->status
!= STATUS_PENDING
)
785 release_object( message
->async
);
786 message
->async
= NULL
;
787 free_message( message
);
791 avail
+= message
->iosb
->in_size
- message
->read_pos
;
792 if (message
->async
&& (avail
<= reader
->buffer_size
|| !message
->iosb
->in_size
))
793 wake_message( message
);
798 reselect_read_queue( reader
);
801 static int pipe_end_read( struct fd
*fd
, struct async
*async
, file_pos_t pos
)
803 struct pipe_end
*pipe_end
= get_fd_user( fd
);
805 switch (pipe_end
->state
)
807 case FILE_PIPE_CONNECTED_STATE
:
809 case FILE_PIPE_DISCONNECTED_STATE
:
810 set_error( STATUS_PIPE_DISCONNECTED
);
812 case FILE_PIPE_LISTENING_STATE
:
813 set_error( STATUS_PIPE_LISTENING
);
815 case FILE_PIPE_CLOSING_STATE
:
816 if (!list_empty( &pipe_end
->message_queue
)) break;
817 set_error( STATUS_PIPE_BROKEN
);
821 queue_async( &pipe_end
->read_q
, async
);
822 reselect_read_queue( pipe_end
);
823 set_error( STATUS_PENDING
);
827 static int pipe_end_write( struct fd
*fd
, struct async
*async
, file_pos_t pos
)
829 struct pipe_end
*pipe_end
= get_fd_user( fd
);
830 struct pipe_message
*message
;
833 switch (pipe_end
->state
)
835 case FILE_PIPE_CONNECTED_STATE
:
837 case FILE_PIPE_DISCONNECTED_STATE
:
838 set_error( STATUS_PIPE_DISCONNECTED
);
840 case FILE_PIPE_LISTENING_STATE
:
841 set_error( STATUS_PIPE_LISTENING
);
843 case FILE_PIPE_CLOSING_STATE
:
844 set_error( STATUS_PIPE_CLOSING
);
848 if (!(pipe_end
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
) && !get_req_data_size()) return 1;
850 iosb
= async_get_iosb( async
);
851 message
= queue_message( pipe_end
->connection
, iosb
);
852 release_object( iosb
);
853 if (!message
) return 0;
855 message
->async
= (struct async
*)grab_object( async
);
856 queue_async( &pipe_end
->write_q
, async
);
857 reselect_write_queue( pipe_end
);
858 set_error( STATUS_PENDING
);
862 static void pipe_end_reselect_async( struct fd
*fd
, struct async_queue
*queue
)
864 struct pipe_end
*pipe_end
= get_fd_user( fd
);
866 if (ignore_reselect
) return;
868 if (&pipe_end
->write_q
== queue
)
869 reselect_write_queue( pipe_end
);
870 else if (&pipe_end
->read_q
== queue
)
871 reselect_read_queue( pipe_end
);
874 static enum server_fd_type
pipe_end_get_fd_type( struct fd
*fd
)
879 static int pipe_end_peek( struct pipe_end
*pipe_end
)
881 unsigned reply_size
= get_reply_max_size();
882 FILE_PIPE_PEEK_BUFFER
*buffer
;
883 struct pipe_message
*message
;
884 data_size_t avail
= 0;
885 data_size_t message_length
= 0;
887 if (reply_size
< offsetof( FILE_PIPE_PEEK_BUFFER
, Data
))
889 set_error( STATUS_INFO_LENGTH_MISMATCH
);
892 reply_size
-= offsetof( FILE_PIPE_PEEK_BUFFER
, Data
);
894 switch (pipe_end
->state
)
896 case FILE_PIPE_CONNECTED_STATE
:
898 case FILE_PIPE_CLOSING_STATE
:
899 if (!list_empty( &pipe_end
->message_queue
)) break;
900 set_error( STATUS_PIPE_BROKEN
);
903 set_error( pipe_end
->pipe
? STATUS_INVALID_PIPE_STATE
: STATUS_PIPE_DISCONNECTED
);
907 LIST_FOR_EACH_ENTRY( message
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
908 avail
+= message
->iosb
->in_size
- message
->read_pos
;
909 reply_size
= min( reply_size
, avail
);
911 if (avail
&& (pipe_end
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
))
913 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
914 message_length
= message
->iosb
->in_size
- message
->read_pos
;
915 reply_size
= min( reply_size
, message_length
);
918 if (!(buffer
= set_reply_data_size( offsetof( FILE_PIPE_PEEK_BUFFER
, Data
[reply_size
] )))) return 0;
919 buffer
->NamedPipeState
= pipe_end
->state
;
920 buffer
->ReadDataAvailable
= avail
;
921 buffer
->NumberOfMessages
= 0; /* FIXME */
922 buffer
->MessageLength
= message_length
;
926 data_size_t write_pos
= 0, writing
;
927 LIST_FOR_EACH_ENTRY( message
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
929 writing
= min( reply_size
- write_pos
, message
->iosb
->in_size
- message
->read_pos
);
930 memcpy( buffer
->Data
+ write_pos
, (const char *)message
->iosb
->in_data
+ message
->read_pos
,
932 write_pos
+= writing
;
933 if (write_pos
== reply_size
) break;
936 if (message_length
> reply_size
) set_error( STATUS_BUFFER_OVERFLOW
);
940 static int pipe_end_transceive( struct pipe_end
*pipe_end
, struct async
*async
)
942 struct pipe_message
*message
;
945 if (!pipe_end
->connection
)
947 set_error( pipe_end
->pipe
? STATUS_INVALID_PIPE_STATE
: STATUS_PIPE_DISCONNECTED
);
951 if ((pipe_end
->flags
& (NAMED_PIPE_MESSAGE_STREAM_WRITE
| NAMED_PIPE_MESSAGE_STREAM_READ
))
952 != (NAMED_PIPE_MESSAGE_STREAM_WRITE
| NAMED_PIPE_MESSAGE_STREAM_READ
))
954 set_error( STATUS_INVALID_READ_MODE
);
958 /* not allowed if we already have read data buffered */
959 if (!list_empty( &pipe_end
->message_queue
))
961 set_error( STATUS_PIPE_BUSY
);
965 iosb
= async_get_iosb( async
);
966 /* ignore output buffer copy transferred because of METHOD_NEITHER */
967 iosb
->in_size
-= iosb
->out_size
;
968 /* transaction never blocks on write, so just queue a message without async */
969 message
= queue_message( pipe_end
->connection
, iosb
);
970 release_object( iosb
);
971 if (!message
) return 0;
972 reselect_read_queue( pipe_end
->connection
);
974 queue_async( &pipe_end
->read_q
, async
);
975 reselect_read_queue( pipe_end
);
976 set_error( STATUS_PENDING
);
980 static int pipe_end_get_connection_attribute( struct pipe_end
*pipe_end
)
982 const char *attr
= get_req_data();
983 data_size_t value_size
, attr_size
= get_req_data_size();
986 if (attr_size
== sizeof("ClientProcessId") && !memcmp( attr
, "ClientProcessId", attr_size
))
988 value
= &pipe_end
->client_pid
;
989 value_size
= sizeof(pipe_end
->client_pid
);
991 else if (attr_size
== sizeof("ServerProcessId") && !memcmp( attr
, "ServerProcessId", attr_size
))
993 value
= &pipe_end
->server_pid
;
994 value_size
= sizeof(pipe_end
->server_pid
);
998 set_error( STATUS_ILLEGAL_FUNCTION
);
1002 if (get_reply_max_size() < value_size
)
1004 set_error( STATUS_INFO_LENGTH_MISMATCH
);
1008 set_reply_data( value
, value_size
);
1012 static int pipe_end_ioctl( struct pipe_end
*pipe_end
, ioctl_code_t code
, struct async
*async
)
1016 case FSCTL_PIPE_GET_CONNECTION_ATTRIBUTE
:
1017 return pipe_end_get_connection_attribute( pipe_end
);
1019 case FSCTL_PIPE_PEEK
:
1020 return pipe_end_peek( pipe_end
);
1022 case FSCTL_PIPE_TRANSCEIVE
:
1023 return pipe_end_transceive( pipe_end
, async
);
1026 return default_fd_ioctl( pipe_end
->fd
, code
, async
);
1030 static int pipe_server_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
)
1032 struct pipe_server
*server
= get_fd_user( fd
);
1036 case FSCTL_PIPE_LISTEN
:
1037 switch(server
->pipe_end
.state
)
1039 case FILE_PIPE_LISTENING_STATE
:
1040 case FILE_PIPE_DISCONNECTED_STATE
:
1042 case FILE_PIPE_CONNECTED_STATE
:
1043 set_error( STATUS_PIPE_CONNECTED
);
1045 case FILE_PIPE_CLOSING_STATE
:
1046 set_error( STATUS_PIPE_CLOSING
);
1050 server
->pipe_end
.state
= FILE_PIPE_LISTENING_STATE
;
1051 queue_async( &server
->listen_q
, async
);
1052 async_wake_up( &server
->pipe_end
.pipe
->waiters
, STATUS_SUCCESS
);
1053 set_error( STATUS_PENDING
);
1056 case FSCTL_PIPE_DISCONNECT
:
1057 switch(server
->pipe_end
.state
)
1059 case FILE_PIPE_CONNECTED_STATE
:
1060 /* dump the client connection - all data is lost */
1061 assert( server
->pipe_end
.connection
);
1062 release_object( server
->pipe_end
.connection
->pipe
);
1063 server
->pipe_end
.connection
->pipe
= NULL
;
1065 case FILE_PIPE_CLOSING_STATE
:
1067 case FILE_PIPE_LISTENING_STATE
:
1068 set_error( STATUS_PIPE_LISTENING
);
1070 case FILE_PIPE_DISCONNECTED_STATE
:
1071 set_error( STATUS_PIPE_DISCONNECTED
);
1075 pipe_end_disconnect( &server
->pipe_end
, STATUS_PIPE_DISCONNECTED
);
1079 return pipe_end_ioctl( &server
->pipe_end
, code
, async
);
1083 static int pipe_client_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
)
1085 struct pipe_client
*client
= get_fd_user( fd
);
1089 case FSCTL_PIPE_LISTEN
:
1090 set_error( STATUS_ILLEGAL_FUNCTION
);
1094 return pipe_end_ioctl( &client
->pipe_end
, code
, async
);
1098 static void init_pipe_end( struct pipe_end
*pipe_end
, struct named_pipe
*pipe
,
1099 unsigned int pipe_flags
, data_size_t buffer_size
)
1101 pipe_end
->pipe
= (struct named_pipe
*)grab_object( pipe
);
1102 pipe_end
->fd
= NULL
;
1103 pipe_end
->flags
= pipe_flags
;
1104 pipe_end
->connection
= NULL
;
1105 pipe_end
->buffer_size
= buffer_size
;
1106 init_async_queue( &pipe_end
->read_q
);
1107 init_async_queue( &pipe_end
->write_q
);
1108 list_init( &pipe_end
->message_queue
);
1111 static struct pipe_server
*create_pipe_server( struct named_pipe
*pipe
, unsigned int options
,
1112 unsigned int pipe_flags
)
1114 struct pipe_server
*server
;
1116 server
= alloc_object( &pipe_server_ops
);
1120 server
->options
= options
;
1121 init_pipe_end( &server
->pipe_end
, pipe
, pipe_flags
, pipe
->insize
);
1122 server
->pipe_end
.state
= FILE_PIPE_LISTENING_STATE
;
1123 server
->pipe_end
.server_pid
= get_process_id( current
->process
);
1125 list_add_head( &pipe
->servers
, &server
->entry
);
1126 if (!(server
->pipe_end
.fd
= alloc_pseudo_fd( &pipe_server_fd_ops
, &server
->pipe_end
.obj
, options
)))
1128 release_object( server
);
1131 allow_fd_caching( server
->pipe_end
.fd
);
1132 set_fd_signaled( server
->pipe_end
.fd
, 1 );
1133 init_async_queue( &server
->listen_q
);
1137 static struct pipe_client
*create_pipe_client( unsigned int flags
, struct named_pipe
*pipe
,
1138 data_size_t buffer_size
, unsigned int options
)
1140 struct pipe_client
*client
;
1142 client
= alloc_object( &pipe_client_ops
);
1146 client
->flags
= flags
;
1147 init_pipe_end( &client
->pipe_end
, pipe
, pipe
->flags
, buffer_size
);
1148 client
->pipe_end
.state
= FILE_PIPE_CONNECTED_STATE
;
1149 client
->pipe_end
.client_pid
= get_process_id( current
->process
);
1151 client
->pipe_end
.fd
= alloc_pseudo_fd( &pipe_client_fd_ops
, &client
->pipe_end
.obj
, options
);
1152 if (!client
->pipe_end
.fd
)
1154 release_object( client
);
1157 allow_fd_caching( client
->pipe_end
.fd
);
1158 set_fd_signaled( client
->pipe_end
.fd
, 1 );
1163 static struct pipe_server
*find_available_server( struct named_pipe
*pipe
)
1165 struct pipe_server
*server
;
1167 /* look for pipe servers that are listening */
1168 LIST_FOR_EACH_ENTRY( server
, &pipe
->servers
, struct pipe_server
, entry
)
1170 if (server
->pipe_end
.state
== FILE_PIPE_LISTENING_STATE
&& async_queued( &server
->listen_q
))
1171 return (struct pipe_server
*)grab_object( server
);
1174 /* fall back to pipe servers that are idle */
1175 LIST_FOR_EACH_ENTRY( server
, &pipe
->servers
, struct pipe_server
, entry
)
1177 if (server
->pipe_end
.state
== FILE_PIPE_LISTENING_STATE
)
1178 return (struct pipe_server
*)grab_object( server
);
1184 static int named_pipe_link_name( struct object
*obj
, struct object_name
*name
, struct object
*parent
)
1186 struct named_pipe_device
*dev
= (struct named_pipe_device
*)parent
;
1188 if (parent
->ops
!= &named_pipe_device_ops
)
1190 set_error( STATUS_OBJECT_NAME_INVALID
);
1193 namespace_add( dev
->pipes
, name
);
1194 name
->parent
= grab_object( parent
);
1198 static struct object
*named_pipe_open_file( struct object
*obj
, unsigned int access
,
1199 unsigned int sharing
, unsigned int options
)
1201 struct named_pipe
*pipe
= (struct named_pipe
*)obj
;
1202 struct pipe_server
*server
;
1203 struct pipe_client
*client
;
1204 unsigned int pipe_sharing
;
1206 if (!(server
= find_available_server( pipe
)))
1208 set_error( STATUS_PIPE_NOT_AVAILABLE
);
1212 pipe_sharing
= pipe
->sharing
;
1213 if (((access
& GENERIC_READ
) && !(pipe_sharing
& FILE_SHARE_READ
)) ||
1214 ((access
& GENERIC_WRITE
) && !(pipe_sharing
& FILE_SHARE_WRITE
)))
1216 set_error( STATUS_ACCESS_DENIED
);
1217 release_object( server
);
1221 if ((client
= create_pipe_client( options
, pipe
, pipe
->outsize
, options
)))
1223 async_wake_up( &server
->listen_q
, STATUS_SUCCESS
);
1224 server
->pipe_end
.state
= FILE_PIPE_CONNECTED_STATE
;
1225 server
->pipe_end
.connection
= &client
->pipe_end
;
1226 client
->pipe_end
.connection
= &server
->pipe_end
;
1227 server
->pipe_end
.client_pid
= client
->pipe_end
.client_pid
;
1228 client
->pipe_end
.server_pid
= server
->pipe_end
.server_pid
;
1230 release_object( server
);
1231 return &client
->pipe_end
.obj
;
1234 static int named_pipe_device_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
)
1236 struct named_pipe_device
*device
= get_fd_user( fd
);
1240 case FSCTL_PIPE_WAIT
:
1242 const FILE_PIPE_WAIT_FOR_BUFFER
*buffer
= get_req_data();
1243 data_size_t size
= get_req_data_size();
1244 struct named_pipe
*pipe
;
1245 struct pipe_server
*server
;
1246 struct unicode_str name
;
1249 if (size
< sizeof(*buffer
) ||
1250 size
< FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER
, Name
[buffer
->NameLength
/sizeof(WCHAR
)]))
1252 set_error( STATUS_INVALID_PARAMETER
);
1255 name
.str
= buffer
->Name
;
1256 name
.len
= (buffer
->NameLength
/ sizeof(WCHAR
)) * sizeof(WCHAR
);
1257 if (!(pipe
= open_named_object( &device
->obj
, &named_pipe_ops
, &name
, 0 ))) return 0;
1259 if (!(server
= find_available_server( pipe
)))
1261 queue_async( &pipe
->waiters
, async
);
1262 when
= buffer
->TimeoutSpecified
? buffer
->Timeout
.QuadPart
: pipe
->timeout
;
1263 async_set_timeout( async
, when
, STATUS_IO_TIMEOUT
);
1264 release_object( pipe
);
1265 set_error( STATUS_PENDING
);
1269 release_object( server
);
1270 release_object( pipe
);
1275 return default_fd_ioctl( fd
, code
, async
);
1280 DECL_HANDLER(create_named_pipe
)
1282 struct named_pipe
*pipe
;
1283 struct pipe_server
*server
;
1284 struct unicode_str name
;
1285 struct object
*root
;
1286 const struct security_descriptor
*sd
;
1287 const struct object_attributes
*objattr
= get_req_object_attributes( &sd
, &name
, &root
);
1289 if (!objattr
) return;
1291 if (!req
->sharing
|| (req
->sharing
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) ||
1292 (!(req
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
) && (req
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
)))
1294 if (root
) release_object( root
);
1295 set_error( STATUS_INVALID_PARAMETER
);
1299 if (!name
.len
) /* pipes need a root directory even without a name */
1301 if (!objattr
->rootdir
)
1303 set_error( STATUS_OBJECT_PATH_SYNTAX_BAD
);
1306 if (!(root
= get_directory_obj( current
->process
, objattr
->rootdir
))) return;
1309 pipe
= create_named_object( root
, &named_pipe_ops
, &name
, objattr
->attributes
| OBJ_OPENIF
, NULL
);
1311 if (root
) release_object( root
);
1314 if (get_error() != STATUS_OBJECT_NAME_EXISTS
)
1316 /* initialize it if it didn't already exist */
1317 pipe
->instances
= 0;
1318 init_async_queue( &pipe
->waiters
);
1319 list_init( &pipe
->servers
);
1320 pipe
->insize
= req
->insize
;
1321 pipe
->outsize
= req
->outsize
;
1322 pipe
->maxinstances
= req
->maxinstances
;
1323 pipe
->timeout
= req
->timeout
;
1324 pipe
->flags
= req
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
;
1325 pipe
->sharing
= req
->sharing
;
1326 if (sd
) default_set_sd( &pipe
->obj
, sd
, OWNER_SECURITY_INFORMATION
|
1327 GROUP_SECURITY_INFORMATION
|
1328 DACL_SECURITY_INFORMATION
|
1329 SACL_SECURITY_INFORMATION
);
1333 if (pipe
->maxinstances
<= pipe
->instances
)
1335 set_error( STATUS_INSTANCE_NOT_AVAILABLE
);
1336 release_object( pipe
);
1339 if (pipe
->sharing
!= req
->sharing
)
1341 set_error( STATUS_ACCESS_DENIED
);
1342 release_object( pipe
);
1345 clear_error(); /* clear the name collision */
1348 server
= create_pipe_server( pipe
, req
->options
, req
->flags
);
1351 reply
->handle
= alloc_handle( current
->process
, server
, req
->access
, objattr
->attributes
);
1353 release_object( server
);
1356 release_object( pipe
);
1359 DECL_HANDLER(set_named_pipe_info
)
1361 struct pipe_end
*pipe_end
;
1363 pipe_end
= (struct pipe_end
*)get_handle_obj( current
->process
, req
->handle
,
1364 FILE_WRITE_ATTRIBUTES
, &pipe_server_ops
);
1367 if (get_error() != STATUS_OBJECT_TYPE_MISMATCH
)
1371 pipe_end
= (struct pipe_end
*)get_handle_obj( current
->process
, req
->handle
,
1372 0, &pipe_client_ops
);
1373 if (!pipe_end
) return;
1376 if ((req
->flags
& ~(NAMED_PIPE_MESSAGE_STREAM_READ
| NAMED_PIPE_NONBLOCKING_MODE
)) ||
1377 ((req
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
) && !(pipe_end
->pipe
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
)))
1379 set_error( STATUS_INVALID_PARAMETER
);
1383 pipe_end
->flags
= pipe_end
->pipe
->flags
| req
->flags
;
1386 release_object( pipe_end
);