Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2013-2015. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 9045 $
  9.  
  10.  
  11. ;------------------------------------------------------------------------------
  12. align 4
  13. sys_clipboard:
  14.         xor     eax, eax
  15.         dec     eax
  16. ; check availability of main list
  17.         cmp     [clipboard_main_list], eax
  18.         je      .exit_1 ; main list area not found
  19.  
  20.         test    ebx, ebx  ; 0 - Get the number of slots in the clipboard
  21.         jnz     .1
  22. ; get the number of slots
  23.         mov     eax, [clipboard_slots]
  24.         jmp     .exit_1
  25. ;------------------------------------------------------------------------------
  26. align 4
  27. .1:
  28.         dec     ebx  ; 1 - Read the data from the clipboard
  29.         jnz     .2
  30. ; verify the existence of slot
  31.         cmp     ecx, [clipboard_slots]
  32.         jae     .exit_2
  33. ; get a pointer to the data of slot
  34.         shl     ecx, 2
  35.         add     ecx, [clipboard_main_list]
  36.         mov     esi, [ecx]
  37.         mov     ecx, [esi]
  38. ; allocate memory for application for copy the data of slots
  39.         push    ecx
  40.         stdcall user_alloc, ecx
  41.         pop     ecx
  42. ; copying data of slots
  43.         mov     edi, eax
  44.         cld
  45.         rep movsb
  46.         jmp     .exit_1
  47. ;------------------------------------------------------------------------------
  48. align 4
  49. .2:
  50.         dec     ebx  ; 2 - Write the data to the clipboard
  51.         jnz     .3
  52.  
  53. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  54.         stdcall is_region_userspace, edx, ecx
  55.         jz      @f
  56.         mov     eax, -1
  57.         jmp     .exit_1
  58. @@:
  59. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  60.  
  61. ; check the lock
  62.         mov     ebx, clipboard_write_lock
  63.         xor     eax, eax
  64.         cmp     [ebx], eax
  65.         jne     .exit_2
  66. ; lock last slot
  67.         inc     eax
  68.         mov     [ebx], eax
  69. ; check the overflow pointer of slots
  70.         cmp     [clipboard_slots], 1024
  71.         jae     .exit_3
  72. ; get memory for new slot
  73.         push    ebx ecx edx
  74.         stdcall kernel_alloc, ecx
  75.         pop     edx ecx ebx
  76.         test    eax, eax
  77.         jz      .exit_3
  78. ; create a new slot
  79.         mov     edi, eax
  80.         mov     eax, [clipboard_slots]
  81.         shl     eax, 2
  82.         add     eax, [clipboard_main_list]
  83.         mov     [eax], edi
  84. ; copy the data into the slot
  85.         mov     esi, edx
  86.         mov     eax, ecx
  87.         cld
  88.         stosd  ; store size of slot
  89.         sub     ecx, 4
  90.         add     esi, 4
  91.         rep movsb ; store slot data
  92. ; increase the counter of slots
  93.         inc     [clipboard_slots]
  94. ; unlock last slot
  95.         xor     eax, eax
  96.         mov     [ebx], eax
  97.         jmp     .exit_1
  98. ;------------------------------------------------------------------------------
  99. align 4
  100. .3:
  101.         dec     ebx  ; 3 - Delete the last slot in the clipboard
  102.         jnz     .4
  103. ; check the availability of slots
  104.         mov     eax, [clipboard_slots]
  105.         test    eax, eax
  106.         jz      .exit_2
  107. ; check the lock
  108.         mov     ebx, clipboard_write_lock
  109.         xor     eax, eax
  110.         cmp     [ebx], eax
  111.         jne     .exit_2
  112. ; lock last slot
  113.         inc     eax
  114.         mov     [ebx], eax
  115. ; decrease the counter of slots
  116.         mov     eax, clipboard_slots
  117.         dec     dword [eax]
  118. ; free of kernel memory allocated for the slot
  119.         mov     eax, [eax]
  120.         shl     eax, 2
  121.         add     eax, [clipboard_main_list]
  122.         mov     eax, [eax]
  123.         push    ebx
  124.         stdcall kernel_free, eax
  125.         pop     ebx
  126. ; unlock last slot
  127.         xor     eax, eax
  128.         mov     [ebx], eax
  129.         jmp     .exit_1
  130. ;------------------------------------------------------------------------------
  131. align 4
  132. .4:
  133.         dec     ebx  ; 4 - Emergency discharge of clipboard
  134.         jnz     .exit
  135. ; check the lock
  136.         mov     ebx, clipboard_write_lock
  137.         xor     eax, eax
  138.         cmp     [ebx], eax
  139.         je      .exit_2
  140.  
  141. ; there should be a procedure for checking the integrity of the slots
  142. ; and I will do so in the future
  143.  
  144. ; unlock last slot
  145.         mov     [ebx], eax
  146.         jmp     .exit
  147. ;------------------------------------------------------------------------------
  148. align 4
  149. .exit_3:
  150. ; unlock last slot
  151.         xor     eax, eax
  152.         mov     [ebx], eax
  153. .exit_2:
  154.         xor     eax, eax
  155.         inc     eax     ; error
  156. .exit_1:
  157.         mov     [esp + 32], eax
  158. .exit:
  159.         ret
  160. ;------------------------------------------------------------------------------
  161. uglobal
  162. align 4
  163. clipboard_slots dd ?
  164. clipboard_main_list dd ?
  165. clipboard_write_lock dd ?
  166. endg
  167. ;------------------------------------------------------------------------------
  168.