Rev 5969 | Rev 6011 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5969 | Rev 5976 | ||
---|---|---|---|
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: 5969 $ |
18 | $Revision: 5976 $ |
Line 19... | Line 19... | ||
19 | 19 | ||
20 | struct SOCKET |
20 | struct SOCKET |
Line 29... | Line 29... | ||
29 | TID dd ? ; thread ID |
29 | TID dd ? ; thread ID |
30 | Domain dd ? ; INET4/INET6/LOCAL/.. |
30 | Domain dd ? ; INET4/INET6/LOCAL/.. |
31 | Type dd ? ; RAW/STREAM/DGRAM |
31 | Type dd ? ; RAW/STREAM/DGRAM |
32 | Protocol dd ? ; UDP/TCP/ARP/ICMP |
32 | Protocol dd ? ; UDP/TCP/ARP/ICMP |
33 | errorcode dd ? |
33 | errorcode dd ? |
34 | device dd ? ; driver pointer, socket pointer if it's an LOCAL socket |
34 | device dd ? ; device pointer, paired socket pointer if it's a local socket |
Line 35... | Line 35... | ||
35 | 35 | ||
36 | options dd ? |
36 | options dd ? |
37 | state dd ? |
37 | state dd ? |
Line 38... | Line 38... | ||
38 | backlog dw ? ; how many incoming connections that can be queued |
38 | backlog dw ? ; number of incoming connections that can be queued |
39 | 39 | ||
40 | snd_proc dd ? |
40 | snd_proc dd ? |
Line 145... | Line 145... | ||
145 | 145 | ||
Line 146... | Line 146... | ||
146 | ends |
146 | ends |
Line 147... | Line 147... | ||
147 | 147 | ||
148 | struct UDP_SOCKET IP_SOCKET |
148 | struct UDP_SOCKET IP_SOCKET |
Line 149... | Line 149... | ||
149 | 149 | ||
Line 150... | Line 150... | ||
150 | LocalPort dw ? ; network byte order |
150 | LocalPort dw ? ; in network byte order |
Line 176... | Line 176... | ||
176 | data_size dd ? |
176 | data_size dd ? |
177 | buf_ptr dd ? |
177 | buf_ptr dd ? |
Line 178... | Line 178... | ||
178 | 178 | ||
Line -... | Line 179... | ||
- | 179 | ends |
|
- | 180 | ||
- | 181 | struct socket_options |
|
- | 182 | ||
- | 183 | level dd ? |
|
- | 184 | optname dd ? |
|
- | 185 | optlen dd ? |
|
- | 186 | optval dd ? |
|
Line 179... | Line 187... | ||
179 | ends |
187 | |
Line 180... | Line 188... | ||
180 | 188 | ends |
|
181 | 189 | ||
Line 188... | Line 196... | ||
188 | uglobal |
196 | uglobal |
189 | align 4 |
197 | align 4 |
Line 190... | Line 198... | ||
190 | 198 | ||
191 | net_sockets rd 4 |
199 | net_sockets rd 4 |
192 | last_socket_num dd ? |
200 | last_socket_num dd ? |
193 | last_UDP_port dw ? ; These values give the number of the last used ephemeral port |
201 | last_UDP_port dw ? ; last used ephemeral port |
194 | last_TCP_port dw ? ; |
202 | last_TCP_port dw ? ; |
Line 195... | Line 203... | ||
195 | socket_mutex MUTEX |
203 | socket_mutex MUTEX |
Line 196... | Line 204... | ||
196 | 204 | ||
197 | endg |
- | |
- | 205 | endg |
|
198 | 206 | ||
199 | - | ||
- | 207 | ||
200 | ;----------------------------------------------------------------- |
208 | ;-----------------------------------------------------------------; |
201 | ; |
209 | ; ; |
Line 202... | Line 210... | ||
202 | ; SOCKET_init |
210 | ; SOCKET_init ; |
203 | ; |
211 | ; ; |
204 | ;----------------------------------------------------------------- |
212 | ;-----------------------------------------------------------------; |
Line 230... | Line 238... | ||
230 | mov ecx, socket_mutex |
238 | mov ecx, socket_mutex |
231 | call mutex_init |
239 | call mutex_init |
Line 232... | Line 240... | ||
232 | 240 | ||
Line 233... | Line 241... | ||
233 | } |
241 | } |
234 | - | ||
- | 242 | ||
235 | ;----------------------------------------------------------------- |
243 | ;-----------------------------------------------------------------; |
236 | ; |
- | |
- | 244 | ; ; |
|
237 | ; Socket API (function 74) |
245 | ; Sockets API (system function 75) ; |
238 | ; |
246 | ; ; |
239 | ;----------------------------------------------------------------- |
247 | ;-----------------------------------------------------------------; |
Line 240... | Line 248... | ||
240 | align 4 |
248 | align 4 |
Line 267... | Line 275... | ||
267 | mov dword[esp+32], -1 |
275 | mov dword[esp+32], -1 |
268 | mov dword[esp+20], EINVAL |
276 | mov dword[esp+20], EINVAL |
Line 269... | Line 277... | ||
269 | 277 | ||
Line 270... | Line 278... | ||
270 | ret |
278 | ret |
271 | - | ||
- | 279 | ||
272 | ;----------------------------------------------------------------- |
280 | ;-----------------------------------------------------------------; |
273 | ; |
- | |
- | 281 | ; ; |
|
274 | ; SOCKET_open |
282 | ; SOCKET_open: Create a new socket. ; |
275 | ; |
283 | ; ; |
276 | ; IN: domain in ecx |
284 | ; IN: ecx = domain ; |
- | 285 | ; edx = type ; |
|
277 | ; type in edx |
286 | ; esi = protocol ; |
278 | ; protocol in esi |
- | |
- | 287 | ; ; |
|
- | 288 | ; OUT: eax = socket number ; |
|
- | 289 | ; eax = -1 on error ; |
|
279 | ; OUT: eax is socket num, -1 on error |
290 | ; ebx = errorcode on error ; |
280 | ; |
291 | ; ; |
281 | ;----------------------------------------------------------------- |
292 | ;-----------------------------------------------------------------; |
Line 282... | Line 293... | ||
282 | align 4 |
293 | align 4 |
Line 403... | Line 414... | ||
403 | mov [eax + SOCKET.snd_proc], SOCKET_send_pppoe |
414 | mov [eax + SOCKET.snd_proc], SOCKET_send_pppoe |
404 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram |
415 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram |
405 | ret |
416 | ret |
Line 406... | Line 417... | ||
406 | 417 | ||
407 | - | ||
- | 418 | ||
408 | ;----------------------------------------------------------------- |
419 | ;-----------------------------------------------------------------; |
409 | ; |
- | |
- | 420 | ; ; |
|
410 | ; SOCKET_bind |
421 | ; SOCKET_bind: Bind to a local port. ; |
411 | ; |
422 | ; ; |
412 | ; IN: socket number in ecx |
423 | ; IN: ecx = socket number ; |
- | 424 | ; edx = pointer to sockaddr struct ; |
|
413 | ; pointer to sockaddr struct in edx |
425 | ; esi = length of sockaddr struct ; |
414 | ; length of that struct in esi |
- | |
- | 426 | ; ; |
|
- | 427 | ; OUT: eax = 0 on success ; |
|
- | 428 | ; eax = -1 on error ; |
|
415 | ; OUT: 0 on success |
429 | ; ebx = errorcode on error ; |
416 | ; |
430 | ; ; |
417 | ;----------------------------------------------------------------- |
431 | ;-----------------------------------------------------------------; |
Line 418... | Line 432... | ||
418 | align 4 |
432 | align 4 |
Line 493... | Line 507... | ||
493 | ret |
507 | ret |
Line 494... | Line 508... | ||
494 | 508 | ||
495 | - | ||
- | 509 | ||
496 | 510 | ||
497 | - | ||
- | 511 | ||
498 | ;----------------------------------------------------------------- |
512 | ;-----------------------------------------------------------------; |
499 | ; |
513 | ; ; |
500 | ; SOCKET_connect |
514 | ; SOCKET_connect: Connect to the remote host. ; |
- | 515 | ; ; |
|
501 | ; |
516 | ; IN: ecx = socket number ; |
502 | ; IN: socket number in ecx |
- | |
- | 517 | ; edx = pointer to sockaddr struct ; |
|
- | 518 | ; esi = length of sockaddr struct ; |
|
- | 519 | ; ; |
|
503 | ; pointer to sockaddr struct in edx |
520 | ; OUT: eax = 0 on success ; |
504 | ; length of that struct in esi |
521 | ; eax = -1 on error ; |
505 | ; OUT: 0 on success |
522 | ; ebx = errorcode on error ; |
Line 506... | Line 523... | ||
506 | ; |
523 | ; ; |
Line 551... | Line 568... | ||
551 | dec eax |
568 | dec eax |
552 | mov ebx, EOPNOTSUPP |
569 | mov ebx, EOPNOTSUPP |
553 | ret |
570 | ret |
Line 554... | Line 571... | ||
554 | 571 | ||
555 | - | ||
- | 572 | ||
556 | ;----------------------------------------------------------------- |
573 | ;-----------------------------------------------------------------; |
557 | ; |
- | |
- | 574 | ; ; |
|
558 | ; SOCKET_listen |
575 | ; SOCKET_listen: Listen for incoming connections. ; |
559 | ; |
576 | ; ; |
- | 577 | ; IN: ecx = socket number ; |
|
560 | ; IN: socket number in ecx |
578 | ; edx = backlog in edx ; |
561 | ; backlog in edx |
- | |
- | 579 | ; ; |
|
- | 580 | ; OUT: eax = 0 on success ; |
|
- | 581 | ; eax = -1 on error ; |
|
562 | ; OUT: eax is socket num, -1 on error |
582 | ; ebx = errorcode on error ; |
563 | ; |
583 | ; ; |
564 | ;----------------------------------------------------------------- |
584 | ;-----------------------------------------------------------------; |
Line 565... | Line 585... | ||
565 | align 4 |
585 | align 4 |
Line 617... | Line 637... | ||
617 | mov dword[esp+20], EALREADY |
637 | mov dword[esp+20], EALREADY |
618 | mov dword[esp+32], -1 |
638 | mov dword[esp+32], -1 |
619 | ret |
639 | ret |
Line 620... | Line 640... | ||
620 | 640 | ||
621 | - | ||
- | 641 | ||
622 | ;----------------------------------------------------------------- |
642 | ;-----------------------------------------------------------------; |
623 | ; |
- | |
- | 643 | ; ; |
|
624 | ; SOCKET_accept |
644 | ; SOCKET_accept: Accept an incoming connection. ; |
625 | ; |
645 | ; ; |
626 | ; IN: socket number in ecx |
646 | ; IN: ecx = socket number (of listening socket) ; |
- | 647 | ; edx = ptr to sockaddr struct ; |
|
627 | ; addr in edx |
648 | ; esi = length of sockaddr struct ; |
628 | ; addrlen in esi |
- | |
- | 649 | ; ; |
|
- | 650 | ; OUT: eax = newly created socket num ; |
|
- | 651 | ; eax = -1 on error ; |
|
629 | ; OUT: eax is socket num, -1 on error |
652 | ; ebx = errorcode on error ; |
630 | ; |
653 | ; ; |
631 | ;----------------------------------------------------------------- |
654 | ;-----------------------------------------------------------------; |
Line 632... | Line 655... | ||
632 | align 4 |
655 | align 4 |
Line 687... | Line 710... | ||
687 | .notsupp: |
710 | .notsupp: |
688 | mov dword[esp+20], EOPNOTSUPP |
711 | mov dword[esp+20], EOPNOTSUPP |
689 | mov dword[esp+32], -1 |
712 | mov dword[esp+32], -1 |
690 | ret |
713 | ret |
Line 691... | Line 714... | ||
691 | 714 | ||
692 | ;----------------------------------------------------------------- |
- | |
- | 715 | ;-----------------------------------------------------------------; |
|
693 | ; |
716 | ; ; |
694 | ; SOCKET_close |
- | |
- | 717 | ; SOCKET_close: Close the socket (and connection). ; |
|
695 | ; |
718 | ; ; |
- | 719 | ; IN: ecx = socket number ; |
|
696 | ; IN: socket number in ecx |
720 | ; ; |
697 | ; OUT: eax is socket num, -1 on error |
- | |
- | 721 | ; OUT: eax = 0 on success ; |
|
- | 722 | ; eax = -1 on error ; |
|
- | 723 | ; ebx = errorcode on error ; |
|
698 | ; |
724 | ; ; |
699 | ;----------------------------------------------------------------- |
725 | ;-----------------------------------------------------------------; |
700 | align 4 |
726 | align 4 |
Line 701... | Line 727... | ||
701 | SOCKET_close: |
727 | SOCKET_close: |
Line 724... | Line 750... | ||
724 | .free: |
750 | .free: |
725 | call SOCKET_free |
751 | call SOCKET_free |
726 | ret |
752 | ret |
Line 727... | Line 753... | ||
727 | 753 | ||
728 | .tcp: |
- | |
729 | 754 | .tcp: |
|
Line 730... | Line 755... | ||
730 | call TCP_usrclosed |
755 | call TCP_usrclosed |
731 | 756 | ||
732 | test eax, eax |
757 | test eax, eax |
733 | jz @f |
758 | jz @f |
734 | call TCP_output ; If connection is not closed yet, send the FIN |
- | |
735 | @@: |
759 | call TCP_output ; If connection is not closed yet, send the FIN |
Line 736... | Line 760... | ||
736 | 760 | @@: |
|
737 | ret |
761 | ret |
738 | 762 | ||
739 | 763 | ||
Line 740... | Line 764... | ||
740 | .invalid: |
764 | .invalid: |
741 | mov dword[esp+20], EINVAL |
- | |
- | 765 | mov dword[esp+20], EINVAL |
|
742 | mov dword[esp+32], -1 |
766 | mov dword[esp+32], -1 |
743 | ret |
- | |
- | 767 | ret |
|
744 | 768 | ||
745 | 769 | ||
746 | ;----------------------------------------------------------------- |
770 | ;-----------------------------------------------------------------; |
747 | ; |
771 | ; ; |
- | 772 | ; SOCKET_receive: Receive some data from the remote end. ; |
|
748 | ; SOCKET_receive |
773 | ; ; |
749 | ; |
- | |
- | 774 | ; IN: ecx = socket number ; |
|
- | 775 | ; edx = addr to application buffer ; |
|
- | 776 | ; edx = length of application buffer ; |
|
- | 777 | ; edi = flags ; |
|
750 | ; IN: socket number in ecx |
778 | ; ; |
751 | ; addr to buffer in edx |
779 | ; OUT: eax = number of bytes copied ; |
752 | ; length of buffer in esi |
780 | ; eax = -1 on error ; |
Line 753... | Line 781... | ||
753 | ; flags in edi |
781 | ; eax = 0 when socket has been closed by the remote end ; |
Line 775... | Line 803... | ||
775 | jne .return |
803 | jne .return |
Line 776... | Line 804... | ||
776 | 804 | ||
777 | test edi, MSG_DONTWAIT |
805 | test edi, MSG_DONTWAIT |
Line 778... | Line 806... | ||
778 | jnz .return_err |
806 | jnz .return_err |
779 | 807 | ||
Line 780... | Line 808... | ||
780 | ; test [eax + SOCKET.options], SO_NONBLOCK |
808 | test [eax + SOCKET.options], SO_NONBLOCK |
781 | ; jnz .return_err |
809 | jnz .return_err |
Line 795... | Line 823... | ||
795 | ret |
823 | ret |
Line 796... | Line 824... | ||
796 | 824 | ||
797 | .last_data: |
825 | .last_data: |
798 | test ecx, ecx |
826 | test ecx, ecx |
799 | jz .return |
827 | jz .return |
800 | call SOCKET_notify |
828 | call SOCKET_notify ; Call me again! |
Line 801... | Line 829... | ||
801 | jmp .return |
829 | jmp .return |
802 | 830 | ||
Line 803... | Line 831... | ||
803 | 831 | ||
Line -... | Line 832... | ||
- | 832 | ||
- | 833 | ||
- | 834 | align 4 |
|
804 | 835 | SOCKET_receive_dgram: |
|
Line 805... | Line 836... | ||
805 | 836 | ||
806 | align 4 |
837 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_receive: DGRAM\n" |
807 | SOCKET_receive_dgram: |
838 | |
Line 837... | Line 868... | ||
837 | rep movsd |
868 | rep movsd |
838 | .nd: |
869 | .nd: |
Line 839... | Line 870... | ||
839 | 870 | ||
840 | call NET_BUFF_free |
871 | call NET_BUFF_free |
- | 872 | pop ecx eax ; return number of bytes copied to application |
|
841 | pop ecx eax ; return number of bytes copied to application |
873 | cmp [eax + SOCKET_QUEUE_LOCATION + queue.size], 0 |
- | 874 | je @f |
|
- | 875 | call SOCKET_notify ; Queue another network event |
|
- | 876 | @@: |
|
842 | xor ebx, ebx |
877 | xor ebx, ebx ; errorcode = 0 (no error) |
Line 843... | Line 878... | ||
843 | ret |
878 | ret |
844 | 879 | ||
845 | .too_small: |
880 | .too_small: |
Line 851... | Line 886... | ||
851 | .wouldblock: |
886 | .wouldblock: |
852 | push EWOULDBLOCK |
887 | push EWOULDBLOCK |
853 | pop ebx |
888 | pop ebx |
854 | ret |
889 | ret |
Line -... | Line 890... | ||
- | 890 | ||
- | 891 | .peek: |
|
- | 892 | xor ebx, ebx |
|
- | 893 | xor ecx, ecx |
|
- | 894 | cmp [eax + SOCKET_QUEUE_LOCATION + queue.size], 0 |
|
- | 895 | je @f |
|
- | 896 | mov esi, [eax + SOCKET_QUEUE_LOCATION + queue.r_ptr] |
|
- | 897 | mov ecx, [esi + socket_queue_entry.data_size] |
|
- | 898 | @@: |
|
Line 855... | Line 899... | ||
855 | 899 | ret |
|
856 | 900 | ||
Line 914... | Line 958... | ||
914 | mov ecx, [eax + STREAM_SOCKET.rcv + RING_BUFFER.size] |
958 | mov ecx, [eax + STREAM_SOCKET.rcv + RING_BUFFER.size] |
915 | xor ebx, ebx |
959 | xor ebx, ebx |
916 | ret |
960 | ret |
Line 917... | Line 961... | ||
917 | 961 | ||
918 | - | ||
- | 962 | ||
919 | ;----------------------------------------------------------------- |
963 | ;-----------------------------------------------------------------; |
920 | ; |
- | |
921 | ; SOCKET_send |
- | |
- | 964 | ; ; |
|
922 | ; |
965 | ; SOCKET_send: Send some data to the remote end. ; |
923 | ; |
966 | ; ; |
924 | ; IN: socket number in ecx |
967 | ; IN: ecx = socket number ; |
925 | ; pointer to data in edx |
968 | ; edx = pointer to data ; |
- | 969 | ; esi = data length ; |
|
- | 970 | ; edi = flags ; |
|
926 | ; datalength in esi |
971 | ; ; |
927 | ; flags in edi |
- | |
- | 972 | ; OUT: eax = number of bytes sent ; |
|
- | 973 | ; eax = -1 on error ; |
|
928 | ; OUT: -1 on error |
974 | ; ebx = errorcode on error ; |
929 | ; |
975 | ; ; |
930 | ;----------------------------------------------------------------- |
976 | ;-----------------------------------------------------------------; |
Line 931... | Line 977... | ||
931 | align 4 |
977 | align 4 |
Line 1082... | Line 1128... | ||
1082 | mov dword[esp+32], -1 |
1128 | mov dword[esp+32], -1 |
1083 | mov dword[esp+20], EINVAL |
1129 | mov dword[esp+20], EINVAL |
1084 | ret |
1130 | ret |
Line 1085... | Line 1131... | ||
1085 | 1131 | ||
1086 | - | ||
- | 1132 | ||
1087 | ;----------------------------------------------------------------- |
1133 | ;-----------------------------------------------------------------; |
1088 | ; |
- | |
- | 1134 | ; ; |
|
1089 | ; SOCKET_get_options |
1135 | ; SOCKET_get_options: Read a socket option ; |
1090 | ; |
1136 | ; ; |
- | 1137 | ; IN: ecx = socket number ; |
|
- | 1138 | ; edx = pointer to socket options struct ; |
|
- | 1139 | ; ; |
|
- | 1140 | ; OUT: eax = 0 on success ; |
|
1091 | ; IN: ecx = socket number |
1141 | ; eax = -1 on error ; |
- | 1142 | ; ebx = errorcode on error ; |
|
- | 1143 | ; ; |
|
1092 | ; edx = pointer to the options: |
1144 | ;-----------------------------------------------------------------; |
1093 | ; dd level, optname, optval, optlen |
1145 | align 4 |
- | 1146 | SOCKET_get_opt: |
|
1094 | ; OUT: -1 on error |
1147 | |
1095 | ; |
1148 | ; FIXME: |
1096 | ; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP. |
1149 | ; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP. |
1097 | ; TODO: find best way to notify that send()'ed data were acknowledged |
- | |
1098 | ; Also pseudo-optname -3 is valid and returns socket state, one of TCPS_*. |
- | |
1099 | ; |
- | |
1100 | ;----------------------------------------------------------------- |
- | |
Line 1101... | Line 1150... | ||
1101 | align 4 |
1150 | ; TODO: find best way to notify that send()'ed data were acknowledged |
Line 1102... | Line 1151... | ||
1102 | SOCKET_get_opt: |
1151 | ; Also pseudo-optname -3 is valid and returns socket state, one of TCPS_*. |
1103 | 1152 | ||
Line 1141... | Line 1190... | ||
1141 | mov dword[esp+32], -1 |
1190 | mov dword[esp+32], -1 |
1142 | mov dword[esp+20], EINVAL |
1191 | mov dword[esp+20], EINVAL |
1143 | ret |
1192 | ret |
Line 1144... | Line 1193... | ||
1144 | 1193 | ||
1145 | - | ||
- | 1194 | ||
1146 | ;----------------------------------------------------------------- |
1195 | ;-----------------------------------------------------------------; |
1147 | ; |
- | |
- | 1196 | ; ; |
|
1148 | ; SOCKET_set_options |
1197 | ; SOCKET_set_options: Set a socket option. ; |
1149 | ; |
1198 | ; ; |
1150 | ; IN: ecx = socket number |
- | |
1151 | ; edx = pointer to socket_options |
- | |
1152 | ; OUT: -1 on error |
1199 | ; IN: ecx = socket number ; |
1153 | ; |
- | |
1154 | ;----------------------------------------------------------------- |
- | |
1155 | 1200 | ; edx = pointer to socket options struct ; |
|
1156 | struct socket_options |
1201 | ; ; |
1157 | level dd ? |
1202 | ; OUT: eax = 0 on success ; |
1158 | optname dd ? |
1203 | ; eax = -1 on error ; |
1159 | optlen dd ? |
- | |
1160 | optval dd ? |
- | |
- | 1204 | ; ebx = errorcode on error ; |
|
1161 | ends |
1205 | ; ; |
1162 | 1206 | ;-----------------------------------------------------------------; |
|
Line 1163... | Line 1207... | ||
1163 | align 4 |
1207 | align 4 |
Line 1224... | Line 1268... | ||
1224 | ret |
1268 | ret |
Line 1225... | Line 1269... | ||
1225 | 1269 | ||
1226 | - | ||
1227 | 1270 | ||
1228 | - | ||
1229 | ;----------------------------------------------------------------- |
1271 | |
1230 | ; |
- | |
- | 1272 | ||
1231 | ; SOCKET_pair |
1273 | ;-----------------------------------------------------------------; |
- | 1274 | ; ; |
|
1232 | ; |
1275 | ; SOCKET_pair: Allocate a pair of linked local sockets. ; |
- | 1276 | ; ; |
|
1233 | ; Allocates a pair of linked LOCAL domain sockets |
1277 | ; IN: / ; |
1234 | ; |
- | |
- | 1278 | ; ; |
|
- | 1279 | ; OUT: eax = socket1 num on success ; |
|
1235 | ; IN: / |
1280 | ; eax = -1 on error ; |
1236 | ; OUT: eax is socket1 num, -1 on error |
1281 | ; ebx = socket2 num on success ; |
1237 | ; ebx is socket2 num |
1282 | ; ebx = errorcode on error ; |
Line 1238... | Line 1283... | ||
1238 | ; |
1283 | ; ; |
Line 1295... | Line 1340... | ||
1295 | mov dword[esp+20], ENOMEM |
1340 | mov dword[esp+20], ENOMEM |
1296 | ret |
1341 | ret |
Line 1297... | Line 1342... | ||
1297 | 1342 | ||
1298 | - | ||
1299 | 1343 | ||
1300 | ;----------------------------------------------------------------- |
- | |
1301 | ; |
1344 | |
1302 | ; SOCKET_debug |
- | |
- | 1345 | ;-----------------------------------------------------------------; |
|
1303 | ; |
1346 | ; ; |
1304 | ; Copies socket variables to application buffer |
1347 | ; SOCKET_debug: Copy socket variables to application buffer. ; |
1305 | ; |
- | |
- | 1348 | ; ; |
|
- | 1349 | ; IN: ecx = socket number ; |
|
1306 | ; IN: ecx = socket number |
1350 | ; edx = pointer to application buffer ; |
- | 1351 | ; ; |
|
- | 1352 | ; OUT: eax = 0 on success ; |
|
1307 | ; edx = pointer to buffer |
1353 | ; eax = -1 on error ; |
1308 | ; |
1354 | ; ebx = errorcode on error ; |
1309 | ; OUT: -1 on error |
1355 | ; ; |
Line 1310... | Line 1356... | ||
1310 | ;----------------------------------------------------------------- |
1356 | ;-----------------------------------------------------------------; |
Line 1348... | Line 1394... | ||
1348 | mov dword[esp+32], -1 |
1394 | mov dword[esp+32], -1 |
1349 | mov dword[esp+20], EINVAL |
1395 | mov dword[esp+20], EINVAL |
1350 | ret |
1396 | ret |
Line 1351... | Line 1397... | ||
1351 | 1397 | ||
- | 1398 | ||
- | 1399 | ;-----------------------------------------------------------------; |
|
- | 1400 | ; ____ ____ ; |
|
- | 1401 | ; \ / End of sockets API \ / ; |
|
- | 1402 | ; \/ \/ ; |
|
- | 1403 | ; () Internally used functions follow () ; |
|
1352 | 1404 | ; ; |
|
1353 | ;----------------------------------------------------------------- |
- | |
1354 | ; |
1405 | ;-----------------------------------------------------------------; |
- | 1406 | ||
- | 1407 | ||
- | 1408 | ;-----------------------------------------------------------------; |
|
1355 | ; SOCKET_find_port |
1409 | ; ; |
1356 | ; |
1410 | ; SOCKET_find_port: ; |
1357 | ; Fills in the local port number for TCP and UDP sockets |
1411 | ; Fill in the local port number for TCP and UDP sockets ; |
1358 | ; This procedure always works because the number of sockets is |
- | |
- | 1412 | ; This procedure always works because the number of sockets is ; |
|
1359 | ; limited to a smaller number then the number of possible ports |
1413 | ; limited to a smaller number then the number of possible ports ; |
- | 1414 | ; ; |
|
1360 | ; |
1415 | ; IN: eax = socket pointer ; |
1361 | ; IN: eax = socket pointer |
- | |
- | 1416 | ; ; |
|
1362 | ; OUT: / |
1417 | ; OUT: / ; |
1363 | ; |
1418 | ; ; |
1364 | ;----------------------------------------------------------------- |
1419 | ;-----------------------------------------------------------------; |
Line 1365... | Line 1420... | ||
1365 | align 4 |
1420 | align 4 |
Line 1408... | Line 1463... | ||
1408 | jz .findit |
1463 | jz .findit |
1409 | ret |
1464 | ret |
Line 1410... | Line 1465... | ||
1410 | 1465 | ||
1411 | - | ||
- | 1466 | ||
1412 | 1467 | ||
1413 | ;----------------------------------------------------------------- |
- | |
- | 1468 | ;-----------------------------------------------------------------; |
|
1414 | ; |
1469 | ; ; |
1415 | ; SOCKET_check_port (to be used with AF_INET only!) |
1470 | ; SOCKET_check_port (to be used with AF_INET only!) ; |
1416 | ; |
- | |
- | 1471 | ; ; |
|
- | 1472 | ; Checks if a local port number is unused ; |
|
1417 | ; Checks if a local port number is unused |
1473 | ; If the proposed port number is unused, it is filled in in the ; |
1418 | ; If the proposed port number is unused, it is filled in in the socket structure |
1474 | ; socket structure ; |
1419 | ; |
- | |
- | 1475 | ; ; |
|
1420 | ; IN: eax = socket ptr (to find out if its a TCP/UDP socket) |
1476 | ; IN: eax = socket ptr ; |
1421 | ; bx = proposed socket number (network byte order) |
- | |
- | 1477 | ; bx = proposed socket number (network byte order) ; |
|
1422 | ; |
1478 | ; ; |
1423 | ; OUT: ZF = set on error |
1479 | ; OUT: ZF = set on error ; |
1424 | ; |
1480 | ; ; |
Line 1425... | Line 1481... | ||
1425 | ;----------------------------------------------------------------- |
1481 | ;-----------------------------------------------------------------; |
Line 1470... | Line 1526... | ||
1470 | or bx, bx ; clear the zero-flag |
1526 | or bx, bx ; clear the zero-flag |
1471 | ret |
1527 | ret |
Line 1472... | Line 1528... | ||
1472 | 1528 | ||
1473 | - | ||
1474 | 1529 | ||
1475 | ;----------------------------------------------------------------- |
- | |
1476 | ; |
1530 | |
1477 | ; SOCKET_input |
- | |
- | 1531 | ;-----------------------------------------------------------------; |
|
1478 | ; |
1532 | ; ; |
1479 | ; Updates a (stateless) socket with received data |
- | |
- | 1533 | ; SOCKET_input: Update a (stateless) socket with received data. ; |
|
1480 | ; |
1534 | ; ; |
1481 | ; Note: the mutex should already be set ! |
1535 | ; Note: The socket's mutex should already be set ! ; |
1482 | ; |
1536 | ; ; |
1483 | ; IN: eax = socket ptr |
1537 | ; IN: eax = socket ptr ; |
1484 | ; ecx = data size |
- | |
- | 1538 | ; ecx = data size ; |
|
1485 | ; esi = ptr to data |
1539 | ; esi = ptr to data ; |
1486 | ; [esp] = ptr to buf |
- | |
- | 1540 | ; [esp] = ptr to buf ; |
|
1487 | ; |
1541 | ; ; |
1488 | ; OUT: / |
1542 | ; OUT: / ; |
1489 | ; |
1543 | ; ; |
Line 1490... | Line 1544... | ||
1490 | ;----------------------------------------------------------------- |
1544 | ;-----------------------------------------------------------------; |
Line 1520... | Line 1574... | ||
1520 | add esp, 8 |
1574 | add esp, 8 |
1521 | call NET_BUFF_free |
1575 | call NET_BUFF_free |
1522 | ret |
1576 | ret |
Line 1523... | Line 1577... | ||
1523 | 1577 | ||
1524 | - | ||
- | 1578 | ||
- | 1579 | ;-----------------------------------------------------------------; |
|
- | 1580 | ; ; |
|
1525 | ;-------------------------- |
1581 | ; SOCKET_ring_create: Create a ringbuffer for sockets. ; |
1526 | ; |
- | |
- | 1582 | ; ; |
|
- | 1583 | ; IN: eax = ptr to ring struct ; |
|
- | 1584 | ; ; |
|
- | 1585 | ; OUT: eax = 0 on error ; |
|
- | 1586 | ; eax = start ptr ; |
|
1527 | ; eax = ptr to ring struct (just a buffer of the right size) |
1587 | ; ; |
1528 | ; |
1588 | ;-----------------------------------------------------------------; |
Line 1529... | Line 1589... | ||
1529 | align 4 |
1589 | align 4 |
1530 | SOCKET_ring_create: |
1590 | SOCKET_ring_create: |
Line 1559... | Line 1619... | ||
1559 | .fail: |
1619 | .fail: |
1560 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_ring_create: Out of memory!\n" |
1620 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_ring_create: Out of memory!\n" |
1561 | pop esi |
1621 | pop esi |
1562 | ret |
1622 | ret |
Line 1563... | Line 1623... | ||
1563 | 1623 | ||
1564 | ;----------------------------------------------------------------- |
- | |
- | 1624 | ;-----------------------------------------------------------------; |
|
1565 | ; |
1625 | ; ; |
1566 | ; SOCKET_ring_write |
- | |
1567 | ; |
1626 | ; SOCKET_ring_write: Write data to ring buffer. ; |
1568 | ; Adds data to a stream socket, and updates write pointer and size |
- | |
1569 | ; |
1627 | ; ; |
1570 | ; IN: eax = ptr to ring struct |
1628 | ; IN: eax = ptr to ring struct ; |
1571 | ; ecx = data size |
1629 | ; ecx = data size ; |
1572 | ; esi = ptr to data |
- | |
- | 1630 | ; esi = ptr to data ; |
|
1573 | ; |
1631 | ; ; |
1574 | ; OUT: ecx = number of bytes stored |
- | |
- | 1632 | ; OUT: ecx = number of bytes stored ; |
|
1575 | ; |
1633 | ; ; |
1576 | ;----------------------------------------------------------------- |
1634 | ;-----------------------------------------------------------------; |
1577 | align 4 |
1635 | align 4 |
Line 1578... | Line 1636... | ||
1578 | SOCKET_ring_write: |
1636 | SOCKET_ring_write: |
Line 1631... | Line 1689... | ||
1631 | call mutex_unlock ; TODO: check what registers this function actually destroys |
1689 | call mutex_unlock ; TODO: check what registers this function actually destroys |
1632 | popa |
1690 | popa |
Line 1633... | Line 1691... | ||
1633 | 1691 | ||
Line 1634... | Line 1692... | ||
1634 | ret |
1692 | ret |
1635 | - | ||
- | 1693 | ||
1636 | ;----------------------------------------------------------------- |
1694 | ;-----------------------------------------------------------------; |
1637 | ; |
- | |
- | 1695 | ; ; |
|
1638 | ; SOCKET_ring_read |
1696 | ; SOCKET_ring_read: Read from ring buffer ; |
1639 | ; |
1697 | ; ; |
1640 | ; IN: eax = ring struct ptr |
1698 | ; IN: eax = ring struct ptr ; |
1641 | ; ecx = bytes to read |
1699 | ; ecx = bytes to read ; |
1642 | ; edx = offset |
- | |
- | 1700 | ; edx = offset ; |
|
1643 | ; edi = ptr to buffer start |
1701 | ; edi = ptr to buffer start ; |
1644 | ; |
1702 | ; ; |
1645 | ; OUT: eax = unchanged |
1703 | ; OUT: eax = unchanged ; |
1646 | ; ecx = number of bytes read (0 on error) |
1704 | ; ecx = number of bytes read (0 on error) ; |
1647 | ; edx = destroyed |
1705 | ; edx = destroyed ; |
1648 | ; esi = destroyed |
- | |
- | 1706 | ; esi = destroyed ; |
|
1649 | ; edi = ptr to buffer end |
1707 | ; edi = ptr to buffer end ; |
1650 | ; |
1708 | ; ; |
1651 | ;----------------------------------------------------------------- |
1709 | ;-----------------------------------------------------------------; |
Line 1652... | Line 1710... | ||
1652 | align 4 |
1710 | align 4 |
Line 1705... | Line 1763... | ||
1705 | .less_data: |
1763 | .less_data: |
1706 | mov ecx, edx |
1764 | mov ecx, edx |
1707 | jmp .copy |
1765 | jmp .copy |
Line 1708... | Line 1766... | ||
1708 | 1766 | ||
1709 | - | ||
- | 1767 | ||
1710 | ;----------------------------------------------------------------- |
1768 | ;-----------------------------------------------------------------; |
1711 | ; |
- | |
1712 | ; SOCKET_ring_free |
1769 | ; ; |
1713 | ; |
- | |
1714 | ; Free's some bytes from the ringbuffer |
1770 | ; SOCKET_ring_free: Free data from a ringbuffer ; |
1715 | ; |
1771 | ; ; |
1716 | ; IN: eax = ptr to ring struct |
- | |
- | 1772 | ; IN: eax = ptr to ring struct ; |
|
1717 | ; ecx = data size |
1773 | ; ecx = data size ; |
1718 | ; |
- | |
- | 1774 | ; ; |
|
1719 | ; OUT: ecx = number of bytes free-ed |
1775 | ; OUT: ecx = number of freed bytes ; |
1720 | ; |
1776 | ; ; |
1721 | ;----------------------------------------------------------------- |
1777 | ;-----------------------------------------------------------------; |
Line 1722... | Line 1778... | ||
1722 | align 4 |
1778 | align 4 |
Line 1757... | Line 1813... | ||
1757 | 1813 | ||
1758 | xor ecx, ecx |
1814 | xor ecx, ecx |
Line 1759... | Line 1815... | ||
1759 | ret |
1815 | ret |
1760 | - | ||
1761 | 1816 | ||
1762 | ;----------------------------------------------------------------- |
- | |
1763 | ; |
1817 | |
1764 | ; SOCKET_block |
- | |
- | 1818 | ;-----------------------------------------------------------------; |
|
1765 | ; |
1819 | ; ; |
- | 1820 | ; SOCKET_block: Suspend the thread attached to a socket. ; |
|
1766 | ; Suspends the thread attached to a socket |
1821 | ; ; |
1767 | ; |
- | |
- | 1822 | ; IN: eax = socket ptr ; |
|
1768 | ; IN: eax = socket ptr |
1823 | ; ; |
1769 | ; OUT: eax = unchanged |
1824 | ; OUT: eax = unchanged ; |
1770 | ; |
1825 | ; ; |
Line 1771... | Line 1826... | ||
1771 | ;----------------------------------------------------------------- |
1826 | ;-----------------------------------------------------------------; |
Line 1800... | Line 1855... | ||
1800 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_block: continuing\n" |
1855 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_block: continuing\n" |
Line 1801... | Line 1856... | ||
1801 | 1856 | ||
Line 1802... | Line 1857... | ||
1802 | ret |
1857 | ret |
1803 | - | ||
- | 1858 | ||
1804 | 1859 | ||
1805 | ;----------------------------------------------------------------- |
- | |
1806 | ; |
1860 | ;-----------------------------------------------------------------; |
1807 | ; SOCKET_notify |
- | |
1808 | ; |
1861 | ; ; |
- | 1862 | ; SOCKET_notify: Wake up socket owner thread. ; |
|
1809 | ; notify's the owner of a socket that something happened |
1863 | ; ; |
1810 | ; |
- | |
- | 1864 | ; IN: eax = socket ptr ; |
|
1811 | ; IN: eax = socket ptr |
1865 | ; ; |
1812 | ; OUT: eax = unchanged |
1866 | ; OUT: eax = unchanged ; |
1813 | ; |
1867 | ; ; |
Line 1814... | Line 1868... | ||
1814 | ;----------------------------------------------------------------- |
1868 | ;-----------------------------------------------------------------; |
Line 1848... | Line 1902... | ||
1848 | 1902 | ||
1849 | .found: |
1903 | .found: |
1850 | test [eax + SOCKET.state], SS_BLOCKED |
1904 | test [eax + SOCKET.state], SS_BLOCKED |
Line 1851... | Line 1905... | ||
1851 | jnz .un_block |
1905 | jnz .un_block |
1852 | 1906 | ||
1853 | ; socket and thread exists and socket is of non blocking type. |
1907 | ; Socket and thread exists and socket is of non blocking type. |
1854 | ; We'll try to flag an event to the thread. |
1908 | ; We'll try to flag an event to the thread. |
Line 1855... | Line 1909... | ||
1855 | shl ecx, 8 |
1909 | shl ecx, 8 |
1856 | or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK |
1910 | or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK |
1857 | 1911 | ||
Line 1858... | Line 1912... | ||
1858 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_notify: poking thread %u!\n", eax |
1912 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_notify: poking thread %u!\n", eax |
1859 | pop esi ecx ebx |
1913 | pop esi ecx ebx |
1860 | ret |
1914 | ret |
1861 | 1915 | ||
1862 | 1916 | ||
Line 1863... | Line 1917... | ||
1863 | .un_block: |
1917 | .un_block: |
1864 | ; socket and thread exists and socket is of blocking type |
1918 | ; Socket and thread exists and socket is of blocking type |
1865 | ; We'll try to unblock it. |
1919 | ; We'll try to unblock it. |
Line 1866... | Line 1920... | ||
1866 | and [eax + SOCKET.state], not SS_BLOCKED ; Clear the 'socket is blocked' flag |
1920 | and [eax + SOCKET.state], not SS_BLOCKED ; Clear the 'socket is blocked' flag |
1867 | mov [esi + TASKDATA.state], 0 ; Run the thread |
- | |
- | 1921 | mov [esi + TASKDATA.state], 0 ; Run the thread |
|
1868 | 1922 | ||
1869 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_notify: Unblocked socket!\n" |
- | |
1870 | pop esi ecx ebx |
1923 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_notify: Unblocked socket!\n" |
1871 | ret |
1924 | pop esi ecx ebx |
1872 | 1925 | ret |
|
1873 | - | ||
- | 1926 | ||
1874 | ;-------------------------------------------------------------------- |
1927 | |
- | 1928 | ;-----------------------------------------------------------------; |
|
- | 1929 | ; ; |
|
1875 | ; |
1930 | ; SOCKET_alloc: ; |
1876 | ; SOCKET_alloc |
1931 | ; Allocate memory for socket and put new socket into the list. ; |
1877 | ; |
- | |
- | 1932 | ; Newly created socket is initialized with calling PID and socket ; |
|
1878 | ; Allocate memory for socket data and put new socket into the list |
1933 | ; number. ; |
1879 | ; Newly created socket is initialized with calling PID and number and |
1934 | ; ; |
1880 | ; put into beginning of list (which is the fastest way). |
1935 | ; IN: / ; |
Line 1881... | Line 1936... | ||
1881 | ; |
1936 | ; ; |
Line 1986... | Line 2041... | ||
1986 | mov dword[esp+20], ENOTCONN |
2041 | mov dword[esp+20], ENOTCONN |
1987 | mov dword[esp+32], -1 |
2042 | mov dword[esp+32], -1 |
1988 | ret |
2043 | ret |
Line 1989... | Line 2044... | ||
1989 | 2044 | ||
1990 | - | ||
- | 2045 | ||
1991 | ;---------------------------------------------------- |
2046 | ;-----------------------------------------------------------------; |
1992 | ; |
- | |
1993 | ; SOCKET_free |
2047 | ; ; |
1994 | ; |
2048 | ; SOCKET_free: ; |
1995 | ; Free socket data memory and remove socket from the list |
- | |
- | 2049 | ; Free socket data memory and remove socket from the list. ; |
|
1996 | ; Caller should lock and unlock socket_mutex |
2050 | ; Caller should lock and unlock socket_mutex. ; |
- | 2051 | ; ; |
|
1997 | ; |
2052 | ; IN: eax = socket ptr ; |
1998 | ; IN: eax = socket ptr |
- | |
- | 2053 | ; ; |
|
1999 | ; OUT: / |
2054 | ; OUT: / ; |
2000 | ; |
2055 | ; ; |
2001 | ;---------------------------------------------------- |
2056 | ;-----------------------------------------------------------------; |
Line 2002... | Line 2057... | ||
2002 | align 4 |
2057 | align 4 |
Line 2054... | Line 2109... | ||
2054 | .error: |
2109 | .error: |
2055 | ret |
2110 | ret |
Line 2056... | Line 2111... | ||
2056 | 2111 | ||
2057 | .error1: |
2112 | .error1: |
2058 | pop ebx |
2113 | pop ebx |
2059 | DEBUGF DEBUG_NETWORK_ERROR, "Error in socket free!\n" |
2114 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_free: error!\n" |
2060 | DEBUGF DEBUG_NETWORK_ERROR, "socket ptr=0x%x caller=0x%x\n", eax, [esp] |
2115 | DEBUGF DEBUG_NETWORK_ERROR, "socket ptr=0x%x caller=0x%x\n", eax, [esp] |
Line 2061... | Line 2116... | ||
2061 | ret |
2116 | ret |
2062 | - | ||
2063 | ;------------------------------------ |
2117 | |
2064 | ; |
- | |
2065 | ; SOCKET_fork |
2118 | ;-----------------------------------------------------------------; |
2066 | ; |
- | |
- | 2119 | ; ; |
|
2067 | ; Create a child socket |
2120 | ; SOCKET_fork: Create a child socket. ; |
- | 2121 | ; ; |
|
2068 | ; |
2122 | ; IN: ebx = socket number ; |
2069 | ; IN: socket nr in ebx |
- | |
- | 2123 | ; ; |
|
- | 2124 | ; OUT: eax = child socket number on success ; |
|
2070 | ; OUT: child socket nr in eax |
2125 | ; eax = 0 on error ; |
2071 | ; |
2126 | ; ; |
2072 | ;----------------------------------- |
2127 | ;-----------------------------------------------------------------; |
Line 2073... | Line 2128... | ||
2073 | align 4 |
2128 | align 4 |
Line 2116... | Line 2171... | ||
2116 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_fork: failed\n" |
2171 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_fork: failed\n" |
2117 | xor eax, eax |
2172 | xor eax, eax |
2118 | ret |
2173 | ret |
Line 2119... | Line 2174... | ||
2119 | 2174 | ||
2120 | - | ||
2121 | ;--------------------------------------------------- |
2175 | |
2122 | ; |
- | |
2123 | ; SOCKET_num_to_ptr |
2176 | ;-----------------------------------------------------------------; |
2124 | ; |
- | |
- | 2177 | ; ; |
|
2125 | ; Get socket structure address by its number |
2178 | ; SOCKET_num_to_ptr: Get socket structure address by its number. ; |
- | 2179 | ; ; |
|
- | 2180 | ; IN: ecx = socket number ; |
|
2126 | ; |
2181 | ; ; |
2127 | ; IN: ecx = socket number |
- | |
- | 2182 | ; OUT: eax = socket ptr ; |
|
2128 | ; OUT: eax = 0 on error, socket ptr otherwise |
2183 | ; eax = 0 on error ; |
2129 | ; |
2184 | ; ; |
2130 | ;--------------------------------------------------- |
2185 | ;-----------------------------------------------------------------; |
Line 2131... | Line 2186... | ||
2131 | align 4 |
2186 | align 4 |
Line 2163... | Line 2218... | ||
2163 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: socket %u not found!\n", eax |
2218 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: socket %u not found!\n", eax |
2164 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: caller = 0x%x\n", [esp] |
2219 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: caller = 0x%x\n", [esp] |
2165 | ret |
2220 | ret |
Line 2166... | Line 2221... | ||
2166 | 2221 | ||
2167 | - | ||
2168 | ;--------------------------------------------------- |
2222 | |
2169 | ; |
- | |
2170 | ; SOCKET_ptr_to_num |
2223 | ;-----------------------------------------------------------------; |
2171 | ; |
- | |
- | 2224 | ; ; |
|
2172 | ; Get socket number by its address |
2225 | ; SOCKET_ptr_to_num: Get socket number by its address. ; |
- | 2226 | ; ; |
|
- | 2227 | ; IN: eax = socket ptr ; |
|
2173 | ; |
2228 | ; ; |
2174 | ; IN: eax = socket ptr |
2229 | ; OUT: eax = socket number ; |
2175 | ; OUT: eax = 0 on error, socket num otherwise |
- | |
- | 2230 | ; eax = 0 on error ; |
|
2176 | ; ZF = set on error |
2231 | ; ZF = set on error ; |
2177 | ; |
2232 | ; ; |
2178 | ;--------------------------------------------------- |
2233 | ;-----------------------------------------------------------------; |
Line 2179... | Line 2234... | ||
2179 | align 4 |
2234 | align 4 |
Line 2192... | Line 2247... | ||
2192 | .error: |
2247 | .error: |
2193 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_ptr_to_num: not found\n", eax |
2248 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_ptr_to_num: not found\n", eax |
2194 | ret |
2249 | ret |
Line 2195... | Line 2250... | ||
2195 | 2250 | ||
2196 | - | ||
2197 | ;--------------------------------------------------- |
2251 | |
2198 | ; |
- | |
2199 | ; SOCKET_check |
2252 | ;-----------------------------------------------------------------; |
2200 | ; |
- | |
- | 2253 | ; ; |
|
2201 | ; checks if the given value is really a socket ptr |
2254 | ; SOCKET_check: Checks if the given ptr is really a socket ptr. ; |
- | 2255 | ; ; |
|
2202 | ; |
2256 | ; IN: eax = socket ptr ; |
2203 | ; IN: eax = socket ptr |
2257 | ; ; |
2204 | ; OUT: eax = 0 on error, unchanged otherwise |
- | |
- | 2258 | ; OUT: eax = 0 on error ; |
|
2205 | ; ZF = set on error |
2259 | ; ZF = set on error ; |
2206 | ; |
2260 | ; ; |
2207 | ;--------------------------------------------------- |
2261 | ;-----------------------------------------------------------------; |
Line 2208... | Line 2262... | ||
2208 | align 4 |
2262 | align 4 |
Line 2227... | Line 2281... | ||
2227 | test eax, eax |
2281 | test eax, eax |
2228 | pop ebx |
2282 | pop ebx |
2229 | ret |
2283 | ret |
Line 2230... | Line 2284... | ||
2230 | 2284 | ||
2231 | .error: |
2285 | .error: |
2232 | DEBUGF DEBUG_NETWORK_ERROR, "Socket_check called with argument 0\n" |
2286 | DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_check: called with argument 0\n" |
2233 | DEBUGF DEBUG_NETWORK_ERROR, "stack: 0x%x, 0x%x, 0x%x\n", [esp], [esp+4], [esp+8] |
2287 | DEBUGF DEBUG_NETWORK_ERROR, "stack: 0x%x, 0x%x, 0x%x\n", [esp], [esp+4], [esp+8] |
Line 2234... | Line 2288... | ||
2234 | ret |
2288 | ret |
2235 | - | ||
2236 | 2289 | ||
2237 | - | ||
2238 | ;--------------------------------------------------- |
2290 | |
2239 | ; |
- | |
- | 2291 | ||
2240 | ; SOCKET_check_owner |
2292 | ;-----------------------------------------------------------------; |
- | 2293 | ; ; |
|
2241 | ; |
2294 | ; SOCKET_check_owner: Check if the caller app owns the socket. ; |
2242 | ; checks if the caller application owns the socket |
- | |
- | 2295 | ; ; |
|
2243 | ; |
2296 | ; IN: eax = socket ptr ; |
2244 | ; IN: eax = socket ptr |
2297 | ; ; |
2245 | ; OUT: ZF = true/false |
2298 | ; OUT: ZF = true/false ; |
Line 2246... | Line 2299... | ||
2246 | ; |
2299 | ; ; |
Line 2259... | Line 2312... | ||
2259 | ret |
2312 | ret |
Line 2260... | Line 2313... | ||
2260 | 2313 | ||
2261 | - | ||
- | 2314 | ||
2262 | 2315 | ||
2263 | - | ||
2264 | ;------------------------------------------------------ |
2316 | |
2265 | ; |
2317 | ;-----------------------------------------------------------------; |
2266 | ; SOCKET_process_end |
2318 | ; ; |
2267 | ; |
- | |
- | 2319 | ; SOCKET_process_end: ; |
|
2268 | ; Kernel calls this function when a certain process ends |
2320 | ; Kernel calls this function when a certain process ends. ; |
- | 2321 | ; This function will check if the process had any open sockets, ; |
|
2269 | ; This function will check if the process had any open sockets |
2322 | ; and update them accordingly (clean up). ; |
2270 | ; And update them accordingly (clean up) |
- | |
- | 2323 | ; ; |
|
2271 | ; |
2324 | ; IN: edx = pid ; |
2272 | ; IN: edx = pid |
2325 | ; ; |
2273 | ; OUT: / |
2326 | ; OUT: / ; |
Line 2274... | Line 2327... | ||
2274 | ; |
2327 | ; ; |
Line 2337... | Line 2390... | ||
2337 | ret |
2390 | ret |
Line 2338... | Line 2391... | ||
2338 | 2391 | ||
2339 | - | ||
- | 2392 | ||
2340 | 2393 | ||
2341 | - | ||
- | 2394 | ||
2342 | ;----------------------------------------------------------------- |
2395 | ;-----------------------------------------------------------------; |
- | 2396 | ; ; |
|
2343 | ; |
2397 | ; SOCKET_is_connecting: Update socket state. ; |
2344 | ; SOCKET_is_connecting |
- | |
- | 2398 | ; ; |
|
2345 | ; |
2399 | ; IN: eax = socket ptr ; |
2346 | ; IN: eax = socket ptr |
- | |
2347 | ; OUT: / |
2400 | ; ; |
2348 | ; |
2401 | ; OUT: / ; |
Line 2349... | Line 2402... | ||
2349 | ;----------------------------------------------------------------- |
2402 | ; ; |
Line 2350... | Line 2403... | ||
2350 | 2403 | ;-----------------------------------------------------------------; |
|
2351 | align 4 |
2404 | align 4 |
2352 | SOCKET_is_connecting: |
- | |
2353 | 2405 | SOCKET_is_connecting: |
|
Line 2354... | Line 2406... | ||
2354 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_connecting: %x\n", eax |
2406 | |
2355 | - | ||
- | 2407 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_connecting: %x\n", eax |
|
2356 | and [eax + SOCKET.state], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING) |
2408 | |
2357 | or [eax + SOCKET.state], SS_ISCONNECTING |
- | |
- | 2409 | and [eax + SOCKET.state], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING) |
|
2358 | 2410 | or [eax + SOCKET.state], SS_ISCONNECTING |
|
- | 2411 | ret |
|
2359 | ret |
2412 | |
2360 | - | ||
- | 2413 | ||
2361 | 2414 | ||
2362 | - | ||
2363 | ;----------------------------------------------------------------- |
2415 | ;-----------------------------------------------------------------; |
2364 | ; |
2416 | ; ; |
Line 2365... | Line 2417... | ||
2365 | ; SOCKET_is_connected |
2417 | ; SOCKET_is_connected: Update socket state. ; |
Line 2366... | Line 2418... | ||
2366 | ; |
2418 | ; ; |
2367 | ; IN: eax = socket ptr |
2419 | ; IN: eax = socket ptr ; |
2368 | ; OUT: / |
- | |
2369 | ; |
2420 | ; ; |
Line 2370... | Line 2421... | ||
2370 | ;----------------------------------------------------------------- |
2421 | ; OUT: / ; |
2371 | - | ||
- | 2422 | ; ; |
|
2372 | align 4 |
2423 | ;-----------------------------------------------------------------; |
2373 | SOCKET_is_connected: |
- | |
- | 2424 | align 4 |
|
2374 | 2425 | SOCKET_is_connected: |
|
- | 2426 | ||
2375 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_connected: %x\n", eax |
2427 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_connected: %x\n", eax |
2376 | - | ||
- | 2428 | ||
2377 | and [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING) |
2429 | and [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING) |
2378 | or [eax + SOCKET.state], SS_ISCONNECTED |
- | |
2379 | 2430 | or [eax + SOCKET.state], SS_ISCONNECTED |
|
2380 | jmp SOCKET_notify |
2431 | jmp SOCKET_notify |
Line 2381... | Line 2432... | ||
2381 | 2432 | ||
Line 2382... | Line 2433... | ||
2382 | 2433 | ||
2383 | 2434 | ||
2384 | - | ||
2385 | ;----------------------------------------------------------------- |
2435 | |
Line 2386... | Line 2436... | ||
2386 | ; |
2436 | ;-----------------------------------------------------------------; |
2387 | ; SOCKET_is_disconnecting |
- | |
- | 2437 | ; ; |
|
2388 | ; |
2438 | ; SOCKET_is_disconnecting: Update socket state. ; |
2389 | ; IN: eax = socket ptr |
- | |
- | 2439 | ; ; |
|
2390 | ; OUT: / |
2440 | ; IN: eax = socket ptr ; |
- | 2441 | ; ; |
|
2391 | ; |
2442 | ; OUT: / ; |
2392 | ;----------------------------------------------------------------- |
- | |
- | 2443 | ; ; |
|
2393 | 2444 | ;-----------------------------------------------------------------; |
|
2394 | align 4 |
- | |
2395 | SOCKET_is_disconnecting: |
2445 | align 4 |
2396 | 2446 | SOCKET_is_disconnecting: |
|
Line 2397... | Line 2447... | ||
2397 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnecting: %x\n", eax |
2447 | |
Line 2398... | Line 2448... | ||
2398 | 2448 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnecting: %x\n", eax |
|
2399 | and [eax + SOCKET.state], not (SS_ISCONNECTING) |
2449 | |
2400 | or [eax + SOCKET.state], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE |
- | |
2401 | - | ||
2402 | jmp SOCKET_notify |
2450 | and [eax + SOCKET.state], not (SS_ISCONNECTING) |
Line 2403... | Line 2451... | ||
2403 | 2451 | or [eax + SOCKET.state], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE |
|
2404 | - | ||
- | 2452 | jmp SOCKET_notify |
|
2405 | 2453 | ||
2406 | ;----------------------------------------------------------------- |
- | |
- | 2454 | ||
2407 | ; |
2455 | |
- | 2456 | ;-----------------------------------------------------------------; |
|
2408 | ; SOCKET_is_disconnected |
2457 | ; ; |
2409 | ; |
- | |
- | 2458 | ; SOCKET_is_disconnected: Update socket state. ; |
|
2410 | ; IN: eax = socket ptr |
2459 | ; ; |
2411 | ; OUT: / |
- | |
2412 | ; |
2460 | ; IN: eax = socket ptr ; |
2413 | ;----------------------------------------------------------------- |
2461 | ; ; |
Line 2414... | Line 2462... | ||
2414 | 2462 | ; OUT: / ; |
|
Line 2415... | Line 2463... | ||
2415 | align 4 |
2463 | ; ; |
2416 | SOCKET_is_disconnected: |
- | |
2417 | 2464 | ;-----------------------------------------------------------------; |
|
2418 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnected: %x\n", eax |
- | |
2419 | - | ||
2420 | and [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING) |
- | |
Line 2421... | Line -... | ||
2421 | or [eax + SOCKET.state], SS_CANTRCVMORE + SS_CANTSENDMORE |
- | |
2422 | - | ||
2423 | - | ||
2424 | jmp SOCKET_notify |
- | |
2425 | - | ||
2426 | - | ||
2427 | - | ||
2428 | ;----------------------------------------------------------------- |
- | |
Line -... | Line 2465... | ||
- | 2465 | align 4 |
|
- | 2466 | SOCKET_is_disconnected: |
|
- | 2467 | ||
- | 2468 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnected: %x\n", eax |
|
- | 2469 | ||
- | 2470 | and [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING) |
|
- | 2471 | or [eax + SOCKET.state], SS_CANTRCVMORE + SS_CANTSENDMORE |
|
- | 2472 | jmp SOCKET_notify |
|
- | 2473 | ||
2429 | ; |
2474 | |
2430 | ; SOCKET_cant_recv_more |
2475 | |
Line 2431... | Line 2476... | ||
2431 | ; |
2476 | ;-----------------------------------------------------------------; |
Line 2432... | Line 2477... | ||
2432 | ; IN: eax = socket ptr |
2477 | ; ; |
2433 | ; OUT: / |
2478 | ; SOCKET_cant_recv_more: Update socket state. ; |
2434 | ; |
- | |
2435 | ;----------------------------------------------------------------- |
2479 | ; ; |
2436 | - | ||
2437 | align 4 |
- | |
Line 2438... | Line 2480... | ||
2438 | SOCKET_cant_recv_more: |
2480 | ; IN: eax = socket ptr ; |
2439 | 2481 | ; ; |
|
2440 | DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_cant_recv_more: %x\n", eax |
2482 | ; OUT: / ; |
2441 | 2483 | ; ; |