Overview
Theset_anonymous_segment_sz syscall sets the size of an anonymous memory segment to a specific value. This syscall is used for precise memory management when you need to set an exact segment size.
Syscall Code
Code:0x00 (TN_SYSCALL_CODE_SET_ANONYMOUS_SEGMENT_SZ)
C SDK Function
Arguments
Virtual address that encodes the segment type, index, and desired size offset. The size is determined by the offset in the 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) - Invalid segment size (not page-aligned)TN_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) - Additional cost: Variable based on size change
- Expansion: Additional units equal to the number of bytes increased
- Shrinking: No additional cost beyond base
- Total formula:
base_cost + max(0, size_increase)
Memory Pages
- Page allocation: Required pages are allocated from the transaction’s page pool
- Page deallocation: Freed pages are returned to the transaction’s page pool
- Page size: Operations work in
TN_COW_TABLE_PAGE_SZchunks
Side Effects
- Memory allocation/deallocation: Pages are allocated when expanding or freed when shrinking the segment
- Segment state: Updates the segment size and page mappings
Usage Notes
- The segment size must be page-aligned (multiple of page size)
- For stack segments, the size is calculated as
(0xFFFFFF - offset + 1) - For heap segments, the size is equal to the offset
- Only works with anonymous data segments (heap and stack types)
- Pages are allocated from the transaction’s page pool