|
|
@@ -2760,7 +2760,7 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
|
|
|
const uint8 *buf = *p_buf;
|
|
|
AOTExport *exports;
|
|
|
uint64 size;
|
|
|
- uint32 i;
|
|
|
+ uint32 i, j;
|
|
|
|
|
|
/* Allocate memory */
|
|
|
size = sizeof(AOTExport) * (uint64)module->export_count;
|
|
|
@@ -2774,14 +2774,60 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
|
|
|
read_uint32(buf, buf_end, exports[i].index);
|
|
|
read_uint8(buf, buf_end, exports[i].kind);
|
|
|
read_string(buf, buf_end, exports[i].name);
|
|
|
-#if 0 /* TODO: check kind and index */
|
|
|
- if (export_funcs[i].index >=
|
|
|
- module->func_count + module->import_func_count) {
|
|
|
- set_error_buf(error_buf, error_buf_size,
|
|
|
- "function index is out of range");
|
|
|
- return false;
|
|
|
+
|
|
|
+ for (j = 0; j < i; j++) {
|
|
|
+ if (!strcmp(exports[i].name, exports[j].name)) {
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
+ "duplicate export name");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ /* Check export kind and index */
|
|
|
+ switch (exports[i].kind) {
|
|
|
+ case EXPORT_KIND_FUNC:
|
|
|
+ if (exports[i].index
|
|
|
+ >= module->import_func_count + module->func_count) {
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
+ "unknown function");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case EXPORT_KIND_TABLE:
|
|
|
+ if (exports[i].index
|
|
|
+ >= module->import_table_count + module->table_count) {
|
|
|
+ set_error_buf(error_buf, error_buf_size, "unknown table");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case EXPORT_KIND_MEMORY:
|
|
|
+ if (exports[i].index
|
|
|
+ >= module->import_memory_count + module->memory_count) {
|
|
|
+ set_error_buf(error_buf, error_buf_size, "unknown memory");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case EXPORT_KIND_GLOBAL:
|
|
|
+ if (exports[i].index
|
|
|
+ >= module->import_global_count + module->global_count) {
|
|
|
+ set_error_buf(error_buf, error_buf_size, "unknown global");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+#if WASM_ENABLE_TAGS != 0
|
|
|
+ /* TODO
|
|
|
+ case EXPORT_KIND_TAG:
|
|
|
+ if (index >= module->import_tag_count + module->tag_count) {
|
|
|
+ set_error_buf(error_buf, error_buf_size, "unknown tag");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ */
|
|
|
#endif
|
|
|
+ default:
|
|
|
+ set_error_buf(error_buf, error_buf_size, "invalid export kind");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
*p_buf = buf;
|