Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb512bf6

Browse files
committed
add as_ptr to trait AllocBytes, fix 2 impls; add pub fn get_bytes_unchecked_raw in allocation.rs; add pub fn get_alloc_bytes_unchecked_raw[_mut] in memory.rs
1 parente32ea48 commitb512bf6

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

‎compiler/rustc_const_eval/src/interpret/memory.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
630630
}
631631
}
632632

633+
/// Gives raw, immutable access to the `Allocation` address, without bounds or alignment checks.
634+
/// The caller is responsible for calling the access hooks!
635+
pubfnget_alloc_bytes_unchecked_raw(&self,id:AllocId) ->InterpResult<'tcx,*constu8>{
636+
let alloc =self.get_alloc_raw(id)?;
637+
Ok(alloc.get_bytes_unchecked_raw())
638+
}
639+
633640
/// Bounds-checked *but not align-checked* allocation access.
634641
pubfnget_ptr_alloc<'a>(
635642
&'aself,
@@ -713,6 +720,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
713720
Ok((alloc,&mutself.machine))
714721
}
715722

723+
/// Gives raw, mutable access to the `Allocation` address, without bounds or alignment checks.
724+
/// The caller is responsible for calling the access hooks!
725+
pubfnget_alloc_bytes_unchecked_raw_mut(
726+
&mutself,
727+
id:AllocId,
728+
) ->InterpResult<'tcx,*mutu8>{
729+
let alloc =self.get_alloc_raw_mut(id)?.0;
730+
Ok(alloc.get_bytes_unchecked_raw_mut())
731+
}
732+
716733
/// Bounds-checked *but not align-checked* allocation access.
717734
pubfnget_ptr_alloc_mut<'a>(
718735
&'amutself,

‎compiler/rustc_middle/src/mir/interpret/allocation.rs‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,16 @@ pub trait AllocBytes: Clone + fmt::Debug + Deref<Target = [u8]> + DerefMut<Targe
4040
/// Gives direct access to the raw underlying storage.
4141
///
4242
/// Crucially this pointer is compatible with:
43-
/// - other pointersretunred by this method, and
43+
/// - other pointersreturned by this method, and
4444
/// - references returned from `deref()`, as long as there was no write.
4545
fnas_mut_ptr(&mutself) ->*mutu8;
46+
47+
/// Gives direct access to the raw underlying storage.
48+
///
49+
/// Crucially this pointer is compatible with:
50+
/// - other pointers returned by this method, and
51+
/// - references returned from `deref()`, as long as there was no write.
52+
fnas_ptr(&self) ->*constu8;
4653
}
4754

4855
/// Default `bytes` for `Allocation` is a `Box<u8>`.
@@ -62,6 +69,11 @@ impl AllocBytes for Box<[u8]> {
6269
// Carefully avoiding any intermediate references.
6370
ptr::addr_of_mut!(**self).cast()
6471
}
72+
73+
fnas_ptr(&self) ->*constu8{
74+
// Carefully avoiding any intermediate references.
75+
ptr::addr_of!(**self).cast()
76+
}
6577
}
6678

6779
/// This type represents an Allocation in the Miri/CTFE core engine.
@@ -490,19 +502,27 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes>
490502
self.provenance.clear(range, cx)?;
491503

492504
assert!(range.end().bytes_usize() <=self.bytes.len());// need to do our own bounds-check
493-
//Cruciall, we go via `AllocBytes::as_mut_ptr`, not `AllocBytes::deref_mut`.
505+
//Crucially, we go via `AllocBytes::as_mut_ptr`, not `AllocBytes::deref_mut`.
494506
let begin_ptr =self.bytes.as_mut_ptr().wrapping_add(range.start.bytes_usize());
495507
let len = range.end().bytes_usize() - range.start.bytes_usize();
496508
Ok(ptr::slice_from_raw_parts_mut(begin_ptr, len))
497509
}
498510

499511
/// This gives direct mutable access to the entire buffer, just exposing their internal state
500-
/// withoutreseting anything. Directly exposes `AllocBytes::as_mut_ptr`. Only works if
512+
/// withoutresetting anything. Directly exposes `AllocBytes::as_mut_ptr`. Only works if
501513
/// `OFFSET_IS_ADDR` is true.
502514
pubfnget_bytes_unchecked_raw_mut(&mutself) ->*mutu8{
503515
assert!(Prov::OFFSET_IS_ADDR);
504516
self.bytes.as_mut_ptr()
505517
}
518+
519+
/// This gives direct immutable access to the entire buffer, just exposing their internal state
520+
/// without resetting anything. Directly exposes `AllocBytes::as_ptr`. Only works if
521+
/// `OFFSET_IS_ADDR` is true.
522+
pubfnget_bytes_unchecked_raw(&self) ->*constu8{
523+
assert!(Prov::OFFSET_IS_ADDR);
524+
self.bytes.as_ptr()
525+
}
506526
}
507527

508528
/// Reading and writing.

‎src/tools/miri/src/alloc_bytes.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,8 @@ impl AllocBytes for MiriAllocBytes {
108108
fnas_mut_ptr(&mutself) ->*mutu8{
109109
self.ptr
110110
}
111+
112+
fnas_ptr(&self) ->*constu8{
113+
self.ptr
114+
}
111115
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp