|
117 | 117 | "version", {
|
118 | 118 | // system attributes
|
119 | 119 | vmVersion: "SqueakJS 1.1.2",
|
120 |
| - vmDate: "2023-12-20", // Maybe replace at build time? |
| 120 | + vmDate: "2023-12-22", // Maybe replace at build time? |
121 | 121 | vmBuild: "unknown", // or replace at runtime by last-modified?
|
122 | 122 | vmPath: "unknown", // Replace at runtime
|
123 | 123 | vmFile: "vm.js",
|
|
9788 | 9788 | // - other ffi* for private methods of this module
|
9789 | 9789 | // - primitiveCalloutToFFI: old callout primitive (not in SqueakFFIPrims)
|
9790 | 9790 | ffi_lastError: 0,
|
| 9791 | + |
| 9792 | + ffiModules: {}, // map library name to module name |
| 9793 | + |
9791 | 9794 | ffiDoCallout: function(argCount, extLibFunc, stArgs) {
|
9792 | 9795 | this.ffi_lastError = Squeak.FFIErrorGenericError;
|
9793 |
| - var modName = extLibFunc.pointers[Squeak.ExtLibFunc_module].bytesAsString(); |
| 9796 | + var libName = extLibFunc.pointers[Squeak.ExtLibFunc_module].bytesAsString(); |
9794 | 9797 | var funcName = extLibFunc.pointers[Squeak.ExtLibFunc_name].bytesAsString();
|
| 9798 | + |
| 9799 | + if (!libName) libName = "libc"; // default to libc |
| 9800 | + |
| 9801 | + var modName = this.ffiModules[libName]; |
| 9802 | + if (modName === undefined) { |
| 9803 | + if (!Squeak.externalModules[libName]) { |
| 9804 | + var prefixes = ["", "lib"]; |
| 9805 | + var suffixes = ["", ".so", |
| 9806 | + ".so.9", ".9", ".so.8", ".8", ".so.7", ".7", |
| 9807 | + ".so.6", ".6", ".so.5", ".5", ".so.4", ".4", |
| 9808 | + ".so.3", ".3", ".so.2", ".2", ".so.1", ".1"]; |
| 9809 | + loop: for (var p = 0; p < prefixes.length; p++) { |
| 9810 | + var prefix = prefixes[p]; |
| 9811 | + for (var s = 0; s < suffixes.length; s++) { |
| 9812 | + var suffix = suffixes[s]; |
| 9813 | + if (Squeak.externalModules[prefix + libName + suffix]) { |
| 9814 | + modName = prefix + libName + suffix; |
| 9815 | + break loop; |
| 9816 | + } |
| 9817 | + if (prefix && libName.startsWith(prefix) && Squeak.externalModules[libName.slice(prefix.length) + suffix]) { |
| 9818 | + modName = libName.slice(prefix.length) + suffix; |
| 9819 | + break loop; |
| 9820 | + } |
| 9821 | + if (suffix && libName.endsWith(suffix) && Squeak.externalModules[prefix + libName.slice(0, -suffix.length)]) { |
| 9822 | + modName = prefix + libName.slice(0, -suffix.length); |
| 9823 | + break loop; |
| 9824 | + } |
| 9825 | + } |
| 9826 | + } |
| 9827 | + if (modName) console.log("FFI: found library " + libName + " as module " + modName); |
| 9828 | + // there still is a chance loadModuleDynamically will find it under libName |
| 9829 | + } |
| 9830 | + if (!modName) modName = libName; // default to libName |
| 9831 | + this.ffiModules[libName] = modName; |
| 9832 | + } |
| 9833 | + |
9795 | 9834 | var mod = this.loadedModules[modName];
|
9796 | 9835 | if (mod === undefined) { // null if earlier load failed
|
9797 | 9836 | mod = this.loadModule(modName);
|
9798 | 9837 | this.loadedModules[modName] = mod;
|
9799 | 9838 | if (!mod) {
|
9800 |
| - this.vm.warnOnce('FFI: module not found: ' + modName); |
| 9839 | + this.vm.warnOnce('FFI: library not found: ' + libName); |
9801 | 9840 | }
|
9802 | 9841 | }
|
9803 | 9842 | if (!mod) {
|
|
9812 | 9851 | }
|
9813 | 9852 | var jsResult;
|
9814 | 9853 | if (!(funcName in mod)) {
|
9815 |
| - if (this.vm.warnOnce('FFI: function not found: ' + modName + '::' + funcName)) { |
| 9854 | + if (this.vm.warnOnce('FFI: function not found: ' + libName + '::' + funcName)) { |
9816 | 9855 | console.warn(jsArgs);
|
9817 | 9856 | }
|
9818 | 9857 | if (mod.ffiFunctionNotFoundHandler) {
|
|
0 commit comments