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

Commitd59f862

Browse files
std: Use read_unaligned for reading DWARF
1 parenta778c83 commitd59f862

File tree

1 file changed

+12
-14
lines changed
  • std/src/sys/personality/dwarf

1 file changed

+12
-14
lines changed

‎std/src/sys/personality/dwarf/mod.rs‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,30 @@ pub struct DwarfReader {
1717
pubptr:*constu8,
1818
}
1919

20-
#[repr(C, packed)]
21-
structUnaligned<T>(T);
22-
20+
#[deny(unsafe_op_in_unsafe_fn)]
2321
implDwarfReader{
2422
pubfnnew(ptr:*constu8) ->DwarfReader{
2523
DwarfReader{ ptr}
2624
}
2725

28-
// DWARF streams are packed, so e.g., a u32 would not necessarily be aligned
29-
// on a 4-byte boundary. This may cause problems on platforms with strict
30-
// alignment requirements. By wrapping data in a "packed" struct, we are
31-
// telling the backend to generate "misalignment-safe" code.
26+
/// Read a type T and then bump the pointer by that amount.
27+
///
28+
/// DWARF streams are "packed", so all types must be read at align 1.
3229
pubunsafefnread<T:Copy>(&mutself) ->T{
33-
letUnaligned(result) =*(self.ptras*constUnaligned<T>);
34-
self.ptr =self.ptr.add(mem::size_of::<T>());
35-
result
30+
unsafe{
31+
let result =self.ptr.cast::<T>().read_unaligned();
32+
self.ptr =self.ptr.byte_add(mem::size_of::<T>());
33+
result
34+
}
3635
}
3736

38-
// ULEB128 and SLEB128 encodings are defined in Section 7.6 - "Variable
39-
// Length Data".
37+
/// ULEB128 and SLEB128 encodings are defined in Section 7.6 - "Variable Length Data".
4038
pubunsafefnread_uleb128(&mutself) ->u64{
4139
letmut shift:usize =0;
4240
letmut result:u64 =0;
4341
letmut byte:u8;
4442
loop{
45-
byte =self.read::<u8>();
43+
byte =unsafe{self.read::<u8>()};
4644
result |=((byte&0x7F)asu64) << shift;
4745
shift +=7;
4846
if byte&0x80 ==0{
@@ -57,7 +55,7 @@ impl DwarfReader {
5755
letmut result:u64 =0;
5856
letmut byte:u8;
5957
loop{
60-
byte =self.read::<u8>();
58+
byte =unsafe{self.read::<u8>()};
6159
result |=((byte&0x7F)asu64) << shift;
6260
shift +=7;
6361
if byte&0x80 ==0{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp