ufrisk / MemProcFS

MemProcFS
GNU Affero General Public License v3.0
3k stars 371 forks source link

Having trouble using VMMDLL_Scatter #211

Closed lipanlp closed 1 year ago

lipanlp commented 1 year ago

Hi ufrisk! I use VMMDLL_Scatter to read the array, everything works fine when using version 5.2. But recently I upgraded to 5.8 and it has a problem. Below is the simplified reading part of the code.

float Matrix[16];
VMMDLL_Scatter_Clear(S_EntPtr, pid, VMMDLL_FLAG_NOCACHE | VMMDLL_FLAG_NOPAGING | VMMDLL_FLAG_NOCACHEPUT | VMMDLL_FLAG_NOPAGING_IO);
VMMDLL_Scatter_Prepare(S_EntPtr, adress, 64);
VMMDLL_Scatter_ExecuteRead(S_EntPtr);
VMMDLL_Scatter_Read(S_EntPtr, adress, sizeof(Matrix), (PBYTE)&Matrix, 0);

Since the upgrade, the array reads 0. After many tests, I found that changing the cb parameter of VMMDLL_Scatter_Prepare to a large value (such as 0x200) can be read normally. This problem has troubled me for a long time, I don't know how to solve it.

ufrisk commented 1 year ago

I'm not able to replicate this issue on 5.8. Does this happen all the time or just some times intermittently?

Also, this partially looks like an old issue with tiny reads which I had a workaround for in MemProcFS in earlier versions, but that I removed when I fixed the root cause.

Have you updated both leechcore.dll and vmm.dll to the most recent versions and still experience these issues?

vmm.dll = 5.8.1 leechcore.dll = v2.16.1

If you have an older leechcore.dll you'd be experiencing these issues 100% of the time for smaller reads, I just want to make sure this is not the case.

maoxian123 commented 1 year ago

I found this trouble too. I use VMMDLL_MemReadScatter for byte data[64], it return all null,but change 64 to 48,it can get the value. After many tests,when the VMMDLL_FLAG_ZEROPAD_ON_FAIL is enable,it will happen. But when i disable the VMMDLL_FLAG_ZEROPAD_ON_FAIL ,only the first 48 bytes can be read, and the remaining 16 bytes are 0.

Another question,what is the difference between VMMDLL_MemReadScatter and VMMDLL_Scatter_Read.

ufrisk commented 1 year ago

Hi,

VMMDLL_MemReadScatter is a quite complex function to use. It has rules around alignment and such that applies especially to FPGA reads. I'd recommend against using it unless you're really wanting to use it.

VMMDLL_Scatter_Read is part of the "new" much simplified scatter API which is the recommended way of doing things nowdays. Have a look in the vmm_example project for examples how to use it. The VMMDLL_Scatter_Initialize/VMMDLL_Scatter_Prepare/VMMDLL_Scatter_Execute/VMMDLL_Scatter_Read/VMMDLL_Scatter_CloseHandle which are parts of this recommended scatter API is in fact just a wrapper around the more complicated VMMDLL_MemReadScatter function.

Can you please try to use the new API and let me know if your issues persist in that one as well.

maoxian123 commented 1 year ago

I have test for VMMDLL_Scatter_Read,when the data size is more than 48 ,it will get all value with null,and the count of read bytes is 0. It only happen in some address(i.e for fpsgame's viewMatrix),other address is normal. And use VMMDLL_MemReadEx is all right.

ufrisk commented 1 year ago

Is there a pattern to the address of your failing reads? i.e. are your failed read addresses ending with 0xfc0 or larger? Or can they the failed addresses end with anything? Also I assume you called VMMDLL_Scatter_Prepare with the correct size (48) before doing Execute and Read.

Also, if you have a failed read can you successfully read the same address/size with VMMDLL_MemReadEx?

maoxian123 commented 1 year ago

Hi, I have test for one trouble addr: 0x23F9B29D578,this addr for VMMDLL_MemReadScatter when the readsize is 8 it can get value,and readsize is 12 can't get value.(with flag VMMDLL_FLAG_ZEROPAD_ON_FAIL )

And for VMMDLL_Scatter_Read ,for readsize 12 、8、4 it all can't get value.

Wish to help you to solve it,or maybe need phy addr?

ufrisk commented 1 year ago

I've resolved a bug which manifested when doing a smaller read across a 0x80 address boundary within a page.

Can you please confirm it works better now?

maoxian123 commented 1 year ago

I've resolved a bug which manifested when doing a smaller read across a 0x80 address boundary within a page.

Can you please confirm it works better now?

Yeah,now it works fine,really thanks.

ufrisk commented 1 year ago

Huge thanks for confirming it now works and for letting me know about the bug :)

Another person told me that the smaller scatter reads are now also greatly improved in speed...

maoxian123 commented 1 year ago

I found that the VMMDLL_Scatter_Read is a little faster than VMMDLL_Scatter_PrepareEx.Is there any difference between them? @ufrisk

ufrisk commented 1 year ago

@maoxian123 if you have lots of overlapping reads it may be read multiple times in VMMDLL_Scatter_PrepareEx if I remember correctly.

How much of a difference are we talking about here?