static void zend_hash_persist_calc(HashTable *ht, void (*pPersistElement)(zval *pElement)) { uint idx; Bucket *p; if (!(ht->u.flags & HASH_FLAG_INITIALIZED)) { return; } if (ht->u.flags & HASH_FLAG_PACKED) { ADD_SIZE(sizeof(Bucket) * ht->nNumUsed); } else { ADD_SIZE(sizeof(Bucket) * ht->nNumUsed + sizeof(uint32_t) * ht->nTableSize); } for (idx = 0; idx < ht->nNumUsed; idx++) { p = ht->arData + idx; if (Z_TYPE(p->val) == IS_UNDEF) continue; /* persist bucket and key */ if (p->key) { zend_uchar flags = GC_FLAGS(p->key) & ~ (IS_STR_PERSISTENT | IS_STR_INTERNED | IS_STR_PERMANENT); ADD_INTERNED_STRING(p->key, 1); GC_FLAGS(p->key) |= flags; } pPersistElement(&p->val); } }
static void zend_persist_ast_calc(zend_ast *ast) { uint32_t i; if (ast->kind == ZEND_AST_ZVAL) { ADD_SIZE(sizeof(zend_ast_zval)); zend_persist_zval_calc(zend_ast_get_zval(ast)); } else if (zend_ast_is_list(ast)) { zend_ast_list *list = zend_ast_get_list(ast); ADD_SIZE(sizeof(zend_ast_list) - sizeof(zend_ast *) + sizeof(zend_ast *) * list->children); for (i = 0; i < list->children; i++) { if (list->child[i]) { zend_persist_ast_calc(list->child[i]); } } } else { uint32_t children = zend_ast_get_num_children(ast); ADD_SIZE(sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children); for (i = 0; i < children; i++) { if (ast->child[i]) { zend_persist_ast_calc(ast->child[i]); } } } }
static int anoubisd_msg_upgrade_size(const char *buf, int buflen) { struct anoubisd_msg_upgrade *msg; DECLARE_SIZE(); CAST(msg, buf, buflen); SHIFT_FIELD(msg, chunk, buf, buflen); if (msg->upgradetype != ANOUBISD_UPGRADE_NOTIFY) CHECK_LEN(msg->chunksize, buflen); switch(msg->upgradetype) { case ANOUBISD_UPGRADE_OK: if (msg->chunksize != 1) return -1; ADD_SIZE(msg->chunksize); break; case ANOUBISD_UPGRADE_NOTIFY: /* * chunksize is the number of upgraded files. No data in * in chunk. */ break; case ANOUBISD_UPGRADE_CHUNK: if (msg->chunksize) STRINGS(buf, buflen); break; default: if (msg->chunksize) return -1; } RETURN_SIZE(); }
static int anoubisd_msg_polreply_size(const char *buf, int buflen) { DECLARE_SIZE(); struct anoubisd_msg_polreply *reply; CAST(reply, buf, buflen); SHIFT_FIELD(reply, data, buf, buflen); CHECK_LEN(reply->len, buflen); ADD_SIZE(reply->len); RETURN_SIZE(); }
static void zend_persist_zval_calc(zval *z) { zend_uchar flags; uint size; switch (Z_TYPE_P(z)) { case IS_STRING: case IS_CONSTANT: flags = Z_GC_FLAGS_P(z) & ~ (IS_STR_PERSISTENT | IS_STR_INTERNED | IS_STR_PERMANENT); ADD_INTERNED_STRING(Z_STR_P(z), 0); if (!Z_REFCOUNTED_P(z)) { Z_TYPE_FLAGS_P(z) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE); } Z_GC_FLAGS_P(z) |= flags; break; case IS_ARRAY: size = zend_shared_memdup_size(Z_ARR_P(z), sizeof(zend_array)); if (size) { ADD_SIZE(size); zend_hash_persist_calc(Z_ARRVAL_P(z), zend_persist_zval_calc); } break; case IS_REFERENCE: size = zend_shared_memdup_size(Z_REF_P(z), sizeof(zend_reference)); if (size) { ADD_SIZE(size); zend_persist_zval_calc(Z_REFVAL_P(z)); } break; case IS_CONSTANT_AST: size = zend_shared_memdup_size(Z_AST_P(z), sizeof(zend_ast_ref)); if (size) { ADD_SIZE(size); zend_persist_ast_calc(Z_ASTVAL_P(z)); } break; } }
static int anoubisd_msg_eventask_size(const char *buf, int buflen) { struct anoubisd_msg_eventask *msg; struct buf_offset offs[5]; int i, j, total = 0; DECLARE_SIZE(); CAST(msg, buf, buflen); /* Detect offset overlaps */ ADDOFFSET(0, csum); ADDOFFSET(1, path); ADDOFFSET(2, ctxcsum); ADDOFFSET(3, ctxpath); ADDOFFSET(4, ev); for (i=0; i<5; ++i) { int s1, e1; if (offs[i].len == 0) continue; s1 = offs[i].off; e1 = s1 + offs[i].len; if (e1 > total) total = e1; for (j=0; j<i; ++j) { int s2, e2; if (offs[j].len == 0) continue; s2 = offs[j].off; e2 = s2 + offs[j].len; if (s2 < e1 && s1 < e2) return -1; } } SHIFT_FIELD(msg, payload, buf, buflen); if (total > buflen) return -1; ADD_SIZE(total); if (msg->pathlen) CHECK_STRING(buf+msg->pathoff, msg->pathlen); if (msg->ctxpathlen) CHECK_STRING(buf+msg->ctxpathoff, msg->ctxpathlen); if (msg->evlen) { int size = eventdev_hdr_size(buf+msg->evoff, msg->evlen); CHECK_SIZE(size); } RETURN_SIZE(); }
/* * Return the size of an anoubisd_msg_polrequest message. */ static int anoubisd_msg_polrequest_size(const char *buf, int buflen) { DECLARE_SIZE(); struct anoubisd_msg_polrequest *req; CAST(req, buf, buflen); SHIFT_FIELD(req, data, buf, buflen); CHECK_LEN(req->len, buflen); ADD_SIZE(req->len); if (verify_polrequest(buf, req->len, req->flags) < 0) return -1; RETURN_SIZE(); }
static int anoubisd_msg_csumop_size(const char *buf, int buflen) { struct anoubisd_msg_csumop *msg; int sfsoplen; DECLARE_SIZE() CAST(msg, buf, buflen); SHIFT_FIELD(msg, msg, buf, buflen); ADD_SIZE(msg->len); sfsoplen = amsg_sfs_checksumop_size(buf, buflen); if (sfsoplen < 0 || sfsoplen > msg->len || sfsoplen > buflen) return -1; RETURN_SIZE(); }
static void zend_hash_persist_calc(HashTable *ht, void (*pPersistElement)(zval *pElement)) { uint idx; Bucket *p; if (!(ht->u.flags & HASH_FLAG_INITIALIZED)) { return; } if (!(ht->u.flags & HASH_FLAG_PACKED) && ht->nNumUsed < -(int32_t)ht->nTableMask / 2) { /* compact table */ int32_t hash_size = -(int32_t)ht->nTableMask; while (hash_size >> 1 > ht->nNumUsed) { hash_size >>= 1; } ADD_SIZE(hash_size * sizeof(uint32_t) + ht->nNumUsed * sizeof(Bucket)); } else {
static void zend_persist_class_entry_calc(zval *zv) { zend_class_entry *ce = Z_PTR_P(zv); if (ce->type == ZEND_USER_CLASS) { ADD_ARENA_SIZE(sizeof(zend_class_entry)); ADD_INTERNED_STRING(ce->name, 0); zend_hash_persist_calc(&ce->function_table, zend_persist_op_array_calc); if (ce->default_properties_table) { int i; ADD_SIZE(sizeof(zval) * ce->default_properties_count); for (i = 0; i < ce->default_properties_count; i++) { zend_persist_zval_calc(&ce->default_properties_table[i]); } } if (ce->default_static_members_table) { int i; ADD_SIZE(sizeof(zval) * ce->default_static_members_count); for (i = 0; i < ce->default_static_members_count; i++) { zend_persist_zval_calc(&ce->default_static_members_table[i]); } } zend_hash_persist_calc(&ce->constants_table, zend_persist_zval_calc); if (ZEND_CE_FILENAME(ce)) { ADD_STRING(ZEND_CE_FILENAME(ce)); } if (ZCG(accel_directives).save_comments && ZEND_CE_DOC_COMMENT(ce)) { ADD_STRING(ZEND_CE_DOC_COMMENT(ce)); } zend_hash_persist_calc(&ce->properties_info, zend_persist_property_info_calc); if (ce->trait_aliases) { int i = 0; while (ce->trait_aliases[i]) { if (ce->trait_aliases[i]->trait_method) { if (ce->trait_aliases[i]->trait_method->method_name) { ADD_INTERNED_STRING(ce->trait_aliases[i]->trait_method->method_name, 0); } if (ce->trait_aliases[i]->trait_method->class_name) { ADD_INTERNED_STRING(ce->trait_aliases[i]->trait_method->class_name, 0); } ADD_SIZE(sizeof(zend_trait_method_reference)); } if (ce->trait_aliases[i]->alias) { ADD_INTERNED_STRING(ce->trait_aliases[i]->alias, 0); } ADD_SIZE(sizeof(zend_trait_alias)); i++; } ADD_SIZE(sizeof(zend_trait_alias*) * (i + 1)); } if (ce->trait_precedences) { int i = 0; while (ce->trait_precedences[i]) { ADD_INTERNED_STRING(ce->trait_precedences[i]->trait_method->method_name, 0); ADD_INTERNED_STRING(ce->trait_precedences[i]->trait_method->class_name, 0); ADD_SIZE(sizeof(zend_trait_method_reference)); if (ce->trait_precedences[i]->exclude_from_classes) { int j = 0; while (ce->trait_precedences[i]->exclude_from_classes[j].class_name) { ADD_INTERNED_STRING(ce->trait_precedences[i]->exclude_from_classes[j].class_name, 0); j++; } ADD_SIZE(sizeof(zend_class_entry*) * (j + 1)); } ADD_SIZE(sizeof(zend_trait_precedence)); i++; } ADD_SIZE(sizeof(zend_trait_precedence*) * (i + 1)); } } }