pax_global_header00006660000000000000000000000064146206063070014516gustar00rootroot0000000000000052 comment=b7eff23db1b11541d11175bd3f42bd4c85214baf hexagonrpc-0.3.2/000077500000000000000000000000001462060630700136565ustar00rootroot00000000000000hexagonrpc-0.3.2/COPYING000066400000000000000000001045151462060630700147170ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program 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 . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . hexagonrpc-0.3.2/README.md000066400000000000000000000127401462060630700151410ustar00rootroot00000000000000This directory contains a FastRPC ioctl wrapper and a reverse tunnel. FastRPC is used to communicate with the Context Hub Runtime Environment, a program on the DSP that manages sensors, and to serve files to remote processors. # Wrapper function The wrapper function is designed so that the ioctl arguments do not need to be constructed for each remote method. Instead, it accepts an open file descriptor, handle, method definition, and arguments to the remote method using `va_args`. This makes it relatively easy to add remote methods without the use of the QAIC interface compiler or a free software alternative. ## Installation You can build and install this project using meson: ~/sensh/fastrpc $ meson setup build ~/sensh/fastrpc $ ninja -C build ~/sensh/fastrpc # ninja -C build install ## Usage Making already-defined method calls is relatively straightforward, depending on the remote method that you're calling. You just need the function definition, an open file descriptor, the handle, and the arguments for it. uint32_t prev_ctx, prev_result, nested_outbufs_len; uint32_t ctx, nested_handle, nested_sc, nested_inbufs_len; uint32_t nested_inbufs_size; const void *nested_outbufs; void *nested_inbufs; int fd; ret = fastrpc2(&adsp_listener_next2_def, fd, ADSP_LISTENER_HANDLE, prev_ctx, prev_result, nested_outbufs_len, nested_outbufs, &ctx, &nested_handle, &nested_sc, &nested_inbufs_len, nested_inbufs_size, nested_inbufs); All inputs are specified before all outputs. Words in the first (called "prim", or primary in QAIC-generated code) input and output buffers go in the form of `uint32_t` arguments. Each buffer is accepted as a `uint32_t` length and a pointer. ### Creating function definitions Assuming you already have knowledge about the remote method to call, you must first write a function definition for it. A function definition is a struct with information on its method ID and the arguments it accepts. First, the method ID is taken from the first argument of the `REMOTE_SCALARS_MAKE()` macro or the second argument of the `REMOTE_SCALARS_MAKEX()` macro (defined [here](https://android.googlesource.com/platform/external/fastrpc/+/d6d6e3bba244e40e6043bd687f4cacf090a767b5/inc/remote.h#80)). Example: REMOTE_SCALARS_MAKE(4, 2, 2) has the method 4. Next, information on how many arguments it takes must be specified. There are four types of arguments: - 32-bit input words in the first input buffer, excluding lengths for the input and output buffers - 32-bit output words in the first output buffer - input buffers, excluding the first - output buffers, excluding the first To get the size of the first input and output buffers, a dump must be consulted, or the prim argument of generated C files: invoking via fastrpc, handle 3, method 4, 2 inbufs, 2 outbufs, 0 inhandles, 0 outhandles fastrpc argument 00000000FFFFFFFF0000000000000000 // 16 bytes, or 4 words fastrpc argument invoking via fastrpc, handle 5, method 4, 1 inbufs, 1 outbufs, 0 inhandles, 0 outhandles fastrpc return 91000000000000000002020029000000 // 16 bytes, or 4 words fastrpc return Since there are 2 input buffers excluding the first (these can have a variable size), 2 must be subtracted from the 4 input words. These will be provided by the wrapper as the sizes for the variable-length input and output buffers. Counting each of these will give the numbers needed for the function definition. A function definition looks like: const struct fastrpc_function_def_interp2 adsp_listener_next2_def = { .msg_id = 4, .in_nums = 2, .in_bufs = 1, .out_nums = 4, .out_bufs = 1, }; or: #define DEFINE_REMOTE_PROCEDURE(mid, name, \ innums, inbufs, \ outnums, outbufs) \ const struct fastrpc_function_def_interp2 name##_def = { \ .msg_id = mid, \ .in_nums = innums, \ .in_bufs = inbufs, \ .out_nums = outnums, \ .out_bufs = outbufs, \ }; DEFINE_REMOTE_PROCEDURE(4, adsp_listener_next2, 2, 1, 4, 1) # Reverse tunnel The reverse tunnel calls the `adsp_listener_next2` remote method to receive method calls for the Application Processor. Interfaces are initialized in the `start_reverse_tunnel` function, in hexagonrpcd/rpcd.c. ## HexagonFS The reverse tunnel's `apps_std` interface serves files to the remote processor. These files are searched for in: Physical file/dir Android file/dir /usr/share/qcom/acdb /vendor/etc/acdbdata /usr/share/qcom/dsp /vendor/dsp /usr/share/qcom/sensors/config /vendor/etc/sensors/config /usr/share/qcom/sensors/registry /mnt/vendor/persist/sensors/registry/registry /usr/share/qcom/sensors/sns_reg.conf /vendor/etc/sensors/sns_reg_config /usr/share/qcom/socinfo /sys/devices/soc0 These files and directories should be populated with files from your device's Android firmware. # Future plans Reverse tunnels are separated by the process that opens the file descriptor and cannot service requests from other processes that do not share the same file descriptor. There should be some daemon that opens the device and allows clients to send requests. FastRPC may be the way to offload work to the DSPs. When a FastRPC function call is made, the `_skel_invoke` function in a shared object named `lib_skel.so` is called on the DSP. Further investigation is needed to make a working build system for this. hexagonrpc-0.3.2/chrecd/000077500000000000000000000000001462060630700151065ustar00rootroot00000000000000hexagonrpc-0.3.2/chrecd/interfaces.c000066400000000000000000000015611462060630700174000ustar00rootroot00000000000000/* * 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 . */ #define HEXAGONRPC_BUILD_METHOD_DEFINITIONS 1 #include "interfaces/chre_slpi.def" hexagonrpc-0.3.2/chrecd/interfaces/000077500000000000000000000000001462060630700172315ustar00rootroot00000000000000hexagonrpc-0.3.2/chrecd/interfaces/chre_slpi.def000066400000000000000000000020631462060630700216620ustar00rootroot00000000000000/* * Context Hub Runtime Environment interface * * 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 . */ #ifndef INTERFACE_CHRE_SLPI_DEF #define INTERFACE_CHRE_SLPI_DEF #include HEXAGONRPC_DEFINE_REMOTE_METHOD(0, chre_slpi_start_thread, 0, 0, 0, 0) HEXAGONRPC_DEFINE_REMOTE_METHOD(1, chre_slpi_wait_on_thread_exit, 0, 0, 0, 0) #endif /* INTERFACE_CHRE_SLPI_DEF */ hexagonrpc-0.3.2/chrecd/main.c000066400000000000000000000053351462060630700162040ustar00rootroot00000000000000/* * CHRE client daemon entry point * * 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 . */ #include #include #include #include #include #include #include #include "interfaces/chre_slpi.def" /* TODO move these to libhexagonrpc since most clients use them */ static int remotectl_open(int fd, char *name, struct fastrpc_context **ctx, void (*err_cb)(const char *err)) { uint32_t handle; int32_t dlret; char err[256]; int ret; ret = fastrpc2(&remotectl_open_def, fd, REMOTECTL_HANDLE, strlen(name) + 1, name, &handle, &dlret, 256, err); if (ret == -1) { err_cb(strerror(errno)); return ret; } if (dlret == -5) { err_cb(err); return dlret; } *ctx = fastrpc_create_context(fd, handle); return ret; } static int remotectl_close(struct fastrpc_context *ctx, void (*err_cb)(const char *err)) { uint32_t dlret; char err[256]; int ret; ret = fastrpc2(&remotectl_close_def, ctx->fd, REMOTECTL_HANDLE, ctx->handle, &dlret, 256, err); if (ret == -1) { err_cb(strerror(errno)); return ret; } fastrpc_destroy_context(ctx); return ret; } static void remotectl_err(const char *err) { fprintf(stderr, "Could not remotectl: %s\n", err); } static int chre_slpi_start_thread(struct fastrpc_context *ctx) { return fastrpc(&chre_slpi_start_thread_def, ctx); } static int chre_slpi_wait_on_thread_exit(struct fastrpc_context *ctx) { return fastrpc(&chre_slpi_wait_on_thread_exit_def, ctx); } int main() { struct fastrpc_context *ctx; int fd, ret; fd = hexagonrpc_fd_from_env(); if (fd == -1) return 1; ret = remotectl_open(fd, "chre_slpi", &ctx, remotectl_err); if (ret) return 1; ret = chre_slpi_start_thread(ctx); if (ret) { fprintf(stderr, "Could not start CHRE\n"); goto err; } ret = chre_slpi_wait_on_thread_exit(ctx); if (ret) { fprintf(stderr, "Could not wait for CHRE thread\n"); goto err; } err: remotectl_close(ctx, remotectl_err); } hexagonrpc-0.3.2/chrecd/meson.build000066400000000000000000000002671462060630700172550ustar00rootroot00000000000000executable('chrecd', 'interfaces.c', 'main.c', c_args : cflags, include_directories : include, install : true, link_with : libhexagonrpc, install_dir : client_target, ) hexagonrpc-0.3.2/hexagonrpcd/000077500000000000000000000000001462060630700161605ustar00rootroot00000000000000hexagonrpc-0.3.2/hexagonrpcd/aee_error.c000066400000000000000000000062121462060630700202700ustar00rootroot00000000000000/* * Imported FastRPC error messages * * Copyright (c) 2019, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of The Linux Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ const char *aee_strerror[] = { "No error", "General failure", "Insufficient RAM", "Specified class unsupported", "Version not supported", "Object already loaded", "Unable to load object/applet", "Unable to unload object/applet", "Alarm is pending", "Invalid time", "NULL class object", "Invalid metric specified", "App/Component Expired", "Invalid state", "Invalid parameter", "Invalid URL scheme", "Invalid item", "Invalid format", "Incomplete item", "Insufficient flash", "API is not supported", "Privileges are insufficient for this operation", "Unable to find specified resource", "Non re-entrant API re-entered", "API called in wrong task context", "App/Module left memory allocated when released.", "Operation is already in progress", "ADS mutual authorization failed", "Need service programming", "bad memory pointer", "heap corruption", "Context (system, interface, etc.) is idle", "Context (system, interface, etc.) is busy", "Invalid subscriber ID", "No type detected/found", "Need more data/info", "ADS Capabilities do not match those required for phone", "App failed to close properly", "Destination buffer given is too small", "No such name, port, socket or service exists or is valid", "ACK pending on application", "Not an owner authorized to perform the operation", "Current item is invalid", "Not allowed to perform the operation", "Invalid handle", "Out of handles", "Waitable call is interrupted", "No more items available -- reached end", "A CPU exception occurred", "Cannot change read-only object or parameter", }; hexagonrpc-0.3.2/hexagonrpcd/aee_error.h000066400000000000000000000060011462060630700202710ustar00rootroot00000000000000/* * Imported FastRPC error numbers * * Copyright (c) 2019, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of The Linux Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef AEE_STRERROR_H #define AEE_STRERROR_H #define AEE_SUCCESS 0 #define AEE_EFAILED 1 #define AEE_ENOMEMORY 2 #define AEE_ECLASSNOTSUPPORT 3 #define AEE_EVERSIONNOTSUPPORT 4 #define AEE_EALREADYLOADED 5 #define AEE_EUNABLETOLOAD 6 #define AEE_EUNABLETOUNLOAD 7 #define AEE_EALARMPENDING 8 #define AEE_EINVALIDTIME 9 #define AEE_EBADCLASS 10 #define AEE_EBADMETRIC 11 #define AEE_EEXPIRED 12 #define AEE_EBADSTATE 13 #define AEE_EBADPARM 14 #define AEE_ESCHEMENOTSUPPORTED 15 #define AEE_EBADITEM 16 #define AEE_EINVALIDFORMAT 17 #define AEE_EINCOMPLETEITEM 18 #define AEE_ENOPERSISTMEMORY 19 #define AEE_EUNSUPPORTED 20 #define AEE_EPRIVLEVEL 21 #define AEE_ERESOURCENOTFOUND 22 #define AEE_EREENTERED 23 #define AEE_EBADTASK 24 #define AEE_EALLOCATED 25 #define AEE_EALREADY 26 #define AEE_EADSAUTHBAD 27 #define AEE_ENEEDSERVICEPROG 28 #define AEE_EMEMPTR 29 #define AEE_EHEAP 30 #define AEE_EIDLE 31 #define AEE_EITEMBUSY 32 #define AEE_EBADSID 33 #define AEE_ENOTYPE 34 #define AEE_ENEEDMORE 35 #define AEE_EADSCAPS 36 #define AEE_EBADSHUTDOWN 37 #define AEE_EBUFFERTOOSMALL 38 #define AEE_ENOSUCH 39 #define AEE_EACKPENDING 40 #define AEE_ENOTOWNER 41 #define AEE_EINVALIDITEM 42 #define AEE_ENOTALLOWED 43 #define AEE_EBADHANDLE 44 #define AEE_EOUTOFHANDLES 45 #define AEE_EINTERRUPTED 46 #define AEE_ENOMORE 47 #define AEE_ECPUEXCEPTION 48 #define AEE_EREADONLY 49 extern const char *aee_strerror[]; #endif hexagonrpc-0.3.2/hexagonrpcd/apps_std.c000066400000000000000000000255551462060630700201550ustar00rootroot00000000000000/* * FastRPC operating system interface implementation * * 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 . */ #include #include #include #include #include #include #include "aee_error.h" #include "interfaces/apps_std.def" #include "hexagonfs.h" #include "iobuffer.h" #include "listener.h" struct apps_std_ctx { int rootfd; int adsp_avs_cfg_dirfd; int adsp_library_dirfd; struct hexagonfs_fd *fds[HEXAGONFS_MAX_FD]; }; static const int apps_std_whence_table[] = { SEEK_SET, SEEK_CUR, SEEK_END, }; /* * This is a placeholder function used to complete any I/O operations. * File descriptors do not have a flush operation because their reads and * writes are blocking. */ static uint32_t apps_std_fflush(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs) { #ifdef HEXAGONRPC_VERBOSE uint32_t *fd = inbufs[0].p; printf("ignore fflush(%u)\n", *fd); #endif memset(outbufs[0].p, 0, outbufs[0].s); return 0; } static uint32_t apps_std_fclose(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs) { struct apps_std_ctx *ctx = data; const uint32_t *first_in = inbufs[0].p; int ret; ret = hexagonfs_close(ctx->fds, *first_in); if (ret) { fprintf(stderr, "Could not close: %s\n", strerror(-ret)); return AEE_EFAILED; } #ifdef HEXAGONRPC_VERBOSE printf("close(%u)\n", *first_in); #endif return 0; } static uint32_t apps_std_fread(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs) { struct apps_std_ctx *ctx = data; const struct { uint32_t fd; uint32_t buf_size; } *first_in = inbufs[0].p; struct { uint32_t written; uint32_t is_eof; } *first_out = outbufs[0].p; ssize_t ret; ret = hexagonfs_read(ctx->fds, first_in->fd, first_in->buf_size, outbufs[1].p); if (ret < 0) { fprintf(stderr, "Could not read file: %s\n", strerror(-ret)); return AEE_EFAILED; } #ifdef HEXAGONRPC_VERBOSE printf("read(%u, %u) -> %ld\n", first_in->fd, first_in->buf_size, ret); #endif first_out->written = ret; first_out->is_eof = first_out->written < first_in->buf_size; return 0; } static uint32_t apps_std_fseek(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs) { struct apps_std_ctx *ctx = data; const struct { uint32_t fd; uint32_t pos; uint32_t whence; } *first_in = inbufs[0].p; int ret; int whence; whence = apps_std_whence_table[first_in->whence]; ret = hexagonfs_lseek(ctx->fds, first_in->fd, first_in->pos, whence); if (ret) { fprintf(stderr, "Could not seek stream: %s\n", strerror(-ret)); return AEE_EFAILED; } #ifdef HEXAGONRPC_VERBOSE printf("lseek(%u, %d, %d)\n", first_in->fd, first_in->pos, first_in->whence); #endif return 0; } static uint32_t apps_std_fopen_with_env(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs) { struct apps_std_ctx *ctx = data; uint32_t *out = outbufs[0].p; char rw_mode; int dirfd, fd; // The name and environment variable must also be NULL-terminated if (((const char *) inbufs[1].p)[inbufs[1].s - 1] != 0 || ((const char *) inbufs[3].p)[inbufs[3].s - 1] != 0 || ((const char *) inbufs[4].p)[inbufs[4].s - 1] != 0) return AEE_EBADPARM; rw_mode = ((const char *) inbufs[4].p)[0]; if (rw_mode == 'w' || rw_mode == 'a') { fprintf(stderr, "Tried to open %s for writing\n", (const char *) inbufs[3].p); return AEE_EUNSUPPORTED; } if (!strcmp(inbufs[1].p, "ADSP_LIBRARY_PATH")) { dirfd = ctx->adsp_library_dirfd; } else if (!strcmp(inbufs[1].p, "ADSP_AVS_CFG_PATH")) { dirfd = ctx->adsp_avs_cfg_dirfd; } else { fprintf(stderr, "Unknown search directory %s\n", (const char *) inbufs[1].p); return AEE_EBADPARM; } if (dirfd < 0) { fprintf(stderr, "Could not open virtual %s: %s\n", (const char *) inbufs[1].p, strerror(-dirfd)); return AEE_EFAILED; } fd = hexagonfs_openat(ctx->fds, ctx->rootfd, dirfd, inbufs[3].p); if (fd < 0) { fprintf(stderr, "Could not open %s: %s\n", (const char *) inbufs[3].p, strerror(errno)); return AEE_EFAILED; } #ifdef HEXAGONRPC_VERBOSE printf("openat($%s, %s) -> %d\n", (const char *) inbufs[1].p, (const char *) inbufs[3].p, fd); #endif *out = fd; return 0; } static uint32_t apps_std_opendir(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs) { struct apps_std_ctx *ctx = data; uint64_t *dir_out = outbufs[0].p; int ret; // The name must be NULL-terminated if (((const char *) inbufs[1].p)[inbufs[1].s - 1] != 0) return AEE_EBADPARM; ret = hexagonfs_openat(ctx->fds, ctx->rootfd, ctx->rootfd, inbufs[1].p); if (ret < 0) { fprintf(stderr, "Could not open %s: %s\n", (const char *) inbufs[1].p, strerror(-ret)); return AEE_EFAILED; } #ifdef HEXAGONRPC_VERBOSE printf("opendir(%s) -> %d\n", (const char *) inbufs[1].p, ret); #endif *dir_out = ret; return 0; } static uint32_t apps_std_closedir(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs) { struct apps_std_ctx *ctx = data; const uint64_t *dir = inbufs[0].p; int ret; ret = hexagonfs_close(ctx->fds, *dir); if (ret) return AEE_EFAILED; #ifdef HEXAGONRPC_VERBOSE printf("closedir(%ld)\n", *dir); #endif return 0; } static uint32_t apps_std_readdir(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs) { struct apps_std_ctx *ctx = data; const uint64_t *dir = inbufs[0].p; struct { uint32_t inode; char name[255]; uint32_t is_eof; } *first_out = outbufs[0].p; int ret; ret = hexagonfs_readdir(ctx->fds, *dir, 255, first_out->name); if (ret < 0) { fprintf(stderr, "Could not read from directory: %s\n", strerror(-ret)); return AEE_EFAILED; } #ifdef HEXAGONRPC_VERBOSE printf("readdir(%ld) -> %s\n", *dir, first_out->name); #endif first_out->inode = 0; first_out->is_eof = (*first_out->name == '\0'); return 0; } static uint32_t apps_std_stat(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs) { struct apps_std_ctx *ctx = data; struct { uint64_t tsz; // Unknown purpose uint64_t dev; uint64_t ino; uint32_t mode; uint32_t nlink; uint64_t rdev; uint64_t size; int64_t atime; int64_t atimensec; int64_t mtime; int64_t mtimensec; int64_t ctime; int64_t ctimensec; } *first_out = outbufs[0].p; const char *pathname = inbufs[1].p; struct stat stats; int fd, ret; if (((const char *) inbufs[1].p)[inbufs[1].s - 1] != 0) return AEE_EBADPARM; fd = hexagonfs_openat(ctx->fds, ctx->rootfd, ctx->rootfd, pathname); if (fd < 0) { fprintf(stderr, "Could not open %s: %s\n", pathname, strerror(-fd)); return AEE_EFAILED; } ret = hexagonfs_fstat(ctx->fds, fd, &stats); if (ret) { fprintf(stderr, "Could not stat %s: %s\n", pathname, strerror(-fd)); return AEE_EFAILED; } hexagonfs_close(ctx->fds, fd); #ifdef HEXAGONRPC_VERBOSE printf("stat(%s)\n", pathname); #endif first_out->tsz = 0; first_out->dev = stats.st_dev; first_out->ino = stats.st_ino; first_out->mode = stats.st_mode; first_out->nlink = stats.st_nlink; first_out->rdev = stats.st_rdev; first_out->size = stats.st_size; first_out->atime = (int64_t) stats.st_atim.tv_sec; first_out->atimensec = (int64_t) stats.st_atim.tv_nsec; first_out->mtime = (int64_t) stats.st_mtim.tv_sec; first_out->mtimensec = (int64_t) stats.st_mtim.tv_nsec; first_out->ctime = (int64_t) stats.st_ctim.tv_nsec; first_out->ctimensec = (int64_t) stats.st_ctim.tv_nsec; return 0; } struct fastrpc_interface *fastrpc_apps_std_init(struct hexagonfs_dirent *root) { struct fastrpc_interface *iface; struct apps_std_ctx *ctx; iface = malloc(sizeof(struct fastrpc_interface)); if (iface == NULL) return NULL; ctx = calloc(1, sizeof(struct apps_std_ctx)); if (ctx == NULL) goto err_free_iface; memcpy(iface, &apps_std_interface, sizeof(struct fastrpc_interface)); ctx->rootfd = hexagonfs_open_root(ctx->fds, root); if (ctx->rootfd < 0) goto err_free_ctx; ctx->adsp_avs_cfg_dirfd = hexagonfs_openat(ctx->fds, ctx->rootfd, ctx->rootfd, "/vendor/etc/acdbdata/"); ctx->adsp_library_dirfd = hexagonfs_openat(ctx->fds, ctx->rootfd, ctx->rootfd, "/usr/lib/qcom/adsp/"); iface->data = ctx; return iface; err_free_ctx: free(ctx); err_free_iface: free(iface); return NULL; } void fastrpc_apps_std_deinit(struct fastrpc_interface *iface) { struct apps_std_ctx *ctx = iface->data; int i; for (i = 0; i < HEXAGONFS_MAX_FD; i++) { if (ctx->fds[i] != NULL) hexagonfs_close(ctx->fds, i); } free(iface->data); free(iface); } static const struct fastrpc_function_impl apps_std_procs[] = { { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = &apps_std_fflush_def, .impl = apps_std_fflush, }, { .def = &apps_std_fclose_def, .impl = apps_std_fclose, }, { .def = &apps_std_fread_def, .impl = apps_std_fread, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = &apps_std_fseek_def, .impl = apps_std_fseek, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = &apps_std_fopen_with_env_def, .impl = apps_std_fopen_with_env, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = &apps_std_opendir_def, .impl = apps_std_opendir, }, { .def = &apps_std_closedir_def, .impl = apps_std_closedir, }, { .def = &apps_std_readdir_def, .impl = apps_std_readdir, }, { .def = NULL, .impl = NULL, }, { .def = NULL, .impl = NULL, }, { .def = &apps_std_stat_def, .impl = apps_std_stat, }, }; const struct fastrpc_interface apps_std_interface = { .name = "apps_std", .n_procs = 32, .procs = apps_std_procs, }; hexagonrpc-0.3.2/hexagonrpcd/apps_std.h000066400000000000000000000020171462060630700201460ustar00rootroot00000000000000/* * FastRPC operating system interface - context initialization * * 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 . */ #ifndef APPS_STD_H #define APPS_STD_H #include "hexagonfs.h" #include "listener.h" struct fastrpc_interface *fastrpc_apps_std_init(struct hexagonfs_dirent *root); void fastrpc_apps_std_deinit(struct fastrpc_interface *iface); #endif hexagonrpc-0.3.2/hexagonrpcd/hexagonfs.c000066400000000000000000000122521462060630700203100ustar00rootroot00000000000000/* * Virtual read-only filesystem for Hexagon processors * * 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 . */ #include #include #include #include #include #include #include #include "hexagonfs.h" static char *copy_segment_and_advance(const char *path, bool *trailing_slash, const char **next) { const char *next_tmp; char *segment; size_t segment_len; next_tmp = strchr(path, '/'); if (next_tmp == NULL) { next_tmp = &path[strlen(path)]; *trailing_slash = false; } else { *trailing_slash = true; } segment_len = next_tmp - path; while (*next_tmp == '/') next_tmp++; segment = malloc(segment_len + 1); if (segment == NULL) return NULL; memcpy(segment, path, segment_len); segment[segment_len] = 0; *next = next_tmp; return segment; } static struct hexagonfs_fd *pop_dir(struct hexagonfs_fd *dir, struct hexagonfs_fd *root) { struct hexagonfs_fd *up; if (dir != root && dir->up != NULL) { up = dir->up; if (!dir->is_assigned) { dir->ops->close(dir->data); free(dir); } } else { up = dir; } return up; } static int allocate_file_number(struct hexagonfs_fd **fds, struct hexagonfs_fd *fd) { size_t i; for (i = 0; i < HEXAGONFS_MAX_FD; i++) { if (fds[i] == NULL) { fd->is_assigned = true; fds[i] = fd; return i; } } return -EMFILE; } static void destroy_file_descriptor(struct hexagonfs_fd *fd) { struct hexagonfs_fd *curr = fd; struct hexagonfs_fd *next; while (curr != NULL && !curr->is_assigned) { next = curr->up; curr->ops->close(curr->data); free(curr); curr = next; } } int hexagonfs_open_root(struct hexagonfs_fd **fds, struct hexagonfs_dirent *root) { struct hexagonfs_fd *fd; int ret; fd = malloc(sizeof(struct hexagonfs_fd)); if (fd == NULL) return -ENOMEM; fd->is_assigned = false; fd->up = NULL; fd->ops = root->ops; ret = root->ops->from_dirent(root->u.ptr, true, &fd->data); if (ret) goto err; ret = allocate_file_number(fds, fd); if (ret < 0) goto err; return ret; err: destroy_file_descriptor(fd); return ret; } int hexagonfs_openat(struct hexagonfs_fd **fds, int rootfd, int dirfd, const char *name) { struct hexagonfs_fd *fd; const char *curr = name; char *segment; bool expect_dir; int selected = dirfd; int ret = 0; if (*curr == '/') { selected = rootfd; while (*curr == '/') curr++; } fd = fds[selected]; while (*curr != '\0' && !ret) { segment = copy_segment_and_advance(curr, &expect_dir, &curr); if (segment == NULL) { ret = -ENOMEM; goto err; } if (!strcmp(segment, ".")) { goto next; } else if (!strcmp(segment, "..")) { fd = pop_dir(fd, fds[rootfd]); } else { ret = fd->ops->openat(fd, segment, expect_dir, &fd); } next: free(segment); } if (ret) goto err; ret = allocate_file_number(fds, fd); if (ret) goto err; return ret; err: destroy_file_descriptor(fd); return ret; } int hexagonfs_close(struct hexagonfs_fd **fds, int fileno) { struct hexagonfs_fd *fd; if (fileno < 0 || fileno >= HEXAGONFS_MAX_FD) return -EBADF; fd = fds[fileno]; if (fd == NULL || fd->ops == NULL) return -EBADF; fd->is_assigned = false; destroy_file_descriptor(fd); fds[fileno] = NULL; return 0; } int hexagonfs_lseek(struct hexagonfs_fd **fds, int fileno, off_t off, int whence) { struct hexagonfs_fd *fd; if (fileno < 0 || fileno >= HEXAGONFS_MAX_FD) return -EBADF; fd = fds[fileno]; if (fd == NULL) return -EBADF; if (fd->ops->seek == NULL) return -ENOSYS; return fd->ops->seek(fd, off, whence); } ssize_t hexagonfs_read(struct hexagonfs_fd **fds, int fileno, size_t size, void *ptr) { struct hexagonfs_fd *fd; if (fileno < 0 || fileno >= HEXAGONFS_MAX_FD) return -EBADF; fd = fds[fileno]; if (fd == NULL) return -EBADF; if (fd->ops->read == NULL) return -ENOSYS; return fd->ops->read(fd, size, ptr); } int hexagonfs_readdir(struct hexagonfs_fd **fds, int fileno, size_t ent_size, char *ent) { struct hexagonfs_fd *fd; if (fileno < 0 || fileno >= HEXAGONFS_MAX_FD) return -EBADF; fd = fds[fileno]; if (fd == NULL) return -EBADF; if (fd->ops->readdir == NULL) return -ENOSYS; return fd->ops->readdir(fd, ent_size, ent); } int hexagonfs_fstat(struct hexagonfs_fd **fds, int fileno, struct stat *stats) { struct hexagonfs_fd *fd; if (fileno < 0 || fileno >= HEXAGONFS_MAX_FD) return -EBADF; fd = fds[fileno]; if (fd == NULL) return -EBADF; if (fd->ops->stat == NULL) return -ENOSYS; return fd->ops->stat(fd, stats); } hexagonrpc-0.3.2/hexagonrpcd/hexagonfs.h000066400000000000000000000051721462060630700203200ustar00rootroot00000000000000/* * Virtual read-only filesystem for Hexagon processors * * 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 . */ #ifndef HEXAGONFS_H #define HEXAGONFS_H #include #include #include #include #define HEXAGONFS_MAX_FD 256 struct hexagonfs_fd; struct hexagonfs_file_ops { void (*close)(void *fd_data); int (*from_dirent)(const void *dirent_data, bool dir, void **fd_data); int (*openat)(struct hexagonfs_fd *dir, const char *segment, bool expect_dir, struct hexagonfs_fd **out); int (*readdir)(struct hexagonfs_fd *fd, size_t size, char *out); ssize_t (*read)(struct hexagonfs_fd *fd, size_t size, void *ptr); int (*stat)(struct hexagonfs_fd *fd, struct stat *stats); int (*seek)(struct hexagonfs_fd *fd, off_t off, int whence); }; struct hexagonfs_dirent { const char *name; struct hexagonfs_file_ops *ops; union hexagonfs_dirent_data { void *ptr; struct hexagonfs_dirent **dir; const char *phys; } u; }; struct hexagonfs_fd { bool is_assigned; struct hexagonfs_fd *up; void *data; struct hexagonfs_file_ops *ops; }; extern struct hexagonfs_file_ops hexagonfs_mapped_ops; extern struct hexagonfs_file_ops hexagonfs_mapped_or_empty_ops; extern struct hexagonfs_file_ops hexagonfs_mapped_sysfs_ops; extern struct hexagonfs_file_ops hexagonfs_plat_subtype_name_ops; extern struct hexagonfs_file_ops hexagonfs_virt_dir_ops; int hexagonfs_open_root(struct hexagonfs_fd **fds, struct hexagonfs_dirent *root); int hexagonfs_openat(struct hexagonfs_fd **fds, int rootfd, int dirfd, const char *name); int hexagonfs_close(struct hexagonfs_fd **fds, int fileno); int hexagonfs_fstat(struct hexagonfs_fd **fds, int fileno, struct stat *stats); int hexagonfs_lseek(struct hexagonfs_fd **fds, int fileno, off_t pos, int whence); int hexagonfs_readdir(struct hexagonfs_fd **fds, int fileno, size_t size, char *name); ssize_t hexagonfs_read(struct hexagonfs_fd **fds, int fileno, size_t size, void *ptr); #endif hexagonrpc-0.3.2/hexagonrpcd/hexagonfs_mapped.c000066400000000000000000000156261462060630700216460ustar00rootroot00000000000000/* * HexagonFS mapped file/directory operations * * 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 . */ #include #include #include #include #include #include #include #include #include "hexagonfs.h" struct mapped_ctx { int fd; DIR *dir; }; static void mapped_close(void *fd_data) { struct mapped_ctx *ctx = fd_data; if (ctx->dir != NULL) closedir(ctx->dir); else close(ctx->fd); free(ctx); } static int mapped_from_dirent(const void *dirent_data, bool dir, void **fd_data) { struct mapped_ctx *ctx; const char *name = dirent_data; int flags = O_RDONLY; int ret; ctx = malloc(sizeof(struct mapped_ctx)); if (ctx == NULL) return -ENOMEM; if (dir) flags |= O_DIRECTORY; ctx->fd = open(name, flags); if (ctx->fd == -1) { ret = -errno; goto err; } ctx->dir = NULL; *fd_data = ctx; return 0; err: free(ctx); return ret; } static int mapped_openat(struct hexagonfs_fd *dir, const char *segment, bool expect_dir, struct hexagonfs_fd **out) { struct mapped_ctx *dir_ctx = dir->data; struct hexagonfs_fd *fd; struct mapped_ctx *ctx; int flags = O_RDONLY; int ret; ctx = malloc(sizeof(struct mapped_ctx)); if (ctx == NULL) return -ENOMEM; fd = malloc(sizeof(struct hexagonfs_fd)); if (fd == NULL) { ret = -ENOMEM; goto err; } if (expect_dir) flags |= O_DIRECTORY; ctx->fd = openat(dir_ctx->fd, segment, flags); if (ctx->fd == -1) { ret = -errno; goto err_free_fd; } ctx->dir = NULL; fd->is_assigned = false; fd->up = dir; fd->ops = &hexagonfs_mapped_ops; fd->data = ctx; *out = fd; return 0; err_free_fd: free(fd); err: free(ctx); return ret; } static ssize_t mapped_read(struct hexagonfs_fd *fd, size_t size, void *out) { struct mapped_ctx *ctx = fd->data; ssize_t ret; ret = read(ctx->fd, out, size); if (ret < 0) return -errno; return ret; } static int mapped_readdir(struct hexagonfs_fd *fd, size_t size, char *out) { struct mapped_ctx *ctx = fd->data; struct dirent *ent; if (ctx->dir == NULL) { ctx->dir = fdopendir(ctx->fd); if (ctx->dir == NULL) return -errno; ctx->fd = dirfd(ctx->dir); if (ctx->fd == -1) return -errno; } errno = 0; ent = readdir(ctx->dir); if (ent == NULL) { out[0] = '\0'; return -errno; } strncpy(out, ent->d_name, size); out[size - 1] = '\0'; return 0; } static int mapped_seek(struct hexagonfs_fd *fd, off_t off, int whence) { struct mapped_ctx *ctx = fd->data; int ret; ret = lseek(ctx->fd, off, whence); if (ret == -1) return -errno; return 0; } static int mapped_stat(struct hexagonfs_fd *fd, struct stat *stats) { struct mapped_ctx *ctx = fd->data; struct stat phys; int ret; ret = fstat(ctx->fd, &phys); if (ret) return -errno; stats->st_size = phys.st_size; stats->st_dev = 0; stats->st_rdev = 0; stats->st_ino = 0; stats->st_nlink = 0; if (phys.st_mode & S_IFDIR) { stats->st_mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; } else { stats->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; } stats->st_atim.tv_sec = phys.st_atim.tv_sec; stats->st_atim.tv_nsec = phys.st_atim.tv_nsec; stats->st_ctim.tv_sec = phys.st_ctim.tv_sec; stats->st_ctim.tv_nsec = phys.st_ctim.tv_nsec; stats->st_mtim.tv_sec = phys.st_mtim.tv_sec; stats->st_mtim.tv_nsec = phys.st_mtim.tv_nsec; return 0; } static void mapped_or_empty_close(void *fd_data) { if (fd_data) mapped_close(fd_data); } static int mapped_or_empty_from_dirent(const void *dirent_data, bool dir, void **fd_data) { int ret; ret = mapped_from_dirent(dirent_data, dir, fd_data); if (ret) *fd_data = NULL; return 0; } static int mapped_or_empty_openat(struct hexagonfs_fd *dir, const char *segment, bool expect_dir, struct hexagonfs_fd **out) { if (dir->data) return mapped_openat(dir, segment, expect_dir, out); else return -ENOENT; } static ssize_t mapped_or_empty_read(struct hexagonfs_fd *fd, size_t size, void *out) { if (fd->data) return mapped_read(fd, size, out); return 0; } static int mapped_or_empty_readdir(struct hexagonfs_fd *fd, size_t size, char *out) { if (fd->data) { return mapped_readdir(fd, size, out); } else { out[0] = '\0'; return 0; } } static int mapped_or_empty_seek(struct hexagonfs_fd *fd, off_t off, int whence) { if (fd->data) return mapped_seek(fd, off, whence); else return 0; } static int mapped_or_empty_stat(struct hexagonfs_fd *fd, struct stat *stats) { if (fd->data) { return mapped_stat(fd, stats); } else { stats->st_size = 0; stats->st_dev = 0; stats->st_rdev = 0; stats->st_ino = 0; stats->st_nlink = 0; stats->st_mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; stats->st_atim.tv_sec = 0; stats->st_atim.tv_nsec = 0; stats->st_ctim.tv_sec = 0; stats->st_ctim.tv_nsec = 0; stats->st_mtim.tv_sec = 0; stats->st_mtim.tv_nsec = 0; return 0; } } /* * This is the sysfs variant of the stat function. * * The remote processor expects a non-zero size if the file is not empty, even * if a size cannot be determined without reading. The size is 256 on * downstream kernels, so set it to that. * * Otherwise, the existing stat() function can be used. */ static int mapped_sysfs_stat(struct hexagonfs_fd *fd, struct stat *stats) { int ret; ret = mapped_stat(fd, stats); if (ret) return ret; if (!(stats->st_mode & S_IFDIR)) stats->st_size = 256; return 0; } struct hexagonfs_file_ops hexagonfs_mapped_ops = { .close = mapped_close, .from_dirent = mapped_from_dirent, .openat = mapped_openat, .read = mapped_read, .readdir = mapped_readdir, .seek = mapped_seek, .stat = mapped_stat, }; struct hexagonfs_file_ops hexagonfs_mapped_or_empty_ops = { .close = mapped_or_empty_close, .from_dirent = mapped_or_empty_from_dirent, .openat = mapped_or_empty_openat, .read = mapped_or_empty_read, .readdir = mapped_or_empty_readdir, .seek = mapped_or_empty_seek, .stat = mapped_or_empty_stat, }; struct hexagonfs_file_ops hexagonfs_mapped_sysfs_ops = { .close = mapped_close, .from_dirent = mapped_from_dirent, .openat = mapped_openat, .read = mapped_read, .readdir = mapped_readdir, .seek = mapped_seek, .stat = mapped_sysfs_stat, }; hexagonrpc-0.3.2/hexagonrpcd/hexagonfs_plat_subtype_name.c000066400000000000000000000043541462060630700241070ustar00rootroot00000000000000/* * HexagonFS operations for a missing sysfs file * * 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 . */ #include #include #include #include #include "hexagonfs.h" struct plat_subtype_ctx { int fd; char *name; }; static void plat_subtype_name_close(void *fd_data) { struct plat_subtype_ctx *ctx = fd_data; close(ctx->fd); if (ctx->name != NULL) free(ctx->name); } static int plat_subtype_name_from_dirent(const void *dirent_data, bool dir, void **fd_data) { struct plat_subtype_ctx *ctx; if (dir) return -ENOTDIR; ctx = malloc(sizeof(struct plat_subtype_ctx)); if (ctx == NULL) return -ENOMEM; ctx->fd = open(dirent_data, O_RDONLY); if (ctx->fd == -1) return -errno; ctx->name = NULL; *fd_data = ctx; return 0; } static int plat_subtype_name_openat(struct hexagonfs_fd *dir, const char *segment, bool expect_dir, struct hexagonfs_fd **out) { return -ENOTDIR; } static int plat_subtype_stat(struct hexagonfs_fd *fd, struct stat *stats) { stats->st_size = 0; stats->st_dev = 0; stats->st_rdev = 0; stats->st_ino = 0; stats->st_nlink = 0; stats->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; stats->st_atim.tv_sec = 0; stats->st_atim.tv_nsec = 0; stats->st_ctim.tv_sec = 0; stats->st_ctim.tv_nsec = 0; stats->st_mtim.tv_sec = 0; stats->st_mtim.tv_nsec = 0; return 0; } struct hexagonfs_file_ops hexagonfs_plat_subtype_name_ops = { .close = plat_subtype_name_close, .from_dirent = plat_subtype_name_from_dirent, .openat = plat_subtype_name_openat, .stat = plat_subtype_stat, }; hexagonrpc-0.3.2/hexagonrpcd/hexagonfs_virt_dir.c000066400000000000000000000056011462060630700222120ustar00rootroot00000000000000/* * HexagonFS virtual directory operations * * 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 . */ #include #include #include #include #include #include "hexagonfs.h" /* * This function searches for the relevant path segment in the path directory. * It is not optimized because it is dealing with small directories. */ static const struct hexagonfs_dirent *walk_dir(const struct hexagonfs_dirent *const *dir, const char *segment) { const struct hexagonfs_dirent *const *curr = dir; while (*curr != NULL) { if (!strcmp(segment, (*curr)->name)) break; curr++; } return *curr; } static int virt_dir_from_dirent(const void *dirent_data, bool dir, void **fd_data) { const struct hexagonfs_dirent *const **wrapper; wrapper = malloc(sizeof(*wrapper)); if (wrapper == NULL) return -ENOMEM; *wrapper = dirent_data; *fd_data = wrapper; return 0; } static int virt_dir_openat(struct hexagonfs_fd *dir, const char *segment, bool expect_dir, struct hexagonfs_fd **out) { const struct hexagonfs_dirent *const **dirlist = dir->data; const struct hexagonfs_dirent *ent; struct hexagonfs_fd *fd; int ret; ent = walk_dir(*dirlist, segment); if (ent == NULL) return -ENOENT; fd = malloc(sizeof(struct hexagonfs_fd)); if (fd == NULL) return -ENOMEM; fd->is_assigned = false; fd->up = dir; fd->ops = ent->ops; ret = ent->ops->from_dirent(ent->u.ptr, expect_dir, &fd->data); if (ret) goto err; *out = fd; return 0; err: free(fd); return ret; } static void virt_dir_close(void *fd_data) { free(fd_data); } static int virt_dir_stat(struct hexagonfs_fd *fd, struct stat *stats) { stats->st_size = 0; stats->st_dev = 0; stats->st_rdev = 0; stats->st_ino = 0; stats->st_nlink = 0; stats->st_mode = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; stats->st_atim.tv_sec = 0; stats->st_atim.tv_nsec = 0; stats->st_ctim.tv_sec = 0; stats->st_ctim.tv_nsec = 0; stats->st_mtim.tv_sec = 0; stats->st_mtim.tv_nsec = 0; return 0; } struct hexagonfs_file_ops hexagonfs_virt_dir_ops = { .close = virt_dir_close, .from_dirent = virt_dir_from_dirent, .openat = virt_dir_openat, .stat = virt_dir_stat, }; hexagonrpc-0.3.2/hexagonrpcd/interfaces.c000066400000000000000000000017101462060630700204460ustar00rootroot00000000000000/* * 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 . */ #define HEXAGONRPC_BUILD_METHOD_DEFINITIONS 1 #include "interfaces/adsp_default_listener.def" #include "interfaces/apps_std.def" #include "interfaces/adsp_listener.def" hexagonrpc-0.3.2/hexagonrpcd/interfaces/000077500000000000000000000000001462060630700203035ustar00rootroot00000000000000hexagonrpc-0.3.2/hexagonrpcd/interfaces/adsp_default_listener.def000066400000000000000000000020251462060630700253220ustar00rootroot00000000000000/* * FastRPC reverse tunnel registration interface * * 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 . */ #ifndef INTERFACE_ADSP_DEFAULT_LISTENER_DEF #define INTERFACE_ADSP_DEFAULT_LISTENER_DEF #include HEXAGONRPC_DEFINE_REMOTE_METHOD(0, adsp_default_listener_register, 0, 0, 0, 0) #endif /* INTERFACE_ADSP_DEFAULT_LISTENER_DEF */ hexagonrpc-0.3.2/hexagonrpcd/interfaces/adsp_listener.def000066400000000000000000000021161462060630700236170ustar00rootroot00000000000000/* * FastRPC reverse tunnel main interface * * 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 . */ #ifndef INTERFACE_ADSP_LISTENER_DEF #define INTERFACE_ADSP_LISTENER_DEF #include #define ADSP_LISTENER_HANDLE 3 HEXAGONRPC_DEFINE_REMOTE_METHOD(3, adsp_listener_init2, 0, 0, 0, 0) HEXAGONRPC_DEFINE_REMOTE_METHOD(4, adsp_listener_next2, 2, 1, 4, 1) #endif /* INTERFACE_ADSP_LISTENER_DEF */ hexagonrpc-0.3.2/hexagonrpcd/interfaces/apps_std.def000066400000000000000000000030441462060630700226010ustar00rootroot00000000000000/* * FastRPC operating system interface * * 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 . */ #ifndef INTERFACE_APPS_STD_DEF #define INTERFACE_APPS_STD_DEF #include HEXAGONRPC_DEFINE_REMOTE_METHOD(1, apps_std_freopen, 1, 0, 1, 1) HEXAGONRPC_DEFINE_REMOTE_METHOD(2, apps_std_fflush, 8, 0, 0, 0) HEXAGONRPC_DEFINE_REMOTE_METHOD(3, apps_std_fclose, 1, 0, 0, 0) HEXAGONRPC_DEFINE_REMOTE_METHOD(4, apps_std_fread, 1, 0, 2, 1) HEXAGONRPC_DEFINE_REMOTE_METHOD(9, apps_std_fseek, 3, 0, 0, 0) HEXAGONRPC_DEFINE_REMOTE_METHOD(19, apps_std_fopen_with_env, 0, 4, 1, 0) HEXAGONRPC_DEFINE_REMOTE_METHOD(26, apps_std_opendir, 0, 1, 2, 0) HEXAGONRPC_DEFINE_REMOTE_METHOD(27, apps_std_closedir, 2, 0, 0, 0) HEXAGONRPC_DEFINE_REMOTE_METHOD(28, apps_std_readdir, 2, 0, 66, 0) HEXAGONRPC_DEFINE_REMOTE_METHOD(31, apps_std_stat, 1, 1, 24, 0) #endif /* INTERFACE_APPS_STD_DEF */ hexagonrpc-0.3.2/hexagonrpcd/iobuffer.c000066400000000000000000000112151462060630700201250ustar00rootroot00000000000000/* * FastRPC reverse tunnel - argument decoder * * 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 . */ #include #include #include #include #include #include "iobuffer.h" #define MIN(x, y) (((x) < (y)) ? (x) : (y)) static size_t consume_size(struct fastrpc_decoder_context *ctx, size_t len, const char *buf) { size_t segment; segment = MIN(len, 4 - ctx->size_off); memcpy(&((char *) &ctx->size)[ctx->size_off], buf, segment); ctx->size_off = (ctx->size_off + segment) % 4; ctx->align = (ctx->align + segment) & 0x7; return segment; } static int try_populate_inbuf(struct fastrpc_decoder_context *ctx) { void *buf; // If we still need to process the size, don't do anything yet. if (ctx->size_off) return 0; buf = malloc(ctx->size); if (buf == NULL) return -1; ctx->inbufs[ctx->idx].s = ctx->size; ctx->inbufs[ctx->idx].p = buf; return 0; } static size_t consume_alignment(struct fastrpc_decoder_context *ctx, size_t len) { size_t segment = 0; if (ctx->align) { segment = MIN(len, 8 - ctx->align); ctx->align = (ctx->align + segment) & 0x7; } return segment; } static size_t consume_buf(struct fastrpc_decoder_context *ctx, size_t len, const void *buf) { size_t segment; void *dest; dest = (void *) &((char *) ctx->inbufs[ctx->idx].p)[ctx->buf_off]; segment = MIN(len, ctx->size - ctx->buf_off); memcpy(dest, buf, segment); if (ctx->buf_off + segment >= ctx->size) { ctx->size = 0; ctx->buf_off = 0; ctx->idx++; } else { ctx->buf_off = ctx->buf_off + segment; } ctx->align = (ctx->align + segment) & 0x7; return segment; } static size_t align_and_copy_outbuf(const struct fastrpc_io_buffer *outbuf, void *dest, off_t align) { char *ptr = dest; size_t zero = 0; if (align) { zero = 8 - align; memset(ptr, 0, zero); } memcpy(&ptr[zero], outbuf->p, outbuf->s); return zero + outbuf->s; } void iobuf_free(size_t n_iobufs, struct fastrpc_io_buffer *iobufs) { size_t i; for (i = 0; i < n_iobufs; i++) free(iobufs[i].p); free(iobufs); } struct fastrpc_decoder_context *inbuf_decode_start(uint32_t sc) { struct fastrpc_decoder_context *ctx; ctx = malloc(sizeof(*ctx)); if (ctx == NULL) return ctx; ctx->idx = 0; ctx->size = 0; ctx->n_inbufs = REMOTE_SCALARS_INBUFS(sc); ctx->size_off = 0; ctx->buf_off = 0; ctx->align = 0; ctx->inbufs = malloc(sizeof(*ctx->inbufs) * ctx->n_inbufs); if (ctx->inbufs == NULL && ctx->n_inbufs != 0) goto err; return ctx; err: free(ctx); return NULL; } struct fastrpc_io_buffer *inbuf_decode_finish(struct fastrpc_decoder_context *ctx) { struct fastrpc_io_buffer *inbufs = ctx->inbufs; free(ctx); return inbufs; } int inbuf_decode_is_complete(struct fastrpc_decoder_context *ctx) { return ctx->idx >= ctx->n_inbufs; } int inbuf_decode(struct fastrpc_decoder_context *ctx, size_t len, const void *src) { const char *buf = src; size_t off = 0; int ret = 0; while (off < len && ctx->idx < ctx->n_inbufs) { if (!ctx->size || ctx->size_off) { off += consume_size(ctx, len - off, &buf[off]); ret = try_populate_inbuf(ctx); } else if (ctx->align && !ctx->buf_off) { off += consume_alignment(ctx, len - off); } else { off += consume_buf(ctx, len - off, &buf[off]); } if (ret == -1) return ret; } return 0; } size_t outbufs_calculate_size(size_t n_outbufs, const struct fastrpc_io_buffer *outbufs) { size_t i; size_t size = 0; for (i = 0; i < n_outbufs; i++) { size += 4; if (size & 0x7) size += 8 - (size & 0x7); size += outbufs[i].s; } return size; } void outbufs_encode(size_t n_outbufs, const struct fastrpc_io_buffer *outbufs, void *dest) { char *ptr = dest; off_t align = 0; size_t written; size_t i; for (i = 0; i < n_outbufs; i++) { *(uint32_t *) ptr = outbufs[i].s; ptr = &ptr[4]; align = (align + 4) & 0x7; if (outbufs[i].s) { written = align_and_copy_outbuf(&outbufs[i], ptr, align); ptr = &ptr[written]; align = (align + written) & 0x7; } } } hexagonrpc-0.3.2/hexagonrpcd/iobuffer.h000066400000000000000000000032651462060630700201400ustar00rootroot00000000000000/* * FastRPC reverse tunnel I/O buffer encoder/decoder API * * 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 . */ #ifndef IOBUFFER_H #define IOBUFFER_H #include #include #include struct fastrpc_io_buffer { uint32_t s; void *p; }; struct fastrpc_decoder_context { struct fastrpc_io_buffer *inbufs; unsigned int n_inbufs; unsigned int idx; uint32_t size; uint32_t buf_off; unsigned int size_off; unsigned int align; }; void iobuf_free(size_t n_iobufs, struct fastrpc_io_buffer *iobufs); struct fastrpc_decoder_context *inbuf_decode_start(uint32_t sc); struct fastrpc_io_buffer *inbuf_decode_finish(struct fastrpc_decoder_context *ctx); int inbuf_decode_is_complete(struct fastrpc_decoder_context *ctx); int inbuf_decode(struct fastrpc_decoder_context *ctx, size_t len, const void *src); size_t outbufs_calculate_size(size_t n_outbufs, const struct fastrpc_io_buffer *outbufs); void outbufs_encode(size_t n_outbufs, const struct fastrpc_io_buffer *outbufs, void *dest); #endif hexagonrpc-0.3.2/hexagonrpcd/listener.c000066400000000000000000000170731462060630700201610ustar00rootroot00000000000000/* * FastRPC reverse tunnel * * 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 . */ #include #include #include #include #include #include "aee_error.h" #include "interfaces/adsp_listener.def" #include "iobuffer.h" #include "listener.h" static int adsp_listener_init2(int fd) { return fastrpc2(&adsp_listener_init2_def, fd, ADSP_LISTENER_HANDLE); } static int adsp_listener_next2(int fd, uint32_t ret_rctx, uint32_t ret_res, uint32_t ret_outbuf_len, void *ret_outbuf, uint32_t *rctx, uint32_t *handle, uint32_t *sc, uint32_t *inbufs_len, uint32_t inbufs_size, void *inbufs) { return fastrpc2(&adsp_listener_next2_def, fd, ADSP_LISTENER_HANDLE, ret_rctx, ret_res, ret_outbuf_len, ret_outbuf, rctx, handle, sc, inbufs_len, inbufs_size, inbufs); } static struct fastrpc_io_buffer *allocate_outbufs(const struct fastrpc_function_def_interp2 *def, uint32_t *first_inbuf) { struct fastrpc_io_buffer *out; size_t out_count; size_t i, j; off_t off; uint32_t *sizes; out_count = def->out_bufs + (def->out_nums && 1); /* * POSIX allows malloc to return a non-NULL pointer to a zero-size area * in memory. Since the code below assumes non-zero size if the pointer * is non-NULL, exit early if we do not need to allocate anything. */ if (out_count == 0) return NULL; out = malloc(sizeof(struct fastrpc_io_buffer) * out_count); if (out == NULL) return NULL; out[0].s = def->out_nums * 4; if (out[0].s) { out[0].p = malloc(def->out_nums * 4); if (out[0].p == NULL) goto err_free_out; } off = def->out_nums && 1; sizes = &first_inbuf[def->in_nums + def->in_bufs]; for (i = 0; i < def->out_bufs; i++) { out[off + i].s = sizes[i]; out[off + i].p = malloc(sizes[i]); if (out[off + i].p == NULL) goto err_free_prev; } return out; err_free_prev: for (j = 0; j < i; j++) free(out[off + j].p); err_free_out: free(out); return NULL; } static int check_inbuf_sizes(const struct fastrpc_function_def_interp2 *def, const struct fastrpc_io_buffer *inbufs) { uint8_t i; const uint32_t *sizes = &((const uint32_t *) inbufs[0].p)[def->in_nums]; if (inbufs[0].s != 4 * (def->in_nums + def->in_bufs + def->out_bufs)) { fprintf(stderr, "Invalid number of input numbers: %" PRIu32 " (expected %u)\n", inbufs[0].s, 4 * (def->in_nums + def->in_bufs + def->out_bufs)); return -1; } for (i = 0; i < def->in_bufs; i++) { if (inbufs[i + 1].s != sizes[i]) { fprintf(stderr, "Invalid buffer size\n"); return -1; } } return 0; } static int return_for_next_invoke(int fd, uint32_t result, uint32_t *rctx, uint32_t *handle, uint32_t *sc, const struct fastrpc_io_buffer *returned, struct fastrpc_io_buffer **decoded) { struct fastrpc_decoder_context *ctx; char inbufs[256]; char *outbufs = NULL; uint32_t inbufs_len; uint32_t outbufs_len; int ret; outbufs_len = outbufs_calculate_size(REMOTE_SCALARS_OUTBUFS(*sc), returned); if (outbufs_len) { outbufs = malloc(outbufs_len); if (outbufs == NULL) { perror("Could not allocate encoded output buffer"); return -1; } outbufs_encode(REMOTE_SCALARS_OUTBUFS(*sc), returned, outbufs); } ret = adsp_listener_next2(fd, *rctx, result, outbufs_len, outbufs, rctx, handle, sc, &inbufs_len, 256, inbufs); if (ret) { if (ret == -1) perror("Could not fetch next FastRPC message"); else fprintf(stderr, "Could not fetch next FastRPC message: %d\n", ret); goto err_free_outbufs; } if (inbufs_len > 256) { fprintf(stderr, "Large (>256B) input buffers aren't implemented\n"); ret = -1; goto err_free_outbufs; } ctx = inbuf_decode_start(*sc); if (!ctx) { perror("Could not start decoding"); ret = -1; goto err_free_outbufs; } ret = inbuf_decode(ctx, inbufs_len, inbufs); if (ret) { perror("Could not decode"); goto err_free_outbufs; } if (!inbuf_decode_is_complete(ctx)) { fprintf(stderr, "Expected more input buffers\n"); ret = -1; goto err_free_outbufs; } *decoded = inbuf_decode_finish(ctx); err_free_outbufs: free(outbufs); return ret; } static int invoke_requested_procedure(size_t n_ifaces, struct fastrpc_interface **ifaces, uint32_t handle, uint32_t sc, uint32_t *result, const struct fastrpc_io_buffer *decoded, struct fastrpc_io_buffer **returned) { const struct fastrpc_function_impl *impl; uint8_t in_count; uint8_t out_count; uint32_t method = REMOTE_SCALARS_METHOD(sc); int ret; if (sc & 0xff) { fprintf(stderr, "Handles are not supported, but got %u in, %u out\n", (sc & 0xf0) >> 4, sc & 0xf); *result = AEE_EBADPARM; return 1; } if (handle >= n_ifaces) { fprintf(stderr, "Unsupported handle: %u\n", handle); *result = AEE_EUNSUPPORTED; return 1; } if (method >= ifaces[handle]->n_procs) { fprintf(stderr, "Unsupported method: %u (%08x)\n", method, sc); *result = AEE_EUNSUPPORTED; return 1; } impl = &ifaces[handle]->procs[method]; if (impl->def == NULL || impl->impl == NULL) { fprintf(stderr, "Unsupported method: %u (%08x)\n", method, sc); *result = AEE_EUNSUPPORTED; return 1; } in_count = impl->def->in_bufs + ((impl->def->in_nums || impl->def->in_bufs || impl->def->out_bufs) && 1); out_count = impl->def->out_bufs + (impl->def->out_nums && 1); if (REMOTE_SCALARS_INBUFS(sc) != in_count || REMOTE_SCALARS_OUTBUFS(sc) != out_count) { fprintf(stderr, "Unexpected buffer count: %08x\n", sc); *result = AEE_EBADPARM; return 1; } ret = check_inbuf_sizes(impl->def, decoded); if (ret) { *result = AEE_EBADPARM; return 1; } *returned = allocate_outbufs(impl->def, decoded[0].p); if (*returned == NULL && out_count > 0) { perror("Could not allocate output buffers"); *result = AEE_ENOMEMORY; return 1; } *result = impl->impl(ifaces[handle]->data, decoded, *returned); return 0; } int run_fastrpc_listener(int fd, size_t n_ifaces, struct fastrpc_interface **ifaces) { struct fastrpc_io_buffer *decoded = NULL, *returned = NULL; uint32_t result = 0xffffffff; uint32_t handle; uint32_t rctx = 0; uint32_t sc = REMOTE_SCALARS_MAKE(0, 0, 0); uint32_t n_outbufs = 0; int ret; ret = adsp_listener_init2(fd); if (ret) { fprintf(stderr, "Could not initialize the listener: %u\n", ret); return ret; } while (!ret) { ret = return_for_next_invoke(fd, result, &rctx, &handle, &sc, returned, &decoded); if (ret) break; if (returned != NULL) iobuf_free(n_outbufs, returned); ret = invoke_requested_procedure(n_ifaces, ifaces, handle, sc, &result, decoded, &returned); if (ret) break; if (decoded != NULL) iobuf_free(REMOTE_SCALARS_INBUFS(sc), decoded); n_outbufs = REMOTE_SCALARS_OUTBUFS(sc); } return ret; } hexagonrpc-0.3.2/hexagonrpcd/listener.h000066400000000000000000000026651462060630700201670ustar00rootroot00000000000000/* * FastRPC reverse tunnel - header file * * 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 . */ #ifndef LISTENER_H #define LISTENER_H #include #include #include #include "iobuffer.h" struct fastrpc_function_impl { const struct fastrpc_function_def_interp2 *def; uint32_t (*impl)(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs); }; struct fastrpc_interface { const char *name; void *data; uint8_t n_procs; const struct fastrpc_function_impl *procs; }; extern const struct fastrpc_interface localctl_interface; extern const struct fastrpc_interface apps_std_interface; int run_fastrpc_listener(int fd, size_t n_ifaces, struct fastrpc_interface **ifaces); #endif hexagonrpc-0.3.2/hexagonrpcd/localctl.c000066400000000000000000000072471462060630700201330ustar00rootroot00000000000000/* * Application processor control interface * * 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 . */ #include #include #include #include #include #include "aee_error.h" #include "iobuffer.h" #include "listener.h" #include "localctl.h" struct remotectl_ctx { size_t n_ifaces; struct fastrpc_interface **ifaces; }; struct remotectl_open_invoke { uint32_t inlen; uint32_t outlen; }; struct remotectl_open_return { uint32_t handle; uint32_t error; }; /* * This is a function that "opens" (searches an array for) an interface for the * remote endpoint to use. If it cannot find the requested interface, it * returns -5 with no error string. * * Having a constant compile-time list of interfaces lets the reverse tunnel * easily sanitize inputs. * * The -5 error was taken from Android code. */ static uint32_t localctl_open(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs) { struct remotectl_ctx *ctx = data; const struct remotectl_open_invoke *first_in = inbufs[0].p; struct remotectl_open_return *first_out = outbufs[0].p; size_t i; if (((const char *) inbufs[1].p)[inbufs[1].s - 1] != 0) return AEE_EBADPARM; memset(outbufs[1].p, 0, first_in->outlen); for (i = 0; i < ctx->n_ifaces; i++) { if (!strcmp(ctx->ifaces[i]->name, inbufs[1].p)) { first_out->handle = i; first_out->error = 0; return 0; } } fprintf(stderr, "Could not find local interface %s\n", (const char *) inbufs[1].p); first_out->handle = 0; first_out->error = -5; return -5; } /* * This is a dummy function that is called when the remote endpoint is done * using an interface. It does not need to do anything because interfaces are * static. */ static uint32_t localctl_close(void *data, const struct fastrpc_io_buffer *inbufs, struct fastrpc_io_buffer *outbufs) { uint32_t *dlerr_size = inbufs[0].p; uint32_t *dlerr_len = outbufs[0].p; memset(outbufs[1].p, 0, *dlerr_size); *dlerr_len = 0; return 0; } struct fastrpc_interface *fastrpc_localctl_init(size_t n_ifaces, struct fastrpc_interface **ifaces) { struct fastrpc_interface *iface; struct remotectl_ctx *ctx; iface = malloc(sizeof(struct fastrpc_interface)); if (iface == NULL) return NULL; ctx = malloc(sizeof(struct remotectl_ctx)); if (ctx == NULL) goto err; memcpy(iface, &localctl_interface, sizeof(struct fastrpc_interface)); ctx->n_ifaces = n_ifaces; ctx->ifaces = ifaces; iface->data = ctx; return iface; err: free(iface); return NULL; } void fastrpc_localctl_deinit(struct fastrpc_interface *iface) { if (iface == NULL) return; free(iface->data); free(iface); } static const struct fastrpc_function_impl localctl_procs[] = { { .def = &remotectl_open_def, .impl = localctl_open, }, { .def = &remotectl_close_def, .impl = localctl_close, }, }; const struct fastrpc_interface localctl_interface = { .name = "remotectl", .n_procs = 2, .procs = localctl_procs, }; hexagonrpc-0.3.2/hexagonrpcd/localctl.h000066400000000000000000000023131462060630700201250ustar00rootroot00000000000000/* * Application processor control interface - context initialization * * 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 . */ #ifndef LOCALCTL_H #define LOCALCTL_H #include "listener.h" /* * Obtain a localctl interface instance. The interfaces array must be fully * initialized once the interface instance is used (when run_fastrpc_listener() * is called). */ struct fastrpc_interface *fastrpc_localctl_init(size_t n_ifaces, struct fastrpc_interface **ifaces); void fastrpc_localctl_deinit(struct fastrpc_interface *iface); #endif hexagonrpc-0.3.2/hexagonrpcd/meson.build000066400000000000000000000006161462060630700203250ustar00rootroot00000000000000executable('hexagonrpcd', 'aee_error.c', 'apps_std.c', 'interfaces.c', 'hexagonfs.c', 'hexagonfs_mapped.c', 'hexagonfs_plat_subtype_name.c', 'hexagonfs_virt_dir.c', 'iobuffer.c', 'listener.c', 'localctl.c', 'rpcd.c', 'rpcd_builder.c', c_args : cflags, include_directories : include, install : true, link_with : libhexagonrpc, install_dir : get_option('bindir'), ) hexagonrpc-0.3.2/hexagonrpcd/rpcd.c000066400000000000000000000155021462060630700172570ustar00rootroot00000000000000/* * FastRPC Example * * 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 . */ #include #include #include #include #include #include #include #include #include #include #include #include #include "aee_error.h" #include "apps_std.h" #include "hexagonfs.h" #include "interfaces/adsp_default_listener.def" #include "listener.h" #include "localctl.h" #include "rpcd_builder.h" static int remotectl_open(int fd, char *name, struct fastrpc_context **ctx, void (*err_cb)(const char *err)) { uint32_t handle; int32_t dlret; char err[256]; int ret; ret = fastrpc2(&remotectl_open_def, fd, REMOTECTL_HANDLE, strlen(name) + 1, name, &handle, &dlret, 256, err); if (ret == -1) { err_cb(strerror(errno)); return ret; } if (dlret == -5) { err_cb(err); return dlret; } else if (dlret) { err_cb(aee_strerror[dlret]); return dlret; } *ctx = fastrpc_create_context(fd, handle); return ret; } static int remotectl_close(struct fastrpc_context *ctx, void (*err_cb)(const char *err)) { uint32_t dlret; char err[256]; int ret; ret = fastrpc2(&remotectl_close_def, ctx->fd, REMOTECTL_HANDLE, ctx->handle, &dlret, 256, err); if (ret == -1) { err_cb(strerror(errno)); return ret; } if (dlret) { err_cb(aee_strerror[dlret]); return dlret; } fastrpc_destroy_context(ctx); return ret; } static int adsp_default_listener_register(struct fastrpc_context *ctx) { return fastrpc(&adsp_default_listener_register_def, ctx); } static void remotectl_err(const char *err) { fprintf(stderr, "Could not remotectl: %s\n", err); } static int register_fastrpc_listener(int fd) { struct fastrpc_context *ctx; int ret; ret = remotectl_open(fd, "adsp_default_listener", &ctx, remotectl_err); if (ret) return 1; ret = adsp_default_listener_register(ctx); if (ret) { fprintf(stderr, "Could not register ADSP default listener\n"); goto err; } err: remotectl_close(ctx, remotectl_err); return ret; } static void print_usage(const char *argv0) { printf("Usage: %s [options] -f DEVICE\n\n", argv0); printf("Server for FastRPC remote procedure calls from Qualcomm DSPs\n\n" "Options:\n" "\t-d DSP\t\tDSP name (default: "")\n" "\t-f DEVICE\tFastRPC device node to attach to\n" "\t-p PROGRAM\tRun client program with shared file descriptor\n" "\t-R DIR\t\tRoot directory of served files (default: /usr/share/qcom/)\n" "\t-s\t\tAttach to sensorspd\n"); } static int setup_environment(int fd) { char *buf; int ret; buf = malloc(256); if (buf == NULL) { perror("Could not format file descriptor"); return 1; } snprintf(buf, 256, "%d", fd); buf[255] = '\0'; ret = setenv("HEXAGONRPC_FD", buf, 1); free(buf); return ret; } static int terminate_clients(size_t n_pids, const pid_t *pids) { size_t i; for (i = 0; i < n_pids; i++) { kill(pids[i], SIGTERM); } return 0; } static int start_clients(size_t n_progs, const char **progs, pid_t *pids) { size_t i; for (i = 0; i < n_progs; i++) { pids[i] = fork(); if (pids[i] == -1) { perror("Could not fork process"); terminate_clients(i, pids); return 1; } if (pids[i] == 0) { execl("/usr/bin/env", "/usr/bin/env", progs[i], (const char *) NULL); exit(1); } } return 0; } static void *start_reverse_tunnel(int fd, const char *device_dir, const char *dsp) { struct fastrpc_interface **ifaces; struct hexagonfs_dirent *root_dir; size_t n_ifaces = 2; int ret; ifaces = malloc(sizeof(struct fastrpc_interface) * n_ifaces); if (ifaces == NULL) return NULL; root_dir = construct_root_dir(device_dir, dsp); /* * The apps_remotectl interface patiently waits for this function to * fully populate the ifaces array as long as it receives a pointer to * it. */ ifaces[REMOTECTL_HANDLE] = fastrpc_localctl_init(n_ifaces, ifaces); // Dynamic interfaces with no hardcoded handle ifaces[1] = fastrpc_apps_std_init(root_dir); ret = register_fastrpc_listener(fd); if (ret) goto err; run_fastrpc_listener(fd, n_ifaces, ifaces); fastrpc_localctl_deinit(ifaces[REMOTECTL_HANDLE]); free(ifaces); return NULL; err: free(ifaces); return NULL; } int main(int argc, char* argv[]) { char *fastrpc_node = NULL; const char *device_dir = "/usr/share/qcom/"; const char *dsp = ""; const char **progs; pid_t *pids; size_t n_progs = 0; int fd, ret, opt; bool attach_sns = false; progs = malloc(sizeof(const char *) * argc); if (progs == NULL) { perror("Could not list client programs"); return 1; } pids = malloc(sizeof(pid_t) * argc); if (pids == NULL) { perror("Could not list client PIDs"); goto err_free_progs; } while ((opt = getopt(argc, argv, "d:f:p:R:s")) != -1) { switch (opt) { case 'd': dsp = optarg; break; case 'f': fastrpc_node = optarg; break; case 'p': progs[n_progs] = optarg; n_progs++; break; case 'R': device_dir = optarg; break; case 's': attach_sns = true; break; default: print_usage(argv[0]); goto err_free_pids; } } if (!fastrpc_node) { print_usage(argv[0]); goto err_free_pids; } printf("Starting %s (%s) on %s\n", argv[0], attach_sns? "INIT_ATTACH_SNS": "INIT_ATTACH", fastrpc_node); fd = open(fastrpc_node, O_RDWR); if (fd < 0) { fprintf(stderr, "Could not open FastRPC node (%s): %s\n", fastrpc_node, strerror(errno)); goto err_free_pids; } if (attach_sns) ret = ioctl(fd, FASTRPC_IOCTL_INIT_ATTACH_SNS, NULL); else ret = ioctl(fd, FASTRPC_IOCTL_INIT_ATTACH, NULL); if (ret) { fprintf(stderr, "Could not attach to FastRPC node: %s\n", strerror(errno)); goto err_close_dev; } ret = setup_environment(fd); if (ret) { perror("Could not setup environment variables"); goto err_close_dev; } ret = start_clients(n_progs, progs, pids); if (ret) goto err_close_dev; start_reverse_tunnel(fd, device_dir, dsp); terminate_clients(n_progs, pids); close(fd); free(pids); free(progs); return 0; err_close_dev: close(fd); err_free_pids: free(pids); err_free_progs: free(progs); return 4; } hexagonrpc-0.3.2/hexagonrpcd/rpcd_builder.c000066400000000000000000000114221462060630700207620ustar00rootroot00000000000000/* * FastRPC virtual filesystem builder * * 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 . */ #include #include #include #include "hexagonfs.h" // These paths are relative, with a prepended '/' if missing from previous segments #define ACDBDATA "/acdb/" #define DSP_LIBS "/dsp/" #define SENSORS_CONFIG "/sensors/config/" #define SENSORS_REGISTRY "/sensors/registry/" #define SNS_REG_CONFIG "/sensors/sns_reg.conf" #define SYSFS_SOCINFO "/socinfo/" static struct hexagonfs_dirent *hfs_mkdir(const char *name, size_t n_ents, ...) { struct hexagonfs_dirent *dir; struct hexagonfs_dirent **list; struct hexagonfs_dirent *ent; va_list va; size_t i; list = malloc(sizeof(struct hexagonfs_dirent *) * (n_ents + 1)); if (list == NULL) return NULL; dir = malloc(sizeof(struct hexagonfs_dirent)); if (dir == NULL) goto err_free_list; va_start(va, n_ents); for (i = 0; i < n_ents; i++) { ent = va_arg(va, struct hexagonfs_dirent *); if (ent == NULL) goto err_free_dir; list[i] = ent; } va_end(va); list[n_ents] = NULL; dir->name = name; dir->ops = &hexagonfs_virt_dir_ops; dir->u.dir = list; return dir; err_free_dir: free(dir); err_free_list: free(list); return NULL; } static struct hexagonfs_dirent *hfs_map(const char *name, const char *path) { struct hexagonfs_dirent *file; file = malloc(sizeof(struct hexagonfs_dirent)); if (file == NULL) return NULL; file->name = name; file->ops = &hexagonfs_mapped_ops; file->u.phys = path; return file; } static struct hexagonfs_dirent *hfs_map_or_empty(const char *name, const char *path) { struct hexagonfs_dirent *file; file = malloc(sizeof(struct hexagonfs_dirent)); if (file == NULL) return NULL; file->name = name; file->ops = &hexagonfs_mapped_or_empty_ops; file->u.phys = path; return file; } /* * Construct the root directory * * TODO: Make this free()-able with reference counts */ struct hexagonfs_dirent *construct_root_dir(const char *prefix, const char *dsp) { char *acdbdata, *dsp_libs, *sns_cfg, *sns_reg, *sns_reg_config, *socinfo; size_t n_prefix; struct hexagonfs_dirent *persist_dir, *vendor_dir; n_prefix = strlen(prefix); acdbdata = malloc(n_prefix + strlen(ACDBDATA) + 1); sns_cfg = malloc(n_prefix + strlen(SENSORS_CONFIG) + 1); sns_reg = malloc(n_prefix + strlen(SENSORS_REGISTRY) + 1); sns_reg_config = malloc(n_prefix + strlen(SNS_REG_CONFIG) + 1); socinfo = malloc(n_prefix + strlen(SYSFS_SOCINFO) + 1); dsp_libs = malloc(n_prefix + strlen(DSP_LIBS) + strlen(dsp) + 1); if (acdbdata != NULL) { strcpy(acdbdata, prefix); strcat(acdbdata, ACDBDATA); } if (sns_cfg != NULL) { strcpy(sns_cfg, prefix); strcat(sns_cfg, SENSORS_CONFIG); } if (sns_reg != NULL) { strcpy(sns_reg, prefix); strcat(sns_reg, SENSORS_REGISTRY); } if (sns_reg_config != NULL) { strcpy(sns_reg_config, prefix); strcat(sns_reg_config, SNS_REG_CONFIG); } if (socinfo != NULL) { strcpy(socinfo, prefix); strcat(socinfo, SYSFS_SOCINFO); } if (dsp_libs != NULL) { strcpy(dsp_libs, prefix); strcat(dsp_libs, DSP_LIBS); strcat(dsp_libs, dsp); } /* * Some platforms need this in / and some need it in /mnt/vendor. Form * a hard link between both locations. */ persist_dir = hfs_mkdir("persist", 1, hfs_mkdir("sensors", 1, hfs_mkdir("registry", 1, hfs_map("registry", sns_reg) ) ) ); /* * Some platforms need vendor in / and some need it in /system. Form * a hard link between both locations. */ vendor_dir = hfs_mkdir("vendor", 1, hfs_mkdir("etc", 2, hfs_mkdir("sensors", 2, hfs_map_or_empty("config", sns_cfg), hfs_map("sns_reg_config", sns_reg_config) ), hfs_map("acdbdata", acdbdata) ) ); return hfs_mkdir("/", 6, hfs_mkdir("mnt", 1, hfs_mkdir("vendor", 1, persist_dir ) ), persist_dir, hfs_mkdir("sys", 1, hfs_mkdir("devices", 1, hfs_map_or_empty("soc0", socinfo) ) ), hfs_mkdir("system", 1, vendor_dir ), hfs_mkdir("usr", 1, hfs_mkdir("lib", 1, hfs_mkdir("qcom", 1, hfs_map_or_empty("adsp", dsp_libs) ) ) ), vendor_dir ); } hexagonrpc-0.3.2/hexagonrpcd/rpcd_builder.h000066400000000000000000000016711462060630700207740ustar00rootroot00000000000000/* * FastRPC virtual filesystem builder - header file * * 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 . */ #ifndef RPCD_BUILDER_H #define RPCD_BUILDER_H #include "hexagonfs.h" struct hexagonfs_dirent *construct_root_dir(const char *prefix, const char *dsp); #endif hexagonrpc-0.3.2/include/000077500000000000000000000000001462060630700153015ustar00rootroot00000000000000hexagonrpc-0.3.2/include/libhexagonrpc/000077500000000000000000000000001462060630700201265ustar00rootroot00000000000000hexagonrpc-0.3.2/include/libhexagonrpc/fastrpc.h000066400000000000000000000044541462060630700217500ustar00rootroot00000000000000/* * FastRPC API Replacement - header files * * 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 . */ #ifndef FASTRPC_H #define FASTRPC_H #include #include #include // See fastrpc.git/inc/remote.h #define REMOTE_SCALARS_MAKEX(nAttr,nMethod,nIn,nOut,noIn,noOut) \ ((((uint32_t) (nAttr) & 0x7) << 29) | \ (((uint32_t) (nMethod) & 0x1f) << 24) | \ (((uint32_t) (nIn) & 0xff) << 16) | \ (((uint32_t) (nOut) & 0xff) << 8) | \ (((uint32_t) (noIn) & 0x0f) << 4) | \ ((uint32_t) (noOut) & 0x0f)) #define REMOTE_SCALARS_MAKE(nMethod,nIn,nOut) REMOTE_SCALARS_MAKEX(0,nMethod,nIn,nOut,0,0) #define REMOTE_SCALARS_METHOD(sc) (((sc) >> 24) & 0x1f) #define REMOTE_SCALARS_INBUFS(sc) (((sc) >> 16) & 0xff) #define REMOTE_SCALARS_OUTBUFS(sc) (((sc) >> 8) & 0xff) struct fastrpc_context { int fd; uint32_t handle; }; struct fastrpc_function_def_interp2 { uint32_t msg_id; uint8_t in_nums; uint8_t in_bufs; uint8_t out_nums; uint8_t out_bufs; }; struct fastrpc_context *fastrpc_create_context(int fd, uint32_t handle); static inline void fastrpc_destroy_context(struct fastrpc_context *ctx) { free(ctx); } int vfastrpc2(const struct fastrpc_function_def_interp2 *def, int fd, uint32_t handle, va_list arg_list); int vfastrpc(const struct fastrpc_function_def_interp2 *def, const struct fastrpc_context *ctx, va_list arg_list); int fastrpc2(const struct fastrpc_function_def_interp2 *def, int fd, uint32_t handle, ...); int fastrpc(const struct fastrpc_function_def_interp2 *def, const struct fastrpc_context *ctx, ...); #endif hexagonrpc-0.3.2/include/libhexagonrpc/interface.h000066400000000000000000000033421462060630700222410ustar00rootroot00000000000000/* * FastRPC interface method definition macros * * 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 . */ #ifndef LIBHEXAGONRPC_INTERFACE_H #define LIBHEXAGONRPC_INTERFACE_H #include /* * We want to declare method definitions as external by default so we only need * special flags when compiling the interfaces. Otherwise, everything that uses * the interfaces would need to define a macro. */ #if !HEXAGONRPC_BUILD_METHOD_DEFINITIONS #define HEXAGONRPC_DEFINE_REMOTE_METHOD(mid, name, \ innums, inbufs, \ outnums, outbufs) \ extern const struct fastrpc_function_def_interp2 name##_def; #else /* HEXAGONRPC_BUILD_METHOD_DEFINITIONS */ #define HEXAGONRPC_DEFINE_REMOTE_METHOD(mid, name, \ innums, inbufs, \ outnums, outbufs) \ const struct fastrpc_function_def_interp2 name##_def = { \ .msg_id = mid, \ .in_nums = innums, \ .in_bufs = inbufs, \ .out_nums = outnums, \ .out_bufs = outbufs, \ }; #endif /* HEXAGONRPC_BUILD_METHOD_DEFINITIONS */ #endif /* LIBHEXAGONRPC_INTERFACE_H */ hexagonrpc-0.3.2/include/libhexagonrpc/interfaces/000077500000000000000000000000001462060630700222515ustar00rootroot00000000000000hexagonrpc-0.3.2/include/libhexagonrpc/interfaces/remotectl.def000066400000000000000000000020621462060630700247270ustar00rootroot00000000000000/* * Remote processor control interface * * 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 . */ #ifndef INTERFACE_REMOTECTL_DEF #define INTERFACE_REMOTECTL_DEF #include #define REMOTECTL_HANDLE 0 HEXAGONRPC_DEFINE_REMOTE_METHOD(0, remotectl_open, 0, 1, 2, 1) HEXAGONRPC_DEFINE_REMOTE_METHOD(1, remotectl_close, 1, 0, 1, 1) #endif /* INTERFACE_REMOTECTL_DEF */ hexagonrpc-0.3.2/include/libhexagonrpc/session.h000066400000000000000000000021511462060630700217610ustar00rootroot00000000000000/* * FastRPC API Replacement - API for session-managed clients * * 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 . */ #ifndef LIBHEXAGONRPC_SESSION_H #define LIBHEXAGONRPC_SESSION_H /* * Get the file descriptor from the environment variables. Due to its * usage of getenv, it is not thread-safe. * * On success, returns the file descriptor. On failure, returns -1. */ int hexagonrpc_fd_from_env(void); #endif /* LIBHEXAGONRPC_SESSION_H */ hexagonrpc-0.3.2/libhexagonrpc/000077500000000000000000000000001462060630700165035ustar00rootroot00000000000000hexagonrpc-0.3.2/libhexagonrpc/context.c000066400000000000000000000026751462060630700203450ustar00rootroot00000000000000/* * FastRPC API Replacement - context-based interface * * 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 . */ #include struct fastrpc_context *fastrpc_create_context(int fd, uint32_t handle) { struct fastrpc_context *ctx; ctx = malloc(sizeof(*ctx)); if (ctx == NULL) return NULL; ctx->fd = fd; ctx->handle = handle; return ctx; } int vfastrpc(const struct fastrpc_function_def_interp2 *def, const struct fastrpc_context *ctx, va_list arg_list) { return vfastrpc2(def, ctx->fd, ctx->handle, arg_list); } int fastrpc(const struct fastrpc_function_def_interp2 *def, const struct fastrpc_context *ctx, ...) { va_list arg_list; int ret; va_start(arg_list, ctx); ret = vfastrpc(def, ctx, arg_list); va_end(arg_list); return ret; } hexagonrpc-0.3.2/libhexagonrpc/fastrpc.c000066400000000000000000000143471462060630700203220ustar00rootroot00000000000000/* * FastRPC API Replacement * * 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 . */ #include #include #include #include #include #include #include static void allocate_first_inbuf(const struct fastrpc_function_def_interp2 *def, struct fastrpc_invoke_args *arg, uint32_t **inbuf) { uint32_t *buf; size_t len; len = sizeof(uint32_t) * (def->in_nums + def->in_bufs + def->out_bufs); if (len) buf = malloc(len); else buf = NULL; *inbuf = buf; if (buf != NULL) { arg->ptr = (__u64) buf; arg->length = len; arg->fd = -1; } } static void allocate_first_outbuf(const struct fastrpc_function_def_interp2 *def, struct fastrpc_invoke_args *arg, uint32_t **outbuf) { uint32_t *buf; size_t len; len = sizeof(uint32_t) * def->out_nums; if (len) buf = malloc(len); else buf = NULL; *outbuf = buf; if (buf != NULL) { arg->ptr = (__u64) buf; arg->length = len; arg->fd = -1; } } /* * This populates relevant inputs (in general) with information necessary to * receive output from the remote processor. * * First, it allocates a new first output buffer to contain the returned 32-bit * integers. This output buffer must be freed after use. * * With a peek at the output arguments, it populates the fastrpc_invoke_args * struct to give information about the buffer to the kernel, and adds an entry * to the first input buffer to tell the remote processor how large the * function-level output buffer can be. * * This is the only part of the argument processing that can be split off into * a different function because it is operating on a copy of the va_list. * Calling va_arg() on a va_list after the return of a function that already * used it causes undefined behavior. */ static void prepare_outbufs(const struct fastrpc_function_def_interp2 *def, struct fastrpc_invoke_args *args, uint8_t out_count, uint32_t *inbuf, uint32_t **outbuf, va_list peek) { int i; int off; int size; allocate_first_outbuf(def, args, outbuf); off = def->out_nums && 1; for (i = 0; i < def->out_nums; i++) va_arg(peek, uint32_t *); for (i = 0; i < def->out_bufs; i++) { size = va_arg(peek, uint32_t); args[off + i].ptr = (__u64) va_arg(peek, void *); args[off + i].length = size; args[off + i].fd = -1; inbuf[i] = size; } } /* * This is the main function to invoke a fastrpc procedure call. The first * parameter specifies how to populate the ioctl-level buffers. The second and * third parameters specify where to send the invocation to. The fourth is the * list of arguments that the procedure call should interact with. * * The argument list has, in order: * - a (uint32_t val) for each input number * - a (uint32_t len, void *buf) for each input buffer * - a (uint32_t *val) for each output number * - a (uint32_t max_size, void *buf) for each output buffer * * A good example for this would be the adsp_listener_next2 call: * * static inline void adsp_listener_next2(int fd, uint32_t handle, * uint32_t prev_ctx, * uint32_t prev_result, * uint32_t nested_outbufs_len, * void *nested_outbufs, * uint32_t *ctx, * uint32_t *nested_handle, * uint32_t *nested_sc, * uint32_t *nested_inbufs_len, * uint32_t nested_inbufs_size, * void *nested_inbufs) * { * struct fastrpc_function_def_interp2 def = { * .in_nums = 2, * .in_bufs = 1, * .out_nums = 4, * .out_bufs = 1, * .mid = 4, * }; * return fastrpc(def, fd, handle, * prev_ctx, * prev_result, * nested_outbufs_len, * nested_outbufs, * ctx, * nested_handle, * nested_sc, * nested_inbufs_len, * nested_inbufs_size, * nested_inbufs); * } */ int vfastrpc2(const struct fastrpc_function_def_interp2 *def, int fd, uint32_t handle, va_list arg_list) { va_list peek; struct fastrpc_invoke invoke; struct fastrpc_invoke_args *args; uint32_t *inbuf; uint32_t *outbuf; uint8_t in_count; uint8_t out_count; uint32_t size; uint8_t i; int ret; /* * Calculate the amount of needed buffers, accounting for the need for * the maximum size of the output buffer. */ in_count = def->in_bufs + ((def->in_nums || def->in_bufs || def->out_bufs) && 1); out_count = def->out_bufs + (def->out_nums && 1); if (in_count || out_count) args = malloc(sizeof(*args) * (in_count + out_count)); else args = NULL; allocate_first_inbuf(def, args, &inbuf); for (i = 0; i < def->in_nums; i++) inbuf[i] = va_arg(arg_list, uint32_t); for (i = 0; i < def->in_bufs; i++) { size = va_arg(arg_list, uint32_t); args[i + 1].ptr = (__u64) va_arg(arg_list, void *); args[i + 1].length = size; args[i + 1].fd = -1; inbuf[def->in_nums + i] = size; } va_copy(peek, arg_list); prepare_outbufs(def, &args[in_count], out_count, &inbuf[def->in_nums + def->in_bufs], &outbuf, peek); va_end(peek); invoke.handle = handle; invoke.sc = REMOTE_SCALARS_MAKE(def->msg_id, in_count, out_count); invoke.args = (__u64) args; ret = ioctl(fd, FASTRPC_IOCTL_INVOKE, (__u64) &invoke); for (i = 0; i < def->out_nums; i++) *va_arg(arg_list, uint32_t *) = outbuf[i]; if (in_count || out_count) free(args); if (in_count) free(inbuf); if (out_count) free(outbuf); return ret; } int fastrpc2(const struct fastrpc_function_def_interp2 *def, int fd, uint32_t handle, ...) { va_list arg_list; int ret; va_start(arg_list, handle); ret = vfastrpc2(def, fd, handle, arg_list); va_end(arg_list); return ret; } hexagonrpc-0.3.2/libhexagonrpc/interfaces.c000066400000000000000000000016061462060630700207750ustar00rootroot00000000000000/* * FastRPC interface list for building common 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 . */ #define HEXAGONRPC_BUILD_METHOD_DEFINITIONS 1 #include hexagonrpc-0.3.2/libhexagonrpc/meson.build000066400000000000000000000002641462060630700206470ustar00rootroot00000000000000libhexagonrpc = shared_library('hexagonrpc', 'context.c', 'fastrpc.c', 'interfaces.c', 'session.c', c_args : cflags, include_directories : include, install : true ) hexagonrpc-0.3.2/libhexagonrpc/session.c000066400000000000000000000021261462060630700203330ustar00rootroot00000000000000/* * FastRPC API Replacement - API for session-managed clients * * 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 . */ #include #include int hexagonrpc_fd_from_env(void) { const char *fd_str; char *num_end; long fd; fd_str = getenv("HEXAGONRPC_FD"); if (fd_str == NULL) return -1; fd = strtol(fd_str, &num_end, 10); if (fd != (int) fd || fd < 0 || *num_end != '\0') return -1; return fd; } hexagonrpc-0.3.2/meson.build000066400000000000000000000005401462060630700160170ustar00rootroot00000000000000project('fastrpc', 'c') include = include_directories('include') client_target = get_option('libexecdir') / 'hexagonrpc' cflags = ['-Wall', '-Wextra', '-Wpedantic', '-Wno-unused-parameter'] if get_option('hexagonrpcd_verbose') cflags += '-DHEXAGONRPC_VERBOSE' endif subdir('libhexagonrpc') subdir('hexagonrpcd') subdir('chrecd') subdir('tests') hexagonrpc-0.3.2/meson.options000066400000000000000000000002321462060630700164110ustar00rootroot00000000000000option('hexagonrpcd_verbose', type : 'boolean', value : true, description : 'Compile hexagonrpcd with extra logging for each remote method invocation') hexagonrpc-0.3.2/tests/000077500000000000000000000000001462060630700150205ustar00rootroot00000000000000hexagonrpc-0.3.2/tests/meson.build000066400000000000000000000013121462060630700171570ustar00rootroot00000000000000valgrind = find_program('valgrind', required : false) if valgrind.found() add_test_setup('valgrind', exe_wrapper : valgrind) endif test_iobuffer = executable('test_iobuffer', 'test_iobuffer.c', '../hexagonrpcd/iobuffer.c', c_args : cflags, include_directories : include, ) sample_file = custom_target('sample_file', input : 'sample_file.txt', output : 'sample_file.txt', command : ['cp', '@INPUT@', '@OUTPUT@'] ) test_hexagonfs = executable('test_hexagonfs', 'test_hexagonfs.c', '../hexagonrpcd/hexagonfs.c', '../hexagonrpcd/hexagonfs_mapped.c', c_args : cflags, include_directories : include, ) test('iobuffer', test_iobuffer) test('hexagonfs', test_hexagonfs, args : [sample_file]) hexagonrpc-0.3.2/tests/sample_file.txt000066400000000000000000000043671462060630700200530ustar00rootroot00000000000000/* * FastRPC reverse tunnel - sample file for HexagonFS mapped file test * * Copyright (C) 2024 The HexagonRPC Contributors * * This file is part of HexagonRPC. * * HexagonRPC 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 . */ #![feature(io_error_more)] use std::collections::HashMap; use std::io::Error; use std::io::ErrorKind; use std::io::Result; use std::process::ExitCode; trait HexagonFSFile { fn seek(&self) -> Result; fn read(&self) -> Result; fn openat<'a>(&'a self, name: &str) -> Result>; } trait HexagonFSDirent { fn open<'a>(&'a self) -> Box; } struct VirtDir<'a> { def: &'a VirtDirDirent<'a>, } impl<'a> HexagonFSFile for VirtDir<'a> { fn seek(&self) -> Result { Err(Error::new(ErrorKind::IsADirectory, "Is a directory")) } fn read(&self) -> Result { Err(Error::new(ErrorKind::IsADirectory, "Is a directory")) } fn openat<'b>(&'b self, name: &str) -> Result> { let resolution = self.def.files.get(name); match resolution { Some(dirent) => Ok(dirent.open()), None => Err(Error::new(ErrorKind::NotFound, "No such file or directory")) } } } struct VirtDirDirent<'a> { files: HashMap<&'a str, Box> } impl<'b> HexagonFSDirent for VirtDirDirent<'b> { fn open<'a>(&'a self) -> Box { Box::new(VirtDir { def: self }) } } fn main() -> ExitCode { let root_dir = &VirtDirDirent { files: HashMap::from([ ("sys", Box::new(VirtDirDirent { files: HashMap::from([ ])}) as Box), ])}; let rootfd = root_dir.open(); let dirfd = rootfd.openat(""); return ExitCode::SUCCESS; } hexagonrpc-0.3.2/tests/test_hexagonfs.c000066400000000000000000000040751462060630700202130ustar00rootroot00000000000000/* * FastRPC reverse tunnel - tests for virtual filesystem * * Copyright (C) 2024 The HexagonRPC Contributors * * This file is part of HexagonRPC. * * HexagonRPC 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 . */ #include #include #include #include #include #include "../hexagonrpcd/hexagonfs.h" static int test_mapped_seq_read(const char *path) { struct hexagonfs_fd file = { .is_assigned = true, .up = NULL, .ops = &hexagonfs_mapped_ops, }; int ret, fd; char *buf1, *buf2; buf1 = malloc(256); if (buf1 == NULL) return 1; buf2 = malloc(256); if (buf2 == NULL) return 1; fd = open(path, O_RDONLY); if (fd == -1) return 1; ret = hexagonfs_mapped_ops.from_dirent(path, false, &file.data); if (ret) return 1; memset(buf1, 0, 6); memset(buf2, 0, 6); read(fd, buf1, 1); read(fd, &buf1[1], 5); hexagonfs_mapped_ops.read(&file, 1, buf2); hexagonfs_mapped_ops.read(&file, 5, &buf2[1]); if (memcmp(buf1, buf2, 6)) return 1; memset(buf1, 0, 27); memset(buf2, 0, 27); lseek(fd, 819 - 6, SEEK_CUR); read(fd, buf1, 27); hexagonfs_mapped_ops.seek(&file, 819 - 6, SEEK_CUR); hexagonfs_mapped_ops.read(&file, 27, buf2); if (memcmp(buf1, buf2, 27)) return 1; hexagonfs_mapped_ops.close(file.data); close(fd); free(buf2); free(buf1); return 0; } int main(int argc, const char **argv) { int ret; if (argc < 2) return 1; ret = test_mapped_seq_read(argv[1]); if (ret) return ret; return 0; } hexagonrpc-0.3.2/tests/test_iobuffer.c000066400000000000000000000126261462060630700200330ustar00rootroot00000000000000/* * FastRPC reverse tunnel - tests for argument encoder/decoder * * 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 . */ #include #include #include "../hexagonrpcd/iobuffer.h" static const unsigned char misaligned_iobufs[] = { /* inbuf 0 (4 bytes misaligned) */ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, /* inbuf 1 (5 bytes misaligned) */ 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x46, 0x8A, 0xCF, 0x13, 0x57, 0x9B, 0xDF, 0x04, 0x8C, /* inbuf 2 (6 bytes misaligned) */ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 'A', 'B', 'C', /* inbuf 3 (7 bytes misaligned) */ 0x04, 0x00, 0x00, 0x00, 0x00, 'F', 'a', 's', 't', /* inbuf 4 (aligned) */ 0x05, 0x00, 0x00, 0x00, 'S', 'l', 'o', 'w', '\0', /* inbuf 5 (1 byte misaligned) */ 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 'f', 'a', 's', 't', 'e', 'r', /* inbuf 6 (2 bytes misaligned) */ 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 'F', 'a', 's', 't', 'R', 'P', 'C', /* inbuf 7 (3 bytes misaligned) */ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ':', 'D', }; static unsigned char misaligned_decoded0[] = { 0x12, }; static unsigned char misaligned_decoded1[] = { 0x02, 0x46, 0x8A, 0xCF, 0x13, 0x57, 0x9B, 0xDF, 0x04, 0x8C, }; static unsigned char misaligned_decoded2[] = { 'A', 'B', 'C', }; static unsigned char misaligned_decoded3[] = { 'F', 'a', 's', 't', }; static unsigned char misaligned_decoded4[] = { 'S', 'l', 'o', 'w', '\0', }; static unsigned char misaligned_decoded5[] = { 'f', 'a', 's', 't', 'e', 'r', }; static unsigned char misaligned_decoded6[] = { 'F', 'a', 's', 't', 'R', 'P', 'C', }; static unsigned char misaligned_decoded7[] = { ':', 'D', }; static const struct fastrpc_io_buffer misaligned_decoded[] = { { .s = 1, .p = misaligned_decoded0, }, { .s = 10, .p = misaligned_decoded1, }, { .s = 3, .p = misaligned_decoded2, }, { .s = 4, .p = misaligned_decoded3, }, { .s = 5, .p = misaligned_decoded4, }, { .s = 6, .p = misaligned_decoded5, }, { .s = 7, .p = misaligned_decoded6, }, { .s = 2, .p = misaligned_decoded7, }, }; static int test_in_empty(void) { struct fastrpc_decoder_context *ctx; struct fastrpc_io_buffer *bufs; int complete; ctx = inbuf_decode_start(REMOTE_SCALARS_MAKE(1, 0, 2)); if (ctx == NULL) return 1; inbuf_decode(ctx, 0, NULL); complete = inbuf_decode_is_complete(ctx); if (!complete) return 1; bufs = inbuf_decode_finish(ctx); iobuf_free(0, bufs); return 0; } static int test_in_normal(void) { struct fastrpc_decoder_context *ctx; struct fastrpc_io_buffer *bufs; int complete; size_t i; int ret; ctx = inbuf_decode_start(REMOTE_SCALARS_MAKE(1, 8, 2)); if (ctx == NULL) return 1; complete = inbuf_decode_is_complete(ctx); if (complete) return 1; inbuf_decode(ctx, sizeof(misaligned_iobufs), misaligned_iobufs); complete = inbuf_decode_is_complete(ctx); if (!complete) return 1; bufs = inbuf_decode_finish(ctx); for (i = 0; i < 8; i++) { if (bufs[i].s != misaligned_decoded[i].s) return 1; ret = memcmp(bufs[i].p, misaligned_decoded[i].p, misaligned_decoded[i].s); if (ret) return 1; } iobuf_free(8, bufs); return 0; } static int test_in_misaligned(void) { struct fastrpc_decoder_context *ctx; struct fastrpc_io_buffer *bufs; int complete; size_t i; int ret; ctx = inbuf_decode_start(REMOTE_SCALARS_MAKE(1, 8, 2)); if (ctx == NULL) return 1; for (i = 0; i < sizeof(misaligned_iobufs); i++) { complete = inbuf_decode_is_complete(ctx); if (complete) return 1; inbuf_decode(ctx, 1, &misaligned_iobufs[i]); } complete = inbuf_decode_is_complete(ctx); if (!complete) return 1; bufs = inbuf_decode_finish(ctx); for (i = 0; i < 8; i++) { if (bufs[i].s != misaligned_decoded[i].s) return 1; ret = memcmp(bufs[i].p, misaligned_decoded[i].p, misaligned_decoded[i].s); if (ret) return 1; } iobuf_free(8, bufs); return 0; } static int test_out_empty(void) { size_t size; size = outbufs_calculate_size(0, NULL); if (size != 0) return 1; outbufs_encode(0, NULL, NULL); return 0; } static int test_out_misaligned(void) { size_t size; void *buf; int ret; size = outbufs_calculate_size(8, misaligned_decoded); if (size != sizeof(misaligned_iobufs)) return 1; buf = malloc(size); if (buf == NULL) return 1; outbufs_encode(8, misaligned_decoded, buf); ret = memcmp(buf, misaligned_iobufs, sizeof(misaligned_iobufs)); if (ret) return 1; free(buf); return 0; } int main(int argc, const char **argv) { int ret; ret = test_in_empty(); if (ret) return ret; ret = test_in_normal(); if (ret) return ret; ret = test_in_misaligned(); if (ret) return ret; ret = test_out_empty(); if (ret) return ret; ret = test_out_misaligned(); if (ret) return ret; return 0; }