Veil
veil_datatypes.h File Reference

Define all Veil public datatypes. More...

#include "utils/hsearch.h"
#include "storage/lwlock.h"

Go to the source code of this file.

Data Structures

struct  MemChunk
 Chunks provide a linked list of dynamically allocated shared memory segments, with the most recently allocated chunk at the tail. More...
 
struct  Object
 General purpose object-type. More...
 
struct  ShmemCtl
 The ShmemCtl structure is the first object allocated from the first chunk of shared memory in context 0. More...
 
struct  Int4Var
 Subtype of Object for storing simple int4 values. More...
 
struct  Range
 Subtype of Object for storing range values. More...
 
struct  Bitmap
 Subtype of Object for storing bitmaps. More...
 
struct  BitmapRef
 Subtype of Object for storing bitmap refs. More...
 
struct  BitmapArray
 Subtype of Object for storing bitmap arrays. More...
 
struct  BitmapHash
 Subtype of Object for storing bitmap hashes. More...
 
struct  Int4Array
 Subtype of Object for storing arrays of integers. More...
 
struct  VarEntry
 A Veil variable. More...
 
struct  veil_variable_t
 Describes a veil shared or session variable. More...
 

Macros

#define VEIL_DATATYPES   1
 Prevent this header from being included multiple times.
 
#define VEIL_DEBUG   1
 Enables various debugging constructs, such as canaries, in code and data structures. More...
 
#define DBG_CANARY   0xca96ca96
 Value to be set in sacrificial "canary" fields. More...
 
#define DBG_CANARY_ENTRY   int32 canary;
 Defines a canary element in a data structure.
 
#define DBG_ELEMS_ENTRY   int32 dbgelems;
 Field to record the size of an array so that its canary element can be found.
 
#define DBG_SET_ELEMS(x, y)   (x).dbgelems = y
 Code to records the size of an array so that its canary element can be found.
 
#define DBG_SET_CANARY(x)   (x).canary = DBG_CANARY
 Code to initialise a canary.
 
#define DBG_TEST_CANARY(x)
 Code to test for a canary having been overwritten. More...
 
#define EMPTY   1
 Base size for an array containing a canary. More...
 
#define DBG_SET_TRAILER(x, y)   (x).y[(x).dbgelems] = DBG_CANARY;
 Set a trailing canary in an array.
 
#define DBG_SET_TRAILERP(x, y)   (x).y[(x).dbgelems] = (void *) DBG_CANARY;
 Set a trailing canary in an array (using a void pointer).
 
#define DBG_TEST_TRAILER(x, y)
 Test the trailing canary in an array. More...
 
#define DBG_CHECK_INDEX(x, i)
 Check whether an array index is in bounds. More...
 
#define HASH_KEYLEN   60
 The key length for veil hash types.
 
#define BITZERO(x)   (x & 0xffffffe0)
 Gives the bitmask index for the bitzero value of a Bitmap. More...
 
#define BITMAX(x)   (x | 0x1f)
 Gives the bitmask index for the bitmax value of a bitmap. More...
 
#define BITSET_ELEM(x)   (x >> 5)
 Gives the index of a bit within the array of 32-bit words that comprise the bitmap. More...
 
#define BITSET_BIT(x)   (x & 0x1f)
 Gives the index into bitmasks for the bit specified in x. More...
 
#define ARRAYELEMS(min, max)   (((max - BITZERO(min)) >> 5) + 1)
 Gives the number of array elements in a Bitmap that runs from element min to element max. More...
 
#define MIN(a, b)   ((a < b)? a: b)
 Return the smaller of a or b. More...
 

Typedefs

typedef struct MemChunk MemChunk
 Chunks provide a linked list of dynamically allocated shared memory segments, with the most recently allocated chunk at the tail. More...
 
typedef struct Object Object
 General purpose object-type. More...
 
typedef struct ShmemCtl ShmemCtl
 The ShmemCtl structure is the first object allocated from the first chunk of shared memory in context 0. More...
 
typedef struct Int4Var Int4Var
 Subtype of Object for storing simple int4 values. More...
 
typedef struct Range Range
 Subtype of Object for storing range values. More...
 
typedef uint32 bm_int
 
typedef struct Bitmap Bitmap
 Subtype of Object for storing bitmaps. More...
 
typedef struct BitmapRef BitmapRef
 Subtype of Object for storing bitmap refs. More...
 
typedef struct BitmapArray BitmapArray
 Subtype of Object for storing bitmap arrays. More...
 
