Ejemplo n.º 1
0
void taint_host_memcpy(
        uint64_t env_ptr, uint64_t dest, uint64_t src,
        FastShad *greg, FastShad *gspec,
        uint64_t size, uint64_t labels_per_reg) {
    int64_t dest_offset = dest - env_ptr, src_offset = src - env_ptr;
    if (dest_offset < 0 || (size_t)dest_offset >= sizeof(CPUState) || 
            src_offset < 0 || (size_t)src_offset >= sizeof(CPUState)) {
        taint_log("hostmemcpy: irrelevant\n");
        return;
    }

    FastShad *shad_dest = NULL, *shad_src = NULL;
    uint64_t addr_dest = 0, addr_src = 0;

    find_offset(greg, gspec, (uint64_t)dest_offset, labels_per_reg,
            &shad_dest, &addr_dest);
    find_offset(greg, gspec, (uint64_t)src_offset, labels_per_reg,
            &shad_src, &addr_src);

#ifdef TAINTDEBUG
    taint_log("hostmemcpy: %lx[%lx+%lx] <- %lx[%lx] (offsets %lx <- %lx) (",
            (uint64_t)shad_dest, dest, size, (uint64_t)shad_src, src,
            dest_offset, src_offset);
    unsigned i;
    for (i = 0; i < size; i++) {
        taint_log("%lx, ", (uint64_t)shad_src->query(src + i));
    }
    taint_log(")\n");
#endif
    FastShad::copy(shad_dest, addr_dest, shad_src, addr_src, size);
}
Ejemplo n.º 2
0
void taint_host_memcpy(
        uint64_t env_ptr, uint64_t dest, uint64_t src,
        FastShad *greg, FastShad *gspec,
        uint64_t size, uint64_t labels_per_reg) {
    int64_t dest_offset = dest - env_ptr, src_offset = src - env_ptr;
    if (dest_offset < 0 || (size_t)dest_offset >= sizeof(CPUArchState) || 
            src_offset < 0 || (size_t)src_offset >= sizeof(CPUArchState)) {
        taint_log("hostmemcpy: irrelevant\n");
        return;
    }

    FastShad *shad_dest = NULL, *shad_src = NULL;
    uint64_t addr_dest = 0, addr_src = 0;

    find_offset(greg, gspec, (uint64_t)dest_offset, labels_per_reg,
            &shad_dest, &addr_dest);
    find_offset(greg, gspec, (uint64_t)src_offset, labels_per_reg,
            &shad_src, &addr_src);

    taint_log("hostmemcpy: %s[%lx+%lx] <- %s[%lx] (offsets %lx <- %lx) ",
            shad_dest->name(), dest, size, shad_src->name(), src,
            dest_offset, src_offset);
    taint_log_labels(shad_src, src, size);
    FastShad::copy(shad_dest, addr_dest, shad_src, addr_src, size);
}
Ejemplo n.º 3
0
bool LineListWrap::in_window(unsigned int pos) {
	if (pos == 0 && size() == 0) return true;
	wxASSERT(size());

	unsigned int index = find_offset(pos);
	return (index >= firstLoadedPos && index < lastLoadedPos);
}
Ejemplo n.º 4
0
// This should only be called on loads/stores from CPUArchState.
void taint_host_copy(
        uint64_t env_ptr, uint64_t addr,
        FastShad *llv, uint64_t llv_offset,
        FastShad *greg, FastShad *gspec,
        uint64_t size, uint64_t labels_per_reg, bool is_store) {
    int64_t offset = addr - env_ptr;
    if (is_irrelevant(offset)) {
        // Irrelevant
        taint_log("hostcopy: irrelevant\n");
        return;
    }

    FastShad *state_shad = NULL;
    uint64_t state_addr = 0;

    find_offset(greg, gspec, (uint64_t)offset, labels_per_reg,
            &state_shad, &state_addr);

    FastShad *shad_src = is_store ? llv : state_shad;
    uint64_t src = is_store ? llv_offset : state_addr;
    FastShad *shad_dest = is_store ? state_shad : llv;
    uint64_t dest = is_store ? state_addr : llv_offset;

    //taint_log("taint_host_copy\n");
    //taint_log("\tenv: %lx, addr: %lx, llv: %lx, offset: %lx\n", env_ptr, addr, llv_ptr, llv_offset);
    //taint_log("\tgreg: %lx, gspec: %lx, size: %lx, is_store: %u\n", greg_ptr, gspec_ptr, size, is_store);
    taint_log("hostcopy: %s[%lx+%lx] <- %s[%lx] (offset %lx) ",
            shad_dest->name(), dest, size, shad_src->name(), src, offset);
    taint_log_labels(shad_src, src, size);
    FastShad::copy(shad_dest, dest, shad_src, src, size);
}
Ejemplo n.º 5
0
/* computes the verity metadata offset for a file with size `f->size' */
static int find_verity_offset(fec_handle *f, uint64_t *offset)
{
    check(f);
    check(offset);

    return find_offset(f->data_size, 0, offset, get_verity_size,
                get_verity_size);
}
Ejemplo n.º 6
0
void* find_function(const char* name, unsigned int target, unsigned int base) {
	int i = 0;
	unsigned int found = 0;
	for(i = 0; i < sizeof(functions); i++) {
		if(!strcmp(functions[i][0], name)) {
			found = find_offset(target, base, 0x40000, functions[i]);
			break;
		}
	}

	return (void*) found;
}
Ejemplo n.º 7
0
void taint_host_delete(
        uint64_t env_ptr, uint64_t dest_addr,
        FastShad *greg, FastShad *gspec,
        uint64_t size, uint64_t labels_per_reg) {
    int64_t offset = dest_addr - env_ptr;

    if (offset < 0 || (size_t)offset >= sizeof(CPUState)) {
        taint_log("hostdel: irrelevant\n");
        return;
    }
    FastShad *shad = NULL;
    uint64_t dest = 0;

    find_offset(greg, gspec, offset, labels_per_reg, &shad, &dest);

    taint_log("hostdel: %lx[%lx+%lx]", (uint64_t)shad, dest, size);

    shad->remove(dest, size);
}
Ejemplo n.º 8
0
/* computes string to be appended to cstr so that src would be added to
 * the compression (best case, it's a 2-byte pointer to some offset within
 * cstr; worst case, it's all of src, converted to rfc3011 format).
 * The computed string is returned directly; its length is returned via retlen;
 * NULL and 0, respectively, are returned if an error occurs.
 */
