Skip to content

Commit 2648d4d

Browse files
committed
style: add rustfmt.toml, simplify ci
1 parent bf76985 commit 2648d4d

7 files changed

Lines changed: 118 additions & 90 deletions

File tree

.github/workflows/ci.yml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
11
name: CI
22

3+
on: [push, pull_request]
4+
35
concurrency:
46
group: ${{ github.workflow }}-${{ github.ref }}
57
cancel-in-progress: true
6-
on: [push, pull_request]
78

89
jobs:
10+
fmt:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: dtolnay/rust-toolchain@nightly
15+
with:
16+
components: rustfmt
17+
- name: Format code
18+
run: cargo fmt --all --check
19+
920
check:
1021
runs-on: ubuntu-latest
1122
strategy:
1223
fail-fast: false
1324
matrix:
14-
targets: [x86_64-unknown-linux-gnu, x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none-softfloat]
25+
target:
26+
- x86_64-unknown-linux-gnu
27+
- x86_64-unknown-none
28+
- riscv64gc-unknown-none-elf
29+
- aarch64-unknown-none-softfloat
30+
- loongarch64-unknown-none-softfloat
1531
steps:
1632
- uses: actions/checkout@v4
1733
- uses: dtolnay/rust-toolchain@nightly
1834
with:
19-
components: rust-src, clippy, rustfmt
20-
targets: ${{ matrix.targets }}
21-
- name: Check rust version
22-
run: rustc --version --verbose
23-
- name: Check code format
24-
run: cargo fmt --all -- --check
35+
components: rust-src, clippy, rustfmt
36+
targets: ${{ matrix.target }}
2537
- name: Clippy
26-
run: cargo clippy --target ${{ matrix.targets }} --all-features
38+
run: cargo clippy --target ${{ matrix.target }} --all-features
2739
- name: Unit test
28-
if: ${{ matrix.targets == 'x86_64-unknown-linux-gnu' }}
29-
run: cargo test --target ${{ matrix.targets }} -- --nocapture
40+
if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }}
41+
run: cargo test --target ${{ matrix.target }} -- --nocapture
42+
3043
doc:
3144
runs-on: ubuntu-latest
3245
steps:
@@ -40,6 +53,7 @@ jobs:
4053
uses: actions/upload-pages-artifact@v3
4154
with:
4255
path: target/doc
56+
4357
deploy:
4458
runs-on: ubuntu-latest
4559
needs: doc
@@ -54,4 +68,4 @@ jobs:
5468
steps:
5569
- name: Deploy to GitHub Pages
5670
id: deployment
57-
uses: actions/deploy-pages@v4
71+
uses: actions/deploy-pages@v4

rustfmt.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
unstable_features = true
2+
3+
style_edition = "2024"
4+
5+
group_imports = "StdExternalCrate"
6+
imports_granularity = "Crate"
7+
8+
normalize_comments = true
9+
10+
reorder_impl_items = true
11+
condense_wildcard_suffixes = true
12+
enum_discrim_align_threshold = 20
13+
use_field_init_shorthand = true
14+
15+
format_strings = true
16+
format_code_in_doc_comments = true
17+
format_macro_matchers = true

src/action.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ use crate::SignalSet;
1515
pub enum DefaultSignalAction {
1616
/// Terminate the process.
1717
Terminate,
18-
1918
/// Ignore the signal.
2019
Ignore,
21-
2220
/// Terminate the process and generate a core dump.
2321
CoreDump,
24-
2522
/// Stop the process.
2623
Stop,
27-
2824
/// Continue the process if stopped.
2925
Continue,
3026
}

src/api/process.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
use alloc::{
2+
sync::{Arc, Weak},
3+
vec::Vec,
4+
};
15
use core::{
26
array,
37
ops::{Index, IndexMut},
48
sync::atomic::{AtomicBool, Ordering},
59
};
610

