STATUS symFindByNameEPICS( 
	SYMTAB_ID symTblId,
	char      *name,
	char      **ppvalue,
	SYM_TYPE  *pType    )
{
	static int leadingUnderscore = 1;
	static int init = 0;
	STATUS status = ERROR;

	if (!init) {
		char *pSymValue;
		SYM_TYPE type;
		status = symFindByName ( symTblId, "symFindByNameEPICS", &pSymValue, &type );
		if (status==OK) {
			leadingUnderscore = 0;
		}
		init = 1;
	}

	if (name[0] != '_' || leadingUnderscore) {
		status = symFindByName ( symTblId, name, ppvalue, pType );
	}
	else {
		status = symFindByName ( symTblId, (name+1), ppvalue, pType );
	}

	return status;
}
Esempio n. 2
0
/*
 * If we find SENS resolver, use the functions found there, i.e.
 * resolvGetHostByName() and resolvGetHostByAddr(). Otherwise we use
 * our own, which are just wrappers around hostGetByName() and
 * hostGetByAddr(). Here we look up the functions.
 */
void ei_init_resolve(void)
{

#ifdef VXWORKS
  void *sym;
  SYM_TYPE symtype;

  if (symFindByName(sysSymTbl,"resolvGetHostByName",
		    (char **)&sym,&symtype) == OK && 
      verify_dns_configuration()) {
      sens_gethostbyname = sym;
      DEBUGF((stderr,"found SENS resolver - using it for gethostbyname()\n"));
      if (symFindByName(sysSymTbl,"resolvGetHostByAddr",
			(char **)&sym,&symtype) == OK) {
	  sens_gethostbyaddr = sym;
	  DEBUGF((stderr,"found SENS resolver - "
		  "using it for gethostbyaddr()\n"));
      }
      else {
	  DEBUGF((stderr,"SENS resolver not found - "
		  "using default gethostbyaddr()\n"));
      }
  }
  else {
      DEBUGF((stderr,"SENS resolver not found - "
	      "using default gethostbyname()\n"));
  }
#endif /* VXWORKS */

#ifdef _REENTRANT
  ei_gethost_sem = ei_mutex_create();
#endif /* _REENTRANT */

  ei_resolve_initialized = 1;
}
Esempio n. 3
0
/*
** Function to verify the DNS configuration on VwXorks SENS.
** Actually configures to a default value if unconfigured...
*/
static int verify_dns_configuration(void) 
{
    /* FIXME problem for threaded ? */ 
    static char resolv_params[sizeof(RESOLV_PARAMS_S)];
    void (*rpg)(char *);
    STATUS (*rps)(char *);
    SYM_TYPE dummy;
    int get_result, set_result;

    get_result = symFindByName(sysSymTbl,"resolvParamsGet", (char **) &rpg, &dummy);
    set_result = symFindByName(sysSymTbl,"resolvParamsSet", (char **) &rps, &dummy);

    if (!(get_result == OK &&
	  set_result == OK))
	return -1;
    (*rpg)(resolv_params);
    if (*resolv_params == '\0') {
	/* It exists, but is not configured, ei_connect would fail
	   if we left it this way... The best we can do is to configure
	   it to use the local host database on the card, as a fallback */
	*resolv_params = (char) 1;
	fprintf(stderr,"Trying to fix up DNS configuration.\n");
	if (((*rps)(resolv_params)) != OK)
	  return -1;
    }
    return 0;
}
Esempio n. 4
0
/**
 * loads the dll libraries and spawns a task for the MAINCRIO
 */