uint8_t* FAST_FUNC dname_enc(const uint8_t *cstr, int clen, const char *src, int *retlen)
{
	uint8_t *d, *dname;
	int off;

	dname = convert_dname(src);
	if (dname == NULL) {
		*retlen = 0;
		return NULL;
	}

	for (d = dname; *d != 0; d += *d + 1) {
		off = find_offset(cstr, clen, d);
		if (off >= 0) {	/* found a match, add pointer and terminate string */
			*d++ = NS_CMPRSFLGS;
			*d = off;
			break;
		}
	}

	*retlen = d - dname + 1;
	return dname;
}
Ejemplo n.º 9
0
static gboolean
xmms_nulstripper_init (xmms_xform_t *xform)
{
	xmms_nulstripper_data_t *data;
	guint o;

	o = find_offset (xform);
	if (!o) {
		return FALSE;
	}

	data = g_new (xmms_nulstripper_data_t, 1);
	data->offset = o;

	xmms_xform_private_data_set (xform, data);

	xmms_xform_outdata_type_add (xform,
	                             XMMS_STREAM_TYPE_MIMETYPE,
	                             "application/octet-stream",
	                             XMMS_STREAM_TYPE_END);

	return TRUE;
}
Ejemplo n.º 10
0
/* Computes string to be appended to cstr so that src would be added to
 * the compression (best case, it's a 2-byte pointer to some offset within
 * cstr; worst case, it's all of src, converted to <4>host<3>com<0> format).
 * The computed string is returned directly; its length is returned via retlen;
 * NULL and 0, respectively, are returned if an error occurs.
 */
