The hexagonrpc function is getting very complex and deserves its own
unit test. Add a unit test for the hexagonrpc function.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The iobuffer decoder depends on REMOTE_SCALARS_INBUFS to know the number
of encoded input buffers without knowing the exact length of the encoded
input. Depend on the new hexagonrpc header which is being switched to.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
Both the hexagonfs and iobuffer tests need malloc and free. The iobuffer
test also needs REMOTE_SCALARS_MAKE. Include stdlib directly and include
the new libhexagonrpc header file.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
With the remote method definitions converted to interp4, the interp2
definitions are no longer needed. Replace the interp2 definitions with
the interp4 definitions recently added.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the chre_slpi interface to interp4, split it into a header
and source file, and update the users.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the adsp_listener interface to interp4, split it into a
header and source file, and update the users.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the apps_mem interface to interp4, split it into a header
and source file, and add the new definitions to the implementation.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the chre_slpi interface to interp4, split it into a header
and source file, and add the new definitions to the implementation.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the chre_slpi interface to interp4, split it into a header
and source file, and update the users.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the remotectl interface to interp4, split it into a header
and source file, and update the users.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
To use interp4 method definitions for everything, the reverse tunnel
needs to be updated to understand them. Add support for the new method
definitions, preferring them if present.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The FastRPC peer can encode a 32-bit size for a variable-length
sequence. The members of the sequence can have a size more than 1,
potentially using more than 32 bits. Expand the buffer size to a size_t.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The handle API is a high-level interface that puts all error messages in
the same buffer. Use the handle API to open and close the chre_slpi
remote interface for code deduplication.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The handle API is a high-level interface that puts all error messages in
the same buffer. Use the handle API to open and close the
adsp_default_listener remote interface.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The code for opening and closing a remote interface with an error is
duplicated in hexagonrpcd and chrecd. Like the remotectl interface
itself, the error handling is useful for most FastRPC applications. Add
a new API for opening and closing remote interfaces with error checking.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
The current method definition format has a few issues. There is no way
to represent `apps_std_mkdir(in string dir, in long long mode)` because
it has a sequence before a fixed-length argument. The fixed-length
arguments are passed in 4-byte units, making large fixed-length arrays
awkward. Sequences of sequences cannot be represented.
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.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
When there are more than 31 methods in a remote interface, an extended
method ID is added to the primary input buffer when the ID is greater
than 30. Select the method from the primary input buffer when the ID is
greater than 30 in the reverse tunnel.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
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.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
No breaking changes
New features:
- systemd unit files
- Android service files and Soong build files
- print access mode in apps_std_fopen_with_env
- run tests in CI and add .editorconfig
- print more detailed error when amount of I/O buffers don't match
definition
Fixes:
- convert to little endian for I/O buffer coding
EditorConfig is a file format and collection of text editor plugins for
maintaining consistent coding styles between different editors and IDEs.
Add a config for hexagonrpc with the preferred indentation style, and
some other settings.
Signed-off-by: Luca Weiss <luca.weiss@fairphone.com>
Make sure that the message is useful and doesn't just print a hex number
like "1f050100".
"Unexpected buffer count for method 31: 1f050100 (in: 5 vs 2, out: 1 vs 1)"
is a much more descriptive and helpful error.
Signed-off-by: Luca Weiss <luca.weiss@fairphone.com>
This is good to print for completeness, and can be useful when extending
fopen to not just allow read operations.
Signed-off-by: Luca Weiss <luca.weiss@fairphone.com>
It is possible (albeit unusual) to boot a big-endian system on a
smartphone, and it's generally good to have portable code.
le32toh and htole32 are a glibc extension that is also implemented by
musl-libc, uclibc-ng, and bionic.
Signed-off-by: J. Neuschäfer <j.ne@posteo.net>
The tests don't require access to Hexagon hardware, they currently pass,
and running them will provide a better assurance against regressions.
Signed-off-by: J. Neuschäfer <j.ne@posteo.net>
This shouldn't be a requirement to compile anything else. Stop requiring
it for building anything, and assume the user just wants to compile the
main project.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
No breaking changes
New features:
- man page for hexagonrpcd
- support for FASTRPC_IOCTL_INIT_CREATE with fastrpc_shell_X
- apps_mem interface (mostly allocating memory for now)
- logic for hexagonfs root directory
- sscregistrygen tool to generate sensor registry
- Github CI (successful compilation only)
Fixes:
- Disabled verbose logging by default
- Documented the paths relative to the root directory
- Made apps_std_stat relative to ADSP libs directory
- Fixed unsigned/signed comparison in reverse tunnel
- Declared minimum meson version for meson.options
- Added soversion to the library build
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
Without this building fails with:
../git/hexagonrpcd/rpcd.c: In function 'start_reverse_tunnel':
../git/hexagonrpcd/rpcd.c:275:21: error: too many arguments to function 'fastrpc_apps_mem_init'; expected 0, have 1
275 | ifaces[2] = fastrpc_apps_mem_init(fd);
| ^~~~~~~~~~~~~~~~~~~~~ ~~
In file included from ../git/hexagonrpcd/rpcd.c:38:
../git/hexagonrpcd/apps_mem.h:27:27: note: declared here
27 | struct fastrpc_interface *fastrpc_apps_mem_init();
| ^~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
The project uses meson.options rather than meson_options.txt. Document
the minimum meson version that can be used to build the project.
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Fix warning / error reported by gcc:
../git/hexagonrpcd/listener.c:115:25: warning: comparison of integer expressions of different signedness: 'uint32_t' {aka 'unsigned int'} and 'int' [-Wsign-compare]
if (inbufs[0].s != 4 * (def->in_nums
^~
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
When loading a new skel file, the DSP may access a testsig.so file. This
calls apps_std_fopen_with_env which is relative to a specified
directory, but also apps_std_stat. Since the same "testsig.so"
path is accessed relative to ADSP_LIBRARY_PATH and to the current
working directory, infer that the current working directory should be
ADSP_LIBRARY_PATH.
The files shouldn't be installed right in /usr/share/qcom except for
testing. Rather, they should be installed in some device-specific
directory to make packaging easier on some distros. Document the paths
relative to the root directory for served files.
The absolute paths shouldn't be installed right in /usr/share/qcom
except for testing. Document the modifiable directory where served files
are retrieved from and the convention of where this directory should be
located.
Link: https://gitlab.com/flamingradian/sensh/-/issues/1
Verbose logging can be useful when something goes wrong, but HexagonRPCD
already works well on some devices. Disable verbose logging by default.
Reported by Adrian on the SDM845 Mainline Matrix channel.
Fixes: 30fa49eb20 ("build: add hexagonrpcd_verbose option")
The data in the directory entry structure is meant to be used in opening
a file. It should not change during the program.
For the virtual directory, the pointer to constant data must be wrapped
because the data for the open file is not constant.
There is extra debug logging in the code which can be activated by
`meson configure build -Dc_args=-DHEXAGONRPC_VERBOSE`. This may be
difficult to trigger, since it requires -D twice in the same argument.
Add the hexagonrpcd_verbose option to make it easier to configure the
extra logging.
This can be activated with `-Dhexagonrpcd_verbose=true` and deactivated
with `-Dhexagonrpcd_verbose=false`.
Most subdirectories in this project have all, pedantic, and some extra
warnings enabled. Set this for tests as well, as there is no real
justification otherwise.
Signed character arrays can overflow when specifying values greater than
127. The actual data is not affected, but this can cause compiler
warnings. Use unsigned character arrays so the compiler does not
complain about overflows.
This file seems to implicitly return 0 when everything is successful,
but this is unclear when reading it. Explicitly return zero when all
tests are successful.
This variable represents the subdirectory in the dsp/ directory where
libraries should be searched. This is the argument to the optional `-d`
and is used when creating the filesystem. Initialize it to an empty
string so HexagonFS searches in /usr/share/qcom/dsp/ by default.
The FastRPC implementation is loosely related to the sensor shell. It is
useful to provide interfaces over FastRPC for sensor DSP firmware, and
enables the sensor shell to provide most physical sensors. However, the
FastRPC implementation has no meaningful connection with the sensor
shell in terms of code. Move the FastRPC implementation to the project
root to make it more intuitive to install and use and to separate it
from a distinct project.
The CHRE client is not part of the core functionality of the daemon. The
client is only meant to run on sensorspd, and should not always run,
such as on non-Android or on rootpd. It should not be stuck in the file
with the program's entry point, as it needs to do more than simply
starting CHRE, like starting any useful nanoapps. Move it into a new
directory as a client that can use the same session as the daemon that
listens for remote method calls to the Application Processor, so the
session can make calls back to fetch files.
Also modify the calling conventions for starting the reverse tunnel,
since the calling conventions are not limited to a single pointer.
The HexagonRPCD daemon has support for sharing sessions with other
programs by executing them with the HEXAGONRPC_FD environment variable
set. Add a library function to obtain the file descriptor used in this
session for FastRPC communication.
The Linux kernel FastRPC driver creates a unique session for every
process that opens a file descriptor. Session sharing allows the sharing
of a reverse tunnel across clients that need it. Add support for
managing the session for clients.
The argument to -p is a path to any executable file, such as /bin/sh.
The file descriptor to the FastRPC device node is in the HEXAGONRPC_FD
environment variable.
Remove the brackets around the -f option which imply that it is
optional. The default value is a NULL pointer.
FastRPC is not specialized to serving files to the DSPs and can do other
things such as logging and profiling, pending discovery. Change the
description of the program accordingly.
Referring to a "FastRPC node" is a bit vague and misses the detail that
the program is expecting a path to a file (a device node). Refer to the
file as a FastRPC device node so the user can intuitively look for what
the program wants.
The letter in the -R option was seemingly chosen arbitrarily. Add the
word which it originated from ("root") to make it memorable.
The INIT_ATTACH and INIT_ATTACH_SNS terms have no meaning in the usage
text. They are terms of jargon originating in the userspace API for the
Linux kernel driver, as abbreviations of FASTRPC_IOCTL_INIT_ATTACH and
FASTRPC_IOCTL_INIT_ATTACH_SNS. It is unclear what the difference is
between the two, and SNS is ambiguous with no clear connection to
sensors (did Qualcomm design some DSP communication protocol around a
Social Networking Service?). Instead of deriving terms used to inform
the driver how to interact with the DSP, use the name of the
PD ("sensorspd") and describe the effective interaction with the DSP.
If the file name for the FastRPC device node is a NULL pointer, then the
error message always prints out a NULL pointer, made redundant by the
word "invalid". An unspecified device node is an error made by the user,
and the usage text should be given to the user instead of an internal
diagnosis of invalid usage.
This is useful for most programs using FastRPC, so it does not make
sense to copy the interface every time. Move it to libhexagonrpc, even
though it may not be strictly necessary to communicate over FastRPC,
since it is common.
Warnings on unused variables or functions can be fixed by removing the
unnecessary variable or function. Unused parameters are a regular
occurrence, and cannot be removed. Warnings about these may be useful
for new internal APIs with long development histories, but clutter any
build logs with meaningless warnings about unused parameters when
defining functions to be used with existing APIs, such as the reverse
tunnel API. Suppress these warnings to bring any more meaningful issues
to attention.
Despite the modularity of the FastRPC implementation, there are no unit
tests. This makes it unpredictable when the implementation encounters an
unlikely scenario, such as when reading uninitialized memory that is
non-zero, or when allocating zero bytes of memory. Add a unit test for
the I/O buffer encoder and decoder so there can be more confidence in
its expected operation.
This does not test edge cases in the malloc() function, such as
allocating zero bytes or failures.
When a pathname navigates to the parent directory via the special "../"
name, the current directory may be assigned a numeric file descriptor.
With a numeric file descriptor, the current directory can still be
referenced, and should not be closed. Only close the directory if it is
not assigned.
The file descriptor for the root directory is required for file
operations. Without the root directory open, opening or getting stats of
a file always fails. Currently, the apps_std methods check if the root
directory is open every time they are called. Fail to initialize if the
root directory cannot be opened to allow the simplification of remote
methods accepting a path name.
The path name is already NULL-terminated by the caller and does not need
to be copied to a larger buffer to add more NULL termination. Allocating
an extra buffer can cause an unnecessary crash or failure when out of
memory. Do not copy the path name. Instead, check that the path name is
NULL-terminated by the caller.
Normally, the CHRE performs a full configuration on streaming sensors
with a stream type of zero. This made it seem like a simple enable would
not properly activate sensors with this stream type, but it is possible
to use the watch command on streaming sensors. Remove this statement
which may be misleading.
The decoding error was added in the previous commit with the -1 return
value. Propagate it as a fatal error (-1).
Also remove a newline in an existing perror statement, where the error
message would be split between lines.
The decoder dynamically allocates memory while decoding so the decoded
buffers have the correct size. This can fail, often when the memory runs
out. Propagate any errors from malloc() and do not attempt to decode the
buffer.
There is no real reason for the position attributes to be signed. It
does not make sense to have a negative offset in the current input
buffer, negative alignment, or negative offset in the size of the
current input buffer. A negative number of input buffers also makes no
sense. Reorganize the decoder context struct and the I/O buffer struct
so offsets and maximums are together, nothing has the unnecessary
capability of being negative, and the sizes are not wider than possible
in the format.
Also include the definition for uint32_t.
Also update the error message format in listener.c to read a 32-bit
integer.
When the decoding continues from a misaligned part of the buffer, the
decoder attempts to skip some of the buffer to realign itself, even if
it is not the beginning of the buffer. To allow the decoding of an input
with a size indivisible by 8, only consume the alignment at the
beginning of an input buffer.
The bug outlined here does not happen in practice because the size of
the encoded input is hardcoded to 256 in listener.c.
Fixes: 77f855ec84 ("fastrpc: decode input buffers")
According to malloc(3p), a call to malloc with a size of zero can result
in a NULL pointer. If this occurs, the initialized decoding context is
still valid and the program may proceed without failing. Allow a NULL
pointer when there are zero input buffers to be processed.
Fixes: 77f855ec84 ("fastrpc: decode input buffers")
The amount of output buffers needed should be computed before the check,
otherwise it checks an uninitialized value. Initialize it first so that
the zero check works as intended.
Fixes: 9ea9bed77b ("fastrpc: hexagonrpcd: listener: do not attempt to allocate zero outbufs")
The mapped_or_empty file implementation uses NULL to denote when an
empty directory should be in place of a non-existent file. Changing the
pointer to the output has no effect. Change the implementation data to a
NULL pointer so empty directories function properly.
The is_assigned attribute should only be true when it is assigned a
numeric ID, otherwise it will not be closed. The from_dirent operations
in the implementations of a file type do not use the calloc() function,
so the is_assigned attribute is uninitialized. Initialize it to zero so
the open file can be closed when requested.
The malloc(3p) manual page states that an implementation may choose to
return a non-NULL pointer when the size is zero. This function assumes
that there is an element in the array if the pointer is not NULL. When
the size is zero, skip the allocation and return NULL.
The qmic utility is rarely packaged in mainstream distributions, making
it inconvenient to set up a working build environment. Add generated
source files to enable compilation without qmic installed.
2023-12-04 19:49:59 -05:00
94 changed files with 4456 additions and 2627 deletions
* FastRPC interface list for building method definitions
*
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
* Sensh is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define HEXAGONRPC_BUILD_METHOD_DEFINITIONS 1
#include"interfaces/adsp_default_listener.def"
#include"interfaces/apps_std.def"
#include"interfaces/adsp_listener.def"
#include"interfaces/chre_slpi.def"
#include"interfaces/remotectl.def"
Loaded 20 of 94 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.