12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092 |
- /*
- +----------------------------------------------------------------------+
- | Zend JIT |
- +----------------------------------------------------------------------+
- | Copyright (c) The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.01 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available through the world-wide-web at the following url: |
- | https://www.php.net/license/3_01.txt |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Dmitry Stogov <dmitry@php.net> |
- +----------------------------------------------------------------------+
- */
- #include "Zend/zend_API.h"
- static ZEND_COLD void undef_result_after_exception(void) {
- const zend_op *opline = EG(opline_before_exception);
- ZEND_ASSERT(EG(exception));
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- zend_execute_data *execute_data = EG(current_execute_data);
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- }
- static ZEND_COLD void zend_jit_illegal_offset(void)
- {
- zend_type_error("Illegal offset type");
- }
- static ZEND_COLD void zend_jit_illegal_string_offset(zval *offset)
- {
- zend_type_error("Cannot access offset of type %s on string", zend_zval_type_name(offset));
- }
- static zend_never_inline zend_function* ZEND_FASTCALL _zend_jit_init_func_run_time_cache(const zend_op_array *op_array) /* {{{ */
- {
- void **run_time_cache;
- run_time_cache = zend_arena_alloc(&CG(arena), op_array->cache_size);
- memset(run_time_cache, 0, op_array->cache_size);
- ZEND_MAP_PTR_SET(op_array->run_time_cache, run_time_cache);
- return (zend_function*)op_array;
- }
- /* }}} */
- static zend_never_inline zend_op_array* ZEND_FASTCALL zend_jit_init_func_run_time_cache_helper(zend_op_array *op_array) /* {{{ */
- {
- void **run_time_cache;
- if (!RUN_TIME_CACHE(op_array)) {
- run_time_cache = zend_arena_alloc(&CG(arena), op_array->cache_size);
- memset(run_time_cache, 0, op_array->cache_size);
- ZEND_MAP_PTR_SET(op_array->run_time_cache, run_time_cache);
- }
- return op_array;
- }
- /* }}} */
- static zend_function* ZEND_FASTCALL zend_jit_find_func_helper(zend_string *name, void **cache_slot)
- {
- zval *func = zend_hash_find_known_hash(EG(function_table), name);
- zend_function *fbc;
- if (UNEXPECTED(func == NULL)) {
- return NULL;
- }
- fbc = Z_FUNC_P(func);
- if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
- fbc = _zend_jit_init_func_run_time_cache(&fbc->op_array);
- }
- *cache_slot = fbc;
- return fbc;
- }
- static zend_function* ZEND_FASTCALL zend_jit_find_ns_func_helper(zval *func_name, void **cache_slot)
- {
- zval *func = zend_hash_find_known_hash(EG(function_table), Z_STR_P(func_name + 1));
- zend_function *fbc;
- if (func == NULL) {
- func = zend_hash_find_known_hash(EG(function_table), Z_STR_P(func_name + 2));
- if (UNEXPECTED(func == NULL)) {
- return NULL;
- }
- }
- fbc = Z_FUNC_P(func);
- if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
- fbc = _zend_jit_init_func_run_time_cache(&fbc->op_array);
- }
- *cache_slot = fbc;
- return fbc;
- }
- static ZEND_COLD void ZEND_FASTCALL zend_jit_invalid_method_call(zval *object)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = EX(opline);
- zval *function_name = function_name = RT_CONSTANT(opline, opline->op2);;
- if (Z_TYPE_P(object) == IS_UNDEF && opline->op1_type == IS_CV) {
- zend_string *cv = EX(func)->op_array.vars[EX_VAR_TO_NUM(opline->op1.var)];
- zend_error(E_WARNING, "Undefined variable $%s", ZSTR_VAL(cv));
- if (UNEXPECTED(EG(exception) != NULL)) {
- return;
- }
- object = &EG(uninitialized_zval);
- }
- zend_throw_error(NULL, "Call to a member function %s() on %s",
- Z_STRVAL_P(function_name), zend_zval_type_name(object));
- }
- static ZEND_COLD void ZEND_FASTCALL zend_jit_invalid_method_call_tmp(zval *object)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = EX(opline);
- zend_jit_invalid_method_call(object);
- zval_ptr_dtor_nogc(EX_VAR(opline->op1.var));
- }
- static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_method(const zend_class_entry *ce, const zend_string *method)
- {
- zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(ce->name), ZSTR_VAL(method));
- }
- static void ZEND_FASTCALL zend_jit_unref_helper(zval *zv)
- {
- zend_reference *ref;
- ZEND_ASSERT(Z_ISREF_P(zv));
- ref = Z_REF_P(zv);
- ZVAL_COPY_VALUE(zv, &ref->val);
- if (GC_DELREF(ref) == 0) {
- efree_size(ref, sizeof(zend_reference));
- } else {
- Z_TRY_ADDREF_P(zv);
- }
- }
- static zend_function* ZEND_FASTCALL zend_jit_find_method_helper(zend_object *obj, zval *function_name, zend_object **obj_ptr)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = EX(opline);
- zend_class_entry *called_scope = obj->ce;
- zend_function *fbc;
- fbc = obj->handlers->get_method(obj_ptr, Z_STR_P(function_name), function_name + 1);
- if (UNEXPECTED(fbc == NULL)) {
- if (EXPECTED(!EG(exception))) {
- zend_undefined_method(called_scope, Z_STR_P(function_name));
- }
- return NULL;
- }
- if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
- zend_init_func_run_time_cache(&fbc->op_array);
- }
- if (UNEXPECTED(obj != *obj_ptr)) {
- return fbc;
- }
- if (EXPECTED(!(fbc->common.fn_flags & (ZEND_ACC_CALL_VIA_TRAMPOLINE|ZEND_ACC_NEVER_CACHE)))) {
- CACHE_POLYMORPHIC_PTR(opline->result.num, called_scope, fbc);
- }
- return fbc;
- }
- static zend_function* ZEND_FASTCALL zend_jit_find_method_tmp_helper(zend_object *obj, zval *function_name, zend_object **obj_ptr)
- {
- zend_function *fbc;
- fbc = zend_jit_find_method_helper(obj, function_name, obj_ptr);
- if (!fbc) {
- if (GC_DELREF(obj) == 0) {
- zend_objects_store_del(obj);
- }
- } else if (obj != *obj_ptr) {
- GC_ADDREF(*obj_ptr);
- if (GC_DELREF(obj) == 0) {
- zend_objects_store_del(obj);
- }
- }
- return fbc;
- }
- static zend_execute_data* ZEND_FASTCALL zend_jit_push_static_metod_call_frame(zend_object *obj, zend_function *fbc, uint32_t num_args)
- {
- zend_class_entry *scope = obj->ce;
- return zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, num_args, scope);
- }
- static zend_execute_data* ZEND_FASTCALL zend_jit_push_static_metod_call_frame_tmp(zend_object *obj, zend_function *fbc, uint32_t num_args)
- {
- zend_class_entry *scope = obj->ce;
- if (GC_DELREF(obj) == 0) {
- zend_objects_store_del(obj);
- if (UNEXPECTED(EG(exception))) {
- return NULL;
- }
- }
- return zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, num_args, scope);
- }
- static zend_execute_data* ZEND_FASTCALL zend_jit_extend_stack_helper(uint32_t used_stack, zend_function *fbc)
- {
- zend_execute_data *call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
- call->func = fbc;
- ZEND_CALL_INFO(call) = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_ALLOCATED;
- return call;
- }
- static zend_execute_data* ZEND_FASTCALL zend_jit_int_extend_stack_helper(uint32_t used_stack)
- {
- zend_execute_data *call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
- ZEND_CALL_INFO(call) = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_ALLOCATED;
- return call;
- }
- static zval* ZEND_FASTCALL zend_jit_symtable_find(HashTable *ht, zend_string *str)
- {
- zend_ulong idx;
- register const char *tmp = str->val;
- do {
- if (*tmp > '9') {
- break;
- } else if (*tmp < '0') {
- if (*tmp != '-') {
- break;
- }
- tmp++;
- if (*tmp > '9' || *tmp < '0') {
- break;
- }
- }
- if (_zend_handle_numeric_str_ex(str->val, str->len, &idx)) {
- return zend_hash_index_find(ht, idx);
- }
- } while (0);
- return zend_hash_find(ht, str);
- }
- static zval* ZEND_FASTCALL zend_jit_hash_index_lookup_rw_no_packed(HashTable *ht, zend_long idx)
- {
- zval *retval = NULL;
- if (!HT_IS_PACKED(ht)) {
- retval = _zend_hash_index_find(ht, idx);
- }
- if (!retval) {
- retval = zend_undefined_offset_write(ht, idx);
- }
- return retval;
- }
- static zval* ZEND_FASTCALL zend_jit_hash_index_lookup_rw(HashTable *ht, zend_long idx)
- {
- zval *retval = zend_hash_index_find(ht, idx);
- if (!retval) {
- retval = zend_undefined_offset_write(ht, idx);
- }
- return retval;
- }
- static zval* ZEND_FASTCALL zend_jit_hash_lookup_rw(HashTable *ht, zend_string *str)
- {
- zval *retval = zend_hash_find_known_hash(ht, str);
- if (!retval) {
- /* Key may be released while throwing the undefined index warning. */
- retval = zend_undefined_index_write(ht, str);
- }
- return retval;
- }
- static zval* ZEND_FASTCALL zend_jit_symtable_lookup_rw(HashTable *ht, zend_string *str)
- {
- zend_ulong idx;
- register const char *tmp = str->val;
- zval *retval;
- do {
- if (*tmp > '9') {
- break;
- } else if (*tmp < '0') {
- if (*tmp != '-') {
- break;
- }
- tmp++;
- if (*tmp > '9' || *tmp < '0') {
- break;
- }
- }
- if (_zend_handle_numeric_str_ex(str->val, str->len, &idx)) {
- retval = zend_hash_index_find(ht, idx);
- if (!retval) {
- retval = zend_undefined_offset_write(ht, idx);
- }
- return retval;
- }
- } while (0);
- retval = zend_hash_find(ht, str);
- if (!retval) {
- /* Key may be released while throwing the undefined index warning. */
- retval = zend_undefined_index_write(ht, str);
- }
- return retval;
- }
- static zval* ZEND_FASTCALL zend_jit_symtable_lookup_w(HashTable *ht, zend_string *str)
- {
- zend_ulong idx;
- register const char *tmp = str->val;
- do {
- if (*tmp > '9') {
- break;
- } else if (*tmp < '0') {
- if (*tmp != '-') {
- break;
- }
- tmp++;
- if (*tmp > '9' || *tmp < '0') {
- break;
- }
- }
- if (_zend_handle_numeric_str_ex(str->val, str->len, &idx)) {
- return zend_hash_index_lookup(ht, idx);
- }
- } while (0);
- return zend_hash_lookup(ht, str);
- }
- static int ZEND_FASTCALL zend_jit_undefined_op_helper(uint32_t var)
- {
- const zend_execute_data *execute_data = EG(current_execute_data);
- zend_string *cv = EX(func)->op_array.vars[EX_VAR_TO_NUM(var)];
- zend_error(E_WARNING, "Undefined variable $%s", ZSTR_VAL(cv));
- return EG(exception) == NULL;
- }
- static int ZEND_FASTCALL zend_jit_undefined_op_helper_write(HashTable *ht, uint32_t var)
- {
- const zend_execute_data *execute_data = EG(current_execute_data);
- zend_string *cv = EX(func)->op_array.vars[EX_VAR_TO_NUM(var)];
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- zend_error(E_WARNING, "Undefined variable $%s", ZSTR_VAL(cv));
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
- if (!GC_REFCOUNT(ht)) {
- zend_array_destroy(ht);
- }
- return 0;
- }
- return EG(exception) == NULL;
- }
- static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, zval *result)
- {
- zend_ulong hval;
- zend_string *offset_key;
- zval *retval;
- zend_execute_data *execute_data;
- const zend_op *opline;
- if (Z_TYPE_P(dim) == IS_REFERENCE) {
- dim = Z_REFVAL_P(dim);
- }
- switch (Z_TYPE_P(dim)) {
- case IS_LONG:
- hval = Z_LVAL_P(dim);
- goto num_index;
- case IS_STRING:
- offset_key = Z_STR_P(dim);
- goto str_index;
- case IS_UNDEF:
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
- zend_array_destroy(ht);
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- return;
- }
- if (EG(exception)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return;
- }
- ZEND_FALLTHROUGH;
- case IS_NULL:
- offset_key = ZSTR_EMPTY_ALLOC();
- goto str_index;
- case IS_DOUBLE:
- hval = zend_dval_to_lval(Z_DVAL_P(dim));
- if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
- zend_array_destroy(ht);
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- return;
- }
- if (EG(exception)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return;
- }
- }
- goto num_index;
- case IS_RESOURCE:
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- zend_use_resource_as_offset(dim);
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
- zend_array_destroy(ht);
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- return;
- }
- if (EG(exception)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return;
- }
- hval = Z_RES_HANDLE_P(dim);
- goto num_index;
- case IS_FALSE:
- hval = 0;
- goto num_index;
- case IS_TRUE:
- hval = 1;
- goto num_index;
- default:
- zend_jit_illegal_offset();
- undef_result_after_exception();
- return;
- }
- str_index:
- if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
- goto num_index;
- }
- retval = zend_hash_find(ht, offset_key);
- if (!retval) {
- zend_error(E_WARNING, "Undefined array key \"%s\"", ZSTR_VAL(offset_key));
- ZVAL_NULL(result);
- return;
- }
- ZVAL_COPY_DEREF(result, retval);
- return;
- num_index:
- ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef);
- ZVAL_COPY_DEREF(result, retval);
- return;
- num_undef:
- zend_error(E_WARNING, "Undefined array key " ZEND_LONG_FMT, hval);
- ZVAL_NULL(result);
- }
- static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim, zval *result)
- {
- zend_ulong hval;
- zend_string *offset_key;
- zval *retval;
- zend_execute_data *execute_data;
- const zend_op *opline;
- if (Z_TYPE_P(dim) == IS_REFERENCE) {
- dim = Z_REFVAL_P(dim);
- }
- switch (Z_TYPE_P(dim)) {
- case IS_LONG:
- hval = Z_LVAL_P(dim);
- goto num_index;
- case IS_STRING:
- offset_key = Z_STR_P(dim);
- goto str_index;
- case IS_UNDEF:
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
- zend_array_destroy(ht);
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- return;
- }
- if (EG(exception)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return;
- }
- ZEND_FALLTHROUGH;
- case IS_NULL:
- offset_key = ZSTR_EMPTY_ALLOC();
- goto str_index;
- case IS_DOUBLE:
- hval = zend_dval_to_lval(Z_DVAL_P(dim));
- if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
- zend_array_destroy(ht);
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- return;
- }
- if (EG(exception)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return;
- }
- }
- goto num_index;
- case IS_RESOURCE:
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- zend_use_resource_as_offset(dim);
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
- zend_array_destroy(ht);
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- return;
- }
- if (EG(exception)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return;
- }
- hval = Z_RES_HANDLE_P(dim);
- goto num_index;
- case IS_FALSE:
- hval = 0;
- goto num_index;
- case IS_TRUE:
- hval = 1;
- goto num_index;
- default:
- zend_jit_illegal_offset();
- undef_result_after_exception();
- return;
- }
- str_index:
- if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
- goto num_index;
- }
- retval = zend_hash_find(ht, offset_key);
- if (!retval) {
- ZVAL_NULL(result);
- return;
- }
- ZVAL_COPY_DEREF(result, retval);
- return;
- num_index:
- ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef);
- ZVAL_COPY_DEREF(result, retval);
- return;
- num_undef:
- ZVAL_NULL(result);
- }
- static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *dim)
- {
- zend_ulong hval;
- zend_string *offset_key;
- zval *retval;
- if (Z_TYPE_P(dim) == IS_REFERENCE) {
- dim = Z_REFVAL_P(dim);
- }
- switch (Z_TYPE_P(dim)) {
- case IS_LONG:
- hval = Z_LVAL_P(dim);
- goto num_index;
- case IS_STRING:
- offset_key = Z_STR_P(dim);
- goto str_index;
- case IS_UNDEF:
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
- zend_array_destroy(ht);
- return 0;
- }
- if (EG(exception)) {
- return 0;
- }
- ZEND_FALLTHROUGH;
- case IS_NULL:
- offset_key = ZSTR_EMPTY_ALLOC();
- goto str_index;
- case IS_DOUBLE:
- hval = zend_dval_to_lval(Z_DVAL_P(dim));
- if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
- zend_array_destroy(ht);
- return 0;
- }
- if (EG(exception)) {
- return 0;
- }
- }
- goto num_index;
- case IS_RESOURCE:
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- zend_use_resource_as_offset(dim);
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
- zend_array_destroy(ht);
- return 0;
- }
- if (EG(exception)) {
- return 0;
- }
- hval = Z_RES_HANDLE_P(dim);
- goto num_index;
- case IS_FALSE:
- hval = 0;
- goto num_index;
- case IS_TRUE:
- hval = 1;
- goto num_index;
- default:
- zend_type_error("Illegal offset type in isset or empty");
- return 0;
- }
- str_index:
- if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
- goto num_index;
- }
- retval = zend_hash_find(ht, offset_key);
- if (!retval) {
- return 0;
- }
- if (UNEXPECTED(Z_TYPE_P(retval) == IS_REFERENCE)) {
- retval = Z_REFVAL_P(retval);
- }
- return Z_TYPE_P(retval) > IS_NULL;
- num_index:
- ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef);
- if (UNEXPECTED(Z_TYPE_P(retval) == IS_REFERENCE)) {
- retval = Z_REFVAL_P(retval);
- }
- return (Z_TYPE_P(retval) > IS_NULL);
- num_undef:
- return 0;
- }
- static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *dim)
- {
- zend_ulong hval;
- zend_string *offset_key;
- zval *retval;
- zend_execute_data *execute_data;
- const zend_op *opline;
- if (Z_TYPE_P(dim) == IS_REFERENCE) {
- dim = Z_REFVAL_P(dim);
- }
- switch (Z_TYPE_P(dim)) {
- case IS_LONG:
- hval = Z_LVAL_P(dim);
- goto num_index;
- case IS_STRING:
- offset_key = Z_STR_P(dim);
- goto str_index;
- case IS_UNDEF:
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- if (UNEXPECTED(opline->opcode == ZEND_HANDLE_EXCEPTION)) {
- opline = EG(opline_before_exception);
- }
- if (!zend_jit_undefined_op_helper_write(ht, opline->op2.var)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- return NULL;
- }
- ZEND_FALLTHROUGH;
- case IS_NULL:
- offset_key = ZSTR_EMPTY_ALLOC();
- goto str_index;
- case IS_DOUBLE:
- hval = zend_dval_to_lval(Z_DVAL_P(dim));
- if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
- if (!GC_REFCOUNT(ht)) {
- zend_array_destroy(ht);
- }
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- return NULL;
- }
- if (EG(exception)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return NULL;
- }
- }
- goto num_index;
- case IS_RESOURCE:
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- zend_use_resource_as_offset(dim);
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
- if (!GC_REFCOUNT(ht)) {
- zend_array_destroy(ht);
- }
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- return NULL;
- }
- if (EG(exception)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return NULL;
- }
- hval = Z_RES_HANDLE_P(dim);
- goto num_index;
- case IS_FALSE:
- hval = 0;
- goto num_index;
- case IS_TRUE:
- hval = 1;
- goto num_index;
- default:
- zend_jit_illegal_offset();
- undef_result_after_exception();
- return NULL;
- }
- str_index:
- if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
- goto num_index;
- }
- retval = zend_hash_find(ht, offset_key);
- if (!retval) {
- /* Key may be released while throwing the undefined index warning. */
- retval = zend_undefined_index_write(ht, offset_key);
- }
- return retval;
- num_index:
- ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef);
- return retval;
- num_undef:
- return zend_undefined_offset_write(ht, hval);
- }
- static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim)
- {
- zend_ulong hval;
- zend_string *offset_key;
- zval *retval;
- zend_execute_data *execute_data;
- const zend_op *opline;
- if (Z_TYPE_P(dim) == IS_REFERENCE) {
- dim = Z_REFVAL_P(dim);
- }
- switch (Z_TYPE_P(dim)) {
- case IS_LONG:
- hval = Z_LVAL_P(dim);
- goto num_index;
- case IS_STRING:
- offset_key = Z_STR_P(dim);
- goto str_index;
- case IS_UNDEF:
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- if (!zend_jit_undefined_op_helper_write(ht, opline->op2.var)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- if (opline->opcode == ZEND_ASSIGN_DIM
- && ((opline+1)->op1_type & (IS_VAR | IS_TMP_VAR))) {
- zval_ptr_dtor_nogc(EX_VAR((opline+1)->op1.var));
- }
- return NULL;
- }
- ZEND_FALLTHROUGH;
- case IS_NULL:
- offset_key = ZSTR_EMPTY_ALLOC();
- goto str_index;
- case IS_DOUBLE:
- hval = zend_dval_to_lval(Z_DVAL_P(dim));
- if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
- if (!GC_REFCOUNT(ht)) {
- zend_array_destroy(ht);
- }
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- return NULL;
- }
- if (EG(exception)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return NULL;
- }
- }
- goto num_index;
- case IS_RESOURCE:
- /* The array may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
- GC_ADDREF(ht);
- }
- execute_data = EG(current_execute_data);
- opline = EX(opline);
- zend_use_resource_as_offset(dim);
- if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
- if (!GC_REFCOUNT(ht)) {
- zend_array_destroy(ht);
- }
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- if (EG(exception)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- } else {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- return NULL;
- }
- if (EG(exception)) {
- if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return NULL;
- }
- hval = Z_RES_HANDLE_P(dim);
- goto num_index;
- case IS_FALSE:
- hval = 0;
- goto num_index;
- case IS_TRUE:
- hval = 1;
- goto num_index;
- default:
- zend_jit_illegal_offset();
- undef_result_after_exception();
- if ((EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA
- && ((EG(opline_before_exception)+1)->op1_type & (IS_VAR|IS_TMP_VAR))) {
- zend_execute_data *execute_data = EG(current_execute_data);
- zval_ptr_dtor_nogc(EX_VAR((EG(opline_before_exception)+1)->op1.var));
- }
- return NULL;
- }
- str_index:
- if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
- goto num_index;
- }
- return zend_hash_lookup(ht, offset_key);
- num_index:
- ZEND_HASH_INDEX_LOOKUP(ht, hval, retval);
- return retval;
- }
- static zend_never_inline zend_long zend_check_string_offset(zval *dim/*, int type*/)
- {
- zend_long offset;
- try_again:
- switch(Z_TYPE_P(dim)) {
- case IS_LONG:
- return Z_LVAL_P(dim);
- case IS_STRING:
- {
- bool trailing_data = false;
- /* For BC reasons we allow errors so that we can warn on leading numeric string */
- if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL,
- /* allow errors */ true, NULL, &trailing_data)) {
- if (UNEXPECTED(trailing_data)
- && EG(current_execute_data)->opline->opcode != ZEND_FETCH_DIM_UNSET) {
- zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
- }
- return offset;
- }
- zend_jit_illegal_string_offset(dim);
- return 0;
- }
- case IS_UNDEF:
- zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
- ZEND_FALLTHROUGH;
- case IS_DOUBLE:
- case IS_NULL:
- case IS_FALSE:
- case IS_TRUE:
- zend_error(E_WARNING, "String offset cast occurred");
- break;
- case IS_REFERENCE:
- dim = Z_REFVAL_P(dim);
- goto try_again;
- default:
- zend_jit_illegal_string_offset(dim);
- return 0;
- }
- return zval_get_long_func(dim, /* is_strict */ false);
- }
- static zend_always_inline zend_string* zend_jit_fetch_dim_str_offset(zend_string *str, zend_long offset)
- {
- if (UNEXPECTED((zend_ulong)offset >= (zend_ulong)ZSTR_LEN(str))) {
- if (EXPECTED(offset < 0)) {
- /* Handle negative offset */
- zend_long real_offset = (zend_long)ZSTR_LEN(str) + offset;
- if (EXPECTED(real_offset >= 0)) {
- return ZSTR_CHAR((zend_uchar)ZSTR_VAL(str)[real_offset]);
- }
- }
- zend_error(E_WARNING, "Uninitialized string offset " ZEND_LONG_FMT, offset);
- return ZSTR_EMPTY_ALLOC();
- } else {
- return ZSTR_CHAR((zend_uchar)ZSTR_VAL(str)[offset]);
- }
- }
- static zend_string* ZEND_FASTCALL zend_jit_fetch_dim_str_offset_r_helper(zend_string *str, zend_long offset)
- {
- return zend_jit_fetch_dim_str_offset(str, offset);
- }
- static zend_string* ZEND_FASTCALL zend_jit_fetch_dim_str_r_helper(zend_string *str, zval *dim)
- {
- zend_long offset;
- if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
- if (!(GC_FLAGS(str) & IS_STR_INTERNED)) {
- GC_ADDREF(str);
- }
- offset = zend_check_string_offset(dim/*, BP_VAR_R*/);
- if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) {
- zend_string *ret = zend_jit_fetch_dim_str_offset(str, offset);
- zend_string_efree(str);
- return ret;
- }
- } else {
- offset = Z_LVAL_P(dim);
- }
- return zend_jit_fetch_dim_str_offset(str, offset);
- }
- static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper(zend_string *str, zval *dim, zval *result)
- {
- zend_long offset;
- try_string_offset:
- if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
- switch (Z_TYPE_P(dim)) {
- /* case IS_LONG: */
- case IS_STRING:
- if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)) {
- break;
- }
- ZVAL_NULL(result);
- return;
- case IS_UNDEF:
- zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
- case IS_DOUBLE:
- case IS_NULL:
- case IS_FALSE:
- case IS_TRUE:
- break;
- case IS_REFERENCE:
- dim = Z_REFVAL_P(dim);
- goto try_string_offset;
- default:
- zend_jit_illegal_string_offset(dim);
- break;
- }
- offset = zval_get_long_func(dim, /* is_strict */ false);
- } else {
- offset = Z_LVAL_P(dim);
- }
- if ((zend_ulong)offset >= (zend_ulong)ZSTR_LEN(str)) {
- if (offset < 0) {
- /* Handle negative offset */
- zend_long real_offset = (zend_long)ZSTR_LEN(str) + offset;
- if (real_offset >= 0) {
- ZVAL_CHAR(result, (zend_uchar)ZSTR_VAL(str)[real_offset]);
- return;
- }
- }
- ZVAL_NULL(result);
- } else {
- ZVAL_CHAR(result, (zend_uchar)ZSTR_VAL(str)[offset]);
- }
- }
- static void ZEND_FASTCALL zend_jit_fetch_dim_obj_r_helper(zval *container, zval *dim, zval *result)
- {
- zval *retval;
- zend_object *obj = Z_OBJ_P(container);
- GC_ADDREF(obj);
- if (UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
- zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
- dim = &EG(uninitialized_zval);
- }
- retval = obj->handlers->read_dimension(obj, dim, BP_VAR_R, result);
- if (retval) {
- if (result != retval) {
- ZVAL_COPY_DEREF(result, retval);
- } else if (UNEXPECTED(Z_ISREF_P(retval))) {
- zend_unwrap_reference(retval);
- }
- } else {
- ZVAL_NULL(result);
- }
- if (UNEXPECTED(GC_DELREF(obj) == 0)) {
- zend_objects_store_del(obj);
- }
- }
- static void ZEND_FASTCALL zend_jit_fetch_dim_obj_is_helper(zval *container, zval *dim, zval *result)
- {
- zval *retval;
- zend_object *obj = Z_OBJ_P(container);
- GC_ADDREF(obj);
- if (UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
- zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
- dim = &EG(uninitialized_zval);
- }
- retval = obj->handlers->read_dimension(obj, dim, BP_VAR_IS, result);
- if (retval) {
- if (result != retval) {
- ZVAL_COPY_DEREF(result, retval);
- } else if (UNEXPECTED(Z_ISREF_P(retval))) {
- zend_unwrap_reference(result);
- }
- } else {
- ZVAL_NULL(result);
- }
- if (UNEXPECTED(GC_DELREF(obj) == 0)) {
- zend_objects_store_del(obj);
- }
- }
- static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zval *value, zval *result)
- {
- zend_uchar c;
- size_t string_len;
- zend_long offset;
- zend_string *s;
- /* separate string */
- if (Z_REFCOUNTED_P(str) && Z_REFCOUNT_P(str) == 1) {
- s = Z_STR_P(str);
- } else {
- s = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
- ZSTR_H(s) = ZSTR_H(Z_STR_P(str));
- if (Z_REFCOUNTED_P(str)) {
- GC_DELREF(Z_STR_P(str));
- }
- ZVAL_NEW_STR(str, s);
- }
- if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
- /* The string may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- GC_ADDREF(s);
- offset = zend_check_string_offset(dim/*, BP_VAR_W*/);
- if (UNEXPECTED(GC_DELREF(s) == 0)) {
- zend_string_efree(s);
- if (result) {
- ZVAL_NULL(result);
- }
- return;
- }
- if (UNEXPECTED(EG(exception) != NULL)) {
- if (UNEXPECTED(result)) {
- ZVAL_UNDEF(result);
- }
- return;
- }
- } else {
- offset = Z_LVAL_P(dim);
- }
- if (offset < -(zend_long)ZSTR_LEN(s)) {
- /* Error on negative offset */
- zend_error(E_WARNING, "Illegal string offset " ZEND_LONG_FMT, offset);
- if (result) {
- ZVAL_NULL(result);
- }
- return;
- }
- if (Z_TYPE_P(value) != IS_STRING) {
- zend_string *tmp;
- /* The string may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- GC_ADDREF(s);
- if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
- const zend_op *op_data = EG(current_execute_data)->opline + 1;
- ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
- zend_jit_undefined_op_helper(op_data->op1.var);
- value = &EG(uninitialized_zval);
- }
- /* Convert to string, just the time to pick the 1st byte */
- tmp = zval_try_get_string_func(value);
- if (UNEXPECTED(GC_DELREF(s) == 0)) {
- zend_string_efree(s);
- if (tmp) {
- zend_string_release_ex(tmp, 0);
- }
- if (result) {
- ZVAL_NULL(result);
- }
- return;
- }
- if (UNEXPECTED(!tmp)) {
- if (result) {
- ZVAL_UNDEF(result);
- }
- return;
- }
- if (UNEXPECTED(!tmp)) {
- if (result) {
- ZVAL_UNDEF(result);
- }
- return;
- }
- string_len = ZSTR_LEN(tmp);
- c = (zend_uchar)ZSTR_VAL(tmp)[0];
- zend_string_release(tmp);
- } else {
- string_len = Z_STRLEN_P(value);
- c = (zend_uchar)Z_STRVAL_P(value)[0];
- }
- if (string_len != 1) {
- if (string_len == 0) {
- /* Error on empty input string */
- zend_throw_error(NULL, "Cannot assign an empty string to a string offset");
- if (result) {
- ZVAL_NULL(result);
- }
- return;
- }
- /* The string may be destroyed while throwing the notice.
- * Temporarily increase the refcount to detect this situation. */
- GC_ADDREF(s);
- zend_error(E_WARNING, "Only the first byte will be assigned to the string offset");
- if (UNEXPECTED(GC_DELREF(s) == 0)) {
- zend_string_efree(s);
- if (result) {
- ZVAL_NULL(result);
- }
- return;
- }
- /* Illegal offset assignment */
- if (UNEXPECTED(EG(exception) != NULL)) {
- if (result) {
- ZVAL_UNDEF(result);
- }
- return;
- }
- }
- if (offset < 0) { /* Handle negative offset */
- offset += (zend_long)ZSTR_LEN(s);
- }
- if ((size_t)offset >= ZSTR_LEN(s)) {
- /* Extend string if needed */
- zend_long old_len = ZSTR_LEN(s);
- ZVAL_NEW_STR(str, zend_string_extend(s, (size_t)offset + 1, 0));
- memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
- Z_STRVAL_P(str)[offset+1] = 0;
- } else {
- zend_string_forget_hash_val(Z_STR_P(str));
- }
- Z_STRVAL_P(str)[offset] = c;
- if (result) {
- /* Return the new character */
- ZVAL_CHAR(result, c);
- }
- }
- static zend_always_inline void ZEND_FASTCALL zend_jit_fetch_dim_obj_helper(zval *object_ptr, zval *dim, zval *result, int type)
- {
- zval *retval;
- if (EXPECTED(Z_TYPE_P(object_ptr) == IS_OBJECT)) {
- zend_object *obj = Z_OBJ_P(object_ptr);
- GC_ADDREF(obj);
- if (dim && UNEXPECTED(Z_ISUNDEF_P(dim))) {
- const zend_op *opline = EG(current_execute_data)->opline;
- zend_jit_undefined_op_helper(opline->op2.var);
- dim = &EG(uninitialized_zval);
- }
- retval = obj->handlers->read_dimension(obj, dim, type, result);
- if (UNEXPECTED(retval == &EG(uninitialized_zval))) {
- zend_class_entry *ce = obj->ce;
- ZVAL_NULL(result);
- zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ZSTR_VAL(ce->name));
- } else if (EXPECTED(retval && Z_TYPE_P(retval) != IS_UNDEF)) {
- if (!Z_ISREF_P(retval)) {
- if (result != retval) {
- ZVAL_COPY(result, retval);
- retval = result;
- }
- if (Z_TYPE_P(retval) != IS_OBJECT) {
- zend_class_entry *ce = obj->ce;
- zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ZSTR_VAL(ce->name));
- }
- } else if (UNEXPECTED(Z_REFCOUNT_P(retval) == 1)) {
- ZVAL_UNREF(retval);
- }
- if (result != retval) {
- ZVAL_INDIRECT(result, retval);
- }
- } else {
- ZEND_ASSERT(EG(exception) && "read_dimension() returned NULL without exception");
- ZVAL_UNDEF(result);
- }
- if (UNEXPECTED(GC_DELREF(obj) == 0)) {
- zend_objects_store_del(obj);
- }
- } else if (EXPECTED(Z_TYPE_P(object_ptr) == IS_STRING)) {
- if (!dim) {
- zend_throw_error(NULL, "[] operator not supported for strings");
- } else {
- if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
- zend_check_string_offset(dim/*, BP_VAR_RW*/);
- }
- zend_wrong_string_offset_error();
- }
- ZVAL_UNDEF(result);
- } else if (Z_TYPE_P(object_ptr) == IS_FALSE) {
- zend_array *arr = zend_new_array(0);
- ZVAL_ARR(object_ptr, arr);
- GC_ADDREF(arr);
- zend_false_to_array_deprecated();
- if (UNEXPECTED(GC_DELREF(arr) == 0)) {
- zend_array_destroy(arr);
- ZVAL_NULL(result);
- return;
- }
- SEPARATE_ARRAY(object_ptr);
- arr = Z_ARRVAL_P(object_ptr);
- zval *var;
- if (dim) {
- if (type == BP_VAR_W) {
- var = zend_jit_fetch_dim_w_helper(arr, dim);
- } else {
- ZEND_ASSERT(type == BP_VAR_RW);
- var = zend_jit_fetch_dim_rw_helper(arr, dim);
- }
- } else {
- var = zend_hash_next_index_insert_new(arr, &EG(uninitialized_zval));
- }
- if (var) {
- ZVAL_INDIRECT(result, var);
- } else {
- ZVAL_UNDEF(result);
- }
- } else {
- if (type == BP_VAR_UNSET) {
- zend_throw_error(NULL, "Cannot unset offset in a non-array variable");
- ZVAL_UNDEF(result);
- } else {
- zend_throw_error(NULL, "Cannot use a scalar value as an array");
- ZVAL_UNDEF(result);
- }
- }
- }
- static void ZEND_FASTCALL zend_jit_fetch_dim_obj_w_helper(zval *object_ptr, zval *dim, zval *result)
- {
- zend_jit_fetch_dim_obj_helper(object_ptr, dim, result, BP_VAR_W);
- }
- static void ZEND_FASTCALL zend_jit_fetch_dim_obj_rw_helper(zval *object_ptr, zval *dim, zval *result)
- {
- zend_jit_fetch_dim_obj_helper(object_ptr, dim, result, BP_VAR_RW);
- }
- //static void ZEND_FASTCALL zend_jit_fetch_dim_obj_unset_helper(zval *object_ptr, zval *dim, zval *result)
- //{
- // zend_jit_fetch_dim_obj_helper(object_ptr, dim, result, BP_VAR_UNSET);
- //}
- static void ZEND_FASTCALL zend_jit_assign_dim_helper(zval *object_ptr, zval *dim, zval *value, zval *result)
- {
- if (EXPECTED(Z_TYPE_P(object_ptr) == IS_OBJECT)) {
- zend_object *obj = Z_OBJ_P(object_ptr);
- GC_ADDREF(obj);
- if (dim && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
- const zend_op *opline = EG(current_execute_data)->opline;
- zend_jit_undefined_op_helper(opline->op2.var);
- dim = &EG(uninitialized_zval);
- }
- if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
- const zend_op *op_data = EG(current_execute_data)->opline + 1;
- ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
- zend_jit_undefined_op_helper(op_data->op1.var);
- value = &EG(uninitialized_zval);
- } else {
- ZVAL_DEREF(value);
- }
- obj->handlers->write_dimension(obj, dim, value);
- if (result) {
- if (EXPECTED(!EG(exception))) {
- ZVAL_COPY(result, value);
- } else {
- ZVAL_UNDEF(result);
- }
- }
- if (UNEXPECTED(GC_DELREF(obj) == 0)) {
- zend_objects_store_del(obj);
- }
- return;
- } else if (EXPECTED(Z_TYPE_P(object_ptr) == IS_STRING) && EXPECTED(dim != NULL)) {
- zend_assign_to_string_offset(object_ptr, dim, value, result);
- return;
- }
- if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
- const zend_op *op_data = EG(current_execute_data)->opline + 1;
- ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
- zend_jit_undefined_op_helper(op_data->op1.var);
- value = &EG(uninitialized_zval);
- }
- if (EXPECTED(Z_TYPE_P(object_ptr) == IS_STRING)) {
- zend_throw_error(NULL, "[] operator not supported for strings");
- if (result) {
- ZVAL_UNDEF(result);
- }
- } else if (Z_TYPE_P(object_ptr) == IS_FALSE) {
- zend_array *arr = zend_new_array(0);
- ZVAL_ARR(object_ptr, arr);
- GC_ADDREF(arr);
- zend_false_to_array_deprecated();
- if (UNEXPECTED(GC_DELREF(arr) == 0)) {
- zend_array_destroy(arr);
- if (result) {
- ZVAL_NULL(result);
- }
- return;
- }
- SEPARATE_ARRAY(object_ptr);
- arr = Z_ARRVAL_P(object_ptr);
- zval *var = dim
- ? zend_jit_fetch_dim_w_helper(arr, dim)
- : zend_hash_next_index_insert_new(arr, &EG(uninitialized_zval));
- if (!var) {
- if (result) {
- ZVAL_UNDEF(result);
- }
- return;
- }
- ZVAL_COPY_DEREF(var, value);
- if (result) {
- ZVAL_COPY(result, var);
- }
- } else {
- if (dim && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
- const zend_op *opline = EG(current_execute_data)->opline;
- zend_jit_undefined_op_helper(opline->op2.var);
- dim = &EG(uninitialized_zval);
- }
- zend_throw_error(NULL, "Cannot use a scalar value as an array");
- if (result) {
- ZVAL_UNDEF(result);
- }
- }
- }
- static void ZEND_FASTCALL zend_jit_assign_dim_op_helper(zval *container, zval *dim, zval *value, binary_op_type binary_op)
- {
- if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
- zend_object *obj = Z_OBJ_P(container);
- zval *z;
- zval rv, res;
- GC_ADDREF(obj);
- if (dim && UNEXPECTED(Z_ISUNDEF_P(dim))) {
- const zend_op *opline = EG(current_execute_data)->opline;
- zend_jit_undefined_op_helper(opline->op2.var);
- dim = &EG(uninitialized_zval);
- }
- z = obj->handlers->read_dimension(obj, dim, BP_VAR_R, &rv);
- if (z != NULL) {
- if (binary_op(&res, Z_ISREF_P(z) ? Z_REFVAL_P(z) : z, value) == SUCCESS) {
- obj->handlers->write_dimension(obj, dim, &res);
- }
- if (z == &rv) {
- zval_ptr_dtor(&rv);
- }
- zval_ptr_dtor(&res);
- } else {
- zend_error(E_WARNING, "Attempt to assign property of non-object");
- }
- if (UNEXPECTED(GC_DELREF(obj) == 0)) {
- zend_objects_store_del(obj);
- //??? if (retval) {
- //??? ZVAL_NULL(retval);
- //??? }
- }
- } else if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) {
- if (!dim) {
- zend_throw_error(NULL, "[] operator not supported for strings");
- } else {
- if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
- zend_check_string_offset(dim/*, BP_VAR_RW*/);
- }
- zend_wrong_string_offset_error();
- }
- } else if (Z_TYPE_P(container) == IS_FALSE) {
- zend_array *arr = zend_new_array(0);
- ZVAL_ARR(container, arr);
- GC_ADDREF(arr);
- zend_false_to_array_deprecated();
- if (UNEXPECTED(GC_DELREF(arr) == 0)) {
- zend_array_destroy(arr);
- return;
- }
- SEPARATE_ARRAY(container);
- arr = Z_ARRVAL_P(container);
- zval *var = dim
- ? zend_jit_fetch_dim_rw_helper(arr, dim)
- : zend_hash_next_index_insert_new(arr, &EG(uninitialized_zval));
- if (var) {
- binary_op(var, var, value);
- }
- } else {
- zend_throw_error(NULL, "Cannot use a scalar value as an array");
- }
- }
- static void ZEND_FASTCALL zend_jit_fast_assign_concat_helper(zval *op1, zval *op2)
- {
- size_t op1_len = Z_STRLEN_P(op1);
- size_t op2_len = Z_STRLEN_P(op2);
- size_t result_len = op1_len + op2_len;
- zend_string *result_str;
- if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
- zend_throw_error(NULL, "String size overflow");
- return;
- }
- do {
- if (Z_REFCOUNTED_P(op1)) {
- if (GC_REFCOUNT(Z_STR_P(op1)) == 1) {
- result_str = perealloc(Z_STR_P(op1), ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(result_len)), 0);
- ZSTR_LEN(result_str) = result_len;
- zend_string_forget_hash_val(result_str);
- if (UNEXPECTED(Z_STR_P(op1) == Z_STR_P(op2))) {
- ZVAL_NEW_STR(op2, result_str);
- }
- break;
- }
- GC_DELREF(Z_STR_P(op1));
- }
- result_str = zend_string_alloc(result_len, 0);
- memcpy(ZSTR_VAL(result_str), Z_STRVAL_P(op1), op1_len);
- } while(0);
- ZVAL_NEW_STR(op1, result_str);
- memcpy(ZSTR_VAL(result_str) + op1_len, Z_STRVAL_P(op2), op2_len);
- ZSTR_VAL(result_str)[result_len] = '\0';
- }
- static void ZEND_FASTCALL zend_jit_fast_concat_helper(zval *result, zval *op1, zval *op2)
- {
- size_t op1_len = Z_STRLEN_P(op1);
- size_t op2_len = Z_STRLEN_P(op2);
- size_t result_len = op1_len + op2_len;
- zend_string *result_str;
- if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
- zend_throw_error(NULL, "String size overflow");
- return;
- }
- result_str = zend_string_alloc(result_len, 0);
- memcpy(ZSTR_VAL(result_str), Z_STRVAL_P(op1), op1_len);
- ZVAL_NEW_STR(result, result_str);
- memcpy(ZSTR_VAL(result_str) + op1_len, Z_STRVAL_P(op2), op2_len);
- ZSTR_VAL(result_str)[result_len] = '\0';
- }
- static void ZEND_FASTCALL zend_jit_fast_concat_tmp_helper(zval *result, zval *op1, zval *op2)
- {
- zend_string *op1_str = Z_STR_P(op1);
- size_t op1_len = ZSTR_LEN(op1_str);
- size_t op2_len = Z_STRLEN_P(op2);
- size_t result_len = op1_len + op2_len;
- zend_string *result_str;
- if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
- zend_throw_error(NULL, "String size overflow");
- return;
- }
- do {
- if (!ZSTR_IS_INTERNED(op1_str)) {
- if (GC_REFCOUNT(op1_str) == 1) {
- Z_STR_P(op1) = result_str =
- perealloc(op1_str, ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(result_len)), 0);
- ZSTR_LEN(result_str) = result_len;
- zend_string_forget_hash_val(result_str);
- break;
- }
- GC_DELREF(op1_str);
- }
- result_str = zend_string_alloc(result_len, 0);
- memcpy(ZSTR_VAL(result_str), ZSTR_VAL(op1_str), op1_len);
- } while (0);
- ZVAL_NEW_STR(result, result_str);
- memcpy(ZSTR_VAL(result_str) + op1_len, Z_STRVAL_P(op2), op2_len);
- ZSTR_VAL(result_str)[result_len] = '\0';
- }
- static int ZEND_FASTCALL zend_jit_isset_dim_helper(zval *container, zval *offset)
- {
- if (UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) {
- zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
- offset = &EG(uninitialized_zval);
- }
- if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
- return Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 0);
- } else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */
- zend_long lval;
- if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) {
- lval = Z_LVAL_P(offset);
- isset_str_offset:
- if (UNEXPECTED(lval < 0)) { /* Handle negative offset */
- lval += (zend_long)Z_STRLEN_P(container);
- }
- if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) {
- return 1;
- }
- } else {
- ZVAL_DEREF(offset);
- if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
- || (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
- && IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, false))) {
- lval = zval_get_long_ex(offset, /* is_strict */ true);
- goto isset_str_offset;
- }
- }
- }
- return 0;
- }
- static void ZEND_FASTCALL zend_jit_free_call_frame(zend_execute_data *call)
- {
- zend_vm_stack_free_call_frame(call);
- }
- static zend_reference* ZEND_FASTCALL zend_jit_fetch_global_helper(zend_string *varname, void **cache_slot)
- {
- zval *value;
- uintptr_t idx;
- zend_reference *ref;
- /* We store "hash slot index" + 1 (NULL is a mark of uninitialized cache slot) */
- idx = (uintptr_t)CACHED_PTR_EX(cache_slot) - 1;
- if (EXPECTED(idx < EG(symbol_table).nNumUsed * sizeof(Bucket))) {
- Bucket *p = (Bucket*)((char*)EG(symbol_table).arData + idx);
- if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF) &&
- (EXPECTED(p->key == varname) ||
- (EXPECTED(p->h == ZSTR_H(varname)) &&
- EXPECTED(p->key != NULL) &&
- EXPECTED(zend_string_equal_content(p->key, varname))))) {
- value = (zval*)p; /* value = &p->val; */
- goto check_indirect;
- }
- }
- value = zend_hash_find_known_hash(&EG(symbol_table), varname);
- if (UNEXPECTED(value == NULL)) {
- value = zend_hash_add_new(&EG(symbol_table), varname, &EG(uninitialized_zval));
- idx = (char*)value - (char*)EG(symbol_table).arData;
- /* Store "hash slot index" + 1 (NULL is a mark of uninitialized cache slot) */
- CACHE_PTR_EX(cache_slot, (void*)(idx + 1));
- } else {
- idx = (char*)value - (char*)EG(symbol_table).arData;
- /* Store "hash slot index" + 1 (NULL is a mark of uninitialized cache slot) */
- CACHE_PTR_EX(cache_slot, (void*)(idx + 1));
- check_indirect:
- /* GLOBAL variable may be an INDIRECT pointer to CV */
- if (UNEXPECTED(Z_TYPE_P(value) == IS_INDIRECT)) {
- value = Z_INDIRECT_P(value);
- if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
- ZVAL_NULL(value);
- }
- }
- }
- if (UNEXPECTED(!Z_ISREF_P(value))) {
- ZVAL_MAKE_REF_EX(value, 2);
- ref = Z_REF_P(value);
- } else {
- ref = Z_REF_P(value);
- GC_ADDREF(ref);
- }
- return ref;
- }
- static bool ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, zend_arg_info *arg_info)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = EX(opline);
- void **cache_slot = CACHE_ADDR(opline->extended_value);
- bool ret = zend_check_user_type_slow(
- &arg_info->type, arg, /* ref */ NULL, cache_slot, /* is_return_type */ false);
- if (UNEXPECTED(!ret)) {
- zend_verify_arg_error(EX(func), arg_info, opline->op1.num, arg);
- return 0;
- }
- return ret;
- }
- static void ZEND_FASTCALL zend_jit_verify_return_slow(zval *arg, const zend_op_array *op_array, zend_arg_info *arg_info, void **cache_slot)
- {
- if (UNEXPECTED(!zend_check_user_type_slow(
- &arg_info->type, arg, /* ref */ NULL, cache_slot, /* is_return_type */ true))) {
- zend_verify_return_error((zend_function*)op_array, arg);
- }
- }
- static void ZEND_FASTCALL zend_jit_fetch_obj_r_slow(zend_object *zobj)
- {
- zval *retval;
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = EX(opline);
- zend_string *name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
- zval *result = EX_VAR(opline->result.var);
- void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS);
- retval = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, result);
- if (retval != result) {
- ZVAL_COPY_DEREF(result, retval);
- } else if (UNEXPECTED(Z_ISREF_P(retval))) {
- zend_unwrap_reference(retval);
- }
- }
- static void ZEND_FASTCALL zend_jit_fetch_obj_r_dynamic(zend_object *zobj, intptr_t prop_offset)
- {
- if (zobj->properties) {
- zval *retval;
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = EX(opline);
- zend_string *name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
- zval *result = EX_VAR(opline->result.var);
- void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS);
- if (!IS_UNKNOWN_DYNAMIC_PROPERTY_OFFSET(prop_offset)) {
- intptr_t idx = ZEND_DECODE_DYN_PROP_OFFSET(prop_offset);
- if (EXPECTED(idx < zobj->properties->nNumUsed * sizeof(Bucket))) {
- Bucket *p = (Bucket*)((char*)zobj->properties->arData + idx);
- if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF) &&
- (EXPECTED(p->key == name) ||
- (EXPECTED(p->h == ZSTR_H(name)) &&
- EXPECTED(p->key != NULL) &&
- EXPECTED(ZSTR_LEN(p->key) == ZSTR_LEN(name)) &&
- EXPECTED(memcmp(ZSTR_VAL(p->key), ZSTR_VAL(name), ZSTR_LEN(name)) == 0)))) {
- ZVAL_COPY_DEREF(result, &p->val);
- return;
- }
- }
- CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_DYNAMIC_PROPERTY_OFFSET);
- }
- retval = zend_hash_find_known_hash(zobj->properties, name);
- if (EXPECTED(retval)) {
- intptr_t idx = (char*)retval - (char*)zobj->properties->arData;
- CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_ENCODE_DYN_PROP_OFFSET(idx));
- ZVAL_COPY_DEREF(result, retval);
- return;
- }
- }
- zend_jit_fetch_obj_r_slow(zobj);
- }
- static void ZEND_FASTCALL zend_jit_fetch_obj_is_slow(zend_object *zobj)
- {
- zval *retval;
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = EX(opline);
- zend_string *name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
- zval *result = EX_VAR(opline->result.var);
- void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS);
- retval = zobj->handlers->read_property(zobj, name, BP_VAR_IS, cache_slot, result);
- if (retval != result) {
- ZVAL_COPY_DEREF(result, retval);
- } else if (UNEXPECTED(Z_ISREF_P(retval))) {
- zend_unwrap_reference(retval);
- }
- }
- static void ZEND_FASTCALL zend_jit_fetch_obj_is_dynamic(zend_object *zobj, intptr_t prop_offset)
- {
- if (zobj->properties) {
- zval *retval;
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = EX(opline);
- zend_string *name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
- zval *result = EX_VAR(opline->result.var);
- void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS);
- if (!IS_UNKNOWN_DYNAMIC_PROPERTY_OFFSET(prop_offset)) {
- intptr_t idx = ZEND_DECODE_DYN_PROP_OFFSET(prop_offset);
- if (EXPECTED(idx < zobj->properties->nNumUsed * sizeof(Bucket))) {
- Bucket *p = (Bucket*)((char*)zobj->properties->arData + idx);
- if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF) &&
- (EXPECTED(p->key == name) ||
- (EXPECTED(p->h == ZSTR_H(name)) &&
- EXPECTED(p->key != NULL) &&
- EXPECTED(ZSTR_LEN(p->key) == ZSTR_LEN(name)) &&
- EXPECTED(memcmp(ZSTR_VAL(p->key), ZSTR_VAL(name), ZSTR_LEN(name)) == 0)))) {
- ZVAL_COPY_DEREF(result, &p->val);
- return;
- }
- }
- CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_DYNAMIC_PROPERTY_OFFSET);
- }
- retval = zend_hash_find_known_hash(zobj->properties, name);
- if (EXPECTED(retval)) {
- intptr_t idx = (char*)retval - (char*)zobj->properties->arData;
- CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_ENCODE_DYN_PROP_OFFSET(idx));
- ZVAL_COPY(result, retval);
- return;
- }
- }
- zend_jit_fetch_obj_is_slow(zobj);
- }
- static zend_always_inline bool promotes_to_array(zval *val) {
- return Z_TYPE_P(val) <= IS_FALSE
- || (Z_ISREF_P(val) && Z_TYPE_P(Z_REFVAL_P(val)) <= IS_FALSE);
- }
- static zend_always_inline bool check_type_array_assignable(zend_type type) {
- if (!ZEND_TYPE_IS_SET(type)) {
- return 1;
- }
- return (ZEND_TYPE_FULL_MASK(type) & (MAY_BE_ITERABLE|MAY_BE_ARRAY)) != 0;
- }
- static zend_property_info *zend_object_fetch_property_type_info(
- zend_object *obj, zval *slot)
- {
- if (EXPECTED(!ZEND_CLASS_HAS_TYPE_HINTS(obj->ce))) {
- return NULL;
- }
- /* Not a declared property */
- if (UNEXPECTED(slot < obj->properties_table ||
- slot >= obj->properties_table + obj->ce->default_properties_count)) {
- return NULL;
- }
- return zend_get_typed_property_info_for_slot(obj, slot);
- }
- static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_prop_error(zend_property_info *prop, const char *type) {
- zend_string *type_str = zend_type_to_string(prop->type);
- zend_type_error(
- "Cannot auto-initialize an %s inside property %s::$%s of type %s",
- type,
- ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name),
- ZSTR_VAL(type_str)
- );
- zend_string_release(type_str);
- }
- static zend_never_inline ZEND_COLD void zend_throw_access_uninit_prop_by_ref_error(
- zend_property_info *prop) {
- zend_throw_error(NULL,
- "Cannot access uninitialized non-nullable property %s::$%s by reference",
- ZSTR_VAL(prop->ce->name),
- zend_get_unmangled_property_name(prop->name));
- }
- static zend_never_inline bool zend_handle_fetch_obj_flags(
- zval *result, zval *ptr, zend_object *obj, zend_property_info *prop_info, uint32_t flags)
- {
- switch (flags) {
- case ZEND_FETCH_DIM_WRITE:
- if (promotes_to_array(ptr)) {
- if (!prop_info) {
- prop_info = zend_object_fetch_property_type_info(obj, ptr);
- if (!prop_info) {
- break;
- }
- }
- if (!check_type_array_assignable(prop_info->type)) {
- zend_throw_auto_init_in_prop_error(prop_info, "array");
- if (result) ZVAL_ERROR(result);
- return 0;
- }
- }
- break;
- case ZEND_FETCH_REF:
- if (Z_TYPE_P(ptr) != IS_REFERENCE) {
- if (!prop_info) {
- prop_info = zend_object_fetch_property_type_info(obj, ptr);
- if (!prop_info) {
- break;
- }
- }
- if (Z_TYPE_P(ptr) == IS_UNDEF) {
- if (!ZEND_TYPE_ALLOW_NULL(prop_info->type)) {
- zend_throw_access_uninit_prop_by_ref_error(prop_info);
- if (result) ZVAL_ERROR(result);
- return 0;
- }
- ZVAL_NULL(ptr);
- }
- ZVAL_NEW_REF(ptr, ptr);
- ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(ptr), prop_info);
- }
- break;
- EMPTY_SWITCH_DEFAULT_CASE()
- }
- return 1;
- }
- static void ZEND_FASTCALL zend_jit_fetch_obj_w_slow(zend_object *zobj)
- {
- zval *retval;
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = EX(opline);
- zend_string *name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
- zval *result = EX_VAR(opline->result.var);
- void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS);
- retval = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_W, cache_slot);
- if (NULL == retval) {
- retval = zobj->handlers->read_property(zobj, name, BP_VAR_W, cache_slot, result);
- if (retval == result) {
- if (UNEXPECTED(Z_ISREF_P(retval) && Z_REFCOUNT_P(retval) == 1)) {
- ZVAL_UNREF(retval);
- }
- return;
- }
- if (UNEXPECTED(EG(exception))) {
- ZVAL_ERROR(result);
- return;
- }
- } else if (UNEXPECTED(Z_ISERROR_P(retval))) {
- ZVAL_ERROR(result);
- return;
- }
- ZVAL_INDIRECT(result, retval);
- /* Support for typed properties */
- do {
- uint32_t flags = opline->extended_value & ZEND_FETCH_OBJ_FLAGS;
- if (flags) {
- zend_property_info *prop_info = NULL;
- if (opline->op2_type == IS_CONST) {
- prop_info = CACHED_PTR_EX(cache_slot + 2);
- if (!prop_info) {
- break;
- }
- }
- if (UNEXPECTED(!zend_handle_fetch_obj_flags(result, retval, zobj, prop_info, flags))) {
- return;
- }
- }
- } while (0);
- if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
- ZVAL_NULL(retval);
- }
- }
- static void ZEND_FASTCALL zend_jit_check_array_promotion(zval *val, zend_property_info *prop)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = execute_data->opline;
- zval *result = EX_VAR(opline->result.var);
- if ((Z_TYPE_P(val) <= IS_FALSE
- || (Z_ISREF_P(val) && Z_TYPE_P(Z_REFVAL_P(val)) <= IS_FALSE))
- && ZEND_TYPE_IS_SET(prop->type)
- && (ZEND_TYPE_FULL_MASK(prop->type) & (MAY_BE_ITERABLE|MAY_BE_ARRAY)) == 0) {
- zend_string *type_str = zend_type_to_string(prop->type);
- zend_type_error(
- "Cannot auto-initialize an array inside property %s::$%s of type %s",
- ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name),
- ZSTR_VAL(type_str)
- );
- zend_string_release(type_str);
- ZVAL_ERROR(result);
- } else {
- ZVAL_INDIRECT(result, val);
- }
- }
- static void ZEND_FASTCALL zend_jit_create_typed_ref(zval *val, zend_property_info *prop, zval *result)
- {
- if (!Z_ISREF_P(val)) {
- ZVAL_NEW_REF(val, val);
- ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(val), prop);
- }
- ZVAL_INDIRECT(result, val);
- }
- static void ZEND_FASTCALL zend_jit_extract_helper(zend_refcounted *garbage)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = execute_data->opline;
- zval *zv = EX_VAR(opline->result.var);
- if (EXPECTED(Z_TYPE_P(zv) == IS_INDIRECT)) {
- ZVAL_COPY(zv, Z_INDIRECT_P(zv));
- }
- rc_dtor_func(garbage);
- }
- static void ZEND_FASTCALL zend_jit_vm_stack_free_args_helper(zend_execute_data *call)
- {
- zend_vm_stack_free_args(call);
- }
- static zend_always_inline zval* zend_jit_assign_to_typed_ref_helper(zend_reference *ref, zval *value, zend_uchar value_type)
- {
- zval variable;
- ZVAL_REF(&variable, ref);
- return zend_assign_to_variable(&variable, value, value_type, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)));
- }
- static zval* ZEND_FASTCALL zend_jit_assign_const_to_typed_ref(zend_reference *ref, zval *value)
- {
- return zend_jit_assign_to_typed_ref_helper(ref, value, IS_CONST);
- }
- static zval* ZEND_FASTCALL zend_jit_assign_tmp_to_typed_ref(zend_reference *ref, zval *value)
- {
- return zend_jit_assign_to_typed_ref_helper(ref, value, IS_TMP_VAR);
- }
- static zval* ZEND_FASTCALL zend_jit_assign_var_to_typed_ref(zend_reference *ref, zval *value)
- {
- return zend_jit_assign_to_typed_ref_helper(ref, value, IS_VAR);
- }
- static zval* ZEND_FASTCALL zend_jit_assign_cv_to_typed_ref(zend_reference *ref, zval *value)
- {
- if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
- const zend_op *opline = EG(current_execute_data)->opline;
- uint32_t var;
- if (opline->opcode == ZEND_ASSIGN) {
- var = opline->op2.var;
- } else {
- ZEND_ASSERT((opline + 1)->opcode == ZEND_OP_DATA);
- var = (opline + 1)->op1.var;
- }
- zend_jit_undefined_op_helper(var);
- value = &EG(uninitialized_zval);
- }
- return zend_jit_assign_to_typed_ref_helper(ref, value, IS_CV);
- }
- static zend_property_info *zend_jit_get_prop_not_accepting_double(zend_reference *ref)
- {
- zend_property_info *prop;
- ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
- if (!(ZEND_TYPE_FULL_MASK(prop->type) & MAY_BE_DOUBLE)) {
- return prop;
- }
- } ZEND_REF_FOREACH_TYPE_SOURCES_END();
- return NULL;
- }
- static ZEND_COLD void zend_jit_throw_inc_ref_error(zend_reference *ref, zend_property_info *error_prop)
- {
- zend_string *type_str = zend_type_to_string(error_prop->type);
- zend_type_error(
- "Cannot increment a reference held by property %s::$%s of type %s past its maximal value",
- ZSTR_VAL(error_prop->ce->name),
- zend_get_unmangled_property_name(error_prop->name),
- ZSTR_VAL(type_str));
- zend_string_release(type_str);
- }
- static ZEND_COLD void zend_jit_throw_dec_ref_error(zend_reference *ref, zend_property_info *error_prop)
- {
- zend_string *type_str = zend_type_to_string(error_prop->type);
- zend_type_error(
- "Cannot decrement a reference held by property %s::$%s of type %s past its minimal value",
- ZSTR_VAL(error_prop->ce->name),
- zend_get_unmangled_property_name(error_prop->name),
- ZSTR_VAL(type_str));
- zend_string_release(type_str);
- }
- static void ZEND_FASTCALL zend_jit_pre_inc_typed_ref(zend_reference *ref, zval *ret)
- {
- zval *var_ptr = &ref->val;
- zval tmp;
- ZVAL_COPY(&tmp, var_ptr);
- increment_function(var_ptr);
- if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE(tmp) == IS_LONG) {
- zend_property_info *error_prop = zend_jit_get_prop_not_accepting_double(ref);
- if (UNEXPECTED(error_prop)) {
- zend_jit_throw_inc_ref_error(ref, error_prop);
- ZVAL_LONG(var_ptr, ZEND_LONG_MAX);
- }
- } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
- zval_ptr_dtor(var_ptr);
- ZVAL_COPY_VALUE(var_ptr, &tmp);
- } else {
- zval_ptr_dtor(&tmp);
- }
- if (ret) {
- ZVAL_COPY(ret, var_ptr);
- }
- }
- static void ZEND_FASTCALL zend_jit_pre_dec_typed_ref(zend_reference *ref, zval *ret)
- {
- zval *var_ptr = &ref->val;
- zval tmp;
- ZVAL_COPY(&tmp, var_ptr);
- decrement_function(var_ptr);
- if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE(tmp) == IS_LONG) {
- zend_property_info *error_prop = zend_jit_get_prop_not_accepting_double(ref);
- if (UNEXPECTED(error_prop)) {
- zend_jit_throw_dec_ref_error(ref, error_prop);
- ZVAL_LONG(var_ptr, ZEND_LONG_MIN);
- }
- } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
- zval_ptr_dtor(var_ptr);
- ZVAL_COPY_VALUE(var_ptr, &tmp);
- } else {
- zval_ptr_dtor(&tmp);
- }
- if (ret) {
- ZVAL_COPY(ret, var_ptr);
- }
- }
- static void ZEND_FASTCALL zend_jit_post_inc_typed_ref(zend_reference *ref, zval *ret)
- {
- zval *var_ptr = &ref->val;
- ZVAL_COPY(ret, var_ptr);
- increment_function(var_ptr);
- if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(ret) == IS_LONG) {
- zend_property_info *error_prop = zend_jit_get_prop_not_accepting_double(ref);
- if (UNEXPECTED(error_prop)) {
- zend_jit_throw_inc_ref_error(ref, error_prop);
- ZVAL_LONG(var_ptr, ZEND_LONG_MAX);
- }
- } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
- zval_ptr_dtor(var_ptr);
- ZVAL_COPY_VALUE(var_ptr, ret);
- }
- }
- static void ZEND_FASTCALL zend_jit_post_dec_typed_ref(zend_reference *ref, zval *ret)
- {
- zval *var_ptr = &ref->val;
- ZVAL_COPY(ret, var_ptr);
- decrement_function(var_ptr);
- if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(ret) == IS_LONG) {
- zend_property_info *error_prop = zend_jit_get_prop_not_accepting_double(ref);
- if (UNEXPECTED(error_prop)) {
- zend_jit_throw_dec_ref_error(ref, error_prop);
- ZVAL_LONG(var_ptr, ZEND_LONG_MIN);
- }
- } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
- zval_ptr_dtor(var_ptr);
- ZVAL_COPY_VALUE(var_ptr, ret);
- }
- }
- static void ZEND_FASTCALL zend_jit_assign_op_to_typed_ref(zend_reference *ref, zval *val, binary_op_type binary_op)
- {
- zval z_copy;
- /* Make sure that in-place concatenation is used if the LHS is a string. */
- if (binary_op == concat_function && Z_TYPE(ref->val) == IS_STRING) {
- concat_function(&ref->val, &ref->val, val);
- ZEND_ASSERT(Z_TYPE(ref->val) == IS_STRING && "Concat should return string");
- return;
- }
- binary_op(&z_copy, &ref->val, val);
- if (EXPECTED(zend_verify_ref_assignable_zval(ref, &z_copy, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
- zval_ptr_dtor(&ref->val);
- ZVAL_COPY_VALUE(&ref->val, &z_copy);
- } else {
- zval_ptr_dtor(&z_copy);
- }
- }
- static void ZEND_FASTCALL zend_jit_assign_op_to_typed_ref_tmp(zend_reference *ref, zval *val, binary_op_type binary_op)
- {
- zval z_copy;
- binary_op(&z_copy, &ref->val, val);
- if (EXPECTED(zend_verify_ref_assignable_zval(ref, &z_copy, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
- zval_ptr_dtor(&ref->val);
- ZVAL_COPY_VALUE(&ref->val, &z_copy);
- } else {
- zval_ptr_dtor(&z_copy);
- }
- zval_ptr_dtor_nogc(val);
- }
- static void ZEND_FASTCALL zend_jit_only_vars_by_reference(zval *arg)
- {
- ZVAL_NEW_REF(arg, arg);
- zend_error(E_NOTICE, "Only variables should be passed by reference");
- }
- static void ZEND_FASTCALL zend_jit_invalid_array_access(zval *container)
- {
- zend_error(E_WARNING, "Trying to access array offset on value of type %s", zend_zval_type_name(container));
- }
- static void ZEND_FASTCALL zend_jit_invalid_property_read(zval *container, const char *property_name)
- {
- zend_error(E_WARNING, "Attempt to read property \"%s\" on %s", property_name, zend_zval_type_name(container));
- }
- static void ZEND_FASTCALL zend_jit_invalid_property_write(zval *container, const char *property_name)
- {
- zend_throw_error(NULL,
- "Attempt to modify property \"%s\" on %s",
- property_name, zend_zval_type_name(container));
- }
- static void ZEND_FASTCALL zend_jit_invalid_property_incdec(zval *container, const char *property_name)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- const zend_op *opline = EX(opline);
- if (Z_TYPE_P(container) == IS_UNDEF && opline->op1_type == IS_CV) {
- zend_string *cv = EX(func)->op_array.vars[EX_VAR_TO_NUM(opline->op1.var)];
- zend_error(E_WARNING, "Undefined variable $%s", ZSTR_VAL(cv));
- }
- if (opline->result_type & (IS_VAR|IS_TMP_VAR)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- zend_throw_error(NULL,
- "Attempt to increment/decrement property \"%s\" on %s",
- property_name, zend_zval_type_name(container));
- if (opline->op1_type == IS_VAR) {
- zval_ptr_dtor_nogc(EX_VAR(opline->op1.var));
- }
- }
- static void ZEND_FASTCALL zend_jit_invalid_property_assign(zval *container, const char *property_name)
- {
- zend_throw_error(NULL,
- "Attempt to assign property \"%s\" on %s",
- property_name, zend_zval_type_name(container));
- }
- static void ZEND_FASTCALL zend_jit_invalid_property_assign_op(zval *container, const char *property_name)
- {
- if (Z_TYPE_P(container) == IS_UNDEF) {
- const zend_execute_data *execute_data = EG(current_execute_data);
- zend_jit_undefined_op_helper(EX(opline)->op1.var);
- }
- zend_jit_invalid_property_assign(container, property_name);
- }
- static zval * ZEND_FASTCALL zend_jit_prepare_assign_dim_ref(zval *ref) {
- zval *val = Z_REFVAL_P(ref);
- if (Z_TYPE_P(val) <= IS_FALSE) {
- if (ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(ref))
- && !zend_verify_ref_array_assignable(Z_REF_P(ref))) {
- return NULL;
- }
- if (Z_TYPE_P(val) == IS_FALSE) {
- ZVAL_ARR(val, zend_new_array(8));
- zend_false_to_array_deprecated();
- if (EG(exception)) {
- return NULL;
- }
- } else {
- ZVAL_ARR(val, zend_new_array(8));
- }
- }
- return val;
- }
- static void ZEND_FASTCALL zend_jit_pre_inc(zval *var_ptr, zval *ret)
- {
- increment_function(var_ptr);
- ZVAL_COPY(ret, var_ptr);
- }
- static void ZEND_FASTCALL zend_jit_pre_dec(zval *var_ptr, zval *ret)
- {
- decrement_function(var_ptr);
- ZVAL_COPY(ret, var_ptr);
- }
- #define HT_POISONED_PTR ((HashTable *) (intptr_t) -1)
- static zend_never_inline void ZEND_FASTCALL _zend_hash_iterators_remove(HashTable *ht)
- {
- HashTableIterator *iter = EG(ht_iterators);
- HashTableIterator *end = iter + EG(ht_iterators_used);
- while (iter != end) {
- if (iter->ht == ht) {
- iter->ht = HT_POISONED_PTR;
- }
- iter++;
- }
- }
- static void ZEND_FASTCALL zend_jit_array_free(HashTable *ht)
- {
- GC_REMOVE_FROM_BUFFER(ht);
- if (UNEXPECTED(HT_HAS_ITERATORS(ht))) {
- _zend_hash_iterators_remove(ht);
- }
- if (!(EXPECTED(HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED))) {
- efree(HT_GET_DATA_ADDR(ht));
- }
- FREE_HASHTABLE(ht);
- }
- static HashTable *ZEND_FASTCALL zend_jit_zval_array_dup(zval *arr)
- {
- HashTable *ht;
- Z_TRY_DELREF_P(arr);
- ht = Z_ARRVAL_P(arr);
- ht = zend_array_dup(ht);
- ZVAL_ARR(arr, ht);
- return ht;
- }
- static zend_array *ZEND_FASTCALL zend_jit_add_arrays_helper(zend_array *op1, zend_array *op2)
- {
- zend_array *res;
- res = zend_array_dup(op1);
- zend_hash_merge(res, op2, zval_add_ref, 0);
- return res;
- }
- static void ZEND_FASTCALL zend_jit_assign_obj_helper(zend_object *zobj, zend_string *name, zval *value, void **cache_slot, zval *result)
- {
- if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
- const zend_op *op_data = EG(current_execute_data)->opline + 1;
- ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
- zend_jit_undefined_op_helper(op_data->op1.var);
- value = &EG(uninitialized_zval);
- }
- ZVAL_DEREF(value);
- value = zobj->handlers->write_property(zobj, name, value, cache_slot);
- if (result) {
- ZVAL_COPY_DEREF(result, value);
- }
- }
- static void ZEND_FASTCALL zend_jit_assign_to_typed_prop(zval *property_val, zend_property_info *info, zval *value, zval *result)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- zval tmp;
- if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
- const zend_op *op_data = execute_data->opline + 1;
- ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
- zend_jit_undefined_op_helper(op_data->op1.var);
- value = &EG(uninitialized_zval);
- }
- if (UNEXPECTED(info->flags & ZEND_ACC_READONLY)) {
- zend_readonly_property_modification_error(info);
- if (result) {
- ZVAL_UNDEF(result);
- }
- return;
- }
- ZVAL_DEREF(value);
- ZVAL_COPY(&tmp, value);
- if (UNEXPECTED(!zend_verify_property_type(info, &tmp, EX_USES_STRICT_TYPES()))) {
- zval_ptr_dtor(&tmp);
- if (result) {
- ZVAL_NULL(result);
- }
- return;
- }
- value = zend_assign_to_variable(property_val, &tmp, IS_TMP_VAR, EX_USES_STRICT_TYPES());
- if (result) {
- ZVAL_COPY_DEREF(result, value);
- }
- }
- static zend_never_inline void _zend_jit_assign_op_overloaded_property(zend_object *object, zend_string *name, void **cache_slot, zval *value, binary_op_type binary_op)
- {
- zval *z;
- zval rv, res;
- GC_ADDREF(object);
- z = object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv);
- if (UNEXPECTED(EG(exception))) {
- OBJ_RELEASE(object);
- //??? if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- //??? ZVAL_UNDEF(EX_VAR(opline->result.var));
- //??? }
- return;
- }
- if (binary_op(&res, z, value) == SUCCESS) {
- object->handlers->write_property(object, name, &res, cache_slot);
- }
- //??? if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- //??? ZVAL_COPY(EX_VAR(opline->result.var), &res);
- //??? }
- if (z == &rv) {
- zval_ptr_dtor(z);
- }
- zval_ptr_dtor(&res);
- OBJ_RELEASE(object);
- }
- static void ZEND_FASTCALL zend_jit_assign_op_to_typed_prop(zval *zptr, zend_property_info *prop_info, zval *value, binary_op_type binary_op)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- zval z_copy;
- if (UNEXPECTED(prop_info->flags & ZEND_ACC_READONLY)) {
- zend_readonly_property_modification_error(prop_info);
- return;
- }
- ZVAL_DEREF(zptr);
- /* Make sure that in-place concatenation is used if the LHS is a string. */
- if (binary_op == concat_function && Z_TYPE_P(zptr) == IS_STRING) {
- concat_function(zptr, zptr, value);
- ZEND_ASSERT(Z_TYPE_P(zptr) == IS_STRING && "Concat should return string");
- return;
- }
- binary_op(&z_copy, zptr, value);
- if (EXPECTED(zend_verify_property_type(prop_info, &z_copy, EX_USES_STRICT_TYPES()))) {
- zval_ptr_dtor(zptr);
- ZVAL_COPY_VALUE(zptr, &z_copy);
- } else {
- zval_ptr_dtor(&z_copy);
- }
- }
- static void ZEND_FASTCALL zend_jit_assign_obj_op_helper(zend_object *zobj, zend_string *name, zval *value, void **cache_slot, binary_op_type binary_op)
- {
- zval *zptr;
- zend_property_info *prop_info;
- if (EXPECTED((zptr = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_RW, cache_slot)) != NULL)) {
- if (UNEXPECTED(Z_ISERROR_P(zptr))) {
- //??? if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- //??? ZVAL_NULL(EX_VAR(opline->result.var));
- //??? }
- } else {
- //??? zval *orig_zptr = zptr;
- zend_reference *ref;
- do {
- if (UNEXPECTED(Z_ISREF_P(zptr))) {
- ref = Z_REF_P(zptr);
- zptr = Z_REFVAL_P(zptr);
- if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) {
- zend_jit_assign_op_to_typed_ref(ref, value, binary_op);
- break;
- }
- }
- //??? if (OP2_TYPE == IS_CONST) {
- prop_info = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
- //??? } else {
- //??? prop_info = zend_object_fetch_property_type_info(Z_OBJ_P(object), orig_zptr);
- //??? }
- if (UNEXPECTED(prop_info)) {
- /* special case for typed properties */
- zend_jit_assign_op_to_typed_prop(zptr, prop_info, value, binary_op);
- } else {
- binary_op(zptr, zptr, value);
- }
- } while (0);
- //??? if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- //??? ZVAL_COPY(EX_VAR(opline->result.var), zptr);
- //??? }
- }
- } else {
- _zend_jit_assign_op_overloaded_property(zobj, name, cache_slot, value, binary_op);
- }
- }
- static ZEND_COLD zend_long _zend_jit_throw_inc_prop_error(zend_property_info *prop)
- {
- zend_string *type_str = zend_type_to_string(prop->type);
- zend_type_error("Cannot increment property %s::$%s of type %s past its maximal value",
- ZSTR_VAL(prop->ce->name),
- zend_get_unmangled_property_name(prop->name),
- ZSTR_VAL(type_str));
- zend_string_release(type_str);
- return ZEND_LONG_MAX;
- }
- static ZEND_COLD zend_long _zend_jit_throw_dec_prop_error(zend_property_info *prop)
- {
- zend_string *type_str = zend_type_to_string(prop->type);
- zend_type_error("Cannot decrement property %s::$%s of type %s past its minimal value",
- ZSTR_VAL(prop->ce->name),
- zend_get_unmangled_property_name(prop->name),
- ZSTR_VAL(type_str));
- zend_string_release(type_str);
- return ZEND_LONG_MIN;
- }
- static void ZEND_FASTCALL zend_jit_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- zval tmp;
- ZVAL_DEREF(var_ptr);
- ZVAL_COPY(&tmp, var_ptr);
- increment_function(var_ptr);
- if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE(tmp) == IS_LONG) {
- if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
- zend_long val = _zend_jit_throw_inc_prop_error(prop_info);
- ZVAL_LONG(var_ptr, val);
- }
- } else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) {
- zval_ptr_dtor(var_ptr);
- ZVAL_COPY_VALUE(var_ptr, &tmp);
- } else {
- zval_ptr_dtor(&tmp);
- }
- }
- static void ZEND_FASTCALL zend_jit_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- zval tmp;
- ZVAL_DEREF(var_ptr);
- ZVAL_COPY(&tmp, var_ptr);
- decrement_function(var_ptr);
- if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE(tmp) == IS_LONG) {
- if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
- zend_long val = _zend_jit_throw_dec_prop_error(prop_info);
- ZVAL_LONG(var_ptr, val);
- }
- } else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) {
- zval_ptr_dtor(var_ptr);
- ZVAL_COPY_VALUE(var_ptr, &tmp);
- } else {
- zval_ptr_dtor(&tmp);
- }
- }
- static void ZEND_FASTCALL zend_jit_pre_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
- {
- ZVAL_DEREF(var_ptr);
- zend_jit_inc_typed_prop(var_ptr, prop_info);
- ZVAL_COPY(result, var_ptr);
- }
- static void ZEND_FASTCALL zend_jit_pre_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
- {
- ZVAL_DEREF(var_ptr);
- zend_jit_dec_typed_prop(var_ptr, prop_info);
- ZVAL_COPY(result, var_ptr);
- }
- static void ZEND_FASTCALL zend_jit_post_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- ZVAL_DEREF(var_ptr);
- ZVAL_COPY(result, var_ptr);
- increment_function(var_ptr);
- if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(result) == IS_LONG) {
- if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
- zend_long val = _zend_jit_throw_inc_prop_error(prop_info);
- ZVAL_LONG(var_ptr, val);
- }
- } else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) {
- zval_ptr_dtor(var_ptr);
- ZVAL_COPY_VALUE(var_ptr, result);
- ZVAL_UNDEF(result);
- }
- }
- static void ZEND_FASTCALL zend_jit_post_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
- {
- zend_execute_data *execute_data = EG(current_execute_data);
- ZVAL_DEREF(var_ptr);
- ZVAL_COPY(result, var_ptr);
- decrement_function(var_ptr);
- if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(result) == IS_LONG) {
- if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
- zend_long val = _zend_jit_throw_dec_prop_error(prop_info);
- ZVAL_LONG(var_ptr, val);
- }
- } else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) {
- zval_ptr_dtor(var_ptr);
- ZVAL_COPY_VALUE(var_ptr, result);
- ZVAL_UNDEF(result);
- }
- }
- static void ZEND_FASTCALL zend_jit_pre_inc_obj_helper(zend_object *zobj, zend_string *name, void **cache_slot, zval *result)
- {
- zval *prop;
- if (EXPECTED((prop = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_RW, cache_slot)) != NULL)) {
- if (UNEXPECTED(Z_ISERROR_P(prop))) {
- if (UNEXPECTED(result)) {
- ZVAL_NULL(result);
- }
- } else {
- zend_property_info *prop_info = (zend_property_info *) CACHED_PTR_EX(cache_slot + 2);
- if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
- fast_long_increment_function(prop);
- if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && UNEXPECTED(prop_info)
- && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
- zend_long val = _zend_jit_throw_inc_prop_error(prop_info);
- ZVAL_LONG(prop, val);
- }
- } else {
- do {
- if (Z_ISREF_P(prop)) {
- zend_reference *ref = Z_REF_P(prop);
- prop = Z_REFVAL_P(prop);
- if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) {
- zend_jit_pre_inc_typed_ref(ref, result);
- break;
- }
- }
- if (UNEXPECTED(prop_info)) {
- zend_jit_inc_typed_prop(prop, prop_info);
- } else {
- increment_function(prop);
- }
- } while (0);
- }
- if (UNEXPECTED(result)) {
- ZVAL_COPY(result, prop);
- }
- }
- } else {
- zval rv;
- zval *z;
- zval z_copy;
- GC_ADDREF(zobj);
- z = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, &rv);
- if (UNEXPECTED(EG(exception))) {
- OBJ_RELEASE(zobj);
- if (UNEXPECTED(result)) {
- ZVAL_NULL(result);
- }
- return;
- }
- ZVAL_COPY_DEREF(&z_copy, z);
- increment_function(&z_copy);
- if (UNEXPECTED(result)) {
- ZVAL_COPY(result, &z_copy);
- }
- zobj->handlers->write_property(zobj, name, &z_copy, cache_slot);
- OBJ_RELEASE(zobj);
- zval_ptr_dtor(&z_copy);
- if (z == &rv) {
- zval_ptr_dtor(z);
- }
- }
- }
- static void ZEND_FASTCALL zend_jit_pre_dec_obj_helper(zend_object *zobj, zend_string *name, void **cache_slot, zval *result)
- {
- zval *prop;
- if (EXPECTED((prop = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_RW, cache_slot)) != NULL)) {
- if (UNEXPECTED(Z_ISERROR_P(prop))) {
- if (UNEXPECTED(result)) {
- ZVAL_NULL(result);
- }
- } else {
- zend_property_info *prop_info = (zend_property_info *) CACHED_PTR_EX(cache_slot + 2);
- if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
- fast_long_decrement_function(prop);
- if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && UNEXPECTED(prop_info)
- && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
- zend_long val = _zend_jit_throw_dec_prop_error(prop_info);
- ZVAL_LONG(prop, val);
- }
- } else {
- do {
- if (Z_ISREF_P(prop)) {
- zend_reference *ref = Z_REF_P(prop);
- prop = Z_REFVAL_P(prop);
- if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) {
- zend_jit_pre_dec_typed_ref(ref, result);
- break;
- }
- }
- if (UNEXPECTED(prop_info)) {
- zend_jit_dec_typed_prop(prop, prop_info);
- } else {
- decrement_function(prop);
- }
- } while (0);
- }
- if (UNEXPECTED(result)) {
- ZVAL_COPY(result, prop);
- }
- }
- } else {
- zval rv;
- zval *z;
- zval z_copy;
- GC_ADDREF(zobj);
- z = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, &rv);
- if (UNEXPECTED(EG(exception))) {
- OBJ_RELEASE(zobj);
- if (UNEXPECTED(result)) {
- ZVAL_NULL(result);
- }
- return;
- }
- ZVAL_COPY_DEREF(&z_copy, z);
- decrement_function(&z_copy);
- if (UNEXPECTED(result)) {
- ZVAL_COPY(result, &z_copy);
- }
- zobj->handlers->write_property(zobj, name, &z_copy, cache_slot);
- OBJ_RELEASE(zobj);
- zval_ptr_dtor(&z_copy);
- if (z == &rv) {
- zval_ptr_dtor(z);
- }
- }
- }
- static void ZEND_FASTCALL zend_jit_post_inc_obj_helper(zend_object *zobj, zend_string *name, void **cache_slot, zval *result)
- {
- zval *prop;
- if (EXPECTED((prop = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_RW, cache_slot)) != NULL)) {
- if (UNEXPECTED(Z_ISERROR_P(prop))) {
- ZVAL_NULL(result);
- } else {
- zend_property_info *prop_info = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
- if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
- ZVAL_LONG(result, Z_LVAL_P(prop));
- fast_long_increment_function(prop);
- if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && UNEXPECTED(prop_info)
- && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
- zend_long val = _zend_jit_throw_inc_prop_error(prop_info);
- ZVAL_LONG(prop, val);
- }
- } else {
- if (Z_ISREF_P(prop)) {
- zend_reference *ref = Z_REF_P(prop);
- prop = Z_REFVAL_P(prop);
- if (ZEND_REF_HAS_TYPE_SOURCES(ref)) {
- zend_jit_post_inc_typed_ref(ref, result);
- return;
- }
- }
- if (UNEXPECTED(prop_info)) {
- zend_jit_post_inc_typed_prop(prop, prop_info, result);
- } else {
- ZVAL_COPY(result, prop);
- increment_function(prop);
- }
- }
- }
- } else {
- zval rv;
- zval *z;
- zval z_copy;
- GC_ADDREF(zobj);
- z = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, &rv);
- if (UNEXPECTED(EG(exception))) {
- OBJ_RELEASE(zobj);
- ZVAL_UNDEF(result);
- return;
- }
- ZVAL_COPY_DEREF(&z_copy, z);
- ZVAL_COPY(result, &z_copy);
- increment_function(&z_copy);
- zobj->handlers->write_property(zobj, name, &z_copy, cache_slot);
- OBJ_RELEASE(zobj);
- zval_ptr_dtor(&z_copy);
- if (z == &rv) {
- zval_ptr_dtor(z);
- }
- }
- }
- static void ZEND_FASTCALL zend_jit_post_dec_obj_helper(zend_object *zobj, zend_string *name, void **cache_slot, zval *result)
- {
- zval *prop;
- if (EXPECTED((prop = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_RW, cache_slot)) != NULL)) {
- if (UNEXPECTED(Z_ISERROR_P(prop))) {
- ZVAL_NULL(result);
- } else {
- zend_property_info *prop_info = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
- if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
- ZVAL_LONG(result, Z_LVAL_P(prop));
- fast_long_decrement_function(prop);
- if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && UNEXPECTED(prop_info)
- && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
- zend_long val = _zend_jit_throw_dec_prop_error(prop_info);
- ZVAL_LONG(prop, val);
- }
- } else {
- if (Z_ISREF_P(prop)) {
- zend_reference *ref = Z_REF_P(prop);
- prop = Z_REFVAL_P(prop);
- if (ZEND_REF_HAS_TYPE_SOURCES(ref)) {
- zend_jit_post_dec_typed_ref(ref, result);
- return;
- }
- }
- if (UNEXPECTED(prop_info)) {
- zend_jit_post_dec_typed_prop(prop, prop_info, result);
- } else {
- ZVAL_COPY(result, prop);
- decrement_function(prop);
- }
- }
- }
- } else {
- zval rv;
- zval *z;
- zval z_copy;
- GC_ADDREF(zobj);
- z = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, &rv);
- if (UNEXPECTED(EG(exception))) {
- OBJ_RELEASE(zobj);
- ZVAL_UNDEF(result);
- return;
- }
- ZVAL_COPY_DEREF(&z_copy, z);
- ZVAL_COPY(result, &z_copy);
- decrement_function(&z_copy);
- zobj->handlers->write_property(zobj, name, &z_copy, cache_slot);
- OBJ_RELEASE(zobj);
- zval_ptr_dtor(&z_copy);
- if (z == &rv) {
- zval_ptr_dtor(z);
- }
- }
- }
- #if (PHP_VERSION_ID <= 80100) && (SIZEOF_SIZE_T == 4)
- static zend_result ZEND_FASTCALL zval_jit_update_constant_ex(zval *p, zend_class_entry *scope)
- {
- if (Z_TYPE_P(p) == IS_CONSTANT_AST) {
- zend_ast *ast = Z_ASTVAL_P(p);
- if (ast->kind == ZEND_AST_CONSTANT) {
- zend_string *name = zend_ast_get_constant_name(ast);
- zval *zv = zend_get_constant_ex(name, scope, ast->attr);
- if (UNEXPECTED(zv == NULL)) {
- return FAILURE;
- }
- zval_ptr_dtor_nogc(p);
- ZVAL_COPY_OR_DUP(p, zv);
- } else {
- zval tmp;
- if (UNEXPECTED(zend_ast_evaluate(&tmp, ast, scope) != SUCCESS)) {
- return FAILURE;
- }
- zval_ptr_dtor_nogc(p);
- ZVAL_COPY_VALUE(p, &tmp);
- }
- }
- return SUCCESS;
- }
- #endif
- static void ZEND_FASTCALL zend_jit_free_trampoline_helper(zend_function *func)
- {
- ZEND_ASSERT(func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE);
- zend_string_release_ex(func->common.function_name, 0);
- zend_free_trampoline(func);
- }
- static void ZEND_FASTCALL zend_jit_exception_in_interrupt_handler_helper(void)
- {
- if (EG(exception)) {
- /* We have to UNDEF result, because ZEND_HANDLE_EXCEPTION is going to free it */
- const zend_op *throw_op = EG(opline_before_exception);
- if (throw_op
- && throw_op->result_type & (IS_TMP_VAR|IS_VAR)
- && throw_op->opcode != ZEND_ADD_ARRAY_ELEMENT
- && throw_op->opcode != ZEND_ADD_ARRAY_UNPACK
- && throw_op->opcode != ZEND_ROPE_INIT
- && throw_op->opcode != ZEND_ROPE_ADD) {
- ZVAL_UNDEF(ZEND_CALL_VAR(EG(current_execute_data), throw_op->result.var));
- }
- }
- }
- static zend_string* ZEND_FASTCALL zend_jit_rope_end(zend_string **rope, uint32_t count)
- {
- zend_string *ret;
- uint32_t i;
- size_t len = 0;
- char *target;
- for (i = 0; i <= count; i++) {
- len += ZSTR_LEN(rope[i]);
- }
- ret = zend_string_alloc(len, 0);
- target = ZSTR_VAL(ret);
- for (i = 0; i <= count; i++) {
- memcpy(target, ZSTR_VAL(rope[i]), ZSTR_LEN(rope[i]));
- target += ZSTR_LEN(rope[i]);
- zend_string_release_ex(rope[i], 0);
- }
- *target = '\0';
- return ret;
- }
|