#define u64_low_32(x) ((u32)x)
#define u64_high_32(x) ((u32)(x >> 32))
-static inline u64 cmpxchg8b(volatile u64 *ptr, u64 old, u64 new)
+static inline u64 nt_cmpxchg8b(volatile u64 *ptr, u64 old, u64 new)
{
u64 prev;
entry->next = old.next;
new.next = entry;
new.depth = old.depth + 1;
- } while (cmpxchg8b(&head->align, old.align, new.align) != old.align);
+ } while (nt_cmpxchg8b(&head->align, old.align, new.align) != old.align);
TRACE4("%p, %p, %p", head, entry, old.next);
return old.next;
}
break;
new.next = entry->next;
new.depth = old.depth - 1;
- } while (cmpxchg8b(&head->align, old.align, new.align) != old.align);
+ } while (nt_cmpxchg8b(&head->align, old.align, new.align) != old.align);
TRACE4("%p, %p", head, entry);
return entry;
}
extern struct wrap_export usb_exports[];
#endif
-static char *get_export(char *name)
+static int get_export(char *name, generic_func *func)
{
- int i;
-
- for (i = 0 ; ntoskernel_exports[i].name != NULL; i++)
- if (strcmp(ntoskernel_exports[i].name, name) == 0)
- return (char *)ntoskernel_exports[i].func;
-
- for (i = 0 ; ntoskernel_io_exports[i].name != NULL; i++)
- if (strcmp(ntoskernel_io_exports[i].name, name) == 0)
- return (char *)ntoskernel_io_exports[i].func;
-
- for (i = 0 ; ndis_exports[i].name != NULL; i++)
- if (strcmp(ndis_exports[i].name, name) == 0)
- return (char *)ndis_exports[i].func;
-
- for (i = 0 ; crt_exports[i].name != NULL; i++)
- if (strcmp(crt_exports[i].name, name) == 0)
- return (char *)crt_exports[i].func;
-
- for (i = 0 ; hal_exports[i].name != NULL; i++)
- if (strcmp(hal_exports[i].name, name) == 0)
- return (char *)hal_exports[i].func;
-
- for (i = 0 ; rtl_exports[i].name != NULL; i++)
- if (strcmp(rtl_exports[i].name, name) == 0)
- return (char *)rtl_exports[i].func;
-
+ int i, j;
+
+ struct wrap_export *exports[] = {
+ ntoskernel_exports,
+ ntoskernel_io_exports,
+ ndis_exports,
+ crt_exports,
+ hal_exports,
+ rtl_exports,
#ifdef ENABLE_USB
- for (i = 0 ; usb_exports[i].name != NULL; i++)
- if (strcmp(usb_exports[i].name, name) == 0)
- return (char *)usb_exports[i].func;
+ usb_exports,
#endif
+ };
+
+ for (j = 0; j < ARRAY_SIZE(exports); j++)
+ for (i = 0; exports[j][i].name != NULL; i++)
+ if (strcmp(exports[j][i].name, name) == 0) {
+ *func = exports[j][i].func;
+ return 0;
+ }
for (i = 0; i < num_pe_exports; i++)
- if (strcmp(pe_exports[i].name, name) == 0)
- return (char *)pe_exports[i].addr;
+ if (strcmp(pe_exports[i].name, name) == 0) {
+ *func = pe_exports[i].addr;
+ return 0;
+ }
- return NULL;
+ return -1;
}
#endif // TEST_LOADER
char *symname = NULL;
int i;
int ret = 0;
- void *adr;
+ generic_func adr;
lookup_tbl = RVA2VA(image, dirent->u.OriginalFirstThunk, ULONG_PTR *);
address_tbl = RVA2VA(image, dirent->FirstThunk, ULONG_PTR *);
~IMAGE_ORDINAL_FLAG) + 2), char *);
}
- adr = get_export(symname);
- if (adr == NULL) {
+ ret = get_export(symname, &adr);
+ if (ret < 0) {
ERROR("unknown symbol: %s:'%s'", dll, symname);
- ret = -1;
} else {
DBGLINKER("found symbol: %s:%s: addr: %p, rva = %Lu",
dll, symname, adr, (uint64_t)address_tbl[i]);