Subversion Repositories Kolibri OS

Rev

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

Rev 5057 Rev 5130
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 5057 $
8
$Revision: 5130 $
9
 
9
 
Line 446... Line 446...
446
        shr     edi, 10
446
        shr     edi, 10
Line 447... Line 447...
447
 
447
 
448
        bt      [cpu_caps], CAPS_PSE
448
        bt      [cpu_caps], CAPS_PSE
449
        jnc     .map_page_tables
449
        jnc     .map_page_tables
450
        or      esi, PG_LARGE+PG_UW
450
        or      esi, PG_LARGE+PG_UW
451
        mov     edx, sys_pgdir+(LFB_BASE shr 20)
451
        mov     edx, sys_proc+PROC.pdt_0+(LFB_BASE shr 20)
452
@@:
452
@@:
453
        mov     [edx], esi
453
        mov     [edx], esi
454
        add     edx, 4
454
        add     edx, 4
455
        add     esi, 0x00400000
455
        add     esi, 0x00400000
456
        dec     edi
456
        dec     edi
Line 457... Line 457...
457
        jnz     @B
457
        jnz     @B
458
 
458
 
459
        bt      [cpu_caps], CAPS_PGE
459
        bt      [cpu_caps], CAPS_PGE
460
        jnc     @F
460
        jnc     @F
461
        or      dword [sys_pgdir+(LFB_BASE shr 20)], PG_GLOBAL
461
        or      dword [sys_proc+PROC.pdt_0+(LFB_BASE shr 20)], PG_GLOBAL
462
@@:
462
@@:
463
        mov     dword [LFBAddress], LFB_BASE
463
        mov     dword [LFBAddress], LFB_BASE
464
        mov     eax, cr3      ;flush TLB
464
        mov     eax, cr3      ;flush TLB
Line 498... Line 498...
498
        push    ebx
498
        push    ebx
499
        push    esi
499
        push    esi
500
        push    edi
500
        push    edi
Line 501... Line 501...
501
 
501
 
-
 
502
        mov     edx, [current_slot]
-
 
503
        mov     ebx, [edx+APPDATA.process]
502
        mov     edx, [current_slot]
504
 
503
        cmp     [edx+APPDATA.heap_base], 0
505
        cmp     [ebx+PROC.heap_base], 0
Line 504... Line 506...
504
        jne     .exit
506
        jne     .exit
505
 
507
 
506
        mov     edi, [new_size]
508
        mov     edi, [new_size]
507
        add     edi, 4095
509
        add     edi, 4095
Line 508... Line 510...
508
        and     edi, not 4095
510
        and     edi, not 4095
509
        mov     [new_size], edi
511
        mov     [new_size], edi
510
 
512
 
Line 511... Line 513...
511
        mov     esi, [edx+APPDATA.mem_size]
513
        mov     esi, [ebx+PROC.mem_used]
512
        add     esi, 4095
514
        add     esi, 4095
Line 541... Line 543...
541
        call    mutex_unlock
543
        call    mutex_unlock
Line 542... Line 544...
542
 
544
 
543
.update_size:
545
.update_size:
544
        mov     edx, [current_slot]
546
        mov     edx, [current_slot]
-
 
547
        mov     ebx, [new_size]
545
        mov     ebx, [new_size]
548
        mov     edx, [edx+APPDATA.process]
546
        call    update_mem_size
549
        mov     [edx+PROC.mem_used], ebx
547
.exit:
550
.exit:
548
        pop     edi
551
        pop     edi
549
        pop     esi
552
        pop     esi
550
        pop     ebx
553
        pop     ebx
Line 617... Line 620...
617
        inc     eax
620
        inc     eax
618
        ret
621
        ret
619
endp
622
endp
Line 620... Line -...
620
 
-
 
621
 
-
 
622
align 4
-
 
623
update_mem_size:
-
 
624
; in: edx = slot base
-
 
625
;     ebx = new memory size
-
 
626
; destroys eax,ecx,edx
-
 
627
 
-
 
628
        mov     [APPDATA.mem_size+edx], ebx
-
 
629
;search threads and update
-
 
630
;application memory size infomation
-
 
631
        mov     ecx, [APPDATA.dir_table+edx]
-
 
632
        mov     eax, 2
