Open SCAP Library
|
00001 /* 00002 * Copyright 2009 Red Hat Inc., Durham, North Carolina. 00003 * All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 * 00019 * Authors: 00020 * "Daniel Kopecek" <dkopecek@redhat.com> 00021 */ 00022 00023 #pragma once 00024 #ifndef _SEXP_VALUE_H 00025 #define _SEXP_VALUE_H 00026 00027 #include <stddef.h> 00028 #include <stdint.h> 00029 #include <stdbool.h> 00030 #include "_sexp-types.h" 00031 #include "../../../common/util.h" 00032 00033 OSCAP_HIDDEN_START; 00034 00035 typedef uint8_t SEXP_valtype_t; 00036 00037 #define SEXP_VALTYPE_EMPTY 0 00038 #define SEXP_VALTYPE_STRING 1 00039 #define SEXP_VALTYPE_NUMBER 2 00040 #define SEXP_VALTYPE_LIST 3 00041 00042 typedef struct { 00043 uint32_t refs; 00044 size_t size; 00045 } __attribute__ ((packed)) SEXP_valhdr_t; 00046 00047 typedef struct { 00048 uintptr_t ptr; 00049 SEXP_valhdr_t *hdr; 00050 void *mem; 00051 SEXP_valtype_t type; 00052 } SEXP_val_t; 00053 00054 #define SEXP_VALP_ALIGN (4 > sizeof(void *) ? 4 : sizeof(void *)) 00055 #define SEXP_VALP_MASK (UINTPTR_MAX << 2) 00056 #define SEXP_VALT_MASK 3 00057 #define SEXP_VALP_HDR(p) ((SEXP_valhdr_t *)(((uintptr_t)(p)) & SEXP_VALP_MASK)) 00058 00059 int SEXP_val_new (SEXP_val_t *dst, size_t vmemsize, SEXP_valtype_t type); 00060 void SEXP_val_dsc (SEXP_val_t *dst, uintptr_t ptr); 00061 uintptr_t SEXP_val_ptr (SEXP_val_t *dsc); 00062 00063 uintptr_t SEXP_rawval_incref (uintptr_t valp); 00064 int SEXP_rawval_decref (uintptr_t valp); 00065 00066 #define SEXP_DEFNUM(s,T) struct SEXP_val_num_##s { T n; SEXP_numtype_t t; } __attribute__ ((packed)) 00067 #define SEXP_NCASTP(s,p) ((struct SEXP_val_num_##s *)(p)) 00068 #define SEXP_NTYPEP(sz,p) *((SEXP_numtype_t *)(((uint8_t *)(p)) + (sz) - sizeof (SEXP_numtype_t))) 00069 00070 SEXP_numtype_t SEXP_rawval_number_type (SEXP_val_t *dsc); 00071 00072 SEXP_DEFNUM(b, bool); 00073 SEXP_DEFNUM(f, double); 00074 SEXP_DEFNUM(i8, int8_t); 00075 SEXP_DEFNUM(u8, uint8_t); 00076 SEXP_DEFNUM(i16, int16_t); 00077 SEXP_DEFNUM(u16, uint16_t); 00078 SEXP_DEFNUM(i32, int32_t); 00079 SEXP_DEFNUM(u32, uint32_t); 00080 SEXP_DEFNUM(i64, int64_t); 00081 SEXP_DEFNUM(u64, uint64_t); 00082 00083 /* 00084 * List 00085 */ 00086 00087 struct SEXP_val_list { 00088 void *b_addr; 00089 uint16_t offset; 00090 } __attribute__ ((packed)); 00091 00092 #define SEXP_LCASTP(p) ((struct SEXP_val_list *)(p)) 00093 00094 struct SEXP_val_lblk { 00095 uintptr_t nxsz; 00096 uint16_t real; 00097 uint16_t refs; 00098 SEXP_t memb[]; 00099 } __attribute__ ((packed)); 00100 00101 size_t SEXP_rawval_list_length (struct SEXP_val_list *list); 00102 uintptr_t SEXP_rawval_list_copy (uintptr_t s_valp); 00103 00104 uintptr_t SEXP_rawval_lblk_copy (uintptr_t lblkp, uint16_t n_skip); 00105 uintptr_t SEXP_rawval_lblk_new (uint8_t sz); 00106 uintptr_t SEXP_rawval_lblk_incref (uintptr_t lblkp); 00107 int SEXP_rawval_lblk_decref (uintptr_t lblkp); 00108 00109 uintptr_t SEXP_rawval_lblk_fill (uintptr_t lblkp, SEXP_t *s_exp[], uint16_t s_exp_count); 00110 uintptr_t SEXP_rawval_lblk_add (uintptr_t lblkp, const SEXP_t *s_exp); 00111 uintptr_t SEXP_rawval_lblk_add1 (uintptr_t lblkp, const SEXP_t *s_exp); 00112 uintptr_t SEXP_rawval_lblk_last (uintptr_t lblkp); 00113 SEXP_t *SEXP_rawval_lblk_nth (uintptr_t lblkp, uint32_t n); 00114 uintptr_t SEXP_rawval_lblk_replace (uintptr_t lblkp, uint32_t n, const SEXP_t *n_val, SEXP_t **o_val); 00115 int SEXP_rawval_lblk_cb (uintptr_t lblkp, int (*func) (SEXP_t *, void *), void *arg, uint32_t n); 00116 void SEXP_rawval_lblk_free (uintptr_t lblkp, void (*func) (SEXP_t *)); 00117 void SEXP_rawval_lblk_free1 (uintptr_t lblkp, void (*func) (SEXP_t *)); 00118 00119 #define SEXP_LBLK_ALIGN (16 > sizeof(void *) ? 16 : sizeof(void *)) 00120 #define SEXP_LBLKP_MASK (UINTPTR_MAX << 4) 00121 #define SEXP_LBLKS_MASK 0x0f 00122 00123 #define SEXP_VALP_LBLK(valp) ((struct SEXP_val_lblk *)((uintptr_t)(valp) & SEXP_LBLKP_MASK)) 00124 00125 OSCAP_HIDDEN_END; 00126 00127 #endif /* _SEXP_VALUE_H */