@@ -170,6 +170,8 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
170
170
171
171
/// Reading and writing
172
172
impl < ' tcx , Tag : Copy , Extra : AllocationExtra < Tag > > Allocation < Tag , Extra > {
173
+ /// Reads bytes until a `0` is encountered. Will error if the end of the allocation is reached
174
+ /// before a `0` is found.
173
175
pub fn read_c_str (
174
176
& self ,
175
177
cx : & impl HasDataLayout ,
@@ -188,14 +190,17 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
188
190
}
189
191
}
190
192
193
+ /// Validates that `ptr.offset` and `ptr.offset + size` do not point to the middle of a
194
+ /// relocation. If `allow_ptr_and_undef` is `false`, also enforces that the memory in the
195
+ /// given range contains neither relocations nor undef bytes.
191
196
pub fn check_bytes (
192
197
& self ,
193
198
cx : & impl HasDataLayout ,
194
199
ptr : Pointer < Tag > ,
195
200
size : Size ,
196
201
allow_ptr_and_undef : bool ,
197
202
) -> EvalResult < ' tcx > {
198
- // Check bounds, align and relocations on the edges
203
+ // Check bounds and relocations on the edges
199
204
self . get_bytes_with_undef_and_ptr ( cx, ptr, size) ?;
200
205
// Check undef and ptr
201
206
if !allow_ptr_and_undef {
@@ -205,6 +210,9 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
205
210
Ok ( ( ) )
206
211
}
207
212
213
+ /// Writes `src` to the memory starting at `ptr.offset`.
214
+ ///
215
+ /// Will do bounds checks on the allocation.
208
216
pub fn write_bytes (
209
217
& mut self ,
210
218
cx : & impl HasDataLayout ,
@@ -216,6 +224,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
216
224
Ok ( ( ) )
217
225
}
218
226
227
+ /// Sets `count` bytes starting at `ptr.offset` with `val`. Basically `memset`.
219
228
pub fn write_repeat (
220
229
& mut self ,
221
230
cx : & impl HasDataLayout ,
@@ -236,6 +245,8 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
236
245
/// * byteorder cannot work with zero element buffers
237
246
/// * in oder to obtain a `Pointer` we need to check for ZSTness anyway due to integer pointers
238
247
/// being valid for ZSTs
248
+ ///
249
+ /// Note: This function does not do *any* alignment checks, you need to do these before calling
239
250
pub fn read_scalar (
240
251
& self ,
241
252
cx : & impl HasDataLayout ,
@@ -270,6 +281,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
270
281
Ok ( ScalarMaybeUndef :: Scalar ( Scalar :: from_uint ( bits, size) ) )
271
282
}
272
283
284
+ /// Note: This function does not do *any* alignment checks, you need to do these before calling
273
285
pub fn read_ptr_sized (
274
286
& self ,
275
287
cx : & impl HasDataLayout ,
@@ -284,6 +296,8 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
284
296
/// * byteorder cannot work with zero element buffers
285
297
/// * in oder to obtain a `Pointer` we need to check for ZSTness anyway due to integer pointers
286
298
/// being valid for ZSTs
299
+ ///
300
+ /// Note: This function does not do *any* alignment checks, you need to do these before calling
287
301
pub fn write_scalar (
288
302
& mut self ,
289
303
cx : & impl HasDataLayout ,
@@ -330,6 +344,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
330
344
Ok ( ( ) )
331
345
}
332
346
347
+ /// Note: This function does not do *any* alignment checks, you need to do these before calling
333
348
pub fn write_ptr_sized (
334
349
& mut self ,
335
350
cx : & impl HasDataLayout ,
@@ -357,7 +372,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
357
372
self . relocations . range ( Size :: from_bytes ( start) ..end)
358
373
}
359
374
360
- /// Check that there ar eno relocations overlapping with the given range.
375
+ /// Check that there are no relocations overlapping with the given range.
361
376
#[ inline( always) ]
362
377
fn check_relocations (
363
378
& self ,
0 commit comments