#if KERNEL
#include <stdarg.h>
-#include <string.h>
+//#include <string.h>
#include <sys/systm.h>
#define vm_page_size page_size
-extern load_return_t fatfile_getarch(
- void * vp, // normally a (struct vnode *)
- vm_offset_t data_ptr,
- struct fat_arch * archret);
+extern void kld_error_vprintf(const char *format, va_list ap);
__private_extern__ char *strstr(const char *in, const char *str);
+extern struct mach_header _mh_execute_header;
+extern struct segment_command *getsegbyname(char *seg_name); // 32 bit only
#else /* !KERNEL */
} Data, *DataRef;
struct sectionRecord {
- const struct section *fSection;
+ const struct section *fSection; // 32 bit mach object section
DataRef fRelocCache;
};
static void errprintf(const char *fmt, ...)
{
- extern void kld_error_vprintf(const char *format, va_list ap);
-
va_list ap;
va_start(ap, fmt);
unsigned int index;
index = sym - file->fSymbolBase;
+
+ if (index && !sym->n_un.n_strx)
+ return file->fStringBase + sym->n_value;
+
if (index < file->fSymtab->nsyms)
return symNameByIndex(file, index);
sPreferArchInfo = arch;
}
+// This function can only operate on 32 bit mach-o files
Boolean
kld_macho_swap(struct mach_header * mh)
{
return (true);
}
+// This function can only operate on 32 bit mach-o files
void
kld_macho_unswap(struct mach_header * mh, Boolean didSwap, int symbols)
{
#endif /* !KERNEL */
+// Note: This functions is only called from kld_file_map()
+// This function can only operate on 32 bit mach-o files
static Boolean findBestArch(struct fileRecord *file, const char *pathName)
{
unsigned long magic;
return true;
}
+// This function can only operate on segments from 32 bit mach-o files
static Boolean
parseSegments(struct fileRecord *file, struct segment_command *seg)
{
return true;
}
+// This function can only operate on symbol table files from 32 bit
+// mach-o files
static Boolean parseSymtab(struct fileRecord *file, const char *pathName)
{
const struct nlist *sym;
errprintf("%s: Undefined in symbol set: %s\n", pathName, symname);
patchsym->n_type = N_ABS;
patchsym->n_desc = 0;
- patchsym->n_value = 0;
+ patchsym->n_value = patchsym->n_un.n_strx;
patchsym->n_un.n_strx = 0;
}
}
static const struct nlist *
-findSymbolByAddressInAllFiles(const struct fileRecord * fromFile,
+findSymbolByAddressInAllFiles(__unused const struct fileRecord * fromFile,
void *entry, const struct fileRecord **resultFile)
{
int i, nfiles = 0;
("Unable to allocate memory metaclass list\n", file->fPath));
}
else { /* perform a duplicate check */
- int i, j, cnt1, cnt2;
+ int k, j, cnt1, cnt2;
struct metaClassRecord **list1, **list2;
list1 = (struct metaClassRecord **) DataGetPtr(file->fClassList);
list2 = (struct metaClassRecord **) DataGetPtr(sMergeMetaClasses);
cnt2 = DataGetLength(sMergeMetaClasses) / sizeof(*list2);
- for (i = 0; i < cnt1; i++) {
+ for (k = 0; k < cnt1; k++) {
for (j = 0; j < cnt2; j++) {
- if (!strcmp(list1[i]->fClassName, list2[j]->fClassName)) {
+ if (!strcmp(list1[k]->fClassName, list2[j]->fClassName)) {
errprintf("duplicate class %s in %s & %s\n",
- list1[i]->fClassName,
+ list1[k]->fClassName,
file->fPath, list2[j]->fFile->fPath);
}
}
#endif /* KERNEL */
}
+// Note: This function is only called from kld_file_prepare_for_link()
+// This function can only operate on 32 bit mach-o files
static Boolean
prepareFileForLink(struct fileRecord *file)
{
// We will need to repair the reloc list
for (j = 0; j < nreloc; j++, rec++) {
void **entry;
- struct nlist *sym;
+ struct nlist *repairSym;
// Repair Damage to object image
entry = (void **) (sectionBase + rec->fRInfo->r_address);
// Check if the symbol that this relocation entry points
// to is marked as erasable
- sym = (struct nlist *) rec->fSymbol;
- if (sym && sym->n_type == (N_EXT | N_UNDF)
- && sym->n_sect == (unsigned char) -1) {
+ repairSym = (struct nlist *) rec->fSymbol;
+ if (repairSym && repairSym->n_type == (N_EXT | N_UNDF)
+ && repairSym->n_sect == (unsigned char) -1) {
// It is in use so we better clear the mark
- sym->n_un.n_strx = -sym->n_un.n_strx;
- sym->n_sect = NO_SECT;
+ repairSym->n_un.n_strx = -repairSym->n_un.n_strx;
+ repairSym->n_sect = NO_SECT;
}
}
}
// Don't need the new strings any more
+
if (file->fNewStringBlocks){
last = DataGetLength(file->fNewStringBlocks) / sizeof(DataRef);
stringBlocks = (DataRef *) DataGetPtr(file->fNewStringBlocks);
last =0;
stringBlocks=0;
}
+
for (i = 0; i < last; i++)
DataRelease(stringBlocks[i]);
return true;
}
+// This function can only operate on 32 bit mach-o files
Boolean
#if KERNEL
kld_file_map(const char *pathName,
} *machO;
const struct load_command *cmd;
boolean_t lookVMRange;
- int i;
+ unsigned long i;
if (!findBestArch(&file, pathName))
break;
// Automatically load the kernel's link edit segment if we are
// attempting to load a driver.
if (!sKernelFile) {
- extern struct mach_header _mh_execute_header;
- extern struct segment_command *getsegbyname(char *seg_name);
-
struct segment_command *sg;
size_t kernelSize;
Boolean ret;
return true;
}
-Boolean kld_file_prepare_for_link()
+Boolean kld_file_prepare_for_link(void)
{
if (sMergedFiles) {
unsigned long i, nmerged = 0;
return true;
}
-void kld_file_cleanup_all_resources()
+void kld_file_cleanup_all_resources(void)
{
unsigned long i, nfiles;