Subversion Repositories Kolibri OS

Rev

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

Rev 3187 Rev 3359
Line 73... Line 73...
73
  msg_exc_b     db "Segment not present", 0
73
  msg_exc_b     db "Segment not present", 0
74
  msg_exc_c     db "Stack fault", 0
74
  msg_exc_c     db "Stack fault", 0
75
  msg_exc_d     db "General protection fault", 0
75
  msg_exc_d     db "General protection fault", 0
76
  msg_exc_e     db "Page fault", 0
76
  msg_exc_e     db "Page fault", 0
Line -... Line 77...
-
 
77
 
-
 
78
  if lang eq sp
-
 
79
    include 'core/sys32-sp.inc'
77
 
80
  else
78
  msg_sel_ker   db "kernel", 0
81
    msg_sel_ker   db "kernel", 0
-
 
82
    msg_sel_app   db "application", 0
Line 79... Line 83...
79
  msg_sel_app   db "application", 0
83
  end if
Line 80... Line 84...
80
 
84
 
81
endg
85
endg
Line 217... Line 221...
217
        mov     ebp, notifyapp
221
        mov     ebp, notifyapp
218
        call    fs_execute_from_sysdir_param
222
        call    fs_execute_from_sysdir_param
219
        pop     ebx
223
        pop     ebx
220
.no_ud:
224
.no_ud:
221
        mov     edx, [TASK_BASE];not scratched below
225
        mov     edx, [TASK_BASE];not scratched below
-
 
226
        if lang eq sp
-
 
227
        DEBUGF  1, "K : Proceso - terminado forzado PID: %x [%s]\n", [edx+TASKDATA.pid], [current_slot]
-
 
228
        else
222
        DEBUGF  1, "K : Process - forced terminate PID: %x\n", [edx+TASKDATA.pid]
229
        DEBUGF  1, "K : Process - forced terminate PID: %x [%s]\n", [edx+TASKDATA.pid], [current_slot]
-
 
230
        end if
223
        cmp     bl, 0x08
231
        cmp     bl, 0x08
224
        jb      .l0
232
        jb      .l0
225
        cmp     bl, 0x0e
233
        cmp     bl, 0x0e
226
        jbe     .l1
234
        jbe     .l1
227
  .l0:
235
  .l0:
Line 711... Line 719...
711
;        call   build_process_gdt_tss_pointer
719
;        call   build_process_gdt_tss_pointer
Line 712... Line 720...
712
 
720
 
713
;        mov    esi,boot_sched_2
721
;        mov    esi,boot_sched_2
714
;        call   boot_log
722
;        call   boot_log
-
 
723
;        ret
-
 
724
 
-
 
725
; Three following procedures are used to guarantee that
-
 
726
; some part of kernel code will not be terminated from outside
-
 
727
; while it is running.
-
 
728
; Note: they do not protect a thread from terminating due to errors inside
-
 
729
; the thread; accessing a nonexisting memory would still terminate it.
-
 
730
 
-
 
731
; First two procedures must be used in pair by thread-to-be-protected
-
 
732
; to signal the beginning and the end of an important part.
-
 
733
; It is OK to have nested areas.
-
 
734
 
-
 
735
; The last procedure must be used by outside wanna-be-terminators;
-
 
736
; if it is safe to terminate the given thread immediately, it returns eax=1;
-
 
737
; otherwise, it returns eax=0 and notifies the target thread that it should
-
 
738
; terminate itself when leaving a critical area (the last critical area if
-
 
739
; they are nested).
-
 
740
 
-
 
741
; Implementation. Those procedures use one dword in APPDATA for the thread,
-
 
742
; APPDATA.terminate_protection.
-
 
743
; * The upper bit is 1 during normal operations and 0 when terminate is requested.
-
 
744
; * Other bits form a number = depth of critical regions,
-
 
745
;   plus 1 if the upper bit is 1.
-
 
746
; * When this dword goes to zero, the thread should be destructed,
-
 
747
;   and the procedure in which it happened becomes responsible for destruction.
-
 
748
 
-
 
749
; Enter critical area. Called by thread which wants to be protected.
-
 
750
proc protect_from_terminate
-
 
751
        mov     edx, [current_slot]
-
 
752
; Atomically increment depth of critical areas and get the old value.
-
 
753
        mov     eax, 1
-
 
754
        lock xadd [edx+APPDATA.terminate_protection], eax
-
 
755
; If the old value was zero, somebody has started to terminate us,
-
 
756
; so we are destructing and cannot do anything protected.
-
 
757
; Otherwise, return to the caller.
-
 
758
        test    eax, eax
-
 
759
        jz      @f
-
 
760
        ret
-
 
761
@@:
-
 
762
; Wait for somebody to finish us.
-
 
763
        call    change_task
-
 
764
        jmp     @b
-
 
765
endp
-
 
766
 
-
 
767
; Leave critical area. Called by thread which wants to be protected.
-
 
768
proc unprotect_from_terminate
-
 
769
        mov     edx, [current_slot]
-
 
770
; Atomically decrement depth of critical areas.
-
 
771
        lock dec [edx+APPDATA.terminate_protection]
-
 
772
; If the result of decrement is zero, somebody has requested termination,
-
 
773
; but at that moment we were inside a critical area; terminate now.
-
 
774
        jz      sys_end
-
 
775
; Otherwise, return to the caller.
-
 
776
        ret
-
 
777
endp
-
 
778
 
-
 
779
; Request termination of thread identified by edx = SLOT_BASE + slot*256.
-
 
780
; Called by anyone.
-
 
781
proc request_terminate
-
 
782
        xor     eax, eax        ; set return value
-
 
783
; Atomically clear the upper bit. If it was already zero, then
-
 
784
; somebody has requested termination before us, so just exit.
-
 
785
        lock btr [edx+APPDATA.terminate_protection], 31
-
 
786
        jnc     .unsafe
-
 
787
; Atomically decrement depth of critical areas.
-
 
788
        lock dec [edx+APPDATA.terminate_protection]
-
 
789
; If the result of decrement is nonzero, the target thread is inside a
-
 
790
; critical area; leave termination to leaving that area.
-
 
791
        jnz     .unsafe
-
 
792
; Otherwise, it is safe to kill the target now and the caller is responsible
-
 
793
; for this. Return eax=1.
-
 
794
        inc     eax
-
 
795
.unsafe:
-
 
796
        ret
-
 
797
endp