Subversion Repositories Kolibri OS

Rev

Rev 9045 | Rev 9279 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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