Subversion Repositories Kolibri OS

Rev

Rev 5842 | Rev 5976 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5842 Rev 5969
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: 5842 $
18
$Revision: 5969 $
Line 19... Line 19...
19
 
19
 
20
struct  SOCKET
20
struct  SOCKET
Line 419... Line 419...
419
SOCKET_bind:
419
SOCKET_bind:
Line 420... Line 420...
420
 
420
 
Line 421... Line 421...
421
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
421
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
-
 
422
 
422
 
423
        call    SOCKET_num_to_ptr
Line 423... Line 424...
423
        call    SOCKET_num_to_ptr
424
        test    eax, eax
424
        jz      .invalid
425
        jz      .invalid
Line 508... Line 509...
508
SOCKET_connect:
509
SOCKET_connect:
Line 509... Line 510...
509
 
510
 
Line 510... Line 511...
510
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
511
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
-
 
512
 
511
 
513
        call    SOCKET_num_to_ptr
Line 512... Line 514...
512
        call    SOCKET_num_to_ptr
514
        test    eax, eax
513
        jz      .invalid
515
        jz      .invalid
Line 564... Line 566...
564
SOCKET_listen:
566
SOCKET_listen:
Line 565... Line 567...
565
 
567
 
Line 566... Line 568...
566
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx
568
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx
-
 
569
 
567
 
570
        call    SOCKET_num_to_ptr
Line 568... Line 571...
568
        call    SOCKET_num_to_ptr
571
        test    eax, eax
569
        jz      .invalid
572
        jz      .invalid
Line 630... Line 633...
630
SOCKET_accept:
633
SOCKET_accept:
Line 631... Line 634...
631
 
634
 
Line 632... Line 635...
632
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
635
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
-
 
636
 
633
 
637
        call    SOCKET_num_to_ptr
Line 634... Line 638...
634
        call    SOCKET_num_to_ptr
638
        test    eax, eax
635
        jz      .invalid
639
        jz      .invalid
Line 647... Line 651...
647
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .block
651
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .block
Line 648... Line 652...
648
 
652
 
649
; Ok, we got a socket ptr
653
; Ok, we got a socket ptr
Line -... Line 654...
-
 
654
        mov     eax, [esi]
-
 
655
 
-
 
656
; Verify that it is (still) a valid socket
-
 
657
        call    SOCKET_check
650
        mov     eax, [esi]
658
        jz      .invalid
651
 
659
 
652
; Change thread ID to that of the current thread
660
; Change sockets thread owner ID to that of the current thread
653
        mov     ebx, [TASK_BASE]
661
        mov     ebx, [TASK_BASE]
Line 654... Line 662...
654
        mov     ebx, [ebx + TASKDATA.pid]
662
        mov     ebx, [ebx + TASKDATA.pid]
655
        mov     [eax + SOCKET.TID], ebx
-
 
656
 
663
        mov     [eax + SOCKET.TID], ebx
657
; Convert it to a socket number
-
 
658
        call    SOCKET_ptr_to_num
-
 
659
        jz      .invalid        ; FIXME ?
664
 
660
 
665
; Return socket number to caller
Line 661... Line 666...
661
; and return it to caller
666
        mov     eax, [eax + SOCKET.Number]
662
        mov     [esp+32], eax
667
        mov     [esp+32], eax
Line 696... Line 701...
696
SOCKET_close:
701
SOCKET_close:
Line 697... Line 702...
697
 
702
 
Line 698... Line 703...
698
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_close: socknum=%u\n", ecx
703
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_close: socknum=%u\n", ecx
-
 
704
 
699
 
705
        call    SOCKET_num_to_ptr
Line 700... Line 706...
700
        call    SOCKET_num_to_ptr
706
        test    eax, eax
Line 701... Line 707...
701
        jz      .invalid
707
        jz      .invalid
Line 752... Line 758...
752
SOCKET_receive:
758
SOCKET_receive:
Line 753... Line 759...
753
 
759
 
Line 754... Line 760...
754
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi
760
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi
-
 
761
 
755
 
762
        call    SOCKET_num_to_ptr
Line 756... Line 763...
756
        call    SOCKET_num_to_ptr
763
        test    eax, eax
757
        jz      .invalid
764
        jz      .invalid
758
 
765
 
Line 925... Line 932...
925
SOCKET_send:
932
SOCKET_send:
Line 926... Line 933...
926
 
933
 
Line 927... Line 934...
927
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi
934
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi
-
 
935
 
928
 
936
        call    SOCKET_num_to_ptr
