1 /* 2 * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved. 3 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved. 4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. 5 * 6 * This software is available to you under a choice of one of two 7 * licenses. You may choose to be licensed under the terms of the GNU 8 * General Public License (GPL) Version 2, available from the file 9 * COPYING in the main directory of this source tree, or the 10 * OpenIB.org BSD license below: 11 * 12 * Redistribution and use in source and binary forms, with or 13 * without modification, are permitted provided that the following 14 * conditions are met: 15 * 16 * - Redistributions of source code must retain the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer. 19 * 20 * - Redistributions in binary form must reproduce the above 21 * copyright notice, this list of conditions and the following 22 * disclaimer in the documentation and/or other materials 23 * provided with the distribution. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 * SOFTWARE. 33 * 34 */ 35 36 /* 37 * Abstract: 38 * Turns on byte packing, which is necessary for passing information from 39 * system to system over a network to ensure no padding by the compiler has 40 * taken place. 41 */ 42 43 /****h* Component Library/Structure Packing 44 * NAME 45 * Structure Packing 46 * 47 * DESCRIPTION 48 * The structure packing header files allow packing structures on byte 49 * boundaries. 50 * 51 * Structure packing should be used whenever a structure is transmitted 52 * between systems, as different platforms pad structures differently if 53 * they are not packed. Packing a structure that is not transmitted between 54 * systems can be detrimental to performance, as fields in the structure may 55 * not align properly for some platforms. Care must be taken when creating 56 * packed structures that the alignment rules for all platforms are followed. 57 * 58 * To pack a structure, include cl_packon.h before defining the structure, and 59 * include cl_packoff.h after the structure definition. Multiple structures 60 * can be packed between the two include statements if desired. 61 * 62 * The structure definition itself must use the PACK_SUFFIX keyword. 63 * 64 * EXAMPLE 65 * #include <complib/cl_packon.h> 66 * 67 * typedef _my_struct_t 68 * { 69 * uint64 large; 70 * uint32 medium; 71 * uint16 small; 72 * 73 * } PACK_SUFFIX my_struct_t; 74 * #include <complib/cl_packoff.h> 75 *********/ 76 77 #ifndef PACK_SUFFIX 78 #define PACK_SUFFIX __attribute__((packed)) 79 #endif 80 81 #ifdef _MSC_VER 82 #pragma pack (push, 1) 83 #endif 84