/** Begin System call monitoring ************************************************************/
int monitorSytemCalls(FILE * logf, struct SCRIPT * script, struct TYPING * types, 
					   unsigned long location, struct LINE * line){
	char * tokens = (char *) calloc(TOKENMAXNB*TOKENSIZE,sizeof(char));
	int nbtokens, i;
	
	//Search for control operations
	if(monitorFileControl(logf,script,types,location,line)) return 1;
	if(monitorRegControl(logf,script,types,location,line)) return 1;
	if(monitorMailControl(logf,script,types,location,line)) return 1;
	//Search for input/output operations
	if(monitorFileIO(logf,script,types,location,line)) return 1;
	if(monitorRegIO(logf,script,types,location,line)) return 1;
	if(monitorMailIO(logf,script,types,location,line)) return 1;

	//Special folder (ignored in this version)
	if(strcasestr(line->line,".GetSpecialFolder")) return 1;
				
	//Parse line for script exit
	nbtokens = decomposeLine(line->line,(char*)tokens,TOKENMAXNB,TOKENSIZE);
	for(i=0;i<nbtokens;i++){
		//Script generic object
		if(isStaticScriptObject(ACCESS(tokens,i))>-1){
			if(!strcasecmp(ACCESS(tokens,i+1),STOP0)){
				line->type = SYSCALL;
				printLogEntry(logf, types, OP_STOP, 0, 0);
				return 1;
			}//if
		}
	}//for
	free(tokens);
	return 0;
}
Esempio n. 2
0
static bool xenmem_access_to_p2m_access(struct p2m_domain *p2m,
                                        xenmem_access_t xaccess,
                                        p2m_access_t *paccess)
{
    static const p2m_access_t memaccess[] = {
#define ACCESS(ac) [XENMEM_access_##ac] = p2m_access_##ac
        ACCESS(n),
        ACCESS(r),
        ACCESS(w),
        ACCESS(rw),
        ACCESS(x),
        ACCESS(rx),
        ACCESS(wx),
        ACCESS(rwx),
        ACCESS(rx2rw),
        ACCESS(n2rwx),
#undef ACCESS
    };

    switch ( xaccess )
    {
    case 0 ... ARRAY_SIZE(memaccess) - 1:
        *paccess = memaccess[xaccess];
        break;
    case XENMEM_access_default:
        *paccess = p2m->default_access;
        break;
    default:
        return false;
    }

    return true;
}
Esempio n. 3
0
// Initialize the application and telephony API. Blocks.
State * TeleKarma::Initialize(Action * a, State * s)
{
	if (s->id != STATE_UNINITIALIZED) return s;
	bool flag = false;
	InitializeAction * ia = dynamic_cast<InitializeAction *>(a);
	State * result = NULL;
	if (ia == NULL) {
		result = SetState(new State(STATE_INITIALIZING, s->turn+1));
		result = SetState(new State(result->id, result->turn, STATUS_FAILED, "Programming error: action cast failed"));
		result = SetState(new State(STATE_UNINITIALIZED, result->turn+1));
	} else {
		// set stun server **before** entering INITIALIZING state
		model->SetStunServer(ia->stunServer);
		result = SetState(new State(STATE_INITIALIZING, s->turn+1));
		// verify existence and type of 'logs' folder
		const char * strPath1 = "logs";
		struct stat status;
		stat(strPath1, &status);
		bool existsLogs = !((ACCESS(strPath1, 0) == -1) || !(status.st_mode & S_IFDIR));
		// verify existence and type of 'recordings' folder
		const char * strPath2 = "recordings";
		stat(strPath2, &status);
		bool existsRecordings = !((ACCESS(strPath2, 0) == -1) || !(status.st_mode & S_IFDIR));
		if (!(existsLogs || existsRecordings)){
			result = SetState(new State(result->id, result->turn, STATUS_FAILED, "Please create \"logs\" and \"recordings\" folders in your TeleKarma program folder."));
			flag = true;
		} else if (!existsLogs) {
			result = SetState(new State(result->id, result->turn, STATUS_FAILED, "Please create a \"logs\" folder in your TeleKarma program folder."));
			flag = true;
		} else if (!existsRecordings) {
			result = SetState(new State(result->id, result->turn, STATUS_FAILED, "Please create a \"recordings\" folder in your TeleKarma program folder."));
			flag = true;
		}
		if (flag) {
			result = SetState(new State(STATE_UNINITIALIZED, result->turn+1));
		} else {
			// create log file
			PTime now;
			PString logFName("logs/log");
			logFName += now.AsString("_yyyy.MM.dd_hh.mm.ss");
			logFName += ".txt";
			PTrace::Initialise(3, logFName);
			// initialize telephony (blocking call)
			phone->Initialise(ia->stunServer);
			PSTUNClient * stunClient = phone->GetSTUNClient();
			if (stunClient != NULL) {
				model->SetStunType(stunClient->GetNatTypeName());
			} else {
				model->SetStunType("none");
			}
			result = SetState(new State(STATE_INITIALIZED, result->turn+1));
		}
	}
	return result;
}
Esempio n. 4
0
/**
 * Write PID file.
 *
 * @param sctx service context
 * @param pid PID to write (should be equal to 'getpid()'
 * @return  #GNUNET_OK on success (including no work to be done)
 */
