Open SCAP Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
_sexp-value.h
1 /*
2  * Copyright 2009 Red Hat Inc., Durham, North Carolina.
3  * All Rights Reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors:
20  * "Daniel Kopecek" <dkopecek@redhat.com>
21  */
22 
23 #pragma once
24 #ifndef _SEXP_VALUE_H
25 #define _SEXP_VALUE_H
26 
27 #include <stddef.h>
28 #include <stdint.h>
29 #include <stdbool.h>
30 #include "_sexp-types.h"
31 #include "../../../common/util.h"
32 
33 OSCAP_HIDDEN_START;
34 
35 typedef uint8_t SEXP_valtype_t;
36 
37 #define SEXP_VALTYPE_EMPTY 0
38 #define SEXP_VALTYPE_STRING 1
39 #define SEXP_VALTYPE_NUMBER 2
40 #define SEXP_VALTYPE_LIST 3
41 
42 typedef struct {
43  uint32_t refs;
44  size_t size;
45 } __attribute__ ((packed)) SEXP_valhdr_t;
46 
47 typedef struct {
48  uintptr_t ptr;
49  SEXP_valhdr_t *hdr;
50  void *mem;
51  SEXP_valtype_t type;
52 } SEXP_val_t;
53 
54 #define SEXP_VALP_ALIGN (4 > sizeof(void *) ? 4 : sizeof(void *))
55 #define SEXP_VALP_MASK (UINTPTR_MAX << 2)
56 #define SEXP_VALT_MASK 3
57 #define SEXP_VALP_HDR(p) ((SEXP_valhdr_t *)(((uintptr_t)(p)) & SEXP_VALP_MASK))
58 
59 int SEXP_val_new (SEXP_val_t *dst, size_t vmemsize, SEXP_valtype_t type);
60 void SEXP_val_dsc (SEXP_val_t *dst, uintptr_t ptr);
61 uintptr_t SEXP_val_ptr (SEXP_val_t *dsc);
62 
63 uintptr_t SEXP_rawval_incref (uintptr_t valp);
64 int SEXP_rawval_decref (uintptr_t valp);
65 
66 #define SEXP_DEFNUM(s,T) struct SEXP_val_num_##s { T n; SEXP_numtype_t t; } __attribute__ ((packed))
67 #define SEXP_NCASTP(s,p) ((struct SEXP_val_num_##s *)(p))
68 #define SEXP_NTYPEP(sz,p) *((SEXP_numtype_t *)(((uint8_t *)(p)) + (sz) - sizeof (SEXP_numtype_t)))
69 
70 SEXP_numtype_t SEXP_rawval_number_type (SEXP_val_t *dsc);
71 
72 SEXP_DEFNUM(b, bool);
73 SEXP_DEFNUM(f, double);
74 SEXP_DEFNUM(i8, int8_t);
75 SEXP_DEFNUM(u8, uint8_t);
76 SEXP_DEFNUM(i16, int16_t);
77 SEXP_DEFNUM(u16, uint16_t);
78 SEXP_DEFNUM(i32, int32_t);
79 SEXP_DEFNUM(u32, uint32_t);
80 SEXP_DEFNUM(i64, int64_t);
81 SEXP_DEFNUM(u64, uint64_t);
82 
83 /*
84  * List
85  */
86 
87 struct SEXP_val_list {
88  void *b_addr;
89  uint16_t offset;
90 } __attribute__ ((packed));
91 
92 #define SEXP_LCASTP(p) ((struct SEXP_val_list *)(p))
93 
94 struct SEXP_val_lblk {
95  uintptr_t nxsz;
96  uint16_t real;
97  uint16_t refs;
98  SEXP_t memb[];
99 } __attribute__ ((packed));
100 
101 size_t SEXP_rawval_list_length (struct SEXP_val_list *list);
102 uintptr_t SEXP_rawval_list_copy (uintptr_t s_valp);
103 
104 uintptr_t SEXP_rawval_lblk_copy (uintptr_t lblkp, uint16_t n_skip);
105 uintptr_t SEXP_rawval_lblk_new (uint8_t sz);
106 uintptr_t SEXP_rawval_lblk_incref (uintptr_t lblkp);
107 int SEXP_rawval_lblk_decref (uintptr_t lblkp);
108 
109 uintptr_t SEXP_rawval_lblk_fill (uintptr_t lblkp, SEXP_t *s_exp[], uint16_t s_exp_count);
110 uintptr_t SEXP_rawval_lblk_add (uintptr_t lblkp, const SEXP_t *s_exp);
111 uintptr_t SEXP_rawval_lblk_add1 (uintptr_t lblkp, const SEXP_t *s_exp);
112 uintptr_t SEXP_rawval_lblk_last (uintptr_t lblkp);
113 SEXP_t *SEXP_rawval_lblk_nth (uintptr_t lblkp, uint32_t n);
114 uintptr_t SEXP_rawval_lblk_replace (uintptr_t lblkp, uint32_t n, const SEXP_t *n_val, SEXP_t **o_val);
115 int SEXP_rawval_lblk_cb (uintptr_t lblkp, int (*func) (SEXP_t *, void *), void *arg, uint32_t n);
116 void SEXP_rawval_lblk_free (uintptr_t lblkp, void (*func) (SEXP_t *));
117 void SEXP_rawval_lblk_free1 (uintptr_t lblkp, void (*func) (SEXP_t *));
118 
119 #define SEXP_LBLK_ALIGN (16 > sizeof(void *) ? 16 : sizeof(void *))
120 #define SEXP_LBLKP_MASK (UINTPTR_MAX << 4)
121 #define SEXP_LBLKS_MASK 0x0f
122 
123 #define SEXP_VALP_LBLK(valp) ((struct SEXP_val_lblk *)((uintptr_t)(valp) & SEXP_LBLKP_MASK))
124 
125 uintptr_t SEXP_rawval_copy(uintptr_t s_valp);
126 
127 OSCAP_HIDDEN_END;
128 
129 #endif /* _SEXP_VALUE_H */
Definition: _sexp-value.h:87
Definition: _sexp-value.h:47
Definition: _sexp-value.h:42
Definition: _sexp-value.h:94
Definition: sexp-types.h:82