Skip to content

Commit ce40faf

Browse files
bradjcppannuto
authored andcommitted
libtock: do not include syscalls
Apps should specify they use syscalls directly. Need to duplicate the exists() function to make this work.
1 parent b613b36 commit ce40faf

File tree

14 files changed

+48
-15
lines changed

14 files changed

+48
-15
lines changed

doc/guide.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ There must be a function to check for syscall driver existence.
170170
Signature:
171171

172172
```
173-
bool libtock_[name]_exists(void);
173+
bool libtock_[name]_driver_exists(void);
174174
```
175175

176176
Example:
177177

178178
```c
179-
bool libtock_[name]_exists(void) {
179+
bool libtock_[name]_driver_exists(void) {
180180
return driver_exists(DRIVER_NUM_[NAME]);
181181
}
182182
```
@@ -202,7 +202,6 @@ The `[name].h` header file must look like:
202202
#pragma once
203203

204204
#include "../tock.h"
205-
#include "syscalls/[name]_syscalls.h"
206205

207206
#ifdef __cplusplus
208207
extern "C" {
@@ -215,7 +214,8 @@ extern "C" {
215214
#endif
216215
```
217216

218-
The `[name].h` header file must include the syscalls header.
217+
The `[name].h` header file must NOT include the syscalls header. Applications
218+
wanting to use the syscalls directly must include the syscalls header.
219219

220220
### Defining a Callback for Asynchronous Operations
221221

@@ -236,6 +236,24 @@ they should have the last argument be a callback function pointer.
236236
returncode_t libtock_[name]_[desc](<arguments>, libtock_[name]_callback_[desc] cb);
237237
```
238238

239+
#### Exists
240+
241+
There must be a function to check for syscall driver existence.
242+
243+
Signature:
244+
245+
```
246+
bool libtock_[name]_exists(void);
247+
```
248+
249+
Example:
250+
251+
```c
252+
bool libtock_[name]_exists(void) {
253+
return libtock_[name]_driver_exists();
254+
}
255+
```
256+
239257
### Example:
240258

241259

@@ -309,7 +327,6 @@ file is used in a C++ app.
309327
#pragma once
310328
311329
#include <libtock/tock.h>
312-
#include <libtock/[category]/syscalls/[name]_syscalls.h>
313330
314331
#ifdef __cplusplus
315332
extern "C" {
@@ -379,7 +396,6 @@ The libtock-sync `[name].h` header file must look like:
379396
```c
380397
#pragma once
381398

382-
#include "syscalls/temperature_syscalls.h"
383399
#include <libtock/tock.h>
384400

385401
#ifdef __cplusplus

examples/tests/aes/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <string.h>
44

55
#include <libtock/crypto/aes.h>
6+
#include <libtock/crypto/syscalls/aes_syscalls.h>
67

78
#define KEY_LEN 16
89
#define IV_LEN 16

libtock/crypto/aes.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#include "aes.h"
2+
#include "syscalls/aes_syscalls.h"
3+
4+
bool libtock_aes_exists(void) {
5+
return libtock_aes_driver_exists();
6+
}
27

38
returncode_t libtock_aes_set_algorithm(libtock_aes_algorithm_t operation, bool encrypting) {
49
return libtock_aes_command_set_algorithm((uint8_t) operation, encrypting);

libtock/crypto/aes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include "../tock.h"
4-
#include "syscalls/aes_syscalls.h"
54

65
#ifdef __cplusplus
76
extern "C" {
@@ -14,6 +13,9 @@ typedef enum {
1413
LIBTOCK_AES128CCM = 3
1514
} libtock_aes_algorithm_t;
1615

16+
// Check if the AES driver exists on this system.
17+
bool libtock_aes_exists(void);
18+
1719
// Set the AES algorithm
1820
// operation:
1921
// * 0 -> AES128Ctr

libtock/crypto/hmac.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "hmac.h"
2+
#include "syscalls/hmac_syscalls.h"
23

34
static void hmac_upcall(int ret,
45
__attribute__ ((unused)) int unused1,
@@ -7,6 +8,9 @@ static void hmac_upcall(int ret,
78
cb(tock_status_to_returncode(ret));
89
}
910

11+
bool libtock_hmac_exists(void) {
12+
return libtock_hmac_driver_exists();
13+
}
1014

1115
returncode_t libtock_hmac_simple(libtock_hmac_algorithm_t hmac_type,
1216
uint8_t* key_buffer, uint32_t key_length,

libtock/crypto/hmac.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "../tock.h"
44
#include "hmac_types.h"
5-
#include "syscalls/hmac_syscalls.h"
65

76
#ifdef __cplusplus
87
extern "C" {
@@ -13,6 +12,7 @@ extern "C" {
1312
// - `arg1` (`returncode_t`): Status from computing the HMAC.
1413
typedef void (*libtock_hmac_callback_hmac)(returncode_t);
1514

15+
bool libtock_hmac_exists(void);
1616

1717
// Compute an HMAC using `keyb_buffer` over `input_buffer` and store the result
1818
// in `hash_buffer`.

libtock/crypto/sha.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "sha.h"
2+
#include "syscalls/sha_syscalls.h"
23

34
static void sha_upcall(int status,
45
__attribute__ ((unused)) int unused1,
@@ -7,6 +8,10 @@ static void sha_upcall(int status,
78
cb(tock_status_to_returncode(status));
89
}
910

11+
bool libtock_sha_exists(void) {
12+
return libtock_sha_driver_exists();
13+
}
14+
1015
returncode_t libtock_sha_simple_hash(libtock_sha_algorithm_t hash_type,
1116
uint8_t* input_buffer, uint32_t input_length,
1217
uint8_t* hash_buffer, uint32_t hash_length,

libtock/crypto/sha.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include "../tock.h"
4-
#include "syscalls/sha_syscalls.h"
54

65
#ifdef __cplusplus
76
extern "C" {
@@ -19,6 +18,7 @@ typedef enum {
1918
} libtock_sha_algorithm_t;
2019

2120

21+
bool libtock_sha_exists(void);
2222

2323
// Compute a SHA hash over `input_buffer` and store the hash in `hash_buffer`.
2424
//

libtock/crypto/syscalls/aes_syscalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define TOCK_AES_CCM_MIC_LEN 7
1818
#define TOCK_AES_CCM_CONF 8
1919

20-
bool libtock_aes_exists(void) {
20+
bool libtock_aes_driver_exists(void) {
2121
return driver_exists(DRIVER_NUM_AES);
2222
}
2323

libtock/crypto/syscalls/aes_syscalls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern "C" {
88

99
#define DRIVER_NUM_AES 0x40006
1010

11-
bool libtock_aes_exists(void);
11+
bool libtock_aes_driver_exists(void);
1212

1313
returncode_t libtock_aes_set_upcall(subscribe_upcall callback, void* opaque);
1414

0 commit comments

Comments
 (0)