dokany icon indicating copy to clipboard operation
dokany copied to clipboard

re-define all structures in x86/×64 compatible style

Open mccoysc opened this issue 7 years ago • 10 comments

I think it's time to re-definetion all structurs in x86/x64 compatible style: more and more issues caused by this matter. And the definetions should follow the following manners: 1,all data type in structures should be in static size either in x86 or x64. 2,all data type in structures should be large enough to hold the data-value both in x86 and x64(__int64 intead of pointers types ,for it can hold 32bit pointer and 64bit pointer). 3,assign operation should be careful for value-extending.for example: ptr32Value=0xffffffff; And _int64Value=ptr32Value. And in fact at this time,int64Value== 0xffffffffffffffff.it's the result of value-extending. the right way for the operating should be: (*__int64)&_int64Value=0x00000000ffffffff&ptr32Value;

mccoysc avatar Feb 05 '18 13:02 mccoysc

4,all structures should be aliganed by same count(8,etc)

mccoysc avatar Feb 05 '18 13:02 mccoysc

Hi @mccoysc ,

Thats right and this should have been reviewed 😢 All structures shared between the library and kernel are in https://github.com/dokan-dev/dokany/blob/master/sys/public.h if you would like to review them.

I have print all size of the structs for x86/x64

  printf("DOKAN_CONTROL %u\n", sizeof(DOKAN_CONTROL));
  printf("DOKAN_LINK_INFORMATION %u\n", sizeof(DOKAN_LINK_INFORMATION));
  printf("DOKAN_RENAME_INFORMATION %u\n", sizeof(DOKAN_RENAME_INFORMATION));
  printf("EVENT_START %u\n", sizeof(EVENT_START));
  printf("EVENT_DRIVER_INFO %u\n", sizeof(EVENT_DRIVER_INFO));
  printf("EVENT_INFORMATION %u\n", sizeof(EVENT_INFORMATION));
  printf("EVENT_CONTEXT %u\n", sizeof(EVENT_CONTEXT));
  printf("SET_SECURITY_CONTEXT %u\n", sizeof(SET_SECURITY_CONTEXT));
  printf("SECURITY_CONTEXT %u\n", sizeof(SECURITY_CONTEXT));
  printf("UNMOUNT_CONTEXT %u\n", sizeof(UNMOUNT_CONTEXT));
  printf("FLUSH_CONTEXT %u\n", sizeof(FLUSH_CONTEXT));
  printf("LOCK_CONTEXT %u\n", sizeof(LOCK_CONTEXT));
  printf("VOLUME_CONTEXT %u\n", sizeof(VOLUME_CONTEXT));
  printf("SETFILE_CONTEXT %u\n", sizeof(SETFILE_CONTEXT));
  printf("FILEINFO_CONTEXT %u\n", sizeof(FILEINFO_CONTEXT));
  printf("WRITE_CONTEXT %u\n", sizeof(WRITE_CONTEXT));
  printf("READ_CONTEXT %u\n", sizeof(READ_CONTEXT));
  printf("DIRECTORY_CONTEXT %u\n", sizeof(DIRECTORY_CONTEXT));
  printf("CLOSE_CONTEXT %u\n", sizeof(CLOSE_CONTEXT));
  printf("CLEANUP_CONTEXT %u\n", sizeof(CLEANUP_CONTEXT));
  printf("CREATE_CONTEXT %u\n", sizeof(CREATE_CONTEXT));
  printf("DOKAN_IO_SECURITY_CONTEXT %u\n", sizeof(DOKAN_IO_SECURITY_CONTEXT));
  printf("DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE %u\n", sizeof(DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE));
  printf("DOKAN_ACCESS_STATE %u\n", sizeof(DOKAN_ACCESS_STATE));
  printf("DOKAN_ACCESS_STATE_INTERMEDIATE %u\n", sizeof(DOKAN_ACCESS_STATE_INTERMEDIATE));
  printf("DOKAN_UNICODE_STRING_INTERMEDIATE %u\n", sizeof(DOKAN_UNICODE_STRING_INTERMEDIATE));

Result:

