@@ -37,6 +37,7 @@ static uvwasi_errno_t uvwasi__insert_stdio(uvwasi_t* uvwasi,
37
37
err = uvwasi_fd_table_insert (uvwasi ,
38
38
table ,
39
39
fd ,
40
+ NULL ,
40
41
name ,
41
42
name ,
42
43
type ,
@@ -58,6 +59,7 @@ static uvwasi_errno_t uvwasi__insert_stdio(uvwasi_t* uvwasi,
58
59
uvwasi_errno_t uvwasi_fd_table_insert (uvwasi_t * uvwasi ,
59
60
struct uvwasi_fd_table_t * table ,
60
61
uv_file fd ,
62
+ uv_tcp_t * sock ,
61
63
const char * mapped_path ,
62
64
const char * real_path ,
63
65
uvwasi_filetype_t type ,
@@ -78,29 +80,40 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
78
80
char * rp_copy ;
79
81
char * np_copy ;
80
82
81
- mp_len = strlen (mapped_path );
82
- rp_len = strlen (real_path );
83
+ if (type != UVWASI_FILETYPE_SOCKET_STREAM ) {
84
+ mp_len = strlen (mapped_path );
85
+ rp_len = strlen (real_path );
86
+ } else {
87
+ mp_len = 0 ;
88
+ rp_len = 0 ;
89
+ rp_copy = NULL ;
90
+ mp_copy = NULL ;
91
+ np_copy = NULL ;
92
+ }
93
+
83
94
/* Reserve room for the mapped path, real path, and normalized mapped path. */
84
95
entry = (struct uvwasi_fd_wrap_t * )
85
96
uvwasi__malloc (uvwasi , sizeof (* entry ) + mp_len + mp_len + rp_len + 3 );
86
97
if (entry == NULL )
87
98
return UVWASI_ENOMEM ;
88
99
89
- mp_copy = (char * )(entry + 1 );
90
- rp_copy = mp_copy + mp_len + 1 ;
91
- np_copy = rp_copy + rp_len + 1 ;
92
- memcpy (mp_copy , mapped_path , mp_len );
93
- mp_copy [mp_len ] = '\0' ;
94
- memcpy (rp_copy , real_path , rp_len );
95
- rp_copy [rp_len ] = '\0' ;
96
-
97
- /* Calculate the normalized version of the mapped path, as it will be used for
98
- any path calculations on this fd. Use the length of the mapped path as an
99
- upper bound for the normalized path length. */
100
- err = uvwasi__normalize_path (mp_copy , mp_len , np_copy , mp_len );
101
- if (err ) {
102
- uvwasi__free (uvwasi , entry );
103
- goto exit ;
100
+ if (type != UVWASI_FILETYPE_SOCKET_STREAM ) {
101
+ mp_copy = (char * )(entry + 1 );
102
+ rp_copy = mp_copy + mp_len + 1 ;
103
+ np_copy = rp_copy + rp_len + 1 ;
104
+ memcpy (mp_copy , mapped_path , mp_len );
105
+ mp_copy [mp_len ] = '\0' ;
106
+ memcpy (rp_copy , real_path , rp_len );
107
+ rp_copy [rp_len ] = '\0' ;
108
+
109
+ /* Calculate the normalized version of the mapped path, as it will be used for
110
+ any path calculations on this fd. Use the length of the mapped path as an
111
+ upper bound for the normalized path length. */
112
+ err = uvwasi__normalize_path (mp_copy , mp_len , np_copy , mp_len );
113
+ if (err ) {
114
+ uvwasi__free (uvwasi , entry );
115
+ goto exit ;
116
+ }
104
117
}
105
118
106
119
uv_rwlock_wrlock (& table -> rwlock );
@@ -150,6 +163,7 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
150
163
151
164
entry -> id = index ;
152
165
entry -> fd = fd ;
166
+ entry -> sock = sock ;
153
167
entry -> path = mp_copy ;
154
168
entry -> real_path = rp_copy ;
155
169
entry -> normalized_path = np_copy ;
@@ -280,6 +294,7 @@ uvwasi_errno_t uvwasi_fd_table_insert_preopen(uvwasi_t* uvwasi,
280
294
return uvwasi_fd_table_insert (uvwasi ,
281
295
table ,
282
296
fd ,
297
+ NULL ,
283
298
path ,
284
299
real_path ,
285
300
UVWASI_FILETYPE_DIRECTORY ,
@@ -290,6 +305,26 @@ uvwasi_errno_t uvwasi_fd_table_insert_preopen(uvwasi_t* uvwasi,
290
305
}
291
306
292
307
308
+ uvwasi_errno_t uvwasi_fd_table_insert_preopen_socket (uvwasi_t * uvwasi ,
309
+ struct uvwasi_fd_table_t * table ,
310
+ uv_tcp_t * sock ) {
311
+ if (table == NULL || sock == NULL )
312
+ return UVWASI_EINVAL ;
313
+
314
+ return uvwasi_fd_table_insert (uvwasi ,
315
+ table ,
316
+ -1 ,
317
+ sock ,
318
+ NULL ,
319
+ NULL ,
320
+ UVWASI_FILETYPE_SOCKET_STREAM ,
321
+ UVWASI__RIGHTS_SOCKET_BASE ,
322
+ UVWASI__RIGHTS_SOCKET_INHERITING ,
323
+ 1 ,
324
+ NULL );
325
+ }
326
+
327
+
293
328
uvwasi_errno_t uvwasi_fd_table_get (struct uvwasi_fd_table_t * table ,
294
329
const uvwasi_fd_t id ,
295
330
struct uvwasi_fd_wrap_t * * wrap ,
0 commit comments