You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1a63b39
Browse filesBrowse the repository at this point in the historyBrowse files
Rollup merge of #162257 - vexide:lewisfm/sync-model, r=joboet
Revise the VEXos synchronization model
This PR fixes some compilation errors in `std::sync` under VEXos by switching to a simple spinlock-based model that properly handles the "multithreading" provided by this platform through user interrupt handlers and documenting exactly how and how not `std::sync` may be used on this target. Spinlocks are used because they are very simple and the OS on this target is not aware of threading by default and has no documented builtin futex or mutex API we can use. I don't expect this platform to have more than 1 thread blocking on access for a mutex at once (since there is only 1 thread that's allowed to block per the updated target docs).
Previously Rust programs running on VEXos were only allowed a single execution context and user ISRs were not allowed to interact with std code whatsoever. After these changes, ISRs are allowed to partially interact with std and `std::sync` can be used to synchronize shared resources between the main thread and interrupts.
Using stack-switching schedulers on this platform remains unsound; this is now written explicitly in the target documentation.
Copy file name to clipboardExpand all lines: src/doc/rustc/src/platform-support/thumbv7a-vex-v5.md
+69-25Lines changed: 69 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,31 +23,6 @@ This target is cross-compiled. Dynamic linking is unsupported.
23
23
24
24
`#![no_std]` crates can be built using `build-std` to build `core` and `panic_abort` and optionally `alloc`. Unwinding panics are not yet supported on this target.
25
25
26
-
`std` has only partial support due to platform limitations. Notably:
27
-
28
-
-`std::process` and `std::net` are unimplemented. `std::thread` only supports sleeping and yielding, as this is a single-threaded environment.
29
-
-`std::time` has full support for `Instant`, but no support for `SystemTime`.
30
-
-`std::io` has full support for `stdin`/`stdout`/`stderr`. `stdout` and `stderr` both write to USB channel 1 on this platform and are not differentiated.
31
-
-`std::fs` has limited support for reading or writing to files. The following features are unsupported:
32
-
- All directory operations (including `mkdir` and `readdir`), although reading directories is possible through [third-party crates](https://docs.rs/vex-sdk/latest/vex_sdk/file/fn.vexFileDirectoryGet.html)
33
-
- Deleting files and directories
34
-
- File metadata other than file size and type (that is, file vs. directory)
35
-
- Opening files with an uncommon combination of open options, such as read + write at the same time.
36
-
The supported modes for opening files are in read-only mode, append mode, or write mode (with or without truncation).
37
-
- A global allocator implemented on top of `dlmalloc` is provided.
38
-
- Modules that do not need to interact with the OS beyond allocation, such as `std::collections`, `std::hash`, `std::future`, `std::sync`, etc., are fully supported.
39
-
- Random number generation and hashing is insecure, as there is no reliable source of entropy on this platform.
40
-
41
-
When compiling for this target, the "C" calling convention maps to AAPCS with VFP registers (hard float ABI) and the "system" calling convention maps to AAPCS without VFP registers (softfp ABI).
42
-
43
-
This target generates binaries in the ELF format that may be uploaded to the brain with external tools.
44
-
45
-
### Platform SDKs
46
-
47
-
To use most platform-specific APIs, users must configure a supporting runtime SDK for `libstd` to link against. Official *VEXcode* SDKs from VEX can be downloaded and linked via the [`vex-sdk-vexcode`](https://crates.io/crates/vex-sdk-vexcode) crate, but they have a restrictive redistribution policy that might not be suitable for all projects. The suggested SDK for open-source projects is the community-supported [`vex-sdk-jumptable`](https://crates.io/crates/vex-sdk-jumptable) crate. SDK implementations are generally thin wrappers over system calls, so projects should not expect to see significant differences in behavior depending on which SDK they use.
48
-
49
-
Libraries may access symbols from the active VEX SDK without depending on a specific implementation by using the [`vex-sdk`](https://crates.io/crates/vex-sdk) crate.
50
-
51
26
## Building the target
52
27
53
28
You can build Rust with support for this target by adding it to the `target` list in `bootstrap.toml`, and then running `./x build --target thumbv7a-vex-v5 compiler`.
@@ -100,6 +75,75 @@ fn main() {
100
75
}
101
76
```
102
77
78
+
## Environment
79
+
80
+
The `main` function is entered on a Zynq 7000's CPU1 in the *System* processor mode in *Secure* state. Programs or runtimes should periodically call `std::thread::yield_now` to flush buffers and fetch the latest peripheral state.
81
+
82
+
Developers writing programs for this target should use a high-level runtime such as [vexide](https://vexide.dev) or a lower-level system access crate such as [`vex-sdk`](https://crates.io/crates/vex-sdk) to access peripherals such as motors and sensors.
83
+
84
+
When compiling for this target, the "C" calling convention maps to AAPCS with VFP registers (hard float ABI) and the "system" calling convention maps to AAPCS without VFP registers (softfp ABI).
85
+
86
+
This target generates binaries in the ELF format that may be uploaded to the brain with external tools.
87
+
88
+
See Also: [VEX V5 Environment](https://internals.vexide.dev/technical/environment).
89
+
90
+
### Platform SDKs
91
+
92
+
To use most platform-specific APIs, users must configure a supporting runtime SDK for `libstd` to link against. Official *VEXcode* SDKs from VEX can be downloaded and linked via the [`vex-sdk-vexcode`](https://crates.io/crates/vex-sdk-vexcode) crate, but they have a restrictive redistribution policy that might not be suitable for all projects. The suggested SDK for open-source projects is the community-supported [`vex-sdk-jumptable`](https://crates.io/crates/vex-sdk-jumptable) crate. SDK implementations are generally thin wrappers over system calls, so projects should not expect to see significant differences in behavior depending on which SDK they use.
93
+
94
+
Libraries may access symbols from the active VEX SDK without depending on a specific implementation by using the [`vex-sdk`](https://crates.io/crates/vex-sdk) crate.
95
+
96
+
### Standard Library Support
97
+
98
+
`std` has only partial support due to platform limitations. Notably:
99
+
100
+
-`std::process` and `std::net` are unimplemented. `std::thread` only supports sleeping and yielding.
101
+
-`std::time` has full support for `Instant`, but no support for `SystemTime`.
102
+
-`std::io` has full support for `stdin`/`stdout`/`stderr`. `stdout` and `stderr` both write to USB channel 1 on this platform and are not differentiated.
103
+
-`std::fs` has limited support for reading or writing to files. The following features are unsupported:
104
+
- All directory operations (including `mkdir` and `readdir`), although reading directories is possible through [third-party crates](https://docs.rs/vex-sdk/latest/vex_sdk/file/fn.vexFileDirectoryGet.html)
105
+
- Deleting files and directories
106
+
- File metadata other than file size and type (that is, file vs. directory)
107
+
- Opening files with an uncommon combination of open options, such as read + write at the same time.
108
+
The supported modes for opening files are in read-only mode, append mode, or write mode (with or without truncation).
109
+
- A global allocator implemented on top of `dlmalloc` is provided.
- Modules that do not need to interact with the OS beyond allocation, such as `std::collections`, `std::hash`, `std::future`, etc., are fully supported.
112
+
- Random number generation and hashing is insecure, as there is no reliable source of entropy on this platform.
113
+
114
+
### Thread Safety and Synchronization
115
+
116
+
*This section only applies to programs that use the `std` crate.*
117
+
118
+
When executing on this target, the `std` crate only supports one Rust execution context plus any user-installed Armv7-A exception handlers (configured using the `VBAR` register), provided they properly synchronize access to shared resources. `std` on this target is not aware of any execution inside a task scheduler, so `thread_local` globals will always have the same identity.
119
+
120
+
#### VEXos Task Scheduler
121
+
122
+
This target begins execution outside of the context of the builtin [VEXos task scheduler](https://internals.vexide.dev/sdk/tasks). Spawning VEXos Full Tasks through VEX's undocumented scheduler API (e.g. using the `vexTaskAdd` function) or using any other stack-switching scheduler (including FreeRTOS) is strictly forbidden on this target and will result in undefined behavior. Rust programs may assume that `vexTasksRun` and `std::thread::yield_now` will never switch stacks.
123
+
124
+
Code running inside a VEXos Simple Task context (for example, inside a user touchscreen callback) is forbidden from ticking the task scheduler reentrantly. Thus, it is invalid for task code to:
125
+
126
+
- call `vexTasksRun`, `thread::yield_now`, `thread::sleep`, `thread::park`, or derivatives,
127
+
- or access standard I/O streams via `std::io`.
128
+
129
+
#### Exception Handlers
130
+
131
+
Interrupt Service Routines and other ARM exception handlers are the only form of preemptive concurrency allowed on this target. Exception handlers may be installed on this target using unsafe code and are conceptually treated akin to UNIX signal handlers.
132
+
133
+
Exception handlers in programs using `std`*must not*:
134
+
135
+
- use the data structures in `std::sync` to synchronize access to shared state,
136
+
- use `thread_local!` values whatsoever,
137
+
- panic, which indirectly accesses thread locals,
138
+
- access standard I/O streams via `std::io`,
139
+
- access the filesystem,
140
+
- allocate/deallocate using the `System` allocator,
141
+
- or call `std::thread::current`, which allocates using the `System` allocator,
142
+
143
+
since these features are not synchronized.
144
+
145
+
However, exception handlers *may* use types originating from `core::sync` and `alloc::sync`, including atomics, to synchronize state.
146
+
103
147
## Testing
104
148
105
149
Binaries built for this target can be run in an emulator (such as [vex-v5-qemu](https://github.com/vexide/vex-v5-qemu)), or uploaded to a physical device over a USB serial connection.
0 commit comments