Rev 9045 | Rev 9279 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4850 | mario79 | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
5363 | yogev_ezra | 3 | ;; Copyright (C) KolibriOS team 2013-2015. All rights reserved. ;; |
4850 | mario79 | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | $Revision: 9265 $ |
||
9 | |||
10 | |||
4199 | mario79 | 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 |
||
8711 | Doczom | 52 | |
9265 | Doczom | 53 | ; check pointer on kernel address |
8711 | Doczom | 54 | stdcall is_region_userspace, edx, ecx |
9045 | dunkaist | 55 | jz @f |
8711 | Doczom | 56 | mov eax, -1 |
57 | jmp .exit_1 |
||
58 | @@: |
||
4199 | mario79 | 59 | ; check the lock |
60 | mov ebx, clipboard_write_lock |
||
61 | xor eax, eax |
||
62 | cmp [ebx], eax |
||
63 | jne .exit_2 |
||
64 | ; lock last slot |
||
65 | inc eax |
||
66 | mov [ebx], eax |
||
67 | ; check the overflow pointer of slots |
||
68 | cmp [clipboard_slots], 1024 |
||
69 | jae .exit_3 |
||
70 | ; get memory for new slot |
||
71 | push ebx ecx edx |
||
72 | stdcall kernel_alloc, ecx |
||
73 | pop edx ecx ebx |
||
74 | test eax, eax |
||
75 | jz .exit_3 |
||
76 | ; create a new slot |
||
77 | mov edi, eax |
||
78 | mov eax, [clipboard_slots] |
||
79 | shl eax, 2 |
||
80 | add eax, [clipboard_main_list] |
||
81 | mov [eax], edi |
||
9265 | Doczom | 82 | push edi ;save pointer to data |
83 | push ecx ;save size data |
||
4199 | mario79 | 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 |
||
9265 | Doczom | 92 | ;copy ecx in Dword[clipboard_main_list+clipboard_slots*4] |
93 | pop ecx |
||
94 | pop eax |
||
95 | mov [eax], ecx |
||
4199 | mario79 | 96 | ; increase the counter of slots |
97 | inc [clipboard_slots] |
||
98 | ; unlock last slot |
||
99 | xor eax, eax |
||
100 | mov [ebx], eax |
||
101 | jmp .exit_1 |
||
102 | ;------------------------------------------------------------------------------ |
||
103 | align 4 |
||
104 | .3: |
||
105 | dec ebx ; 3 - Delete the last slot in the clipboard |
||
106 | jnz .4 |
||
107 | ; check the availability of slots |
||
108 | mov eax, [clipboard_slots] |
||
109 | test eax, eax |
||
110 | jz .exit_2 |
||
111 | ; check the lock |
||
112 | mov ebx, clipboard_write_lock |
||
113 | xor eax, eax |
||
114 | cmp [ebx], eax |
||
115 | jne .exit_2 |
||
116 | ; lock last slot |
||
117 | inc eax |
||
118 | mov [ebx], eax |
||
119 | ; decrease the counter of slots |
||
120 | mov eax, clipboard_slots |
||
121 | dec dword [eax] |
||
122 | ; free of kernel memory allocated for the slot |
||
123 | mov eax, [eax] |
||
124 | shl eax, 2 |
||
125 | add eax, [clipboard_main_list] |
||
126 | mov eax, [eax] |
||
127 | push ebx |
||
128 | stdcall kernel_free, eax |
||
129 | pop ebx |
||
130 | ; unlock last slot |
||
131 | xor eax, eax |
||
132 | mov [ebx], eax |
||
133 | jmp .exit_1 |
||
134 | ;------------------------------------------------------------------------------ |
||
135 | align 4 |
||
136 | .4: |
||
137 | dec ebx ; 4 - Emergency discharge of clipboard |
||
138 | jnz .exit |
||
139 | ; check the lock |
||
140 | mov ebx, clipboard_write_lock |
||
141 | xor eax, eax |
||
142 | cmp [ebx], eax |
||
143 | je .exit_2 |
||
144 | |||
145 | ; there should be a procedure for checking the integrity of the slots |
||
146 | ; and I will do so in the future |
||
147 | |||
148 | ; unlock last slot |
||
149 | mov [ebx], eax |
||
150 | jmp .exit |
||
151 | ;------------------------------------------------------------------------------ |
||
152 | align 4 |
||
153 | .exit_3: |
||
154 | ; unlock last slot |
||
155 | xor eax, eax |
||
156 | mov [ebx], eax |
||
157 | .exit_2: |
||
158 | xor eax, eax |
||
159 | inc eax ; error |
||
160 | .exit_1: |
||
161 | mov [esp + 32], eax |
||
162 | .exit: |
||
163 | ret |
||
164 | ;------------------------------------------------------------------------------ |
||
165 | uglobal |
||
166 | align 4 |
||
167 | clipboard_slots dd ? |
||
168 | clipboard_main_list dd ? |
||
169 | clipboard_write_lock dd ? |
||
170 | endg |
||
171 | ;------------------------------------------------------------------------------ |