-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add create_satisfying_shared_memories
i plan to use this for wasi-threads
- Loading branch information
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include <assert.h> | ||
|
||
#include "instance.h" | ||
#include "type.h" | ||
|
||
static void | ||
_dtor(struct import_object *imo) | ||
{ | ||
uint32_t i; | ||
for (i = 0; i < imo->nentries; i++) { | ||
struct import_object_entry *e = &imo->entries[i]; | ||
struct meminst *mi = e->u.mem; | ||
if (mi != NULL) { | ||
memory_instance_destroy(mi); | ||
} | ||
} | ||
} | ||
|
||
int | ||
create_satisfying_shared_memories(struct module *m, | ||
struct import_object **imop) | ||
{ | ||
struct import_object *imo = NULL; | ||
uint32_t nsharedimports; | ||
uint32_t i; | ||
struct meminst *mi = NULL; | ||
int ret; | ||
|
||
nsharedimports = 0; | ||
for (i = 0; i < m->nimports; i++) { | ||
const struct import *im = &m->imports[i]; | ||
if (im->desc.type != IMPORT_MEMORY) { | ||
continue; | ||
} | ||
const struct memtype *mt = &im->desc.u.memtype; | ||
if ((mt->flags & MEMTYPE_FLAG_SHARED) == 0) { | ||
continue; | ||
} | ||
nsharedimports++; | ||
} | ||
|
||
ret = import_object_alloc(nsharedimports, &imo); | ||
if (ret != 0) { | ||
goto fail; | ||
} | ||
imo->dtor = _dtor; | ||
|
||
uint32_t idx = 0; | ||
for (i = 0; i < m->nimports; i++) { | ||
const struct import *im = &m->imports[i]; | ||
if (im->desc.type != IMPORT_MEMORY) { | ||
continue; | ||
} | ||
const struct memtype *mt = &im->desc.u.memtype; | ||
if ((mt->flags & MEMTYPE_FLAG_SHARED) == 0) { | ||
continue; | ||
} | ||
ret = memory_instance_create(&mi, mt); | ||
if (ret != 0) { | ||
goto fail; | ||
} | ||
assert(idx < imo->nentries); | ||
struct import_object_entry *e = &imo->entries[idx++]; | ||
e->module_name = &im->module_name; | ||
e->name = &im->name; | ||
e->type = IMPORT_MEMORY; | ||
e->u.mem = mi; | ||
} | ||
|
||
*imop = imo; | ||
return 0; | ||
fail: | ||
if (imo != NULL) { | ||
import_object_destroy(imo); | ||
} | ||
if (mi != NULL) { | ||
memory_instance_destroy(mi); | ||
} | ||
return ret; | ||
} |