-
 
633
 
-
 
634
.search_threads:
-
 
635
;eax = current slot
-
 
636
;ebx = new memory size
-
 
637
;ecx = page directory
-
 
638
        cmp     eax, [TASK_COUNT]
-
 
639
        jg      .search_threads_end
-
 
640
        mov     edx, eax
-
 
641
        shl     edx, 5
-
 
642
        cmp     word [CURRENT_TASK+edx+TASKDATA.state], 9  ;if slot empty?
-
 
643
        jz      .search_threads_next
-
 
644
        shl     edx, 3
-
 
645
        cmp     [SLOT_BASE+edx+APPDATA.dir_table], ecx      ;if it is our thread?
-
 
646
        jnz     .search_threads_next
-
 
647
        mov     [SLOT_BASE+edx+APPDATA.mem_size], ebx      ;update memory size
-
 
648
.search_threads_next:
-
 
649
        inc     eax
-
 
650
        jmp     .search_threads
-
 
651
.search_threads_end:
-
 
652
        ret
623
 
653
 
624
 
654
; param
625
; param
655
;  eax= linear address
626
;  eax= linear address
656
;
627
;
Line 705... Line 676...
705
.fail:  ;simply return to caller
676
.fail:  ;simply return to caller
706
        mov     esp, ebp
677
        mov     esp, ebp
