validate struct layout

This commit is contained in:
dcode 2019-03-27 23:23:53 +01:00
parent 96dc211c5d
commit a067982c30
4 changed files with 562 additions and 13 deletions

View File

@ -143,13 +143,14 @@ export type dircookie_t = u64;
/** A directory entry. */ /** A directory entry. */
@unmanaged export class dirent { @unmanaged export class dirent {
/** The offset of the next directory entry stored in this directory. */ /** The offset of the next directory entry stored in this directory. */
next: dircookie_t; next: dircookie_t; // 0
/** The serial number of the file referred to by this directory entry. */ /** The serial number of the file referred to by this directory entry. */
ino: inode_t; ino: inode_t; // 8
/** The length of the name of the directory entry. */ /** The length of the name of the directory entry. */
namlen: u32; namlen: u32; // 16
/** The type of the file referred to by this directory entry. */ /** The type of the file referred to by this directory entry. */
type: filetype_t; type: filetype_t;
private __padding0: u16;
} }
/** Error codes returned by functions. */ /** Error codes returned by functions. */
@ -312,16 +313,23 @@ export const enum errno {
export type errno_t = u16; export type errno_t = u16;
/** An event that occurred. */ /** An event that occurred. */
@unmanaged export class event { @unmanaged export abstract class event {
/** User-provided value that got attached to `subscription#userdata`. */
userdata: userdata_t; userdata: userdata_t;
/** If non-zero, an error that occurred while processing the subscription request. */
error: errno_t; error: errno_t;
/* The type of the event that occurred. */
type: eventtype_t; type: eventtype_t;
private __padding0: u16;
} }
/** An event that occurred when type is `eventtype.FD_READ` or `eventtype.FD_WRITE`. */ /** An event that occurred when type is `eventtype.FD_READ` or `eventtype.FD_WRITE`. */
@unmanaged export class rwevent extends event { @unmanaged export class rwevent extends event {
/* The number of bytes available for reading or writing. */
nbytes: filesize_t; nbytes: filesize_t;
/* The state of the file descriptor. */
flags: eventrwflags_t; flags: eventrwflags_t;
private __padding1: u32;
} }
/** The state of the file descriptor subscribed to with `eventtype.FD_READ` or `eventtype.FD_WRITE`. */ /** The state of the file descriptor subscribed to with `eventtype.FD_READ` or `eventtype.FD_WRITE`. */
@ -632,11 +640,12 @@ export const enum subclockflags {
export type subclockflags_t = u16; export type subclockflags_t = u16;
/** Subscription to an event. */ /** Subscription to an event. */
@unmanaged export class subscription { @unmanaged export abstract class subscription {
/** User-provided value that is attached to the subscription. */ /** User-provided value that is attached to the subscription. */
userdata: userdata_t; userdata: userdata_t;
/** The type of the event to which to subscribe. */ /** The type of the event to which to subscribe. */
type: eventtype_t; type: eventtype_t;
private __padding0: u32;
} }
/* Subscription to an event of type `eventtype.CLOCK`.**/ /* Subscription to an event of type `eventtype.CLOCK`.**/
@ -651,12 +660,13 @@ export type subclockflags_t = u16;
precision: timestamp_t; precision: timestamp_t;
/** Flags specifying whether the timeout is absolute or relative. */ /** Flags specifying whether the timeout is absolute or relative. */
flags: subclockflags_t; flags: subclockflags_t;
private __padding1: u32;
} }
/* Subscription to an event of type `eventtype.FD_READ` or `eventtype.FD_WRITE`.**/ /* Subscription to an event of type `eventtype.FD_READ` or `eventtype.FD_WRITE`.**/
@unmanaged export class fdsubscription extends subscription { @unmanaged export class fdsubscription extends subscription {
/** The file descriptor on which to wait for it to become ready for reading or writing. */ /** The file descriptor on which to wait for it to become ready for reading or writing. */
fd_readwrite: fd_t; fd: fd_t;
} }
/** Timestamp in nanoseconds. */ /** Timestamp in nanoseconds. */

View File

@ -1,11 +1,12 @@
(module (module
(type $FUNCSIG$v (func)) (type $FUNCSIG$v (func))
(memory $0 0) (memory $0 1)
(data (i32.const 8) "\07\00\00\00w\00a\00s\00i\00.\00t\00s")
(table $0 1 funcref) (table $0 1 funcref)
(elem (i32.const 0) $null) (elem (i32.const 0) $start)
(export "memory" (memory $0)) (export "memory" (memory $0))
(export "table" (table $0)) (export "table" (table $0))
(func $null (; 0 ;) (type $FUNCSIG$v) (func $start (; 0 ;) (type $FUNCSIG$v)
nop nop
) )
) )

View File

