Beispiel #1
0
void * dlopen(const char * path, int mode)
{
    const struct stat * sbuf;
    struct dlstatus * dls;
    const char * fullPath;
    if (!path)
    {
        return &mainStatus;
    }    
    if (!(sbuf = findFile(path, &fullPath)))
    {
        error("file \"%s\" not found", path);
        return NULL;
    }
    /* Now checks that it hasn't been closed already */
    if ((dls = lookupStatus(sbuf)) && (dls->refs > 0))
    {
        /* debug("status found"); */
        return reference(dls, mode);    
    }
    if (isFlagSet(mode, RTLD_NOLOAD))
    {
        error("no existing handle and RTLD_NOLOAD specified");
        return NULL;
    }
    return reference(loadModule(fullPath, sbuf, mode),mode);
}
Beispiel #2
0
static void processOI(struct sqlConnection *conn, struct gbSelect* select,
                      struct gbStatusTbl* statusTbl,
                      struct estOrientInfo* oi, struct lineFile *oiLf)
/* Process the next orientationInfo entry */
{
struct gbStatus *status = lookupStatus(oi->name, statusTbl, oiLf, NULL);
if (status != NULL)
    {
    struct gbAlignTbl *gat = gbAlignTblSetGet(alignTblSet, status);
    gbAlignTblWriteOi(gat, oi, conn);
    }
}
Beispiel #3
0
static void processIntronPsl(struct sqlConnection *conn,
                             struct gbSelect* select,
                             struct gbStatusTbl* statusTbl, struct psl* psl,
                             struct lineFile *pslLf)
/* Process the next intron PSL entry */
{
struct gbStatus *status = lookupStatus(psl->qName, statusTbl, pslLf, NULL);
if (status != NULL)
    {
    struct gbAlignTbl *gat = gbAlignTblSetGetIntronEst(alignTblSet);
    gbAlignTblWrite(gat, psl, conn);
    }
}
Beispiel #4
0
static void processPsl(struct sqlConnection *conn, struct gbSelect* select,
                       struct gbStatusTbl* statusTbl, struct psl* psl,
                       struct lineFile *pslLf)
/* Process the next PSL */
{
short version;
struct gbStatus *status = lookupStatus(psl->qName, statusTbl, pslLf, &version);
if (status != NULL)
    {
    processSelectedPsl(conn, select, status, psl);
    status->version = version;
    status->numAligns++;
    }
}
Beispiel #5
0
void *DL_PREFIX(dlopen)(const char *path, int mode)
{
	const struct stat *sbuf;
	struct dlstatus *dls;
	const char *fullPath;

	dolock();
	resetdlerror();
	if (!path)
	{
		dls = &mainStatus;
		goto dlopenok;
	}
	if (!(sbuf = findFile(path, &fullPath)))
	{
		error("file \"%s\" not found", path);
		goto dlopenerror;
	}
	/* Now checks that it hasn't been closed already */
	if ((dls = lookupStatus(sbuf)) && (dls->refs > 0))
	{
		/* debug("status found"); */
		dls = reference(dls, mode);
		goto dlopenok;
	}
#ifdef 	RTLD_NOLOAD
	if (isFlagSet(mode, RTLD_NOLOAD))
	{
		error("no existing handle and RTLD_NOLOAD specified");
		goto dlopenerror;
	}
#endif
	if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW))
	{
		error("how can I load something both RTLD_LAZY and RTLD_NOW?");
		goto dlopenerror;
	}
	dls = loadModule(fullPath, sbuf, mode);
	
  dlopenok:
	dounlock();
	return (void *)dls;
  dlopenerror:
	dounlock();
	return NULL;
}
static void loadRow(struct mgcStatusTbl *mst, struct lineFile *lf, char **row, 
                    int numCols)
/* Load an mgcStatus row from a tab file */
{
int imageId =  lineFileNeedNum(lf, row, 0);
struct mgcStatusType *status = lookupStatus(row[1]);
enum mgcState state;
if (status == NULL)
    errAbort("%s:%d: invalid status value: \"%s\"",
             lf->fileName, lf->lineIx, row[1]);
state = mgcStateParse(row[2]);
if (state == MGC_STATE_NULL)
    errAbort("%s:%d: invalid state value: \"%s\"",
             lf->fileName, lf->lineIx, row[2]);
if (state != status->state)
    errAbort("%s:%d: state value \"%s\" dosn't match status value \"%s\"",
             lf->fileName, lf->lineIx, row[2], row[1]);

if ((state == MGC_STATE_FULL_LENGTH) || !(mst->opts & mgcStatusFullOnly))
    {
    char *geneName = (numCols > MGCSTATUS_MIN_NUM_COLS) ? row[5] : NULL;
    mgcStatusTblAdd(mst, imageId, status, row[3], row[4], geneName);
    }
}
Beispiel #7
0
static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode)
{
	NSObjectFileImage ofi = 0;
	NSObjectFileImageReturnCode ofirc;
	struct dlstatus *dls;
	NSLinkEditErrors ler;
	int lerno;
	const char *errstr;
	const char *file;
	void (*init) (void);
	ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
	switch (ofirc)
	{
		case NSObjectFileImageSuccess:
			break;
		case NSObjectFileImageInappropriateFile:
			if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
			{	
				if (isFlagSet(mode, RTLD_LOCAL))
				{
					warning("trying to open a .dylib with RTLD_LOCAL");
					error("unable to open this file with RTLD_LOCAL");
					return NULL;
				}
			}
			else
			{
				error("opening this file is unsupported on this system");
				return NULL;
			}
			break;
		case NSObjectFileImageFailure:
			error("object file setup failure");
			return NULL;
		case NSObjectFileImageArch:
			error("no object for this architecture");
			return NULL;
		case NSObjectFileImageFormat:
			error("bad object file format");
			return NULL;
		case NSObjectFileImageAccess:
			error("can't read object file");
			return NULL;
		default:
			error("unknown error from NSCreateObjectFileImageFromFile()");
			return NULL;
	}
	dls = lookupStatus(sbuf);
	if (!dls)
	{
		dls = allocStatus();
	}
	if (!dls)
	{
		error("unable to allocate memory");
		return NULL;
	}
	dls->lib = 0;
	if (ofirc == NSObjectFileImageInappropriateFile)
	{
		if ((dls->lib = dyld_NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR)))
		{
			debug("Dynamic lib loaded at %ld", dls->lib);
			ofi = MAGIC_DYLIB_OFI;
			dls->module = MAGIC_DYLIB_MOD;
			ofirc = NSObjectFileImageSuccess;
			/* Although it is possible with a bit of work to modify this so it works and
			   functions with RTLD_NOW, I don't deem it necessary at the moment */
		}
		if (!(dls->module))
		{
			NSLinkEditError(&ler, &lerno, &file, &errstr);
			if (!errstr || (!strlen(errstr)))
				error("Can't open this file type");
			else
				error(errstr);
			if ((dls->flags & DL_IN_LIST) == 0)
			{
				free(dls);
			}
			return NULL;
		}
	}
	else
	{
		dls->module = NSLinkModule(ofi, path,
								   NSLINKMODULE_OPTION_RETURN_ON_ERROR |
								   NSLINKMODULE_OPTION_PRIVATE |
								   (isFlagSet(mode, RTLD_NOW) ? NSLINKMODULE_OPTION_BINDNOW : 0));
		NSDestroyObjectFileImage(ofi);
		if (dls->module)
		{
			dls->lib = get_mach_header_from_NSModule(dls->module);
		}
	}
	if (!dls->module)
	{
		NSLinkEditError(&ler, &lerno, &file, &errstr);
		if ((dls->flags & DL_IN_LIST) == 0)
		{
			free(dls);
		}
		error(errstr);
		return NULL;
	}

	insertStatus(dls, sbuf);
	dls = reference(dls, mode);
	if ((init = dlsymIntern(dls, "__init", 0)))
	{
		debug("calling _init()");
		init();
	}
	return dls;
}
Beispiel #8
0
static struct dlstatus * loadModule(const char * path, 
                    const struct stat * sbuf, int mode)
{
    NSObjectFileImage ofi = 0;
    NSObjectFileImageReturnCode ofirc;
    struct dlstatus * dls; 
    NSLinkEditErrors ler;
    int lerno;
    const char* errstr;
    const char* file;
    void (*init)(void);

    ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
    switch (ofirc)
    {
        case NSObjectFileImageSuccess:
            break;
        case NSObjectFileImageInappropriateFile:
            if (isFlagSet(mode, RTLD_LOCAL))
            {
                warning("trying to open a .dylib with RTLD_LOCAL");
                error("unable to open this file with RTLD_LOCAL");
                return NULL;
            }                
            break;
        case NSObjectFileImageFailure:
            error("object file setup failure");
            return NULL;
        case NSObjectFileImageArch:
            error("no object for this architecture");
            return NULL;
        case NSObjectFileImageFormat:
            error("bad object file format");
            return NULL;
        case NSObjectFileImageAccess:
            error("can't read object file");
            return NULL;
        default:
            error("unknown error from NSCreateObjectFileImageFromFile()");
            return NULL;
    }
    dls = lookupStatus(sbuf);
    if (!dls) 
    {
        dls = allocStatus();
    }    
    if (!dls)
    {
        error("unable to allocate memory");
        return NULL;
    }
    dls->lib=0;
    if (ofirc == NSObjectFileImageInappropriateFile)
    {
        if ((dls->lib = NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR)))
        {
            debug("Dynamic lib loaded at %ld",dls->lib);
            ofi = MAGIC_DYLIB_OFI;
            dls->module = MAGIC_DYLIB_MOD;
            ofirc = NSObjectFileImageSuccess;
        }
    }
    else 
    {
        /* Should change this to take care of RLTD_LAZY etc */
        dls->module = NSLinkModule(ofi, path,
                    NSLINKMODULE_OPTION_RETURN_ON_ERROR
                     | NSLINKMODULE_OPTION_PRIVATE
                    | NSLINKMODULE_OPTION_BINDNOW);
        NSDestroyObjectFileImage(ofi);
    }
    if (!dls->module)
    {
        NSLinkEditError(&ler,&lerno,&file,&errstr);            
        free(dls); 
        error(errstr);
        return NULL;
    }
    insertStatus(dls, sbuf);
    
    if ((init = dlsymIntern(dls, "__init",0)))
    {
        debug("calling _init()");
        init();
    }

    return dls;
}