Line 929... Line 937...
929
        call    SOCKET_num_to_ptr
937
        test    eax, eax
930
        jz      .invalid
938
        jz      .invalid
Line 1094... Line 1102...
1094
SOCKET_get_opt:
1102
SOCKET_get_opt:
Line 1095... Line 1103...
1095
 
1103
 
Line 1096... Line 1104...
1096
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_get_opt\n"
1104
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_get_opt\n"
-
 
1105
 
1097
 
1106
        call    SOCKET_num_to_ptr
Line 1098... Line 1107...
1098
        call    SOCKET_num_to_ptr
1107
        test    eax, eax
1099
        jz      .invalid
1108
        jz      .invalid
1100
 
1109
 
Line 1155... Line 1164...
1155
SOCKET_set_opt:
1164
SOCKET_set_opt:
Line 1156... Line 1165...
1156
 
1165
 
Line 1157... Line 1166...
1157
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_set_opt\n"
1166
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_set_opt\n"
-
 
1167
 
1158
 
1168
        call    SOCKET_num_to_ptr
Line 1159... Line 1169...
1159
        call    SOCKET_num_to_ptr
1169
        test    eax, eax
1160
        jz      .invalid
1170
        jz      .invalid
1161
 
1171
 
Line 1262... Line 1272...
1262
        mov     [ebx + SOCKET.device], eax
1272
        mov     [ebx + SOCKET.device], eax
Line 1263... Line 1273...
1263
 
1273
 
1264
        lea     eax, [eax + STREAM_SOCKET.rcv]
1274
        lea     eax, [eax + STREAM_SOCKET.rcv]
1265
        call    SOCKET_ring_create
1275
        call    SOCKET_ring_create
1266
        test    eax, eax
1276
        test    eax, eax
Line 1267... Line 1277...
1267
        jz      .nomem1
1277
        jz      .nomem2
1268
 
1278
 
1269
        lea     eax, [ebx + STREAM_SOCKET.rcv]
1279
        lea     eax, [ebx + STREAM_SOCKET.rcv]
1270
        call    SOCKET_ring_create
1280
        call    SOCKET_ring_create
Line 1271... Line 1281...
1271
        test    eax, eax
1281
        test    eax, eax
Line 1272... Line 1282...
1272
        jz      .nomem2
1282
        jz      .nomem2
1273
 
1283
 
1274
        ret
1284
        ret
-
 
1285
 
1275
 
1286
  .nomem2:
-
 
1287
        mov     eax, [esp+20]
-
 
1288
        call    SOCKET_free
-
 
1289
 
1276
  .nomem2:
1290
  .nomem1:
1277
        mov     eax, ebx
1291
        mov     eax, [esp+32]
1278
        call    SOCKET_free
1292
        call    SOCKET_free
Line 1279... Line 1293...
1279
  .nomem1:
1293
 
Line 1303... Line 1317...
1303
 
1317
 
1304
        test    ecx, ecx
1318
        test    ecx, ecx
Line 1305... Line 1319...
1305
        jz      .returnall
1319
        jz      .returnall
-
 
1320
 
1306
 
1321
        call    SOCKET_num_to_ptr
Line 1307... Line 1322...
1307
        call    SOCKET_num_to_ptr
1322
        test    eax, eax
1308
        jz      .invalid
1323
        jz      .invalid
1309
 
1324
 
Line 1329... Line 1344...
1329
        mov     dword[esp+32], eax
1344
        mov     dword[esp+32], eax
1330
        ret
1345
        ret
Line 1331... Line 1346...
1331
 
1346
 
1332
  .invalid:
1347
  .invalid:
1333
        mov     dword[esp+32], -1
1348
        mov     dword[esp+32], -1
1334
        mov     dword[esp+28], EINVAL
1349
        mov     dword[esp+20], EINVAL
Line 1335... Line 1350...
1335
        ret
1350
        ret
1336
 
1351
 
Line 1521... Line 1536...
1521
        stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SWR
1536
        stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SWR
1522
        pop     edx
1537
        pop     edx
1523
        test    eax, eax
1538
        test    eax, eax
1524
        jz      .fail
1539
        jz      .fail
Line 1525... Line 1540...
1525
 
1540
 
Line 1526... Line 1541...
1526
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_created: %x\n", eax
1541
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_create: %x\n", eax
1527
 
1542
 
1528
        pusha
1543
        pusha
1529
        lea     ecx, [esi + RING_BUFFER.mutex]
