flat assembler
Message board for the users of flat assembler.
Index
> Windows > Weird QueryPerformanceFrequency Error |
Author |
|
windwakr 12 Oct 2009, 18:32
Haven't looked at it, but I believe the return for the function needs to be aligned by 4 for the "Query" functions.
|
|||
12 Oct 2009, 18:32 |
|
revolution 12 Oct 2009, 18:48
IIRC the qwords should be align by 8.
|
|||
12 Oct 2009, 18:48 |
|
windwakr 12 Oct 2009, 18:50
I found this:
http://board.flatassembler.net/topic.php?t=9376 |
|||
12 Oct 2009, 18:50 |
|
pal 12 Oct 2009, 18:53
revolution: Do you mean like:
Code:
lpTime dq ?
lpFrequency dq ?
lpStart dq ?
lpStop dq ?
align 8
If so then that doesn't work. I also tried with the aligns in between each variable. I also tried putting it before. (Sorry I haven't had to use align x before). I also tried putting align 4 and align 8 after the call to QPF but that didn't do anything either, if that is what you meant me to do. |
|||
12 Oct 2009, 18:53 |
|
revolution 12 Oct 2009, 18:54
The align should be before the dq's
|
|||
12 Oct 2009, 18:54 |
|
pal 12 Oct 2009, 18:56
Yeah I tried that too:
Code:
align 8
lpTime dq ?
lpFrequency dq ?
lpStart dq ?
lpStop dq ?
|
|||
12 Oct 2009, 18:56 |
|
pal 12 Oct 2009, 18:58
Weird, OK it is working now. I put all of the variables into a .data section instead of having them in the .idata section.
Is that normal? I did still need the align 8 though. |
|||
12 Oct 2009, 18:58 |
|
LocoDelAssembly 12 Oct 2009, 18:59
pal, try again, you probably put "align 8" before lMultiplier but you must put it above lpTime.
[edit]Also, add a separate section for data (it worked for me without this fix but it is still wrong not doing it), you are currently using the import section for more purposes than intended. You can also define just a data section and then use the "data import" directive inside the section.[/edit] |
|||
12 Oct 2009, 18:59 |
|
pal 12 Oct 2009, 19:04
Loco: I got it fixed, but cheers :p
Any ideas why it had to be in its own (well with the rest of the 'variables') .data section rather than .idata. I have never had this problem before. Do C/C++ compilers automatically align the data as I tried the code in C++ and it worked fine. |
|||
12 Oct 2009, 19:04 |
|
revolution 12 Oct 2009, 19:13
There is nothing special about the import section, it is just another data section that happens to contain the imports.
Most HLL compilers will always align data to "natural" boundaries. This is standard good programming practice. |
|||
12 Oct 2009, 19:13 |
|
revolution 12 Oct 2009, 19:20
One way of making sure all data is aligned without putting in oodles of align's is to order all the data top-down.
Code: align 16 ;our one and only align xmm_value_1 dq ?,? ... xmm_value_n dq ?,? quad_value_1 dq ? ;guaranteed aligned by 8 ... quad_value_n dq ? dword_value_1 dd ? ;guaranteed aligned by 4 ... dword_value_n dd ? word_value_1 dw ? ;guaranteed aligned by 2 ... word_value_n dw ? byte_value_1 db ? ;guaranteed aligned no matter what ... byte_value_n db ? |
|||
12 Oct 2009, 19:20 |
|
LocoDelAssembly 12 Oct 2009, 19:28
pal, sorry, I didn't see your second post
It was the alignment thing the problem here, using a data section is just to be safe. Your C/C++ compiler probably aligned your variables because of the optimization settings, but I think I have read in some forum (or blog) about problems with this functions even with C/C++. I don't know how it is possible that Microsoft does not document the alignment requirement for this functions... PS: Hey, here I found something: http://bobmoore.mvps.org/Win32/w32tip75.htm |
|||
12 Oct 2009, 19:28 |
|
LocoDelAssembly 12 Oct 2009, 19:34
revolution, but he is marking the entire section as the import table that way, the spec really states that it is OK doing so? What would be OK is this:
Code: section '.data' readable writeable data import library MSCVRT,'MSVCRT.DLL',\ KERNEL,'KERNEL32.DLL',\ USER,'USER32.DLL' import USER,\ MessageBox,'MessageBoxA' import MSCVRT,\ printf,'printf' import KERNEL,\ QueryPerformanceCounter,'QueryPerformanceCounter',\ QueryPerformanceFrequency,'QueryPerformanceFrequency' end data align 8 lpTime dq ? lpFrequency dq ? lpStart dq ? lpStop dq ? lMultiplier dw 10000 szTime db "Time taken: %Lf",0 szStringOne db 'Hello',0 szStringTwo db 'Hello',0 |
|||
12 Oct 2009, 19:34 |
|
revolution 12 Oct 2009, 19:37
As long as the imports start at offset 0 in the import section then there is no restriction upon the length of that section, so you can put as much data following the imports in there as you please. Windows has no way of "knowing" that the data is not needed for the imports.
|
|||
12 Oct 2009, 19:37 |
|
LocoDelAssembly 12 Oct 2009, 20:02
Quote:
But, are you saying this because it is actually documented as you describe or it is just common sense that could be proven wrong in the future? |
|||
12 Oct 2009, 20:02 |
|
revolution 12 Oct 2009, 20:10
Windows can't validate the imports in the way you suggest since the imports can be formatted in so many different ways. You could put all the function name strings at the end if you wanted to. Windows won't try to validate that you have not sneaked in some naughty data structures in between various bits.
|
|||
12 Oct 2009, 20:10 |
|
pal 12 Oct 2009, 20:25
Cheers for all the help. I am still confused as to why it worked when I added some other APIs, I guess it just did something to the alignment...
That is a good idea revolution about putting the larger variables at the top by the way. Cheers, pal. |
|||
12 Oct 2009, 20:25 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.