winehq.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2025
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
January
2003
December
November
October
September
August
July
June
May
April
March
February
January
2002
December
November
October
September
August
July
June
May
April
March
February
January
2001
December
November
October
September
August
July
June
May
April
March
February
List overview
wine-commits
June 2022
----- 2025 -----
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
January 2004
----- 2003 -----
December 2003
November 2003
October 2003
September 2003
August 2003
July 2003
June 2003
May 2003
April 2003
March 2003
February 2003
January 2003
----- 2002 -----
December 2002
November 2002
October 2002
September 2002
August 2002
July 2002
June 2002
May 2002
April 2002
March 2002
February 2002
January 2002
----- 2001 -----
December 2001
November 2001
October 2001
September 2001
August 2001
July 2001
June 2001
May 2001
April 2001
March 2001
February 2001
wine-commits@winehq.org
2 participants
791 discussions
Start a n
N
ew thread
Rémi Bernon : dinput/tests: Support test IOCTLs on the bus control interface.
by Alexandre Julliard
02 Jun '22
02 Jun '22
Module: wine Branch: master Commit: c76915958bce016035d5fd14c0dc07be5471d25d URL:
https://source.winehq.org/git/wine.git/?a=commit;h=c76915958bce016035d5fd14…
Author: Rémi Bernon <rbernon(a)codeweavers.com> Date: Wed Jun 1 12:11:59 2022 +0200 dinput/tests: Support test IOCTLs on the bus control interface. Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com> --- dlls/dinput/tests/dinput_test.h | 25 +++++++++++------- dlls/dinput/tests/driver_bus.c | 30 ++++++++++++++++------ dlls/dinput/tests/driver_hid.h | 2 ++ dlls/dinput/tests/hid.c | 57 +++++++++++++++++++++++++++++++---------- 4 files changed, 84 insertions(+), 30 deletions(-) Diff:
https://source.winehq.org/git/wine.git/?a=commitdiff;h=c76915958bce016035d5…
1
0
0
0
Rémi Bernon : dinput/tests: Fix source file in driver test context.
by Alexandre Julliard
02 Jun '22
02 Jun '22
Module: wine Branch: master Commit: 5611335198f62545f2a383c2036c12ca674afe0a URL:
https://source.winehq.org/git/wine.git/?a=commit;h=5611335198f62545f2a383c2…
Author: Rémi Bernon <rbernon(a)codeweavers.com> Date: Wed Jun 1 12:10:20 2022 +0200 dinput/tests: Fix source file in driver test context. Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com> --- dlls/dinput/tests/dinput_test.h | 12 ++---------- dlls/dinput/tests/force_feedback.c | 6 +++--- dlls/dinput/tests/hid.c | 20 +++++++++++++++----- dlls/dinput/tests/hotplug.c | 4 ++-- dlls/dinput/tests/joystick8.c | 14 +++++++------- 5 files changed, 29 insertions(+), 27 deletions(-) Diff:
https://source.winehq.org/git/wine.git/?a=commitdiff;h=5611335198f62545f2a3…
1
0
0
0
Rémi Bernon : dinput/tests: Enforce ioctl buffer sizes to avoid overflows.
by Alexandre Julliard
02 Jun '22
02 Jun '22
Module: wine Branch: master Commit: 01e8a9d03b17cbfe97663cf4b1e6d2c6fd67ca2a URL:
https://source.winehq.org/git/wine.git/?a=commit;h=01e8a9d03b17cbfe97663cf4…
Author: Rémi Bernon <rbernon(a)codeweavers.com> Date: Wed Jun 1 10:24:49 2022 +0200 dinput/tests: Enforce ioctl buffer sizes to avoid overflows. Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com> --- dlls/dinput/tests/driver_bus.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dlls/dinput/tests/driver_bus.c b/dlls/dinput/tests/driver_bus.c index dc9b549e1d8..64ca33e7c89 100644 --- a/dlls/dinput/tests/driver_bus.c +++ b/dlls/dinput/tests/driver_bus.c @@ -1251,18 +1251,22 @@ static NTSTATUS pdo_handle_ioctl( struct phys_device *impl, IRP *irp, ULONG code switch (code) { case IOCTL_WINETEST_HID_SET_EXPECT: + if (in_size > EXPECT_QUEUE_BUFFER_SIZE) return STATUS_BUFFER_OVERFLOW; expect_queue_reset( &impl->expect_queue, in_buffer, in_size ); return STATUS_SUCCESS; case IOCTL_WINETEST_HID_WAIT_EXPECT: { - struct wait_expect_params wait_params = *(struct wait_expect_params *)in_buffer; - if (!wait_params.wait_pending) return expect_queue_wait( &impl->expect_queue, irp ); + struct wait_expect_params *wait_params = (struct wait_expect_params *)in_buffer; + if (in_size < sizeof(*wait_params)) return STATUS_BUFFER_TOO_SMALL; + if (!wait_params->wait_pending) return expect_queue_wait( &impl->expect_queue, irp ); else return expect_queue_wait_pending( &impl->expect_queue, irp ); } case IOCTL_WINETEST_HID_SEND_INPUT: + if (in_size > EXPECT_QUEUE_BUFFER_SIZE) return STATUS_BUFFER_OVERFLOW; input_queue_reset( &impl->input_queue, in_buffer, in_size ); return STATUS_SUCCESS; case IOCTL_WINETEST_HID_SET_CONTEXT: + if (in_size > sizeof(impl->expect_queue.context)) return STATUS_BUFFER_OVERFLOW; KeAcquireSpinLock( &impl->expect_queue.lock, &irql ); memcpy( impl->expect_queue.context, in_buffer, in_size ); KeReleaseSpinLock( &impl->expect_queue.lock, irql );
1
0
0
0
Rémi Bernon : dinput/tests: Move bus PDO ioctl handling to a separate helper.
by Alexandre Julliard
02 Jun '22
02 Jun '22
Module: wine Branch: master Commit: 5a1d2b58b388869c1a4747af2471620aac666a22 URL:
https://source.winehq.org/git/wine.git/?a=commit;h=5a1d2b58b388869c1a4747af…
Author: Rémi Bernon <rbernon(a)codeweavers.com> Date: Tue May 31 20:57:22 2022 +0200 dinput/tests: Move bus PDO ioctl handling to a separate helper. Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com> --- dlls/dinput/tests/driver_bus.c | 53 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/dlls/dinput/tests/driver_bus.c b/dlls/dinput/tests/driver_bus.c index 6a1994e509c..dc9b549e1d8 100644 --- a/dlls/dinput/tests/driver_bus.c +++ b/dlls/dinput/tests/driver_bus.c @@ -1244,40 +1244,29 @@ static NTSTATUS WINAPI driver_internal_ioctl( DEVICE_OBJECT *device, IRP *irp ) return fdo_internal_ioctl( device, irp ); } -static NTSTATUS WINAPI pdo_ioctl( DEVICE_OBJECT *device, IRP *irp ) +static NTSTATUS pdo_handle_ioctl( struct phys_device *impl, IRP *irp, ULONG code, void *in_buffer, ULONG in_size ) { - IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp ); - struct phys_device *impl = pdo_from_DEVICE_OBJECT( device ); - ULONG in_size = stack->Parameters.DeviceIoControl.InputBufferLength; - ULONG code = stack->Parameters.DeviceIoControl.IoControlCode; - NTSTATUS status; KIRQL irql; - if (winetest_debug > 1) trace( "%s: device %p, code %#lx %s\n", __func__, device, code, debugstr_ioctl(code) ); - switch (code) { case IOCTL_WINETEST_HID_SET_EXPECT: - expect_queue_reset( &impl->expect_queue, irp->AssociatedIrp.SystemBuffer, in_size ); - status = STATUS_SUCCESS; - break; + expect_queue_reset( &impl->expect_queue, in_buffer, in_size ); + return STATUS_SUCCESS; case IOCTL_WINETEST_HID_WAIT_EXPECT: { - struct wait_expect_params wait_params = *(struct wait_expect_params *)irp->AssociatedIrp.SystemBuffer; - if (!wait_params.wait_pending) status = expect_queue_wait( &impl->expect_queue, irp ); - else status = expect_queue_wait_pending( &impl->expect_queue, irp ); - break; + struct wait_expect_params wait_params = *(struct wait_expect_params *)in_buffer; + if (!wait_params.wait_pending) return expect_queue_wait( &impl->expect_queue, irp ); + else return expect_queue_wait_pending( &impl->expect_queue, irp ); } case IOCTL_WINETEST_HID_SEND_INPUT: - input_queue_reset( &impl->input_queue, irp->AssociatedIrp.SystemBuffer, in_size ); - status = STATUS_SUCCESS; - break; + input_queue_reset( &impl->input_queue, in_buffer, in_size ); + return STATUS_SUCCESS; case IOCTL_WINETEST_HID_SET_CONTEXT: KeAcquireSpinLock( &impl->expect_queue.lock, &irql ); - memcpy( impl->expect_queue.context, irp->AssociatedIrp.SystemBuffer, in_size ); + memcpy( impl->expect_queue.context, in_buffer, in_size ); KeReleaseSpinLock( &impl->expect_queue.lock, irql ); - status = STATUS_SUCCESS; - break; + return STATUS_SUCCESS; case IOCTL_WINETEST_REMOVE_DEVICE: KeAcquireSpinLock( &impl->base.lock, &irql ); impl->base.state = PNP_DEVICE_REMOVED; @@ -1285,17 +1274,27 @@ static NTSTATUS WINAPI pdo_ioctl( DEVICE_OBJECT *device, IRP *irp ) KeReleaseSpinLock( &impl->base.lock, irql ); impl->pending_remove = irp; IoMarkIrpPending( irp ); - status = STATUS_PENDING; - break; + return STATUS_PENDING; case IOCTL_WINETEST_CREATE_DEVICE: ok( 0, "unexpected call\n" ); - status = irp->IoStatus.Status; - break; + return irp->IoStatus.Status; default: ok( 0, "unexpected call\n" ); - status = irp->IoStatus.Status; - break; + return irp->IoStatus.Status; } +} + +static NTSTATUS WINAPI pdo_ioctl( DEVICE_OBJECT *device, IRP *irp ) +{ + IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp ); + struct phys_device *impl = pdo_from_DEVICE_OBJECT( device ); + ULONG in_size = stack->Parameters.DeviceIoControl.InputBufferLength; + ULONG code = stack->Parameters.DeviceIoControl.IoControlCode; + NTSTATUS status; + + if (winetest_debug > 1) trace( "%s: device %p, code %#lx %s\n", __func__, device, code, debugstr_ioctl(code) ); + + status = pdo_handle_ioctl( impl, irp, code, irp->AssociatedIrp.SystemBuffer, in_size ); if (status != STATUS_PENDING) {
1
0
0
0
Rémi Bernon : ntdll: Use a more compact block layout.
by Alexandre Julliard
02 Jun '22
02 Jun '22
Module: wine Branch: master Commit: a18ffeae21cf1713236244ccc7ab2583384d9b3e URL:
https://source.winehq.org/git/wine.git/?a=commit;h=a18ffeae21cf1713236244cc…
Author: Rémi Bernon <rbernon(a)codeweavers.com> Date: Wed May 4 11:04:54 2022 +0200 ntdll: Use a more compact block layout. With a separate block_flags field. Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com> --- dlls/ntdll/heap.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index 3f14de39a1d..0ecff6f6cba 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -78,9 +78,10 @@ struct rtl_heap_entry struct block { - DWORD size; /* Block size; must be the first field */ - DWORD magic : 24; /* Magic number */ - DWORD unused_bytes : 8; /* Number of bytes in the block not used by user data (max value is HEAP_MIN_DATA_SIZE+HEAP_MIN_SHRINK_SIZE) */ + WORD block_size; /* block size in multiple of ALIGNMENT */ + BYTE block_flags; + BYTE tail_size; /* unused size (used block) / high size bits (free block) */ + DWORD magic; }; C_ASSERT( sizeof(struct block) == 8 ); @@ -228,36 +229,39 @@ static inline BOOL contains( const void *a, SIZE_T a_size, const void *b, SIZE_T static inline UINT block_get_flags( const struct block *block ) { - return block->size & ~ARENA_SIZE_MASK; + return block->block_flags; } static inline UINT block_get_type( const struct block *block ) { - if (block_get_flags( block ) & BLOCK_FLAG_FREE) return (block->unused_bytes << 24)|block->magic; return block->magic; } static inline void block_set_type( struct block *block, UINT type ) { - if (type >> 24) block->unused_bytes = type >> 24; block->magic = type; } static inline UINT block_get_overhead( const struct block *block ) { if (block_get_flags( block ) & BLOCK_FLAG_FREE) return sizeof(*block) + sizeof(struct list); - return sizeof(*block) + block->unused_bytes; + return sizeof(*block) + block->tail_size; } /* return the size of a block, including its header */ static inline UINT block_get_size( const struct block *block ) { - return block->size & ARENA_SIZE_MASK; + UINT block_size = block->block_size; + if (block_get_flags( block ) & BLOCK_FLAG_FREE) block_size += (UINT)block->tail_size << 16; + return block_size * ALIGNMENT; } -static inline void block_set_size( struct block *block, UINT flags, UINT block_size ) +static inline void block_set_size( struct block *block, UINT block_flags, UINT block_size ) { - block->size = (block_size & ARENA_SIZE_MASK) | (flags & ~ARENA_SIZE_MASK); + block_size /= ALIGNMENT; + if (block_flags & BLOCK_FLAG_FREE) block->tail_size = block_size >> 16; + block->block_size = block_size; + block->block_flags = block_flags; } static inline void *subheap_base( const SUBHEAP *subheap ) @@ -350,7 +354,7 @@ static inline void mark_block_free( void *ptr, SIZE_T size, DWORD flags ) /* mark a block of memory as a tail block */ static inline void mark_block_tail( struct block *block, DWORD flags ) { - char *tail = (char *)block + block_get_size( block ) - block->unused_bytes; + char *tail = (char *)block + block_get_size( block ) - block->tail_size; if (flags & HEAP_TAIL_CHECKING_ENABLED) { valgrind_make_writable( tail, ALIGNMENT ); @@ -518,7 +522,7 @@ static void heap_dump( const HEAP *heap ) { TRACE( " %p: (used) type %#10x, size %#8x, flags %#4x, unused %#4x", block, block_get_type( block ), block_get_size( block ), block_get_flags( block ), - block->unused_bytes ); + block->tail_size ); if (!(block_get_flags( block ) & BLOCK_FLAG_PREV_FREE)) TRACE( "\n" ); else TRACE( ", back %p\n", *((struct block **)block - 1) ); @@ -548,7 +552,7 @@ static void heap_dump( const HEAP *heap ) if (!(block = heap->pending_free[i])) break; TRACE( " %c%p: (pend) type %#10x, size %#8x, flags %#4x, unused %#4x", i == heap->pending_pos ? '*' : ' ', - block, block_get_type( block ), block_get_size( block ), block_get_flags( block ), block->unused_bytes ); + block, block_get_type( block ), block_get_size( block ), block_get_flags( block ), block->tail_size ); if (!(block_get_flags( block ) & BLOCK_FLAG_PREV_FREE)) TRACE( "\n" ); else TRACE( ", back %p\n", *((struct block **)block - 1) ); } @@ -763,15 +767,15 @@ static inline void shrink_used_block( SUBHEAP *subheap, struct block *block, UIN if (old_block_size >= block_size + HEAP_MIN_BLOCK_SIZE) { block_set_size( block, flags, block_size ); - block->unused_bytes = block_size - sizeof(*block) - size; + block->tail_size = block_size - sizeof(*block) - size; create_free_block( subheap, next_block( subheap, block ), old_block_size - block_size ); } else { struct block *next; block_set_size( block, flags, old_block_size ); - block->unused_bytes = old_block_size - sizeof(*block) - size; - if ((next = next_block( subheap, block ))) next->size &= ~BLOCK_FLAG_PREV_FREE; + block->tail_size = old_block_size - sizeof(*block) - size; + if ((next = next_block( subheap, block ))) next->block_flags &= ~BLOCK_FLAG_PREV_FREE; } } @@ -1136,7 +1140,7 @@ static BOOL validate_used_block( const SUBHEAP *subheap, const struct block *blo err = "invalid block flags"; else if (!contains( base, commit_end - base, block, block_get_size( block ) )) err = "invalid block size"; - else if (block->unused_bytes > block_get_size( block ) - sizeof(*block)) + else if (block->tail_size > block_get_size( block ) - sizeof(*block)) err = "invalid block unused size"; else if ((next = next_block( subheap, block )) && (block_get_flags( next ) & BLOCK_FLAG_PREV_FREE)) err = "invalid next block flags"; @@ -1162,7 +1166,7 @@ static BOOL validate_used_block( const SUBHEAP *subheap, const struct block *blo } else if (!err && (flags & HEAP_TAIL_CHECKING_ENABLED)) { - const unsigned char *tail = (unsigned char *)block + block_get_size( block ) - block->unused_bytes; + const unsigned char *tail = (unsigned char *)block + block_get_size( block ) - block->tail_size; for (i = 0; !err && i < ALIGNMENT; i++) if (tail[i] != ARENA_TAIL_FILLER) err = "invalid block tail"; }
1
0
0
0
Rémi Bernon : ntdll: Round free block size to block size alignment.
by Alexandre Julliard
02 Jun '22
02 Jun '22
Module: wine Branch: master Commit: ff12dc1247f501d93b260586c4e702bff529e4d0 URL:
https://source.winehq.org/git/wine.git/?a=commit;h=ff12dc1247f501d93b260586…
Author: Rémi Bernon <rbernon(a)codeweavers.com> Date: Mon May 30 14:19:16 2022 +0200 ntdll: Round free block size to block size alignment. Block sizes are now always rounded to ALIGNMENT multiple, except for the last free block in a region. This makes it consistent and will let us use a more compact block layout. Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com> --- dlls/ntdll/heap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index 0a6228217ff..3f14de39a1d 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -892,6 +892,7 @@ static SUBHEAP *HEAP_CreateSubHeap( HEAP *heap, LPVOID address, DWORD flags, SIZE_T commitSize, SIZE_T totalSize ) { struct entry *pEntry; + SIZE_T block_size; SUBHEAP *subheap; unsigned int i; @@ -991,9 +992,9 @@ static SUBHEAP *HEAP_CreateSubHeap( HEAP *heap, LPVOID address, DWORD flags, } } - /* Create the first free block */ - - create_free_block( subheap, first_block( subheap ), subheap_size( subheap ) - subheap_overhead( subheap ) ); + block_size = subheap_size( subheap ) - subheap_overhead( subheap ); + block_size &= ~(ALIGNMENT - 1); + create_free_block( subheap, first_block( subheap ), block_size ); return subheap; }
1
0
0
0
Rémi Bernon : ntdll: Improve block size rounding compatibility.
by Alexandre Julliard
02 Jun '22
02 Jun '22
Module: wine Branch: master Commit: deaf0891b096628cf99e58834c39a45a6c99c54c URL:
https://source.winehq.org/git/wine.git/?a=commit;h=deaf0891b096628cf99e5883…
Author: Rémi Bernon <rbernon(a)codeweavers.com> Date: Mon May 2 13:21:28 2022 +0200 ntdll: Improve block size rounding compatibility. This also increase the default heap size to 2MiB (32bit) / 4MiB (64bit), for the tests to pass. Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com> --- dlls/kernel32/tests/heap.c | 6 +----- dlls/ntdll/heap.c | 46 +++++++++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c index bb5e57fe94e..91f582f36de 100644 --- a/dlls/kernel32/tests/heap.c +++ b/dlls/kernel32/tests/heap.c @@ -1055,7 +1055,6 @@ static void test_HeapCreate(void) { if (entries[i].wFlags != PROCESS_HEAP_ENTRY_BUSY) continue; ok( entries[i].cbData == 0x18 + 2 * sizeof(void *), "got cbData %#lx\n", entries[i].cbData ); - todo_wine_if(sizeof(void *) == 8) ok( entries[i].cbOverhead == 0x8, "got cbOverhead %#x\n", entries[i].cbOverhead ); } @@ -2175,10 +2174,7 @@ static void test_block_layout( HANDLE heap, DWORD global_flags, DWORD heap_flags expect_size = max( alloc_size, 2 * sizeof(void *) ); expect_size = ALIGN_BLOCK_SIZE( expect_size + extra_size ); diff = min( llabs( ptr2 - ptr1 ), llabs( ptr1 - ptr0 ) ); - todo_wine_if( (heap_flags & (HEAP_VALIDATE_PARAMS|HEAP_VALIDATE_ALL)) || - ((global_flags & ~FLG_HEAP_ENABLE_TAIL_CHECK) && alloc_size < 0x10000) || - (!global_flags && alloc_size < 2 * sizeof(void *)) || - (alloc_size == 0xfd000 && sizeof(void *) == 8) ) + todo_wine_if( (!(global_flags & ~FLG_HEAP_ENABLE_FREE_CHECK) && alloc_size < 2 * sizeof(void *)) ) ok( diff == expect_size, "got diff %#Ix exp %#Ix\n", diff, expect_size ); ok( !memcmp( ptr0 + alloc_size, tail_buf, tail_size ), "missing block tail\n" ); diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index 59d191ed1b3..0a6228217ff 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -127,20 +127,18 @@ typedef struct /* everything is aligned on 8 byte boundaries (16 for Win64) */ #define LARGE_ALIGNMENT 16 /* large blocks have stricter alignment */ -#define ARENA_OFFSET (ALIGNMENT - sizeof(struct block)) #define COMMIT_MASK 0xffff /* bitmask for commit/decommit granularity */ C_ASSERT( sizeof(ARENA_LARGE) % LARGE_ALIGNMENT == 0 ); #define ROUND_ADDR(addr, mask) ((void *)((UINT_PTR)(addr) & ~(UINT_PTR)(mask))) -#define ROUND_SIZE(size) ((((size) + ALIGNMENT - 1) & ~(ALIGNMENT-1)) + ARENA_OFFSET) - -/* minimum data size (without arenas) of an allocated block */ -/* make sure that it's larger than a free list entry */ -#define HEAP_MIN_DATA_SIZE ROUND_SIZE(2 * sizeof(struct list)) -#define HEAP_MIN_BLOCK_SIZE (HEAP_MIN_DATA_SIZE + sizeof(struct block)) -/* minimum size that must remain to shrink an allocated block */ -#define HEAP_MIN_SHRINK_SIZE (HEAP_MIN_DATA_SIZE+sizeof(struct entry)) +#define ROUND_SIZE(size, mask) ((((SIZE_T)(size) + (mask)) & ~(SIZE_T)(mask))) + +#define HEAP_MIN_BLOCK_SIZE ROUND_SIZE(sizeof(struct entry) + ALIGNMENT, ALIGNMENT - 1) + +C_ASSERT( sizeof(struct block) <= HEAP_MIN_BLOCK_SIZE ); +C_ASSERT( sizeof(struct entry) <= HEAP_MIN_BLOCK_SIZE ); + /* minimum size to start allocating large blocks */ #define HEAP_MIN_LARGE_BLOCK_SIZE (0x10000 * ALIGNMENT - 0x1000) /* extra size to add at the end of block for tail checking */ @@ -208,7 +206,7 @@ C_ASSERT( offsetof(HEAP, subheap) <= COMMIT_MASK ); #define HEAP_MAGIC ((DWORD)('H' | ('E'<<8) | ('A'<<16) | ('P'<<24))) -#define HEAP_DEF_SIZE 0x110000 /* Default heap size = 1Mb + 64Kb */ +#define HEAP_DEF_SIZE (0x40000 * ALIGNMENT) #define MAX_FREE_PENDING 1024 /* max number of free requests to delay */ /* some undocumented flags (names are made up) */ @@ -217,6 +215,7 @@ C_ASSERT( offsetof(HEAP, subheap) <= COMMIT_MASK ); #define HEAP_VALIDATE 0x10000000 #define HEAP_VALIDATE_ALL 0x20000000 #define HEAP_VALIDATE_PARAMS 0x40000000 +#define HEAP_CHECKING_ENABLED 0x80000000 static HEAP *processHeap; /* main process heap */ @@ -447,7 +446,8 @@ static RTL_CRITICAL_SECTION_DEBUG process_heap_cs_debug = static inline ULONG heap_get_flags( const HEAP *heap, ULONG flags ) { - flags &= HEAP_GENERATE_EXCEPTIONS | HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY | HEAP_REALLOC_IN_PLACE_ONLY; + if (flags & (HEAP_TAIL_CHECKING_ENABLED | HEAP_FREE_CHECKING_ENABLED)) flags |= HEAP_CHECKING_ENABLED; + flags &= HEAP_GENERATE_EXCEPTIONS | HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY | HEAP_REALLOC_IN_PLACE_ONLY | HEAP_CHECKING_ENABLED; return heap->flags | flags; } @@ -760,7 +760,7 @@ static void free_used_block( SUBHEAP *subheap, struct block *block ) static inline void shrink_used_block( SUBHEAP *subheap, struct block *block, UINT flags, SIZE_T old_block_size, SIZE_T block_size, SIZE_T size ) { - if (old_block_size >= block_size + HEAP_MIN_SHRINK_SIZE) + if (old_block_size >= block_size + HEAP_MIN_BLOCK_SIZE) { block_set_size( block, flags, block_size ); block->unused_bytes = block_size - sizeof(*block) - size; @@ -782,7 +782,7 @@ static inline void shrink_used_block( SUBHEAP *subheap, struct block *block, UIN static void *allocate_large_block( HEAP *heap, DWORD flags, SIZE_T size ) { ARENA_LARGE *arena; - SIZE_T block_size = sizeof(*arena) + ROUND_SIZE( size ); + SIZE_T block_size = ROUND_SIZE( sizeof(*arena) + size, COMMIT_MASK ); LPVOID address = NULL; if (!(flags & HEAP_GROWABLE)) return NULL; @@ -1469,13 +1469,29 @@ HANDLE WINAPI RtlDestroyHeap( HANDLE heap ) return 0; } +static SIZE_T heap_get_block_size( HEAP *heap, ULONG flags, SIZE_T size ) +{ + static const ULONG padd_flags = HEAP_VALIDATE | HEAP_VALIDATE_ALL | HEAP_VALIDATE_PARAMS; + static const ULONG check_flags = HEAP_TAIL_CHECKING_ENABLED | HEAP_FREE_CHECKING_ENABLED | HEAP_CHECKING_ENABLED; + SIZE_T overhead; + + if ((flags & check_flags)) overhead = ALIGNMENT; + else overhead = sizeof(struct block); + + if ((flags & HEAP_TAIL_CHECKING_ENABLED) || RUNNING_ON_VALGRIND) overhead += ALIGNMENT; + if (flags & padd_flags) overhead += ALIGNMENT; + + if (size < ALIGNMENT) size = ALIGNMENT; + return ROUND_SIZE( size + overhead, ALIGNMENT - 1 ); +} + static NTSTATUS heap_allocate( HEAP *heap, ULONG flags, SIZE_T size, void **ret ) { SIZE_T old_block_size, block_size; struct block *block; SUBHEAP *subheap; - block_size = sizeof(*block) + ROUND_SIZE(size) + HEAP_TAIL_EXTRA_SIZE(flags); + block_size = heap_get_block_size( heap, flags, size ); if (block_size < size) return STATUS_NO_MEMORY; /* overflow */ if (block_size < HEAP_MIN_BLOCK_SIZE) block_size = HEAP_MIN_BLOCK_SIZE; @@ -1572,7 +1588,7 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size SUBHEAP *subheap; NTSTATUS status; - block_size = sizeof(*block) + ROUND_SIZE(size) + HEAP_TAIL_EXTRA_SIZE(flags); + block_size = heap_get_block_size( heap, flags, size ); if (block_size < size) return STATUS_NO_MEMORY; /* overflow */ if (block_size < HEAP_MIN_BLOCK_SIZE) block_size = HEAP_MIN_BLOCK_SIZE;
1
0
0
0
Rémi Bernon : ntdll: Remove unnecessary constants and typedefs.
by Alexandre Julliard
02 Jun '22
02 Jun '22
Module: wine Branch: master Commit: adae12e9f318ca790986014f8e89bf0f2b02da48 URL:
https://source.winehq.org/git/wine.git/?a=commit;h=adae12e9f318ca790986014f…
Author: Rémi Bernon <rbernon(a)codeweavers.com> Date: Tue May 3 22:16:45 2022 +0200 ntdll: Remove unnecessary constants and typedefs. Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com> --- dlls/ntdll/heap.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index 8c50b41cd54..59d191ed1b3 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -76,12 +76,12 @@ struct rtl_heap_entry #define ALIGNMENT (2 * sizeof(void *)) -typedef struct block +struct block { DWORD size; /* Block size; must be the first field */ DWORD magic : 24; /* Magic number */ DWORD unused_bytes : 8; /* Number of bytes in the block not used by user data (max value is HEAP_MIN_DATA_SIZE+HEAP_MIN_SHRINK_SIZE) */ -} ARENA_INUSE; +}; C_ASSERT( sizeof(struct block) == 8 ); @@ -127,7 +127,7 @@ typedef struct /* everything is aligned on 8 byte boundaries (16 for Win64) */ #define LARGE_ALIGNMENT 16 /* large blocks have stricter alignment */ -#define ARENA_OFFSET (ALIGNMENT - sizeof(ARENA_INUSE)) +#define ARENA_OFFSET (ALIGNMENT - sizeof(struct block)) #define COMMIT_MASK 0xffff /* bitmask for commit/decommit granularity */ C_ASSERT( sizeof(ARENA_LARGE) % LARGE_ALIGNMENT == 0 ); @@ -138,7 +138,7 @@ C_ASSERT( sizeof(ARENA_LARGE) % LARGE_ALIGNMENT == 0 ); /* minimum data size (without arenas) of an allocated block */ /* make sure that it's larger than a free list entry */ #define HEAP_MIN_DATA_SIZE ROUND_SIZE(2 * sizeof(struct list)) -#define HEAP_MIN_BLOCK_SIZE (HEAP_MIN_DATA_SIZE + sizeof(ARENA_INUSE)) +#define HEAP_MIN_BLOCK_SIZE (HEAP_MIN_DATA_SIZE + sizeof(struct block)) /* minimum size that must remain to shrink an allocated block */ #define HEAP_MIN_SHRINK_SIZE (HEAP_MIN_DATA_SIZE+sizeof(struct entry)) /* minimum size to start allocating large blocks */ @@ -195,7 +195,7 @@ typedef struct tagHEAP SIZE_T min_size; /* Minimum committed size */ DWORD magic; /* Magic number */ DWORD pending_pos; /* Position in pending free requests ring */ - ARENA_INUSE **pending_free; /* Ring buffer for pending free requests */ + struct block **pending_free; /* Ring buffer for pending free requests */ RTL_CRITICAL_SECTION cs; struct entry free_lists[HEAP_NB_FREE_LISTS]; SUBHEAP subheap; @@ -1528,7 +1528,7 @@ void *WINAPI DECLSPEC_HOTPATCH RtlAllocateHeap( HANDLE heap, ULONG flags, SIZE_T static NTSTATUS heap_free( HEAP *heap, void *ptr ) { - ARENA_INUSE *block; + struct block *block; SUBHEAP *subheap; if (!(block = unsafe_block_from_ptr( heap, ptr, &subheap ))) return STATUS_INVALID_PARAMETER; @@ -1716,7 +1716,7 @@ BOOLEAN WINAPI RtlUnlockHeap( HANDLE heap ) static NTSTATUS heap_size( HEAP *heap, const void *ptr, SIZE_T *size ) { - const ARENA_INUSE *block; + const struct block *block; SUBHEAP *subheap; if (!(block = unsafe_block_from_ptr( heap, ptr, &subheap ))) return STATUS_INVALID_PARAMETER;
1
0
0
0
Rémi Bernon : ntdll: Use a fixed block tail size.
by Alexandre Julliard
02 Jun '22
02 Jun '22
Module: wine Branch: master Commit: 1b23283396ad21f09deccc85b156d6b65f4dca34 URL:
https://source.winehq.org/git/wine.git/?a=commit;h=1b23283396ad21f09deccc85…
Author: Rémi Bernon <rbernon(a)codeweavers.com> Date: Wed May 4 23:39:44 2022 +0200 ntdll: Use a fixed block tail size. Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com> --- dlls/ntdll/heap.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index aec7bdc420c..8c50b41cd54 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -349,14 +349,15 @@ static inline void mark_block_free( void *ptr, SIZE_T size, DWORD flags ) } /* mark a block of memory as a tail block */ -static inline void mark_block_tail( void *ptr, SIZE_T size, DWORD flags ) +static inline void mark_block_tail( struct block *block, DWORD flags ) { + char *tail = (char *)block + block_get_size( block ) - block->unused_bytes; if (flags & HEAP_TAIL_CHECKING_ENABLED) { - valgrind_make_writable( ptr, size ); - memset( ptr, ARENA_TAIL_FILLER, size ); + valgrind_make_writable( tail, ALIGNMENT ); + memset( tail, ARENA_TAIL_FILLER, ALIGNMENT ); } - valgrind_make_noaccess( ptr, size ); + valgrind_make_noaccess( tail, ALIGNMENT ); } /* initialize contents of a newly created block of memory */ @@ -1161,7 +1162,7 @@ static BOOL validate_used_block( const SUBHEAP *subheap, const struct block *blo else if (!err && (flags & HEAP_TAIL_CHECKING_ENABLED)) { const unsigned char *tail = (unsigned char *)block + block_get_size( block ) - block->unused_bytes; - for (i = 0; !err && i < block->unused_bytes; i++) if (tail[i] != ARENA_TAIL_FILLER) err = "invalid block tail"; + for (i = 0; !err && i < ALIGNMENT; i++) if (tail[i] != ARENA_TAIL_FILLER) err = "invalid block tail"; } if (err) @@ -1328,7 +1329,7 @@ static void heap_set_debug_flags( HANDLE handle ) else { if (block_get_type( block ) == ARENA_PENDING_MAGIC) mark_block_free( block + 1, block_get_size( block ) - sizeof(*block), flags ); - else mark_block_tail( (char *)block + block_get_size( block ) - block->unused_bytes, block->unused_bytes, flags ); + else mark_block_tail( block, flags ); } } } @@ -1493,7 +1494,7 @@ static NTSTATUS heap_allocate( HEAP *heap, ULONG flags, SIZE_T size, void **ret block_set_type( block, ARENA_INUSE_MAGIC ); shrink_used_block( subheap, block, 0, old_block_size, block_size, size ); initialize_block( block + 1, size, flags ); - mark_block_tail( (char *)(block + 1) + size, block->unused_bytes, flags ); + mark_block_tail( block, flags ); *ret = block + 1; return STATUS_SUCCESS; @@ -1614,7 +1615,7 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size shrink_used_block( subheap, block, block_get_flags( block ), old_block_size, block_size, size ); if (size > old_size) initialize_block( (char *)(block + 1) + old_size, size - old_size, flags ); - mark_block_tail( (char *)(block + 1) + size, block->unused_bytes, flags ); + mark_block_tail( block, flags ); /* Return the new arena */
1
0
0
0
Rémi Bernon : ntdll: Call mark_block_tail outside of initialize_block.
by Alexandre Julliard
02 Jun '22
02 Jun '22
Module: wine Branch: master Commit: 36d32eb8fa2035559f0ce552348de9ece2dbc99d URL:
https://source.winehq.org/git/wine.git/?a=commit;h=36d32eb8fa2035559f0ce552…
Author: Rémi Bernon <rbernon(a)codeweavers.com> Date: Mon May 30 22:28:28 2022 +0200 ntdll: Call mark_block_tail outside of initialize_block. Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com> --- dlls/ntdll/heap.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index f03d0ad4a53..aec7bdc420c 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -360,7 +360,7 @@ static inline void mark_block_tail( void *ptr, SIZE_T size, DWORD flags ) } /* initialize contents of a newly created block of memory */ -static inline void initialize_block( void *ptr, SIZE_T size, SIZE_T unused, DWORD flags ) +static inline void initialize_block( void *ptr, SIZE_T size, DWORD flags ) { if (flags & HEAP_ZERO_MEMORY) { @@ -372,8 +372,6 @@ static inline void initialize_block( void *ptr, SIZE_T size, SIZE_T unused, DWOR valgrind_make_writable( ptr, size ); memset( ptr, ARENA_INUSE_FILLER, size ); } - - mark_block_tail( (char *)ptr + size, unused, flags ); } /* notify that a new block of memory has been allocated for debugging purposes */ @@ -833,7 +831,7 @@ static void *realloc_large_block( HEAP *heap, DWORD flags, void *ptr, SIZE_T siz { /* FIXME: we could remap zero-pages instead */ valgrind_notify_resize( arena + 1, old_size, size ); - if (size > old_size) initialize_block( (char *)ptr + old_size, size - old_size, 0, flags ); + if (size > old_size) initialize_block( (char *)ptr + old_size, size - old_size, flags ); arena->data_size = size; valgrind_make_noaccess( (char *)arena + sizeof(*arena) + arena->data_size, arena->block_size - sizeof(*arena) - arena->data_size ); @@ -1494,7 +1492,8 @@ static NTSTATUS heap_allocate( HEAP *heap, ULONG flags, SIZE_T size, void **ret block_set_type( block, ARENA_INUSE_MAGIC ); shrink_used_block( subheap, block, 0, old_block_size, block_size, size ); - initialize_block( block + 1, size, block->unused_bytes, flags ); + initialize_block( block + 1, size, flags ); + mark_block_tail( (char *)(block + 1) + size, block->unused_bytes, flags ); *ret = block + 1; return STATUS_SUCCESS; @@ -1614,8 +1613,8 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size valgrind_notify_resize( block + 1, old_size, size ); shrink_used_block( subheap, block, block_get_flags( block ), old_block_size, block_size, size ); - if (size <= old_size) mark_block_tail( (char *)(block + 1) + size, block->unused_bytes, flags ); - else initialize_block( (char *)(block + 1) + old_size, size - old_size, block->unused_bytes, flags ); + if (size > old_size) initialize_block( (char *)(block + 1) + old_size, size - old_size, flags ); + mark_block_tail( (char *)(block + 1) + size, block->unused_bytes, flags ); /* Return the new arena */
1
0
0
0
← Newer
1
...
72
73
74
75
76
77
78
79
80
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Results per page:
10
25
50
100
200