Rebase against d003ed3b1743985282c8c8e9c597d77c4b47bb15.

This commit is contained in:
Sebastian Lackner
2017-09-08 00:29:26 +02:00
parent 7709f6b37c
commit 279eca11f1
8 changed files with 98 additions and 172 deletions

View File

@@ -1,4 +1,4 @@
From 7e530d8dbeddd226975a3d2c156a6bf4385f4fe2 Mon Sep 17 00:00:00 2001
From 6d426bf5815052c59127d85383a82e080a00f21b Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sat, 3 Jan 2015 20:07:08 +0100
Subject: ntdll: Expose wine_uninterrupted_[read|write]_memory as exports.
@@ -6,16 +6,16 @@ Subject: ntdll: Expose wine_uninterrupted_[read|write]_memory as exports.
---
dlls/ntdll/ntdll.spec | 4 ++++
dlls/ntdll/ntdll_misc.h | 2 --
dlls/ntdll/signal_i386.c | 10 +++++-----
dlls/ntdll/virtual.c | 34 ++++++++++++++++++++++------------
dlls/ntdll/signal_i386.c | 12 ++++++------
dlls/ntdll/virtual.c | 26 ++++++++++++++++----------
include/winternl.h | 3 +++
5 files changed, 34 insertions(+), 19 deletions(-)
5 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 68d7f22b192..77c4a589e15 100644
index 69bfe923234..5d5fa5b5c4e 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1491,6 +1491,10 @@
@@ -1495,6 +1495,10 @@
# signal handling
@ cdecl __wine_set_signal_handler(long ptr)
@@ -27,23 +27,23 @@ index 68d7f22b192..77c4a589e15 100644
@ cdecl wine_nt_to_unix_file_name(ptr ptr long long)
@ cdecl wine_unix_to_nt_file_name(ptr ptr)
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index c97b1e1f73f..7a8b046ba7a 100644
index 3358119657d..af142a31c70 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -170,8 +170,6 @@ extern BOOL virtual_is_valid_code_address( const void *addr, SIZE_T size ) DECLS
@@ -173,8 +173,6 @@ extern BOOL virtual_is_valid_code_address( const void *addr, SIZE_T size ) DECLS
extern NTSTATUS virtual_handle_fault( LPCVOID addr, DWORD err, BOOL on_signal_stack ) DECLSPEC_HIDDEN;
extern BOOL virtual_check_buffer_for_read( const void *ptr, SIZE_T size ) DECLSPEC_HIDDEN;
extern BOOL virtual_check_buffer_for_write( void *ptr, SIZE_T size ) DECLSPEC_HIDDEN;
-extern SIZE_T virtual_uninterrupted_read_memory( const void *addr, void *buffer, SIZE_T size ) DECLSPEC_HIDDEN;
-extern SIZE_T virtual_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_T size ) DECLSPEC_HIDDEN;
-extern NTSTATUS virtual_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_T size ) DECLSPEC_HIDDEN;
extern void VIRTUAL_SetForceExec( BOOL enable ) DECLSPEC_HIDDEN;
extern void virtual_release_address_space(void) DECLSPEC_HIDDEN;
extern void virtual_set_large_address_space(void) DECLSPEC_HIDDEN;
diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c
index f33c43f1782..03b0f2dcdf6 100644
index ab8d1144472..94b06214568 100644
--- a/dlls/ntdll/signal_i386.c
+++ b/dlls/ntdll/signal_i386.c
@@ -1802,13 +1802,13 @@ static BOOL check_atl_thunk( EXCEPTION_RECORD *rec, CONTEXT *context )
@@ -1802,14 +1802,14 @@ static BOOL check_atl_thunk( EXCEPTION_RECORD *rec, CONTEXT *context )
union atl_thunk thunk_copy;
SIZE_T thunk_len;
@@ -54,11 +54,13 @@ index f33c43f1782..03b0f2dcdf6 100644
if (thunk_len >= sizeof(thunk_copy.t1) && thunk_copy.t1.movl == 0x042444c7 &&
thunk_copy.t1.jmp == 0xe9)
{
- if (virtual_uninterrupted_write_memory( (DWORD *)context->Esp + 1,
+ if (wine_uninterrupted_write_memory( (DWORD *)context->Esp + 1,
&thunk_copy.t1.this, sizeof(DWORD) ) == sizeof(DWORD))
- if (!virtual_uninterrupted_write_memory( (DWORD *)context->Esp + 1,
- &thunk_copy.t1.this, sizeof(DWORD) ))
+ if (!wine_uninterrupted_write_memory( (DWORD *)context->Esp + 1,
+ &thunk_copy.t1.this, sizeof(DWORD) ))
{
context->Eip = (DWORD_PTR)(&thunk->t1.func + 1) + thunk_copy.t1.func;
TRACE( "emulating ATL thunk type 1 at %p, func=%08x arg=%08x\n",
@@ -1852,11 +1852,11 @@ static BOOL check_atl_thunk( EXCEPTION_RECORD *rec, CONTEXT *context )
thunk_copy.t5.inst2 == 0x0460)
{
@@ -69,16 +71,16 @@ index f33c43f1782..03b0f2dcdf6 100644
- virtual_uninterrupted_read_memory( (DWORD *)stack[1] + 1,
+ wine_uninterrupted_read_memory( (DWORD *)stack[1] + 1,
&func, sizeof(DWORD) ) == sizeof(DWORD) &&
- virtual_uninterrupted_write_memory( (DWORD *)context->Esp + 1,
+ wine_uninterrupted_write_memory( (DWORD *)context->Esp + 1,
&stack[0], sizeof(stack[0]) ) == sizeof(stack[0]))
- !virtual_uninterrupted_write_memory( (DWORD *)context->Esp + 1, &stack[0], sizeof(stack[0]) ))
+ !wine_uninterrupted_write_memory( (DWORD *)context->Esp + 1, &stack[0], sizeof(stack[0]) ))
{
context->Ecx = stack[0];
context->Eax = stack[1];
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 9f1b6da0c5e..c9a5945efbf 100644
index a73041706f7..cb3b9aad385 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1838,13 +1838,14 @@ BOOL virtual_check_buffer_for_write( void *ptr, SIZE_T size )
@@ -1862,13 +1862,14 @@ BOOL virtual_check_buffer_for_write( void *ptr, SIZE_T size )
/***********************************************************************
@@ -96,7 +98,7 @@ index 9f1b6da0c5e..c9a5945efbf 100644
{
struct file_view *view;
sigset_t sigset;
@@ -1862,10 +1863,14 @@ SIZE_T virtual_uninterrupted_read_memory( const void *addr, void *buffer, SIZE_T
@@ -1886,10 +1887,14 @@ SIZE_T virtual_uninterrupted_read_memory( const void *addr, void *buffer, SIZE_T
while (bytes_read < size && (VIRTUAL_GetUnixProt( get_page_vprot( page )) & PROT_READ))
{
SIZE_T block_size = min( size, page_size - ((UINT_PTR)addr & page_mask) );
@@ -114,12 +116,12 @@ index 9f1b6da0c5e..c9a5945efbf 100644
bytes_read += block_size;
page += page_size;
}
@@ -1877,13 +1882,14 @@ SIZE_T virtual_uninterrupted_read_memory( const void *addr, void *buffer, SIZE_T
@@ -1901,13 +1906,14 @@ SIZE_T virtual_uninterrupted_read_memory( const void *addr, void *buffer, SIZE_T
/***********************************************************************
- * virtual_uninterrupted_write_memory
+ * wine_uninterrupted_write_memory (NTDLL.@)
+ * wine_uninterrupted_write_memory
*
* Similar to NtWriteVirtualMemory, but without wineserver calls. Moreover
* permissions are checked before accessing each page, to ensure that no
@@ -127,39 +129,30 @@ index 9f1b6da0c5e..c9a5945efbf 100644
+ * exceptions can happen. When a NULL pointer is passed as buffer the
+ * permissions are only checked and no actual memcpy is performed.
*/
-SIZE_T virtual_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_T size )
+SIZE_T CDECL wine_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_T size )
-NTSTATUS virtual_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_T size )
+NTSTATUS CDECL wine_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_T size )
{
struct file_view *view;
sigset_t sigset;
@@ -1921,10 +1927,14 @@ SIZE_T virtual_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_
}
block_size = min( size, page_size - ((UINT_PTR)addr & page_mask) );
- memcpy( addr, buffer, block_size );
- addr = (void *)((char *)addr + block_size);
- buffer = (const void *)((const char *)buffer + block_size);
+ if (buffer)
+ {
+ memcpy( addr, buffer, block_size );
+ buffer = (const void *)((const char *)buffer + block_size);
+ }
+
+ addr = (void *)((char *)addr + block_size);
bytes_written += block_size;
}
@@ -1931,7 +1937,7 @@ NTSTATUS virtual_uninterrupted_write_memory( void *addr, const void *buffer, SIZ
set_page_vprot_bits( addr, size, 0, VPROT_WRITEWATCH );
mprotect_range( view, addr, size, 0, 0 );
}
- memcpy( addr, buffer, size );
+ if (buffer) memcpy( addr, buffer, size );
ret = STATUS_SUCCESS;
}
done:
diff --git a/include/winternl.h b/include/winternl.h
index df20da58c3c..5c697dd45cd 100644
index 3d60baa1f98..3ff6c38d6dc 100644
--- a/include/winternl.h
+++ b/include/winternl.h
@@ -2789,6 +2789,9 @@ NTSYSAPI NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW,
@@ -2790,6 +2790,9 @@ NTSYSAPI NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW,
UINT disposition, BOOLEAN check_case );
NTSYSAPI NTSTATUS CDECL wine_unix_to_nt_file_name( const ANSI_STRING *name, UNICODE_STRING *nt );
+NTSYSAPI SIZE_T CDECL wine_uninterrupted_read_memory( const void *addr, void *buffer, SIZE_T size );
+NTSYSAPI SIZE_T CDECL wine_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_T size );
+NTSYSAPI NTSTATUS CDECL wine_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_T size );
+
/***********************************************************************

View File

@@ -1,4 +1,4 @@
From 252e65f38146194200160b94bf2b4c1963980a07 Mon Sep 17 00:00:00 2001
From 1f6c4cab7763e40ed66d3d9336e47be045a4abb1 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Fri, 21 Nov 2014 12:22:46 +0100
Subject: ws2_32: Avoid race-conditions of async WSARecv() operations with
@@ -41,10 +41,10 @@ that data is immediately available.
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index d13fbf4da4..a532c2591d 100644
index 681f340bc6d..ac356035cc6 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -2332,7 +2332,20 @@ static int WS2_recv( int fd, struct ws2_async *wsa, int flags )
@@ -2358,7 +2358,20 @@ static int WS2_recv( int fd, struct ws2_async *wsa, int flags )
while ((n = recvmsg(fd, &hdr, flags)) == -1)
{
@@ -55,7 +55,7 @@ index d13fbf4da4..a532c2591d 100644
+ for (i = wsa->first_iovec; i < wsa->n_iovecs; i++)
+ {
+ struct iovec *iov = &wsa->iovec[i];
+ if (wine_uninterrupted_write_memory( iov->iov_base, NULL, iov->iov_len ) < iov->iov_len)
+ if (wine_uninterrupted_write_memory( iov->iov_base, NULL, iov->iov_len ) != STATUS_SUCCESS)
+ {
+ errno = EFAULT;
+ return -1;
@@ -67,5 +67,5 @@ index d13fbf4da4..a532c2591d 100644
}
--
2.11.0
2.14.1