static int
write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid)
{
  FILE *pidfd;
  char *pif;
  char *user;
  char *rdir;
  int len;

  if (NULL == (pif = get_pid_file_name (sctx)))
    return GNUNET_OK;           /* no file desired */
  user = get_user_name (sctx);
  rdir = GNUNET_strdup (pif);
  len = strlen (rdir);
  while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
    len--;
  rdir[len] = '\0';
  if (0 != ACCESS (rdir, F_OK))
  {
    /* we get to create a directory -- and claim it
     * as ours! */
    (void) GNUNET_DISK_directory_create (rdir);
    if ((NULL != user) && (0 < strlen (user)))
      GNUNET_DISK_file_change_owner (rdir, user);
  }
  if (0 != ACCESS (rdir, W_OK | X_OK))
  {
    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
    GNUNET_free (rdir);
    GNUNET_free_non_null (user);
    GNUNET_free (pif);
    return GNUNET_SYSERR;
  }
  GNUNET_free (rdir);
  pidfd = FOPEN (pif, "w");
  if (NULL == pidfd)
  {
    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
    GNUNET_free (pif);
    GNUNET_free_non_null (user);
    return GNUNET_SYSERR;
  }
  if (0 > FPRINTF (pidfd, "%u", pid))
    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
  GNUNET_break (0 == FCLOSE (pidfd));
  if ((NULL != user) && (0 < strlen (user)))
    GNUNET_DISK_file_change_owner (pif, user);
  GNUNET_free_non_null (user);
  GNUNET_free (pif);
  return GNUNET_OK;
}
Esempio n. 5
0
access_game (char *filename, char *mode, size_t (*af) ())
{
FILE *fd;
	fd = fopen (filename, mode);
	if (fd != NULL)
	{
		ACCESS (map)
		ACCESS (men)
		ACCESS (man)
		ACCESS (mutant)
		ACCESS (level)
		fclose (fd);
	}
}
Esempio n. 6
0
void playWav(char* filename, float samplerate)
{
    int fp= STDIN_FILENO;
    if(filename[0]!='-') fp = open(filename, 'r');
    //int sz = lseek(fp, 0L, SEEK_END);
    //lseek(fp, 0L, SEEK_SET);
    //short* data = (short*)malloc(sz);
    //read(fp, data, sz);
    
    int bufPtr=0;
    float datanew, dataold = 0;
    short data;
    
    for (int i=0; i<22; i++)
       read(fp, &data, 2);  // read past header
    
    while (read(fp, &data, 2)) {
        float fmconstant = samplerate * 50.0e-6;  // for pre-emphisis filter.  50us time constant
        int clocksPerSample = 22500.0/samplerate*1400.0;  // for timing

        datanew = (float)(data)/32767;
        
        float sample = datanew + (dataold-datanew) / (1-fmconstant);  // fir of 1 + s tau
        float dval = sample*15.0;  // actual transmitted sample.  15 is bandwidth (about 75 kHz)
        
        int intval = (int)(round(dval));  // integer component
        float frac = (dval - (float)intval)/2 + 0.5;
        unsigned int fracval = frac*clocksPerSample;
         
        bufPtr++;
        while( ACCESS(DMABASE + 0x04 /* CurBlock*/) ==  (int)(instrs[bufPtr].p)) usleep(1000);
        ((struct CB*)(instrs[bufPtr].v))->SOURCE_AD = (int)constPage.p + 2048 + intval*4 - 4 ;
        
        bufPtr++;
        while( ACCESS(DMABASE + 0x04 /* CurBlock*/) ==  (int)(instrs[bufPtr].p)) usleep(1000);
        ((struct CB*)(instrs[bufPtr].v))->TXFR_LEN = clocksPerSample-fracval;
        
        bufPtr++;
        while( ACCESS(DMABASE + 0x04 /* CurBlock*/) ==  (int)(instrs[bufPtr].p)) usleep(1000);
        ((struct CB*)(instrs[bufPtr].v))->SOURCE_AD = (int)constPage.p + 2048 + intval*4+4;
        
        bufPtr=(bufPtr+1) % (1024);
        while( ACCESS(DMABASE + 0x04 /* CurBlock*/) ==  (int)(instrs[bufPtr].p)) usleep(1000);
        ((struct CB*)(instrs[bufPtr].v))->TXFR_LEN = fracval;
        
        dataold = datanew;
    }
    close(fp);
}
Esempio n. 7
0
	Cmiss_differential_operator(FE_region *fe_region, int dimension, int term) :
		fe_region(ACCESS(FE_region)(fe_region)),
		dimension(dimension),
		term(term),
		access_count(1)
	{
	}