Struct x86 x64
DOKAN_CONTROL 800 800
DOKAN_LINK_INFORMATION 12 12
DOKAN_RENAME_INFORMATION 12 12
EVENT_START 664 664
EVENT_DRIVER_INFO 144 144
EVENT_INFORMATION 48 48
EVENT_CONTEXT 176 176
SET_SECURITY_CONTEXT 20 20
SECURITY_CONTEXT 16 16
UNMOUNT_CONTEXT 132 132
FLUSH_CONTEXT 8 8
LOCK_CONTEXT 32 32
VOLUME_CONTEXT 8 8
SETFILE_CONTEXT 20 20
FILEINFO_CONTEXT 16 16
WRITE_CONTEXT 32 32
READ_CONTEXT 24 24
DIRECTORY_CONTEXT 28 28
CLOSE_CONTEXT 8 8
CLEANUP_CONTEXT 8 8
CREATE_CONTEXT 56 56
DOKAN_IO_SECURITY_CONTEXT 44 72
DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE 36 36
DOKAN_ACCESS_STATE 40 64
DOKAN_ACCESS_STATE_INTERMEDIATE 32 32
DOKAN_UNICODE_STRING_INTERMEDIATE 6 6

Only DOKAN_IO_SECURITY_CONTEXT and DOKAN_ACCESS_STATE have different sizes.

The issue here is that we cannot break API, if changes would break API, we need to do it for the v2. See https://github.com/dokan-dev/dokany/blob/Corillian-asyncio/sys/public.h#L345-L349 in the V2 branch that already fix one of the issues.

Liryna avatar Feb 25 '18 13:02 Liryna

size is one part of many issues……for example,2 structures have same suze but may be different in field offset and so on.

On Feb 25, 2018, at 21:49, Liryna [email protected] wrote:

Hi @mccoysc ,

Thats right and this should have been reviewed 😢 All structures shared between the library and kernel are in https://github.com/dokan-dev/dokany/blob/master/sys/public.h if you would like to review them.

I have print all size of the structs for x86/x64

printf("DOKAN_CONTROL %u\n", sizeof(DOKAN_CONTROL)); printf("DOKAN_LINK_INFORMATION %u\n", sizeof(DOKAN_LINK_INFORMATION)); printf("DOKAN_RENAME_INFORMATION %u\n", sizeof(DOKAN_RENAME_INFORMATION)); printf("EVENT_START %u\n", sizeof(EVENT_START)); printf("EVENT_DRIVER_INFO %u\n", sizeof(EVENT_DRIVER_INFO)); printf("EVENT_INFORMATION %u\n", sizeof(EVENT_INFORMATION)); printf("EVENT_CONTEXT %u\n", sizeof(EVENT_CONTEXT)); printf("SET_SECURITY_CONTEXT %u\n", sizeof(SET_SECURITY_CONTEXT)); printf("SECURITY_CONTEXT %u\n", sizeof(SECURITY_CONTEXT)); printf("UNMOUNT_CONTEXT %u\n", sizeof(UNMOUNT_CONTEXT)); printf("FLUSH_CONTEXT %u\n", sizeof(FLUSH_CONTEXT)); printf("LOCK_CONTEXT %u\n", sizeof(LOCK_CONTEXT)); printf("VOLUME_CONTEXT %u\n", sizeof(VOLUME_CONTEXT)); printf("SETFILE_CONTEXT %u\n", sizeof(SETFILE_CONTEXT)); printf("FILEINFO_CONTEXT %u\n", sizeof(FILEINFO_CONTEXT)); printf("WRITE_CONTEXT %u\n", sizeof(WRITE_CONTEXT)); printf("READ_CONTEXT %u\n", sizeof(READ_CONTEXT)); printf("DIRECTORY_CONTEXT %u\n", sizeof(DIRECTORY_CONTEXT)); printf("CLOSE_CONTEXT %u\n", sizeof(CLOSE_CONTEXT)); printf("CLEANUP_CONTEXT %u\n", sizeof(CLEANUP_CONTEXT)); printf("CREATE_CONTEXT %u\n", sizeof(CREATE_CONTEXT)); printf("DOKAN_IO_SECURITY_CONTEXT %u\n", sizeof(DOKAN_IO_SECURITY_CONTEXT)); printf("DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE %u\n", sizeof(DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE)); printf("DOKAN_ACCESS_STATE %u\n", sizeof(DOKAN_ACCESS_STATE)); printf("DOKAN_ACCESS_STATE_INTERMEDIATE %u\n", sizeof(DOKAN_ACCESS_STATE_INTERMEDIATE)); printf("DOKAN_UNICODE_STRING_INTERMEDIATE %u\n", sizeof(DOKAN_UNICODE_STRING_INTERMEDIATE)); Result:

