Subversion Repositories Kolibri OS

Rev

Rev 7320 | Rev 7322 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 7321 $
  9.  
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11. ;;                                                            ;;
  12. ;;                     SYSENTER ENTRY                         ;;
  13. ;;                                                            ;;
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15.  
  16. align 32
  17. sysenter_entry:
  18.         ; Настраиваем стек
  19.         mov     esp, [ss:tss._esp0]
  20.         sti
  21.         push    ebp                     ; save app esp + 4
  22.         mov     ebp, [ebp]              ; ebp - original ebp
  23.         ;------------------
  24.         pushad
  25.         cld
  26.  
  27.         call    protect_from_terminate
  28.  
  29.         movzx   eax, byte [esp+28]
  30.         mov     edx, dword [esp+20]
  31.         call    dword [servetable2 + eax * 4]
  32.  
  33.         call    unprotect_from_terminate
  34.         popad
  35.         ;------------------
  36.         xchg    ecx, [ss:esp]           ; в вершин стека - app ecx, ecx - app esp + 4
  37.         sub     ecx, 4
  38.         xchg    edx, [ecx]              ; edx - return point, & save original edx
  39.         push    edx
  40.         mov     edx, [ss:esp + 4]
  41.         mov     [ecx + 4], edx          ; save original ecx
  42.         pop     edx
  43.         sysexit
  44.  
  45. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  46. ;;                                                            ;;
  47. ;;                   SYSTEM CALL ENTRY                        ;;
  48. ;;                                                            ;;
  49. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  50.  
  51. align 16
  52. i40:
  53.         pushad
  54.         cld
  55.         call    protect_from_terminate
  56.         movzx   eax, byte [esp+28]
  57.         mov     edx, dword [esp+20]
  58.         call    dword [servetable2 + eax * 4]
  59.         call    unprotect_from_terminate
  60.         popad
  61.         iretd
  62.  
  63. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  64. ;;                                                            ;;
  65. ;;                     SYSCALL ENTRY                          ;;
  66. ;;                                                            ;;
  67. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  68. align 32
  69. syscall_entry:
  70.   ;     cli                 syscall clear IF
  71.         xchg    esp, [ss:tss._esp0]
  72.         push    ecx
  73.         lea     ecx, [esp+4]
  74.         xchg    ecx, [ss:tss._esp0]
  75.         sti
  76.         push    ecx
  77.         mov     ecx, [ecx]
  78.         ;------------------
  79.         pushad
  80.         cld
  81.         call    protect_from_terminate
  82.  
  83.         movzx   eax, byte [esp+28]
  84.         mov     edx, dword [esp+20]
  85.         call    dword [servetable2 + eax * 4]
  86.  
  87.         call    unprotect_from_terminate
  88.         popad
  89.         ;------------------
  90.         mov     ecx, [ss:esp+4]
  91.         pop     esp
  92.         sysret
  93.  
  94. iglobal
  95.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  96.   ;; SYSTEM FUNCTIONS TABLE ;;
  97.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  98.   align 4
  99.   servetable2:
  100.  
  101.       dd syscall_draw_window     ; 0-DrawWindow
  102.       dd syscall_setpixel        ; 1-SetPixel
  103.       dd sys_getkey              ; 2-GetKey
  104.       dd sys_clock               ; 3-GetTime
  105.       dd syscall_writetext       ; 4-WriteText
  106.       dd delay_hs_unprotected    ; 5-DelayHs
  107.       dd undefined_syscall       ; 6-deprecated OpenRamdiskFile
  108.       dd syscall_putimage        ; 7-PutImage
  109.       dd syscall_button          ; 8-DefineButton
  110.       dd sys_cpuusage            ; 9-GetProcessInfo
  111.       dd sys_waitforevent        ; 10-WaitForEvent
  112.       dd sys_getevent            ; 11-CheckForEvent
  113.       dd sys_redrawstat          ; 12-BeginDraw and EndDraw
  114.       dd syscall_drawrect        ; 13-DrawRect
  115.       dd syscall_getscreensize   ; 14-GetScreenSize
  116.       dd sys_background          ; 15-bgr
  117.       dd sys_cachetodiskette     ; 16-FlushFloppyCache
  118.       dd sys_getbutton           ; 17-GetButton
  119.       dd sys_system              ; 18-System Services
  120.       dd paleholder              ; 19-reserved
  121.       dd sys_midi                ; 20-ResetMidi and OutputMidi
  122.       dd sys_setup               ; 21-SetMidiBase,SetKeymap,SetShiftKeymap,.
  123.       dd sys_settime             ; 22-setting date,time,clock and alarm-clock
  124.       dd sys_wait_event_timeout  ; 23-TimeOutWaitForEvent
  125.       dd syscall_cdaudio         ; 24-PlayCdTrack,StopCd and GetCdPlaylist
  126.       dd syscall_putarea_backgr  ; 25-Put Area to background
  127.       dd sys_getsetup            ; 26-GetMidiBase,GetKeymap,GetShiftKeymap,.
  128.       dd undefined_syscall       ; 27-reserved
  129.       dd undefined_syscall       ; 28-reserved
  130.       dd sys_date                ; 29-GetDate
  131.       dd sys_current_directory   ; 30-Get/SetCurrentDirectory
  132.       dd undefined_syscall       ; 31-reserved
  133.       dd undefined_syscall       ; 32-reserved
  134.       dd undefined_syscall       ; 33-reserved
  135.       dd syscall_getpixel_WinMap ; 34-GetPixel WinMap
  136.       dd syscall_getpixel        ; 35-GetPixel
  137.       dd syscall_getarea         ; 36-GetArea
  138.       dd readmousepos            ; 37-GetMousePosition_ScreenRelative,.
  139.       dd syscall_drawline        ; 38-DrawLine
  140.       dd sys_getbackground       ; 39-GetBackgroundSize,ReadBgrData,.
  141.       dd set_app_param           ; 40-WantEvents
  142.       dd undefined_syscall       ; 41- deprecated GetIrqOwner
  143.       dd undefined_syscall       ; 42- deprecated ReadIrqData
  144.       dd sys_outport             ; 43-SendDeviceData
  145.       dd undefined_syscall       ; 44- deprecated ProgramIrqs
  146.       dd undefined_syscall       ; 45- deprecated ReserveIrq and FreeIrq
  147.       dd syscall_reserveportarea ; 46-ReservePortArea and FreePortArea
  148.       dd display_number          ; 47-WriteNum
  149.       dd syscall_display_settings ; 48-SetRedrawType and SetButtonType
  150.       dd sys_apm                 ; 49-Advanced Power Management (APM)
  151.       dd syscall_set_window_shape ; 50-Window shape & scale
  152.       dd syscall_threads         ; 51-Threads
  153.       dd undefined_syscall       ; 52- deprecated Stack driver status
  154.       dd undefined_syscall       ; 53- deprecated Socket interface
  155.       dd sys_clipboard           ; 54-Custom clipboard
  156.       dd sound_interface         ; 55-Sound interface
  157.       dd undefined_syscall       ; 56-reserved
  158.       dd sys_pcibios             ; 57-PCI BIOS32
  159.       dd undefined_syscall       ; 58-deprecated Common file system interface
  160.       dd undefined_syscall       ; 59-reserved
  161.       dd sys_IPC                 ; 60-Inter Process Communication
  162.       dd sys_gs                  ; 61-Direct graphics access
  163.       dd pci_api                 ; 62-PCI functions
  164.       dd sys_msg_board           ; 63-System message board
  165.       dd sys_resize_app_memory   ; 64-Resize application memory usage
  166.       dd sys_putimage_palette    ; 65-PutImagePalette
  167.       dd sys_process_def         ; 66-Process definitions - keyboard
  168.       dd syscall_move_window     ; 67-Window move or resize
  169.       dd f68                     ; 68-Some internal services
  170.       dd sys_debug_services      ; 69-Debug
  171.       dd file_system_lfn         ; 70-Common file system interface, version 2
  172.       dd syscall_window_settings ; 71-Window settings
  173.       dd sys_sendwindowmsg       ; 72-Send window message
  174.       dd blit_32                 ; 73-blitter;
  175.       dd sys_network             ; 74-reserved for new stack
  176.       dd sys_socket              ; 75-reserved for new stack
  177.       dd sys_protocols           ; 76-reserved for new stack
  178.       dd sys_posix               ; posix support
  179.       dd undefined_syscall       ; 78-free
  180.       dd undefined_syscall       ; 79-free
  181.       dd fileSystemUnicode       ; 80-File system interface for different encodings
  182.       dd setInt0x40              ; 81-Implementation of the function in the system
  183.  
  184.         times 255 - ( ($-servetable2) /4 )  dd undefined_syscall
  185.       dd sys_end                 ; -1-end application
  186.  
  187. endg
  188.  
  189. ; Author Pavel Iakovlev
  190. ; Return EAX = 0 security kernel, error set function
  191. ; Return Else EAX > 0 success set function
  192. align 32
  193. setInt0x40:
  194.  
  195.            ; !!! kernel security !!!
  196.         and     ebx, 0FFh
  197.         mov     eax, dword [servetable2 + ebx * 4]
  198. ;       cmp     eax, undefined_syscall
  199. ;       jne     errorSet0x40
  200.            ; -----------------------
  201.  
  202.         pushad
  203.         add     edx, 16
  204.         stdcall kernel_alloc, edx
  205.         push    eax
  206.         pop     dword[tempPointerAlloc]
  207.         popad
  208.  
  209.  
  210.         push    ebx
  211.         push    dword[tempPointerAlloc]
  212.         pop     eax
  213.         mov     ebx, eax
  214.         add     eax, edx
  215.  
  216.         push    0
  217.         pop     dword[hashDataFunction1]
  218.         push    1
  219.         pop     dword[hashDataFunction2]
  220.  
  221.         loopCopyMemory:
  222.         xor     edx, edx
  223.  
  224.         mov     dl, byte[ecx]
  225.         mov     byte[ebx], dl
  226.  
  227.         ; hash security function
  228.         add     dword[hashDataFunction1], edx
  229.         mov     edx, dword[hashDataFunction1]
  230.         add     dword[hashDataFunction2], edx
  231.         ;-----------------------------
  232.  
  233.         inc     ebx
  234.         inc     ecx
  235.         cmp     ebx, eax
  236.         jne     loopCopyMemory
  237.  
  238.         pop     ebx
  239.  
  240.         ; check hash security data
  241.         ; cmp     edi, dword[hashDataFunction1]
  242.         ; jne     errorSet0x40
  243.         ; cmp     esi, dword[hashDataFunction2]
  244.         ; jne     errorSet0x40
  245.         ;-------------------------------
  246.  
  247.         mov     eax, dword[tempPointerAlloc]
  248.         mov     dword [servetable2 + ebx * 4], eax
  249.         jmp     successSet0x40
  250.  
  251.         errorSet0x40:
  252.         xor     eax, eax
  253.  
  254.         successSet0x40:
  255.         ret
  256.  
  257. tempPointerAlloc dd ?
  258. ;hashDataFunction1 dd ?
  259. ;hashDataFunction2 dd ?
  260. ;-------------------