1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/*
* BRLTTY - A background process providing access to the console screen (when in
* text mode) for a blind person using a refreshable braille display.
*
* Copyright (C) 1995-2025 by The BRLTTY Developers.
*
* BRLTTY comes with ABSOLUTELY NO WARRANTY.
*
* This is free software, placed under the terms of the
* GNU Lesser General Public License, as published by the Free Software
* Foundation; either version 2.1 of the License, or (at your option) any
* later version. Please see the file LICENSE-LGPL for details.
*
* Web Page: http://brltty.app/
*
* This software is maintained by Dave Mielke <dave@mielke.cc>.
*/
#include "prologue.h"
#include <stdio.h>
#include <string.h>
#include <mach-o/dyld.h>
#include "log.h"
#include "dynld.h"
static void
logDyldError (const char *action) {
NSLinkEditErrors errors;
int number;
const char *file;
const char *message;
NSLinkEditError(&errors, &number, &file, &message);
logMessage(LOG_ERR, "%.*s", (int)(strlen(message)-1), message);
}
void *
loadSharedObject (const char *path) {
NSObjectFileImage image;
switch (NSCreateObjectFileImageFromFile(path, &image)) {
case NSObjectFileImageSuccess: {
NSModule module = NSLinkModule(image, path, NSLINKMODULE_OPTION_RETURN_ON_ERROR);
if (module) return module;
logDyldError("link module");
logMessage(LOG_ERR, "shared object not linked: %s", path);
break;
}
case NSObjectFileImageInappropriateFile:
logMessage(LOG_ERR, "inappropriate object type: %s", path);
break;
case NSObjectFileImageArch:
logMessage(LOG_ERR, "incorrect object architecture: %s", path);
break;
case NSObjectFileImageFormat:
logMessage(LOG_ERR, "invalid object format: %s", path);
break;
case NSObjectFileImageAccess:
logMessage(LOG_ERR, "inaccessible object: %s", path);
break;
case NSObjectFileImageFailure:
default:
logMessage(LOG_ERR, "shared object not loaded: %s", path);
break;
}
return NULL;
}
void
unloadSharedObject (void *object) {
NSModule module = object;
NSUnLinkModule(module, NSUNLINKMODULE_OPTION_NONE);
}
int
findSharedSymbol (void *object, const char *symbol, void *pointerAddress) {
NSModule module = object;
char name[strlen(symbol) + 2];
snprintf(name, sizeof(name), "_%s", symbol);
{
NSSymbol sym = NSLookupSymbolInModule(module, name);
if (sym) {
void **address = pointerAddress;
*address = NSAddressOfSymbol(sym);
return 1;
}
}
return 0;
}
const char *
getSharedSymbolName (void *address, ptrdiff_t *offset) {
return NULL;
}
|