Rev 5976 | Rev 6476 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5976 | Rev 6011 | ||
---|---|---|---|
Line 13... | Line 13... | ||
13 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; GNU GENERAL PUBLIC LICENSE ;; |
14 | ;; Version 2, June 1991 ;; |
14 | ;; Version 2, June 1991 ;; |
15 | ;; ;; |
15 | ;; ;; |
16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 17... | Line 17... | ||
17 | 17 | ||
Line 18... | Line 18... | ||
18 | $Revision: 5976 $ |
18 | $Revision: 6011 $ |
Line 19... | Line 19... | ||
19 | 19 | ||
20 | struct SOCKET |
20 | struct SOCKET |
Line 205... | Line 205... | ||
205 | endg |
205 | endg |
Line 206... | Line 206... | ||
206 | 206 | ||
207 | 207 | ||
208 | ;-----------------------------------------------------------------; |
208 | ;-----------------------------------------------------------------; |
209 | ; ; |
209 | ; ; |
210 | ; SOCKET_init ; |
210 | ; socket_init ; |
211 | ; ; |
211 | ; ; |
Line 212... | Line 212... | ||
212 | ;-----------------------------------------------------------------; |
212 | ;-----------------------------------------------------------------; |
213 | macro SOCKET_init { |
213 | macro socket_init { |
214 | 214 | ||
215 | xor eax, eax |
215 | xor eax, eax |
Line 249... | Line 249... | ||
249 | sys_socket: |
249 | sys_socket: |
Line 250... | Line 250... | ||
250 | 250 | ||
Line 251... | Line 251... | ||
251 | mov dword[esp+20], 0 ; Set error code to 0 |
251 | mov dword[esp+20], 0 ; Set error code to 0 |
252 | 252 | ||
Line 253... | Line 253... | ||
253 | cmp ebx, 255 |
253 | cmp ebx, 255 |
254 | jz SOCKET_debug |
254 | jz socket_debug |
255 | 255 | ||
Line 256... | Line 256... | ||
256 | cmp ebx, .number |
256 | cmp ebx, .number |
257 | ja .error |
257 | ja .error |
258 | jmp dword [.table + 4*ebx] |
258 | jmp dword [.table + 4*ebx] |
259 | 259 | ||
260 | .table: |
260 | .table: |
261 | dd SOCKET_open ; 0 |
261 | dd socket_open ; 0 |
262 | dd SOCKET_close ; 1 |
262 | dd socket_close ; 1 |
263 | dd SOCKET_bind ; 2 |
263 | dd socket_bind ; 2 |
264 | dd SOCKET_listen ; 3 |
264 | dd socket_listen ; 3 |
265 | dd SOCKET_connect ; 4 |
265 | dd socket_connect ; 4 |
266 | dd SOCKET_accept ; 5 |
266 | dd socket_accept ; 5 |
267 | dd SOCKET_send ; 6 |
267 | dd socket_send ; 6 |
268 | dd SOCKET_receive ; 7 |
268 | dd socket_receive ; 7 |
Line 269... | Line 269... | ||
269 | dd SOCKET_set_opt ; 8 |
269 | dd socket_set_opt ; 8 |
270 | dd SOCKET_get_opt ; 9 |
270 | dd socket_get_opt ; 9 |
271 | dd SOCKET_pair ; 10 |
271 | dd socket_pair ; 10 |
Line 272... | Line 272... | ||
272 | .number = ($ - .table) / 4 - 1 |
272 | .number = ($ - .table) / 4 - 1 |
Line 273... | Line 273... | ||
273 | 273 | ||
274 | .error: |
274 | .error: |
275 | mov dword[esp+32], -1 |
275 | mov dword[esp+32], -1 |
276 | mov dword[esp+20], EINVAL |
276 | mov dword[esp+20], EINVAL |
277 | 277 | ||
278 | ret |
278 | ret |
279 | 279 | ||
280 | ;-----------------------------------------------------------------; |
280 | ;-----------------------------------------------------------------; |
Line 289... | Line 289... | ||
289 | ; eax = -1 on error ; |
289 | ; eax = -1 on error ; |
290 | ; ebx = errorcode on error ; |
290 | ; ebx = errorcode on error ; |
291 | ; ; |
291 | ; ; |
292 | ;-----------------------------------------------------------------; |
292 | ;-----------------------------------------------------------------; |
293 | align 4 |
293 | align 4 |
294 | SOCKET_open: |
294 | socket_open: |
Line 295... | Line 295... | ||
295 | 295 | ||
Line 296... | Line 296... | ||
296 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_open: domain=%u type=%u protocol=%x ", ecx, edx, esi |
296 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_open: domain=%u type=%u protocol=%x ", ecx, edx, esi |
297 | 297 | ||
298 | push ecx edx esi |
298 | push ecx edx esi |
299 | call SOCKET_alloc |
299 | call socket_alloc |
300 | pop esi edx ecx |
300 | pop esi edx ecx |
Line 301... | Line 301... | ||
301 | test eax, eax |
301 | test eax, eax |
Line 337... | Line 337... | ||
337 | je .pppoe |
337 | je .pppoe |
Line 338... | Line 338... | ||
338 | 338 | ||
339 | .no_ppp: |
339 | .no_ppp: |
340 | .unsupported: |
340 | .unsupported: |
341 | push eax |
341 | push eax |
342 | call SOCKET_free |
342 | call socket_free |
343 | pop eax |
343 | pop eax |
344 | mov dword[esp+20], EOPNOTSUPP |
344 | mov dword[esp+20], EOPNOTSUPP |
345 | mov dword[esp+32], -1 |
345 | mov dword[esp+32], -1 |
Line 364... | Line 364... | ||
364 | push eax |
364 | push eax |
365 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
365 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
366 | pop eax |
366 | pop eax |
Line 367... | Line 367... | ||
367 | 367 | ||
368 | mov [eax + SOCKET.Protocol], IP_PROTO_UDP |
368 | mov [eax + SOCKET.Protocol], IP_PROTO_UDP |
369 | mov [eax + SOCKET.snd_proc], SOCKET_send_udp |
369 | mov [eax + SOCKET.snd_proc], socket_send_udp |
370 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram |
370 | mov [eax + SOCKET.rcv_proc], socket_receive_dgram |
371 | mov [eax + SOCKET.connect_proc], UDP_connect |
371 | mov [eax + SOCKET.connect_proc], udp_connect |
Line 372... | Line 372... | ||
372 | ret |
372 | ret |
373 | 373 | ||
374 | align 4 |
374 | align 4 |
375 | .tcp: |
375 | .tcp: |
376 | mov [eax + SOCKET.Protocol], IP_PROTO_TCP |
376 | mov [eax + SOCKET.Protocol], IP_PROTO_TCP |
377 | mov [eax + SOCKET.snd_proc], SOCKET_send_tcp |
377 | mov [eax + SOCKET.snd_proc], socket_send_tcp |
Line 378... | Line 378... | ||
378 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_stream |
378 | mov [eax + SOCKET.rcv_proc], socket_receive_stream |
379 | mov [eax + SOCKET.connect_proc], TCP_connect |
379 | mov [eax + SOCKET.connect_proc], tcp_connect |
Line 380... | Line 380... | ||
380 | 380 | ||
381 | TCP_init_socket eax |
381 | tcp_init_socket eax |
382 | ret |
382 | ret |
383 | 383 | ||
384 | 384 | ||
Line 385... | Line 385... | ||
385 | align 4 |
385 | align 4 |
386 | .raw_ip: |
386 | .raw_ip: |
387 | push eax |
387 | push eax |
388 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
388 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
Line 389... | Line 389... | ||
389 | pop eax |
389 | pop eax |
390 | 390 | ||
391 | mov [eax + SOCKET.snd_proc], SOCKET_send_ip |
391 | mov [eax + SOCKET.snd_proc], socket_send_ip |
392 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram |
392 | mov [eax + SOCKET.rcv_proc], socket_receive_dgram |
393 | mov [eax + SOCKET.connect_proc], IPv4_connect |
393 | mov [eax + SOCKET.connect_proc], ipv4_connect |
Line 394... | Line 394... | ||
394 | ret |
394 | ret |
395 | 395 | ||
396 | 396 | ||
397 | align 4 |
397 | align 4 |
Line 398... | Line 398... | ||
398 | .raw_icmp: |
398 | .raw_icmp: |
399 | push eax |
399 | push eax |
400 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
400 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
401 | pop eax |
401 | pop eax |
402 | 402 | ||
Line 403... | Line 403... | ||
403 | mov [eax + SOCKET.snd_proc], SOCKET_send_icmp |
403 | mov [eax + SOCKET.snd_proc], socket_send_icmp |
404 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram |
404 | mov [eax + SOCKET.rcv_proc], socket_receive_dgram |
405 | mov [eax + SOCKET.connect_proc], IPv4_connect |
405 | mov [eax + SOCKET.connect_proc], ipv4_connect |
Line 406... | Line 406... | ||
406 | ret |
406 | ret |
407 | 407 | ||
408 | align 4 |
408 | align 4 |
409 | .pppoe: |
409 | .pppoe: |
410 | push eax |
410 | push eax |
411 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
411 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
412 | pop eax |
412 | pop eax |
413 | 413 | ||
Line 428... | Line 428... | ||
428 | ; eax = -1 on error ; |
428 | ; eax = -1 on error ; |
429 | ; ebx = errorcode on error ; |
429 | ; ebx = errorcode on error ; |
430 | ; ; |
430 | ; ; |
431 | ;-----------------------------------------------------------------; |
431 | ;-----------------------------------------------------------------; |
432 | align 4 |
432 | align 4 |
433 | SOCKET_bind: |
433 | socket_bind: |
Line 434... | Line 434... | ||
434 | 434 | ||
Line 435... | Line 435... | ||
435 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi |
435 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi |
436 | 436 | ||
437 | call SOCKET_num_to_ptr |
437 | call socket_num_to_ptr |
Line 438... | Line 438... | ||
438 | test eax, eax |
438 | test eax, eax |
439 | jz .invalid |
439 | jz .invalid |
Line 477... | Line 477... | ||
477 | 477 | ||
Line 478... | Line 478... | ||
478 | jmp .notsupp |
478 | jmp .notsupp |
479 | 479 | ||
480 | .tcp: |
- | |
481 | .udp: |
480 | .tcp: |
482 | 481 | .udp: |
|
Line 483... | Line 482... | ||
483 | pushd [edx + 4] ; First, fill in the IP |
482 | pushd [edx + 4] ; First, fill in the IP |
484 | popd [eax + IP_SOCKET.LocalIP] |
483 | popd [eax + IP_SOCKET.LocalIP] |
485 | 484 | ||
486 | mov bx, [edx + 2] ; Did caller specify a local port? |
485 | mov bx, [edx + 2] ; Did caller specify a local port? |
487 | test bx, bx |
486 | test bx, bx |
Line 488... | Line 487... | ||
488 | jnz .just_check |
487 | jnz .just_check |
489 | call SOCKET_find_port ; Nope, find an ephemeral one |
488 | call socket_find_port ; Nope, find an ephemeral one |
490 | jmp .done |
489 | jmp .done |
Line 491... | Line 490... | ||
491 | 490 | ||
492 | .just_check: |
491 | .just_check: |
493 | call SOCKET_check_port ; Yes, check if it's still available |
492 | call socket_check_port ; Yes, check if it's still available |
Line 509... | Line 508... | ||
509 | 508 | ||
510 | 509 | ||
511 | 510 | ||
512 | ;-----------------------------------------------------------------; |
511 | ;-----------------------------------------------------------------; |
513 | ; ; |
512 | ; ; |
514 | ; SOCKET_connect: Connect to the remote host. ; |
513 | ; socket_connect: Connect to the remote host. ; |
515 | ; ; |
514 | ; ; |
516 | ; IN: ecx = socket number ; |
515 | ; IN: ecx = socket number ; |
Line 521... | Line 520... | ||
521 | ; eax = -1 on error ; |
520 | ; eax = -1 on error ; |
522 | ; ebx = errorcode on error ; |
521 | ; ebx = errorcode on error ; |
523 | ; ; |
522 | ; ; |
524 | ;-----------------------------------------------------------------; |
523 | ;-----------------------------------------------------------------; |
525 | align 4 |
524 | align 4 |
526 | SOCKET_connect: |
525 | socket_connect: |
Line 527... | Line 526... | ||
527 | 526 | ||
Line 528... | Line 527... | ||
528 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi |
527 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi |
529 | 528 | ||
530 | call SOCKET_num_to_ptr |
529 | call socket_num_to_ptr |
Line 531... | Line 530... | ||
531 | test eax, eax |
530 | test eax, eax |
532 | jz .invalid |
531 | jz .invalid |
Line 570... | Line 569... | ||
570 | ret |
569 | ret |
Line 571... | Line 570... | ||
571 | 570 | ||
572 | 571 | ||
573 | ;-----------------------------------------------------------------; |
572 | ;-----------------------------------------------------------------; |
574 | ; ; |
573 | ; ; |
575 | ; SOCKET_listen: Listen for incoming connections. ; |
574 | ; socket_listen: Listen for incoming connections. ; |
576 | ; ; |
575 | ; ; |
577 | ; IN: ecx = socket number ; |
576 | ; IN: ecx = socket number ; |
578 | ; edx = backlog in edx ; |
577 | ; edx = backlog in edx ; |
579 | ; ; |
578 | ; ; |
580 | ; OUT: eax = 0 on success ; |
579 | ; OUT: eax = 0 on success ; |
581 | ; eax = -1 on error ; |
580 | ; eax = -1 on error ; |
582 | ; ebx = errorcode on error ; |
581 | ; ebx = errorcode on error ; |
583 | ; ; |
582 | ; ; |
584 | ;-----------------------------------------------------------------; |
583 | ;-----------------------------------------------------------------; |
Line 585... | Line 584... | ||
585 | align 4 |
584 | align 4 |
Line 586... | Line 585... | ||
586 | SOCKET_listen: |
585 | socket_listen: |
587 | 586 | ||
588 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx |
587 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx |
Line 589... | Line 588... | ||
589 | 588 | ||
590 | call SOCKET_num_to_ptr |
589 | call socket_num_to_ptr |
Line 639... | Line 638... | ||
639 | ret |
638 | ret |
Line 640... | Line 639... | ||
640 | 639 | ||
641 | 640 | ||
642 | ;-----------------------------------------------------------------; |
641 | ;-----------------------------------------------------------------; |
643 | ; ; |
642 | ; ; |
644 | ; SOCKET_accept: Accept an incoming connection. ; |
643 | ; socket_accept: Accept an incoming connection. ; |
645 | ; ; |
644 | ; ; |
646 | ; IN: ecx = socket number (of listening socket) ; |
645 | ; IN: ecx = socket number (of listening socket) ; |
647 | ; edx = ptr to sockaddr struct ; |
646 | ; edx = ptr to sockaddr struct ; |
Line 651... | Line 650... | ||
651 | ; eax = -1 on error ; |
650 | ; eax = -1 on error ; |
652 | ; ebx = errorcode on error ; |
651 | ; ebx = errorcode on error ; |
653 | ; ; |
652 | ; ; |
654 | ;-----------------------------------------------------------------; |
653 | ;-----------------------------------------------------------------; |
655 | align 4 |
654 | align 4 |
656 | SOCKET_accept: |
655 | socket_accept: |
Line 657... | Line 656... | ||
657 | 656 | ||
Line 658... | Line 657... | ||
658 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi |
657 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi |
659 | 658 | ||
660 | call SOCKET_num_to_ptr |
659 | call socket_num_to_ptr |
Line 661... | Line 660... | ||
661 | test eax, eax |
660 | test eax, eax |
662 | jz .invalid |
661 | jz .invalid |
Line 675... | Line 674... | ||
675 | 674 | ||
676 | ; Ok, we got a socket ptr |
675 | ; Ok, we got a socket ptr |
Line 677... | Line 676... | ||
677 | mov eax, [esi] |
676 | mov eax, [esi] |
678 | 677 | ||
679 | ; Verify that it is (still) a valid socket |
678 | ; Verify that it is (still) a valid socket |
Line 680... | Line 679... | ||
680 | call SOCKET_check |
679 | call socket_check |
681 | jz .invalid |
680 | jz .invalid |
682 | 681 | ||
Line 692... | Line 691... | ||
692 | 691 | ||
693 | .block: |
692 | .block: |
694 | test [eax + SOCKET.options], SO_NONBLOCK |
693 | test [eax + SOCKET.options], SO_NONBLOCK |
Line 695... | Line 694... | ||
695 | jnz .wouldblock |
694 | jnz .wouldblock |
696 | 695 | ||
Line 697... | Line 696... | ||
697 | call SOCKET_block |
696 | call socket_block |
698 | jmp .loop |
697 | jmp .loop |
699 | 698 | ||
Line 712... | Line 711... | ||
712 | mov dword[esp+32], -1 |
711 | mov dword[esp+32], -1 |
713 | ret |
712 | ret |
Line 714... | Line 713... | ||
714 | 713 | ||
715 | ;-----------------------------------------------------------------; |
714 | ;-----------------------------------------------------------------; |
716 | ; ; |
715 | ; ; |
717 | ; SOCKET_close: Close the socket (and connection). ; |
716 | ; socket_close: Close the socket (and connection). ; |
718 | ; ; |
717 | ; ; |
719 | ; IN: ecx = socket number ; |
718 | ; IN: ecx = socket number ; |
720 | ; ; |
719 | ; ; |
721 | ; OUT: eax = 0 on success ; |
720 | ; OUT: eax = 0 on success ; |
722 | ; eax = -1 on error ; |
721 | ; eax = -1 on error ; |
723 | ; ebx = errorcode on error ; |
722 | ; ebx = errorcode on error ; |
724 | ; ; |
723 | ; ; |
725 | ;-----------------------------------------------------------------; |
724 | ;-----------------------------------------------------------------; |
726 | align 4 |
725 | align 4 |
Line 727... | Line 726... | ||
727 | SOCKET_close: |
726 | socket_close: |
Line 728... | Line 727... | ||
728 | 727 | ||
729 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_close: socknum=%u\n", ecx |
728 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_close: socknum=%u\n", ecx |
730 | 729 | ||
Line 731... | Line 730... | ||
731 | call SOCKET_num_to_ptr |
730 | call socket_num_to_ptr |
Line 732... | Line 731... | ||
732 | test eax, eax |
731 | test eax, eax |
Line 733... | Line 732... | ||
733 | jz .invalid |
732 | jz .invalid |
734 | 733 | ||
735 | mov dword[esp+32], 0 ; The socket exists, so we will succeed in closing it. |
734 | mov dword[esp+32], 0 ; The socket exists, so we will succeed in closing it. |
736 | 735 | ||
Line 737... | Line 736... | ||
737 | or [eax + SOCKET.options], SO_NONBLOCK ; Mark the socket as non blocking, we dont want it to block any longer! |
736 | or [eax + SOCKET.options], SO_NONBLOCK ; Mark the socket as non blocking, we dont want it to block any longer! |
738 | 737 | ||
Line 739... | Line 738... | ||
739 | test [eax + SOCKET.state], SS_BLOCKED ; Is the socket still in blocked state? |
738 | test [eax + SOCKET.state], SS_BLOCKED ; Is the socket still in blocked state? |
740 | jz @f |
739 | jz @f |
Line 741... | Line 740... | ||
741 | call SOCKET_notify ; Unblock it. |
740 | call socket_notify ; Unblock it. |
742 | @@: |
741 | @@: |
743 | 742 | ||
Line 744... | Line 743... | ||
744 | cmp [eax + SOCKET.Domain], AF_INET4 |
743 | cmp [eax + SOCKET.Domain], AF_INET4 |
745 | jne .free |
744 | jne .free |
Line 746... | Line 745... | ||
746 | 745 | ||
747 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
746 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
748 | je .tcp |
747 | je .tcp |
749 | 748 | ||
750 | .free: |
749 | .free: |
Line 751... | Line 750... | ||
751 | call SOCKET_free |
750 | call socket_free |
Line 767... | Line 766... | ||
767 | ret |
766 | ret |
Line 768... | Line 767... | ||
768 | 767 | ||
769 | 768 | ||
770 | ;-----------------------------------------------------------------; |
769 | ;-----------------------------------------------------------------; |
771 | ; ; |
770 | ; ; |
772 | ; SOCKET_receive: Receive some data from the remote end. ; |
771 | ; socket_receive: Receive some data from the remote end. ; |
773 | ; ; |
772 | ; ; |
774 | ; IN: ecx = socket number ; |
773 | ; IN: ecx = socket number ; |
775 | ; edx = addr to application buffer ; |
774 | ; edx = addr to application buffer ; |
Line 781... | Line 780... | ||
781 | ; eax = 0 when socket has been closed by the remote end ; |
780 | ; eax = 0 when socket has been closed by the remote end ; |
782 | ; ebx = errorcode on error ; |
781 | ; ebx = errorcode on error ; |
783 | ; ; |
782 | ; ; |
784 | ;-----------------------------------------------------------------; |
783 | ;-----------------------------------------------------------------; |
785 | align 4 |
784 | align 4 |
786 | SOCKET_receive: |
785 | socket_receive: |
Line 787... | Line 786... | ||
787 | 786 | ||
Line 788... | Line 787... | ||
788 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi |
787 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi |
789 | 788 | ||
790 | call SOCKET_num_to_ptr |
789 | call socket_num_to_ptr |
Line 791... | Line 790... | ||
791 | test eax, eax |
790 | test eax, eax |
792 | jz .invalid |
791 | jz .invalid |
Line 806... | Line 805... | ||
806 | jnz .return_err |
805 | jnz .return_err |
Line 807... | Line 806... | ||
807 | 806 | ||
808 | test [eax + SOCKET.options], SO_NONBLOCK |
807 | test [eax + SOCKET.options], SO_NONBLOCK |
Line 809... | Line 808... | ||
809 | jnz .return_err |
808 | jnz .return_err |
810 | 809 | ||
Line 811... | Line 810... | ||
811 | call SOCKET_block |
810 | call socket_block |
812 | jmp .loop |
811 | jmp .loop |
Line 823... | Line 822... | ||
823 | ret |
822 | ret |
Line 824... | Line 823... | ||
824 | 823 | ||
825 | .last_data: |
824 | .last_data: |
826 | test ecx, ecx |
825 | test ecx, ecx |
827 | jz .return |
826 | jz .return |
828 | call SOCKET_notify ; Call me again! |
827 | call socket_notify ; Call me again! |
Line 829... | Line 828... | ||
829 | jmp .return |
828 | jmp .return |
830 | 829 | ||
Line 831... | Line 830... | ||
831 | 830 | ||
Line 832... | Line 831... | ||
832 | 831 | ||
833 | 832 | ||
Line 866... | Line 865... | ||
866 | test ecx, ecx |
865 | test ecx, ecx |
867 | jz .nd |
866 | jz .nd |
868 | rep movsd |
867 | rep movsd |
869 | .nd: |
868 | .nd: |
Line 870... | Line 869... | ||
870 | 869 | ||
871 | call NET_BUFF_free |
870 | call net_buff_free |
872 | pop ecx eax ; return number of bytes copied to application |
871 | pop ecx eax ; return number of bytes copied to application |
873 | cmp [eax + SOCKET_QUEUE_LOCATION + queue.size], 0 |
872 | cmp [eax + SOCKET_QUEUE_LOCATION + queue.size], 0 |
874 | je @f |
873 | je @f |
875 | call SOCKET_notify ; Queue another network event |
874 | call socket_notify ; Queue another network event |
876 | @@: |
875 | @@: |
877 | xor ebx, ebx ; errorcode = 0 (no error) |
876 | xor ebx, ebx ; errorcode = 0 (no error) |
Line 878... | Line 877... | ||
878 | ret |
877 | ret |
Line 898... | Line 897... | ||
898 | @@: |
897 | @@: |
899 | ret |
898 | ret |
Line 900... | Line 899... | ||
900 | 899 | ||
901 | 900 | ||
Line 902... | Line 901... | ||
902 | align 4 |
901 | align 4 |
903 | SOCKET_receive_local: |
902 | socket_receive_local: |
904 | 903 | ||
Line 911... | Line 910... | ||
911 | mov ebx, [ebx + TASKDATA.pid] |
910 | mov ebx, [ebx + TASKDATA.pid] |
912 | mov [eax + SOCKET.PID], ebx |
911 | mov [eax + SOCKET.PID], ebx |
913 | mov [eax + SOCKET.TID], ebx ; currently TID = PID in kolibrios :( |
912 | mov [eax + SOCKET.TID], ebx ; currently TID = PID in kolibrios :( |
914 | @@: |
913 | @@: |
Line 915... | Line 914... | ||
915 | 914 | ||
Line 916... | Line 915... | ||
916 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_stream |
915 | mov [eax + SOCKET.rcv_proc], socket_receive_stream |
Line 917... | Line 916... | ||
917 | 916 | ||
918 | ; ... continue to SOCKET_receive_stream |
917 | ; ... continue to SOCKET_receive_stream |
Line 919... | Line 918... | ||
919 | 918 | ||
Line 920... | Line 919... | ||
920 | align 4 |
919 | align 4 |
921 | SOCKET_receive_stream: |
920 | socket_receive_stream: |
Line 932... | Line 931... | ||
932 | mov edi, edx |
931 | mov edi, edx |
933 | xor edx, edx |
932 | xor edx, edx |
Line 934... | Line 933... | ||
934 | 933 | ||
935 | push eax |
934 | push eax |
936 | add eax, STREAM_SOCKET.rcv |
935 | add eax, STREAM_SOCKET.rcv |
937 | call SOCKET_ring_read ; copy data from kernel buffer to application buffer |
936 | call socket_ring_read ; copy data from kernel buffer to application buffer |
938 | call SOCKET_ring_free ; free read memory |
937 | call socket_ring_free ; free read memory |
Line 939... | Line 938... | ||
939 | pop eax |
938 | pop eax |
940 | 939 | ||
941 | cmp [eax + STREAM_SOCKET.rcv + RING_BUFFER.size], 0 |
940 | cmp [eax + STREAM_SOCKET.rcv + RING_BUFFER.size], 0 |
942 | jne .more_data |
941 | jne .more_data |
Line 943... | Line 942... | ||
943 | xor ebx, ebx ; errorcode = 0 (no error) |
942 | xor ebx, ebx ; errorcode = 0 (no error) |
944 | ret |
943 | ret |
945 | 944 | ||
946 | .more_data: |
945 | .more_data: |
Line 947... | Line 946... | ||
947 | call SOCKET_notify ; Queue another network event |
946 | call socket_notify ; Queue another network event |
948 | xor ebx, ebx ; errorcode = 0 (no error) |
947 | xor ebx, ebx ; errorcode = 0 (no error) |
Line 960... | Line 959... | ||
960 | ret |
959 | ret |
Line 961... | Line 960... | ||
961 | 960 | ||
962 | 961 | ||
963 | ;-----------------------------------------------------------------; |
962 | ;-----------------------------------------------------------------; |
964 | ; ; |
963 | ; ; |
965 | ; SOCKET_send: Send some data to the remote end. ; |
964 | ; socket_send: Send some data to the remote end. ; |
966 | ; ; |
965 | ; ; |
967 | ; IN: ecx = socket number ; |
966 | ; IN: ecx = socket number ; |
968 | ; edx = pointer to data ; |
967 | ; edx = pointer to data ; |
Line 973... | Line 972... | ||
973 | ; eax = -1 on error ; |
972 | ; eax = -1 on error ; |
974 | ; ebx = errorcode on error ; |
973 | ; ebx = errorcode on error ; |
975 | ; ; |
974 | ; ; |
976 | ;-----------------------------------------------------------------; |
975 | ;-----------------------------------------------------------------; |
977 | align 4 |
976 | align 4 |
978 | SOCKET_send: |
977 | socket_send: |
Line 979... | Line 978... | ||
979 | 978 | ||
Line 980... | Line 979... | ||
980 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi |
979 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi |
981 | 980 | ||
982 | call SOCKET_num_to_ptr |
981 | call socket_num_to_ptr |
Line 983... | Line 982... | ||
983 | test eax, eax |
982 | test eax, eax |
984 | jz .invalid |
983 | jz .invalid |
Line 993... | Line 992... | ||
993 | mov dword[esp+32], -1 |
992 | mov dword[esp+32], -1 |
994 | ret |
993 | ret |
Line 995... | Line 994... | ||
995 | 994 | ||
996 | 995 | ||
Line 997... | Line 996... | ||
997 | align 4 |
996 | align 4 |
Line 998... | Line 997... | ||
998 | SOCKET_send_udp: |
997 | socket_send_udp: |
999 | 998 | ||
1000 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: UDP\n" |
999 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: UDP\n" |
1001 | 1000 | ||
1002 | mov [esp+32], ecx |
1001 | mov [esp+32], ecx |
Line 1003... | Line 1002... | ||
1003 | call UDP_output |
1002 | call udp_output |
Line 1010... | Line 1009... | ||
1010 | mov dword[esp+20], EMSGSIZE ; FIXME: UDP_output should return error codes! |
1009 | mov dword[esp+20], EMSGSIZE ; FIXME: UDP_output should return error codes! |
1011 | ret |
1010 | ret |
Line 1012... | Line 1011... | ||
1012 | 1011 | ||
1013 | 1012 | ||
Line 1014... | Line 1013... | ||
1014 | align 4 |
1013 | align 4 |
Line 1015... | Line 1014... | ||
1015 | SOCKET_send_tcp: |
1014 | socket_send_tcp: |
1016 | 1015 | ||
1017 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: TCP\n" |
1016 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: TCP\n" |
1018 | 1017 | ||
Line 1019... | Line 1018... | ||
1019 | push eax |
1018 | push eax |
1020 | add eax, STREAM_SOCKET.snd |
1019 | add eax, STREAM_SOCKET.snd |
1021 | call SOCKET_ring_write |
1020 | call socket_ring_write |
1022 | pop eax |
1021 | pop eax |
1023 | 1022 | ||
1024 | mov [esp+32], ecx |
1023 | mov [esp+32], ecx |
1025 | mov [eax + SOCKET.errorcode], 0 |
1024 | mov [eax + SOCKET.errorcode], 0 |
1026 | push eax |
1025 | push eax |
Line 1027... | Line 1026... | ||
1027 | call TCP_output ; FIXME: this doesnt look pretty, does it? |
1026 | call tcp_output ; FIXME: this doesnt look pretty, does it? |
1028 | pop eax |
1027 | pop eax |
Line 1029... | Line 1028... | ||
1029 | mov eax, [eax + SOCKET.errorcode] |
1028 | mov eax, [eax + SOCKET.errorcode] |
Line 1030... | Line 1029... | ||
1030 | mov [esp+20], eax |
1029 | mov [esp+20], eax |
1031 | ret |
1030 | ret |
1032 | 1031 | ||
1033 | 1032 | ||
1034 | align 4 |
1033 | align 4 |
Line 1035... | Line 1034... | ||
1035 | SOCKET_send_ip: |
1034 | socket_send_ip: |
Line 1047... | Line 1046... | ||
1047 | mov dword[esp+20], ebx |
1046 | mov dword[esp+20], ebx |
1048 | ret |
1047 | ret |
Line 1049... | Line 1048... | ||
1049 | 1048 | ||
1050 | 1049 | ||
Line 1051... | Line 1050... | ||
1051 | align 4 |
1050 | align 4 |
Line 1052... | Line 1051... | ||
1052 | SOCKET_send_icmp: |
1051 | socket_send_icmp: |
1053 | 1052 | ||
1054 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: ICMP\n" |
1053 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: ICMP\n" |
1055 | 1054 | ||
1056 | mov [esp+32], ecx |
1055 | mov [esp+32], ecx |
Line 1057... | Line 1056... | ||
1057 | call ICMP_output_raw |
1056 | call icmp_output_raw |
Line 1064... | Line 1063... | ||
1064 | mov dword[esp+20], ebx |
1063 | mov dword[esp+20], ebx |
1065 | ret |
1064 | ret |
Line 1066... | Line 1065... | ||
1066 | 1065 | ||
1067 | 1066 | ||
Line 1068... | Line 1067... | ||
1068 | align 4 |
1067 | align 4 |
Line 1069... | Line 1068... | ||
1069 | SOCKET_send_pppoe: |
1068 | socket_send_pppoe: |
1070 | 1069 | ||
Line 1071... | Line 1070... | ||
1071 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: PPPoE\n" |
1070 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: PPPoE\n" |
1072 | 1071 | ||
1073 | mov [esp+32], ecx |
1072 | mov [esp+32], ecx |
1074 | mov ebx, [eax + SOCKET.device] |
1073 | mov ebx, [eax + SOCKET.device] |
Line 1075... | Line 1074... | ||
1075 | 1074 | ||
Line 1084... | Line 1083... | ||
1084 | ret |
1083 | ret |
Line 1085... | Line 1084... | ||
1085 | 1084 | ||
1086 | 1085 | ||
Line 1087... | Line 1086... | ||
1087 | 1086 | ||
1088 | align 4 |
1087 | align 4 |
1089 | SOCKET_send_local: |
1088 | socket_send_local: |
Line 1096... | Line 1095... | ||
1096 | mov ebx, [TASK_BASE] |
1095 | mov ebx, [TASK_BASE] |
1097 | mov ebx, [ebx + TASKDATA.pid] |
1096 | mov ebx, [ebx + TASKDATA.pid] |
1098 | mov [eax + SOCKET.PID], ebx |
1097 | mov [eax + SOCKET.PID], ebx |
1099 | mov [eax + SOCKET.TID], ebx ; currently TID = PID in kolibrios :( |
1098 | mov [eax + SOCKET.TID], ebx ; currently TID = PID in kolibrios :( |
1100 | @@: |
1099 | @@: |
1101 | mov [eax + SOCKET.snd_proc], SOCKET_send_local_ |
1100 | mov [eax + SOCKET.snd_proc], socket_send_local_initialized |
Line 1102... | Line 1101... | ||
1102 | 1101 | ||
1103 | align 4 |
1102 | align 4 |
Line 1104... | Line 1103... | ||
1104 | SOCKET_send_local_: |
1103 | socket_send_local_initialized: |
Line 1105... | Line 1104... | ||
1105 | 1104 | ||
1106 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: LOCAL\n" |
1105 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_send: LOCAL\n" |
1107 | 1106 | ||
1108 | ; get the other side's socket and check if it still exists |
1107 | ; get the other side's socket and check if it still exists |
Line 1109... | Line 1108... | ||
1109 | mov eax, [eax + SOCKET.device] |
1108 | mov eax, [eax + SOCKET.device] |
1110 | call SOCKET_check |
1109 | call socket_check |
1111 | jz .invalid |
1110 | jz .invalid |
1112 | 1111 | ||
1113 | ; allright, shove in the data! |
1112 | ; allright, shove in the data! |
Line 1114... | Line 1113... | ||
1114 | push eax |
1113 | push eax |
1115 | add eax, STREAM_SOCKET.rcv |
1114 | add eax, STREAM_SOCKET.rcv |
Line 1116... | Line 1115... | ||
1116 | call SOCKET_ring_write |
1115 | call socket_ring_write |
1117 | pop eax |
1116 | pop eax |
Line 1118... | Line 1117... | ||
1118 | 1117 | ||
Line 1119... | Line 1118... | ||
1119 | ; return the number of written bytes (or errorcode) to application |
1118 | ; return the number of written bytes (or errorcode) to application |
1120 | mov [esp+32], ecx |
1119 | mov [esp+32], ecx |
Line 1130... | Line 1129... | ||
1130 | ret |
1129 | ret |
Line 1131... | Line 1130... | ||
1131 | 1130 | ||
1132 | 1131 | ||
1133 | ;-----------------------------------------------------------------; |
1132 | ;-----------------------------------------------------------------; |
1134 | ; ; |
1133 | ; ; |
1135 | ; SOCKET_get_options: Read a socket option ; |
1134 | ; socket_get_opt: Read a socket option ; |
1136 | ; ; |
1135 | ; ; |
1137 | ; IN: ecx = socket number ; |
1136 | ; IN: ecx = socket number ; |
1138 | ; edx = pointer to socket options struct ; |
1137 | ; edx = pointer to socket options struct ; |
1139 | ; ; |
1138 | ; ; |
1140 | ; OUT: eax = 0 on success ; |
1139 | ; OUT: eax = 0 on success ; |
1141 | ; eax = -1 on error ; |
1140 | ; eax = -1 on error ; |
1142 | ; ebx = errorcode on error ; |
1141 | ; ebx = errorcode on error ; |
1143 | ; ; |
1142 | ; ; |
1144 | ;-----------------------------------------------------------------; |
1143 | ;-----------------------------------------------------------------; |
Line 1145... | Line 1144... | ||
1145 | align 4 |
1144 | align 4 |
1146 | SOCKET_get_opt: |
1145 | socket_get_opt: |
1147 | 1146 | ||
1148 | ; FIXME: |
1147 | ; FIXME: |
Line 1149... | Line 1148... | ||
1149 | ; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP. |
1148 | ; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP. |
Line 1150... | Line 1149... | ||
1150 | ; TODO: find best way to notify that send()'ed data were acknowledged |
1149 | ; TODO: find best way to notify that send()'ed data were acknowledged |
1151 | ; Also pseudo-optname -3 is valid and returns socket state, one of TCPS_*. |
1150 | ; Also pseudo-optname -3 is valid and returns socket state, one of TCPS_*. |
1152 | 1151 | ||
Line 1153... | Line 1152... | ||
1153 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_get_opt\n" |
1152 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_get_opt\n" |
1154 | 1153 | ||
Line 1192... | Line 1191... | ||
1192 | ret |
1191 | ret |
Line 1193... | Line 1192... | ||
1193 | 1192 | ||
1194 | 1193 | ||
1195 | ;-----------------------------------------------------------------; |
1194 | ;-----------------------------------------------------------------; |
1196 | ; ; |
1195 | ; ; |
1197 | ; SOCKET_set_options: Set a socket option. ; |
1196 | ; socket_set_options: Set a socket option. ; |
1198 | ; ; |
1197 | ; ; |
1199 | ; IN: ecx = socket number ; |
1198 | ; IN: ecx = socket number ; |
1200 | ; edx = pointer to socket options struct ; |
1199 | ; edx = pointer to socket options struct ; |
1201 | ; ; |
1200 | ; ; |
1202 | ; OUT: eax = 0 on success ; |
1201 | ; OUT: eax = 0 on success ; |
1203 | ; eax = -1 on error ; |
1202 | ; eax = -1 on error ; |
1204 | ; ebx = errorcode on error ; |
1203 | ; ebx = errorcode on error ; |
1205 | ; ; |
1204 | ; ; |
1206 | ;-----------------------------------------------------------------; |
1205 | ;-----------------------------------------------------------------; |
Line 1207... | Line 1206... | ||
1207 | align 4 |
1206 | align 4 |
Line 1208... | Line 1207... | ||
1208 | SOCKET_set_opt: |
1207 | socket_set_opt: |
1209 | 1208 | ||
1210 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_set_opt\n" |
1209 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_set_opt\n" |
Line 1211... | Line 1210... | ||
1211 | 1210 | ||
1212 | call SOCKET_num_to_ptr |
1211 | call socket_num_to_ptr |
Line 1270... | Line 1269... | ||
1270 | 1269 | ||
1271 | 1270 | ||
1272 | 1271 | ||
1273 | ;-----------------------------------------------------------------; |
1272 | ;-----------------------------------------------------------------; |
1274 | ; ; |
1273 | ; ; |
1275 | ; SOCKET_pair: Allocate a pair of linked local sockets. ; |
1274 | ; socket_pair: Allocate a pair of linked local sockets. ; |
1276 | ; ; |
1275 | ; ; |
1277 | ; IN: / ; |
1276 | ; IN: / ; |
1278 | ; ; |
1277 | ; ; |
1279 | ; OUT: eax = socket1 num on success ; |
1278 | ; OUT: eax = socket1 num on success ; |
1280 | ; eax = -1 on error ; |
1279 | ; eax = -1 on error ; |
1281 | ; ebx = socket2 num on success ; |
1280 | ; ebx = socket2 num on success ; |
1282 | ; ebx = errorcode on error ; |
1281 | ; ebx = errorcode on error ; |
1283 | ; ; |
1282 | ; ; |
Line 1284... | Line 1283... | ||
1284 | ;-----------------------------------------------------------------; |
1283 | ;-----------------------------------------------------------------; |
Line 1285... | Line 1284... | ||
1285 | align 4 |
1284 | align 4 |
1286 | SOCKET_pair: |
1285 | socket_pair: |
1287 | 1286 | ||
1288 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_pair\n" |
1287 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_pair\n" |
Line 1289... | Line 1288... | ||
1289 | 1288 | ||
1290 | call SOCKET_alloc |
1289 | call socket_alloc |
1291 | test eax, eax |
1290 | test eax, eax |
1292 | jz .nomem1 |
1291 | jz .nomem1 |
1293 | mov [esp+32], edi ; application's eax |
1292 | mov [esp+32], edi ; application's eax |
1294 | 1293 | ||
1295 | mov [eax + SOCKET.Domain], AF_LOCAL |
1294 | mov [eax + SOCKET.Domain], AF_LOCAL |
Line 1296... | Line 1295... | ||
1296 | mov [eax + SOCKET.Type], SOCK_STREAM |
1295 | mov [eax + SOCKET.Type], SOCK_STREAM |
1297 | mov [eax + SOCKET.Protocol], 0 ;;; CHECKME |
1296 | mov [eax + SOCKET.Protocol], 0 ;;; CHECKME |
1298 | mov [eax + SOCKET.snd_proc], SOCKET_send_local |
1297 | mov [eax + SOCKET.snd_proc], socket_send_local |
1299 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_local |
1298 | mov [eax + SOCKET.rcv_proc], socket_receive_local |
Line 1300... | Line 1299... | ||
1300 | mov [eax + SOCKET.PID], 0 |
1299 | mov [eax + SOCKET.PID], 0 |
1301 | mov ebx, eax |
1300 | mov ebx, eax |
1302 | 1301 | ||
1303 | call SOCKET_alloc |
1302 | call socket_alloc |
1304 | test eax, eax |
1303 | test eax, eax |
1305 | jz .nomem2 |
1304 | jz .nomem2 |
Line 1306... | Line 1305... | ||
1306 | mov [esp+20], edi ; application's ebx |
1305 | mov [esp+20], edi ; application's ebx |
1307 | 1306 | ||
1308 | mov [eax + SOCKET.Domain], AF_LOCAL |
1307 | mov [eax + SOCKET.Domain], AF_LOCAL |
Line 1309... | Line 1308... | ||
1309 | mov [eax + SOCKET.Type], SOCK_STREAM |
1308 | mov [eax + SOCKET.Type], SOCK_STREAM |
1310 | mov [eax + SOCKET.Protocol], 0 ;;; CHECKME |
1309 | mov [eax + SOCKET.Protocol], 0 ;;; CHECKME |
1311 | mov [eax + SOCKET.snd_proc], SOCKET_send_local |
1310 | mov [eax + SOCKET.snd_proc], socket_send_local |
1312 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_local |
1311 | mov [eax + SOCKET.rcv_proc], socket_receive_local |
Line 1313... | Line 1312... | ||
1313 | mov [eax + SOCKET.PID], 0 |
1312 | mov [eax + SOCKET.PID], 0 |
1314 | 1313 | ||
1315 | ; Link the two sockets to eachother |
1314 | ; Link the two sockets to eachother |
1316 | mov [eax + SOCKET.device], ebx |
1315 | mov [eax + SOCKET.device], ebx |
Line 1317... | Line 1316... | ||
1317 | mov [ebx + SOCKET.device], eax |
1316 | mov [ebx + SOCKET.device], eax |
Line 1318... | Line 1317... | ||
1318 | 1317 | ||
1319 | lea eax, [eax + STREAM_SOCKET.rcv] |
1318 | lea eax, [eax + STREAM_SOCKET.rcv] |
1320 | call SOCKET_ring_create |
1319 | call socket_ring_create |
Line 1321... | Line 1320... | ||
1321 | test eax, eax |
1320 | test eax, eax |
1322 | jz .nomem2 |
1321 | jz .nomem2 |
1323 | 1322 | ||
Line 1324... | Line 1323... | ||
1324 | lea eax, [ebx + STREAM_SOCKET.rcv] |
1323 | lea eax, [ebx + STREAM_SOCKET.rcv] |
1325 | call SOCKET_ring_create |
1324 | call socket_ring_create |
1326 | test eax, eax |
1325 | test eax, eax |
Line 1327... | Line 1326... | ||
1327 | jz .nomem2 |
1326 | jz .nomem2 |
1328 | 1327 | ||
1329 | ret |
1328 | ret |
1330 | 1329 | ||
1331 | .nomem2: |
1330 | .nomem2: |
1332 | mov eax, [esp+20] |
1331 | mov eax, [esp+20] |
1333 | call SOCKET_free |
1332 | call socket_free |
1334 | 1333 | ||
1335 | .nomem1: |
1334 | .nomem1: |
1336 | mov eax, [esp+32] |
1335 | mov eax, [esp+32] |
1337 | call SOCKET_free |
1336 | call socket_free |
1338 | 1337 | ||
1339 | mov dword[esp+32], -1 |
1338 | mov dword[esp+32], -1 |
1340 | mov dword[esp+20], ENOMEM |
1339 | mov dword[esp+20], ENOMEM |
Line 1341... | Line 1340... | ||
1341 | ret |
1340 | ret |
Line 1342... | Line 1341... | ||
1342 | 1341 | ||
Line 1343... | Line 1342... | ||
1343 | 1342 | ||
1344 | 1343 | ||
Line 1345... | Line 1344... | ||
1345 | ;-----------------------------------------------------------------; |
1344 | ;-----------------------------------------------------------------; |
1346 | ; ; |
1345 | ; ; |
1347 | ; SOCKET_debug: Copy socket variables to application buffer. ; |
1346 | ; socket_debug: Copy socket variables to application buffer. ; |
Line 1348... | Line 1347... | ||
1348 | ; ; |
1347 | ; ; |
1349 | ; IN: ecx = socket number ; |
1348 | ; IN: ecx = socket number ; |
Line 1405... | Line 1404... | ||
1405 | ;-----------------------------------------------------------------; |
1404 | ;-----------------------------------------------------------------; |
Line 1406... | Line 1405... | ||
1406 | 1405 | ||
1407 | 1406 | ||
1408 | ;-----------------------------------------------------------------; |
1407 | ;-----------------------------------------------------------------; |
1409 | ; ; |
1408 | ; ; |
1410 | ; SOCKET_find_port: ; |
1409 | ; socket_find_port: ; |
1411 | ; Fill in the local port number for TCP and UDP sockets ; |
1410 | ; Fill in the local port number for TCP and UDP sockets ; |
1412 | ; This procedure always works because the number of sockets is ; |
1411 | ; This procedure always works because the number of sockets is ; |
1413 | ; limited to a smaller number then the number of possible ports ; |
1412 | ; limited to a smaller number then the number of possible ports ; |
1414 | ; ; |
1413 | ; ; |
1415 | ; IN: eax = socket pointer ; |
1414 | ; IN: eax = socket pointer ; |
1416 | ; ; |
1415 | ; ; |
1417 | ; OUT: / ; |
1416 | ; OUT: / ; |
1418 | ; ; |
1417 | ; ; |
1419 | ;-----------------------------------------------------------------; |
1418 | ;-----------------------------------------------------------------; |
Line 1420... | Line 1419... | ||
1420 | align 4 |
1419 | align 4 |
Line 1421... | Line 1420... | ||
1421 | SOCKET_find_port: |
1420 | socket_find_port: |
Line 1457... | Line 1456... | ||
1457 | je .restart |
1456 | je .restart |
Line 1458... | Line 1457... | ||
1458 | 1457 | ||
1459 | add bh, 1 |
1458 | add bh, 1 |
Line 1460... | Line 1459... | ||
1460 | adc bl, 0 |
1459 | adc bl, 0 |
1461 | 1460 | ||
1462 | call SOCKET_check_port |
1461 | call socket_check_port |
Line 1463... | Line 1462... | ||
1463 | jz .findit |
1462 | jz .findit |
1464 | ret |
1463 | ret |
1465 | 1464 | ||
1466 | - | ||
1467 | 1465 | ||
1468 | ;-----------------------------------------------------------------; |
1466 | |
1469 | ; ; |
1467 | ;-----------------------------------------------------------------; |
1470 | ; SOCKET_check_port (to be used with AF_INET only!) ; |
1468 | ; ; |
1471 | ; ; |
1469 | ; socket_check_port: (to be used with AF_INET only!) ; |
1472 | ; Checks if a local port number is unused ; |
1470 | ; Checks if a local port number is unused ; |
1473 | ; If the proposed port number is unused, it is filled in in the ; |
1471 | ; If the proposed port number is unused, it is filled in in the ; |
1474 | ; socket structure ; |
1472 | ; socket structure. ; |
1475 | ; ; |
1473 | ; ; |
1476 | ; IN: eax = socket ptr ; |
1474 | ; IN: eax = socket ptr ; |
1477 | ; bx = proposed socket number (network byte order) ; |
1475 | ; bx = proposed socket number (network byte order) ; |
1478 | ; ; |
1476 | ; ; |
Line 1479... | Line 1477... | ||
1479 | ; OUT: ZF = set on error ; |
1477 | ; OUT: ZF = set on error ; |
Line 1480... | Line 1478... | ||
1480 | ; ; |
1478 | ; ; |
1481 | ;-----------------------------------------------------------------; |
1479 | ;-----------------------------------------------------------------; |
Line 1528... | Line 1526... | ||
1528 | 1526 | ||
1529 | 1527 | ||
1530 | 1528 | ||
1531 | ;-----------------------------------------------------------------; |
1529 | ;-----------------------------------------------------------------; |
1532 | ; ; |
1530 | ; ; |
1533 | ; SOCKET_input: Update a (stateless) socket with received data. ; |
1531 | ; socket_input: Update a (stateless) socket with received data. ; |
1534 | ; ; |
1532 | ; ; |
1535 | ; Note: The socket's mutex should already be set ! ; |
1533 | ; Note: The socket's mutex should already be set ! ; |
Line 1541... | Line 1539... | ||
1541 | ; ; |
1539 | ; ; |
1542 | ; OUT: / ; |
1540 | ; OUT: / ; |
1543 | ; ; |
1541 | ; ; |
1544 | ;-----------------------------------------------------------------; |
1542 | ;-----------------------------------------------------------------; |
1545 | align 4 |
1543 | align 4 |
1546 | SOCKET_input: |
1544 | socket_input: |
Line 1547... | Line 1545... | ||
1547 | 1545 | ||
Line 1548... | Line 1546... | ||
1548 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx |
1546 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx |
1549 | 1547 | ||
1550 | push ecx |
1548 | push ecx |
Line 1551... | Line 1549... | ||
1551 | push esi |
1549 | push esi |
Line 1552... | Line 1550... | ||
1552 | mov esi, esp |
1550 | mov esi, esp |
1553 | 1551 | ||
Line 1554... | Line 1552... | ||
1554 | add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, SOCKET_input.full |
1552 | add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .full |
1555 | 1553 | ||
1556 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_input: success\n" |
1554 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_input: success\n" |
1557 | add esp, sizeof.socket_queue_entry |
1555 | add esp, sizeof.socket_queue_entry |
Line 1558... | Line 1556... | ||
1558 | 1556 | ||
Line 1559... | Line 1557... | ||
1559 | pusha |
1557 | pusha |
1560 | lea ecx, [eax + SOCKET.mutex] |
1558 | lea ecx, [eax + SOCKET.mutex] |
Line 1561... | Line 1559... | ||
1561 | call mutex_unlock |
1559 | call mutex_unlock |
1562 | popa |
1560 | popa |
1563 | 1561 | ||
1564 | jmp SOCKET_notify |
1562 | jmp socket_notify |
Line 1565... | Line 1563... | ||
1565 | 1563 | ||
1566 | .full: |
1564 | .full: |
1567 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_input: socket %x is full!\n", eax |
1565 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_input: socket %x is full!\n", eax |
Line 1568... | Line 1566... | ||
1568 | 1566 | ||
1569 | pusha |
1567 | pusha |
1570 | lea ecx, [eax + SOCKET.mutex] |
1568 | lea ecx, [eax + SOCKET.mutex] |
1571 | call mutex_unlock |
1569 | call mutex_unlock |
1572 | popa |
1570 | popa |
1573 | 1571 | ||
1574 | add esp, 8 |
1572 | add esp, 8 |
1575 | call NET_BUFF_free |
1573 | call net_buff_free |
1576 | ret |
1574 | ret |
1577 | 1575 | ||
1578 | 1576 | ||
1579 | ;-----------------------------------------------------------------; |
1577 | ;-----------------------------------------------------------------; |
Line 1580... | Line 1578... | ||
1580 | ; ; |
1578 | ; ; |
1581 | ; SOCKET_ring_create: Create a ringbuffer for sockets. ; |
1579 | ; socket_ring_create: Create a ringbuffer for sockets. ; |
Line 1582... | Line 1580... | ||
1582 | ; ; |
1580 | ; ; |
Line 1621... | Line 1619... | ||
1621 | pop esi |
1619 | pop esi |
1622 | ret |
1620 | ret |
Line 1623... | Line 1621... | ||
1623 | 1621 | ||
1624 | ;-----------------------------------------------------------------; |
1622 | ;-----------------------------------------------------------------; |
1625 | ; ; |
1623 | ; ; |
1626 | ; SOCKET_ring_write: Write data to ring buffer. ; |
1624 | ; socket_ring_write: Write data to ring buffer. ; |
1627 | ; ; |
1625 | ; ; |
1628 | ; IN: eax = ptr to ring struct ; |
1626 | ; IN: eax = ptr to ring struct ; |
1629 | ; ecx = data size ; |
1627 | ; ecx = data size ; |
1630 | ; esi = ptr to data ; |
1628 | ; esi = ptr to data ; |
1631 | ; ; |
1629 | ; ; |
1632 | ; OUT: ecx = number of bytes stored ; |
1630 | ; OUT: ecx = number of bytes stored ; |
1633 | ; ; |
1631 | ; ; |
1634 | ;-----------------------------------------------------------------; |
1632 | ;-----------------------------------------------------------------; |
1635 | align 4 |
1633 | align 4 |
Line 1636... | Line 1634... | ||
1636 | SOCKET_ring_write: |
1634 | socket_ring_write: |
Line 1637... | Line 1635... | ||
1637 | 1635 | ||
1638 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_ring_write: ringbuff=%x ptr=%x size=%u\n", eax, esi, ecx |
1636 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_ring_write: ringbuff=%x ptr=%x size=%u\n", eax, esi, ecx |
Line 1691... | Line 1689... | ||
1691 | 1689 | ||
Line 1692... | Line 1690... | ||
1692 | ret |
1690 | ret |
1693 | 1691 | ||
1694 | ;-----------------------------------------------------------------; |
1692 | ;-----------------------------------------------------------------; |
1695 | ; ; |
1693 | ; ; |
1696 | ; SOCKET_ring_read: Read from ring buffer ; |
1694 | ; socket_ring_read: Read from ring buffer ; |
1697 | ; ; |
1695 | ; ; |
1698 | ; IN: eax = ring struct ptr ; |
1696 | ; IN: eax = ring struct ptr ; |
1699 | ; ecx = bytes to read ; |
1697 | ; ecx = bytes to read ; |
Line 1706... | Line 1704... | ||
1706 | ; esi = destroyed ; |
1704 | ; esi = destroyed ; |
1707 | ; edi = ptr to buffer end ; |
1705 | ; edi = ptr to buffer end ; |
1708 | ; ; |
1706 | ; ; |
1709 | ;-----------------------------------------------------------------; |
1707 | ;-----------------------------------------------------------------; |
1710 | align 4 |
1708 | align 4 |
1711 | SOCKET_ring_read: |
1709 | socket_ring_read: |
Line 1712... | Line 1710... | ||
1712 | 1710 | ||
Line 1713... | Line 1711... | ||
1713 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_ring_read: ringbuff=%x ptr=%x size=%u offset=%x\n", eax, edi, ecx, edx |
1711 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_ring_read: ringbuff=%x ptr=%x size=%u offset=%x\n", eax, edi, ecx, edx |
1714 | 1712 | ||
Line 1765... | Line 1763... | ||
1765 | jmp .copy |
1763 | jmp .copy |
Line 1766... | Line 1764... | ||
1766 | 1764 | ||
1767 | 1765 | ||
1768 | ;-----------------------------------------------------------------; |
1766 | ;-----------------------------------------------------------------; |
1769 | ; ; |
1767 | ; ; |
1770 | ; SOCKET_ring_free: Free data from a ringbuffer ; |
1768 | ; socket_ring_free: Free data from a ringbuffer. ; |
1771 | ; ; |
1769 | ; ; |
1772 | ; IN: eax = ptr to ring struct ; |
1770 | ; IN: eax = ptr to ring struct ; |
1773 | ; ecx = data size ; |
1771 | ; ecx = data size ; |
1774 | ; ; |
1772 | ; ; |
1775 | ; OUT: ecx = number of freed bytes ; |
1773 | ; OUT: ecx = number of freed bytes ; |
1776 | ; ; |
1774 | ; ; |
1777 | ;-----------------------------------------------------------------; |
1775 | ;-----------------------------------------------------------------; |
Line 1778... | Line 1776... | ||
1778 | align 4 |
1776 | align 4 |
Line 1779... | Line 1777... | ||
1779 | SOCKET_ring_free: |
1777 | socket_ring_free: |
1780 | 1778 | ||
Line 1815... | Line 1813... | ||
1815 | ret |
1813 | ret |
Line 1816... | Line 1814... | ||
1816 | 1814 | ||
1817 | 1815 | ||
1818 | ;-----------------------------------------------------------------; |
1816 | ;-----------------------------------------------------------------; |
1819 | ; ; |
1817 | ; ; |
1820 | ; SOCKET_block: Suspend the thread attached to a socket. ; |
1818 | ; socket_block: Suspend the thread attached to a socket. ; |
1821 | ; ; |
1819 | ; ; |
1822 | ; IN: eax = socket ptr ; |
1820 | ; IN: eax = socket ptr ; |
1823 | ; ; |
1821 | ; ; |
1824 | ; OUT: eax = unchanged ; |
1822 | ; OUT: eax = unchanged ; |
1825 | ; ; |
1823 | ; ; |
1826 | ;-----------------------------------------------------------------; |
1824 | ;-----------------------------------------------------------------; |
Line 1827... | Line 1825... | ||
1827 | align 4 |
1825 | align 4 |
Line 1828... | Line 1826... | ||
1828 | SOCKET_block: |
1826 | socket_block: |
Line 1857... | Line 1855... | ||
1857 | ret |
1855 | ret |
Line 1858... | Line 1856... | ||
1858 | 1856 | ||
1859 | 1857 | ||
1860 | ;-----------------------------------------------------------------; |
1858 | ;-----------------------------------------------------------------; |
1861 | ; ; |
1859 | ; ; |
1862 | ; SOCKET_notify: Wake up socket owner thread. ; |
1860 | ; socket_notify: Wake up socket owner thread. ; |
1863 | ; ; |
1861 | ; ; |
1864 | ; IN: eax = socket ptr ; |
1862 | ; IN: eax = socket ptr ; |
1865 | ; ; |
1863 | ; ; |
1866 | ; OUT: eax = unchanged ; |
1864 | ; OUT: eax = unchanged ; |
1867 | ; ; |
1865 | ; ; |
1868 | ;-----------------------------------------------------------------; |
1866 | ;-----------------------------------------------------------------; |
Line 1869... | Line 1867... | ||
1869 | align 4 |
1867 | align 4 |
Line 1870... | Line 1868... | ||
1870 | SOCKET_notify: |
1868 | socket_notify: |
1871 | 1869 | ||
Line 1872... | Line 1870... | ||
1872 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_notify: %x\n", eax |
1870 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_notify: %x\n", eax |
1873 | 1871 | ||
1874 | call SOCKET_check |
1872 | call socket_check |
Line 1925... | Line 1923... | ||
1925 | ret |
1923 | ret |
Line 1926... | Line 1924... | ||
1926 | 1924 | ||
1927 | 1925 | ||
1928 | ;-----------------------------------------------------------------; |
- | |
1929 | ; ; |
1926 | ;-----------------------------------------------------------------; |
1930 | ; SOCKET_alloc: ; |
1927 | ; ; |
1931 | ; Allocate memory for socket and put new socket into the list. ; |
1928 | ; socket_alloc: Allocate memory for socket and put new socket ; |
1932 | ; Newly created socket is initialized with calling PID and socket ; |
1929 | ; into the list. Newly created socket is initialized with calling ; |
1933 | ; number. ; |
1930 | ; PID and given a socket number. ; |
1934 | ; ; |
1931 | ; ; |
1935 | ; IN: / ; |
1932 | ; IN: / ; |
1936 | ; ; |
1933 | ; ; |
1937 | ; OUT: eax = socket ptr on success ; |
1934 | ; OUT: eax = socket ptr on success ; |
1938 | ; eax = 0 on error ; |
1935 | ; eax = 0 on error ; |
1939 | ; edi = socket number on success ; |
1936 | ; edi = socket number on success ; |
1940 | ; ; |
1937 | ; ; |
1941 | ;-----------------------------------------------------------------; |
1938 | ;-----------------------------------------------------------------; |
Line 1942... | Line 1939... | ||
1942 | align 4 |
1939 | align 4 |
Line 1943... | Line 1940... | ||
1943 | SOCKET_alloc: |
1940 | socket_alloc: |
1944 | 1941 | ||
Line 2043... | Line 2040... | ||
2043 | ret |
2040 | ret |
Line 2044... | Line 2041... | ||
2044 | 2041 | ||
2045 | 2042 | ||
2046 | ;-----------------------------------------------------------------; |
- | |
2047 | ; ; |
2043 | ;-----------------------------------------------------------------; |
2048 | ; SOCKET_free: ; |
2044 | ; ; |
2049 | ; Free socket data memory and remove socket from the list. ; |
2045 | ; socket_free: Free socket data memory and remove socket from ; |
2050 | ; Caller should lock and unlock socket_mutex. ; |
2046 | ; the list. Caller should lock and unlock socket_mutex. ; |
2051 | ; ; |
2047 | ; ; |
2052 | ; IN: eax = socket ptr ; |
2048 | ; IN: eax = socket ptr ; |
2053 | ; ; |
2049 | ; ; |
2054 | ; OUT: / ; |
2050 | ; OUT: / ; |
2055 | ; ; |
2051 | ; ; |
2056 | ;-----------------------------------------------------------------; |
2052 | ;-----------------------------------------------------------------; |
Line 2057... | Line 2053... | ||
2057 | align 4 |
2053 | align 4 |
Line 2058... | Line 2054... | ||
2058 | SOCKET_free: |
2054 | socket_free: |
2059 | 2055 | ||
Line 2060... | Line 2056... | ||
2060 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_free: %x\n", eax |
2056 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_free: %x\n", eax |
Line 2061... | Line 2057... | ||
2061 | 2057 | ||
Line 2115... | Line 2111... | ||
2115 | DEBUGF DEBUG_NETWORK_ERROR, "socket ptr=0x%x caller=0x%x\n", eax, [esp] |
2111 | DEBUGF DEBUG_NETWORK_ERROR, "socket ptr=0x%x caller=0x%x\n", eax, [esp] |
2116 | ret |
2112 | ret |
Line 2117... | Line 2113... | ||
2117 | 2113 | ||
2118 | ;-----------------------------------------------------------------; |
2114 | ;-----------------------------------------------------------------; |
2119 | ; ; |
2115 | ; ; |
2120 | ; SOCKET_fork: Create a child socket. ; |
2116 | ; socket_fork: Create a child socket. ; |
2121 | ; ; |
2117 | ; ; |
2122 | ; IN: ebx = socket number ; |
2118 | ; IN: ebx = socket number ; |
2123 | ; ; |
2119 | ; ; |
2124 | ; OUT: eax = child socket number on success ; |
2120 | ; OUT: eax = child socket number on success ; |
2125 | ; eax = 0 on error ; |
2121 | ; eax = 0 on error ; |
2126 | ; ; |
2122 | ; ; |
2127 | ;-----------------------------------------------------------------; |
2123 | ;-----------------------------------------------------------------; |
2128 | align 4 |
2124 | align 4 |
Line 2129... | Line 2125... | ||
2129 | SOCKET_fork: |
2125 | socket_fork: |
Line 2130... | Line 2126... | ||
2130 | 2126 | ||
2131 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_fork: %x\n", ebx |
2127 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_fork: %x\n", ebx |
2132 | 2128 | ||
2133 | ; Exit if backlog queue is full |
2129 | ; Exit if backlog queue is full |
Line 2134... | Line 2130... | ||
2134 | mov eax, [ebx + SOCKET_QUEUE_LOCATION + queue.size] |
2130 | mov eax, [ebx + SOCKET_QUEUE_LOCATION + queue.size] |
2135 | cmp ax, [ebx + SOCKET.backlog] |
2131 | cmp ax, [ebx + SOCKET.backlog] |
2136 | jae .fail |
2132 | jae .fail |
2137 | 2133 | ||
2138 | ; Allocate new socket |
2134 | ; Allocate new socket |
2139 | push ebx |
2135 | push ebx |
Line 2140... | Line 2136... | ||
2140 | call SOCKET_alloc |
2136 | call socket_alloc |
Line 2158... | Line 2154... | ||
2158 | and [eax + SOCKET.options], not SO_ACCEPTCON |
2154 | and [eax + SOCKET.options], not SO_ACCEPTCON |
Line 2159... | Line 2155... | ||
2159 | 2155 | ||
2160 | ; Notify owner of parent socket |
2156 | ; Notify owner of parent socket |
2161 | push eax |
2157 | push eax |
2162 | mov eax, ebx |
2158 | mov eax, ebx |
2163 | call SOCKET_notify |
2159 | call socket_notify |
Line 2164... | Line 2160... | ||
2164 | pop eax |
2160 | pop eax |
Line 2165... | Line 2161... | ||
2165 | 2161 | ||
Line 2173... | Line 2169... | ||
2173 | ret |
2169 | ret |
Line 2174... | Line 2170... | ||
2174 | 2170 | ||
2175 | 2171 | ||
2176 | ;-----------------------------------------------------------------; |
2172 | ;-----------------------------------------------------------------; |
2177 | ; ; |
2173 | ; ; |
2178 | ; SOCKET_num_to_ptr: Get socket structure address by its number. ; |
2174 | ; socket_num_to_ptr: Get socket structure address by its number. ; |
2179 | ; ; |
2175 | ; ; |
2180 | ; IN: ecx = socket number ; |
2176 | ; IN: ecx = socket number ; |
2181 | ; ; |
2177 | ; ; |
2182 | ; OUT: eax = socket ptr ; |
2178 | ; OUT: eax = socket ptr ; |
2183 | ; eax = 0 on error ; |
2179 | ; eax = 0 on error ; |
2184 | ; ; |
2180 | ; ; |
2185 | ;-----------------------------------------------------------------; |
2181 | ;-----------------------------------------------------------------; |
Line 2186... | Line 2182... | ||
2186 | align 4 |
2182 | align 4 |
Line 2187... | Line 2183... | ||
2187 | SOCKET_num_to_ptr: |
2183 | socket_num_to_ptr: |
2188 | 2184 | ||
Line 2220... | Line 2216... | ||
2220 | ret |
2216 | ret |
Line 2221... | Line 2217... | ||
2221 | 2217 | ||
2222 | 2218 | ||
2223 | ;-----------------------------------------------------------------; |
2219 | ;-----------------------------------------------------------------; |
2224 | ; ; |
2220 | ; ; |
2225 | ; SOCKET_ptr_to_num: Get socket number by its address. ; |
2221 | ; socket_ptr_to_num: Get socket number by its address. ; |
2226 | ; ; |
2222 | ; ; |
2227 | ; IN: eax = socket ptr ; |
2223 | ; IN: eax = socket ptr ; |
2228 | ; ; |
2224 | ; ; |
2229 | ; OUT: eax = socket number ; |
2225 | ; OUT: eax = socket number ; |
2230 | ; eax = 0 on error ; |
2226 | ; eax = 0 on error ; |
2231 | ; ZF = set on error ; |
2227 | ; ZF = set on error ; |
2232 | ; ; |
2228 | ; ; |
2233 | ;-----------------------------------------------------------------; |
2229 | ;-----------------------------------------------------------------; |
Line 2234... | Line 2230... | ||
2234 | align 4 |
2230 | align 4 |
Line 2235... | Line 2231... | ||
2235 | SOCKET_ptr_to_num: |
2231 | socket_ptr_to_num: |
2236 | 2232 | ||
Line 2237... | Line 2233... | ||
2237 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_ptr_to_num: ptr=%x ", eax |
2233 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_ptr_to_num: ptr=%x ", eax |
Line 2238... | Line 2234... | ||
2238 | 2234 | ||
Line 2249... | Line 2245... | ||
2249 | ret |
2245 | ret |
Line 2250... | Line 2246... | ||
2250 | 2246 | ||
2251 | 2247 | ||
2252 | ;-----------------------------------------------------------------; |
2248 | ;-----------------------------------------------------------------; |
2253 | ; ; |
2249 | ; ; |
2254 | ; SOCKET_check: Checks if the given ptr is really a socket ptr. ; |
2250 | ; socket_check: Checks if the given ptr is really a socket ptr. ; |
2255 | ; ; |
2251 | ; ; |
2256 | ; IN: eax = socket ptr ; |
2252 | ; IN: eax = socket ptr ; |
2257 | ; ; |
2253 | ; ; |
2258 | ; OUT: eax = 0 on error ; |
2254 | ; OUT: eax = 0 on error ; |
2259 | ; ZF = set on error ; |
2255 | ; ZF = set on error ; |
2260 | ; ; |
2256 | ; ; |
2261 | ;-----------------------------------------------------------------; |
2257 | ;-----------------------------------------------------------------; |
Line 2262... | Line 2258... | ||
2262 | align 4 |
2258 | align 4 |
Line 2263... | Line 2259... | ||
2263 | SOCKET_check: |
2259 | socket_check: |
2264 | 2260 | ||
Line 2289... | Line 2285... | ||
2289 | 2285 | ||
2290 | 2286 | ||
2291 | 2287 | ||
2292 | ;-----------------------------------------------------------------; |
2288 | ;-----------------------------------------------------------------; |
2293 | ; ; |
2289 | ; ; |
2294 | ; SOCKET_check_owner: Check if the caller app owns the socket. ; |
2290 | ; socket_check_owner: Check if the caller app owns the socket. ; |
2295 | ; ; |
2291 | ; ; |
2296 | ; IN: eax = socket ptr ; |
2292 | ; IN: eax = socket ptr ; |
2297 | ; ; |
2293 | ; ; |
2298 | ; OUT: ZF = true/false ; |
2294 | ; OUT: ZF = true/false ; |
2299 | ; ; |
2295 | ; ; |
Line 2300... | Line 2296... | ||
2300 | ;-----------------------------------------------------------------; |
2296 | ;-----------------------------------------------------------------; |
Line 2301... | Line 2297... | ||
2301 | align 4 |
2297 | align 4 |
2302 | SOCKET_check_owner: |
2298 | socket_check_owner: |
Line 2314... | Line 2310... | ||
2314 | 2310 | ||
2315 | 2311 | ||
2316 | - | ||
2317 | ;-----------------------------------------------------------------; |
2312 | |
2318 | ; ; |
2313 | ;-----------------------------------------------------------------; |
2319 | ; SOCKET_process_end: ; |
2314 | ; ; |
2320 | ; Kernel calls this function when a certain process ends. ; |
2315 | ; socket_process_end: Kernel calls this function when a certain ; |
2321 | ; This function will check if the process had any open sockets, ; |
2316 | ; process ends. This function will check if the process had any ; |
2322 | ; and update them accordingly (clean up). ; |
2317 | ; open sockets and update them accordingly (clean up). ; |
2323 | ; ; |
2318 | ; ; |
2324 | ; IN: edx = pid ; |
2319 | ; IN: edx = pid ; |
2325 | ; ; |
2320 | ; ; |
2326 | ; OUT: / ; |
2321 | ; OUT: / ; |
2327 | ; ; |
2322 | ; ; |
Line 2328... | Line 2323... | ||
2328 | ;-----------------------------------------------------------------; |
2323 | ;-----------------------------------------------------------------; |
Line 2329... | Line 2324... | ||
2329 | align 4 |
2324 | align 4 |
2330 | SOCKET_process_end: |
2325 | socket_process_end: |
Line 2366... | Line 2361... | ||
2366 | jne .free |
2361 | jne .free |
Line 2367... | Line 2362... | ||
2367 | 2362 | ||
2368 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
2363 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
Line 2369... | Line 2364... | ||
2369 | jne .free |
2364 | jne .free |
2370 | 2365 | ||
Line 2371... | Line 2366... | ||
2371 | call TCP_disconnect |
2366 | call tcp_disconnect |
2372 | jmp .closed |
2367 | jmp .closed |
Line 2373... | Line 2368... | ||
2373 | 2368 | ||
2374 | .free: |
2369 | .free: |
2375 | call SOCKET_free |
2370 | call socket_free |
Line 2392... | Line 2387... | ||
2392 | 2387 | ||
2393 | 2388 | ||
2394 | 2389 | ||
2395 | ;-----------------------------------------------------------------; |
2390 | ;-----------------------------------------------------------------; |
2396 | ; ; |
2391 | ; ; |
2397 | ; SOCKET_is_connecting: Update socket state. ; |
2392 | ; socket_is_connecting: Update socket state. ; |
2398 | ; ; |
2393 | ; ; |
2399 | ; IN: eax = socket ptr ; |
2394 | ; IN: eax = socket ptr ; |
2400 | ; ; |
2395 | ; ; |
2401 | ; OUT: / ; |
2396 | ; OUT: / ; |
2402 | ; ; |
2397 | ; ; |
Line 2403... | Line 2398... | ||
2403 | ;-----------------------------------------------------------------; |
2398 | ;-----------------------------------------------------------------; |
Line 2404... | Line 2399... | ||
2404 | align 4 |
2399 | align 4 |
2405 | SOCKET_is_connecting: |
2400 | socket_is_connecting: |
Line 2412... | Line 2407... | ||
2412 | 2407 | ||
2413 | 2408 | ||
2414 | 2409 | ||
2415 | ;-----------------------------------------------------------------; |
2410 | ;-----------------------------------------------------------------; |
2416 | ; ; |
2411 | ; ; |
2417 | ; SOCKET_is_connected: Update socket state. ; |
2412 | ; socket_is_connected: Update socket state. ; |
2418 | ; ; |
2413 | ; ; |
2419 | ; IN: eax = socket ptr ; |
2414 | ; IN: eax = socket ptr ; |
2420 | ; ; |
2415 | ; ; |
2421 | ; OUT: / ; |
2416 | ; OUT: / ; |
2422 | ; ; |
2417 | ; ; |
Line 2423... | Line 2418... | ||
2423 | ;-----------------------------------------------------------------; |
2418 | ;-----------------------------------------------------------------; |
Line 2424... | Line 2419... | ||
2424 | align 4 |
2419 | align 4 |
2425 | SOCKET_is_connected: |
2420 | socket_is_connected: |
2426 | 2421 | ||
Line 2427... | Line 2422... | ||
2427 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_connected: %x\n", eax |
2422 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_connected: %x\n", eax |
2428 | 2423 | ||
2429 | and [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING) |
2424 | and [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING) |
2430 | or [eax + SOCKET.state], SS_ISCONNECTED |
2425 | or [eax + SOCKET.state], SS_ISCONNECTED |
2431 | jmp SOCKET_notify |
2426 | jmp socket_notify |
2432 | 2427 | ||
2433 | 2428 | ||
2434 | 2429 | ||
2435 | 2430 | ||
2436 | ;-----------------------------------------------------------------; |
2431 | ;-----------------------------------------------------------------; |
2437 | ; ; |
2432 | ; ; |
Line 2438... | Line 2433... | ||
2438 | ; SOCKET_is_disconnecting: Update socket state. ; |
2433 | ; socket_is_disconnecting: Update socket state. ; |
Line 2439... | Line 2434... | ||
2439 | ; ; |
2434 | ; ; |
2440 | ; IN: eax = socket ptr ; |
2435 | ; IN: eax = socket ptr ; |
2441 | ; ; |
2436 | ; ; |
Line 2442... | Line 2437... | ||
2442 | ; OUT: / ; |
2437 | ; OUT: / ; |
2443 | ; ; |
2438 | ; ; |
2444 | ;-----------------------------------------------------------------; |
2439 | ;-----------------------------------------------------------------; |
2445 | align 4 |
2440 | align 4 |
2446 | SOCKET_is_disconnecting: |
2441 | socket_is_disconnecting: |
2447 | 2442 | ||
2448 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnecting: %x\n", eax |
2443 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnecting: %x\n", eax |
2449 | 2444 | ||
2450 | and [eax + SOCKET.state], not (SS_ISCONNECTING) |
2445 | and [eax + SOCKET.state], not (SS_ISCONNECTING) |
2451 | or [eax + SOCKET.state], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE |
2446 | or [eax + SOCKET.state], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE |
2452 | jmp SOCKET_notify |
2447 | jmp socket_notify |
Line 2453... | Line 2448... | ||
2453 | 2448 | ||
Line 2454... | Line 2449... | ||
2454 | 2449 | ||
2455 | 2450 | ||
2456 | ;-----------------------------------------------------------------; |
2451 | ;-----------------------------------------------------------------; |
Line 2457... | Line 2452... | ||
2457 | ; ; |
2452 | ; ; |
2458 | ; SOCKET_is_disconnected: Update socket state. ; |
2453 | ; socket_is_disconnected: Update socket state. ; |
2459 | ; ; |
2454 | ; ; |
2460 | ; IN: eax = socket ptr ; |
2455 | ; IN: eax = socket ptr ; |
2461 | ; ; |
2456 | ; ; |
2462 | ; OUT: / ; |
2457 | ; OUT: / ; |
2463 | ; ; |
2458 | ; ; |
2464 | ;-----------------------------------------------------------------; |
2459 | ;-----------------------------------------------------------------; |
2465 | align 4 |
2460 | align 4 |
2466 | SOCKET_is_disconnected: |
2461 | socket_is_disconnected: |
2467 | 2462 | ||
Line 2468... | Line 2463... | ||
2468 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnected: %x\n", eax |
2463 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnected: %x\n", eax |
Line 2469... | Line 2464... | ||
2469 | 2464 | ||
2470 | and [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING) |
2465 | and [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING) |
Line 2471... | Line 2466... | ||
2471 | or [eax + SOCKET.state], SS_CANTRCVMORE + SS_CANTSENDMORE |
2466 | or [eax + SOCKET.state], SS_CANTRCVMORE + SS_CANTSENDMORE |
2472 | jmp SOCKET_notify |
2467 | jmp socket_notify |
2473 | 2468 | ||
2474 | 2469 | ||
2475 | 2470 | ||
2476 | ;-----------------------------------------------------------------; |
2471 | ;-----------------------------------------------------------------; |
2477 | ; ; |
2472 | ; ; |
2478 | ; SOCKET_cant_recv_more: Update socket state. ; |
2473 | ; socket_cant_recv_more: Update socket state. ; |
2479 | ; ; |
2474 | ; ; |
2480 | ; IN: eax = socket ptr ; |
2475 | ; IN: eax = socket ptr ; |
2481 | ; ; |
2476 | ; ; |
Line 2482... | Line 2477... | ||
2482 | ; OUT: / ; |
2477 | ; OUT: / ; |
Line 2483... | Line 2478... | ||
2483 | ; ; |
2478 | ; ; |
2484 | ;-----------------------------------------------------------------; |
2479 | ;-----------------------------------------------------------------; |
2485 | align 4 |
2480 | align 4 |
Line 2486... | Line 2481... | ||
2486 | SOCKET_cant_recv_more: |
2481 | socket_cant_recv_more: |
2487 | 2482 | ||
2488 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_cant_recv_more: %x\n", eax |
2483 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_cant_recv_more: %x\n", eax |
2489 | 2484 |