@ -1 +1,50 @@
import "bindings/wasi"; import { dirent, rwevent, fdstat, filestat, iovec, clocksubscription, fdsubscription } from "bindings/wasi";
// TODO: WASM64
assert(offsetof<dirent>("next") == 0);
assert(offsetof<dirent>("ino") == 8);
assert(offsetof<dirent>("namlen") == 16);
assert(offsetof<dirent>("type") == 20);
assert(offsetof<dirent>() == 24);
assert(offsetof<rwevent>("userdata") == 0);
assert(offsetof<rwevent>("error") == 8);
assert(offsetof<rwevent>("type") == 10);
assert(offsetof<rwevent>("nbytes") == 16);
assert(offsetof<rwevent>("flags") == 24);
assert(offsetof<rwevent>() == 32);
assert(offsetof<fdstat>("filetype") == 0);
assert(offsetof<fdstat>("flags") == 2);
assert(offsetof<fdstat>("rights_base") == 8);
assert(offsetof<fdstat>("rights_inheriting") == 16);
assert(offsetof<fdstat>() == 24);
assert(offsetof<filestat>("dev") == 0);
assert(offsetof<filestat>("ino") == 8);
assert(offsetof<filestat>("filetype") == 16);
assert(offsetof<filestat>("nlink") == 20);
assert(offsetof<filestat>("size") == 24);
assert(offsetof<filestat>("atim") == 32);
assert(offsetof<filestat>("mtim") == 40);
assert(offsetof<filestat>("ctim") == 48);
assert(offsetof<filestat>() == 56);
assert(offsetof<iovec>("buf") == 0);
assert(offsetof<iovec>("buf_len") == 4);
assert(offsetof<iovec>() == 8);
assert(offsetof<clocksubscription>("userdata") == 0);
assert(offsetof<clocksubscription>("type") == 8);
assert(offsetof<clocksubscription>("identifier") == 16);
assert(offsetof<clocksubscription>("clock_id") == 24);
assert(offsetof<clocksubscription>("timeout") == 32);
assert(offsetof<clocksubscription>("precision") == 40);
assert(offsetof<clocksubscription>("flags") == 48);
assert(offsetof<clocksubscription>() == 56);
assert(offsetof<fdsubscription>("userdata") == 0);
assert(offsetof<fdsubscription>("type") == 8);
assert(offsetof<fdsubscription>("fd") == 16);
assert(offsetof<fdsubscription>() == 20);

View File

@ -1,11 +1,500 @@
(module (module
(type $FUNCSIG$viiii (func (param i32 i32 i32 i32)))
(type $FUNCSIG$v (func)) (type $FUNCSIG$v (func))
(memory $0 0) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32)))
(memory $0 1)
(data (i32.const 8) "\07\00\00\00w\00a\00s\00i\00.\00t\00s\00")
(table $0 1 funcref) (table $0 1 funcref)
(elem (i32.const 0) $null) (elem (i32.const 0) $null)
(global $~lib/memory/HEAP_BASE i32 (i32.const 8)) (global $~lib/memory/HEAP_BASE i32 (i32.const 28))
(export "memory" (memory $0)) (export "memory" (memory $0))
(export "table" (table $0)) (export "table" (table $0))
(func $null (; 0 ;) (type $FUNCSIG$v) (start $start)
(func $start:wasi (; 1 ;) (type $FUNCSIG$v)
i32.const 0
i32.const 0
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 5
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 8
i32.const 8
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 6
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 16
i32.const 16
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 7
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 20
i32.const 20
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 8
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 24
i32.const 24
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 9
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 0
i32.const 0
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 11
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 8
i32.const 8
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 12
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 10
i32.const 10
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 13
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 16
i32.const 16
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 14
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 24
i32.const 24
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 15
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 32
i32.const 32
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 16
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 0
i32.const 0
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 18
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 2
i32.const 2
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 19
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 8
i32.const 8
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 20
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 16
i32.const 16
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 21
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 24
i32.const 24
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 22
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 0
i32.const 0
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 24
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 8
i32.const 8
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 25
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 16
i32.const 16
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 26
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 20
i32.const 20
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 27
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 24
i32.const 24
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 28
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 32
i32.const 32
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 29
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 40
i32.const 40
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 30
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 48
i32.const 48
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 31
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 56
i32.const 56
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 32
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 0
i32.const 0
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 34
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 4
i32.const 4
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 35
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 8
i32.const 8
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 36
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 0
i32.const 0
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 38
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 8
i32.const 8
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 39
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 16
i32.const 16
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 40
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 24
i32.const 24
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 41
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 32
i32.const 32
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 42
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 40
i32.const 40
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 43
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 48
i32.const 48
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 44
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 56
i32.const 56
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 45
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 0
i32.const 0
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 47
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 8
i32.const 8
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 48
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 16
i32.const 16
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 49
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 20
i32.const 20
i32.eq
i32.eqz
if
i32.const 0
i32.const 8
i32.const 50
i32.const 0
call $~lib/env/abort
unreachable
end
)
(func $start (; 2 ;) (type $FUNCSIG$v)
call $start:wasi
)
(func $null (; 3 ;) (type $FUNCSIG$v)
) )
) )