Skip to content

Conversation

radekdoulik
Copy link
Member

Get further with running interpreter tests.

Fix ICU loading from development hosts

Update wasm calli stubs to handle instance methods

@radekdoulik radekdoulik added this to the Future milestone Sep 17, 2025
@radekdoulik radekdoulik added arch-wasm WebAssembly architecture area-VM-coreclr labels Sep 17, 2025
@radekdoulik
Copy link
Member Author

With these changes we now fail with

RuntimeError: memory access out of bounds
    at corerun.wasm.DispatchToken::DecodeTypeID(unsigned long) (wasm://wasm/corerun.wasm-1b61dba6:wasm-function[14976]:0x580515)
    at corerun.wasm.DispatchToken::GetTypeID() const (wasm://wasm/corerun.wasm-1b61dba6:wasm-function[14960]:0x57e1f9)
    at corerun.wasm.DispatchToken::IsThisToken() const (wasm://wasm/corerun.wasm-1b61dba6:wasm-function[14974]:0x580158)
    at corerun.wasm.VirtualCallStubManager::GetTarget(DispatchToken, MethodTable*, int) (wasm://wasm/corerun.wasm-1b61dba6:wasm-function[14978]:0x5807fa)
    at corerun.wasm.MethodTable::GetMethodDescForInterfaceMethod(TypeHandle, MethodDesc*, int) (wasm://wasm/corerun.wasm-1b61dba6:wasm-function[12094]:0x47a2b1)
    at corerun.wasm.MethodTable::TryResolveConstraintMethodApprox(TypeHandle, MethodDesc*, int*) (wasm://wasm/corerun.wasm-1b61dba6:wasm-function[12417]:0x49eb13)
    at corerun.wasm.CEEInfo::getCallInfo(CORINFO_RESOLVED_TOKEN*, CORINFO_RESOLVED_TOKEN*, CORINFO_METHOD_STRUCT_*, CORINFO_CALLINFO_FLAGS, CORINFO_CALL_INFO*) (wasm://wasm/corerun.wasm-1b61dba6:wasm-function[10558]:0x3e2548)
    at corerun.wasm.InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN*, bool, bool, bool, bool) (wasm://wasm/corerun.wasm-1b61dba6:wasm-function[24442]:0xb4dbbe)
    at corerun.wasm.InterpCompiler::GenerateCode(CORINFO_METHOD_INFO*) (wasm://wasm/corerun.wasm-1b61dba6:wasm-function[24409]:0xb41bcb)
    at corerun.wasm.InterpCompiler::CompileMethod() (wasm://wasm/corerun.wasm-1b61dba6:wasm-function[24405]:0xb3797e)

in the interpreter compiler. It happens during compilation of System.SpanHelpers:IndexOfAnyInRange[char](byref,char,char,int)

std::fprintf(stderr, "Failed to load the ICU data\n");
return -1;
}
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif
#endif // TARGET_WASM

#define __CORERUN_WASM_HPP__

void wasm_add_pinvoke_override();
int32_t wasm_load_icu_data(const char* assemblyPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this to be bool instead of int32_t.

return icuPath;
}

int32_t wasm_load_icu_data(const char* assemblyPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is probably copied from somewhere, but it is using very low leve APIs. For example, open vs fopen. Can we instead clean this up to be as C++ as possible?


extern "C" int32_t mono_wasm_load_icu_data(const void* pData);

static char* _wasm_get_icu_dat_file_path(const char* assemblyPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static char* _wasm_get_icu_dat_file_path(const char* assemblyPath)
static char* wasm_get_icu_dat_file_path(const char* assemblyPath)


int32_t wasm_load_icu_data(const char* assemblyPath)
{
char* icuFile = _wasm_get_icu_dat_file_path(assemblyPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
char* icuFile = _wasm_get_icu_dat_file_path(assemblyPath);
char* icuFile = wasm_get_icu_dat_file_path(assemblyPath);

return strdup(icuFileName);

size_t dirLen = (size_t)(lastSeparator - assemblyPath) + 1; // include separator
size_t fileNameLen = sizeof(icuFileName) - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
size_t fileNameLen = sizeof(icuFileName) - 1;
size_t fileNameLen = ARRAY_SIZE(icuFileName) - 1;

Using sizeof is too easy to do wrong. All someone needs to do is change that to const char icuFileName* and it will compile and be wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the -1 and then you can remove the +1 and icuPath[dirLen + fileNameLen] = '\0';. Doing that and making a comment is all that is needed.


static char* _wasm_get_icu_dat_file_path(const char* assemblyPath)
{
if (!assemblyPath || !*assemblyPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will this be NULL?

}
close(fd);

return mono_wasm_load_icu_data(buffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this returns failure, we should clean things up.

return 0;
}

struct stat st;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct stat st;
stat st;

Comment on lines +35 to +36
// WASM-TODO: check where we reach that, return nullptr for now to not break runtime initialization
//PORTABILITY_ASSERT("The function is not implemented on wasm, it lacks registers");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we getting here? Can you share a callstack? I would prefer us to nicely ifdef out the caller in an intelligent way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-VM-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants