Subversion Repositories Kolibri OS

Rev

Rev 9911 | Details | Compare with Previous | Last modification | View Log | RSS feed

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