typedef struct BitmapHash BitmapHash
 Subtype of Object for storing bitmap hashes. More...
 
typedef struct Int4Array Int4Array
 Subtype of Object for storing arrays of integers.
 
typedef struct VarEntry VarEntry
 A Veil variable. More...
 
typedef struct veil_variable_t veil_variable_t
 Describes a veil shared or session variable. More...
 

Enumerations

enum  ObjType {
  OBJ_UNDEFINED = 0, OBJ_SHMEMCTL, OBJ_INT4, OBJ_RANGE,
  OBJ_BITMAP, OBJ_BITMAP_ARRAY, OBJ_BITMAP_HASH, OBJ_BITMAP_REF,
  OBJ_INT4_ARRAY, OBJ_UNDEFINED = 0, OBJ_SHMEMCTL, OBJ_INT4,
  OBJ_RANGE, OBJ_BITMAP, OBJ_BITMAP_ARRAY, OBJ_BITMAP_HASH,
  OBJ_BITMAP_REF, OBJ_INT4_ARRAY
}
 Describes the type of an Object record or one of its subtypes.
 

Detailed Description

Define all Veil public datatypes.

Author: Marc Munro
Copyright (c) 2005 - 2011 Marc Munro
License: BSD

Definition in file veil_datatypes.h.

Macro Definition Documentation

◆ VEIL_DEBUG

#define VEIL_DEBUG   1

Enables various debugging constructs, such as canaries, in code and data structures.

If such debugging is required, define VEIL_DEBUG in the make invocation, eg: "make VEIL_DEBUG=1".

Definition at line 27 of file veil_datatypes.h.

◆ DBG_CANARY

#define DBG_CANARY   0xca96ca96

Value to be set in sacrificial "canary" fields.

If this value is not as expected, the canary has been killed by something inappropriately stomping on memory.

Definition at line 36 of file veil_datatypes.h.

◆ DBG_TEST_CANARY

#define DBG_TEST_CANARY (   x)
Value:
if ((x).canary != DBG_CANARY) {\
elog(ERROR, "canary fault"); }
#define DBG_CANARY
Value to be set in sacrificial "canary" fields.

Code to test for a canary having been overwritten.

Definition at line 63 of file veil_datatypes.h.

Referenced by vl_BitmapFromArray(), vl_BitmapSetbit(), vl_ClearBitmapArray(), and vl_NewBitmapArray().

◆ EMPTY

#define EMPTY   1

Base size for an array containing a canary.

This is zero if VEIL_DEBUG is not defined, when this is defined arrays will be one element longer to allow a canary to be placed at the end of the array.

Definition at line 71 of file veil_datatypes.h.

◆ DBG_TEST_TRAILER

#define DBG_TEST_TRAILER (   x,
 
)
Value:
if ((uintptr_t) (x).y[(x).dbgelems] != DBG_CANARY) { \
elog(ERROR, "trailing canary fault"); }
#define DBG_CANARY
Value to be set in sacrificial "canary" fields.

Test the trailing canary in an array.

Definition at line 85 of file veil_datatypes.h.

Referenced by vl_BitmapFromArray(), vl_BitmapSetbit(), vl_ClearBitmapArray(), and vl_NewBitmapArray().

◆ DBG_CHECK_INDEX

#define DBG_CHECK_INDEX (   x,
 
)
Value:
if (i >= (x).dbgelems) {\
elog(ERROR, "Element index out of range %d", i); }

Check whether an array index is in bounds.

Definition at line 92 of file veil_datatypes.h.

Referenced by vl_BitmapFromArray(), vl_BitmapSetbit(), and vl_ClearBitmapArray().

◆ BITZERO

#define BITZERO (   x)    (x & 0xffffffe0)

Gives the bitmask index for the bitzero value of a Bitmap.

This is part of the "normalisation" process for bitmap ranges. This process allows unlike bitmaps to be more easily compared by forcing bitmap indexes to be normalised around 32 or 64 bit word boundaries. Eg, 2 bitmaps with domains 1 to 50 and 3 to 55, will have identical bit patterns for bits 3 to 50.

Parameters
xThe bitzero value of a bitmap
Returns
The bitmask index representing x.

Definition at line 229 of file veil_datatypes.h.

Referenced by vl_BitmapClearbit(), vl_BitmapSetbit(), and vl_BitmapTestbit().

◆ BITMAX

#define BITMAX (   x)    (x | 0x1f)

Gives the bitmask index for the bitmax value of a bitmap.

See BITZERO() for more information.

Parameters
xThe bitmax value of a bitmap
Returns
The bitmask index representing x.

Definition at line 243 of file veil_datatypes.h.

◆ BITSET_ELEM

#define BITSET_ELEM (   x)    (x >> 5)

Gives the index of a bit within the array of 32-bit words that comprise the bitmap.

Parameters
xThe bit in question
Returns
The array index of the bit.

Definition at line 257 of file veil_datatypes.h.

Referenced by vl_BitmapClearbit(), vl_BitmapSetbit(), and vl_BitmapTestbit().

◆ BITSET_BIT

#define BITSET_BIT (   x)    (x & 0x1f)

Gives the index into bitmasks for the bit specified in x.

Parameters
xThe bit in question
Returns
The bitmask index

Definition at line 270 of file veil_datatypes.h.

Referenced by vl_BitmapClearbit(), vl_BitmapSetbit(), and vl_BitmapTestbit().

◆ ARRAYELEMS

#define ARRAYELEMS (   min,
  max 
)    (((max - BITZERO(min)) >> 5) + 1)

Gives the number of array elements in a Bitmap that runs from element min to element max.

Parameters
min
max
Returns
The number of elements in the bitmap.

Definition at line 285 of file veil_datatypes.h.

Referenced by deserialise_one_bitmap(), serialise_bitmap(), serialise_bitmap_array(), serialise_bitmap_hash(), serialise_one_bitmap(), vl_BitmapIntersect(), vl_BitmapUnion(), vl_ClearBitmap(), vl_NewBitmap(), and vl_NewBitmapArray().

◆ MIN

#define MIN (   a,
 
)    ((a < b)? a: b)

Return the smaller of a or b.

Note that expressions a and b may be evaluated more than once.

Parameters
a
b
Returns
The smaller value of a or b.

Definition at line 298 of file veil_datatypes.h.

Typedef Documentation

◆ MemChunk

typedef struct MemChunk MemChunk

Chunks provide a linked list of dynamically allocated shared memory segments, with the most recently allocated chunk at the tail.

Shmalloc allocates space from this list of chunks, creating new chunks as needed up to MAX_ALLOWED_SHMEM.

◆ Object

typedef struct Object Object

General purpose object-type.

All veil variables are effectively sub-types of this.

◆ ShmemCtl

typedef struct ShmemCtl ShmemCtl

The ShmemCtl structure is the first object allocated from the first chunk of shared memory in context 0.

This object describes and manages shared memory allocated by shmalloc()

◆ Int4Var

typedef struct Int4Var Int4Var

Subtype of Object for storing simple int4 values.

These values are allowed to be null.

◆ Range

typedef struct Range Range

Subtype of Object for storing range values.

A range has an upper and lower bound, both stored as int4s. Nulls are not allowed.

◆ Bitmap

typedef struct Bitmap Bitmap

Subtype of Object for storing bitmaps.

A bitmap is stored as an array of int4 values. See veil_bitmap.c for more information. Note that the size of a Bitmap structure is determined dynamically at run time as the size of the array is only known then.

◆ BitmapRef

typedef struct BitmapRef BitmapRef

Subtype of Object for storing bitmap refs.

A bitmapref is like a bitmap but instead of containing a bitmap it contains a reference to one. This reference may be set during a transaction and then referenced only from within the setting transaction.

◆ BitmapArray

typedef struct BitmapArray BitmapArray

Subtype of Object for storing bitmap arrays.

A bitmap array is simply an array of pointers to dynamically allocated Bitmaps. Note that the size of a Bitmap structure is determined dynamically at run time as the size of the array is only known then.

◆ BitmapHash

typedef struct BitmapHash BitmapHash

Subtype of Object for storing bitmap hashes.

A bitmap hash is a hash of dynamically allocated bitmaps, keyed by strings. Note that these cannot be created as shared variables.

◆ VarEntry

typedef struct VarEntry VarEntry

A Veil variable.

These may be session or shared variables, and may contain any Veil variable type. They are created and accessed by vl_lookup_shared_variable() and vl_lookup_variable(), and are stored in either the shared hash or one of the session hashes. See veil_shmem.c and veil_variables.c for more details.

◆ veil_variable_t

Describes a veil shared or session variable.

This matches the SQL veil_variable_t which is defined as:

create type veil_variable_t as (
    name    text,
    type    text,
    shared  bool,
);