Skip to content

Commit bb2f1c7

Browse files
committed
Remove more unjustified unsafe
1 parent 5e1fdf8 commit bb2f1c7

File tree

11 files changed

+134
-134
lines changed

11 files changed

+134
-134
lines changed

11_exceptions_part1_groundwork/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ The actual handlers referenced from the assembly can now branch to it for the ti
328328

329329
```rust
330330
#[no_mangle]
331-
unsafe extern "C" fn current_elx_irq(e: &mut ExceptionContext) {
331+
extern "C" fn current_elx_irq(e: &mut ExceptionContext) {
332332
default_exception_handler(e);
333333
}
334334
```
@@ -367,7 +367,7 @@ To survive this exception, the respective handler has a special demo case:
367367

368368
```rust
369369
#[no_mangle]
370-
unsafe extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
370+
extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
371371
if e.fault_address_valid() {
372372
let far_el1 = FAR_EL1.get();
373373

@@ -565,17 +565,17 @@ diff -uNr 10_virtual_mem_part1_identity_mapping/src/_arch/aarch64/exception.rs 1
565565
+//------------------------------------------------------------------------------
566566
+
567567
+#[no_mangle]
568-
+unsafe extern "C" fn current_el0_synchronous(_e: &mut ExceptionContext) {
568+
+extern "C" fn current_el0_synchronous(_e: &mut ExceptionContext) {
569569
+ panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
570570
+}
571571
+
572572
+#[no_mangle]
573-
+unsafe extern "C" fn current_el0_irq(_e: &mut ExceptionContext) {
573+
+extern "C" fn current_el0_irq(_e: &mut ExceptionContext) {
574574
+ panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
575575
+}
576576
+
577577
+#[no_mangle]
578-
+unsafe extern "C" fn current_el0_serror(_e: &mut ExceptionContext) {
578+
+extern "C" fn current_el0_serror(_e: &mut ExceptionContext) {
579579
+ panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
580580
+}
581581
+
@@ -584,7 +584,7 @@ diff -uNr 10_virtual_mem_part1_identity_mapping/src/_arch/aarch64/exception.rs 1
584584
+//------------------------------------------------------------------------------
585585
+
586586
+#[no_mangle]
587-
+unsafe extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
587+
+extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
588588
+ if e.fault_address_valid() {
589589
+ let far_el1 = FAR_EL1.get();
590590
+
@@ -601,12 +601,12 @@ diff -uNr 10_virtual_mem_part1_identity_mapping/src/_arch/aarch64/exception.rs 1
601601
+}
602602
+
603603
+#[no_mangle]
604-
+unsafe extern "C" fn current_elx_irq(e: &mut ExceptionContext) {
604+
+extern "C" fn current_elx_irq(e: &mut ExceptionContext) {
605605
+ default_exception_handler(e);
606606
+}
607607
+
608608
+#[no_mangle]
609-
+unsafe extern "C" fn current_elx_serror(e: &mut ExceptionContext) {
609+
+extern "C" fn current_elx_serror(e: &mut ExceptionContext) {
610610
+ default_exception_handler(e);
611611
+}
612612
+
@@ -615,17 +615,17 @@ diff -uNr 10_virtual_mem_part1_identity_mapping/src/_arch/aarch64/exception.rs 1
615615
+//------------------------------------------------------------------------------
616616
+
617617
+#[no_mangle]
618-
+unsafe extern "C" fn lower_aarch64_synchronous(e: &mut ExceptionContext) {
618+
+extern "C" fn lower_aarch64_synchronous(e: &mut ExceptionContext) {
619619
+ default_exception_handler(e);
620620
+}
621621
+
622622
+#[no_mangle]
623-
+unsafe extern "C" fn lower_aarch64_irq(e: &mut ExceptionContext) {
623+
+extern "C" fn lower_aarch64_irq(e: &mut ExceptionContext) {
624624
+ default_exception_handler(e);
625625
+}
626626
+
627627
+#[no_mangle]
628-
+unsafe extern "C" fn lower_aarch64_serror(e: &mut ExceptionContext) {
628+
+extern "C" fn lower_aarch64_serror(e: &mut ExceptionContext) {
629629
+ default_exception_handler(e);
630630
+}
631631
+
@@ -634,17 +634,17 @@ diff -uNr 10_virtual_mem_part1_identity_mapping/src/_arch/aarch64/exception.rs 1
634634
+//------------------------------------------------------------------------------
635635
+
636636
+#[no_mangle]
637-
+unsafe extern "C" fn lower_aarch32_synchronous(e: &mut ExceptionContext) {
637+
+extern "C" fn lower_aarch32_synchronous(e: &mut ExceptionContext) {
638638
+ default_exception_handler(e);
639639
+}
640640
+
641641
+#[no_mangle]
642-
+unsafe extern "C" fn lower_aarch32_irq(e: &mut ExceptionContext) {
642+
+extern "C" fn lower_aarch32_irq(e: &mut ExceptionContext) {
643643
+ default_exception_handler(e);
644644
+}
645645
+
646646
+#[no_mangle]
647-
+unsafe extern "C" fn lower_aarch32_serror(e: &mut ExceptionContext) {
647+
+extern "C" fn lower_aarch32_serror(e: &mut ExceptionContext) {
648648
+ default_exception_handler(e);
649649
+}
650650
+

11_exceptions_part1_groundwork/src/_arch/aarch64/exception.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ fn default_exception_handler(exc: &ExceptionContext) {
6767
//------------------------------------------------------------------------------
6868

6969
#[no_mangle]
70-
unsafe extern "C" fn current_el0_synchronous(_e: &mut ExceptionContext) {
70+
extern "C" fn current_el0_synchronous(_e: &mut ExceptionContext) {
7171
panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
7272
}
7373

7474
#[no_mangle]
75-
unsafe extern "C" fn current_el0_irq(_e: &mut ExceptionContext) {
75+
extern "C" fn current_el0_irq(_e: &mut ExceptionContext) {
7676
panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
7777
}
7878

7979
#[no_mangle]
80-
unsafe extern "C" fn current_el0_serror(_e: &mut ExceptionContext) {
80+
extern "C" fn current_el0_serror(_e: &mut ExceptionContext) {
8181
panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
8282
}
8383

@@ -86,7 +86,7 @@ unsafe extern "C" fn current_el0_serror(_e: &mut ExceptionContext) {
8686
//------------------------------------------------------------------------------
8787

8888
#[no_mangle]
89-
unsafe extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
89+
extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
9090
if e.fault_address_valid() {
9191
let far_el1 = FAR_EL1.get();
9292

@@ -103,12 +103,12 @@ unsafe extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
103103
}
104104

105105
#[no_mangle]
106-
unsafe extern "C" fn current_elx_irq(e: &mut ExceptionContext) {
106+
extern "C" fn current_elx_irq(e: &mut ExceptionContext) {
107107
default_exception_handler(e);
108108
}
109109

110110
#[no_mangle]
111-
unsafe extern "C" fn current_elx_serror(e: &mut ExceptionContext) {
111+
extern "C" fn current_elx_serror(e: &mut ExceptionContext) {
112112
default_exception_handler(e);
113113
}
114114

@@ -117,17 +117,17 @@ unsafe extern "C" fn current_elx_serror(e: &mut ExceptionContext) {
117117
//------------------------------------------------------------------------------
118118

119119
#[no_mangle]
120-
unsafe extern "C" fn lower_aarch64_synchronous(e: &mut ExceptionContext) {
120+
extern "C" fn lower_aarch64_synchronous(e: &mut ExceptionContext) {
121121
default_exception_handler(e);
122122
}
123123

124124
#[no_mangle]
125-
unsafe extern "C" fn lower_aarch64_irq(e: &mut ExceptionContext) {
125+
extern "C" fn lower_aarch64_irq(e: &mut ExceptionContext) {
126126
default_exception_handler(e);
127127
}
128128

129129
#[no_mangle]
130-
unsafe extern "C" fn lower_aarch64_serror(e: &mut ExceptionContext) {
130+
extern "C" fn lower_aarch64_serror(e: &mut ExceptionContext) {
131131
default_exception_handler(e);
132132
}
133133

@@ -136,17 +136,17 @@ unsafe extern "C" fn lower_aarch64_serror(e: &mut ExceptionContext) {
136136
//------------------------------------------------------------------------------
137137

138138
#[no_mangle]
139-
unsafe extern "C" fn lower_aarch32_synchronous(e: &mut ExceptionContext) {
139+
extern "C" fn lower_aarch32_synchronous(e: &mut ExceptionContext) {
140140
default_exception_handler(e);
141141
}
142142

143143
#[no_mangle]
144-
unsafe extern "C" fn lower_aarch32_irq(e: &mut ExceptionContext) {
144+
extern "C" fn lower_aarch32_irq(e: &mut ExceptionContext) {
145145
default_exception_handler(e);
146146
}
147147

148148
#[no_mangle]
149-
unsafe extern "C" fn lower_aarch32_serror(e: &mut ExceptionContext) {
149+
extern "C" fn lower_aarch32_serror(e: &mut ExceptionContext) {
150150
default_exception_handler(e);
151151
}
152152

12_integrated_testing/kernel/src/_arch/aarch64/exception.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ fn default_exception_handler(exc: &ExceptionContext) {
6767
//------------------------------------------------------------------------------
6868

6969
#[no_mangle]
70-
unsafe extern "C" fn current_el0_synchronous(_e: &mut ExceptionContext) {
70+
extern "C" fn current_el0_synchronous(_e: &mut ExceptionContext) {
7171
panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
7272
}
7373

7474
#[no_mangle]
75-
unsafe extern "C" fn current_el0_irq(_e: &mut ExceptionContext) {
75+
extern "C" fn current_el0_irq(_e: &mut ExceptionContext) {
7676
panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
7777
}
7878

7979
#[no_mangle]
80-
unsafe extern "C" fn current_el0_serror(_e: &mut ExceptionContext) {
80+
extern "C" fn current_el0_serror(_e: &mut ExceptionContext) {
8181
panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
8282
}
8383

@@ -86,7 +86,7 @@ unsafe extern "C" fn current_el0_serror(_e: &mut ExceptionContext) {
8686
//------------------------------------------------------------------------------
8787

8888
#[no_mangle]
89-
unsafe extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
89+
extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
9090
#[cfg(feature = "test_build")]
9191
{
9292
const TEST_SVC_ID: u64 = 0x1337;
@@ -102,12 +102,12 @@ unsafe extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
102102
}
103103

104104
#[no_mangle]
105-
unsafe extern "C" fn current_elx_irq(e: &mut ExceptionContext) {
105+
extern "C" fn current_elx_irq(e: &mut ExceptionContext) {
106106
default_exception_handler(e);
107107
}
108108

109109
#[no_mangle]
110-
unsafe extern "C" fn current_elx_serror(e: &mut ExceptionContext) {
110+
extern "C" fn current_elx_serror(e: &mut ExceptionContext) {
111111
default_exception_handler(e);
112112
}
113113

@@ -116,17 +116,17 @@ unsafe extern "C" fn current_elx_serror(e: &mut ExceptionContext) {
116116
//------------------------------------------------------------------------------
117117

118118
#[no_mangle]
119-
unsafe extern "C" fn lower_aarch64_synchronous(e: &mut ExceptionContext) {
119+
extern "C" fn lower_aarch64_synchronous(e: &mut ExceptionContext) {
120120
default_exception_handler(e);
121121
}
122122

123123
#[no_mangle]
124-
unsafe extern "C" fn lower_aarch64_irq(e: &mut ExceptionContext) {
124+
extern "C" fn lower_aarch64_irq(e: &mut ExceptionContext) {
125125
default_exception_handler(e);
126126
}
127127

128128
#[no_mangle]
129-
unsafe extern "C" fn lower_aarch64_serror(e: &mut ExceptionContext) {
129+
extern "C" fn lower_aarch64_serror(e: &mut ExceptionContext) {
130130
default_exception_handler(e);
131131
}
132132

@@ -135,17 +135,17 @@ unsafe extern "C" fn lower_aarch64_serror(e: &mut ExceptionContext) {
135135
//------------------------------------------------------------------------------
136136

137137
#[no_mangle]
138-
unsafe extern "C" fn lower_aarch32_synchronous(e: &mut ExceptionContext) {
138+
extern "C" fn lower_aarch32_synchronous(e: &mut ExceptionContext) {
139139
default_exception_handler(e);
140140
}
141141

142142
#[no_mangle]
143-
unsafe extern "C" fn lower_aarch32_irq(e: &mut ExceptionContext) {
143+
extern "C" fn lower_aarch32_irq(e: &mut ExceptionContext) {
144144
default_exception_handler(e);
145145
}
146146

147147
#[no_mangle]
148-
unsafe extern "C" fn lower_aarch32_serror(e: &mut ExceptionContext) {
148+
extern "C" fn lower_aarch32_serror(e: &mut ExceptionContext) {
149149
default_exception_handler(e);
150150
}
151151

13_exceptions_part2_peripheral_IRQs/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ the the implementation of the trait's handling function:
367367

368368
```rust
369369
#[no_mangle]
370-
unsafe extern "C" fn current_elx_irq(_e: &mut ExceptionContext) {
371-
let token = &exception::asynchronous::IRQContext::new();
370+
extern "C" fn current_elx_irq(_e: &mut ExceptionContext) {
371+
let token = unsafe { &exception::asynchronous::IRQContext::new() };
372372
exception::asynchronous::irq_manager().handle_pending_irqs(token);
373373
}
374374
```
@@ -887,10 +887,10 @@ diff -uNr 12_integrated_testing/kernel/src/_arch/aarch64/exception.rs 13_excepti
887887
}
888888

889889
#[no_mangle]
890-
-unsafe extern "C" fn current_elx_irq(e: &mut ExceptionContext) {
890+
-extern "C" fn current_elx_irq(e: &mut ExceptionContext) {
891891
- default_exception_handler(e);
892-
+unsafe extern "C" fn current_elx_irq(_e: &mut ExceptionContext) {
893-
+ let token = &exception::asynchronous::IRQContext::new();
892+
+extern "C" fn current_elx_irq(_e: &mut ExceptionContext) {
893+
+ let token = unsafe { &exception::asynchronous::IRQContext::new() };
894894
+ exception::asynchronous::irq_manager().handle_pending_irqs(token);
895895
}
896896

13_exceptions_part2_peripheral_IRQs/kernel/src/_arch/aarch64/exception.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ fn default_exception_handler(exc: &ExceptionContext) {
6868
//------------------------------------------------------------------------------
6969

7070
#[no_mangle]
71-
unsafe extern "C" fn current_el0_synchronous(_e: &mut ExceptionContext) {
71+
extern "C" fn current_el0_synchronous(_e: &mut ExceptionContext) {
7272
panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
7373
}
7474

7575
#[no_mangle]
76-
unsafe extern "C" fn current_el0_irq(_e: &mut ExceptionContext) {
76+
extern "C" fn current_el0_irq(_e: &mut ExceptionContext) {
7777
panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
7878
}
7979

8080
#[no_mangle]
81-
unsafe extern "C" fn current_el0_serror(_e: &mut ExceptionContext) {
81+
extern "C" fn current_el0_serror(_e: &mut ExceptionContext) {
8282
panic!("Should not be here. Use of SP_EL0 in EL1 is not supported.")
8383
}
8484

@@ -87,7 +87,7 @@ unsafe extern "C" fn current_el0_serror(_e: &mut ExceptionContext) {
8787
//------------------------------------------------------------------------------
8888

8989
#[no_mangle]
90-
unsafe extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
90+
extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
9191
#[cfg(feature = "test_build")]
9292
{
9393
const TEST_SVC_ID: u64 = 0x1337;
@@ -103,13 +103,13 @@ unsafe extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
103103
}
104104

105105
#[no_mangle]
106-
unsafe extern "C" fn current_elx_irq(_e: &mut ExceptionContext) {
107-
let token = &exception::asynchronous::IRQContext::new();
106+
extern "C" fn current_elx_irq(_e: &mut ExceptionContext) {
107+
let token = unsafe { &exception::asynchronous::IRQContext::new() };
108108
exception::asynchronous::irq_manager().handle_pending_irqs(token);
109109
}
110110

111111
#[no_mangle]
112-
unsafe extern "C" fn current_elx_serror(e: &mut ExceptionContext) {
112+
extern "C" fn current_elx_serror(e: &mut ExceptionContext) {
113113
default_exception_handler(e);
114114
}
115115

@@ -118,17 +118,17 @@ unsafe extern "C" fn current_elx_serror(e: &mut ExceptionContext) {
118118
//------------------------------------------------------------------------------
119119

120120
#[no_mangle]
121-
unsafe extern "C" fn lower_aarch64_synchronous(e: &mut ExceptionContext) {
121+
extern "C" fn lower_aarch64_synchronous(e: &mut ExceptionContext) {
122122
default_exception_handler(e);
123123
}
124124

125125
#[no_mangle]
126-
unsafe extern "C" fn lower_aarch64_irq(e: &mut ExceptionContext) {
126+
extern "C" fn lower_aarch64_irq(e: &mut ExceptionContext) {
127127
default_exception_handler(e);
128128
}
129129

130130
#[no_mangle]
131-
unsafe extern "C" fn lower_aarch64_serror(e: &mut ExceptionContext) {
131+
extern "C" fn lower_aarch64_serror(e: &mut ExceptionContext) {
132132
default_exception_handler(e);
133133
}
134134

@@ -137,17 +137,17 @@ unsafe extern "C" fn lower_aarch64_serror(e: &mut ExceptionContext) {
137137
//------------------------------------------------------------------------------
138138

139139
#[no_mangle]
140-
unsafe extern "C" fn lower_aarch32_synchronous(e: &mut ExceptionContext) {
140+
extern "C" fn lower_aarch32_synchronous(e: &mut ExceptionContext) {
141141
default_exception_handler(e);
142142
}
143143

144144
#[no_mangle]
145-
unsafe extern "C" fn lower_aarch32_irq(e: &mut ExceptionContext) {
145+
extern "C" fn lower_aarch32_irq(e: &mut ExceptionContext) {
146146
default_exception_handler(e);
147147
}
148148

149149
#[no_mangle]
150-
unsafe extern "C" fn lower_aarch32_serror(e: &mut ExceptionContext) {
150+
extern "C" fn lower_aarch32_serror(e: &mut ExceptionContext) {
151151
default_exception_handler(e);
152152
}
153153

0 commit comments

Comments
 (0)