Skip to content

Use F_NOEXPORTRUNTIME if __rtti_base is missing #1808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ function postInstantiate(extendedExports, instance) {
const __pin = exports.__pin || F_NOEXPORTRUNTIME;
const __unpin = exports.__unpin || F_NOEXPORTRUNTIME;
const __collect = exports.__collect || F_NOEXPORTRUNTIME;
const __rtti_base = exports.__rtti_base || ~0; // oob if not present
const __rtti_base = exports.__rtti_base;
const getRttiCount = __rtti_base
? function (arr) { return arr[__rtti_base >>> 2]; }
: F_NOEXPORTRUNTIME;

extendedExports.__new = __new;
extendedExports.__pin = __pin;
Expand All @@ -98,7 +101,7 @@ function postInstantiate(extendedExports, instance) {
/** Gets the runtime type info for the given id. */
function getInfo(id) {
const U32 = new Uint32Array(memory.buffer);
const count = U32[__rtti_base >>> 2];
const count = getRttiCount(U32);
if ((id >>>= 0) >= count) throw Error(`invalid id: ${id}`);
return U32[(__rtti_base + 4 >>> 2) + id * 2];
}
Expand All @@ -113,7 +116,7 @@ function postInstantiate(extendedExports, instance) {
/** Gets the runtime base id for the given id. */
function getBase(id) {
const U32 = new Uint32Array(memory.buffer);
const count = U32[__rtti_base >>> 2];
const count = getRttiCount(U32);
if ((id >>>= 0) >= count) throw Error(`invalid id: ${id}`);
return U32[(__rtti_base + 4 >>> 2) + id * 2 + 1];
}
Expand Down Expand Up @@ -284,7 +287,7 @@ function postInstantiate(extendedExports, instance) {
function __instanceof(ptr, baseId) {
const U32 = new Uint32Array(memory.buffer);
let id = U32[ptr + ID_OFFSET >>> 2];
if (id <= U32[__rtti_base >>> 2]) {
if (id <= getRttiCount(U32)) {
do {
if (id == baseId) return true;
id = getBase(id);
Expand Down