Beispiel #1
0
/*
 * destination buffer size
 */
size_t
_elf32_xltsize(const Elf_Data *src, unsigned dv, unsigned encode, int tof) {
    Elf_Type type = src->d_type;
    unsigned sv = src->d_version;
    xlator op;

    if (!valid_version(sv) || !valid_version(dv)) {
	seterr(ERROR_UNKNOWN_VERSION);
	return (size_t)-1;
    }
    if (tof) {
	/*
	 * Encoding doesn't really matter (the translator only looks at
	 * the source, which resides in memory), but we need a proper
	 * encoding to select a translator...
	 */
	encode = ELFDATA2LSB;
    }
    else if (!valid_encoding(encode)) {
	seterr(ERROR_UNKNOWN_ENCODING);
	return (size_t)-1;
    }
    if (!valid_type(type)) {
	seterr(ERROR_UNKNOWN_TYPE);
	return (size_t)-1;
    }
    if (!(op = translator(sv, dv, encode, type, tof))) {
	seterr(ERROR_UNKNOWN_TYPE);
	return (size_t)-1;
    }
    return (*op)(NULL, src->d_buf, src->d_size);
}
Beispiel #2
0
  int MPI_Bcast_local(void *buffer, int count, MPI_Datatype datatype, int local_root, MPI_Comm comm)
  {
    assert(valid_type(datatype));

    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;

    ::MPI_Aint datasize, lb;
    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);
    

    if(ep_rank_loc == local_root)
    {
      comm.my_buffer->void_buffer[local_root] = buffer;
    }

    MPI_Barrier_local(comm);

    if(ep_rank_loc != local_root)
    {
      #pragma omp critical (_bcast)      
      memcpy(buffer, comm.my_buffer->void_buffer[local_root], datasize * count);
    }

    MPI_Barrier_local(comm);
  }
Beispiel #3
0
/*
 * Extension: report memory size
 */
size_t
gelf_msize(Elf *elf, Elf_Type type, size_t count, unsigned ver) {
    size_t n;

    if (elf) {
	if (elf->e_kind != ELF_K_ELF) {
	    seterr(ERROR_NOTELF);
	}
	else if (!valid_class(elf->e_class)) {
	    seterr(ERROR_UNKNOWN_CLASS);
	}
	else if (!valid_version(ver)) {
	    seterr(ERROR_UNKNOWN_VERSION);
	}
	else if (!valid_type(type)) {
	    seterr(ERROR_UNKNOWN_TYPE);
	}
	else if (!(n = _msize(elf->e_class, ver, type))) {
	    seterr(ERROR_UNKNOWN_TYPE);
	}
	else {
	    return count * n;
	}
    }
    return 0;
}
Beispiel #4
0
/*
 * Extension: report memory size
 */
size_t
gcgcef_msize(CGCEf *cgcef, CGCEf_Type type, size_t count, unsigned ver) {
    size_t n;

    if (cgcef) {
	if (cgcef->e_kind != CGCEF_K_CGCEF) {
	    seterr(ERROR_NOTCGCEF);
	}
	else if (!valid_class(cgcef->e_class)) {
	    seterr(ERROR_UNKNOWN_CLASS);
	}
	else if (!valid_version(ver)) {
	    seterr(ERROR_UNKNOWN_VERSION);
	}
	else if (!valid_type(type)) {
	    seterr(ERROR_UNKNOWN_TYPE);
	}
	else if (!(n = _msize(cgcef->e_class, ver, type))) {
	    seterr(ERROR_UNKNOWN_TYPE);
	}
	else {
	    return count * n;
	}
    }
    return 0;
}
Beispiel #5
0
static yajl_gen_status
generate_key(yajl_gen g, Var v, void *ctx)
{
    struct generate_context *gctx = (struct generate_context *)ctx;

    switch (v.type) {
    case TYPE_OBJ:
    case TYPE_INT:
    case TYPE_FLOAT:
    case TYPE_ERR:
	{
	    const char *tmp = value_to_literal(v);
	    if (MODE_EMBEDDED_TYPES == gctx->mode)
		tmp = append_type(tmp, v.type);
	    return yajl_gen_string(g, (const unsigned char *)tmp, strlen(tmp));
	}
    case TYPE_STR:
	{
	    const char *tmp = v.v.str;
	    size_t len = strlen(tmp);
	    if (MODE_EMBEDDED_TYPES == gctx->mode)
		if (TYPE_NONE != valid_type(&tmp, &len))
		    tmp = append_type(tmp, v.type);
	    return yajl_gen_string(g, (const unsigned char *)tmp, strlen(tmp));
	}
    default:
	panic("Unsupported type in generate_key()");
    }

    return yajl_gen_keys_must_be_strings;
}
Beispiel #6
0
  int MPI_Gatherv_local(const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, const int recvcounts[], const int displs[], int local_root, MPI_Comm comm)
  {
    assert(valid_type(datatype));

    ::MPI_Aint datasize, lb;
    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);

    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;


    #pragma omp critical (_gatherv)
    comm.my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf);

    MPI_Barrier_local(comm);

    if(ep_rank_loc == local_root)
    {
      for(int i=0; i<num_ep; i++)
        memcpy(recvbuf + datasize*displs[i], comm.my_buffer->void_buffer[i], datasize*recvcounts[i]);

    }

    MPI_Barrier_local(comm);
  }
Beispiel #7
0
static yajl_gen_status
generate(yajl_gen g, Var v, void *ctx)
{
    struct generate_context *gctx = (struct generate_context *)ctx;

    switch (v.type) {
    case TYPE_INT:
	return yajl_gen_integer(g, v.v.num);
    case TYPE_FLOAT:
	return yajl_gen_double(g, *v.v.fnum);
    case TYPE_OBJ:
    case TYPE_ERR:
	{
	    const char *tmp = value_to_literal(v);
	    if (MODE_EMBEDDED_TYPES == gctx->mode)
		tmp = append_type(tmp, v.type);
	    return yajl_gen_string(g, (const unsigned char *)tmp, strlen(tmp));
	}
    case TYPE_STR:
	{
	    const char *tmp = v.v.str;
	    size_t len = strlen(tmp);
	    if (MODE_EMBEDDED_TYPES == gctx->mode)
		if (TYPE_NONE != valid_type(&tmp, &len))
		    tmp = append_type(tmp, v.type);
	    return yajl_gen_string(g, (const unsigned char *)tmp, strlen(tmp));
	}
    case TYPE_MAP:
	{
	    struct do_map_closure dmc;
	    dmc.g = g;
	    dmc.gctx = gctx;
	    dmc.status = yajl_gen_status_ok;
	    yajl_gen_map_open(g);
	    if (mapforeach(v, do_map, &dmc))
		return dmc.status;
	    yajl_gen_map_close(g);
	    return yajl_gen_status_ok;
	}
    case TYPE_LIST:
	{
	    int i;
	    yajl_gen_status status;
	    yajl_gen_array_open(g);
	    for (i = 1; i <= v.v.list[0].v.num; i++) {
		status = generate(g, v.v.list[i], ctx);
		if (yajl_gen_status_ok != status)
		    return status;
	    }
	    yajl_gen_array_close(g);
	    return yajl_gen_status_ok;
	}
    default:
	panic("Unsupported type in generate()");
    }

    return -1;
}
Beispiel #8
0
static char*
_elf_item(Elf *elf, Elf_Type type, size_t n, size_t off, int *flag) {
    Elf_Data src, dst;

    *flag = 0;
    elf_assert(n);
    elf_assert(valid_type(type));
    if (off > elf->e_size) {
	seterr(ERROR_OUTSIDE);
	return NULL;
    }

    src.d_type = type;
    src.d_version = elf->e_version;
    src.d_size = n * _fsize(elf->e_class, src.d_version, type);
    elf_assert(src.d_size);
    if ((elf->e_size - off) < src.d_size) {
	seterr(truncerr(type));
	return NULL;
    }

    dst.d_version = _elf_version;
    dst.d_size = n * _msize(elf->e_class, dst.d_version, type);
    elf_assert(dst.d_size);

    elf_assert(elf->e_data);
    if (elf->e_rawdata != elf->e_data && dst.d_size <= src.d_size) {
	dst.d_buf = elf->e_data + off;
    }
    else if (!(dst.d_buf = malloc(dst.d_size))) {
	seterr(memerr(type));
	return NULL;
    }
    else {
	*flag = 1;
    }

    if (elf->e_rawdata) {
	src.d_buf = elf->e_rawdata + off;
    }
    else {
	src.d_buf = elf->e_data + off;
    }

    if (_elf_xlatetom(elf, &dst, &src)) {
	if (!*flag) {
	    elf->e_cooked = 1;
	}
	return (char*)dst.d_buf;
    }

    if (*flag) {
	free(dst.d_buf);
	*flag = 0;
    }
    return NULL;
}
/*
 * direction-independent translation
 */
static Elf_Data*
elf32_xlate(Elf_Data *dst, const Elf_Data *src, unsigned encode, int tof) {
    Elf_Type type;
    int dv;
    int sv;
    size_t dsize;
    size_t tmp;
    xlator op;

    if (!src || !dst) {
	return NULL;
    }
    if (!src->d_buf || !dst->d_buf) {
	seterr(ERROR_NULLBUF);
	return NULL;
    }
    if (!valid_encoding(encode)) {
	seterr(ERROR_UNKNOWN_ENCODING);
	return NULL;
    }
    sv = src->d_version;
    dv = dst->d_version;
    if (!valid_version(sv) || !valid_version(dv)) {
	seterr(ERROR_UNKNOWN_VERSION);
	return NULL;
    }
    type = src->d_type;
    if (!valid_type(type)) {
	seterr(ERROR_UNKNOWN_TYPE);
	return NULL;
    }
    op = translator(sv, dv, encode, type, tof);
    if (!op) {
	seterr(ERROR_UNKNOWN_TYPE);
	return NULL;
    }
    dsize = (*op)(NULL, src->d_buf, src->d_size);
    if (dsize == (size_t)-1) {
	return NULL;
    }
    if (dst->d_size < dsize) {
	seterr(ERROR_DST2SMALL);
	return NULL;
    }
    if (dsize) {
	tmp = (*op)(dst->d_buf, src->d_buf, src->d_size);
	if (tmp == (size_t)-1) {
	    return NULL;
	}
	elf_assert(tmp == dsize);
    }
    dst->d_size = dsize;
    dst->d_type = type;
    return dst;
}
 double recent_time(timer_type type = TOTAL_TIME) const {
   if (!valid_type(type)) throw std::runtime_error("stopwatch: invalid timer type");
   if (!running) return 0;
   switch (type) {
     case WALL_TIME: return recent_wall_time();
     case TOTAL_TIME: return recent_total_time();
     case USER_TIME: return recent_user_time();
     case SYSTEM_TIME: return recent_system_time();
     case PAGEFAULTS: return recent_major_pagefaults();
     default: throw std::runtime_error("bug-didn't handle timer type in stopwatch::recent_time");
   }
 }
Beispiel #11
0
int parse_path(const char * path, char ** type, char ** target, char ** name)
{
	assert(path != NULL);

	*type = *target = *name = NULL;

	char * delim1 = strchr(path, ':');
	char * delim2 = strrchr(path, ':');

	if (delim1 == NULL && delim2 == NULL) {	// <target>
		if (asprintf(target, "%s", path) < 0) {
			ERRNO(errno);
			return -1;
		}
	} else if (delim1 == delim2) {		// <target>:<name>
		if (asprintf(target, "%.*s", (uint32_t)(delim1 - path), path) < 0) {
			ERRNO(errno);
			return -1;
		}
		delim1++;
		if (asprintf(name, "%s", delim1) < 0) {
			ERRNO(errno);
			return -1;
		}

		if (valid_type(*target) == true) {
			*type = *target;
			*target = *name;
			*name = NULL;
		}
	} else if (delim1 != delim2) {		// <type>:<target>:<name>
		if (asprintf(type, "%.*s", (uint32_t)(delim1 - path), path) < 0) {
			ERRNO(errno);
			return -1;
		}
		delim1++;
		if (asprintf(target, "%.*s", (uint32_t)(delim2 - delim1), delim1) < 0) {
			ERRNO(errno);
			return -1;
		}
		delim2++;
		if (asprintf(name, "%s", delim2) < 0) {
			ERRNO(errno);
			return -1;
		}
	}

	return 0;
}
Beispiel #12
0
static size_t
_elf_fsize(unsigned cls, Elf_Type type, unsigned ver) {
    size_t n = 0;

    if (!valid_version(ver)) {
	seterr(ERROR_UNKNOWN_VERSION);
    }
    else if (!valid_type(type)) {
	seterr(ERROR_UNKNOWN_TYPE);
    }
    else if (!(n = _fsize(cls, ver, type))) {
	seterr(ERROR_UNKNOWN_TYPE);
    }
    return n;
}
Beispiel #13
0
/*
 * Checks:
 *   name not null and alphabetic
 *   valid type of variable 
 *
 *  Returns:
 *	<0 if there is an error
 *
 *  NULL data is fine
 */
static int
check_table( const optionT * opt )
{	int i;

	assert( opt );

	for( i=0; opt[i].name && buffIsValid(opt[i].name) &&
	     valid_type(opt[i].type) && valid_flag(opt[i].flags) ; i++ )
		;

	if( opt[i].name == NULL )
		return -i;

	return check_colitions( opt );
}
Beispiel #14
0
/*
 * direction-independent translation
 */
static Elf_Data*
elf32_xlate(Elf_Data *dst, const Elf_Data *src, unsigned encode, int tof) {
    size_t ssize, dsize, count;
    Elf_Type type;
    int sv, dv;
    xlator op;

    if (!src || !dst) {
	return NULL;
    }
    if (!src->d_buf || !dst->d_buf) {
	seterr(ERROR_NULLBUF);
	return NULL;
    }
    if (!valid_encoding(encode)) {
	seterr(ERROR_UNKNOWN_ENCODING);
	return NULL;
    }
    sv = src->d_version;
    dv = dst->d_version;
    if (!valid_version(sv) || !valid_version(dv)) {
	seterr(ERROR_UNKNOWN_VERSION);
	return NULL;
    }
    type = src->d_type;
    if (!valid_type(type)) {
	seterr(ERROR_UNKNOWN_TYPE);
	return NULL;
    }
    ssize = _fmsize(ELFCLASS32, sv, type, 1 - tof);
    dsize = _fmsize(ELFCLASS32, dv, type, tof);
    op = translator(sv, dv, encode, type, tof);
    if (!ssize || !dsize || !op) {
	seterr(ERROR_UNKNOWN_TYPE);
	return NULL;
    }
    count = src->d_size / ssize;
    if (dst->d_size < count * dsize) {
	seterr(ERROR_DST2SMALL);
	return NULL;
    }
    if (count) {
	(*op)(dst->d_buf, src->d_buf, count);
    }
    dst->d_size = count * dsize;
    dst->d_type = type;
    return dst;
}
Beispiel #15
0
static char*
_elf_item(void *buf, Elf *elf, Elf_Type type, size_t off) {
    Elf_Data src, dst;

    elf_assert(valid_type(type));
    if (off < 0 || off > elf->e_size) {
	seterr(ERROR_OUTSIDE);
	return NULL;
    }

    src.d_type = type;
    src.d_version = elf->e_version;
    src.d_size = _fsize(elf->e_class, src.d_version, type);
    elf_assert(src.d_size);
    if ((elf->e_size - off) < src.d_size) {
	seterr(truncerr(type));
	return NULL;
    }

    dst.d_version = _elf_version;
    dst.d_size = _msize(elf->e_class, dst.d_version, type);
    elf_assert(dst.d_size);

    if (!(dst.d_buf = buf) && !(dst.d_buf = malloc(dst.d_size))) {
	seterr(memerr(type));
	return NULL;
    }

    elf_assert(elf->e_data);
    if (elf->e_rawdata) {
	src.d_buf = elf->e_rawdata + off;
    }
    else {
	src.d_buf = elf->e_data + off;
    }

    if (_elf_xlatetom(elf, &dst, &src)) {
	return (char*)dst.d_buf;
    }
    if (dst.d_buf != buf) {
	free(dst.d_buf);
    }
    return NULL;
}
Beispiel #16
0
  int MPI_Exscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
  {
    if(!comm.is_ep)
    {
      return ::MPI_Scan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm));
    }
    
    valid_type(datatype);

    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;

    ::MPI_Aint datasize, lb;
    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);
    
    void* tmp_sendbuf;
    tmp_sendbuf = new void*[datasize * count];

    int my_src = 0;
    int my_dst = ep_rank;

    std::vector<int> my_map(mpi_size, 0);

    for(int i=0; i<comm.rank_map->size(); i++) my_map[comm.rank_map->at(i).second]++;

    for(int i=0; i<mpi_rank; i++) my_src += my_map[i];
    my_src += ep_rank_loc;

     
    for(int i=0; i<mpi_size; i++)
    {
      if(my_dst < my_map[i])
      {
        my_dst = get_ep_rank(comm, my_dst, i); 
        break;
      }
      else
        my_dst -= my_map[i];
    }

    if(ep_rank != my_dst) 
    {
      MPI_Request request[2];
      MPI_Status status[2];

      MPI_Isend(sendbuf,     count, datatype, my_dst, my_dst,  comm, &request[0]);
    
      MPI_Irecv(tmp_sendbuf, count, datatype, my_src, ep_rank, comm, &request[1]);
    
      MPI_Waitall(2, request, status);
    }

    else memcpy(tmp_sendbuf, sendbuf, datasize*count);
    

    void* tmp_recvbuf;
    tmp_recvbuf = new void*[datasize * count];    

    MPI_Reduce_local(tmp_sendbuf, tmp_recvbuf, count, datatype, op, 0, comm);

    if(ep_rank_loc == 0)
      ::MPI_Exscan(MPI_IN_PLACE, tmp_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm));

    // printf(" ID=%d : %d  %d \n", ep_rank, static_cast<int*>(tmp_recvbuf)[0], static_cast<int*>(tmp_recvbuf)[1]);
    
    MPI_Exscan_local(tmp_sendbuf, tmp_recvbuf, count, datatype, op, comm);

     // printf(" ID=%d : after local tmp_sendbuf = %d %d ; tmp_recvbuf = %d  %d \n", ep_rank, static_cast<int*>(tmp_sendbuf)[0], static_cast<int*>(tmp_sendbuf)[1], static_cast<int*>(tmp_recvbuf)[0], static_cast<int*>(tmp_recvbuf)[1]);



    if(ep_rank != my_src) 
    {
      MPI_Request request[2];
      MPI_Status status[2];

      MPI_Isend(tmp_recvbuf, count, datatype, my_src, my_src,  comm, &request[0]);
    
      MPI_Irecv(recvbuf,     count, datatype, my_dst, ep_rank, comm, &request[1]);
    
      MPI_Waitall(2, request, status);
    }

    else memcpy(recvbuf, tmp_recvbuf, datasize*count);
    



    delete[] tmp_sendbuf;
    delete[] tmp_recvbuf;

  }
Beispiel #17
0
static off_t
scn_data_layout(Elf_Scn *scn, unsigned v, unsigned type, size_t *algn, unsigned *flag) {
    Elf *elf = scn->s_elf;
    Elf_Data *data;
    int layout = (elf->e_elf_flags & ELF_F_LAYOUT) == 0;
    size_t scn_align = 1;
    size_t len = 0;
    Scn_Data *sd;
    size_t fsize;

    if (!(sd = scn->s_data_1)) {
	/* no data in section */
	*algn = scn_align;
	return (off_t)len;
    }
    /* load data from file, if any */
    if (!(data = elf_getdata(scn, NULL))) {
	return (off_t)-1;
    }
    elf_assert(data == &sd->sd_data);
    for (; sd; sd = sd->sd_link) {
	elf_assert(sd->sd_magic == DATA_MAGIC);
	elf_assert(sd->sd_scn == scn);

	if (!valid_version(sd->sd_data.d_version)) {
	    return (off_t)-1;
	}

	fsize = sd->sd_data.d_size;
	if (fsize && type != SHT_NOBITS && valid_type(sd->sd_data.d_type)) {
	    if (elf->e_class == ELFCLASS32) {
		fsize = _elf32_xltsize(&sd->sd_data, v, ELFDATA2LSB, 1);
	    }
#if __LIBELF64
	    else if (elf->e_class == ELFCLASS64) {
		fsize = _elf64_xltsize(&sd->sd_data, v, ELFDATA2LSB, 1);
	    }
#endif /* __LIBELF64 */
	    else {
		elf_assert(valid_class(elf->e_class));
		seterr(ERROR_UNIMPLEMENTED);
		return (off_t)-1;
	    }
	    if (fsize == (size_t)-1) {
		return (off_t)-1;
	    }
	}

	if (layout) {
	    align(len, sd->sd_data.d_align);
	    scn_align = max(scn_align, sd->sd_data.d_align);
	    rewrite(sd->sd_data.d_off, (off_t)len, sd->sd_data_flags);
	    len += fsize;
	}
	else {
	    len = max(len, sd->sd_data.d_off + fsize);
	}

	*flag |= sd->sd_data_flags;
    }
    *algn = scn_align;
    return (off_t)len;
}
Beispiel #18
0
void dump_program(struct state *state)
{
	int i, sect_size;
	uint8_t *ptr;

	state->hdr = next_sect(state, &sect_size);

	printf("######## HEADER: (size %d)\n", sect_size);
	printf("\tsize:       %d\n", state->hdr->size);
	printf("\tattributes: %d\n", state->hdr->num_attribs);
	printf("\tuniforms:   %d\n", state->hdr->num_uniforms);
	printf("\tsamplers:   %d\n", state->hdr->num_samplers);
	printf("\tvaryings:   %d\n", state->hdr->num_varyings);
	if (full_dump)
		dump_hex((void *)state->hdr, sect_size);
	printf("\n");

	/* there seems to be two 0xba5eba11's at the end of the header, possibly
	 * with some other stuff between them:
	 */
	next_sect(state, &sect_size);

	for (i = 0; (i < state->hdr->num_attribs) && (state->sz > 0); i++) {
		state->attribs[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->attribs[i]->type_info))
			state->attribs[i] = next_sect(state, &sect_size);

		clean_ascii(state->attribs[i]->name, sect_size - 28);
		if (full_dump) {
			printf("######## ATTRIBUTE: (size %d)\n", sect_size);
			dump_attribute(state->attribs[i]);
			dump_hex((char *)state->attribs[i], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_uniforms) && (state->sz > 0); i++) {
		state->uniforms[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->uniforms[i]->type_info))
			state->uniforms[i] = next_sect(state, &sect_size);

		clean_ascii(state->uniforms[i]->name, sect_size - 41);
		if (full_dump) {
			printf("######## UNIFORM: (size %d)\n", sect_size);
			dump_uniform(state->uniforms[i]);
			dump_hex((char *)state->uniforms[i], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_samplers) && (state->sz > 0); i++) {
		state->samplers[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->samplers[i]->type_info))
			state->samplers[i] = next_sect(state, &sect_size);

		clean_ascii(state->samplers[i]->name, sect_size - 33);
		if (full_dump) {
			printf("######## SAMPLER: (size %d)\n", sect_size);
			dump_sampler(state->samplers[i]);
			dump_hex((char *)state->samplers[i], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_varyings) && (state->sz > 0); i++) {
		state->varyings[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->varyings[i]->type_info))
			state->varyings[i] = next_sect(state, &sect_size);

		clean_ascii(state->varyings[i]->name, sect_size - 16);
		if (full_dump) {
			printf("######## VARYING: (size %d)\n", sect_size);
			dump_varying(state->varyings[i]);
			dump_hex((char *)state->varyings[i], sect_size);
		}
	}

	if (gpu_id >= 300) {
		dump_shaders_a3xx(state);
	} else {
		dump_shaders_a2xx(state);
	}

	if (!full_dump)
		return;

	/* dump ascii version of shader program: */
	ptr = next_sect(state, &sect_size);
	printf("\n#######################################################\n");
	printf("######## SHADER SRC: (size=%d)\n", sect_size);
	dump_ascii(ptr, sect_size);
	free(ptr);

	/* dump remaining sections (there shouldn't be any): */
	while (state->sz > 0) {
		ptr = next_sect(state, &sect_size);
		printf("######## section (size=%d)\n", sect_size);
		printf("as hex:\n");
		dump_hex(ptr, sect_size);
		printf("as float:\n");
		dump_float(ptr, sect_size);
		printf("as ascii:\n");
		dump_ascii(ptr, sect_size);
		free(ptr);
	}
}
value HTMLHeader::evaluate() const {
	if(valid_type())
		return(value("<!DOCTYPE html><html><body>"+x->evaluate().getStr_val()+"</body></html>", String));
	else
		return(value("ERROR:HTMLHeader", -1));
}
Beispiel #20
0
static off_t
_elf64_write(Elf *elf, char *outbuf, size_t len) {
    Elf64_Ehdr *ehdr;
    Elf64_Shdr *shdr;
    Elf_Scn *scn;
    Scn_Data *sd;
    Elf_Data src;
    Elf_Data dst;
    unsigned encode;

    elf_assert(len);
    elf_assert(elf->e_ehdr);
    ehdr = (Elf64_Ehdr*)elf->e_ehdr;
    encode = ehdr->e_ident[EI_DATA];

    src.d_buf = ehdr;
    src.d_type = ELF_T_EHDR;
    src.d_size = _msize(ELFCLASS64, _elf_version, ELF_T_EHDR);
    src.d_version = _elf_version;
    dst.d_buf = outbuf;
    dst.d_size = ehdr->e_ehsize;
    dst.d_version = ehdr->e_version;
    if (!elf64_xlatetof(&dst, &src, encode)) {
	return -1;
    }

    if (ehdr->e_phnum) {
	src.d_buf = elf->e_phdr;
	src.d_type = ELF_T_PHDR;
	src.d_size = ehdr->e_phnum * _msize(ELFCLASS64, _elf_version, ELF_T_PHDR);
	src.d_version = _elf_version;
	dst.d_buf = outbuf + ehdr->e_phoff;
	dst.d_size = ehdr->e_phnum * ehdr->e_phentsize;
	dst.d_version = ehdr->e_version;
	if (!elf64_xlatetof(&dst, &src, encode)) {
	    return -1;
	}
    }

    for (scn = elf->e_scn_1; scn; scn = scn->s_link) {
	elf_assert(scn->s_magic == SCN_MAGIC);
	elf_assert(scn->s_elf == elf);

	src.d_buf = &scn->s_uhdr;
	src.d_type = ELF_T_SHDR;
	src.d_size = _msize(ELFCLASS64, EV_CURRENT, ELF_T_SHDR);
	src.d_version = EV_CURRENT;
	dst.d_buf = outbuf + ehdr->e_shoff + scn->s_index * ehdr->e_shentsize;
	dst.d_size = ehdr->e_shentsize;
	dst.d_version = ehdr->e_version;
	if (!elf64_xlatetof(&dst, &src, encode)) {
	    return -1;
	}

	if (scn->s_index == SHN_UNDEF) {
	    continue;
	}
	shdr = &scn->s_shdr64;
	if (shdr->sh_type == SHT_NULL || shdr->sh_type == SHT_NOBITS) {
	    continue;
	}
	/* XXX: this is probably no longer necessary */
	if (scn->s_data_1 && !elf_getdata(scn, NULL)) {
	    return -1;
	}
	for (sd = scn->s_data_1; sd; sd = sd->sd_link) {
	    elf_assert(sd->sd_magic == DATA_MAGIC);
	    elf_assert(sd->sd_scn == scn);
	    src = sd->sd_data;
	    if (!src.d_size) {
		continue;
	    }
	    if (!src.d_buf) {
		seterr(ERROR_NULLBUF);
		return -1;
	    }
	    dst.d_buf = outbuf + shdr->sh_offset + src.d_off;
	    dst.d_size = src.d_size;
	    dst.d_version = ehdr->e_version;
	    if (valid_type(src.d_type)) {
		size_t tmp;

		tmp = _elf64_xltsize(&src, dst.d_version, ELFDATA2LSB, 1);
		if (tmp == (size_t)-1) {
		    return -1;
		}
		dst.d_size = tmp;
	    }
	    else {
		src.d_type = ELF_T_BYTE;
	    }
	    if (!elf64_xlatetof(&dst, &src, encode)) {
		return -1;
	    }
	}
    }

    /* cleanup */
    if (elf->e_readable && _elf_update_pointers(elf, outbuf, len)) {
	return -1;
    }
    /* NOTE: ehdr is no longer valid! */
    ehdr = (Elf64_Ehdr*)elf->e_ehdr; elf_assert(ehdr);
    elf->e_encoding = ehdr->e_ident[EI_DATA];
    elf->e_version = ehdr->e_ident[EI_VERSION];
    elf->e_elf_flags &= ~ELF_F_DIRTY;
    elf->e_ehdr_flags &= ~ELF_F_DIRTY;
    elf->e_phdr_flags &= ~ELF_F_DIRTY;
    for (scn = elf->e_scn_1; scn; scn = scn->s_link) {
	scn->s_scn_flags &= ~ELF_F_DIRTY;
	scn->s_shdr_flags &= ~ELF_F_DIRTY;
	for (sd = scn->s_data_1; sd; sd = sd->sd_link) {
	    sd->sd_data_flags &= ~ELF_F_DIRTY;
	}
	if (elf->e_readable) {
	    shdr = &scn->s_shdr64;
	    scn->s_type = shdr->sh_type;
	    scn->s_size = shdr->sh_size;
	    scn->s_offset = shdr->sh_offset;
	}
    }
    elf->e_size = len;
    return len;
}
int HTMLHeader::infer_type() const {
	if(valid_type()) 
		return(String);
	else
		return(-1);
}
Beispiel #22
0
/*
 * Set an individual arp entry
 */
