Skip to content

Commit 9f30561

Browse files
committed
make API changes to libhexagonrpc
Add a new version of the remote method definition to support more methods, with sequences of sequences, mixed input and output arguments, and fixed-length data structures greater than 32 bits. Use thread-local variables to replace the leading fd and handle arguments in the inline functions.
1 parent a63a64a commit 9f30561

29 files changed

+2181
-317
lines changed

chrecd/interfaces/chre_slpi.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Context Hub Runtime Environment interface - method definitions
3+
*
4+
* Copyright (C) 2025 HexagonRPC Contributors
5+
*
6+
* This file is part of HexagonRPC.
7+
*
8+
* HexagonRPC is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
#include <stdint.h>
23+
#include <libhexagonrpc/hexagonrpc.h>
24+
25+
__thread uint32_t chre_slpi;
26+
27+
struct hrpc_method_def_interp4 chre_slpi_start_thread_def = {
28+
.msg_id = 0,
29+
.n_args = 0,
30+
.args = NULL,
31+
.n_inner_types = 0,
32+
.inner_types = NULL,
33+
};
34+
35+
struct hrpc_method_def_interp4 chre_slpi_wait_on_thread_exit_def = {
36+
.msg_id = 1,
37+
.n_args = 0,
38+
.args = NULL,
39+
.n_inner_types = 0,
40+
.inner_types = NULL,
41+
};

chrecd/interfaces/chre_slpi.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Context Hub Runtime Environment interface - API
3+
*
4+
* Copyright (C) 2025 HexagonRPC Contributors
5+
*
6+
* This file is part of HexagonRPC.
7+
*
8+
* HexagonRPC is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
#ifndef INTERFACE_CHRE_SLPI_H
23+
#define INTERFACE_CHRE_SLPI_H
24+
25+
#include <stdint.h>
26+
#include <libhexagonrpc/hexagonrpc.h>
27+
#include <libhexagonrpc/session.h>
28+
29+
extern __thread uint32_t chre_slpi;
30+
static inline int hrpc_open_chre_slpi(size_t n_err, char *err)
31+
{
32+
return hexagonrpc_open("chre_slpi",
33+
&chre_slpi,
34+
n_err, err);
35+
}
36+
37+
extern struct hrpc_method_def_interp4 chre_slpi_start_thread_def;
38+
static inline int chre_slpi_start_thread()
39+
{
40+
return hexagonrpc(&chre_slpi_start_thread_def,
41+
hexagonrpc_fd, chre_slpi);
42+
}
43+
44+
extern struct hrpc_method_def_interp4 chre_slpi_wait_on_thread_exit_def;
45+
static inline int chre_slpi_wait_on_thread_exit()
46+
{
47+
return hexagonrpc(&chre_slpi_wait_on_thread_exit_def,
48+
hexagonrpc_fd, chre_slpi);
49+
}
50+
51+
52+
#endif /* INTERFACE_CHRE_SLPI_H */

chrecd/main.c

Lines changed: 12 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -20,105 +20,39 @@
2020
*/
2121

2222
#include <errno.h>
23-
#include <libhexagonrpc/fastrpc.h>
24-
#include <libhexagonrpc/interfaces/remotectl.def>
23+
#include <libhexagonrpc/hexagonrpc.h>
24+
#include <libhexagonrpc/interfaces/remotectl.h>
2525
#include <libhexagonrpc/session.h>
2626
#include <stdio.h>
2727
#include <stdlib.h>
2828
#include <string.h>
2929

30-
#include "interfaces/chre_slpi.def"
30+
#include "interfaces/chre_slpi.h"
3131

