Skip to content

Commit d2ade7f

Browse files
committed
libdyld: use slish.h where appropriate
1 parent d8c4bf5 commit d2ade7f

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

libdyld/dyld.c

+21-21
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
#include "exec_context.h"
2727
#include "fileio.h"
2828
#include "instance.h"
29-
#include "list.h"
3029
#include "load_context.h"
3130
#include "mem.h"
3231
#include "module.h"
32+
#include "slist.h"
3333
#include "type.h"
3434
#include "util.h"
3535
#include "xlog.h"
@@ -250,7 +250,7 @@ static bool
250250
is_main_object(struct dyld_object *obj)
251251
{
252252
struct dyld *dyld = obj->dyld;
253-
return LIST_FIRST(&dyld->objs) == obj;
253+
return SLIST_FIRST(&dyld->objs) == obj;
254254
}
255255

256256
void
@@ -268,7 +268,7 @@ void
268268
dyld_init(struct dyld *d, struct mem_context *mctx)
269269
{
270270
memset(d, 0, sizeof(*d));
271-
LIST_HEAD_INIT(&d->objs);
271+
SLIST_HEAD_INIT(&d->objs);
272272
d->table_base = 0;
273273
d->memory_base = 0;
274274
dyld_options_set_defaults(&d->opts);
@@ -279,7 +279,7 @@ static struct dyld_object *
279279
dyld_find_object_by_name(struct dyld *d, const struct name *name)
280280
{
281281
struct dyld_object *obj;
282-
LIST_FOREACH(obj, &d->objs, q) {
282+
SLIST_FOREACH(obj, &d->objs, q) {
283283
if (is_main_object(obj)) {
284284
continue;
285285
}
@@ -338,7 +338,7 @@ dyld_load_needed_objects(struct dyld *d, struct dyld_object *start)
338338
*/
339339
int ret = 0;
340340
struct dyld_object *obj;
341-
for (obj = start; obj != NULL; obj = LIST_NEXT(obj, q)) {
341+
for (obj = start; obj != NULL; obj = SLIST_NEXT(obj, q)) {
342342
const struct dylink_needs *needs = &obj->module->dylink->needs;
343343
uint32_t i;
344344
for (i = 0; i < needs->count; i++) {
@@ -732,7 +732,7 @@ dyld_execute_obj_init_func(struct dyld_object *obj, const struct name *names,
732732
return 0;
733733
}
734734

735-
LIST_HEAD_NAMED(struct dyld_object, tsort_list);
735+
SLIST_HEAD_NAMED(struct dyld_object, tsort_list);
736736

737737
static void
738738
tsort_visit(struct dyld_object *obj, struct tsort_list *list)
@@ -752,31 +752,31 @@ tsort_visit(struct dyld_object *obj, struct tsort_list *list)
752752
assert(needed_obj != NULL);
753753
tsort_visit(needed_obj, list);
754754
}
755-
LIST_INSERT_TAIL(list, obj, tq);
755+
SLIST_INSERT_TAIL(list, obj, tq);
756756
}
757757

758758
int
759759
dyld_execute_all_init_funcs(struct dyld *d, struct dyld_object *start)
760760
{
761761
/* topological sort */
762762
struct tsort_list list;
763-
LIST_HEAD_INIT(&list);
763+
SLIST_HEAD_INIT(&list);
764764
struct dyld_object *obj;
765-
for (obj = start; obj != NULL; obj = LIST_NEXT(obj, q)) {
765+
for (obj = start; obj != NULL; obj = SLIST_NEXT(obj, q)) {
766766
assert(!obj->visited);
767767
}
768-
for (obj = start; obj != NULL; obj = LIST_NEXT(obj, q)) {
768+
for (obj = start; obj != NULL; obj = SLIST_NEXT(obj, q)) {
769769
tsort_visit(obj, &list);
770770
}
771771

772-
LIST_FOREACH(obj, &list, tq) {
772+
SLIST_FOREACH(obj, &list, tq) {
773773
int ret = dyld_execute_obj_init_func(obj, reloc_funcs,
774774
ARRAYCOUNT(reloc_funcs));
775775
if (ret != 0) {
776776
return ret;
777777
}
778778
}
779-
LIST_FOREACH(obj, &list, tq) {
779+
SLIST_FOREACH(obj, &list, tq) {
780780
int ret = dyld_execute_obj_init_func(obj, ctor_funcs,
781781
ARRAYCOUNT(ctor_funcs));
782782
if (ret != 0) {
@@ -838,7 +838,7 @@ dyld_load_object_from_file(struct dyld *d, const struct name *name,
838838
* otherwise, it's probably non-pie.
839839
*/
840840
bool pie_or_lib;
841-
if (LIST_EMPTY(&d->objs)) {
841+
if (SLIST_EMPTY(&d->objs)) {
842842
/* the main module */
843843
d->pie = pie_or_lib = module_imports_env_memory(obj->module);
844844
if (d->pie) {
@@ -900,7 +900,7 @@ dyld_load_object_from_file(struct dyld *d, const struct name *name,
900900
if (ret != 0) {
901901
goto fail;
902902
}
903-
LIST_INSERT_TAIL(&d->objs, obj, q);
903+
SLIST_INSERT_TAIL(&d->objs, obj, q);
904904
xlog_trace("dyld: %.*s loaded", CSTR(name));
905905
if (objp != NULL) {
906906
*objp = obj;
@@ -1210,7 +1210,7 @@ dyld_resolve_symbol(struct dyld_object *refobj, enum symtype symtype,
12101210
{
12111211
struct dyld *d = refobj->dyld;
12121212
struct dyld_object *obj;
1213-
LIST_FOREACH(obj, &d->objs, q) {
1213+
SLIST_FOREACH(obj, &d->objs, q) {
12141214
int ret = dyld_resolve_symbol_in_obj(refobj, obj, symtype, sym,
12151215
resultp);
12161216
if (ret == 0) {
@@ -1263,7 +1263,7 @@ static int
12631263
dyld_resolve_all_got_symbols(struct dyld *d, struct dyld_object *start)
12641264
{
12651265
struct dyld_object *obj;
1266-
for (obj = start; obj != NULL; obj = LIST_NEXT(obj, q)) {
1266+
for (obj = start; obj != NULL; obj = SLIST_NEXT(obj, q)) {
12671267
int ret = dyld_resolve_got_symbols(obj);
12681268
if (ret != 0) {
12691269
return ret;
@@ -1302,7 +1302,7 @@ static int
13021302
dyld_resolve_all_plt_symbols(struct dyld *d, struct dyld_object *start)
13031303
{
13041304
struct dyld_object *obj;
1305-
for (obj = start; obj != NULL; obj = LIST_NEXT(obj, q)) {
1305+
for (obj = start; obj != NULL; obj = SLIST_NEXT(obj, q)) {
13061306
int ret = dyld_resolve_plt_symbols(obj);
13071307
if (ret != 0) {
13081308
return ret;
@@ -1388,7 +1388,7 @@ dyld_load(struct dyld *d, const char *filename)
13881388
int
13891389
dyld_execute_init_funcs(struct dyld *d)
13901390
{
1391-
struct dyld_object *obj = LIST_FIRST(&d->objs);
1391+
struct dyld_object *obj = SLIST_FIRST(&d->objs);
13921392
return dyld_execute_all_init_funcs(d, obj);
13931393
}
13941394

@@ -1397,8 +1397,8 @@ dyld_clear(struct dyld *d)
13971397
{
13981398
struct mem_context *mctx = d->mctx;
13991399
struct dyld_object *obj;
1400-
while ((obj = LIST_FIRST(&d->objs)) != NULL) {
1401-
LIST_REMOVE(&d->objs, obj, q);
1400+
while ((obj = SLIST_FIRST(&d->objs)) != NULL) {
1401+
SLIST_REMOVE(&d->objs, (struct dyld_object *)NULL, obj, q);
14021402
dyld_object_destroy(obj);
14031403
}
14041404
if (d->pie) {
@@ -1433,7 +1433,7 @@ dyld_clear(struct dyld *d)
14331433
struct instance *
14341434
dyld_main_object_instance(struct dyld *d)
14351435
{
1436-
const struct dyld_object *obj = LIST_FIRST(&d->objs);
1436+
const struct dyld_object *obj = SLIST_FIRST(&d->objs);
14371437
return obj->instance;
14381438
}
14391439

libdyld/dyld.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <stdint.h>
22

33
#include "host_instance.h"
4-
#include "list.h"
54
#include "platform.h"
5+
#include "slist.h"
66
#include "toywasm_config.h"
77
#include "type.h"
88
#include "vec.h"
@@ -72,7 +72,7 @@ struct dyld {
7272
} pie;
7373
} u;
7474

75-
LIST_HEAD(struct dyld_object) objs;
75+
SLIST_HEAD(struct dyld_object) objs;
7676

7777
struct dyld_options opts;
7878

libdyld/dyld_dlfcn.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ dyld_dlfcn_resolve_symbol(struct exec_context *ctx, struct host_instance *hi,
182182
* libraries as well.
183183
*/
184184
uint32_t addr;
185-
ret = dyld_resolve_symbol_in_obj(LIST_FIRST(&d->objs), dobj->obj, type,
186-
&name, &addr);
185+
ret = dyld_resolve_symbol_in_obj(SLIST_FIRST(&d->objs), dobj->obj,
186+
type, &name, &addr);
187187
if (ret != 0) {
188188
xlog_trace("dyld: dyld:resolve_symbol dyld_resolve_symbol "
189189
"failed for %.*s with %d",

libdyld/dyld_impl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <stdbool.h>
22

3-
#include "list.h"
43
#include "mem.h"
4+
#include "slist.h"
55
#include "type.h"
66

77
struct dyld;
@@ -45,11 +45,11 @@ struct dyld_object {
4545
struct mem_context instance_mctx;
4646

4747
struct dyld *dyld;
48-
LIST_ENTRY(struct dyld_object) q;
48+
SLIST_ENTRY(struct dyld_object) q;
4949

5050
/* for tsort */
5151
bool visited;
52-
LIST_ENTRY(struct dyld_object) tq;
52+
SLIST_ENTRY(struct dyld_object) tq;
5353
};
5454

5555
struct dyld_dynamic_object {

libdyld/dyld_stats.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void
88
dyld_print_stats(struct dyld *d)
99
{
1010
struct dyld_object *obj;
11-
LIST_FOREACH(obj, &d->objs, q) {
11+
SLIST_FOREACH(obj, &d->objs, q) {
1212
struct escaped_string e;
1313
escape_name(&e, obj->name);
1414

0 commit comments

Comments
 (0)