Exemplo n.º 1
0
bool ExifHasher::HashExif(const std::string& path,
                          unsigned char* sha1_hash) const {
  FD fd;
  sys_call_rv(fd, open, path.c_str(), O_RDONLY);
  struct stat stat_buf;
  sys_call(fstat, fd, &stat_buf);
  void* memblock;
  sys_call2_rv(NULL, memblock, mmap, NULL, stat_buf.st_size, PROT_READ,
               MAP_PRIVATE, fd, 0);
  auto bytes = static_cast<const unsigned char*>(memblock);

  Exiv2::Image::AutoPtr image;
  try {
    image = Exiv2::ImageFactory::open(bytes, stat_buf.st_size);
  } catch (const std::exception& e) {
    std::cerr << "Error: " << e.what() << std::endl;
    return false;
  }

  if (image.get() != 0)
    image->readMetadata();
  else
    std::cerr << "Warning: EXIF not found in: " << path << std::endl;

  sys_call(munmap, memblock, stat_buf.st_size);
  fd.Close();

  if (image.get() == 0)
    return false;

  const auto& exifData = image->exifData();
  if (!exifData.empty()) {
    std::ostringstream oss;
    auto end = exifData.end();
    for (auto i = exifData.begin(); i != end; ++i) {
      // std::cerr << i->key() << " (" << i->count() << ")" << ": " <<
      //     i->value() << std::endl;
      oss << i->key() << i->value();
    }
    const std::string& exif_str = oss.str();
    SHA1(reinterpret_cast<const unsigned char*>(exif_str.c_str()),
         exif_str.size(), sha1_hash);
    return true;
  } else {
    std::cerr << "Warning: EXIF not found in: " << path << std::endl;
  }

  return false;
}
Exemplo n.º 2
0
void giet_coproc_run( unsigned int coproc_reg_index )
{
    if ( sys_call( SYSCALL_COPROC_RUN,
                   coproc_reg_index,
                   0, 0, 0 ) ) 
        giet_exit("error in giet_coproc_run()");
}
Exemplo n.º 3
0
void giet_coproc_release( unsigned int coproc_reg_index )
{
    if ( sys_call( SYSCALL_COPROC_RELEASE,
                   coproc_reg_index,
                   0, 0, 0 ) )  
        giet_exit("error in giet_coproc_release()");
}
Exemplo n.º 4
0
void giet_coproc_channel_init( unsigned int            channel,
                               giet_coproc_channel_t*  desc )
{
    if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT,
                   channel,
                   (unsigned int)desc,
                   0, 0 ) ) 
        giet_exit("error in giet_coproc_channel_init()");
}
Exemplo n.º 5
0
/*
 * Executes a system call
 * reg - register to pass to syscall
 * const8 - syscall code to run
 */
void
_sys (int reg, int const8)
{
    check (reg, TYPE_REG, 1);
    check (const8, TYPE_CONST8, 2);

    /* Execute system call */
    sys_call (reg, const8);
}
Exemplo n.º 6
0
void giet_coproc_alloc( unsigned int   coproc_type,
                        unsigned int*  coproc_info )
{
    if ( sys_call( SYSCALL_COPROC_ALLOC,
                   coproc_type,
                   (unsigned int)coproc_info,
                   0, 0 ) )  
        giet_exit("error in giet_coproc_alloc()");
}
Exemplo n.º 7
0
void giet_proc_xyp( unsigned int* cluster_x,
                    unsigned int* cluster_y,
                    unsigned int* lpid )
{
    sys_call( SYSCALL_PROC_XYP,
              (unsigned int)cluster_x,
              (unsigned int)cluster_y,
              (unsigned int)lpid,
               0 );
}
Exemplo n.º 8
0
unsigned int giet_rand() 
{
    unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME,
                                             0, 0, 0, 0);
    if ((x & 0xF) > 7) 
    {
        return (x*x & 0xFFFF);
    }
    else 
    {
        return (x*x*x & 0xFFFF);
    }
}
Exemplo n.º 9
0
int main(){
  int x,y,z;

  if (y > 0)
    y = y + 1; // y > 0
  else{ 
    y = foo(y) - 1; // {-1,0}    
    y = foo(5) +  5; // {5,6}
    // POST: y > 0
  }
  // SAFE
  _TRACER_abort(y <= 0);
  
  z = sys_call(y);

  // UNSAFE
  _TRACER_abort(z <= 0);
  return z ;
}
Exemplo n.º 10
0
int main(int argc, char** argv){

	// Get time of mininmal function call in C
	clock_gettime(CLOCK_ID,&func_start);
	func_call();
	clock_gettime(CLOCK_ID,&func_end);
	func_time = get_time(func_start, func_end);

	// Get time of minimal system call in C
	clock_gettime(CLOCK_ID,&sys_start);
	sys_call();
	clock_gettime(CLOCK_ID,&sys_end);
	sys_time = get_time(sys_start,sys_end);

	// Calculate the time difference between the two calls
	time_diff = sys_time - func_time;

	// Print the time difference
	printf("The time it takes to do a minimum function call in C: %llu(ns)\n", (long long unsigned int) func_time);
	printf("The time it takes to do a minimum system call in C: %llu(ns)\n", (long long unsigned int) sys_time);
	printf("The time difference between a system call and a function call in C: %llu(ns)\n", (long long unsigned int) time_diff);

	exit(EXIT_SUCCESS);
} 
Exemplo n.º 11
0
void giet_exit( char* string ) 
{
    sys_call( SYSCALL_EXIT,
              (unsigned int)string,
              0, 0, 0 );
}
Exemplo n.º 12
0
unsigned int giet_global_task_id() 
{
    return (unsigned int)sys_call( SYSCALL_GLOBAL_TASK_ID, 
                                   0, 0, 0, 0 );
}
Exemplo n.º 13
0
unsigned int giet_thread_id() 
{
    return (unsigned int)sys_call( SYSCALL_THREAD_ID, 
                                   0, 0, 0, 0 );
}
Exemplo n.º 14
0
Arquivo: message.c Projeto: orlv/fos
res_t send(struct message *msg)
{
  return sys_call(_FOS_SEND, (u32_t) msg);
}
Exemplo n.º 15
0
unsigned int giet_proc_task_id() 
{
    return (unsigned int)sys_call( SYSCALL_LOCAL_TASK_ID, 
                                   0, 0, 0, 0 );
}
Exemplo n.º 16
0
/**
	\brief make event inactive
	\param event: event handle
	\retval none
*/
void event_clear(HANDLE event)
{
	sys_call(EVENT_CLEAR, (unsigned int)event, 0, 0);
}
Exemplo n.º 17
0
int giet_exec_application( char* name ) 
{
    return ( sys_call( SYSCALL_EXEC_APP,
                       (unsigned int)name,
                       0, 0, 0 ) );
}
Exemplo n.º 18
0
void giet_coproc_completed()
{
    if ( sys_call( SYSCALL_COPROC_COMPLETED,
                   0, 0, 0, 0 ) ) 
        giet_exit("error in giet_coproc_completed");
}
Exemplo n.º 19
0
void giet_tty_alloc( unsigned int shared )
{
    if ( sys_call( SYSCALL_TTY_ALLOC,
                   shared,
                   0, 0, 0 ) )  giet_exit("error in giet_tty_alloc()");
}
Exemplo n.º 20
0
/**
	\brief make event active, release all waiters, go inactive state
	\param event: event handle
	\retval none
*/
void event_pulse(HANDLE event)
{
	sys_call(EVENT_PULSE, (unsigned int)event, 0, 0);
}
Exemplo n.º 21
0
/**
	\brief check is event is active
	\param event: event handle
	\retval true if active, false if not
*/
bool event_is_set(HANDLE event)
{
	return sys_call(EVENT_IS_SET, (unsigned int)event, 0, 0);
}
Exemplo n.º 22
0
Arquivo: message.c Projeto: orlv/fos
res_t reply(struct message *msg)
{
  return sys_call(_FOS_REPLY, (u32_t) msg);
}
Exemplo n.º 23
0
Arquivo: message.c Projeto: orlv/fos
res_t receive(struct message *msg)
{
  return sys_call(_FOS_RECEIVE, (u32_t) msg);
}
Exemplo n.º 24
0
Dir::~Dir() {
  sys_call(closedir, dir_);
}
Exemplo n.º 25
0
void giet_context_switch() 
{
    sys_call( SYSCALL_CTX_SWITCH,
              0, 0, 0, 0 );
}
Exemplo n.º 26
0
static  int __printf( char* format, unsigned int channel, va_list* args) 
{
    int ret;                    // return value from the syscall 
    enum TModifiers {NO_MOD, L_MOD, LL_MOD} modifiers;

printf_text:

    while (*format) 
    {
        unsigned int i;
        for (i = 0 ; format[i] && (format[i] != '%') ; i++);
        if (i) 
        {
            ret = sys_call(SYSCALL_TTY_WRITE, 
                           (unsigned int)format,
                           i, 
                           channel,
                           0);

            if (ret != i) goto return_error;

            format += i;
        }
        if (*format == '%') 
        {
            format++;
            modifiers = NO_MOD;
            goto printf_arguments;
        }
    }

    return 0;

printf_arguments:

    {
        char              buf[30];
        char *            pbuf;
        unsigned int      len = 0;
        static const char HexaTab[] = "0123456789ABCDEF";
        unsigned int      i;
        
        /* Ignored fields : width and precision */
        for (; *format >= '0' && *format <= '9'; format++);

        switch (*format++) 
        {
            case ('%'):
            {
                len = 1;
                pbuf = "%";
                break;
            }
            case ('c'):             /* char conversion */
            {
                int val = va_arg( *args, int );
                if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning
                
                len = 1;
                buf[0] = val;
                pbuf = &buf[0];
                break;
            }
            case ('d'):             /* decimal signed integer */
            {
                int val = va_arg( *args, int );
                
                if (modifiers == LL_MOD) goto return_error; // 64 bits not supported
                
                if (val < 0) 
                {
                    val = -val;
                    ret = sys_call(SYSCALL_TTY_WRITE, 
                                   (unsigned int)"-",
                                   1,
                                   channel,
                                   0);
                    if (ret != 1) goto return_error;
                }
                for(i = 0; i < 10; i++) 
                {
                    buf[9 - i] = HexaTab[val % 10];
                    if (!(val /= 10)) break;
                }
                len =  i + 1;
                pbuf = &buf[9 - i];
                break;
            }
            case ('u'):             /* decimal unsigned integer */
            {
                if (modifiers != LL_MOD) //32 bits integer
                {
                    unsigned int val = va_arg( *args, unsigned int );
                    for(i = 0; i < 10; i++) 
                    {
                        buf[9 - i] = HexaTab[val % 10];
                        if (!(val /= 10)) break;
                    }
                    len =  i + 1;
                    pbuf = &buf[9 - i];
                    break;
                }
                //64 bits : base 10 unsupported : continue to hexa
            }
            case ('x'):
            case ('X'):             /* hexadecimal integer */
            {
                unsigned long long val;
                int imax;
                
                if (modifiers == LL_MOD) // 64 bits
                {
                    val = va_arg( *args, unsigned long long);
                    
                    // if asked to print in base 10, can do only if it fits in 32 bits
                    if (*(format-1) == 'u' && (!(val & 0xFFFFFFFF00000000ULL))) 
                    {
                        unsigned int uintv = (unsigned int) val;
                        
                        for(i = 0; i < 10; i++) 
                        {
                            buf[9 - i] = HexaTab[uintv % 10];
                            if (!(uintv /= 10)) break;
                        }
                        len =  i + 1;
                        pbuf = &buf[9 - i];
                        break;
                    }
                    
                    imax = 16;
                }
                else //32 bits
                {
                    val = va_arg( *args, unsigned int);
                    imax = 8;
                }
                
                ret = sys_call(SYSCALL_TTY_WRITE,
                               (unsigned int)"0x",
                               2,
                               channel,
                               0);
                if (ret != 2) goto return_error;
                
                for(i = 0; i < imax; i++) 
                {
                    buf[(imax-1) - i] = HexaTab[val % 16];
                    if (!(val /= 16))  break;
                }
                len =  i + 1;
                pbuf = &buf[(imax-1) - i];
                break;
            }
Exemplo n.º 27
0
void giet_tasks_status()
{
    sys_call( SYSCALL_TASKS_STATUS,
              0, 0, 0, 0 );
}
Exemplo n.º 28
0
unsigned int giet_proctime() 
{
    return (unsigned int)sys_call( SYSCALL_PROC_TIME, 
                                   0, 0, 0, 0 );
}
Exemplo n.º 29
0
/**
	\brief make event active, release all waiters, stay in active state
	\param event: event handle
	\retval none
*/
void event_set(HANDLE event)
{
	sys_call(EVENT_SET, (unsigned int)event, 0, 0);
}
Exemplo n.º 30
0
int giet_kill_application( char* name ) 
{
    return ( sys_call( SYSCALL_KILL_APP,
                       (unsigned int)name,
                       0, 0, 0 ) );
}