1544
        lea     ecx, [esi + RING_BUFFER.mutex]
Line 1536... Line 1551...
1536
        mov     [esi + RING_BUFFER.size], 0
1551
        mov     [esi + RING_BUFFER.size], 0
1537
        add     eax, SOCKET_MAXDATA
1552
        add     eax, SOCKET_MAXDATA
1538
        mov     [esi + RING_BUFFER.end_ptr], eax
1553
        mov     [esi + RING_BUFFER.end_ptr], eax
1539
        mov     eax, esi
1554
        mov     eax, esi
Line -... Line 1555...
-
 
1555
 
-
 
1556
        pop     esi
-
 
1557
        ret
1540
 
1558
 
-
 
1559
  .fail:
1541
  .fail:
1560
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_ring_create: Out of memory!\n"
1542
        pop     esi
1561
        pop     esi
Line 1543... Line 1562...
1543
        ret
1562
        ret
1544
 
1563
 
Line 1856... Line 1875...
1856
;
1875
;
1857
; SOCKET_alloc
1876
; SOCKET_alloc
1858
;
1877
;
1859
; Allocate memory for socket data and put new socket into the list
1878
; Allocate memory for socket data and put new socket into the list
1860
; Newly created socket is initialized with calling PID and number and
1879
; Newly created socket is initialized with calling PID and number and
1861
; put into beginning of list (which is a fastest way).
1880
; put into beginning of list (which is the fastest way).
1862
;
1881
;
1863
; IN:  /
1882
; IN:  /
1864
; OUT: eax = 0 on error, socket ptr otherwise
1883
; OUT: eax = 0 on error, socket ptr otherwise
1865
;      edi = socket number
1884
;      edi = socket number
1866
;
1885
;
Line 1869... Line 1888...
1869
SOCKET_alloc:
1888
SOCKET_alloc:
Line 1870... Line 1889...
1870
 
1889
 
Line 1871... Line 1890...
1871
        push    ebx
1890
        push    ebx
1872
 
-
 
1873
        stdcall kernel_alloc, SOCKETBUFFSIZE
1891
 
1874
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_alloc: ptr=%x\n", eax
1892
        stdcall kernel_alloc, SOCKETBUFFSIZE
-
 
1893
        or      eax, eax
Line 1875... Line 1894...
1875
        or      eax, eax
1894
        jz      .nomem
1876
        jz      .exit
1895
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_alloc: ptr=%x\n", eax
1877
 
1896
 
1878
; zero-initialize allocated memory
1897
; zero-initialize allocated memory
Line 1952... Line 1971...
1952
 
1971
 
1953
        pusha
1972
        pusha
1954
        mov     ecx, socket_mutex
1973
        mov     ecx, socket_mutex
1955
        call    mutex_unlock
1974
        call    mutex_unlock
1956
        popa
-
 
1957
 
-
 
1958
  .exit:
1975
        popa
Line 1959... Line 1976...
1959
        pop     ebx
1976
        pop     ebx
Line -... Line 1977...
-
 
1977
 
-
 
1978
        ret
-
 
1979
 
-
 
1980
  .nomem:
-
 
1981
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_alloc: Out of memory!\n"
1960
 
1982
        pop     ebx
1961
        ret
1983
        ret
1962
 
1984
 
1963
  .not_yet:
1985
  .not_yet:
Line 1990... Line 2012...
1990
        pusha
2012
        pusha
1991
        lea     ecx, [eax + SOCKET.mutex]
2013
        lea     ecx, [eax + SOCKET.mutex]
1992
        call    mutex_lock
2014
        call    mutex_lock
1993
        popa
2015
        popa
Line 1994... Line 2016...
1994
 
2016
 
1995
        cmp     [eax + SOCKET.Domain], AF_INET4
-
 
1996
        jnz     .no_tcp
-
 
1997
 
-
 
1998
        cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
2017
        cmp     [eax + SOCKET.Type], SOCK_STREAM
Line 1999... Line 2018...
1999
        jnz     .no_tcp
2018
        jne     .no_stream
-
 
2019
 
-
 
2020
        mov     ebx, eax
2000
 
2021
        cmp     [eax + STREAM_SOCKET.rcv.start_ptr], 0
-
 
2022
        je      @f
-
 
2023
        stdcall free_kernel_space, [eax + STREAM_SOCKET.rcv.start_ptr]
-
 
2024
  @@:
2001
        mov     ebx, eax
2025
        cmp     [ebx + STREAM_SOCKET.snd.start_ptr], 0
-
 
