From 81c212b208114f3d34e570b6a052fe9473ded502 Mon Sep 17 00:00:00 2001 From: dcode Date: Thu, 23 May 2019 04:15:05 +0200 Subject: [PATCH] monkey-patch loader --- lib/loader/index.js | 191 +++++++++++++------------- lib/loader/tests/assembly/index.ts | 6 - lib/loader/tests/build/untouched.wasm | Bin 6968 -> 6404 bytes lib/loader/tests/index.js | 30 ++-- src/compiler.ts | 2 +- tests/compiler/exports.optimized.wat | 2 +- tests/compiler/exports.untouched.wat | 2 +- 7 files changed, 114 insertions(+), 119 deletions(-) diff --git a/lib/loader/index.js b/lib/loader/index.js index aa32b1cc..b46473ee 100644 --- a/lib/loader/index.js +++ b/lib/loader/index.js @@ -1,11 +1,15 @@ "use strict"; -/** Size of the runtime header, in bytes. */ -const HEADER_SIZE = 16; -/** Runtime header offset of `classId`. */ -const CLASSID_OFFSET = -HEADER_SIZE; -/** Runtime header offset of `payloadLength`. */ -const PAYLOADLENGTH_OFFSET = -HEADER_SIZE + 4; +/** Relative header `id` offset. */ +const ID_OFFSET = -8; +/** Relative header `size` offset. */ +const SIZE_OFFSET = -4; + +/** Unique runtime id of an `ArrayBuffer`. */ +const ARRAYBUFFER_ID = 0; +/** Unique runtime id of a `String`. */ +const STRING_ID = 1; + /** Whether BigInt arrays are supported. */ const SUPPORTS_BIGINT = typeof BigUint64Array !== "undefined"; /** Unique symbol for memoized 'this'. */ @@ -13,19 +17,18 @@ const THIS = Symbol(); /** Gets a string from an U32 and an U16 view on a memory. */ function getStringImpl(U32, U16, ptr) { - var size32 = U32[(ptr + PAYLOADLENGTH_OFFSET) >>> 2]; - var offset16 = ptr >>> 1; - var remain32 = size32; + var length = U32[(ptr + SIZE_OFFSET) >>> 2] >>> 1; + var offset = ptr >>> 1; var parts = []; const chunkSize = 1024; - while (remain32 > chunkSize) { - let last = U16[offset16 + chunkSize - 1]; + while (length > chunkSize) { + let last = U16[offset + chunkSize - 1]; let size = last >= 0xD800 && last < 0xDC00 ? chunkSize - 1 : chunkSize; - let part = U16.subarray(offset16, offset16 += size); + let part = U16.subarray(offset, offset += size); parts.push(String.fromCharCode.apply(String, part)); - remain32 -= size; + length -= size; } - return parts.join("") + String.fromCharCode.apply(String, U16.subarray(offset16, offset16 + remain32)); + return parts.join("") + String.fromCharCode.apply(String, U16.subarray(offset, offset + length)); } /** Prepares the base module prior to instantiation. */ @@ -58,11 +61,11 @@ function preInstantiate(imports) { function postInstantiate(baseModule, instance) { var rawExports = instance.exports; var memory = rawExports.memory; - var memory_allocate = rawExports["memory.allocate"]; + var alloc = rawExports["__alloc"]; + var free = rawExports["__free"]; + var setargc = rawExports["__setargc"] || function() {}; var memory_fill = rawExports["memory.fill"]; - var memory_free = rawExports["memory.free"]; var table = rawExports.table; - var setargc = rawExports["$.setArgc"] || function() {}; // Provide views for all sorts of basic values var buffer, I8, U8, I16, U16, I32, U32, F32, F64, I64, U64; @@ -90,12 +93,10 @@ function postInstantiate(baseModule, instance) { /** Allocates a new string in the module's memory and returns its pointer. */ function newString(str) { - var dataLength = str.length; - var ptr = memory_allocate(4 + (dataLength << 1)); - var dataOffset = (4 + ptr) >>> 1; + var length = str.length; + var ptr = alloc(length << 1, STRING_ID); checkMem(); - U32[ptr >>> 2] = dataLength; - for (let i = 0; i < dataLength; ++i) U16[dataOffset + i] = str.charCodeAt(i); + for (let i = 0, j = ptr >>> 1; i < length; ++i) U16[j + i] = str.charCodeAt(i); return ptr; } @@ -109,88 +110,88 @@ function postInstantiate(baseModule, instance) { baseModule.getString = getString; - function computeBufferSize(byteLength) { - const HEADER_SIZE = 8; - return 1 << (32 - Math.clz32(byteLength + HEADER_SIZE - 1)); - } + // function computeBufferSize(byteLength) { + // const HEADER_SIZE = 8; + // return 1 << (32 - Math.clz32(byteLength + HEADER_SIZE - 1)); + // } - /** Creates a new typed array in the module's memory and returns its pointer. */ - function newArray(view, length, unsafe) { - var ctor = view.constructor; - if (ctor === Function) { // TypedArray constructor created in memory - ctor = view; - view = null; - } else { // TypedArray instance copied into memory - if (length === undefined) length = view.length; - } - var elementSize = ctor.BYTES_PER_ELEMENT; - if (!elementSize) throw Error("not a typed array"); - var byteLength = elementSize * length; - var ptr = memory_allocate(12); // TypedArray header - var buf = memory_allocate(computeBufferSize(byteLength)); // ArrayBuffer - checkMem(); - U32[ ptr >>> 2] = buf; // .buffer - U32[(ptr + 4) >>> 2] = 0; // .byteOffset - U32[(ptr + 8) >>> 2] = byteLength; // .byteLength - U32[ buf >>> 2] = byteLength; // .byteLength - U32[(buf + 4) >>> 2] = 0; // 0 - if (view) { - new ctor(buffer, buf + 8, length).set(view); - if (view.length < length && !unsafe) { - let setLength = elementSize * view.length; - memory_fill(buf + 8 + setLength, 0, byteLength - setLength); - } - } else if (!unsafe) { - memory_fill(buf + 8, 0, byteLength); - } - return ptr; - } + // /** Creates a new typed array in the module's memory and returns its pointer. */ + // function newArray(view, length, unsafe) { + // var ctor = view.constructor; + // if (ctor === Function) { // TypedArray constructor created in memory + // ctor = view; + // view = null; + // } else { // TypedArray instance copied into memory + // if (length === undefined) length = view.length; + // } + // var elementSize = ctor.BYTES_PER_ELEMENT; + // if (!elementSize) throw Error("not a typed array"); + // var byteLength = elementSize * length; + // var ptr = alloc(12); // TypedArray header + // var buf = alloc(computeBufferSize(byteLength)); // ArrayBuffer + // checkMem(); + // U32[ ptr >>> 2] = buf; // .buffer + // U32[(ptr + 4) >>> 2] = 0; // .byteOffset + // U32[(ptr + 8) >>> 2] = byteLength; // .byteLength + // U32[ buf >>> 2] = byteLength; // .byteLength + // U32[(buf + 4) >>> 2] = 0; // 0 + // if (view) { + // new ctor(buffer, buf + 8, length).set(view); + // if (view.length < length && !unsafe) { + // let setLength = elementSize * view.length; + // memory_fill(buf + 8 + setLength, 0, byteLength - setLength); + // } + // } else if (!unsafe) { + // memory_fill(buf + 8, 0, byteLength); + // } + // return ptr; + // } - baseModule.newArray = newArray; + // baseModule.newArray = newArray; - /** Gets a view on a typed array in the module's memory by its pointer. */ - function getArray(ctor, ptr) { - var elementSize = ctor.BYTES_PER_ELEMENT; - if (!elementSize) throw Error("not a typed array"); - checkMem(); - var buf = U32[ ptr >>> 2]; - var byteOffset = U32[(ptr + 4) >>> 2]; - var byteLength = U32[(ptr + 8) >>> 2]; - return new ctor(buffer, buf + 8 + byteOffset, (byteLength - byteOffset) / elementSize); - } + // /** Gets a view on a typed array in the module's memory by its pointer. */ + // function getArray(ctor, ptr) { + // var elementSize = ctor.BYTES_PER_ELEMENT; + // if (!elementSize) throw Error("not a typed array"); + // checkMem(); + // var buf = U32[ ptr >>> 2]; + // var byteOffset = U32[(ptr + 4) >>> 2]; + // var byteLength = U32[(ptr + 8) >>> 2]; + // return new ctor(buffer, buf + 8 + byteOffset, (byteLength - byteOffset) / elementSize); + // } - baseModule.getArray = getArray; + // baseModule.getArray = getArray; - /** Frees a typed array in the module's memory. Must not be accessed anymore afterwards. */ - function freeArray(ptr) { - checkMem(); - var buf = U32[ptr >>> 2]; - memory_free(buf); - memory_free(ptr); - } + // /** Frees a typed array in the module's memory. Must not be accessed anymore afterwards. */ + // function freeArray(ptr) { + // checkMem(); + // var buf = U32[ptr >>> 2]; + // free(buf); + // free(ptr); + // } - baseModule.freeArray = freeArray; + // baseModule.freeArray = freeArray; - /** - * Creates a new function in the module's table and returns its pointer. Note that only actual - * WebAssembly functions, i.e. as exported by the module, are supported. - */ - function newFunction(fn) { - if (typeof fn.original === "function") fn = fn.original; - var index = table.length; - table.grow(1); - table.set(index, fn); - return index; - } + // /** + // * Creates a new function in the module's table and returns its pointer. Note that only actual + // * WebAssembly functions, i.e. as exported by the module, are supported. + // */ + // function newFunction(fn) { + // if (typeof fn.original === "function") fn = fn.original; + // var index = table.length; + // table.grow(1); + // table.set(index, fn); + // return index; + // } - baseModule.newFunction = newFunction; + // baseModule.newFunction = newFunction; - /** Gets a function by its pointer. */ - function getFunction(ptr) { - return wrapFunction(table.get(ptr), setargc); - } + // /** Gets a function by its pointer. */ + // function getFunction(ptr) { + // return wrapFunction(table.get(ptr), setargc); + // } - baseModule.getFunction = getFunction; + // baseModule.getFunction = getFunction; // Pull basic exports to baseModule so code in preInstantiate can use them baseModule.memory = baseModule.memory || memory; @@ -253,7 +254,7 @@ exports.instantiateStreaming = instantiateStreaming; /** Demangles an AssemblyScript module's exports to a friendly object structure. */ function demangle(exports, baseModule) { var module = baseModule ? Object.create(baseModule) : {}; - var setargc = exports[".setargc"] || function() {}; + var setargc = exports["__setargc"] || function() {}; function hasOwnProperty(elem, prop) { return Object.prototype.hasOwnProperty.call(elem, prop); } diff --git a/lib/loader/tests/assembly/index.ts b/lib/loader/tests/assembly/index.ts index 1c60c327..770be909 100644 --- a/lib/loader/tests/assembly/index.ts +++ b/lib/loader/tests/assembly/index.ts @@ -1,5 +1,3 @@ -import "allocator/tlsf"; - export { memory }; export const COLOR: string = "red"; @@ -39,10 +37,6 @@ export class Car { this.doorsOpen = false; return true; } - - dispose(): void { - memory.free(changetype(this)); - } } export function sum(arr: Int32Array): i32 { diff --git a/lib/loader/tests/build/untouched.wasm b/lib/loader/tests/build/untouched.wasm index 656568dff51357314729c7c34a320bc9a50f37ba..5bdfc74da246b651109ca751671dc3ceff531e3c 100644 GIT binary patch literal 6404 zcmai2U2Ggz6+ZXgnVs3a>v+0k3KT=ASS)ZtcdMmj}awjI4`cXRS+3^Y~&EX%$n{AZloek|d5*5{V{?yhfL9?-G)$(1jzykMfns2KLUTa>4po#N_3=h7vbF;8}e#%8$A zUg;KRx2|nIH5d#>^f}oYO>Qk7tEkpTLbS3CVRN#}gp<4XO*8G<045EutrdeI%}(*o z04zblr;Z3ke=zEXjZZVd!t?&it52=0yzrulnPB1C=vt>Q1g2p|*EZ=h@EY1W!z*j_ zcw@ISWH(N?!eVv17@8zmLjZaEOmb-ulK!9#pcm!HpX?%=s8nD(crOYUB6xc@~jJAdGhNIQFNVxw66cF7naF zu2()PMtO|8)T<3Vu~^=59-?EP9T5BdN-PY_@&?;^JWpIBT5=7SEb8OdC0Ju;QD@dE zJ$970T$DFmoTskkno#A^p4UZ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`+d)(ab|A;bzyxr(^G00Q#=R0S4?)^N@+KBhUivFZXJCssU9>_UfT5;p+>go{ zXXw>CE&W3{+i}t16F|74BP%~&_r?*v=qTWz=mgLgMF%tZeNuE_yVB1Jn&6h*;jfRVOfc%RePHXt*AB?YfTLhKA8?tI=~D4ICQTb0l`)Pf96`U3 zHsx>!4=_at??Z4!@W}McMEV1Pk1ItP<~lp6Ebn_Qr7ynnhT{8|3C2`Fec++U9ORiQ zGR)wD>%EQk1Qx<~G4E9b4UR}y16hfH=)mQijhv{996}I_>uOmDCOQ8vY4=a%yvzE$ zR-&SEgRTCa!ZDNA5tCfv@`Jf-=lBdagb`2Sn+EcFzHLAGM7amUahrC6sAn4?%n9dp zRuMzbKzj5GIMZcA9IkVgBF~MU?|c1Y$Nle{_IwZhuU{yb<|Y{-LsUXZ}cM zu{JRuHLjc*s!GJ)e8!=$f_lG>;n(!QoIcB8NAQSq4F@@AGGyV(QAVPRam4aJeVyT$ zDPjYn06$&Caq2i8n$rrV3@LqJ&OyM&y^Uz=WA4C(Gbxl~8>UWYt|Z)0;wxc*&xs9k zO^b^=NBAfOx(;FCW6=kWUcv-G?lQQ8xA?Y<9M<~^u#?rnnIYgQ$yEdbrHAUp*M=tq zckZ0biIta;1jy5O$*$N_oTuD=v+8Kmxh+9p;`1@~mLqgaiPlfTUWhWmO!3BdZqG?) zN+ZI6|4b2K&?;TwtG472lRl^_b38=Mg#Ypbdz6swgO(K;dOwNQmsL)`r04K`@$dly zE{5hq(nra@2~!w4P37+ngOp3J<(|u$=e-+0CImiI)un6LMKi?P!Rk7~=+~ux4A!=>&9@xAfmlQOFA&YtE&u=k diff --git a/lib/loader/tests/index.js b/lib/loader/tests/index.js index 133dda77..3b0ce510 100644 --- a/lib/loader/tests/index.js +++ b/lib/loader/tests/index.js @@ -21,7 +21,7 @@ assert(proto.F64 instanceof Float64Array); // should export memory assert(module.memory instanceof WebAssembly.Memory); -assert(typeof module.memory.free === "function"); +assert(typeof module.memory.copy === "function"); // should be able to get an exported string assert.strictEqual(module.getString(module.COLOR), "red"); @@ -33,17 +33,17 @@ assert.strictEqual(module.getString(ptr), str); assert.strictEqual(module.strlen(ptr), str.length); // should be able to allocate a typed array and sum up its values -var arr = [1, 2, 3, 4, 5, 0x7fffffff]; -ptr = module.newArray(new Int32Array(arr)); -assert.strictEqual(module.sum(ptr), arr.reduce((a, b) => a + b, 0) | 0); +// var arr = [1, 2, 3, 4, 5, 0x7fffffff]; +// ptr = module.newArray(new Int32Array(arr)); +// assert.strictEqual(module.sum(ptr), arr.reduce((a, b) => a + b, 0) | 0); // should be able to get a view on an internal typed array -assert.deepEqual(module.getArray(Int32Array, ptr), arr); +// assert.deepEqual(module.getArray(Int32Array, ptr), arr); // should be able to free and reuse the space of an internal typed array -module.freeArray(ptr); -var ptr2 = module.newArray(new Int32Array(arr)); -assert.strictEqual(ptr, ptr2); +// module.freeArray(ptr); +// var ptr2 = module.newArray(new Int32Array(arr)); +// assert.strictEqual(ptr, ptr2); // should be able to just call a function with variable arguments assert.strictEqual(module.varadd(), 3); @@ -51,14 +51,14 @@ assert.strictEqual(module.varadd(2, 3), 5); assert.strictEqual(module.varadd(2), 4); // should be able to get a function from the table and just call it with variable arguments -var fn = module.getFunction(module.varadd_ptr); -assert.strictEqual(fn(), 3); -assert.strictEqual(fn(2, 3), 5); -assert.strictEqual(fn(2), 4); +// var fn = module.getFunction(module.varadd_ptr); +// assert.strictEqual(fn(), 3); +// assert.strictEqual(fn(2, 3), 5); +// assert.strictEqual(fn(2), 4); // should be able to create a new function and call it from WASM -ptr = module.newFunction(module.varadd); -assert.strictEqual(module.calladd(ptr, 2, 3), 5); +// ptr = module.newFunction(module.varadd); +// assert.strictEqual(module.calladd(ptr, 2, 3), 5); // should be able to use a class var car = new module.Car(5); @@ -70,4 +70,4 @@ car.closeDoors(); assert.strictEqual(car.isDoorsOpen, 0); // should be able to use trace -module.dotrace(42); \ No newline at end of file +module.dotrace(42); diff --git a/src/compiler.ts b/src/compiler.ts index f2575075..e4996703 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -6489,7 +6489,7 @@ export class Compiler extends DiagnosticEmitter { module.createGetLocal(0, NativeType.I32) ) ); - module.addFunctionExport(BuiltinSymbols.setargc, "$.setArgc"); + module.addFunctionExport(BuiltinSymbols.setargc, "__setargc"); } return BuiltinSymbols.setargc; } diff --git a/tests/compiler/exports.optimized.wat b/tests/compiler/exports.optimized.wat index 5c590e34..5f6568f7 100644 --- a/tests/compiler/exports.optimized.wat +++ b/tests/compiler/exports.optimized.wat @@ -20,7 +20,7 @@ (global $exports/vehicles.Car i32 (i32.const 4)) (export "memory" (memory $0)) (export "add" (func $exports/add)) - (export "$.setArgc" (func $~lib/setargc)) + (export "__setargc" (func $~lib/setargc)) (export "subOpt" (func $exports/subOpt|trampoline)) (export "math.sub" (func $exports/subOpt)) (export "Animal.CAT" (global $exports/Animal.CAT)) diff --git a/tests/compiler/exports.untouched.wat b/tests/compiler/exports.untouched.wat index c33c65f8..56fd0434 100644 --- a/tests/compiler/exports.untouched.wat +++ b/tests/compiler/exports.untouched.wat @@ -23,7 +23,7 @@ (global $exports/vehicles.Car i32 (i32.const 4)) (export "memory" (memory $0)) (export "add" (func $exports/add)) - (export "$.setArgc" (func $~lib/setargc)) + (export "__setargc" (func $~lib/setargc)) (export "subOpt" (func $exports/subOpt|trampoline)) (export "math.sub" (func $exports/math.sub)) (export "Animal.CAT" (global $exports/Animal.CAT))