32-
/* TODO move these to libhexagonrpc since most clients use them */
33-
static int remotectl_open(int fd, char *name, struct fastrpc_context **ctx, void (*err_cb)(const char *err))
32+
int main(void)
3433
{
35-
uint32_t handle;
36-
int32_t dlret;
3734
char err[256];
38-
int ret;
39-
40-
ret = fastrpc2(&remotectl_open_def, fd, REMOTECTL_HANDLE,
41-
strlen(name) + 1, name,
42-
&handle,
43-
&dlret,
44-
256, err);
45-
46-
if (ret == -1) {
47-
err_cb(strerror(errno));
48-
return ret;
49-
}
50-
51-
if (dlret == -5) {
52-
err_cb(err);
53-
return dlret;
54-
}
55-
56-
*ctx = fastrpc_create_context(fd, handle);
57-
58-
return ret;
59-
}
60-
61-
static int remotectl_close(struct fastrpc_context *ctx, void (*err_cb)(const char *err))
62-
{
63-
uint32_t dlret;
64-
char err[256];
65-
int ret;
66-
67-
ret = fastrpc2(&remotectl_close_def, ctx->fd, REMOTECTL_HANDLE,
68-
ctx->handle,
69-
&dlret,
70-
256, err);
71-
72-
if (ret == -1) {
73-
err_cb(strerror(errno));
74-
return ret;
75-
}
76-
77-
fastrpc_destroy_context(ctx);
78-
79-
return ret;
80-
}
81-
82-
static void remotectl_err(const char *err)
83-
{
84-
fprintf(stderr, "Could not remotectl: %s\n", err);
85-
}
86-
87-
static int chre_slpi_start_thread(struct fastrpc_context *ctx)
88-
{
89-
return fastrpc(&chre_slpi_start_thread_def, ctx);
90-
}
91-
92-
static int chre_slpi_wait_on_thread_exit(struct fastrpc_context *ctx)
93-
{
94-
return fastrpc(&chre_slpi_wait_on_thread_exit_def, ctx);
95-
}
96-
97-
int main()
98-
{
99-
struct fastrpc_context *ctx;
10035
int fd, ret;
10136

10237
fd = hexagonrpc_fd_from_env();
10338
if (fd == -1)
10439
return 1;
10540

106-
ret = remotectl_open(fd, "chre_slpi", &ctx, remotectl_err);
107-
if (ret)
41+
ret = hrpc_open_chre_slpi(256, err);
42+
if (ret) {
43+
fprintf(stderr, "Could not open CHRE: %s\n", err);
10844
return 1;
45+
}
10946

110-
ret = chre_slpi_start_thread(ctx);
47+
ret = chre_slpi_start_thread();
11148
if (ret) {
11249
fprintf(stderr, "Could not start CHRE\n");
113-
goto err;
50+
return 1;
11451
}
11552

116-
ret = chre_slpi_wait_on_thread_exit(ctx);
53+
ret = chre_slpi_wait_on_thread_exit();
11754
if (ret) {
11855
fprintf(stderr, "Could not wait for CHRE thread\n");
119-
goto err;
56+
return 1;
12057
}
121-
122-
err:
123-
remotectl_close(ctx, remotectl_err);
12458
}

