Need help to understand why MmProbeAndLock fails in non-debug mod e but not in kernel debug mode

Hi,

What I am trying to do is to lock about 1GB memory using MmProbeAndLock()
during process initialization. The system has 2GB memory installed. It seems
to work fine when I enable the kernel debugger, but when I run the code
without the kernel debugger, the memory lock process failed. In order to
understand why MmProbeAndLock() failed in non-kernel debug mode, I removed
__try { … …} __except(…) from MmProbeAndLock() code block and force to
cause blue screen and generate the complete dumpfile. From the dump file, I
see MmProbeAndLock() throws ERROR_WORKING_SET_QUOTA exception. Here is some
information from the dump file. Please help me to understand why this does
not happen when the kernel debugger is on. What can I do to prevent this
from happening. Thanks,

Exception: ERROR_WORKING_SET_QUOTA
Arg1: c00000a1, The exception code that was not handled
Arg2: 8051f452, The address that the exception occurred at
Arg3: ac3f4788, Trap Frame
Arg4: 00000000

kd> .trap ac3f4788
ESP EDITED! New esp=ac3f4b38
ErrCode = 00000000
eax=894b8000 ebx=c00e0b3c ecx=00000000 edx=00000000 esi=898f15d8
edi=894b8000
eip=8051f452 esp=ac3f47fc ebp=ac3f4bc0 iopl=0 nv up ei pl nz na pe
nc
cs=0000 ss=0010 ds=0023 es=0023 fs=0030 gs=0000
efl=00000202
nt!MmProbeAndLockPages+0x414:
8051f452 e96166fdff jmp nt!MmProbeAndLockPages+0x414 (804f5ab8)

kd> x MmReferenceCountCheck
kd> dd MmReferenceCountCheck
80551088 000009c4 03010218 07050705 03010218
80551098 06040604 00000001 00000001 804d7000
805510a8 0000f000 00000080 00000008 00000001
805510b8 0000000b 00000011 0000003b 0000000f
805510c8 0000000b 000000ff 000000bb ff011800
805510d8 ffffff04 ffffff05 ffffffff ff030200
805510e8 ffffff06 ffffff07 ffffffff 000003e8
805510f8 00000005 00000006 00000320 00004e20

kd> u nt!MmProbeAndLockPages+0x414
nt!MmUnlockPages+0x67:
804f5c48 c62c0100 mov byte ptr [ecx+eax],0x0
804f5c4c 008945ec8975 add [ecx+0x7589ec45],cl
804f5c52 f08b45ec lock mov eax,[ebp-0x14]
804f5c56 8b4df0 mov ecx,[ebp-0x10]
804f5c59 0fc101 xadd [ecx],eax
804f5c5c e9d8feffff jmp nt!MmUnlockPages+0x7b (804f5b39)
804f5c61 64a124010000 mov eax,fs:[00000124]
804f5c67 8b4044 mov eax,[eax+0x44]

kd> !memusage
loading PFN database
loading (100% complete)
Compiling memory usage data (99% Complete).
Zeroed: 311055 (1244220 kb)
Free: 0 ( 0 kb)
Standby: 22254 ( 89016 kb)
Modified: 746 ( 2984 kb)
ModifiedNoWrite: 0 ( 0 kb)
Active/Valid: 185829 (743316 kb)
Transition: 0 ( 0 kb)
Unknown: 0 ( 0 kb)
TOTAL: 519884 (2079536 kb)

Why do you need to lock 1GB? Any reasons?

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From:
To: “Windows System Software Devs Interest List”
Sent: Tuesday, January 18, 2005 8:23 PM
Subject: [ntdev] Need help to understand why MmProbeAndLock fails in non-debug
mod e but not in kernel debug mode

> Hi,
>
> What I am trying to do is to lock about 1GB memory using MmProbeAndLock()
> during process initialization. The system has 2GB memory installed. It seems
> to work fine when I enable the kernel debugger, but when I run the code
> without the kernel debugger, the memory lock process failed. In order to
> understand why MmProbeAndLock() failed in non-kernel debug mode, I removed
> try { … …} except(…) from MmProbeAndLock() code block and force to
> cause blue screen and generate the complete dumpfile. From the dump file, I
> see MmProbeAndLock() throws ERROR_WORKING_SET_QUOTA exception. Here is some
> information from the dump file. Please help me to understand why this does
> not happen when the kernel debugger is on. What can I do to prevent this
> from happening. Thanks,
>
> Exception: ERROR_WORKING_SET_QUOTA
> Arg1: c00000a1, The exception code that was not handled
> Arg2: 8051f452, The address that the exception occurred at
> Arg3: ac3f4788, Trap Frame
> Arg4: 00000000
>
> kd> .trap ac3f4788
> ESP EDITED! New esp=ac3f4b38
> ErrCode = 00000000
> eax=894b8000 ebx=c00e0b3c ecx=00000000 edx=00000000 esi=898f15d8
> edi=894b8000
> eip=8051f452 esp=ac3f47fc ebp=ac3f4bc0 iopl=0 nv up ei pl nz na pe
> nc
> cs=0000 ss=0010 ds=0023 es=0023 fs=0030 gs=0000
> efl=00000202
> nt!MmProbeAndLockPages+0x414:
> 8051f452 e96166fdff jmp nt!MmProbeAndLockPages+0x414 (804f5ab8)
>
>
> kd> x MmReferenceCountCheck
> kd> dd MmReferenceCountCheck
> 80551088 000009c4 03010218 07050705 03010218
> 80551098 06040604 00000001 00000001 804d7000
> 805510a8 0000f000 00000080 00000008 00000001
> 805510b8 0000000b 00000011 0000003b 0000000f
> 805510c8 0000000b 000000ff 000000bb ff011800
> 805510d8 ffffff04 ffffff05 ffffffff ff030200
> 805510e8 ffffff06 ffffff07 ffffffff 000003e8
> 805510f8 00000005 00000006 00000320 00004e20
>
>
> kd> u nt!MmProbeAndLockPages+0x414
> nt!MmUnlockPages+0x67:
> 804f5c48 c62c0100 mov byte ptr [ecx+eax],0x0
> 804f5c4c 008945ec8975 add [ecx+0x7589ec45],cl
> 804f5c52 f08b45ec lock mov eax,[ebp-0x14]
> 804f5c56 8b4df0 mov ecx,[ebp-0x10]
> 804f5c59 0fc101 xadd [ecx],eax
> 804f5c5c e9d8feffff jmp nt!MmUnlockPages+0x7b (804f5b39)
> 804f5c61 64a124010000 mov eax,fs:[00000124]
> 804f5c67 8b4044 mov eax,[eax+0x44]
>
>
> kd> !memusage
> loading PFN database
> loading (100% complete)
> Compiling memory usage data (99% Complete).
> Zeroed: 311055 (1244220 kb)
> Free: 0 ( 0 kb)
> Standby: 22254 ( 89016 kb)
> Modified: 746 ( 2984 kb)
> ModifiedNoWrite: 0 ( 0 kb)
> Active/Valid: 185829 (743316 kb)
> Transition: 0 ( 0 kb)
> Unknown: 0 ( 0 kb)
> TOTAL: 519884 (2079536 kb)
>
>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Quota’s are charged to processes. In what context are you calling
MmProbeAndLock()?

