Skip to content

Commit 2e5f6e5

Browse files
committed
fastrpc: libhexagonrpc: add error API
When the kernel side of FastRPC fails, the return value is -1 and errno is set. When the remote side of FastRPC fails, the return value is an AEE error code. It is not specialized for the reverse tunnel. Add an error API that can convert the return value to a string-based error.
1 parent f1f499a commit 2e5f6e5

File tree

8 files changed

+28
-16
lines changed

8 files changed

+28
-16
lines changed

hexagonrpcd/apps_std.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
*/
2121

2222
#include <errno.h>
23+
#include <libhexagonrpc/error.h>
2324
#include <stdio.h>
2425
#include <stdint.h>
2526
#include <string.h>
2627
#include <sys/stat.h>
2728
#include <unistd.h>
2829

29-
#include "aee_error.h"
3030
#include "interfaces/apps_std.def"
3131
#include "hexagonfs.h"
3232
#include "iobuffer.h"

hexagonrpcd/listener.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
*/
2121

2222
#include <inttypes.h>
23+
#include <libhexagonrpc/error.h>
2324
#include <libhexagonrpc/fastrpc.h>
2425
#include <libhexagonrpc/interfaces/remotectl.def>
2526
#include <stddef.h>
2627
#include <stdio.h>
2728

28-
#include "aee_error.h"
2929
#include "interfaces/adsp_listener.def"
3030
#include "iobuffer.h"
3131
#include "listener.h"

hexagonrpcd/localctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2020
*/
2121

22+
#include <libhexagonrpc/error.h>
2223
#include <libhexagonrpc/interfaces/remotectl.def>
2324
#include <stddef.h>
2425
#include <stdio.h>
2526
#include <stdlib.h>
2627
#include <string.h>
2728

28-
#include "aee_error.h"
2929
#include "iobuffer.h"
3030
#include "listener.h"
3131
#include "localctl.h"

hexagonrpcd/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
executable('hexagonrpcd',
2-
'aee_error.c',
32
'apps_mem.c',
43
'apps_std.c',
54
'interfaces.c',

hexagonrpcd/rpcd.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <errno.h>
2323
#include <fcntl.h>
24+
#include <libhexagonrpc/error.h>
2425
#include <libhexagonrpc/fastrpc.h>
2526
#include <libhexagonrpc/interfaces/remotectl.def>
2627
#include <misc/fastrpc.h>
@@ -34,7 +35,6 @@
3435
#include <sys/stat.h>
3536
#include <sys/types.h>
3637

37-
#include "aee_error.h"
3838
#include "apps_mem.h"
3939
#include "apps_std.h"
4040
#include "hexagonfs.h"
@@ -56,17 +56,14 @@ static int remotectl_open(int fd, char *name, struct fastrpc_context **ctx, void
5656
&dlret,
5757
256, err);
5858

59-
if (ret == -1) {
60-
err_cb(strerror(errno));
59+
if (ret) {
60+
err_cb(hexagonrpc_strerror(errno));
6161
return ret;
6262
}
6363

64-
if (dlret == -5) {
64+
if (dlret) {
6565
err_cb(err);
6666
return dlret;
67-
} else if (dlret) {
68-
err_cb(aee_strerror[dlret]);
69-
return dlret;
7067
}
7168

7269
*ctx = fastrpc_create_context(fd, handle);
@@ -85,13 +82,13 @@ static int remotectl_close(struct fastrpc_context *ctx, void (*err_cb)(const cha
8582
&dlret,
8683
256, err);
8784

88-
if (ret == -1) {
89-
err_cb(strerror(errno));
85+
if (ret) {
86+
err_cb(hexagonrpc_strerror(errno));
9087
return ret;
9188
}
9289

9390
if (dlret) {
94-
err_cb(aee_strerror[dlret]);
91+
err_cb(err);
9592
return dlret;
9693
}
9794

hexagonrpcd/aee_error.h renamed to include/libhexagonrpc/error.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Imported FastRPC error numbers
33
*
44
* Copyright (c) 2019, The Linux Foundation. All rights reserved.
5+
* Copyright (c) 2023, The Sensor Shell Contributors. All rights reserved.
56
*
67
* Redistribution and use in source and binary forms, with or without
78
* modification, are permitted provided that the following conditions are
@@ -83,6 +84,6 @@
8384
#define AEE_ECPUEXCEPTION 48
8485
#define AEE_EREADONLY 49
8586

86-
extern const char *aee_strerror[];
87+
const char *hexagonrpc_strerror(int ret);
8788

8889
#endif

hexagonrpcd/aee_error.c renamed to libhexagonrpc/error.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Imported FastRPC error messages
33
*
44
* Copyright (c) 2019, The Linux Foundation. All rights reserved.
5+
* Copyright (c) 2023, The Sensor Shell Contributors. All rights reserved.
56
*
67
* Redistribution and use in source and binary forms, with or without
78
* modification, are permitted provided that the following conditions are
@@ -29,7 +30,10 @@
2930
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3031
*/
3132

32-
const char *aee_strerror[] = {
33+
#include <errno.h>
34+
#include <string.h>
35+
36+
static const char *err_tab[] = {
3337
"No error",
3438
"General failure",
3539
"Insufficient RAM",
@@ -81,3 +85,13 @@ const char *aee_strerror[] = {
8185
"A CPU exception occurred",
8286
"Cannot change read-only object or parameter",
8387
};
88+
89+
const char *hexagonrpc_strerror(int ret)
90+
{
91+
if (ret == -1)
92+
return strerror(errno);
93+
else if (ret >= 0 && (unsigned int) ret < sizeof(err_tab) / sizeof(*err_tab))
94+
return err_tab[ret];
95+
96+
return "Unknown error";
97+
}

libhexagonrpc/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
libhexagonrpc = shared_library('hexagonrpc',
22
'context.c',
3+
'error.c',
34
'fastrpc.c',
45
'interfaces.c',
56
'session.c',

0 commit comments

Comments
 (0)