Giter VIP home page Giter VIP logo

tinywasi's Introduction

Tiny WASI - A tiny WASI runtime written in typescript

This runtime implements the bare minimum set of functions to get most C/C++ libraries that have been compiled with the "reactor" exec model running.

The only thing it allows is writing to stdout/stderr, getting the current time and getting random numbers, which should really be enough for everyone.

Example

import { TinyWASI } from "tinywasi";

let tinywasi = new TinyWASI();

let imports = {
	<your_own_imports>,
	...tinywasi.imports
};

const { module, instance } = await WebAssembly.instantiate( <wasm_source>, imports );

tinywasi.initialize( instance );

API

new TinyWASI( trace?: boolean )

Instantiates a new TinyWASI runtime.

Parameters

  • trace: boolean, optional. Wether or not to print all system calls to the console for debugging.

initialize( instance: WebAssembly.Instance )

Initializes the runtime and WASM instance. Call this before making any other calls.

Parameters

  • instance: WebAssembly instance to connect to and initialize.

imports: array

Array containing the functions to be imported by the WebAssembly module.
Pass this directly to WebAssembly.instantiate or add it to your own imports.

Implemented system calls

Currently TinyWASI implements the following system calls:

fd_fdstat_get

Implemented for the proper function of stat and isatty which are needed for printing to stdout/stderr to work correctly.

fd_write

Implemented for writing to stdout and stderr. Writing to any other file descriptor returns ERRNO_BADF.

All writes to stdout (fd 1) are logged to the console using console.log.
All writes to stderr (fd 2) are logged to the console using console.error.

clock_res_get and clock_time_get

Implemented to make functions like time() work. Right now only the realtime clock (id 0) is supported.

random_get

Implemented to make C++ std::random_device work.

Unimplemented system calls

All other system calls are unimplemented and return ERRNO_NOSYS while printing an error message to the console.

Dependencies

None.

Dev-Dependencies

  • typescript - for compiling the typescript source files to javascript
  • @types/node - typescript definitions for node's API

Optionally:

  • prettier - for code formatting using the included .prettierrc

tinywasi's People

Contributors

krisslyka avatar miunau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tinywasi's Issues

clock_time_get incorrectly splits its time across u32s

clock_time_get reads the current time via Date.now(), and then attempts to construct a u64 result by splitting the value across two u32s:

  view.setUint32( timeOut, ( now * 1000000.0 ) % 0xFFFFFFFF, true );
  view.setUint32( timeOut + 4, now * 1000000.0 / 0xFFFFFFFF, true );

but the correct modulus for this splitting is (1<<32), not 0xFFFFFFFF which is one too small.

This should either be & 0xFFFFFFFF or % 1<<32.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.