Subversion Repositories Kolibri OS

Rev

Rev 431 | Rev 465 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 431 Rev 448
Line 1... Line 1...
1
$Revision: 431 $
1
$Revision: 448 $
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                              ;;
3
;;                                                              ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
5
;; Distributed under terms of the GNU General Public License    ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
6
;;                                                              ;;
Line 750... Line 750...
750
           xor eax, eax
750
           xor eax, eax
751
           xchg eax, [page_tabs+esi*4]
751
           xchg eax, [page_tabs+esi*4]
752
           test eax, 1
752
           test eax, 1
753
           jz @F
753
           jz @F
754
           call free_page
754
           call free_page
-
 
755
           mov eax, esi
-
 
756
           shl eax, 12
-
 
757
           invlpg [eax]
755
@@:
758
@@:
756
           inc esi
759
           inc esi
757
           dec ecx
760
           dec ecx
758
           jnz .release
761
           jnz .release
759
.not_used:
762
.not_used:
Line 762... Line 765...
762
           mov esi, dword [edx+SLOT_BASE+APPDATA.heap_base]; heap_base
765
           mov esi, dword [edx+SLOT_BASE+APPDATA.heap_base]; heap_base
763
           mov edi, dword [edx+SLOT_BASE+APPDATA.heap_top]; heap_top
766
           mov edi, dword [edx+SLOT_BASE+APPDATA.heap_top]; heap_top
764
           sub ebx, [edx+SLOT_BASE+APPDATA.mem_size]
767
           sub ebx, [edx+SLOT_BASE+APPDATA.mem_size]
765
           neg ebx
768
           neg ebx
766
           call update_mem_size
769
           call update_mem_size
-
 
770
           call user_normalize
-
 
771
           ret
-
 
772
.exit:
-
 
773
           xor eax, eax
-
 
774
           inc eax
-
 
775
           ret
-
 
776
endp
-
 
777
 
-
 
778
user_normalize:
-
 
779
; in: esi=heap_base, edi=heap_top
-
 
780
; out: eax=0 <=> OK
-
 
781
; destroys: ebx,edx,esi,edi
767
           add esi, new_app_base
782
           add esi, new_app_base
768
           add edi, new_app_base
783
           add edi, new_app_base
769
           shr esi, 12
784
           shr esi, 12
770
           shr edi, 12
785
           shr edi, 12
771
@@:
786
@@:
Line 806... Line 821...
806
           inc eax
821
           inc eax
807
           ret
822
           ret
808
.err:
823
.err:
809
           xor eax, eax
824
           xor eax, eax
810
           ret
825
           ret
-
 
826
 
-
 
827
user_realloc:
-
 
828
; in: eax = pointer, ebx = new size
-
 
829
; out: eax = new pointer or NULL
-
 
830
        test    eax, eax
-
 
831
        jnz     @f
-
 
832
; realloc(NULL,sz) - same as malloc(sz)
-
 
833
        push    ebx
-
 
834
        call    user_alloc
-
 
835
        ret
-
 
836
@@:
-
 
837
        push    ecx edx
-
 
838
        lea     ecx, [eax + new_app_base - 0x1000]
-
 
839
        shr     ecx, 12
-
 
840
        mov     edx, [page_tabs+ecx*4]
-
 
841
        test    edx, USED_BLOCK
-
 
842
        jnz     @f
-
 
843
; attempt to realloc invalid pointer
811
endp
844
.ret0:
-
 
845
        pop     edx ecx
-
 
846
        xor     eax, eax
-
 
847
        ret
-
 
848
@@:
-
 
849
        add     ebx, 0x1FFF
-
 
850
        shr     edx, 12
-
 
851
        shr     ebx, 12
-
 
852
; edx = allocated size, ebx = new size
-
 
853
        add     edx, ecx
-
 
854
        add     ebx, ecx
-
 
855
        cmp     edx, ebx
-
 
856
        jb      .realloc_add
-
 
857
; release part of allocated memory
-
 
858
.loop:
-
 
859
        cmp     edx, ebx
-
 
860
        jz      .release_done
-
 
861
        dec     edx
-
 
862
        xor     eax, eax
-
 
863
        xchg    eax, [page_tabs+edx*4]
-
 
864
        test    al, 1
-
 
865
        jz      .loop
-
 
866
        call    free_page
-
 
867
        mov     eax, edx
-
 
868
        shl     eax, 12
-
 
869
        invlpg  [eax]