static int
set(int argc, char **argv)
{
	struct sockaddr_in *addr;
	struct sockaddr_in *dst;	/* what are we looking for */
	struct sockaddr_dl *sdl;
	struct rt_msghdr *rtm;
	struct ether_addr *ea;
	char *host = argv[0], *eaddr = argv[1];
	struct sockaddr_dl sdl_m;

	argc -= 2;
	argv += 2;

	bzero(&sdl_m, sizeof(sdl_m));
	sdl_m.sdl_len = sizeof(sdl_m);
	sdl_m.sdl_family = AF_LINK;

	dst = getaddr(host);
	if (dst == NULL)
		return (1);
	doing_proxy = flags = expire_time = 0;
	while (argc-- > 0) {
		if (strncmp(argv[0], "temp", 4) == 0) {
			struct timespec tp;
			int max_age;
			size_t len = sizeof(max_age);

			clock_gettime(CLOCK_MONOTONIC, &tp);
			if (sysctlbyname("net.link.ether.inet.max_age",
			    &max_age, &len, NULL, 0) != 0)
				err(1, "sysctlbyname");
			expire_time = tp.tv_sec + max_age;
		} else if (strncmp(argv[0], "pub", 3) == 0) {
			flags |= RTF_ANNOUNCE;
			doing_proxy = 1;
			if (argc && strncmp(argv[1], "only", 3) == 0) {
				/*
				 * Compatibility: in pre FreeBSD 8 times
				 * the "only" keyword used to mean that
				 * an ARP entry should be announced, but
				 * not installed into routing table.
				 */
				argc--; argv++;
			}
		} else if (strncmp(argv[0], "blackhole", 9) == 0) {
			if (flags & RTF_REJECT) {
				printf("Choose one of blackhole or reject, not both.\n");
			}
			flags |= RTF_BLACKHOLE;
		} else if (strncmp(argv[0], "reject", 6) == 0) {
			if (flags & RTF_BLACKHOLE) {
				printf("Choose one of blackhole or reject, not both.\n");
			}
			flags |= RTF_REJECT;
		} else if (strncmp(argv[0], "trail", 5) == 0) {
			/* XXX deprecated and undocumented feature */
			printf("%s: Sending trailers is no longer supported\n",
				host);
		}
		argv++;
	}
	ea = (struct ether_addr *)LLADDR(&sdl_m);
	if (doing_proxy && !strcmp(eaddr, "auto")) {
		if (!get_ether_addr(dst->sin_addr.s_addr, ea)) {
			printf("no interface found for %s\n",
			       inet_ntoa(dst->sin_addr));
			return (1);
		}
		sdl_m.sdl_alen = ETHER_ADDR_LEN;
	} else {
		struct ether_addr *ea1 = ether_aton(eaddr);

		if (ea1 == NULL) {
			warnx("invalid Ethernet address '%s'", eaddr);
			return (1);
		} else {
			*ea = *ea1;
			sdl_m.sdl_alen = ETHER_ADDR_LEN;
		}
	}

	/*
	 * In the case a proxy-arp entry is being added for
	 * a remote end point, the RTF_ANNOUNCE flag in the 
	 * RTM_GET command is an indication to the kernel
	 * routing code that the interface associated with
	 * the prefix route covering the local end of the
	 * PPP link should be returned, on which ARP applies.
	 */
	rtm = rtmsg(RTM_GET, dst, &sdl_m);
	if (rtm == NULL) {
		warn("%s", host);
		return (1);
	}
	addr = (struct sockaddr_in *)(rtm + 1);
	sdl = (struct sockaddr_dl *)(SA_SIZE(addr) + (char *)addr);

	if ((sdl->sdl_family != AF_LINK) ||
	    (rtm->rtm_flags & RTF_GATEWAY) ||
	    !valid_type(sdl->sdl_type)) {
		printf("cannot intuit interface index and type for %s\n", host);
		return (1);
	}
	sdl_m.sdl_type = sdl->sdl_type;
	sdl_m.sdl_index = sdl->sdl_index;
	return (rtmsg(RTM_ADD, dst, &sdl_m) == NULL);
}
Beispiel #23
0
 double total_time(timer_type type=TOTAL_TIME) const
 {
     if (!valid_type(type))
         throw std::runtime_error("stopwatch: invalid timer type");
     return totals[type] + recent_time(type);
 }