2026
        je      @f
2002
        stdcall kernel_free, [ebx + STREAM_SOCKET.rcv.start_ptr]
2027
        stdcall free_kernel_space, [ebx + STREAM_SOCKET.snd.start_ptr]
2003
        stdcall kernel_free, [ebx + STREAM_SOCKET.snd.start_ptr]
2028
  @@:
Line 2004... Line 2029...
2004
        mov     eax, ebx
2029
        mov     eax, ebx
2005
  .no_tcp:
2030
  .no_stream:
2006
 
2031
 
2007
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_free: freeing socket %x\n", eax
2032
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_free: freeing socket %x\n", eax
Line 2027... Line 2052...
2027
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_free: success!\n"
2052
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_free: success!\n"
Line 2028... Line 2053...
2028
 
2053
 
2029
  .error:
2054
  .error:
Line -... Line 2055...
-
 
2055
        ret
-
 
2056
 
-
 
2057
  .error1:
-
 
2058
        pop     ebx
-
 
2059
        DEBUGF  DEBUG_NETWORK_ERROR, "Error in socket free!\n"
-
 
2060
        DEBUGF  DEBUG_NETWORK_ERROR, "socket ptr=0x%x caller=0x%x\n", eax, [esp]
2030
        ret
2061
        ret
2031
 
2062
 
2032
;------------------------------------
2063
;------------------------------------
2033
;
2064
;
2034
; SOCKET_fork
2065
; SOCKET_fork
Line 2093... Line 2124...
2093
;
2124
;
2094
; Get socket structure address by its number
2125
; Get socket structure address by its number
2095
;
2126
;
2096
; IN:  ecx = socket number
2127
; IN:  ecx = socket number
2097
; OUT: eax = 0 on error, socket ptr otherwise
2128
; OUT: eax = 0 on error, socket ptr otherwise
2098
;       ZF = set on error
-
 
2099
;
2129
;
2100
;---------------------------------------------------
2130
;---------------------------------------------------
2101
align 4
2131
align 4
2102
SOCKET_num_to_ptr:
2132
SOCKET_num_to_ptr:
Line 2107... Line 2137...
2107
        mov     ecx, socket_mutex
2137
        mov     ecx, socket_mutex
2108
        call    mutex_lock
2138
        call    mutex_lock
2109
        popa
2139
        popa
Line 2110... Line 2140...
2110
 
2140
 
2111
        mov     eax, net_sockets
-
 
2112
 
2141
        mov     eax, net_sockets
2113
  .next_socket:
2142
  .next_socket:
2114
        mov     eax, [eax + SOCKET.NextPtr]
2143
        mov     eax, [eax + SOCKET.NextPtr]
2115
        or      eax, eax
2144
        test    eax, eax
2116
        jz      .error
2145
        jz      .error
2117
        cmp     [eax + SOCKET.Number], ecx
2146
        cmp     [eax + SOCKET.Number], ecx
Line 2118... Line -...
2118
        jne     .next_socket
-
 
2119
 
-
 
2120
        test    eax, eax
2147
        jne     .next_socket
2121
 
2148
 
2122
        pusha
2149
        pusha
2123
        mov     ecx, socket_mutex
2150
        mov     ecx, socket_mutex
Line 2181... Line 2208...
2181
align 4
2208
align 4
2182
SOCKET_check:
2209
SOCKET_check:
Line 2183... Line 2210...
2183
 
2210
 
Line -... Line 2211...
-
 
2211
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_check: %x\n", eax
-
 
2212
 
2184
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_check: %x\n", eax
2213
        test    eax, eax
2185
 
2214
        jz      .error
Line 2186... Line 2215...
2186
        push    ebx
2215
        push    ebx
2187
        mov     ebx, net_sockets
2216
        mov     ebx, net_sockets
Line 2195... Line 2224...
2195
 
2224
 
2196
  .done:
2225
  .done:
2197
        mov     eax, ebx
2226
        mov     eax, ebx
2198
        test    eax, eax
2227
        test    eax, eax
-
 
2228
        pop     ebx
Line -... Line 2229...
-
 
2229
        ret
-
 
2230
 
-
 
2231
  .error:
2199
        pop     ebx
2232
        DEBUGF  DEBUG_NETWORK_ERROR, "Socket_check called with argument 0\n"
Line 2200... Line 2233...
2200
 
2233
        DEBUGF  DEBUG_NETWORK_ERROR, "stack: 0x%x, 0x%x, 0x%x\n", [esp], [esp+4], [esp+8]