void MyStart(void) {
    printf("Loading Dynamic Library...\n");
    /* load the library */
#if NiFpga_Windows || NiFpga_Ets
    MODULE_ID lib =  LoadLibraryA("MainCRIO.dll");
#elif NiFpga_VxWorks
    MODULE_ID lib =  VxLoadLibraryFromPath("MainCRIO.out", 0);
#else
    printf("Error dudes loading MainCRIO.out\n");
#endif
    const char* const name = "MainCRIO";
    void** const address;
    SYM_TYPE type;
    STATUS retVal = symFindByName(sysSymTbl,
                                  (char*)name,
                                  (char**)address,
                                  &type);
    if (retVal == OK)
    {
        taskSpawn("MainCRIO", 100, VX_FP_TASK, 0x8000, (FUNCPTR) *address, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    }
    else {
        perror("Error loading MainCRIO function");
    }
    /* Freeing the library makes shit go all explody if the task hasn't
     * exited */

    /*printf("Freeing the library...\n");
    VxFreeLibrary(lib, 0);
    printf("Library freed...\n");*/
}
Esempio n. 5
0
STATUS symFindByNameEPICS(SYMTAB_ID symTblId, char *name, char **ppvalue,
    SYM_TYPE *pType)
{
    if (name[0] == '_' && symNoUnderscore(symTblId))
        name++;

    return symFindByName(symTblId, name, ppvalue, pType);
}
Esempio n. 6
0
static  FUNCPTR lookup_function(char *symname){
    char *value;
    SYM_TYPE type;
    if(symFindByName(sysSymTbl,
		     symname,
		     &value,
		     &type) == ERROR /*|| type != N_TEXT*/)
	return NULL;
    return (FUNCPTR) value;
}
Esempio n. 7
0
File: os.c Progetto: heathzj/moped
void* dlsym(void* handle, const char* symbol) {
    //char symName[strlen(symbol) + 1];

    //strcpy(symName, symbol);

    char* fn;
    SYM_TYPE ptype;

    STATUS status = symFindByName(sysSymTbl, (char*)symbol, &fn, &ptype);
	
    return status == OK ? fn : NULL;
}
Esempio n. 8
0
static int symNoUnderscore(SYMTAB_ID symTblId)
{
    static int init = 0;
    static int noUnderscore = 0;

    if (!init) {
        char name[] = "symFindByNameEPICS";
        char *pSymValue;
        SYM_TYPE type;

        if (symFindByName(symTblId, name, &pSymValue, &type) == OK)
            noUnderscore = 1;
        init = 1;
    }
    return noUnderscore;
}
Esempio n. 9
0
/*
 *  Find and Exec a function in the System Symbol Table
 *
 */
int execFunc(char *funcName, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7, void *arg8)
{
    int stat;
    char *addr,type;
    PFIentry   pFuncEntry;

    /* function name in the sysmbol table, obtain entry point if present */
    stat = symFindByName(sysSymTbl,funcName,&addr,&type);
    if ((stat != 0) || (addr == NULL))
        return(-1);

    DPRINT4(2,"execFunc()  stat: %d from sysFindByname('%s'): Addr: 0x%lx, Type: %d\n",stat,funcName,addr,type);
    pFuncEntry = (PFIentry) addr;
    stat =  (*pFuncEntry)(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8);
    return(stat);
}
Esempio n. 10
0
STATUS
newfh(vxfh_t * vxfhp, char *fullpath)
{
	DEV_HDR        *devhdrp;
	SYMBOL         *sp, *sp2;
	int             fd;
	char           *valuep, type;

	if ((fd = open(fullpath, O_RDONLY, 0)) < 0)
		return ERROR;

	if ((devhdrp = iosFdDevFind(fd)) == NULL) {
		close(fd);
		return ERROR;
	}
	if (devhdrp->drvNum == rt11FsDrvNum) {
		vxfhp->type = rt11FsDrvNum;
		strcpy(vxfhp->opaque, fullpath);
		close(fd);
		return OK;
	}
	if (devhdrp->drvNum == dosFsDrvNum) {
		path_to_all_lower(fullpath);

		if (symFindByName(nfsd_pathtab, fullpath, &valuep,
				  &type) == OK) {
			vxfhp->type = dosFsDrvNum;
			*((int *) (vxfhp->opaque)) = (int) valuep;

			close(fd);

			nfsd_debug("newfh: return existing valuep %x <%s>\n",
				   valuep, fullpath);

			return OK;
		}
		if (!(sp = symAlloc(nfsd_pathtab, fullpath, 0,
				    (SYM_TYPE) NFSD_MSDOS_TYPE, 0))) {
			nfsd_debug("newfh: can't symAlloc sp %x <%s>\n",
				   sp, fullpath);
			nfsd_debugno();
			close(fd);
			return ERROR;
		}
		sp->value = (char *) sp;

		if (symTblAdd(nfsd_pathtab, sp) == ERROR) {
			/*
			 * XXX -- only try 2 times if it fails. highly
			 * unlikely hash will collide two times in a row with
			 * different values. but this is obviously imperfect.
			 */
			if (!(sp2 = symAlloc(nfsd_pathtab, fullpath, 0,
					  (SYM_TYPE) NFSD_MSDOS_TYPE, 0))) {
				nfsd_debug("newfh: can't symAlloc sp2 <%s>\n",
					   fullpath);
				close(fd);
				symFree(nfsd_pathtab, sp);
				return ERROR;
			}
			symFree(nfsd_pathtab, sp);
			sp = sp2;
			sp->value = (char *) sp;

			if (symTblAdd(nfsd_pathtab, sp) == ERROR) {
				nfsd_debugno();
				nfsd_debug("newfh: couldn't add <%s>\n",
					   fullpath);
				symFree(nfsd_pathtab, sp);
				close(fd);

				return ERROR;
			}
		}
		nfsd_debug("newfh: <%s> added as <%x>\n",
			   fullpath, sp);

		nfsd_debug("newfh: total %d paths are in pathtab now.\n",
			   nfsd_pathtab->nsymbols);

		vxfhp->type = dosFsDrvNum;
		*((int *) (vxfhp->opaque)) = (int) sp;

		close(fd);
		return OK;
	}
	close(fd);
	return ERROR;
}
Esempio n. 11
0
/*
    Launch the CGI process and return a handle to it. Process spawning is not supported in VxWorks.  Instead, we spawn a
    "task".  A major difference is that we have to know the entry point for the taskSpawn API.  Also the module may have
    to be loaded before being executed; it may also be part of the OS image, in which case it cannot be loaded or
    unloaded.  
    The following sequence is used:
    1. If the module is already loaded, unload it from memory.
    2. Search for a query string keyword=value pair in the environment variables where the keyword is cgientry.  If
        found use its value as the the entry point name.  If there is no such pair set the entry point name to the
        default: basename_cgientry, where basename is the name of the cgi file without the extension.  Use the entry
        point name in a symbol table search for that name to use as the entry point address.  If successful go to step 5.
    3. Try to load the module into memory.  If not successful error out.
    4. If step 3 is successful repeat the entry point search from step 2. If the entry point exists, go to step 5.  If
        it does not, error out.
    5. Use taskSpawn to start a new task which uses vxWebsCgiEntry as its starting point. The five arguments to
        vxWebsCgiEntry will be the user entry point address, argp, envp, stdIn and stdOut.  vxWebsCgiEntry will convert
        argp to an argc argv pair to pass to the user entry, it will initialize the task environment with envp, it will
        open and redirect stdin and stdout to stdIn and stdOut, and then it will call the user entry.
    6.  Return the taskSpawn return value.
 */
static int launchCgi(char *cgiPath, char **argp, char **envp, char *stdIn, char *stdOut)
{
    SYM_TYPE    ptype;
    char      *p, *basename, *pEntry, *pname, *entryAddr, **pp;
    int         priority, rc, fd;

    /*
        Determine the basename, which is without path or the extension.
     */
    if ((int)(p = strrchr(cgiPath, '/') + 1) == 1) {
        p = cgiPath;
    }
    basename = sclone(p);
    if ((p = strrchr(basename, '.')) != NULL) {
        *p = '\0';
    }
    /*
        Unload the module, if it is already loaded.  Get the current task priority.
     */
    unld(cgiPath, 0);
    taskPriorityGet(taskIdSelf(), &priority);
    rc = fd = -1;

    /*
         Set the entry point symbol name as described above.  Look for an already loaded entry point; if it exists, spawn
         the task accordingly.  
     */
    for (pp = envp, pEntry = NULL; pp != NULL && *pp != NULL; pp++) {
        if (strncmp(*pp, "cgientry=", 9) == 0) {
            pEntry = sclone(*pp + 9);
            break;
        }
    }
    if (pEntry == NULL) {
        pEntry = sfmt("%s_%s", basename, "cgientry");
    }
    entryAddr = 0;
    if (symFindByName(sysSymTbl, pEntry, &entryAddr, &ptype) == -1) {
        pname = sfmt("_%s", pEntry);
        symFindByName(sysSymTbl, pname, &entryAddr, &ptype);
        wfree(pname);
    }
    if (entryAddr != 0) {
        rc = taskSpawn(pEntry, priority, 0, 20000, (void*) vxWebsCgiEntry, (int) entryAddr, (int) argp, 
            (int) envp, (int) stdIn, (int) stdOut, 0, 0, 0, 0, 0);
        goto done;
    }

    /*
        Try to load the module.
     */
    if ((fd = open(cgiPath, O_RDONLY | O_BINARY, 0666)) < 0 ||
        loadModule(fd, LOAD_GLOBAL_SYMBOLS) == NULL) {
        goto done;
    }
    if ((symFindByName(sysSymTbl, pEntry, &entryAddr, &ptype)) == -1) {
        pname = sfmt("_%s", pEntry);
        symFindByName(sysSymTbl, pname, &entryAddr, &ptype);
        wfree(pname);
    }
    if (entryAddr != 0) {
        rc = taskSpawn(pEntry, priority, 0, 20000, (void*) vxWebsCgiEntry, (int) entryAddr, (int) argp, 
            (int) envp, (int) stdIn, (int) stdOut, 0, 0, 0, 0, 0);
    }
done:
    if (fd != -1) {
        close(fd);
    }
    wfree(basename);
    wfree(pEntry);
    return rc;
}
Esempio n. 12
0
static int start_process(Channel * c, char ** envp, char * dir, char * exe, char ** args, int attach,
                int * pid, int * selfattach, ChildProcess ** prs) {
    int err = 0;
    char * ptr;
    SYM_TYPE type;

    if (symFindByName(sysSymTbl, exe, &ptr, &type) != OK) {
        err = errno;
        if (err == S_symLib_SYMBOL_NOT_FOUND) err = ERR_SYM_NOT_FOUND;
        assert(err != 0);
    }
    else {
        int i;
        int pipes[2][2];
        /* TODO: arguments, environment */
        *pid = taskCreate("tTcf", 100, 0, 0x4000, (FUNCPTR)ptr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        for (i = 0; i < 2; i++) {
            char pnm[32];
            char pnm_m[32];
            char pnm_s[32];
            snprintf(pnm, sizeof(pnm), "/pty/tcf-%0*lx-%d", sizeof(*pid) * 2, *pid, i);
            snprintf(pnm_m, sizeof(pnm_m), "%sM", pnm);
            snprintf(pnm_s, sizeof(pnm_m), "%sS", pnm);
            if (ptyDevCreate(pnm, PIPE_SIZE, PIPE_SIZE) == ERROR) {
                err = errno;
                break;
            }
            pipes[i][0] = open(pnm_m, O_RDWR, 0);
            pipes[i][1] = open(pnm_s, O_RDWR, 0);
            if (pipes[i][0] < 0 || pipes[i][1] < 0) {
                err = errno;
                break;
            }
        }
        if (err) {
            taskDelete(*pid);
            *pid = 0;
        }
        else {
            semTake(prs_list_lock, WAIT_FOREVER);
            ioTaskStdSet(*pid, 0, pipes[0][1]);
            ioTaskStdSet(*pid, 1, pipes[0][1]);
            ioTaskStdSet(*pid, 2, pipes[1][1]);
            *prs = loc_alloc_zero(sizeof(ChildProcess));
            (*prs)->inp = pipes[0][0];
            (*prs)->out = pipes[0][0];
            (*prs)->err = pipes[1][0];
            (*prs)->pid = *pid;
            (*prs)->bcg = c->bcg;
            list_add_first(&(*prs)->link, &prs_list);
            if (attach) {
                taskStop(*pid);
                taskActivate(*pid);
                assert(taskIsStopped(*pid));
            }
            else {
                taskActivate(*pid);
            }
            semGive(prs_list_lock);
        }
    }
    if (!err) return 0;
    errno = err;
    return -1;
}
Esempio n. 13
0
int websLaunchCgiProc(char_t *cgiPath, char_t **argp, char_t **envp,
					  char_t *stdIn, char_t *stdOut)
{
	SYM_TYPE	ptype;
	char_t		*p, *basename, *pEntry, *pname, *entryAddr, **pp;
	int			priority, rc, fd;

/*
 *	Determine the basename, which is without path or the extension.
 */
	if ((int)(p = gstrrchr(cgiPath, '/') + 1) == 1) {
		p = cgiPath;
	}
	basename = bstrdup(B_L, p);
	if ((p = gstrrchr(basename, '.')) != NULL) {
		*p = '\0';
	}

/*
 *	Unload the module, if it is already loaded.  Get the current task
 *	priority.
 */
	unld(cgiPath, 0);
	taskPriorityGet(taskIdSelf(), &priority);
	rc = fd = -1;

/*
 *	Set the entry point symbol name as described above.  Look for an already
 *	loaded entry point; if it exists, spawn the task accordingly.
 */
	for (pp = envp, pEntry = NULL; pp != NULL && *pp != NULL; pp++) {
		if (gstrncmp(*pp, T("cgientry="), 9) == 0) {
			pEntry = bstrdup(B_L, *pp + 9);
			break;
		}
	}
	if (pEntry == NULL) {
		fmtAlloc(&pEntry, LF_PATHSIZE, T("%s_%s"), basename, T("cgientry"));
	}

	entryAddr = 0;
	if (symFindByName(sysSymTbl, pEntry, &entryAddr, &ptype) == -1) {
		fmtAlloc(&pname, VALUE_MAX_STRING, T("_%s"), pEntry);
		symFindByName(sysSymTbl, pname, &entryAddr, &ptype);
		bfreeSafe(B_L, pname);
	}
	if (entryAddr != 0) {
		rc = taskSpawn(pEntry, priority, 0, 20000, (void *)vxWebsCgiEntry,
			(int)entryAddr, (int)argp, (int)envp, (int)stdIn, (int)stdOut,
			0, 0, 0, 0, 0);
		goto DONE;
	}

/*
 *	Try to load the module.
 */
	if ((fd = gopen(cgiPath, O_RDONLY | O_BINARY, 0666)) < 0 ||
		loadModule(fd, LOAD_GLOBAL_SYMBOLS) == NULL) {
		goto DONE;
	}
	if ((symFindByName(sysSymTbl, pEntry, &entryAddr, &ptype)) == -1) {
		fmtAlloc(&pname, VALUE_MAX_STRING, T("_%s"), pEntry);
		symFindByName(sysSymTbl, pname, &entryAddr, &ptype);
		bfreeSafe(B_L, pname);
	}
	if (entryAddr != 0) {
		rc = taskSpawn(pEntry, priority, 0, 20000, (void *)vxWebsCgiEntry,
			(int)entryAddr, (int)argp, (int)envp, (int)stdIn, (int)stdOut,
			0, 0, 0, 0, 0);
	}

DONE:
	if (fd != -1) {
		gclose(fd);
	}
	bfree(B_L, basename);
	bfree(B_L, pEntry);
	return rc;
}
Esempio n. 14
0
/*
    Start the command to run (stdIn and stdOut are named from the client's perspective)
 */
int startProcess(MprCmd *cmd)
{
    MprCmdTaskFn    entryFn;
    SYM_TYPE        symType;
    char            *entryPoint, *program;
    int             i, pri;

    mprLog(cmd, 4, "cmd: start %s", cmd->program);

    entryPoint = 0;
    if (cmd->env) {
        for (i = 0; cmd->env[i]; i++) {
            if (strncmp(cmd->env[i], "entryPoint=", 11) == 0) {
                entryPoint = mprStrdup(cmd, cmd->env[i]);
            }
        }
    }
    program = mprGetPathBase(cmd, cmd->program);
    if (entryPoint == 0) {
        program = mprTrimPathExtension(cmd, program);
#if BLD_HOST_CPU_ARCH == MPR_CPU_IX86 || BLD_HOST_CPU_ARCH == MPR_CPU_IX64
        entryPoint = mprStrcat(cmd, -1, "_", program, "Main", NULL);
#else
        entryPoint = mprStrcat(cmd, -1, program, "Main", NULL);
#endif
    }

    if (symFindByName(sysSymTbl, entryPoint, (char**) &entryFn, &symType) < 0) {
        if (mprLoadModule(cmd, cmd->program, NULL) == 0) {
            mprError(cmd, "start: can't load DLL %s, errno %d", program, mprGetOsError());
            return MPR_ERR_CANT_READ;
        }
        if (symFindByName(sysSymTbl, entryPoint, (char**) &entryFn, &symType) < 0) {
            mprError(cmd, "start: can't find symbol %s, errno %d", entryPoint, mprGetOsError());
            return MPR_ERR_CANT_ACCESS;
        }
    }
    taskPriorityGet(taskIdSelf(), &pri);

    /*
     *  Pass the server output file to become the client stdin.
     */
    cmd->pid = taskSpawn(entryPoint, pri, VX_FP_TASK, MPR_DEFAULT_STACK, (FUNCPTR) cmdTaskEntry, 
        (int) cmd->program, (int) entryFn, (int) cmd, 0, 0, 0, 0, 0, 0, 0);

    if (cmd->pid < 0) {
        mprError(cmd, "start: can't create task %s, errno %d", entryPoint, mprGetOsError());
        mprFree(entryPoint);
        return MPR_ERR_CANT_CREATE;
    }

    mprLog(cmd, 7, "cmd, child taskId %d", cmd->pid);
    mprFree(entryPoint);

    if (semTake(cmd->startCond, MPR_TIMEOUT_START_TASK) != OK) {
        mprError(cmd, "start: child %s did not initialize, errno %d", cmd->program, mprGetOsError());
        return MPR_ERR_CANT_CREATE;
    }
    semDelete(cmd->startCond);
    cmd->startCond = 0;

    return 0;
}