void CWE367_TOC_TOU__access_01_bad()
{
    {
        char filename[100] = "";
        int fileDesc = -1;
        if (fgets(filename, 100, stdin) == NULL)
        {
            printLine("fgets() failed");
            /* Restore NUL terminator if fgets fails */
            filename[0] = '\0';
        }
        if (strlen(filename) > 0)
        {
            filename[strlen(filename)-1] = '\0'; /* remove newline */
        }
        /* FLAW: Open and write to the file after checking the status information */
        if (ACCESS(filename, W_OK) == -1)
        {
            exit(1);
        }
        fileDesc  = OPEN(filename, O_RDWR);
        if (fileDesc == -1)
        {
            exit(1);
        }
        if (WRITE(fileDesc, BAD_SINK_STRING, strlen(BAD_SINK_STRING)) == -1)
        {
            exit(1);
        }
        if (fileDesc != -1)
        {
            CLOSE(fileDesc);
        }
    }
}
Esempio n. 9
0
UINT AviConverter::run() {
  try {
    CPicture picture;
    picture.load(m_nameArray[0]);
    const CSize imageSize = picture.getSize();

    HDC screenDC = getScreenDC();
    m_dc     = CreateCompatibleDC(screenDC);
    m_bitmap = CreateCompatibleBitmap(screenDC, imageSize.cx, imageSize.cy);
    DeleteDC(screenDC);
    DWORD codec = 0; // mmioFOURCC('w','m','v',' ');

    if(ACCESS(m_outFileName, 0) == 0) {
      UNLINK(m_outFileName);
    }
    CAviFile aviFile(m_outFileName, true, codec, m_framesPerSecond);

    for(m_index = 0; m_index < (int)m_nameArray.size(); m_index += m_useEvery) {
      if(isInterrupted()) {
        throwException(_T("Interrupted by user"));
      }
      picture.load(m_nameArray[m_index]);
      HGDIOBJ oldGDI = SelectObject(m_dc, m_bitmap);
      picture.show(m_dc);
      SelectObject(m_dc, oldGDI);
      aviFile.appendNewFrame(m_bitmap);
    }
  } catch(Exception e) {
    m_ok  = false;
    m_msg = e.what();
  }
  return 0;
}
Esempio n. 10
0
int ensure_dir(const char *sPathName)
{
	char DirName[MAX_PATH];
	int i, len = 0;
	strcpy(DirName, sPathName);
	len = (int)strlen(DirName);
	if (DirName[len - 1] != '/')
		strcat(DirName, "/");

	len = (int)strlen(DirName);

	for (i = 1; i < len; i++) {
		if (DirName[i] == '/' || DirName[i] == '\\') {
			DirName[i] = 0;
//			printf("%s\n", DirName);
			if (ACCESS(DirName, 0) != 0) {
				if (MKDIR(DirName) != 0) {
					printf("mkdir %s error %d\n", DirName, GETLASTERROR);
					return -1;
				}
			}
			DirName[i] = '/';
		}
	}

	return 0;
}
Esempio n. 11
0
/*********************************************
Functon:    Lia_Fifo_Read
Description:  read context from fifo
Author: liujian
Date: 2015/09/04
Input: void * pBuf:the context being readed from fifo
		pi8Path:fifo path
		i32MaxReadLen:maxium length of read
Returns: 0 indicates success
		negative numbers indicate failure
*********************************************/
Int32 Lia_Fifo_Read(Int8 *pi8Path,void * pBuf,Int32 i32MaxReadLen)
{
	Int32 i32Fd=-1;
	Int32 i32ReadCnt = -1;
	JUDGE_POINTER_IS_NULL(pBuf);
	JUDGE_POINTER_IS_NULL(pi8Path);
	ACCESS(pi8Path,F_OK);
	i32Fd=open(pi8Path, O_RDONLY,0);
	if (i32Fd < 0)
	{
		printf("open error:%s\n", strerror(errno));
		return -1;
	}
	i32ReadCnt = read(i32Fd, pBuf, i32MaxReadLen);
	if (i32ReadCnt<0)
	{
		printf("read error\n");
		return -1;
	}
	else if(0== i32ReadCnt)//write fifo has closed,unlink the read fifo
	{
		unlink(pi8Path);
	}
	close(i32Fd);

	return 0;
}
Esempio n. 12
0
bool QFile::exists( const char *fileName )
{
#if defined(CHECK_NULL)
    ASSERT( fileName != 0 );
#endif
    return ACCESS( fileName, F_OK ) == 0;
}
Esempio n. 13
0
void setup_fm()
{

    /* open /dev/mem */
    if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
        printf("can't open /dev/mem \n");
        exit (-1);
    }
    
    allof7e = (unsigned *)mmap(
                  NULL,
                  0x01000000,  //len
                  PROT_READ|PROT_WRITE,
                  MAP_SHARED,
                  mem_fd,
                  0x20000000  //base
              );

    if ((int)allof7e==-1) exit(-1);

    SETBIT(GPFSEL0 , 14);
    CLRBIT(GPFSEL0 , 13);
    CLRBIT(GPFSEL0 , 12);

 
    struct GPCTL setupword = {6/*SRC*/, 1, 0, 0, 0, 1,0x5a};

    ACCESS(CM_GP0CTL) = *((int*)&setupword);
}
Esempio n. 14
0
int jackpifm_setup_fm() {
  /* open /dev/mem */
  if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
    fprintf(stderr, "Can't open /dev/mem: %s\n", strerror(errno));
    return 1;
  }

  allof7e = (unsigned *)mmap(
      NULL,
      0x01000000,  //len
      PROT_READ|PROT_WRITE,
      MAP_SHARED,
      mem_fd,
      0x20000000  //base
  );

  if ((int)allof7e==-1) return 1;

  SETBIT(GPFSEL0 , 14);
  CLRBIT(GPFSEL0 , 13);
  CLRBIT(GPFSEL0 , 12);

  struct GPCTL setupword = {6/*SRC*/, 1, 0, 0, 0, 1,0x5a};
  ACCESS(CM_GP0CTL) = *((int*)(&setupword));
  return 0;
}
Esempio n. 15
0
// create the file, fail if it already exists and bOverwrite
bool wxFile::Create(const wxChar *szFileName, bool bOverwrite, int accessMode)
{
    // if bOverwrite we create a new file or truncate the existing one,
    // otherwise we only create the new file and fail if it already exists
#if defined(__WXMAC__) && !defined(__UNIX__) && !wxUSE_UNICODE
    // Dominic Mazzoni [[email protected]] reports that open is still broken on the mac, so we replace
    // int fd = open( szFileName , O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access);
    int fd = creat( szFileName , accessMode);
#else
    int fd = wxOpen( szFileName,
                     O_BINARY | O_WRONLY | O_CREAT |
                     (bOverwrite ? O_TRUNC : O_EXCL)
                     ACCESS(accessMode) );
#endif
    if ( fd == -1 )
    {
        wxLogSysError(_("can't create file '%s'"), szFileName);
        return false;
    }
    else
    {
        Attach(fd);
        return true;
    }
}
/** Begin Code emulation ********************************************************************/
void startFunction(FILE * logf, struct SCRIPT * script, 
				   struct TYPING * types, int funcindex, struct LINE * line){
	char * tokens = (char *) calloc(TOKENMAXNB*TOKENSIZE,sizeof(char));
	int parameters[10];
	char arguments[10][TOKENSIZE];
	int i, j, retobj, nbtokens, nbarg, nextparam, pos = 0;
	
	//Jump to function
	printf("[+] Jump inside function %s\n",
		script->functionslist[funcindex].name);
	//Merge parameters with local aliases from the signature
	nbarg = script->functionslist[funcindex].nbarg;
	nbtokens = decomposeLine(line->line,(char*)tokens,TOKENMAXNB,TOKENSIZE);
	for(i=0;i<nbtokens;i++){
		if(!strcasecmp(ACCESS(tokens,i),script->functionslist[funcindex].name)) break;
	}
	nextparam = i+1;
	for(j=1;j<=nbarg;j++){
		processExpression(logf,script,types,FUNCLEVEL|funcindex,
			              line,nextparam,0,arguments[j-1],&nextparam);
		parameters[j-1] = updateTypesBeforeLocCall(types, arguments[j-1], 
			              script->functionslist[funcindex].arguments[j-1]);
	}
	
	//Following the execution path
	while(pos<script->functionslist[funcindex].nblines){
		//Analyze code
		pos = processLines(logf,script,types,FUNCLEVEL|funcindex,pos);	
	}//while

	//Return from function
	printf("[+] Return from function %s\n",script->functionslist[funcindex].name);
	//Unmerge parameters with local aliases from the signature
	for(j=1;j<=nbarg;j++){
		removeObjectReference(types, parameters[j-1], 
			script->functionslist[funcindex].arguments[j-1]);
	}
	retobj = isKnownObject(types,script->functionslist[funcindex].name);
	if(retobj>-1){
		removeObjectReference(types,retobj,script->functionslist[funcindex].name);
		//If the return value is affected
		if(i>1 && ((char*)ACCESS(tokens,i-1))[0]== '='){
			addObjectReference(types,retobj,ACCESS(tokens,i-2));
		}//if affectation
	}
	free(tokens);
}
Esempio n. 17
0
int
main (int argc, char *argv[])
{
  int c;
  unsigned long start,end,inc,x;

  printf ("Data CPLB replacement Test\n\n");

    /* Check the passed arg */

  start = 0x4000;
  inc = 0x1000;
  end = 0x8000;

    while ((c = getopt (argc, argv, "vch?s:e:i:")) > 0)
     {
      switch (c)
      {
      case 'v':
        printf ("%s: version %s\n", argv[0], VERSION);
        exit (0);
      case 's':
        start = str2long(optarg, "s");
        break;
      case 'e':
        end = str2long(optarg, "e");
        break;
      case 'i':
        inc = str2long(optarg, "i");
        break;
      case 'h':
      case '?':
        usage (stdout, 0);
        break;
      default:
        fprintf (stderr, "ERROR: unkown option '%c'\n", c);
        usage (stderr, 1);
        break;
      }
     }

  printf ("Start:\t 0x%X\n",start);
  printf ("End:\t 0x%X\n",end);
  printf ("Incr:\t 0x%X\n\n",inc);

  if(start >= end ){
    usage (stdout, 0);
    return 0;
  }

  for(x=start; x<=end; x+=inc){
    ACCESS(x);
  }

  printf ("Test Success\n\n");
  system("cat /proc/cplbinfo");

exit (0);
}
Esempio n. 18
0
void jackpifm_outputter_sync() {
  void *pos = (void *)(ACCESS(DMABASE + 0x04 /* CurBlock*/) & ~ 0x7F);
  for (bufPtr = 0; bufPtr < BUFFERINSTRUCTIONS; bufPtr += 4)
    if (instrs[bufPtr].p == pos) return;

  // We should never get here
  abort();
}
Esempio n. 19
0
/************************************
Functon:    Lia_Fifo_UnInit
Description:  unlink fifo.If the fifo has
			been unlinked, return -1
Author: liujian
Date: 2015/09/04
Input: const Int8 * pi8Path £ºFIFO path name
Returns: 0 indicates success
			negative number indicates failure
************************************/
Int32 Lia_Fifo_UnInit(const Int8 * pi8Path)
{
	JUDGE_POINTER_IS_NULL(pi8Path);
	ACCESS(pi8Path,F_OK);//determines fifo if path exists
	unlink(pi8Path);

	return 0;
}
Esempio n. 20
0
static inline void
bench_iteration()
{
    const long line_size = bench_settings.line_size;

    for (long i = 0; i < bench_size; i += line_size)
        ACCESS(next_address());
}
Esempio n. 21
0
/**
 * Obtain the location of ".my.cnf".
 *
 * @param cfg our configuration
 * @param section the section
 * @return NULL on error
 */
