MCPcopy Create free account
hub / github.com/PLSysSec/wave / wasi_socket

Function wasi_socket

src/wrappers.rs:1274–1298  ·  view source on GitHub ↗
(ctx: &mut VmCtx, domain: u32, ty: u32, protocol: u32)

Source from the content-addressed store, hash-verified

1272#[ensures(ctx_safe(ctx))]
1273#[ensures(trace_safe(trace, ctx))]
1274pub fn wasi_socket(ctx: &mut VmCtx, domain: u32, ty: u32, protocol: u32) -> RuntimeResult<u32> {
1275 // We only allow TCP and UDP, which can both be identified using protocol=0 when
1276 // domain.ty are (AF_INET,SOCK_STREAM) or (AF_INET,SOCK_DGRAM) respectively
1277 if protocol != 0 {
1278 return Err(Einval);
1279 }
1280
1281 let protocol = protocol as i32;
1282 // convert from wasi constants to posix constants
1283 let domain = sock_domain_to_posix(domain)?;
1284 let ty = sock_type_to_posix(ty)?;
1285
1286 let wasi_proto = WasiProto::new(domain, ty, protocol);
1287 if matches!(wasi_proto, WasiProto::Unknown) {
1288 return Err(Einval);
1289 }
1290 if !(domain == libc::AF_INET && (ty == libc::SOCK_STREAM || ty == libc::SOCK_DGRAM)) {
1291 return Err(Einval);
1292 }
1293
1294 let res = trace_socket(ctx, domain, ty, protocol)?;
1295
1296 ctx.fdmap.create_sock(HostFd::from_raw(res), wasi_proto)
1297 // ctx.fdmap.create(res.into())
1298}
1299
1300// No spec for this one since we added it
1301#[with_ghost_var(trace: &mut Trace)]

Calls 4

sock_domain_to_posixFunction · 0.85
sock_type_to_posixFunction · 0.85
trace_socketFunction · 0.85
create_sockMethod · 0.80

Tested by

no test coverage detected