/src/hdf5/src/H5Oshmesg.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | | * Copyright by The HDF Group. * |
3 | | * All rights reserved. * |
4 | | * * |
5 | | * This file is part of HDF5. The full HDF5 copyright notice, including * |
6 | | * terms governing use, modification, and redistribution, is contained in * |
7 | | * the LICENSE file, which can be found at the root of the source code * |
8 | | * distribution tree, or in https://www.hdfgroup.org/licenses. * |
9 | | * If you do not have access to either file, you may request a copy from * |
10 | | * help@hdfgroup.org. * |
11 | | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
12 | | |
13 | | /* |
14 | | * Purpose: A message holding "implicitly shared object header message" |
15 | | * information in the superblock extension. |
16 | | */ |
17 | | |
18 | | #include "H5Omodule.h" /* This source code file is part of the H5O module */ |
19 | | |
20 | | #include "H5private.h" /* Generic Functions */ |
21 | | #include "H5Eprivate.h" /* Error handling */ |
22 | | #include "H5Opkg.h" /* Object headers */ |
23 | | #include "H5MMprivate.h" /* Memory management */ |
24 | | |
25 | | static void *H5O__shmesg_decode(H5F_t *f, H5O_t *open_oh, unsigned mesg_flags, unsigned *ioflags, |
26 | | size_t p_size, const uint8_t *p); |
27 | | static herr_t H5O__shmesg_encode(H5F_t *f, bool disable_shared, size_t H5_ATTR_UNUSED p_size, uint8_t *p, |
28 | | const void *_mesg); |
29 | | static void *H5O__shmesg_copy(const void *_mesg, void *_dest); |
30 | | static size_t H5O__shmesg_size(const H5F_t *f, bool disable_shared, const void *_mesg); |
31 | | static herr_t H5O__shmesg_debug(H5F_t *f, const void *_mesg, FILE *stream, int indent, int fwidth); |
32 | | |
33 | | /* This message derives from H5O message class */ |
34 | | const H5O_msg_class_t H5O_MSG_SHMESG[1] = {{ |
35 | | H5O_SHMESG_ID, /*message id number */ |
36 | | "shared message table", /*message name for debugging */ |
37 | | sizeof(H5O_shmesg_table_t), /*native message size */ |
38 | | 0, /* messages are shareable? */ |
39 | | H5O__shmesg_decode, /*decode message */ |
40 | | H5O__shmesg_encode, /*encode message */ |
41 | | H5O__shmesg_copy, /*copy the native value */ |
42 | | H5O__shmesg_size, /*raw message size */ |
43 | | NULL, /*free internal memory */ |
44 | | NULL, /* free method */ |
45 | | NULL, /* file delete method */ |
46 | | NULL, /* link method */ |
47 | | NULL, /* set share method */ |
48 | | NULL, /*can share method */ |
49 | | NULL, /* pre copy native value to file */ |
50 | | NULL, /* copy native value to file */ |
51 | | NULL, /* post copy native value to file */ |
52 | | NULL, /* get creation index */ |
53 | | NULL, /* set creation index */ |
54 | | H5O__shmesg_debug /*debug the message */ |
55 | | }}; |
56 | | |
57 | | /*------------------------------------------------------------------------- |
58 | | * Function: H5O__shmesg_decode |
59 | | * |
60 | | * Purpose: Decode a shared message table message and return a pointer |
61 | | * to a newly allocated H5O_shmesg_table_t struct. |
62 | | * |
63 | | * Return: Success: Ptr to new message in native struct. |
64 | | * Failure: NULL |
65 | | *------------------------------------------------------------------------- |
66 | | */ |
67 | | static void * |
68 | | H5O__shmesg_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, unsigned H5_ATTR_UNUSED mesg_flags, |
69 | | unsigned H5_ATTR_UNUSED *ioflags, size_t p_size, const uint8_t *p) |
70 | 0 | { |
71 | 0 | H5O_shmesg_table_t *mesg; /* New shared message table */ |
72 | 0 | const uint8_t *p_end = p + p_size - 1; /* End of the p buffer */ |
73 | 0 | void *ret_value = NULL; |
74 | |
|
75 | 0 | FUNC_ENTER_PACKAGE |
76 | |
|
77 | 0 | assert(f); |
78 | 0 | assert(p); |
79 | |
|
80 | 0 | if (NULL == (mesg = (H5O_shmesg_table_t *)H5MM_calloc(sizeof(H5O_shmesg_table_t)))) |
81 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, |
82 | 0 | "memory allocation failed for shared message table message"); |
83 | | |
84 | | /* Retrieve version, table address, and number of indexes */ |
85 | 0 | if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end)) |
86 | 0 | HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding"); |
87 | 0 | mesg->version = *p++; |
88 | |
|
89 | 0 | if (H5_IS_BUFFER_OVERFLOW(p, H5F_sizeof_addr(f), p_end)) |
90 | 0 | HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding"); |
91 | 0 | H5F_addr_decode(f, &p, &(mesg->addr)); |
92 | |
|
93 | 0 | if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end)) |
94 | 0 | HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding"); |
95 | 0 | mesg->nindexes = *p++; |
96 | | |
97 | | /* Set return value */ |
98 | 0 | ret_value = (void *)mesg; |
99 | |
|
100 | 0 | done: |
101 | 0 | if (!ret_value && mesg) |
102 | 0 | H5MM_xfree(mesg); |
103 | |
|
104 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
105 | 0 | } /* end H5O__shmesg_decode() */ |
106 | | |
107 | | /*------------------------------------------------------------------------- |
108 | | * Function: H5O__shmesg_encode |
109 | | * |
110 | | * Purpose: Encode a shared message table message. |
111 | | * |
112 | | * Return: Non-negative on success/Negative on failure |
113 | | * |
114 | | *------------------------------------------------------------------------- |
115 | | */ |
116 | | static herr_t |
117 | | H5O__shmesg_encode(H5F_t *f, bool H5_ATTR_UNUSED disable_shared, size_t H5_ATTR_UNUSED p_size, uint8_t *p, |
118 | | const void *_mesg) |
119 | 0 | { |
120 | 0 | const H5O_shmesg_table_t *mesg = (const H5O_shmesg_table_t *)_mesg; |
121 | |
|
122 | 0 | FUNC_ENTER_PACKAGE_NOERR |
123 | | |
124 | | /* Sanity check */ |
125 | 0 | assert(f); |
126 | 0 | assert(p); |
127 | 0 | assert(mesg); |
128 | | |
129 | | /* Store version, table address, and number of indexes */ |
130 | 0 | *p++ = (uint8_t)mesg->version; |
131 | 0 | H5F_addr_encode(f, &p, mesg->addr); |
132 | 0 | *p++ = (uint8_t)mesg->nindexes; |
133 | |
|
134 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
135 | 0 | } /* end H5O__shmesg_encode() */ |
136 | | |
137 | | /*------------------------------------------------------------------------- |
138 | | * Function: H5O__shmesg_copy |
139 | | * |
140 | | * Purpose: Copies a message from _MESG to _DEST, allocating _DEST if |
141 | | * necessary. |
142 | | * |
143 | | * Return: Success: Ptr to _DEST |
144 | | * Failure: NULL |
145 | | * |
146 | | *------------------------------------------------------------------------- |
147 | | */ |
148 | | static void * |
149 | | H5O__shmesg_copy(const void *_mesg, void *_dest) |
150 | 0 | { |
151 | 0 | const H5O_shmesg_table_t *mesg = (const H5O_shmesg_table_t *)_mesg; |
152 | 0 | H5O_shmesg_table_t *dest = (H5O_shmesg_table_t *)_dest; |
153 | 0 | void *ret_value = NULL; /* Return value */ |
154 | |
|
155 | 0 | FUNC_ENTER_PACKAGE |
156 | | |
157 | | /* Sanity check */ |
158 | 0 | assert(mesg); |
159 | |
|
160 | 0 | if (!dest && NULL == (dest = (H5O_shmesg_table_t *)H5MM_malloc(sizeof(H5O_shmesg_table_t)))) |
161 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, |
162 | 0 | "memory allocation failed for shared message table message"); |
163 | | |
164 | | /* All this message requires is a shallow copy */ |
165 | 0 | *dest = *mesg; |
166 | | |
167 | | /* Set return value */ |
168 | 0 | ret_value = dest; |
169 | |
|
170 | 0 | done: |
171 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
172 | 0 | } /* end H5O__shmesg_copy() */ |
173 | | |
174 | | /*------------------------------------------------------------------------- |
175 | | * Function: H5O__shmesg_size |
176 | | * |
177 | | * Purpose: Returns the size of the raw message in bytes not counting the |
178 | | * message type or size fields, but only the data fields. |
179 | | * |
180 | | * Return: Success: Message data size in bytes w/o alignment. |
181 | | * Failure: 0 |
182 | | * |
183 | | *------------------------------------------------------------------------- |
184 | | */ |
185 | | static size_t |
186 | | H5O__shmesg_size(const H5F_t *f, bool H5_ATTR_UNUSED disable_shared, const void H5_ATTR_UNUSED *_mesg) |
187 | 0 | { |
188 | 0 | size_t ret_value = 0; /* Return value */ |
189 | |
|
190 | 0 | FUNC_ENTER_PACKAGE_NOERR |
191 | | |
192 | | /* Sanity check */ |
193 | 0 | assert(f); |
194 | |
|
195 | 0 | ret_value = (size_t)(1 + /* Version number */ |
196 | 0 | H5F_SIZEOF_ADDR(f) + /* Table address */ |
197 | 0 | 1); /* Number of indexes */ |
198 | |
|
199 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
200 | 0 | } /* end H5O__shmesg_size() */ |
201 | | |
202 | | /*------------------------------------------------------------------------- |
203 | | * Function: H5O__shmesg_debug |
204 | | * |
205 | | * Purpose: Prints debugging info for the message. |
206 | | * |
207 | | * Return: Non-negative on success/Negative on failure |
208 | | * |
209 | | *------------------------------------------------------------------------- |
210 | | */ |
211 | | static herr_t |
212 | | H5O__shmesg_debug(H5F_t H5_ATTR_UNUSED *f, const void *_mesg, FILE *stream, int indent, int fwidth) |
213 | 0 | { |
214 | 0 | const H5O_shmesg_table_t *mesg = (const H5O_shmesg_table_t *)_mesg; |
215 | |
|
216 | 0 | FUNC_ENTER_PACKAGE_NOERR |
217 | | |
218 | | /* Sanity check */ |
219 | 0 | assert(f); |
220 | 0 | assert(mesg); |
221 | 0 | assert(stream); |
222 | 0 | assert(indent >= 0); |
223 | 0 | assert(fwidth >= 0); |
224 | |
|
225 | 0 | fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Version:", mesg->version); |
226 | 0 | fprintf(stream, "%*s%-*s %" PRIuHADDR " (rel)\n", indent, "", fwidth, |
227 | 0 | "Shared message table address:", mesg->addr); |
228 | 0 | fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Number of indexes:", mesg->nindexes); |
229 | |
|
230 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
231 | 0 | } /* end H5O__shmesg_debug() */ |