uint8_t* FAST_FUNC dname_enc(const uint8_t *cstr, int clen, const char *src, int *retlen)
{
	uint8_t *d, *dname;
	int off;

	dname = convert_dname(src);
	if (dname == NULL) {
		*retlen = 0;
		return NULL;
	}

	d = dname;
	while (*d) {
		if (cstr) {
			off = find_offset(cstr, clen, d);
			if (off >= 0) {	/* found a match, add pointer and return */
				*d++ = NS_CMPRSFLGS | (off >> 8);
				*d = off;
				break;
			}
		}
		d += *d + 1;
	}
Ejemplo n.º 11
0
SEXP extract_impl(SEXP x, SEXP index, SEXP missing) {
  if (!Rf_isVector(x)) {
    Rf_errorcall(R_NilValue, "`x` must be a vector (not a %s)",
      Rf_type2char(TYPEOF(x)));
  }

  if (TYPEOF(index) != VECSXP) {
    Rf_errorcall(R_NilValue, "`index` must be a vector (not a %s)",
      Rf_type2char(TYPEOF(index)));
  }

  int n = Rf_length(index);

  for (int i = 0; i < n; ++i) {
    SEXP index_i = VECTOR_ELT(index, i);

    int offset = find_offset(x, index_i, i);
    if (offset < 0)
      return missing;

    switch(TYPEOF(x)) {
    case NILSXP:  return missing;
    case LGLSXP:  x = Rf_ScalarLogical(LOGICAL(x)[offset]); break;
    case INTSXP:  x = Rf_ScalarInteger(INTEGER(x)[offset]); break;
    case REALSXP: x = Rf_ScalarReal(REAL(x)[offset]); break;
    case STRSXP:  x = Rf_ScalarString(STRING_ELT(x, offset)); break;
    case VECSXP:  x = VECTOR_ELT(x, offset); break;
    default:
      Rf_errorcall(R_NilValue,
        "Don't know how to index object of type %s at level %i",
        Rf_type2char(TYPEOF(x)), i + 1
      );
    }
  }

  return x;
}
Ejemplo n.º 12
0
// This should only be called on loads/stores from CPUState.
void taint_host_copy(
        uint64_t env_ptr, uint64_t addr,
        FastShad *llv, uint64_t llv_offset,
        FastShad *greg, FastShad *gspec,
        uint64_t size, uint64_t labels_per_reg, bool is_store) {
    int64_t offset = addr - env_ptr;
    if (offset < 0 || (size_t)offset >= sizeof(CPUState)) {
        // Irrelevant
        taint_log("hostcopy: irrelevant\n");
        return;
    }

    FastShad *state_shad = NULL;
    uint64_t state_addr = 0;

    find_offset(greg, gspec, (uint64_t)offset, labels_per_reg,
            &state_shad, &state_addr);

    FastShad *shad_src = is_store ? llv : state_shad;
    uint64_t src = is_store ? llv_offset : state_addr;
    FastShad *shad_dest = is_store ? state_shad : llv;
    uint64_t dest = is_store ? state_addr : llv_offset;

    //taint_log("taint_host_copy\n");
    //taint_log("\tenv: %lx, addr: %lx, llv: %lx, offset: %lx\n", env_ptr, addr, llv_ptr, llv_offset);
    //taint_log("\tgreg: %lx, gspec: %lx, size: %lx, is_store: %u\n", greg_ptr, gspec_ptr, size, is_store);
#ifdef TAINTDEBUG
    taint_log("hostcopy: %lx[%lx+%lx] <- %lx[%lx] (offset %lx) (",
            (uint64_t)shad_dest, dest, size, (uint64_t)shad_src, src, offset);
    unsigned i;
    for (i = 0; i < size; i++) {
        taint_log("%lx, ", (uint64_t)shad_src->query(src + i));
    }
    taint_log(")\n");
#endif
    FastShad::copy(shad_dest, dest, shad_src, src, size);
}
Ejemplo n.º 13
0
RelationSpec* sortmerge_join(RelationSpec* rSpec, RelationSpec* sSpec,
		const string &mainJoinAttr, const vector<string> &joinAttrOrder,
		size_t& recordCount, bool saveResult, bool printProcess) {
	// sort relations based on join attributes
	int roffset = rSpec->get_attr_idx(mainJoinAttr);
	int soffset = sSpec->get_attr_idx(mainJoinAttr);
	assert(roffset != -1);
	assert(soffset != -1);
	sort(rSpec->memDB.begin(), rSpec->memDB.end(), sorter(roffset));
	sort(sSpec->memDB.begin(), sSpec->memDB.end(), sorter(soffset));

	// Check whether there are other attributes (beside the mainJoinAttr) need to be joined at the same time
	vector<string> commonAttrs = sort_intersect(rSpec->attrNames,
			sSpec->attrNames);
	assert(commonAttrs.size() > 0);
	vector<string> otherAttrsToJoin;
	if (commonAttrs.size() == 1) {
		assert(commonAttrs.at(0) == mainJoinAttr);
	} else {
//		cerr << "Additional attributes: ";
		// make sure the mainJoinAttr is in the commonAttrs
		int mainIdx = find_offset(commonAttrs, mainJoinAttr);
		assert(mainIdx != -1);
		// get other attributes need to be joined
		for (int i = 0; i != commonAttrs.size(); i++) {
			string curCommonAttr = commonAttrs.at(i);
			if (i == mainIdx)
				continue;
			if (find_offset(joinAttrOrder, curCommonAttr) != -1) {
//				cerr << curCommonAttr << " ";
				otherAttrsToJoin.push_back(curCommonAttr);
			}
		}
//		cerr << ". ";
	}

	int otherSize = otherAttrsToJoin.size();
	int *rOffs = new int[otherSize];
	int *sOffs = new int[otherSize];
	for (int i = 0; i != otherAttrsToJoin.size(); i++) {
		string curAttr = otherAttrsToJoin.at(i);
		rOffs[i] = rSpec->get_attr_idx(curAttr);
		sOffs[i] = sSpec->get_attr_idx(curAttr);
	}

	// Create the joint relation specification file
	// The attributes of the joined relation is a distinct union of the attributes of the two input relations
	vector<string> nAttrNames = sort_union(rSpec->attrNames, sSpec->attrNames);
	int nAttrSize = nAttrNames.size();
	string nRelName = rSpec->relName + sSpec->relName;
	RelationSpec* nSpec = new RelationSpec(nRelName, "", nAttrNames, false);
	int* rAttrIdx = new int[nAttrSize];
	int* sAttrIdx = new int[nAttrSize];
	for (int i = 0; i != nAttrSize; i++) {
		string curAttr = nAttrNames.at(i);
		rAttrIdx[i] = find_offset(rSpec->attrNames, curAttr);
		sAttrIdx[i] = find_offset(sSpec->attrNames, curAttr);
	}

//	cerr << "Joined schema: ";
//	for (int i = 0; i != nAttrNames.size(); i++)
//		cerr << nAttrNames.at(i) << " ";
//	cerr << endl;

	// Here start the core part of the sort merge join algorithm
	bool firstRun = true;
	int rKey, sKey, rLastKey = -1, sLastIdx = 0;
	size_t rSize = rSpec->memDB.size();
	size_t sSize = sSpec->memDB.size();
	size_t rIdx = -1, sIdx = -1;
	int *rRecPtr, *sRecPtr, *nRecPtr;
	for (rIdx = 0; rIdx != rSize; rIdx++) {
		rRecPtr = rSpec->memDB[rIdx];
		rKey = *(rRecPtr + roffset);

		if (!firstRun && rKey != rLastKey) {
			sLastIdx = sIdx;
		}

		for (sIdx = sLastIdx; sIdx != sSize; sIdx++) {
			sRecPtr = sSpec->memDB[sIdx];
			sKey = *(sRecPtr + soffset);
			if (rKey == sKey) {
				// Before we move on, we need to check other common attributes are the same, too.
				if (!check_other_attrs(rRecPtr, sRecPtr, rOffs, sOffs,
						otherSize)) {
					continue;
				} else {
					// Making new records.
					recordCount++;
					if (saveResult) {
						nRecPtr = new int[nAttrSize];
						make_record(rRecPtr, sRecPtr, rAttrIdx, sAttrIdx,
								nAttrSize, nRecPtr);
						nSpec->memDB.push_back(nRecPtr);
					}
					if (printProcess) {
						if (recordCount % PRINT_NUM == 1)
							cerr << ".";
						if (recordCount % (PRINT_NUM * 20) == 1)
							cerr << endl;
					}
				}
			} else {
				if (rKey > sKey) {
					continue;
				} else { // rKey < sKey
					break;
				}
			}
		}
		rLastKey = rKey;
		firstRun = false;
	}
//	cerr << endl;
//	cerr << "Joining done. Records: " << recordCount << endl;

	//clean up
	delete[] rOffs;
	delete[] sOffs;
	delete[] rAttrIdx;
	delete[] sAttrIdx;

	return nSpec;
}
Ejemplo n.º 14
0
int main(int argc, char **argv)
{
    register int i;
    int tmp, tmp2;
    int err = 0;
    int dbl_order, flt_order, lng_order, int_order, shrt_order;

    /* Find native sizes */
    printf("\n/* Native machine sizes */\n");
    printf("#define NATIVE_DOUBLE %d\n", (nat_dbl = sizeof(double)));
    printf("#define NATIVE_FLOAT  %d\n", (nat_flt = sizeof(float)));
    printf("#define NATIVE_OFF_T  %d\n", (nat_off_t = sizeof(off_t)));
    printf("#define NATIVE_LONG   %d\n", (nat_lng = sizeof(long)));
    printf("#define NATIVE_INT    %d\n", (nat_int = sizeof(int)));
    printf("#define NATIVE_SHORT  %d\n", (nat_shrt = sizeof(short)));
    printf("#define NATIVE_CHAR   %d\n", (nat_char = sizeof(char)));

    /* Following code checks only if all assumptions are fulfilled */
    /* Check sizes */
    if (nat_dbl != PORT_DOUBLE) {
	fprintf(stderr, "ERROR, sizeof (double) != %d\n", PORT_DOUBLE);
	err = 1;
    }
    if (nat_flt != PORT_FLOAT) {
	fprintf(stderr, "ERROR, sizeof (float) != %d\n", PORT_FLOAT);
	err = 1;
    }
    /* port_off_t is variable */
    if (nat_lng < PORT_LONG) {
	fprintf(stderr, "ERROR, sizeof (long) < %d\n", PORT_LONG);
	err = 1;
    }
    if (nat_int < PORT_INT) {
	fprintf(stderr, "ERROR, sizeof (int) < %d\n", PORT_INT);
	err = 1;
    }
    if (nat_shrt < PORT_SHORT) {
	fprintf(stderr, "ERROR, sizeof (short) < %d\n", PORT_SHORT);
	err = 1;
    }
    if (nat_char != PORT_CHAR) {
	fprintf(stderr, "ERROR, sizeof (char) != %d\n", PORT_CHAR);
	err = 1;
    }

    /* Find for each byte in big endian test pattern (*_cmpr) 
     * offset of corresponding byte in machine native order.
     * Look if native byte order is little or big or some other (pdp)
     * endian.
     */
    /* Find double order */
    u.d = TEST_PATTERN;
    for (i = 0; i < PORT_DOUBLE; i++) {
	tmp = find_offset(u.c, dbl_cmpr[i], PORT_DOUBLE);
	if (-1 == tmp) {
	    fprintf(stderr, "ERROR, could not find '%x' in double\n",
		    dbl_cmpr[i]);
	    err = 1;
	}
	dbl_cnvrt[i] = tmp;
    }
    tmp = tmp2 = 1;
    for (i = 0; i < PORT_DOUBLE; i++) {
	if (dbl_cnvrt[i] != i)
	    tmp = 0;		/* isn't big endian */
	if (dbl_cnvrt[i] != (PORT_DOUBLE - i - 1))
	    tmp2 = 0;		/* isn't little endian */
    }
    if (tmp)
	dbl_order = ENDIAN_BIG;
    else if (tmp2)
	dbl_order = ENDIAN_LITTLE;
    else
	dbl_order = ENDIAN_OTHER;

    /* Find float order */
    u.f = TEST_PATTERN;
    for (i = 0; i < PORT_FLOAT; i++) {
	tmp = find_offset(u.c, flt_cmpr[i], PORT_FLOAT);
	if (-1 == tmp) {
	    fprintf(stderr, "ERROR, could not find '%x' in float\n",
		    flt_cmpr[i]);
	    err = 1;
	}
	flt_cnvrt[i] = tmp;
    }
    tmp = tmp2 = 1;
    for (i = 0; i < PORT_FLOAT; i++) {
	if (flt_cnvrt[i] != i)
	    tmp = 0;
	if (flt_cnvrt[i] != (PORT_FLOAT - i - 1))
	    tmp2 = 0;
    }
    if (tmp)
	flt_order = ENDIAN_BIG;
    else if (tmp2)
	flt_order = ENDIAN_LITTLE;
    else
	flt_order = ENDIAN_OTHER;

    /* Find off_t order */
    if (nat_off_t == 8)
	u.o = OFF_T_TEST;
    else
	u.o = LONG_TEST;
    for (i = 0; i < nat_off_t; i++) {
	tmp = find_offset(u.c, off_t_cmpr[i], nat_off_t);
	if (-1 == tmp) {
	    fprintf(stderr, "ERROR, could not find '%x' in off_t\n",
		    off_t_cmpr[i]);
	    err = 1;
	}
	off_t_cnvrt[i] = tmp;
    }
    tmp = tmp2 = 1;
    for (i = 0; i < nat_off_t; i++) {
	if (off_t_cnvrt[i] != (i + (nat_off_t - nat_off_t)))
	    tmp = 0;
	if (off_t_cnvrt[i] != (nat_off_t - i - 1))
	    tmp2 = 0;
    }
    if (tmp)
	off_t_order = ENDIAN_BIG;
    else if (tmp2)
	off_t_order = ENDIAN_LITTLE;
    else
	off_t_order = ENDIAN_OTHER;

    /* Find long order */
    u.l = LONG_TEST;
    for (i = 0; i < PORT_LONG; i++) {
	tmp = find_offset(u.c, lng_cmpr[i], nat_lng);
	if (-1 == tmp) {
	    fprintf(stderr, "ERROR, could not find '%x' in long\n",
		    lng_cmpr[i]);
	    err = 1;
	}
	lng_cnvrt[i] = tmp;
    }
    tmp = tmp2 = 1;
    for (i = 0; i < PORT_LONG; i++) {
	if (lng_cnvrt[i] != (i + (nat_lng - PORT_LONG)))
	    tmp = 0;
	if (lng_cnvrt[i] != (PORT_LONG - i - 1))
	    tmp2 = 0;
    }
    if (tmp)
	lng_order = ENDIAN_BIG;
    else if (tmp2)
	lng_order = ENDIAN_LITTLE;
    else
	lng_order = ENDIAN_OTHER;

    /* Find int order */
    u.i = INT_TEST;
    for (i = 0; i < PORT_INT; i++) {
	tmp = find_offset(u.c, int_cmpr[i], nat_int);
	if (-1 == tmp) {
	    fprintf(stderr, "ERROR, could not find '%x' in int\n",
		    int_cmpr[i]);
	    err = 1;
	}
	int_cnvrt[i] = tmp;
    }
    tmp = tmp2 = 1;
    for (i = 0; i < PORT_INT; i++) {
	if (int_cnvrt[i] != (i + (nat_lng - PORT_LONG)))
	    tmp = 0;
	if (int_cnvrt[i] != (PORT_INT - i - 1))
	    tmp2 = 0;
    }
    if (tmp)
	int_order = ENDIAN_BIG;
    else if (tmp2)
	int_order = ENDIAN_LITTLE;
    else
	int_order = ENDIAN_OTHER;

    /* Find short order */
    u.s = SHORT_TEST;
    for (i = 0; i < PORT_SHORT; i++) {
	tmp = find_offset(u.c, shrt_cmpr[i], nat_shrt);
	if (-1 == tmp) {
	    fprintf(stderr, "ERROR, could not find '%x' in shrt\n",
		    shrt_cmpr[i]);
	    err = 1;
	}
	shrt_cnvrt[i] = tmp;
    }
    tmp = tmp2 = 1;
    for (i = 0; i < PORT_SHORT; i++) {
	if (shrt_cnvrt[i] != (i + (nat_shrt - PORT_SHORT)))
	    tmp = 0;
	if (shrt_cnvrt[i] != (PORT_SHORT - i - 1))
	    tmp2 = 0;
    }
    if (tmp)
	shrt_order = ENDIAN_BIG;
    else if (tmp2)
	shrt_order = ENDIAN_LITTLE;
    else
	shrt_order = ENDIAN_OTHER;

    printf("\n/* Native machine byte orders */\n");
    printf("#define DOUBLE_ORDER %d\n", dbl_order);
    printf("#define FLOAT_ORDER  %d\n", flt_order);
    printf("#define OFF_T_ORDER  %d\n", off_t_order);
    printf("#define LONG_ORDER   %d\n", lng_order);
    printf("#define INT_ORDER    %d\n", int_order);
    printf("#define SHORT_ORDER  %d\n", shrt_order);

    printf("\n\n/* Translation matrices from big endian to native */\n");
    dumpflags();

    return (err);
}
Ejemplo n.º 15
0
static int
print_offset(void *data, size_t offset, char *toString)
{
    PSYMBOLFILE_HEADER RosSymHeader = (PSYMBOLFILE_HEADER)data;
    PROSSYM_ENTRY e = NULL;
    PROSSYM_ENTRY e2 = NULL;
    int bFileOffsetChanged = 0;
    char fmt[LINESIZE];
    char *Strings = (char *)data + RosSymHeader->StringsOffset;

    fmt[0] = '\0';
    e = find_offset(data, offset);
    if (opt_twice)
    {
        e2 = find_offset(data, offset - 1);

        if (e == e2)
            e2 = NULL;
        else
            summ.diff++;

        if (opt_Twice && e2)
        {
            e = e2;
            e2 = NULL;
            /* replaced (transparantly), but updated stats */
        }
    }
    if (e || e2)
    {
        strcpy(lastLine.file1, &Strings[e->FileOffset]);
        strcpy(lastLine.func1, &Strings[e->FunctionOffset]);
        lastLine.nr1 = e->SourceLine;
        sources_entry_create(&sources, lastLine.file1, SVN_PREFIX);
        lastLine.valid = 1;
        if (e2)
        {
            strcpy(lastLine.file2, &Strings[e2->FileOffset]);
            strcpy(lastLine.func2, &Strings[e2->FunctionOffset]);
            lastLine.nr2 = e2->SourceLine;
            sources_entry_create(&sources, lastLine.file2, SVN_PREFIX);
            bFileOffsetChanged = e->FileOffset != e2->FileOffset;
            if (e->FileOffset != e2->FileOffset || e->FunctionOffset != e2->FunctionOffset)
                summ.majordiff++;

            /*
             * - "%.0s" displays nothing, but processes argument
             * - bFileOffsetChanged implies always display 2nd SourceLine even if the same
             * - also for FunctionOffset
             */
            strcat(fmt, "%s");
            if (bFileOffsetChanged)
                strcat(fmt, "[%s]");
            else
                strcat(fmt, "%.0s");

            strcat(fmt, ":%u");
            if (e->SourceLine != e2->SourceLine || bFileOffsetChanged)
                strcat(fmt, "[%u]");
            else
                strcat(fmt, "%.0u");

            strcat(fmt, " (%s");
            if (e->FunctionOffset != e2->FunctionOffset || bFileOffsetChanged)
                strcat(fmt, "[%s])");
            else
                strcat(fmt, "%.0s)");

            if (toString)
            {   // put in toString if provided
                snprintf(toString, LINESIZE, fmt,
                    &Strings[e->FileOffset],
                    &Strings[e2->FileOffset],
                    (unsigned int)e->SourceLine,
                    (unsigned int)e2->SourceLine,
                    &Strings[e->FunctionOffset],
                    &Strings[e2->FunctionOffset]);
            }
            else
            {
                strcat(fmt, "\n");
                printf(fmt,
                    &Strings[e->FileOffset],
                    &Strings[e2->FileOffset],
                    (unsigned int)e->SourceLine,
                    (unsigned int)e2->SourceLine,
                    &Strings[e->FunctionOffset],
                    &Strings[e2->FunctionOffset]);
            }
        }
        else
        {
            if (toString)
            {   // put in toString if provided
                snprintf(toString, LINESIZE, "%s:%u (%s)",
                    &Strings[e->FileOffset],
                    (unsigned int)e->SourceLine,
                    &Strings[e->FunctionOffset]);
            }
            else
            {
                printf("%s:%u (%s)\n",
                    &Strings[e->FileOffset],
                    (unsigned int)e->SourceLine,
                    &Strings[e->FunctionOffset]);
            }
        }
        return 0;
    }
    return 1;
}
Ejemplo n.º 16
0
int read_circuit (FILE *circuit_fd)
{
    char c;
    int nerrs = 0;
    int fn, nofanin, i, j;
    int int_nog, int_nopi, int_nopo;
    int net_size;
    char symbol[MAXSTRING];
	register HASHPTR hp;
	register GATEPTR cg;
	GATEPTR pg;
	begnet=(GATEPTR)NULL;
	GATEPTR pfanin[MAXFIN+100];
	GATEPTR po_gates[MAXPO+100];
	
    int_nog = int_nopi = int_nopo = 0;
    nofanin=0;
    
    InitHash (symbol_tbl, HASHSIZE);
    
    while ((c = getsymbol (circuit_fd, symbol)) != EOF) {
			switch (c) {
				
				case '=' :
					hp = Find_and_Insert_Hash (symbol_tbl, HASHSIZE, symbol, 0);
					//printf("in read: hp =  %s \n", symbol);
					
					if ((cg = hp->pnode) == NULL) {
						cg = (GATETYPE *)xmalloc(sizeof(GATETYPE)); 
						hp->pnode = cg;
						cg->symbol = hp;
						cg->next = begnet;
						begnet = cg;
					}
				break;
					
				case '(' :
					if ((fn = gatetype (symbol)) < 0) {
						fprintf (stderr, "Error: Gate type %s is not valid\n", symbol);
						return(-1);
					}
				break;
				
				case ',' :             
					hp = Find_and_Insert_Hash (symbol_tbl, HASHSIZE, symbol, 0);
					if ((pg = hp->pnode) == NULL) {
						pg = (GATETYPE *)xmalloc(sizeof(GATETYPE));
						hp->pnode = pg;
						pg->symbol = hp;
						pg->index = (-1);
						pg->next = begnet;
						begnet = pg;
					}
					pfanin[nofanin++] = pg;
				break;
					
				case ')':				
					hp = Find_and_Insert_Hash (symbol_tbl, HASHSIZE, symbol, 0);
					if ((pg = hp->pnode) == NULL) {
						pg = (GATETYPE *)xmalloc(sizeof(GATETYPE));
						hp->pnode = pg;
						pg->symbol = hp; 
						pg->index = (-1);
						pg->next = begnet;
						begnet = pg;
					}		
				
				    switch(fn) {
						
						case PI:
							int_nopi++;
							pg->index = int_nog++;
							pg->ninput = 0;
							pg->inlis=(GATEPTR *)NULL;
							pg->fn = PI;
							pg->noutput = 0;
							pg->outlis = (GATEPTR *)NULL;
						break;
						
						case PO:
							po_gates[int_nopo++] = pg;
						break;
						
						default:
							pfanin[nofanin++] = pg;

							if (cg == NULL) {
								fprintf(stderr,"Error: Syntax error in the circuit file\n");
								return(-1);
							}
						
							cg->index = int_nog++;
							cg->fn = fn;
							if ((cg->ninput = nofanin) == 0) cg->inlis = NULL;
							else { cg->inlis = (GATEPTR *)xmalloc(cg->ninput*(sizeof(GATEPTR)));
							}
							for (i = 0; i<nofanin; i++) cg->inlis[i] = pfanin[i];
							cg->noutput = 0;
							cg->outlis = (GATEPTR *)NULL;
							
							nofanin = 0;
							cg = (GATEPTR) NULL;
							break; 
					}		
			}
    }
    
    
    
    net_size = int_nog + int_nopo;
    //printf(" net = %d\n",net_size);
    
    net = (GATEPTR *)xmalloc(net_size*(sizeof(GATEPTR)));
    primaryin = (int *)xmalloc(int_nopi*(sizeof(int)));
    primaryout = (int *)xmalloc(int_nopo*(sizeof(int)));
    
    nog=nopi=nopo=0;
    
    for (cg = begnet; cg != NULL; cg = cg->next) {
		if (cg->index < 0) {
			fprintf(stderr,"Error: floating net %s\n",cg->symbol->symbol);
			fprintf(stderr, "Workaround. You have to take one of the two actions:\n");
			fprintf(stderr, "   1. Remove all the floating input and associated gates, or\n");
			fprintf(stderr, "   2. Make each floating input a primary output.\n");
			return(-1);
		}
		
		net[cg->index] = cg;
		nog++;

    }
   
   
	for (i = nog; i<net_size; i++) net[i] = (GATEPTR)NULL;

    if (nog != int_nog) {
		fprintf(stderr,"Error in read_circuit\n");
		return(-1);
    }
    

	for (i = 0; i<nog; i++) {
		cg = net[i];

		for (j = 0; j<cg->ninput; j++) cg->inlis[j]->noutput++;

		if (cg->fn == PI) primaryin[nopi++] = i; 
    }
    
    
    for (i = 0; i<int_nopo; i++) primaryout[nopo++] = po_gates[i]->index;
    
    
    for (i = 0; i<nog; i++) {
		cg = net[i];
		if (cg->noutput>0) {
		    cg->outlis = (GATEPTR *)xmalloc(cg->noutput*(sizeof(GATEPTR)));	 
    	    //maxfout = MAX(maxfout,cg->noutput);
    	    //cg->noutput= 0;
        }
    }


    for (i = 0; i<nog; i++) net[i]->noutput = 0;

    
	for (i = 0; i<nog; i++) {
		cg = net[i];

		for (j = 0; j<cg->ninput; j++) {
			cg->inlis[j]->outlis[(cg->inlis[j]->noutput)++] = cg;
			//pg = cg->inlis[j];
			//pg->outlis[pg->noutput++] = cg;
		}
	}
		
	
	for (i = 0; i<nog; i++) {
		cg = net[i];

		//<-----------------------------------------
		cg->offset = 0;
		cg->offset = find_offset(cg);
		//printf(" i have offset %d\n",cg->offset);
		if (cg->noutput > 0) continue;
		
		for (j = 0; j<int_nopo; j++)
			if (cg == po_gates[j]) break;

		if (j == int_nopo) {
			fprintf(stderr, "Error: floating output '%s' detected!\n", cg->symbol->symbol); 
			nerrs++;
		}
	}
	 
   
	if (nerrs > 0) {
		fprintf(stderr, "Workaround. You have to take one of the two actions:\n");
		fprintf(stderr, "   1. Remove all the floating output and associated gates, or\n");
		fprintf(stderr, "   2. Make each floating output a primary output.\n");
		return(-1);
	}

	if (int_nog == nog) return(nog);
	else return(-1);
}