Skip to content

Commit 13c14c1

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 916db47 commit 13c14c1

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_std.c',
43
'interfaces.c',
54
'hexagonfs.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>
@@ -32,7 +33,6 @@
3233
#include <sys/ioctl.h>
3334
#include <sys/types.h>
3435

35-
#include "aee_error.h"
3636
#include "apps_std.h"
3737
#include "hexagonfs.h"
3838
#include "interfaces/adsp_default_listener.def"
@@ -53,17 +53,14 @@ static int remotectl_open(int fd, char *name, struct fastrpc_context **ctx, void
5353
&dlret,
5454
256, err);
5555

56-
if (ret == -1) {
57-
err_cb(strerror(errno));
56+
if (ret) {
57+
err_cb(hexagonrpc_strerror(errno));
5858
return ret;
5959
}
6060

61-
if (dlret == -5) {
61+
if (dlret) {
6262
err_cb(err);
6363
return dlret;
64-
} else if (dlret) {
65-
err_cb(aee_strerror[dlret]);
66-
return dlret;
6764
}
6865

6966
*ctx = fastrpc_create_context(fd, handle);
@@ -82,13 +79,13 @@ static int remotectl_close(struct fastrpc_context *ctx, void (*err_cb)(const cha
8279
&dlret,
8380
256, err);
8481

85-
if (ret == -1) {
86-
err_cb(strerror(errno));
82+
if (ret) {
83+
err_cb(hexagonrpc_strerror(errno));
8784
return ret;
8885
}
8986

9087
if (dlret) {
91-
err_cb(aee_strerror[dlret]);
88+
err_cb(err);
9289
return dlret;
9390
}
9491

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)