Struct x86 x64 DOKAN_CONTROL 800 800 DOKAN_LINK_INFORMATION 12 12 DOKAN_RENAME_INFORMATION 12 12 EVENT_START 664 664 EVENT_DRIVER_INFO 144 144 EVENT_INFORMATION 48 48 EVENT_CONTEXT 176 176 SET_SECURITY_CONTEXT 20 20 SECURITY_CONTEXT 16 16 UNMOUNT_CONTEXT 132 132 FLUSH_CONTEXT 8 8 LOCK_CONTEXT 32 32 VOLUME_CONTEXT 8 8 SETFILE_CONTEXT 20 20 FILEINFO_CONTEXT 16 16 WRITE_CONTEXT 32 32 READ_CONTEXT 24 24 DIRECTORY_CONTEXT 28 28 CLOSE_CONTEXT 8 8 CLEANUP_CONTEXT 8 8 CREATE_CONTEXT 56 56 DOKAN_IO_SECURITY_CONTEXT 44 72 DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE 36 36 DOKAN_ACCESS_STATE 40 64 DOKAN_ACCESS_STATE_INTERMEDIATE 32 32 DOKAN_UNICODE_STRING_INTERMEDIATE 6 6 Only DOKAN_IO_SECURITY_CONTEXT and DOKAN_ACCESS_STATE have different sizes.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

mccoysc avatar Feb 25 '18 13:02 mccoysc

Yes ofc, like DOKAN_ACCESS_STATE is a member of DOKAN_IO_SECURITY_CONTEXT. If you can review the Corillian-asyncio branch it would be highly appreciated 👍

Liryna avatar Feb 25 '18 13:02 Liryna

Ok,i'll give a x86/×64 compatible .h file,maybe in next end of a week

On Feb 25, 2018, at 21:57, Liryna [email protected] wrote:

Yes ofc, like DOKAN_ACCESS_STATE is a member of DOKAN_IO_SECURITY_CONTEXT. If you can review the Corillian-asyncio branch it would be highly appreciated 👍

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

mccoysc avatar Feb 25 '18 14:02 mccoysc

and may be another way: user can't load dll directly,instead,you write a COM exe(called out-process COM) and export COM interface for dokan users.and the COM exe is in native mode(x64 exe on x64 os and x86 exe on x86 os ). user can use x86 exe to intetactive with your x64 COM interface and no the current issues.

On Feb 25, 2018, at 21:57, Liryna [email protected] wrote:

Yes ofc, like DOKAN_ACCESS_STATE is a member of DOKAN_IO_SECURITY_CONTEXT. If you can review the Corillian-asyncio branch it would be highly appreciated 👍

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

mccoysc avatar Feb 25 '18 14:02 mccoysc

the library is also used for msys2 & cygwin, COM will not be an option here 😞

Liryna avatar Feb 25 '18 14:02 Liryna

and...en...you can also support dokan.dll with the same apis,but,the low-level code is changed: for example: dokan.dll export an API called initDokan(),may be now you call DeviceIoControl to interactive with kernel,but instead,you interactive with your com interface. so,users include msys and cygwin can still use dokan.dll with no change.

On Feb 25, 2018, at 22:31, Liryna [email protected] wrote:

the library is also used for msys2 & cygwin, COM will not be an option here 😞

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

mccoysc avatar Feb 25 '18 14:02 mccoysc

kernel<=>COM<=>dokan.dll(x86/x64)

On Feb 25, 2018, at 22:31, Liryna [email protected] wrote:

the library is also used for msys2 & cygwin, COM will not be an option here 😞

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

mccoysc avatar Feb 25 '18 14:02 mccoysc

and com can work well across network……this is the another advantage

On Feb 25, 2018, at 22:31, Liryna [email protected] wrote:

the library is also used for msys2 & cygwin, COM will not be an option here 😞

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

mccoysc avatar Feb 25 '18 14:02 mccoysc