async.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /*
  2. * Server-side async I/O support
  3. *
  4. * Copyright (C) 2007 Alexandre Julliard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #include <assert.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <stdarg.h>
  24. #include "ntstatus.h"
  25. #define WIN32_NO_STATUS
  26. #include "windef.h"
  27. #include "winternl.h"
  28. #include "object.h"
  29. #include "file.h"
  30. #include "request.h"
  31. #include "process.h"
  32. #include "handle.h"
  33. struct async
  34. {
  35. struct object obj; /* object header */
  36. struct thread *thread; /* owning thread */
  37. struct list queue_entry; /* entry in async queue list */
  38. struct list process_entry; /* entry in process list */
  39. struct async_queue *queue; /* queue containing this async */
  40. struct fd *fd; /* fd associated with an unqueued async */
  41. struct timeout_user *timeout;
  42. unsigned int timeout_status; /* status to report upon timeout */
  43. struct event *event;
  44. async_data_t data; /* data for async I/O call */
  45. struct iosb *iosb; /* I/O status block */
  46. obj_handle_t wait_handle; /* pre-allocated wait handle */
  47. unsigned int initial_status; /* status returned from initial request */
  48. unsigned int signaled :1;
  49. unsigned int pending :1; /* request successfully queued, but pending */
  50. unsigned int direct_result :1;/* a flag if we're passing result directly from request instead of APC */
  51. unsigned int alerted :1; /* fd is signaled, but we are waiting for client-side I/O */
  52. unsigned int terminated :1; /* async has been terminated */
  53. unsigned int canceled :1; /* have we already queued cancellation for this async? */
  54. unsigned int unknown_status :1; /* initial status is not known yet */
  55. unsigned int blocking :1; /* async is blocking */
  56. struct completion *completion; /* completion associated with fd */
  57. apc_param_t comp_key; /* completion key associated with fd */
  58. unsigned int comp_flags; /* completion flags */
  59. async_completion_callback completion_callback; /* callback to be called on completion */
  60. void *completion_callback_private; /* argument to completion_callback */
  61. };
  62. static void async_dump( struct object *obj, int verbose );
  63. static int async_signaled( struct object *obj, struct wait_queue_entry *entry );
  64. static void async_satisfied( struct object * obj, struct wait_queue_entry *entry );
  65. static void async_destroy( struct object *obj );
  66. static const struct object_ops async_ops =
  67. {
  68. sizeof(struct async), /* size */
  69. &no_type, /* type */
  70. async_dump, /* dump */
  71. add_queue, /* add_queue */
  72. remove_queue, /* remove_queue */
  73. async_signaled, /* signaled */
  74. async_satisfied, /* satisfied */
  75. no_signal, /* signal */
  76. no_get_fd, /* get_fd */
  77. default_map_access, /* map_access */
  78. default_get_sd, /* get_sd */
  79. default_set_sd, /* set_sd */
  80. no_get_full_name, /* get_full_name */
  81. no_lookup_name, /* lookup_name */
  82. no_link_name, /* link_name */
  83. NULL, /* unlink_name */
  84. no_open_file, /* open_file */
  85. no_kernel_obj_list, /* get_kernel_obj_list */
  86. no_close_handle, /* close_handle */
  87. async_destroy /* destroy */
  88. };
  89. static inline void async_reselect( struct async *async )
  90. {
  91. if (async->queue && async->fd) fd_reselect_async( async->fd, async->queue );
  92. }
  93. static void async_dump( struct object *obj, int verbose )
  94. {
  95. struct async *async = (struct async *)obj;
  96. assert( obj->ops == &async_ops );
  97. fprintf( stderr, "Async thread=%p\n", async->thread );
  98. }
  99. static int async_signaled( struct object *obj, struct wait_queue_entry *entry )
  100. {
  101. struct async *async = (struct async *)obj;
  102. assert( obj->ops == &async_ops );
  103. return async->signaled;
  104. }
  105. static void async_satisfied( struct object *obj, struct wait_queue_entry *entry )
  106. {
  107. struct async *async = (struct async *)obj;
  108. assert( obj->ops == &async_ops );
  109. /* we only return an async handle for asyncs created via create_request_async() */
  110. assert( async->iosb );
  111. if (async->direct_result)
  112. {
  113. async_set_result( &async->obj, async->iosb->status, async->iosb->result );
  114. async->direct_result = 0;
  115. }
  116. if (async->initial_status == STATUS_PENDING && async->blocking)
  117. set_wait_status( entry, async->iosb->status );
  118. else
  119. set_wait_status( entry, async->initial_status );
  120. /* close wait handle here to avoid extra server round trip */
  121. if (async->wait_handle)
  122. {
  123. close_handle( async->thread->process, async->wait_handle );
  124. async->wait_handle = 0;
  125. }
  126. }
  127. static void async_destroy( struct object *obj )
  128. {
  129. struct async *async = (struct async *)obj;
  130. assert( obj->ops == &async_ops );
  131. list_remove( &async->process_entry );
  132. if (async->queue)
  133. {
  134. list_remove( &async->queue_entry );
  135. async_reselect( async );
  136. }
  137. else if (async->fd) release_object( async->fd );
  138. if (async->timeout) remove_timeout_user( async->timeout );
  139. if (async->completion) release_object( async->completion );
  140. if (async->event) release_object( async->event );
  141. if (async->iosb) release_object( async->iosb );
  142. release_object( async->thread );
  143. }
  144. /* notifies client thread of new status of its async request */
  145. void async_terminate( struct async *async, unsigned int status )
  146. {
  147. struct iosb *iosb = async->iosb;
  148. if (async->terminated) return;
  149. async->terminated = 1;
  150. if (async->iosb && async->iosb->status == STATUS_PENDING) async->iosb->status = status;
  151. if (status == STATUS_ALERTED)
  152. async->alerted = 1;
  153. /* if no APC could be queued (e.g. the process is terminated),
  154. * thread_queue_apc() may trigger async_set_result(), which may drop the
  155. * last reference to the async, so grab a temporary reference here */
  156. grab_object( async );
  157. if (!async->direct_result)
  158. {
  159. apc_call_t data;
  160. memset( &data, 0, sizeof(data) );
  161. data.type = APC_ASYNC_IO;
  162. data.async_io.user = async->data.user;
  163. data.async_io.result = iosb ? iosb->result : 0;
  164. /* this can happen if the initial status was unknown (i.e. for device
  165. * files). the client should not fill the IOSB in this case; pass it as
  166. * NULL to communicate that.
  167. * note that we check the IOSB status and not the initial status */
  168. if (NT_ERROR( status ) && (!is_fd_overlapped( async->fd ) || !async->pending))
  169. data.async_io.sb = 0;
  170. else
  171. data.async_io.sb = async->data.iosb;
  172. /* if there is output data, the client needs to make an extra request
  173. * to retrieve it; use STATUS_ALERTED to signal this case */
  174. if (iosb && iosb->out_data)
  175. data.async_io.status = STATUS_ALERTED;
  176. else
  177. data.async_io.status = status;
  178. thread_queue_apc( async->thread->process, async->thread, &async->obj, &data );
  179. }
  180. async_reselect( async );
  181. release_object( async );
  182. }
  183. /* callback for timeout on an async request */
  184. static void async_timeout( void *private )
  185. {
  186. struct async *async = private;
  187. async->timeout = NULL;
  188. async_terminate( async, async->timeout_status );
  189. }
  190. /* free an async queue, cancelling all async operations */
  191. void free_async_queue( struct async_queue *queue )
  192. {
  193. struct async *async, *next;
  194. LIST_FOR_EACH_ENTRY_SAFE( async, next, &queue->queue, struct async, queue_entry )
  195. {
  196. if (!async->completion) async->completion = fd_get_completion( async->fd, &async->comp_key );
  197. async->fd = NULL;
  198. async_terminate( async, STATUS_HANDLES_CLOSED );
  199. async->queue = NULL;
  200. release_object( &async->obj );
  201. }
  202. }
  203. void queue_async( struct async_queue *queue, struct async *async )
  204. {
  205. /* fd will be set to NULL in free_async_queue when fd is destroyed */
  206. release_object( async->fd );
  207. async->queue = queue;
  208. grab_object( async );
  209. list_add_tail( &queue->queue, &async->queue_entry );
  210. set_fd_signaled( async->fd, 0 );
  211. }
  212. /* create an async on a given queue of a fd */
  213. struct async *create_async( struct fd *fd, struct thread *thread, const async_data_t *data, struct iosb *iosb )
  214. {
  215. struct event *event = NULL;
  216. struct async *async;
  217. if (data->event && !(event = get_event_obj( thread->process, data->event, EVENT_MODIFY_STATE )))
  218. return NULL;
  219. if (!(async = alloc_object( &async_ops )))
  220. {
  221. if (event) release_object( event );
  222. return NULL;
  223. }
  224. async->thread = (struct thread *)grab_object( thread );
  225. async->event = event;
  226. async->data = *data;
  227. async->timeout = NULL;
  228. async->queue = NULL;
  229. async->fd = (struct fd *)grab_object( fd );
  230. async->initial_status = STATUS_PENDING;
  231. async->signaled = 0;
  232. async->pending = 1;
  233. async->wait_handle = 0;
  234. async->direct_result = 0;
  235. async->alerted = 0;
  236. async->terminated = 0;
  237. async->canceled = 0;
  238. async->unknown_status = 0;
  239. async->blocking = !is_fd_overlapped( fd );
  240. async->completion = fd_get_completion( fd, &async->comp_key );
  241. async->comp_flags = 0;
  242. async->completion_callback = NULL;
  243. async->completion_callback_private = NULL;
  244. if (iosb) async->iosb = (struct iosb *)grab_object( iosb );
  245. else async->iosb = NULL;
  246. list_add_head( &thread->process->asyncs, &async->process_entry );
  247. if (event) reset_event( event );
  248. if (async->completion && data->apc)
  249. {
  250. release_object( async );
  251. set_error( STATUS_INVALID_PARAMETER );
  252. return NULL;
  253. }
  254. return async;
  255. }
  256. /* set the initial status of an async whose status was previously unknown
  257. * the initial status may be STATUS_PENDING */
  258. void async_set_initial_status( struct async *async, unsigned int status )
  259. {
  260. assert( async->unknown_status );
  261. if (!async->terminated)
  262. {
  263. async->initial_status = status;
  264. async->unknown_status = 0;
  265. }
  266. }
  267. void set_async_pending( struct async *async )
  268. {
  269. if (!async->terminated)
  270. async->pending = 1;
  271. }
  272. void async_wake_obj( struct async *async )
  273. {
  274. assert( !async->unknown_status );
  275. if (!async->blocking)
  276. {
  277. async->signaled = 1;
  278. wake_up( &async->obj, 0 );
  279. }
  280. }
  281. /* return async object status and wait handle to client */
  282. obj_handle_t async_handoff( struct async *async, data_size_t *result, int force_blocking )
  283. {
  284. async->blocking = force_blocking || async->blocking;
  285. if (async->unknown_status)
  286. {
  287. /* even the initial status is not known yet */
  288. set_error( STATUS_PENDING );
  289. return async->wait_handle;
  290. }
  291. async->initial_status = get_error();
  292. if (!async->pending && NT_ERROR( get_error() ))
  293. {
  294. close_handle( async->thread->process, async->wait_handle );
  295. async->wait_handle = 0;
  296. return 0;
  297. }
  298. if (get_error() != STATUS_PENDING)
  299. {
  300. /* status and data are already set and returned */
  301. async_terminate( async, get_error() );
  302. }
  303. else if (async->iosb->status != STATUS_PENDING)
  304. {
  305. /* result is already available in iosb, return it */
  306. if (async->iosb->out_data)
  307. {
  308. set_reply_data_ptr( async->iosb->out_data, async->iosb->out_size );
  309. async->iosb->out_data = NULL;
  310. }
  311. }
  312. if (async->iosb->status != STATUS_PENDING)
  313. {
  314. if (result) *result = async->iosb->result;
  315. async->signaled = 1;
  316. }
  317. else
  318. {
  319. async->direct_result = 0;
  320. async->pending = 1;
  321. if (!async->blocking)
  322. {
  323. close_handle( async->thread->process, async->wait_handle);
  324. async->wait_handle = 0;
  325. }
  326. }
  327. async->initial_status = async->iosb->status;
  328. set_error( async->iosb->status );
  329. return async->wait_handle;
  330. }
  331. /* complete a request-based async with a pre-allocated buffer */
  332. void async_request_complete( struct async *async, unsigned int status, data_size_t result,
  333. data_size_t out_size, void *out_data )
  334. {
  335. struct iosb *iosb = async_get_iosb( async );
  336. /* the async may have already been canceled */
  337. if (iosb->status != STATUS_PENDING)
  338. {
  339. release_object( iosb );
  340. free( out_data );
  341. return;
  342. }
  343. iosb->status = status;
  344. iosb->result = result;
  345. iosb->out_data = out_data;
  346. iosb->out_size = out_size;
  347. release_object( iosb );
  348. async_terminate( async, status );
  349. }
  350. /* complete a request-based async */
  351. void async_request_complete_alloc( struct async *async, unsigned int status, data_size_t result,
  352. data_size_t out_size, const void *out_data )
  353. {
  354. void *out_data_copy = NULL;
  355. if (out_size && !(out_data_copy = memdup( out_data, out_size )))
  356. {
  357. async_terminate( async, STATUS_NO_MEMORY );
  358. return;
  359. }
  360. async_request_complete( async, status, result, out_size, out_data_copy );
  361. }
  362. /* mark an async as having unknown initial status */
  363. void async_set_unknown_status( struct async *async )
  364. {
  365. async->unknown_status = 1;
  366. async->direct_result = 0;
  367. }
  368. /* set the timeout of an async operation */
  369. void async_set_timeout( struct async *async, timeout_t timeout, unsigned int status )
  370. {
  371. if (async->timeout) remove_timeout_user( async->timeout );
  372. if (timeout != TIMEOUT_INFINITE) async->timeout = add_timeout_user( timeout, async_timeout, async );
  373. else async->timeout = NULL;
  374. async->timeout_status = status;
  375. }
  376. /* set a callback to be notified when the async is completed */
  377. void async_set_completion_callback( struct async *async, async_completion_callback func, void *private )
  378. {
  379. async->completion_callback = func;
  380. async->completion_callback_private = private;
  381. }
  382. static void add_async_completion( struct async *async, apc_param_t cvalue, unsigned int status,
  383. apc_param_t information )
  384. {
  385. if (async->fd && !async->completion) async->completion = fd_get_completion( async->fd, &async->comp_key );
  386. if (async->completion) add_completion( async->completion, async->comp_key, cvalue, status, information );
  387. }
  388. /* store the result of the client-side async callback */
  389. void async_set_result( struct object *obj, unsigned int status, apc_param_t total )
  390. {
  391. struct async *async = (struct async *)obj;
  392. if (obj->ops != &async_ops) return; /* in case the client messed up the APC results */
  393. assert( async->terminated ); /* it must have been woken up if we get a result */
  394. if (async->alerted && status == STATUS_PENDING) /* restart it */
  395. {
  396. async->terminated = 0;
  397. async->alerted = 0;
  398. async_reselect( async );
  399. }
  400. else
  401. {
  402. if (async->timeout) remove_timeout_user( async->timeout );
  403. async->timeout = NULL;
  404. async->terminated = 1;
  405. if (async->iosb) async->iosb->status = status;
  406. /* don't signal completion if the async failed synchronously
  407. * this can happen if the initial status was unknown (i.e. for device files)
  408. * note that we check the IOSB status here, not the initial status */
  409. if (async->pending || !NT_ERROR( status ))
  410. {
  411. if (async->data.apc)
  412. {
  413. apc_call_t data;
  414. memset( &data, 0, sizeof(data) );
  415. data.type = APC_USER;
  416. data.user.func = async->data.apc;
  417. data.user.args[0] = async->data.apc_context;
  418. data.user.args[1] = async->data.iosb;
  419. data.user.args[2] = 0;
  420. thread_queue_apc( NULL, async->thread, NULL, &data );
  421. }
  422. else if (async->data.apc_context && (async->pending ||
  423. !(async->comp_flags & FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)))
  424. {
  425. add_async_completion( async, async->data.apc_context, status, total );
  426. }
  427. if (async->event) set_event( async->event );
  428. else if (async->fd) set_fd_signaled( async->fd, 1 );
  429. }
  430. if (!async->signaled)
  431. {
  432. async->signaled = 1;
  433. wake_up( &async->obj, 0 );
  434. }
  435. if (async->completion_callback)
  436. async->completion_callback( async->completion_callback_private );
  437. async->completion_callback = NULL;
  438. if (async->queue)
  439. {
  440. list_remove( &async->queue_entry );
  441. async_reselect( async );
  442. async->fd = NULL;
  443. async->queue = NULL;
  444. release_object( async );
  445. }
  446. }
  447. }
  448. /* check if an async operation is waiting to be alerted */
  449. int async_waiting( struct async_queue *queue )
  450. {
  451. struct list *ptr;
  452. struct async *async;
  453. if (!(ptr = list_head( &queue->queue ))) return 0;
  454. async = LIST_ENTRY( ptr, struct async, queue_entry );
  455. return !async->terminated;
  456. }
  457. static int cancel_async( struct process *process, struct object *obj, struct thread *thread, client_ptr_t iosb )
  458. {
  459. struct async *async;
  460. int woken = 0;
  461. /* FIXME: it would probably be nice to replace the "canceled" flag with a
  462. * single LIST_FOR_EACH_ENTRY_SAFE, but currently cancelling an async can
  463. * cause other asyncs to be removed via async_reselect() */
  464. restart:
  465. LIST_FOR_EACH_ENTRY( async, &process->asyncs, struct async, process_entry )
  466. {
  467. if (async->terminated || async->canceled) continue;
  468. if ((!obj || (get_fd_user( async->fd ) == obj)) &&
  469. (!thread || async->thread == thread) &&
  470. (!iosb || async->data.iosb == iosb))
  471. {
  472. async->canceled = 1;
  473. fd_cancel_async( async->fd, async );
  474. woken++;
  475. goto restart;
  476. }
  477. }
  478. return woken;
  479. }
  480. void cancel_process_asyncs( struct process *process )
  481. {
  482. cancel_async( process, NULL, NULL, 0 );
  483. }
  484. /* wake up async operations on the queue */
  485. void async_wake_up( struct async_queue *queue, unsigned int status )
  486. {
  487. struct list *ptr, *next;
  488. LIST_FOR_EACH_SAFE( ptr, next, &queue->queue )
  489. {
  490. struct async *async = LIST_ENTRY( ptr, struct async, queue_entry );
  491. async_terminate( async, status );
  492. if (status == STATUS_ALERTED) break; /* only wake up the first one */
  493. }
  494. }
  495. static void iosb_dump( struct object *obj, int verbose );
  496. static void iosb_destroy( struct object *obj );
  497. static const struct object_ops iosb_ops =
  498. {
  499. sizeof(struct iosb), /* size */
  500. &no_type, /* type */
  501. iosb_dump, /* dump */
  502. no_add_queue, /* add_queue */
  503. NULL, /* remove_queue */
  504. NULL, /* signaled */
  505. NULL, /* satisfied */
  506. no_signal, /* signal */
  507. no_get_fd, /* get_fd */
  508. default_map_access, /* map_access */
  509. default_get_sd, /* get_sd */
  510. default_set_sd, /* set_sd */
  511. no_get_full_name, /* get_full_name */
  512. no_lookup_name, /* lookup_name */
  513. no_link_name, /* link_name */
  514. NULL, /* unlink_name */
  515. no_open_file, /* open_file */
  516. no_kernel_obj_list, /* get_kernel_obj_list */
  517. no_close_handle, /* close_handle */
  518. iosb_destroy /* destroy */
  519. };
  520. static void iosb_dump( struct object *obj, int verbose )
  521. {
  522. assert( obj->ops == &iosb_ops );
  523. fprintf( stderr, "I/O status block\n" );
  524. }
  525. static void iosb_destroy( struct object *obj )
  526. {
  527. struct iosb *iosb = (struct iosb *)obj;
  528. free( iosb->in_data );
  529. free( iosb->out_data );
  530. }
  531. /* allocate iosb struct */
  532. static struct iosb *create_iosb( const void *in_data, data_size_t in_size, data_size_t out_size )
  533. {
  534. struct iosb *iosb;
  535. if (!(iosb = alloc_object( &iosb_ops ))) return NULL;
  536. iosb->status = STATUS_PENDING;
  537. iosb->result = 0;
  538. iosb->in_size = in_size;
  539. iosb->in_data = NULL;
  540. iosb->out_size = out_size;
  541. iosb->out_data = NULL;
  542. if (in_size && !(iosb->in_data = memdup( in_data, in_size )))
  543. {
  544. release_object( iosb );
  545. iosb = NULL;
  546. }
  547. return iosb;
  548. }
  549. /* create an async associated with iosb for async-based requests
  550. * returned async must be passed to async_handoff */
  551. struct async *create_request_async( struct fd *fd, unsigned int comp_flags, const async_data_t *data )
  552. {
  553. struct async *async;
  554. struct iosb *iosb;
  555. if (!(iosb = create_iosb( get_req_data(), get_req_data_size(), get_reply_max_size() )))
  556. return NULL;
  557. async = create_async( fd, current, data, iosb );
  558. release_object( iosb );
  559. if (async)
  560. {
  561. if (!(async->wait_handle = alloc_handle( current->process, async, SYNCHRONIZE, 0 )))
  562. {
  563. release_object( async );
  564. return NULL;
  565. }
  566. async->pending = 0;
  567. async->direct_result = 1;
  568. async->comp_flags = comp_flags;
  569. }
  570. return async;
  571. }
  572. struct iosb *async_get_iosb( struct async *async )
  573. {
  574. return async->iosb ? (struct iosb *)grab_object( async->iosb ) : NULL;
  575. }
  576. struct thread *async_get_thread( struct async *async )
  577. {
  578. return async->thread;
  579. }
  580. /* find the first pending async in queue */
  581. struct async *find_pending_async( struct async_queue *queue )
  582. {
  583. struct async *async;
  584. LIST_FOR_EACH_ENTRY( async, &queue->queue, struct async, queue_entry )
  585. if (!async->terminated) return (struct async *)grab_object( async );
  586. return NULL;
  587. }
  588. /* cancels all async I/O */
  589. DECL_HANDLER(cancel_async)
  590. {
  591. struct object *obj = get_handle_obj( current->process, req->handle, 0, NULL );
  592. struct thread *thread = req->only_thread ? current : NULL;
  593. if (obj)
  594. {
  595. int count = cancel_async( current->process, obj, thread, req->iosb );
  596. if (!count && req->iosb) set_error( STATUS_NOT_FOUND );
  597. release_object( obj );
  598. }
  599. }
  600. /* get async result from associated iosb */
  601. DECL_HANDLER(get_async_result)
  602. {
  603. struct iosb *iosb = NULL;
  604. struct async *async;
  605. LIST_FOR_EACH_ENTRY( async, &current->process->asyncs, struct async, process_entry )
  606. if (async->data.user == req->user_arg)
  607. {
  608. iosb = async->iosb;
  609. break;
  610. }
  611. if (!iosb)
  612. {
  613. set_error( STATUS_INVALID_PARAMETER );
  614. return;
  615. }
  616. if (iosb->out_data)
  617. {
  618. data_size_t size = min( iosb->out_size, get_reply_max_size() );
  619. if (size)
  620. {
  621. set_reply_data_ptr( iosb->out_data, size );
  622. iosb->out_data = NULL;
  623. }
  624. }
  625. set_error( iosb->status );
  626. }