707
        pop     ebx               ;restore exception number (#PF)
678
        pop     ebx               ;restore exception number (#PF)
708
        ret
679
        ret
Line 709... Line -...
709
 
-
 
710
;        xchg bx, bx
-
 
711
;        add     esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller
-
 
712
;        restore_ring3_context
-
 
713
;        iretd
-
 
714
 
680
 
715
.user_space:
681
.user_space:
716
        test    eax, PG_MAP
682
        test    eax, PG_MAP
717
        jnz     .err_access       ;Страница присутствует
683
        jnz     .err_access       ;Страница присутствует
Line 749... Line 715...
749
 
715
 
750
.err_access:
716
.err_access:
751
; access denied? this may be a result of copy-on-write protection for DLL
717
; access denied? this may be a result of copy-on-write protection for DLL
752
; check list of HDLLs
718
; check list of HDLLs
753
        and     ebx, not 0xFFF
719
        and     ebx, not 0xFFF
754
        mov     eax, [CURRENT_TASK]
-
 
755
        shl     eax, 8
720
        mov     eax, [current_process]
756
        mov     eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
721
        mov     eax, [eax+PROC.dlls_list_ptr]
757
        test    eax, eax
722
        test    eax, eax
758
        jz      .fail
723
        jz      .fail
759
        mov     esi, [eax+HDLL.fd]
724
        mov     esi, [eax+HDLL.fd]
760
.scan_hdll:
725
.scan_hdll:
Line 827... Line 792...
827
        rep movsd
792
        rep movsd
828
        jmp     .exit
793
        jmp     .exit
829
endp
794
endp
Line 830... Line 795...
830
 
795
 
831
; returns number of mapped bytes
796
; returns number of mapped bytes
832
proc map_mem stdcall, lin_addr:dword,slot:dword,\
797
proc map_mem_ipc stdcall, lin_addr:dword,slot:dword,\
-
 
798
                      ofs:dword,buf_size:dword,req_access:dword
833
                      ofs:dword,buf_size:dword,req_access:dword
799
        locals
-
 
800
             count   dd ?
-
 
801
             process dd ?
Line -... Line 802...
-
 
802
        endl
834
        push    0 ; initialize number of mapped bytes
803
 
835
 
804
        mov     [count], 0
Line 836... Line 805...
836
        cmp     [buf_size], 0
805
        cmp     [buf_size], 0
837
        jz      .exit
806
        jz      .exit
838
 
807
 
839
        mov     eax, [slot]
808
        mov     eax, [slot]
-
 
809
        shl     eax, 8
Line 840... Line 810...
840
        shl     eax, 8
810
        mov     eax, [SLOT_BASE+eax+APPDATA.process]
841
        mov     eax, [SLOT_BASE+eax+APPDATA.dir_table]
811
        test    eax, eax
842
        and     eax, 0xFFFFF000
812
        jz      .exit
843
 
813
 
844
        stdcall map_page, [ipc_pdir], eax, PG_UW
814
        mov     [process], eax
845
        mov     ebx, [ofs]
-
 
846
        shr     ebx, 22
815
        mov     ebx, [ofs]
847
        mov     esi, [ipc_pdir]
816
        shr     ebx, 22
848
        mov     edi, [ipc_ptab]
817
        mov     eax, [eax+PROC.pdt_0+ebx*4]                 ;get page table
849
        mov     eax, [esi+ebx*4]
-
 
850
        and     eax, 0xFFFFF000
-
 
851
        jz      .exit
-
 
852
        stdcall map_page, edi, eax, PG_UW
-
 
853
;           inc ebx
-
 
854
;           add edi, 0x1000
-
 
855
;           mov eax, [esi+ebx*4]
-
 
856
;           test eax, eax
-
 
857
;           jz @f
818
        mov     esi, [ipc_ptab]
858
;          and eax, 0xFFFFF000
819
        and     eax, 0xFFFFF000
859
;           stdcall map_page, edi, eax
820
        jz      .exit
860
 
821
        stdcall map_page, esi, eax, PG_SW
861
@@:
822
@@:
862
        mov     edi, [lin_addr]
823
        mov     edi, [lin_addr]
863
        and     edi, 0xFFFFF000
824
        and     edi, 0xFFFFF000
Line 864... Line 825...
864
        mov     ecx, [buf_size]
825
        mov     ecx, [buf_size]
865
        add     ecx, 4095
826
        add     ecx, 4095
866
        shr     ecx, 12
827
        shr     ecx, 12
867
        inc     ecx
-
 
868
 
-
 
869
        mov     edx, [ofs]
828
        inc     ecx                  ; ???????????
870
        shr     edx, 12
829
 
871
        and     edx, 0x3FF
830
        mov     edx, [ofs]
872
        mov     esi, [ipc_ptab]
831
        shr     edx, 12
873
 
832
        and     edx, 0x3FF
874
.map:
833
.map:
875
        stdcall safe_map_page, [slot], [req_access], [ofs]
834
        stdcall safe_map_page, [slot], [req_access], [ofs]
-
 
835
        jnc     .exit
876
        jnc     .exit
836
        add     [count], PAGE_SIZE
877
        add     dword [ebp-4], 4096
837
        add     [ofs], PAGE_SIZE
878
        add     [ofs], 4096
838
        dec     ecx
879
        dec     ecx
839
        jz      .exit
-
 
840
 
880
        jz      .exit
841
        add     edi, PAGE_SIZE
881
        add     edi, 0x1000
842
        inc     edx
882
        inc     edx
843
        cmp     edx, 1024
883
        cmp     edx, 0x400
844
        jnz     .map
884
        jnz     .map
845
 
-
 
846
        inc     ebx
885
        inc     ebx
847
        mov     eax, [process]
886
        mov     eax, [ipc_pdir]
848
        mov     eax, [eax+PROC.pdt_0+ebx*4]
887
        mov     eax, [eax+ebx*4]
849
        and     eax, 0xFFFFF000
888
        and     eax, 0xFFFFF000
-
 
889
        jz      .exit
850
        jz      .exit
890
        stdcall map_page, esi, eax, PG_UW
851
 
891
        xor     edx, edx
852
        stdcall map_page, esi, eax, PG_SW
892
        jmp     .map
853
        xor     edx, edx
Line 893... Line 854...
893
 
854
        jmp     .map
894
.exit:
855
.exit:
-
 
856
        mov     eax, [count]
895
        pop     eax
857
        ret
-
 
858
endp
-
 
859
 
Line -... Line 860...
-
 
860
proc map_memEx stdcall, lin_addr:dword,slot:dword,\
896
        ret
861
                        ofs:dword,buf_size:dword,req_access:dword
897
endp
862
        locals
Line 898... Line 863...
898
 
863
             count   dd ?
899
proc map_memEx stdcall, lin_addr:dword,slot:dword,\
864
             process dd ?
900
                        ofs:dword,buf_size:dword,req_access:dword
865
        endl
901
        push    0 ; initialize number of mapped bytes
866
 
-
 
867
        mov     [count], 0
Line 902... Line 868...
902
 
868
        cmp     [buf_size], 0
903
        cmp     [buf_size], 0
869
        jz      .exit
904
        jz      .exit
870
 
905
 
871
        mov     eax, [slot]
906
        mov     eax, [slot]
872
        shl     eax, 8
907
        shl     eax, 8
-
 
908
        mov     eax, [SLOT_BASE+eax+APPDATA.dir_table]
873
        mov     eax, [SLOT_BASE+eax+APPDATA.process]
909
        and     eax, 0xFFFFF000
-
 
910
 
874
        test    eax, eax
911
        stdcall map_page, [proc_mem_pdir], eax, PG_UW
875
        jz      .exit
912
        mov     ebx, [ofs]
-
 
913
        shr     ebx, 22
876
 
914
        mov     esi, [proc_mem_pdir]
877
        mov     [process], eax
915
        mov     edi, [proc_mem_tab]
878
        mov     ebx, [ofs]
916
        mov     eax, [esi+ebx*4]
879
        shr     ebx, 22
917
        and     eax, 0xFFFFF000
880
        mov     eax, [eax+PROC.pdt_0+ebx*4]                 ;get page table
918
        test    eax, eax
881
        mov     esi, [proc_mem_tab]
919
        jz      .exit
882
        and     eax, 0xFFFFF000
Line 920... Line 883...
920
        stdcall map_page, edi, eax, PG_UW
883
        jz      .exit
921
 
884
        stdcall map_page, esi, eax, PG_SW
922
@@:
885
@@:
923
        mov     edi, [lin_addr]
-
 
924
        and     edi, 0xFFFFF000
-
 
925
        mov     ecx, [buf_size]
886
        mov     edi, [lin_addr]
926
        add     ecx, 4095
887
        and     edi, 0xFFFFF000
927
        shr     ecx, 12
888
        mov     ecx, [buf_size]
928
        inc     ecx
-
 
929
 
889
        add     ecx, 4095
930
        mov     edx, [ofs]
890
        shr     ecx, 12
931
        shr     edx, 12
-
 
932
        and     edx, 0x3FF
891
        inc     ecx                  ; ???????????
-
 
892
 
-
 
893
        mov     edx, [ofs]
-
 
894
        shr     edx, 12
-
 
895
        and     edx, 0x3FF
-
 
896
.map:
933
        mov     esi, [proc_mem_tab]
897
        stdcall safe_map_page, [slot], [req_access], [ofs]
-
 
898
        jnc     .exit
-
 
899
        add     [count], PAGE_SIZE
-
 
900
        add     [ofs], PAGE_SIZE
-
 
901
        dec     ecx
-
 
902
        jz      .exit
-
 
903
 
-
 
904
        add     edi, PAGE_SIZE
-
 
905
        inc     edx
-
 
906
        cmp     edx, 1024
-
 
907
        jnz     .map
934
 
908
 
935
.map:
909
        inc     ebx
936
        stdcall safe_map_page, [slot], [req_access], [ofs]
910
        mov     eax, [process]
937
        jnc     .exit
911
        mov     eax, [eax+PROC.pdt_0+ebx*4]
Line 938... Line 912...
938
        add     dword [ebp-4], 0x1000
912
        and     eax, 0xFFFFF000
939
        add     edi, 0x1000
913
        jz      .exit
Line 986... Line 960...
986
        cli
960
        cli
987
        cld
961
        cld
988
        push    ebx ecx
962
        push    ebx ecx
989
        mov     eax, [slot]
963
        mov     eax, [slot]
990
        shl     eax, 8
964
        shl     eax, 8
991
        mov     eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
965
        mov     eax, [SLOT_BASE+eax+APPDATA.process]
-
 
966
        mov     eax, [eax+PROC.dlls_list_ptr]
992
        test    eax, eax
967
        test    eax, eax
993
        jz      .no_hdll
968
        jz      .no_hdll
994
        mov     ecx, [eax+HDLL.fd]
969
        mov     ecx, [eax+HDLL.fd]
995
.scan_hdll:
970
.scan_hdll:
996
        cmp     ecx, eax
971
        cmp     ecx, eax
Line 1073... Line 1048...
1073
@@:
1048
@@:
1074
        or      eax, -1
1049
        or      eax, -1
1075
        mov     [esp+32], eax
1050
        mov     [esp+32], eax
1076
        ret
1051
        ret
Line 1077... Line -...
1077
 
-
 
1078
;align 4
-
 
1079
;proc set_ipc_buff
-
 
1080
 
-
 
1081
;           mov  eax,[current_slot]
-
 
1082
;           pushf
-
 
1083
;           cli
-
 
1084
;           mov  [eax+APPDATA.ipc_start],ebx     ;set fields in extended information area
-
 
1085
;           mov  [eax+APPDATA.ipc_size],ecx
-
 
1086
;
-
 
1087
;           add ecx, ebx
-
 
1088
;           add ecx, 4095
-
 
1089
;           and ecx, not 4095
-
 
1090
;
-
 
1091
;.touch:    mov eax, [ebx]
-
 
1092
;           add ebx, 0x1000
-
 
1093
;           cmp ebx, ecx
-
 
1094
;           jb  .touch
-
 
1095
;
-
 
1096
;           popf
-
 
1097
;           xor eax, eax
-
 
1098
;           ret
-
 
1099
;endp
-
 
1100
 
1052
 
1101
proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
1053
proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
1102
           locals
1054
           locals
1103
             dst_slot   dd ?
1055
             dst_slot   dd ?
1104
             dst_offset dd ?
1056
             dst_offset dd ?
Line 1114... Line 1066...
1114
        test    eax, eax
1066
        test    eax, eax
1115
        jz      .no_pid
1067
        jz      .no_pid
Line 1116... Line 1068...
1116
 
1068
 
1117
        mov     [dst_slot], eax
1069
        mov     [dst_slot], eax
1118
        shl     eax, 8
1070
        shl     eax, 8
1119
        mov     edi, [eax+SLOT_BASE+0xa0] ;is ipc area defined?
1071
        mov     edi, [eax+SLOT_BASE+APPDATA.ipc_start] ;is ipc area defined?
1120
        test    edi, edi
1072
        test    edi, edi
Line 1121... Line 1073...
1121
        jz      .no_ipc_area
1073
        jz      .no_ipc_area
1122
 
1074
 
1123
        mov     ebx, edi
1075
        mov     ebx, edi
Line 1124... Line 1076...
1124
        and     ebx, 0xFFF
1076
        and     ebx, 0xFFF
1125
        mov     [dst_offset], ebx
1077
        mov     [dst_offset], ebx
Line 1126... Line 1078...
1126
 
1078
 
1127
        mov     esi, [eax+SLOT_BASE+0xa4]
1079
        mov     esi, [eax+SLOT_BASE+APPDATA.ipc_size]
1128
        mov     [buf_size], esi
1080
        mov     [buf_size], esi
Line 1135... Line 1087...
1135
        stdcall alloc_kernel_space, esi
1087
        stdcall alloc_kernel_space, esi
1136
        mov     ecx, eax
1088
        mov     ecx, eax
1137
        pop     edi esi
1089
        pop     edi esi
1138
@@:
1090
@@:
1139
        mov     [used_buf], ecx
1091
        mov     [used_buf], ecx
1140
        stdcall map_mem, ecx, [dst_slot], \
1092
        stdcall map_mem_ipc, ecx, [dst_slot], \
1141
                edi, esi, PG_SW
1093
                edi, esi, PG_SW
Line 1142... Line 1094...
1142
 
1094
 
1143
        mov     edi, [dst_offset]
1095
        mov     edi, [dst_offset]
1144
        add     edi, [used_buf]
1096
        add     edi, [used_buf]
Line 1206... Line 1158...
1206
.buffer_overflow:
1158
.buffer_overflow:
1207
        push    3
1159
        push    3
1208
.ret:
1160
.ret:
1209
        mov     eax, [used_buf]
1161
        mov     eax, [used_buf]
1210
        cmp     eax, [ipc_tmp]
1162
        cmp     eax, [ipc_tmp]
1211
        jz      @f
1163
        je      @f
1212
        stdcall free_kernel_space, eax
1164
        stdcall free_kernel_space, eax
1213
@@:
1165
@@:
1214
        pop     eax
1166
        pop     eax
1215
        popf
1167
        popf
1216
        ret
1168
        ret