int main(int  argc,
         char **argv) {
  char buffer[4096];
  char *bufptr = buffer;
  size_t ix;

  /* type signature of main is constrained by SDL */
  UNREFERENCED_PARAMETER(argc);
  UNREFERENCED_PARAMETER(argv);

  NACL_ASSERT_IS_POINTER(bufptr);
  NACL_ASSERT_IS_ARRAY(buffer);

  /*
   * NACL_ASSERT_IS_ARRAY(bufptr);
   */

  printf("#buffer = %"NACL_PRIuS"\n", NACL_ARRAY_SIZE(buffer));

  /*
   * printf("#bufptr = %lu\n", ARRAY_SIZE(bufptr));
   */

  /*
   * for checking that the store to gNaClArrayCheck is moved out of
   * the loop.
   */
  for (ix = 0; ix < NACL_ARRAY_SIZE(buffer); ++ix) {
    buffer[ix] = (char) ix;
  }
  return (buffer[10] + buffer[4095] == 0);  /* loop was not dead code! */
}
int main(void) {
  char buffer[4096];
  char *bufptr = buffer;
  size_t ix;

  NACL_ASSERT_IS_POINTER(bufptr);
  NACL_ASSERT_IS_ARRAY(buffer);

  /*
   * NACL_ASSERT_IS_ARRAY(bufptr);
   */

  printf("#buffer = %"NACL_PRIuS"\n", NACL_ARRAY_SIZE(buffer));

  /*
   * printf("#bufptr = %lu\n", ARRAY_SIZE(bufptr));
   */

  /*
   * for checking that the store to gNaClArrayCheck is moved out of
   * the loop.
   */
  for (ix = 0; ix < NACL_ARRAY_SIZE(buffer); ++ix) {
    buffer[ix] = (char) ix;
  }
  return (buffer[10] + buffer[4095] == 0);  /* loop was not dead code! */
}
int main(void) {
  char buffer[4096];

  NACL_ASSERT_IS_ARRAY(buffer);

  return 0;
}
Exemplo n.º 4
0
/*
 * Records the time in sv and  returns its index in sv
 * Note that the first time this routine is called on a sv that was just
 * constructed via NaClPerfCounterCtor(), it will return 1, but that
 * is actually the SECOND sample.
 */
int NaClPerfCounterMark(struct NaClPerfCounter *sv, const char *ev_name)
{
  if((NULL == sv) || (NULL == ev_name))
  {
    ZLOG(LOG_ERROR, "NaClPerfCounterMark received null args");
    return -1;
  }
  if(sv->samples >= NACL_MAX_PERF_COUNTER_SAMPLES)
  {
    ZLOG(LOG_ERROR, "NaClPerfCounterMark going beyond buffer size");
    return -1;
  }
  /* busy loop until we succeed, damn it */
  while(0 != NaClGetTimeOfDay(&(sv->sample_list[sv->samples])))
    ;

  /*
   * This relies upon memset() inside NaClPerfCounterCtor() for
   * correctness
   */

  NACL_ASSERT_IS_ARRAY(sv->sample_names[sv->samples]);

  strncpy(sv->sample_names[sv->samples], ev_name, LAST_IDX(sv->sample_names[sv->samples]));
  /* Being explicit about string termination */
  sv->sample_names[sv->samples][LAST_IDX(sv->sample_names[sv->samples])] = '\0';

  return (sv->samples)++;
}
Exemplo n.º 5
0
void NaClPerfCounterCtor(struct NaClPerfCounter *sv, const char *app_name)
{
  if(NULL == sv)
  {
    ZLOG(LOG_ERROR, "NaClPerfCounterStart received null pointer");
    return;
  };

  memset(sv, 0, sizeof(struct NaClPerfCounter));

  if(NULL == app_name)
  {
    app_name = "__unknown_app__";
  }

  NACL_ASSERT_IS_ARRAY(sv->app_name);
  strncpy(sv->app_name, app_name, LAST_IDX(sv->app_name));

  /* Being explicit about string termination */
  sv->app_name[LAST_IDX(sv->app_name)] = '\0';

  strncpy(sv->sample_names[0], "__start__", LAST_IDX(sv->sample_names[0]));

  while(0 != NaClGetTimeOfDay(&sv->sample_list[sv->samples]))
  {
    /* repeat until we get a sample */
  }

  sv->samples++;
}
Exemplo n.º 6
0
/*
 * __NaClSrpcImcWrite attempts to write n_elt elements of size elt_size from
 * source to the specified buffer.  It returns the number of elements it
 * wrote if successful, and -1 otherwise.
 */
nacl_abi_size_t __NaClSrpcImcWrite(const void* source,
                                   nacl_abi_size_t elt_size,
                                   nacl_abi_size_t n_elt,
                                   NaClSrpcImcBuffer* buffer) {
  nacl_abi_size_t request_bytes;
  nacl_abi_size_t avail_bytes;
  /*
   * What follows works on the assumption that buffer->bytes is an array,
   * rather than a pointer to a buffer.  If it were the latter, the subtraction
   * would almost invariably be negative, producing a massive size_t value
   * and allowing heap corruptions.
   */
#ifndef __native_client__ /* these checks are unnecessary in an ILP32 module */
  CHECK(sizeof(buffer->bytes) <= NACL_ABI_SIZE_T_MAX);
  CHECK(sizeof(buffer->bytes) >= buffer->next_byte);
#endif /* __native_client__ */
  avail_bytes =
      nacl_abi_size_t_saturate(sizeof(buffer->bytes) - buffer->next_byte);

  /*
   * protect against future change of buffer->bytes to be dynamically
   * allocated, since otherwise avail_bytes becomes huge
   */
  NACL_ASSERT_IS_ARRAY(buffer->bytes);

  if (n_elt >= SIZE_T_MAX / elt_size) {
    return -1;
  }
  request_bytes = n_elt * elt_size;
  /*
   * Writes are not broken into multiple datagram sends for now either.
   */
  if (avail_bytes < request_bytes) {
    dprintf((SIDE "SRPC: WRITE: insufficient space available to satisfy.\n"));
    return -1;
  } else {
    memcpy((void*)(buffer->bytes + buffer->next_byte), source, request_bytes);
    buffer->next_byte += request_bytes;
    return n_elt;
  }
}