← All docs

The Runtime

Hand-written assembly routines for strings, arrays, generators, fibers, system calls, exceptions, and I/O.

Source: src/codegen/runtime/mod.rs, emitters.rs, data/, x86_minimal.rs, strings/, arrays/, buffers/, callables/, exceptions.rs, exceptions/, io/, objects/, system/, pointers/, fibers/, generators/

The runtime is a collection of hand-written assembly routines that handle operations too complex for inline code generation. When the code generator needs to convert an integer to a string or concatenate two strings, it emits a bl __rt_itoa or bl __rt_concat — a call to a runtime routine.

These routines end up in every compiled binary. In the CLI flow they are usually pre-assembled into the cached runtime object rather than textually appended to each user .s file, but they are still part of the final executable rather than an external shared dependency.

Why a runtime?

Some operations can’t be done with a few inline instructions:

  • Integer to string (itoa): Requires a loop that divides by 10, extracts digits, and writes them right-to-left
  • String concatenation: Needs to copy bytes from two source strings into a buffer
  • Array operations: Require heap allocation, bounds checking, and element copying

These are 20-50+ instructions each. Inlining them at every call site would bloat the binary. Instead, they’re emitted once and called with bl.

Naming convention

All runtime routines start with __rt_:

__rt_itoa          integer → string
__rt_resource_to_string resource → "Resource id #N"
__rt_ftoa          float → string
__rt_concat        string + string → string
__rt_str_eq        string == string → bool
__rt_array_new     allocate a new array
__rt_throw_current throw the active exception
__rt_build_argv    build $argv from C strings

Diagnostic routines

Source: src/codegen/runtime/diagnostics.rs

These helpers implement PHP’s @ error-suppression operator and the runtime warning channel. The suppression depth lives in _rt_diag_suppression; while it is non-zero, suppressible warnings are silently dropped instead of written to stderr. They are emitted before any PHP-visible helper so the rest of the runtime can report warnings through a single path.

RoutineWhat it doesInputOutput
__rt_diag_push_suppressionEnter one nested @ suppression scope (increment _rt_diag_suppression)
__rt_diag_pop_suppressionLeave one @ suppression scope, clamped against underflow
__rt_diag_warningWrite a runtime warning string to stderr unless suppression is activex1/x2 = message string

String routines

Source: src/codegen/runtime/strings/

__rt_itoa — Integer to string

File: strings/itoa.rs

Converts a signed 64-bit integer in x0 to a decimal string.

Input: x0 = integer value Output: x1 = pointer to string, x2 = length

Algorithm:

  1. Check for negative → set flag, negate
  2. Check for zero → output “0” directly
  3. Loop: divide by 10 (udiv + msub), convert remainder to ASCII digit (+ 48), store right-to-left
  4. Prepend ’-’ if negative
  5. Update concat buffer offset

The digits are written right-to-left because division gives us the least significant digit first. The result is written into the concat buffer.

__rt_resource_to_string — Resource to string

File: strings/resource_to_string.rs