static char *
get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
                 const char *section)
{
  char *cnffile;
  char *home_dir;
  struct stat st;

#ifndef WINDOWS
  struct passwd *pw;
#endif
  int configured;

#ifndef WINDOWS
  pw = getpwuid (getuid ());
  if (!pw)
  {
    GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_ERROR, "mysql", "getpwuid");
    return NULL;
  }
  if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, section, "CONFIG"))
  {
    GNUNET_assert (GNUNET_OK ==
                   GNUNET_CONFIGURATION_get_value_filename (cfg, section,
                                                            "CONFIG",
                                                            &cnffile));
    configured = GNUNET_YES;
  }
  else
  {
    home_dir = GNUNET_strdup (pw->pw_dir);
    GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
    GNUNET_free (home_dir);
    configured = GNUNET_NO;
  }
#else
  home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1);
  plibc_conv_to_win_path ("~/", home_dir);
  GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
  GNUNET_free (home_dir);
  configured = GNUNET_NO;
#endif
  GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql",
                   _("Trying to use file `%s' for MySQL configuration.\n"),
                   cnffile);
  if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) ||
      (!S_ISREG (st.st_mode)))
  {
    if (configured == GNUNET_YES)
      GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
                       _("Could not access file `%s': %s\n"), cnffile,
                       STRERROR (errno));
    GNUNET_free (cnffile);
    return NULL;
  }
  return cnffile;
}
Esempio n. 22
0
/***************************************************************************//**
 * Modifier function to set the region, region path and field name.
 * Fields must not be the same name as a child region.
 *
 * Examples:
 *   /heart/coordinates = region path and field name
 *   heart              = region path only
 *   coordinates        = field name only
 * @param region_path_and_name a struct Cmiss_region_path_and_name which if
 *   set contains an ACCESSed region and allocated path and name which caller
 *   is required to clean up. Name may be NULL if path is fully resolved.
 */
