IOS/IoBuffer

From WiiBrew
< IOS
Jump to: navigation, search

Contents

The io buffer subsystem

This page is dedicated to the io buffer subsystem of IOS.

struct iobuf

An io buffer consists of a header and a memory region. The header is represented by the struct iobuf.

struct iobuf {
    int unknown;
    struct iobuf *next_ptr; /* 0x04: used for iobuf pool as single linked list */
    int very_unknown;       /* 0x08: */  
    void *buffer;           /* 0x0C: pointer to start of the buffer */
    void *head_ptr;         /* 0x10: pointer into the buffer */
    unsigned short capacity; /* 0x014: capacity of the buffer in bytes*/
    unsigned short size_from_head; /* 0x16: number of bytes from head_ptr to end of payload */
    unsigned short offset_unknown2; /* 0x18: unknown offset */
    unsigned char unknown_byte;     /* 0x1A: is no padding byte */
    unsigned char refcount;         /* 0x1B: used for reference counting */
    int  unknown_int;       /* 0x1C: */
    unsigned short magic;   /* 0x20: magic value to verify that a pointer is an iobuf (0x4942 in IOS-35)*/ 
    unsigned short padding_maybe; /* 0x22: */
    unsigned int unknown_3;       /* 0x24: ??? */
}

syscall 36, Allocate io buffer

struct iobuf *alloc_iobuf(arg1, size) 

This syscall is used to allocate a new io buffer. The system has a fixed number of io buffer. These are managed in a pool (a single linked list). The function removes the first buffer from the pool, initializes the internal state and returns it to the caller.

parameter
arg1 - the first argument is a 32 value, not sure what it is used for.
size - size of the buffer in bytes
return value
the function returns an allocated io buffer, or NULL if no buffers are available.

syscall 37, Release io buffer

int free_iobuf(struct iobuf *buf) 

This syscall decreases the reference counter of the io buffer by one. When the result is zero, the buffer is released.

parameter
buf - the io buffer to release

syscall 38, Some debug output

This syscall prints some debug output that cannot be seen by homebrew users unless you patch the SVC vector to redirect this debug output to a USB Gecko.

syscall 39, Some more debug output

The syscall prints about the available io buffers of a certain size. You cannot see the output unless you patch the SVC vector to redirect this output to a USB Gecko.

syscall 3a, Append some bytes to the buffer

void *extend_iobuf(struct iobuf *buf, unsigned short num)

This syscall allows you to append some bytes to the end of the io buffer. The buffer size is extendend by num bytes and a pointer to the extendend memory location is returned. Usually, memcpy is used to put some data in the extended range.


syscall 3b, hide a header

void *IOS_PushIob(struct iobuf *iob, unsigned short num)

This syscall moves the head pointer of the buffer some byte to the end. This is used inside the network stack, i.e. for removing for hiding the Ethernet header of an IP packet.

syscall 3c, unhide a header

void *IOS_PullIob(struct iobuf *iob, unsigned short num)

This syscall dows the opposite of syscall 3b.

syscall 3d, verify an io buffer

int verify_iobuf(struct iobuf *iob)

This syscall verifies if the pointer really points to an io buffer. Therefore, it check if the struct contains sane values and if the magic is correct.

Personal tools
Resources
Community