Exemplo n.º 1
0
int
main(int argc, char *argv[])
{
	struct timerinfo info;
	task_t task;
	char stack[16];
	u_long start, end;
	int i, pri, error;

	printf("Benchmark to create/terminate %d threads\n", NR_THREADS);

	sys_info(INFO_TIMER, &info);
	if (info.hz == 0)
		panic("can not get timer tick rate");

	thread_getpri(thread_self(), &pri);
	thread_setpri(thread_self(), pri - 1);

	task = task_self();
	error = vm_allocate(task, (void **)&thread,
			    sizeof(thread_t) * NR_THREADS, 1);
	if (error)
		panic("vm_allocate is failed");

	sys_time(&start);

	/*
	 * Create threads
	 */
	for (i = 0; i < NR_THREADS; i++) {
		if (thread_create(task, &thread[i]) != 0)
			panic("thread_create is failed");

		if (thread_load(thread[i], null_thread, &stack) != 0)
			panic("thread_load is failed");

		if (thread_resume(thread[i]) != 0)
			panic("thread_resume is failed");
	}

	/*
	 * Teminate threads
	 */
	for (i = 0; i < NR_THREADS; i++)
		thread_terminate(thread[i]);

	sys_time(&end);

	vm_free(task, thread);

	printf("Complete. The score is %d msec (%d ticks).\n",
	       (int)((end - start) * 1000 / info.hz),
	       (int)(end - start));

	return 0;
}
Exemplo n.º 2
0
void log(char *file, char *string)
{
    int fd, length;

    sprintf(stack, "logs/%s.log", file);
#if defined( FREEBSD )
    fd = open(stack, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
#else
    fd = open(stack, O_CREAT | O_WRONLY | O_SYNC, S_IRUSR | S_IWUSR);
#endif
    length = lseek(fd, 0, SEEK_END);
    if (length > MAX_LOG_SIZE)
    {
        close(fd);
#if defined( FREEBSD )
        fd = open(stack, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);
#else
        fd = open(stack, O_CREAT | O_WRONLY | O_SYNC | O_TRUNC, S_IRUSR | S_IWUSR);
#endif

    }
    sprintf(stack, "%s - %s\n", sys_time(), string);
    if (!no_tty)
        printf(stack);
    write(fd, stack, strlen(stack));
    close(fd);
}
Exemplo n.º 3
0
term nif_erlang_universaltime_0(Context *ctx, int argc, term argv[])
{
    UNUSED(ctx);
    UNUSED(argv);

    if (argc != 0) {
        fprintf(stderr, "system_time_to_universal_time(): wrong args count\n");
        abort();
    }

    // 4 = size of date/time tuple, 3 size of date time tuple
    memory_ensure_free(ctx, 3 + 4 + 4);
    term date_tuple = term_alloc_tuple(3, ctx);
    term time_tuple = term_alloc_tuple(3, ctx);
    term date_time_tuple = term_alloc_tuple(2, ctx);

    struct timespec ts;
    sys_time(&ts);

    struct tm broken_down_time;
    gmtime_r(&ts.tv_sec, &broken_down_time);

    term_put_tuple_element(date_tuple, 0, term_from_int32(1900 + broken_down_time.tm_year));
    term_put_tuple_element(date_tuple, 1, term_from_int32(broken_down_time.tm_mon + 1));
    term_put_tuple_element(date_tuple, 2, term_from_int32(broken_down_time.tm_mday));

    term_put_tuple_element(time_tuple, 0, term_from_int32(broken_down_time.tm_hour));
    term_put_tuple_element(time_tuple, 1, term_from_int32(broken_down_time.tm_min));
    term_put_tuple_element(time_tuple, 2, term_from_int32(broken_down_time.tm_sec));

    term_put_tuple_element(date_time_tuple, 0, date_tuple);
    term_put_tuple_element(date_time_tuple, 1, time_tuple);

    return date_time_tuple;
}
Exemplo n.º 4
0
void event_handler( event_type_t event_type, unidata_t unidata ) 
   { 
    result_t err;
    uint64_t cur_time;
    static uint64_t last_detect_time = 0;
    
    DBG("call event_handler");
    switch(event_type)
    {
    case TIMER_EVENT:
       if((stage == STAGE_IDLE) )
       {
          stage = STAGE_PYRO; 
          init_adc();
       }
       err = stimer_set(TIMER_0, SHOT_PERIOD );
       if( ENOERR != err ) DBG("FAIL: start timer");
       break;
    case ADC12_EVENT:
       switch(stage)
       {
       case STAGE_PYRO:
          cur_time = sys_time();
          unidata <<= 4;
          if((unidata < MOTION_LO_TH) || (unidata > MOTION_HI_TH))
          {
             // Motion is detected
             if(cur_MotionState == MOTION_STATE_QUIET)
             {
                uint16_t attr = 0;
                attr_write(0xE2, &attr);
             }
             cur_MotionState = MOTION_STATE_ALARM;
             last_detect_time = cur_time;
          }
          else if(cur_MotionState == MOTION_STATE_ALARM)
          {
             if((cur_time - last_detect_time) > QUIET_MSG_TIMEOUT)
             {
                uint16_t attr = 1;
                attr_write(0xE2, &attr);
                cur_MotionState = MOTION_STATE_QUIET;
             }
          }
          middle_point += (unidata - middle_point) >> 8;
          //unidata = ((uint32_t)3000 * (uint32_t)unidata) / 4095; // Calculation of voltage 
          break;
       default:
          stage = STAGE_PYRO;

       }
       break;
    default:
       DBG("UNKNOW EVENT");
    }

    DBG("return event_handler");
    return;
   }
Exemplo n.º 5
0
int gettimeofday(struct timeval *tp, void * tzp)
{
	long time = sys_time();
	tp->tv_sec = time;
	tp->tv_usec = 0;
	errno = 0;
	return 0;
}
Exemplo n.º 6
0
int gui_init(int argc, char *argv[])
{
	memset(frame_time, 0, sizeof(long)*MAX_FRAMES);
	stash = sth_create(512,512);
	if (!stash)
	{
		printf("Could not create stash.\n");
		return -1;
	}
	font_load(0,"data/gui/SourceCodePro-Regular.ttf");
	font_load(1,"data/gui/SourceCodePro-Bold.ttf");
	font_load(2,"data/gui/SourceSansPro-Regular.ttf");
	font_load(3,"data/gui/SourceSansPro-Bold.ttf");

	widget *w;
	widget *menu = widget_menu_new();
	widget *item = widget_menu_add(menu, "File");
	widget_menu_item_add(item, "Open", spawn_open);
	widget_menu_item_add(item, "Voxel Open", spawn_voxopen);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "Exit", menu_killme);

	item = widget_menu_add(menu, "Display");
	w = widget_menu_item_add(item, "	 Fullscreen - F11", menu_fullscreen);
	w->draw = widget_menu_bool_draw;
	w->data2 = &fullscreen;
	w = widget_menu_item_add(item, "	 Draw 3D Texture", menu_texdraw);
	w->draw = widget_menu_bool_draw;
	extern int texdraw;
	w->data2 = &texdraw;
	widget_menu_item_add(item, "GPU Information", spawn_gpuinfo);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "Rebuild Shaders", voxel_rebuildshader);

	item = widget_menu_add(menu, "Input");
	w = widget_menu_item_add(item, "	 Accepting Tablets",
		menu_http_toggle);
	w->draw = widget_menu_bool_draw;
	w->data2 = &http_accepting_new_clients;
	w = widget_menu_item_add(item, "Authorised Devices", spawn_http_auth );
	w = widget_menu_item_add(item, "Pending Authorisation", spawn_http_pend);

	item = widget_menu_add(menu, "Help");
	widget_menu_item_add(item, "Overview \u2560", 0);
	widget_menu_item_add(item, "Wiki \u26a0", 0);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "Credits \u2623", spawn_credits);
	widget_menu_item_add(item, "License", spawn_license);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "About", spawn_about);

	widget_add(menu);

	last_time = sys_time();
	return 0;
}
Exemplo n.º 7
0
Arquivo: time.c Projeto: deater/vmwos
int time(int *t) {

	int our_time;

	our_time=sys_time();

	if (t!=NULL) *t=our_time;

	return our_time;
}
Exemplo n.º 8
0
inline double ibprof_timestamp(void)
{
#if defined(CONF_TIMESTAMP) && (CONF_TIMESTAMP == 1)
	return ((double)sys_rdtsc() / __get_cpu_clocks_per_sec());
#else
	struct timeval tv;

	sys_time(&tv);

	return ((tv.tv_sec) + (tv.tv_usec) * 1.0e-6);
#endif
}
Exemplo n.º 9
0
Arquivo: screen.c Projeto: hankem/jed
static char *status_get_time(void)
{
   static char status_time[10];
   register char *t, ch, *t1;
   char am;
   int n;

   if (Display_Time == 0) return (NULL);
   if (Status_This_Time == 0) Status_This_Time = sys_time();
   if (Status_This_Time - Status_Last_Time >= 30)
     {
	Status_Last_Time = Status_This_Time;
	am = 'a';
	t = SLcurrent_time_string ();
	/* returns a string like:  "Tue Nov 2 13:18:19 1993" */
	t1 = status_time;
	while (ch = *t, (ch <= '0') || (ch > '9')) t++;
	/* on date number, skip it */
	while (*t++ != ' ');
	if (*t == '0') t++;
	if (Display_Time > 0)
	  {
	     n = 0;
	     while ((ch = *t++) != ':')
	       {
		  n = 10 * n + (int) (ch - '0');
	       }
	     if (n >= 12) am = 'p';
	     n = n % 12;
	     if (n == 0) n = 12;
	     if (n >= 10)
	       {
		  n -= 10;
		  *t1++ = '1';
	       }
	     *t1++ = '0' + n;
	     *t1++ = ':';
	     while ((*t1++ = *t++) != ':');
	     *(t1 - 1) = am; *t1++ = 'm'; *t1 = 0;
	  }
	else
	  {
	     *t1++ = '[';
	     while ((*t1++ = *t++) != ':');
	     while ((*t1++ = *t++) != ':');
	     *--t1 = ']'; *++t1 = 0;
	  }
     }
   return (status_time);
}
Exemplo n.º 10
0
void gui_draw(void)
{
	widget_draw(widget_root);

	long long delta_time, this_time = sys_time();
	delta_time = this_time - last_time;
	last_time = this_time;
//	double DeltaTime = (double)delta_time / (double)sys_ticksecond;

	frame_number++;
	if(frame_number>=MAX_FRAMES) frame_number=0;
	frame_time[frame_number] = (long)delta_time;
	long fps_sum = 0;
	for(int i=0; i<MAX_FRAMES; i++)
		fps_sum += frame_time[i];

	double fps = (double)MAX_FRAMES / ((double)fps_sum / (double)sys_ticksecond);

	glColor4f(1,1,1,1);
	sth_begin_draw(stash);
	char tempstr[50];
	sprintf(tempstr, "%4.1fHz", fps);
	sth_draw_text(stash, 3, 30, vid_width-90, -26, tempstr, 0);
#ifndef __APPLE__
	int i;
	for(i=0; i< nvml_device_count; i++)
	{
		sprintf(tempstr, "%d°C", nvml_gputemp[i]);
		sth_draw_text(stash, 3, 30, vid_width-70, -(50+i*50), tempstr, 0);
	}
	for(int j=0; j< adl_device_count; j++)
	{
		sprintf(tempstr, "%d°C", adl_gputemp[j]);
		sth_draw_text(stash, 3, 30, vid_width-70, -(50+(i+j)*50), tempstr, 0);
	}
#endif
	sth_end_draw(stash);

	gui_http_draw();


}
Exemplo n.º 11
0
void tm_edit_init(void)
{
   unsigned long cur_time = sys_time() / 1000;
   parse_time2(cur_time, &tm4edit);
   
   if(tm4edit.tm_year > 99)
      tm4edit.tm_year = 0;
   if(tm4edit.tm_mon > 11)
      tm4edit.tm_mon = 0;
   if(tm4edit.tm_mday > 31)
      tm4edit.tm_mday = 1;
   if(tm4edit.tm_hour > 23)
      tm4edit.tm_hour = 0;
   if(tm4edit.tm_min > 59)
      tm4edit.tm_min = 0;
   if(tm4edit.tm_sec > 59)
      tm4edit.tm_sec = 0;

   tm_edit.buf_pos = 0;
}
Exemplo n.º 12
0
void stat_draw_time(unsigned int x, unsigned int y, struct statusbar_item * item)
{
   
   time_t cur_time;
   struct tm fmt_time;
   unsigned int i;
   char str[32];
   char * str_ptr;
   

   cur_time = sys_time() / 1000;
   parse_time2(cur_time, &fmt_time);
   //tm2str(&fmt_time, str);
   
   format_str(str, 32, "%02u/%02u/%02u %02u:%02u:%02u", fmt_time.tm_mday, fmt_time.tm_mon + 1, getyear2(fmt_time.tm_year),
         fmt_time.tm_hour, fmt_time.tm_min, fmt_time.tm_sec);
   
   //format_str(str, 32, "%llx", sys_time());
   OLED_puts(x, y, 0xff, font6x9, str);
}
Exemplo n.º 13
0
void Logger::sys_register(const std::string& message, Flags level) {
	mutex.lock();

	std::string type;

	switch(level){
		case DEBUG:   type = "DEBUG"; 	break;
		case ERROR:	  type = "ERROR"; 	break;
		case INFO:	  type = "INFO"; 	break;
		case WARNING: type = "WARNING"; break;
	}

	std::string text {"[#] TYPE: " + type + "\t\tDATE: " + sys_time() +
					   "\n" + message + "\n"};

	output << "========" << std::endl;
	output << text <<std::endl;
	output << "========" << std::endl;

	mutex.unlock();
}
Exemplo n.º 14
0
term nif_erlang_system_time_1(Context *ctx, int argc, term argv[])
{
    UNUSED(ctx);

    if (argc != 1) {
        fprintf(stderr, "erlang:system_time: wrong args count\n");
        abort();
    }

    struct timespec ts;
    sys_time(&ts);

    term minute_atom = term_from_atom_string(ctx->global, "\x6" "minute");
    if (argv[0] == minute_atom) {
        // FIXME: This is not standard, however we cannot hold seconds since 1970 in just 27 bits.
        return term_from_int32(ts.tv_sec / 60);

    } else {
        fprintf(stderr, "nif_erlang_system_time: error, got: %lx\n", argv[0]);
        abort();
    }
}
Exemplo n.º 15
0
int main_init(int argc, char *argv[])
{
	printf("Version    : %s-%s\n", GIT_TAG, GIT_REV);
	printf("GL Vendor  : %s\n", glGetString(GL_VENDOR) );
	printf("GL Renderer: %s\n", glGetString(GL_RENDERER) );
	printf("GL Version : %s\n", glGetString(GL_VERSION) );
	printf("SL Version : %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION) );

	int glver[2];
	glGetIntegerv(GL_MAJOR_VERSION, &glver[0]);
	glGetIntegerv(GL_MINOR_VERSION, &glver[1]);
	printf("GL3 Version: %d.%d\n", glver[0], glver[1]);
	
#ifndef __APPLE__
	if(!GLEW_VERSION_4_3)
	{
		printf("Fatal: OpenGL 4.3 Required.\n");
		return 1;
	}
	gpuinfo_init();
#endif

	ocl_init();

	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat mat_shininess[] = { 50.0 };
	GLfloat light_position[] = { -100.0, -100.0, -100.0, 0.0 };
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);

	time_start = sys_time();
	http_init();
//	voxel_init();

	return gui_init(argc, argv);
}
Exemplo n.º 16
0
Arquivo: timing.c Projeto: ipeet/ubw32
//! Delay a certain number of seconds
unsigned int sleep(unsigned int seconds) {
    unsigned int start = sys_time();
    unsigned int ms = seconds*1000;
    while( start + ms > sys_time() ) delay();
    return 0;
}
Exemplo n.º 17
0
void main_loop(void)
{
#ifndef __APPLE__
	gpuinfo_tick();
#endif
	for(int i=0; i<4; i++)
	{
		joy[i].fflarge = joy[i].lt;
		joy[i].ffsmall = joy[i].rt;
	}

	pos.w = 0.5 / (float)vid_width;

	float3 req = {0,0,0};
	float nice = 0.007;

	if(keys[KEY_ESCAPE])
	{
		killme=1;
	}
	if(keys[KEY_W])
	{
		req.z -= nice;
	}
	if(keys[KEY_S])
	{
		req.z += nice;
	}
	if(keys[KEY_A])
	{
		req.x -= nice;
	}
	if(keys[KEY_D])
	{
		req.x += nice;
	}
	if(keys[KEY_LCONTROL])
	{
		req.y -= nice;
	}
	if(keys[KEY_SPACE])
	{
		req.y += nice;
	}

	if(mouse[2]) /// right mouse
	{
		angle.x += mickey_y * 0.003;
		angle.y += mickey_x * 0.003;
	}
	if(keys[KEY_O])
	{
		p_swim = !p_swim;
		keys[KEY_S] = 0;
		printf("Swimming is %s.\n", p_swim ? "engaged" : "off");
	}
	if(keys[KEY_P])
	{
		printf("float4 pos = {%f, %f, %f, 0.0};\n", pos.x, pos.y, pos.z);
		printf("float4 angle = {%f, %f, %f, M_PI*0.5};\n", angle.x, angle.y, angle.z);
	}

	if(p_swim)
	{
		float cx = cos(angle.x), sx = sin(angle.x), ty = req.y;
		req.y = req.y * cx - req.z * sx;	// around x
		req.z = ty * sx + req.z * cx;
	}


	float cy = cos(angle.y), sy = sin(angle.y), tx = req.x;
	req.x = req.x * cy + req.z * sy;	// around y
	req.z = tx * sy - req.z * cy;


	F3ADD(pos, pos, req);


	time = (float)(sys_time() - time_start)/(float)sys_ticksecond;

	glClearColor(0.3f, 0.3f, 0.32f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	gui_input();
//	voxel_loop();
	ocl_loop();
	gui_draw();
	http_loop();
}
Exemplo n.º 18
0
bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
{
	struct task_struct *tsk;
	unsigned long caller;
	int vsyscall_nr, syscall_nr, tmp;
	int prev_sig_on_uaccess_error;
	long ret;

	/*
	 * No point in checking CS -- the only way to get here is a user mode
	 * trap to a high address, which means that we're in 64-bit user code.
	 */

	WARN_ON_ONCE(address != regs->ip);

	if (vsyscall_mode == NONE) {
		warn_bad_vsyscall(KERN_INFO, regs,
				  "vsyscall attempted with vsyscall=none");
		return false;
	}

	vsyscall_nr = addr_to_vsyscall_nr(address);

	trace_emulate_vsyscall(vsyscall_nr);

	if (vsyscall_nr < 0) {
		warn_bad_vsyscall(KERN_WARNING, regs,
				  "misaligned vsyscall (exploit attempt or buggy program) -- look up the vsyscall kernel parameter if you need a workaround");
		goto sigsegv;
	}

	if (get_user(caller, (unsigned long __user *)regs->sp) != 0) {
		warn_bad_vsyscall(KERN_WARNING, regs,
				  "vsyscall with bad stack (exploit attempt?)");
		goto sigsegv;
	}

	tsk = current;

	/*
	 * Check for access_ok violations and find the syscall nr.
	 *
	 * NULL is a valid user pointer (in the access_ok sense) on 32-bit and
	 * 64-bit, so we don't need to special-case it here.  For all the
	 * vsyscalls, NULL means "don't write anything" not "write it at
	 * address 0".
	 */
	switch (vsyscall_nr) {
	case 0:
		if (!write_ok_or_segv(regs->di, sizeof(struct timeval)) ||
		    !write_ok_or_segv(regs->si, sizeof(struct timezone))) {
			ret = -EFAULT;
			goto check_fault;
		}

		syscall_nr = __NR_gettimeofday;
		break;

	case 1:
		if (!write_ok_or_segv(regs->di, sizeof(time_t))) {
			ret = -EFAULT;
			goto check_fault;
		}

		syscall_nr = __NR_time;
		break;

	case 2:
		if (!write_ok_or_segv(regs->di, sizeof(unsigned)) ||
		    !write_ok_or_segv(regs->si, sizeof(unsigned))) {
			ret = -EFAULT;
			goto check_fault;
		}

		syscall_nr = __NR_getcpu;
		break;
	}

	/*
	 * Handle seccomp.  regs->ip must be the original value.
	 * See seccomp_send_sigsys and Documentation/prctl/seccomp_filter.txt.
	 *
	 * We could optimize the seccomp disabled case, but performance
	 * here doesn't matter.
	 */
	regs->orig_ax = syscall_nr;
	regs->ax = -ENOSYS;
	tmp = secure_computing(syscall_nr);
	if ((!tmp && regs->orig_ax != syscall_nr) || regs->ip != address) {
		warn_bad_vsyscall(KERN_DEBUG, regs,
				  "seccomp tried to change syscall nr or ip");
		do_exit(SIGSYS);
	}
	if (tmp)
		goto do_ret;  /* skip requested */

	/*
	 * With a real vsyscall, page faults cause SIGSEGV.  We want to
	 * preserve that behavior to make writing exploits harder.
	 */
	prev_sig_on_uaccess_error = current_thread_info()->sig_on_uaccess_error;
	current_thread_info()->sig_on_uaccess_error = 1;

	ret = -EFAULT;
	switch (vsyscall_nr) {
	case 0:
		ret = sys_gettimeofday(
			(struct timeval __user *)regs->di,
			(struct timezone __user *)regs->si);
		break;

	case 1:
		ret = sys_time((time_t __user *)regs->di);
		break;

	case 2:
		ret = sys_getcpu((unsigned __user *)regs->di,
				 (unsigned __user *)regs->si,
				 NULL);
		break;
	}

	current_thread_info()->sig_on_uaccess_error = prev_sig_on_uaccess_error;

check_fault:
	if (ret == -EFAULT) {
		/* Bad news -- userspace fed a bad pointer to a vsyscall. */
		warn_bad_vsyscall(KERN_INFO, regs,
				  "vsyscall fault (exploit attempt?)");

		/*
		 * If we failed to generate a signal for any reason,
		 * generate one here.  (This should be impossible.)
		 */
		if (WARN_ON_ONCE(!sigismember(&tsk->pending.signal, SIGBUS) &&
				 !sigismember(&tsk->pending.signal, SIGSEGV)))
			goto sigsegv;

		return true;  /* Don't emulate the ret. */
	}

	regs->ax = ret;

do_ret:
	/* Emulate a ret instruction. */
	regs->ip = caller;
	regs->sp += 8;
	return true;

sigsegv:
	force_sig(SIGSEGV, current);
	return true;
}
Exemplo n.º 19
0
static void _set_state(enum _control_states new_state) {
    _control_state = new_state;
    _last_event_time = sys_time();
}
Exemplo n.º 20
0
Arquivo: screen.c Projeto: hankem/jed
/* if force then do update otherwise return 1 if update or 0 if not */
static int update_1(Line *top, int force)
{
   int i;
   Window_Type *start_win;
   int did_eob, time_has_expired = 0;

   if (Batch ||
       (!force
	&& (Executing_Keyboard_Macro || (Repeat_Factor != NULL)
	    || screen_input_pending (0)
	    || (Read_This_Character != NULL)))
       || (CBuf != JWindow->buffer))

     {
	return(0);
     }

   if (Suspend_Screen_Update != 0)
     {
	Suspend_Screen_Update = 0;
	touch_screen ();
     }

   JWindow->mark.line = CLine;
   JWindow->mark.point = Point;
   JWindow->mark.n = LineNum + CBuf->nup;
   CBuf->linenum = LineNum;
   CBuf->max_linenum = Max_LineNum;

   if (Wants_Attributes && CBuf->vis_marks)
     {
	JWindow->trashed = 1;
     }

   /* Do not bother setting this unless it is really needed */
   if (Display_Time)
     {
	Status_This_Time = sys_time();
	time_has_expired = (Status_This_Time > Status_Last_Time + 45);
     }

   /* if cursor moves just left right, do not update status line */
   if (!force && !JWindow->trashed &&
       ((JWindow == JWindow->next) || (User_Prefers_Line_Numbers && Cursor_Motion))
       /* if % wanted, assume user is like me and gets annoyed with
	* screen updates
	*/
       && (User_Prefers_Line_Numbers
	   || time_has_expired))
     {
	update_status_line(0);
	return(1);
     }

   if (!JWindow->trashed && Cursor_Motion)
     {
#if JED_HAS_LINE_ATTRIBUTES
	if (CLine->flags & JED_LINE_IS_READONLY)
	  update_status_line (0);
#endif
	return 1;
     }

   start_win = JWindow;
   do
     {
	int imax;
	unsigned int start_column;

#if JED_HAS_LINE_ATTRIBUTES
	if (CBuf->min_unparsed_line_num)
	  jed_syntax_parse_buffer (0);
#endif
	if (Wants_Syntax_Highlight) init_syntax_highlight ();

#if JED_HAS_LINE_ATTRIBUTES
	if (top != NULL) top = jed_find_non_hidden_line (top);
#endif

	/* (void) SLsmg_utf8_enable (CBuf->local_vars.is_utf8); */
	if (top == NULL)
	  {
	     top = find_top();
	     if (top == NULL) top = CLine;
	  }

	JWindow->beg.line = top;
#if JED_HAS_LINE_ATTRIBUTES
	if (top->flags & JED_LINE_HIDDEN)
	  top = NULL;
	else
#endif
	  mark_window_attributes ((start_win == JWindow) || (start_win->buffer != CBuf));

	did_eob = 0;

	i = JWindow->sy;
	imax = i + JWindow->rows;

	compute_line_display_size ();
	start_column = JWindow->sx;

	while (i < imax)
	  {
#if JED_HAS_LINE_ATTRIBUTES
	     if ((top != NULL) && (top->flags & JED_LINE_HIDDEN))
	       {
		  top = top->next;
		  continue;
	       }
#endif

	     /* the next line is really optional */
#if 0
	     if (!force && (Exit_From_MiniBuffer ||
			    screen_input_pending (0))) break;
#endif

	     if ((JScreen[i].line != top)
		 || JScreen[i].is_modified
		 || (Want_Eob
		     && !did_eob
		     && (i != Jed_Num_Screen_Rows - 1)
		     && (top == NULL)))
	       {
		  if (((top == NULL) || (top->len == 0))
		      && (Want_Eob && !did_eob && !(CBuf->flags & READ_ONLY)))
		    {
		       display_line(&Eob_Line, i, start_column);

		       /* JScreen[i].line = top; */
		       did_eob = 1;
		    }
		  else display_line(top, i, start_column);
	       }

	     if (top != NULL)
	       top = top->next;
	     i++;
	  }

	HScroll_Line = NULL;
	Mode_Has_Syntax_Highlight = 0;
	if (!force && screen_input_pending (0))
	  {
	     while (JWindow != start_win) other_window();
	     JWindow->trashed = 1;  /* since cursor not pointed */
	     /* (void) SLsmg_utf8_enable (1); */  /* default state */

	     return(0);
	  }
	else update_status_line (start_win != JWindow);

#if JED_HAS_DISPLAY_LINE_NUMBERS
	if (CBuf->line_num_display_size)
	  display_line_numbers ();
#endif
	JWindow->trashed = 0;

	other_window();
	top = NULL;
	/* if (!JWindow->trashed) top = JWindow->beg.line; else  top = NULL; */

     }
   while (JWindow != start_win);
   /* SLsmg_utf8_enable (1); */	       /* default state */
   return 1;
}
Exemplo n.º 21
0
bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
{
	struct task_struct *tsk;
	unsigned long caller;
	int vsyscall_nr;
	long ret;

	/*
	 * No point in checking CS -- the only way to get here is a user mode
	 * trap to a high address, which means that we're in 64-bit user code.
	 */

	WARN_ON_ONCE(address != regs->ip);

	if (vsyscall_mode == NONE) {
		warn_bad_vsyscall(KERN_INFO, regs,
				  "vsyscall attempted with vsyscall=none");
		return false;
	}

	vsyscall_nr = addr_to_vsyscall_nr(address);

	trace_emulate_vsyscall(vsyscall_nr);

	if (vsyscall_nr < 0) {
		warn_bad_vsyscall(KERN_WARNING, regs,
				  "misaligned vsyscall (exploit attempt or buggy program) -- look up the vsyscall kernel parameter if you need a workaround");
		goto sigsegv;
	}

	if (get_user(caller, (unsigned long __user *)regs->sp) != 0) {
		warn_bad_vsyscall(KERN_WARNING, regs,
				  "vsyscall with bad stack (exploit attempt?)");
		goto sigsegv;
	}

	tsk = current;
	if (seccomp_mode(&tsk->seccomp))
		do_exit(SIGKILL);

	switch (vsyscall_nr) {
	case 0:
		ret = sys_gettimeofday(
			(struct timeval __user *)regs->di,
			(struct timezone __user *)regs->si);
		break;

	case 1:
		ret = sys_time((time_t __user *)regs->di);
		break;

	case 2:
		ret = sys_getcpu((unsigned __user *)regs->di,
				 (unsigned __user *)regs->si,
				 0);
		break;
	}

	if (ret == -EFAULT) {
		/*
		 * Bad news -- userspace fed a bad pointer to a vsyscall.
		 *
		 * With a real vsyscall, that would have caused SIGSEGV.
		 * To make writing reliable exploits using the emulated
		 * vsyscalls harder, generate SIGSEGV here as well.
		 */
		warn_bad_vsyscall(KERN_INFO, regs,
				  "vsyscall fault (exploit attempt?)");
		goto sigsegv;
	}

	regs->ax = ret;

	/* Emulate a ret instruction. */
	regs->ip = caller;
	regs->sp += 8;

	return true;

sigsegv:
	force_sig(SIGSEGV, current);
	return true;
}
Exemplo n.º 22
0
bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
{
	struct task_struct *tsk;
	unsigned long caller;
	int vsyscall_nr;
	int prev_sig_on_uaccess_error;
	long ret;

	/*
	 * No point in checking CS -- the only way to get here is a user mode
	 * trap to a high address, which means that we're in 64-bit user code.
	 */

	WARN_ON_ONCE(address != regs->ip);

	if (vsyscall_mode == NONE) {
		warn_bad_vsyscall(KERN_INFO, regs,
				  "vsyscall attempted with vsyscall=none");
		return false;
	}

	vsyscall_nr = addr_to_vsyscall_nr(address);

	trace_emulate_vsyscall(vsyscall_nr);

	if (vsyscall_nr < 0) {
		warn_bad_vsyscall(KERN_WARNING, regs,
				  "misaligned vsyscall (exploit attempt or buggy program) -- look up the vsyscall kernel parameter if you need a workaround");
		goto sigsegv;
	}

	if (get_user(caller, (unsigned long __user *)regs->sp) != 0) {
		warn_bad_vsyscall(KERN_WARNING, regs,
				  "vsyscall with bad stack (exploit attempt?)");
		goto sigsegv;
	}

	tsk = current;
	if (seccomp_mode(&tsk->seccomp))
		do_exit(SIGKILL);

	/*
	 * With a real vsyscall, page faults cause SIGSEGV.  We want to
	 * preserve that behavior to make writing exploits harder.
	 */
	prev_sig_on_uaccess_error = current_thread_info()->sig_on_uaccess_error;
	current_thread_info()->sig_on_uaccess_error = 1;

	/*
	 * NULL is a valid user pointer (in the access_ok sense) on 32-bit and
	 * 64-bit, so we don't need to special-case it here.  For all the
	 * vsyscalls, NULL means "don't write anything" not "write it at
	 * address 0".
	 */
	ret = -EFAULT;
	switch (vsyscall_nr) {
	case 0:
		if (!write_ok_or_segv(regs->di, sizeof(struct timeval)) ||
		    !write_ok_or_segv(regs->si, sizeof(struct timezone)))
			break;

		ret = sys_gettimeofday(
			(struct timeval __user *)regs->di,
			(struct timezone __user *)regs->si);
		break;

	case 1:
		if (!write_ok_or_segv(regs->di, sizeof(time_t)))
			break;

		ret = sys_time((time_t __user *)regs->di);
		break;

	case 2:
		if (!write_ok_or_segv(regs->di, sizeof(unsigned)) ||
		    !write_ok_or_segv(regs->si, sizeof(unsigned)))
			break;

		ret = sys_getcpu((unsigned __user *)regs->di,
				 (unsigned __user *)regs->si,
				 NULL);
		break;
	}

	current_thread_info()->sig_on_uaccess_error = prev_sig_on_uaccess_error;

	if (ret == -EFAULT) {
		/* Bad news -- userspace fed a bad pointer to a vsyscall. */
		warn_bad_vsyscall(KERN_INFO, regs,
				  "vsyscall fault (exploit attempt?)");

		/*
		 * If we failed to generate a signal for any reason,
		 * generate one here.  (This should be impossible.)
		 */
		if (WARN_ON_ONCE(!sigismember(&tsk->pending.signal, SIGBUS) &&
				 !sigismember(&tsk->pending.signal, SIGSEGV)))
			goto sigsegv;

		return true;  /* Don't emulate the ret. */
	}

	regs->ax = ret;

	/* Emulate a ret instruction. */
	regs->ip = caller;
	regs->sp += 8;

	return true;

sigsegv:
	force_sig(SIGSEGV, current);
	return true;
}
Exemplo n.º 23
0
int main()
{
  uint32 i;
  SM_guardTest_Handle      sMachine;
  GuardTest_IfaceHandle*   interfaceHandle=0;

  uint32                   statesCount[st_GuardTest_MAX];

  SimElement*          simListe = NULL;
  ResElement*          resListe = NULL;

  /* create some triggers */

  /* Loop 1: trigger1 is set and value is correct */
  addSimElementVar(&simListe, 100, gValue, 3);
  addSimElementVar(&simListe, 100, out, 0);
  addSimElementTrig(&simListe, 100, trigger1);

  /* back */
  addSimElementTrig(&simListe, 200, trigger4);

  addResElementVar(&resListe, 100, startState, 0);
  addResElementVar(&resListe, 100, state1, 1);
  addResElementVar(&resListe, 100, state2, 0);
  addResElementVar(&resListe, 100, state3, 0);
  addResElementVar(&resListe, 100, state4, 0);
  addResElementVar(&resListe, 100, state5, 0);
  addResElementVar(&resListe, 100, state6, 0);
  addResElementVar(&resListe, 100, out, 0);



  /* Loop 2: trigger1 is set value is 1 */
  addSimElementVar(&simListe, 300, gValue, 5);
  addSimElementVar(&simListe, 300, out, 0);
  addSimElementTrig(&simListe, 300, trigger1);

  /* back */
  addSimElementTrig(&simListe, 400, trigger4);

  addResElementVar(&resListe, 300, startState, 0);
  addResElementVar(&resListe, 300, state1, 0);
  addResElementVar(&resListe, 300, state2, 1);
  addResElementVar(&resListe, 300, state3, 0);
  addResElementVar(&resListe, 300, state4, 0);
  addResElementVar(&resListe, 300, state5, 0);
  addResElementVar(&resListe, 300, state6, 0);
  addResElementVar(&resListe, 300, out, 0);



  /* Loop 3: trigger1 is set, value is 1 */
  addSimElementVar(&simListe, 500, gValue, 1);
  addSimElementVar(&simListe, 500, out, 0);
  addSimElementTrig(&simListe, 500, trigger2);

  /* back */
  addSimElementTrig(&simListe, 600, trigger4);

  addResElementVar(&resListe, 500, startState, 0);
  addResElementVar(&resListe, 500, state1, 0);
  addResElementVar(&resListe, 500, state2, 0);
  addResElementVar(&resListe, 500, state3, 1);
  addResElementVar(&resListe, 500, state4, 0);
  addResElementVar(&resListe, 500, state5, 0);
  addResElementVar(&resListe, 500, state6, 0);
  addResElementVar(&resListe, 500, out, 4);


  /* Loop 4: trigger1 is set and value is correct */
  addSimElementVar(&simListe, 700, gValue, 3);
  addSimElementVar(&simListe, 700, out, 0);
  addSimElementTrig(&simListe, 700, trigger2);

  /* back */
  addSimElementTrig(&simListe, 800, trigger4);

  addResElementVar(&resListe, 700, startState, 0);
  addResElementVar(&resListe, 700, state1, 1);
  addResElementVar(&resListe, 700, state2, 0);
  addResElementVar(&resListe, 700, state3, 0);
  addResElementVar(&resListe, 700, state4, 0);
  addResElementVar(&resListe, 700, state5, 0);
  addResElementVar(&resListe, 700, state6, 0);
  addResElementVar(&resListe, 700, out, 1);



  /* Loop 5: trigger1 is set value is 1 */
  addSimElementVar(&simListe, 900, gValue, 5);
  addSimElementVar(&simListe, 900, out, 0);
  addSimElementTrig(&simListe, 900, trigger2);

  /* back */
  addSimElementTrig(&simListe, 1000, trigger4);

  addResElementVar(&resListe, 900, startState, 0);
  addResElementVar(&resListe, 900, state1, 0);
  addResElementVar(&resListe, 900, state2, 1);
  addResElementVar(&resListe, 900, state3, 0);
  addResElementVar(&resListe, 900, state4, 0);
  addResElementVar(&resListe, 900, state5, 0);
  addResElementVar(&resListe, 900, state6, 0);
  addResElementVar(&resListe, 900, out, 2);



  /* Loop 6: trigger1 is set, value is 1 */
  addSimElementVar(&simListe, 1100, gValue, 2);
  addSimElementVar(&simListe, 1100, out, 0);
  addSimElementTrig(&simListe, 1100, trigger3);

  /* back */
  addSimElementTrig(&simListe, 1200, trigger4);

  addResElementVar(&resListe, 1100, startState, 0);
  addResElementVar(&resListe, 1100, state1, 0);
  addResElementVar(&resListe, 1100, state2, 0);
  addResElementVar(&resListe, 1100, state3, 1);
  addResElementVar(&resListe, 1100, state4, 0);
  addResElementVar(&resListe, 1100, state5, 0);
  addResElementVar(&resListe, 1100, state6, 0);
  addResElementVar(&resListe, 1100, out, 3);



  /* Loop 7: Test for wrong triggers */
  addSimElementVar(&simListe, 1300, gValue, 0);
  addSimElementVar(&simListe, 1300, out, 0);
  addSimElementTrig(&simListe, 1300, trigger4);

  addResElementVar(&resListe, 1300, startState, 1);
  addResElementVar(&resListe, 1300, state1, 0);
  addResElementVar(&resListe, 1300, state2, 0);
  addResElementVar(&resListe, 1300, state3, 0);
  addResElementVar(&resListe, 1300, state4, 0);
  addResElementVar(&resListe, 1300, state5, 0);
  addResElementVar(&resListe, 1300, state6, 0);
  addResElementVar(&resListe, 1300, out, 0);



  /* Loop 8: Test for wrong triggers */
  addSimElementVar(&simListe, 1400, gValue, 0);
  addSimElementVar(&simListe, 1400, out, 0);
  addSimElementTrig(&simListe, 1400, trigger5);

  addResElementVar(&resListe, 1400, startState, 1);
  addResElementVar(&resListe, 1400, state1, 0);
  addResElementVar(&resListe, 1400, state2, 0);
  addResElementVar(&resListe, 1400, state3, 0);
  addResElementVar(&resListe, 1400, state4, 0);
  addResElementVar(&resListe, 1400, state5, 0);
  addResElementVar(&resListe, 1400, state6, 0);
  addResElementVar(&resListe, 1400, out, 0);


  /* Loop 9: Test for reachability of state4 */
  addSimElementVar(&simListe, 1600, value1, 11);
  addSimElementVar(&simListe, 1600, value2, 3);
  /* addSimElementTrig(&simListe, 1600, trigger1); */
  addSimElementTrig(&simListe, 1800, trigger4);

  addResElementVar(&resListe, 1700, startState, 0);
  addResElementVar(&resListe, 1700, state1, 0);
  addResElementVar(&resListe, 1700, state2, 0);
  addResElementVar(&resListe, 1700, state3, 0);
  addResElementVar(&resListe, 1700, state4, 1);
  addResElementVar(&resListe, 1700, state5, 0);
  addResElementVar(&resListe, 1700, state6, 0);

  /* does the state machine returns back after trigger */
  addResElementVar(&resListe, 1900, startState, 1);
  addResElementVar(&resListe, 1900, state1, 0);
  addResElementVar(&resListe, 1900, state2, 0);
  addResElementVar(&resListe, 1900, state3, 0);
  addResElementVar(&resListe, 1900, state4, 0);
  addResElementVar(&resListe, 1900, state5, 0);
  addResElementVar(&resListe, 1900, state6, 0);



  /* Loop 10: Test for unreachability of state4 */
  addSimElementVar(&simListe, 2000, value1, 10);
  addSimElementVar(&simListe, 2000, value2, 3);

  addResElementVar(&resListe, 2000, startState, 1);
  addResElementVar(&resListe, 2000, state1, 0);
  addResElementVar(&resListe, 2000, state2, 0);
  addResElementVar(&resListe, 2000, state3, 0);
  addResElementVar(&resListe, 2000, state4, 0);
  addResElementVar(&resListe, 2000, state5, 0);
  addResElementVar(&resListe, 2000, state6, 0);



  /* Loop 11: Test for unreachability of state4 */
  addSimElementVar(&simListe, 2100, value1, 11);
  addSimElementVar(&simListe, 2100, value2, 2);

  addResElementVar(&resListe, 2100, startState, 1);
  addResElementVar(&resListe, 2100, state1, 0);
  addResElementVar(&resListe, 2100, state2, 0);
  addResElementVar(&resListe, 2100, state3, 0);
  addResElementVar(&resListe, 2100, state4, 0);
  addResElementVar(&resListe, 2100, state5, 0);
  addResElementVar(&resListe, 2100, state6, 0);




  /* Loop 12: Test Choice first path ( value1 > 100 ) */
  addSimElementVar(&simListe, 2200, value1, 110);
  addSimElementVar(&simListe, 2200, value2, 10);

  addResElementVar(&resListe, 2200, startState, 0);
  addResElementVar(&resListe, 2200, state1, 0);
  addResElementVar(&resListe, 2200, state2, 0);
  addResElementVar(&resListe, 2200, state3, 0);
  addResElementVar(&resListe, 2200, state4, 0);
  addResElementVar(&resListe, 2200, state5, 1);
  addResElementVar(&resListe, 2200, state6, 0);




  /* Loop 13: Test for Junction back to state 1 */
  addSimElementTrig(&simListe, 2300, trigger4);
  addSimElementVar(&simListe, 2300, value2, 0); /* should not met the value again */

  addResElementVar(&resListe, 2300, startState, 1);
  addResElementVar(&resListe, 2300, state1, 0);
  addResElementVar(&resListe, 2300, state2, 0);
  addResElementVar(&resListe, 2300, state3, 0);
  addResElementVar(&resListe, 2300, state4, 0);
  addResElementVar(&resListe, 2300, state5, 0);
  addResElementVar(&resListe, 2300, state6, 0);




  /* Loop 12: Test Choice first path ( value1 < 100 ) */
  addSimElementVar(&simListe, 2400, value1, 80);
  addSimElementVar(&simListe, 2400, value2, 10);

  addResElementVar(&resListe, 2400, startState, 0);
  addResElementVar(&resListe, 2400, state1, 0);
  addResElementVar(&resListe, 2400, state2, 0);
  addResElementVar(&resListe, 2400, state3, 0);
  addResElementVar(&resListe, 2400, state4, 0);
  addResElementVar(&resListe, 2400, state5, 0);
  addResElementVar(&resListe, 2400, state6, 1);




  /* Loop 13: Test for Junction back to state 1 */
  addSimElementTrig(&simListe, 2500, trigger4);
  addSimElementVar(&simListe, 2500, value2, 0); /* should not met the value again */

  addResElementVar(&resListe, 2500, startState, 1);
  addResElementVar(&resListe, 2500, state1, 0);
  addResElementVar(&resListe, 2500, state2, 0);
  addResElementVar(&resListe, 2500, state3, 0);
  addResElementVar(&resListe, 2500, state4, 0);
  addResElementVar(&resListe, 2500, state5, 0);
  addResElementVar(&resListe, 2500, state6, 0);


  /* carries the information, which state has been reached, and how often */
  for(i=0; i<st_GuardTest_MAX; ++i)
	  statesCount[i] = 0;

  guardTest_init(&sMachine, &interfaceHandle);

  guardTest_Iface_cleanTriggers(interfaceHandle);
  guardTest_Iface_cleanVariables(interfaceHandle);


  for(i=0; i<MAX_SIM_CYCLES; ++i) {

	  BOOL        stateMachineFinished = FALSE;

	  installChange(simListe, interfaceHandle,  sys_time());

	  GuardTest_timerIface_trigger(sys_time());

	  while (stateMachineFinished == FALSE) {
 		  stateMachineFinished = guardTest_runCycle(&sMachine);
		  guardTest_Iface_cleanInputTriggers(interfaceHandle);
	  }

	  compareResults(resListe, interfaceHandle, sys_time());

	  guardTest_Iface_cleanTriggers(interfaceHandle);

      statesCount[sMachine.state]++;

#ifdef DEBUG
      printf("\r  %d     ", i);
#endif

/*      printf(" %d ", *stateIDVar); */

      stepTime(10); /* add 10ms for the next cycle */
  }

  printf("\n\nFinished\n\n");

  for(i=0; i<st_GuardTest_MAX; ++i) {
	  printf(" State No. %d   -> %d\n",i, statesCount[i]);
  }

  printStatistics(resListe);

  return(0);
}
Exemplo n.º 24
0
// Print sensor data
static void sense();
// Print control state
static void control_mon();
// 'adc' command
static void adc_cmd(char *args);
// pwm test command
static void pwm_cmd();

char temp_err[32];

/* Blink an LED, indicating that polling is continuing */
void heartbeat(void* data __attribute__((unused))) 
{
    // blink much more rapidly immediately after reset, to indicate reset.
    int period = sys_time() < 2000 ? 75 : 250;

    if( (sys_time()/period) & 0x1 ) {
        mLED_2_On();
    } else {
        mLED_2_Off();
    }
}

int main()
{   
    init_timing();
    add_poll(heartbeat, 0);
    init_system();
    init_adc();
    init_file_io();
Exemplo n.º 25
0
Arquivo: timing.c Projeto: ipeet/ubw32
//! Delay a certain number of microseconds.
unsigned int usleep(unsigned int us) {
   unsigned int start = sys_time();
   unsigned int ms = us / 1000;
   while( start + ms > sys_time() ) delay();
   return 0;
}