| 152 | } |
| 153 | |
| 154 | export function resolve_import(import_addr) { |
| 155 | if (import_addr.read16(0) !== 0x25ff) { |
| 156 | throw Error(`instruction at ${import_addr} is not of the form: jmp qword [rip + X]`); |
| 157 | } |
| 158 | // module_function_import: |
| 159 | // jmp qword [rip + X] |
| 160 | // ff 25 xx xx xx xx // signed 32-bit displacement |
| 161 | const disp = import_addr.read32(2); |
| 162 | // assume disp and offset are 32-bit integers |
| 163 | // x | 0 will always be a signed integer |
| 164 | const offset = (disp | 0) + 6; |
| 165 | // The rIP value used by "jmp [rip + X]" instructions is actually the rIP |
| 166 | // of the next instruction. This means that the actual address used is |
| 167 | // [rip + X + sizeof(jmp_insn)], where sizeof(jmp_insn) is the size of the |
| 168 | // jump instruction, which is 6 in this case. |
| 169 | const function_addr = import_addr.readp(offset); |
| 170 | |
| 171 | return function_addr; |
| 172 | } |
| 173 | |
| 174 | export function init_syscall_array(syscall_array, libkernel_web_base, max_search_size) { |
| 175 | if (!Number.isInteger(max_search_size)) { |