-
 
870
        jmp     .loop
-
 
871
.release_done:
-
 
872
        sub     ebx, ecx
-
 
873
        cmp     ebx, 1
-
 
874
        jnz     .nofreeall
-
 
875
        mov     eax, [page_tabs+ecx*4]
-
 
876
        and     eax, not 0xFFF
-
 
877
        mov     edx, [CURRENT_TASK]
-
 
878
        shl     edx, 8
-
 
879
        mov     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
-
 
880
        sub     ebx, eax
-
 
881
        add     ebx, 0x1000
-
 
882
        or      al, FREE_BLOCK
-
 
883
        mov     [page_tabs+ecx*4], eax
-
 
884
        push    esi edi
-
 
885
        mov     esi, [SLOT_BASE+APPDATA.heap_base+edx]
-
 
886
        mov     edi, [SLOT_BASE+APPDATA.heap_top+edx]
-
 
887
        call    update_mem_size
-
 
888
        call    user_normalize
-
 
889
        pop     edi esi
-
 
890
        jmp     .ret0   ; all freed
-
 
891
.nofreeall:
-
 
892
        sub     edx, ecx
-
 
893
        shl     ebx, 12
-
 
894
        or      ebx, USED_BLOCK
-
 
895
        xchg    [page_tabs+ecx*4], ebx
-
 
896
        shr     ebx, 12
-
 
897
        sub     ebx, edx
-
 
898
        push    ebx ecx edx
-
 
899
        mov     edx, [CURRENT_TASK]
-
 
900
        shl     edx, 8
-
 
901
        shl     ebx, 12
-
 
902
        sub     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
-
 
903
        neg     ebx
-
 
904
        call    update_mem_size
-
 
905
        pop     edx ecx ebx
-
 
906
        lea     eax, [ecx+1-(new_app_base shr 12)]
-
 
907
        shl     eax, 12
-
 
908
        push    eax
-
 
909
        add     ecx, ebx
-
 
910
        add     edx, ecx
-
 
911
        shl     ebx, 12
-
 
912
        jz      .ret
-
 
913
        push    esi
-
 
914
        mov     esi, [CURRENT_TASK]
-
 
915
        shl     esi, 8
-
 
916
        mov     esi, [SLOT_BASE+APPDATA.heap_top+esi]
-
 
917
        shr     esi, 12
-
 
918
@@:
-
 
919
        cmp     edx, esi
-
 
920
        jae     .merge_done
-
 
921
        mov     eax, [page_tabs+edx*4]
-
 
922
        test    al, USED_BLOCK
-
 
923
        jz      .merge_done
-
 
924
        and     dword [page_tabs+edx*4], 0
-
 
925
        and     eax, not 0xFFF
-
 
926
        add     ebx, eax
-
 
927
        add     edx, eax
-
 
928
        jmp     @b
-
 
929
.merge_done:
-
 
930
        pop     esi
-
 
931
        or      ebx, FREE_BLOCK
-
 
932
        mov     [page_tabs+ecx*4], ebx
-
 
933
.ret:
-
 
934
        pop     eax edx ecx
-
 
935
        ret
-
 
936
.realloc_add:
-
 
937
; get some additional memory
-
 
938
        mov     eax, [CURRENT_TASK]
-
 
939
        shl     eax, 8
-
 
940
        mov     eax, [SLOT_BASE+APPDATA.heap_top+eax]
-
 
941
        add     eax, new_app_base
-
 
942
        shr     eax, 12
-
 
943
        cmp     edx, eax
-
 
944
        jae     .cant_inplace
-
 
945
        mov     eax, [page_tabs+edx*4]
-
 
946
        shr     eax, 12
-
 
947
        add     eax, edx
-
 
948
        cmp     eax, ebx
-
 
949
        jb      .cant_inplace
-
 
950
        sub     eax, ebx
-
 
951
        jz      @f
-
 
952
        shl     eax, 12
-
 
953
        or      al, FREE_BLOCK
-
 
954
        mov     [page_tabs+ebx*4], eax
-
 
955
@@:
-
 
956
        mov     eax, ebx
-
 
957
        sub     eax, ecx
-
 
958
        shl     eax, 12
-
 
959
        or      al, USED_BLOCK
-
 
960
        mov     [page_tabs+ecx*4], eax
-
 
961
        lea     eax, [ecx+1-(new_app_base shr 12)]
-
 
962
        shl     eax, 12