static int set_region_path_and_or_field_name(struct Parse_state *state,
	void *region_path_and_name_void, void *root_region_void)
{
	const char *current_token;
	int return_code;
	struct Cmiss_region_path_and_name *name_data;
	struct Cmiss_region *root_region;

	ENTER(set_region_path_and_or_field_name);
	if (state && (name_data = (struct Cmiss_region_path_and_name *)region_path_and_name_void) &&
		(root_region = (struct Cmiss_region *)root_region_void))
	{
		current_token = state->current_token;
		if (!current_token)
		{
			display_message(WARNING_MESSAGE, "Missing region path and/or field name");
			display_parse_state_location(state);
			return_code = 0;
		}
		else if (Parse_state_help_mode(state))
		{
			display_message(INFORMATION_MESSAGE, " REGION_PATH|REGION_PATH/FIELD_NAME|FIELD_NAME");
			return_code = 1;
		}
		else if (Cmiss_region_get_partial_region_path(root_region, current_token,
			&name_data->region, &name_data->region_path, &name_data->name))
		{
			ACCESS(Cmiss_region)(name_data->region);
			if (!name_data->name || (NULL == strchr(name_data->name, CMISS_REGION_PATH_SEPARATOR_CHAR)))
			{
				return_code = shift_Parse_state(state, 1);
			}
			else
			{
				display_message(ERROR_MESSAGE, "Bad region path and/or field name: %s",current_token);
				display_parse_state_location(state);
				return_code = 0;
			}
		}
		else
		{
			display_message(ERROR_MESSAGE,
				"set_region_path_and_or_field_name.  Failed to get path and name");
			return_code = 0;
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"set_region_path_and_or_field_name.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
}
Esempio n. 23
0
/*
 * Get access type for a gfn.
 * If gfn == INVALID_GFN, gets the default access type.
 */
static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn,
                               xenmem_access_t *access)
{
    p2m_type_t t;
    p2m_access_t a;
    mfn_t mfn;

    static const xenmem_access_t memaccess[] = {
#define ACCESS(ac) [p2m_access_##ac] = XENMEM_access_##ac
            ACCESS(n),
            ACCESS(r),
            ACCESS(w),
            ACCESS(rw),
            ACCESS(x),
            ACCESS(rx),
            ACCESS(wx),
            ACCESS(rwx),
            ACCESS(rx2rw),
            ACCESS(n2rwx),
#undef ACCESS
    };

    /* If request to get default access. */
    if ( gfn_eq(gfn, INVALID_GFN) )
    {
        *access = memaccess[p2m->default_access];
        return 0;
    }

    gfn_lock(p2m, gfn, 0);
    mfn = p2m->get_entry(p2m, gfn_x(gfn), &t, &a, 0, NULL, NULL);
    gfn_unlock(p2m, gfn, 0);

    if ( mfn_eq(mfn, INVALID_MFN) )
        return -ESRCH;

    if ( (unsigned int)a >= ARRAY_SIZE(memaccess) )
        return -ERANGE;

    *access =  memaccess[a];
    return 0;
}
Int32 main(Int32 argc, char **argv)
{

  _set_new_handler(mainNewHandler);

  // for NA_YOS newHandler_NSK needs to be added, once it is ready -- Sri gadde

  mxCompileUserModule mxCUM;
  mxCUMptr = &mxCUM;

  // process command line arguments
  Cmdline_Args args;
  args.processArgs(argc, argv);
  ApplicationFile *appFile=NULL;

  // check if application file exists
  if (ACCESS(args.application().c_str(), READABLE) != 0) {
    mxCUM << ERROR << DgSqlCode(-2223)
          << DgString0(args.application().c_str());
  }
  else {
    // ask factory to create an ELFFile or a SQLJFile
    appFile = ApplicationFile::makeApplicationFile(args.application());
    if (!appFile) { // no, it's not an application file
      mxCUM << ERROR << DgSqlCode(-2202)
            << DgString0(args.application().c_str());
    }
    else {
      // open the application file
      if (appFile->openFile(args)) {
        // process appFile's embedded module definitions
        std::string modName;
        while (appFile->findNextModule(modName)) {
          // extract embedded module definition & SQL compile it
          if (!appFile->processModule()) {
            mxCUM << WARNING << DgSqlCode(-2204) << DgString0(modName.c_str());
            // set mxCUM to WARNING at least. processModule may have set
            // it to WARNING, ERROR, or FAIL. If we get here, mxCUM
            // should never be set to SUCCEED.
          }
        }
        // close the application file
        appFile->closeFile();
        appFile->logErrors();
      }
    }
  }
  mxCUM.dumpDiags();
  if (appFile) {
    appFile->printSummary();
    delete appFile;
  }
  return mxCUM.returnCode();
}
Esempio n. 25
0
bool qt_file_access( const QString& fn, int t )
{
    if ( fn.isEmpty() )
	return FALSE;
#if defined(__CYGWIN32_)
    return ACCESS( QFile::encodeName(fn), t ) == 0;
#else
    QString str = fn;
    reslashify(str);
    return ( _waccess( (wchar_t*) str.ucs2(), t ) == 0 );
#endif
}
Esempio n. 26
0
// Open all external files and store the id
char AH5_open_external_files(AH5_eet_dataset_t *eet_dataset)
{
  char success = AH5_TRUE;
  hid_t file_id;
  hid_t *buf_id;
  AH5_set_t buf;
  hsize_t i;
  char const* name;
  hsize_t id = 0;
  size_t fpath_size;
  char* fpath;

  AH5_init_set(&buf);
  buf_id = malloc(eet_dataset->nb_eed_items * sizeof(hid_t));  // temporary buffer containing file_id
  for (i = 0; i < eet_dataset->nb_eed_items; ++i)
  {
    name = eet_dataset->eed_items[AH5_EE_EXTERNAL_FILE_NAME(i)]; // copy of the pointer (shorter expression)

    if (AH5_index_in_set(&buf, name, &id) == AH5_FALSE)  // avoid multiple opening
    {

      fpath_size = AH5_file_path_next_to(eet_dataset->principle_file_path, name, NULL, 0);
      fpath = malloc(fpath_size);
      AH5_file_path_next_to(eet_dataset->principle_file_path, name, fpath, fpath_size);
      if (ACCESS(fpath, F_OK | R_OK) != -1)
      {
        file_id = H5Fopen(fpath, H5F_ACC_RDONLY, H5P_DEFAULT);
      }
      else
      {
        file_id = -1;
      }
      free(fpath);
      AH5_add_to_set(&buf, name);
      buf_id[buf.nb_values - 1] = file_id;
      eet_dataset->file_id[i] = file_id;  // write new file_id into the ext_elt structure
      if (file_id < 0)
      {
        printf("***** ERROR(%s): Cannot open file \"%s\". *****\n\n", AH5_C_EXTERNAL_ELEMENT, name);
        success = AH5_FALSE;
      }
    }
    else
    {
      eet_dataset->file_id[i] = buf_id[id];  // write existing file_id into the ext_elt structure
    }
  }

  AH5_free_set(&buf);
  free(buf_id);
  return success;
}
Transmitter::Transmitter(double frequency)
{
    int memFd;
    if ((memFd = open("/dev/mem", O_RDWR | O_SYNC)) < 0) {
        std::cout << "Error: sudo privileges are required" << std::endl;
        throw std::exception();
    }

    void *peripheralsMap = mmap(NULL, 0x002FFFFF, PROT_READ | PROT_WRITE, MAP_SHARED, memFd, 0x3F000000);
    close(memFd);
    if (peripheralsMap == MAP_FAILED) {
        std::cout << "Error: cannot obtain access to peripherals (mmap error)" << std::endl;
        throw std::exception();
    }

    peripherals = (volatile unsigned*)peripheralsMap;

    ACCESS(peripherals, 0x00200000) = (ACCESS(peripherals, 0x00200000) & 0xFFFF8FFF) | (0x01 << 14);
    ACCESS(peripherals, 0x00101070) = (0x5A << 24) | (0x01 << 9) | (0x01 << 4) | 0x06;

    clockDivisor = (unsigned int)((500 << 12) / frequency + 0.5);
}
Esempio n. 28
0
// open the file
bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode)
{
    int flags = O_BINARY;

    switch ( mode )
    {
        case read:
            flags |= O_RDONLY;
            break;

        case write_append:
            if ( wxFile::Exists(szFileName) )
            {
                flags |= O_WRONLY | O_APPEND;
                break;
            }
            //else: fall through as write_append is the same as write if the
            //      file doesn't exist

        case write:
            flags |= O_WRONLY | O_CREAT | O_TRUNC;
            break;

        case write_excl:
            flags |= O_WRONLY | O_CREAT | O_EXCL;
            break;

        case read_write:
            flags |= O_RDWR;
            break;
    }

#ifdef __WINDOWS__
    // only read/write bits for "all" are supported by this function under
    // Windows, and VC++ 8 returns EINVAL if any other bits are used in
    // accessMode, so clear them as they have at best no effect anyhow
    accessMode &= wxS_IRUSR | wxS_IWUSR;
#endif // __WINDOWS__

    int fd = wxOpen( szFileName, flags ACCESS(accessMode));

    if ( fd == -1 )
    {
        wxLogSysError(_("can't open file '%s'"), szFileName);
        return false;
    }
    else {
        Attach(fd);
        return true;
    }
}
int processLoop(FILE * logf, struct SCRIPT * script, struct TYPING * types,
			    unsigned long location, int lineindex, int statement){
	struct LINE * nextline;
	char * tokens = (char *) calloc(TOKENMAXNB*TOKENSIZE,sizeof(char));
	char endtoken[5];
	int nbtokens, maxpos, pos;

	endtoken[0] = 0;
	//for to or for each...next statement
	switch(statement){
		case 1:
			printf(" for to/each case\n");
			strcat_s(endtoken,5,"next");
			break;
		case 2:
			printf(" do while/until case\n");
			strcat_s(endtoken,5,"loop");
			break;
		case 3:
			printf(" while case\n");
			strcat_s(endtoken,5,"wend");
	}//switch
	printLogEntry(logf, types, L_LOOP, 0, 0);

	//Process the line for calls into the statement
	processLine(logf,script,types,location,
		        accessLine(script,location,lineindex));

	//Blocks on new lines, parse following ones
	pos = lineindex+1;
	maxpos = recoverMaximalPosition(script,location);
	while(pos<maxpos){
		nextline = accessLine(script,location,pos);
		if(nextline->type==COMMENT){pos++; continue;}		//skip comment
		if(nextline->type==MANAGER){pos++; continue;}		//skip manager declaration
		if(nextline->type==DECLARATION){pos++; continue;}	//(declaration may require variable typing)....
		if(nextline->type==MARKUP){pos++; continue;}
		nbtokens = decomposeLine(nextline->line,(char*)tokens,TOKENMAXNB,TOKENSIZE);
		//Loop structure
		if(!strncasecmp(ACCESS(tokens,0),endtoken,4)){
			printf("[+] End of loop statement\n");
			printLogEntry(logf, types, R_LOOP, 0, 0);
			return pos+1;
		}else{
			pos = processLines(logf,script,types,location,pos);
		}
	}//while
	free(tokens);
	return pos;
}
Esempio n. 30
0
void jackpifm_outputter_output(const jackpifm_sample_t *data, size_t size) {
  for (size_t i = 0; i < size; i++) {
    float value = data[i];
    value *= 8;          // modulation index (AKA volume!)
    value += fracerror;  // error that couldn't be encoded from last time.

    int intval = (int)(round(value));  // integer component
    float frac = (value - (float)intval + 1)/2;
    unsigned int fracval = round(frac*clocksPerSample); // the fractional component

    // we also record time error so that if one sample is output
    // for slightly too long, the next sample will be shorter.
    timeErr = timeErr - (int)(timeErr) + clocksPerSample;

    fracerror = (frac - (float)fracval*(1.0-2.3/clocksPerSample)/clocksPerSample)*2;  // error to feed back for delta sigma

    // Note, the 2.3 constant is because our PWM isn't perfect.
    // There is a finite time for the DMA controller to load a new value from memory,
    // Therefore the width of each pulse we try to insert has a constant added to it.
    // That constant is about 2.3 bytes written to the serializer, or about 18 cycles.  We use delta sigma
    // to correct for this error and the pwm timing quantization error.

    // To reduce noise, rather than just rounding to the nearest clock we can use, we PWM between
    // the two nearest values.

    // delay if necessary.  We can also print debug stuff here while not breaking timing.
    static int time;
    time++;

    while( (ACCESS(DMABASE + 0x04 /* CurBlock*/) & ~ 0x7F) ==  (int)(instrs[bufPtr].p)) {
      nanosleep(&sleeptime, NULL);  // are we anywhere in the next 4 instructions?
    }

    // Create DMA command to set clock controller to output FM signal for PWM "LOW" time.
    ((struct CB*)(instrs[bufPtr].v))->SOURCE_AD = (int)constPage.p + 2048 + intval*4 - 4 ;
    bufPtr++;

    // Create DMA command to delay using serializer module for suitable time.
    ((struct CB*)(instrs[bufPtr].v))->TXFR_LEN = (int)timeErr-fracval;
    bufPtr++;

    // Create DMA command to set clock controller to output FM signal for PWM "HIGH" time.
    ((struct CB*)(instrs[bufPtr].v))->SOURCE_AD = (int)constPage.p + 2048 + intval*4 + 4;
    bufPtr++;

    // Create DMA command for more delay.
    ((struct CB*)(instrs[bufPtr].v))->TXFR_LEN = fracval;
    bufPtr=(bufPtr+1) % (BUFFERINSTRUCTIONS);
  }
}