void kp_cdata_ptr_set(ktap_state_t *ks, ktap_cdata_t *cd, ktap_val_t *key, ktap_val_t *val) { ktap_number idx; csymbol *cs; size_t size; char *addr; if (!is_number(key)) { kp_error(ks, "array index should be number\n"); return; } idx = nvalue(key); if (unlikely(idx < 0 || (cd_ptr_nmemb(cd) >= 0 && idx >= cd_ptr_nmemb(cd)))) { kp_error(ks, "array index out of bound\n"); return; } cs = csym_ptr_deref(ks, cd_csym(ks, cd)); if (kp_cdata_type_match(ks, cs, val)) { kp_error(ks, "array member should be %s type\n", csym_name(cs)); return; } size = csym_size(ks, cs); addr = cd_ptr(cd); addr += size * idx; kp_cdata_unpack(ks, addr, cs, val); }
void kp_cdata_record_set(ktap_state_t *ks, ktap_cdata_t *cd, ktap_val_t *key, ktap_val_t *val) { const char *mb_name; csymbol *cs, *mb_cs; csymbol_struct *csst; struct_member *mb; char *addr; if (!is_shrstring(key)) { kp_error(ks, "struct member name should be string\n"); return; } mb_name = svalue(key); cs = cd_csym(ks, cd); csst = csym_struct(cs); mb = csymst_mb_by_name(ks, csst, mb_name); if (mb == NULL) { kp_error(ks, "struct member %s doesn't exist\n", mb_name); return; } mb_cs = id_to_csym(ks, mb->id); if (kp_cdata_type_match(ks, mb_cs, val)) { kp_error(ks, "struct member should be %s type\n", csym_name(mb_cs)); return; } addr = cd_record(cd); addr += csym_record_mb_offset_by_name(ks, cs, mb_name); kp_cdata_unpack(ks, addr, mb_cs, val); }
static void ffi_unpack(ktap_state_t *ks, char *dst, csymbol_func *csf, int idx, int align) { StkId arg = kp_arg(ks, idx + 1); csymbol *cs = ffi_get_arg_csym(ks, csf, idx); size_t size = csym_size(ks, cs); /* initialize the destination section */ memset(dst, 0, ALIGN(size, align)); kp_cdata_unpack(ks, dst, cs, arg); }