Example #1
0
/**
 * Read response from card.
 * @todo Implement Auto-CMD responses being held in R3 for multi-block xfers.
 * @param sc
 */
static void
get_response(struct fsl_sdhc_softc *sc)
{
	struct mmc_command *cmd = sc->request->cmd;
	int i;
	uint32_t val;
	uint8_t ext = 0;

	if (cmd->flags & MMC_RSP_136) {
		/* CRC is stripped, need to shift one byte left. */
		for (i = 0; i < 4; i++) {
			val = read4(sc, SDHC_CMDRSP0 + i * 4);
			cmd->resp[3 - i] = (val << 8) + ext;
			ext = val >> 24;
		}
	} else {
static void read_proc_kallsyms(void)
{
	unsigned int size;
	char *buf;

	size = read4();
	if (!size)
		return;

	buf = malloc_or_die(size);
	read_or_die(buf, size);

	parse_proc_kallsyms(buf, size);

	free(buf);
}
Example #3
0
static void
reset_controller_all(struct fsl_sdhc_softc *sc)
{
	uint32_t count = 5;

	set_bit(sc, SDHC_SYSCTL, SYSCTL_RSTA);
	while (read4(sc, SDHC_SYSCTL) & SYSCTL_RSTA) {
		DELAY(FSL_SDHC_RESET_DELAY);
		--count;
		if (count == 0) {
			device_printf(sc->self,
			    "Can't reset the controller\n");
			return;
		}
	}
}
 int read(char *buf, int n) {
     int i = 0, offset = 0;
     if(ptr < end){
         offset = min(n, end - ptr);
         memcpy(buf, sb + ptr, offset);
         i += offset, ptr += offset;
     }
     while(i < n && end == 4){
         ptr = 0;
         end = read4(sb);
         memcpy(buf + i, sb, end);
         offset = min(n - i, end);
         i += offset, ptr += offset;
     }
     return i;
 }
static int read_ftrace_files(struct tep_handle *pevent)
{
	unsigned long long size;
	int count;
	int i;
	int ret;

	count = read4(pevent);

	for (i = 0; i < count; i++) {
		size = read8(pevent);
		ret = read_ftrace_file(pevent, size);
		if (ret)
			return ret;
	}
	return 0;
}
Example #6
0
  int read(char *buf, int n){
    int res = 0;
    while(res < n){
      char[] tmp = new char[4];
      int k = read4(tmp);
      for(int i = 0; i < k && res < n; i++){
        buf[res++] = tmp[i]; // res++
      }

      if(k < 4){ // end of file
        return res;
      }
    }
    return res;

    
  }
 /**
  * @param buf Destination buffer
  * @param n   Maximum number of characters to read
  * @return    The number of characters read
  */
 int read(char *buf, int n) {
     int bufptr=0;
     while (n) {
         if (available) {
             buf[bufptr++] = readBuf[rbptr];
             rbptr = (rbptr+1) % 4;
             available--;
             n--;
             continue;
         } else {
             available = read4(readBuf);
             rbptr=0;
             if (available == 0) return bufptr;
             continue;
         }
     }
     return bufptr;
 }
int readII(char * buf, int n)
{
	if(!buf) return 0;
	int count = 0;
	while(count < n)
	{
		if(p4 == n4)  // last time we reached an end
		{
			n4 = read4(buf4);
			p4 = 0;
			if(p4 > n4) break;    // a corner case here if read4 return ""
		}
		while(count < n && p4 < n4)
		{
			buf[count++] = buf4[p4++];
		}
	}
	return count;
}
Example #9
0
struct octet_buffer get_config_zone (fd)
{
  const unsigned int SIZE_OF_CONFIG_ZONE = 88;
  const unsigned int NUM_OF_WORDS = SIZE_OF_CONFIG_ZONE / 4;

  struct octet_buffer buf = make_buffer (SIZE_OF_CONFIG_ZONE);
  uint8_t *write_loc = buf.ptr;

  unsigned int addr = 0;
  unsigned int word = 0;

  while (word < NUM_OF_WORDS)
    {
      addr = word * 4;
      read4 (fd, CONFIG_ZONE, word, (uint32_t*)(write_loc+addr));
      word++;
    }

  return buf;
}
Example #10
0
uint8_t* decodeLZMA(uint8_t* in, unsigned inSize, unsigned* uncompressedSizeOut)
{
  const unsigned PropHeaderSize = 5;
  const unsigned HeaderSize = 13;

  int32_t outSize = read4(in + PropHeaderSize);
  SizeT outSizeT = outSize;

  uint8_t* out = static_cast<uint8_t*>(malloc(outSize));

  SizeT inSizeT = inSize;

  ELzmaStatus status;
  int result = LzmaDecode(out, &outSizeT, in + HeaderSize, &inSizeT, in, PropHeaderSize,
     LZMA_FINISH_END, &status, &g_Alloc);

  //expect(s, status == LZMA_STATUS_FINISHED_WITH_MARK);
  *uncompressedSizeOut = outSize;
  return out;
}
 // The read1 implementation is from the `Read N Characters Given Read4` problem
 // Add the feature - write the extra char(s) into RingBuffer
 int read1(char *buf, int n) {
     char _buf[4];   // the buffer for read4()
     int _n = 0;     // the return for read4()
     int len = 0;    // total buffer read from read4()
     int size = 0;   // how many bytes need be copied from `_buf` to `buf`
     while((_n = read4(_buf)) > 0){
         //check the space of `buf` whether full or not
         size = len + _n > n ? n-len : _n;
         //write the extra char(s) into RingBuffer
         if (len + _n > n ){
             _ring_buffer.write(_buf + size, _n - size);    
         }
         strncpy(buf+len, _buf, size);
         len += size;
         //buffer is full
         if (len>=n){
             break;
         }
     }
     return len;
 }
    int read(char *buf, int n) {
        if (n <= 0) return n; int idx = 0;
        
        while (remaining > 0 && idx < n) {
            buf[idx++] = cache[curp++]; 
            --remaining; // If we have some data left lets read that
            if(curp ==4) curp = 0;
        }
        
        while (true)
        {
            if (idx >= n) return idx;
            remaining = read4(cache);
            if (remaining == 0) return idx;

            while (remaining && idx < n) { // populate our buffer given we have bytes to read
                buf[idx++] = cache[curp++]; 
                --remaining;
                if(curp ==4) curp = 0;
            }
        }
    }
Example #13
0
static int read_proc_kallsyms(struct tep_handle *pevent)
{
	unsigned int size;

	size = read4(pevent);
	if (!size)
		return 0;
	/*
	 * Just skip it, now that we configure libtraceevent to use the
	 * tools/perf/ symbol resolver.
	 *
	 * We need to skip it so that we can continue parsing old perf.data
	 * files, that contains this /proc/kallsyms payload.
	 *
	 * Newer perf.data files will have just the 4-bytes zeros "kallsyms
	 * payload", so that older tools can continue reading it and interpret
	 * it as "no kallsyms payload is present".
	 */
	lseek(input_fd, size, SEEK_CUR);
	trace_data_size += size;
	return 0;
}
static void read_ftrace_printk(void)
{
	unsigned int size;
#else
static void read_ftrace_;
#endif
	char *buf;

	size = read4();
	if (!size)
		return;

	buf = malloc_or_die(size);
	read_or_die(buf, size);

#ifdef CONFIG_DEBUG_PRINTK
	parse_ftrace_printk(buf, size);
#else
	parse_ftrace_;
#endif

	free(buf);
}
static int read_ftrace_printk(struct pevent *pevent)
{
	unsigned int size;
	char *buf;

	/* it can have 0 size */
	size = read4(pevent);
	if (!size)
		return 0;

	buf = malloc(size);
	if (buf == NULL)
		return -1;

	if (do_read(buf, size) < 0) {
		free(buf);
		return -1;
	}

	parse_ftrace_printk(pevent, buf, size);

	free(buf);
	return 0;
}
static int read_proc_kallsyms(struct pevent *pevent)
{
	unsigned int size;
	char *buf;

	size = read4(pevent);
	if (!size)
		return 0;

	buf = malloc(size + 1);
	if (buf == NULL)
		return -1;

	if (do_read(buf, size) < 0) {
		free(buf);
		return -1;
	}
	buf[size] = '\0';

	parse_proc_kallsyms(pevent, buf, size);

	free(buf);
	return 0;
}
Example #17
0
uint8_t* decodeLZMA(System* s,
                    avian::util::Alloc* a,
                    uint8_t* in,
                    unsigned inSize,
                    unsigned* outSize)
{
  const unsigned PropHeaderSize = 5;
  const unsigned HeaderSize = 13;

  int32_t outSize32 = read4(in + PropHeaderSize);
  expect(s, outSize32 >= 0);
  SizeT outSizeT = outSize32;

  uint8_t* out = static_cast<uint8_t*>(a->allocate(outSize32));

  SizeT inSizeT = inSize;
  LzmaAllocator allocator(a);

  ELzmaStatus status;
  int result = LzmaDecode(out,
                          &outSizeT,
                          in + HeaderSize,
                          &inSizeT,
                          in,
                          PropHeaderSize,
                          LZMA_FINISH_END,
                          &status,
                          &(allocator.allocator));

  expect(s, result == SZ_OK);
  expect(s, status == LZMA_STATUS_FINISHED_WITH_MARK);

  *outSize = outSize32;

  return out;
}
Example #18
0
bool is_locked (int fd, enum DATA_ZONE zone)
{
  uint32_t buf = 0;
  const uint8_t config_addr = 0x15;
  uint8_t *ptr = (uint8_t *)&buf;
  const uint8_t UNLOCKED = 0x55;
  bool result = true;
  const unsigned int CONFIG_ZONE_OFFSET = 3;
  const unsigned int DATA_ZONE_OFFSET = 2;
  unsigned int offset = 0;

  switch (zone)
    {
    case CONFIG_ZONE:
      offset = CONFIG_ZONE_OFFSET;
      break;
    case DATA_ZONE:
    case OTP_ZONE:
      offset = DATA_ZONE_OFFSET;
      break;
    default:
      assert (false);

    }

  if (read4 (fd, CONFIG_ZONE, config_addr, &buf))
    {
      ptr = ptr + offset;
      if (UNLOCKED == *ptr)
        result = false;
      else
        result = true;
    }

  return result;
}
Example #19
0
File: File.cpp Project: LuaAV/LuaAV
void DataFile::read4(void * dst, ULONG len){
	UI4 * d = (UI4 *)dst;
	for(ULONG i=0; i<len; i++) read4(d + i);
}
Example #20
0
TVerdict CTestSyscalls::doTestStepL()
	{
	int err;
	if(TestStepName() == KCreat)
   		{
   		INFO_PRINTF1(_L("Creat():"));
   		err = Creat();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kopen1)
		{
		INFO_PRINTF1(_L("open1():"));
		err = open1();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
   	   	
	else if(TestStepName() == Kopen2)
		{
		INFO_PRINTF1(_L("open2():"));
		err = open2();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen3)
		{
		INFO_PRINTF1(_L("open3():"));
		err = open3();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen4)
		{
		INFO_PRINTF1(_L("open4():"));
		err = open4();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen5)
		{
		INFO_PRINTF1(_L("open5():"));
		err = open5();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen6)
		{
		INFO_PRINTF1(_L("open6():"));
		err = open6();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpenTruncate1)
		{
		INFO_PRINTF1(_L("OpenTruncate1:"));
		err = OpenTruncate1();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpenTruncate2)
		{
		INFO_PRINTF1(_L("OpenTruncate2:"));
		err = OpenTruncate2();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen7)
   		{
   		INFO_PRINTF1(_L("open7():"));
   		err = open7();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpenInAppendMode)
   		{
   		INFO_PRINTF1(_L("OpenInAppendMode():"));
   		err = OpenInAppendMode();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kwrite1)
		{
   		INFO_PRINTF1(_L("write1():"));
		err = write1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kwrite2)
   		{
   		INFO_PRINTF1(_L("write2():"));
   		err = write2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kwrite3)
   		{
   		INFO_PRINTF1(_L("write3():"));
   		err = write3();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kwrite5)
		{
   		INFO_PRINTF1(_L("write5():"));
   		err = write5();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread1)
   		{
   		INFO_PRINTF1(_L("read1():"));
   		err = read1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread2)
   		{
		INFO_PRINTF1(_L("read2():"));
   		err = read2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread3)
   		{
		INFO_PRINTF1(_L("read3():"));
   		err = read3();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread4)
		{
		INFO_PRINTF1(_L("read4():"));
		err = read4();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == KOpendir)
   		{
   	   	INFO_PRINTF1(_L("Opendir():"));
   	   	err = Opendir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KClosedir)
   		{
   	   	INFO_PRINTF1(_L("Closedir():"));
   	   	err = Closedir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KReaddir)
   		{
   	   	INFO_PRINTF1(_L("Readdir():"));
   	   	err = Readdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KLseek)
   		{
   	   	INFO_PRINTF1(_L("Lseek():"));
   	   	err = Lseek();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KLseek1)
   		{
   	   	INFO_PRINTF1(_L("Lseek1():"));
   	   	err = Lseek1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
    else if(TestStepName() == KAccess)
   		{
   	   	INFO_PRINTF1(_L("Access():"));
   	   	err = Access();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KAccess1)
   		{
   	   	INFO_PRINTF1(_L("Access1():"));
   	   	err = Access1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KDup)
   		{
   	   	INFO_PRINTF1(_L("Dup():"));
   	   	err = Dup();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KDup2)
   		{
   	   	INFO_PRINTF1(_L("Dup2():"));
   	   	err = Dup2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename)
   		{
   	   	INFO_PRINTF1(_L("Rename():"));
   	   	err = Rename();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename1)
   		{
   	   	INFO_PRINTF1(_L("Rename1():"));
   	   	err = Rename1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChmod)
   		{
   	   	INFO_PRINTF1(_L("Chmod():"));
   	   	err = Chmod();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChmod1)
   		{
   	   	INFO_PRINTF1(_L("Chmod1():"));
   	   	err = Chmod1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
    else if(TestStepName() == KChmod_dir)
   		{
   	   	INFO_PRINTF1(_L("Chmod_dir():"));
   	   	err = Chmod_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFChmod)
   		{
   	   	INFO_PRINTF1(_L("FChmod():"));
   	   	err = FChmod();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFChmod_dir)
   		{
   	   	INFO_PRINTF1(_L("FChmod_dir():"));
   	   	err = FChmod_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KExit)
   		{
   	   	INFO_PRINTF1(_L("Exit():"));
   	   	err = Exit();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KClose)
   		{
   	   	INFO_PRINTF1(_L("Close():"));
   	   	err = Close();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KMkdir)
   		{
   	   	INFO_PRINTF1(_L("Mkdir():"));
   	   	err = Mkdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KMk_dir)
   		{
   	   	INFO_PRINTF1(_L("Mk_dir():"));
   	   	err = Mk_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KRmdir)
   		{
   	   	INFO_PRINTF1(_L("Rmdir():"));
   	   	err = Rmdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KRm_dir)
   		{
   	   	INFO_PRINTF1(_L("Rm_dir():"));
   	   	err = Rm_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
    else if(TestStepName() == KRmdir1)
   		{
   	   	INFO_PRINTF1(_L("Rmdir1():"));
   	   	err = Rmdir1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRmdir_Chdir)
   		{
   	   	INFO_PRINTF1(_L("Rmdir_Chdir():"));
   	   	err = Rmdir_Chdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFsync)
   		{
   	   	INFO_PRINTF1(_L("Fsync():"));
   	   	err = Fsync();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KUtimes)
   		{
   	   	INFO_PRINTF1(_L("Utimes():"));
   	   	err = Utimes();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
   	else if(TestStepName() == KUtime)
   		{
   	   	INFO_PRINTF1(_L("Utime():"));
   	   	err = Utime();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChdir)
   		{
   	   	INFO_PRINTF1(_L("Chdir():"));
   	   	err = Chdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFcntl)
   		{
   	   	INFO_PRINTF1(_L("Fcntl():"));
   	   	err = Fcntl();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KIoctl)
   		{
   	   	INFO_PRINTF1(_L("Ioctl():"));
   	   	err = Ioctl();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFstat)
   		{
   	   	INFO_PRINTF1(_L("Fstat():"));
   	   	err = Fstat();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KStat)
   		{
   	   	INFO_PRINTF1(_L("Stat():"));
   	   	err = Stat();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KStat1)
   		{
   	   	INFO_PRINTF1(_L("Stat1():"));
   	   	err = Stat1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KStat2)
   		{
   	   	INFO_PRINTF1(_L("Stat2():"));
   	   	err = Stat2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KStat3)
   		{
   	   	INFO_PRINTF1(_L("Stat3():"));
   	   	err = Stat3();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KGetpid)
   		{
   	   	INFO_PRINTF1(_L("Getpid():"));
   	   	err = Getpid();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KClock)
   		{
   	   	INFO_PRINTF1(_L("Clock():"));
   	   	err = Clock();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KTime)
   		{
   	   	INFO_PRINTF1(_L("Time():"));
   	   	err = Time();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KWaitPid)
   		{
   	   	INFO_PRINTF1(_L("WaitPid():"));
   	   	err = WaitPid();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KReadV)
   		{
   	   	INFO_PRINTF1(_L("ReadV():"));
   	   	err = ReadV();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KWriteV)
   		{
   	   	INFO_PRINTF1(_L("WriteV():"));
   	   	err = WriteV();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KSleep)
   		{
   	   	INFO_PRINTF1(_L("Sleep():"));
   	   	err = Sleep();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KSeekDir)
   		{
   	   	INFO_PRINTF1(_L("SeekDir():"));
   	   	err = SeekDir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRewindDir)
   		{
   	   	INFO_PRINTF1(_L("RewindDir():"));
   	   	err = RewindDir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KTelldir)
   		{
   	   	INFO_PRINTF1(_L("Telldir():"));
   	   	err = Telldir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KTestClock)
   		{
   	   	INFO_PRINTF1(_L("TestClock():"));
   	   	err = TestClock();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KCreat2)
   		{
   		INFO_PRINTF1(_L("Creat2():"));
   		err = Creat2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
   	else if(TestStepName() == Kopen8)
   		{
   		INFO_PRINTF1(_L("open8():"));
   		err = open8();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
   	else if(TestStepName() == KTestStat)
   		{
   		INFO_PRINTF1(_L("KTestStat():"));
   		err = TestStat();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KLseekttytest1)
   		{
   		INFO_PRINTF1(_L("Lseekttytest1():"));
   		err = Lseekttytest1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KLseekttytest2)
   		{
   		INFO_PRINTF1(_L("Lseekttytest2():"));
   		err = Lseekttytest2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KWaitPidtest)
   		{
   		INFO_PRINTF1(_L("WaitPidtest():"));
   		err = WaitPidtest();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KWaittest)
   		{
   		INFO_PRINTF1(_L("Waittest():"));
   		err = Waittest();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpen_FileDes_Test)
   		{
   		INFO_PRINTF1(_L("Open_FileDes_Test():"));
   		err = Open_FileDes_Test();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopenuid)
   		{
   		INFO_PRINTF1(_L("openuid():"));
   		err = openuid();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KMkdir1)
   		{
   	   	INFO_PRINTF1(_L("Mkdir1():"));
   	   	err = Mkdir1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KMkdir2)
   		{
   	   	INFO_PRINTF1(_L("Mkdir2():"));
   	   	err = Mkdir2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KRename2)
   		{
   	   	INFO_PRINTF1(_L("Rename2():"));
   	   	err = Rename2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == Ktestfsync)
   		{
   		INFO_PRINTF1(_L("testfsync():"));
   		err = testfsync();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Ktestrename)
   		{
   		INFO_PRINTF1(_L("testrename():"));
   		err = testrename();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Ktestopenvalidate)
   		{
   		INFO_PRINTF1(_L("testopenvalidate():"));
   		err = testopenvalidate();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Ksync_safe)
   		{
   		INFO_PRINTF1(_L("sync_safe():"));
   		err = sync_safe();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
   	else if(TestStepName() == KFstat1)
   		{
   	   	INFO_PRINTF1(_L("Fstat1():"));
   	   	err = Fstat1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KUtimes1)
   		{
   	   	INFO_PRINTF1(_L("Utimes1():"));
   	   	err = Utimes1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KMkdir_test1)
   		{
   	   	INFO_PRINTF1(_L("Mkdir_test1():"));
   	   	err = Mkdir_test1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChmod_test)
   		{
   	   	INFO_PRINTF1(_L("Chmod_test():"));
   	   	err = Chmod_test();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KChdir1)
   		{
   	   	INFO_PRINTF1(_L("Chdir1():"));
   	   	err = Chdir1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}   
   	else if(TestStepName() == KRmdir2)
   		{
   	   	INFO_PRINTF1(_L("Rmdir2():"));
   	   	err = Rmdir2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename_test)
   		{
   	   	INFO_PRINTF1(_L("Rename_test():"));
   	   	err = Rename_test();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename3)
   		{
   	   	INFO_PRINTF1(_L("Rename3():"));
   	   	err = Rename3();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KCreat1)
   		{
   		INFO_PRINTF1(_L("Creat1():"));
   		err = Creat1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
   	else if(TestStepName() == KReadV1)
   		{
   	   	INFO_PRINTF1(_L("ReadV1():"));
   	   	err = ReadV1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
 	else if(TestStepName() == KUtimes2)
    		{
    	   	INFO_PRINTF1(_L("Utimes2():"));
    	   	err = Utimes2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
 		}
 	else if(TestStepName() == KStat_test)
    		{
    	   	INFO_PRINTF1(_L("Stat_test():"));
    	   	err = Stat_test();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
    	else if(TestStepName() == KMkdir_test2)
    		{
    	   	INFO_PRINTF1(_L("Mkdir_test2():"));
    	   	err = Mkdir_test2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
    	else if(TestStepName() == KChmod2)
    		{
    	   	INFO_PRINTF1(_L("Chmod2():"));
    	   	err = Chmod2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
    	else if(TestStepName() == KChdir2)
    		{
    	   	INFO_PRINTF1(_L("Chdir2():"));
    	   	err = Chdir2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	} 
    	else if(TestStepName() == KRename4)
    		{
    	   	INFO_PRINTF1(_L("Rename4():"));
    	   	err = Rename4();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
 	else if(TestStepName() == KRename5)
    		{
    	   	INFO_PRINTF1(_L("Rename5():"));
    	   	err = Rename5();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}  
 	else if(TestStepName() == KRmdir3)
    		{
    	   	INFO_PRINTF1(_L("Rmdir3():"));
    	   	err = Rmdir3();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}  
    	else if(TestStepName() == Kread5)
 		{
 		INFO_PRINTF1(_L("read5():"));
 		err = read5();
    		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    		} 	   	 
	return TestStepResult(); 
	}
Example #21
0
static void syscall_handler(struct intr_frame *f) {
    
    int status;
    const char *cmdline, *f_name;
    unsigned f_size, position, size;
    uint32_t fd;
    mapid_t mapping;
    struct supp_table *st;
    struct thread* t = thread_current();

    /* Retrieve syscall number */
    uint32_t sys_no = read4(f, 0);
    
    void *buffer; 
    pid_t pid;
    
    /* The following is for page fault in syscall.
     * Set the thread's syscall status as true.
     * Store the current esp in the thread's esp field */
    t->syscall = true;
    t->esp = f->esp;

    /* Note after each syscall is about to finish, we will
     * set the thread's syscall status back to false. */
    switch (sys_no) {
        case SYS_HALT:
            halt();
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_EXIT:
            status = (int) read4(f, 4);
            exit(status);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_EXEC:
            cmdline = (const char*) read4(f, 4);
            f->eax = (uint32_t) exec(cmdline);
            break;
            
        case SYS_WAIT:
            pid = (pid_t) read4(f, 4);
            f->eax = (uint32_t) wait(pid);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_CREATE:
            f_name = (const char*) read4(f, 4);
            f_size = (unsigned) read4(f, 8);
            f->eax = (uint32_t) create(f_name, f_size);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_REMOVE:
            f_name = (const char*) read4(f, 4);
            f->eax = (uint32_t) remove(f_name);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_OPEN:
            f_name = (const char*) read4(f, 4);
            f->eax = (uint32_t) open(f_name);
            break;
            
        case SYS_FILESIZE:
            fd = (uint32_t) read4(f, 4);
            f->eax = (uint32_t) filesize(fd);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_READ:
            fd = (uint32_t) read4(f, 4);
            buffer = (void*) read4(f, 8);
            size = (unsigned) read4(f, 12);
            f->eax = (uint32_t) read(fd, buffer, size);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_WRITE:
            fd = (uint32_t) read4(f, 4);
            buffer = (void*) read4(f, 8);
            size = (unsigned) read4(f, 12);
            f->eax = (uint32_t) write(fd, buffer, size);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_SEEK:
            fd = (uint32_t) read4(f, 4);
            position = (unsigned) read4(f, 8);
            seek(fd, position);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_TELL:
            fd = (uint32_t) read4(f, 4);
            f->eax = (uint32_t) tell(fd);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_CLOSE:
            fd = (uint32_t) read4(f, 4);
            close(fd);
            t->syscall = false;
            t->esp = NULL;
            break;

        case SYS_MMAP:
            fd = (uint32_t) read4(f, 4);
            buffer = (void*) read4(f, 8);
            f->eax = (uint32_t) mmap(fd, buffer);
            t->syscall = false;
            t->esp = NULL;
            break;

        case SYS_MUNMAP:
            mapping = (mapid_t) read4(f, 4);
            munmap(mapping);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_ISDIR:
            fd = (uint32_t) read4(f, 4);
            f->eax = (uint32_t) _isdir(fd);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_INUMBER:
            fd = (uint32_t) read4(f,4);
            f->eax = (uint32_t) _inumber(fd);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_CHDIR:
            f_name = (const char*) read4(f,4);
            f->eax = (uint32_t) _chdir(f_name);
            t->syscall = false;
            t->esp = NULL;
            break;
            
        case SYS_MKDIR:
            f_name = (const char*) read4(f,4);
            f->eax = (uint32_t) _mkdir(f_name);
            t->syscall = false;
            t->esp = NULL;
            break;
        
        case SYS_READDIR:
            fd = (uint32_t) read4(f,4);
            f_name = (char*) read4(f, 8);
            f->eax = (uint32_t) _readdir(fd, f_name);
            t->syscall = false;
            t->esp = NULL;
            break;

        default:
            exit(-1);
            t->syscall = false;
            t->esp = NULL;
            break;
    }
    
}
Example #22
0
 inline float readFloat() { float c=0.0f; read4((char*)&c); return c; }
Example #23
0
 /**
  * @param buf Destination buffer
  * @param n   Maximum number of characters to read
  * @return    The number of characters read
  */
 int read(char *buf, int n) {
     int i = 0;
     while (i < n && (i4 < n4 || (i4 = 0) < (n4 = read4(buf4))))
         buf[i++] = buf4[i4++];
     return i;
 }
Example #24
0
 inline unsigned int readUInt() { unsigned int c=0; read4((char*)&c); return c; }
Example #25
0
 inline int readInt() { int c=0; read4((char*)&c); return c; }
Example #26
0
get_response(struct fsl_sdhc_softc *sc)
{
	struct mmc_command *cmd = sc->request->cmd;
	int i;
	uint32_t val;
	uint8_t ext = 0;

	if (cmd->flags & MMC_RSP_136) {
		/* CRC is stripped, need to shift one byte left. */
		for (i = 0; i < 4; i++) {
			val = read4(sc, SDHC_CMDRSP0 + i * 4);
			cmd->resp[3 - i] = (val << 8) + ext;
			ext = val >> 24;
		}
	} else {
		cmd->resp[0] = read4(sc, SDHC_CMDRSP0);
	}
}

#ifdef FSL_SDHC_NO_DMA
/**
 * Read all content of a fifo buffer.
 * @warning Assumes data buffer is 32-bit aligned.
 * @param sc
 */
static void
read_block_pio(struct fsl_sdhc_softc *sc)
{
	struct mmc_data *data = sc->request->cmd->data;
	size_t left = min(FSL_SDHC_FIFO_BUF_SIZE, data->len);
	uint8_t *buf = data->data;
Example #27
0
int MpoParser::parseFile(const wchar_t *path)
{
	static const unsigned short MARKER_SOI = 0xFFD8;
	static const unsigned short MARKER_APP1 = 0xFFE1;
	static const unsigned short MARKER_APP2 = 0xFFE2;
	static const unsigned short MARKER_DQT = 0xFFDB;
	static const unsigned short MARKER_DHT = 0xFFC4;
	static const unsigned short MARKER_DRI = 0xFFDD;
	static const unsigned short MARKER_SOF = 0xFFC0;
	static const unsigned short MARKER_SOS = 0xFFDA;
	static const unsigned short MARKER_EOI = 0xFFD9;
	static const unsigned int MP_LITTLE_ENDIAN = 0x49492A00;

	m_NumberOfImages = 0;
	for(int i=0; i<m_NumberOfImages; i++)
		safe_delete(m_datas[i]);

	FILE *r = _wfopen(path, L"rb");
	if (!r)
		return 0;

	unsigned short soi = read2(r, false);
	if (soi != MARKER_SOI)
	{
		fclose(r);
		return 0;
	}

	while (ftell(r) < fsize(r))
	{
		unsigned short marker = read2(r, false);
		unsigned short length = read2(r, false);

		if (marker == MARKER_APP2)
		{
			// Read APP2 block
			char identifier[5] = {0};
			fread(identifier, 1, 4, r);
			length -= 4;

			if (strcmp(identifier, "MPF\0") == 0)
			{
				// Read MP Extensions
				unsigned int startOfOffset = ftell(r);
				unsigned int mpEndian = read4(r, false);
				bool isLittleEndian = mpEndian == MP_LITTLE_ENDIAN;
				unsigned int offsetToFirstIFD = read4(r, isLittleEndian);
				fseek(r, startOfOffset + offsetToFirstIFD, SEEK_SET);

				unsigned short count = read2(r, isLittleEndian);

				// Read the MP Index IFD
				char version[5] = {0};
				m_NumberOfImages = 0;
				unsigned int mpEntry = 0;
				unsigned int imageUIDList = 0;
				unsigned int totalFrames = 0;
				for (int i = 0; i < count; i++)
				{
					unsigned short tag = read2(r, isLittleEndian);
					unsigned short type = read2(r, isLittleEndian);
					unsigned int count2 = read4(r, isLittleEndian);
					switch (tag)
					{
					case 0xB000:
						fread(version, 1, 4, r);
						break;
					case 0xB001:
						m_NumberOfImages = read4(r, isLittleEndian);
						break;
					case 0xB002:
						mpEntry = read4(r, isLittleEndian);
						break;
					case 0xB003:
						imageUIDList = read4(r, isLittleEndian);
						break;
					case 0xB004:
						totalFrames = read4(r, isLittleEndian);
						break;
					}
				}

				unsigned int offsetNext = read4(r, isLittleEndian);

				// Read the values of the MP Index IFD
				for (int i = 0; i < m_NumberOfImages; i++)
				{
					// var bytes = r.ReadBytes(16);
					unsigned int iattr = read4(r, isLittleEndian);
					unsigned int imageSize = read4(r, isLittleEndian);
					unsigned int dataOffset = read4(r, isLittleEndian);
					unsigned short d1EntryNo = read2(r, isLittleEndian);
					unsigned short d2EntryNo = read2(r, isLittleEndian);

					// Calculate offset from beginning of file
					long offset = i == 0 ? 0 : dataOffset + startOfOffset;

					// store the current position
					long o = ftell(r);

					// read the image
					fseek(r, offset, SEEK_SET);
					m_datas[i] = new char[imageSize];
					m_sizes[i] = imageSize;
					if (fread(m_datas[i], 1, imageSize, r) != imageSize)
						return (m_NumberOfImages=0);

					// restore the current position                                    
					fseek(r, o, SEEK_SET);
				}

				fclose(r);
				return m_NumberOfImages;
			}
		}
		fseek(r, length-2, SEEK_CUR);
	}

	fclose(r);
	return m_NumberOfImages;
}
Example #28
0
int tfm::load(const char *file)
{
  FILE *fp = fopen(file, "r");
  if (!fp) {
    error("can't open `%1': %2", file, strerror(errno));
    return 0;
  }
  int c1 = getc(fp);
  int c2 = getc(fp);
  if (c1 == EOF || c2 == EOF) {
    fclose(fp);
    error("unexpected end of file on `%1'", file);
    return 0;
  }
  int lf = (c1 << 8) + c2;
  int toread = lf*4 - 2;
  unsigned char *buf = new unsigned char[toread];
  if (fread(buf, 1, toread, fp) != toread) {
    if (feof(fp))
      error("unexpected end of file on `%1'", file);
    else
      error("error on file `%1'", file);
    delete buf;
    fclose(fp);
    return 0;
  }
  fclose(fp);
  if (lf < 6) {
    error("bad tfm file `%1': impossibly short", file);
    delete buf;
    return 0;
  }
  unsigned char *ptr = buf;
  int lh = read2(ptr);
  bc = read2(ptr);
  ec = read2(ptr);
  nw = read2(ptr);
  nh = read2(ptr);
  nd = read2(ptr);
  ni = read2(ptr);
  nl = read2(ptr);
  nk = read2(ptr);
  int ne = read2(ptr);
  np = read2(ptr);
  if (6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np != lf) {
    error("bad tfm file `%1': lengths do not sum", file);
    delete buf;
    return 0;
  }
  if (lh < 2) {
    error("bad tfm file `%1': header too short", file);
    delete buf;
    return 0;
  }
  char_info = new char_info_word[ec - bc + 1];
  width = new int[nw];
  height = new int[nh];
  depth = new int[nd];
  italic = new int[ni];
  lig_kern = new lig_kern_command[nl];
  kern = new int[nk];
  param = new int[np];
  int i;
  cs = read4(ptr);
  ds = read4(ptr);
  ptr += (lh-2)*4;
  for (i = 0; i < ec - bc + 1; i++) {
    char_info[i].width_index = *ptr++;
    unsigned char tem = *ptr++;
    char_info[i].depth_index = tem & 0xf;
    char_info[i].height_index = tem >> 4;
    tem = *ptr++;
    char_info[i].italic_index = tem >> 2;
    char_info[i].tag = tem & 3;
    char_info[i].remainder = *ptr++;
  }
  for (i = 0; i < nw; i++)
    width[i] = read4(ptr);
  for (i = 0; i < nh; i++)
    height[i] = read4(ptr);
  for (i = 0; i < nd; i++)
    depth[i] = read4(ptr);
  for (i = 0; i < ni; i++)
    italic[i] = read4(ptr);
  for (i = 0; i < nl; i++) {
    lig_kern[i].skip_byte = *ptr++;
    lig_kern[i].next_char = *ptr++;
    lig_kern[i].op_byte = *ptr++;
    lig_kern[i].remainder = *ptr++;
  }
  for (i = 0; i < nk; i++)
    kern[i] = read4(ptr);
  ptr += ne*4;
  for (i = 0; i < np; i++)
    param[i] = read4(ptr);
  assert(ptr == buf + lf*4 - 2);
  delete buf;
  return 1;
}
Example #29
0
ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe)
{
	char buf[BUFSIZ];
	char test[] = { 23, 8, 68 };
	char *version;
	int show_version = 0;
	int show_funcs = 0;
	int show_printk = 0;
	ssize_t size = -1;
	int file_bigendian;
	int host_bigendian;
	int file_long_size;
	int file_page_size;
	struct tep_handle *pevent = NULL;
	int err;

	repipe = __repipe;
	input_fd = fd;

	if (do_read(buf, 3) < 0)
		return -1;
	if (memcmp(buf, test, 3) != 0) {
		pr_debug("no trace data in the file");
		return -1;
	}

	if (do_read(buf, 7) < 0)
		return -1;
	if (memcmp(buf, "tracing", 7) != 0) {
		pr_debug("not a trace file (missing 'tracing' tag)");
		return -1;
	}

	version = read_string();
	if (version == NULL)
		return -1;
	if (show_version)
		printf("version = %s\n", version);

	if (do_read(buf, 1) < 0) {
		free(version);
		return -1;
	}
	file_bigendian = buf[0];
	host_bigendian = bigendian();

	if (trace_event__init(tevent)) {
		pr_debug("trace_event__init failed");
		goto out;
	}

	pevent = tevent->pevent;

	tep_set_flag(pevent, TEP_NSEC_OUTPUT);
	tep_set_file_bigendian(pevent, file_bigendian);
	tep_set_host_bigendian(pevent, host_bigendian);

	if (do_read(buf, 1) < 0)
		goto out;
	file_long_size = buf[0];

	file_page_size = read4(pevent);
	if (!file_page_size)
		goto out;

	tep_set_long_size(pevent, file_long_size);
	tep_set_page_size(pevent, file_page_size);

	err = read_header_files(pevent);
	if (err)
		goto out;
	err = read_ftrace_files(pevent);
	if (err)
		goto out;
	err = read_event_files(pevent);
	if (err)
		goto out;
	err = read_proc_kallsyms(pevent);
	if (err)
		goto out;
	err = read_ftrace_printk(pevent);
	if (err)
		goto out;
	if (atof(version) >= 0.6) {
		err = read_saved_cmdline(pevent);
		if (err)
			goto out;
	}

	size = trace_data_size;
	repipe = false;

	if (show_funcs) {
		tep_print_funcs(pevent);
	} else if (show_printk) {
		tep_print_printk(pevent);
	}

	pevent = NULL;

out:
	if (pevent)
		trace_event__cleanup(tevent);
	free(version);
	return size;
}
Example #30
0
int
main(int ac, const char** av)
{
  const unsigned PropHeaderSize = 5;
  const unsigned HeaderSize = 13;

  SizeT inSize = SYMBOL(end) - SYMBOL(start);

  int32_t outSize32 = read4(SYMBOL(start) + PropHeaderSize);
  SizeT outSize = outSize32;

  uint8_t* out = static_cast<uint8_t*>(malloc(outSize));
  if (out) {
    ISzAlloc allocator = { myAllocate, myFree };
    ELzmaStatus status = LZMA_STATUS_NOT_SPECIFIED;

    if (SZ_OK == LzmaDecode
        (out, &outSize, SYMBOL(start) + HeaderSize, &inSize, SYMBOL(start),
         PropHeaderSize, LZMA_FINISH_END, &status, &allocator))
    {
      const unsigned BufferSize = 1024;
      char buffer[BufferSize];
      const char* name = temporaryFileName(buffer, BufferSize);
      if (name) {
        int file = open(name, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, S_IRWXU);
        if (file != -1) {
          SizeT result = write(file, out, outSize);
          free(out);

          if (close(file) == 0 and outSize == result) {
            void* library = openLibrary(name);
            unlink(name);

            if (library) {
              void* main = librarySymbol(library, "avianMain");
              if (main) {
                int (*mainFunction)(const char*, int, const char**);
                memcpy(&mainFunction, &main, sizeof(void*));
                return mainFunction(name, ac, av);
              } else {
                fprintf(stderr, "unable to find main in %s", name);
              }
            } else {
              fprintf(stderr, "unable to load %s: %s\n", name,
                      libraryError(library));
            }
          } else {
            unlink(name);

            fprintf(stderr, "close or write failed; tried %d, got %d; %s\n",
                    static_cast<int>(outSize), static_cast<int>(result),
                    strerror(errno));
          }
        } else {
          fprintf(stderr, "unable to open %s\n", name);
        }
      } else {
        fprintf(stderr, "unable to make temporary file name\n");
      }
    } else {
      fprintf(stderr, "unable to decode LZMA data\n");
    }
  } else {
    fprintf(stderr, "unable to allocate buffer of size %d\n",
            static_cast<int>(outSize));
  }

  return -1;
}