static struct ptunit_result copy_self(struct image_fixture *ifix) { uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; status = pt_image_copy(&ifix->image, &ifix->image); ptu_int_eq(status, 2); status = pt_image_read(&ifix->image, buffer, 2, &ifix->asid[1], 0x2003ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], 0x03); ptu_uint_eq(buffer[1], 0x04); ptu_uint_eq(buffer[2], 0xcc); return ptu_passed(); }
static struct ptunit_result copy_empty(struct image_fixture *ifix) { struct pt_asid asid; uint8_t buffer[] = { 0xcc, 0xcc }; int status; pt_asid_init(&asid); status = pt_image_copy(&ifix->copy, &ifix->image); ptu_int_eq(status, 0); status = pt_image_read(&ifix->copy, 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 copy_duplicate(struct image_fixture *ifix) { uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; status = pt_image_add(&ifix->copy, &ifix->section[1], &ifix->asid[1], 0x2000ull); ptu_int_eq(status, 0); status = pt_image_copy(&ifix->copy, &ifix->image); ptu_int_eq(status, 1); status = pt_image_read(&ifix->copy, buffer, 2, &ifix->asid[1], 0x2003ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], 0x03); ptu_uint_eq(buffer[1], 0x04); ptu_uint_eq(buffer[2], 0xcc); return ptu_passed(); }
static int pt_sb_add_context_by_pid(struct pt_sb_context **pcontext, struct pt_sb_session *session, uint32_t pid) { struct pt_sb_context *context; struct pt_image *kernel; char iname[16]; int errcode; if (!pcontext || !session) return -pte_invalid; kernel = pt_sb_kernel_image(session); if (!kernel) return -pte_internal; memset(iname, 0, sizeof(iname)); (void) snprintf(iname, sizeof(iname), "pid-%x", pid); context = pt_sb_ctx_alloc(iname); if (!context) return -pte_nomem; errcode = pt_image_copy(context->image, kernel); if (errcode < 0) { (void) pt_sb_ctx_put(context); return errcode; } context->next = session->contexts; context->pid = pid; session->contexts = context; *pcontext = context; return 0; }