Overview
Theincrement_anonymous_segment_sz syscall modifies the size of an anonymous memory segment by adding or subtracting a delta value. This is useful for dynamic memory allocation and deallocation.
Syscall Code
Code:0x01 (TN_SYSCALL_CODE_INCREMENT_ANONYMOUS_SEGMENT_SZ)
C SDK Function
Arguments
Virtual address that identifies the anonymous segment to modify. The segment type and index are extracted from this address.
Delta value to add to the current segment size. Can be positive (expand) or negative (shrink). If zero, returns the current segment boundary address without modification.
Pointer to store the resulting segment boundary address.
Return Value
Returns a syscall result code:TN_VM_SYSCALL_SUCCESS(0) - Operation completed successfully
TN_VM_ERR_SYSCALL_INVALID_SEGMENT_ID(-20) - Invalid segment type or indexTN_VM_ERR_SYSCALL_INVALID_SEGMENT_SIZE(-27) - Size overflow/underflow detectedTN_VM_ERR_SYSCALL_INSUFFICIENT_PAGES(-25) - Not enough free pages for expansionTN_VM_ERR_SYSCALL_UNFREEABLE_PAGE(-28) - Cannot free pages when shrinking
Resource Consumption
Compute Units
- Base cost:
TN_VM_SYSCALL_BASE_COST(512 units) - Delta cost: Additional units based on delta value
- Positive delta: Additional units equal to the delta value
- Negative delta: No additional cost beyond base
- Zero delta: No additional cost (query operation)
- Total formula:
base_cost + max(0, delta)
Memory Pages
- Page allocation: New pages allocated from transaction pool when expanding
- Page deallocation: Freed pages returned to transaction pool when shrinking
- Page constraints: Pages can only be freed if allocated in current or later call frames
Side Effects
- Memory allocation/deallocation: Pages allocated when expanding or freed when shrinking
- Output parameter: Sets the addr parameter to the segment boundary address
- Segment state: Updates segment size and page mappings
Usage Notes
- When delta is 0, returns current segment size without modification
- For positive delta: allocates new pages and returns old boundary
- For negative delta: frees pages and returns new boundary
- Overflow/underflow protection prevents invalid size calculations
- Only works with anonymous data segments (heap and stack types)