Formats the native resource payload used by stream handles as PHP’s display string (Resource id #N). The helper keeps resources distinct from integers when boxing into mixed, while still letting the I/O runtime pass the underlying file descriptor to stream syscalls.

Input: x0 = native resource payload Output: x1 = pointer to string, x2 = length

__rt_resource_write_stdout uses the same display form for echo / print without exposing the raw file descriptor as an integer.

__rt_ftoa — Float to string

File: strings/ftoa.rs

Converts a double-precision float in d0 to a decimal string. Handles special cases: INF, -INF, NAN. For normal numbers, it separates the integer and fractional parts, converts each to digits, and joins them with a decimal point.

Input: d0 = float value Output: x1 = pointer to string, x2 = length

__rt_concat — String concatenation

File: strings/concat.rs

Concatenates two strings by copying both into the concat buffer.

Input: x1/x2 = left string (ptr/len), x3/x4 = right string (ptr/len) Output: x1 = pointer to result, x2 = total length

Algorithm:

  1. Get current position in concat buffer
  2. Copy left string bytes (byte-by-byte loop)
  3. Copy right string bytes
  4. Update buffer offset
  5. Return pointer to start of result + total length

__rt_atoi — String to integer

File: strings/atoi.rs

Parses a decimal string into a 64-bit integer. Handles optional leading - sign.

Input: x1 = string pointer, x2 = length Output: x0 = integer value

__rt_str_eq — String equality

File: strings/str_eq.rs

Compares two strings byte-by-byte.

Input: x1/x2 = first string, x3/x4 = second string Output: x0 = 1 if equal, 0 if not

Algorithm:

  1. Compare lengths — if different, return 0 immediately
  2. Loop: compare byte by byte
  3. If all bytes match, return 1

Other string routines

Each routine follows the same pattern — inputs in registers, output in standard result registers:

RoutineWhat it doesInputOutput
__rt_strcopyCopy string into concat bufferx1/x2x1/x2
__rt_str_to_numberParse a PHP numeric string for loose comparison and numeric-string castsx1/x2numeric payload + success flag
__rt_str_loose_eqCompare two strings using PHP loose-comparison numeric-string rules before falling back to bytestwo stringsx0 (0 or 1)
__rt_strtolowerLowercase conversionx1/x2x1/x2
__rt_strtoupperUppercase conversionx1/x2x1/x2
__rt_trimStrip whitespace (no args) or chars in maskx1/x2x1/x2
__rt_ltrim / __rt_rtrimStrip left/right whitespace or maskx1/x2x1/x2
__rt_trim_maskStrip chars in custom mask from both endsx1/x2 + maskx1/x2
__rt_ltrim_mask / __rt_rtrim_maskStrip custom mask from left/rightx1/x2 + maskx1/x2
__rt_strrevReverse stringx1/x2x1/x2
__rt_strposFind substringx1/x2 + x3/x4x0 (index or -1)
__rt_strrposFind last occurrencex1/x2 + x3/x4x0
__rt_str_repeatRepeat N times with heap fallback for large resultsx1/x2 + countx1/x2
__rt_str_replaceReplace all occurrencessearch + replace + subjectx1/x2
__rt_explodeSplit by delimiterdelimiter + stringx0 (array ptr)
__rt_implodeJoin string array with glueglue + arrayx1/x2
__rt_implode_intJoin integer array with glueglue + arrayx1/x2
__rt_strcmpBinary comparisontwo stringsx0 (-1, 0, 1)
__rt_strcasecmpCase-insensitive comparetwo stringsx0
__rt_str_starts_withCheck prefix matchx1/x2 + x3/x4x0 (0 or 1)
__rt_str_ends_withCheck suffix matchx1/x2 + x3/x4x0 (0 or 1)
__rt_chrASCII code → charx0x1/x2
__rt_addslashesEscape quotes/backslashesx1/x2x1/x2
__rt_nl2brInsert <br /> before newlinesx1/x2x1/x2
__rt_bin2hexBinary → hex stringx1/x2x1/x2
__rt_hex2binHex → binaryx1/x2x1/x2
__rt_md5MD5 hashx1/x2x1/x2
__rt_sha1SHA1 hashx1/x2x1/x2
__rt_sprintfFormat stringformat + args on stackx1/x2
__rt_base64_encodeBase64 encodex1/x2x1/x2
__rt_base64_decodeBase64 decodex1/x2x1/x2
__rt_urlencodeURL encodex1/x2x1/x2
__rt_urldecodeURL decodex1/x2x1/x2
__rt_htmlspecialcharsHTML escapex1/x2x1/x2
__rt_html_entity_decodeDecode HTML entitiesx1/x2x1/x2
__rt_rawurlencodeURL encode (RFC 3986)x1/x2x1/x2
__rt_stripslashesRemove escape backslashesx1/x2x1/x2
__rt_ucwordsUppercase first letter of each wordx1/x2x1/x2
__rt_str_ireplaceCase-insensitive replacesearch + replace + subjectx1/x2
__rt_substr_replaceReplace substring at offsetstr + replacement + start + lenx1/x2
__rt_str_padPad string to lengthstr + len + pad_str + typex1/x2
__rt_str_splitSplit into chunksstr + chunk_lenx0 (array ptr)
__rt_wordwrapWrap text at widthstr + width + breakx1/x2
__rt_number_formatFormat number with separatorsfloat + decimals + sepx1/x2
__rt_hashHash with algorithmalgo + datax1/x2
__rt_sscanfParse string with formatstr + formatx0 (array ptr)

Callable routines

Source: src/codegen/runtime/callables/ (2 files)

These routines implement the runtime fallback path for is_callable() when the argument is not a compile-time literal or statically known callable value. They consult generated metadata for builtins, user functions, public methods, public static methods, and __invoke objects.

RoutineWhat it doesInputOutput
__rt_is_callable_stringResolve a string as a builtin, active user function, or Class::method static-method callablex1/x2 = stringx0 = bool
__rt_is_callable_method_nameCheck whether an object exposes a public method with the supplied nameobject pointer + method stringx0 = bool
__rt_is_callable_static_method_nameCheck whether a class string exposes a public static method with the supplied nameclass string + method stringx0 = bool
__rt_is_callable_objectCheck object callability through public __invoke metadataobject pointerx0 = bool
__rt_is_callable_arrayValidate indexed callable arrays such as [$obj, "method"] or [ClassName::class, "method"]array pointerx0 = bool
__rt_is_callable_assocValidate associative callable-array payloads produced through boxed or dynamic data pathshash pointerx0 = bool
__rt_is_callable_mixedUnbox a Mixed value and dispatch string, array, hash, or object callable checksmixed pointerx0 = bool
__rt_is_callable_heapDispatch callable checks from a raw heap pointer by inspecting its heap-kind tagheap pointerx0 = bool

Array routines

Source: src/codegen/runtime/arrays/ (119 files)

Core allocation

RoutineWhat it doesInputOutput
__rt_heap_allocFree-list + bump allocator with a 16-byte [size:4][refcount:4][kind:8] headerx0 = sizex0 = pointer
__rt_heap_freeReturn block to free list (bump reset if last block)x0 = pointer
__rt_heap_free_safeFree only if pointer is in heap rangex0 = pointer
__rt_heap_debug_failPrint a heap-debug fatal error and terminate immediatelyx1 = msg ptr, x2 = msg len
__rt_heap_debug_check_liveReject incref / decref operations on already-freed heap blocksx0 = pointer
__rt_heap_debug_validate_free_listValidate the ordered free list and small-bin chains before allocator mutations
__rt_heap_debug_reportPrint heap-debug exit summary with leak/high-water stats
__rt_heap_kindReturn the uniform heap-kind tag for a heap-backed pointerx0 = pointerx0 = kind
__rt_array_newCreate indexed array with headerx0 = capacity, x1 = elem_sizex0 = array ptr
__rt_array_clone_shallowClone indexed array storage for copy-on-write splitting, retaining nested heap children as neededx0 = arrayx0 = new array
__rt_array_to_mixedConvert an indexed array’s live slots to boxed Mixed cells and stamp the array metadata as mixedx0 = arrayx0 = same array
__rt_array_ensure_uniqueSplit a shared indexed array before mutationx0 = arrayx0 = unique array
__rt_array_growEnsure uniqueness, double array capacity, copy elements, free old unique storagex0 = arrayx0 = new array
__rt_array_free_deepFree array storage and release nested heap-backed elementsx0 = array
__rt_array_unionBuild PHP indexed-array union: left numeric keys win, only missing right suffix keys are appendedx0 = left array, x1 = right arrayx0 = result array
__rt_array_hash_unionBuild PHP indexed+associative union by converting left indexes to integer hash keys before appending missing right entriesx0 = left array, x1 = right hashx0 = result hash
__rt_array_push_intAppend int to array (grows if needed)x0 = array, x1 = valuex0 = array
__rt_array_push_refcountedincref borrowed heap payload, then append it as an 8-byte array elementx0 = array, x1 = heap ptrx0 = array
__rt_array_push_strPersist string + append to array (grows if needed)x0 = array, x1/x2 = strx0 = array
__rt_sort_int / __rt_rsort_intIn-place sort ascending or descendingx0 = array
__rt_str_persistCopy string from concat_buf to heap (skips .data/heap)x1/x2 = strx1/x2 = heap str

Common copy-producing array/hash routines now also have dedicated _refcounted siblings for nested heap-backed payloads. These variants retain borrowed values before pushing or inserting them into freshly allocated arrays/hash tables, covering array literals with spreads plus array_merge, array_chunk, array_slice, array_reverse, array_pad, array_unique, array_splice, array_diff, array_intersect, array_filter, array_fill, array_combine, and array_fill_keys.

Refcounted siblingWhat it does
__rt_array_reverse_refcountedReverse an indexed array while retaining nested heap-backed elements
__rt_array_merge_refcountedMerge indexed arrays that carry nested heap-backed payloads
__rt_array_slice_refcounted / __rt_array_splice_refcountedSlice or splice while retaining nested heap-backed payloads
__rt_array_unique_refcountedRemove duplicates while preserving retained heap-backed elements
__rt_array_fill_refcounted / __rt_array_fill_keys_refcountedBuild filled arrays/hashes from borrowed heap-backed values
__rt_array_pad_refcountedPad an array with retained heap-backed values
__rt_array_diff_refcounted / __rt_array_intersect_refcountedSet-style comparisons that keep nested heap-backed values alive
__rt_array_combine_refcountedCombine key/value arrays into a hash while retaining heap-backed values
__rt_array_chunk_refcountedSplit an array into retained heap-backed chunks
__rt_array_filter_refcountedFilter an array of heap-backed elements without dropping borrowed payloads; an optional third argument carries a captured-closure environment
__rt_array_merge_into_refcountedAppend one indexed array into another in-place while retaining nested heap-backed elements

Hash table (for associative arrays)

RoutineWhat it doesInputOutput
__rt_hash_fnv1aFNV-1a hash of stringx1/x2 = stringx0 = hash
__rt_hash_normalize_keyNormalize PHP string array keys, converting integer-form numeric strings to integer keysx1/x2 = string keyx1/x2 = normalized key
__rt_hash_key_hashHash a normalized int/string array keyx1/x2 = normalized keyx0 = hash
__rt_hash_key_eqCompare normalized int/string array keysx1/x2, x3/x4 = keysx0 = equal flag
__rt_hash_newCreate hash tablex0 = capacity, x1 = coarse value-type summaryx0 = hash ptr
__rt_hash_clone_shallowClone hash storage for copy-on-write splitting, re-persisting keys and retaining nested heap values as neededx0 = hashx0 = new hash
__rt_hash_ensure_uniqueSplit a shared hash table before mutationx0 = hashx0 = unique hash
__rt_hash_growDouble hash table capacity, rehash all entriesx0 = hashx0 = new hash
__rt_hash_setInsert/update (grows at 75% load)x0=hash, x1/x2=normalized key, x3/x4=value, x5=value_tagx0 = hash
__rt_hash_insert_ownedReinsert an already-owned key/value pair during hash growthx0=hash, x1/x2=normalized key, x3/x4=value, x5=value_tagx0 = hash
__rt_hash_getLook up value by keyx0=hash, x1/x2=normalized keyx0=found, x1=val_lo, x2=val_hi, x3=value_tag
__rt_hash_iter_nextIterate to next entry in insertion orderx0=hash, x1=cursorx0=next cursor, x1/x2=key, x3/x4=value, x5=value_tag
__rt_hash_unionBuild PHP associative-array union: left duplicate keys win, missing right entries append in insertion orderx0=left hash, x1=right hashx0=result hash
__rt_hash_array_unionBuild PHP associative+indexed union by cloning the left hash and appending right indexes absent from the shared key spacex0=left hash, x1=right arrayx0=result hash
__rt_hash_countCount occupied entriesx0=hashx0=count
__rt_hash_free_deepFree a hash table plus owned keys and nested heap-backed valuesx0=hash
__rt_mixed_from_valueBox a tagged payload into a heap-allocated mixed cellx0=value_tag, x1=value_lo, x2=value_hix0 = mixed cell
__rt_mixed_write_stdoutPrint a boxed mixed value by inspecting its inner tagx0 = mixed cell

__rt_hash_iter_next uses a small cursor protocol rather than a raw slot index: 0 starts from the hash header’s head, positive cursors encode slot_index + 1, -2 marks the post-tail state after yielding the final entry, and -1 means iteration is exhausted.

See Memory Model for the hash table memory layout.

Array manipulation

RoutineWhat it does
__rt_array_key_existsCheck if integer key is in bounds
__rt_array_searchLinear search for value in indexed array
__rt_array_reverseReverse element order
__rt_array_sum / __rt_array_productSum/product of all elements
__rt_array_shift / __rt_array_unshiftRemove/add at beginning
__rt_array_mergeConcatenate two indexed arrays into a new array
__rt_array_merge_intoAppend all elements from source array into dest array (in-place)
__rt_array_slice / __rt_array_spliceExtract slices and remove splice windows from indexed arrays
__rt_array_uniqueRemove duplicate values
__rt_array_diff / __rt_array_intersectSet difference/intersection by value
__rt_array_diff_key / __rt_array_intersect_keySet operations by key
__rt_array_flipSwap indexed integer values into associative-array keys
__rt_array_flip_stringSwap indexed string values into associative-array keys, normalizing numeric-string keys
__rt_array_combineCombine key array + value array → AssocArray
__rt_array_fill / __rt_array_fill_keysCreate filled arrays
__rt_array_chunk / __rt_array_padChunk/pad arrays
__rt_array_columnExtract column from array of assoc arrays (int values)
__rt_array_column_refExtract column of retained heap-backed values (arrays / hashes / objects)
__rt_array_column_strExtract column from array of assoc arrays (string values)
__rt_array_column_mixedExtract column values as boxed Mixed cells for heterogeneous input payloads
__rt_rangeGenerate integer range array
__rt_shuffle / __rt_array_randRandomize order / pick random
__rt_random_u32 / __rt_random_uniformTarget-aware random primitives used by rand(), random_int(), shuffle(), and array_rand()
__rt_asort / __rt_arsortSort by value while preserving keys, ascending or descending
__rt_ksort / __rt_krsortSort by key, ascending or descending
__rt_natsort / __rt_natcasesortNatural-order sort, case-sensitive or case-insensitive
__rt_array_mapApply callback to each scalar element, return new array; an optional third argument carries a captured-closure environment for generated callback wrappers
__rt_array_map_strApply callback to each scalar or string element and return a string array; an optional third argument carries a captured-closure environment
__rt_array_filterFilter scalar elements where callback returns truthy; an optional third argument carries a captured-closure environment
__rt_array_reduceReduce array to single value via callback; an optional fourth argument carries a captured-callback environment
__rt_array_walkCall callback on each element (side-effects); an optional third argument carries a captured-callback environment
__rt_usortSort array using user comparison callback; an optional third argument carries a captured-callback environment

Reference counting

RoutineWhat it doesInputOutput
__rt_increfIncrement reference count (safe with null/non-heap pointers)x0 = user pointer
__rt_decref_anyRelease any heap-backed value by inspecting the uniform heap-kind tagx0 = pointer
__rt_decref_arrayDecrement refcount, deep-free indexed array if zerox0 = array pointer
__rt_decref_hashDecrement refcount, free hash table if zerox0 = hash pointer
__rt_decref_mixedDecrement refcount, deep-free mixed cell if zerox0 = mixed pointer
__rt_decref_objectDecrement refcount, free object if zerox0 = object pointer
__rt_gc_note_child_refAdd one transient incoming edge to a heap child during cycle countingx0 = child pointer
__rt_gc_mark_reachableRecursively mark array/hash/object blocks reachable from external rootsx0 = pointer
__rt_gc_collect_cyclesRun the targeted cycle collector over heap-backed arrays/hashes/objects
__rt_mixed_free_deepFree a mixed cell and release any nested heap-backed payloadx0 = mixed pointer
__rt_object_free_deepFree an object and release heap-backed properties using runtime/class metadatax0 = object pointer

Refcounts are stored as a 32-bit value in the uniform 16-byte heap header, at [user_ptr - 12]. Each heap allocation starts with refcount 1. When a reference is shared (e.g., assigned to another variable or passed to a function), __rt_incref bumps it. When the reference goes away, __rt_decref_any can dispatch through the uniform heap-kind tag to the concrete string/array/hash/object/mixed release path. Arrays, hashes, objects, and boxed mixed cells still use ordinary reference counting first, but when a decref sees a container/object graph that can contain nested heap-backed values, the runtime can invoke __rt_gc_collect_cycles to clear transient metadata, count heap-only incoming edges, mark externally reachable blocks, and deep-free the remaining unreachable array/hash/object/mixed island.

System routines

Source: src/codegen/runtime/system/ (34 files)

__rt_build_argv — Build $argv array

File: system/build_argv.rs

At program start, the OS passes argc (argument count) in x0 and argv (pointer to C string pointers) in x1. This routine:

  1. Creates a new string array
  2. For each C string pointer in argv: measures the string length (scan for null byte), pushes ptr+len into the array
  3. Returns the array pointer

Core system routines

RoutineWhat it doesInputOutput
__rt_timeGet current Unix timestamp via gettimeofday syscallx0 = seconds since epoch
__rt_microtimeGet current time as float seconds via gettimeofday syscalld0 = seconds.microseconds
__rt_getenvGet environment variable value via libc getenv()x1/x2 = name stringx1/x2 = value string
__rt_php_unameRead target runtime system information via libc uname(); supports PHP modes a, s, n, r, v, and mx1/x2 = mode stringx1/x2 = selected uname string
__rt_shell_execExecute shell command and capture output via libc popen()/pclose()x1/x2 = command stringx1/x2 = output string

Exception routines

Source: src/codegen/runtime/exceptions.rs plus src/codegen/runtime/exceptions/ (5 files)

elephc lowers exceptions with a small runtime layer around _setjmp / _longjmp. Codegen publishes the current exception object into _exc_value, pushes a handler record into _exc_handler_top, and then uses these helpers to unwind, match catch clauses, and resume control flow through catch / finally.

RoutineWhat it doesInputOutput
__rt_exception_cleanup_framesWalk the activation-record stack, run per-frame cleanup callbacks, and stop at the frame that should survive the catchx0 = surviving activation record
__rt_exception_matchesCheck whether the active exception matches a catch target by class id or interface idx0 = exception object, x1 = target id, x2 = 0 for class / 1 for interfacex0 = 1 if it matches, 0 otherwise
__rt_instanceof_lookupResolve a dynamic class-string instanceof target through emitted case-insensitive class/interface metadatax1/x2 = target stringx0 = found flag, x1 = target id, x2 = 0 class / 1 interface
__rt_instanceof_invalid_targetAbort when a dynamic instanceof target is neither a string nor an objectdoes not return
__rt_throw_currentUnwind to the nearest active handler or print the fatal uncaught-exception message and exitreads _exc_value, _exc_handler_top, _exc_call_frame_topdoes not return normally
__rt_rethrow_currentRe-enter the ordinary throw path with the currently active exceptionnone (uses global exception state)does not return normally

The fatal uncaught-exception path writes Fatal error: uncaught exception to stderr and exits with status 1. The runtime also resets the concat-buffer cursor before the final longjmp, so partially built string state from the throwing frame does not leak into the resumed catch/finally code.

Date/time routines

Files: system/date/, system/date_data.rs, system/mktime.rs, system/strtotime/

RoutineWhat it doesInputOutput
__rt_dateFormat a Unix timestamp using PHP date format characters (Y, m, d, H, i, s, l, F, etc.). Uses localtime_r() from libc and static lookup tables (_day_names, _month_names) for day/month namesx1/x2 = format string, x0 = timestampx1/x2 = formatted string
__rt_mktimeCreate a Unix timestamp from date components (hour, minute, second, month, day, year). Populates a tm struct on the stack and calls libc mktime()x0-x5 = h, m, s, mon, day, yearx0 = Unix timestamp
__rt_strtotimeParse trimmed date/time strings through strategy emitters: ISO dates/datetimes, time-only forms, bare keywords (now, today, tomorrow, yesterday, midnight, noon), relative offsets (+1 day, 3 months ago, a/an <unit> article forms), and named weekdays with next / last / this. Successful paths populate a tm struct and call libc mktime(); malformed input returns -1.x1/x2 = date stringx0 = Unix timestamp or -1

JSON routines

Files: system/json_data.rs, system/json_depth.rs, system/json_throw_error.rs, system/json_last_error_msg.rs, system/json_validate/, system/json_decode.rs, system/json_decode_mixed/, system/json_encode_bool.rs, system/json_encode_null.rs, system/json_encode_float.rs, system/json_encode_str/, system/json_encode_array_int.rs, system/json_encode_array_str.rs, system/json_encode_array_dynamic.rs, system/json_encode_assoc.rs, system/json_encode_mixed.rs, system/json_encode_object.rs, system/json_pretty.rs, plus objects/stdclass.rs for stdClass-specific JSON object encoding.

The json_encode implementation uses type-aware dispatch — the codegen calls a different runtime routine depending on the compile-time type of the value being encoded:

RoutineWhat it doesInputOutput
__rt_json_encode_boolEncode bool as "true" or "false" using static data labelsx0 = 0 or 1x1/x2 = JSON string
__rt_json_encode_nullEncode null as "null" using a static data labelx1/x2 = JSON string
__rt_json_encode_strEncode a string with JSON escaping (quotes, backslashes, control chars)x1/x2 = input stringx1/x2 = JSON string
__rt_json_encode_array_intEncode an integer array as a JSON array (e.g., [1,2,3])x0 = array ptrx1/x2 = JSON string
__rt_json_encode_array_strEncode a string array as a JSON array with quoted elementsx0 = array ptrx1/x2 = JSON string
__rt_json_encode_array_dynamicEncode an indexed array by inspecting its packed runtime value_type tag at runtime (int, string, float, bool, nested array/hash, mixed, or null fallback), caching active JSON flags in a callee-saved register during the walkx0 = array ptrx1/x2 = JSON string
__rt_json_encode_assocEncode an associative array as a JSON object, while tracking PHP list-shape keys during the same hash walk and compacting to JSON array form when applicablex0 = hash ptrx1/x2 = JSON string
__rt_json_encode_floatEncode finite floats and record JSON_ERROR_INF_OR_NAN for INF/NAN, honoring throw and partial-output flagsd0 = floatx1/x2 = JSON string
__rt_json_encode_mixedEncode a boxed mixed payload by unboxing its runtime tag and dispatching to the concrete JSON encoderx0 = mixed ptrx1/x2 = JSON string
__rt_json_encode_objectEncode class objects by consulting per-class JSON descriptors; dispatches JsonSerializable::jsonSerialize() when present, otherwise walks public propertiesx0 = object ptrx1/x2 = JSON string
__rt_json_encode_stdclassEncode the dynamic-property hash backing stdClass, preserving {} for empty instancesx0 = stdClass hash ptrx1/x2 = JSON string
__rt_json_decodeString-only compatibility helper used by string decode paths; trims outer whitespace and unescapes quoted JSON strings including surrogate-aware \uXXXX sequencesx1/x2 = JSON stringx1/x2 = decoded string
__rt_json_decode_mixedChecked structural recursive decoder that returns boxed Mixed cells for null, bool, int, float, string, indexed arrays, associative arrays, and stdClass objects depending on _json_decode_assoc; records syntax/depth/UTF-16 errors and returns 0 on malformed inputx1/x2 = JSON stringx0 = Mixed* or 0
__rt_json_decode_mixed_array_realRecursive array parser used by json_decode_mixed once the outer [ token is knownparser cursor + JSON boundsboxed Mixed array
__rt_json_decode_mixed_object_realRecursive object parser used by json_decode_mixed once the outer { token is known; returns assoc hash or stdClass payload based on decode modeparser cursor + JSON boundsboxed Mixed object/hash
__rt_json_skip_wsShared RFC 8259 whitespace skipper used by json_decode_mixed and its recursive array/object parsers; advances a caller-owned cursor to the next token or caller-supplied limitJSON slice pointer, exclusive limit, cursorupdated cursor
__rt_json_validateStandalone RFC 8259 validator used by json_validate(); scalar validator helpers are also reused by json_decode_mixed for strings and numbersx1/x2 = JSON stringx0 = 1 valid / 0 invalid
__rt_json_depth_enter / __rt_json_depth_exitMaintain _json_active_depth and compare against _json_depth_limit for recursive encode/decode/validate walksglobal JSON statestatus / updated state
__rt_json_throw_errorRecord a JSON error code and construct/throw JsonException when JSON_THROW_ON_ERROR is activex0 = JSON_ERROR_* codemay not return
__rt_json_last_error_msgReturn the message string corresponding to _json_last_error through the _json_err_msg_table data tableglobal JSON statex1/x2 = message
__rt_json_pretty_push / __rt_json_pretty_pop / __rt_json_pretty_line / __rt_json_pretty_colon_spaceMaintain _json_indent_depth and append PHP-style pretty-print whitespace while each container encoder emits bytes. These helpers are no-ops unless JSON_PRETTY_PRINT is active, avoiding a second buffer walk.current JSON state, x11 write pointer for line/space helpersupdated formatting state / x11 write pointer

Regex routines

Files: system/preg_strip.rs, system/pcre_to_posix.rs, system/preg_match.rs, system/preg_match_all.rs, system/preg_replace.rs, system/preg_replace_callback.rs, system/preg_split.rs

All regex routines use POSIX extended regular expressions via libc’s regcomp(), regexec(), and regfree(). Shared helpers (__rt_preg_strip and __rt_pcre_to_posix) strip PHP-style delimiters and translate common PCRE shorthands and Unicode property shims before passing the pattern to the POSIX API. Before compilation, regex helpers activate LC_CTYPE with C.UTF-8 and fall back to setlocale(LC_CTYPE, "") so POSIX character classes can observe UTF-8 text when the host provides that locale; the broad \p{L} shim avoids relying on locale-specific alpha tables.

RoutineWhat it doesInputOutput
__rt_preg_matchTest if a regex matches the subject string. Compiles the pattern, executes once, freespattern + subject stringsx0 = 1 (match) or 0 (no match)
__rt_preg_match_allCount all non-overlapping matches by repeatedly executing the regex with advancing offsetspattern + subject stringsx0 = match count
__rt_preg_replaceReplace all regex matches with a replacement string. Builds the result incrementally in the concat buffer and expands $0..$9 / \0..\9 from the regexec() capture vectorpattern + replacement + subjectx1/x2 = result string
__rt_preg_replace_callbackReplace all regex matches by building an indexed $matches string array, invoking the callback, and appending the callback string result while preserving concat-buffer state across callback prologuespattern + callback + subjectx1/x2 = result string
__rt_preg_splitSplit the subject string at regex match boundaries. Returns a string array of the non-matching segmentspattern + subject stringsx0 = array pointer

I/O routines

Source: src/codegen/runtime/io/ (30 files)

These routines handle file and filesystem operations through target-aware libc/syscall helpers. PHP strings (pointer + length) must be converted to null-terminated C strings before passing to C or OS APIs — __rt_cstr handles the primary buffer and also emits __rt_cstr2 for routines that need a second simultaneous C string.

RoutineWhat it does
__rt_cstrConvert PHP string (ptr+len) to null-terminated C string
__rt_fopenOpen file via target-aware open() handling, or return -1 after emitting a suppressible warning for open failures and invalid modes
__rt_fgetsRead line from file descriptor
__rt_fgetcRead a single byte from a file descriptor (tail-calls __rt_fread with length 1)
__rt_feofCheck end-of-file flag for a file descriptor
__rt_freadRead N bytes from file descriptor
__rt_readfileOpen a path, stream contents to stdout, and return copied byte count, -1 on read failure, or a false sentinel on open failure
__rt_fpassthruStream the remaining bytes from an existing descriptor to stdout and return copied byte count or -1 on read failure
__rt_flockCall libc flock(), translating PHP’s LOCK_UN constant and exposing would-block state for the optional output parameter
__rt_tmpfileCreate an anonymous temporary file descriptor through mkstemp() plus immediate unlink
__rt_file_get_contentsRead entire file into string, or return a null pointer after emitting a suppressible warning on failure
__rt_file_put_contentsWrite string to file (create/truncate)
__rt_fileRead file into array of lines
__rt_statGet file metadata (size, timestamps)
__rt_file_exists / __rt_is_file / __rt_is_dirExistence and path-type checks backed by stat()
__rt_is_readable / __rt_is_writableAccess checks backed by access()
__rt_filesize / __rt_filemtimeFile size and modification timestamp from stat metadata
__rt_fileatime / __rt_filectime / __rt_fileperms / __rt_fileowner / __rt_filegroup / __rt_fileinodeExtended stat scalar metadata. Return a payload plus success flag so codegen can box PHP false without confusing legitimate zero values.
__rt_filetype / __rt_is_executable / __rt_is_linkFile type and permission predicates; filetype() uses lstat() so symlinks report "link" and missing paths box as false.
__rt_stat_array / __rt_lstat_array / __rt_fstat_arrayBuild PHP-compatible stat arrays with numeric and string keys, returning a null pointer for codegen to box as false on failure
__rt_unlink / __rt_mkdir / __rt_rmdir / __rt_chdirFilesystem path operations via libc/syscalls
__rt_rename / __rt_copyTwo-path filesystem helpers using dual C-string scratch buffers
__rt_symlink / __rt_linkCreate symbolic or hard links through libc
__rt_readlinkRead a symbolic-link target into a heap-backed string, with null output for PHP false on failure
__rt_linkinfoReturn lstat() device metadata for a link path, or PHP’s -1 failure sentinel
__rt_getcwdGet current working directory
__rt_scandirList directory contents into array
__rt_globPattern-match filenames
__rt_tempnamCreate temporary filename
__rt_fgetcsvParse CSV line from file
__rt_fputcsvWrite CSV line to file
__rt_basename / __rt_dirname / __rt_dirname_levelsCompute path components for basename() / dirname() including repeated parent traversal
__rt_fnmatchMatch shell-style path globs with PHP/libc-compatible flag bits for the selected target
__rt_realpathCanonicalize an existing path, returning a null pointer on failure so codegen can box PHP false
__rt_pathinfo_str / __rt_pathinfo_arrayReturn one pathinfo() component for component flags, or build the associative-array PATHINFO_ALL shape
__rt_chmod / __rt_chown / __rt_chown_user / __rt_chgrp_groupFile ownership and mode modification helpers
__rt_umask / __rt_ftruncateProcess umask and file truncation helpers
__rt_fsync / __rt_fflush / __rt_fdatasyncFile descriptor flush helpers; fflush() maps to fsync() because elephc has no userspace stdio buffer
__rt_touchCreate missing files and update access/modification timestamps

Pointer routines

Source: src/codegen/runtime/pointers/ (5 files)

These helpers support the compiler-specific pointer builtins.

RoutineWhat it doesInputOutput
__rt_ptoaFormat a pointer value as a hexadecimal string with 0x prefixx0 = pointer/addressx1/x2 = formatted string
__rt_ptr_check_nonnullAbort with Fatal error: null pointer dereference if the pointer is nullx0 = pointer/addressx0 unchanged on success
__rt_str_to_cstrCopy an elephc string to temporary null-terminated heap storage for a native callx1/x2 = stringx0 = C string pointer
__rt_cstr_to_strCopy a borrowed null-terminated C string back into an owned elephc stringx0 = C string pointerx1/x2 = elephc string
__rt_ptr_read_stringCopy a fixed-length byte range from a raw pointer into an owned elephc stringx0 = pointer, x1 = lengthx1/x2 = elephc string
__rt_ptr_write_stringCopy an elephc string’s bytes into the memory addressed by a raw pointerx0 = pointer, x1/x2 = string

Buffer routines

Source: src/codegen/runtime/buffers/ (5 files including mod.rs)

These helpers support the compiler-specific buffer<T> hot-path data type.

RoutineWhat it doesInputOutput
__rt_buffer_newAllocate a contiguous buffer with header [length:8][stride:8] followed by zero-initialized payloadx0 = element count, x1 = element stridex0 = buffer pointer
__rt_buffer_lenRead the logical element count from a buffer headerx0 = buffer pointerx0 = length
__rt_buffer_bounds_failAbort with Fatal error: buffer index out of boundsdoes not return
__rt_buffer_use_after_freeAbort with Fatal error: use of buffer after buffer_free()does not return

Mixed-type helpers

RoutineWhat it doesInputOutput
__rt_mixed_cast_intUnbox a mixed cell and cast to integerx0 = mixed cell pointerx0 = integer
__rt_mixed_cast_boolUnbox a mixed cell and cast to booleanx0 = mixed cell pointerx0 = 0 or 1
__rt_mixed_cast_floatUnbox a mixed cell and cast to floatx0 = mixed cell pointerd0 = float
__rt_mixed_cast_stringUnbox a mixed cell and cast to stringx0 = mixed cell pointerx1/x2 = string
__rt_mixed_instanceofUnbox a mixed cell and test object payloads against class/interface metadatax0 = mixed cell pointer, x1 = target id, x2 = 0 class / 1 interfacex0 = 0 or 1
__rt_instanceof_lookupResolve a dynamic class-string target against emitted class/interface name metadatax1/x2 = stringx0 = found, x1 = target id, x2 = 0 class / 1 interface
__rt_mixed_is_emptyCheck emptiness of a mixed cell (PHP semantics)x0 = mixed cell pointerx0 = 0 or 1
__rt_mixed_strict_eqCompare two mixed cells by tag and valuex0, x1 = mixed pointersx0 = 0 or 1
__rt_mixed_unboxExtract the raw payload from a mixed cellx0 = mixed cell pointerx0/x1/x2 depending on type
__rt_mixed_countCount boxed indexed arrays and hashes, returning zero for non-countable payloadsx0 = mixed cell pointerx0 = count
__rt_iterable_write_stdoutPrint iterable arrays and hashes as PHP’s "Array" display stringx0 = iterable heap pointer
__rt_iterable_unsupported_kindAbort when runtime iterable dispatch sees an unsupported heap kinddoes not return
__rt_hash_may_have_cyclic_valuesScan hash entries to check if any contain refcounted childrenx0 = hash pointerx0 = 0 (scalar-only) or 1 (has cycles)
__rt_match_unhandledAbort with Fatal error: unhandled match casedoes not return
__rt_enum_from_failAbort with Fatal error: enum case not found when Enum::from() has no matchdoes not return

Object and stdClass routines

Source: src/codegen/runtime/objects/ (3 files)

These helpers support stdClass, json_decode() object results, and boxed Mixed property/index access. stdClass instances use a compact [class_id][hash_ptr] payload, with dynamic properties stored in a hash of boxed Mixed values.

RoutineWhat it doesInputOutput
__rt_stdclass_newAllocate an empty stdClass object with hash-backed dynamic property storagestdClass class id from runtime dataobject pointer
__rt_stdclass_from_hashWrap a decoded JSON object hash in a stdClass instancehash pointerobject pointer
__rt_stdclass_getRead a dynamic property and return a boxed Mixed value, or Mixed(null) when missingobject pointer + property stringboxed mixed payload
__rt_stdclass_setStore a boxed Mixed value into a dynamic property hashobject pointer + property string + boxed value
__rt_mixed_property_getUnbox a Mixed object payload and dispatch stdClass property readsboxed mixed + property stringboxed mixed payload
__rt_mixed_property_setUnbox a Mixed object payload and dispatch stdClass property writesboxed mixed + property string + boxed value
__rt_mixed_array_getUnbox Mixed array/hash/stdClass payloads for $mixed[$key] accessboxed mixed + normalized key tupleboxed mixed payload
__rt_json_encode_stdclassEncode the dynamic-property hash backing stdClass as a JSON objectstdClass hash pointerx1/x2 = JSON string

Generator routines

Source: src/codegen/runtime/generators/ (2 files)

These helpers back the built-in Generator class. Generator functions emit a heap-allocated frame and a generated resume function; the runtime helpers read/write that frame for the public Iterator surface and coroutine operations.

RoutineWhat it doesInputOutput
__rt_gen_currentReturn an owned ref to the boxed Mixed value from the most recent yieldGeneratorFrame*boxed mixed payload
__rt_gen_keyReturn an owned ref to the boxed Mixed key from the most recent yieldGeneratorFrame*boxed mixed key
__rt_gen_validReport whether the generator is not terminatedGeneratorFrame*bool
__rt_gen_nextResume the state machine past the current yield unless terminatedGeneratorFrame*
__rt_gen_next_doneShared global return label used after next() skips or completes a resumeGeneratorFrame*
__rt_gen_sendStore a boxed Mixed sent value, then resume the state machineGeneratorFrame*, boxed mixed valueboxed mixed payload
__rt_gen_send_doneShared global return label used after send() skips or completes a resumeGeneratorFrame*boxed mixed payload
__rt_gen_rewindRun the generator to its first yield onceGeneratorFrame*
__rt_gen_rewind_doneShared global return label used when rewind() has already run or just finishedGeneratorFrame*
__rt_gen_throwMark the generator terminated and throw through the normal exception runtimeGeneratorFrame*, throwable objectdoes not return
__rt_gen_get_returnReturn an owned ref to the boxed terminal return valueGeneratorFrame*boxed mixed payload

Generator frames are stamped as object heap blocks because Generator is a built-in class implementing Iterator. __rt_object_free_deep detects the built-in Generator class id and releases the frame’s custom Mixed slots plus any active yield from delegate instead of treating the payload as ordinary class properties.

Fiber routines

Source: src/codegen/runtime/fibers/ (4 files)

These helpers implement PHP 8.1-style cooperative coroutines. They are emitted on AArch64 and in the Linux x86_64 runtime slice.

RoutineWhat it doesInputOutput
__rt_fiber_alloc_stackAllocate a per-fiber native stack with a protected guard pagerequested usable stack sizestack base, initial top, mapped size
__rt_fiber_free_stackReturn a mapped fiber stack to the OSstack base, mapped size
__rt_fiber_switchSave the current callee-saved context and restore the target fiber/main contexttarget Fiber* or null for mainresumes when this context is switched back to
__rt_fiber_entryTrampoline run on first entry to a fiber stack; calls the generated wrapper, records return/escape state, and switches backactive _fiber_currentdoes not return normally inside the fiber
__rt_fiber_constructAllocate and initialize the runtime-managed Fiber object and its initial stack framecallable pointer, Fiber class id, generated wrapper pointerFiber*
__rt_fiber_throw_state_errorAllocate a FiberError and throw it through the normal exception runtimemessage pointer and lengthdoes not return
__rt_fiber_startStart a not-yet-started fiber and return its first yielded value or null on immediate terminationFiber*boxed mixed payload
__rt_fiber_resumeResume a suspended fiber with a boxed payloadFiber*, boxed mixed valueboxed mixed payload
__rt_fiber_suspendSuspend the current fiber and yield a boxed payload to its callerboxed mixed valueboxed mixed value supplied by the next resume
__rt_fiber_throwResume a suspended fiber by throwing into its pending suspend pointFiber*, throwable objectboxed mixed payload or rethrown exception
__rt_fiber_get_currentReturn the currently running fiber, or null when running on the main stackboxed mixed payload
__rt_fiber_get_returnRead the terminal return payload from a terminated fiberFiber*boxed mixed payload
__rt_fiber_state_eqShared predicate helper for isStarted(), isSuspended(), isRunning(), and isTerminated()Fiber*, state idbool

How routines are emitted

File: src/codegen/runtime/emitters.rs

The emit_runtime() function calls every AArch64 routine emitter in a fixed order. For Linux x86_64, it delegates to x86_minimal.rs, which emits the supported runtime slice for that backend.

pub fn emit_runtime(emitter: &mut Emitter) {
    // diagnostics: runtime warning emission and @ suppression state
    // strings: itoa, resource display/stdout, ftoa, concat, atoi, equality, formatting, trim/mask,
    // search/replace, explode/implode, hashing, encoding, sscanf, ...
    // callables: dynamic is_callable() fallback for strings, arrays, hashes, objects, and Mixed
    // system: argv, time, getenv, shell, date/mktime/strtotime, JSON, regex
    // exceptions: cleanup walk, catch matching, throw/rethrow helpers
    // arrays: heap alloc/free, array/hash helpers, sort, callbacks, refcount
    // buffers: contiguous buffer allocation, bounds checking, UAF traps
    // io: c-string buffers, file I/O, stat/fs helpers, scandir/glob/tempnam, CSV
    // objects: stdClass dynamic properties and boxed Mixed property/index dispatch
    // pointers: ptoa, null check, str_to_cstr, cstr_to_str
    // generators: Generator current/key/valid/next/send/rewind/throw/getReturn helpers
    // fibers: guarded stack allocation, context switch, entry trampoline, Fiber API
}

Notable runtime-only helpers emitted here include __rt_diag_push_suppression, __rt_diag_pop_suppression, __rt_diag_warning, __rt_exception_cleanup_frames, __rt_exception_matches, __rt_instanceof_lookup, __rt_instanceof_invalid_target, __rt_throw_current, __rt_heap_debug_fail, __rt_heap_kind, __rt_hash_insert_owned, __rt_hash_free_deep, __rt_array_column_ref, __rt_mixed_instanceof, __rt_iterable_write_stdout, __rt_iterable_unsupported_kind, __rt_gen_current, __rt_gen_send, __rt_preg_strip, __rt_pcre_to_posix, __rt_str_to_cstr, __rt_cstr_to_str, __rt_fiber_switch, and __rt_fiber_entry in addition to the more user-visible helpers.

Every routine in the selected target runtime slice is linked into the binary, even if unused by the current program. elephc already does AST-side control-flow pruning and dead-code elimination before codegen, but runtime-specific dead stripping is still future work.

Runtime data

The runtime data layer lives in src/codegen/runtime/data/. fixed.rs emits shared buffers, error strings, and lookup tables; user.rs emits per-program globals, statics, enum-case slots, and metadata tables; instanceof.rs formats dynamic instanceof lookup names. Together they declare global buffers using .comm and static data tables:

.comm _concat_buf, 65536     ; 64KB string buffer
.comm _concat_off, 8         ; current offset into string buffer
.comm _global_argc, 8        ; saved argc from OS
.comm _global_argv, 8        ; saved argv pointer from OS
.comm _exc_handler_top, 8    ; top of the active exception-handler stack
.comm _exc_call_frame_top, 8 ; top of the activation-record cleanup stack
.comm _exc_value, 8          ; currently propagating exception object
.comm _fiber_current, 8      ; currently running Fiber object, or null on main
.comm _fiber_main_saved_sp, 8 ; saved main-stack pointer while running a fiber
.comm _fiber_main_saved_exc, 8 ; saved main exception-handler chain while running a fiber
.comm _fiber_main_saved_call_frame, 8 ; saved main cleanup-frame chain while running a fiber
.comm _rt_diag_suppression, 8 ; nested runtime warning-suppression depth for @
.comm _heap_buf, 8388608     ; 8MB heap by default (--heap-size overrides)
.comm _heap_off, 8           ; current heap offset
.comm _heap_free_list, 8     ; head of the general address-ordered free list
.comm _heap_small_bins, 32   ; 4 x 8-byte heads for <=8/16/32/64-byte cached blocks
.comm _heap_debug_enabled, 8 ; BSS-backed debug flag, set to 1 in _main when compiled with --heap-debug
.comm _gc_collecting, 8      ; cycle collector re-entry guard
.comm _gc_release_suppressed, 8 ; suppress nested collection during deep frees
.comm _json_last_error, 8    ; last JSON_ERROR_* code
.comm _json_active_flags, 8  ; active JSON flags for encode/decode/validate
.comm _json_active_depth, 8  ; current recursive JSON container depth
.comm _json_indent_depth, 8  ; current JSON_PRETTY_PRINT formatting depth
.comm _json_depth_limit, 8   ; configured JSON depth limit
.comm _json_validate_idx, 8  ; validator cursor index
.comm _json_validate_ptr, 8  ; validator input pointer
.comm _json_validate_len, 8  ; validator input length
.comm _json_decode_assoc, 8  ; json_decode object-shape selector
_heap_max:
    .quad 8388608            ; configured heap size limit
.comm _gc_allocs, 8          ; allocation counter
.comm _gc_frees, 8           ; free counter
.comm _gc_live, 8            ; current live heap footprint in bytes
.comm _gc_peak, 8            ; high-water mark counter
.comm _cstr_buf, 4096        ; 4KB C-string conversion buffer
.comm _cstr_buf2, 4096       ; 4KB second C-string buffer
.comm _eof_flags, 256        ; EOF flag per file descriptor
; Per-program: global variable storage (one per `global $var` used)
.comm _gvar_x, 16            ; 16 bytes per global variable
; Per-program: static variable storage (one pair per `static $var`)
.comm _static_func_var, 16   ; 16 bytes for persisted value
.comm _static_func_var_init, 8 ; 8-byte initialization flag
; Per-program: static property storage (one slot per effective declaring class property)
.comm _static_prop_Class_prop, 16 ; 16 bytes for the static property value

Additionally, the runtime emits static data tables:

  • _fmt_g — printf format string for float-to-string conversion via %.14G
  • _b64_encode_tbl — 64-byte Base64 encoding lookup table
  • _b64_decode_tbl — 256-byte Base64 decoding lookup table
  • _spl_autoload_exts_default, _spl_autoload_exts_ptr, _spl_autoload_exts_len — mutable SPL autoload extension state
  • _heap_err_msg, _arr_cap_err_msg, _ptr_null_err_msg — fatal runtime error strings
  • _buffer_bounds_msg, _buffer_uaf_msg, _match_unhandled_msg, _enum_from_msg, _static_prop_private_access_msg, _instanceof_target_type_msg, _iterable_unsupported_kind_msg — fatal runtime error strings for buffers, match, enums, late-bound private static-property access, dynamic instanceof target validation, and iterable dispatch
  • _heap_dbg_bad_refcount_msg, _heap_dbg_double_free_msg, _heap_dbg_free_list_msg — fatal heap-debug error strings enabled by --heap-debug
  • _heap_dbg_* summary labels — fixed strings used by __rt_heap_debug_report for alloc/free/live/leak output
  • _resource_id_prefix — prefix used by resource display helpers
  • _uncaught_exc_msg — fatal exception string written by __rt_throw_current when no handler exists
  • _diag_fopen_failed_msg, _diag_file_get_contents_failed_msg, _diag_define_already_defined_msg — suppressible runtime warning text routed through __rt_diag_warning
  • _fiber_msg_already_started, _fiber_msg_not_suspended, _fiber_msg_throw_not_suspended, _fiber_msg_not_terminated, _fiber_msg_suspend_outside, _fiber_msg_unsupported_callable, _fiber_msg_stack_alloc_failed — messages used by FiberError runtime paths
  • _fiber_class_id, _fiber_error_class_id — per-program class ids used by Fiber object cleanup and FiberError construction
  • _generator_class_id — per-program class id used to recognize Generator frames during object deep-free
  • _php_uname_mode_len_msg, _php_uname_mode_value_msg — fatal php_uname() argument diagnostics for invalid mode strings
  • _filetype_*, _stat_key_*, _dirname_*, _pathinfo_key_*, _tmpfile_template — file metadata, path, stat-array, and temporary-file lookup strings used by I/O helpers
  • _locale_utf8_name, _locale_env_name, _pcre_* regex replacement strings — locale selectors plus PCRE shorthand and Unicode-property replacement strings for the POSIX regex bridge
  • _json_true, _json_false, _json_null — JSON keyword strings used by __rt_json_encode_bool and __rt_json_encode_null
  • _json_int_max_str, _json_int_min_str — decimal threshold strings used by JSON_BIGINT_AS_STRING overflow detection without wrapping through integer parsing
  • _json_err_msg_0_json_err_msg_10, _json_err_msg_table, _json_err_msg_countjson_last_error_msg() lookup data for the supported JSON_ERROR_* code range
  • _day_names — 7 entries (84 bytes), each 12 bytes: day name padded to 10 chars + 1 length byte + 1 padding byte. Used by __rt_date for l (full name) and D (abbreviated) format characters
  • _month_names — 12 entries (144 bytes), same layout as day names. Used by __rt_date for F (full name) and M (abbreviated) format characters
  • _strtotime_keyword_tab, _strtotime_unit_tab — keyword, weekday, modifier, and unit lookup tables used by __rt_strtotime
  • _instanceof_target_count, _instanceof_target_entries, _instanceof_name_* — case-insensitive class/interface name metadata used by dynamic instanceof string targets, including leading-backslash aliases
  • _class_gc_desc_count, _class_gc_desc_ptrs, _class_gc_desc_<id> — per-class property traversal metadata used by object deep-free and cycle collection
  • _class_json_desc_ptrs, _class_json_desc_<id>, _class_json_pname_<id>_<slot>, _json_exception_class_id, _stdclass_class_id — JSON object encoding descriptors, JsonException construction metadata, and stdClass runtime class id
  • _class_attribute_count, _class_attribute_ptrs, _class_attributes_<id> — emitted class-level PHP attribute metadata. The current PHP-facing helpers and Reflection owner constructors materialize their results from the same ClassInfo metadata during codegen, rather than doing dynamic runtime class/member lookup.
  • _class_vtable_ptrs, _class_vtable_<id> — per-class virtual-method tables used by inheritance dispatch through class_id
  • _class_static_vtable_ptrs, _class_static_vtable_<id> — per-class static-method tables used by late static binding
  • static_property_symbol(...)-derived .comm slots — 16-byte storage slots for effective declaring static properties, shared by inherited static properties until a subclass redeclares the property
  • enum_case_symbol(...)-derived .comm slots — singleton backing storage for enum cases emitted from user program metadata

When --heap-debug is enabled, the runtime also activates __rt_heap_debug_check_live, __rt_heap_debug_validate_free_list, and __rt_heap_debug_report. These helpers turn allocator corruption into immediate fatal errors for duplicate frees, zero-refcount incref/decref paths, and malformed free-list or small-bin state, poison freed payload bytes with 0xA5, and print an end-of-process summary with alloc/free counts, live block count, live bytes, leak summary, and the peak live-byte watermark.

Every heap allocation now also carries a uniform 8-byte kind tag in its 16-byte allocator header. The current runtime uses 0=raw/untyped, 1=string, 2=indexed array, 3=assoc/hash, 4=object, and 5=boxed mixed, which lets runtime dispatch stay independent from each payload’s internal layout. Generator frames use heap kind 4 because Generator is a built-in object with a custom payload layout. The low 16 bits keep the persistent container metadata: low byte = heap kind, bits 8..14 = indexed-array runtime value_type, and bit 15 = copy-on-write container flag. The collector reuses higher bits for transient reachable/incoming-edge metadata during __rt_gc_collect_cycles. Runtime data also now includes _gc_collecting, _gc_release_suppressed, _class_gc_desc_count, _class_gc_desc_ptrs, _class_vtable_ptrs, _class_static_vtable_ptrs, and static-property storage slots so deep-free / cycle-collection paths can coordinate nested releases, discover class property traversal metadata, and support inherited instance dispatch, static-property reads/writes, and late static binding.

See Memory Model for details on how these buffers work.