7-
use alloc::{
8-
sync::{Arc, Weak},
9-
vec::Vec,
10-
};
1111
use kspin::SpinNoIrq;
1212

1313
use crate::{
@@ -27,6 +27,7 @@ impl Default for SignalActions {
2727

2828
impl Index<Signo> for SignalActions {
2929
type Output = SignalAction;
30+
3031
fn index(&self, signo: Signo) -> &SignalAction {
3132
&self.0[signo as usize - 1]
3233
}

src/api/thread.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
use alloc::sync::Arc;
12
use core::{
23
alloc::Layout,
34
mem::offset_of,
45
sync::atomic::{AtomicBool, Ordering},
56
};
67

7-
use alloc::sync::Arc;
88
use axcpu::uspace::UserContext;
99
use kspin::SpinNoIrq;
1010
use starry_vm::VmMutPtr;
1111

12+
use super::ProcessSignalManager;
1213
use crate::{
1314
DefaultSignalAction, PendingSignals, SignalAction, SignalActionFlags, SignalDisposition,
1415
SignalInfo, SignalOSAction, SignalSet, SignalStack, Signo, arch::UContext,
1516
};
1617

17-
use super::ProcessSignalManager;
18-
1918
struct SignalFrame {
2019
ucontext: UContext,
2120
siginfo: SignalInfo,
@@ -188,7 +187,7 @@ impl ThreadSignalManager {
188187
/// Restores the signal frame. Called by `sigreturn`.
189188
pub fn restore(&self, uctx: &mut UserContext) {
190189
let frame_ptr = uctx.sp() as *const SignalFrame;
191-
// SAFETY: pointer is valid
190+
// FIXME: remove this `unsafe`
192191
let frame = unsafe { &*frame_ptr };
193192

194193
*uctx = frame.uctx;

src/pending.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use core::array;
2-
31
use alloc::{boxed::Box, collections::vec_deque::VecDeque};
2+
use core::array;
43

54
use crate::{SignalInfo, SignalSet};
65

src/types.rs

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,70 +10,70 @@ use crate::DefaultSignalAction;
1010
#[repr(u8)]
1111
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromRepr, EnumIter)]
1212
pub enum Signo {
13-
SIGHUP = 1,
14-
SIGINT = 2,
15-
SIGQUIT = 3,
16-
SIGILL = 4,
17-
SIGTRAP = 5,
18-
SIGABRT = 6,
19-
SIGBUS = 7,
20-
SIGFPE = 8,
21-
SIGKILL = 9,
22-
SIGUSR1 = 10,
23-
SIGSEGV = 11,
24-
SIGUSR2 = 12,
25-
SIGPIPE = 13,
26-
SIGALRM = 14,
27-
SIGTERM = 15,
13+
SIGHUP = 1,
14+
SIGINT = 2,
15+
SIGQUIT = 3,
16+
SIGILL = 4,
17+
SIGTRAP = 5,
18+
SIGABRT = 6,
19+
SIGBUS = 7,
20+
SIGFPE = 8,
21+
SIGKILL = 9,
22+
SIGUSR1 = 10,
23+
SIGSEGV = 11,
24+
SIGUSR2 = 12,
25+
SIGPIPE = 13,
26+
SIGALRM = 14,
27+
SIGTERM = 15,
2828
SIGSTKFLT = 16,
29-
SIGCHLD = 17,
30-
SIGCONT = 18,
31-
SIGSTOP = 19,
32-
SIGTSTP = 20,
33-
SIGTTIN = 21,
34-
SIGTTOU = 22,
35-
SIGURG = 23,
36-
SIGXCPU = 24,
37-
SIGXFSZ = 25,
29+
SIGCHLD = 17,
30+
SIGCONT = 18,
31+
SIGSTOP = 19,
32+
SIGTSTP = 20,
33+
SIGTTIN = 21,
34+
SIGTTOU = 22,
35+
SIGURG = 23,
36+
SIGXCPU = 24,
37+
SIGXFSZ = 25,
3838
SIGVTALRM = 26,
39-
SIGPROF = 27,
40-
SIGWINCH = 28,
41-
SIGIO = 29,
42-
SIGPWR = 30,
43-
SIGSYS = 31,
44-
SIGRTMIN = 32,
45-
SIGRT1 = 33,
46-
SIGRT2 = 34,
47-
SIGRT3 = 35,
48-
SIGRT4 = 36,
49-
SIGRT5 = 37,
50-
SIGRT6 = 38,
51-
SIGRT7 = 39,
52-
SIGRT8 = 40,
53-
SIGRT9 = 41,
54-
SIGRT10 = 42,
55-
SIGRT11 = 43,
56-
SIGRT12 = 44,
57-
SIGRT13 = 45,
58-
SIGRT14 = 46,
59-
SIGRT15 = 47,
60-
SIGRT16 = 48,
61-
SIGRT17 = 49,
62-
SIGRT18 = 50,
63-
SIGRT19 = 51,
64-
SIGRT20 = 52,
65-
SIGRT21 = 53,
66-
SIGRT22 = 54,
67-
SIGRT23 = 55,
68-
SIGRT24 = 56,
69-
SIGRT25 = 57,
70-
SIGRT26 = 58,
71-
SIGRT27 = 59,
72-
SIGRT28 = 60,
73-
SIGRT29 = 61,
74-
SIGRT30 = 62,
75-
SIGRT31 = 63,
76-
SIGRT32 = 64,
39+
SIGPROF = 27,
40+
SIGWINCH = 28,
41+
SIGIO = 29,
42+
SIGPWR = 30,
43+
SIGSYS = 31,
44+
SIGRTMIN = 32,
45+
SIGRT1 = 33,
46+
SIGRT2 = 34,
47+
SIGRT3 = 35,
48+
SIGRT4 = 36,
49+
SIGRT5 = 37,
50+
SIGRT6 = 38,
51+
SIGRT7 = 39,
52+
SIGRT8 = 40,
53+
SIGRT9 = 41,
54+
SIGRT10 = 42,
55+
SIGRT11 = 43,
56+
SIGRT12 = 44,
57+
SIGRT13 = 45,
58+
SIGRT14 = 46,
59+
SIGRT15 = 47,
60+
SIGRT16 = 48,
61+
SIGRT17 = 49,
62+
SIGRT18 = 50,
63+
SIGRT19 = 51,
64+
SIGRT20 = 52,
65+
SIGRT21 = 53,
66+
SIGRT22 = 54,
67+
SIGRT23 = 55,
68+
SIGRT24 = 56,
69+
SIGRT25 = 57,
70+
SIGRT26 = 58,
71+
SIGRT27 = 59,
72+
SIGRT28 = 60,
73+
SIGRT29 = 61,
74+
SIGRT30 = 62,
75+
SIGRT31 = 63,
76+
SIGRT32 = 64,
7777
}
7878

7979
impl Signo {
@@ -211,6 +211,7 @@ impl SignalInfo {
211211
result.set_code(SI_KERNEL as _);
212212
result
213213
}
214+
214215
pub fn new_user(signo: Signo, code: i32, pid: u32) -> Self {
215216
// FIXME: Zeroable
216217
let mut result: Self = unsafe { mem::zeroed() };
@@ -243,8 +244,9 @@ impl SignalInfo {
243244
}
244245

245246
pub fn errno(&self) -> i32 {
246-
// SAFETY: The union layout matches Linux's siginfo_t definition. bindgen keeps this layout,
247-
// so it is safe to read the errno field through the anonymous union.
247+
// SAFETY: The union layout matches Linux's siginfo_t definition. bindgen keeps
248+
// this layout, so it is safe to read the errno field through the
249+
// anonymous union.
248250
unsafe { self.0.__bindgen_anon_1.__bindgen_anon_1.si_errno }
249251
}
250252
}

0 commit comments

Comments
 (0)