@@ -211,17 +211,16 @@ protocol WASI {
211
211
212
212
/// Concurrently poll for the occurrence of a set of events.
213
213
func poll_oneoff(
214
- subscriptions: UnsafeGuestRawPointer ,
215
- events: UnsafeGuestRawPointer ,
216
- numberOfSubscriptions: WASIAbi . Size
214
+ subscriptions: UnsafeGuestBufferPointer < WASIAbi . Subscription > ,
215
+ events: UnsafeGuestBufferPointer < WASIAbi . Event >
217
216
) throws -> WASIAbi . Size
218
217
219
218
/// Write high-quality random data into a buffer.
220
219
func random_get( buffer: UnsafeGuestPointer < UInt8 > , length: WASIAbi . Size )
221
220
}
222
221
223
222
enum WASIAbi {
224
- enum Errno : UInt32 , Error {
223
+ enum Errno : UInt32 , Error , GuestPointee {
225
224
/// No error occurred. System call completed successfully.
226
225
case SUCCESS = 0
227
226
/// Argument list too long.
@@ -952,7 +951,6 @@ public struct WASIHostModule {
952
951
extension WASI {
953
952
var _hostModules : [ String : WASIHostModule ] {
954
953
let unimplementedFunctionTypes : [ String : FunctionType ] = [
955
- " poll_oneoff " : . init( parameters: [ . i32, . i32, . i32, . i32] , results: [ . i32] ) ,
956
954
" proc_raise " : . init( parameters: [ . i32] , results: [ . i32] ) ,
957
955
" sched_yield " : . init( parameters: [ ] , results: [ . i32] ) ,
958
956
" sock_accept " : . init( parameters: [ . i32, . i32, . i32] , results: [ . i32] ) ,
@@ -1493,6 +1491,24 @@ extension WASI {
1493
1491
}
1494
1492
}
1495
1493
1494
+ preview1 [ " poll_oneoff " ] = wasiFunction (
1495
+ type: . init( parameters: [ . i32, . i32, . i32, . i32] , results: [ . i32] )
1496
+ ) { caller, arguments in
1497
+ try withMemoryBuffer ( caller: caller) { buffer in
1498
+ let subscriptionsBaseAddress = UnsafeGuestPointer < WASIAbi . Subscription > ( memorySpace: buffer, offset: arguments [ 0 ] . i32)
1499
+ let eventsBaseAddress = UnsafeGuestPointer < WASIAbi . Event > ( memorySpace: buffer, offset: arguments [ 1 ] . i32)
1500
+ let size = try self . poll_oneoff (
1501
+ subscriptions: . init( baseAddress: subscriptionsBaseAddress, count: arguments [ 2 ] . i32) ,
1502
+ events: . init( baseAddress: eventsBaseAddress, count: arguments [ 2 ] . i32)
1503
+ )
1504
+ buffer. withUnsafeMutableBufferPointer ( offset: . init( arguments [ 3 ] . i32) , count: MemoryLayout< UInt32> . size) { raw in
1505
+ raw. withMemoryRebound ( to: UInt32 . self) { rebound in rebound [ 0 ] = size. littleEndian }
1506
+ }
1507
+
1508
+ return [ . i32( WASIAbi . Errno. SUCCESS. rawValue) ]
1509
+ }
1510
+ }
1511
+
1496
1512
return [
1497
1513
" wasi_snapshot_preview1 " : WASIHostModule ( functions: preview1)
1498
1514
]
@@ -1977,11 +1993,24 @@ public class WASIBridgeToHost: WASI {
1977
1993
}
1978
1994
1979
1995
func poll_oneoff(
1980
- subscriptions: UnsafeGuestRawPointer ,
1981
- events: UnsafeGuestRawPointer ,
1982
- numberOfSubscriptions: WASIAbi . Size
1996
+ subscriptions: UnsafeGuestBufferPointer < WASIAbi . Subscription > ,
1997
+ events: UnsafeGuestBufferPointer < WASIAbi . Event >
1983
1998
) throws -> WASIAbi . Size {
1984
- throw WASIAbi . Errno. ENOTSUP
1999
+ for subscription in subscriptions {
2000
+ switch subscription. union {
2001
+ case . clock:
2002
+ throw WASIAbi . Errno. ENOTSUP
2003
+
2004
+ case . fdRead( let fd) , . fdWrite( let fd) :
2005
+ guard case let . file( entry) = self . fdTable [ fd] else {
2006
+ throw WASIAbi . Errno. EBADF
2007
+
2008
+ }
2009
+ throw WASIAbi . Errno. ENOTSUP
2010
+ }
2011
+ }
2012
+
2013
+ return 0
1985
2014
}
1986
2015
1987
2016
func random_get( buffer: UnsafeGuestPointer < UInt8 > , length: WASIAbi . Size ) {
0 commit comments