Path: blob/21.2-virgl/src/gallium/auxiliary/rbug/rbug_internal.h
4561 views
/*1* Copyright 2009 VMware, Inc.2* All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* on the rights to use, copy, modify, merge, publish, distribute, sub8* license, and/or sell copies of the Software, and to permit persons to whom9* the Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL18* VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,19* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR20* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE21* USE OR OTHER DEALINGS IN THE SOFTWARE.22*/2324/*25* This file is internal to the rbug protocol code, and contains asorted26* features needed by the code.27*/2829#ifndef _RBUG_INTERNAL_H_30#define _RBUG_INTERNAL_H_3132#include "rbug_proto.h"3334#include "util/u_memory.h"35#include "util/u_debug.h"36#include <errno.h>3738int rbug_connection_send_start(struct rbug_connection *con, enum rbug_opcode opcode, uint32_t length);39int rbug_connection_write(struct rbug_connection *con, void *data, uint32_t size);40int rbug_connection_send_finish(struct rbug_connection *con, uint32_t *c);4142/**43* Only works with multiples of 244*/45#define PAD(from, to) \46do { \47from = (from + to - 1) & ~(to - 1); \48} while(0)4950#define LEN(size) \51do { \52PAD(__len, size); \53__len += size; \54} while(0)5556#define LEN_ARRAY(size, name) \57do { \58LEN(4); \59PAD(__len, size); \60__len += size * name##_len; \61} while(0)6263#define WRITE(size, type, name) \64do { \65PAD(__pos, size); \66*((type *)(&__data[__pos])) = name; \67__pos += size; \68} while(0)6970#define WRITE_ARRAY(size, type, name) \71do { \72WRITE(4, uint32_t, name##_len); \73PAD(__pos, size); \74memcpy(&__data[__pos], name, size * name##_len); \75__pos += size * name##_len; \76} while(0)7778#define READ(size, type, name) \79do { \80PAD(pos, size); \81pos += size; \82if (pos > len) \83break; \84ret->name = *((type *)(&data[pos - size])); \85} while(0)8687#define READ_ARRAY(size, type, name) \88do { \89READ(4, uint32_t, name##_len); \90if (pos > len) \91break; \92PAD(pos, size); \93pos += size * ret->name##_len; \94if (pos > len) \95break; \96ret->name = (type *)&data[pos - size * ret->name##_len]; \97} while(0)9899#endif100101102