chrecd/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
executable('chrecd',
2-
'interfaces.c',
2+
'interfaces/chre_slpi.c',
33
'main.c',
44
c_args : cflags,
55
include_directories : include,

hexagonrpcd/apps_mem.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
#include <stdio.h>
2424
#include <stdlib.h>
2525
#include <string.h>
26+
#include <libhexagonrpc/error.h>
2627
#include <misc/fastrpc.h>
2728
#include <sys/ioctl.h>
2829

29-
#include "aee_error.h"
3030
#include "apps_mem.h"
31-
#include "interfaces/apps_mem.def"
31+
#include "interfaces/apps_mem.h"
3232
#include "listener.h"
3333

3434
// See fastrpc.git/src/apps_mem_imp.c
@@ -71,11 +71,9 @@ static uint32_t apps_mem_request_map64(void *data,
7171
mmap.size = first_in->len;
7272

7373
ret = ioctl(ctx->fd, FASTRPC_IOCTL_MMAP, &mmap);
74-
if (ret == -1) {
75-
perror("Memory map failed");
76-
return AEE_EFAILED;
77-
} else if (ret) {
78-
fprintf(stderr, "Memory map failed: %s\n", aee_strerror[ret]);
74+
if (ret) {
75+
fprintf(stderr, "Memory map failed: %s\n",
76+
hexagonrpc_strerror(ret));
7977
return ret;
8078
}
8179

hexagonrpcd/apps_std.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#include <sys/stat.h>
2828
#include <unistd.h>
2929

30-
#include "interfaces/apps_std.def"
3130
#include "hexagonfs.h"
31+
#include "interfaces/apps_std.h"
3232
#include "iobuffer.h"
3333
#include "listener.h"
3434

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* FastRPC reverse tunnel registration interface - method definitions
3+
*
4+
* Copyright (C) 2025 HexagonRPC Contributors
5+
*
6+
* This file is part of HexagonRPC.
7+
*
8+
* HexagonRPC is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
#include <stdint.h>
23+
#include <libhexagonrpc/hexagonrpc.h>
24+
25+
__thread uint32_t adsp_default_listener;
26+
27+
struct hrpc_method_def_interp4 adsp_default_listener_register_def = {
28+
.msg_id = 0,
29+
.n_args = 0,
30+
.args = NULL,
31+
.n_inner_types = 0,
32+
.inner_types = NULL,
33+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* FastRPC reverse tunnel registration interface - API
3+
*
4+
* Copyright (C) 2025 HexagonRPC Contributors
5+
*
6+
* This file is part of HexagonRPC.
7+
*
8+
* HexagonRPC is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
#ifndef INTERFACE_ADSP_DEFAULT_LISTENER_H
23+
#define INTERFACE_ADSP_DEFAULT_LISTENER_H
24+
25+
#include <stddef.h>
26+
#include <stdint.h>
27+
#include <libhexagonrpc/hexagonrpc.h>
28+
#include <libhexagonrpc/session.h>
29+
30+
extern __thread uint32_t adsp_default_listener;
31+
static inline int hrpc_open_adsp_default_listener(size_t n_err, char *err)
32+
{
33+
return hexagonrpc_open("adsp_default_listener",
34+
&adsp_default_listener,
35+
n_err, err);
36+
}
37+
38+
extern struct hrpc_method_def_interp4 adsp_default_listener_register_def;
39+
static inline int adsp_default_listener_register(void)
40+
{
41+
return hexagonrpc(&adsp_default_listener_register_def,
42+
hexagonrpc_fd, adsp_default_listener);
43+
}
44+
45+
#endif /* INTERFACE_ADSP_DEFAULT_LISTENER_H */
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* FastRPC reverse tunnel main interface - method definitions
3+
*
4+
* Copyright (C) 2025 HexagonRPC Contributors
5+
*
6+
* This file is part of HexagonRPC.
7+
*
8+
* HexagonRPC is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
#include <stdint.h>
23+
#include <libhexagonrpc/hexagonrpc.h>
24+
25+
struct hrpc_method_def_interp4 adsp_listener_init2_def = {
26+
.msg_id = 3,
27+
.n_args = 0,
28+
.args = NULL,
29+
.n_inner_types = 0,
30+
.inner_types = NULL,
31+
};
32+
33+
struct hrpc_arg_def_interp4 adsp_listener_next2_args[] = {
34+
{ HRPC_ARG_WORD, sizeof(uint32_t) },
35+
{ HRPC_ARG_WORD, sizeof(uint32_t) },
36+
{ HRPC_ARG_BLOB_SEQ, sizeof(char) },
37+
{ HRPC_ARG_OUT_BLOB, sizeof(uint32_t) },
38+
{ HRPC_ARG_OUT_BLOB, sizeof(uint32_t) },
39+
{ HRPC_ARG_OUT_BLOB, sizeof(uint32_t) },
40+
{ HRPC_ARG_OUT_BLOB, sizeof(uint32_t) },
41+
{ HRPC_ARG_OUT_BLOB_SEQ, sizeof(char) },
42+
};
43+
44+
struct hrpc_method_def_interp4 adsp_listener_next2_def = {
45+
.msg_id = 4,
46+
.n_args = HRPC_ARRAY_SIZE(adsp_listener_next2_args),
47+
.args = adsp_listener_next2_args,
48+
.n_inner_types = 0,
49+
.inner_types = NULL,
50+
};

0 commit comments

Comments
 (0)