예제 #1
0
bool ArgumentDecoder::alignBufferPosition(unsigned alignment, size_t size)
{
    uint8_t* alignedPosition = roundUpToAlignment(m_bufferPos, alignment);
    if (!alignedBufferIsLargeEnoughToContain(alignedPosition, m_bufferEnd, size)) {
        // We've walked off the end of this buffer.
        markInvalid();
        return false;
    }
    
    m_bufferPos = alignedPosition;
    return true;
}
예제 #2
0
void ArgumentDecoder::initialize(const uint8_t* buffer, size_t bufferSize)
{
    // This is the largest primitive type we expect to unpack from the message.
    const size_t expectedAlignment = sizeof(uint64_t);
    m_allocatedBase = static_cast<uint8_t*>(malloc(bufferSize + expectedAlignment));
    m_buffer = roundUpToAlignment(m_allocatedBase, expectedAlignment);
    ASSERT(!(reinterpret_cast<uintptr_t>(m_buffer) % expectedAlignment));

    m_bufferPos = m_buffer;
    m_bufferEnd = m_buffer + bufferSize;
    memcpy(m_buffer, buffer, bufferSize);
}
예제 #3
0
bool ArgumentDecoder::alignBufferPosition(unsigned alignment, size_t size)
{
    uint8_t* buffer = roundUpToAlignment(m_bufferPos, alignment);
    if (static_cast<size_t>(m_bufferEnd - buffer) < size) {
        // We've walked off the end of this buffer.
        markInvalid();
        return false;
    }
    
    m_bufferPos = buffer;
    return true;
}
예제 #4
0
uint8_t* ArgumentEncoder::grow(unsigned alignment, size_t size)
{
    size_t alignedSize = roundUpToAlignment(m_bufferSize, alignment);
    
    if (alignedSize + size > m_bufferCapacity) {
        size_t newCapacity = std::max(alignedSize + size, std::max(static_cast<size_t>(32), m_bufferCapacity + m_bufferCapacity / 4 + 1));
        if (!m_buffer)
            m_buffer = static_cast<uint8_t*>(fastMalloc(newCapacity));
        else
            m_buffer = static_cast<uint8_t*>(fastRealloc(m_buffer, newCapacity));
        
        // FIXME: What should we do if allocating memory fails?

        m_bufferCapacity = newCapacity;        
    }

    m_bufferSize = alignedSize + size;
    m_bufferPointer = m_buffer + alignedSize + size;
    
    return m_buffer + alignedSize;
}
예제 #5
0
bool ArgumentDecoder::bufferIsLargeEnoughToContain(unsigned alignment, size_t size) const
{
    return alignedBufferIsLargeEnoughToContain(roundUpToAlignment(m_bufferPos, alignment), m_bufferEnd, size);
}
예제 #6
0
bool ArgumentDecoder::bufferIsLargeEnoughToContain(unsigned alignment, size_t size) const
{
    return static_cast<size_t>(m_bufferEnd - roundUpToAlignment(m_bufferPos, alignment)) >= size;
}