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
For the command logic, you must also use the `enter` API. The first parameter of the closure will be a mutable reference to a `GrantData` wrapper over the previously defined `App`. The wrapper is transparent, meaning it permits accessing fields of the generic type.
171
171
172
172
The next step is configuring the capsule in the board's main file. Remember you need to add the capsule in the `NucleoF429ZI` structure, the `SyscallDriverLookup` and initialize the printer counter capsule.
173
+
174
+
## The role of a Scheduler
175
+
176
+
This task aims to illustrate the importance of OS preemption in the context of untrusted applications. Currently the scheduler used by the board is `kernel::scheduler::RoundRobinSched`, which implements a classical scheduling algorithm, allowing each process to run up to a maximum time slice called **quanta**. In the event that an application tries starving all other processes, the kernel will interrupt the malicious application after its quanta expires and will then schedule another process.
177
+
178
+
### Trust but verify
179
+
180
+
Your task will be to verify the previous claims, by flashing two C applications. One of them will be the `blink` example. After flashing the kernel by running `make flash` in the board's main directory (`boards/nucleo_f429zi`), you can load the application by running `make flash` in the example's root folder (`example/blink`).
181
+
182
+
As there are no *"malicious"* examples, we will have to add them on our own. In this case, an app that would print a message, then just infinitely spin in a `while` loop is enough. For this, you can adapt the `examples/c_hello` example, the flash it.
183
+
184
+
If you managed to flash both applications, you should be able to connect to the board using `tockloader listen` and see a similar output when running `list`:
185
+
186
+
```shell
187
+
tockloader listen
188
+
[INFO ] No device name specified. Using default name "tock".
189
+
[INFO ] No serial port with device name "tock" found.
190
+
[INFO ] Found 2 serial ports.
191
+
Multiple serial port options found. Which would you like to use?
192
+
[0] /dev/cu.debug-console - n/a
193
+
[1] /dev/cu.usbmodem1103 - STM32 STLink
194
+
195
+
Which option? [0] 1
196
+
[INFO ] Using "/dev/cu.usbmodem1103 - STM32 STLink".
197
+
[INFO ] Listening for serial output.
198
+
199
+
tock$ list
200
+
PID ShortID Name Quanta Syscalls Restarts Grants State
201
+
0 Unique blink 0 289 0 1/11 Yielded
202
+
1 Unique ws-demo 640 6 0 1/11 Running
203
+
tock$
204
+
```
205
+
206
+
You should be able to see the on-board LEDs flashing on the board.
207
+
208
+
### Cooperation flaw
209
+
210
+
Now, let's test the same scenario, but with a cooperative scheduling mechanism. You have to first change the kernel's scheduler in the board's `main.rs` file to use the `scheduler::cooperative::CooperativeSched`. Then you must re-flash the kernel by running `make flash`. Fortunately flashing the kernel should preserve the applications, so you will not have to re-flash them as well.
211
+
212
+
After you are done flashing, check that both applications are present. You can try to reset the board a few times by running `reset` in tock's process console (the terminal you open by running `tockloader listen`).
0 commit comments