Beispiel #24
0
static int
handle_string(void *ctx, const unsigned char *stringVal, unsigned int stringLen)
{
    struct parse_context *pctx = (struct parse_context *)ctx;
    var_type type;
    Var v;

    const char *val = (const char *)stringVal;
    size_t len = (size_t)stringLen;

    if (MODE_EMBEDDED_TYPES == pctx->mode
	&& TYPE_NONE != (type = valid_type(&val, &len))) {
	switch (type) {
	case TYPE_OBJ:
	    {
		char *p;
		if (*val == '#')
		    val++;
		v.type = TYPE_OBJ;
		v.v.num = strtol(val, &p, 10);
		break;
	    }
	case TYPE_INT:
	    {
		char *p;
		v = new_int(strtol(val, &p, 10));
		break;
	    }
	case TYPE_FLOAT:
	    {
		char *p;
		v = new_float(strtod(val, &p));
		break;
	    }
	case TYPE_ERR:
	    {
		char temp[len + 1];
		strncpy(temp, val, len);
		temp[len] = '\0';
		v.type = TYPE_ERR;
		int err = parse_error(temp);
		v.v.err = err > -1 ? err : E_NONE;
		break;
	    }
	case TYPE_STR:
	    {
		char temp[len + 1];
		strncpy(temp, val, len);
		temp[len] = '\0';
		v.type = TYPE_STR;
		v.v.str = str_dup(temp);
		break;
	    }
	default:
	    panic("Unsupported type in handle_string()");
	}
    } else {
	char temp[len + 1];
	strncpy(temp, val, len);
	temp[len] = '\0';
	v.type = TYPE_STR;
	v.v.str = str_dup(temp);
    }

    PUSH(pctx->top, v);
    return 1;
}
Beispiel #25
0
void dump_program(struct state *state)
{
	int i, sect_size;
	uint8_t *ptr;

	state->hdr = next_sect(state, &sect_size);

	printf("######## HEADER: (size %d)\n", sect_size);
	printf("\tsize:           %d\n", state->hdr->size);
	printf("\trevision:       %d\n", state->hdr->revision);
	printf("\tattributes:     %d\n", state->hdr->num_attribs);
	printf("\tuniforms:       %d\n", state->hdr->num_uniforms);
	printf("\tsamplers:       %d\n", state->hdr->num_samplers);
	printf("\tvaryings:       %d\n", state->hdr->num_varyings);
	printf("\tuniform blocks: %d\n", state->hdr->num_uniformblocks);
	if (full_dump)
		dump_hex((void *)state->hdr, sect_size);
	printf("\n");

	/* there seems to be two 0xba5eba11's at the end of the header, possibly
	 * with some other stuff between them:
	 */
	ptr = next_sect(state, &sect_size);
	if (full_dump) {
		dump_hex_ascii(ptr, sect_size);
	}

	for (i = 0; (i < state->hdr->num_attribs) && (state->sz > 0); i++) {
		state->attribs[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->attribs[i]->type_info)) {
			dump_hex_ascii(state->attribs[i], sect_size);
			state->attribs[i] = next_sect(state, &sect_size);
		}

		clean_ascii(state->attribs[i]->name, sect_size - 28);
		if (full_dump) {
			printf("######## ATTRIBUTE: (size %d)\n", sect_size);
			dump_attribute(state->attribs[i]);
			dump_hex((char *)state->attribs[i], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_uniforms) && (state->sz > 0); i++) {
		state->uniforms[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->uniforms[i]->type_info)) {
			dump_hex_ascii(state->uniforms[i], sect_size);
			state->uniforms[i] = next_sect(state, &sect_size);
		}

		if (is_uniform_v2(state->uniforms[i])) {
			clean_ascii(state->uniforms[i]->v2.name, sect_size - 53);
		} else {
			clean_ascii(state->uniforms[i]->v1.name, sect_size - 41);
		}

		if (full_dump) {
			printf("######## UNIFORM: (size %d)\n", sect_size);
			dump_uniform(state->uniforms[i]);
			dump_hex((char *)state->uniforms[i], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_samplers) && (state->sz > 0); i++) {
		state->samplers[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->samplers[i]->type_info)) {
			dump_hex_ascii(state->samplers[i], sect_size);
			state->samplers[i] = next_sect(state, &sect_size);
		}

		clean_ascii(state->samplers[i]->name, sect_size - 33);
		if (full_dump) {
			printf("######## SAMPLER: (size %d)\n", sect_size);
			dump_sampler(state->samplers[i]);
			dump_hex((char *)state->samplers[i], sect_size);
		}

	}

	// These sections show up after all of the other sampler sections
	// Loops through them all since we don't deal with them
	if (state->hdr->revision >= 7) {
		for (i = 0; (i < state->hdr->num_samplers) && (state->sz > 0); i++) {
			ptr = next_sect(state, &sect_size);
			dump_hex_ascii(ptr, sect_size);
		}
	}


	for (i = 0; (i < state->hdr->num_varyings) && (state->sz > 0); i++) {
		state->varyings[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->varyings[i]->type_info)) {
			dump_hex_ascii(state->varyings[i], sect_size);
			state->varyings[i] = next_sect(state, &sect_size);
		}

		clean_ascii(state->varyings[i]->name, sect_size - 16);
		if (full_dump) {
			printf("######## VARYING: (size %d)\n", sect_size);
			dump_varying(state->varyings[i]);
			dump_hex((char *)state->varyings[i], sect_size);
		}
	}

	/* not sure exactly which revision started this, but seems at least
	 * rev7 and rev8 implicitly include a new section for gl_FragColor:
	 */
	if (state->hdr->revision >= 7) {
		/* I guess only one? */
		state->outputs[0] = next_sect(state, &sect_size);

		clean_ascii(state->outputs[0]->name, sect_size - 32);
		if (full_dump) {
			printf("######## OUTPUT: (size %d)\n", sect_size);
			dump_output(state->outputs[0]);
			dump_hex((char *)state->outputs[0], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_uniformblocks) && (state->sz > 0); i++) {
		state->uniformblocks[i].header = next_sect(state, &sect_size);

		clean_ascii(state->uniformblocks[i].header->name, sect_size - 40);
		if (full_dump) {
			printf("######## UNIFORM BLOCK: (size %d)\n", sect_size);
			dump_uniformblock(state->uniformblocks[i].header);
			dump_hex((char *)state->uniformblocks[i].header, sect_size);
		}

		/*
		 * OpenGL ES 3.0 spec mandates a minimum amount of 16K members supported
		 * a330 supports a minimum of 65K
		 */
		state->uniformblocks[i].members = malloc(state->uniformblocks[i].header->num_members * sizeof(void*));

		int member = 0;
		for (member = 0; (member < state->uniformblocks[i].header->num_members) && (state->sz > 0); member++) {
			state->uniformblocks[i].members[member] = next_sect(state, &sect_size);

			clean_ascii(state->uniformblocks[i].members[member]->name, sect_size - 56);
			if (full_dump) {
				printf("######## UNIFORM BLOCK MEMBER: (size %d)\n", sect_size);
				dump_uniformblockmember(state->uniformblocks[i].members[member]);
				dump_hex((char *)state->uniformblocks[i].members[member], sect_size);
			}
		}
		/*
		 * Qualcomm saves the UBO members twice for each UBO
		 * Don't ask me why
		 */
		for (member = 0; (member < state->uniformblocks[i].header->num_members) && (state->sz > 0); member++) {
			state->uniformblocks[i].members[member] = next_sect(state, &sect_size);

			clean_ascii(state->uniformblocks[i].members[member]->name, sect_size - 56);
			if (full_dump) {
				printf("######## UNIFORM BLOCK MEMBER2: (size %d)\n", sect_size);
				dump_uniformblockmember(state->uniformblocks[i].members[member]);
				dump_hex((char *)state->uniformblocks[i].members[member], sect_size);
			}
		}
	}

	if (gpu_id >= 300) {
		dump_shaders_a3xx(state);
	} else {
		dump_shaders_a2xx(state);
	}

	if (!full_dump)
		return;

	/* dump ascii version of shader program: */
	ptr = next_sect(state, &sect_size);
	printf("\n#######################################################\n");
	printf("######## SHADER SRC: (size=%d)\n", sect_size);
	dump_ascii(ptr, sect_size);
	free(ptr);

	/* dump remaining sections (there shouldn't be any): */
	while (state->sz > 0) {
		ptr = next_sect(state, &sect_size);
		printf("######## section (size=%d)\n", sect_size);
		printf("as hex:\n");
		dump_hex(ptr, sect_size);
		printf("as float:\n");
		dump_float(ptr, sect_size);
		printf("as ascii:\n");
		dump_ascii(ptr, sect_size);
		free(ptr);
	}
	/* cleanup the uniform buffer members we allocated */
	if (state->hdr->num_uniformblocks > 0)
		free (state->uniformblocks[i].members);
}