+Crash when loaded in high adress space

Bug reports will be moved here when the described bug has been fixed

Moderators: Hacker, petermad, Stefan2, white

Post Reply
peterwesterstrom
New Member
New Member
Posts: 1
Joined: 2014-02-27, 14:56 UTC

+Crash when loaded in high adress space

Post by *peterwesterstrom »

If I set the registry key
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Memory Management\AllocationPreference (DWORD)
to 0x100000

64-bit totalcomander do not start. I get a dialog "Access violation".

That usually mean there is some pointer (64-bit) that is stored in a 32-bit word and can cause a crash whenever pointer happen to be in above the 4GB point in address space.

/Peter Westerström
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6975
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Crash when loaded in high adress space

Post by *Horst.Epp »

peterwesterstrom wrote:If I set the registry key
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Memory Management\AllocationPreference (DWORD)
to 0x100000

64-bit totalcomander do not start. I get a dialog "Access violation".

That usually mean there is some pointer (64-bit) that is stored in a 32-bit word and can cause a crash whenever pointer happen to be in above the 4GB point in address space.

/Peter Westerström
There is no need in a x64 Windows for any address manipulation
to start an x64 program.
Looks like you are searching for trouble no one else has.
Sob
Power Member
Power Member
Posts: 945
Joined: 2005-01-19, 17:33 UTC

Post by *Sob »

Looks like he is searching for hidden bugs. Just because they usually don't manifest themselves, does not mean they don't exist.
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

This setting in the registry, that peterwesterstrom described, is useful during a software development. And it's normal that during software development he uses TC ;)
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Thanks for your report. I have tried to find the reason for the last several hours, without much success. It seems to happen somewhere in the handler of WM_MEASUREITEM, but probably not in my own code. The biggest problem is that the Lazarus/free pascal debugger "gdb" crashes immediately after starting any program when this switch is set.
Author of Total Commander
https://www.ghisler.com
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

The problem was indeed WM_MEASUREITEM, because it doesn't pass a window handle to the window function. Lazarus uses the WPARAM value (control ID), which is set to the memory address of the control object.

There were two bugs involved, one in Lazarus and one in Windows itself:
1. Lazarus uses SetWindowLong instead of SetWindowPtr to set the control ID.
2. Although WPARAM is 64-bit, WM_MEASUREITEM only passes the lower 32-bit of the control ID to the window function.

I have implemented a workaround now, please try it!
Author of Total Commander
https://www.ghisler.com
User avatar
Lefteous
Power Member
Power Member
Posts: 9537
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2ghisler(Author)
Although WPARAM is 64-bit, WM_MEASUREITEM only passes the lower 32-bit of the control ID to the window function.
WPARAM is defined as ctlID of MEASUREITEMSTRUCT. It is of type UINT which is clearly 32 bit. I don't see the Windows bug here. The only member of MEASUREITEMSTRUCT that can be 64 bit is itemData.
Can you explain where the 64 bit value is coming from?
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

WPARAM should be the control ID, and the control ID can be 64-bit on 64-bit Windows. The field in the struct is 32-bit only, but the WPARAM is 64-bit, so there is no reason to pass only the lower 32-bit of the 64-bit control ID.
Author of Total Commander
https://www.ghisler.com
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

The GetDlgCtrlID API function returns 32-bit integer, so control ID's are 32-bit.

This is probably for interoperability reasons - 32-bit applications can exchange CtlIDs with 64-bit applications. For the same reason, some handles, although have 64-bit size in Win64, are guaranteed not to exceed lower 32-bits.

More info here: Interprocess Communication Between 32-bit and 64-bit Applications.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Why is it then possible to set 64-bit ID with SetWindowLongPtr? Reading it back with GetWindowLongPtr works with full 64-bit.

Anyway, that's irrelevant for the current bug - can anyone try the fix?
Author of Total Commander
https://www.ghisler.com
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

I can confirm, that TC 8.51 Beta 1 64-bit raises Access Violation exceptions during the startup, and there are no AVs anymore in TC 8.51 Beta 2 64-bit.

Tested with Windows 7 64-bit.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Thanks!
Author of Total Commander
https://www.ghisler.com
Post Reply