예제 #1
0
static struct ptunit_result match_cr3(void)
{
	struct pt_asid lhs, rhs;
	int errcode;

	pt_asid_init(&lhs);
	pt_asid_init(&rhs);

	lhs.cr3 = 0x2300ull;
	rhs.cr3 = 0x2300ull;

	errcode = pt_asid_match(&lhs, &rhs);
	ptu_int_eq(errcode, 1);

	return ptu_passed();
}
예제 #2
0
static struct ptunit_result match_vmcs_false(void)
{
	struct pt_asid lhs, rhs;
	int errcode;

	pt_asid_init(&lhs);
	pt_asid_init(&rhs);

	lhs.vmcs = 0x42000ull;
	rhs.vmcs = 0x23000ull;

	errcode = pt_asid_match(&lhs, &rhs);
	ptu_int_eq(errcode, 0);

	return ptu_passed();
}
예제 #3
0
int pt_asid_from_user(struct pt_asid *asid, const struct pt_asid *user)
{
	if (!asid)
		return -pte_internal;

	pt_asid_init(asid);

	if (user) {
		size_t size;

		size = user->size;

		/* Ignore fields in the user's asid we don't know. */
		if (sizeof(*asid) < size)
			size = sizeof(*asid);

		/* Copy (portions of) the user's asid. */
		memcpy(asid, user, size);

		/* We copied user's size - fix it. */
		asid->size = sizeof(*asid);
	}

	return 0;
}
예제 #4
0
struct ptunit_result ifix_init(struct image_fixture *ifix)
{
	pt_image_init(&ifix->image, NULL);
	pt_image_init(&ifix->copy, NULL);

	pt_init_section(&ifix->section[0], "file-0", &ifix->status[0],
			&ifix->mapping[0]);
	pt_init_section(&ifix->section[1], "file-1", &ifix->status[1],
			&ifix->mapping[1]);
	pt_init_section(&ifix->section[2], "file-2", &ifix->status[2],
			&ifix->mapping[2]);

	pt_asid_init(&ifix->asid[0]);
	ifix->asid[0].cr3 = 0xa000;

	pt_asid_init(&ifix->asid[1]);
	ifix->asid[1].cr3 = 0xb000;

	pt_asid_init(&ifix->asid[2]);
	ifix->asid[2].cr3 = 0xc000;

	return ptu_passed();
}
예제 #5
0
void pt_msec_init(struct pt_mapped_section *msec, struct pt_section *section,
		  const struct pt_asid *asid, uint64_t vaddr)
{
	if (!msec)
		return;

	msec->section = section;
	msec->vaddr = vaddr;

	if (asid)
		msec->asid = *asid;
	else
		pt_asid_init(&msec->asid);
}
예제 #6
0
static struct ptunit_result from_user_null(void)
{
	struct pt_asid user;
	int errcode;

	pt_asid_init(&user);

	errcode = pt_asid_from_user(NULL, NULL);
	ptu_int_eq(errcode, -pte_internal);

	errcode = pt_asid_from_user(NULL, &user);
	ptu_int_eq(errcode, -pte_internal);

	return ptu_passed();
}
static struct ptunit_result read_nomem_asid(struct section_fixture *sfix)
{
	struct pt_asid asid;
	uint8_t buffer[] = { 0xcc };
	int status;

	pt_asid_init(&asid);
	asid.cr3 = 0xcece00ull;

	status = pt_msec_read(&sfix->msec, buffer, 2, &asid, sfix->vaddr);
	ptu_int_eq(status, -pte_nomap);
	ptu_uint_eq(buffer[0], 0xcc);

	return ptu_passed();
}
예제 #8
0
static struct ptunit_result read_empty(struct image_fixture *ifix)
{
	struct pt_asid asid;
	uint8_t buffer[] = { 0xcc, 0xcc };
	int status;

	pt_asid_init(&asid);

	status = pt_image_read(&ifix->image, buffer, sizeof(buffer), &asid,
			       0x1000ull);
	ptu_int_eq(status, -pte_nomap);
	ptu_uint_eq(buffer[0], 0xcc);
	ptu_uint_eq(buffer[1], 0xcc);

	return ptu_passed();
}
static struct ptunit_result read_default_asid(struct section_fixture *sfix)
{
	struct pt_asid asid;
	uint8_t buffer[] = { 0xcc, 0xcc, 0xcc };
	int status;

	pt_asid_init(&asid);

	status = pt_msec_read(&sfix->msec, buffer, 2, &asid, sfix->vaddr);
	ptu_int_eq(status, 2);
	ptu_uint_eq(buffer[0], sfix->mapping.content[0]);
	ptu_uint_eq(buffer[1], sfix->mapping.content[1]);
	ptu_uint_eq(buffer[2], 0xcc);

	return ptu_passed();
}
예제 #10
0
static void pt_insn_reset(struct pt_insn_decoder *decoder)
{
	if (!decoder)
		return;

	decoder->mode = ptem_unknown;
	decoder->ip = 0ull;
	decoder->last_disable_ip = 0ull;
	decoder->status = 0;
	decoder->enabled = 0;
	decoder->process_event = 0;
	decoder->speculative = 0;
	decoder->event_may_change_ip = 1;

	pt_retstack_init(&decoder->retstack);
	pt_asid_init(&decoder->asid);
}
static struct ptunit_result asid(void)
{
	struct pt_mapped_section msec;
	struct pt_asid asid;
	const struct pt_asid *pasid;

	pt_asid_init(&asid);
	asid.cr3 = 0xa00;

	pt_msec_init(&msec, NULL, &asid, 0ull);

	pasid = pt_msec_asid(&msec);
	ptu_uint_eq(pasid->size, asid.size);
	ptu_uint_eq(pasid->cr3, asid.cr3);

	return ptu_passed();
}
예제 #12
0
static struct ptunit_result match_null(void)
{
	struct pt_asid asid;
	int errcode;

	pt_asid_init(&asid);

	errcode = pt_asid_match(NULL, NULL);
	ptu_int_eq(errcode, -pte_internal);

	errcode = pt_asid_match(NULL, &asid);
	ptu_int_eq(errcode, -pte_internal);

	errcode = pt_asid_match(&asid, NULL);
	ptu_int_eq(errcode, -pte_internal);

	return ptu_passed();
}
static struct ptunit_result sfix_init(struct section_fixture *sfix)
{
	uint8_t i;

	sfix->section.size = sfix->mapping.size = sizeof(sfix->mapping.content);
	sfix->vaddr = 0x1000;

	for (i = 0; i < sfix->mapping.size; ++i)
		sfix->mapping.content[i] = i;

	sfix->section.status = &sfix->mapping;
	sfix->section.mapping = NULL;

	pt_asid_init(&sfix->asid);
	sfix->asid.cr3 = 0x4200ull;

	pt_msec_init(&sfix->msec, &sfix->section, &sfix->asid, sfix->vaddr);

	return ptu_passed();
}
예제 #14
0
static struct ptunit_result fini(void)
{
	struct ifix_mapping mapping;
	struct ifix_status status;
	struct pt_section section;
	struct pt_image image;
	struct pt_asid asid;
	int errcode;

	pt_asid_init(&asid);
	pt_init_section(&section, NULL, &status, &mapping);

	pt_image_init(&image, NULL);
	errcode = pt_image_add(&image, &section, &asid, 0x0ull);
	ptu_int_eq(errcode, 0);

	pt_image_fini(&image);
	ptu_int_eq(section.ucount, 0);
	ptu_int_eq(section.mcount, 0);
	ptu_int_eq(status.deleted, 1);

	return ptu_passed();
}