----------------------------------------------------------------------------------------
                      [BUG/PRB.] VFP 9.0 FIX - PURGE CACHED VIRTUAL MEMORY IN THE SYS(1104) FUNCTION
                                January 2024
                 ----------------------------------------------------------------------------------------
                                     CCB



1. BUG:

     If we enable purging cached virtual memory in the SYS(1104) function in Visual FoxPro Advanced,
     it will free more memory, and there is more available memory.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Label60930a ::
             cmp  dword ptr [ ebp + 12 ] , 02h                               ;0x0060930a :        837d0c02
             jne Label6093aa                                                 ;0x0060930e :        0f8596000000
             and  dword ptr [ ebp + 0FFFFD0ECh ] , 00h                       ;0x00609314 :        83a5ecd0ffff00
             lea esi ,  dword ptr [ ebx + 44 ]                               ;0x0060931b :        8d732c
             mov edi , esi                                                   ;0x0060931e :        8bfe
             call Fun529a6e                                                  ;0x00609320 :        e84907f2ff
             cmp  byte ptr [esi] , 049h                                      ;0x00609325 :        803e49
             je Label609367                                                  ;0x00609328 :        743d
             mov eax , esi                                                   ;0x0060932a :        8bc6
             call Fun42371d                                                  ;0x0060932c :        e8eca3e1ff
             mov  eax , dword ptr [ ebx + 52 ]                               ;0x00609331 :        8b4334
             inc eax                                                         ;0x00609334 :        40
             call Fun420d46                                                  ;0x00609335 :        e80c7ae1ff
             mov  eax , dword ptr [ ebx + 76 ]                               ;0x0060933a :        8b434c
             mov  eax , dword ptr [eax]                                      ;0x0060933d :        8b00
             mov  ecx , dword ptr [ ebx + 52 ]                               ;0x0060933f :        8b4b34
             mov  byte ptr [ eax + ecx ] , 00h                               ;0x00609342 :        c6040800
             mov  eax , dword ptr [ ebx + 76 ]                               ;0x00609346 :        8b434c
             mov  eax , dword ptr [eax]                                      ;0x00609349 :        8b00
             pushd 00h                                                       ;0x0060934b :        6a00
             push eax                                                        ;0x0060934d :        50
             call Fun432788                                                  ;0x0060934e :        e83594e2ff
             cmp eax , 0FFFFFFFFh                                            ;0x00609353 :        83f8ff
             je Label609375                                                  ;0x00609356 :        741d
             mov edx , eax                                                   ;0x00609358 :        8bd0
             call Fun531d42                                                  ;0x0060935a :        e8e389f2ff
             test eax , eax                                                  ;0x0060935f :        85c0
             je Label609375                                                  ;0x00609361 :        7412
             mov ecx , eax                                                   ;0x00609363 :        8bc8
             jmp Label60936a                                                 ;0x00609365 :        eb03

     Label609367 ::
             mov  ecx , dword ptr [ ebx + 56 ]                               ;0x00609367 :        8b4b38

     Label60936a ::
             call Fun421627                                                  ;0x0060936a :        e8b882e1ff
             mov  dword ptr [ ebp + 0FFFFD0ECh ] , eax                       ;0x0060936f :        8985ecd0ffff

     Label609375 ::
             mov  edi , dword ptr [ ebp + 0FFFFD0ECh ]                       ;0x00609375 :        8bbdecd0ffff
             test edi , edi                                                  ;0x0060937b :        85ff
             jne Label609389                                                 ;0x0060937d :        750a
             mov esi , 0385h                                                 ;0x0060937f :        be85030000
             call Fun452790                                                  ;0x00609384 :        e80794e4ff

     Label609389 ::
             mov  eax , dword ptr [edi]                                      ;0x00609389 :        8b07
             mov esi , 0100h                                                 ;0x0060938b :        be00010000
             test  dword ptr [ eax + 32 ] , esi                              ;0x00609390 :        857020
             jne Label6093b4                                                 ;0x00609393 :        751f
             mov  eax , dword ptr [eax]                                      ;0x00609395 :        8b00
             call Fun53b58b                                                  ;0x00609397 :        e8ef21f3ff
             test  dword ptr [ eax + 44 ] , esi                              ;0x0060939c :        85702c
             je Label6093b4                                                  ;0x0060939f :        7413
             mov esi , edi                                                   ;0x006093a1 :        8bf7
             call Fun524ba6                                                  ;0x006093a3 :        e8feb7f1ff
             jmp Label6093b4                                                 ;0x006093a8 :        eb0a

     Label6093aa ::
             mov eax , 07FFFFFFFh                                            ;0x006093aa :        b8ffffff7f
             call Fun68507b                                                  ;0x006093af :        e8c7bc0700


     ;
     ;                 -----------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - PURGE CACHED VIRTUAL MEMORY IN THE SYS(1104) FUNCTION
     ;                                  April 2021
     ;                 -----------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; Purge cached virtual memory in the SYS(1104) function.
     ;
     ; 2021/4/15, by ccb
     ;

             cmp dword ptr vfpa_sys9057_data,00h
             je Label6093b4
             ;; Purge Cached Virtual Memory
             push esi
             push ecx
             lea esi ,  dword ptr [ esp ]
             mov  dword ptr [ esp ] , 07FFFFFFFh
             call Fun7e0c91
             pop ecx
             pop esi
             IF VFPA_VERSION GE 102
             ;; Purge Cached Large Memory
             call vfpa_lmm_purgecachedmemory
             ENDIF
             IF VFPA_VERSION GE 102
             ;; Set Process Working Set Size for Large Memory
             call vfpa_lmm_setprocessworkingsetsize
             ENDIF


     Label6093b4 ::
             pushd 00h                                                       ;0x006093b4 :        6a00
             pushd 00h                                                       ;0x006093b6 :        6a00
             jmp Label4558d4                                                 ;0x006093b8 :        e917c5e4ff


4. APPLIES TO:

     VFP 6.0.8167.0
     VFP 6.0.8961.0 (SP5)

     VFP 7.0.0.9262
     VFP 7.0.0.9465 (SP1)

     VFP 8.0.0.2521
     VFP 8.0.0.3117 (SP1)

     VFP 9.0.0.2412
     VFP 9.0.0.3504 (SP1)
     VFP 9.0.0.4611 (SP2)
     VFP 9.0.0.5015 (SP2)
     VFP 9.0.0.5411 (SP2)
     VFP 9.0.0.5721 (SP2)
     VFP 9.0.0.5815 (SP2)
     VFP 9.0.0.6303 (SP2)
     VFP 9.0.0.6602 (SP2)
     VFP 9.0.0.7423 (SP2)

     The bug has been fixed in VFP Advanced.


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix166.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix168.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix169.asp


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please send me an email at ccb2000@163.com.