Rev 6928 | Rev 8130 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6928 | Rev 6929 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 7... | Line 7... | ||
7 | 7 | ||
Line -... | Line 8... | ||
- | 8 | $Revision: 6917 $ |
|
- | 9 | ||
- | 10 | F_READ equ 0x0001 ; file opened for reading |
|
8 | $Revision: 6917 $ |
11 | F_WRITE equ 0x0002 ; file opened for writing |
9 | 12 | ||
Line 10... | Line 13... | ||
10 | O_CLOEXEC equ 0x40000 |
13 | O_CLOEXEC equ 0x40000 |
Line 94... | Line 97... | ||
94 | mov edx, [.fdwrite] |
97 | mov edx, [.fdwrite] |
95 | mov ecx, [.pipefd] |
98 | mov ecx, [.pipefd] |
Line 96... | Line 99... | ||
96 | 99 | ||
97 | mov [eax+FILED.magic], 'PIPE' |
100 | mov [eax+FILED.magic], 'PIPE' |
- | 101 | mov [eax+FILED.destroy], 0 |
|
98 | mov [eax+FILED.destroy], 0 |
102 | mov [eax+FILED.mode], F_READ |
Line 99... | Line 103... | ||
99 | mov [eax+FILED.file], ebp |
103 | mov [eax+FILED.file], ebp |
100 | 104 | ||
- | 105 | mov [edx+FILED.magic], 'PIPE' |
|
101 | mov [edx+FILED.magic], 'PIPE' |
106 | mov [edx+FILED.destroy], 0 |
Line 102... | Line 107... | ||
102 | mov [edx+FILED.destroy], 0 |
107 | mov [edx+FILED.mode], F_WRITE |
103 | mov [edx+FILED.file], ebp |
108 | mov [edx+FILED.file], ebp |
Line 123... | Line 128... | ||
123 | mov ecx, [.fdread] |
128 | mov ecx, [.fdread] |
124 | call destroy_object |
129 | call destroy_object |
125 | .err_0: |
130 | .err_0: |
126 | add esp, 5*4 |
131 | add esp, 5*4 |
127 | .fail: |
132 | .fail: |
128 | mov [esp+SYSCALL_STACK._eax], ebp |
133 | mov eax, ebp |
129 | pop ebp |
134 | pop ebp |
- | 135 | mov [esp+SYSCALL_STACK._eax], eax |
|
130 | ret |
136 | ret |
Line 131... | Line 137... | ||
131 | 137 | ||
132 | purge .pipeflags |
138 | purge .pipeflags |
133 | purge .filefd |
139 | purge .filefd |
134 | purge .fdread |
140 | purge .fdread |
135 | purge .fdwrite |
141 | purge .fdwrite |
Line 136... | Line 142... | ||
136 | purge .intpipe |
142 | purge .intpipe |
137 | 143 | ||
138 | 144 | ||
Line 139... | Line 145... | ||
139 | ; edx buf |
145 | ; edx dst_buf |
140 | ; esi count |
146 | ; esi read count |
- | 147 | ; ebp pipe |
|
141 | ; ebp pipe |
148 | |
Line 142... | Line -... | ||
142 | - | ||
143 | align 4 |
149 | align 4 |
144 | pipe_read: |
150 | pipe_read: |
145 | mov edi, edx |
151 | |
146 | 152 | mov edi, edx |
|
147 | .again: |
153 | |
148 | lea ecx, [ebp+PIPE.pipe_lock] |
154 | lea ecx, [ebp+PIPE.pipe_lock] |
Line 149... | Line 155... | ||
149 | call mutex_lock |
155 | call mutex_lock |
Line 168... | Line 174... | ||
168 | cld |
174 | cld |
169 | rep movsb |
175 | rep movsb |
170 | and esi, 0xFFF |
176 | and esi, 0xFFF |
171 | mov [ebp+PIPE.read_end], esi |
177 | mov [ebp+PIPE.read_end], esi |
Line -... | Line 178... | ||
- | 178 | ||
- | 179 | lea ecx, [ebp+PIPE.wlist] |
|
- | 180 | cmp ecx, [ebp+PIPE.wlist.next] |
|
- | 181 | je @F |
|
- | 182 | ||
- | 183 | mov ecx, [ecx+MUTEX_WAITER.task] |
|
- | 184 | mov [ecx+TASKDATA.state], 0 ;activate writer task |
|
- | 185 | @@: |
|
- | 186 | cmp [ebp+PIPE.count], 0 |
|
- | 187 | je @F |
|
- | 188 | ||
- | 189 | lea eax, [ebp+PIPE.rlist] |
|
- | 190 | cmp eax, [ebp+PIPE.rlist.next] |
|
- | 191 | je @F |
|
- | 192 | ||
- | 193 | mov eax, [eax+MUTEX_WAITER.task] |
|
- | 194 | mov [eax+TASKDATA.state], 0 ;activate reader task |
|
172 | 195 | @@: |
|
173 | lea ecx, [ebp+PIPE.pipe_lock] |
196 | lea ecx, [ebp+PIPE.pipe_lock] |
174 | call mutex_unlock |
197 | call mutex_unlock |
Line 175... | Line 198... | ||
175 | ret |
198 | ret |
- | 199 | ||
- | 200 | .wait: |
|
- | 201 | pushfd |
|
176 | 202 | cli |
|
177 | .wait: |
203 | |
178 | sub esp, sizeof.MUTEX_WAITER |
204 | sub esp, sizeof.MUTEX_WAITER |
179 | mov ebx, [TASK_BASE] |
205 | mov ebx, [TASK_BASE] |
Line 186... | Line 212... | ||
186 | call mutex_unlock |
212 | call mutex_unlock |
Line 187... | Line 213... | ||
187 | 213 | ||
188 | mov [ebx+TASKDATA.state], 1 |
214 | mov [ebx+TASKDATA.state], 1 |
Line -... | Line 215... | ||
- | 215 | call change_task |
|
- | 216 | ||
- | 217 | lea ecx, [ebp+PIPE.pipe_lock] |
|
189 | call change_task |
218 | call mutex_lock |
190 | 219 | ||
- | 220 | list_del esp |
|
191 | list_del esp |
221 | add esp, sizeof.MUTEX_WAITER |
Line 192... | Line 222... | ||
192 | add esp, sizeof.MUTEX_WAITER |
222 | popfd |
193 | jmp .again |
223 | jmp .again |
194 | 224 | ||
195 | .eof: |
225 | .eof: |
196 | mov [esp+SYSCALL_STACK._eax], eax |
226 | mov [esp+SYSCALL_STACK._eax], eax |
Line 197... | Line 227... | ||
197 | lea ecx, [ebp+PIPE.pipe_lock] |
227 | lea ecx, [ebp+PIPE.pipe_lock] |
198 | call mutex_unlock |
228 | call mutex_unlock |
199 | ret |
229 | ret |
Line 200... | Line 230... | ||
200 | 230 | ||
201 | ; edx buf |
231 | ; edx src_buf |
202 | ; esi count |
- | |
Line 203... | Line 232... | ||
203 | ; ebp pipe |
232 | ; esi write count |
- | 233 | ; ebp pipe |
|
- | 234 | ||
- | 235 | align 4 |
|
- | 236 | pipe_write: |
|
- | 237 | ||
204 | 238 | .written equ esp |
|
205 | align 4 |
239 | |
206 | pipe_write: |
240 | push 0 ;written |
207 | mov edi, edx |
241 | mov ebx, esi ;ebx = write count |
208 | 242 | mov esi, edx ;esi = src |
|
209 | .again: |
243 | |
Line 210... | Line 244... | ||
210 | lea ecx, [ebp+PIPE.pipe_lock] |
244 | lea ecx, [ebp+PIPE.pipe_lock] |
211 | call mutex_lock |
245 | call mutex_lock |
212 | 246 | .again: |
|
Line 213... | Line 247... | ||
213 | xor eax, eax |
247 | xor eax, eax |
214 | cmp eax, [ebp+PIPE.readers] |
248 | cmp eax, [ebp+PIPE.readers] |
215 | je .epipe |
249 | je .epipe |
216 | 250 | ||
217 | mov ecx, [ebp+PIPE.count] |
251 | mov ecx, 4096 |
218 | sub ecx, 4096 |
- | |
219 | jz .wait |
252 | sub ecx, [ebp+PIPE.count] |
220 | 253 | jz .wait ;wait if buffer full |
|
221 | .check_count: |
254 | |
- | 255 | .check_count: |
|
222 | cmp ecx, esi |
256 | cmp ecx, ebx |
- | 257 | jb .write |
|
223 | jb .write |
258 | mov ecx, ebx |
224 | mov ecx, esi |
259 | .write: |
225 | .write: |
260 | mov edi, [ebp+PIPE.buffer] |
226 | mov esi, edi |
261 | add edi, [ebp+PIPE.write_end] |
Line -... | Line 262... | ||
- | 262 | add [.written], ecx |
|
- | 263 | sub ebx, ecx |
|
- | 264 | add [ebp+PIPE.count], ecx |
|
- | 265 | ||
- | 266 | cld |
|
- | 267 | rep movsb |
|
- | 268 | and edi, 0xFFF |
|
- | 269 | mov [ebp+PIPE.write_end], edi |
|
- | 270 | ||
- | 271 | pushfd |
|
- | 272 | cli |
|
- | 273 | ||
- | 274 | lea eax, [ebp+PIPE.rlist] |
|
- | 275 | cmp eax, [ebp+PIPE.rlist.next] |
|
- | 276 | je @F |
|
- | 277 | ||
- | 278 | mov eax, [eax+MUTEX_WAITER.task] |
|
- | 279 | mov [eax+TASKDATA.state], 0 ;activate reader task |
|
- | 280 | @@: |
|
- | 281 | cmp [ebp+PIPE.count], 4096 |
|
- | 282 | je @F |
|
- | 283 | ||
227 | mov edi, [ebp+PIPE.buffer] |
284 | lea ecx, [ebp+PIPE.wlist] |
228 | add edi, [ebp+PIPE.write_end] |
285 | cmp ecx, [ebp+PIPE.wlist.next] |
- | 286 | je @F |
|
- | 287 | ||
- | 288 | mov ecx, [eax+MUTEX_WAITER.task] |
|
- | 289 | mov [ecx+TASKDATA.state], 0 ;activate writer task |
|
- | 290 | @@: |
|
- | 291 | popfd |
|
229 | mov [esp+SYSCALL_STACK._eax], ecx |
292 | |
Line 230... | Line 293... | ||
230 | add [ebp+PIPE.count], ecx |
293 | lea ecx, [ebp+PIPE.pipe_lock] |
- | 294 | call mutex_unlock |
|
- | 295 | ||
- | 296 | test ebx, ebx |
|
231 | cld |
297 | jnz .again |
232 | rep movsb |
298 | |
233 | and edi, 0xFFF |
299 | pop eax ; written |
234 | mov [ebp+PIPE.write_end], edi |
300 | mov [esp+SYSCALL_STACK._eax], eax |
Line 235... | Line 301... | ||
235 | 301 | ret |
|
Line 236... | Line 302... | ||
236 | lea ecx, [ebp+PIPE.pipe_lock] |
302 | |
237 | call mutex_unlock |
303 | .wait: |
Line 238... | Line 304... | ||
238 | ret |
304 | pushfd |
239 | 305 | cli |
|
Line -... | Line 306... | ||
- | 306 | ||
- | 307 | sub esp, sizeof.MUTEX_WAITER |
|
- | 308 | mov ecx, [TASK_BASE] |
|
240 | .wait: |
309 | mov [esp+MUTEX_WAITER.task], ecx |
241 | sub esp, sizeof.MUTEX_WAITER |
310 | lea edx, [ebp+PIPE.wlist] |
- | 311 | ||
242 | mov ebx, [TASK_BASE] |
312 | list_add_tail esp, edx ;esp= new waiter, edx= list head |
Line 243... | Line 313... | ||
243 | mov [esp+MUTEX_WAITER.task], ebx |
313 | |
244 | lea edx, [ebp+PIPE.wlist] |
- | |
245 | 314 | lea ecx, [ebp+PIPE.pipe_lock] |
|
246 | list_add_tail esp, edx ;esp= new waiter, edx= list head |
315 | call mutex_unlock |
- | 316 | ||
- | 317 | mov [ecx+TASKDATA.state], 1 |
|
- | 318 | call change_task |
|
247 | 319 | ||
Line 248... | Line 320... | ||
248 | lea ecx, [ebp+PIPE.pipe_lock] |
320 | lea ecx, [ebp+PIPE.pipe_lock] |
249 | call mutex_unlock |
321 | call mutex_lock |
250 | 322 |