Rev 4432 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4432 | Rev 4434 | ||
---|---|---|---|
Line 556... | Line 556... | ||
556 | restore block_list |
556 | restore block_list |
557 | restore block_base |
557 | restore block_base |
558 | restore block_size |
558 | restore block_size |
559 | restore block_flags |
559 | restore block_flags |
Line 560... | Line 560... | ||
560 | 560 | ||
Line 561... | Line 561... | ||
561 | ;;;;;;;;;;;;;; USER ;;;;;;;;;;;;;;;;; |
561 | ;;;;;;;;;;;;;; USER HEAP ;;;;;;;;;;;;;;;;; |
Line 562... | Line 562... | ||
562 | 562 | ||
563 | HEAP_TOP equ 0x80000000 |
563 | HEAP_TOP equ 0x80000000 |
Line 571... | Line 571... | ||
571 | jz @F |
571 | jz @F |
572 | sub eax, [ebx+PROC.heap_base] |
572 | sub eax, [ebx+PROC.heap_base] |
573 | sub eax, PAGE_SIZE |
573 | sub eax, PAGE_SIZE |
574 | ret |
574 | ret |
575 | @@: |
575 | @@: |
- | 576 | lea ecx, [ebx+PROC.heap_lock] |
|
- | 577 | call mutex_init |
|
- | 578 | ||
576 | mov esi, [ebx+PROC.mem_used] |
579 | mov esi, [ebx+PROC.mem_used] |
577 | add esi, 4095 |
580 | add esi, 4095 |
578 | and esi, not 4095 |
581 | and esi, not 4095 |
579 | mov [ebx+PROC.mem_used], esi |
582 | mov [ebx+PROC.mem_used], esi |
580 | mov eax, HEAP_TOP |
583 | mov eax, HEAP_TOP |
Line 595... | Line 598... | ||
595 | 598 | ||
596 | push ebx |
599 | push ebx |
597 | push esi |
600 | push esi |
Line -... | Line 601... | ||
- | 601 | push edi |
|
- | 602 | ||
- | 603 | mov ebx, [current_process] |
|
- | 604 | lea ecx, [ebx+PROC.heap_lock] |
|
598 | push edi |
605 | call mutex_lock |
599 | 606 | ||
600 | mov ecx, [alloc_size] |
607 | mov ecx, [alloc_size] |
Line 601... | Line -... | ||
601 | add ecx, (4095+PAGE_SIZE) |
- | |
602 | and ecx, not 4095 |
608 | add ecx, (4095+PAGE_SIZE) |
603 | 609 | and ecx, not 4095 |
|
604 | mov ebx, [current_process] |
610 | |
605 | mov esi, dword [ebx+PROC.heap_base] ; heap_base |
611 | mov esi, dword [ebx+PROC.heap_base] ; heap_base |
606 | mov edi, dword [ebx+PROC.heap_top] ; heap_top |
612 | mov edi, dword [ebx+PROC.heap_top] ; heap_top |
Line 641... | Line 647... | ||
641 | mov ebx, [alloc_size] |
647 | mov ebx, [alloc_size] |
642 | add ebx, 0xFFF |
648 | add ebx, 0xFFF |
643 | and ebx, not 0xFFF |
649 | and ebx, not 0xFFF |
644 | add [edx+PROC.mem_used], ebx |
650 | add [edx+PROC.mem_used], ebx |
Line -... | Line 651... | ||
- | 651 | ||
- | 652 | lea ecx, [edx+PROC.heap_lock] |
|
- | 653 | call mutex_unlock |
|
645 | 654 | ||
Line 646... | Line 655... | ||
646 | lea eax, [esi+4096] |
655 | lea eax, [esi+4096] |
647 | 656 | ||
648 | pop edi |
657 | pop edi |
Line 656... | Line 665... | ||
656 | and eax, 0xFFFFF000 |
665 | and eax, 0xFFFFF000 |
657 | .m_next: |
666 | .m_next: |
658 | add esi, eax |
667 | add esi, eax |
659 | jmp .scan |
668 | jmp .scan |
660 | .m_exit: |
669 | .m_exit: |
- | 670 | mov ecx, [current_process] |
|
- | 671 | lea ecx, [ecx+PROC.heap_lock] |
|
- | 672 | call mutex_unlock |
|
- | 673 | ||
661 | xor eax, eax |
674 | xor eax, eax |
662 | pop edi |
675 | pop edi |
663 | pop esi |
676 | pop esi |
664 | pop ebx |
677 | pop ebx |
665 | ret |
678 | ret |
Line 671... | Line 684... | ||
671 | push ebx |
684 | push ebx |
672 | push esi |
685 | push esi |
673 | push edi |
686 | push edi |
Line 674... | Line 687... | ||
674 | 687 | ||
- | 688 | mov ebx, [current_process] |
|
- | 689 | lea ecx, [ebx+PROC.heap_lock] |
|
Line 675... | Line 690... | ||
675 | mov ebx, [current_process] |
690 | call mutex_lock |
676 | 691 | ||
677 | mov edx, [address] |
692 | mov edx, [address] |
678 | and edx, not 0xFFF |
693 | and edx, not 0xFFF |
Line 695... | Line 710... | ||
695 | cmp edx, ecx |
710 | cmp edx, ecx |
696 | jb .found |
711 | jb .found |
697 | mov esi, ecx |
712 | mov esi, ecx |
698 | jmp .scan |
713 | jmp .scan |
699 | .error: |
714 | .error: |
- | 715 | mov ecx, [current_process] |
|
- | 716 | lea ecx, [ecx+PROC.heap_lock] |
|
- | 717 | call mutex_unlock |
|
- | 718 | ||
700 | xor eax, eax |
719 | xor eax, eax |
701 | pop edi |
720 | pop edi |
702 | pop esi |
721 | pop esi |
703 | pop ebx |
722 | pop ebx |
704 | ret |
723 | ret |
Line 752... | Line 771... | ||
752 | mov ebx, [alloc_size] |
771 | mov ebx, [alloc_size] |
753 | add ebx, 0xFFF |
772 | add ebx, 0xFFF |
754 | and ebx, not 0xFFF |
773 | and ebx, not 0xFFF |
755 | add [edx+PROC.mem_used], ebx |
774 | add [edx+PROC.mem_used], ebx |
Line -... | Line 775... | ||
- | 775 | ||
- | 776 | lea ecx, [edx+PROC.heap_lock] |
|
- | 777 | call mutex_unlock |
|
756 | 778 | ||
Line 757... | Line 779... | ||
757 | mov eax, [address] |
779 | mov eax, [address] |
758 | 780 | ||
759 | pop edi |
781 | pop edi |
Line 767... | Line 789... | ||
767 | 789 | ||
Line 768... | Line 790... | ||
768 | push esi |
790 | push esi |
769 | 791 | ||
770 | mov esi, [base] |
792 | mov esi, [base] |
Line 771... | Line 793... | ||
771 | test esi, esi |
793 | test esi, esi |
Line -... | Line 794... | ||
- | 794 | jz .fail |
|
- | 795 | ||
- | 796 | push ebx |
|
- | 797 | ||
772 | jz .exit |
798 | mov ebx, [current_process] |
773 | 799 | lea ecx, [ebx+PROC.heap_lock] |
|
774 | push ebx |
800 | call mutex_lock |
775 | 801 | ||
776 | xor ebx, ebx |
802 | xor ebx, ebx |
Line 807... | Line 833... | ||
807 | 833 | ||
808 | .released: |
834 | .released: |
Line 809... | Line 835... | ||
809 | push edi |
835 | push edi |
- | 836 | ||
810 | 837 | mov edx, [current_process] |
|
811 | mov edx, [current_process] |
838 | lea ecx, [edx+PROC.heap_lock] |
812 | mov esi, dword [edx+PROC.heap_base] |
839 | mov esi, dword [edx+PROC.heap_base] |
813 | mov edi, dword [edx+PROC.heap_top] |
840 | mov edi, dword [edx+PROC.heap_top] |
814 | sub ebx, [edx+PROC.mem_used] |
841 | sub ebx, [edx+PROC.mem_used] |
815 | neg ebx |
842 | neg ebx |
816 | mov [edx+PROC.mem_used], ebx |
843 | mov [edx+PROC.mem_used], ebx |
817 | call user_normalize |
- | |
818 | pop edi |
- | |
819 | pop ebx |
- | |
820 | pop esi |
844 | call user_normalize |
- | 845 | pop edi |
|
- | 846 | .exit: |
|
821 | ret |
847 | call mutex_unlock |
822 | .exit: |
848 | |
823 | xor eax, eax |
849 | xor eax, eax |
824 | inc eax |
850 | pop ebx |
- | 851 | pop esi |
|
825 | pop esi |
852 | ret |
- | 853 | ||
- | 854 | .cantfree: |
|
- | 855 | mov ecx, [current_process] |
|
- | 856 | lea ecx, [ecx+PROC.heap_lock] |
|
826 | ret |
857 | jmp .exit |
827 | .cantfree: |
858 | .fail: |
828 | xor eax, eax |
859 | xor eax, eax |
829 | pop ebx |
860 | inc eax |
830 | pop esi |
861 | pop esi |
Line 953... | Line 984... | ||
953 | push ebx |
984 | push ebx |
954 | call user_alloc |
985 | call user_alloc |
955 | ret |
986 | ret |
956 | @@: |
987 | @@: |
957 | push ecx edx |
988 | push ecx edx |
- | 989 | ||
- | 990 | push eax |
|
- | 991 | mov ecx, [current_process] |
|
- | 992 | lea ecx, [ecx+PROC.heap_lock] |
|
- | 993 | call mutex_lock |
|
- | 994 | pop eax |
|
- | 995 | ||
958 | lea ecx, [eax - 0x1000] |
996 | lea ecx, [eax - 0x1000] |
959 | shr ecx, 12 |
997 | shr ecx, 12 |
960 | mov edx, [page_tabs+ecx*4] |
998 | mov edx, [page_tabs+ecx*4] |
961 | test dl, USED_BLOCK |
999 | test dl, USED_BLOCK |
962 | jnz @f |
1000 | jnz @f |
963 | ; attempt to realloc invalid pointer |
1001 | ; attempt to realloc invalid pointer |
964 | .ret0: |
1002 | .ret0: |
- | 1003 | mov ecx, [current_process] |
|
- | 1004 | lea ecx, [ecx+PROC.heap_lock] |
|
- | 1005 | call mutex_unlock |
|
- | 1006 | ||
965 | pop edx ecx |
1007 | pop edx ecx |
966 | xor eax, eax |
1008 | xor eax, eax |
967 | ret |
1009 | ret |
968 | @@: |
1010 | @@: |
969 | test dl, DONT_FREE_BLOCK |
1011 | test dl, DONT_FREE_BLOCK |
Line 1049... | Line 1091... | ||
1049 | .merge_done: |
1091 | .merge_done: |
1050 | pop esi |
1092 | pop esi |
1051 | or ebx, FREE_BLOCK |
1093 | or ebx, FREE_BLOCK |
1052 | mov [page_tabs+ecx*4], ebx |
1094 | mov [page_tabs+ecx*4], ebx |
1053 | .ret: |
1095 | .ret: |
- | 1096 | mov ecx, [current_process] |
|
- | 1097 | lea ecx, [ecx+PROC.heap_lock] |
|
- | 1098 | call mutex_unlock |
|
1054 | pop eax edx ecx |
1099 | pop eax edx ecx |
1055 | ret |
1100 | ret |
- | 1101 | ||
1056 | .realloc_add: |
1102 | .realloc_add: |
1057 | ; get some additional memory |
1103 | ; get some additional memory |
1058 | mov eax, [current_process] |
1104 | mov eax, [current_process] |
1059 | mov eax, [eax+PROC.heap_top] |
1105 | mov eax, [eax+PROC.heap_top] |
1060 | shr eax, 12 |
1106 | shr eax, 12 |
Line 1089... | Line 1135... | ||
1089 | rep stosd |
1135 | rep stosd |
1090 | pop edi |
1136 | pop edi |
1091 | mov edx, [current_process] |
1137 | mov edx, [current_process] |
1092 | shl ebx, 12 |
1138 | shl ebx, 12 |
1093 | add [edx+PROC.mem_used], ebx |
1139 | add [edx+PROC.mem_used], ebx |
- | 1140 | ||
- | 1141 | mov ecx, [current_process] |
|
- | 1142 | lea ecx, [ecx+PROC.heap_lock] |
|
- | 1143 | call mutex_unlock |
|
1094 | pop eax edx ecx |
1144 | pop eax edx ecx |
1095 | ret |
1145 | ret |
- | 1146 | ||
1096 | .cant_inplace: |
1147 | .cant_inplace: |
1097 | push esi edi |
1148 | push esi edi |
1098 | mov eax, [current_process] |
1149 | mov eax, [current_process] |
1099 | mov esi, [eax+PROC.heap_base] |
1150 | mov esi, [eax+PROC.heap_base] |
1100 | mov edi, [eax+PROC.heap_top] |
1151 | mov edi, [eax+PROC.heap_top] |
Line 1167... | Line 1218... | ||
1167 | @@: |
1218 | @@: |
1168 | mov dword [page_tabs+esi*4], 2 |
1219 | mov dword [page_tabs+esi*4], 2 |
1169 | inc esi |
1220 | inc esi |
1170 | dec ebx |
1221 | dec ebx |
1171 | jnz @b |
1222 | jnz @b |
- | 1223 | ||
- | 1224 | mov ecx, [current_process] |
|
- | 1225 | lea ecx, [ecx+PROC.heap_lock] |
|
- | 1226 | call mutex_unlock |
|
1172 | pop eax edi esi edx ecx |
1227 | pop eax edi esi edx ecx |
1173 | ret |
1228 | ret |