-
 
963
        push    eax
-
 
964
        push    edi
-
 
965
        lea     edi, [page_tabs+edx*4]
-
 
966
        mov     eax, 2
-
 
967
        sub     ebx, edx
-
 
968
        mov     ecx, ebx
-
 
969
        cld
-
 
970
        rep     stosd
-
 
971
        pop     edi
-
 
972
        mov     edx, [CURRENT_TASK]
-
 
973
        shl     edx, 8
-
 
974
        shl     ebx, 12
-
 
975
        add     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
-
 
976
        call    update_mem_size
-
 
977
        pop     eax edx ecx
-
 
978
        ret
-
 
979
.cant_inplace:
-
 
980
        push    esi edi
-
 
981
        mov     eax, [CURRENT_TASK]
-
 
982
        shl     eax, 8
-
 
983
        mov     esi, [SLOT_BASE+APPDATA.heap_base+eax]
-
 
984
        mov     edi, [SLOT_BASE+APPDATA.heap_top+eax]
-
 
985
        add     esi, new_app_base
-
 
986
        add     edi, new_app_base
-
 
987
        shr     esi, 12
-
 
988
        shr     edi, 12
-
 
989
        sub     ebx, ecx
-
 
990
.find_place:
-
 
991
        cmp     esi, edi
-
 
992
        jae     .place_not_found
-
 
993
        mov     eax, [page_tabs+esi*4]
-
 
994
        test    al, FREE_BLOCK
-
 
995
        jz      .next_place
-
 
996
        shr     eax, 12
-
 
997
        cmp     eax, ebx
-
 
998
        jae     .place_found
-
 
999
        add     esi, eax
-
 
1000
        jmp     .find_place
-
 
1001
.next_place:
-
 
1002
        shr     eax, 12
-
 
1003
        add     esi, eax
-
 
1004
        jmp     .find_place
-
 
1005
.place_not_found:
-
 
1006
        pop     edi esi
-
 
1007
        jmp     .ret0
-
 
1008
.place_found:
-
 
1009
        sub     eax, ebx
-
 
1010
        jz      @f
-
 
1011
        push    esi
-
 
1012
        add     esi, eax
-
 
1013
        shl     eax, 12
-
 
1014
        or      al, FREE_BLOCK
-
 
1015
        mov     [page_tabs+esi*4], eax
-
 
1016
        pop     esi
-
 
1017
@@:
-
 
1018
        mov     eax, ebx
-
 
1019
        shl     eax, 12
-
 
1020
        or      al, USED_BLOCK
-
 
1021
        mov     [page_tabs+esi*4], eax
-
 
1022
        inc     esi
-
 
1023
        mov     eax, esi
-
 
1024
        shl     eax, 12
-
 
1025
        sub     eax, new_app_base
-
 
1026
        push    eax
-
 
1027
        mov     eax, [page_tabs+ecx*4]
-
 
1028
        and     eax, not 0xFFF
-
 
1029
        or      al, FREE_BLOCK
-
 
1030
        sub     edx, ecx
-
 
1031
        mov     [page_tabs+ecx*4], eax
-
 
1032
        inc     ecx
-
 
1033
@@:
-
 
1034
        xor     eax, eax
-
 
1035
        xchg    eax, [page_tabs+ecx*4]
-
 
1036
        mov     [page_tabs+esi*4], eax
-
 
1037
	mov     eax, ecx
-
 
1038
	shl     eax, 12
-
 
1039
	invlpg  [eax]
-
 
1040
        inc     ecx
-
 
1041
        inc     esi
-
 
1042
        dec     ebx
-
 
1043
        dec     edx
-
 
1044
        jnz     @b
-
 
1045
        push    ebx
-
 
1046
        mov     edx, [CURRENT_TASK]
-
 
1047
        shl     edx, 8
-
 
1048
        shl     ebx, 12
-
 
1049
        add     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
-
 
1050
        call    update_mem_size
-
 
1051
        pop     ebx
-
 
1052
@@:
-
 
1053
        mov     dword [page_tabs+esi*4], 2
-
 
1054
        inc     esi
-
 
1055
        dec     ebx
-
 
1056
        jnz     @b
-
 
1057
        pop     eax edi esi edx ecx
-
 
1058
        ret
Line 812... Line 1059...
812
 
1059
 
813
if 0
1060
if 0
814
align 4
1061
align 4
815
proc alloc_dll
1062
proc alloc_dll