ntdll: Introduce a sync_ioctl() helper.

This commit is contained in:
Elizabeth Figura 2022-06-25 15:45:55 -05:00 committed by Alexandre Julliard
parent 35ad787138
commit d215435c78
3 changed files with 22 additions and 21 deletions

View file

@ -2268,7 +2268,6 @@ static NTSTATUS get_mountmgr_fs_info( HANDLE handle, int fd, struct mountmgr_uni
OBJECT_ATTRIBUTES attr;
UNICODE_STRING string;
char *unix_name;
IO_STATUS_BLOCK io = {{0}};
HANDLE mountmgr;
unsigned int status;
int letter;
@ -2294,8 +2293,7 @@ static NTSTATUS get_mountmgr_fs_info( HANDLE handle, int fd, struct mountmgr_uni
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SYNCHRONOUS_IO_NONALERT );
if (status) return status;
status = NtDeviceIoControlFile( mountmgr, NULL, NULL, NULL, &io, IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE,
drive, sizeof(*drive), drive, size );
status = sync_ioctl( mountmgr, IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE, drive, sizeof(*drive), drive, size );
NtClose( mountmgr );
if (status == STATUS_BUFFER_OVERFLOW) status = STATUS_SUCCESS;
else if (status) WARN("failed to retrieve filesystem type from mountmgr, status %#x\n", status);
@ -5321,8 +5319,6 @@ struct io_timeouts
static unsigned int get_io_timeouts( HANDLE handle, enum server_fd_type type, ULONG count, BOOL is_read,
struct io_timeouts *timeouts )
{
unsigned int status = STATUS_SUCCESS;
timeouts->interval = timeouts->total = -1;
switch(type)
@ -5331,11 +5327,9 @@ static unsigned int get_io_timeouts( HANDLE handle, enum server_fd_type type, UL
{
/* GetCommTimeouts */
SERIAL_TIMEOUTS st;
IO_STATUS_BLOCK io = {{0}};
status = NtDeviceIoControlFile( handle, NULL, NULL, NULL, &io,
IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, &st, sizeof(st) );
if (status) break;
if (sync_ioctl( handle, IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, &st, sizeof(st) ))
break;
if (is_read)
{
@ -5370,8 +5364,7 @@ static unsigned int get_io_timeouts( HANDLE handle, enum server_fd_type type, UL
{
req->handle = wine_server_obj_handle( handle );
req->flags = 0;
if (!(status = wine_server_call( req )) &&
reply->read_timeout != TIMEOUT_INFINITE)
if (!wine_server_call( req ) && reply->read_timeout != TIMEOUT_INFINITE)
timeouts->total = reply->read_timeout / -10000;
}
SERVER_END_REQ;
@ -5418,14 +5411,13 @@ static NTSTATUS get_io_avail_mode( HANDLE handle, enum server_fd_type type, BOOL
{
/* GetCommTimeouts */
SERIAL_TIMEOUTS st;
IO_STATUS_BLOCK io = {{0}};
status = NtDeviceIoControlFile( handle, NULL, NULL, NULL, &io,
IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, &st, sizeof(st) );
if (status) break;
*avail_mode = (!st.ReadTotalTimeoutMultiplier &&
!st.ReadTotalTimeoutConstant &&
st.ReadIntervalTimeout == MAXDWORD);
if (!(status = sync_ioctl( handle, IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, &st, sizeof(st) )))
{
*avail_mode = (!st.ReadTotalTimeoutMultiplier &&
!st.ReadTotalTimeoutConstant &&
st.ReadIntervalTimeout == MAXDWORD);
}
break;
}
case FD_TYPE_MAILSLOT:
@ -6182,6 +6174,15 @@ NTSTATUS WINAPI NtDeviceIoControlFile( HANDLE handle, HANDLE event, PIO_APC_ROUT
}
/* helper for internal ioctl calls */
NTSTATUS sync_ioctl( HANDLE file, ULONG code, void *in_buffer, ULONG in_size, void *out_buffer, ULONG out_size )
{
IO_STATUS_BLOCK io;
return NtDeviceIoControlFile( file, NULL, NULL, NULL, &io, code, in_buffer, in_size, out_buffer, out_size );
}
/* Tell Valgrind to ignore any holes in structs we will be passing to the
* server */
static void ignore_server_ioctl_struct_holes( ULONG code, const void *in_buffer, ULONG in_size )

View file

@ -413,9 +413,7 @@ static void set_stdio_fd( int stdin_fd, int stdout_fd )
*/
static BOOL is_unix_console_handle( HANDLE handle )
{
IO_STATUS_BLOCK io = {{0}};
return !NtDeviceIoControlFile( handle, NULL, NULL, NULL, &io, IOCTL_CONDRV_IS_UNIX,
NULL, 0, NULL, 0 );
return !sync_ioctl( handle, IOCTL_CONDRV_IS_UNIX, NULL, 0, NULL, 0 );
}

View file

@ -312,6 +312,8 @@ extern NTSTATUS set_thread_wow64_context( HANDLE handle, const void *ctx, ULONG
extern void fill_vm_counters( VM_COUNTERS_EX *pvmi, int unix_pid );
extern NTSTATUS open_hkcu_key( const char *path, HANDLE *key );
extern NTSTATUS sync_ioctl( HANDLE file, ULONG code, void *in_buffer, ULONG in_size,
void *out_buffer, ULONG out_size );
extern NTSTATUS cdrom_DeviceIoControl( HANDLE device, HANDLE event, PIO_APC_ROUTINE apc, void *apc_user,
IO_STATUS_BLOCK *io, UINT code, void *in_buffer,
UINT in_size, void *out_buffer, UINT out_size );