Rev 9265 | Rev 9715 | 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: 9279 $ |
||
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 |
||
82 | ; copy the data into the slot |
||
83 | mov esi, edx |
||
84 | mov eax, ecx |
||
85 | cld |
||
86 | stosd ; store size of slot |
||
87 | sub ecx, 4 |
||
88 | add esi, 4 |
||
89 | rep movsb ; store slot data |
||
90 | ; increase the counter of slots |
||
91 | inc [clipboard_slots] |
||
92 | ; unlock last slot |
||
93 | xor eax, eax |
||
94 | mov [ebx], eax |
||
95 | jmp .exit_1 |
||
96 | ;------------------------------------------------------------------------------ |
||
97 | align 4 |
||
98 | .3: |
||
99 | dec ebx ; 3 - Delete the last slot in the clipboard |
||
100 | jnz .4 |
||
101 | ; check the availability of slots |
||
102 | mov eax, [clipboard_slots] |
||
103 | test eax, eax |
||
104 | jz .exit_2 |
||
105 | ; check the lock |
||
106 | mov ebx, clipboard_write_lock |
||
107 | xor eax, eax |
||
108 | cmp [ebx], eax |
||
109 | jne .exit_2 |
||
110 | ; lock last slot |
||
111 | inc eax |
||
112 | mov [ebx], eax |
||
113 | ; decrease the counter of slots |
||
114 | mov eax, clipboard_slots |
||
115 | dec dword [eax] |
||
116 | ; free of kernel memory allocated for the slot |
||
117 | mov eax, [eax] |
||
118 | shl eax, 2 |
||
119 | add eax, [clipboard_main_list] |
||
120 | mov eax, [eax] |
||
121 | push ebx |
||
122 | stdcall kernel_free, eax |
||
123 | pop ebx |
||
124 | ; unlock last slot |
||
125 | xor eax, eax |
||
126 | mov [ebx], eax |
||
127 | jmp .exit_1 |
||
128 | ;------------------------------------------------------------------------------ |
||
129 | align 4 |
||
130 | .4: |
||
131 | dec ebx ; 4 - Emergency discharge of clipboard |
||
132 | jnz .exit |
||
133 | ; check the lock |
||
134 | mov ebx, clipboard_write_lock |
||
135 | xor eax, eax |
||
136 | cmp [ebx], eax |
||
137 | je .exit_2 |
||
138 | |||
139 | ; there should be a procedure for checking the integrity of the slots |
||
140 | ; and I will do so in the future |
||
141 | |||
142 | ; unlock last slot |
||
143 | mov [ebx], eax |
||
144 | jmp .exit |
||
145 | ;------------------------------------------------------------------------------ |
||
146 | align 4 |
||
147 | .exit_3: |
||
148 | ; unlock last slot |
||
149 | xor eax, eax |
||
150 | mov [ebx], eax |
||
151 | .exit_2: |
||
152 | xor eax, eax |
||
153 | inc eax ; error |
||
154 | .exit_1: |
||
155 | mov [esp + 32], eax |
||
156 | .exit: |
||
157 | ret |
||
158 | ;------------------------------------------------------------------------------ |
||
159 | uglobal |
||
160 | align 4 |
||
161 | clipboard_slots dd ? |
||
162 | clipboard_main_list dd ? |
||
163 | clipboard_write_lock dd ? |
||
164 | endg |
||
165 | ;------------------------------------------------------------------------------ |