161 Commits

Author SHA1 Message Date
Richard Acayan
b4db2118cb fastrpc: add iobuffer unit test
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.
v0.2.2
2023-12-27 18:23:41 -05:00
Richard Acayan
ecd901bc48 fastrpc: hexagonrpcd: hexagonfs: only close popped dir if not assigned
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.
2023-12-26 19:47:25 -05:00
Richard Acayan
a31ec9caf9 fastrpc: hexagonrpcd: apps_std: do not initialize without root dir
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.
2023-12-26 19:47:04 -05:00
Richard Acayan
0156911ba4 fastrpc: hexagonrpcd: apps_std: do not copy path name in stat()
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.
2023-12-26 19:39:09 -05:00
Richard Acayan
c82b2da4eb fastrpc: hexagonrpcd: listener: remove fastrpc_listener_interfaces
This is a variable which was superseded by dynamically initialized
interfaces. Remove it.
2023-12-18 20:07:17 -05:00
Richard Acayan
cd314096a3 README: remove statement that watch command is invalid for stream type 0
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.
2023-12-18 19:48:40 -05:00
Richard Acayan
1162ccd84c fastrpc: hexagonrpcd: listener: propagate decoding error
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.
2023-12-12 19:10:25 -05:00
Richard Acayan
a56406c928 fastrpc: hexagonrpcd: iobuffer: propagate decoding allocation failure
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.
2023-12-12 19:08:12 -05:00
Richard Acayan
4054893648 fastrpc: hexagonrpcd: iobuffer: change types in decoder context
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.
2023-12-11 21:24:54 -05:00
Richard Acayan
d6c458bd17 fastrpc: hexagonrpcd: iobuffer: only align at beginning of inbuf
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")
2023-12-11 21:24:46 -05:00
Richard Acayan
753ebda39b fastrpc: hexagonrpcd: iobuffer: allow null pointer for zero inbufs
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")
2023-12-11 21:24:01 -05:00
Richard Acayan
1dc590d638 fastrpc: hexagonrpcd: listener: compute out_count before zero check
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")
2023-12-07 19:55:18 -05:00
Richard Acayan
f085f578e3 fastrpc: hexagonrpcd: do not close un-opened file
The device node has not been opened yet at this point. Directly return
without closing it.
2023-12-04 21:57:51 -05:00
Richard Acayan
0b4c7bffaf fastrpc: hexagonrpcd: hexagonfs: mapped: return NULL for empty dirs
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.
v0.2.1
2023-12-04 19:50:34 -05:00
Richard Acayan
00b5f80608 fastrpc: hexagonrpcd: hexagonfs: initialize is_assigned in from_dirent
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.
2023-12-04 19:50:24 -05:00
Richard Acayan
9ea9bed77b fastrpc: hexagonrpcd: listener: do not attempt to allocate zero outbufs
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.
2023-12-04 19:50:11 -05:00
Richard Acayan
23585daf67 qmi: add generated substitute
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
Richard Acayan
e0d6c2a7ac fastrpc: hexagonrpcd: hexagonfs: remove static root filesystem
The root filesystem is now dynamically constructed in rpcd_builder.c.
Remove this macro-generated filesystem as it is unused and generates a
warning.
v0.2.0
2023-11-27 18:53:31 -05:00
Richard Acayan
329f1ae841 fastrpc: hexagonrpcd: apps_std: remove unused variables
These variables went unused since the input buffer lengths were switched
to the sizes parsed by iobuffer.c, instead of the sizes in the primary
input argument. This makes it unnecessary at times to unpack the primary
input buffer, although the variables were being kept around to document
calling conventions. Remove the variables since they add unnecessary
warnings.

The calling conventions can still be found in the Android implementation
of FastRPC.
2023-11-27 18:53:31 -05:00
Richard Acayan
2358946095 fastrpc: hexagonrpcd: apps_std: include correct headers
This interface implementation no longer opens files directly, but sends
requests to hexagonfs. Hence, fcntl.h and dirent.h are no longer needed.
Also, it uses 32-bit integers from stdint.h.
2023-11-27 18:53:31 -05:00
Richard Acayan
06ef0b17a4 fastrpc: README: remove note about source code directory structure
This has been completed a long time ago.
2023-11-27 18:53:31 -05:00
Richard Acayan
d87d8ffc47 fastrpc: README: mention correct interface listings
The interfaces being created on the reverse tunnel are now dynamically
generated.
2023-11-27 18:53:31 -05:00
Richard Acayan
947f52d779 fastrpc: README: clarify REMOTE_SCALARS_MAKE
This macro is used to generate the 32-bit remote "scalars"/"sc"
argument. Correct the name and link to the definition.
2023-11-27 18:53:31 -05:00
Richard Acayan
4983830139 fastrpc: README: add more usage documentation
The data types for the ioctl wrapper are important, as it has variable
arguments. Document them.

Also mention terminology used in QAIC output to aid in understanding
this project in relation to existing FastRPC implementations.
2023-11-27 18:53:31 -05:00
Richard Acayan
5e04177155 fastrpc: README: document meson build system
The meson.build was added a while ago.
2023-11-27 18:52:44 -05:00