If this is arbitrary thread context the behaviour could change for many
reasons (including changing from debug to non-debug mode). You probably
want to do this in a system thread (e.g. use PsCreateSystemThread) so the
call is made under the system process. I would imagine this maximize your
quota allowance, though I don’t know if that will resolve your problem.

Resource strategies are different on workstation and server versions of the
operating system. This is more likely to work on the server version if that
is an option.

Jack.

wrote in message news:xxxxx@ntdev…
> Hi,
>
> What I am trying to do is to lock about 1GB memory using MmProbeAndLock()
> during process initialization. The system has 2GB memory installed. It
seems
> to work fine when I enable the kernel debugger, but when I run the code
> without the kernel debugger, the memory lock process failed. In order to
> understand why MmProbeAndLock() failed in non-kernel debug mode, I removed
> try { … …} except(…) from MmProbeAndLock() code block and force
to
> cause blue screen and generate the complete dumpfile. From the dump file,
I
> see MmProbeAndLock() throws ERROR_WORKING_SET_QUOTA exception. Here is
some
> information from the dump file. Please help me to understand why this does
> not happen when the kernel debugger is on. What can I do to prevent this
> from happening. Thanks,
>
> Exception: ERROR_WORKING_SET_QUOTA
> Arg1: c00000a1, The exception code that was not handled
> Arg2: 8051f452, The address that the exception occurred at
> Arg3: ac3f4788, Trap Frame
> Arg4: 00000000
>
> kd> .trap ac3f4788
> ESP EDITED! New esp=ac3f4b38
> ErrCode = 00000000
> eax=894b8000 ebx=c00e0b3c ecx=00000000 edx=00000000 esi=898f15d8
> edi=894b8000
> eip=8051f452 esp=ac3f47fc ebp=ac3f4bc0 iopl=0 nv up ei pl nz na pe
> nc
> cs=0000 ss=0010 ds=0023 es=0023 fs=0030 gs=0000
> efl=00000202
> nt!MmProbeAndLockPages+0x414:
> 8051f452 e96166fdff jmp nt!MmProbeAndLockPages+0x414 (804f5ab8)
>
>
> kd> x MmReferenceCountCheck
> kd> dd MmReferenceCountCheck
> 80551088 000009c4 03010218 07050705 03010218
> 80551098 06040604 00000001 00000001 804d7000
> 805510a8 0000f000 00000080 00000008 00000001
> 805510b8 0000000b 00000011 0000003b 0000000f
> 805510c8 0000000b 000000ff 000000bb ff011800
> 805510d8 ffffff04 ffffff05 ffffffff ff030200
> 805510e8 ffffff06 ffffff07 ffffffff 000003e8
> 805510f8 00000005 00000006 00000320 00004e20
>
>
> kd> u nt!MmProbeAndLockPages+0x414
> nt!MmUnlockPages+0x67:
> 804f5c48 c62c0100 mov byte ptr [ecx+eax],0x0
> 804f5c4c 008945ec8975 add [ecx+0x7589ec45],cl
> 804f5c52 f08b45ec lock mov eax,[ebp-0x14]
> 804f5c56 8b4df0 mov ecx,[ebp-0x10]
> 804f5c59 0fc101 xadd [ecx],eax
> 804f5c5c e9d8feffff jmp nt!MmUnlockPages+0x7b (804f5b39)
> 804f5c61 64a124010000 mov eax,fs:[00000124]
> 804f5c67 8b4044 mov eax,[eax+0x44]
>
>
> kd> !memusage
> loading PFN database
> loading (100% complete)
> Compiling memory usage data (99% Complete).
> Zeroed: 311055 (1244220 kb)
> Free: 0 ( 0 kb)
> Standby: 22254 ( 89016 kb)
> Modified: 746 ( 2984 kb)
> ModifiedNoWrite: 0 ( 0 kb)
> Active/Valid: 185829 (743316 kb)
> Transition: 0 ( 0 kb)
> Unknown: 0 ( 0 kb)
> TOTAL: 519884 (2079536 kb)
>
>
>
>
>