pax_global_header00006660000000000000000000000064151725621450014522gustar00rootroot0000000000000052 comment=61fe107ff96a22e7df0029877529b7ce6da36850 crash-utility-crash-61fe107/000077500000000000000000000000001517256214500157545ustar00rootroot00000000000000crash-utility-crash-61fe107/.github/000077500000000000000000000000001517256214500173145ustar00rootroot00000000000000crash-utility-crash-61fe107/.github/workflows/000077500000000000000000000000001517256214500213515ustar00rootroot00000000000000crash-utility-crash-61fe107/.github/workflows/ci-build.yml000066400000000000000000000053501517256214500235670ustar00rootroot00000000000000name: Build on: push: branches: [ "master" ] jobs: build: name: Build runs-on: ubuntu-24.04 strategy: matrix: arch: - x86_64 - aarch64 - s390x - powerpc64 - x86 - riscv64 - mips - alpha - sparc64 steps: - name: Checkout uses: actions/checkout@v4 - name: Set Environment env: ARCH: ${{ matrix.arch }} run: | case $ARCH in x86) GNU_ARCH="i686-linux-gnu" ;; x86_64) CROSS_COMPILER_PKG="gcc-x86-64-linux-gnu" CROSS_COMPILER_PKG+=" g++-x86-64-linux-gnu" GNU_ARCH="$ARCH-linux-gnu" ;; *) GNU_ARCH="$ARCH-linux-gnu" ;; esac if [ -n "$GNU_ARCH" ]; then if [ -z "$CROSS_COMPILER_PKG" ]; then CROSS_COMPILER_PKG="gcc-$GNU_ARCH" CROSS_COMPILER_PKG+=" g++-$GNU_ARCH" fi EXTRA_PKGS+=" $CROSS_COMPILER_PKG" CROSS_COMPILE="$GNU_ARCH" fi echo "EXTRA_PKGS=$EXTRA_PKGS" >> $GITHUB_ENV echo "CROSS_COMPILE=$CROSS_COMPILE" >> $GITHUB_ENV - name: Install deps for crash-utility building run: | sudo apt-get update sudo apt-get install make gcc g++ bison flex texinfo wget patch tar build-essential libc-dev autoconf automake libncurses-dev - name: Install corss compile tool pkgs if: env.EXTRA_PKGS != '' run: | sudo apt-get update sudo apt-get -q=2 install ${{ env.EXTRA_PKGS }} - name: Cross compile gmp lib run: | mkdir $GITHUB_WORKSPACE/libtools wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2 tar -jxvf gmp-6.2.1.tar.bz2 cd gmp-6.2.1 ./configure --host=${{ env.CROSS_COMPILE }} --prefix=$GITHUB_WORKSPACE/libtools make -j`nproc` sudo make install cd .. - name: Cross compile mpfr lib run: | wget https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2 tar -jxvf mpfr-4.1.0.tar.bz2 cd mpfr-4.1.0 ./configure --host=${{ env.CROSS_COMPILE }} --prefix=$GITHUB_WORKSPACE/libtools --with-gmp=$GITHUB_WORKSPACE/libtools make -j`nproc` sudo make install cd .. - name: Cross compile crash-utility run: | sudo cp $GITHUB_WORKSPACE/libtools/include/* /usr/include/ sudo cp -r $GITHUB_WORKSPACE/libtools/lib/* /usr/lib/ make CROSS_COMPILE=${{ env.CROSS_COMPILE }}- -j`nproc` warn - name: Checking and Clean up run: | echo "Run command: file crash ..." file crash echo "Clean up for compiling ..." make CROSS_COMPILE=${{ env.CROSS_COMPILE }}- -j`nproc` clean crash-utility-crash-61fe107/.github/workflows/ci-test.yml000066400000000000000000000020471517256214500234470ustar00rootroot00000000000000name: Testing Farm CI on: schedule: - cron: '10 2 * * 1' jobs: cron_schedule: name: Testing Farm CI (${{ matrix.arch }} ${{ matrix.compose }}) runs-on: ubuntu-latest timeout-minutes: 90 strategy: fail-fast: false matrix: arch: [x86_64] compose: [Fedora-Rawhide] steps: - name: Checkout repository uses: actions/checkout@v4 - name: Checking TF_API_KEY run: | if [ -z "${{ secrets.TF_API_KEY }}" ]; then echo "TF_API_KEY is empty!" exit 1 else echo "TF_API_KEY is set!" fi - name: Schedule tests on Testing Farm id: testing-farm uses: sclorg/testing-farm-as-github-action@v4 with: api_key: ${{ secrets.TF_API_KEY }} git_url: https://github.com/crash-utility/crash.git tf_scope: private git_ref: master tmt_path: ci-tests tmt_plan_regex: local$ compose: ${{ matrix.compose }} arch: ${{ matrix.arch }} crash-utility-crash-61fe107/.github/workflows/pr-closer.yml000066400000000000000000000007241517256214500240050ustar00rootroot00000000000000name: Close Pull Request on: pull_request_target: types: [opened, reopened] jobs: run: runs-on: ubuntu-latest steps: - uses: superbrothers/close-pull-request@v3 with: comment: "The github repo does not accept PRs, please subscribe to mail list via https://lists.crash-utility.osci.io/admin/lists/devel.lists.crash-utility.osci.io/ for contribution and discussion. Or post your patch to mail list: devel@lists.crash-utility.osci.io" crash-utility-crash-61fe107/.gitignore000066400000000000000000000004721517256214500177470ustar00rootroot00000000000000configure build_data.c cscope.out crashlib.a *.o crash CFLAGS.extra LDFLAGS.extra crash.spec *.gz *.rpm gdb.files gdb-7.6/ gdb-10.2/ gdb-16.2/ extensions/defs.h extensions/*.so extensions/eppic # cscope files cscope.* ncscope.* # ctags files tags TAGS # Clang's compilation database file /compile_commands.json crash-utility-crash-61fe107/.rh_rpm_package000066400000000000000000000000061517256214500207130ustar00rootroot000000000000009.0.2 crash-utility-crash-61fe107/COPYING3000066400000000000000000001045131517256214500170760ustar00rootroot00000000000000 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 . crash-utility-crash-61fe107/Makefile000066400000000000000000000661751517256214500174330ustar00rootroot00000000000000# Makefile for core analysis suite # # Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. # www.missioncriticallinux.com, info@missioncriticallinux.com # # Copyright (C) 2002-2016 David Anderson # Copyright (C) 2002-2016 Red Hat, Inc. All rights reserved. # # 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 2 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. # MAKEFLAGS += --no-print-directory PROGRAM=crash # # Supported targets: X86 ALPHA PPC IA64 PPC64 SPARC64 # TARGET and GDB_CONF_FLAGS will be configured automatically by configure # TARGET= GDB_CONF_FLAGS= # Supported arches for cross compilation: x86_64, x86, aarch64, s390x, # powerpc64, alpha, sparc64, mips, riscv64 # E.g: cross compile crash-utility for aarch64 on X86_64 # make CROSS_COMPILE=aarch64-linux-gnu- -j`nproc` # or # make CROSS_COMPILE=aarch64-linux-gnu- -j`nproc` warn # ifneq ($(CROSS_COMPILE),) ARCH := $(shell echo $(CROSS_COMPILE) | sed 's:^.*/::g' | cut -d- -f1) else ARCH := $(shell uname -m) endif ARCH := $(shell echo $(ARCH) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/) CC = $(CROSS_COMPILE)gcc CXX = $(CROSS_COMPILE)g++ HOSTCC = gcc ifeq (${ARCH}, ppc64) CONF_FLAGS = -m64 endif ifneq ($(CROSS_COMPILE),) ifeq (${ARCH}, x86_64) CONF_TARGET_ARCH := X86_64 else ifeq (${ARCH}, aarch64) CONF_TARGET_ARCH := ARM64 else ifeq (${ARCH}, s390x) CONF_TARGET_ARCH := S390X else ifeq (${ARCH}, powerpc64) CONF_TARGET_ARCH := PPC64 else ifeq (${ARCH}, ppc64le) CONF_TARGET_ARCH := PPC64 else ifeq (${ARCH}, alpha) CONF_TARGET_ARCH := ALPHA else ifeq (${ARCH}, i386) CONF_TARGET_ARCH := X86 else ifeq (${ARCH}, mips) CONF_TARGET_ARCH := MIPS else ifeq (${ARCH}, sparc64) CONF_TARGET_ARCH := SPARC64 else ifeq (${ARCH}, riscv64) CONF_TARGET_ARCH := RISCV64 else $(error The current Arch(${ARCH}) does not support cross compilation) endif CONF_FLAGS += -DCONF_TARGET_ARCH=${CONF_TARGET_ARCH} CONF_FLAGS += -DGDB_TARGET_DEFAULT="\"GDB_CONF_FLAGS=--host=$(shell echo $(CROSS_COMPILE) | sed -e 's:^.*/::g' -e 's/-$$//')\"" endif # # GDB, GDB_FILES, GDB_OFILES and GDB_PATCH_FILES will be configured automatically by configure # GDB= GDB_FILES= GDB_OFILES= GDB_PATCH_FILES= # # Default installation directory # INSTALLDIR=${DESTDIR}/usr/bin # LDFLAGS will be configured automatically by configure LDFLAGS= GENERIC_HFILES=defs.h xen_hyper_defs.h xen_dom0.h MCORE_HFILES=va_server.h vas_crash.h REDHAT_HFILES=netdump.h diskdump.h makedumpfile.h xendump.h kvmdump.h qemu-load.h vmcore.h LKCD_DUMP_HFILES=lkcd_vmdump_v1.h lkcd_vmdump_v2_v3.h lkcd_dump_v5.h \ lkcd_dump_v7.h lkcd_dump_v8.h LKCD_OBSOLETE_HFILES=lkcd_fix_mem.h LKCD_TRACE_HFILES=lkcd_x86_trace.h IBM_HFILES=ibm_common.h SADUMP_HFILES=sadump.h UNWIND_HFILES=unwind.h unwind_i.h rse.h unwind_x86.h unwind_x86_64.h VMWARE_HFILES=vmware_vmss.h MAPLE_TREE_HFILES=maple_tree.h LZORLE_HFILES=lzorle_decompress.h CFILES=main.c tools.c global_data.c memory.c filesys.c help.c task.c \ kernel.c test.c gdb_interface.c configure.c net.c dev.c bpf.c \ printk.c \ alpha.c x86.c ppc.c ia64.c s390.c s390x.c s390dbf.c ppc64.c x86_64.c \ arm.c arm64.c mips.c mips64.c riscv64.c loongarch64.c sparc64.c \ extensions.c remote.c va_server.c va_server_v1.c symbols.c cmdline.c \ lkcd_common.c lkcd_v1.c lkcd_v2_v3.c lkcd_v5.c lkcd_v7.c lkcd_v8.c\ lkcd_fix_mem.c s390_dump.c lkcd_x86_trace.c \ netdump.c diskdump.c makedumpfile.c xendump.c unwind.c unwind_decoder.c \ unwind_x86_32_64.c unwind_arm.c \ xen_hyper.c xen_hyper_command.c xen_hyper_global_data.c \ xen_hyper_dump_tables.c kvmdump.c qemu.c qemu-load.c sadump.c ipcs.c \ ramdump.c vmware_vmss.c vmware_guestdump.c \ xen_dom0.c kaslr_helper.c sbitmap.c maple_tree.c \ lzorle_decompress.c SOURCE_FILES=${CFILES} ${GENERIC_HFILES} ${MCORE_HFILES} \ ${REDHAT_CFILES} ${REDHAT_HFILES} ${UNWIND_HFILES} \ ${LKCD_DUMP_HFILES} ${LKCD_TRACE_HFILES} ${LKCD_OBSOLETE_HFILES}\ ${IBM_HFILES} ${SADUMP_HFILES} ${VMWARE_HFILES} ${MAPLE_TREE_HFILES} \ ${LZORLE_HFILES} OBJECT_FILES=main.o tools.o global_data.o memory.o filesys.o help.o task.o \ build_data.o kernel.o test.o gdb_interface.o net.o dev.o bpf.o \ printk.o \ alpha.o x86.o ppc.o ia64.o s390.o s390x.o s390dbf.o ppc64.o x86_64.o \ arm.o arm64.o mips.o mips64.o riscv64.o loongarch64.o sparc64.o \ extensions.o remote.o va_server.o va_server_v1.o symbols.o cmdline.o \ lkcd_common.o lkcd_v1.o lkcd_v2_v3.o lkcd_v5.o lkcd_v7.o lkcd_v8.o \ lkcd_fix_mem.o s390_dump.o netdump.o diskdump.o makedumpfile.o xendump.o \ lkcd_x86_trace.o unwind_v1.o unwind_v2.o unwind_v3.o \ unwind_x86_32_64.o unwind_arm.o \ xen_hyper.o xen_hyper_command.o xen_hyper_global_data.o \ xen_hyper_dump_tables.o kvmdump.o qemu.o qemu-load.o sadump.o ipcs.o \ ramdump.o vmware_vmss.o vmware_guestdump.o \ xen_dom0.o kaslr_helper.o sbitmap.o maple_tree.o \ lzorle_decompress.o MEMORY_DRIVER_FILES=memory_driver/Makefile memory_driver/crash.c memory_driver/README # These are the current set of crash extensions sources. They are not built # by default unless the third command line of the "all:" stanza is uncommented. # Alternatively, they can be built by entering "make extensions" from this # directory. EXTENSIONS=extensions EXTENSION_SOURCE_FILES=${EXTENSIONS}/Makefile ${EXTENSIONS}/echo.c ${EXTENSIONS}/dminfo.c \ ${EXTENSIONS}/snap.c ${EXTENSIONS}/snap.mk ${EXTENSIONS}/trace.c \ ${EXTENSIONS}/eppic.c ${EXTENSIONS}/eppic.mk DAEMON_OBJECT_FILES=remote_daemon.o va_server.o va_server_v1.o \ lkcd_common.o lkcd_v1.o lkcd_v2_v3.o lkcd_v5.o lkcd_v7.o lkcd_v8.o \ s390_dump.o netdump_daemon.o GDB_5.0_FILES=${GDB}/gdb/Makefile.in \ ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ ${GDB}/gdb/blockframe.c ${GDB}/gdb/alpha-tdep.c \ ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/gnu-regex.c \ ${GDB}/gdb/ppc-linux-nat.c GDB_5.0_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o ${GDB}/gdb/target.o \ ${GDB}/gdb/blockframe.o ${GDB}/gdb/alpha-tdep.o \ ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o ${GDB}/gdb/gnu-regex.o \ ${GDB}/gdb/ppc-linux-nat.o GDB_5.1_FILES=${GDB}/gdb/Makefile.in \ ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ ${GDB}/gdb/blockframe.c ${GDB}/gdb/alpha-tdep.c \ ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/gnu-regex.c GDB_5.1_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o ${GDB}/gdb/target.o \ ${GDB}/gdb/blockframe.o ${GDB}/gdb/alpha-tdep.o \ ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o ${GDB}/gdb/gnu-regex.o GDB_5.2.1_FILES=${GDB}/gdb/Makefile.in \ ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ ${GDB}/gdb/blockframe.c ${GDB}/gdb/alpha-tdep.c \ ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c GDB_5.2.1_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o ${GDB}/gdb/target.o \ ${GDB}/gdb/blockframe.o ${GDB}/gdb/alpha-tdep.o \ ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o GDB_5.3post-0.20021129.36rh_FILES=${GDB}/gdb/Makefile.in \ ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ ${GDB}/gdb/frame.c ${GDB}/gdb/alpha-tdep.c \ ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/dwarf2read.c GDB_5.3post-0.20021129.36rh_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o \ ${GDB}/gdb/target.o ${GDB}/gdb/frame.o ${GDB}/gdb/alpha-tdep.o \ ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o ${GDB}/gdb/ui-file.o \ ${GDB}/gdb/utils.o ${GDB}/gdb/dwarf2read.o GDB_6.0_FILES=${GDB}/gdb/Makefile.in ${GDB}/Makefile.in \ ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c \ ${GDB}/gdb/ppc-linux-tdep.c ${GDB}/sim/ppc/ppc-instructions \ ${GDB}/bfd/simple.c ${GDB}/include/obstack.h GDB_6.0_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o \ ${GDB}/gdb/target.o ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o \ ${GDB}/gdb/ppc-linux-tdep.o ${GDB}/bfd/simple.o GDB_6.1_FILES=${GDB}/gdb/Makefile.in ${GDB}/Makefile.in \ ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/dwarf2read.c \ ${GDB}/include/obstack.h ${GDB}/gdb/ppc-linux-tdep.c GDB_6.1_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o \ ${GDB}/gdb/target.o ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o ${GDB}/gdb/dwarf2read.o \ ${GDB}/gdb/ppc-linux-tdep.o GDB_7.0_FILES= GDB_7.0_OFILES=${GDB}/gdb/symtab.o GDB_7.3.1_FILES= GDB_7.3.1_OFILES=${GDB}/gdb/symtab.o GDB_7.6_FILES= GDB_7.6_OFILES=${GDB}/gdb/symtab.o GDB_10.2_FILES= GDB_10.2_OFILES=${GDB}/gdb/symtab.o crash_target.o GDB_16.2_FILES= GDB_16.2_OFILES=${GDB}/gdb/symtab.o crash_target.o # # GDB_FLAGS is passed up from the gdb Makefile. # GDB_FLAGS= # # WARNING_OPTIONS and WARNING_ERROR are both applied on a per-file basis. # WARNING_ERROR is NOT used on files including "dirty" gdb headers so that # successful compilations can be achieved with acceptable warnings; its # usefulness is also dependent upon the processor's compiler -- your mileage # may vary. # #WARNING_OPTIONS=-Wall -O2 -Wstrict-prototypes -Wmissing-prototypes -fstack-protector -Wformat-security #WARNING_ERROR=-Werror # TARGET_CFLAGS will be configured automatically by configure TARGET_CFLAGS= CRASH_CFLAGS=-g -D${TARGET} ${TARGET_CFLAGS} ${GDB_FLAGS} ${CFLAGS} GPL_FILES= TAR_FILES=${SOURCE_FILES} Makefile ${GPL_FILES} README .rh_rpm_package crash.8 \ ${EXTENSION_SOURCE_FILES} ${MEMORY_DRIVER_FILES} CSCOPE_FILES=${SOURCE_FILES} READLINE_DIRECTORY=./${GDB}/readline/readline BFD_DIRECTORY=./${GDB}/bfd GDB_INCLUDE_DIRECTORY=./${GDB}/include REDHATFLAGS=-DREDHAT # target could be set on command line when invoking make. Like: make target=ARM # otherwise target will be the same as the host ifneq ($(target),) CONF_TARGET_FLAG="-t$(target)" endif ifeq ($(findstring warn,$(MAKECMDGOALS)),warn) CONF_TARGET_FLAG += -w endif ifeq ($(findstring Warn,$(MAKECMDGOALS)),Warn) CONF_TARGET_FLAG += -W endif ifeq ($(findstring nowarn,$(MAKECMDGOALS)),nowarn) CONF_TARGET_FLAG += -n endif ifeq ($(findstring lzo,$(MAKECMDGOALS)),lzo) CONF_TARGET_FLAG += -x lzo endif ifeq ($(findstring snappy,$(MAKECMDGOALS)),snappy) CONF_TARGET_FLAG += -x snappy endif ifeq ($(findstring zstd,$(MAKECMDGOALS)),zstd) CONF_TARGET_FLAG += -x zstd endif ifeq ($(findstring valgrind,$(MAKECMDGOALS)),valgrind) CONF_TARGET_FLAG += -x valgrind endif # To build the extensions library by default, uncomment the third command # line below. Otherwise they can be built by entering "make extensions". all: make_configure @./configure ${CONF_TARGET_FLAG} -p "RPMPKG=${RPMPKG}" -b @$(MAKE) gdb_merge # @$(MAKE) extensions gdb_merge: force @if [ ! -f ${GDB}/README ]; then \ $(MAKE) gdb_unzip; fi @echo "${LDFLAGS} -lz -ldl -rdynamic" > ${GDB}/gdb/mergelibs @echo "../../${PROGRAM} ../../${PROGRAM}lib.a" > ${GDB}/gdb/mergeobj @rm -f ${PROGRAM} @if [ ! -f ${GDB}/config.status ]; then \ (cd ${GDB}; ./configure ${GDB_CONF_FLAGS} --with-separate-debug-dir=/usr/lib/debug \ --with-bugurl="" --with-expat=no --with-python=no --disable-sim; \ $(MAKE) CRASH_TARGET=${TARGET}; echo ${TARGET} > crash.target) \ else $(MAKE) rebuild; fi @if [ ! -f ${PROGRAM} ]; then \ echo; echo "${PROGRAM} build failed"; \ echo; exit 1; fi rebuild: @if [ ! -f ${GDB}/${GDB}.patch ]; then \ touch ${GDB}/${GDB}.patch; fi @if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ] && \ [ "`md5sum < ${GDB}.patch`" != "`md5sum < ${GDB}/${GDB}.patch`" ]; then \ (sh -x ${GDB}.patch ${TARGET}; patch -N -p0 -r- --fuzz=0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; cd ${GDB}; \ $(MAKE) CRASH_TARGET=${TARGET}) \ else (cd ${GDB}/gdb; $(MAKE) CRASH_TARGET=${TARGET}); fi gdb_unzip: @rm -f gdb.files @for FILE in ${GDB_FILES} dummy; do\ echo $$FILE >> gdb.files; done @if [ ! -f ${GDB}.tar.gz ] && [ ! -f /usr/bin/wget ]; then \ echo /usr/bin/wget is required to download ${GDB}.tar.gz; echo; exit 1; fi @if [ ! -f ${GDB}.tar.gz ] && [ -f /usr/bin/wget ]; then \ [ ! -t 2 ] && WGET_OPTS="--progress=dot:mega"; \ wget $$WGET_OPTS http://ftp.gnu.org/gnu/gdb/${GDB}.tar.gz; fi @tar --exclude-from gdb.files -xzmf ${GDB}.tar.gz @$(MAKE) gdb_patch gdb_patch: if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ]; then \ patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi library: ${OBJECT_FILES} ar -rs ${PROGRAM}lib.a ${OBJECT_FILES} gdb: force rm -f ${GDB_OFILES} @$(MAKE) all force: make_configure: force @rm -f configure @${HOSTCC} ${CONF_FLAGS} -o configure configure.c ${WARNING_ERROR} ${WARNING_OPTIONS} clean: make_configure @./configure ${CONF_TARGET_FLAG} -q -b @$(MAKE) do_clean do_clean: rm -f ${OBJECT_FILES} ${DAEMON_OBJECT_FILES} ${PROGRAM} ${PROGRAM}lib.a ${GDB_OFILES} @$(MAKE) -C extensions -i clean @$(MAKE) -C memory_driver -i clean build_data.o: force ${CC} -c ${CRASH_CFLAGS} build_data.c ${WARNING_OPTIONS} ${WARNING_ERROR} install: /usr/bin/install -d ${INSTALLDIR} /usr/bin/install ${PROGRAM} ${INSTALLDIR} # /usr/bin/install ${PROGRAM}d ${INSTALLDIR} unconfig: make_configure @./configure -u warn Warn nowarn lzo snappy zstd valgrind: all @true #dummy main.o: ${GENERIC_HFILES} main.c ${CC} -c ${CRASH_CFLAGS} main.c ${WARNING_OPTIONS} ${WARNING_ERROR} cmdline.o: ${GENERIC_HFILES} cmdline.c ${CC} -c ${CRASH_CFLAGS} cmdline.c -I${READLINE_DIRECTORY} ${WARNING_OPTIONS} ${WARNING_ERROR} tools.o: ${GENERIC_HFILES} tools.c ${CC} -c ${CRASH_CFLAGS} tools.c ${WARNING_OPTIONS} ${WARNING_ERROR} sbitmap.o: ${GENERIC_HFILES} sbitmap.c ${CC} -c ${CRASH_CFLAGS} sbitmap.c ${WARNING_OPTIONS} ${WARNING_ERROR} global_data.o: ${GENERIC_HFILES} global_data.c ${CC} -c ${CRASH_CFLAGS} global_data.c ${WARNING_OPTIONS} ${WARNING_ERROR} symbols.o: ${GENERIC_HFILES} symbols.c ${CC} -c ${CRASH_CFLAGS} symbols.c -I${BFD_DIRECTORY} -I${GDB_INCLUDE_DIRECTORY} ${WARNING_OPTIONS} ${WARNING_ERROR} filesys.o: ${GENERIC_HFILES} filesys.c ${CC} -c ${CRASH_CFLAGS} filesys.c ${WARNING_OPTIONS} ${WARNING_ERROR} help.o: ${GENERIC_HFILES} help.c ${CC} -c ${CRASH_CFLAGS} help.c ${WARNING_OPTIONS} ${WARNING_ERROR} memory.o: ${GENERIC_HFILES} ${MAPLE_TREE_HFILES} memory.c ${CC} -c ${CRASH_CFLAGS} memory.c ${WARNING_OPTIONS} ${WARNING_ERROR} test.o: ${GENERIC_HFILES} test.c ${CC} -c ${CRASH_CFLAGS} test.c ${WARNING_OPTIONS} ${WARNING_ERROR} task.o: ${GENERIC_HFILES} task.c ${CC} -c ${CRASH_CFLAGS} task.c ${WARNING_OPTIONS} ${WARNING_ERROR} kernel.o: ${GENERIC_HFILES} kernel.c ${CC} -c ${CRASH_CFLAGS} kernel.c -I${BFD_DIRECTORY} -I${GDB_INCLUDE_DIRECTORY} ${WARNING_OPTIONS} ${WARNING_ERROR} printk.o: ${GENERIC_HFILES} printk.c ${CC} -c ${CRASH_CFLAGS} printk.c -I${GDB_INCLUDE_DIRECTORY} ${WARNING_OPTIONS} ${WARNING_ERROR} gdb_interface.o: ${GENERIC_HFILES} gdb_interface.c ${CC} -c ${CRASH_CFLAGS} gdb_interface.c ${WARNING_OPTIONS} ${WARNING_ERROR} va_server.o: ${MCORE_HFILES} va_server.c ${CC} -c ${CRASH_CFLAGS} va_server.c ${WARNING_OPTIONS} ${WARNING_ERROR} va_server_v1.o: ${MCORE_HFILES} va_server_v1.c ${CC} -c ${CRASH_CFLAGS} va_server_v1.c ${WARNING_OPTIONS} ${WARNING_ERROR} lkcd_common.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_common.c ${CC} -c ${CRASH_CFLAGS} lkcd_common.c ${WARNING_OPTIONS} ${WARNING_ERROR} lkcd_v1.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_v1.c ${CC} -c ${CRASH_CFLAGS} lkcd_v1.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} lkcd_v2_v3.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_v2_v3.c ${CC} -c ${CRASH_CFLAGS} lkcd_v2_v3.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} lkcd_v5.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_v5.c ${CC} -c ${CRASH_CFLAGS} lkcd_v5.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} lkcd_v7.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_v7.c ${CC} -c ${CRASH_CFLAGS} lkcd_v7.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} lkcd_v8.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_v8.c ${CC} -c ${CRASH_CFLAGS} lkcd_v8.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} net.o: ${GENERIC_HFILES} net.c ${CC} -c ${CRASH_CFLAGS} net.c ${WARNING_OPTIONS} ${WARNING_ERROR} dev.o: ${GENERIC_HFILES} ${REDHAT_HFILES} dev.c ${CC} -c ${CRASH_CFLAGS} dev.c ${WARNING_OPTIONS} ${WARNING_ERROR} # remote.c functionality has been deprecated remote.o: ${GENERIC_HFILES} remote.c @${CC} -c ${CRASH_CFLAGS} remote.c ${WARNING_OPTIONS} ${WARNING_ERROR} remote_daemon.o: ${GENERIC_HFILES} remote.c ${CC} -c ${CRASH_CFLAGS} -DDAEMON remote.c -o remote_daemon.o ${WARNING_OPTIONS} ${WARNING_ERROR} x86.o: ${GENERIC_HFILES} ${REDHAT_HFILES} x86.c ${CC} -c ${CRASH_CFLAGS} x86.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} alpha.o: ${GENERIC_HFILES} alpha.c ${CC} -c ${CRASH_CFLAGS} alpha.c ${WARNING_OPTIONS} ${WARNING_ERROR} ppc.o: ${GENERIC_HFILES} ppc.c ${CC} -c ${CRASH_CFLAGS} ppc.c ${WARNING_OPTIONS} ${WARNING_ERROR} ia64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} ia64.c ${CC} -c ${CRASH_CFLAGS} ia64.c ${WARNING_OPTIONS} ${WARNING_ERROR} ppc64.o: ${GENERIC_HFILES} ppc64.c ${CC} -c ${CRASH_CFLAGS} ppc64.c ${WARNING_OPTIONS} ${WARNING_ERROR} x86_64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} x86_64.c ${CC} -c ${CRASH_CFLAGS} x86_64.c ${WARNING_OPTIONS} ${WARNING_ERROR} arm.o: ${GENERIC_HFILES} ${REDHAT_HFILES} arm.c ${CC} -c ${CRASH_CFLAGS} arm.c ${WARNING_OPTIONS} ${WARNING_ERROR} arm64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} arm64.c ${CC} -c ${CRASH_CFLAGS} arm64.c ${WARNING_OPTIONS} ${WARNING_ERROR} mips.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips.c ${CC} -c ${CRASH_CFLAGS} mips.c ${WARNING_OPTIONS} ${WARNING_ERROR} mips64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips64.c ${CC} -c ${CRASH_CFLAGS} mips64.c ${WARNING_OPTIONS} ${WARNING_ERROR} riscv64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} riscv64.c ${CC} -c ${CRASH_CFLAGS} riscv64.c ${WARNING_OPTIONS} ${WARNING_ERROR} sparc64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} sparc64.c ${CC} -c ${CRASH_CFLAGS} sparc64.c ${WARNING_OPTIONS} ${WARNING_ERROR} loongarch64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} loongarch64.c ${CC} -c ${CRASH_CFLAGS} loongarch64.c ${WARNING_OPTIONS} ${WARNING_ERROR} s390.o: ${GENERIC_HFILES} ${IBM_HFILES} s390.c ${CC} -c ${CRASH_CFLAGS} s390.c ${WARNING_OPTIONS} ${WARNING_ERROR} s390x.o: ${GENERIC_HFILES} ${IBM_HFILES} s390x.c ${CC} -c ${CRASH_CFLAGS} s390x.c ${WARNING_OPTIONS} ${WARNING_ERROR} s390dbf.o: ${GENERIC_HFILES} ${IBM_HFILES} s390dbf.c ${CC} -c ${CRASH_CFLAGS} s390dbf.c ${WARNING_OPTIONS} ${WARNING_ERROR} s390_dump.o: ${GENERIC_HFILES} ${IBM_HFILES} s390_dump.c ${CC} -c ${CRASH_CFLAGS} s390_dump.c ${WARNING_OPTIONS} ${WARNING_ERROR} netdump.o: ${GENERIC_HFILES} ${REDHAT_HFILES} ${SADUMP_HFILES} netdump.c ${CC} -c ${CRASH_CFLAGS} netdump.c ${WARNING_OPTIONS} ${WARNING_ERROR} netdump_daemon.o: ${GENERIC_HFILES} ${REDHAT_HFILES} netdump.c ${CC} -c ${CRASH_CFLAGS} -DDAEMON netdump.c -o netdump_daemon.o ${WARNING_OPTIONS} ${WARNING_ERROR} diskdump.o: ${GENERIC_HFILES} ${REDHAT_HFILES} diskdump.c ${CC} -c ${CRASH_CFLAGS} diskdump.c ${WARNING_OPTIONS} ${WARNING_ERROR} makedumpfile.o: ${GENERIC_HFILES} ${REDHAT_HFILES} makedumpfile.c ${CC} -c ${CRASH_CFLAGS} makedumpfile.c ${WARNING_OPTIONS} ${WARNING_ERROR} xendump.o: ${GENERIC_HFILES} ${REDHAT_HFILES} xendump.c ${CC} -c ${CRASH_CFLAGS} xendump.c ${WARNING_OPTIONS} ${WARNING_ERROR} kvmdump.o: ${GENERIC_HFILES} ${REDHAT_HFILES} kvmdump.c ${CC} -c ${CRASH_CFLAGS} kvmdump.c ${WARNING_OPTIONS} ${WARNING_ERROR} qemu.o: ${GENERIC_HFILES} ${REDHAT_HFILES} qemu.c ${CC} -c ${CRASH_CFLAGS} qemu.c ${WARNING_OPTIONS} ${WARNING_ERROR} qemu-load.o: ${GENERIC_HFILES} ${REDHAT_HFILES} qemu-load.c ${CC} -c ${CRASH_CFLAGS} qemu-load.c ${WARNING_OPTIONS} ${WARNING_ERROR} sadump.o: ${GENERIC_HFILES} ${SADUMP_HFILES} sadump.c ${CC} -c ${CRASH_CFLAGS} sadump.c ${WARNING_OPTIONS} ${WARNING_ERROR} ipcs.o: ${GENERIC_HFILES} ipcs.c ${CC} -c ${CRASH_CFLAGS} ipcs.c ${WARNING_OPTIONS} ${WARNING_ERROR} extensions.o: ${GENERIC_HFILES} extensions.c ${CC} -c ${CRASH_CFLAGS} extensions.c ${WARNING_OPTIONS} ${WARNING_ERROR} lkcd_x86_trace.o: ${GENERIC_HFILES} ${LKCD_TRACE_HFILES} lkcd_x86_trace.c ${CC} -c ${CRASH_CFLAGS} lkcd_x86_trace.c -DREDHAT ${WARNING_OPTIONS} ${WARNING_ERROR} unwind_x86_32_64.o: ${GENERIC_HFILES} ${UNWIND_HFILES} unwind_x86_32_64.c ${CC} -c ${CRASH_CFLAGS} unwind_x86_32_64.c -o unwind_x86_32_64.o ${WARNING_OPTIONS} ${WARNING_ERROR} unwind_arm.o: ${GENERIC_HFILES} ${UNWIND_HFILES} unwind_arm.c ${CC} -c ${CRASH_CFLAGS} unwind_arm.c -o unwind_arm.o ${WARNING_OPTIONS} ${WARNING_ERROR} unwind_v1.o: ${GENERIC_HFILES} ${UNWIND_HFILES} unwind.c unwind_decoder.c ${CC} -c ${CRASH_CFLAGS} unwind.c -DREDHAT -DUNWIND_V1 -o unwind_v1.o ${WARNING_OPTIONS} ${WARNING_ERROR} unwind_v2.o: ${GENERIC_HFILES} ${UNWIND_HFILES} unwind.c unwind_decoder.c ${CC} -c ${CRASH_CFLAGS} unwind.c -DREDHAT -DUNWIND_V2 -o unwind_v2.o ${WARNING_OPTIONS} ${WARNING_ERROR} unwind_v3.o: ${GENERIC_HFILES} ${UNWIND_HFILES} unwind.c unwind_decoder.c ${CC} -c ${CRASH_CFLAGS} unwind.c -DREDHAT -DUNWIND_V3 -o unwind_v3.o ${WARNING_OPTIONS} ${WARNING_ERROR} lkcd_fix_mem.o: ${GENERIC_HFILES} ${LKCD_HFILES} lkcd_fix_mem.c ${CC} -c ${CRASH_CFLAGS} lkcd_fix_mem.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} xen_hyper.o: ${GENERIC_HFILES} xen_hyper.c ${CC} -c ${CRASH_CFLAGS} xen_hyper.c ${WARNING_OPTIONS} ${WARNING_ERROR} xen_hyper_command.o: ${GENERIC_HFILES} xen_hyper_command.c ${CC} -c ${CRASH_CFLAGS} xen_hyper_command.c ${WARNING_OPTIONS} ${WARNING_ERROR} xen_hyper_global_data.o: ${GENERIC_HFILES} xen_hyper_global_data.c ${CC} -c ${CRASH_CFLAGS} xen_hyper_global_data.c ${WARNING_OPTIONS} ${WARNING_ERROR} xen_hyper_dump_tables.o: ${GENERIC_HFILES} xen_hyper_dump_tables.c ${CC} -c ${CRASH_CFLAGS} xen_hyper_dump_tables.c ${WARNING_OPTIONS} ${WARNING_ERROR} xen_dom0.o: ${GENERIC_HFILES} xen_dom0.c ${CC} -c ${CRASH_CFLAGS} xen_dom0.c ${WARNING_OPTIONS} ${WARNING_ERROR} ramdump.o: ${GENERIC_HFILES} ${REDHAT_HFILES} ramdump.c ${CC} -c ${CRASH_CFLAGS} ramdump.c ${WARNING_OPTIONS} ${WARNING_ERROR} vmware_vmss.o: ${GENERIC_HFILES} ${VMWARE_HFILES} vmware_vmss.c ${CC} -c ${CRASH_CFLAGS} vmware_vmss.c ${WARNING_OPTIONS} ${WARNING_ERROR} vmware_guestdump.o: ${GENERIC_HFILES} ${VMWARE_HFILES} vmware_guestdump.c ${CC} -c ${CRASH_CFLAGS} vmware_guestdump.c ${WARNING_OPTIONS} ${WARNING_ERROR} kaslr_helper.o: ${GENERIC_HFILES} kaslr_helper.c ${CC} -c ${CRASH_CFLAGS} kaslr_helper.c ${WARNING_OPTIONS} ${WARNING_ERROR} bpf.o: ${GENERIC_HFILES} bpf.c ${CC} -c ${CRASH_CFLAGS} bpf.c ${WARNING_OPTIONS} ${WARNING_ERROR} maple_tree.o: ${GENERIC_HFILES} ${MAPLE_TREE_HFILES} maple_tree.c ${CC} -c ${CRASH_CFLAGS} maple_tree.c ${WARNING_OPTIONS} ${WARNING_ERROR} lzorle_decompress.o: lzorle_decompress.c ${CC} -c ${CRASH_CFLAGS} lzorle_decompress.c ${WARNING_OPTIONS} ${WARNING_ERROR} ${PROGRAM}: force @$(MAKE) all # Remote daemon functionality has been deprecated. daemon_deprecated: force @echo "WARNING: remote daemon functionality has been deprecated" @echo ${PROGRAM}d: daemon_deprecated make_configure @./configure -d @$(MAKE) build_data.o @$(MAKE) daemon daemon: ${DAEMON_OBJECT_FILES} ${CC} ${LDFLAGS} -o ${PROGRAM}d ${DAEMON_OBJECT_FILES} build_data.o -lz files: make_configure @./configure -q -b @$(MAKE) show_files gdb_files: make_configure @./configure -q -b @echo ${GDB_FILES} ${GDB_PATCH_FILES} show_files: @if [ -f ${PROGRAM} ]; then \ ./${PROGRAM} --no_scroll --no_crashrc -h README > README; fi @echo ${SOURCE_FILES} Makefile ${GDB_FILES} ${GDB_PATCH_FILES} ${GPL_FILES} README \ .rh_rpm_package crash.8 ${EXTENSION_SOURCE_FILES} ${MEMORY_DRIVER_FILES} ctags: ctags ${SOURCE_FILES} tar: make_configure @./configure -q -b @$(MAKE) do_tar do_tar: @if [ -f ${PROGRAM} ]; then \ ./${PROGRAM} --no_scroll --no_crashrc -h README > README; fi tar cvzf ${PROGRAM}.tar.gz ${TAR_FILES} ${GDB_FILES} ${GDB_PATCH_FILES} @echo; ls -l ${PROGRAM}.tar.gz VERSION= RELEASE=0 release: make_configure @if [ "`id --user`" != "0" ]; then \ echo "make release: must be super-user"; exit 1; fi @./configure -P "RPMPKG=${RPMPKG}" -u -g @$(MAKE) release_configure @echo @echo "cvs tag this release if necessary" release_configure: make_configure @if [ "${GDB}" = "" ] ; then \ echo "make release: GDB not defined: append GDB=gdb-x.x to make command line"; echo; exit 1; fi @./configure -r ${GDB} @$(MAKE) do_release do_release: @echo "CRASH VERSION: ${VERSION} GDB VERSION: ${GDB}" @if [ ! -f .rh_rpm_package ]; then \ echo "no .rh_rpm_package exists!"; exit 1; fi @chmod 666 .rh_rpm_package @rm -rf ./RELDIR; mkdir ./RELDIR; mkdir ./RELDIR/${PROGRAM}-${VERSION} @rm -f ${PROGRAM}-${VERSION}.tar.gz @rm -f ${PROGRAM}-${VERSION}-${RELEASE}.src.rpm @chown root ./RELDIR/${PROGRAM}-${VERSION} @tar cf - ${SOURCE_FILES} Makefile ${GDB_FILES} ${GDB_PATCH_FILES} ${GPL_FILES} \ .rh_rpm_package crash.8 ${EXTENSION_SOURCE_FILES} ${MEMORY_DRIVER_FILES} | \ (cd ./RELDIR/${PROGRAM}-${VERSION}; tar xf -) @cp ${GDB}.tar.gz ./RELDIR/${PROGRAM}-${VERSION} @./${PROGRAM} --no_scroll --no_crashrc -h README > README @cp README ./RELDIR/${PROGRAM}-${VERSION}/README @(cd ./RELDIR; find . -exec chown root {} ";") @(cd ./RELDIR; find . -exec chgrp root {} ";") @(cd ./RELDIR; find . -exec touch {} ";") @(cd ./RELDIR; \ tar czvf ../${PROGRAM}-${VERSION}.tar.gz ${PROGRAM}-${VERSION}) @chgrp root ${PROGRAM}-${VERSION}.tar.gz @rm -rf ./RELDIR @echo @ls -l ${PROGRAM}-${VERSION}.tar.gz @./configure -s -u > ${PROGRAM}.spec @if [ -s ${PROGRAM}.spec ]; then \ rm -rf ./RPMBUILD; \ mkdir -p ./RPMBUILD/SOURCES ./RPMBUILD/SPECS ./RPMBUILD/SRPMS; \ cp ${PROGRAM}-${VERSION}.tar.gz ./RPMBUILD/SOURCES; \ cp ${PROGRAM}.spec ./RPMBUILD/SPECS; \ rpmbuild --define "_sourcedir ./RPMBUILD/SOURCES" \ --define "_srcrpmdir ./RPMBUILD/SRPMS" \ --define "_specdir ./RPMBUILD/SPECS" \ --nodeps -bs ./RPMBUILD/SPECS/${PROGRAM}.spec > /dev/null; \ mv ./RPMBUILD/SRPMS/${PROGRAM}-${VERSION}-${RELEASE}.src.rpm . ; \ rm -rf ./RPMBUILD; \ ls -l ${PROGRAM}-${VERSION}-${RELEASE}.src.rpm; \ fi ref: $(MAKE) ctags cscope cscope: rm -f cscope.files cscope.out for FILE in ${SOURCE_FILES}; do \ echo $$FILE >> cscope.files; done cscope -b -f cscope.out glink: make_configure @./configure -q -b rm -f gdb ln -s ${GDB}/gdb gdb (cd ${GDB}/gdb; rm -f ${PROGRAM}; ln -s ../../${PROGRAM} ${PROGRAM}) name: @echo ${PROGRAM} dis: objdump --disassemble --line-numbers ${PROGRAM} > ${PROGRAM}.dis extensions: make_configure @./configure ${CONF_TARGET_FLAG} -q -b @$(MAKE) do_extensions do_extensions: @$(MAKE) -C extensions -i CC=$(CC) TARGET=$(TARGET) TARGET_CFLAGS="$(CFLAGS) $(TARGET_CFLAGS)" GDB=$(GDB) GDB_FLAGS=$(GDB_FLAGS) memory_driver: make_configure @$(MAKE) -C memory_driver -i crash-utility-crash-61fe107/README000066400000000000000000000412741517256214500166440ustar00rootroot00000000000000 CORE ANALYSIS SUITE The core analysis suite is a self-contained tool that can be used to investigate either live systems, kernel core dumps created from dump creation facilities such as kdump, kvmdump, xendump, the netdump and diskdump packages offered by Red Hat, the LKCD kernel patch, the mcore kernel patch created by Mission Critical Linux, as well as other formats created by manufacturer-specific firmware. o The tool is loosely based on the SVR4 crash command, but has been completely integrated with gdb in order to be able to display formatted kernel data structures, disassemble source code, etc. o The current set of available commands consist of common kernel core analysis tools such as a context-specific stack traces, source code disassembly, kernel variable displays, memory display, dumps of linked-lists, etc. In addition, any gdb command may be entered, which in turn will be passed onto the gdb module for execution. o There are several commands that delve deeper into specific kernel subsystems, which also serve as templates for kernel developers to create new commands for analysis of a specific area of interest. Adding a new command is a simple affair, and a quick recompile adds it to the command menu. o The intent is to make the tool independent of Linux version dependencies, building in recognition of major kernel code changes so as to adapt to new kernel versions, while maintaining backwards compatibility. A whitepaper with complete documentation concerning the use of this utility can be found here: https://crash-utility.github.io/crash_whitepaper.html These are the current prerequisites: o At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips, mips64, loongarch64, riscv64, s390 and s390x-based kernels are supported. Other architectures may be addressed in the future. o One size fits all -- the utility can be run on any Linux kernel version version dating back to 2.2.5-15. A primary design goal is to always maintain backwards-compatibility. o In order to contain debugging data, the top-level kernel Makefile's CFLAGS definition must contain the -g flag. Typically distributions will contain a package containing a vmlinux file with full debuginfo data. If not, the kernel must be rebuilt: For 2.2 kernels that are not built with -g, change the following line: CFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer to: CFLAGS = -g -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer For 2.4 kernels that are not built with -g, change the following line: CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing to: CFLAGS := -g $(CPPFLAGS) -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing For 2.6 and later kernels that are not built with -g, the kernel should be configured with CONFIG_DEBUG_INFO enabled, which in turn will add the -g flag to the CFLAGS setting in the kernel Makefile. After the kernel is re-compiled, the uncompressed "vmlinux" kernel that is created in the top-level kernel build directory must be saved. o Requirements for building: Fedora: make gcc gcc-c++ ncurses-devel zlib-devel lzo-devel snappy-devel bison wget patch texinfo libzstd-devel gmp-devel mpfr-devel Ubuntu/Debian: make gcc g++ libncurses-dev zlib1g-dev liblzo2-dev libsnappy-dev bison wget patch texinfo libzstd-dev Arch Linux: make gcc ncurses zlib lzo snappy bison wget patch texinfo zstd openSUSE: make gcc gcc-c++ ncurses-devel zlib-devel lzo-devel snappy-devel bison wget patch texinfo libzstd-devel To build the crash utility: $ tar -xf crash-9.0.2.tar.gz $ cd crash-9.0.2 $ make To cross compile the crash utility for aarch64 on x86_64: $ make CROSS_COMPILE=aarch64-linux-gnu- -j`nproc` Supported arches for cross compilation: x86_64, x86, aarch64, s390x, powerpc64, alpha, sparc64, mips, riscv64 The initial build will take several minutes because the embedded gdb module must be configured and built. Alternatively, the crash source RPM file may be installed and built, and the resultant crash binary RPM file installed. The crash binary can only be used on systems of the same architecture as the host build system. There are a few optional manners of building the crash binary: o On an x86_64 host, a 32-bit x86 binary that can be used to analyze 32-bit x86 dumpfiles may be built by typing "make target=X86". o On an x86 or x86_64 host, a 32-bit x86 binary that can be used to analyze 32-bit arm dumpfiles may be built by typing "make target=ARM". o On an x86 or x86_64 host, a 32-bit x86 binary that can be used to analyze 32-bit mips dumpfiles may be built by typing "make target=MIPS". o On an ppc64 host, a 32-bit ppc binary that can be used to analyze 32-bit ppc dumpfiles may be built by typing "make target=PPC". o On an x86_64 host, an x86_64 binary that can be used to analyze arm64 dumpfiles may be built by typing "make target=ARM64". o On an x86_64 host, an x86_64 binary that can be used to analyze ppc64le dumpfiles may be built by typing "make target=PPC64". o On an x86_64 host, an x86_64 binary that can be used to analyze riscv64 dumpfiles may be built by typing "make target=RISCV64". o On an x86_64 host, an x86_64 binary that can be used to analyze loongarch64 dumpfiles may be built by typing "make target=LOONGARCH64". Traditionally when vmcores are compressed via the makedumpfile(8) facility the libz compression library is used, and by default the crash utility only supports libz. Recently makedumpfile has been enhanced to optionally use the LZO, snappy or zstd compression libraries. To build crash with any or all of those libraries, type "make lzo", "make snappy" or "make zstd". crash supports valgrind Memcheck tool on the crash's custom memory allocator. To build crash with this feature enabled, type "make valgrind" and then run crash with valgrind as "valgrind crash vmlinux vmcore". All of the alternate build commands above are "sticky" in that the special "make" targets only have to be entered one time; all subsequent builds will follow suit. If the tool is run against a kernel dumpfile, two arguments are required, the uncompressed kernel name and the kernel dumpfile name. If run on a live system, only the kernel name is required, because /dev/mem will be used as the "dumpfile". On Red Hat or Fedora kernels where the /dev/mem device is restricted, the /dev/crash memory driver will be used. If neither /dev/mem or /dev/crash are available, then /proc/kcore will be be used as the live memory source. If /proc/kcore is also restricted, then the Red Hat /dev/crash driver may be compiled and installed; its source is included in the crash-9.0.2/memory_driver subdirectory. If the kernel file is stored in /boot, /, /boot/efi, or in any /usr/src or /usr/lib/debug/lib/modules subdirectory, then no command line arguments are required -- the first kernel found that matches /proc/version will be used as the namelist. For example, invoking crash on a live system would look like this: $ crash crash 9.0.2 Copyright (C) 2002-2026 Red Hat, Inc. Copyright (C) 2004, 2005, 2006, 2010 IBM Corporation Copyright (C) 1999-2006 Hewlett-Packard Co Copyright (C) 2005, 2006, 2011, 2012 Fujitsu Limited Copyright (C) 2006, 2007 VA Linux Systems Japan K.K. Copyright (C) 2005, 2011, 2020-2022 NEC Corporation Copyright (C) 1999, 2002, 2007 Silicon Graphics, Inc. Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. Copyright (C) 2015, 2021 VMware, Inc. This program is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Enter "help copying" to see the conditions. This program has absolutely no warranty. Enter "help warranty" for details. GNU gdb 16.2 Copyright 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-pc-linux-gnu"... KERNEL: /boot/vmlinux DUMPFILE: /dev/mem CPUS: 1 DATE: Fri Apr 24 10:38:29 CST 2026 UPTIME: 10 days, 22:55:18 LOAD AVERAGE: 0.08, 0.03, 0.01 TASKS: 42 NODENAME: ha2.mclinux.com RELEASE: 2.4.0-test10 VERSION: #11 SMP Thu Nov 4 15:09:25 EST 2000 MACHINE: i686 (447 MHz) MEMORY: 128 MB PID: 3621 COMMAND: "crash" TASK: c463c000 CPU: 0 STATE: TASK_RUNNING (ACTIVE) crash> help * files mod sbitmapq union alias foreach mount search vm ascii fuser net set vtop bpf gdb p sig waitq bt help ps struct whatis btop ipcs pte swap wr dev irq ptob sym q dis kmem ptov sys eval list rd task exit log repeat timer extend mach runq tree crash version: 9.0.0 gdb version: 16.2 For help on any command above, enter "help ". For help on input options, enter "help input". For help on output options, enter "help output". crash> When run on a dumpfile, both the kernel namelist and dumpfile must be entered on the command line. For example, when run on a core dump created by the Red Hat netdump or diskdump facilities: $ crash vmlinux vmcore crash 9.0.2 Copyright (C) 2002-2026 Red Hat, Inc. Copyright (C) 2004, 2005, 2006, 2010 IBM Corporation Copyright (C) 1999-2006 Hewlett-Packard Co Copyright (C) 2005, 2006, 2011, 2012 Fujitsu Limited Copyright (C) 2006, 2007 VA Linux Systems Japan K.K. Copyright (C) 2005, 2011, 2020-2022 NEC Corporation Copyright (C) 1999, 2002, 2007 Silicon Graphics, Inc. Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. Copyright (C) 2015, 2021 VMware, Inc. This program is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Enter "help copying" to see the conditions. This program has absolutely no warranty. Enter "help warranty" for details. GNU gdb 16.2 Copyright 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-pc-linux-gnu"... KERNEL: vmlinux DUMPFILE: vmcore CPUS: 4 DATE: Fri Apr 24 10:38:29 CST 2026 UPTIME: 00:02:40 LOAD AVERAGE: 2.24, 0.96, 0.37 TASKS: 70 NODENAME: pro1.lab.boston.redhat.com RELEASE: 2.6.3-2.1.214.11smp VERSION: #1 SMP Tue Mar 2 10:58:27 EST 2004 MACHINE: i686 (2785 Mhz) MEMORY: 512 MB PANIC: "Oops: 0002 [#1]" (check log for details) PID: 0 COMMAND: "swapper" TASK: 22fa200 (1 of 4) [THREAD_INFO: 2356000] CPU: 0 STATE: TASK_RUNNING (PANIC) crash> The tool's environment is context-specific. On a live system, the default context is the command itself; on a dump the default context will be the task that panicked. The most commonly-used commands are: set - set a new task context by pid, task address, or cpu. bt - backtrace of the current context, or as specified with arguments. p - print the contents of a kernel variable. rd - read memory, which may be either kernel virtual, user virtual, or physical. ps - simple process listing. log - dump the kernel log_buf. struct - print the contents of a structure at a specified address. foreach - execute a command on all tasks, or those specified, in the system. Detailed help concerning the use of each of the commands in the menu above may be displayed by entering "help command", where "command" is one of those listed above. Rather than getting bogged down in details here, simply run the help command on each of the commands above. Note that many commands have multiple options so as to avoid the proliferation of command names. Command output may be piped to external commands or redirected to files. Enter "help output" for details. The command line history mechanism allows for command-line recall and command-line editing. Input files containing a set of crash commands may be substituted for command-line input. Enter "help input" for details. Note that a .crashrc file (or .rc if the name has been changed), may contain any number of "set" or "alias" commands -- see the help pages on those two commands for details. Lastly, if a command is entered that is not recognized, it is checked against the kernel's list of variables, structure, union or typedef names, and if found, the command is passed to "p", "struct", "union" or "whatis". That being the case, as long as a kernel variable/structure/union name is different than any of the current commands. (1) A kernel variable can be dumped by simply entering its name: crash> init_mm init_mm = $2 = { mmap = 0xc022d540, mmap_avl = 0x0, mmap_cache = 0x0, pgd = 0xc0101000, count = { counter = 0x6 }, map_count = 0x1, mmap_sem = { count = { counter = 0x1 }, waking = 0x0, wait = 0x0 }, context = 0x0, start_code = 0xc0000000, end_code = 0xc022b4c8, end_data = c0250388, ... (2) A structure or can be dumped simply by entering its name and address: crash> vm_area_struct c5ba3910 struct vm_area_struct { vm_mm = 0xc3ae3210, vm_start = 0x821b000, vm_end = 0x8692000, vm_next = 0xc5ba3890, vm_page_prot = { pgprot = 0x25 }, vm_flags = 0x77, vm_avl_height = 0x4, vm_avl_left = 0xc0499540, vm_avl_right = 0xc0499f40, vm_next_share = 0xc04993c0, vm_pprev_share = 0xc0499060, vm_ops = 0x0, vm_offset = 0x0, vm_file = 0x0, vm_pte = 0x0 } The crash utility has been designed to facilitate the task of adding new commands. New commands may be permanently compiled into the crash executable, or dynamically added during runtime using shared object files. To permanently add a new command to the crash executable's menu: 1. For a command named "xxx", put a reference to cmd_xxx() in defs.h. 2. Add cmd_xxx into the base_command_table[] array in global_data.c. 3. Write cmd_xxx(), putting it in one of the appropriate files. Look at the other commands for guidance on getting symbolic data, reading memory, displaying data, etc... 4. Recompile and run. Note that while the initial compile of crash, which configures and compiles the gdb module, takes several minutes, subsequent re-compiles to do such things as add new commands or fix bugs just takes a few seconds. Alternatively, you can create shared object library files consisting of crash command extensions, that can be dynamically linked into the crash executable during runtime or during initialization. This will allow the same shared object to be used with subsequent crash releases without having to re-merge the command's code into each new set of crash sources. The dynamically linked-in commands will automatically show up in the crash help menu. For details, enter "help extend" during runtime, or enter "crash -h extend" from the shell command line. crash-utility-crash-61fe107/alpha.c000066400000000000000000002252661517256214500172220ustar00rootroot00000000000000/* alpha.c - core analysis suite * * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. * Copyright (C) 2002-2006, 2010-2013 David Anderson * Copyright (C) 2002-2006, 2010-2013 Red Hat, Inc. All rights reserved. * * 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 2 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. * */ #ifdef ALPHA #include "defs.h" static void alpha_back_trace(struct gnu_request *, struct bt_info *); static int alpha_trace_status(struct gnu_request *, struct bt_info *); static void alpha_exception_frame(ulong, ulong, struct gnu_request *, struct bt_info *); static void alpha_frame_offset(struct gnu_request *, ulong); static int alpha_backtrace_resync(struct gnu_request *, ulong, struct bt_info *); static void alpha_print_stack_entry(struct gnu_request *, ulong, char *, ulong, struct bt_info *); static int alpha_resync_speculate(struct gnu_request *, ulong,struct bt_info *); static int alpha_dis_filter(ulong, char *, unsigned int); static void dis_address_translation(ulong, char *, unsigned int); static void alpha_cmd_mach(void); static int alpha_get_smp_cpus(void); static void alpha_display_machine_stats(void); static void alpha_dump_line_number(char *, ulong); static void display_hwrpb(unsigned int); static void alpha_post_init(void); static struct line_number_hook alpha_line_number_hooks[]; #define ALPHA_CONTINUE_TRACE (1) #define ALPHA_END_OF_TRACE (2) #define ALPHA_EXCEPTION_FRAME (3) #define ALPHA_SYSCALL_FRAME (4) #define ALPHA_MM_FAULT (5) #define ALPHA_INTERRUPT_PENDING (6) #define ALPHA_RESCHEDULE (7) #define ALPHA_DOWN_FAILED (8) #define ALPHA_RET_FROM_SMP_FORK (9) #define ALPHA_SIGNAL_RETURN (10) #define ALPHA_STRACE (11) static int alpha_eframe_search(struct bt_info *); static int alpha_uvtop(struct task_context *, ulong, physaddr_t *, int); static int alpha_kvtop(struct task_context *, ulong, physaddr_t *, int); static void alpha_back_trace_cmd(struct bt_info *); static ulong alpha_get_task_pgd(ulong task); static ulong alpha_processor_speed(void); static void alpha_dump_irq(int); static void alpha_get_stack_frame(struct bt_info *, ulong *, ulong *); static void get_alpha_frame(struct bt_info *, ulong *, ulong *); static int verify_user_eframe(struct bt_info *, ulong, ulong); static int alpha_translate_pte(ulong, void *, ulonglong); static uint64_t alpha_memory_size(void); static ulong alpha_vmalloc_start(void); static int alpha_is_task_addr(ulong); static int alpha_verify_symbol(const char *, ulong, char); struct percpu_data { ulong halt_PC; ulong halt_ra; ulong halt_pv; }; #define GET_HALT_PC 0x1 #define GET_HALT_RA 0x2 #define GET_HALT_PV 0x3 static ulong get_percpu_data(int, ulong, struct percpu_data *); /* * Do all necessary machine-specific setup here. This is called three times, * before symbol table initialization, and before and after GDB has been * initialized. */ void alpha_init(int when) { int tmp; switch (when) { case PRE_SYMTAB: machdep->verify_symbol = alpha_verify_symbol; if (pc->flags & KERNEL_DEBUG_QUERY) return; machdep->pagesize = memory_page_size(); machdep->pageshift = ffs(machdep->pagesize) - 1; machdep->pageoffset = machdep->pagesize - 1; machdep->pagemask = ~(machdep->pageoffset); machdep->stacksize = machdep->pagesize * 2; if ((machdep->pgd = (char *)malloc(PAGESIZE())) == NULL) error(FATAL, "cannot malloc pgd space."); if ((machdep->pmd = (char *)malloc(PAGESIZE())) == NULL) error(FATAL, "cannot malloc pmd space."); if ((machdep->ptbl = (char *)malloc(PAGESIZE())) == NULL) error(FATAL, "cannot malloc ptbl space."); machdep->last_pgd_read = 0; machdep->last_pmd_read = 0; machdep->last_ptbl_read = 0; machdep->verify_paddr = generic_verify_paddr; machdep->ptrs_per_pgd = PTRS_PER_PGD; break; case PRE_GDB: switch (symbol_value("_stext") & KSEG_BASE) { case KSEG_BASE: machdep->kvbase = KSEG_BASE; break; case KSEG_BASE_48_BIT: machdep->kvbase = KSEG_BASE_48_BIT; break; default: error(FATAL, "cannot determine KSEG base from _stext: %lx\n", symbol_value("_stext")); } machdep->identity_map_base = machdep->kvbase; machdep->is_kvaddr = generic_is_kvaddr; machdep->is_uvaddr = generic_is_uvaddr; machdep->eframe_search = alpha_eframe_search; machdep->back_trace = alpha_back_trace_cmd; machdep->processor_speed = alpha_processor_speed; machdep->uvtop = alpha_uvtop; machdep->kvtop = alpha_kvtop; machdep->get_task_pgd = alpha_get_task_pgd; if (symbol_exists("irq_desc")) machdep->dump_irq = generic_dump_irq; else machdep->dump_irq = alpha_dump_irq; machdep->get_stack_frame = alpha_get_stack_frame; machdep->get_stackbase = generic_get_stackbase; machdep->get_stacktop = generic_get_stacktop; machdep->translate_pte = alpha_translate_pte; machdep->memory_size = alpha_memory_size; machdep->vmalloc_start = alpha_vmalloc_start; machdep->is_task_addr = alpha_is_task_addr; if (symbol_exists("console_crash")) { get_symbol_data("console_crash", sizeof(int), &tmp); if (tmp) machdep->flags |= HWRESET; } machdep->dis_filter = alpha_dis_filter; machdep->cmd_mach = alpha_cmd_mach; machdep->get_smp_cpus = alpha_get_smp_cpus; machdep->line_number_hooks = alpha_line_number_hooks; machdep->value_to_symbol = generic_machdep_value_to_symbol; machdep->init_kernel_pgd = NULL; break; case POST_GDB: MEMBER_OFFSET_INIT(thread_struct_ptbr, "thread_struct", "ptbr"); MEMBER_OFFSET_INIT(hwrpb_struct_cycle_freq, "hwrpb_struct", "cycle_freq"); MEMBER_OFFSET_INIT(hwrpb_struct_processor_offset, "hwrpb_struct", "processor_offset"); MEMBER_OFFSET_INIT(hwrpb_struct_processor_size, "hwrpb_struct", "processor_size"); MEMBER_OFFSET_INIT(percpu_struct_halt_PC, "percpu_struct", "halt_PC"); MEMBER_OFFSET_INIT(percpu_struct_halt_ra, "percpu_struct", "halt_ra"); MEMBER_OFFSET_INIT(percpu_struct_halt_pv, "percpu_struct", "halt_pv"); MEMBER_OFFSET_INIT(switch_stack_r26, "switch_stack", "r26"); if (symbol_exists("irq_action")) ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_action, "irq_action", NULL, 0); else if (symbol_exists("irq_desc")) ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc, "irq_desc", NULL, 0); else machdep->nr_irqs = 0; if (!machdep->hz) machdep->hz = HZ; break; case POST_INIT: alpha_post_init(); break; } } /* * Unroll a kernel stack. */ static void alpha_back_trace_cmd(struct bt_info *bt) { char buf[BUFSIZE]; struct gnu_request *req; bt->flags |= BT_EXCEPTION_FRAME; if (CRASHDEBUG(1) || bt->debug) fprintf(fp, " => PC: %lx (%s) FP: %lx \n", bt->instptr, value_to_symstr(bt->instptr, buf, 0), bt->stkptr ); req = (struct gnu_request *)GETBUF(sizeof(struct gnu_request)); req->command = GNU_STACK_TRACE; req->flags = GNU_RETURN_ON_ERROR; req->buf = GETBUF(BUFSIZE); req->debug = bt->debug; req->task = bt->task; req->pc = bt->instptr; req->sp = bt->stkptr; if (bt->flags & BT_USE_GDB) { strcpy(req->buf, "backtrace"); gdb_interface(req); } else alpha_back_trace(req, bt); FREEBUF(req->buf); FREEBUF(req); } /* * Unroll the kernel stack. */ #define ALPHA_BACKTRACE_SPECULATE(X) \ { \ speculate_location = X; \ \ if (bt->flags & BT_SPECULATE) \ return; \ \ BZERO(btloc, sizeof(struct bt_info)); \ btloc->task = req->task; \ btloc->tc = bt->tc; \ btloc->stackbase = bt->stackbase; \ btloc->stacktop = bt->stacktop; \ btloc->flags = BT_TEXT_SYMBOLS_NOPRINT; \ hook.eip = 0; \ hook.esp = req->lastsp ? req->lastsp + sizeof(long) : 0; \ btloc->hp = &hook; \ \ back_trace(btloc); \ \ if (hook.esp && hook.eip) { \ req->hookp = &hook; \ if (alpha_resync_speculate(req, bt->flags, bt)) { \ req->pc = hook.eip; \ req->sp = hook.esp; \ continue; \ } \ goto show_remaining_text; \ } \ goto show_remaining_text; \ } static void alpha_back_trace(struct gnu_request *req, struct bt_info *bt) { char buf[BUFSIZE]; int frame; int done; int status; struct stack_hook hook; int eframe_same_pc_ra_function; int speculate_location; struct bt_info bt_info, *btloc; frame = 0; req->curframe = 0; btloc = &bt_info; if (!IS_KVADDR(req->pc)) { if (BT_REFERENCE_CHECK(bt)) return; if ((machdep->flags & HWRESET) && is_task_active(req->task)) { fprintf(fp, "(hardware reset while in user space)\n"); return; } fprintf(fp, "invalid pc: %lx\n", req->pc); alpha_exception_frame(USER_EFRAME_ADDR(req->task), BT_USER_EFRAME, req, bt); return; } for (done = FALSE; !done && (frame < 100); frame++) { speculate_location = 0; if ((req->name = closest_symbol(req->pc)) == NULL) { req->ra = req->pc = 0; if (alpha_backtrace_resync(req, bt->flags | BT_FROM_CALLFRAME, bt)) continue; if (BT_REFERENCE_FOUND(bt)) return; ALPHA_BACKTRACE_SPECULATE(1); } if (!INSTACK(req->sp, bt)) break; if (!is_kernel_text(req->pc)) ALPHA_BACKTRACE_SPECULATE(2); alpha_print_stack_entry(req, req->pc, req->name, bt->flags | BT_SAVE_LASTSP, bt); if (BT_REFERENCE_FOUND(bt)) return; switch (status = alpha_trace_status(req, bt)) { case ALPHA_CONTINUE_TRACE: alpha_frame_offset(req, 0); if (!req->value) { done = TRUE; break; } req->prevpc = req->pc; req->pc = GET_STACK_ULONG(req->sp); req->prevsp = req->sp; req->sp += req->value; break; case ALPHA_END_OF_TRACE: done = TRUE; break; case ALPHA_STRACE: alpha_exception_frame(req->sp, BT_USER_EFRAME|BT_STRACE, req, bt); done = TRUE; break; case ALPHA_RET_FROM_SMP_FORK: alpha_exception_frame(USER_EFRAME_ADDR(req->task), BT_USER_EFRAME|BT_RET_FROM_SMP_FORK, req, bt); done = TRUE; break; case ALPHA_DOWN_FAILED: frame++; alpha_print_stack_entry(req, req->pc, closest_symbol(req->pc), bt->flags | BT_SAVE_LASTSP, bt); if (BT_REFERENCE_FOUND(bt)) return; alpha_frame_offset(req, 0); if (!req->value) { done = TRUE; break; } req->prevpc = req->pc; req->pc = GET_STACK_ULONG(req->sp); req->prevsp = req->sp; req->sp += req->value; break; case ALPHA_RESCHEDULE: alpha_exception_frame(USER_EFRAME_ADDR(req->task), BT_USER_EFRAME|BT_RESCHEDULE, req, bt); done = TRUE; break; case ALPHA_MM_FAULT: alpha_exception_frame(req->sp, bt->flags, req, bt); if (!IS_KVADDR(req->pc)) { done = TRUE; break; } alpha_frame_offset(req, 0); if (!req->value) { done = TRUE; break; } frame++; alpha_print_stack_entry(req, req->pc, closest_symbol(req->pc), bt->flags | BT_SAVE_LASTSP, bt); if (BT_REFERENCE_FOUND(bt)) return; if (!IS_KVADDR(req->pc)) { done = TRUE; break; } req->prevpc = req->pc; req->pc = GET_STACK_ULONG(req->sp); req->prevsp = req->sp; req->sp += req->value; break; case ALPHA_SYSCALL_FRAME: req->sp = verify_user_eframe(bt, req->task, req->sp) ? req->sp : USER_EFRAME_ADDR(req->task); alpha_exception_frame(req->sp, bt->flags, req, bt); if (!IS_KVADDR(req->pc)) { done = TRUE; break; } alpha_frame_offset(req, 0); if (!req->value) { done = TRUE; break; } req->prevpc = req->pc; req->pc = GET_STACK_ULONG(req->sp); req->prevsp = req->sp; req->sp += req->value; break; case ALPHA_SIGNAL_RETURN: alpha_exception_frame(USER_EFRAME_ADDR(req->task), bt->flags, req, bt); done = TRUE; break; case ALPHA_EXCEPTION_FRAME: alpha_frame_offset(req, 0); if (!req->value) { fprintf(fp, "ALPHA EXCEPTION FRAME w/no frame offset for %lx (%s)\n", req->pc, value_to_symstr(req->pc, buf, 0)); done = TRUE; break; } alpha_exception_frame(req->sp + req->value, bt->flags, req, bt); if (!IS_KVADDR(req->pc)) { done = TRUE; break; } alpha_frame_offset(req, 0); if (!req->value) { fprintf(fp, "ALPHA EXCEPTION FRAME w/no frame offset for %lx (%s)\n", req->pc, value_to_symstr(req->pc, buf, 0)); done = TRUE; break; } eframe_same_pc_ra_function = SAME_FUNCTION(req->pc, req->ra); frame++; alpha_print_stack_entry(req, req->pc, closest_symbol(req->pc), bt->flags | BT_SAVE_LASTSP, bt); if (BT_REFERENCE_FOUND(bt)) return; if (!IS_KVADDR(req->pc)) { done = TRUE; break; } if (STREQ(closest_symbol(req->pc), "ret_from_reschedule")) { alpha_exception_frame( USER_EFRAME_ADDR(req->task), BT_USER_EFRAME|BT_RESCHEDULE, req, bt); done = TRUE; break; } req->prevpc = req->pc; req->pc = GET_STACK_ULONG(req->sp); if (!is_kernel_text(req->pc)) { if (alpha_backtrace_resync(req, bt->flags | BT_FROM_EXCEPTION, bt)) break; if (BT_REFERENCE_FOUND(bt)) return; ALPHA_BACKTRACE_SPECULATE(3); } if (!eframe_same_pc_ra_function && (req->pc != req->ra)) { req->pc = req->ra; break; } req->prevsp = req->sp; req->sp += req->value; break; case ALPHA_INTERRUPT_PENDING: alpha_frame_offset(req, 0); if (!req->value) { req->prevpc = req->pc; req->pc = req->addr; req->prevsp = req->sp; req->sp = req->frame; } else { req->prevpc = req->pc; req->pc = GET_STACK_ULONG(req->sp); req->prevsp = req->sp; req->sp += req->value; } break; } } return; show_remaining_text: if (BT_REFERENCE_CHECK(bt)) return; BZERO(btloc, sizeof(struct bt_info)); btloc->task = req->task; btloc->tc = bt->tc; btloc->stackbase = bt->stackbase; btloc->stacktop = bt->stacktop; btloc->flags = BT_TEXT_SYMBOLS_NOPRINT; hook.esp = req->lastsp + sizeof(long); btloc->hp = &hook; back_trace(btloc); if (hook.eip) { fprintf(fp, "NOTE: cannot resolve trace from this point -- remaining text symbols on stack:\n"); btloc->flags = BT_TEXT_SYMBOLS_PRINT|BT_ERROR_MASK; hook.esp = req->lastsp + sizeof(long); back_trace(btloc); } else fprintf(fp, "NOTE: cannot resolve trace from this point -- no remaining text symbols\n"); if (CRASHDEBUG(1)) fprintf(fp, "speculate_location: %d\n", speculate_location); alpha_exception_frame(USER_EFRAME_ADDR(req->task), BT_USER_EFRAME, req, bt); } /* * print one entry of a stack trace */ static void alpha_print_stack_entry(struct gnu_request *req, ulong callpc, char *name, ulong flags, struct bt_info *bt) { struct load_module *lm; if (BT_REFERENCE_CHECK(bt)) { switch (bt->ref->cmdflags & (BT_REF_SYMBOL|BT_REF_HEXVAL)) { case BT_REF_SYMBOL: if (STREQ(name, bt->ref->str) || (STREQ(name, "strace") && STREQ(bt->ref->str, "entSys"))) { bt->ref->cmdflags |= BT_REF_FOUND; } break; case BT_REF_HEXVAL: if (bt->ref->hexval == callpc) bt->ref->cmdflags |= BT_REF_FOUND; break; } } else { fprintf(fp, "%s#%d [%lx] %s at %lx", req->curframe < 10 ? " " : "", req->curframe, req->sp, STREQ(name, "strace") ? "strace (via entSys)" : name, callpc); if (module_symbol(callpc, NULL, &lm, NULL, 0)) fprintf(fp, " [%s]", lm->mod_name); fprintf(fp, "\n"); } if (!(flags & BT_SPECULATE)) req->curframe++; if (flags & BT_SAVE_LASTSP) req->lastsp = req->sp; if (BT_REFERENCE_CHECK(bt)) return; if (flags & BT_LINE_NUMBERS) alpha_dump_line_number(name, callpc); } static const char *hook_files[] = { "arch/alpha/kernel/entry.S", "arch/alpha/kernel/head.S", "init/main.c", "arch/alpha/kernel/smp.c", }; #define ENTRY_S ((char **)&hook_files[0]) #define HEAD_S ((char **)&hook_files[1]) #define MAIN_C ((char **)&hook_files[2]) #define SMP_C ((char **)&hook_files[3]) static struct line_number_hook alpha_line_number_hooks[] = { {"entInt", ENTRY_S}, {"entMM", ENTRY_S}, {"entArith", ENTRY_S}, {"entIF", ENTRY_S}, {"entDbg", ENTRY_S}, {"kernel_clone", ENTRY_S}, {"kernel_thread", ENTRY_S}, {"__kernel_execve", ENTRY_S}, {"do_switch_stack", ENTRY_S}, {"undo_switch_stack", ENTRY_S}, {"entUna", ENTRY_S}, {"entUnaUser", ENTRY_S}, {"sys_fork", ENTRY_S}, {"sys_clone", ENTRY_S}, {"sys_vfork", ENTRY_S}, {"alpha_switch_to", ENTRY_S}, {"entSys", ENTRY_S}, {"ret_from_sys_call", ENTRY_S}, {"ret_from_reschedule", ENTRY_S}, {"restore_all", ENTRY_S}, {"strace", ENTRY_S}, {"strace_success", ENTRY_S}, {"strace_error", ENTRY_S}, {"syscall_error", ENTRY_S}, {"ret_success", ENTRY_S}, {"signal_return", ENTRY_S}, {"ret_from_fork", ENTRY_S}, {"reschedule", ENTRY_S}, {"sys_sigreturn", ENTRY_S}, {"sys_rt_sigreturn", ENTRY_S}, {"sys_sigsuspend", ENTRY_S}, {"sys_rt_sigsuspend", ENTRY_S}, {"ret_from_smpfork", ENTRY_S}, {"_stext", HEAD_S}, {"__start", HEAD_S}, {"__smp_callin", HEAD_S}, {"cserve_ena", HEAD_S}, {"cserve_dis", HEAD_S}, {"halt", HEAD_S}, {"start_kernel", MAIN_C}, {"smp_callin", SMP_C}, {NULL, NULL} /* list must be NULL-terminated */ }; static void alpha_dump_line_number(char *name, ulong callpc) { char buf[BUFSIZE], *p; int retries; retries = 0; try_closest: get_line_number(callpc, buf, FALSE); if (strlen(buf)) { if (retries) { p = strstr(buf, ": "); if (p) *p = NULLCHAR; } fprintf(fp, " %s\n", buf); } else { if (retries) fprintf(fp, GDB_PATCHED() ? "" : " (cannot determine file and line number)\n"); else { retries++; callpc = closest_symbol_value(callpc); goto try_closest; } } } /* * Look for the frame size storage at the beginning of a function. * If it's not obvious, try gdb. * * For future reference, here's where the numbers come from: * * 0xfffffc00003217e8 : subq sp,0x50,sp * fffffc00003217e8: 43ca153e * 010000 11110 01010000 1 0101001 11110 * * 0xfffffc0000321668 : subq sp,0x60,sp * fffffc0000321668: 43cc153e * 010000 11110 01100000 1 0101001 11110 * * 0xfffffc000035d028 : subq sp,0x70,sp * fffffc000035d028: 43ce153e * 010000 11110 01110000 1 0101001 11110 * * 0100 0011 110x xxxx xxx1 0101 0011 1110 * 1111 1111 111x xxxx xxx1 1111 1111 1111 * 0000 0000 0001 1111 1110 0000 0000 0000 * f f e 0 1 f f f instruction mask * 0 0 1 f e 0 0 0 offset * * stq ra,0(sp) * fffffc000035d034: b75e0000 */ static void alpha_frame_offset(struct gnu_request *req, ulong alt_pc) { uint *ip, ival; ulong value; req->value = value = 0; if (alt_pc && !is_kernel_text(alt_pc)) error(FATAL, "trying to get frame offset of non-text address: %lx\n", alt_pc); else if (!alt_pc && !is_kernel_text(req->pc)) error(FATAL, "trying to get frame offset of non-text address: %lx\n", req->pc); ip = alt_pc ? (int *)closest_symbol_value(alt_pc) : (int *)closest_symbol_value(req->pc); if (!ip) goto use_gdb; ival = 0; /* * Don't go any farther than "stq ra,0(sp)" (0xb75e0000) */ while (ival != 0xb75e0000) { readmem((ulong)ip, KVADDR, &ival, sizeof(uint), "text value", FAULT_ON_ERROR); if ((ival & 0xffe01fff) == 0x43c0153e) { value = (ival & 0x1fe000) >> 13; break; } ip++; } if (value) { req->value = value; return; } use_gdb: #ifndef GDB_5_3 { static int gdb_frame_offset_warnings = 10; if (gdb_frame_offset_warnings-- > 0) error(WARNING, "GNU_ALPHA_FRAME_OFFSET functionality not ported to gdb\n"); } #endif req->command = GNU_ALPHA_FRAME_OFFSET; if (alt_pc) { ulong pc_save; pc_save = req->pc; req->pc = alt_pc; gdb_interface(req); req->pc = pc_save; } else gdb_interface(req); } /* * Look for key routines that either mean the trace has ended or has * bumped into an exception frame. */ int alpha_trace_status(struct gnu_request *req, struct bt_info *bt) { ulong value; char *func; ulong frame; req->addr = 0; func = req->name; frame = req->sp; if (STREQ(func, "start_kernel") || STREQ(func, "smp_callin") || STREQ(func, "kernel_thread") || STREQ(func, "__kernel_thread")) return ALPHA_END_OF_TRACE; if (STREQ(func, "ret_from_smp_fork") || STREQ(func, "ret_from_smpfork")) return ALPHA_RET_FROM_SMP_FORK; if (STREQ(func, "entSys")) return ALPHA_SYSCALL_FRAME; if (STREQ(func, "entMM")) { req->sp += 56; /* see entMM in entry.S */ return ALPHA_MM_FAULT; } if (STREQ(func, "do_entInt")) return ALPHA_EXCEPTION_FRAME; if (STREQ(func, "do_entArith")) return ALPHA_EXCEPTION_FRAME; if (STREQ(func, "do_entIF")) return ALPHA_EXCEPTION_FRAME; if (STREQ(func, "do_entDbg")) return ALPHA_EXCEPTION_FRAME; if (STREQ(func, "handle_bottom_half")) return ALPHA_EXCEPTION_FRAME; if (STREQ(func, "handle_softirq")) return ALPHA_EXCEPTION_FRAME; if (STREQ(func, "reschedule")) return ALPHA_RESCHEDULE; if (STREQ(func, "ret_from_reschedule")) return ALPHA_RESCHEDULE; if (STREQ(func, "signal_return")) return ALPHA_SIGNAL_RETURN; if (STREQ(func, "strace")) return ALPHA_STRACE; if (STREQ(func, "__down_failed") || STREQ(func, "__down_failed_interruptible")) { readmem(req->sp + 144, KVADDR, &req->pc, sizeof(ulong), "__down_failed r26", FAULT_ON_ERROR); req->sp += 160; return ALPHA_DOWN_FAILED; } value = GET_STACK_ULONG(frame); if (STREQ(closest_symbol(value), "do_entInt") || STREQ(closest_symbol(value), "do_entArith") || STREQ(closest_symbol(value), "do_entIF") || STREQ(closest_symbol(value), "do_entDbg")) { req->addr = value; req->frame = 0; while (INSTACK(frame, bt)) { frame += sizeof(ulong); value = GET_STACK_ULONG(frame); if (STREQ(closest_symbol(value), "ret_from_sys_call")) { alpha_frame_offset(req, req->addr); /* req->frame = frame + req->value; XXX */ break; } } return ALPHA_INTERRUPT_PENDING; } return ALPHA_CONTINUE_TRACE; } /* * Redo the gdb pt_regs structure output. */ enum regnames { _r0_, _r1_, _r2_, _r3_, _r4_, _r5_, _r6_, _r7_, _r8_, _r19_, _r20_, _r21_, _r22_, _r23_, _r24_, _r25_, _r26_, _r27_, _r28_, _hae_, _trap_a0_, _trap_a1_, _trap_a2_, _ps_, _pc_, _gp_, _r16_, _r17_, _r18_, NUMREGS}; struct alpha_eframe { char regs[30][30]; ulong value[29]; }; static void alpha_exception_frame(ulong addr, ulong flags, struct gnu_request *req, struct bt_info *bt) { int i, j; char buf[BUFSIZE]; ulong value; physaddr_t paddr; struct alpha_eframe eframe; if (CRASHDEBUG(4)) fprintf(fp, "alpha_exception_frame: %lx\n", addr); if (flags & BT_SPECULATE) { req->pc = 0; fprintf(fp, "ALPHA EXCEPTION FRAME\n"); return; } BZERO(&eframe, sizeof(struct alpha_eframe)); open_tmpfile(); dump_struct("pt_regs", addr, RADIX(16)); rewind(pc->tmpfile); while (fgets(buf, BUFSIZE, pc->tmpfile)) { strip_comma(clean_line(buf)); if (!strstr(buf, "0x")) continue; extract_hex(buf, &value, NULLCHAR, TRUE); if (CRASHDEBUG(4)) fprintf(pc->saved_fp, "<%s> %lx\n", buf, value); if (STRNEQ(buf, "r0 = ")) { sprintf(eframe.regs[_r0_], " V0/R0: %016lx", value); eframe.value[_r0_] = value; } if (STRNEQ(buf, "r1 = ")) { sprintf(eframe.regs[_r1_], " T0/R1: %016lx", value); eframe.value[_r1_] = value; } if (STRNEQ(buf, "r2 = ")) { sprintf(eframe.regs[_r2_], " T1/R2: %016lx", value); eframe.value[_r2_] = value; } if (STRNEQ(buf, "r3 = ")) { sprintf(eframe.regs[_r3_], " T2/R3: %016lx", value); eframe.value[_r3_] = value; } if (STRNEQ(buf, "r4 = ")) { sprintf(eframe.regs[_r4_], " T3/R4: %016lx", value); eframe.value[_r4_] = value; } if (STRNEQ(buf, "r5 = ")) { sprintf(eframe.regs[_r5_], " T4/R5: %016lx", value); eframe.value[_r5_] = value; } if (STRNEQ(buf, "r6 = ")) { sprintf(eframe.regs[_r6_], " T5/R6: %016lx", value); eframe.value[_r6_] = value; } if (STRNEQ(buf, "r7 = ")) { sprintf(eframe.regs[_r7_], " T6/R7: %016lx", value); eframe.value[_r7_] = value; } if (STRNEQ(buf, "r8 = ")) { sprintf(eframe.regs[_r8_], " T7/R8: %016lx", value); eframe.value[_r8_] = value; } if (STRNEQ(buf, "r19 = ")) { sprintf(eframe.regs[_r19_], " A3/R19: %016lx", value); eframe.value[_r19_] = value; } if (STRNEQ(buf, "r20 = ")) { sprintf(eframe.regs[_r20_], " A4/R20: %016lx", value); eframe.value[_r20_] = value; } if (STRNEQ(buf, "r21 = ")) { sprintf(eframe.regs[_r21_], " A5/R21: %016lx", value); eframe.value[_r21_] = value; } if (STRNEQ(buf, "r22 = ")) { sprintf(eframe.regs[_r22_], " T8/R22: %016lx", value); eframe.value[_r22_] = value; } if (STRNEQ(buf, "r23 = ")) { sprintf(eframe.regs[_r23_], " T9/R23: %016lx", value); eframe.value[_r23_] = value; } if (STRNEQ(buf, "r24 = ")) { sprintf(eframe.regs[_r24_], "T10/R24: %016lx", value); eframe.value[_r24_] = value; } if (STRNEQ(buf, "r25 = ")) { sprintf(eframe.regs[_r25_], "T11/R25: %016lx", value); eframe.value[_r25_] = value; } if (STRNEQ(buf, "r26 = ")) { sprintf(eframe.regs[_r26_], " RA/R26: %016lx", value); eframe.value[_r26_] = value; } if (STRNEQ(buf, "r27 = ")) { sprintf(eframe.regs[_r27_], "T12/R27: %016lx", value); eframe.value[_r27_] = value; } if (STRNEQ(buf, "r28 = ")) { sprintf(eframe.regs[_r28_], " AT/R28: %016lx", value); eframe.value[_r28_] = value; } if (STRNEQ(buf, "hae = ")) { sprintf(eframe.regs[_hae_], " HAE: %016lx", value); eframe.value[_hae_] = value; } if (STRNEQ(buf, "trap_a0 = ")) { sprintf(eframe.regs[_trap_a0_], "TRAP_A0: %016lx", value); eframe.value[_trap_a0_] = value; } if (STRNEQ(buf, "trap_a1 = ")) { sprintf(eframe.regs[_trap_a1_], "TRAP_A1: %016lx", value); eframe.value[_trap_a1_] = value; } if (STRNEQ(buf, "trap_a2 = ")) { sprintf(eframe.regs[_trap_a2_], "TRAP_A2: %016lx", value); eframe.value[_trap_a2_] = value; } if (STRNEQ(buf, "ps = ")) { sprintf(eframe.regs[_ps_], " PS: %016lx", value); eframe.value[_ps_] = value; } if (STRNEQ(buf, "pc = ")) { sprintf(eframe.regs[_pc_], " PC: %016lx", value); eframe.value[_pc_] = value; } if (STRNEQ(buf, "gp = ")) { sprintf(eframe.regs[_gp_], " GP/R29: %016lx", value); eframe.value[_gp_] = value; } if (STRNEQ(buf, "r16 = ")) { sprintf(eframe.regs[_r16_], " A0/R16: %016lx", value); eframe.value[_r16_] = value; } if (STRNEQ(buf, "r17 = ")) { sprintf(eframe.regs[_r17_], " A1/R17: %016lx", value); eframe.value[_r17_] = value; } if (STRNEQ(buf, "r18 =")) { sprintf(eframe.regs[_r18_], " A2/R18: %016lx", value); eframe.value[_r18_] = value; } } close_tmpfile(); if ((flags & BT_EXCEPTION_FRAME) && !BT_REFERENCE_CHECK(bt)) { dump_eframe: fprintf(fp, " EFRAME: %lx ", addr); fprintf(fp, "%s\n", eframe.regs[_r24_]); for (i = 0; i < (((NUMREGS+1)/2)-1); i++) { fprintf(fp, "%s ", eframe.regs[i]); pad_line(fp, 21 - strlen(eframe.regs[i]), ' '); j = i+((NUMREGS+1)/2); fprintf(fp, "%s", eframe.regs[j]); if (((j == _pc_) || (j == _r26_)) && is_kernel_text(eframe.value[j])) fprintf(fp, " <%s>", value_to_symstr(eframe.value[j], buf, 0)); fprintf(fp, "\n"); } } req->ra = eframe.value[_r26_]; req->pc = eframe.value[_pc_]; req->sp = addr + (29 * sizeof(ulong)); if (flags & BT_USER_EFRAME) { flags &= ~BT_USER_EFRAME; if (!BT_REFERENCE_CHECK(bt) && (eframe.value[_ps_] == 8) && (((uvtop(task_to_context(req->task), req->pc, &paddr, 0) || (volatile ulong)paddr) && (uvtop(task_to_context(req->task), req->ra, &paddr, 0) || (volatile ulong)paddr)) || (IS_ZOMBIE(req->task) || IS_EXITING(req->task)))) { if (!(flags & (BT_RESCHEDULE|BT_RET_FROM_SMP_FORK|BT_STRACE))) fprintf(fp, "NOTE: kernel-entry exception frame:\n"); goto dump_eframe; } } } /* * Look for likely exception frames in a stack. */ struct alpha_pt_regs { ulong reg_value[NUMREGS]; }; static int alpha_eframe_search(struct bt_info *bt) { ulong *first, *last; ulong eframe; struct alpha_pt_regs *pt; struct gnu_request *req; /* needed for alpha_exception_frame */ ulong *stack; int cnt; stack = (ulong *)bt->stackbuf; req = (struct gnu_request *)GETBUF(sizeof(struct gnu_request)); req->task = bt->task; first = stack + (roundup(SIZE(task_struct), sizeof(ulong)) / sizeof(ulong)); last = stack + (((bt->stacktop - bt->stackbase) - SIZE(pt_regs)) / sizeof(ulong)); for (cnt = 0; first <= last; first++) { pt = (struct alpha_pt_regs *)first; /* check for kernel exception frame */ if (!(pt->reg_value[_ps_] & 0xfffffffffffffff8) && (is_kernel_text(pt->reg_value[_pc_]) || IS_MODULE_VADDR(pt->reg_value[_pc_])) && (is_kernel_text(pt->reg_value[_r26_]) || IS_MODULE_VADDR(pt->reg_value[_r26_])) && IS_KVADDR(pt->reg_value[_gp_])) { cnt++; if (bt->flags & BT_EFRAME_COUNT) continue; fprintf(fp, "\nKERNEL-MODE EXCEPTION FRAME:\n"); eframe = bt->task + ((ulong)first - (ulong)stack); alpha_exception_frame(eframe, BT_EXCEPTION_FRAME, req, bt); continue; } /* check for user exception frame */ if ((pt->reg_value[_ps_] == 0x8) && ((IN_TASK_VMA(bt->task, pt->reg_value[_pc_]) && IN_TASK_VMA(bt->task, pt->reg_value[_r26_]) && IS_UVADDR(pt->reg_value[_gp_], bt->tc)) || ((first == last) && (IS_ZOMBIE(bt->task) || IS_EXITING(bt->task))))) { cnt++; if (bt->flags & BT_EFRAME_COUNT) continue; fprintf(fp, "\nUSER-MODE EXCEPTION FRAME:\n"); eframe = bt->task + ((ulong)first - (ulong)stack); alpha_exception_frame(eframe, BT_EXCEPTION_FRAME, req, bt); } } FREEBUF(req); return cnt; } /* * Before dumping a nonsensical exception frame, give it a quick test. */ static int verify_user_eframe(struct bt_info *bt, ulong task, ulong sp) { struct alpha_pt_regs ptbuf, *pt; readmem(sp, KVADDR, &ptbuf, sizeof(struct alpha_pt_regs), "pt_regs", FAULT_ON_ERROR); pt = &ptbuf; if ((pt->reg_value[_ps_] == 0x8) && ((IN_TASK_VMA(task, pt->reg_value[_pc_]) && IN_TASK_VMA(task, pt->reg_value[_r26_]) && IS_UVADDR(pt->reg_value[_gp_], bt->tc)) || ((pt == (struct alpha_pt_regs *)USER_EFRAME_ADDR(task)) && (IS_ZOMBIE(task) || IS_EXITING(task))))) { return TRUE; } return FALSE; } /* * Try to resync the stack location when there is no valid stack frame, * typically just above an exception frame. Use the req->ra value from the * exception frame as the new starting req->pc. Then walk up the stack until * a text routine that calls the newly-assigned pc is found -- that stack * location then becomes the new req->sp. * * If we're not coming from an exception frame, req-ra and req->pc will be * purposely zeroed out. In that case, use the prevsp value to find the * first pc that called the last frame's pc. * * Add any other repeatable "special-case" frames to the beginning of this * routine (ex. debug_spin_lock). Last ditch -- at the end of this routine, * speculate what might have happened (possibly in the background) -- and * if it looks good, run with it. */ static int alpha_backtrace_resync(struct gnu_request *req, ulong flags, struct bt_info *bt) { char addr[BUFSIZE]; char buf[BUFSIZE]; char lookfor1[BUFSIZE]; char lookfor2[BUFSIZE]; ulong newpc; ulong *stkp; ulong *stkp_newpc, *stkp_next; ulong value; int found; char *name; int exception; if (CRASHDEBUG(1)) fprintf(fp, "RESYNC1: [%lx-%d] ra: %lx pc: %lx sp: %lx\n", flags, req->curframe, req->ra, req->pc, req->sp); if (!req->ra && !req->pc) { req->ra = req->prevpc; exception = FALSE; } else exception = TRUE; if (!IS_KVADDR(req->ra)) return FALSE; name = closest_symbol(req->ra); sprintf(lookfor1, "<%s>", name); sprintf(lookfor2, "<%s+", name); if (CRASHDEBUG(1)) fprintf(fp, "RESYNC2: exception: %s lookfor: %s or %s\n", exception ? "TRUE" : "FALSE", lookfor1, lookfor2); /* * This is common when a non-panicking active CPU is spinning * in debug_spin_lock(). The next pc is offset by 0x30 from * the top of the exception frame, and the next sp is equal * to the frame offset of debug_spin_lock(). I can't explain it... */ if ((flags & BT_FROM_EXCEPTION) && STREQ(name, "debug_spin_lock")) { alpha_print_stack_entry(req, req->ra, closest_symbol(req->ra), flags, bt); if (BT_REFERENCE_FOUND(bt)) return FALSE; alpha_frame_offset(req, req->ra); stkp = (ulong *)(req->sp + 0x30); value = GET_STACK_ULONG(stkp); if (!is_kernel_text(value)) { req->sp = req->prevsp; return FALSE; } req->pc = value; req->sp += req->value; return TRUE; } /* * If the ra is a system call, then all we should have to do is * find the next reference to entSys on the stack, and set the * sp to that value. */ if (is_system_call(name, 0)) { /* stkp = (ulong *)req->sp; */ stkp = (ulong *)req->prevsp; for (stkp++; INSTACK(stkp, bt); stkp++) { value = GET_STACK_ULONG(stkp); if (IS_KVADDR(value) && is_kernel_text(value)) { if (STREQ(closest_symbol(value), "entSys")) { req->pc = value; req->sp = USER_EFRAME_ADDR(req->task); return TRUE; } } } } /* * Just find the next location containing text. (?) */ if (STREQ(name, "do_coredump")) { stkp = (ulong *)(req->sp + sizeof(long)); for (stkp++; INSTACK(stkp, bt); stkp++) { value = GET_STACK_ULONG(stkp); if (IS_KVADDR(value) && is_kernel_text(value)) { req->pc = req->ra; req->sp = (ulong)stkp; return TRUE; } } } if (flags & BT_SPECULATE) return FALSE; if (CRASHDEBUG(1)) { fprintf(fp, "RESYNC3: prevsp: %lx ra: %lx name: %s\n", req->prevsp, req->ra, name); fprintf(fp, "RESYNC3: prevpc: %lx\n", req->prevpc); } stkp_newpc = stkp_next = 0; newpc = 0; found = FALSE; if (exception) { newpc = req->ra; stkp = (ulong *)req->sp; } else stkp = (ulong *)req->prevsp; if (CRASHDEBUG(1)) fprintf(fp, "RESYNC4: stkp: %lx newpc: %lx\n", (ulong)stkp, newpc); for (stkp++; INSTACK(stkp, bt); stkp++) { value = GET_STACK_ULONG(stkp); /* * First find the new pc on the stack. */ if (!found) { if (!exception && is_kernel_text(value)) { found = TRUE; } else if (value == newpc) { found = TRUE; stkp_newpc = stkp; continue; } } if (!IS_KVADDR(value)) continue; if (is_kernel_text(value)) { if (!stkp_next) stkp_next = stkp; if (CRASHDEBUG(2)) { fprintf(fp, "RESYNC6: disassemble %lx (%s)\n", value - sizeof(uint), value_to_symstr(value - sizeof(uint), buf, 0)); } req->command = GNU_DISASSEMBLE; req->addr = value - sizeof(uint); sprintf(addr, "0x%lx", req->addr); open_tmpfile(); req->fp = pc->tmpfile; gdb_interface(req); rewind(pc->tmpfile); while (fgets(buf, BUFSIZE, pc->tmpfile)) { clean_line(buf); if (STRNEQ(buf, "Dump of") || STRNEQ(buf, "End of")) continue; if (STRNEQ(buf, addr)) { if (LASTCHAR(buf) == ':') { fgets(buf, BUFSIZE, pc->tmpfile); clean_line(buf); } if (CRASHDEBUG(2) && (strstr(buf, "jsr") || strstr(buf, "bsr"))) fprintf(pc->saved_fp, "%s\n", buf); if ((strstr(buf, "jsr") || strstr(buf, "bsr")) && (strstr(buf, lookfor1) || strstr(buf, lookfor2))) { if (exception) { req->pc = newpc; req->sp = (ulong)stkp; } else req->pc = req->addr; close_tmpfile(); return TRUE; } } } close_tmpfile(); } } if (CRASHDEBUG(1)) { fprintf(fp, "RESYNC9: [%d] name: %s pc: %lx ra: %lx\n", req->curframe, name, req->pc, req->ra); fprintf(fp, "RESYNC9: sp: %lx lastsp: %lx\n", req->sp, req->lastsp); fprintf(fp, "RESYNC9: prevpc: %lx prevsp: %lx\n", req->prevpc, req->prevsp); } /* * At this point, all we can do is speculate based upon * past experiences... */ return (alpha_resync_speculate(req, flags, bt)); } /* * Try one level of speculation. If it works, fine -- if not, give up. */ static int alpha_resync_speculate(struct gnu_request *req, ulong flags, struct bt_info *bt) { ulong *stkp; ulong value; ulong found_sp, found_ra; struct stack_hook hook; struct bt_info bt_info, *btloc; char buf[BUFSIZE]; int kernel_thread; int looks_good; if (flags & BT_SPECULATE) /* already been here on this trace... */ return FALSE; if (pc->tmpfile) return FALSE; found_ra = found_sp = 0; kernel_thread = is_kernel_thread(req->task); /* * Add "known" possibilities here. */ switch (flags & (BT_FROM_EXCEPTION|BT_FROM_CALLFRAME)) { case BT_FROM_EXCEPTION: if (STREQ(closest_symbol(req->prevpc), "read_lock") || STREQ(closest_symbol(req->ra), "do_select") || STREQ(closest_symbol(req->ra), "schedule")) { stkp = (ulong *)req->sp; for (stkp++; INSTACK(stkp, bt); stkp++) { value = GET_STACK_ULONG(stkp); if (found_ra) { if (is_kernel_text_offset(value)) { found_sp = (ulong)stkp; break; } continue; } if (value == req->ra) found_ra = value; } } break; case BT_FROM_CALLFRAME: if (STREQ(closest_symbol(req->ra), "sys_read")) { value = GET_STACK_ULONG(req->prevsp - 32); if (STREQ(closest_symbol(value), "entSys")) { found_ra = value; found_sp = req->prevsp - 32; } } else if (STREQ(closest_symbol(req->ra), "exit_autofs4_fs")) { stkp = (ulong *)req->sp; for (stkp++; INSTACK(stkp, bt); stkp++) { value = GET_STACK_ULONG(stkp); if (found_ra && (value != found_ra)) { if (is_kernel_text_offset(value)) { found_sp = (ulong)stkp; break; } continue; } if (is_kernel_text_offset(value)) found_ra = value; } } break; default: if (req->hookp && STREQ(closest_symbol(req->prevpc), "filemap_nopage") && !STREQ(closest_symbol(req->hookp->eip), "do_no_page")) { found_ra = found_sp = 0; stkp = (ulong *)req->prevsp; for (stkp++; INSTACK(stkp, bt); stkp++) { value = GET_STACK_ULONG(stkp); if (found_ra && (value != found_ra)) { if (is_kernel_text_offset(value)) { found_sp = (ulong)stkp; break; } continue; } if (is_kernel_text_offset(value) && STREQ(closest_symbol(value), "do_no_page")) found_ra = value; } if (found_ra && found_sp) { req->hookp->eip = found_ra; req->hookp->esp = found_sp; return TRUE; } } if (req->hookp) { found_ra = req->hookp->eip; found_sp = req->hookp->esp; } break; } if (found_ra && found_sp) { looks_good = FALSE; hook.esp = found_sp; hook.eip = found_ra; if (CRASHDEBUG(1)) fprintf(pc->saved_fp, "----- RESYNC SPECULATE START -----\n"); open_tmpfile(); btloc = &bt_info; BZERO(btloc, sizeof(struct bt_info)); btloc->task = req->task; btloc->tc = bt->tc; btloc->stackbase = bt->stackbase; btloc->stacktop = bt->stacktop; btloc->flags = BT_SPECULATE; btloc->hp = &hook; back_trace(btloc); rewind(pc->tmpfile); while (fgets(buf, BUFSIZE, pc->tmpfile)) { if (CRASHDEBUG(1)) fprintf(pc->saved_fp, "%s", buf); if (strstr(buf, "NOTE: cannot resolve")) { looks_good = FALSE; break; } if (strstr(buf, "ALPHA EXCEPTION FRAME")) { looks_good = TRUE; break; } if (kernel_thread) { if (strstr(buf, " kernel_thread ") || strstr(buf, " __kernel_thread ") || strstr(buf, " start_kernel ") || strstr(buf, " smp_callin ")) { looks_good = TRUE; break; } } } close_tmpfile(); if (CRASHDEBUG(1)) fprintf(pc->saved_fp, "----- RESYNC SPECULATE DONE ------\n"); if (looks_good) { req->pc = found_ra; req->sp = found_sp; return TRUE; } } return FALSE; } /* * Translates a user virtual address to its physical address. cmd_vtop() * sets the verbose flag so that the pte translation gets displayed; all * other callers quietly accept the translation. * * This routine can also take mapped kernel virtual addresses if the -u flag * was passed to cmd_vtop(). If so, it makes the translation using the * kernel-memory PGD entry instead of swapper_pg_dir. */ static int alpha_uvtop(struct task_context *tc, ulong vaddr, physaddr_t *paddr, int verbose) { ulong mm; ulong *pgd; ulong *page_dir; ulong *page_middle; ulong *page_table; ulong pgd_pte; ulong pmd_pte; ulong pte; if (!tc) error(FATAL, "current context invalid\n"); *paddr = 0; if (is_kernel_thread(tc->task) && IS_KVADDR(vaddr)) { pgd = (ulong *)machdep->get_task_pgd(tc->task); } else { if (!tc->mm_struct) pgd = (ulong *)machdep->get_task_pgd(tc->task); else { if ((mm = task_mm(tc->task, TRUE))) pgd = ULONG_PTR(tt->mm_struct + OFFSET(mm_struct_pgd)); else readmem(tc->mm_struct + OFFSET(mm_struct_pgd), KVADDR, &pgd, sizeof(long), "mm_struct pgd", FAULT_ON_ERROR); } } if (verbose) fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd); page_dir = pgd + ((vaddr >> PGDIR_SHIFT) & (PTRS_PER_PAGE - 1)); FILL_PGD(PAGEBASE(pgd), KVADDR, PAGESIZE()); pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(page_dir)); if (verbose) fprintf(fp, " PGD: %lx => %lx\n", (ulong)page_dir, pgd_pte); if (!(pgd_pte & _PAGE_VALID)) goto no_upage; page_middle = (ulong *) (PTOV((pgd_pte & _PFN_MASK) >> (32-PAGESHIFT()))) + ((vaddr >> PMD_SHIFT) & (PTRS_PER_PAGE - 1)); FILL_PMD(PAGEBASE(page_middle), KVADDR, PAGESIZE()); pmd_pte = ULONG(machdep->pmd + PAGEOFFSET(page_middle)); if (verbose) fprintf(fp, " PMD: %lx => %lx\n", (ulong)page_middle, pmd_pte); if (!(pmd_pte & _PAGE_VALID)) goto no_upage; page_table = (ulong *) (PTOV((pmd_pte & _PFN_MASK) >> (32-PAGESHIFT()))) + (BTOP(vaddr) & (PTRS_PER_PAGE - 1)); FILL_PTBL(PAGEBASE(page_table), KVADDR, PAGESIZE()); pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table)); if (verbose) fprintf(fp, " PTE: %lx => %lx\n", (ulong)page_table, pte); if (!(pte & (_PAGE_VALID))) { *paddr = pte; if (pte && verbose) { fprintf(fp, "\n"); alpha_translate_pte(pte, 0, 0); } goto no_upage; } *paddr = ((pte & _PFN_MASK) >> (32-PAGESHIFT())) + PAGEOFFSET(vaddr); if (verbose) { fprintf(fp, " PAGE: %lx\n\n", PAGEBASE(*paddr)); alpha_translate_pte(pte, 0, 0); } return TRUE; no_upage: return FALSE; } /* * Translates a kernel virtual address to its physical address. cmd_vtop() * sets the verbose flag so that the pte translation gets displayed; all * other callers quietly accept the translation. */ static int alpha_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose) { ulong *pgd; ulong *page_dir; ulong *page_middle; ulong *page_table; ulong pgd_pte; ulong pmd_pte; ulong pte; if (!IS_KVADDR(kvaddr)) return FALSE; if (!vt->vmalloc_start) { /* presume KSEG this early */ *paddr = VTOP(kvaddr); return TRUE; } if (!IS_VMALLOC_ADDR(kvaddr)) { *paddr = VTOP(kvaddr); return TRUE; } pgd = (ulong *)vt->kernel_pgd[0]; if (verbose) fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd); page_dir = pgd + ((kvaddr >> PGDIR_SHIFT) & (PTRS_PER_PAGE - 1)); FILL_PGD(PAGEBASE(pgd), KVADDR, PAGESIZE()); pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(page_dir)); if (verbose) fprintf(fp, " PGD: %lx => %lx\n", (ulong)page_dir, pgd_pte); if (!(pgd_pte & _PAGE_VALID)) goto no_kpage; page_middle = (ulong *) (PTOV((pgd_pte & _PFN_MASK) >> (32-PAGESHIFT()))) + ((kvaddr >> PMD_SHIFT) & (PTRS_PER_PAGE - 1)); FILL_PMD(PAGEBASE(page_middle), KVADDR, PAGESIZE()); pmd_pte = ULONG(machdep->pmd + PAGEOFFSET(page_middle)); if (verbose) fprintf(fp, " PMD: %lx => %lx\n", (ulong)page_middle, pmd_pte); if (!(pmd_pte & _PAGE_VALID)) goto no_kpage; page_table = (ulong *) (PTOV((pmd_pte & _PFN_MASK) >> (32-PAGESHIFT()))) + (BTOP(kvaddr) & (PTRS_PER_PAGE - 1)); FILL_PTBL(PAGEBASE(page_table), KVADDR, PAGESIZE()); pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table)); if (verbose) fprintf(fp, " PTE: %lx => %lx\n", (ulong)page_table, pte); if (!(pte & (_PAGE_VALID))) { if (pte && verbose) { fprintf(fp, "\n"); alpha_translate_pte(pte, 0, 0); } goto no_kpage; } *paddr = ((pte & _PFN_MASK) >> (32-PAGESHIFT())) + PAGEOFFSET(kvaddr); if (verbose) { fprintf(fp, " PAGE: %lx\n\n", PAGEBASE(*paddr)); alpha_translate_pte(pte, 0, 0); } return TRUE; no_kpage: return FALSE; } /* * Get the relevant page directory pointer from a task structure. */ static ulong alpha_get_task_pgd(ulong task) { long offset; ulong ptbr; offset = OFFSET_OPTION(task_struct_thread, task_struct_tss); offset += OFFSET(thread_struct_ptbr); readmem(task + offset, KVADDR, &ptbr, sizeof(ulong), "task thread ptbr", FAULT_ON_ERROR); return(PTOV(PTOB(ptbr))); } /* * Calculate and return the speed of the processor. */ static ulong alpha_processor_speed(void) { ulong hwrpb; long offset; long cycle_freq; ulong mhz; if (machdep->mhz) return machdep->mhz; mhz = 0; get_symbol_data("hwrpb", sizeof(void *), &hwrpb); offset = OFFSET(hwrpb_struct_cycle_freq); if (!hwrpb || (offset == -1) || !readmem(hwrpb+offset, KVADDR, &cycle_freq, sizeof(ulong), "hwrpb cycle_freq", RETURN_ON_ERROR)) return (machdep->mhz = mhz); mhz = cycle_freq/1000000; return (machdep->mhz = mhz); } void alpha_dump_machdep_table(ulong arg) { int others; others = 0; fprintf(fp, " flags: %lx (", machdep->flags); if (machdep->flags & HWRESET) fprintf(fp, "%sHWRESET", others++ ? "|" : ""); fprintf(fp, ")\n"); fprintf(fp, " kvbase: %lx\n", machdep->kvbase); fprintf(fp, " identity_map_base: %lx\n", machdep->identity_map_base); fprintf(fp, " pagesize: %d\n", machdep->pagesize); fprintf(fp, " pageshift: %d\n", machdep->pageshift); fprintf(fp, " pagemask: %llx\n", machdep->pagemask); fprintf(fp, " pageoffset: %lx\n", machdep->pageoffset); fprintf(fp, " stacksize: %ld\n", machdep->stacksize); fprintf(fp, " hz: %d\n", machdep->hz); fprintf(fp, " mhz: %ld\n", machdep->mhz); fprintf(fp, " memsize: %ld (0x%lx)\n", machdep->memsize, machdep->memsize); fprintf(fp, " bits: %d\n", machdep->bits); fprintf(fp, " nr_irqs: %d\n", machdep->nr_irqs); fprintf(fp, " eframe_search: alpha_eframe_search()\n"); fprintf(fp, " back_trace: alpha_back_trace_cmd()\n"); fprintf(fp, " processor_speed: alpha_processor_speed()\n"); fprintf(fp, " uvtop: alpha_uvtop()\n"); fprintf(fp, " kvtop: alpha_uvtop()\n"); fprintf(fp, " get_task_pgd: alpha_get_task_pgd()\n"); if (machdep->dump_irq == generic_dump_irq) fprintf(fp, " dump_irq: generic_dump_irq()\n"); else fprintf(fp, " dump_irq: alpha_dump_irq()\n"); fprintf(fp, " get_stack_frame: alpha_get_stack_frame()\n"); fprintf(fp, " get_stackbase: generic_get_stackbase()\n"); fprintf(fp, " get_stacktop: generic_get_stacktop()\n"); fprintf(fp, " translate_pte: alpha_translate_pte()\n"); fprintf(fp, " memory_size: alpha_get_memory_size()\n"); fprintf(fp, " vmalloc_start: alpha_get_vmalloc_start()\n"); fprintf(fp, " is_task_addr: alpha_is_task_addr()\n"); fprintf(fp, " verify_symbol: alpha_verify_symbol()\n"); fprintf(fp, " dis_filter: alpha_dis_filter()\n"); fprintf(fp, " cmd_mach: alpha_cmd_mach()\n"); fprintf(fp, " get_smp_cpus: alpha_get_smp_cpus()\n"); fprintf(fp, " is_kvaddr: generic_is_kvaddr()\n"); fprintf(fp, " is_uvaddr: generic_is_uvaddr()\n"); fprintf(fp, " verify_paddr: generic_verify_paddr()\n"); fprintf(fp, " init_kernel_pgd: NULL\n"); fprintf(fp, " value_to_symbol: generic_machdep_value_to_symbol()\n"); fprintf(fp, " line_number_hooks: alpha_line_number_hooks\n"); fprintf(fp, " last_pgd_read: %lx\n", machdep->last_pgd_read); fprintf(fp, " last_pmd_read: %lx\n", machdep->last_pmd_read); fprintf(fp, " last_ptbl_read: %lx\n", machdep->last_ptbl_read); fprintf(fp, " pgd: %lx\n", (ulong)machdep->pgd); fprintf(fp, " pmd: %lx\n", (ulong)machdep->pmd); fprintf(fp, " ptbl: %lx\n", (ulong)machdep->ptbl); fprintf(fp, " ptrs_per_pgd: %d\n", machdep->ptrs_per_pgd); fprintf(fp, " machspec: %lx\n", (ulong)machdep->machspec); } /* * Fix up jsr's to show the right target. * * If a value is passed with no buf, then cmd_dis is fishing for whether * the GP can be calculated from the first couple of instructions of the * target routine: * * 0xfffffc0000349fa0 : ldah gp,35(t12) * 0xfffffc0000349fa4 : lda gp,6216(gp) * * If a buf pointer is passed, then check whether the t12 register * is being set up as an offset from gp, then calculate the target address: * * 0xfffffc000042c364 : ldq t12,-29336(gp) * 0xfffffc000042c368 : * jsr ra,(t12),0xfffffc0000429dc0 * * If the next instruction is a jsr ra,(t12), then correct the bracketed * target address translation. * */ #define LDAH_GP_T12 (0x27bb0000) #define LDA_GP_GP (0x23bd0000) #define LDQ_T12_GP (0xa77d0000) #define JSR_RA_T12 (0x6b5b0000) #define OPCODE_OPERAND_MASK (0xffff0000) #define OPCODE_MEM_DISP_MASK (0x0000ffff) static struct instruction_data { uint inst[2]; short mem_disp[2]; ulong gp; ulong target; char *curfunc; } instruction_data = { {0} }; static int alpha_dis_filter(ulong vaddr, char *buf, unsigned int output_radix) { struct syment *sp; struct instruction_data *id; char buf2[BUFSIZE], *p1; id = &instruction_data; if (!buf) { BZERO(id, sizeof(struct instruction_data)); if (!(sp = value_search(vaddr, NULL))) return FALSE; readmem(sp->value, KVADDR, &id->inst[0], sizeof(uint) * 2, "two instructions", FAULT_ON_ERROR); if (((id->inst[0] & OPCODE_OPERAND_MASK) == LDAH_GP_T12) && ((id->inst[1] & OPCODE_OPERAND_MASK) == LDA_GP_GP)) { id->mem_disp[0] = (short)(id->inst[0] & OPCODE_MEM_DISP_MASK); id->mem_disp[1] = (short)(id->inst[1] & OPCODE_MEM_DISP_MASK); id->gp = sp->value + (65536*id->mem_disp[0]) + id->mem_disp[1]; id->curfunc = sp->name; if (CRASHDEBUG(1)) console("%s: ldah(%d) and lda(%d) gp: %lx\n", id->curfunc, id->mem_disp[0], id->mem_disp[1], id->gp); return TRUE; } /* send all lines through the generic */ return TRUE; /* dis_address_translation() filter */ } dis_address_translation(vaddr, buf, output_radix); if (!id->gp || !(sp = value_search(vaddr, NULL)) || !STREQ(id->curfunc, sp->name)) { BZERO(id, sizeof(struct instruction_data)); return FALSE; } readmem(vaddr, KVADDR, &id->inst[0], sizeof(uint), "one instruction", FAULT_ON_ERROR); if ((id->inst[0] & OPCODE_OPERAND_MASK) == JSR_RA_T12) { if (!id->target || !strstr(buf, "jsr\tra,(t12)") || !strstr(buf, "<")) return FALSE; p1 = strstr(strstr(buf, "jsr"), "0x"); sprintf(p1, "0x%lx <%s>%s", id->target, value_to_symstr(id->target, buf2, output_radix), CRASHDEBUG(1) ? " [PATCHED]\n" : "\n"); return TRUE; } if ((id->inst[0] & OPCODE_OPERAND_MASK) == LDQ_T12_GP) { id->mem_disp[0] = (short)(id->inst[0] & OPCODE_MEM_DISP_MASK); readmem(id->gp + id->mem_disp[0], KVADDR, &id->target, sizeof(ulong), "jsr target", FAULT_ON_ERROR); } else id->target = 0; return TRUE; } /* * For some reason gdb can go off into the weeds translating text addresses, * so this routine both fixes the references as well as imposing the current * output radix on the translations. */ static void dis_address_translation(ulong vaddr, char *inbuf, unsigned int output_radix) { char buf1[BUFSIZE]; char buf2[BUFSIZE]; char *colon, *p1; int argc; char *argv[MAXARGS]; ulong value; console("IN: %s", inbuf); colon = strstr(inbuf, ":"); if (colon) { sprintf(buf1, "0x%lx <%s>", vaddr, value_to_symstr(vaddr, buf2, output_radix)); sprintf(buf2, "%s%s", buf1, colon); strcpy(inbuf, buf2); } strcpy(buf1, inbuf); argc = parse_line(buf1, argv); if ((FIRSTCHAR(argv[argc-1]) == '<') && (LASTCHAR(argv[argc-1]) == '>')) { p1 = rindex(inbuf, '<'); while ((p1 > inbuf) && (*p1 != ',')) p1--; if (!STRNEQ(p1, ",0x")) return; p1++; if (!extract_hex(p1, &value, NULLCHAR, TRUE)) return; sprintf(buf1, "0x%lx <%s>\n", value, value_to_symstr(value, buf2, output_radix)); sprintf(p1, "%s", buf1); } console(" %s", inbuf); } /* * If we're generically-inclined, call generic_dump_irq(). Otherwise * dump the IRQ table the old-fashioned way. */ static void alpha_dump_irq(int irq) { ulong action; ulong value; char *arglist[MAXARGS]; int argc, others; char buf[BUFSIZE]; if (symbol_exists("irq_desc")) { machdep->dump_irq = generic_dump_irq; return(generic_dump_irq(irq)); } action = symbol_value("irq_action") + (sizeof(void *) * irq); readmem(action, KVADDR, &action, sizeof(void *), "irq_action pointer", FAULT_ON_ERROR); if (!action) { fprintf(fp, " IRQ: %d\n", irq); fprintf(fp, "handler:\n"); fprintf(fp, " flags: \n"); fprintf(fp, " mask: \n"); fprintf(fp, " name: \n"); fprintf(fp, " dev_id: \n"); fprintf(fp, " next: \n\n"); return; } fprintf(fp, " IRQ: %d\n", irq); open_tmpfile(); do_linked_action: dump_struct("irqaction", action, RADIX(16)); action = 0; rewind(pc->tmpfile); while (fgets(buf, BUFSIZE, pc->tmpfile)) { strip_comma(buf); argc = parse_line(buf, arglist); if (STREQ(arglist[0], "struct") || STREQ(buf, "};")) continue; if (STREQ(arglist[0], "handler")) { fprintf(pc->saved_fp, "handler: %s ", strip_hex(arglist[2])); if (argc == 4) fprintf(pc->saved_fp, "%s", arglist[3]); fprintf(pc->saved_fp, "\n"); } if (STREQ(arglist[0], "flags")) { value = htol(strip_comma(arglist[2]), FAULT_ON_ERROR, NULL); fprintf(pc->saved_fp, " flags: %lx ", value); if (value) { others = 0; fprintf(pc->saved_fp, "("); if (value & SA_INTERRUPT) fprintf(pc->saved_fp, "%sSA_INTERRUPT", others++ ? "|" : ""); if (value & SA_PROBE) fprintf(pc->saved_fp, "%sSA_PROBE", others++ ? "|" : ""); if (value & SA_SAMPLE_RANDOM) fprintf(pc->saved_fp, "%sSA_SAMPLE_RANDOM", others++ ? "|" : ""); if (value & SA_SHIRQ) fprintf(pc->saved_fp, "%sSA_SHIRQ", others++ ? "|" : ""); fprintf(pc->saved_fp, ")"); if (value & ~ACTION_FLAGS) { fprintf(pc->saved_fp, " (bits %lx not translated)", value & ~ACTION_FLAGS); } } fprintf(pc->saved_fp, "\n"); } if (STREQ(arglist[0], "mask")) { value = htol(strip_comma(arglist[2]), FAULT_ON_ERROR, NULL); fprintf(pc->saved_fp, " mask: %lx\n", value); } if (STREQ(arglist[0], "name")) { fprintf(pc->saved_fp, " name: %s ", strip_hex(arglist[2])); if (argc == 4) fprintf(pc->saved_fp, "\"%s\"", arglist[3]); fprintf(pc->saved_fp, "\n"); } if (STREQ(arglist[0], "dev_id")) { value = htol(strip_comma(arglist[2]), FAULT_ON_ERROR, NULL); fprintf(pc->saved_fp, " dev_id: %lx\n", value); } if (STREQ(arglist[0], "next")) { value = htol(strip_comma(arglist[2]), FAULT_ON_ERROR, NULL); fprintf(pc->saved_fp, " next: %s\n", strip_hex(arglist[2])); if (value) action = value; } } close_tmpfile(); fprintf(fp, "\n"); if (action) goto do_linked_action; } /* * Get a stack frame combination of pc and ra from the most relevent spot. */ static void alpha_get_stack_frame(struct bt_info *bt, ulong *pcp, ulong *spp) { struct syment *sp; ulong ksp; ulong ip; if (pcp) { if (DUMPFILE() && is_panic_thread(bt->task)) { sp = next_symbol("crash_save_current_state", NULL); if (HWRESET_TASK(bt->task)) ip = get_percpu_data(0, GET_HALT_PC, 0); else if (sp) ip = sp->value - 4; else ip = symbol_value("crash_save_current_state") + 16; } else get_alpha_frame(bt, &ip, NULL); *pcp = ip; } if (spp) { ip = 0; if (!get_panic_ksp(bt, &ksp)) get_alpha_frame(bt, HWRESET_TASK(bt->task) ? &ip : NULL, &ksp); if (!INSTACK(ksp, bt)) error(FATAL, "cannot determine starting stack address\n", bt->task); *spp = ksp; if (ip) *pcp = ip; } } /* * Do the work formerly done by alpha_get_sp() and alpha_get_pc(). */ static void get_alpha_frame(struct bt_info *bt, ulong *getpc, ulong *getsp) { int i; ulong ip; ulong r26; ulong ksp, sp; ulong *spp; ulong percpu_ra; ulong percpu_pv; struct percpu_data percpu_data; char buf[BUFSIZE]; ulong task; ulong *stack; task = bt->task; stack = (ulong *)bt->stackbuf; if (tt->flags & THREAD_INFO) { /* pcb.ksp is 1st word in thread_info */ readmem(bt->tc->thread_info, KVADDR, &ksp, sizeof(ulong), "thread_info pcb ksp", FAULT_ON_ERROR); sp = ksp; } else if (VALID_MEMBER(task_struct_tss_ksp)) ksp = sp = stack[OFFSET(task_struct_tss_ksp)/sizeof(long)]; else ksp = sp = stack[OFFSET(task_struct_thread_ksp)/sizeof(long)]; ip = 0; percpu_ra = percpu_pv = 0; spp = &stack[(sp - task)/sizeof(long)]; if (DUMPFILE() && getsp) { if (HWRESET_TASK(task)) { if (INSTACK(sp, bt)) { *getsp = sp; return; } else { get_percpu_data(0, 0, &percpu_data); percpu_ra = percpu_data.halt_ra; percpu_pv = percpu_data.halt_pv; spp = &stack[roundup(SIZE(task_struct), sizeof(ulong)) / sizeof(ulong)]; } } if (!percpu_ra && (STREQ(closest_symbol(*spp), "panic") || STREQ(closest_symbol(*spp), "handle_ipi"))) { *getsp = sp; return; } } percpu_retry: if (CRASHDEBUG(1) && percpu_ra) { fprintf(fp, "get_alpha_frame: look for %lx (%s)\n", percpu_ra, value_to_symstr(percpu_ra, buf, 0)); } for (i = 0, spp++; spp < &stack[LONGS_PER_STACK]; spp++,i++) { if (CRASHDEBUG(1) && (percpu_ra || percpu_pv) && is_kernel_text(*spp)) { fprintf(fp, "%lx: %lx (%s)\n", ((ulong)spp - (ulong)stack) + task, *spp, value_to_symstr(*spp, buf, 0)); } if (percpu_ra) { if (*spp == percpu_ra) { *getsp = ((ulong)spp - (ulong)stack) + task; return; } continue; } else if (percpu_pv) { if (*spp == percpu_pv) { *getsp = ((ulong)spp - (ulong)stack) + task; if (getpc) *getpc = percpu_pv; return; } continue; } if (!INSTACK(*spp, bt)) continue; if (is_kernel_text(*(spp+1))) { sp = *spp; ip = *(spp+1); break; } } if (percpu_ra) { percpu_ra = 0; error(INFO, "cannot find return address (percpu_ra) in HARDWARE RESET stack\n"); error(INFO, "looking for procedure address (percpu_pv) in HARDWARE RESET stack\n"); if (CRASHDEBUG(1)) { fprintf(fp, "get_alpha_frame: look for %lx (%s)\n", percpu_pv, value_to_symstr(percpu_pv, buf, 0)); } spp = &stack[roundup(SIZE(task_struct), sizeof(ulong)) / sizeof(ulong)]; goto percpu_retry; } if (percpu_pv) { error(INFO, "cannot find procedure address (percpu_pv) in HARDWARE RESET stack\n"); } /* * Check for a forked task that has not yet run in user space. */ if (!ip) { if (INSTACK(ksp + OFFSET(switch_stack_r26), bt)) { readmem(ksp + OFFSET(switch_stack_r26), KVADDR, &r26, sizeof(ulong), "ret_from_smp_fork check", FAULT_ON_ERROR); if (STREQ(closest_symbol(r26), "ret_from_smp_fork") || STREQ(closest_symbol(r26), "ret_from_smpfork")) { ip = r26; sp = ksp; } } } if (getsp) *getsp = sp; if (getpc) *getpc = ip; } /* * Fill the percpu_data structure with information from the * hwrpb/percpu_data structures for a given CPU. If requested, * return one of the specified entries. */ static ulong get_percpu_data(int cpu, ulong flag, struct percpu_data *pd) { ulong hwrpb, halt_ra, halt_PC, halt_pv; unsigned long processor_offset, processor_size; get_symbol_data("hwrpb", sizeof(void *), &hwrpb); readmem(hwrpb+OFFSET(hwrpb_struct_processor_offset), KVADDR, &processor_offset, sizeof(ulong), "hwrpb processor_offset", FAULT_ON_ERROR); readmem(hwrpb+OFFSET(hwrpb_struct_processor_size), KVADDR, &processor_size, sizeof(ulong), "hwrpb processor_size", FAULT_ON_ERROR); readmem(hwrpb + processor_offset + (cpu * processor_size) + OFFSET(percpu_struct_halt_PC), KVADDR, &halt_PC, sizeof(ulong), "percpu halt_PC", FAULT_ON_ERROR); readmem(hwrpb + processor_offset + (cpu * processor_size) + OFFSET(percpu_struct_halt_ra), KVADDR, &halt_ra, sizeof(ulong), "percpu halt_ra", FAULT_ON_ERROR); readmem(hwrpb + processor_offset + (cpu * processor_size) + OFFSET(percpu_struct_halt_pv), KVADDR, &halt_pv, sizeof(ulong), "percpu halt_pv", FAULT_ON_ERROR); if (pd) { pd->halt_PC = halt_PC; pd->halt_ra = halt_ra; pd->halt_pv = halt_pv; } switch (flag) { case GET_HALT_PC: return halt_PC; case GET_HALT_RA: return halt_ra; case GET_HALT_PV: return halt_pv; default: return 0; } } /* * Translate a PTE, returning TRUE if the page is _PAGE_VALID or _PAGE_PRESENT, * whichever is appropriate for the machine type. If a physaddr pointer is * passed in, don't print anything. */ static int alpha_translate_pte(ulong pte, void *physaddr, ulonglong unused) { int c, len1, len2, len3, others, page_present; char buf[BUFSIZE]; char buf2[BUFSIZE]; char buf3[BUFSIZE]; char ptebuf[BUFSIZE]; char physbuf[BUFSIZE]; char *arglist[MAXARGS]; physaddr_t paddr; paddr = PTOB(pte >> 32); page_present = (pte & _PAGE_VALID); if (physaddr) { *((ulong *)physaddr) = paddr; return page_present; } sprintf(ptebuf, "%lx", pte); len1 = MAX(strlen(ptebuf), strlen("PTE")); fprintf(fp, "%s ", mkstring(buf, len1, CENTER|LJUST, "PTE")); if (!page_present && pte) { swap_location(pte, buf); if ((c = parse_line(buf, arglist)) != 3) error(FATAL, "cannot determine swap location\n"); len2 = MAX(strlen(arglist[0]), strlen("SWAP")); len3 = MAX(strlen(arglist[2]), strlen("OFFSET")); fprintf(fp, "%s %s\n", mkstring(buf2, len2, CENTER|LJUST, "SWAP"), mkstring(buf3, len3, CENTER|LJUST, "OFFSET")); strcpy(buf2, arglist[0]); strcpy(buf3, arglist[2]); fprintf(fp, "%s %s %s\n", mkstring(ptebuf, len1, CENTER|RJUST, NULL), mkstring(buf2, len2, CENTER|RJUST, NULL), mkstring(buf3, len3, CENTER|RJUST, NULL)); return page_present; } sprintf(physbuf, "%llx", paddr); len2 = MAX(strlen(physbuf), strlen("PHYSICAL")); fprintf(fp, "%s ", mkstring(buf, len2, CENTER|LJUST, "PHYSICAL")); fprintf(fp, "FLAGS\n"); fprintf(fp, "%s %s ", mkstring(ptebuf, len1, CENTER|RJUST, NULL), mkstring(physbuf, len2, CENTER|RJUST, NULL)); fprintf(fp, "("); others = 0; if (pte) { if (pte & _PAGE_VALID) fprintf(fp, "%sVALID", others++ ? "|" : ""); if (pte & _PAGE_FOR) fprintf(fp, "%sFOR", others++ ? "|" : ""); if (pte & _PAGE_FOW) fprintf(fp, "%sFOW", others++ ? "|" : ""); if (pte & _PAGE_FOE) fprintf(fp, "%sFOE", others++ ? "|" : ""); if (pte & _PAGE_ASM) fprintf(fp, "%sASM", others++ ? "|" : ""); if (pte & _PAGE_KRE) fprintf(fp, "%sKRE", others++ ? "|" : ""); if (pte & _PAGE_URE) fprintf(fp, "%sURE", others++ ? "|" : ""); if (pte & _PAGE_KWE) fprintf(fp, "%sKWE", others++ ? "|" : ""); if (pte & _PAGE_UWE) fprintf(fp, "%sUWE", others++ ? "|" : ""); if (pte & _PAGE_DIRTY) fprintf(fp, "%sDIRTY", others++ ? "|" : ""); if (pte & _PAGE_ACCESSED) fprintf(fp, "%sACCESSED", others++ ? "|" : ""); } else { fprintf(fp, "no mapping"); } fprintf(fp, ")\n"); return page_present; } /* * This is currently not machine-dependent, but eventually I'd prefer to use * the HWPCB for the real physical memory size. */ static uint64_t alpha_memory_size(void) { return (generic_memory_size()); } /* * Determine where vmalloc'd memory starts. */ static ulong alpha_vmalloc_start(void) { return VMALLOC_START; } /* * ALPHA tasks are all stacksize-aligned. */ static int alpha_is_task_addr(ulong task) { return (IS_KVADDR(task) && (ALIGNED_STACK_OFFSET(task) == 0)); } /* * Keep or reject a symbol from the kernel namelist. */ int alpha_verify_symbol(const char *name, ulong value, char type) { if (CRASHDEBUG(8) && name && strlen(name)) fprintf(fp, "%016lx %s\n", value, name); return (name && strlen(name) && (value > MIN_SYMBOL_VALUE)); } /* * Override smp_num_cpus if possible and necessary. */ int alpha_get_smp_cpus(void) { int cpus; if ((cpus = get_cpus_online())) return cpus; else return kt->cpus; } /* * Machine dependent command. */ void alpha_cmd_mach(void) { int c, cflag; unsigned int radix; cflag = radix = 0; while ((c = getopt(argcnt, args, "cxd")) != EOF) { switch(c) { case 'c': cflag++; break; case 'x': if (radix == 10) error(FATAL, "-d and -x are mutually exclusive\n"); radix = 16; break; case 'd': if (radix == 16) error(FATAL, "-d and -x are mutually exclusive\n"); radix = 10; break; default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); if (cflag) display_hwrpb(radix); else alpha_display_machine_stats(); } /* * "mach" command output. */ static void alpha_display_machine_stats(void) { struct new_utsname *uts; char buf[BUFSIZE]; ulong mhz; uts = &kt->utsname; fprintf(fp, " MACHINE TYPE: %s\n", uts->machine); fprintf(fp, " MEMORY SIZE: %s\n", get_memory_size(buf)); fprintf(fp, " CPUS: %d\n", kt->cpus); fprintf(fp, " PROCESSOR SPEED: "); if ((mhz = machdep->processor_speed())) fprintf(fp, "%ld Mhz\n", mhz); else fprintf(fp, "(unknown)\n"); fprintf(fp, " HZ: %d\n", machdep->hz); fprintf(fp, " PAGE SIZE: %d\n", PAGESIZE()); fprintf(fp, " L1 CACHE SIZE: %d\n", l1_cache_size()); fprintf(fp, "KERNEL VIRTUAL BASE: %lx\n", machdep->kvbase); fprintf(fp, "KERNEL VMALLOC BASE: %lx\n", vt->vmalloc_start); fprintf(fp, " KERNEL STACK SIZE: %ld\n", STACKSIZE()); } /* * Display the hwrpb_struct and each percpu_struct. */ static void display_hwrpb(unsigned int radix) { int cpu; ulong hwrpb, percpu; ulong processor_offset, processor_size; get_symbol_data("hwrpb", sizeof(void *), &hwrpb); readmem(hwrpb+OFFSET(hwrpb_struct_processor_offset), KVADDR, &processor_offset, sizeof(ulong), "hwrpb processor_offset", FAULT_ON_ERROR); readmem(hwrpb+OFFSET(hwrpb_struct_processor_size), KVADDR, &processor_size, sizeof(ulong), "hwrpb processor_size", FAULT_ON_ERROR); fprintf(fp, "HWRPB:\n"); dump_struct("hwrpb_struct", hwrpb, radix); for (cpu = 0; cpu < kt->cpus; cpu++) { fprintf(fp, "\nCPU %d:\n", cpu); percpu = hwrpb + processor_offset + (processor_size * cpu); dump_struct("percpu_struct", percpu, radix); } } /* * Perform any leftover pre-prompt machine-specific initialization tasks here. */ static void alpha_post_init(void) { modify_signame(7, "SIGEMT", NULL); modify_signame(10, "SIGBUS", NULL); modify_signame(12, "SIGSYS", NULL); modify_signame(16, "SIGURG", NULL); modify_signame(17, "SIGSTOP", NULL); modify_signame(18, "SIGTSTP", NULL); modify_signame(19, "SIGCONT", NULL); modify_signame(20, "SIGCHLD", NULL); modify_signame(23, "SIGIO", "SIGPOLL"); modify_signame(29, "SIGINFO", "SIGPWR"); modify_signame(30, "SIGUSR1", NULL); modify_signame(31, "SIGUSR2", NULL); } #endif /* ALPHA */ crash-utility-crash-61fe107/arm.c000066400000000000000000001360671517256214500167140ustar00rootroot00000000000000/* * arm.c - core analysis suite * * Authors: * Thomas Fänge * Jan Karlsson * Mika Westerberg * * Copyright (C) 2010-2011 Nokia Corporation * Copyright (C) 2010 Sony Ericsson. All rights reserved. * * 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 2 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. */ #ifdef ARM #include #include "defs.h" static void arm_parse_cmdline_args(void); static void arm_get_crash_notes(void); static int arm_verify_symbol(const char *, ulong, char); static int arm_is_module_addr(ulong); static int arm_is_kvaddr(ulong); static int arm_is_uvaddr(ulong, struct task_context *); static int arm_in_exception_text(ulong); static int arm_in_ret_from_syscall(ulong, int *); static void arm_back_trace(struct bt_info *); static void arm_back_trace_cmd(struct bt_info *); static ulong arm_processor_speed(void); static int arm_translate_pte(ulong, void *, ulonglong); static int arm_vtop(ulong, ulong *, physaddr_t *, int); static int arm_kvtop(struct task_context *, ulong, physaddr_t *, int); static int arm_uvtop(struct task_context *, ulong, physaddr_t *, int); static int arm_get_frame(struct bt_info *, ulong *, ulong *); static int arm_get_dumpfile_stack_frame(struct bt_info *, ulong *, ulong *); static void arm_get_stack_frame(struct bt_info *, ulong *, ulong *); static void arm_dump_exception_stack(ulong, ulong); static void arm_display_full_frame(struct bt_info *, ulong); static ulong arm_vmalloc_start(void); static int arm_is_task_addr(ulong); static int arm_dis_filter(ulong, char *, unsigned int); static int arm_eframe_search(struct bt_info *); static ulong arm_get_task_pgd(ulong); static void arm_cmd_mach(void); static void arm_display_machine_stats(void); static int arm_get_smp_cpus(void); static void arm_init_machspec(void); static struct line_number_hook arm_line_number_hooks[]; static struct machine_specific arm_machine_specific; /** * struct arm_cpu_context_save - idle task registers * * This structure holds idle task registers. Only FP, SP, and PC are needed for * unwinding the stack. */ struct arm_cpu_context_save { ulong fp; ulong sp; ulong pc; }; /* * Holds registers during the crash. */ static struct arm_pt_regs *panic_task_regs; #define PGDIR_SIZE() (4 * PAGESIZE()) #define PGDIR_OFFSET(X) (((ulong)(X)) & (PGDIR_SIZE() - 1)) #define _SECTION_PAGE_MASK (~((MEGABYTES(1))-1)) #define PMD_TYPE_MASK 3 #define PMD_TYPE_SECT 2 #define PMD_TYPE_TABLE 1 #define PMD_TYPE_SECT_LPAE 1 static inline ulong * pmd_page_addr(ulong pmd) { ulong ptr; if (machdep->flags & PGTABLE_V2) { ptr = PAGEBASE(pmd); } else { ptr = pmd & ~(PTRS_PER_PTE * sizeof(void *) - 1); ptr += PTRS_PER_PTE * sizeof(void *); } return (ulong *)ptr; } /* * "Linux" PTE definitions. */ #define L_PTE_PRESENT (1 << 0) #define L_PTE_YOUNG (1 << 1) #define L_PTE_FILE (1 << 2) #define L_PTE_DIRTY (1 << 6) #define L_PTE_WRITE (1 << 7) #define L_PTE_RDONLY L_PTE_WRITE #define L_PTE_USER (1 << 8) #define L_PTE_EXEC (1 << 9) #define L_PTE_XN L_PTE_EXEC #define L_PTE_SHARED (1 << 10) #define pte_val(pte) (pte) #define pte_present(pte) (pte_val(pte) & L_PTE_PRESENT) #define pte_write(pte) (pte_val(pte) & L_PTE_WRITE) #define pte_rdonly(pte) (pte_val(pte) & L_PTE_RDONLY) #define pte_dirty(pte) (pte_val(pte) & L_PTE_DIRTY) #define pte_young(pte) (pte_val(pte) & L_PTE_YOUNG) #define pte_exec(pte) (pte_val(pte) & L_PTE_EXEC) #define pte_xn(pte) (pte_val(pte) & L_PTE_XN) /* * Following stuff is taken directly from the kernel sources. These are used in * dump_exception_stack() to format an exception stack entry. */ #define USR26_MODE 0x00000000 #define FIQ26_MODE 0x00000001 #define IRQ26_MODE 0x00000002 #define SVC26_MODE 0x00000003 #define USR_MODE 0x00000010 #define FIQ_MODE 0x00000011 #define IRQ_MODE 0x00000012 #define SVC_MODE 0x00000013 #define ABT_MODE 0x00000017 #define UND_MODE 0x0000001b #define SYSTEM_MODE 0x0000001f #define MODE32_BIT 0x00000010 #define MODE_MASK 0x0000001f #define PSR_T_BIT 0x00000020 #define PSR_F_BIT 0x00000040 #define PSR_I_BIT 0x00000080 #define PSR_A_BIT 0x00000100 #define PSR_E_BIT 0x00000200 #define PSR_J_BIT 0x01000000 #define PSR_Q_BIT 0x08000000 #define PSR_V_BIT 0x10000000 #define PSR_C_BIT 0x20000000 #define PSR_Z_BIT 0x40000000 #define PSR_N_BIT 0x80000000 #define isa_mode(regs) \ ((((regs)->ARM_cpsr & PSR_J_BIT) >> 23) | \ (((regs)->ARM_cpsr & PSR_T_BIT) >> 5)) #define processor_mode(regs) \ ((regs)->ARM_cpsr & MODE_MASK) #define interrupts_enabled(regs) \ (!((regs)->ARM_cpsr & PSR_I_BIT)) #define fast_interrupts_enabled(regs) \ (!((regs)->ARM_cpsr & PSR_F_BIT)) static const char *processor_modes[] = { "USER_26", "FIQ_26", "IRQ_26", "SVC_26", "UK4_26", "UK5_26", "UK6_26", "UK7_26" , "UK8_26", "UK9_26", "UK10_26", "UK11_26", "UK12_26", "UK13_26", "UK14_26", "UK15_26", "USER_32", "FIQ_32", "IRQ_32", "SVC_32", "UK4_32", "UK5_32", "UK6_32", "ABT_32", "UK8_32", "UK9_32", "UK10_32", "UND_32", "UK12_32", "UK13_32", "UK14_32", "SYS_32", }; static const char *isa_modes[] = { "ARM" , "Thumb" , "Jazelle", "ThumbEE", }; #define NOT_IMPLEMENTED() \ error(FATAL, "%s: N/A\n", __func__) /* * Do all necessary machine-specific setup here. This is called several times * during initialization. */ void arm_init(int when) { ulong vaddr; char *string; struct syment *sp; #if defined(__i386__) || defined(__x86_64__) if (ACTIVE()) error(FATAL, "compiled for the ARM architecture\n"); #endif switch (when) { case PRE_SYMTAB: machdep->verify_symbol = arm_verify_symbol; machdep->machspec = &arm_machine_specific; if (pc->flags & KERNEL_DEBUG_QUERY) return; machdep->pagesize = memory_page_size(); machdep->pageshift = ffs(machdep->pagesize) - 1; machdep->pageoffset = machdep->pagesize - 1; machdep->pagemask = ~((ulonglong)machdep->pageoffset); machdep->stacksize = machdep->pagesize * 2; machdep->last_pgd_read = 0; machdep->last_pmd_read = 0; machdep->last_ptbl_read = 0; machdep->verify_paddr = generic_verify_paddr; machdep->ptrs_per_pgd = PTRS_PER_PGD; if (machdep->cmdline_args[0]) arm_parse_cmdline_args(); break; case PRE_GDB: if ((machdep->pgd = (char *)malloc(PGDIR_SIZE())) == NULL) error(FATAL, "cannot malloc pgd space."); if ((machdep->pmd = (char *)malloc(PMDSIZE())) == NULL) error(FATAL, "cannot malloc pmd space."); if ((machdep->ptbl = (char *)malloc(PAGESIZE())) == NULL) error(FATAL, "cannot malloc ptbl space."); /* * LPAE requires an additional page for the PGD, * so PG_DIR_SIZE = 0x5000 for LPAE */ if ((string = pc->read_vmcoreinfo("CONFIG_ARM_LPAE"))) { machdep->flags |= PAE; free(string); } else if ((sp = next_symbol("swapper_pg_dir", NULL)) && (sp->value - symbol_value("swapper_pg_dir")) == 0x5000) machdep->flags |= PAE; machdep->kvbase = symbol_value("_stext") & ~KVBASE_MASK; machdep->identity_map_base = machdep->kvbase; machdep->is_kvaddr = arm_is_kvaddr; machdep->is_uvaddr = arm_is_uvaddr; machdep->eframe_search = arm_eframe_search; machdep->back_trace = arm_back_trace_cmd; machdep->processor_speed = arm_processor_speed; machdep->uvtop = arm_uvtop; machdep->kvtop = arm_kvtop; machdep->get_task_pgd = arm_get_task_pgd; machdep->get_stack_frame = arm_get_stack_frame; machdep->get_stackbase = generic_get_stackbase; machdep->get_stacktop = generic_get_stacktop; machdep->translate_pte = arm_translate_pte; machdep->memory_size = generic_memory_size; machdep->vmalloc_start = arm_vmalloc_start; machdep->is_task_addr = arm_is_task_addr; machdep->dis_filter = arm_dis_filter; machdep->cmd_mach = arm_cmd_mach; machdep->get_smp_cpus = arm_get_smp_cpus; machdep->line_number_hooks = arm_line_number_hooks; machdep->value_to_symbol = generic_machdep_value_to_symbol; machdep->init_kernel_pgd = NULL; machdep->dump_irq = generic_dump_irq; machdep->show_interrupts = generic_show_interrupts; machdep->get_irq_affinity = generic_get_irq_affinity; arm_init_machspec(); break; case POST_GDB: /* * Starting from 2.6.38 hardware and Linux page tables * were reordered. See also mainline kernel commit * d30e45eeabe (ARM: pgtable: switch order of Linux vs * hardware page tables). */ if (THIS_KERNEL_VERSION > LINUX(2,6,37) || STRUCT_EXISTS("pteval_t")) machdep->flags |= PGTABLE_V2; if (THIS_KERNEL_VERSION >= LINUX(3,3,0) || symbol_exists("idmap_pgd")) machdep->flags |= IDMAP_PGD; if (machdep->flags & PAE) { machdep->section_size_bits = _SECTION_SIZE_BITS_LPAE; machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_LPAE; } else { machdep->section_size_bits = _SECTION_SIZE_BITS; machdep->max_physmem_bits = _MAX_PHYSMEM_BITS; } if (symbol_exists("irq_desc")) ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc, "irq_desc", NULL, 0); else if (kernel_symbol_exists("nr_irqs")) get_symbol_data("nr_irqs", sizeof(unsigned int), &machdep->nr_irqs); /* * Registers for idle threads are saved in * thread_info.cpu_context. */ STRUCT_SIZE_INIT(cpu_context_save, "cpu_context_save"); MEMBER_OFFSET_INIT(cpu_context_save_r7, "cpu_context_save", "r7"); MEMBER_OFFSET_INIT(cpu_context_save_fp, "cpu_context_save", "fp"); MEMBER_OFFSET_INIT(cpu_context_save_sp, "cpu_context_save", "sp"); MEMBER_OFFSET_INIT(cpu_context_save_pc, "cpu_context_save", "pc"); MEMBER_OFFSET_INIT(thread_info_cpu_context, "thread_info", "cpu_context"); /* * We need to have information about note_buf_t which is used to * hold ELF note containing registers and status of the thread * that panic'd. */ STRUCT_SIZE_INIT(note_buf, "note_buf_t"); STRUCT_SIZE_INIT(elf_prstatus, "elf_prstatus"); MEMBER_OFFSET_INIT(elf_prstatus_pr_pid, "elf_prstatus", "pr_pid"); MEMBER_OFFSET_INIT(elf_prstatus_pr_reg, "elf_prstatus", "pr_reg"); if (!machdep->hz) machdep->hz = 100; break; case POST_VM: machdep->machspec->vmalloc_start_addr = vt->high_memory; /* * Modules are placed in first vmalloc'd area. This is 16MB * below PAGE_OFFSET. */ machdep->machspec->modules_end = machdep->kvbase - 1; vaddr = first_vmalloc_address(); if (vaddr > machdep->machspec->modules_end) machdep->machspec->modules_vaddr = DEFAULT_MODULES_VADDR; else machdep->machspec->modules_vaddr = vaddr; /* * crash_notes contains machine specific information about the * crash. In particular, it contains CPU registers at the time * of the crash. We need this information to extract correct * backtraces from the panic task. */ if (!ACTIVE()) arm_get_crash_notes(); if (init_unwind_tables()) { if (CRASHDEBUG(1)) fprintf(fp, "using unwind tables\n"); } else { if (CRASHDEBUG(1)) fprintf(fp, "using framepointers\n"); } break; case LOG_ONLY: machdep->machspec = &arm_machine_specific; machdep->kvbase = kt->vmcoreinfo._stext_SYMBOL & 0xffff0000UL; arm_init_machspec(); break; } } void arm_dump_machdep_table(ulong arg) { const struct machine_specific *ms; int others, i; others = 0; fprintf(fp, " flags: %lx (", machdep->flags); if (machdep->flags & KSYMS_START) fprintf(fp, "%sKSYMS_START", others++ ? "|" : ""); if (machdep->flags & PHYS_BASE) fprintf(fp, "%sPHYS_BASE", others++ ? "|" : ""); if (machdep->flags & PGTABLE_V2) fprintf(fp, "%sPGTABLE_V2", others++ ? "|" : ""); if (machdep->flags & IDMAP_PGD) fprintf(fp, "%sIDMAP_PGD", others++ ? "|" : ""); if (machdep->flags & PAE) fprintf(fp, "%sPAE", others++ ? "|" : ""); fprintf(fp, ")\n"); fprintf(fp, " kvbase: %lx\n", machdep->kvbase); fprintf(fp, " identity_map_base: %lx\n", machdep->kvbase); fprintf(fp, " pagesize: %d\n", machdep->pagesize); fprintf(fp, " pageshift: %d\n", machdep->pageshift); fprintf(fp, " pagemask: %lx\n", (ulong)machdep->pagemask); fprintf(fp, " pageoffset: %lx\n", machdep->pageoffset); fprintf(fp, " stacksize: %ld\n", machdep->stacksize); fprintf(fp, " hz: %d\n", machdep->hz); fprintf(fp, " mhz: %ld\n", machdep->mhz); fprintf(fp, " memsize: %lld (0x%llx)\n", machdep->memsize, machdep->memsize); fprintf(fp, " bits: %d\n", machdep->bits); fprintf(fp, " nr_irqs: %d\n", machdep->nr_irqs); fprintf(fp, " eframe_search: arm_eframe_search()\n"); fprintf(fp, " back_trace: arm_back_trace_cmd()\n"); fprintf(fp, " processor_speed: arm_processor_speed()\n"); fprintf(fp, " uvtop: arm_uvtop()\n"); fprintf(fp, " kvtop: arm_kvtop()\n"); fprintf(fp, " get_task_pgd: arm_get_task_pgd()\n"); fprintf(fp, " dump_irq: generic_dump_irq()\n"); fprintf(fp, " get_stack_frame: arm_get_stack_frame()\n"); fprintf(fp, " get_stackbase: generic_get_stackbase()\n"); fprintf(fp, " get_stacktop: generic_get_stacktop()\n"); fprintf(fp, " translate_pte: arm_translate_pte()\n"); fprintf(fp, " memory_size: generic_memory_size()\n"); fprintf(fp, " vmalloc_start: arm_vmalloc_start()\n"); fprintf(fp, " is_task_addr: arm_is_task_addr()\n"); fprintf(fp, " verify_symbol: arm_verify_symbol()\n"); fprintf(fp, " dis_filter: arm_dis_filter()\n"); fprintf(fp, " cmd_mach: arm_cmd_mach()\n"); fprintf(fp, " get_smp_cpus: arm_get_smp_cpus()\n"); fprintf(fp, " is_kvaddr: arm_is_kvaddr()\n"); fprintf(fp, " is_uvaddr: arm_is_uvaddr()\n"); fprintf(fp, " verify_paddr: generic_verify_paddr()\n"); fprintf(fp, " show_interrupts: generic_show_interrupts()\n"); fprintf(fp, " get_irq_affinity: generic_get_irq_affinity()\n"); fprintf(fp, " xendump_p2m_create: NULL\n"); fprintf(fp, "xen_kdump_p2m_create: NULL\n"); fprintf(fp, " line_number_hooks: arm_line_number_hooks\n"); fprintf(fp, " last_pgd_read: %lx\n", machdep->last_pgd_read); fprintf(fp, " last_pmd_read: %lx\n", machdep->last_pmd_read); fprintf(fp, " last_ptbl_read: %lx\n", machdep->last_ptbl_read); fprintf(fp, "clear_machdep_cache: NULL\n"); fprintf(fp, " pgd: %lx\n", (ulong)machdep->pgd); fprintf(fp, " pmd: %lx\n", (ulong)machdep->pmd); fprintf(fp, " ptbl: %lx\n", (ulong)machdep->ptbl); fprintf(fp, " ptrs_per_pgd: %d\n", machdep->ptrs_per_pgd); fprintf(fp, " section_size_bits: %ld\n", machdep->section_size_bits); fprintf(fp, " max_physmem_bits: %ld\n", machdep->max_physmem_bits); fprintf(fp, " sections_per_root: %ld\n", machdep->sections_per_root); for (i = 0; i < MAX_MACHDEP_ARGS; i++) { fprintf(fp, " cmdline_args[%d]: %s\n", i, machdep->cmdline_args[i] ? machdep->cmdline_args[i] : "(unused)"); } ms = machdep->machspec; fprintf(fp, " machspec: %lx\n", (ulong)ms); fprintf(fp, " phys_base: %lx\n", ms->phys_base); fprintf(fp, " vmalloc_start_addr: %lx\n", ms->vmalloc_start_addr); fprintf(fp, " modules_vaddr: %lx\n", ms->modules_vaddr); fprintf(fp, " modules_end: %lx\n", ms->modules_end); fprintf(fp, " kernel_text_start: %lx\n", ms->kernel_text_start); fprintf(fp, " kernel_text_end: %lx\n", ms->kernel_text_end); fprintf(fp, "exception_text_start: %lx\n", ms->exception_text_start); fprintf(fp, " exception_text_end: %lx\n", ms->exception_text_end); fprintf(fp, " crash_task_regs: %lx\n", (ulong)ms->crash_task_regs); fprintf(fp, "unwind_index_prel31: %d\n", ms->unwind_index_prel31); } /* * Parse machine dependent command line arguments. * * Force the phys_base address via: * * --machdep phys_base=
*/ static void arm_parse_cmdline_args(void) { int index, i, c, err; char *arglist[MAXARGS]; char buf[BUFSIZE]; char *p; ulong value = 0; for (index = 0; index < MAX_MACHDEP_ARGS; index++) { if (!machdep->cmdline_args[index]) break; if (!strstr(machdep->cmdline_args[index], "=")) { error(WARNING, "ignoring --machdep option: %x\n", machdep->cmdline_args[index]); continue; } strcpy(buf, machdep->cmdline_args[index]); for (p = buf; *p; p++) { if (*p == ',') *p = ' '; } c = parse_line(buf, arglist); for (i = 0; i < c; i++) { err = 0; if (STRNEQ(arglist[i], "phys_base=")) { int megabytes = FALSE; int flags = RETURN_ON_ERROR | QUIET; if ((LASTCHAR(arglist[i]) == 'm') || (LASTCHAR(arglist[i]) == 'M')) { LASTCHAR(arglist[i]) = NULLCHAR; megabytes = TRUE; } p = arglist[i] + strlen("phys_base="); if (strlen(p)) { if (megabytes) value = dtol(p, flags, &err); else value = htol(p, flags, &err); } if (!err) { if (megabytes) value = MEGABYTES(value); machdep->machspec->phys_base = value; error(NOTE, "setting phys_base to: 0x%lx\n", machdep->machspec->phys_base); machdep->flags |= PHYS_BASE; continue; } } error(WARNING, "ignoring --machdep option: %s\n", arglist[i]); } } } /* * Retrieve task registers for the time of the crash. */ static void arm_get_crash_notes(void) { struct machine_specific *ms = machdep->machspec; ulong crash_notes; Elf32_Nhdr *note; ulong offset; char *buf, *p; ulong *notes_ptrs; ulong i, found; if (!symbol_exists("crash_notes")) return; crash_notes = symbol_value("crash_notes"); notes_ptrs = (ulong *)GETBUF(kt->cpus*sizeof(notes_ptrs[0])); /* * Read crash_notes for the first CPU. crash_notes are in standard ELF * note format. */ if (!readmem(crash_notes, KVADDR, ¬es_ptrs[kt->cpus-1], sizeof(notes_ptrs[kt->cpus-1]), "crash_notes", RETURN_ON_ERROR)) { error(WARNING, "cannot read crash_notes\n"); FREEBUF(notes_ptrs); return; } if (symbol_exists("__per_cpu_offset")) { /* Add __per_cpu_offset for each cpu to form the pointer to the notes */ for (i = 0; icpus; i++) notes_ptrs[i] = notes_ptrs[kt->cpus-1] + kt->__per_cpu_offset[i]; } buf = GETBUF(SIZE(note_buf)); if (!(panic_task_regs = calloc((size_t)kt->cpus, sizeof(*panic_task_regs)))) error(FATAL, "cannot calloc panic_task_regs space\n"); for (i = found = 0; icpus; i++) { if (!readmem(notes_ptrs[i], KVADDR, buf, SIZE(note_buf), "note_buf_t", RETURN_ON_ERROR)) { error(WARNING, "cpu %d: cannot read NT_PRSTATUS note\n", i); continue; } /* * Do some sanity checks for this note before reading registers from it. */ note = (Elf32_Nhdr *)buf; p = buf + sizeof(Elf32_Nhdr); /* * dumpfiles created with qemu won't have crash_notes, but there will * be elf notes; dumpfiles created by kdump do not create notes for * offline cpus. */ if (note->n_namesz == 0 && (DISKDUMP_DUMPFILE() || KDUMP_DUMPFILE())) { if (DISKDUMP_DUMPFILE()) note = diskdump_get_prstatus_percpu(i); else if (KDUMP_DUMPFILE()) note = netdump_get_prstatus_percpu(i); if (note) { /* * SIZE(note_buf) accounts for a "final note", which is a * trailing empty elf note header. */ long notesz = SIZE(note_buf) - sizeof(Elf32_Nhdr); if (sizeof(Elf32_Nhdr) + roundup(note->n_namesz, 4) + note->n_descsz == notesz) BCOPY((char *)note, buf, notesz); } else { error(WARNING, "cpu %d: cannot find NT_PRSTATUS note\n", i); continue; } } /* * Check the sanity of NT_PRSTATUS note only for each online cpu. * If this cpu has invalid note, continue to find the crash notes * for other online cpus. */ if (note->n_type != NT_PRSTATUS) { error(WARNING, "cpu %d: invalid NT_PRSTATUS note (n_type != NT_PRSTATUS)\n", i); continue; } if (!STRNEQ(p, "CORE")) { error(WARNING, "cpu %d: invalid NT_PRSTATUS note (name != \"CORE\")\n", i); continue; } /* * Find correct location of note data. This contains elf_prstatus * structure which has registers etc. for the crashed task. */ offset = sizeof(Elf32_Nhdr); offset = roundup(offset + note->n_namesz, 4); p = buf + offset; /* start of elf_prstatus */ BCOPY(p + OFFSET(elf_prstatus_pr_reg), &panic_task_regs[i], sizeof(panic_task_regs[i])); found++; } /* * And finally we have the registers for the crashed task. This is * used later on when dumping backtrace. */ ms->crash_task_regs = panic_task_regs; FREEBUF(buf); FREEBUF(notes_ptrs); if (!found) { free(panic_task_regs); ms->crash_task_regs = NULL; } } /* * Accept or reject a symbol from the kernel namelist. */ static int arm_verify_symbol(const char *name, ulong value, char type) { if (STREQ(name, "swapper_pg_dir")) machdep->flags |= KSYMS_START; if (!name || !strlen(name) || !(machdep->flags & KSYMS_START)) return FALSE; if (STREQ(name, "$a") || STREQ(name, "$n") || STREQ(name, "$d")) return FALSE; if (STREQ(name, "PRRR") || STREQ(name, "NMRR")) return FALSE; if ((type == 'A') && STRNEQ(name, "__crc_")) return FALSE; if (CRASHDEBUG(8) && name && strlen(name)) fprintf(fp, "%08lx %s\n", value, name); return TRUE; } static int arm_is_module_addr(ulong vaddr) { ulong modules_start; ulong modules_end = machdep->machspec->modules_end; if (!MODULES_VADDR) { /* * In case we are still initializing, and vm_init() has not been * called, we use defaults here which is 16MB below kernel start * address. */ modules_start = DEFAULT_MODULES_VADDR; } else { modules_start = MODULES_VADDR; } return (vaddr >= modules_start && vaddr <= modules_end); } int arm_is_vmalloc_addr(ulong vaddr) { if (arm_is_module_addr(vaddr)) return TRUE; if (!VMALLOC_START) return FALSE; return (vaddr >= VMALLOC_START); } /* * Check whether given address falls inside kernel address space (including * modules). */ static int arm_is_kvaddr(ulong vaddr) { if (arm_is_module_addr(vaddr)) return TRUE; return (vaddr >= machdep->kvbase); } static int arm_is_uvaddr(ulong vaddr, struct task_context *unused) { if (arm_is_module_addr(vaddr)) return FALSE; return (vaddr < machdep->kvbase); } /* * Returns TRUE if given pc is in exception area. */ static int arm_in_exception_text(ulong pc) { ulong exception_start = machdep->machspec->exception_text_start; ulong exception_end = machdep->machspec->exception_text_end; if (exception_start && exception_end) return (pc >= exception_start && pc < exception_end); return FALSE; } /* * Returns TRUE if given pc points to a return from syscall * entrypoint. In case the function returns TRUE and if offset is given, * it is filled with the offset that should be added to the SP to get * address of the exception frame where the user registers are. */ static int arm_in_ret_from_syscall(ulong pc, int *offset) { /* * On fast syscall return path, the stack looks like: * * SP + 0 {r4, r5} * SP + 8 user pt_regs * * The asm syscall handler pushes fifth and sixth registers * onto the stack before calling the actual syscall handler. * * So in order to print out the user registers at the time * the syscall was made, we need to adjust SP for 8. */ if (pc == symbol_value("ret_fast_syscall")) { if (offset) *offset = 8; return TRUE; } /* * In case we are on the slow syscall path, the SP already * points to the start of the user registers hence no * adjustments needs to be done. */ if (pc == symbol_value("ret_slow_syscall")) { if (offset) *offset = 0; return TRUE; } return FALSE; } /* * Unroll the kernel stack using a minimal amount of gdb services. */ static void arm_back_trace(struct bt_info *bt) { int n = 0; /* * In case bt->machdep contains pointer to a full register set, we take * FP from there. */ if (bt->machdep) { const struct arm_pt_regs *regs = bt->machdep; bt->frameptr = regs->ARM_fp; } /* * Stack frame layout: * optionally saved caller registers (r4 - r10) * saved fp * saved sp * saved lr * frame => saved pc * optionally saved arguments (r0 - r3) * saved sp => * * Functions start with the following code sequence: * mov ip, sp * stmfd sp!, {r0 - r3} (optional) * corrected pc => stmfd sp!, {..., fp, ip, lr, pc} */ while (bt->frameptr && INSTACK(bt->frameptr, bt)) { ulong from; ulong sp; /* * We correct the PC to point to the actual instruction (current * value is PC + 8). */ bt->instptr = GET_STACK_ULONG(bt->frameptr - 0); bt->instptr -= 8; /* * Now get LR, saved SP and FP from the frame as well. */ from = GET_STACK_ULONG(bt->frameptr - 4); sp = GET_STACK_ULONG(bt->frameptr - 8); bt->frameptr = GET_STACK_ULONG(bt->frameptr - 12); arm_dump_backtrace_entry(bt, n++, from, sp); bt->stkptr = sp; } } /* * Unroll a kernel stack. */ static void arm_back_trace_cmd(struct bt_info *bt) { if (bt->flags & BT_REGS_NOT_FOUND) return; if (kt->flags & DWARF_UNWIND) unwind_backtrace(bt); else arm_back_trace(bt); } /* * Calculate and return the speed of the processor. */ static ulong arm_processor_speed(void) { /* * For now, we don't support reading CPU speed. */ return 0; } /* * Translate a PTE, returning TRUE if the page is present. If a physaddr pointer * is passed in, don't print anything. */ static int arm_translate_pte(ulong pte, void *physaddr, ulonglong lpae_pte) { char ptebuf[BUFSIZE]; char physbuf[BUFSIZE]; char buf[BUFSIZE]; int page_present; ulonglong paddr; int len1, len2, others; if (machdep->flags & PAE) { paddr = LPAE_PAGEBASE(lpae_pte); sprintf(ptebuf, "%llx", lpae_pte); pte = (ulong)lpae_pte; } else { paddr = PAGEBASE(pte); sprintf(ptebuf, "%lx", pte); } page_present = pte_present(pte); if (physaddr) { if (machdep->flags & PAE) *((ulonglong *)physaddr) = paddr; else *((ulong *)physaddr) = (ulong)paddr; return page_present; } len1 = MAX(strlen(ptebuf), strlen("PTE")); fprintf(fp, "%s ", mkstring(buf, len1, CENTER | LJUST, "PTE")); if (!page_present && pte) { /* swap page, not handled yet */ return page_present; } sprintf(physbuf, "%llx", paddr); len2 = MAX(strlen(physbuf), strlen("PHYSICAL")); fprintf(fp, "%s ", mkstring(buf, len2, CENTER | LJUST, "PHYSICAL")); fprintf(fp, "FLAGS\n"); fprintf(fp, "%s %s ", mkstring(ptebuf, len1, CENTER | RJUST, NULL), mkstring(physbuf, len2, CENTER | RJUST, NULL)); fprintf(fp, "("); others = 0; if (pte) { if (pte_present(pte)) fprintf(fp, "%sPRESENT", others++ ? "|" : ""); if (pte_dirty(pte)) fprintf(fp, "%sDIRTY", others++ ? "|" : ""); if (pte_young(pte)) fprintf(fp, "%sYOUNG", others++ ? "|" : ""); if (machdep->flags & PGTABLE_V2) { if (!pte_rdonly(pte)) fprintf(fp, "%sWRITE", others++ ? "|" : ""); if (!pte_xn(pte)) fprintf(fp, "%sEXEC", others++ ? "|" : ""); } else { if (pte_write(pte)) fprintf(fp, "%sWRITE", others++ ? "|" : ""); if (pte_exec(pte)) fprintf(fp, "%sEXEC", others++ ? "|" : ""); } } else { fprintf(fp, "no mapping"); } fprintf(fp, ")\n"); return 0; } /* * Virtual to physical memory translation. This function will be called by both * arm_kvtop() and arm_uvtop(). */ static int arm_vtop(ulong vaddr, ulong *pgd, physaddr_t *paddr, int verbose) { char buf[BUFSIZE]; ulong *page_dir; ulong *page_middle; ulong *page_table; ulong pgd_pte; ulong pmd_pte; ulong pte; /* * Page tables in ARM Linux * * In hardware PGD is 16k (having 4096 pointers to PTE) and PTE is 1k * (containing 256 translations). * * Linux, however, wants to have PTEs as page sized entities. This means * that in ARM Linux we have following setup (see also * arch/arm/include/asm/pgtable.h) * * Before 2.6.38 * * PGD PTE * +---------+ * | | 0 ----> +------------+ * +- - - - -+ | h/w pt 0 | * | | 4 ----> +------------+ +1024 * +- - - - -+ | h/w pt 1 | * . . +------------+ +2048 * . . | Linux pt 0 | * . . +------------+ +3072 * | | 4095 | Linux pt 1 | * +---------+ +------------+ +4096 * * Starting from 2.6.38 * * PGD PTE * +---------+ * | | 0 ----> +------------+ * +- - - - -+ | Linux pt 0 | * | | 4 ----> +------------+ +1024 * +- - - - -+ | Linux pt 1 | * . . +------------+ +2048 * . . | h/w pt 0 | * . . +------------+ +3072 * | | 4095 | h/w pt 1 | * +---------+ +------------+ +4096 * * So in Linux implementation we have two hardware pointers to second * level page tables. Depending on the kernel version, the "Linux" page * tables either follow or precede the hardware tables. * * Linux PT entries contain bits that are not supported on hardware, for * example "young" and "dirty" flags. * * Our translation scheme only uses Linux PTEs here. */ if (verbose) fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd); /* * pgd_offset(pgd, vaddr) */ page_dir = pgd + PGD_OFFSET(vaddr) * 2; /* The unity-mapped region is mapped using 1MB pages, * hence 1-level translation if bit 20 is set; if we * are 1MB apart physically, we move the page_dir in * case bit 20 is set. */ if (((vaddr) >> (20)) & 1) page_dir = page_dir + 1; FILL_PGD(PAGEBASE(pgd), KVADDR, PGDIR_SIZE()); pgd_pte = ULONG(machdep->pgd + PGDIR_OFFSET(page_dir)); if (verbose) fprintf(fp, " PGD: %s => %lx\n", mkstring(buf, VADDR_PRLEN, RJUST | LONG_HEX, MKSTR((ulong)page_dir)), pgd_pte); if (!pgd_pte) return FALSE; /* * pmd_offset(pgd, vaddr) * * Here PMD is folded into a PGD. */ pmd_pte = pgd_pte; page_middle = page_dir; if (verbose) fprintf(fp, " PMD: %s => %lx\n", mkstring(buf, VADDR_PRLEN, RJUST | LONG_HEX, MKSTR((ulong)page_middle)), pmd_pte); if ((pmd_pte & PMD_TYPE_MASK) == PMD_TYPE_SECT) { ulong sectionbase = pmd_pte & _SECTION_PAGE_MASK; if (verbose) { fprintf(fp, " PAGE: %s (1MB)\n\n", mkstring(buf, VADDR_PRLEN, RJUST | LONG_HEX, MKSTR(sectionbase))); } *paddr = sectionbase + (vaddr & ~_SECTION_PAGE_MASK); return TRUE; } /* * pte_offset_map(pmd, vaddr) */ page_table = pmd_page_addr(pmd_pte) + PTE_OFFSET(vaddr); FILL_PTBL(PAGEBASE(page_table), PHYSADDR, PAGESIZE()); pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table)); if (verbose) { fprintf(fp, " PTE: %s => %lx\n\n", mkstring(buf, VADDR_PRLEN, RJUST | LONG_HEX, MKSTR((ulong)page_table)), pte); } if (!pte_present(pte)) { if (pte && verbose) { fprintf(fp, "\n"); arm_translate_pte(pte, 0, 0); } return FALSE; } *paddr = PAGEBASE(pte) + PAGEOFFSET(vaddr); if (verbose) { fprintf(fp, " PAGE: %s\n\n", mkstring(buf, VADDR_PRLEN, RJUST | LONG_HEX, MKSTR(PAGEBASE(pte)))); arm_translate_pte(pte, 0, 0); } return TRUE; } /* * Virtual to physical memory translation when "CONFIG_ARM_LPAE=y". * This function will be called by both arm_kvtop() and arm_uvtop(). */ static int arm_lpae_vtop(ulong vaddr, ulong *pgd, physaddr_t *paddr, int verbose) { char buf[BUFSIZE]; physaddr_t page_dir; physaddr_t page_middle; physaddr_t page_table; pgd_t pgd_pmd; pmd_t pmd_pte; pte_t pte; if (IS_KVADDR(vaddr)) { if (!vt->vmalloc_start) { *paddr = LPAE_VTOP(vaddr); return TRUE; } if (!IS_VMALLOC_ADDR(vaddr)) { *paddr = LPAE_VTOP(vaddr); if (!verbose) return TRUE; } } if (verbose) fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd); /* * pgd_offset(pgd, vaddr) */ page_dir = LPAE_VTOP((ulong)pgd + LPAE_PGD_OFFSET(vaddr) * 8); FILL_PGD_LPAE(LPAE_VTOP(pgd), PHYSADDR, LPAE_PGDIR_SIZE()); pgd_pmd = ULONGLONG(machdep->pgd + LPAE_PGDIR_OFFSET(page_dir)); if (verbose) fprintf(fp, " PGD: %8llx => %llx\n", (ulonglong)page_dir, pgd_pmd); if (!pgd_pmd) return FALSE; /* * pmd_offset(pgd, vaddr) */ page_middle = LPAE_PAGEBASE(pgd_pmd) + LPAE_PMD_OFFSET(vaddr) * 8; FILL_PMD_LPAE(LPAE_PAGEBASE(pgd_pmd), PHYSADDR, LPAE_PMDIR_SIZE()); pmd_pte = ULONGLONG(machdep->pmd + LPAE_PMDIR_OFFSET(page_middle)); if (!pmd_pte) return FALSE; if ((pmd_pte & PMD_TYPE_MASK) == PMD_TYPE_SECT_LPAE) { ulonglong sectionbase = LPAE_PAGEBASE(pmd_pte) & LPAE_SECTION_PAGE_MASK; if (verbose) fprintf(fp, " PAGE: %8llx (2MB)\n\n", (ulonglong)sectionbase); *paddr = sectionbase + (vaddr & ~LPAE_SECTION_PAGE_MASK); return TRUE; } /* * pte_offset_map(pmd, vaddr) */ page_table = LPAE_PAGEBASE(pmd_pte) + PTE_OFFSET(vaddr) * 8; FILL_PTBL_LPAE(LPAE_PAGEBASE(pmd_pte), PHYSADDR, LPAE_PTEDIR_SIZE()); pte = ULONGLONG(machdep->ptbl + LPAE_PTEDIR_OFFSET(page_table)); if (verbose) { fprintf(fp, " PTE: %8llx => %llx\n\n", (ulonglong)page_table, pte); } if (!pte_present(pte)) { if (pte && verbose) { fprintf(fp, "\n"); arm_translate_pte(0, 0, pte); } return FALSE; } *paddr = LPAE_PAGEBASE(pte) + PAGEOFFSET(vaddr); if (verbose) { fprintf(fp, " PAGE: %s\n\n", mkstring(buf, VADDR_PRLEN, RJUST | LONG_HEX, MKSTR(PAGEBASE(pte)))); arm_translate_pte(0, 0, pte); } return TRUE; } /* * Translates a user virtual address to its physical address. cmd_vtop() sets * the verbose flag so that the pte translation gets displayed; all other * callers quietly accept the translation. */ static int arm_uvtop(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbose) { ulong *pgd; if (!tc) error(FATAL, "current context invalid\n"); /* * Before idmap_pgd was introduced with upstream commit 2c8951ab0c * (ARM: idmap: use idmap_pgd when setting up mm for reboot), the * panic task pgd was overwritten by soft reboot code, so we can't do * any vtop translations. */ if (!(machdep->flags & IDMAP_PGD) && tc->task == tt->panic_task) error(FATAL, "panic task pgd is trashed by soft reboot code\n"); *paddr = 0; if (is_kernel_thread(tc->task) && IS_KVADDR(uvaddr)) { ulong active_mm; readmem(tc->task + OFFSET(task_struct_active_mm), KVADDR, &active_mm, sizeof(void *), "task active_mm contents", FAULT_ON_ERROR); if (!active_mm) error(FATAL, "no active_mm for this kernel thread\n"); readmem(active_mm + OFFSET(mm_struct_pgd), KVADDR, &pgd, sizeof(long), "mm_struct pgd", FAULT_ON_ERROR); } else { ulong mm; mm = task_mm(tc->task, TRUE); if (mm) pgd = ULONG_PTR(tt->mm_struct + OFFSET(mm_struct_pgd)); else readmem(tc->mm_struct + OFFSET(mm_struct_pgd), KVADDR, &pgd, sizeof(long), "mm_struct pgd", FAULT_ON_ERROR); } if (machdep->flags & PAE) return arm_lpae_vtop(uvaddr, pgd, paddr, verbose); return arm_vtop(uvaddr, pgd, paddr, verbose); } /* * Translates a kernel virtual address to its physical address. cmd_vtop() sets * the verbose flag so that the pte translation gets displayed; all other * callers quietly accept the translation. */ static int arm_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose) { if (!IS_KVADDR(kvaddr)) return FALSE; if (machdep->flags & PAE) return arm_lpae_vtop(kvaddr, (ulong *)vt->kernel_pgd[0], paddr, verbose); if (!vt->vmalloc_start) { *paddr = VTOP(kvaddr); return TRUE; } if (!IS_VMALLOC_ADDR(kvaddr)) { *paddr = VTOP(kvaddr); if (!verbose) return TRUE; } return arm_vtop(kvaddr, (ulong *)vt->kernel_pgd[0], paddr, verbose); } /* * Get SP and PC values for idle tasks. */ static int arm_get_frame(struct bt_info *bt, ulong *pcp, ulong *spp) { const char *cpu_context; if (!bt->tc || !(tt->flags & THREAD_INFO)) return FALSE; /* * Update thread_info in tt. */ if (!fill_thread_info(bt->tc->thread_info)) return FALSE; cpu_context = tt->thread_info + OFFSET(thread_info_cpu_context); #define GET_REG(ptr, cp, off) ((*ptr) = (*((ulong *)((cp) + OFFSET(off))))) GET_REG(spp, cpu_context, cpu_context_save_sp); GET_REG(pcp, cpu_context, cpu_context_save_pc); /* * Unwinding code needs FP (R7 for Thumb code) value also so we pass it * with bt. */ if (*pcp & 1) GET_REG(&bt->frameptr, cpu_context, cpu_context_save_r7); else GET_REG(&bt->frameptr, cpu_context, cpu_context_save_fp); return TRUE; } /* * Get the starting point for the active cpu in a diskdump. */ static int arm_get_dumpfile_stack_frame(struct bt_info *bt, ulong *nip, ulong *ksp) { const struct machine_specific *ms = machdep->machspec; if (!ms->crash_task_regs || (!ms->crash_task_regs[bt->tc->processor].ARM_pc && !ms->crash_task_regs[bt->tc->processor].ARM_sp)) { bt->flags |= BT_REGS_NOT_FOUND; return FALSE; } /* * We got registers for panic task from crash_notes. Just return them. */ *nip = ms->crash_task_regs[bt->tc->processor].ARM_pc; *ksp = ms->crash_task_regs[bt->tc->processor].ARM_sp; /* * Also store pointer to all registers in case unwinding code needs * to access LR. */ bt->machdep = &(ms->crash_task_regs[bt->tc->processor]); return TRUE; } /* * Get a stack frame combination of PC and SP from the most relevant spot. */ static void arm_get_stack_frame(struct bt_info *bt, ulong *pcp, ulong *spp) { ulong ip, sp; int ret; ip = sp = 0; bt->machdep = NULL; if (DUMPFILE() && is_task_active(bt->task)) ret = arm_get_dumpfile_stack_frame(bt, &ip, &sp); else ret = arm_get_frame(bt, &ip, &sp); if (!ret) error(WARNING, "cannot determine starting stack frame for task %lx\n", bt->task); if (pcp) *pcp = ip; if (spp) *spp = sp; } /* * Prints out exception stack starting from start. */ void arm_dump_exception_stack(ulong start, ulong end) { struct arm_pt_regs regs; ulong flags; char buf[64]; if (!readmem(start, KVADDR, ®s, sizeof(regs), "exception regs", RETURN_ON_ERROR)) { error(WARNING, "failed to read exception registers\n"); return; } fprintf(fp, " pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n" " sp : %08lx ip : %08lx fp : %08lx\n", regs.ARM_pc, regs.ARM_lr, regs.ARM_cpsr, regs.ARM_sp, regs.ARM_ip, regs.ARM_fp); fprintf(fp, " r10: %08lx r9 : %08lx r8 : %08lx\n", regs.ARM_r10, regs.ARM_r9, regs.ARM_r8); fprintf(fp, " r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n", regs.ARM_r7, regs.ARM_r6, regs.ARM_r5, regs.ARM_r4); fprintf(fp, " r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n", regs.ARM_r3, regs.ARM_r2, regs.ARM_r1, regs.ARM_r0); flags = regs.ARM_cpsr; buf[0] = flags & PSR_N_BIT ? 'N' : 'n'; buf[1] = flags & PSR_Z_BIT ? 'Z' : 'z'; buf[2] = flags & PSR_C_BIT ? 'C' : 'c'; buf[3] = flags & PSR_V_BIT ? 'V' : 'v'; buf[4] = '\0'; fprintf(fp, " Flags: %s IRQs o%s FIQs o%s Mode %s ISA %s\n", buf, interrupts_enabled(®s) ? "n" : "ff", fast_interrupts_enabled(®s) ? "n" : "ff", processor_modes[processor_mode(®s)], isa_modes[isa_mode(®s)]); } static void arm_display_full_frame(struct bt_info *bt, ulong sp) { ulong words, addr; ulong *up; char buf[BUFSIZE]; int i, u_idx; if (!INSTACK(sp, bt) || !INSTACK(bt->stkptr, bt)) return; words = (sp - bt->stkptr) / sizeof(ulong); if (words == 0) { fprintf(fp, " (no frame)\n"); return; } addr = bt->stkptr; u_idx = (bt->stkptr - bt->stackbase) / sizeof(ulong); for (i = 0; i < words; i++, u_idx++) { if ((i % 4) == 0) fprintf(fp, "%s %lx: ", i ? "\n" : "", addr); up = (ulong *)(&bt->stackbuf[u_idx * sizeof(ulong)]); fprintf(fp, "%s ", format_stack_entry(bt, buf, *up, 0)); addr += sizeof(ulong); } fprintf(fp, "\n"); } /* * Prints out a single stack frame. What is printed depends on flags passed in * with bt. * * What is expected when calling this function: * bt->frameptr = current FP (or 0 if there is no such) * bt->stkptr = current SP * bt->instptr = current PC * * from = LR * sp = previous/saved SP */ void arm_dump_backtrace_entry(struct bt_info *bt, int level, ulong from, ulong sp) { struct load_module *lm; const char *name; int offset = 0; struct syment *symp; ulong symbol_offset; char *name_plus_offset; char buf[BUFSIZE]; name = closest_symbol(bt->instptr); name_plus_offset = NULL; if (bt->flags & BT_SYMBOL_OFFSET) { symp = value_search(bt->instptr, &symbol_offset); if (symp && symbol_offset) name_plus_offset = value_to_symstr(bt->instptr, buf, bt->radix); } if (module_symbol(bt->instptr, NULL, &lm, NULL, 0)) { fprintf(fp, "%s#%d [<%08lx>] (%s [%s]) from [<%08lx>]\n", level < 10 ? " " : "", level, bt->instptr, name_plus_offset ? name_plus_offset : name, lm->mod_name, from); } else { fprintf(fp, "%s#%d [<%08lx>] (%s) from [<%08lx>]\n", level < 10 ? " " : "", level, bt->instptr, name_plus_offset ? name_plus_offset : name, from); } if (bt->flags & BT_LINE_NUMBERS) { char buf[BUFSIZE]; get_line_number(bt->instptr, buf, FALSE); if (strlen(buf)) fprintf(fp, " %s\n", buf); } if (arm_in_exception_text(bt->instptr)) { arm_dump_exception_stack(sp, sp + sizeof(struct arm_pt_regs)); } else if (arm_in_ret_from_syscall(from, &offset)) { ulong nsp = sp + offset; arm_dump_exception_stack(nsp, nsp + sizeof(struct arm_pt_regs)); } if (bt->flags & BT_FULL) { if (kt->flags & DWARF_UNWIND) { fprintf(fp, " " "[PC: %08lx LR: %08lx SP: %08lx SIZE: %ld]\n", bt->instptr, from, bt->stkptr, sp - bt->stkptr); } else { fprintf(fp, " " "[PC: %08lx LR: %08lx SP: %08lx FP: %08lx " "SIZE: %ld]\n", bt->instptr, from, bt->stkptr, bt->frameptr, sp - bt->stkptr); } arm_display_full_frame(bt, sp); } } /* * Determine where vmalloc'd memory starts. */ static ulong arm_vmalloc_start(void) { machdep->machspec->vmalloc_start_addr = vt->high_memory; return vt->high_memory; } /* * Checks whether given task is valid task address. */ static int arm_is_task_addr(ulong task) { if (tt->flags & THREAD_INFO) return IS_KVADDR(task); return (IS_KVADDR(task) && ALIGNED_STACK_OFFSET(task) == 0); } /* * Filter dissassembly output if the output radix is not gdb's default 10 */ static int arm_dis_filter(ulong vaddr, char *inbuf, unsigned int output_radix) { char buf1[BUFSIZE]; char buf2[BUFSIZE]; char *colon, *p1; int argc; char *argv[MAXARGS]; ulong value; if (!inbuf) return TRUE; /* * For some reason gdb can go off into the weeds translating text addresses, * (on alpha -- not necessarily seen on arm) so this routine both fixes the * references as well as imposing the current output radix on the translations. */ console("IN: %s", inbuf); colon = strstr(inbuf, ":"); if (colon) { sprintf(buf1, "0x%lx <%s>", vaddr, value_to_symstr(vaddr, buf2, output_radix)); sprintf(buf2, "%s%s", buf1, colon); strcpy(inbuf, buf2); } strcpy(buf1, inbuf); argc = parse_line(buf1, argv); if ((FIRSTCHAR(argv[argc-1]) == '<') && (LASTCHAR(argv[argc-1]) == '>')) { p1 = rindex(inbuf, '<'); while ((p1 > inbuf) && !STRNEQ(p1, " 0x")) p1--; if (!STRNEQ(p1, " 0x")) return FALSE; p1++; if (!extract_hex(p1, &value, NULLCHAR, TRUE)) return FALSE; sprintf(buf1, "0x%lx <%s>\n", value, value_to_symstr(value, buf2, output_radix)); sprintf(p1, "%s", buf1); } console(" %s", inbuf); return TRUE; } /* * Look for likely exception frames in a stack. */ static int arm_eframe_search(struct bt_info *bt) { return (NOT_IMPLEMENTED()); } /* * Get the relevant page directory pointer from a task structure. */ static ulong arm_get_task_pgd(ulong task) { return (NOT_IMPLEMENTED()); } /* * Machine dependent command. */ static void arm_cmd_mach(void) { int c; while ((c = getopt(argcnt, args, "cm")) != -1) { switch (c) { case 'c': case 'm': fprintf(fp, "ARM: '-%c' option is not supported\n", c); break; default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); arm_display_machine_stats(); } static void arm_display_machine_stats(void) { struct new_utsname *uts; char buf[BUFSIZE]; ulong mhz; uts = &kt->utsname; fprintf(fp, " MACHINE TYPE: %s\n", uts->machine); fprintf(fp, " MEMORY SIZE: %s\n", get_memory_size(buf)); fprintf(fp, " CPUS: %d\n", get_cpus_to_display()); fprintf(fp, " PROCESSOR SPEED: "); if ((mhz = machdep->processor_speed())) fprintf(fp, "%ld Mhz\n", mhz); else fprintf(fp, "(unknown)\n"); fprintf(fp, " HZ: %d\n", machdep->hz); fprintf(fp, " PAGE SIZE: %d\n", PAGESIZE()); fprintf(fp, "KERNEL VIRTUAL BASE: %lx\n", machdep->kvbase); fprintf(fp, "KERNEL MODULES BASE: %lx\n", MODULES_VADDR); fprintf(fp, "KERNEL VMALLOC BASE: %lx\n", vt->vmalloc_start); fprintf(fp, " KERNEL STACK SIZE: %ld\n", STACKSIZE()); } static int arm_get_smp_cpus(void) { int cpus; if ((cpus = get_cpus_present())) return cpus; else return MAX(get_cpus_online(), get_highest_cpu_online()+1); } /* * Initialize ARM specific stuff. */ static void arm_init_machspec(void) { struct machine_specific *ms = machdep->machspec; ulong phys_base; if (symbol_exists("__exception_text_start") && symbol_exists("__exception_text_end")) { ms->exception_text_start = symbol_value("__exception_text_start"); ms->exception_text_end = symbol_value("__exception_text_end"); } if (symbol_exists("_stext") && symbol_exists("_etext")) { ms->kernel_text_start = symbol_value("_stext"); ms->kernel_text_end = symbol_value("_etext"); } if (CRASHDEBUG(1)) { fprintf(fp, "kernel text: [%lx - %lx]\n", ms->kernel_text_start, ms->kernel_text_end); fprintf(fp, "exception text: [%lx - %lx]\n", ms->exception_text_start, ms->exception_text_end); } if (machdep->flags & PHYS_BASE) /* --machdep override */ return; /* * Next determine suitable value for phys_base. User can override this * by passing valid '--machdep phys_base=' option. */ ms->phys_base = 0; if (ACTIVE()) { char buf[BUFSIZE]; char *p1; int errflag; FILE *fp; if ((fp = fopen("/proc/iomem", "r")) == NULL) return; /* * Memory regions are sorted in ascending order. We take the * first region which should be correct for most uses. */ errflag = 1; while (fgets(buf, BUFSIZE, fp)) { if (strstr(buf, ": System RAM")) { clean_line(buf); errflag = 0; break; } } fclose(fp); if (errflag) return; if (!(p1 = strstr(buf, "-"))) return; *p1 = NULLCHAR; phys_base = htol(buf, RETURN_ON_ERROR | QUIET, &errflag); if (errflag) return; ms->phys_base = phys_base; } else if (DISKDUMP_DUMPFILE() && diskdump_phys_base(&phys_base)) { ms->phys_base = phys_base; } else if (KDUMP_DUMPFILE() && arm_kdump_phys_base(&phys_base)) { ms->phys_base = phys_base; } else { error(WARNING, "phys_base cannot be determined from the dumpfile.\n" "Using default value of 0. If this is not correct,\n" "consider using '--machdep phys_base='\n"); } if (CRASHDEBUG(1)) fprintf(fp, "using %lx as phys_base\n", ms->phys_base); } static const char *hook_files[] = { "arch/arm/kernel/entry-armv.S", "arch/arm/kernel/entry-common.S", }; #define ENTRY_ARMV_S ((char **)&hook_files[0]) #define ENTRY_COMMON_S ((char **)&hook_files[1]) static struct line_number_hook arm_line_number_hooks[] = { { "__dabt_svc", ENTRY_ARMV_S }, { "__irq_svc", ENTRY_ARMV_S }, { "__und_svc", ENTRY_ARMV_S }, { "__pabt_svc", ENTRY_ARMV_S }, { "__switch_to", ENTRY_ARMV_S }, { "ret_fast_syscall", ENTRY_COMMON_S }, { "ret_slow_syscall", ENTRY_COMMON_S }, { "ret_from_fork", ENTRY_COMMON_S }, { NULL, NULL }, }; #endif /* ARM */ crash-utility-crash-61fe107/arm64.c000066400000000000000000005116201517256214500170560ustar00rootroot00000000000000/* * arm64.c - core analysis suite * * Copyright (C) 2012-2020 David Anderson * Copyright (C) 2012-2020 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #ifdef ARM64 #include "defs.h" #include #include #include #include #define NOT_IMPLEMENTED(X) error((X), "%s: function not implemented\n", __func__) static struct machine_specific arm64_machine_specific = { 0 }; static int arm64_verify_symbol(const char *, ulong, char); static void arm64_parse_cmdline_args(void); static int arm64_search_for_kimage_voffset(ulong); static int verify_kimage_voffset(void); static void arm64_calc_kimage_voffset(void); static void arm64_calc_phys_offset(void); static void arm64_calc_physvirt_offset(void); static void arm64_calc_virtual_memory_ranges(void); static void arm64_get_section_size_bits(void); static int arm64_kdump_phys_base(ulong *); static ulong arm64_processor_speed(void); static void arm64_init_kernel_pgd(void); static int arm64_kvtop(struct task_context *, ulong, physaddr_t *, int); static int arm64_uvtop(struct task_context *, ulong, physaddr_t *, int); static int arm64_vtop_2level_64k(ulong, ulong, physaddr_t *, int); static int arm64_vtop_3level_64k(ulong, ulong, physaddr_t *, int); static int arm64_vtop_2level_16k(ulong, ulong, physaddr_t *, int); static int arm64_vtop_3level_16k(ulong, ulong, physaddr_t *, int); static int arm64_vtop_4level_16k(ulong, ulong, physaddr_t *, int); static int arm64_vtop_3level_4k(ulong, ulong, physaddr_t *, int); static int arm64_vtop_4level_4k(ulong, ulong, physaddr_t *, int); static ulong arm64_get_task_pgd(ulong); static void arm64_irq_stack_init(void); static void arm64_overflow_stack_init(void); static void arm64_stackframe_init(void); static int arm64_eframe_search(struct bt_info *); static int arm64_is_kernel_exception_frame(struct bt_info *, ulong); static int arm64_in_exception_text(ulong); static int arm64_in_exp_entry(ulong); static void arm64_back_trace_cmd(struct bt_info *); static void arm64_back_trace_cmd_v2(struct bt_info *); static void arm64_print_text_symbols(struct bt_info *, struct arm64_stackframe *, FILE *); static int arm64_print_stackframe_entry(struct bt_info *, int, struct arm64_stackframe *, FILE *); static int arm64_print_stackframe_entry_v2(struct bt_info *, int, struct arm64_stackframe *, FILE *); static void arm64_display_full_frame(struct bt_info *, ulong); static void arm64_display_full_frame_v2(struct bt_info *, struct arm64_stackframe *, struct arm64_stackframe *); static int arm64_unwind_frame(struct bt_info *, struct arm64_stackframe *); static int arm64_unwind_frame_v2(struct bt_info *, struct arm64_stackframe *, FILE *); static int arm64_get_dumpfile_stackframe(struct bt_info *, struct arm64_stackframe *); static int arm64_in_kdump_text(struct bt_info *, struct arm64_stackframe *); static int arm64_in_kdump_text_on_irq_stack(struct bt_info *); static int arm64_switch_stack(struct bt_info *, struct arm64_stackframe *, FILE *); static int arm64_switch_stack_from_overflow(struct bt_info *, struct arm64_stackframe *, FILE *); static int arm64_get_stackframe(struct bt_info *, struct arm64_stackframe *); static void arm64_get_stack_frame(struct bt_info *, ulong *, ulong *); static void arm64_gen_hidden_frame(struct bt_info *bt, ulong, struct arm64_stackframe *); static void arm64_print_exception_frame(struct bt_info *, ulong, int, FILE *); static void arm64_do_bt_reference_check(struct bt_info *, ulong, char *); static int arm64_translate_pte(ulong, void *, ulonglong); static ulong arm64_vmalloc_start(void); static int arm64_is_task_addr(ulong); static int arm64_dis_filter(ulong, char *, unsigned int); static void arm64_cmd_mach(void); static void arm64_display_machine_stats(void); static int arm64_get_smp_cpus(void); static void arm64_clear_machdep_cache(void); static int arm64_on_process_stack(struct bt_info *, ulong); static int arm64_in_alternate_stack(int, ulong); static int arm64_in_alternate_stackv(int cpu, ulong stkptr, ulong *stacks, ulong stack_size); static int arm64_on_irq_stack(int, ulong); static int arm64_on_overflow_stack(int, ulong); static void arm64_set_irq_stack(struct bt_info *); static void arm64_set_overflow_stack(struct bt_info *); static void arm64_set_process_stack(struct bt_info *); static int arm64_get_kvaddr_ranges(struct vaddr_range *); static void arm64_get_crash_notes(void); static void arm64_calc_VA_BITS(void); static int arm64_is_uvaddr(ulong, struct task_context *); static void arm64_calc_KERNELPACMASK(void); static void arm64_recalc_KERNELPACMASK(void); static int arm64_get_vmcoreinfo(unsigned long *vaddr, const char *label, int base); static ulong arm64_set_irq_stack_size(void); struct kernel_range { unsigned long modules_vaddr, modules_end; unsigned long vmalloc_start_addr, vmalloc_end; unsigned long vmemmap_vaddr, vmemmap_end; }; static struct kernel_range *arm64_get_va_range(struct machine_specific *ms); static void arm64_get_struct_page_size(struct machine_specific *ms); /* mte tag shift bit */ #define MTE_TAG_SHIFT 56 /* native kernel pointers tag */ #define KASAN_TAG_KERNEL 0xFF /* minimum value for random tags */ #define KASAN_TAG_MIN 0xF0 /* right shift the tag to MTE_TAG_SHIFT bit */ #define mte_tag_shifted(tag) ((ulong)(tag) << MTE_TAG_SHIFT) /* get the top byte value of the original kvaddr */ #define mte_tag_get(addr) (unsigned char)((ulong)(addr) >> MTE_TAG_SHIFT) /* reset the top byte to get an untaggged kvaddr */ #define mte_tag_reset(addr) (((ulong)addr & ~mte_tag_shifted(KASAN_TAG_KERNEL)) | \ mte_tag_shifted(KASAN_TAG_KERNEL)) struct user_regs_bitmap_struct { struct arm64_pt_regs ur; ulong bitmap[32]; }; #define MAX_EXCEPTION_STACKS 7 ulong extra_stacks_idx = 0; struct user_regs_bitmap_struct *extra_stacks_regs[MAX_EXCEPTION_STACKS] = {0}; static inline bool is_mte_kvaddr(ulong addr) { /* check for ARM64_MTE enabled */ if (!(machdep->flags & ARM64_MTE)) return false; /* check the validity of HW Tag-Based kvaddr */ if (mte_tag_get(addr) >= KASAN_TAG_MIN && mte_tag_get(addr) < KASAN_TAG_KERNEL) return true; return false; } static int arm64_is_kvaddr(ulong addr) { if (is_mte_kvaddr(addr)) return (mte_tag_reset(addr) >= (ulong)(machdep->kvbase)); return (addr >= (ulong)(machdep->kvbase)); } static void arm64_calc_kernel_start(void) { struct machine_specific *ms = machdep->machspec; struct syment *sp; if (THIS_KERNEL_VERSION >= LINUX(5,11,0)) sp = kernel_symbol_search("_stext"); else sp = kernel_symbol_search("_text"); ms->kimage_text = (sp ? sp->value : 0); sp = kernel_symbol_search("_end"); ms->kimage_end = (sp ? sp->value : 0); } static int arm64_vmemmap_is_page_ptr(ulong addr, physaddr_t *phys) { ulong size = SIZE(page); ulong pfn, nr; if (IS_SPARSEMEM() && (machdep->flags & VMEMMAP) && (addr >= VMEMMAP_VADDR && addr <= VMEMMAP_END) && !((addr - VMEMMAP_VADDR) % size)) { pfn = (addr - machdep->machspec->vmemmap) / size; nr = pfn_to_section_nr(pfn); if (valid_section_nr(nr)) { if (phys) *phys = PTOB(pfn); return TRUE; } } return FALSE; } static void arm64_get_vmemmap_page_ptr(void) { struct machine_specific *ms = machdep->machspec; /* If vmemmap exists, it means kernel enabled CONFIG_SPARSEMEM_VMEMMAP */ if (arm64_get_vmcoreinfo(&ms->vmemmap, "SYMBOL(vmemmap)", NUM_HEX)) goto out; /* The global symbol of vmemmap is removed since kernel commit 7bc1a0f9e1765 */ if (kernel_symbol_exists("vmemmap")) ms->vmemmap = symbol_value("vmemmap"); else ms->vmemmap = ms->vmemmap_vaddr - ((ms->phys_offset >> machdep->pageshift) * ms->struct_page_size); out: if (ms->vmemmap) machdep->is_page_ptr = arm64_vmemmap_is_page_ptr; } static int arm64_get_current_task_reg(int regno, const char *name, int size, void *value, int sid) { struct bt_info bt_info, bt_setup; struct task_context *tc; struct user_regs_bitmap_struct *ur_bitmap; ulong ip, sp; bool ret = FALSE; switch (regno) { case X0_REGNUM ... PC_REGNUM: break; default: return FALSE; } tc = CURRENT_CONTEXT(); if (!tc) return FALSE; if (sid && sid <= extra_stacks_idx) { ur_bitmap = extra_stacks_regs[extra_stacks_idx - 1]; goto get_sub; } BZERO(&bt_setup, sizeof(struct bt_info)); clone_bt_info(&bt_setup, &bt_info, tc); if (bt_info.stackbase == 0) return FALSE; fill_stackbuf(&bt_info); get_dumpfile_regs(&bt_info, &sp, &ip); if (bt_info.stackbuf) FREEBUF(bt_info.stackbuf); ur_bitmap = (struct user_regs_bitmap_struct *)bt_info.machdep; if (!ur_bitmap) return FALSE; if (!bt_info.need_free) { goto get_all; } get_sub: switch (regno) { case X0_REGNUM ... X30_REGNUM: if (!NUM_IN_BITMAP(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + regno - X0_REGNUM)) { if (!sid) FREEBUF(ur_bitmap); return FALSE; } break; case SP_REGNUM: if (!NUM_IN_BITMAP(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, sp))) { if (!sid) FREEBUF(ur_bitmap); return FALSE; } break; case PC_REGNUM: if (!NUM_IN_BITMAP(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, pc))) { if (!sid) FREEBUF(ur_bitmap); return FALSE; } break; } get_all: switch (regno) { case X0_REGNUM ... X30_REGNUM: if (size != sizeof(ur_bitmap->ur.regs[regno])) break; memcpy(value, &ur_bitmap->ur.regs[regno], size); ret = TRUE; break; case SP_REGNUM: if (size != sizeof(ur_bitmap->ur.sp)) break; memcpy(value, &ur_bitmap->ur.sp, size); ret = TRUE; break; case PC_REGNUM: if (size != sizeof(ur_bitmap->ur.pc)) break; memcpy(value, &ur_bitmap->ur.pc, size); ret = TRUE; break; } if (!sid && bt_info.need_free) { FREEBUF(ur_bitmap); bt_info.need_free = FALSE; } return ret; } /* * Do all necessary machine-specific setup here. This is called several times * during initialization. */ void arm64_init(int when) { ulong value; struct machine_specific *ms; #if defined(__x86_64__) if (ACTIVE()) error(FATAL, "compiled for the ARM64 architecture\n"); #endif switch (when) { case SETUP_ENV: machdep->process_elf_notes = process_elf64_notes; break; case PRE_SYMTAB: machdep->machspec = &arm64_machine_specific; machdep->verify_symbol = arm64_verify_symbol; if (pc->flags & KERNEL_DEBUG_QUERY) return; machdep->verify_paddr = generic_verify_paddr; if (machdep->cmdline_args[0]) arm64_parse_cmdline_args(); machdep->flags |= MACHDEP_BT_TEXT; ms = machdep->machspec; /* * The st->_stext_vmlinux is needed in arm64_init(PRE_GDB) when a * dumpfile does not have vmcoreinfo and we use -m vabits_actual * option, e.g. a raw RAM dumpfile. */ if (ms->VA_BITS_ACTUAL) st->_stext_vmlinux = UNINITIALIZED; if (!ms->kimage_voffset && STREQ(pc->live_memsrc, "/dev/crash")) ioctl(pc->mfd, DEV_CRASH_ARCH_DATA, &ms->kimage_voffset); if (!ms->kimage_voffset) arm64_get_vmcoreinfo(&ms->kimage_voffset, "NUMBER(kimage_voffset)", NUM_HEX); if (ms->kimage_voffset || (ACTIVE() && (symbol_value_from_proc_kallsyms("kimage_voffset") != BADVAL))) { machdep->flags |= NEW_VMEMMAP; /* * Even if CONFIG_RANDOMIZE_BASE is not configured, * derive_kaslr_offset() should work and set * kt->relocate to 0 */ if (!kt->relocate && !(kt->flags2 & (RELOC_AUTO|KASLR))) kt->flags2 |= (RELOC_AUTO|KASLR); } break; case PRE_GDB: if (kernel_symbol_exists("kimage_voffset")) machdep->flags |= NEW_VMEMMAP; if (kernel_symbol_exists("cpu_enable_mte")) machdep->flags |= ARM64_MTE; if (!machdep->pagesize && arm64_get_vmcoreinfo(&value, "PAGESIZE", NUM_DEC)) machdep->pagesize = (unsigned int)value; if (!machdep->pagesize) { /* * Kerneldoc Documentation/arm64/booting.txt describes * the kernel image header flags field. */ value = machdep->machspec->kernel_flags; value = (value >> 1) & 3; switch(value) { case 0: break; case 1: machdep->pagesize = 4096; break; case 2: machdep->pagesize = 16384; break; case 3: machdep->pagesize = 65536; break; } } /* * This code section will only be executed if the kernel is * earlier than Linux 4.4 (if there is no vmcoreinfo) */ if (!machdep->pagesize && kernel_symbol_exists("swapper_pg_dir") && kernel_symbol_exists("idmap_pg_dir")) { value = symbol_value("swapper_pg_dir") - symbol_value("idmap_pg_dir"); /* * idmap_pg_dir is 2 pages prior to 4.1, * and 3 pages thereafter. Only 4K and 64K * page sizes are supported. */ switch (value) { case (4096 * 2): case (4096 * 3): machdep->pagesize = 4096; break; case (65536 * 2): case (65536 * 3): machdep->pagesize = 65536; break; } } else if (ACTIVE()) machdep->pagesize = memory_page_size(); /* host */ machdep->pageshift = ffs(machdep->pagesize) - 1; machdep->pageoffset = machdep->pagesize - 1; machdep->pagemask = ~((ulonglong)machdep->pageoffset); ms = machdep->machspec; arm64_get_struct_page_size(ms); arm64_calc_VA_BITS(); arm64_calc_KERNELPACMASK(); /* vabits_actual introduced after mm flip, so it should be flipped layout */ if (ms->VA_BITS_ACTUAL) { ms->page_offset = ARM64_FLIP_PAGE_OFFSET; /* useless on arm64 */ machdep->identity_map_base = ARM64_FLIP_PAGE_OFFSET; machdep->kvbase = ARM64_FLIP_PAGE_OFFSET; ms->userspace_top = ARM64_USERSPACE_TOP_ACTUAL; } else { ms->page_offset = ARM64_PAGE_OFFSET; machdep->identity_map_base = ARM64_PAGE_OFFSET; machdep->kvbase = ARM64_VA_START; ms->userspace_top = ARM64_USERSPACE_TOP; } machdep->is_kvaddr = arm64_is_kvaddr; machdep->kvtop = arm64_kvtop; /* The defaults */ ms->vmalloc_end = ARM64_VMALLOC_END; ms->vmemmap_vaddr = ARM64_VMEMMAP_VADDR; ms->vmemmap_end = ARM64_VMEMMAP_END; if (machdep->flags & NEW_VMEMMAP) { struct syment *sp; struct kernel_range *r; /* It is finally decided in arm64_calc_kernel_start() */ sp = kernel_symbol_search("_text"); ms->kimage_text = (sp ? sp->value : 0); sp = kernel_symbol_search("_end"); ms->kimage_end = (sp ? sp->value : 0); if (ms->struct_page_size && (r = arm64_get_va_range(ms))) { /* We can get all the MODULES/VMALLOC/VMEMMAP ranges now.*/ ms->modules_vaddr = r->modules_vaddr; ms->modules_end = r->modules_end - 1; ms->vmalloc_start_addr = r->vmalloc_start_addr; ms->vmalloc_end = r->vmalloc_end - 1; ms->vmemmap_vaddr = r->vmemmap_vaddr; ms->vmemmap_end = r->vmemmap_end - 1; } else if (ms->VA_BITS_ACTUAL) { ms->modules_vaddr = (st->_stext_vmlinux & TEXT_OFFSET_MASK) - ARM64_MODULES_VSIZE; ms->modules_end = ms->modules_vaddr + ARM64_MODULES_VSIZE -1; ms->vmalloc_start_addr = ms->modules_end + 1; } else { ms->modules_vaddr = ARM64_VA_START; if (kernel_symbol_exists("kasan_init")) ms->modules_vaddr += ARM64_KASAN_SHADOW_SIZE; ms->modules_end = ms->modules_vaddr + ARM64_MODULES_VSIZE -1; ms->vmalloc_start_addr = ms->modules_end + 1; } arm64_calc_kimage_voffset(); } else { ms->modules_vaddr = ARM64_PAGE_OFFSET - MEGABYTES(64); ms->modules_end = ARM64_PAGE_OFFSET - 1; ms->vmalloc_start_addr = ARM64_VA_START; } switch (machdep->pagesize) { case 4096: machdep->ptrs_per_pgd = PTRS_PER_PGD_L3_4K; if ((machdep->pgd = (char *)malloc(PTRS_PER_PGD_L3_4K * 8)) == NULL) error(FATAL, "cannot malloc pgd space."); if (machdep->machspec->VA_BITS > PGDIR_SHIFT_L4_4K) { machdep->flags |= VM_L4_4K; if ((machdep->pud = (char *)malloc(PTRS_PER_PUD_L4_4K * 8)) == NULL) error(FATAL, "cannot malloc pud space."); } else { machdep->flags |= VM_L3_4K; machdep->pud = NULL; /* not used */ } if ((machdep->pmd = (char *)malloc(PTRS_PER_PMD_L3_4K * 8)) == NULL) error(FATAL, "cannot malloc pmd space."); if ((machdep->ptbl = (char *)malloc(PTRS_PER_PTE_L3_4K * 8)) == NULL) error(FATAL, "cannot malloc ptbl space."); break; case 16384: if (machdep->machspec->VA_BITS == 48) { machdep->flags |= VM_L4_16K; if (!machdep->ptrs_per_pgd) machdep->ptrs_per_pgd = PTRS_PER_PGD_L4_16K; if ((machdep->pgd = (char *)malloc(machdep->ptrs_per_pgd * 8)) == NULL) error(FATAL, "cannot malloc pgd space."); if ((machdep->pud = (char *)malloc(PTRS_PER_PUD_L4_16K * 8)) == NULL) error(FATAL, "cannot malloc pud space."); if ((machdep->pmd = (char *)malloc(PTRS_PER_PMD_L4_16K * 8)) == NULL) error(FATAL, "cannot malloc pmd space."); if ((machdep->ptbl = (char *)malloc(PTRS_PER_PTE_L4_16K * 8)) == NULL) error(FATAL, "cannot malloc ptbl space."); } else if (machdep->machspec->VA_BITS == 47) { machdep->flags |= VM_L3_16K; if (!machdep->ptrs_per_pgd) machdep->ptrs_per_pgd = PTRS_PER_PGD_L3_16K; if ((machdep->pgd = (char *)malloc(machdep->ptrs_per_pgd * 8)) == NULL) error(FATAL, "cannot malloc pgd space."); if ((machdep->pmd = (char *)malloc(PTRS_PER_PMD_L3_16K * 8)) == NULL) error(FATAL, "cannot malloc pmd space."); if ((machdep->ptbl = (char *)malloc(PTRS_PER_PTE_L3_16K * 8)) == NULL) error(FATAL, "cannot malloc ptbl space."); machdep->pud = NULL; /* not used */ } else if (machdep->machspec->VA_BITS == 36) { machdep->flags |= VM_L2_16K; if (!machdep->ptrs_per_pgd) machdep->ptrs_per_pgd = PTRS_PER_PGD_L2_16K; if ((machdep->pgd = (char *)malloc(machdep->ptrs_per_pgd * 8)) == NULL) error(FATAL, "cannot malloc pgd space."); if ((machdep->ptbl = (char *)malloc(PTRS_PER_PTE_L2_16K * 8)) == NULL) error(FATAL, "cannot malloc ptbl space."); machdep->pmd = NULL; /* not used */ machdep->pud = NULL; /* not used */ } else { error(FATAL, "Do not support 52 bits, 4-level for 16K page now."); } break; case 65536: /* * idmap_ptrs_per_pgd has been removed since Linux-v6.0-rc1, see: * commit ebd9aea1f27e ("arm64: head: drop idmap_ptrs_per_pgd") */ if (kernel_symbol_exists("idmap_ptrs_per_pgd") && readmem(symbol_value("idmap_ptrs_per_pgd"), KVADDR, &value, sizeof(ulong), "idmap_ptrs_per_pgd", QUIET|RETURN_ON_ERROR)) machdep->ptrs_per_pgd = value; if (machdep->machspec->VA_BITS > PGDIR_SHIFT_L3_64K) { machdep->flags |= VM_L3_64K; if (!machdep->ptrs_per_pgd) { if (machdep->machspec->VA_BITS == 52) machdep->ptrs_per_pgd = PTRS_PER_PGD_L3_64K_52; else if (machdep->machspec->VA_BITS == 48) machdep->ptrs_per_pgd = PTRS_PER_PGD_L3_64K_48; else error(FATAL, "wrong VA_BITS for 64K page."); } if ((machdep->pgd = (char *)malloc(machdep->ptrs_per_pgd * 8)) == NULL) error(FATAL, "cannot malloc pgd space."); if ((machdep->pmd = (char *)malloc(PTRS_PER_PMD_L3_64K * 8)) == NULL) error(FATAL, "cannot malloc pmd space."); if ((machdep->ptbl = (char *)malloc(PTRS_PER_PTE_L3_64K * 8)) == NULL) error(FATAL, "cannot malloc ptbl space."); } else { machdep->flags |= VM_L2_64K; if (!machdep->ptrs_per_pgd) machdep->ptrs_per_pgd = PTRS_PER_PGD_L2_64K; if ((machdep->pgd = (char *)malloc(machdep->ptrs_per_pgd * 8)) == NULL) error(FATAL, "cannot malloc pgd space."); if ((machdep->ptbl = (char *)malloc(PTRS_PER_PTE_L2_64K * 8)) == NULL) error(FATAL, "cannot malloc ptbl space."); machdep->pmd = NULL; /* not used */ } machdep->pud = NULL; /* not used */ break; default: if (machdep->pagesize) error(FATAL, "invalid/unsupported page size: %d\n", machdep->pagesize); else error(FATAL, "cannot determine page size\n"); } machdep->last_pgd_read = 0; machdep->last_pud_read = 0; machdep->last_pmd_read = 0; machdep->last_ptbl_read = 0; machdep->clear_machdep_cache = arm64_clear_machdep_cache; machdep->stacksize = ARM64_STACK_SIZE; machdep->flags |= VMEMMAP; machdep->uvtop = arm64_uvtop; machdep->is_uvaddr = arm64_is_uvaddr; machdep->eframe_search = arm64_eframe_search; machdep->back_trace = arm64_back_trace_cmd; machdep->in_alternate_stack = arm64_in_alternate_stack; machdep->processor_speed = arm64_processor_speed; machdep->get_task_pgd = arm64_get_task_pgd; machdep->get_stack_frame = arm64_get_stack_frame; machdep->get_stackbase = generic_get_stackbase; machdep->get_stacktop = generic_get_stacktop; machdep->translate_pte = arm64_translate_pte; machdep->memory_size = generic_memory_size; machdep->vmalloc_start = arm64_vmalloc_start; machdep->get_kvaddr_ranges = arm64_get_kvaddr_ranges; machdep->is_task_addr = arm64_is_task_addr; machdep->dis_filter = arm64_dis_filter; machdep->cmd_mach = arm64_cmd_mach; machdep->get_smp_cpus = arm64_get_smp_cpus; machdep->line_number_hooks = NULL; machdep->value_to_symbol = generic_machdep_value_to_symbol; machdep->dump_irq = generic_dump_irq; machdep->show_interrupts = generic_show_interrupts; machdep->get_irq_affinity = generic_get_irq_affinity; machdep->dumpfile_init = NULL; machdep->verify_line_number = NULL; machdep->init_kernel_pgd = arm64_init_kernel_pgd; machdep->get_current_task_reg = arm64_get_current_task_reg; /* use machdep parameters */ arm64_calc_phys_offset(); arm64_calc_physvirt_offset(); if (CRASHDEBUG(1)) { if (machdep->flags & NEW_VMEMMAP) fprintf(fp, "kimage_voffset: %lx\n", machdep->machspec->kimage_voffset); fprintf(fp, "phys_offset: %lx\n", machdep->machspec->phys_offset); fprintf(fp, "physvirt_offset: %lx\n", machdep->machspec->physvirt_offset); } break; case POST_GDB: /* Rely on kernel version to decide the kernel start address */ arm64_calc_kernel_start(); /* Can we get the size of struct page before POST_GDB */ ms = machdep->machspec; if (!ms->struct_page_size) arm64_calc_virtual_memory_ranges(); arm64_get_vmemmap_page_ptr(); arm64_get_section_size_bits(); if (!machdep->max_physmem_bits) { if (arm64_get_vmcoreinfo(&machdep->max_physmem_bits, "NUMBER(MAX_PHYSMEM_BITS)", NUM_DEC)) { /* nothing */ } else if (machdep->machspec->VA_BITS == 52) /* guess */ machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_52; else if (THIS_KERNEL_VERSION >= LINUX(3,17,0)) machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_3_17; else machdep->max_physmem_bits = _MAX_PHYSMEM_BITS; } if (CRASHDEBUG(1)) { if (ms->VA_BITS_ACTUAL) { fprintf(fp, "CONFIG_ARM64_VA_BITS: %ld\n", ms->CONFIG_ARM64_VA_BITS); fprintf(fp, " VA_BITS_ACTUAL: %ld\n", ms->VA_BITS_ACTUAL); fprintf(fp, "(calculated) VA_BITS: %ld\n", ms->VA_BITS); fprintf(fp, " PAGE_OFFSET: %lx\n", ARM64_FLIP_PAGE_OFFSET); fprintf(fp, " VA_START: %lx\n", ms->VA_START); fprintf(fp, " modules: %lx - %lx\n", ms->modules_vaddr, ms->modules_end); fprintf(fp, " vmalloc: %lx - %lx\n", ms->vmalloc_start_addr, ms->vmalloc_end); fprintf(fp, "kernel image: %lx - %lx\n", ms->kimage_text, ms->kimage_end); fprintf(fp, " vmemmap: %lx - %lx\n\n", ms->vmemmap_vaddr, ms->vmemmap_end); } } if (THIS_KERNEL_VERSION >= LINUX(6,10,0)) { ms->__SWP_TYPE_BITS = 5; ms->__SWP_TYPE_SHIFT = 6; ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1); ms->__SWP_OFFSET_SHIFT = 12; ms->__SWP_OFFSET_BITS = 50; ms->__SWP_OFFSET_MASK = ((1UL << ms->__SWP_OFFSET_BITS) - 1); ms->PTE_PROT_NONE = 0; /* unused */ ms->PTE_FILE = 0; /* unused */ } else if (THIS_KERNEL_VERSION >= LINUX(5,19,0)) { ms->__SWP_TYPE_BITS = 5; ms->__SWP_TYPE_SHIFT = 3; ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1); ms->__SWP_OFFSET_SHIFT = (ms->__SWP_TYPE_BITS + ms->__SWP_TYPE_SHIFT); ms->__SWP_OFFSET_BITS = 50; ms->__SWP_OFFSET_MASK = ((1UL << ms->__SWP_OFFSET_BITS) - 1); ms->PTE_PROT_NONE = (1UL << 58); ms->PTE_FILE = 0; /* unused */ } else if (THIS_KERNEL_VERSION >= LINUX(4,0,0)) { ms->__SWP_TYPE_BITS = 6; ms->__SWP_TYPE_SHIFT = 2; ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1); ms->__SWP_OFFSET_SHIFT = (ms->__SWP_TYPE_BITS + ms->__SWP_TYPE_SHIFT); ms->__SWP_OFFSET_BITS = 50; ms->__SWP_OFFSET_MASK = ((1UL << ms->__SWP_OFFSET_BITS) - 1); ms->PTE_PROT_NONE = (1UL << 58); ms->PTE_FILE = 0; /* unused */ } else if (THIS_KERNEL_VERSION >= LINUX(3,13,0)) { ms->__SWP_TYPE_BITS = 6; ms->__SWP_TYPE_SHIFT = 3; ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1); ms->__SWP_OFFSET_SHIFT = (ms->__SWP_TYPE_BITS + ms->__SWP_TYPE_SHIFT); ms->__SWP_OFFSET_BITS = 49; ms->__SWP_OFFSET_MASK = ((1UL << ms->__SWP_OFFSET_BITS) - 1); ms->PTE_PROT_NONE = (1UL << 58); ms->PTE_FILE = (1UL << 2); } else if (THIS_KERNEL_VERSION >= LINUX(3,11,0)) { ms->__SWP_TYPE_BITS = 6; ms->__SWP_TYPE_SHIFT = 4; ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1); ms->__SWP_OFFSET_SHIFT = (ms->__SWP_TYPE_BITS + ms->__SWP_TYPE_SHIFT); ms->__SWP_OFFSET_BITS = 0; /* unused */ ms->__SWP_OFFSET_MASK = 0; /* unused */ ms->PTE_PROT_NONE = (1UL << 2); ms->PTE_FILE = (1UL << 3); } else { ms->__SWP_TYPE_BITS = 6; ms->__SWP_TYPE_SHIFT = 3; ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1); ms->__SWP_OFFSET_SHIFT = (ms->__SWP_TYPE_BITS + ms->__SWP_TYPE_SHIFT); ms->__SWP_OFFSET_BITS = 0; /* unused */ ms->__SWP_OFFSET_MASK = 0; /* unused */ ms->PTE_PROT_NONE = (1UL << 1); ms->PTE_FILE = (1UL << 2); } if (symbol_exists("irq_desc")) ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc, "irq_desc", NULL, 0); else if (kernel_symbol_exists("nr_irqs")) get_symbol_data("nr_irqs", sizeof(unsigned int), &machdep->nr_irqs); if (!machdep->hz) machdep->hz = 100; /* * Let's calculate the KERNELPACMASK value based on the * vabits, see: * arch/arm64/kernel/vmcore_info.c * arch/arm64/include/asm/pointer_auth.h */ if(!machdep->machspec->CONFIG_ARM64_KERNELPACMASK) arm64_recalc_KERNELPACMASK(); arm64_irq_stack_init(); arm64_overflow_stack_init(); arm64_stackframe_init(); break; case POST_INIT: /* * crash_notes contains machine specific information about the * crash. In particular, it contains CPU registers at the time * of the crash. We need this information to extract correct * backtraces from the panic task. */ if (!LIVE()) arm64_get_crash_notes(); gdb_change_thread_context(); break; case LOG_ONLY: machdep->machspec = &arm64_machine_specific; arm64_calc_VA_BITS(); arm64_calc_KERNELPACMASK(); arm64_calc_phys_offset(); machdep->machspec->page_offset = ARM64_PAGE_OFFSET; arm64_calc_physvirt_offset(); break; } } struct kernel_va_range_handler { unsigned long kernel_versions_start; /* include */ unsigned long kernel_versions_end; /* exclude */ struct kernel_range *(*get_range)(struct machine_specific *); }; static struct kernel_range tmp_range; #define _PAGE_END(va) (-(1UL << ((va) - 1))) #define SZ_64K 0x00010000 #define SZ_2M 0x00200000 /* * Get the max shift of the size of struct page. * Most of the time, it is 64 bytes, but not sure. */ static int arm64_get_struct_page_max_shift(struct machine_specific *ms) { return (int)ceil(log2(ms->struct_page_size)); } /* Return TRUE if we succeed, return FALSE on failure. */ static int arm64_get_vmcoreinfo(unsigned long *vaddr, const char *label, int base) { int err = 0; char *string = pc->read_vmcoreinfo(label); if (!string) return FALSE; switch (base) { case NUM_HEX: *vaddr = strtoul(string, NULL, 16); break; case NUM_DEC: *vaddr = strtoul(string, NULL, 10); break; default: err++; error(INFO, "Unknown type:%#x, (NUM_HEX|NUM_DEC)\n", base); } free(string); return err ? FALSE: TRUE; } /* * The change is caused by the kernel patch since v5.18-rc1: * "arm64: crash_core: Export MODULES, VMALLOC, and VMEMMAP ranges" */ static struct kernel_range *arm64_get_range_v5_18(struct machine_specific *ms) { struct kernel_range *r = &tmp_range; /* Get the MODULES_VADDR ~ MODULES_END */ if (!arm64_get_vmcoreinfo(&r->modules_vaddr, "NUMBER(MODULES_VADDR)", NUM_HEX)) return NULL; if (!arm64_get_vmcoreinfo(&r->modules_end, "NUMBER(MODULES_END)", NUM_HEX)) return NULL; /* Get the VMEMMAP_START ~ VMEMMAP_END */ if (!arm64_get_vmcoreinfo(&r->vmemmap_vaddr, "NUMBER(VMEMMAP_START)", NUM_HEX)) return NULL; if (!arm64_get_vmcoreinfo(&r->vmemmap_end, "NUMBER(VMEMMAP_END)", NUM_HEX)) return NULL; /* Get the VMALLOC_START ~ VMALLOC_END */ if (!arm64_get_vmcoreinfo(&r->vmalloc_start_addr, "NUMBER(VMALLOC_START)", NUM_HEX)) return NULL; if (!arm64_get_vmcoreinfo(&r->vmalloc_end, "NUMBER(VMALLOC_END)", NUM_HEX)) return NULL; return r; } /* * The change is caused by the kernel patch since v5.17-rc1: * "b89ddf4cca43 arm64/bpf: Remove 128MB limit for BPF JIT programs" */ static struct kernel_range *arm64_get_range_v5_17(struct machine_specific *ms) { struct kernel_range *r = &tmp_range; unsigned long v = ms->CONFIG_ARM64_VA_BITS; unsigned long vmem_shift, vmemmap_size; /* Not initialized yet */ if (v == 0) return NULL; if (v > 48) v = 48; /* Get the MODULES_VADDR ~ MODULES_END */ r->modules_vaddr = _PAGE_END(v); r->modules_end = r->modules_vaddr + MEGABYTES(128); /* Get the VMEMMAP_START ~ VMEMMAP_END */ vmem_shift = machdep->pageshift - arm64_get_struct_page_max_shift(ms); vmemmap_size = (_PAGE_END(v) - PAGE_OFFSET) >> vmem_shift; r->vmemmap_vaddr = (-(1UL << (ms->CONFIG_ARM64_VA_BITS - vmem_shift))); r->vmemmap_end = r->vmemmap_vaddr + vmemmap_size; /* Get the VMALLOC_START ~ VMALLOC_END */ r->vmalloc_start_addr = r->modules_end; r->vmalloc_end = r->vmemmap_vaddr - MEGABYTES(256); return r; } /* * The change is caused by the kernel patch since v5.11: * "9ad7c6d5e75b arm64: mm: tidy up top of kernel VA space" */ static struct kernel_range *arm64_get_range_v5_11(struct machine_specific *ms) { struct kernel_range *r = &tmp_range; unsigned long v = ms->CONFIG_ARM64_VA_BITS; unsigned long vmem_shift, vmemmap_size, bpf_jit_size = MEGABYTES(128); /* Not initialized yet */ if (v == 0) return NULL; if (v > 48) v = 48; /* Get the MODULES_VADDR ~ MODULES_END */ r->modules_vaddr = _PAGE_END(v) + bpf_jit_size; r->modules_end = r->modules_vaddr + MEGABYTES(128); /* Get the VMEMMAP_START ~ VMEMMAP_END */ vmem_shift = machdep->pageshift - arm64_get_struct_page_max_shift(ms); vmemmap_size = (_PAGE_END(v) - PAGE_OFFSET) >> vmem_shift; r->vmemmap_vaddr = (-(1UL << (ms->CONFIG_ARM64_VA_BITS - vmem_shift))); r->vmemmap_end = r->vmemmap_vaddr + vmemmap_size; /* Get the VMALLOC_START ~ VMALLOC_END */ r->vmalloc_start_addr = r->modules_end; r->vmalloc_end = r->vmemmap_vaddr - MEGABYTES(256); return r; } static unsigned long arm64_get_pud_size(void) { unsigned long PUD_SIZE = 0; switch (machdep->pagesize) { case 4096: if (machdep->machspec->VA_BITS > PGDIR_SHIFT_L4_4K) { PUD_SIZE = PUD_SIZE_L4_4K; } else { PUD_SIZE = PGDIR_SIZE_L3_4K; } break; case 65536: PUD_SIZE = PGDIR_SIZE_L2_64K; default: break; } return PUD_SIZE; } /* * The change is caused by the kernel patches since v5.4, such as: * "ce3aaed87344 arm64: mm: Modify calculation of VMEMMAP_SIZE" * "14c127c957c1 arm64: mm: Flip kernel VA space" */ static struct kernel_range *arm64_get_range_v5_4(struct machine_specific *ms) { struct kernel_range *r = &tmp_range; unsigned long v = ms->CONFIG_ARM64_VA_BITS; unsigned long kasan_shadow_shift, kasan_shadow_offset, PUD_SIZE; unsigned long vmem_shift, vmemmap_size, bpf_jit_size = MEGABYTES(128); char *string; int ret; /* Not initialized yet */ if (v == 0) return NULL; if (v > 48) v = 48; /* Get the MODULES_VADDR ~ MODULES_END */ if (kernel_symbol_exists("kasan_init")) { /* See the arch/arm64/Makefile */ ret = get_kernel_config("CONFIG_KASAN_SW_TAGS", NULL); if (ret == IKCONFIG_N) return NULL; kasan_shadow_shift = (ret == IKCONFIG_Y) ? 4: 3; /* See the arch/arm64/Kconfig*/ ret = get_kernel_config("CONFIG_KASAN_SHADOW_OFFSET", &string); if (ret != IKCONFIG_STR) return NULL; kasan_shadow_offset = atol(string); r->modules_vaddr = (1UL << (64 - kasan_shadow_shift)) + kasan_shadow_offset + bpf_jit_size; } else { r->modules_vaddr = _PAGE_END(v) + bpf_jit_size; } r->modules_end = r->modules_vaddr + MEGABYTES(128); /* Get the VMEMMAP_START ~ VMEMMAP_END */ vmem_shift = machdep->pageshift - arm64_get_struct_page_max_shift(ms); vmemmap_size = (_PAGE_END(v) - PAGE_OFFSET) >> vmem_shift; r->vmemmap_vaddr = (-vmemmap_size - SZ_2M); /* * In the v5.7, the patch: "bbd6ec605c arm64/mm: Enable memory hot remove" * adds the VMEMMAP_END. * * But before the VMEMMAP_END was added to kernel, we can also see * the following in arch/arm64/mm/dump.c: * { VMEMMAP_START + VMEMMAP_SIZE, "vmemmap end" }, */ r->vmemmap_end = r->vmemmap_vaddr + vmemmap_size; /* Get the VMALLOC_START ~ VMALLOC_END */ PUD_SIZE = arm64_get_pud_size(); r->vmalloc_start_addr = r->modules_end; r->vmalloc_end = (-PUD_SIZE - vmemmap_size - SZ_64K); return r; } /* * The change is caused by the kernel patches since v5.0, such as: * "91fc957c9b1d arm64/bpf: don't allocate BPF JIT programs in module memory" */ static struct kernel_range *arm64_get_range_v5_0(struct machine_specific *ms) { struct kernel_range *r = &tmp_range; unsigned long v = ms->CONFIG_ARM64_VA_BITS; unsigned long kasan_shadow_shift, PUD_SIZE; unsigned long vmemmap_size, bpf_jit_size = MEGABYTES(128); unsigned long va_start, page_offset; int ret; /* Not initialized yet */ if (v == 0) return NULL; va_start = (0xffffffffffffffffUL - (1UL << v) + 1); page_offset = (0xffffffffffffffffUL - (1UL << (v - 1)) + 1); /* Get the MODULES_VADDR ~ MODULES_END */ if (kernel_symbol_exists("kasan_init")) { /* See the arch/arm64/Makefile */ ret = get_kernel_config("CONFIG_KASAN_SW_TAGS", NULL); if (ret == IKCONFIG_N) return NULL; kasan_shadow_shift = (ret == IKCONFIG_Y) ? 4: 3; r->modules_vaddr = va_start + (1UL << (v - kasan_shadow_shift)) + bpf_jit_size; } else { r->modules_vaddr = va_start + bpf_jit_size; } r->modules_end = r->modules_vaddr + MEGABYTES(128); /* Get the VMEMMAP_START ~ VMEMMAP_END */ vmemmap_size = (1UL << (v - machdep->pageshift - 1 + arm64_get_struct_page_max_shift(ms))); r->vmemmap_vaddr = page_offset - vmemmap_size; r->vmemmap_end = r->vmemmap_vaddr + vmemmap_size; /* See the arch/arm64/mm/dump.c */ /* Get the VMALLOC_START ~ VMALLOC_END */ PUD_SIZE = arm64_get_pud_size(); r->vmalloc_start_addr = r->modules_end; r->vmalloc_end = page_offset - PUD_SIZE - vmemmap_size - SZ_64K; return r; } static struct kernel_va_range_handler kernel_va_range_handlers[] = { { LINUX(5,18,0), LINUX(999,0,0), /* Just a boundary */ get_range: arm64_get_range_v5_18, }, { LINUX(5,17,0), LINUX(5,18,0), get_range: arm64_get_range_v5_17, }, { LINUX(5,11,0), LINUX(5,17,0), get_range: arm64_get_range_v5_11, }, { LINUX(5,4,0), LINUX(5,11,0), get_range: arm64_get_range_v5_4, }, { LINUX(5,0,0), LINUX(5,4,0), get_range: arm64_get_range_v5_0, }, }; #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) static unsigned long arm64_get_kernel_version(void) { char *string; if (THIS_KERNEL_VERSION) return THIS_KERNEL_VERSION; if ((string = pc->read_vmcoreinfo("OSRELEASE"))) { parse_kernel_version(string); free(string); } return THIS_KERNEL_VERSION; } /* Return NULL if we fail. */ static struct kernel_range *arm64_get_va_range(struct machine_specific *ms) { struct kernel_va_range_handler *h; unsigned long kernel_version = arm64_get_kernel_version(); struct kernel_range *r = NULL; int i; if (!kernel_version) goto range_failed; for (i = 0; i < ARRAY_SIZE(kernel_va_range_handlers); i++) { h = kernel_va_range_handlers + i; /* Get the right hook for this kernel version */ if (h->kernel_versions_start <= kernel_version && kernel_version < h->kernel_versions_end) { /* Get the correct virtual address ranges */ r = h->get_range(ms); if (!r) goto range_failed; return r; } } range_failed: /* Reset ms->struct_page_size to 0 for arm64_calc_virtual_memory_ranges() */ ms->struct_page_size = 0; return NULL; } /* Get the size of struct page {} */ static void arm64_get_struct_page_size(struct machine_specific *ms) { arm64_get_vmcoreinfo(&ms->struct_page_size, "SIZE(page)", NUM_DEC); } /* * Accept or reject a symbol from the kernel namelist. */ static int arm64_verify_symbol(const char *name, ulong value, char type) { if (!name || !strlen(name)) return FALSE; if ((type == 'A') && STREQ(name, "_kernel_flags_le")) machdep->machspec->kernel_flags = le64toh(value); if ((type == 'A') && STREQ(name, "_kernel_flags_le_hi32")) machdep->machspec->kernel_flags |= ((ulong)le32toh(value) << 32); if ((type == 'A') && STREQ(name, "_kernel_flags_le_lo32")) machdep->machspec->kernel_flags |= le32toh(value); if (((type == 'A') || (type == 'a')) && (highest_bit_long(value) != 63)) return FALSE; if ((value == 0) && ((type == 'a') || (type == 'n') || (type == 'N') || (type == 'U'))) return FALSE; if (STREQ(name, "$d") || STRNEQ(name, "$d.") || STREQ(name, "$x") || STRNEQ(name, "$x.") || STREQ(name, "$c") || STRNEQ(name, "$c.")) return FALSE; if ((type == 'A') && STRNEQ(name, "__crc_")) return FALSE; if ((type == 'N') && strstr(name, "$d")) return FALSE; if (!(machdep->flags & KSYMS_START) && STREQ(name, "idmap_pg_dir")) machdep->flags |= KSYMS_START; return TRUE; } void arm64_dump_machdep_table(ulong arg) { const struct machine_specific *ms = machdep->machspec; int others, i; others = 0; fprintf(fp, " flags: %lx (", machdep->flags); if (machdep->flags & KSYMS_START) fprintf(fp, "%sKSYMS_START", others++ ? "|" : ""); if (machdep->flags & PHYS_OFFSET) fprintf(fp, "%sPHYS_OFFSET", others++ ? "|" : ""); if (machdep->flags & VM_L2_64K) fprintf(fp, "%sVM_L2_64K", others++ ? "|" : ""); if (machdep->flags & VM_L3_64K) fprintf(fp, "%sVM_L3_64K", others++ ? "|" : ""); if (machdep->flags & VM_L2_16K) fprintf(fp, "%sVM_L2_16K", others++ ? "|" : ""); if (machdep->flags & VM_L3_16K) fprintf(fp, "%sVM_L3_16K", others++ ? "|" : ""); if (machdep->flags & VM_L4_16K) fprintf(fp, "%sVM_L4_16K", others++ ? "|" : ""); if (machdep->flags & VM_L3_4K) fprintf(fp, "%sVM_L3_4K", others++ ? "|" : ""); if (machdep->flags & VM_L4_4K) fprintf(fp, "%sVM_L4_4K", others++ ? "|" : ""); if (machdep->flags & VMEMMAP) fprintf(fp, "%sVMEMMAP", others++ ? "|" : ""); if (machdep->flags & KDUMP_ENABLED) fprintf(fp, "%sKDUMP_ENABLED", others++ ? "|" : ""); if (machdep->flags & IRQ_STACKS) fprintf(fp, "%sIRQ_STACKS", others++ ? "|" : ""); if (machdep->flags & UNW_4_14) fprintf(fp, "%sUNW_4_14", others++ ? "|" : ""); if (machdep->flags & MACHDEP_BT_TEXT) fprintf(fp, "%sMACHDEP_BT_TEXT", others++ ? "|" : ""); if (machdep->flags & NEW_VMEMMAP) fprintf(fp, "%sNEW_VMEMMAP", others++ ? "|" : ""); if (machdep->flags & FLIPPED_VM) fprintf(fp, "%sFLIPPED_VM", others++ ? "|" : ""); if (machdep->flags & HAS_PHYSVIRT_OFFSET) fprintf(fp, "%sHAS_PHYSVIRT_OFFSET", others++ ? "|" : ""); if (machdep->flags & ARM64_MTE) fprintf(fp, "%sARM64_MTE", others++ ? "|" : ""); fprintf(fp, ")\n"); fprintf(fp, " kvbase: %lx\n", machdep->kvbase); fprintf(fp, " identity_map_base: %lx\n", machdep->identity_map_base); fprintf(fp, " pagesize: %d\n", machdep->pagesize); fprintf(fp, " pageshift: %d\n", machdep->pageshift); fprintf(fp, " pagemask: %lx\n", (ulong)machdep->pagemask); fprintf(fp, " pageoffset: %lx\n", machdep->pageoffset); fprintf(fp, " stacksize: %ld\n", machdep->stacksize); fprintf(fp, " hz: %d\n", machdep->hz); fprintf(fp, " mhz: %ld\n", machdep->mhz); fprintf(fp, " memsize: %lld (0x%llx)\n", (ulonglong)machdep->memsize, (ulonglong)machdep->memsize); fprintf(fp, " bits: %d\n", machdep->bits); fprintf(fp, " nr_irqs: %d\n", machdep->nr_irqs); fprintf(fp, " eframe_search: arm64_eframe_search()\n"); fprintf(fp, " back_trace: arm64_back_trace_cmd() (default: %s method)\n", kt->flags & USE_OPT_BT ? "optional" : "original"); fprintf(fp, " in_alternate_stack: arm64_in_alternate_stack()\n"); fprintf(fp, " processor_speed: arm64_processor_speed()\n"); fprintf(fp, " uvtop: arm64_uvtop()->%s()\n", machdep->flags & VM_L3_4K ? "arm64_vtop_3level_4k" : machdep->flags & VM_L4_4K ? "arm64_vtop_4level_4k" : machdep->flags & VM_L2_16K ? "arm64_vtop_2level_16k" : machdep->flags & VM_L3_16K ? "arm64_vtop_3level_16k" : machdep->flags & VM_L4_16K ? "arm64_vtop_4level_16k" : machdep->flags & VM_L3_64K ? "arm64_vtop_3level_64k" : "arm64_vtop_2level_64k"); fprintf(fp, " kvtop: arm64_kvtop()->%s()\n", machdep->flags & VM_L3_4K ? "arm64_vtop_3level_4k" : machdep->flags & VM_L4_4K ? "arm64_vtop_4level_4k" : machdep->flags & VM_L2_16K ? "arm64_vtop_2level_16k" : machdep->flags & VM_L3_16K ? "arm64_vtop_3level_16k" : machdep->flags & VM_L4_16K ? "arm64_vtop_4level_16k" : machdep->flags & VM_L3_64K ? "arm64_vtop_3level_64k" : "arm64_vtop_2level_64k"); fprintf(fp, " get_task_pgd: arm64_get_task_pgd()\n"); fprintf(fp, " dump_irq: generic_dump_irq()\n"); fprintf(fp, " get_stack_frame: arm64_get_stack_frame()\n"); fprintf(fp, " get_stackbase: generic_get_stackbase()\n"); fprintf(fp, " get_stacktop: generic_get_stacktop()\n"); fprintf(fp, " translate_pte: arm64_translate_pte()\n"); fprintf(fp, " memory_size: generic_memory_size()\n"); fprintf(fp, " vmalloc_start: arm64_vmalloc_start()\n"); fprintf(fp, " get_kvaddr_ranges: arm64_get_kvaddr_ranges()\n"); fprintf(fp, " is_task_addr: arm64_is_task_addr()\n"); fprintf(fp, " verify_symbol: arm64_verify_symbol()\n"); fprintf(fp, " dis_filter: arm64_dis_filter()\n"); fprintf(fp, " cmd_mach: arm64_cmd_mach()\n"); fprintf(fp, " get_smp_cpus: arm64_get_smp_cpus()\n"); fprintf(fp, " is_kvaddr: arm64_is_kvaddr()\n"); fprintf(fp, " is_uvaddr: arm64_is_uvaddr()\n"); fprintf(fp, " value_to_symbol: generic_machdep_value_to_symbol()\n"); fprintf(fp, " init_kernel_pgd: arm64_init_kernel_pgd\n"); fprintf(fp, " verify_paddr: generic_verify_paddr()\n"); fprintf(fp, " show_interrupts: generic_show_interrupts()\n"); fprintf(fp, " get_irq_affinity: generic_get_irq_affinity()\n"); fprintf(fp, " dumpfile_init: (not used)\n"); fprintf(fp, " process_elf_notes: process_elf64_notes()\n"); fprintf(fp, " verify_line_number: (not used)\n"); fprintf(fp, " xendump_p2m_create: (n/a)\n"); fprintf(fp, "xen_kdump_p2m_create: (n/a)\n"); fprintf(fp, " xendump_panic_task: (n/a)\n"); fprintf(fp, " get_xendump_regs: (n/a)\n"); fprintf(fp, " line_number_hooks: (not used)\n"); fprintf(fp, " last_pgd_read: %lx\n", machdep->last_pgd_read); fprintf(fp, " last_pud_read: "); if ((!(machdep->flags & VM_L4_4K)) && (!(machdep->flags & VM_L4_16K))) fprintf(fp, "(not used)\n"); else fprintf(fp, "%lx\n", machdep->last_pud_read); fprintf(fp, " last_pmd_read: "); if ((machdep->flags & VM_L2_64K) || (machdep->flags & VM_L2_16K)) fprintf(fp, "(not used)\n"); else fprintf(fp, "%lx\n", machdep->last_pmd_read); fprintf(fp, " last_ptbl_read: %lx\n", machdep->last_ptbl_read); fprintf(fp, " clear_machdep_cache: arm64_clear_machdep_cache()\n"); fprintf(fp, " pgd: %lx\n", (ulong)machdep->pgd); fprintf(fp, " pud: %lx\n", (ulong)machdep->pud); fprintf(fp, " pmd: %lx\n", (ulong)machdep->pmd); fprintf(fp, " ptbl: %lx\n", (ulong)machdep->ptbl); fprintf(fp, " ptrs_per_pgd: %d\n", machdep->ptrs_per_pgd); fprintf(fp, " section_size_bits: %ld\n", machdep->section_size_bits); fprintf(fp, " max_physmem_bits: %ld\n", machdep->max_physmem_bits); fprintf(fp, " sections_per_root: %ld\n", machdep->sections_per_root); for (i = 0; i < MAX_MACHDEP_ARGS; i++) { fprintf(fp, " cmdline_args[%d]: %s\n", i, machdep->cmdline_args[i] ? machdep->cmdline_args[i] : "(unused)"); } fprintf(fp, " machspec: %lx\n", (ulong)ms); fprintf(fp, " struct_page_size: %ld\n", ms->struct_page_size); fprintf(fp, " VA_BITS: %ld\n", ms->VA_BITS); fprintf(fp, " CONFIG_ARM64_VA_BITS: %ld\n", ms->CONFIG_ARM64_VA_BITS); fprintf(fp, " VA_START: "); if (ms->VA_START) fprintf(fp, "%lx\n", ms->VA_START); else fprintf(fp, "(unused)\n"); fprintf(fp, " VA_BITS_ACTUAL: "); if (ms->VA_BITS_ACTUAL) fprintf(fp, "%ld\n", ms->VA_BITS_ACTUAL); else fprintf(fp, "(unused)\n"); fprintf(fp, "CONFIG_ARM64_KERNELPACMASK: "); if (ms->CONFIG_ARM64_KERNELPACMASK) fprintf(fp, "%lx\n", ms->CONFIG_ARM64_KERNELPACMASK); else fprintf(fp, "(unused)\n"); fprintf(fp, " userspace_top: %016lx\n", ms->userspace_top); fprintf(fp, " page_offset: %016lx\n", ms->page_offset); fprintf(fp, " vmalloc_start_addr: %016lx\n", ms->vmalloc_start_addr); fprintf(fp, " vmalloc_end: %016lx\n", ms->vmalloc_end); fprintf(fp, " modules_vaddr: %016lx\n", ms->modules_vaddr); fprintf(fp, " modules_end: %016lx\n", ms->modules_end); fprintf(fp, " vmemmap_vaddr: %016lx\n", ms->vmemmap_vaddr); fprintf(fp, " vmemmap_end: %016lx\n", ms->vmemmap_end); if (machdep->flags & NEW_VMEMMAP) { fprintf(fp, " vmemmap: %016lx\n", ms->vmemmap); fprintf(fp, " kimage_text: %016lx\n", ms->kimage_text); fprintf(fp, " kimage_end: %016lx\n", ms->kimage_end); fprintf(fp, " kimage_voffset: %016lx\n", ms->kimage_voffset); } fprintf(fp, " phys_offset: %lx\n", ms->phys_offset); fprintf(fp, " physvirt_offset: %lx\n", ms->physvirt_offset); fprintf(fp, "__exception_text_start: %lx\n", ms->__exception_text_start); fprintf(fp, " __exception_text_end: %lx\n", ms->__exception_text_end); fprintf(fp, " __irqentry_text_start: %lx\n", ms->__irqentry_text_start); fprintf(fp, " __irqentry_text_end: %lx\n", ms->__irqentry_text_end); fprintf(fp, " exp_entry1_start: %lx\n", ms->exp_entry1_start); fprintf(fp, " exp_entry1_end: %lx\n", ms->exp_entry1_end); fprintf(fp, " exp_entry2_start: %lx\n", ms->exp_entry2_start); fprintf(fp, " exp_entry2_end: %lx\n", ms->exp_entry2_end); fprintf(fp, " panic_task_regs: %lx\n", (ulong)ms->panic_task_regs); fprintf(fp, " user_eframe_offset: %ld\n", ms->user_eframe_offset); fprintf(fp, " kern_eframe_offset: %ld\n", ms->kern_eframe_offset); fprintf(fp, " PTE_PROT_NONE: %lx\n", ms->PTE_PROT_NONE); fprintf(fp, " PTE_FILE: "); if (ms->PTE_FILE) fprintf(fp, "%lx\n", ms->PTE_FILE); else fprintf(fp, "(unused)\n"); fprintf(fp, " __SWP_TYPE_BITS: %ld\n", ms->__SWP_TYPE_BITS); fprintf(fp, " __SWP_TYPE_SHIFT: %ld\n", ms->__SWP_TYPE_SHIFT); fprintf(fp, " __SWP_TYPE_MASK: %lx\n", ms->__SWP_TYPE_MASK); fprintf(fp, " __SWP_OFFSET_BITS: "); if (ms->__SWP_OFFSET_BITS) fprintf(fp, "%ld\n", ms->__SWP_OFFSET_BITS); else fprintf(fp, "(unused)\n"); fprintf(fp, " __SWP_OFFSET_SHIFT: %ld\n", ms->__SWP_OFFSET_SHIFT); fprintf(fp, " __SWP_OFFSET_MASK: "); if (ms->__SWP_OFFSET_MASK) fprintf(fp, "%lx\n", ms->__SWP_OFFSET_MASK); else fprintf(fp, "(unused)\n"); fprintf(fp, " machine_kexec_start: %lx\n", ms->machine_kexec_start); fprintf(fp, " machine_kexec_end: %lx\n", ms->machine_kexec_end); fprintf(fp, " crash_kexec_start: %lx\n", ms->crash_kexec_start); fprintf(fp, " crash_kexec_end: %lx\n", ms->crash_kexec_end); fprintf(fp, " crash_save_cpu_start: %lx\n", ms->crash_save_cpu_start); fprintf(fp, " crash_save_cpu_end: %lx\n", ms->crash_save_cpu_end); fprintf(fp, " kernel_flags: %lx\n", ms->kernel_flags); fprintf(fp, " irq_stackbuf: %lx\n", (ulong)ms->irq_stackbuf); if (machdep->flags & IRQ_STACKS) { fprintf(fp, " irq_stack_size: %ld\n", ms->irq_stack_size); for (i = 0; i < kt->cpus; i++) fprintf(fp, " irq_stacks[%d]: %lx\n", i, ms->irq_stacks[i]); } else { fprintf(fp, " irq_stack_size: (unused)\n"); fprintf(fp, " irq_stacks: (unused)\n"); } } static int arm64_parse_machdep_arg_l(char *argstring, char *param, ulong *value) { int len; int megabytes = FALSE; char *p; len = strlen(param); if (!STRNEQ(argstring, param) || (argstring[len] != '=')) return FALSE; if ((LASTCHAR(argstring) == 'm') || (LASTCHAR(argstring) == 'M')) { LASTCHAR(argstring) = NULLCHAR; megabytes = TRUE; } p = argstring + len + 1; if (strlen(p)) { int flags = RETURN_ON_ERROR | QUIET; int err = 0; if (STRNEQ(argstring, "max_physmem_bits")) { *value = dtol(p, flags, &err); } else if (STRNEQ(argstring, "vabits_actual")) { *value = dtol(p, flags, &err); } else if (megabytes) { *value = dtol(p, flags, &err); if (!err) *value = MEGABYTES(*value); } else { *value = htol(p, flags, &err); } if (!err) return TRUE; } return FALSE; } /* * Parse machine dependent command line arguments. * * Force the phys_offset address via: * * --machdep phys_offset=
*/ static void arm64_parse_cmdline_args(void) { int index, i, c; char *arglist[MAXARGS]; char buf[BUFSIZE]; char *p; for (index = 0; index < MAX_MACHDEP_ARGS; index++) { if (!machdep->cmdline_args[index]) break; if (!strstr(machdep->cmdline_args[index], "=")) { error(WARNING, "ignoring --machdep option: %x\n", machdep->cmdline_args[index]); continue; } strcpy(buf, machdep->cmdline_args[index]); for (p = buf; *p; p++) { if (*p == ',') *p = ' '; } c = parse_line(buf, arglist); for (i = 0; i < c; i++) { if (arm64_parse_machdep_arg_l(arglist[i], "phys_offset", &machdep->machspec->phys_offset)) { error(NOTE, "setting phys_offset to: 0x%lx\n\n", machdep->machspec->phys_offset); machdep->flags |= PHYS_OFFSET; continue; } else if (arm64_parse_machdep_arg_l(arglist[i], "kimage_voffset", &machdep->machspec->kimage_voffset)) { error(NOTE, "setting kimage_voffset to: 0x%lx\n\n", machdep->machspec->kimage_voffset); continue; } else if (arm64_parse_machdep_arg_l(arglist[i], "max_physmem_bits", &machdep->max_physmem_bits)) { error(NOTE, "setting max_physmem_bits to: %ld\n\n", machdep->max_physmem_bits); continue; } else if (arm64_parse_machdep_arg_l(arglist[i], "vabits_actual", &machdep->machspec->VA_BITS_ACTUAL)) { error(NOTE, "setting vabits_actual to: %ld\n\n", machdep->machspec->VA_BITS_ACTUAL); continue; } error(WARNING, "ignoring --machdep option: %s\n", arglist[i]); } } } #define MIN_KIMG_ALIGN (0x00200000) /* kimage load address must be aligned 2M */ /* * Traverse the entire dumpfile to find/verify kimage_voffset. */ static int arm64_search_for_kimage_voffset(ulong phys_base) { ulong kimage_load_addr; ulong phys_end; struct machine_specific *ms = machdep->machspec; if (!arm_kdump_phys_end(&phys_end)) return FALSE; for (kimage_load_addr = phys_base; kimage_load_addr <= phys_end; kimage_load_addr += MIN_KIMG_ALIGN) { ms->kimage_voffset = ms->vmalloc_start_addr - kimage_load_addr; if ((kt->flags2 & KASLR) && (kt->flags & RELOC_SET)) ms->kimage_voffset += (kt->relocate * - 1); if (verify_kimage_voffset()) { if (CRASHDEBUG(1)) error(INFO, "dumpfile searched for kimage_voffset: %lx\n\n", ms->kimage_voffset); break; } } if (kimage_load_addr > phys_end) return FALSE; return TRUE; } static int verify_kimage_voffset(void) { ulong kimage_voffset; if (!readmem(symbol_value("kimage_voffset"), KVADDR, &kimage_voffset, sizeof(kimage_voffset), "verify kimage_voffset", QUIET|RETURN_ON_ERROR)) return FALSE; return (machdep->machspec->kimage_voffset == kimage_voffset); } static void arm64_calc_kimage_voffset(void) { struct machine_specific *ms = machdep->machspec; ulong phys_addr = 0; int errflag; if (ms->kimage_voffset) /* vmcoreinfo, ioctl, or --machdep override */ return; if (ACTIVE()) { char buf[BUFSIZE]; char *p1; FILE *iomem; ulong kimage_voffset, vaddr; if (pc->flags & PROC_KCORE) { kimage_voffset = symbol_value_from_proc_kallsyms("kimage_voffset"); if ((kimage_voffset != BADVAL) && (READMEM(pc->mfd, &vaddr, sizeof(ulong), kimage_voffset, KCORE_USE_VADDR) > 0)) { ms->kimage_voffset = vaddr; return; } } if ((iomem = fopen("/proc/iomem", "r")) == NULL) return; errflag = 1; while (fgets(buf, BUFSIZE, iomem)) { if(strstr(buf, ": Kernel code")) { errflag = 0; break; } if (strstr(buf, ": System RAM")) { clean_line(buf); if (!(p1 = strstr(buf, "-"))) continue; *p1 = NULLCHAR; phys_addr = htol(buf, RETURN_ON_ERROR | QUIET, NULL); if (phys_addr == BADADDR) continue; } } fclose(iomem); if (errflag) return; } else if (KDUMP_DUMPFILE()) { errflag = 1; if (arm_kdump_phys_base(&phys_addr)) { /* Get start address of first memory block */ ms->kimage_voffset = ms->vmalloc_start_addr - phys_addr; if ((kt->flags2 & KASLR) && (kt->flags & RELOC_SET)) ms->kimage_voffset += (kt->relocate * -1); if (verify_kimage_voffset() || arm64_search_for_kimage_voffset(phys_addr)) errflag = 0; } if (errflag) { error(WARNING, "kimage_voffset cannot be determined from the dumpfile.\n"); error(CONT, "Try using the command line option: --machdep kimage_voffset=\n"); } return; } else { error(WARNING, "kimage_voffset cannot be determined from the dumpfile.\n"); error(CONT, "Using default value of 0. If this is not correct, then try\n"); error(CONT, "using the command line option: --machdep kimage_voffset=\n"); return; } ms->kimage_voffset = ms->vmalloc_start_addr - phys_addr; if ((kt->flags2 & KASLR) && (kt->flags & RELOC_SET)) ms->kimage_voffset += (kt->relocate * -1); } /* * The physvirt_offset only exits in kernel [5.4, 5.10) * * 1) In kernel v5.4, the patch: * "5383cc6efed137 arm64: mm: Introduce vabits_actual" * * introduced the physvirt_offset. * * 2) In kernel v5.10, the patch: * "7bc1a0f9e17658 arm64: mm: use single quantity * to represent the PA to VA translation" * removed the physvirt_offset. */ static void arm64_calc_physvirt_offset(void) { struct machine_specific *ms = machdep->machspec; ulong physvirt_offset; struct syment *sp; ulong value; if ((sp = kernel_symbol_search("physvirt_offset")) && machdep->machspec->kimage_voffset) { if (pc->flags & PROC_KCORE) { value = symbol_value_from_proc_kallsyms("physvirt_offset"); if ((value != BADVAL) && (READMEM(pc->mfd, &physvirt_offset, sizeof(ulong), value, KCORE_USE_VADDR) > 0)) { machdep->flags |= HAS_PHYSVIRT_OFFSET; ms->physvirt_offset = physvirt_offset; /* Update the ms->phys_offset which is wrong */ ms->phys_offset = ms->physvirt_offset + ms->page_offset; return; } } if (READMEM(pc->mfd, &physvirt_offset, sizeof(physvirt_offset), sp->value, sp->value - machdep->machspec->kimage_voffset) > 0) { machdep->flags |= HAS_PHYSVIRT_OFFSET; ms->physvirt_offset = physvirt_offset; return; } } /* Useless if no symbol 'physvirt_offset', just keep semantics */ ms->physvirt_offset = ms->phys_offset - ms->page_offset; } static void arm64_calc_phys_offset(void) { struct machine_specific *ms = machdep->machspec; ulong phys_offset; if (machdep->flags & PHYS_OFFSET) /* --machdep override */ return; /* * Next determine suitable value for phys_offset. User can override this * by passing valid '--machdep phys_offset=' option. */ ms->phys_offset = 0; if (ACTIVE()) { char buf[BUFSIZE]; char *p1; int errflag; FILE *iomem; physaddr_t paddr; ulong vaddr; struct syment *sp; if ((machdep->flags & NEW_VMEMMAP) && ms->kimage_voffset && (sp = kernel_symbol_search("memstart_addr"))) { if (pc->flags & PROC_KCORE) { if (arm64_get_vmcoreinfo(&ms->phys_offset, "NUMBER(PHYS_OFFSET)", NUM_HEX)) return; vaddr = symbol_value_from_proc_kallsyms("memstart_addr"); if (vaddr == BADVAL) vaddr = sp->value; paddr = KCORE_USE_VADDR; } else { vaddr = sp->value; paddr = sp->value - machdep->machspec->kimage_voffset; } if (READMEM(pc->mfd, &phys_offset, sizeof(phys_offset), vaddr, paddr) > 0) { ms->phys_offset = phys_offset; return; } } if ((iomem = fopen("/proc/iomem", "r")) == NULL) return; /* * Memory regions are sorted in ascending order. We take the * first region which should be correct for most uses. */ errflag = 1; while (fgets(buf, BUFSIZE, iomem)) { if (strstr(buf, ": System RAM")) { clean_line(buf); errflag = 0; break; } } fclose(iomem); if (errflag) return; if (!(p1 = strstr(buf, "-"))) return; *p1 = NULLCHAR; phys_offset = htol(buf, RETURN_ON_ERROR | QUIET, &errflag); if (errflag) return; ms->phys_offset = phys_offset; } else if (DISKDUMP_DUMPFILE() && diskdump_phys_base(&phys_offset)) { ms->phys_offset = phys_offset; } else if (KDUMP_DUMPFILE() && arm64_kdump_phys_base(&phys_offset)) { ms->phys_offset = phys_offset; } else { error(WARNING, "phys_offset cannot be determined from the dumpfile.\n"); error(CONT, "Using default value of 0. If this is not correct, then try\n"); error(CONT, "using the command line option: --machdep phys_offset=\n"); } if (CRASHDEBUG(1)) fprintf(fp, "using %lx as phys_offset\n", ms->phys_offset); } /* * Determine SECTION_SIZE_BITS either by reading VMCOREINFO or the kernel * config, otherwise use the 64-bit ARM default definiton. */ static void arm64_get_section_size_bits(void) { int ret; char *string; if (THIS_KERNEL_VERSION >= LINUX(5,12,0)) { if (machdep->pagesize == 65536) machdep->section_size_bits = _SECTION_SIZE_BITS_5_12_64K; else machdep->section_size_bits = _SECTION_SIZE_BITS_5_12; } else machdep->section_size_bits = _SECTION_SIZE_BITS; if (arm64_get_vmcoreinfo(&machdep->section_size_bits, "NUMBER(SECTION_SIZE_BITS)", NUM_DEC)) { /* nothing */ } else if (kt->ikconfig_flags & IKCONFIG_AVAIL) { if ((ret = get_kernel_config("CONFIG_MEMORY_HOTPLUG", NULL)) == IKCONFIG_Y) { if ((ret = get_kernel_config("CONFIG_HOTPLUG_SIZE_BITS", &string)) == IKCONFIG_STR) machdep->section_size_bits = atol(string); } } if (CRASHDEBUG(1)) fprintf(fp, "SECTION_SIZE_BITS: %ld\n", machdep->section_size_bits); } /* * Determine PHYS_OFFSET either by reading VMCOREINFO or the kernel * symbol, otherwise borrow the 32-bit ARM functionality. */ static int arm64_kdump_phys_base(ulong *phys_offset) { struct syment *sp; physaddr_t paddr; if (arm64_get_vmcoreinfo(phys_offset, "NUMBER(PHYS_OFFSET)", NUM_HEX)) return TRUE; if ((machdep->flags & NEW_VMEMMAP) && machdep->machspec->kimage_voffset && (sp = kernel_symbol_search("memstart_addr"))) { paddr = sp->value - machdep->machspec->kimage_voffset; if (READMEM(-1, phys_offset, sizeof(*phys_offset), sp->value, paddr) > 0) return TRUE; } return arm_kdump_phys_base(phys_offset); } static void arm64_init_kernel_pgd(void) { int i; ulong value; if (!kernel_symbol_exists("init_mm") || !readmem(symbol_value("init_mm") + OFFSET(mm_struct_pgd), KVADDR, &value, sizeof(void *), "init_mm.pgd", RETURN_ON_ERROR)) { if (kernel_symbol_exists("swapper_pg_dir")) value = symbol_value("swapper_pg_dir"); else { error(WARNING, "cannot determine kernel pgd location\n"); return; } } for (i = 0; i < NR_CPUS; i++) vt->kernel_pgd[i] = value; } ulong arm64_PTOV(ulong paddr) { struct machine_specific *ms = machdep->machspec; /* * Either older kernel before kernel has 'physvirt_offset' or newer * kernel which removes 'physvirt_offset' has the same formula: * #define __phys_to_virt(x) ((unsigned long)((x) - PHYS_OFFSET) | PAGE_OFFSET) */ if (!(machdep->flags & HAS_PHYSVIRT_OFFSET)) return (paddr - ms->phys_offset) | PAGE_OFFSET; else return paddr - ms->physvirt_offset; } ulong arm64_VTOP(ulong addr) { if (is_mte_kvaddr(addr)) addr = mte_tag_reset(addr); if (machdep->flags & NEW_VMEMMAP) { if (machdep->machspec->VA_START && (addr >= machdep->machspec->kimage_text) && (addr <= machdep->machspec->kimage_end)) { return addr - machdep->machspec->kimage_voffset; } if (addr >= machdep->machspec->page_offset) { if (machdep->flags & HAS_PHYSVIRT_OFFSET) { return addr + machdep->machspec->physvirt_offset; } else { /* * Either older kernel before kernel has 'physvirt_offset' or newer * kernel which removes 'physvirt_offset' has the same formula: * #define __lm_to_phys(addr) (((addr) & ~PAGE_OFFSET) + PHYS_OFFSET) */ return (addr & ~PAGE_OFFSET) + machdep->machspec->phys_offset; } } else if (machdep->machspec->kimage_voffset) return addr - machdep->machspec->kimage_voffset; else /* no randomness */ return machdep->machspec->phys_offset + (addr - machdep->machspec->vmalloc_start_addr); } else { return machdep->machspec->phys_offset + (addr - machdep->machspec->page_offset); } } static int arm64_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose) { ulong kernel_pgd; if (!IS_KVADDR(kvaddr)) return FALSE; if (!vt->vmalloc_start) { *paddr = VTOP(kvaddr); return TRUE; } if (!IS_VMALLOC_ADDR(kvaddr)) { *paddr = VTOP(kvaddr); if (!verbose) return TRUE; } kernel_pgd = vt->kernel_pgd[0]; *paddr = 0; switch (machdep->flags & (VM_L2_64K|VM_L3_64K|VM_L3_4K|VM_L4_4K|VM_L2_16K|VM_L3_16K|VM_L4_16K)) { case VM_L2_64K: return arm64_vtop_2level_64k(kernel_pgd, kvaddr, paddr, verbose); case VM_L3_64K: return arm64_vtop_3level_64k(kernel_pgd, kvaddr, paddr, verbose); case VM_L3_4K: return arm64_vtop_3level_4k(kernel_pgd, kvaddr, paddr, verbose); case VM_L4_4K: return arm64_vtop_4level_4k(kernel_pgd, kvaddr, paddr, verbose); case VM_L2_16K: return arm64_vtop_2level_16k(kernel_pgd, kvaddr, paddr, verbose); case VM_L3_16K: return arm64_vtop_3level_16k(kernel_pgd, kvaddr, paddr, verbose); case VM_L4_16K: return arm64_vtop_4level_16k(kernel_pgd, kvaddr, paddr, verbose); default: return FALSE; } } static int arm64_uvtop(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbose) { ulong user_pgd; readmem(tc->mm_struct + OFFSET(mm_struct_pgd), KVADDR, &user_pgd, sizeof(long), "user pgd", FAULT_ON_ERROR); *paddr = 0; switch (machdep->flags & (VM_L2_64K|VM_L3_64K|VM_L3_4K|VM_L4_4K|VM_L2_16K|VM_L3_16K|VM_L4_16K)) { case VM_L2_64K: return arm64_vtop_2level_64k(user_pgd, uvaddr, paddr, verbose); case VM_L3_64K: return arm64_vtop_3level_64k(user_pgd, uvaddr, paddr, verbose); case VM_L3_4K: return arm64_vtop_3level_4k(user_pgd, uvaddr, paddr, verbose); case VM_L4_4K: return arm64_vtop_4level_4k(user_pgd, uvaddr, paddr, verbose); case VM_L2_16K: return arm64_vtop_2level_16k(user_pgd, uvaddr, paddr, verbose); case VM_L3_16K: return arm64_vtop_3level_16k(user_pgd, uvaddr, paddr, verbose); case VM_L4_16K: return arm64_vtop_4level_16k(user_pgd, uvaddr, paddr, verbose); default: return FALSE; } } #define PTE_ADDR_LOW ((((1UL) << (48 - machdep->pageshift)) - 1) << machdep->pageshift) #define PTE_ADDR_HIGH ((0xfUL) << 12) #define PTE_ADDR_HIGH_SHIFT 36 #define PTE_TO_PHYS(pteval) (machdep->max_physmem_bits == 52 ? \ (((pteval & PTE_ADDR_LOW) | ((pteval & PTE_ADDR_HIGH) << PTE_ADDR_HIGH_SHIFT))) : (pteval & PTE_ADDR_LOW)) #define PUD_TYPE_MASK 3 #define PUD_TYPE_SECT 1 #define PMD_TYPE_MASK 3 #define PMD_TYPE_SECT 1 #define PMD_TYPE_TABLE 2 #define SECTION_PAGE_MASK_2MB ((long)(~((MEGABYTES(2))-1))) #define SECTION_PAGE_MASK_32MB ((long)(~((MEGABYTES(32))-1))) #define SECTION_PAGE_MASK_512MB ((long)(~((MEGABYTES(512))-1))) #define SECTION_PAGE_MASK_1GB ((long)(~((GIGABYTES(1))-1))) #define SECTION_PAGE_MASK_64GB ((long)(~((GIGABYTES(64))-1))) static int arm64_vtop_2level_64k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) { ulong *pgd_base, *pgd_ptr, pgd_val; ulong *pte_base, *pte_ptr, pte_val; if (verbose) fprintf(fp, "PAGE DIRECTORY: %lx\n", pgd); pgd_base = (ulong *)pgd; FILL_PGD(pgd_base, KVADDR, machdep->ptrs_per_pgd * sizeof(ulong)); pgd_ptr = pgd_base + (((vaddr) >> PGDIR_SHIFT_L2_64K) & (machdep->ptrs_per_pgd - 1)); pgd_val = ULONG(machdep->pgd + PAGEOFFSET(pgd_ptr)); if (verbose) fprintf(fp, " PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val); if (!pgd_val) goto no_page; /* * #define __PAGETABLE_PUD_FOLDED * #define __PAGETABLE_PMD_FOLDED */ if ((pgd_val & PMD_TYPE_MASK) == PMD_TYPE_SECT) { ulong sectionbase = PTE_TO_PHYS(pgd_val & SECTION_PAGE_MASK_512MB); if (verbose) { fprintf(fp, " PAGE: %lx (512MB%s)\n\n", sectionbase, IS_ZEROPAGE(sectionbase) ? ", ZERO PAGE" : ""); arm64_translate_pte(pgd_val, 0, 0); } *paddr = sectionbase + (vaddr & ~SECTION_PAGE_MASK_512MB); return TRUE; } pte_base = (ulong *)PTOV(PTE_TO_PHYS(pgd_val)); FILL_PTBL(pte_base, KVADDR, PTRS_PER_PTE_L2_64K * sizeof(ulong)); pte_ptr = pte_base + (((vaddr) >> machdep->pageshift) & (PTRS_PER_PTE_L2_64K - 1)); pte_val = ULONG(machdep->ptbl + PAGEOFFSET(pte_ptr)); if (verbose) fprintf(fp, " PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val); if (!pte_val) goto no_page; if (pte_val & PTE_VALID) { *paddr = PTE_TO_PHYS(pte_val) + PAGEOFFSET(vaddr); if (verbose) { fprintf(fp, " PAGE: %lx %s\n\n", PAGEBASE(*paddr), IS_ZEROPAGE(PAGEBASE(*paddr)) ? "(ZERO PAGE)" : ""); arm64_translate_pte(pte_val, 0, 0); } } else { if (IS_UVADDR(vaddr, NULL)) *paddr = pte_val; if (verbose) { fprintf(fp, "\n"); arm64_translate_pte(pte_val, 0, 0); } goto no_page; } return TRUE; no_page: return FALSE; } static int arm64_vtop_3level_64k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) { ulong *pgd_base, *pgd_ptr, pgd_val; ulong *pmd_base, *pmd_ptr, pmd_val; ulong *pte_base, *pte_ptr, pte_val; if (verbose) fprintf(fp, "PAGE DIRECTORY: %lx\n", pgd); pgd_base = (ulong *)pgd; FILL_PGD(pgd_base, KVADDR, machdep->ptrs_per_pgd * sizeof(ulong)); /* * Use machdep->ptrs_per_pgd to mask vaddr instead of using macro, because * 48-bits and 52-bits have different size of ptrs_per_pgd. */ pgd_ptr = pgd_base + (((vaddr) >> PGDIR_SHIFT_L3_64K) & (machdep->ptrs_per_pgd - 1)); pgd_val = ULONG(machdep->pgd + PGDIR_OFFSET_L3_64K(pgd_ptr)); if (verbose) fprintf(fp, " PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val); if (!pgd_val) goto no_page; /* * #define __PAGETABLE_PUD_FOLDED */ pmd_base = (ulong *)PTOV(PTE_TO_PHYS(pgd_val)); FILL_PMD(pmd_base, KVADDR, PTRS_PER_PMD_L3_64K * sizeof(ulong)); pmd_ptr = pmd_base + (((vaddr) >> PMD_SHIFT_L3_64K) & (PTRS_PER_PMD_L3_64K - 1)); pmd_val = ULONG(machdep->pmd + PAGEOFFSET(pmd_ptr)); if (verbose) fprintf(fp, " PMD: %lx => %lx\n", (ulong)pmd_ptr, pmd_val); if (!pmd_val) goto no_page; if ((pmd_val & PMD_TYPE_MASK) == PMD_TYPE_SECT) { ulong sectionbase = PTE_TO_PHYS(pmd_val & SECTION_PAGE_MASK_512MB); if (verbose) { fprintf(fp, " PAGE: %lx (512MB%s)\n\n", sectionbase, IS_ZEROPAGE(sectionbase) ? ", ZERO PAGE" : ""); arm64_translate_pte(pmd_val, 0, 0); } *paddr = sectionbase + (vaddr & ~SECTION_PAGE_MASK_512MB); return TRUE; } pte_base = (ulong *)PTOV(PTE_TO_PHYS(pmd_val)); FILL_PTBL(pte_base, KVADDR, PTRS_PER_PTE_L3_64K * sizeof(ulong)); pte_ptr = pte_base + (((vaddr) >> machdep->pageshift) & (PTRS_PER_PTE_L3_64K - 1)); pte_val = ULONG(machdep->ptbl + PAGEOFFSET(pte_ptr)); if (verbose) fprintf(fp, " PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val); if (!pte_val) goto no_page; if (pte_val & PTE_VALID) { *paddr = PTE_TO_PHYS(pte_val) + PAGEOFFSET(vaddr); if (verbose) { fprintf(fp, " PAGE: %lx %s\n\n", PAGEBASE(*paddr), IS_ZEROPAGE(PAGEBASE(*paddr)) ? "(ZERO PAGE)" : ""); arm64_translate_pte(pte_val, 0, 0); } } else { if (IS_UVADDR(vaddr, NULL)) *paddr = pte_val; if (verbose) { fprintf(fp, "\n"); arm64_translate_pte(pte_val, 0, 0); } goto no_page; } return TRUE; no_page: return FALSE; } static int arm64_vtop_2level_16k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) { ulong *pgd_base, *pgd_ptr, pgd_val; ulong *pte_base, *pte_ptr, pte_val; if (verbose) fprintf(fp, "PAGE DIRECTORY: %lx\n", pgd); pgd_base = (ulong *)pgd; FILL_PGD(pgd_base, KVADDR, machdep->ptrs_per_pgd * sizeof(ulong)); pgd_ptr = pgd_base + (((vaddr) >> PGDIR_SHIFT_L2_16K) & (machdep->ptrs_per_pgd - 1)); pgd_val = ULONG(machdep->pgd + PGDIR_OFFSET_L2_16K(pgd_ptr)); if (verbose) fprintf(fp, " PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val); if (!pgd_val) goto no_page; /* * #define __PAGETABLE_PUD_FOLDED * #define __PAGETABLE_PMD_FOLDED */ if ((pgd_val & PMD_TYPE_MASK) == PMD_TYPE_SECT) { ulong sectionbase = PTE_TO_PHYS(pgd_val & SECTION_PAGE_MASK_32MB); if (verbose) { fprintf(fp, " PAGE: %lx (32MB%s)\n\n", sectionbase, IS_ZEROPAGE(sectionbase) ? ", ZERO PAGE" : ""); arm64_translate_pte(pgd_val, 0, 0); } *paddr = sectionbase + (vaddr & ~SECTION_PAGE_MASK_32MB); return TRUE; } pte_base = (ulong *)PTOV(PTE_TO_PHYS(pgd_val)); FILL_PTBL(pte_base, KVADDR, PTRS_PER_PTE_L2_16K * sizeof(ulong)); pte_ptr = pte_base + (((vaddr) >> machdep->pageshift) & (PTRS_PER_PTE_L2_16K - 1)); pte_val = ULONG(machdep->ptbl + PAGEOFFSET(pte_ptr)); if (verbose) fprintf(fp, " PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val); if (!pte_val) goto no_page; if (pte_val & PTE_VALID) { *paddr = PTE_TO_PHYS(pte_val) + PAGEOFFSET(vaddr); if (verbose) { fprintf(fp, " PAGE: %lx %s\n\n", PAGEBASE(*paddr), IS_ZEROPAGE(PAGEBASE(*paddr)) ? "(ZERO PAGE)" : ""); arm64_translate_pte(pte_val, 0, 0); } } else { if (IS_UVADDR(vaddr, NULL)) *paddr = pte_val; if (verbose) { fprintf(fp, "\n"); arm64_translate_pte(pte_val, 0, 0); } goto no_page; } return TRUE; no_page: return FALSE; } static int arm64_vtop_3level_16k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) { ulong *pgd_base, *pgd_ptr, pgd_val; ulong *pmd_base, *pmd_ptr, pmd_val; ulong *pte_base, *pte_ptr, pte_val; if (verbose) fprintf(fp, "PAGE DIRECTORY: %lx\n", pgd); pgd_base = (ulong *)pgd; FILL_PGD(pgd_base, KVADDR, machdep->ptrs_per_pgd * sizeof(ulong)); pgd_ptr = pgd_base + (((vaddr) >> PGDIR_SHIFT_L3_16K) & (machdep->ptrs_per_pgd - 1)); pgd_val = ULONG(machdep->pgd + PGDIR_OFFSET_L3_16K(pgd_ptr)); if (verbose) fprintf(fp, " PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val); if (!pgd_val) goto no_page; /* * #define __PAGETABLE_PUD_FOLDED */ pmd_base = (ulong *)PTOV(PTE_TO_PHYS(pgd_val)); FILL_PMD(pmd_base, KVADDR, PTRS_PER_PMD_L3_16K * sizeof(ulong)); pmd_ptr = pmd_base + (((vaddr) >> PMD_SHIFT_L3_16K) & (PTRS_PER_PMD_L3_16K - 1)); pmd_val = ULONG(machdep->pmd + PAGEOFFSET(pmd_ptr)); if (verbose) fprintf(fp, " PMD: %lx => %lx\n", (ulong)pmd_ptr, pmd_val); if (!pmd_val) goto no_page; if ((pmd_val & PMD_TYPE_MASK) == PMD_TYPE_SECT) { ulong sectionbase = PTE_TO_PHYS(pmd_val & SECTION_PAGE_MASK_32MB); if (verbose) { fprintf(fp, " PAGE: %lx (32MB%s)\n\n", sectionbase, IS_ZEROPAGE(sectionbase) ? ", ZERO PAGE" : ""); arm64_translate_pte(pmd_val, 0, 0); } *paddr = sectionbase + (vaddr & ~SECTION_PAGE_MASK_32MB); return TRUE; } pte_base = (ulong *)PTOV(PTE_TO_PHYS(pmd_val)); FILL_PTBL(pte_base, KVADDR, PTRS_PER_PTE_L3_16K * sizeof(ulong)); pte_ptr = pte_base + (((vaddr) >> machdep->pageshift) & (PTRS_PER_PTE_L3_16K - 1)); pte_val = ULONG(machdep->ptbl + PAGEOFFSET(pte_ptr)); if (verbose) fprintf(fp, " PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val); if (!pte_val) goto no_page; if (pte_val & PTE_VALID) { *paddr = PTE_TO_PHYS(pte_val) + PAGEOFFSET(vaddr); if (verbose) { fprintf(fp, " PAGE: %lx %s\n\n", PAGEBASE(*paddr), IS_ZEROPAGE(PAGEBASE(*paddr)) ? "(ZERO PAGE)" : ""); arm64_translate_pte(pte_val, 0, 0); } } else { if (IS_UVADDR(vaddr, NULL)) *paddr = pte_val; if (verbose) { fprintf(fp, "\n"); arm64_translate_pte(pte_val, 0, 0); } goto no_page; } return TRUE; no_page: return FALSE; } static int arm64_vtop_4level_16k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) { ulong *pgd_base, *pgd_ptr, pgd_val; ulong *pud_base, *pud_ptr, pud_val; ulong *pmd_base, *pmd_ptr, pmd_val; ulong *pte_base, *pte_ptr, pte_val; if (verbose) fprintf(fp, "PAGE DIRECTORY: %lx\n", pgd); pgd_base = (ulong *)pgd; FILL_PGD(pgd_base, KVADDR, PTRS_PER_PGD_L4_16K * sizeof(ulong)); pgd_ptr = pgd_base + (((vaddr) >> PGDIR_SHIFT_L4_16K) & (PTRS_PER_PGD_L4_16K - 1)); pgd_val = ULONG(machdep->pgd + PGDIR_OFFSET_L4_16K(pgd_ptr)); if (verbose) fprintf(fp, " PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val); if (!pgd_val) goto no_page; pud_base = (ulong *)PTOV(PTE_TO_PHYS(pgd_val)); FILL_PUD(pud_base, KVADDR, PTRS_PER_PUD_L4_16K * sizeof(ulong)); pud_ptr = pud_base + (((vaddr) >> PUD_SHIFT_L4_16K) & (PTRS_PER_PUD_L4_16K - 1)); pud_val = ULONG(machdep->pud + PAGEOFFSET(pud_ptr)); if (verbose) fprintf(fp, " PUD: %lx => %lx\n", (ulong)pud_ptr, pud_val); if (!pud_val) goto no_page; /* * TODO: * PUD Section mapping is only supported for LPA2 is enabled. * LPA2 depends on CONFIG_ARM64_16K_PAGES and CONFIG_ARM64_PA_BITS_52. */ pmd_base = (ulong *)PTOV(PTE_TO_PHYS(pud_val)); FILL_PMD(pmd_base, KVADDR, PTRS_PER_PMD_L4_16K * sizeof(ulong)); pmd_ptr = pmd_base + (((vaddr) >> PMD_SHIFT_L4_16K) & (PTRS_PER_PMD_L4_16K - 1)); pmd_val = ULONG(machdep->pmd + PAGEOFFSET(pmd_ptr)); if (verbose) fprintf(fp, " PMD: %lx => %lx\n", (ulong)pmd_ptr, pmd_val); if (!pmd_val) goto no_page; if ((pmd_val & PMD_TYPE_MASK) == PMD_TYPE_SECT) { ulong sectionbase = PTE_TO_PHYS(pmd_val) & SECTION_PAGE_MASK_32MB; if (verbose) { fprintf(fp, " PAGE: %lx (32MB%s)\n\n", sectionbase, IS_ZEROPAGE(sectionbase) ? ", ZERO PAGE" : ""); arm64_translate_pte(pmd_val, 0, 0); } *paddr = sectionbase + (vaddr & ~SECTION_PAGE_MASK_32MB); return TRUE; } pte_base = (ulong *)PTOV(PTE_TO_PHYS(pmd_val)); FILL_PTBL(pte_base, KVADDR, PTRS_PER_PTE_L4_16K * sizeof(ulong)); pte_ptr = pte_base + (((vaddr) >> machdep->pageshift) & (PTRS_PER_PTE_L4_16K - 1)); pte_val = ULONG(machdep->ptbl + PAGEOFFSET(pte_ptr)); if (verbose) fprintf(fp, " PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val); if (!pte_val) goto no_page; if (pte_val & PTE_VALID) { *paddr = PTE_TO_PHYS(pte_val) + PAGEOFFSET(vaddr); if (verbose) { fprintf(fp, " PAGE: %lx %s\n\n", PAGEBASE(*paddr), IS_ZEROPAGE(PAGEBASE(*paddr)) ? "(ZERO PAGE)" : ""); arm64_translate_pte(pte_val, 0, 0); } } else { if (IS_UVADDR(vaddr, NULL)) *paddr = pte_val; if (verbose) { fprintf(fp, "\n"); arm64_translate_pte(pte_val, 0, 0); } goto no_page; } return TRUE; no_page: return FALSE; } static int arm64_vtop_3level_4k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) { ulong *pgd_base, *pgd_ptr, pgd_val; ulong *pmd_base, *pmd_ptr, pmd_val; ulong *pte_base, *pte_ptr, pte_val; if (verbose) fprintf(fp, "PAGE DIRECTORY: %lx\n", pgd); pgd_base = (ulong *)pgd; FILL_PGD(pgd_base, KVADDR, PTRS_PER_PGD_L3_4K * sizeof(ulong)); pgd_ptr = pgd_base + (((vaddr) >> PGDIR_SHIFT_L3_4K) & (PTRS_PER_PGD_L3_4K - 1)); pgd_val = ULONG(machdep->pgd + PAGEOFFSET(pgd_ptr)); if (verbose) fprintf(fp, " PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val); if (!pgd_val) goto no_page; if ((pgd_val & PUD_TYPE_MASK) == PUD_TYPE_SECT) { ulong sectionbase = PTE_TO_PHYS(pgd_val & SECTION_PAGE_MASK_1GB); if (verbose) { fprintf(fp, " PAGE: %lx (1GB)\n\n", sectionbase); arm64_translate_pte(pgd_val, 0, 0); } *paddr = sectionbase + (vaddr & ~SECTION_PAGE_MASK_1GB); return TRUE; } /* * #define __PAGETABLE_PUD_FOLDED */ pmd_base = (ulong *)PTOV(PTE_TO_PHYS(pgd_val)); FILL_PMD(pmd_base, KVADDR, PTRS_PER_PMD_L3_4K * sizeof(ulong)); pmd_ptr = pmd_base + (((vaddr) >> PMD_SHIFT_L3_4K) & (PTRS_PER_PMD_L3_4K - 1)); pmd_val = ULONG(machdep->pmd + PAGEOFFSET(pmd_ptr)); if (verbose) fprintf(fp, " PMD: %lx => %lx\n", (ulong)pmd_ptr, pmd_val); if (!pmd_val) goto no_page; if ((pmd_val & PMD_TYPE_MASK) == PMD_TYPE_SECT) { ulong sectionbase = PTE_TO_PHYS(pmd_val & SECTION_PAGE_MASK_2MB); if (verbose) { fprintf(fp, " PAGE: %lx (2MB%s)\n\n", sectionbase, IS_ZEROPAGE(sectionbase) ? ", ZERO PAGE" : ""); arm64_translate_pte(pmd_val, 0, 0); } *paddr = sectionbase + (vaddr & ~SECTION_PAGE_MASK_2MB); return TRUE; } pte_base = (ulong *)PTOV(PTE_TO_PHYS(pmd_val)); FILL_PTBL(pte_base, KVADDR, PTRS_PER_PTE_L3_4K * sizeof(ulong)); pte_ptr = pte_base + (((vaddr) >> machdep->pageshift) & (PTRS_PER_PTE_L3_4K - 1)); pte_val = ULONG(machdep->ptbl + PAGEOFFSET(pte_ptr)); if (verbose) fprintf(fp, " PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val); if (!pte_val) goto no_page; if (pte_val & PTE_VALID) { *paddr = PTE_TO_PHYS(pte_val) + PAGEOFFSET(vaddr); if (verbose) { fprintf(fp, " PAGE: %lx %s\n\n", PAGEBASE(*paddr), IS_ZEROPAGE(PAGEBASE(*paddr)) ? "(ZERO PAGE)" : ""); arm64_translate_pte(pte_val, 0, 0); } } else { if (IS_UVADDR(vaddr, NULL)) *paddr = pte_val; if (verbose) { fprintf(fp, "\n"); arm64_translate_pte(pte_val, 0, 0); } goto no_page; } return TRUE; no_page: return FALSE; } static int arm64_vtop_4level_4k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) { ulong *pgd_base, *pgd_ptr, pgd_val; ulong *pud_base, *pud_ptr, pud_val; ulong *pmd_base, *pmd_ptr, pmd_val; ulong *pte_base, *pte_ptr, pte_val; if (verbose) fprintf(fp, "PAGE DIRECTORY: %lx\n", pgd); pgd_base = (ulong *)pgd; FILL_PGD(pgd_base, KVADDR, PTRS_PER_PGD_L4_4K * sizeof(ulong)); pgd_ptr = pgd_base + (((vaddr) >> PGDIR_SHIFT_L4_4K) & (PTRS_PER_PGD_L4_4K - 1)); pgd_val = ULONG(machdep->pgd + PGDIR_OFFSET_48VA(pgd_ptr)); if (verbose) fprintf(fp, " PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val); if (!pgd_val) goto no_page; pud_base = (ulong *)PTOV(PTE_TO_PHYS(pgd_val)); FILL_PUD(pud_base, KVADDR, PTRS_PER_PUD_L4_4K * sizeof(ulong)); pud_ptr = pud_base + (((vaddr) >> PUD_SHIFT_L4_4K) & (PTRS_PER_PUD_L4_4K - 1)); pud_val = ULONG(machdep->pud + PAGEOFFSET(pud_ptr)); if (verbose) fprintf(fp, " PUD: %lx => %lx\n", (ulong)pud_ptr, pud_val); if (!pud_val) goto no_page; if ((pud_val & PUD_TYPE_MASK) == PUD_TYPE_SECT) { ulong sectionbase = PTE_TO_PHYS(pud_val & SECTION_PAGE_MASK_1GB); if (verbose) { fprintf(fp, " PAGE: %lx (1GB)\n\n", sectionbase); arm64_translate_pte(pud_val, 0, 0); } *paddr = sectionbase + (vaddr & ~SECTION_PAGE_MASK_1GB); return TRUE; } pmd_base = (ulong *)PTOV(PTE_TO_PHYS(pud_val)); FILL_PMD(pmd_base, KVADDR, PTRS_PER_PMD_L4_4K * sizeof(ulong)); pmd_ptr = pmd_base + (((vaddr) >> PMD_SHIFT_L4_4K) & (PTRS_PER_PMD_L4_4K - 1)); pmd_val = ULONG(machdep->pmd + PAGEOFFSET(pmd_ptr)); if (verbose) fprintf(fp, " PMD: %lx => %lx\n", (ulong)pmd_ptr, pmd_val); if (!pmd_val) goto no_page; if ((pmd_val & PMD_TYPE_MASK) == PMD_TYPE_SECT) { ulong sectionbase = PTE_TO_PHYS(pmd_val & SECTION_PAGE_MASK_2MB); if (verbose) { fprintf(fp, " PAGE: %lx (2MB%s)\n\n", sectionbase, IS_ZEROPAGE(sectionbase) ? ", ZERO PAGE" : ""); arm64_translate_pte(pmd_val, 0, 0); } *paddr = sectionbase + (vaddr & ~SECTION_PAGE_MASK_2MB); return TRUE; } pte_base = (ulong *)PTOV(PTE_TO_PHYS(pmd_val)); FILL_PTBL(pte_base, KVADDR, PTRS_PER_PTE_L4_4K * sizeof(ulong)); pte_ptr = pte_base + (((vaddr) >> machdep->pageshift) & (PTRS_PER_PTE_L4_4K - 1)); pte_val = ULONG(machdep->ptbl + PAGEOFFSET(pte_ptr)); if (verbose) fprintf(fp, " PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val); if (!pte_val) goto no_page; if (pte_val & PTE_VALID) { *paddr = PTE_TO_PHYS(pte_val) + PAGEOFFSET(vaddr); if (verbose) { fprintf(fp, " PAGE: %lx %s\n\n", PAGEBASE(*paddr), IS_ZEROPAGE(PAGEBASE(*paddr)) ? "(ZERO PAGE)" : ""); arm64_translate_pte(pte_val, 0, 0); } } else { if (IS_UVADDR(vaddr, NULL)) *paddr = pte_val; if (verbose) { fprintf(fp, "\n"); arm64_translate_pte(pte_val, 0, 0); } goto no_page; } return TRUE; no_page: return FALSE; } static ulong arm64_get_task_pgd(ulong task) { struct task_context *tc; ulong pgd; if ((tc = task_to_context(task)) && readmem(tc->mm_struct + OFFSET(mm_struct_pgd), KVADDR, &pgd, sizeof(long), "user pgd", RETURN_ON_ERROR)) return pgd; else return NO_TASK; } static ulong arm64_processor_speed(void) { return 0; }; /* * Gather IRQ stack values. */ static void arm64_irq_stack_init(void) { int i; struct syment *sp; struct gnu_request request, *req; struct machine_specific *ms = machdep->machspec; ulong p, sz; req = &request; if (symbol_exists("irq_stack") && (sp = per_cpu_symbol_search("irq_stack")) && get_symbol_type("irq_stack", NULL, req)) { /* before v4.14 or CONFIG_VMAP_STACK disabled */ if (CRASHDEBUG(1)) { fprintf(fp, "irq_stack: \n"); fprintf(fp, " type: %s\n", (req->typecode == TYPE_CODE_ARRAY) ? "TYPE_CODE_ARRAY" : "other"); fprintf(fp, " target_typecode: %s\n", req->target_typecode == TYPE_CODE_INT ? "TYPE_CODE_INT" : "other"); fprintf(fp, " target_length: %ld\n", req->target_length); fprintf(fp, " length: %ld\n", req->length); } if (!(ms->irq_stacks = (ulong *)malloc((size_t)(kt->cpus * sizeof(ulong))))) error(FATAL, "cannot malloc irq_stack addresses\n"); ms->irq_stack_size = req->length; machdep->flags |= IRQ_STACKS; for (i = 0; i < kt->cpus; i++) ms->irq_stacks[i] = kt->__per_cpu_offset[i] + sp->value; } else if (symbol_exists("irq_stack_ptr") && (sp = per_cpu_symbol_search("irq_stack_ptr")) && get_symbol_type("irq_stack_ptr", NULL, req)) { /* v4.14 and later with CONFIG_VMAP_STACK enabled */ if (CRASHDEBUG(1)) { fprintf(fp, "irq_stack_ptr: \n"); fprintf(fp, " type: %x, %s\n", (int)req->typecode, (req->typecode == TYPE_CODE_PTR) ? "TYPE_CODE_PTR" : "other"); fprintf(fp, " target_typecode: %x, %s\n", (int)req->target_typecode, req->target_typecode == TYPE_CODE_INT ? "TYPE_CODE_INT" : "other"); fprintf(fp, " target_length: %ld\n", req->target_length); fprintf(fp, " length: %ld\n", req->length); } if (!(ms->irq_stacks = (ulong *)malloc((size_t)(kt->cpus * sizeof(ulong))))) error(FATAL, "cannot malloc irq_stack addresses\n"); /* * Determining the IRQ_STACK_SIZE is tricky, but for now * 4.14 kernel has: * * #define IRQ_STACK_SIZE THREAD_SIZE * * and finding a solid usage of THREAD_SIZE is hard, but: * * union thread_union { * ... * unsigned long stack[THREAD_SIZE/sizeof(long)]; * }; */ if (MEMBER_EXISTS("thread_union", "stack")) { if ((sz = MEMBER_SIZE("thread_union", "stack")) > 0) ms->irq_stack_size = sz; } else { ulong res = arm64_set_irq_stack_size(); ms->irq_stack_size = (res > 0) ? res : ARM64_IRQ_STACK_SIZE; } machdep->flags |= IRQ_STACKS; for (i = 0; i < kt->cpus; i++) { p = kt->__per_cpu_offset[i] + sp->value; readmem(p, KVADDR, &(ms->irq_stacks[i]), sizeof(ulong), "IRQ stack pointer", RETURN_ON_ERROR); } } } /* * Gather Overflow stack values. * * Overflow stack supported since 4.14, in commit 872d8327c */ static void arm64_overflow_stack_init(void) { int i; struct syment *sp; struct gnu_request request, *req; struct machine_specific *ms = machdep->machspec; req = &request; if (symbol_exists("overflow_stack") && (sp = per_cpu_symbol_search("overflow_stack")) && get_symbol_type("overflow_stack", NULL, req)) { if (CRASHDEBUG(1)) { fprintf(fp, "overflow_stack: \n"); fprintf(fp, " type: %x, %s\n", (int)req->typecode, (req->typecode == TYPE_CODE_ARRAY) ? "TYPE_CODE_ARRAY" : "other"); fprintf(fp, " target_typecode: %x, %s\n", (int)req->target_typecode, req->target_typecode == TYPE_CODE_INT ? "TYPE_CODE_INT" : "other"); fprintf(fp, " target_length: %ld\n", req->target_length); fprintf(fp, " length: %ld\n", req->length); } if (!(ms->overflow_stacks = (ulong *)malloc((size_t)(kt->cpus * sizeof(ulong))))) error(FATAL, "cannot malloc overflow_stack addresses\n"); ms->overflow_stack_size = ARM64_OVERFLOW_STACK_SIZE; machdep->flags |= OVERFLOW_STACKS; for (i = 0; i < kt->cpus; i++) ms->overflow_stacks[i] = kt->__per_cpu_offset[i] + sp->value; } } /* * Gather and verify all of the backtrace requirements. */ static void arm64_stackframe_init(void) { long task_struct_thread; long thread_struct_cpu_context; long context_sp, context_pc, context_fp; long context_x19, context_x20, context_x21, context_x22; long context_x23, context_x24, context_x25, context_x26; long context_x27, context_x28; struct syment *sp1, *sp1n, *sp2, *sp2n, *sp3, *sp3n; STRUCT_SIZE_INIT(note_buf, "note_buf_t"); STRUCT_SIZE_INIT(elf_prstatus, "elf_prstatus"); MEMBER_OFFSET_INIT(elf_prstatus_pr_pid, "elf_prstatus", "pr_pid"); MEMBER_OFFSET_INIT(elf_prstatus_pr_reg, "elf_prstatus", "pr_reg"); if (MEMBER_EXISTS("pt_regs", "stackframe")) { machdep->machspec->user_eframe_offset = SIZE(pt_regs); machdep->machspec->kern_eframe_offset = SIZE(pt_regs) - 16; } else { machdep->machspec->user_eframe_offset = SIZE(pt_regs) + 16; machdep->machspec->kern_eframe_offset = SIZE(pt_regs); } if ((sp1 = kernel_symbol_search("__exception_text_start")) && (sp2 = kernel_symbol_search("__exception_text_end"))) { machdep->machspec->__exception_text_start = sp1->value; machdep->machspec->__exception_text_end = sp2->value; } if ((sp1 = kernel_symbol_search("__irqentry_text_start")) && (sp2 = kernel_symbol_search("__irqentry_text_end"))) { machdep->machspec->__irqentry_text_start = sp1->value; machdep->machspec->__irqentry_text_end = sp2->value; } if ((sp1 = kernel_symbol_search("vectors")) && (sp1n = kernel_symbol_search("cpu_switch_to")) && (sp2 = kernel_symbol_search("ret_fast_syscall")) && (sp2n = kernel_symbol_search("sys_rt_sigreturn_wrapper"))) { machdep->machspec->exp_entry1_start = sp1->value; machdep->machspec->exp_entry1_end = sp1n->value; machdep->machspec->exp_entry2_start = sp2->value; machdep->machspec->exp_entry2_end = sp2n->value; } if ((sp1 = kernel_symbol_search("crash_kexec")) && (sp1n = next_symbol(NULL, sp1)) && (sp2 = kernel_symbol_search("crash_save_cpu")) && (sp2n = next_symbol(NULL, sp2)) && (sp3 = kernel_symbol_search("machine_kexec")) && (sp3n = next_symbol(NULL, sp3))) { machdep->machspec->crash_kexec_start = sp1->value; machdep->machspec->crash_kexec_end = sp1n->value; machdep->machspec->crash_save_cpu_start = sp2->value; machdep->machspec->crash_save_cpu_end = sp2n->value; machdep->machspec->machine_kexec_start = sp3->value; machdep->machspec->machine_kexec_end = sp3n->value; machdep->flags |= KDUMP_ENABLED; } task_struct_thread = MEMBER_OFFSET("task_struct", "thread"); thread_struct_cpu_context = MEMBER_OFFSET("thread_struct", "cpu_context"); if ((task_struct_thread == INVALID_OFFSET) || (thread_struct_cpu_context == INVALID_OFFSET)) { error(INFO, "cannot determine task_struct.thread.context offset\n"); return; } /* * Pay for the convenience of using a hardcopy of a kernel structure. */ if (offsetof(struct arm64_stackframe, sp) != MEMBER_OFFSET("stackframe", "sp")) { if (CRASHDEBUG(1)) error(INFO, "builtin stackframe.sp offset differs from kernel version\n"); } if (offsetof(struct arm64_stackframe, fp) != MEMBER_OFFSET("stackframe", "fp")) { if (CRASHDEBUG(1)) error(INFO, "builtin stackframe.fp offset differs from kernel version\n"); } if (offsetof(struct arm64_stackframe, pc) != MEMBER_OFFSET("stackframe", "pc")) { if (CRASHDEBUG(1)) error(INFO, "builtin stackframe.pc offset differs from kernel version\n"); } if (!MEMBER_EXISTS("stackframe", "sp")) machdep->flags |= UNW_4_14; context_sp = MEMBER_OFFSET("cpu_context", "sp"); context_fp = MEMBER_OFFSET("cpu_context", "fp"); context_pc = MEMBER_OFFSET("cpu_context", "pc"); context_x19 = MEMBER_OFFSET("cpu_context", "x19"); context_x20 = MEMBER_OFFSET("cpu_context", "x20"); context_x21 = MEMBER_OFFSET("cpu_context", "x21"); context_x22 = MEMBER_OFFSET("cpu_context", "x22"); context_x23 = MEMBER_OFFSET("cpu_context", "x23"); context_x24 = MEMBER_OFFSET("cpu_context", "x24"); context_x25 = MEMBER_OFFSET("cpu_context", "x25"); context_x26 = MEMBER_OFFSET("cpu_context", "x26"); context_x27 = MEMBER_OFFSET("cpu_context", "x27"); context_x28 = MEMBER_OFFSET("cpu_context", "x28"); if (context_sp == INVALID_OFFSET) { error(INFO, "cannot determine cpu_context.sp offset\n"); return; } if (context_fp == INVALID_OFFSET) { error(INFO, "cannot determine cpu_context.fp offset\n"); return; } if (context_pc == INVALID_OFFSET) { error(INFO, "cannot determine cpu_context.pc offset\n"); return; } ASSIGN_OFFSET(task_struct_thread_context_sp) = task_struct_thread + thread_struct_cpu_context + context_sp; ASSIGN_OFFSET(task_struct_thread_context_fp) = task_struct_thread + thread_struct_cpu_context + context_fp; ASSIGN_OFFSET(task_struct_thread_context_pc) = task_struct_thread + thread_struct_cpu_context + context_pc; ASSIGN_OFFSET(task_struct_thread_context_x19) = task_struct_thread + thread_struct_cpu_context + context_x19; ASSIGN_OFFSET(task_struct_thread_context_x20) = task_struct_thread + thread_struct_cpu_context + context_x20; ASSIGN_OFFSET(task_struct_thread_context_x21) = task_struct_thread + thread_struct_cpu_context + context_x21; ASSIGN_OFFSET(task_struct_thread_context_x22) = task_struct_thread + thread_struct_cpu_context + context_x22; ASSIGN_OFFSET(task_struct_thread_context_x23) = task_struct_thread + thread_struct_cpu_context + context_x23; ASSIGN_OFFSET(task_struct_thread_context_x24) = task_struct_thread + thread_struct_cpu_context + context_x24; ASSIGN_OFFSET(task_struct_thread_context_x25) = task_struct_thread + thread_struct_cpu_context + context_x25; ASSIGN_OFFSET(task_struct_thread_context_x26) = task_struct_thread + thread_struct_cpu_context + context_x26; ASSIGN_OFFSET(task_struct_thread_context_x27) = task_struct_thread + thread_struct_cpu_context + context_x27; ASSIGN_OFFSET(task_struct_thread_context_x28) = task_struct_thread + thread_struct_cpu_context + context_x28; } #define KERNEL_MODE (1) #define USER_MODE (2) #define USER_EFRAME_OFFSET (machdep->machspec->user_eframe_offset) #define KERN_EFRAME_OFFSET (machdep->machspec->kern_eframe_offset) /* * PSR bits */ #define PSR_MODE_EL0t 0x00000000 #define PSR_MODE_EL1t 0x00000004 #define PSR_MODE_EL1h 0x00000005 #define PSR_MODE_EL2t 0x00000008 #define PSR_MODE_EL2h 0x00000009 #define PSR_MODE_EL3t 0x0000000c #define PSR_MODE_EL3h 0x0000000d #define PSR_MODE_MASK 0x0000000f /* Architecturally defined mapping between AArch32 and AArch64 registers */ #define compat_usr(x) regs[(x)] #define compat_fp regs[11] #define compat_sp regs[13] #define compat_lr regs[14] #define user_mode(ptregs) \ (((ptregs)->pstate & PSR_MODE_MASK) == PSR_MODE_EL0t) #define compat_user_mode(ptregs) \ (((ptregs)->pstate & (PSR_MODE32_BIT | PSR_MODE_MASK)) == \ (PSR_MODE32_BIT | PSR_MODE_EL0t)) #define user_stack_pointer(ptregs) \ (!compat_user_mode(ptregs) ? (ptregs)->sp : (ptregs)->compat_sp) #define user_frame_pointer(ptregs) \ (!compat_user_mode(ptregs) ? (ptregs)->regs[29] : (ptregs)->compat_fp) static int arm64_is_kernel_exception_frame(struct bt_info *bt, ulong stkptr) { struct arm64_pt_regs *regs; struct machine_specific *ms = machdep->machspec; if (stkptr > STACKSIZE() && !INSTACK(stkptr, bt)) { if (CRASHDEBUG(1)) error(WARNING, "stkptr: %lx is outside the kernel stack range\n", stkptr); return FALSE; } regs = (struct arm64_pt_regs *)&bt->stackbuf[(ulong)(STACK_OFFSET_TYPE(stkptr))]; if (INSTACK(regs->sp, bt) && INSTACK(regs->regs[29], bt) && !(regs->pstate & (0xffffffff00000000ULL | PSR_MODE32_BIT)) && is_kernel_text(regs->pc) && is_kernel_text(regs->regs[30] | ms->CONFIG_ARM64_KERNELPACMASK)) { switch (regs->pstate & PSR_MODE_MASK) { case PSR_MODE_EL1t: case PSR_MODE_EL1h: case PSR_MODE_EL2t: case PSR_MODE_EL2h: return TRUE; } } return FALSE; } static int arm64_eframe_search(struct bt_info *bt) { int c; ulong ptr, count; struct machine_specific *ms; if (bt->flags & BT_EFRAME_SEARCH2) { if (!(machdep->flags & IRQ_STACKS)) error(FATAL, "IRQ stacks do not exist in this kernel\n"); ms = machdep->machspec; for (c = 0; c < kt->cpus; c++) { if ((bt->flags & BT_CPUMASK) && !(NUM_IN_BITMAP(bt->cpumask, c))) continue; fprintf(fp, "CPU %d IRQ STACK:", c); bt->stackbase = ms->irq_stacks[c]; bt->stacktop = bt->stackbase + ms->irq_stack_size; alter_stackbuf(bt); count = 0; for (ptr = bt->stackbase; ptr < bt->stacktop - SIZE(pt_regs); ptr++) { if (arm64_is_kernel_exception_frame(bt, ptr)) { fprintf(fp, "%s\nKERNEL-MODE EXCEPTION FRAME AT: %lx\n", count ? "" : "\n", ptr); arm64_print_exception_frame(bt, ptr, KERNEL_MODE, fp); count++; } } if (count) fprintf(fp, "\n"); else fprintf(fp, "(none found)\n\n"); } return 0; } count = 0; for (ptr = bt->stackbase; ptr < bt->stacktop - SIZE(pt_regs); ptr++) { if (arm64_is_kernel_exception_frame(bt, ptr)) { fprintf(fp, "\nKERNEL-MODE EXCEPTION FRAME AT: %lx\n", ptr); arm64_print_exception_frame(bt, ptr, KERNEL_MODE, fp); count++; } } if (is_kernel_thread(bt->tc->task)) return count; ptr = bt->stacktop - USER_EFRAME_OFFSET; fprintf(fp, "%sUSER-MODE EXCEPTION FRAME AT: %lx\n", count++ ? "\n" : "", ptr); arm64_print_exception_frame(bt, ptr, USER_MODE, fp); return count; } static char *arm64_exception_functions[] = { "do_undefinstr", "do_sysinstr", "do_debug_exception", "do_mem_abort", "do_el0_irq_bp_hardening", "do_sp_pc_abort", "handle_bad_stack", NULL }; static int arm64_in_exception_text(ulong ptr) { struct machine_specific *ms = machdep->machspec; char *name, **func; if (ms->__irqentry_text_start && ms->__irqentry_text_end && ((ptr >= ms->__irqentry_text_start) && (ptr < ms->__irqentry_text_end))) return TRUE; if (ms->__exception_text_start && ms->__exception_text_end) { if ((ptr >= ms->__exception_text_start) && (ptr < ms->__exception_text_end)) return TRUE; } name = closest_symbol(ptr); if (name != NULL) { /* Linux 5.5 and later */ for (func = &arm64_exception_functions[0]; *func; func++) { if (STREQ(name, *func)) return TRUE; } } return FALSE; } static int arm64_in_exp_entry(ulong addr) { struct machine_specific *ms; ms = machdep->machspec; if ((ms->exp_entry1_start <= addr) && (addr < ms->exp_entry1_end)) return TRUE; if ((ms->exp_entry2_start <= addr) && (addr < ms->exp_entry2_end)) return TRUE; return FALSE; } #define BACKTRACE_CONTINUE (1) #define BACKTRACE_COMPLETE_KERNEL (2) #define BACKTRACE_COMPLETE_USER (3) static int arm64_print_stackframe_entry(struct bt_info *bt, int level, struct arm64_stackframe *frame, FILE *ofp) { char *name, *name_plus_offset; ulong branch_pc, symbol_offset; struct syment *sp; struct load_module *lm; char buf[BUFSIZE]; /* * if pc comes from a saved lr, it actually points to an instruction * after branch. To avoid any confusion, decrement pc by 4. * See, for example, "bl schedule" before ret_to_user(). */ branch_pc = frame->pc - 4; name = closest_symbol(branch_pc); name_plus_offset = NULL; if (bt->flags & BT_SYMBOL_OFFSET) { sp = value_search(branch_pc, &symbol_offset); if (sp && symbol_offset) name_plus_offset = value_to_symstr(branch_pc, buf, bt->radix); } if (!INSTACK(frame->fp, bt) && IN_TASK_VMA(bt->task, frame->fp)) frame->fp = 0; if (bt->flags & BT_FULL) { if (level) arm64_display_full_frame(bt, frame->fp); bt->frameptr = frame->fp; } fprintf(ofp, "%s#%d [%8lx] %s at %lx", level < 10 ? " " : "", level, frame->fp ? frame->fp : bt->stacktop - USER_EFRAME_OFFSET, name_plus_offset ? name_plus_offset : name, branch_pc); if (BT_REFERENCE_CHECK(bt)) { arm64_do_bt_reference_check(bt, frame->pc, closest_symbol(frame->pc)); arm64_do_bt_reference_check(bt, branch_pc, name); } if (module_symbol(branch_pc, NULL, &lm, NULL, 0)) fprintf(ofp, " [%s]", lm->mod_name); fprintf(ofp, "\n"); if (bt->flags & BT_LINE_NUMBERS) { get_line_number(branch_pc, buf, FALSE); if (strlen(buf)) fprintf(ofp, " %s\n", buf); } if (STREQ(name, "start_kernel") || STREQ(name, "secondary_start_kernel") || STREQ(name, "kthread") || STREQ(name, "kthreadd")) return BACKTRACE_COMPLETE_KERNEL; return BACKTRACE_CONTINUE; } static int arm64_print_stackframe_entry_v2(struct bt_info *bt, int level, struct arm64_stackframe *frame, FILE *ofp) { char *name, *name_plus_offset; ulong pc, symbol_offset; struct syment *sp; struct load_module *lm; char buf[BUFSIZE]; /* * if pc comes from a saved lr, it actually points to an instruction * after branch. To avoid any confusion, decrement pc by 4. * See, for example, "bl schedule" before ret_to_user(). */ pc = frame->pc - 0x4; name = closest_symbol(pc); name_plus_offset = NULL; if (bt->flags & BT_SYMBOL_OFFSET) { sp = value_search(pc, &symbol_offset); if (sp && symbol_offset) name_plus_offset = value_to_symstr(pc, buf, bt->radix); } if (bt->flags & BT_USER_EFRAME) frame->fp = 0; fprintf(ofp, "%s#%d [%8lx] %s at %lx", level < 10 ? " " : "", level, frame->fp ? frame->fp : bt->stacktop - USER_EFRAME_OFFSET, name_plus_offset ? name_plus_offset : name, pc); if (BT_REFERENCE_CHECK(bt)) arm64_do_bt_reference_check(bt, pc, name); if (module_symbol(pc, NULL, &lm, NULL, 0)) fprintf(ofp, " [%s]", lm->mod_name); fprintf(ofp, "\n"); if (bt->flags & BT_LINE_NUMBERS) { get_line_number(pc, buf, FALSE); if (strlen(buf)) fprintf(ofp, " %s\n", buf); } if (STREQ(name, "start_kernel") || STREQ(name, "secondary_start_kernel") || STREQ(name, "kthread") || STREQ(name, "kthreadd")) return BACKTRACE_COMPLETE_KERNEL; return BACKTRACE_CONTINUE; } static void arm64_display_full_frame(struct bt_info *bt, ulong sp) { int i, u_idx; ulong *up; ulong words, addr; char buf[BUFSIZE]; if (bt->frameptr == sp) return; if (INSTACK(bt->frameptr, bt)) { if (INSTACK(sp, bt)) { ; /* normal case */ } else { if (sp == 0) /* interrupt in user mode */ sp = bt->stacktop - USER_EFRAME_OFFSET; else /* interrupt in kernel mode */ sp = bt->stacktop; } } else { /* This is a transition case from irq to process stack. */ return; } words = (sp - bt->frameptr) / sizeof(ulong); addr = bt->frameptr; u_idx = (bt->frameptr - bt->stackbase)/sizeof(ulong); for (i = 0; i < words; i++, u_idx++) { if (!(i & 1)) fprintf(fp, "%s %lx: ", i ? "\n" : "", addr); up = (ulong *)(&bt->stackbuf[u_idx*sizeof(ulong)]); fprintf(fp, "%s ", format_stack_entry(bt, buf, *up, 0)); addr += sizeof(ulong); } fprintf(fp, "\n"); } static void arm64_display_full_frame_v2(struct bt_info *bt, struct arm64_stackframe *cur, struct arm64_stackframe *next) { struct machine_specific *ms; ulong next_fp, stackbase; char *stackbuf; int i, u_idx; ulong *up; ulong words, addr; char buf[BUFSIZE]; stackbase = bt->stackbase; stackbuf = bt->stackbuf; ms = machdep->machspec; /* Calc next fp for dump */ if (next->fp == 0) /* last stackframe on kernel tack */ next_fp = bt->stacktop - 0x10; else if (!INSTACK(cur->sp, bt)) { /* We have just switched over stacks */ next_fp = ms->irq_stacks[bt->tc->processor] + ms->irq_stack_size - 0x10; /* * We are already buffering a process stack. * So use an old buffer for IRQ stack. */ stackbase = ms->irq_stacks[bt->tc->processor]; stackbuf = ms->irq_stackbuf; } else next_fp = next->fp; if (CRASHDEBUG(1)) fprintf(fp, " frame <%016lx:%016lx>\n", cur->fp, next_fp); /* Check here because we want to see a debug message above. */ if (!(bt->flags & BT_FULL)) return; if (next_fp <= cur->fp) return; /* Dump */ words = (next_fp - cur->fp) / sizeof(ulong); addr = cur->fp; u_idx = (cur->fp - stackbase)/sizeof(ulong); for (i = 0; i < words; i++, u_idx++) { if (!(i & 1)) fprintf(fp, "%s %lx: ", i ? "\n" : "", addr); up = (ulong *)(&stackbuf[u_idx*sizeof(ulong)]); fprintf(fp, "%s ", format_stack_entry(bt, buf, *up, 0)); addr += sizeof(ulong); } fprintf(fp, "\n"); if (stackbuf == ms->irq_stackbuf) FREEBUF(stackbuf); } static int arm64_unwind_frame(struct bt_info *bt, struct arm64_stackframe *frame) { unsigned long high, low, fp; unsigned long stack_mask; unsigned long irq_stack_ptr, orig_sp; struct arm64_pt_regs *ptregs; struct machine_specific *ms = machdep->machspec; stack_mask = (unsigned long)(ARM64_STACK_SIZE) - 1; fp = frame->fp; low = frame->sp; high = (low + stack_mask) & ~(stack_mask); if (fp < low || fp > high || fp & 0xf || !INSTACK(fp, bt)) return FALSE; frame->sp = fp + 0x10; frame->fp = GET_STACK_ULONG(fp); frame->pc = GET_STACK_ULONG(fp + 8); if (is_kernel_text(frame->pc | ms->CONFIG_ARM64_KERNELPACMASK)) frame->pc |= ms->CONFIG_ARM64_KERNELPACMASK; if ((frame->fp == 0) && (frame->pc == 0)) return FALSE; if (!(machdep->flags & (IRQ_STACKS | OVERFLOW_STACKS))) return TRUE; if (machdep->flags & UNW_4_14) { if (((bt->flags & BT_IRQSTACK) && !arm64_on_irq_stack(bt->tc->processor, frame->fp)) || ((bt->flags & BT_OVERFLOW_STACK) && !arm64_on_overflow_stack(bt->tc->processor, frame->fp))) { if (arm64_on_process_stack(bt, frame->fp)) { arm64_set_process_stack(bt); frame->sp = frame->fp - KERN_EFRAME_OFFSET; /* * for switch_stack * fp still points to irq stack */ bt->bptr = fp; /* * for display_full_frame * sp points to process stack * * If we want to see pt_regs, * comment out the below. * bt->frameptr = frame->sp; */ } else { /* irq -> user */ return FALSE; } } return TRUE; } /* * The kernel's manner of determining the end of the IRQ stack: * * #define THREAD_SIZE 16384 * #define THREAD_START_SP (THREAD_SIZE - 16) * #define IRQ_STACK_START_SP THREAD_START_SP * #define IRQ_STACK_PTR(cpu) ((unsigned long)per_cpu(irq_stack, cpu) + IRQ_STACK_START_SP) * #define IRQ_STACK_TO_TASK_STACK(ptr) (*((unsigned long *)((ptr) - 0x08))) * * irq_stack_ptr = IRQ_STACK_PTR(raw_smp_processor_id()); * orig_sp = IRQ_STACK_TO_TASK_STACK(irq_stack_ptr); (pt_regs pointer on process stack) */ irq_stack_ptr = ms->irq_stacks[bt->tc->processor] + ms->irq_stack_size - 16; if (frame->sp == irq_stack_ptr) { orig_sp = GET_STACK_ULONG(irq_stack_ptr - 8); arm64_set_process_stack(bt); if (INSTACK(orig_sp, bt) && (INSTACK(frame->fp, bt) || (frame->fp == 0))) { ptregs = (struct arm64_pt_regs *)&bt->stackbuf[(ulong)(STACK_OFFSET_TYPE(orig_sp))]; frame->sp = orig_sp; frame->pc = ptregs->pc; bt->bptr = fp; if (CRASHDEBUG(1)) error(INFO, "arm64_unwind_frame: switch stacks: fp: %lx sp: %lx pc: %lx\n", frame->fp, frame->sp, frame->pc); } else { error(WARNING, "arm64_unwind_frame: on IRQ stack: oriq_sp: %lx%s fp: %lx%s\n", orig_sp, INSTACK(orig_sp, bt) ? "" : " (?)", frame->fp, INSTACK(frame->fp, bt) ? "" : " (?)"); return FALSE; } } return TRUE; } /* * The following figure shows how unwinding can be done. * Here we assume that the callstack order is: * #(X-1) ppc (previous PC) * #X cpc (current PC) * < #(X+ 1) epc (Exception entry) > * #(X+1/2) npc (Next PC) * #(X+2/3) Npc (One before Next) * #(X+3/4) NNpc (One before 'Npc') * and unwind frames from #X to #(X+1). * When we add a faked frame for exception entry (exception frame) * as #(X+1), the next frame for npc will be recognized as #(x+2). * * (1)Normal stackframe: * +------+ * | pfp | * | cpc | * psp + + * | | * | | * pfp +------+ <--- :prev stackframe = * | cfp | * | npc | * csp + + * | | * | | * cfp +------+ <--- :curr stackframe = * | nfp | cfp = *pfp * | Npc | csp = pfp + 0x10 * nsp + + * | | * | | * nfp +------+ <--- :next stackframe = * | | * * (2)Exception on the same (IRQ or process) stack: * +------+ * | pfp | * | cpc | * psp + + * | | * | | * pfp +------+ <--- :prev stackframe = * | cfp | * | npc | * csp + + * | | * | | * cfp +------+ <--- :curr stackframe = * | nfp | * | epc | * + + * | | * | | faked(*) * esp +------+ <--- :excp stackframe = <---, esp, epc * | | esp = nsp - sizeof(pt_regs) * | | * | Npc | (*) If we didn't add this frame, the next frame * | nfp | would be * | nsp | * | npc | and the frame below for npc would be lost. * nsp + + * | | * nfp +------+ <--- :task stackframe = * | Nfp | * | NNpc | * Nsp + + * | | * Nfp +------+ <--- :task stackframe = * | NNfp | * * (3)Interrupt: * +------+ * | cfp | * | ipc | * csp + + * | | * | | * cfp +------+ <--- :curr stackframe = * | ifp | * | epc | * isp + + * | | * | | (*) * ifp +------+ <--- :irq stackframe = * | nfp | ifp == IRQ_STACK_PTR * | esp | (*) Before the kernel enters an irq handler, frame * top +------+ pointer moves to the top of IRQ stack. * IRQ stack So we have to skip this frame in unwinding. * * faked * esp +------+ <--- :excp stackframe = <---, esp, epc> * | | esp = nsp - sizeof(pt_regs) * | | * | Npc | * | nfp | * | nsp | * | npc | * nsp + + * | | * nfp +------+ <--- :task stackframe = * | Nfp | * | NNpc | * Nsp + + * | | * Nfp +------+ <--- :task stackframe = * | NNfp | */ static struct arm64_stackframe ext_frame; static int arm64_unwind_frame_v2(struct bt_info *bt, struct arm64_stackframe *frame, FILE *ofp) { unsigned long high, low, fp; unsigned long stack_mask; unsigned long irq_stack_ptr; struct machine_specific *ms; stack_mask = (unsigned long)(ARM64_STACK_SIZE) - 1; fp = frame->fp; low = frame->sp; high = (low + stack_mask) & ~(stack_mask); if (fp < low || fp > high || fp & 0xf || !INSTACK(fp, bt)) return FALSE; if (CRASHDEBUG(1)) fprintf(ofp, " cur fp:%016lx sp:%016lx pc:%016lx\n", frame->fp, frame->sp, frame->pc); if (ext_frame.pc) { /* * The previous frame was a dummy for exception entry. * So complement a missing (task) stackframe now. */ frame->fp = ext_frame.fp; frame->sp = ext_frame.sp; frame->pc = ext_frame.pc; ext_frame.pc = 0; /* back to normal unwinding */ goto unwind_done; } frame->pc = GET_STACK_ULONG(fp + 8); if (!arm64_in_exp_entry(frame->pc)) { /* (1) Normal stack frame */ frame->sp = fp + 0x10; frame->fp = GET_STACK_ULONG(fp); } else { /* * We are in exception entry code, and so * - add a faked frame for exception entry, and * - prepare for a stackframe hidden by exception */ ext_frame.fp = GET_STACK_ULONG(fp); /* * Note: * In the following code, we determine a stack pointer for * exception entry based on ext_frame.fp because we have * no way to know a ext_frame.sp. * Fortunately, this will work fine for most functions * in the kernel. */ if (ext_frame.fp == 0) { /* * (2) * Either on process stack or on IRQ stack, * the next frame is the last one on process stack. */ frame->sp = bt->stacktop - sizeof(struct arm64_pt_regs) - 0x10; frame->fp = frame->sp; } else if (!arm64_on_irq_stack(bt->tc->processor, frame->sp)) { /* * (2) * We are on process stack. Just add a faked frame */ if (!arm64_on_irq_stack(bt->tc->processor, ext_frame.fp)) frame->sp = ext_frame.fp - sizeof(struct arm64_pt_regs); else { /* * FIXME: very exceptional case * We are already back on process stack, but * a saved frame pointer indicates that we are * on IRQ stack. Unfortunately this can happen * when some functions are called after * an irq handler is done because irq_exit() * doesn't restore a frame pointer (x29). * Those functions include * - do_notify_resume() * - trace_hardirqs_off() * - schedule() * * We have no perfect way to determine a true * stack pointer value here. * 0x20 is a stackframe size of schedule(). * Really ugly */ frame->sp = frame->fp + 0x20; fprintf(ofp, " (Next exception frame might be wrong)\n"); } frame->fp = frame->sp; } else { /* We are on IRQ stack */ ms = machdep->machspec; irq_stack_ptr = ms->irq_stacks[bt->tc->processor] + ms->irq_stack_size - 0x20; if (ext_frame.fp != irq_stack_ptr) { /* (2) Just add a faked frame */ frame->sp = ext_frame.fp - sizeof(struct arm64_pt_regs); frame->fp = frame->sp; } else { /* * (3) * Switch from IRQ stack to process stack */ frame->sp = GET_STACK_ULONG(irq_stack_ptr + 8); frame->fp = frame->sp; /* * Keep a buffer for a while until * displaying the last frame on IRQ stack * at next arm64_print_stackframe_entry_v2() */ if (bt->flags & BT_FULL) ms->irq_stackbuf = bt->stackbuf; arm64_set_process_stack(bt); } } /* prepare for a stackframe hidden by exception */ arm64_gen_hidden_frame(bt, frame->sp, &ext_frame); } unwind_done: if (CRASHDEBUG(1)) fprintf(ofp, " nxt fp:%016lx sp:%016lx pc:%016lx\n", frame->fp, frame->sp, frame->pc); return TRUE; } /* * A layout of a stack frame in a function looks like: * * stack grows to lower addresses. * /|\ * | * | | * new sp +------+ <--- * |dyn | | * | vars | | * new fp +- - - + | * |old fp| | a function's stack frame * |old lr| | * |static| | * | vars| | * old sp +------+ <--- * |dyn | * | vars | * old fp +------+ * | | * * - On function entry, sp is decremented down to new fp. * * - and old fp and sp are saved into this stack frame. * "Static" local variables are allocated at the same time. * * - Later on, "dynamic" local variables may be allocated on a stack. * But those dynamic variables are rarely used in the kernel image, * and, as a matter of fact, sp is equal to fp in almost all functions. * (not 100% though.) * * - Currently, sp is determined in arm64_unwind_frame() by * sp = a callee's fp + 0x10 * where 0x10 stands for a saved area for fp and sp * * - As you can see, however, this calculated sp still points to the top of * callee's static local variables and doesn't match with a *real* sp. * * - So, generally, dumping a stack from this calculated sp to the next frame's * sp shows "callee's static local variables", old fp and sp. * * Diagram and explanation courtesy of Takahiro Akashi */ static void arm64_back_trace_cmd(struct bt_info *bt) { struct arm64_stackframe stackframe; int level; ulong exception_frame; FILE *ofp; extra_stacks_idx = 0; if (bt->flags & BT_OPT_BACK_TRACE) { if (machdep->flags & UNW_4_14) { option_not_supported('o'); return; } arm64_back_trace_cmd_v2(bt); return; } ofp = BT_REFERENCE_CHECK(bt) ? pc->nullfp : fp; /* * stackframes are created from 3 contiguous stack addresses: * * x: contains stackframe.fp -- points to next triplet * x+8: contains stackframe.pc -- text return address * x+16: is the stackframe.sp address */ if (bt->flags & BT_KDUMP_ADJUST) { if (arm64_on_irq_stack(bt->tc->processor, bt->bptr)) { arm64_set_irq_stack(bt); bt->flags |= BT_IRQSTACK; } stackframe.fp = GET_STACK_ULONG(bt->bptr - 8); stackframe.pc = GET_STACK_ULONG(bt->bptr); stackframe.sp = bt->bptr + 8; bt->frameptr = stackframe.sp; } else if (bt->hp && bt->hp->esp) { if (arm64_on_irq_stack(bt->tc->processor, bt->hp->esp)) { arm64_set_irq_stack(bt); bt->flags |= BT_IRQSTACK; } stackframe.fp = GET_STACK_ULONG(bt->hp->esp - 8); stackframe.pc = bt->hp->eip ? bt->hp->eip : GET_STACK_ULONG(bt->hp->esp); stackframe.sp = bt->hp->esp + 8; bt->flags &= ~BT_REGS_NOT_FOUND; } else { if (arm64_on_irq_stack(bt->tc->processor, bt->frameptr)) { arm64_set_irq_stack(bt); bt->flags |= BT_IRQSTACK; } else if (arm64_on_overflow_stack(bt->tc->processor, bt->frameptr)) { arm64_set_overflow_stack(bt); bt->flags |= BT_OVERFLOW_STACK; } stackframe.sp = bt->stkptr; stackframe.pc = bt->instptr; stackframe.fp = bt->frameptr; } if (is_task_active(bt->task)) { if (!extra_stacks_regs[extra_stacks_idx]) { extra_stacks_regs[extra_stacks_idx] = (struct user_regs_bitmap_struct *) malloc(sizeof(struct user_regs_bitmap_struct)); } memset(extra_stacks_regs[extra_stacks_idx], 0, sizeof(struct user_regs_bitmap_struct)); if (bt->task != tt->panic_task && stackframe.sp) { readmem(stackframe.sp - 8, KVADDR, &extra_stacks_regs[extra_stacks_idx]->ur.pc, sizeof(ulong), "extra_stacks_regs.pc", RETURN_ON_ERROR); readmem(stackframe.sp - 16, KVADDR, &extra_stacks_regs[extra_stacks_idx]->ur.sp, sizeof(ulong), "extra_stacks_regs.sp", RETURN_ON_ERROR); } else { extra_stacks_regs[extra_stacks_idx]->ur.pc = stackframe.pc; extra_stacks_regs[extra_stacks_idx]->ur.sp = stackframe.sp; } SET_BIT(extra_stacks_regs[extra_stacks_idx]->bitmap, REG_SEQ(arm64_pt_regs, pc)); SET_BIT(extra_stacks_regs[extra_stacks_idx]->bitmap, REG_SEQ(arm64_pt_regs, sp)); if (!bt->machdep || (extra_stacks_regs[extra_stacks_idx]->ur.sp != ((struct user_regs_bitmap_struct *)(bt->machdep))->ur.sp && extra_stacks_regs[extra_stacks_idx]->ur.pc != ((struct user_regs_bitmap_struct *)(bt->machdep))->ur.pc)) { gdb_add_substack (extra_stacks_idx++); } } if (bt->flags & BT_TEXT_SYMBOLS) { arm64_print_text_symbols(bt, &stackframe, ofp); if (BT_REFERENCE_FOUND(bt)) { print_task_header(fp, task_to_context(bt->task), 0); arm64_print_text_symbols(bt, &stackframe, fp); fprintf(fp, "\n"); } return; } if (bt->flags & BT_REGS_NOT_FOUND) return; if (!(bt->flags & BT_KDUMP_ADJUST)) { if (bt->flags & BT_USER_SPACE) goto complete_user; if (DUMPFILE() && is_task_active(bt->task)) { exception_frame = stackframe.fp - KERN_EFRAME_OFFSET; if (arm64_is_kernel_exception_frame(bt, exception_frame)) arm64_print_exception_frame(bt, exception_frame, KERNEL_MODE, ofp); } } level = exception_frame = 0; while (1) { bt->instptr = stackframe.pc; switch (arm64_print_stackframe_entry(bt, level, &stackframe, ofp)) { case BACKTRACE_COMPLETE_KERNEL: return; case BACKTRACE_COMPLETE_USER: goto complete_user; case BACKTRACE_CONTINUE: break; } if (exception_frame) { arm64_print_exception_frame(bt, exception_frame, KERNEL_MODE, ofp); exception_frame = 0; } if (!arm64_unwind_frame(bt, &stackframe)) break; if (arm64_in_exception_text(bt->instptr) && INSTACK(stackframe.fp, bt)) { if (bt->flags & BT_OVERFLOW_STACK) { exception_frame = stackframe.fp - KERN_EFRAME_OFFSET; } else if (!(bt->flags & BT_IRQSTACK) || ((stackframe.sp + SIZE(pt_regs)) < bt->stacktop)) { if (arm64_is_kernel_exception_frame(bt, stackframe.fp - KERN_EFRAME_OFFSET)) exception_frame = stackframe.fp - KERN_EFRAME_OFFSET; } } if ((bt->flags & BT_IRQSTACK) && !arm64_on_irq_stack(bt->tc->processor, stackframe.fp)) { bt->flags &= ~BT_IRQSTACK; if (arm64_switch_stack(bt, &stackframe, ofp) == USER_MODE) break; } if ((bt->flags & BT_OVERFLOW_STACK) && !arm64_on_overflow_stack(bt->tc->processor, stackframe.fp)) { bt->flags &= ~BT_OVERFLOW_STACK; if (arm64_switch_stack_from_overflow(bt, &stackframe, ofp) == USER_MODE) break; } level++; } if (is_kernel_thread(bt->tc->task)) return; complete_user: exception_frame = bt->stacktop - USER_EFRAME_OFFSET; arm64_print_exception_frame(bt, exception_frame, USER_MODE, ofp); if ((bt->flags & (BT_USER_SPACE|BT_KDUMP_ADJUST)) == BT_USER_SPACE) fprintf(ofp, " #0 [user space]\n"); } static void arm64_back_trace_cmd_v2(struct bt_info *bt) { struct arm64_stackframe stackframe, cur_frame; int level, mode; ulong exception_frame; FILE *ofp; ofp = BT_REFERENCE_CHECK(bt) ? pc->nullfp : fp; /* * stackframes are created from 3 contiguous stack addresses: * * x: contains stackframe.fp -- points to next triplet * x+8: contains stackframe.pc -- text return address * x+16: is the stackframe.sp address */ if (bt->flags & BT_KDUMP_ADJUST) { if (arm64_on_irq_stack(bt->tc->processor, bt->bptr)) { arm64_set_irq_stack(bt); bt->flags |= BT_IRQSTACK; } stackframe.fp = GET_STACK_ULONG(bt->bptr); stackframe.pc = GET_STACK_ULONG(bt->bptr + 8); stackframe.sp = bt->bptr + 16; bt->frameptr = stackframe.fp; } else { if (arm64_on_irq_stack(bt->tc->processor, bt->frameptr)) { arm64_set_irq_stack(bt); bt->flags |= BT_IRQSTACK; } stackframe.sp = bt->stkptr; stackframe.pc = bt->instptr; stackframe.fp = bt->frameptr; } if (is_task_active(bt->task)) { if (!extra_stacks_regs[extra_stacks_idx]) { extra_stacks_regs[extra_stacks_idx] = (struct user_regs_bitmap_struct *) malloc(sizeof(struct user_regs_bitmap_struct)); } memset(extra_stacks_regs[extra_stacks_idx], 0, sizeof(struct user_regs_bitmap_struct)); if (bt->task != tt->panic_task && stackframe.sp) { readmem(stackframe.sp - 8, KVADDR, &extra_stacks_regs[extra_stacks_idx]->ur.pc, sizeof(ulong), "extra_stacks_regs.pc", RETURN_ON_ERROR); readmem(stackframe.sp - 16, KVADDR, &extra_stacks_regs[extra_stacks_idx]->ur.sp, sizeof(ulong), "extra_stacks_regs.sp", RETURN_ON_ERROR); } else { extra_stacks_regs[extra_stacks_idx]->ur.pc = stackframe.pc; extra_stacks_regs[extra_stacks_idx]->ur.sp = stackframe.sp; } SET_BIT(extra_stacks_regs[extra_stacks_idx]->bitmap, REG_SEQ(arm64_pt_regs, pc)); SET_BIT(extra_stacks_regs[extra_stacks_idx]->bitmap, REG_SEQ(arm64_pt_regs, sp)); if (!bt->machdep || (extra_stacks_regs[extra_stacks_idx]->ur.sp != ((struct user_regs_bitmap_struct *)(bt->machdep))->ur.sp && extra_stacks_regs[extra_stacks_idx]->ur.pc != ((struct user_regs_bitmap_struct *)(bt->machdep))->ur.pc)) { gdb_add_substack (extra_stacks_idx++); } } if (bt->flags & BT_TEXT_SYMBOLS) { arm64_print_text_symbols(bt, &stackframe, ofp); if (BT_REFERENCE_FOUND(bt)) { print_task_header(fp, task_to_context(bt->task), 0); arm64_print_text_symbols(bt, &stackframe, fp); fprintf(fp, "\n"); } return; } if (bt->flags & BT_REGS_NOT_FOUND) return; if (!(bt->flags & BT_KDUMP_ADJUST)) { if (bt->flags & BT_USER_SPACE) { user_space: exception_frame = bt->stacktop - USER_EFRAME_OFFSET; arm64_print_exception_frame(bt, exception_frame, USER_MODE, ofp); // fprintf(ofp, " #0 [user space]\n"); return; } if (DUMPFILE() && is_task_active(bt->task)) { exception_frame = stackframe.fp - SIZE(pt_regs); if (arm64_is_kernel_exception_frame(bt, exception_frame)) arm64_print_exception_frame(bt, exception_frame, KERNEL_MODE, ofp); } } for (level = 0;; level++) { bt->instptr = stackframe.pc; /* * Show one-line stackframe info */ if (arm64_print_stackframe_entry_v2(bt, level, &stackframe, ofp) == BACKTRACE_COMPLETE_KERNEL) break; cur_frame = stackframe; if (!arm64_unwind_frame_v2(bt, &stackframe, ofp)) break; /* * Dump the contents of the current stackframe. * We need to know the next stackframe to determine * the dump range: * */ arm64_display_full_frame_v2(bt, &cur_frame, &stackframe); /* * If we are in a normal stackframe, just continue, * otherwise show an exception frame. * Since exception entry code doesn't have a real * stackframe, we fake a dummy frame here. */ if (!arm64_in_exp_entry(stackframe.pc)) continue; if (!INSTACK(cur_frame.sp, bt)) fprintf(ofp, "--- ---\n"); arm64_print_stackframe_entry_v2(bt, ++level, &stackframe, ofp); if (bt->flags & BT_USER_EFRAME) goto user_space; cur_frame = stackframe; arm64_unwind_frame_v2(bt, &stackframe, ofp); /* * and don't show the contenxts. Instead, * show an exception frame below */ if (!INSTACK(cur_frame.sp, bt)) { /* This check is a safeguard. See unwind_frame(). */ error(WARNING, "stack pointer for exception frame is wrong\n"); return; } mode = (stackframe.pc < machdep->machspec->userspace_top) ? USER_MODE : KERNEL_MODE; // fprintf(ofp, "--- ---\n", // mode == KERNEL_MODE ? "kernel" : "user"); arm64_print_exception_frame(bt, cur_frame.sp, mode, ofp); if (mode == USER_MODE) break; } } static void arm64_print_text_symbols(struct bt_info *bt, struct arm64_stackframe *frame, FILE *ofp) { int i; ulong *up; struct load_module *lm; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char *name; ulong start; ulong val; struct machine_specific *ms = machdep->machspec; if (bt->flags & BT_TEXT_SYMBOLS_ALL) start = bt->stackbase; else { start = frame->sp - 8; fprintf(ofp, "%sSTART: %s at %lx\n", space(VADDR_PRLEN > 8 ? 14 : 6), bt->flags & BT_SYMBOL_OFFSET ? value_to_symstr(frame->pc, buf2, bt->radix) : closest_symbol(frame->pc), frame->pc); } for (i = (start - bt->stackbase)/sizeof(ulong); i < LONGS_PER_STACK; i++) { up = (ulong *)(&bt->stackbuf[i*sizeof(ulong)]); val = *up; if (is_kernel_text(val | ms->CONFIG_ARM64_KERNELPACMASK)) { val |= ms->CONFIG_ARM64_KERNELPACMASK; name = closest_symbol(val); fprintf(ofp, " %s[%s] %s at %lx", bt->flags & BT_ERROR_MASK ? " " : "", mkstring(buf1, VADDR_PRLEN, RJUST|LONG_HEX, MKSTR(bt->stackbase + (i * sizeof(long)))), bt->flags & BT_SYMBOL_OFFSET ? value_to_symstr(val, buf2, bt->radix) : name, val); if (module_symbol(val, NULL, &lm, NULL, 0)) fprintf(ofp, " [%s]", lm->mod_name); fprintf(ofp, "\n"); if (BT_REFERENCE_CHECK(bt)) arm64_do_bt_reference_check(bt, val, name); } } } static int arm64_in_kdump_text(struct bt_info *bt, struct arm64_stackframe *frame) { ulong *ptr, *start, *base; struct machine_specific *ms; ulong crash_kexec_frame; if (!(machdep->flags & KDUMP_ENABLED)) return FALSE; base = (ulong *)&bt->stackbuf[(ulong)(STACK_OFFSET_TYPE(bt->stackbase))]; if (bt->flags & BT_USER_SPACE) start = (ulong *)&bt->stackbuf[(ulong)(STACK_OFFSET_TYPE(bt->stacktop))]; else { if (INSTACK(frame->fp, bt)) start = (ulong *)&bt->stackbuf[(ulong)(STACK_OFFSET_TYPE(frame->fp))]; else start = (ulong *)&bt->stackbuf[(ulong)(STACK_OFFSET_TYPE(bt->stacktop))]; } crash_kexec_frame = 0; ms = machdep->machspec; for (ptr = start - 8; ptr >= base; ptr--) { if (bt->flags & BT_OPT_BACK_TRACE) { if ((*ptr > ms->crash_kexec_start) && (*ptr < ms->crash_kexec_end) && INSTACK(*(ptr - 1), bt)) { bt->bptr = ((ulong)(ptr - 1) - (ulong)base) + task_to_stackbase(bt->tc->task); if (CRASHDEBUG(1)) fprintf(fp, "%lx: %lx (crash_kexec)\n", bt->bptr, *ptr); return TRUE; } if ((*ptr > ms->crash_save_cpu_start) && (*ptr < ms->crash_save_cpu_end) && INSTACK(*(ptr - 1), bt)) { bt->bptr = ((ulong)(ptr - 1) - (ulong)base) + task_to_stackbase(bt->tc->task); if (CRASHDEBUG(1)) fprintf(fp, "%lx: %lx (crash_save_cpu)\n", bt->bptr, *ptr); return TRUE; } } else { if ((*ptr > ms->machine_kexec_start) && (*ptr < ms->machine_kexec_end)) { bt->bptr = ((ulong)ptr - (ulong)base) + task_to_stackbase(bt->tc->task); if (CRASHDEBUG(1)) fprintf(fp, "%lx: %lx (machine_kexec)\n", bt->bptr, *ptr); return TRUE; } if ((*ptr > ms->crash_kexec_start) && (*ptr < ms->crash_kexec_end)) { /* * Stash the first crash_kexec frame in case the machine_kexec * frame is not found. */ if (!crash_kexec_frame) { crash_kexec_frame = ((ulong)ptr - (ulong)base) + task_to_stackbase(bt->tc->task); if (CRASHDEBUG(1)) fprintf(fp, "%lx: %lx (crash_kexec)\n", bt->bptr, *ptr); } continue; } if ((*ptr > ms->crash_save_cpu_start) && (*ptr < ms->crash_save_cpu_end)) { bt->bptr = ((ulong)ptr - (ulong)base) + task_to_stackbase(bt->tc->task); if (CRASHDEBUG(1)) fprintf(fp, "%lx: %lx (crash_save_cpu)\n", bt->bptr, *ptr); return TRUE; } } } if (crash_kexec_frame) { bt->bptr = crash_kexec_frame; return TRUE; } return FALSE; } static int arm64_in_kdump_text_on_irq_stack(struct bt_info *bt) { int cpu; ulong stackbase; char *stackbuf; ulong *ptr, *start, *base; struct machine_specific *ms; if ((machdep->flags & (IRQ_STACKS|KDUMP_ENABLED)) != (IRQ_STACKS|KDUMP_ENABLED)) return FALSE; ms = machdep->machspec; cpu = bt->tc->processor; stackbase = ms->irq_stacks[cpu]; stackbuf = GETBUF(ms->irq_stack_size); if (!readmem(stackbase, KVADDR, stackbuf, ms->irq_stack_size, "IRQ stack contents", RETURN_ON_ERROR)) { error(INFO, "read of IRQ stack at %lx failed\n", stackbase); FREEBUF(stackbuf); return FALSE; } base = (ulong *)stackbuf; start = (ulong *)(stackbuf + ms->irq_stack_size); for (ptr = start - 8; ptr >= base; ptr--) { if (bt->flags & BT_OPT_BACK_TRACE) { if ((*ptr > ms->crash_kexec_start) && (*ptr < ms->crash_kexec_end) && INSTACK(*(ptr - 1), bt)) { bt->bptr = ((ulong)(ptr - 1) - (ulong)base) + stackbase; if (CRASHDEBUG(1)) fprintf(fp, "%lx: %lx (crash_kexec on IRQ stack)\n", bt->bptr, *ptr); FREEBUF(stackbuf); return TRUE; } if ((*ptr > ms->crash_save_cpu_start) && (*ptr < ms->crash_save_cpu_end) && INSTACK(*(ptr - 1), bt)) { bt->bptr = ((ulong)(ptr - 1) - (ulong)base) + stackbase; if (CRASHDEBUG(1)) fprintf(fp, "%lx: %lx (crash_save_cpu on IRQ stack)\n", bt->bptr, *ptr); FREEBUF(stackbuf); return TRUE; } } else { if ((*ptr > ms->crash_kexec_start) && (*ptr < ms->crash_kexec_end)) { bt->bptr = ((ulong)ptr - (ulong)base) + stackbase; if (CRASHDEBUG(1)) fprintf(fp, "%lx: %lx (crash_kexec on IRQ stack)\n", bt->bptr, *ptr); FREEBUF(stackbuf); return TRUE; } if ((*ptr > ms->crash_save_cpu_start) && (*ptr < ms->crash_save_cpu_end)) { bt->bptr = ((ulong)ptr - (ulong)base) + stackbase; if (CRASHDEBUG(1)) fprintf(fp, "%lx: %lx (crash_save_cpu on IRQ stack)\n", bt->bptr, *ptr); FREEBUF(stackbuf); return TRUE; } } } FREEBUF(stackbuf); return FALSE; } static int arm64_switch_stack(struct bt_info *bt, struct arm64_stackframe *frame, FILE *ofp) { int i; ulong stacktop, words, addr; ulong *stackbuf; char buf[BUFSIZE]; struct machine_specific *ms = machdep->machspec; if (bt->flags & BT_FULL) { stacktop = ms->irq_stacks[bt->tc->processor] + ms->irq_stack_size; words = (stacktop - bt->bptr) / sizeof(ulong); stackbuf = (ulong *)GETBUF(words * sizeof(ulong)); readmem(bt->bptr, KVADDR, stackbuf, words * sizeof(long), "top of IRQ stack", FAULT_ON_ERROR); addr = bt->bptr; for (i = 0; i < words; i++) { if (!(i & 1)) fprintf(ofp, "%s %lx: ", i ? "\n" : "", addr); fprintf(ofp, "%s ", format_stack_entry(bt, buf, stackbuf[i], 0)); addr += sizeof(ulong); } fprintf(ofp, "\n"); FREEBUF(stackbuf); } fprintf(ofp, "--- ---\n"); if (frame->fp == 0) return USER_MODE; if (!(machdep->flags & UNW_4_14)) arm64_print_exception_frame(bt, frame->sp, KERNEL_MODE, ofp); return KERNEL_MODE; } static int arm64_switch_stack_from_overflow(struct bt_info *bt, struct arm64_stackframe *frame, FILE *ofp) { int i; ulong stacktop, words, addr; ulong *stackbuf; char buf[BUFSIZE]; struct machine_specific *ms = machdep->machspec; if (bt->flags & BT_FULL) { stacktop = ms->overflow_stacks[bt->tc->processor] + ms->overflow_stack_size; words = (stacktop - bt->bptr) / sizeof(ulong); stackbuf = (ulong *)GETBUF(words * sizeof(ulong)); readmem(bt->bptr, KVADDR, stackbuf, words * sizeof(long), "top of overflow stack", FAULT_ON_ERROR); addr = bt->bptr; for (i = 0; i < words; i++) { if (!(i & 1)) fprintf(ofp, "%s %lx: ", i ? "\n" : "", addr); fprintf(ofp, "%s ", format_stack_entry(bt, buf, stackbuf[i], 0)); addr += sizeof(ulong); } fprintf(ofp, "\n"); FREEBUF(stackbuf); } fprintf(ofp, "--- ---\n"); if (frame->fp == 0) return USER_MODE; if (!(machdep->flags & UNW_4_14)) arm64_print_exception_frame(bt, frame->sp, KERNEL_MODE, ofp); return KERNEL_MODE; } static int arm64_get_dumpfile_stackframe(struct bt_info *bt, struct arm64_stackframe *frame) { struct machine_specific *ms = machdep->machspec; struct arm64_pt_regs *ptregs; bool skip = false; if (bt->flags & BT_SKIP_IDLE) { skip = true; bt->flags &= ~BT_SKIP_IDLE; } if (!ms->panic_task_regs || (!ms->panic_task_regs[bt->tc->processor].sp && !ms->panic_task_regs[bt->tc->processor].pc)) { bt->flags |= BT_REGS_NOT_FOUND; return FALSE; } ptregs = &ms->panic_task_regs[bt->tc->processor]; frame->pc = ptregs->pc; if (user_mode(ptregs)) { frame->sp = user_stack_pointer(ptregs); frame->fp = user_frame_pointer(ptregs); if (is_kernel_text(frame->pc) || !in_user_stack(bt->tc->task, frame->sp)) { error(WARNING, "corrupt NT_PRSTATUS? pstate: 0x%lx, but no user frame found\n", ptregs->pstate); if (is_kernel_text(frame->pc) && INSTACK(frame->sp, bt) && INSTACK(frame->fp, bt)) goto try_kernel; bt->flags |= BT_REGS_NOT_FOUND; return FALSE; } bt->flags |= BT_USER_SPACE; } else { try_kernel: frame->sp = ptregs->sp; frame->fp = ptregs->regs[29]; bt->machdep = ptregs; } if (arm64_in_kdump_text(bt, frame) || arm64_in_kdump_text_on_irq_stack(bt)) { bt->flags |= BT_KDUMP_ADJUST; if (skip && is_idle_thread(bt->task)) bt->flags |= BT_SKIP_IDLE; } return TRUE; } static int arm64_get_stackframe(struct bt_info *bt, struct arm64_stackframe *frame) { if (!fill_task_struct(bt->task)) return FALSE; frame->sp = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_sp)); frame->pc = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_pc)); frame->fp = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_fp)); frame->x19 = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_x19)); frame->x20 = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_x20)); frame->x21 = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_x21)); frame->x22 = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_x22)); frame->x23 = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_x23)); frame->x24 = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_x24)); frame->x25 = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_x25)); frame->x26 = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_x26)); frame->x27 = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_x27)); frame->x28 = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_x28)); return TRUE; } static void arm64_get_stack_frame(struct bt_info *bt, ulong *pcp, ulong *spp) { struct user_regs_bitmap_struct *ur_bitmap; struct arm64_stackframe stackframe = { 0 }; if (DUMPFILE() && is_task_active(bt->task)) { arm64_get_dumpfile_stackframe(bt, &stackframe); bt->need_free = FALSE; } else { if (bt->flags & BT_SKIP_IDLE) bt->flags &= ~BT_SKIP_IDLE; arm64_get_stackframe(bt, &stackframe); ur_bitmap = (struct user_regs_bitmap_struct *)GETBUF(sizeof(*ur_bitmap)); memset(ur_bitmap, 0, sizeof(*ur_bitmap)); ur_bitmap->ur.pc = stackframe.pc; ur_bitmap->ur.sp = stackframe.sp; ur_bitmap->ur.regs[29] = stackframe.fp; ur_bitmap->ur.regs[28] = stackframe.x28; ur_bitmap->ur.regs[27] = stackframe.x27; ur_bitmap->ur.regs[26] = stackframe.x26; ur_bitmap->ur.regs[25] = stackframe.x25; ur_bitmap->ur.regs[24] = stackframe.x24; ur_bitmap->ur.regs[23] = stackframe.x23; ur_bitmap->ur.regs[22] = stackframe.x22; ur_bitmap->ur.regs[21] = stackframe.x21; ur_bitmap->ur.regs[20] = stackframe.x20; ur_bitmap->ur.regs[19] = stackframe.x19; SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, pc)); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, sp)); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + X29_REGNUM - X0_REGNUM); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + X28_REGNUM - X0_REGNUM); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + X27_REGNUM - X0_REGNUM); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + X26_REGNUM - X0_REGNUM); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + X25_REGNUM - X0_REGNUM); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + X24_REGNUM - X0_REGNUM); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + X23_REGNUM - X0_REGNUM); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + X22_REGNUM - X0_REGNUM); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + X21_REGNUM - X0_REGNUM); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + X20_REGNUM - X0_REGNUM); SET_BIT(ur_bitmap->bitmap, REG_SEQ(arm64_pt_regs, regs[0]) + X19_REGNUM - X0_REGNUM); bt->machdep = ur_bitmap; bt->need_free = TRUE; } bt->frameptr = stackframe.fp; if (pcp) *pcp = stackframe.pc; if (spp) *spp = stackframe.sp; } static void arm64_gen_hidden_frame(struct bt_info *bt, ulong sp, struct arm64_stackframe *frame) { struct arm64_pt_regs *ptregs; if (IN_TASK_VMA(bt->task, sp)) { bt->flags |= BT_USER_EFRAME; return; } ptregs = (struct arm64_pt_regs *) &bt->stackbuf[(ulong)(STACK_OFFSET_TYPE(sp))]; frame->pc = ptregs->pc; frame->fp = ptregs->regs[29]; frame->sp = ptregs->sp; } static void arm64_print_exception_frame(struct bt_info *bt, ulong pt_regs, int mode, FILE *ofp) { int i, r, rows, top_reg, is_64_bit; struct arm64_pt_regs *regs; struct syment *sp; ulong LR, SP, offset; char buf[BUFSIZE]; struct machine_specific *ms = machdep->machspec; if (CRASHDEBUG(1)) fprintf(ofp, "pt_regs: %lx\n", pt_regs); regs = (struct arm64_pt_regs *) &bt->stackbuf[(ulong)(STACK_OFFSET_TYPE(pt_regs))]; if ((mode == USER_MODE) && (regs->pstate & PSR_MODE32_BIT)) { LR = regs->regs[14]; SP = regs->regs[13]; top_reg = 12; is_64_bit = FALSE; rows = 4; } else { LR = regs->regs[30]; if (is_kernel_text (LR | ms->CONFIG_ARM64_KERNELPACMASK)) LR |= ms->CONFIG_ARM64_KERNELPACMASK; SP = regs->sp; top_reg = 29; is_64_bit = TRUE; rows = 3; } switch (mode) { case USER_MODE: if (is_64_bit) fprintf(ofp, " PC: %016lx LR: %016lx SP: %016lx\n ", (ulong)regs->pc, LR, SP); else fprintf(ofp, " PC: %08lx LR: %08lx SP: %08lx PSTATE: %08lx\n ", (ulong)regs->pc, LR, SP, (ulong)regs->pstate); break; case KERNEL_MODE: fprintf(ofp, " PC: %016lx ", (ulong)regs->pc); if (is_kernel_text(regs->pc) && (sp = value_search(regs->pc, &offset))) { fprintf(ofp, "[%s", sp->name); if (offset) fprintf(ofp, (*gdb_output_radix == 16) ? "+0x%lx" : "+%ld", offset); fprintf(ofp, "]\n"); } else fprintf(ofp, "[unknown or invalid address]\n"); fprintf(ofp, " LR: %016lx ", LR); if (is_kernel_text(LR) && (sp = value_search(LR, &offset))) { fprintf(ofp, "[%s", sp->name); if (offset) fprintf(ofp, (*gdb_output_radix == 16) ? "+0x%lx" : "+%ld", offset); fprintf(ofp, "]\n"); } else fprintf(ofp, "[unknown or invalid address]\n"); fprintf(ofp, " SP: %016lx PSTATE: %08lx\n ", SP, (ulong)regs->pstate); break; } for (i = top_reg, r = 1; i >= 0; r++, i--) { fprintf(ofp, "%sX%d: ", i < 10 ? " " : "", i); fprintf(ofp, is_64_bit ? "%016lx" : "%08lx", (ulong)regs->regs[i]); if ((i == 0) && !is_64_bit) fprintf(ofp, "\n"); else if ((i == 0) || ((r % rows) == 0)) fprintf(ofp, "\n%s", (i == 0) && (mode == KERNEL_MODE) ? "" : " "); else fprintf(ofp, "%s", is_64_bit ? " " : " "); } if (is_64_bit) { if (mode == USER_MODE) { fprintf(ofp, "ORIG_X0: %016lx SYSCALLNO: %lx", (ulong)regs->orig_x0, (ulong)regs->syscallno); fprintf(ofp, " PSTATE: %08lx\n", (ulong)regs->pstate); } else if (!(bt->flags & BT_EFRAME_SEARCH)) { if (!extra_stacks_regs[extra_stacks_idx]) { extra_stacks_regs[extra_stacks_idx] = (struct user_regs_bitmap_struct *) malloc(sizeof(struct user_regs_bitmap_struct)); } memset(extra_stacks_regs[extra_stacks_idx], 0, sizeof(struct user_regs_bitmap_struct)); memcpy(&extra_stacks_regs[extra_stacks_idx]->ur, regs, sizeof(struct arm64_pt_regs)); for (int i = 0; i < sizeof(struct arm64_pt_regs)/sizeof(long); i++) SET_BIT(extra_stacks_regs[extra_stacks_idx]->bitmap, i); if (!bt->machdep || (extra_stacks_regs[extra_stacks_idx]->ur.sp != ((struct user_regs_bitmap_struct *)(bt->machdep))->ur.sp && extra_stacks_regs[extra_stacks_idx]->ur.pc != ((struct user_regs_bitmap_struct *)(bt->machdep))->ur.pc)) { gdb_add_substack (extra_stacks_idx++); } } } if (is_kernel_text(regs->pc) && (bt->flags & BT_LINE_NUMBERS)) { get_line_number(regs->pc, buf, FALSE); if (strlen(buf)) fprintf(ofp, " %s\n", buf); } if (BT_REFERENCE_CHECK(bt)) { arm64_do_bt_reference_check(bt, regs->pc, NULL); if ((sp = value_search(regs->pc, &offset))) arm64_do_bt_reference_check(bt, 0, sp->name); arm64_do_bt_reference_check(bt, LR, NULL); arm64_do_bt_reference_check(bt, SP, NULL); arm64_do_bt_reference_check(bt, regs->pstate, NULL); for (i = 0; i <= top_reg; i++) arm64_do_bt_reference_check(bt, regs->regs[i], NULL); if (is_64_bit) { arm64_do_bt_reference_check(bt, regs->orig_x0, NULL); arm64_do_bt_reference_check(bt, regs->syscallno, NULL); } } } /* * Check a frame for a requested reference. */ static void arm64_do_bt_reference_check(struct bt_info *bt, ulong text, char *name) { ulong offset; struct syment *sp = NULL; if (!name) sp = value_search(text, &offset); else if (!text) sp = symbol_search(name); switch (bt->ref->cmdflags & (BT_REF_SYMBOL|BT_REF_HEXVAL)) { case BT_REF_SYMBOL: if (name) { if (STREQ(name, bt->ref->str)) bt->ref->cmdflags |= BT_REF_FOUND; } else { if (sp && !offset && STREQ(sp->name, bt->ref->str)) bt->ref->cmdflags |= BT_REF_FOUND; } break; case BT_REF_HEXVAL: if (text) { if (bt->ref->hexval == text) bt->ref->cmdflags |= BT_REF_FOUND; } else if (sp && (bt->ref->hexval == sp->value)) bt->ref->cmdflags |= BT_REF_FOUND; else if (!name && !text && (bt->ref->hexval == 0)) bt->ref->cmdflags |= BT_REF_FOUND; break; } } /* * Translate a PTE, returning TRUE if the page is present. * If a physaddr pointer is passed in, don't print anything. */ static int arm64_translate_pte(ulong pte, void *physaddr, ulonglong unused) { int c, others, len1, len2, len3; ulong paddr; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char buf3[BUFSIZE]; char ptebuf[BUFSIZE]; char physbuf[BUFSIZE]; char *arglist[MAXARGS]; int page_present; paddr = PTE_TO_PHYS(pte); page_present = pte & (PTE_VALID | machdep->machspec->PTE_PROT_NONE); if (physaddr) { *((ulong *)physaddr) = paddr; return page_present; } sprintf(ptebuf, "%lx", pte); len1 = MAX(strlen(ptebuf), strlen("PTE")); fprintf(fp, "%s ", mkstring(buf1, len1, CENTER|LJUST, "PTE")); if (!page_present) { swap_location(pte, buf1); if ((c = parse_line(buf1, arglist)) != 3) error(FATAL, "cannot determine swap location\n"); len2 = MAX(strlen(arglist[0]), strlen("SWAP")); len3 = MAX(strlen(arglist[2]), strlen("OFFSET")); fprintf(fp, "%s %s\n", mkstring(buf2, len2, CENTER|LJUST, "SWAP"), mkstring(buf3, len3, CENTER|LJUST, "OFFSET")); strcpy(buf2, arglist[0]); strcpy(buf3, arglist[2]); fprintf(fp, "%s %s %s\n", mkstring(ptebuf, len1, CENTER|RJUST, NULL), mkstring(buf2, len2, CENTER|RJUST, NULL), mkstring(buf3, len3, CENTER|RJUST, NULL)); return page_present; } sprintf(physbuf, "%lx", paddr); len2 = MAX(strlen(physbuf), strlen("PHYSICAL")); fprintf(fp, "%s ", mkstring(buf1, len2, CENTER|LJUST, "PHYSICAL")); fprintf(fp, "FLAGS\n"); fprintf(fp, "%s %s ", mkstring(ptebuf, len1, CENTER|RJUST, NULL), mkstring(physbuf, len2, CENTER|RJUST, NULL)); fprintf(fp, "("); others = 0; if (pte) { if (pte & PTE_VALID) fprintf(fp, "%sVALID", others++ ? "|" : ""); if (pte & machdep->machspec->PTE_FILE) fprintf(fp, "%sFILE", others++ ? "|" : ""); if (pte & machdep->machspec->PTE_PROT_NONE) fprintf(fp, "%sPROT_NONE", others++ ? "|" : ""); if (pte & PTE_USER) fprintf(fp, "%sUSER", others++ ? "|" : ""); if (pte & PTE_RDONLY) fprintf(fp, "%sRDONLY", others++ ? "|" : ""); if (pte & PTE_SHARED) fprintf(fp, "%sSHARED", others++ ? "|" : ""); if (pte & PTE_AF) fprintf(fp, "%sAF", others++ ? "|" : ""); if (pte & PTE_NG) fprintf(fp, "%sNG", others++ ? "|" : ""); if (pte & PTE_PXN) fprintf(fp, "%sPXN", others++ ? "|" : ""); if (pte & PTE_UXN) fprintf(fp, "%sUXN", others++ ? "|" : ""); if (pte & PTE_DIRTY) fprintf(fp, "%sDIRTY", others++ ? "|" : ""); if (pte & PTE_SPECIAL) fprintf(fp, "%sSPECIAL", others++ ? "|" : ""); } else { fprintf(fp, "no mapping"); } fprintf(fp, ")\n"); return (page_present); } static ulong arm64_vmalloc_start(void) { return machdep->machspec->vmalloc_start_addr; } /* * Not so accurate since thread_info introduction. */ static int arm64_is_task_addr(ulong task) { if (tt->flags & THREAD_INFO) return IS_KVADDR(task); else return (IS_KVADDR(task) && (ALIGNED_STACK_OFFSET(task) == 0)); } static ulong PLT_veneer_to_kvaddr(ulong value) { uint32_t insn; ulong addr = 0; int i; /* * PLT veneer always looks: * movn x16, #0x.... * movk x16, #0x...., lsl #16 * movk x16, #0x...., lsl #32 * br x16 */ for (i = 0; i < 4; i++) { if (!readmem(value + i * sizeof(insn), KVADDR, &insn, sizeof(insn), "PLT veneer", RETURN_ON_ERROR)) { error(WARNING, "cannot read PLT veneer instruction at %lx\n", value + i * sizeof(insn)); return value; } switch (i) { case 0: if ((insn & 0xffe0001f) != 0x92800010) goto not_plt; addr = ~((ulong)(insn & 0x1fffe0) >> 5); break; case 1: if ((insn & 0xffe0001f) != 0xf2a00010) goto not_plt; addr &= 0xffffffff0000ffff; addr |= (ulong)(insn & 0x1fffe0) << (16 - 5); break; case 2: if ((insn & 0xffe0001f) != 0xf2c00010) goto not_plt; addr &= 0xffff0000ffffffff; addr |= (ulong)(insn & 0x1fffe0) << (32 - 5); break; case 3: if (insn != 0xd61f0200) goto not_plt; break; default: return value; /* to avoid any warnings */ } } return addr; not_plt: return value; } /* * Filter dissassembly output if the output radix is not gdb's default 10 */ static int arm64_dis_filter(ulong vaddr, char *inbuf, unsigned int output_radix) { char buf1[BUFSIZE]; char buf2[BUFSIZE]; char *colon, *p1; int argc; char *argv[MAXARGS]; ulong value; if (!inbuf) return TRUE; console("IN: %s", inbuf); colon = strstr(inbuf, ":"); if (colon) { sprintf(buf1, "0x%lx <%s>", vaddr, value_to_symstr(vaddr, buf2, output_radix)); sprintf(buf2, "%s%s", buf1, colon); strcpy(inbuf, buf2); } strcpy(buf1, inbuf); argc = parse_line(buf1, argv); if ((FIRSTCHAR(argv[argc-1]) == '<') && (LASTCHAR(argv[argc-1]) == '>')) { p1 = rindex(inbuf, '<'); while ((p1 > inbuf) && !(STRNEQ(p1, " 0x") || STRNEQ(p1, "\t0x"))) p1--; if (!(STRNEQ(p1, " 0x") || STRNEQ(p1, "\t0x"))) return FALSE; p1++; if (!extract_hex(p1, &value, NULLCHAR, TRUE)) return FALSE; sprintf(buf1, "0x%lx <%s>\n", value, value_to_symstr(value, buf2, output_radix)); sprintf(p1, "%s", buf1); } if (IS_MODULE_VADDR(vaddr)) { ulong orig_value; p1 = &inbuf[strlen(inbuf)-1]; strcpy(buf1, inbuf); argc = parse_line(buf1, argv); if ((STREQ(argv[argc-2], "b") || STREQ(argv[argc-2], "bl")) && extract_hex(argv[argc-1], &orig_value, NULLCHAR, TRUE)) { value = PLT_veneer_to_kvaddr(orig_value); sprintf(p1, " <%s%s>\n", value == orig_value ? "" : "plt:", value_to_symstr(value, buf2, output_radix)); } } console(" %s", inbuf); return TRUE; } /* * Machine dependent command. */ static void arm64_cmd_mach(void) { int c; while ((c = getopt(argcnt, args, "cm")) != -1) { switch (c) { case 'c': case 'm': option_not_supported(c); break; default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); arm64_display_machine_stats(); } static void arm64_display_machine_stats(void) { int i, pad; struct new_utsname *uts; char buf[BUFSIZE]; ulong mhz; uts = &kt->utsname; fprintf(fp, " MACHINE TYPE: %s\n", uts->machine); fprintf(fp, " MEMORY SIZE: %s\n", get_memory_size(buf)); fprintf(fp, " CPUS: %d\n", get_cpus_to_display()); if ((mhz = machdep->processor_speed())) fprintf(fp, " PROCESSOR SPEED: %ld Mhz\n", mhz); fprintf(fp, " HZ: %d\n", machdep->hz); fprintf(fp, " PAGE SIZE: %d\n", PAGESIZE()); fprintf(fp, "KERNEL VIRTUAL BASE: %lx\n", machdep->machspec->page_offset); fprintf(fp, "KERNEL MODULES BASE: %lx\n", machdep->machspec->modules_vaddr); fprintf(fp, "KERNEL VMALLOC BASE: %lx\n", machdep->machspec->vmalloc_start_addr); fprintf(fp, "KERNEL VMEMMAP BASE: %lx\n", machdep->machspec->vmemmap_vaddr); fprintf(fp, " KERNEL STACK SIZE: %ld\n", STACKSIZE()); if (machdep->machspec->irq_stack_size) { fprintf(fp, " IRQ STACK SIZE: %ld\n", machdep->machspec->irq_stack_size); fprintf(fp, " IRQ STACKS:\n"); for (i = 0; i < kt->cpus; i++) { pad = (i < 10) ? 3 : (i < 100) ? 2 : (i < 1000) ? 1 : 0; fprintf(fp, "%s CPU %d: %lx\n", space(pad), i, machdep->machspec->irq_stacks[i]); } } if (machdep->machspec->overflow_stack_size) { fprintf(fp, "OVERFLOW STACK SIZE: %ld\n", machdep->machspec->overflow_stack_size); fprintf(fp, " OVERFLOW STACKS:\n"); for (i = 0; i < kt->cpus; i++) { pad = (i < 10) ? 3 : (i < 100) ? 2 : (i < 1000) ? 1 : 0; fprintf(fp, "%s CPU %d: %lx\n", space(pad), i, machdep->machspec->overflow_stacks[i]); } } } static int arm64_get_smp_cpus(void) { int cpus; if ((cpus = get_cpus_present())) return cpus; else return MAX(get_cpus_online(), get_highest_cpu_online()+1); } /* * Retrieve task registers for the time of the crash. */ static void arm64_get_crash_notes(void) { struct machine_specific *ms = machdep->machspec; ulong crash_notes; Elf64_Nhdr *note = NULL; ulong offset; char *buf, *p; ulong *notes_ptrs; ulong i, found; if (!symbol_exists("crash_notes")) { if (DISKDUMP_DUMPFILE() || KDUMP_DUMPFILE()) { if (!(ms->panic_task_regs = calloc((size_t)kt->cpus, sizeof(struct arm64_pt_regs)))) error(FATAL, "cannot calloc panic_task_regs space\n"); for (i = found = 0; i < kt->cpus; i++) { if (DISKDUMP_DUMPFILE()) note = diskdump_get_prstatus_percpu(i); else if (KDUMP_DUMPFILE()) note = netdump_get_prstatus_percpu(i); if (!note) { error(WARNING, "cpu %d: cannot find NT_PRSTATUS note\n", i); continue; } /* * Find correct location of note data. This contains elf_prstatus * structure which has registers etc. for the crashed task. */ offset = sizeof(Elf64_Nhdr); offset = roundup(offset + note->n_namesz, 4); p = (char *)note + offset; /* start of elf_prstatus */ BCOPY(p + OFFSET(elf_prstatus_pr_reg), &ms->panic_task_regs[i], sizeof(struct arm64_pt_regs)); found++; } if (!found) { free(ms->panic_task_regs); ms->panic_task_regs = NULL; } } return; } crash_notes = symbol_value("crash_notes"); notes_ptrs = (ulong *)GETBUF(kt->cpus*sizeof(notes_ptrs[0])); /* * Read crash_notes for the first CPU. crash_notes are in standard ELF * note format. */ if (!readmem(crash_notes, KVADDR, ¬es_ptrs[kt->cpus-1], sizeof(notes_ptrs[kt->cpus-1]), "crash_notes", RETURN_ON_ERROR)) { error(WARNING, "cannot read \"crash_notes\"\n"); FREEBUF(notes_ptrs); return; } if (symbol_exists("__per_cpu_offset")) { /* * Add __per_cpu_offset for each cpu to form the notes pointer. */ for (i = 0; icpus; i++) notes_ptrs[i] = notes_ptrs[kt->cpus-1] + kt->__per_cpu_offset[i]; } buf = GETBUF(SIZE(note_buf)); if (!(ms->panic_task_regs = calloc((size_t)kt->cpus, sizeof(struct arm64_pt_regs)))) error(FATAL, "cannot calloc panic_task_regs space\n"); for (i = found = 0; i < kt->cpus; i++) { if (!readmem(notes_ptrs[i], KVADDR, buf, SIZE(note_buf), "note_buf_t", RETURN_ON_ERROR)) { error(WARNING, "cpu %d: cannot read NT_PRSTATUS note\n", i); continue; } /* * Do some sanity checks for this note before reading registers from it. */ note = (Elf64_Nhdr *)buf; p = buf + sizeof(Elf64_Nhdr); /* * dumpfiles created with qemu won't have crash_notes, but there will * be elf notes; dumpfiles created by kdump do not create notes for * offline cpus. */ if (note->n_namesz == 0 && (DISKDUMP_DUMPFILE() || KDUMP_DUMPFILE())) { if (DISKDUMP_DUMPFILE()) note = diskdump_get_prstatus_percpu(i); else if (KDUMP_DUMPFILE()) note = netdump_get_prstatus_percpu(i); if (note) { /* * SIZE(note_buf) accounts for a "final note", which is a * trailing empty elf note header. */ long notesz = SIZE(note_buf) - sizeof(Elf64_Nhdr); if (sizeof(Elf64_Nhdr) + roundup(note->n_namesz, 4) + note->n_descsz == notesz) BCOPY((char *)note, buf, notesz); } else { error(WARNING, "cpu %d: cannot find NT_PRSTATUS note\n", i); continue; } } /* * Check the sanity of NT_PRSTATUS note only for each online cpu. * If this cpu has invalid note, continue to find the crash notes * for other online cpus. */ if (note->n_type != NT_PRSTATUS) { error(WARNING, "cpu %d: invalid NT_PRSTATUS note (n_type != NT_PRSTATUS)\n", i); continue; } if (!STRNEQ(p, "CORE")) { error(WARNING, "cpu %d: invalid NT_PRSTATUS note (name != \"CORE\")\n", i); continue; } /* * Find correct location of note data. This contains elf_prstatus * structure which has registers etc. for the crashed task. */ offset = sizeof(Elf64_Nhdr); offset = roundup(offset + note->n_namesz, 4); p = buf + offset; /* start of elf_prstatus */ BCOPY(p + OFFSET(elf_prstatus_pr_reg), &ms->panic_task_regs[i], sizeof(struct arm64_pt_regs)); found++; } FREEBUF(buf); FREEBUF(notes_ptrs); if (!found) { free(ms->panic_task_regs); ms->panic_task_regs = NULL; } } static void arm64_clear_machdep_cache(void) { /* * TBD: probably not necessary... */ return; } static int arm64_on_process_stack(struct bt_info *bt, ulong stkptr) { ulong stackbase, stacktop; stackbase = GET_STACKBASE(bt->task); stacktop = GET_STACKTOP(bt->task); if ((stkptr >= stackbase) && (stkptr < stacktop)) return TRUE; return FALSE; } static int arm64_in_alternate_stackv(int cpu, ulong stkptr, ulong *stacks, ulong stack_size) { if ((cpu >= kt->cpus) || (stacks == NULL) || !stack_size) return FALSE; if ((stkptr >= stacks[cpu]) && (stkptr < (stacks[cpu] + stack_size))) return TRUE; return FALSE; } static int arm64_in_alternate_stack(int cpu, ulong stkptr) { return (arm64_on_irq_stack(cpu, stkptr) || arm64_on_overflow_stack(cpu, stkptr)); } static int arm64_on_irq_stack(int cpu, ulong stkptr) { struct machine_specific *ms = machdep->machspec; return arm64_in_alternate_stackv(cpu, stkptr, ms->irq_stacks, ms->irq_stack_size); } static int arm64_on_overflow_stack(int cpu, ulong stkptr) { struct machine_specific *ms = machdep->machspec; return arm64_in_alternate_stackv(cpu, stkptr, ms->overflow_stacks, ms->overflow_stack_size); } static void arm64_set_irq_stack(struct bt_info *bt) { struct machine_specific *ms = machdep->machspec; bt->stackbase = ms->irq_stacks[bt->tc->processor]; bt->stacktop = bt->stackbase + ms->irq_stack_size; alter_stackbuf(bt); } static void arm64_set_overflow_stack(struct bt_info *bt) { struct machine_specific *ms = machdep->machspec; bt->stackbase = ms->overflow_stacks[bt->tc->processor]; bt->stacktop = bt->stackbase + ms->overflow_stack_size; alter_stackbuf(bt); } static void arm64_set_process_stack(struct bt_info *bt) { bt->stackbase = GET_STACKBASE(bt->task); bt->stacktop = GET_STACKTOP(bt->task); alter_stackbuf(bt); } static int compare_kvaddr(const void *v1, const void *v2) { struct vaddr_range *r1, *r2; r1 = (struct vaddr_range *)v1; r2 = (struct vaddr_range *)v2; return (r1->start < r2->start ? -1 : r1->start == r2->start ? 0 : 1); } static int arm64_get_kvaddr_ranges(struct vaddr_range *vrp) { int cnt; cnt = 0; vrp[cnt].type = KVADDR_UNITY_MAP; vrp[cnt].start = machdep->machspec->page_offset; vrp[cnt++].end = vt->high_memory; vrp[cnt].type = KVADDR_VMALLOC; vrp[cnt].start = machdep->machspec->vmalloc_start_addr; vrp[cnt++].end = last_vmalloc_address(); if (st->mods_installed) { vrp[cnt].type = KVADDR_MODULES; vrp[cnt].start = lowest_module_address(); vrp[cnt++].end = roundup(highest_module_address(), PAGESIZE()); } if (machdep->flags & VMEMMAP) { vrp[cnt].type = KVADDR_VMEMMAP; vrp[cnt].start = machdep->machspec->vmemmap_vaddr; vrp[cnt++].end = vt->node_table[vt->numnodes-1].mem_map + (vt->node_table[vt->numnodes-1].size * SIZE(page)); } qsort(vrp, cnt, sizeof(struct vaddr_range), compare_kvaddr); return cnt; } /* * Include both vmalloc'd, module and vmemmap address space as VMALLOC space. */ int arm64_IS_VMALLOC_ADDR(ulong vaddr) { struct machine_specific *ms = machdep->machspec; if (is_mte_kvaddr(vaddr)) vaddr = mte_tag_reset(vaddr); if ((machdep->flags & NEW_VMEMMAP) && (vaddr >= machdep->machspec->kimage_text) && (vaddr <= machdep->machspec->kimage_end)) return FALSE; if (ms->VA_START && (vaddr >= ms->VA_START)) return TRUE; return ((vaddr >= ms->vmalloc_start_addr && vaddr <= ms->vmalloc_end) || ((machdep->flags & VMEMMAP) && ((vaddr >= ms->vmemmap_vaddr && vaddr <= ms->vmemmap_end) || (vaddr >= ms->vmalloc_end && vaddr <= ms->vmemmap_vaddr))) || (vaddr >= ms->modules_vaddr && vaddr <= ms->modules_end)); } /* Return TRUE if we succeed, return FALSE on failure. */ static int arm64_set_va_bits_by_tcr(void) { ulong value; if (arm64_get_vmcoreinfo(&value, "NUMBER(TCR_EL1_T1SZ)", NUM_HEX) || arm64_get_vmcoreinfo(&value, "NUMBER(tcr_el1_t1sz)", NUM_HEX)) { /* See ARMv8 ARM for the description of * TCR_EL1.T1SZ and how it can be used * to calculate the vabits_actual * supported by underlying kernel. * * Basically: * vabits_actual = 64 - T1SZ; */ value = 64 - value; if (CRASHDEBUG(1)) fprintf(fp, "vmcoreinfo : vabits_actual: %ld\n", value); machdep->machspec->VA_BITS_ACTUAL = value; machdep->machspec->VA_BITS = value; machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL); return TRUE; } return FALSE; } static void arm64_calc_VA_BITS(void) { int bitval; struct syment *sp; ulong vabits_actual, value; arm64_get_vmcoreinfo(&machdep->machspec->CONFIG_ARM64_VA_BITS, "NUMBER(VA_BITS)", NUM_DEC); if (kernel_symbol_exists("vabits_actual")) { if (pc->flags & PROC_KCORE) { vabits_actual = symbol_value_from_proc_kallsyms("vabits_actual"); if ((vabits_actual != BADVAL) && (READMEM(pc->mfd, &value, sizeof(ulong), vabits_actual, KCORE_USE_VADDR) > 0)) { if (CRASHDEBUG(1)) fprintf(fp, "/proc/kcore: vabits_actual: %ld\n", value); machdep->machspec->VA_BITS_ACTUAL = value; machdep->machspec->VA_BITS = value; machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL); } else error(FATAL, "/proc/kcore: cannot read vabits_actual\n"); } else if (ACTIVE()) error(FATAL, "cannot determine VA_BITS_ACTUAL: please use /proc/kcore\n"); else { if (arm64_set_va_bits_by_tcr()) { /* nothing */ } else if (machdep->machspec->VA_BITS_ACTUAL) { machdep->machspec->VA_BITS = machdep->machspec->VA_BITS_ACTUAL; machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL); } else if (machdep->machspec->CONFIG_ARM64_VA_BITS) { /* guess */ machdep->machspec->VA_BITS_ACTUAL = machdep->machspec->CONFIG_ARM64_VA_BITS; machdep->machspec->VA_BITS = machdep->machspec->CONFIG_ARM64_VA_BITS; machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL); } else error(FATAL, "cannot determine VA_BITS_ACTUAL\n"); } if (machdep->machspec->CONFIG_ARM64_VA_BITS) machdep->machspec->VA_BITS = machdep->machspec->CONFIG_ARM64_VA_BITS; /* * The mm flip commit is introduced before 52-bits VA, which is before the * commit to export NUMBER(TCR_EL1_T1SZ) */ machdep->flags |= FLIPPED_VM; return; } else if (arm64_set_va_bits_by_tcr()) { return; } else if (machdep->machspec->VA_BITS_ACTUAL) { machdep->machspec->VA_BITS = machdep->machspec->VA_BITS_ACTUAL; machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL); return; } if (!(sp = symbol_search("swapper_pg_dir")) && !(sp = symbol_search("idmap_pg_dir")) && !(sp = symbol_search("_text")) && !(sp = symbol_search("stext"))) { for (sp = st->symtable; sp < st->symend; sp++) { if (highest_bit_long(sp->value) == 63) break; } } if (sp) value = sp->value; else value = kt->vmcoreinfo.log_buf_SYMBOL; /* crash --log */ for (bitval = highest_bit_long(value); bitval; bitval--) { if ((value & (1UL << bitval)) == 0) { if (machdep->flags & NEW_VMEMMAP) machdep->machspec->VA_BITS = bitval + 1; else machdep->machspec->VA_BITS = bitval + 2; break; } } /* * Verify against dumpfiles that export VA_BITS in vmcoreinfo */ if (machdep->machspec->CONFIG_ARM64_VA_BITS && (machdep->machspec->VA_BITS != machdep->machspec->CONFIG_ARM64_VA_BITS)) { error(WARNING, "VA_BITS: calculated: %ld vmcoreinfo: %ld\n", machdep->machspec->VA_BITS, machdep->machspec->CONFIG_ARM64_VA_BITS); machdep->machspec->VA_BITS = machdep->machspec->CONFIG_ARM64_VA_BITS; } if (CRASHDEBUG(1)) fprintf(fp, "VA_BITS: %ld\n", machdep->machspec->VA_BITS); } /* * The size and end of the vmalloc range is dependent upon the kernel's * VMEMMAP_SIZE value, and the vmemmap range is dependent upon the end * of the vmalloc range as well as the VMEMMAP_SIZE: * * #define VMEMMAP_SIZE ALIGN((1UL << (VA_BITS - PAGE_SHIFT)) * sizeof(struct page), PUD_SIZE) * #define VMALLOC_START (UL(0xffffffffffffffff) << VA_BITS) * #define VMALLOC_END (PAGE_OFFSET - PUD_SIZE - VMEMMAP_SIZE - SZ_64K) * * Since VMEMMAP_SIZE is dependent upon the size of a struct page, * the two ranges cannot be determined until POST_GDB. * * Since 52-bit VA was introduced: * * #define STRUCT_PAGE_MAX_SHIFT 6 * #define VMEMMAP_SIZE (UL(1) << (VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT)) * #define VMEMMAP_START (-VMEMMAP_SIZE) * #define VMALLOC_START (MODULES_END) * #define VMALLOC_END (- PUD_SIZE - VMEMMAP_SIZE - SZ_64K) * #define vmemmap ((struct page *)VMEMMAP_START - (memstart_addr >> PAGE_SHIFT)) */ #define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) #define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) static void arm64_calc_virtual_memory_ranges(void) { struct machine_specific *ms = machdep->machspec; ulong value, vmemmap_start, vmemmap_end, vmemmap_size, vmalloc_end; char *string; int ret; ulong PUD_SIZE = UNINITIALIZED; if (!machdep->machspec->CONFIG_ARM64_VA_BITS) { if (arm64_get_vmcoreinfo(&value, "NUMBER(VA_BITS)", NUM_DEC)) { machdep->machspec->CONFIG_ARM64_VA_BITS = value; } else if (kt->ikconfig_flags & IKCONFIG_AVAIL) { if ((ret = get_kernel_config("CONFIG_ARM64_VA_BITS", &string)) == IKCONFIG_STR) machdep->machspec->CONFIG_ARM64_VA_BITS = atol(string); } } if (THIS_KERNEL_VERSION < LINUX(3,17,0)) /* use original hardwired values */ return; STRUCT_SIZE_INIT(page, "page"); ms->struct_page_size = SIZE(page); switch (machdep->flags & (VM_L2_64K|VM_L3_64K|VM_L3_4K|VM_L4_4K)) { case VM_L2_64K: case VM_L3_64K: PUD_SIZE = PGDIR_SIZE_L2_64K; break; case VM_L3_4K: PUD_SIZE = PGDIR_SIZE_L3_4K; case VM_L4_4K: PUD_SIZE = PUD_SIZE_L4_4K; break; } #define STRUCT_PAGE_MAX_SHIFT 6 if (ms->VA_BITS_ACTUAL) { ulong va_bits_min = 48; if (machdep->machspec->CONFIG_ARM64_VA_BITS < 48) va_bits_min = ms->CONFIG_ARM64_VA_BITS; vmemmap_size = (1UL) << (va_bits_min - machdep->pageshift - 1 + STRUCT_PAGE_MAX_SHIFT); vmalloc_end = (- PUD_SIZE - vmemmap_size - KILOBYTES(64)); vmemmap_start = (-vmemmap_size - MEGABYTES(2)); ms->vmalloc_end = vmalloc_end - 1; ms->vmemmap_vaddr = vmemmap_start; ms->vmemmap_end = vmemmap_start + vmemmap_size; return; } if (machdep->flags & NEW_VMEMMAP) vmemmap_size = 1UL << (ms->VA_BITS - machdep->pageshift - 1 + STRUCT_PAGE_MAX_SHIFT); else vmemmap_size = ALIGN((1UL << (ms->VA_BITS - machdep->pageshift)) * SIZE(page), PUD_SIZE); vmalloc_end = (ms->page_offset - PUD_SIZE - vmemmap_size - SZ_64K); if (machdep->flags & NEW_VMEMMAP) { vmemmap_start = ms->page_offset - vmemmap_size; vmemmap_end = ms->page_offset; } else { vmemmap_start = vmalloc_end + SZ_64K; vmemmap_end = vmemmap_start + vmemmap_size; } ms->vmalloc_end = vmalloc_end - 1; ms->vmemmap_vaddr = vmemmap_start; ms->vmemmap_end = vmemmap_end - 1; } static int arm64_is_uvaddr(ulong addr, struct task_context *tc) { return (addr < machdep->machspec->userspace_top); } ulong arm64_swp_type(ulong pte) { struct machine_specific *ms = machdep->machspec; pte >>= ms->__SWP_TYPE_SHIFT; pte &= ms->__SWP_TYPE_MASK; return pte; } ulong arm64_swp_offset(ulong pte) { struct machine_specific *ms = machdep->machspec; pte >>= ms->__SWP_OFFSET_SHIFT; if (ms->__SWP_OFFSET_MASK) pte &= ms->__SWP_OFFSET_MASK; return pte; } static void arm64_calc_KERNELPACMASK(void) { ulong value; if (arm64_get_vmcoreinfo(&value, "NUMBER(KERNELPACMASK)", NUM_HEX)) { machdep->machspec->CONFIG_ARM64_KERNELPACMASK = value; if (CRASHDEBUG(1)) fprintf(fp, "CONFIG_ARM64_KERNELPACMASK: %lx\n", value); } } #define GENMASK_UL(h, l) \ (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) static void arm64_recalc_KERNELPACMASK(void){ /* * Check if PAC is enabled according to the existence of * kernel symbol 'ptrauth_keys_kernel'. */ if (STRUCT_EXISTS("ptrauth_keys_kernel") && machdep->machspec->VA_BITS_ACTUAL){ machdep->machspec->CONFIG_ARM64_KERNELPACMASK = GENMASK_UL(63, machdep->machspec->VA_BITS_ACTUAL); if (CRASHDEBUG(1)) fprintf(fp, "CONFIG_ARM64_KERNELPACMASK: %lx\n", machdep->machspec->CONFIG_ARM64_KERNELPACMASK); } } static ulong arm64_set_irq_stack_size(void) { int min_thread_shift = 14; ulong thread_shift = 0; char buf1[BUFSIZE]; char *pos1, *pos2; int errflag = 0; if (kernel_symbol_exists("vmcoreinfo_data") && kernel_symbol_exists("vmcoreinfo_size")) { /* * Referring to arch/arm64/include/asm/memory.h */ if (kernel_symbol_exists("kasan_enable_current")) min_thread_shift += 1; if (MEMBER_EXISTS("task_struct", "stack_vm_area") && (min_thread_shift < machdep->pageshift)) thread_shift = machdep->pageshift; else thread_shift = min_thread_shift; } else { sprintf(buf1, "x/32i vectors"); open_tmpfile(); if (!gdb_pass_through(buf1, pc->tmpfile, GNU_RETURN_ON_ERROR)) goto out; rewind(pc->tmpfile); while (fgets(buf1, BUFSIZE, pc->tmpfile)) { if ((pos1 = strstr(buf1, "tbnz"))) { if ((pos2 = strchr(pos1, '#'))) { pos2 += 1; for (pos1 = pos2; *pos2 != '\0' && *pos2 != ','; pos2++); *pos2 = '\0'; thread_shift = stol(pos1, RETURN_ON_ERROR|QUIET, &errflag); if (errflag) thread_shift = 0; break; } } } out: close_tmpfile(); } if (thread_shift) return ((1UL) << thread_shift); return 0; } #endif /* ARM64 */ crash-utility-crash-61fe107/bpf.c000066400000000000000000001206651517256214500167010ustar00rootroot00000000000000/* bpf.c - core analysis suite * * Copyright (C) 2018 David Anderson * Copyright (C) 2018 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #include "defs.h" struct bpf_info { ulong status; ulong progs, maps; struct list_pair *proglist; struct list_pair *maplist; char *bpf_prog_buf; char *bpf_prog_aux_buf; char *bpf_map_buf; char *bytecode_buf; int bpf_prog_type_size; int bpf_map_map_type_size; int idr_type; #define IDR_ORIG (1) #define IDR_RADIX (2) #define IDR_XARRAY (3) char prog_hdr1[81]; char map_hdr1[81]; } bpf_info = { .status = UNINITIALIZED, }; static void do_bpf(ulong, ulong, ulong, int); static void bpf_init(struct bpf_info *); static int bpf_type_size_init(void); static char *bpf_prog_type_string(int, char *); static char *bpf_map_map_type_string(int, char *); static char *bpf_prog_used_maps(int, char *); static char *bpf_prog_tag_string(char *, char *); static void bpf_prog_gpl_compatible(char *, ulong); static void dump_xlated_plain(void *, unsigned int, int); static void print_boot_time(unsigned long long, char *, unsigned int); static int do_old_idr(int, ulong, struct list_pair *); #define IDR_ORIG_INIT (1) #define IDR_ORIG_COUNT (2) #define IDR_ORIG_GATHER (3) #define PROG_ID (0x1) #define MAP_ID (0x2) #define DUMP_STRUCT (0x4) #define JITED (0x8) #define XLATED (0x10) #define OPCODES (0x20) #define PROG_VERBOSE (0x40) #define MAP_VERBOSE (0x80) static int map_is_per_cpu(int type) { /* See the definition of bpf_map_type: include/uapi/linux/bpf.h */ #define BPF_MAP_TYPE_PERCPU_HASH (5UL) #define BPF_MAP_TYPE_PERCPU_ARRAY (6UL) #define BPF_MAP_TYPE_LRU_PERCPU_HASH (10UL) #define BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE (21UL) return type == BPF_MAP_TYPE_PERCPU_HASH || type == BPF_MAP_TYPE_PERCPU_ARRAY || type == BPF_MAP_TYPE_LRU_PERCPU_HASH || type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE; } static int map_is_fd_map(int type) { /* See the definition of bpf_map_type: include/uapi/linux/bpf.h */ #define BPF_MAP_TYPE_PROG_ARRAY (3UL) #define BPF_MAP_TYPE_PERF_EVENT_ARRAY (4UL) #define BPF_MAP_TYPE_CGROUP_ARRAY (8UL) #define BPF_MAP_TYPE_ARRAY_OF_MAPS (12UL) #define BPF_MAP_TYPE_HASH_OF_MAPS (13UL) return type == BPF_MAP_TYPE_PROG_ARRAY || type == BPF_MAP_TYPE_PERF_EVENT_ARRAY || type == BPF_MAP_TYPE_CGROUP_ARRAY || type == BPF_MAP_TYPE_ARRAY_OF_MAPS || type == BPF_MAP_TYPE_HASH_OF_MAPS; } static ulong bpf_map_memory_size(int map_type, uint value_size, uint key_size, uint max_entries) { ulong size; uint valsize; int cpus = 0; if (map_is_per_cpu(map_type)) { cpus = get_cpus_possible(); if (!cpus) { error(WARNING, "cpu_possible_map does not exist, possible cpus: %d\n", cpus); return 0; } valsize = roundup(value_size, 8) * cpus; } else if (map_is_fd_map(map_type)) valsize = sizeof(uint); else valsize = value_size; size = roundup((key_size + valsize), 8); return roundup((max_entries * size), PAGESIZE()); } /* * Code replicated from kernel/bpf/ringbuf.c:ringbuf_map_mem_usage() */ static ulong ringbuf_map_mem_usage(struct bpf_info *bpf, int i) { ulong nr_pages; ulong usage = SIZE(bpf_ringbuf_map); ulong rb = (ulong)(bpf->maplist[i].value) - OFFSET(bpf_ringbuf_map_map) + OFFSET(bpf_ringbuf_map_rb); readmem(rb, KVADDR, &rb, sizeof(ulong), "bpf_ringbuf *", FAULT_ON_ERROR); readmem(rb + OFFSET(bpf_ringbuf_nr_pages), KVADDR, &nr_pages, sizeof(ulong), "bpf_ringbuf.nr_pages", FAULT_ON_ERROR); usage += (nr_pages << PAGESHIFT()); ulong nr_meta_pages = (OFFSET(bpf_ringbuf_consumer_pos) >> PAGESHIFT()) + 2; ulong nr_data_pages = UINT(bpf->bpf_map_buf + OFFSET(bpf_map_max_entries)) >> PAGESHIFT(); usage += (nr_meta_pages + 2 * nr_data_pages) * sizeof(void *); return usage; } void cmd_bpf(void) { int c, radix; ulong flags, prog_id, map_id; flags = prog_id = map_id = radix = 0; while ((c = getopt(argcnt, args, "PMtTjsxdm:p:")) != EOF) { switch(c) { case 'j': flags |= JITED; break; case 'T': flags |= (XLATED|OPCODES); break; case 't': flags |= XLATED; break; case 'm': map_id = stol(optarg, FAULT_ON_ERROR, NULL); flags |= MAP_ID; break; case 'p': prog_id = stol(optarg, FAULT_ON_ERROR, NULL); flags |= PROG_ID; break; case 's': flags |= DUMP_STRUCT; break; case 'P': flags |= PROG_VERBOSE; break; case 'M': flags |= MAP_VERBOSE; break; case 'x': if (radix == 10) error(FATAL, "-d and -x are mutually exclusive\n"); radix = 16; break; case 'd': if (radix == 16) error(FATAL, "-d and -x are mutually exclusive\n"); radix = 16; break; default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); if ((flags & JITED) && !(flags & (PROG_ID|PROG_VERBOSE))) error(FATAL, "-j option only applicable with -p or -P\n"); if ((flags & XLATED) && !(flags & (PROG_ID|PROG_VERBOSE))) error(FATAL, "-t option only applicable with -p or -P\n"); if ((flags & DUMP_STRUCT) && !(flags & (PROG_ID|PROG_VERBOSE|MAP_ID|MAP_VERBOSE))) error(FATAL, "-s option requires either -p, -P, -m or -M\n"); if (radix && !(flags & (PROG_ID|PROG_VERBOSE|MAP_ID|MAP_VERBOSE))) error(FATAL, "-%c option requires -s\n", radix == 10 ? 'd' : 'x'); while (args[optind]) { error(FATAL, "invalid argument: %s\n", args[optind]); optind++; } do_bpf(flags, prog_id, map_id, radix); } static void bpf_init(struct bpf_info *bpf) { long len; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char buf3[BUFSIZE]; char buf4[BUFSIZE]; switch (bpf->status) { case UNINITIALIZED: if (!kernel_symbol_exists("prog_idr") || !kernel_symbol_exists("map_idr")) { bpf->status = FALSE; command_not_supported(); } STRUCT_SIZE_INIT(bpf_prog, "bpf_prog"); STRUCT_SIZE_INIT(bpf_prog_aux, "bpf_prog_aux"); STRUCT_SIZE_INIT(bpf_map, "bpf_map"); STRUCT_SIZE_INIT(bpf_insn, "bpf_insn"); STRUCT_SIZE_INIT(bpf_ringbuf_map, "bpf_ringbuf_map"); MEMBER_OFFSET_INIT(bpf_prog_aux, "bpf_prog", "aux"); MEMBER_OFFSET_INIT(bpf_prog_type, "bpf_prog", "type"); MEMBER_OFFSET_INIT(bpf_prog_tag, "bpf_prog", "tag"); MEMBER_OFFSET_INIT(bpf_prog_jited_len, "bpf_prog", "jited_len"); MEMBER_OFFSET_INIT(bpf_prog_bpf_func, "bpf_prog", "bpf_func"); MEMBER_OFFSET_INIT(bpf_prog_len, "bpf_prog", "len"); MEMBER_OFFSET_INIT(bpf_prog_insnsi, "bpf_prog", "insnsi"); MEMBER_OFFSET_INIT(bpf_map_map_type, "bpf_map", "map_type"); MEMBER_OFFSET_INIT(bpf_map_map_flags, "bpf_map", "map_flags"); MEMBER_OFFSET_INIT(bpf_prog_aux_used_maps, "bpf_prog_aux", "used_maps"); MEMBER_OFFSET_INIT(bpf_prog_aux_used_map_cnt, "bpf_prog_aux", "used_map_cnt"); MEMBER_OFFSET_INIT(bpf_ringbuf_map_map, "bpf_ringbuf_map", "map"); MEMBER_OFFSET_INIT(bpf_ringbuf_map_rb, "bpf_ringbuf_map", "rb"); MEMBER_OFFSET_INIT(bpf_ringbuf_consumer_pos, "bpf_ringbuf", "consumer_pos"); MEMBER_OFFSET_INIT(bpf_ringbuf_nr_pages, "bpf_ringbuf", "nr_pages"); if (!VALID_STRUCT(bpf_prog) || !VALID_STRUCT(bpf_prog_aux) || !VALID_STRUCT(bpf_map) || !VALID_STRUCT(bpf_insn) || INVALID_MEMBER(bpf_prog_aux) || INVALID_MEMBER(bpf_prog_type) || INVALID_MEMBER(bpf_prog_tag) || INVALID_MEMBER(bpf_prog_jited_len) || INVALID_MEMBER(bpf_prog_bpf_func) || INVALID_MEMBER(bpf_prog_len) || INVALID_MEMBER(bpf_prog_insnsi) || INVALID_MEMBER(bpf_map_map_flags) || INVALID_MEMBER(bpf_map_map_type) || INVALID_MEMBER(bpf_prog_aux_used_maps) || INVALID_MEMBER(bpf_prog_aux_used_map_cnt)) { bpf->status = FALSE; command_not_supported(); } /* * Not required for basic functionality */ MEMBER_OFFSET_INIT(bpf_prog_pages, "bpf_prog", "pages"); MEMBER_OFFSET_INIT(bpf_prog_aux_load_time, "bpf_prog_aux", "load_time"); MEMBER_OFFSET_INIT(bpf_prog_aux_user, "bpf_prog_aux", "user"); MEMBER_OFFSET_INIT(bpf_prog_aux_name, "bpf_prog_aux", "name"); MEMBER_OFFSET_INIT(bpf_map_key_size, "bpf_map", "key_size"); MEMBER_OFFSET_INIT(bpf_map_value_size, "bpf_map", "value_size"); MEMBER_OFFSET_INIT(bpf_map_max_entries, "bpf_map", "max_entries"); MEMBER_OFFSET_INIT(bpf_map_pages, "bpf_map", "pages"); MEMBER_OFFSET_INIT(bpf_map_name, "bpf_map", "name"); MEMBER_OFFSET_INIT(bpf_map_user, "bpf_map", "user"); MEMBER_OFFSET_INIT(user_struct_uid, "user_struct", "uid"); /* Linux 5.3 */ MEMBER_OFFSET_INIT(bpf_map_memory, "bpf_map", "memory"); if (VALID_MEMBER(bpf_map_memory)) { MEMBER_OFFSET_INIT(bpf_map_memory_pages, "bpf_map_memory", "pages"); MEMBER_OFFSET_INIT(bpf_map_memory_user, "bpf_map_memory", "user"); } if (!bpf_type_size_init()) { bpf->status = FALSE; command_not_supported(); } sprintf(bpf->prog_hdr1, "%s %s %s %s ", mkstring(buf1, 4, CENTER|LJUST, "ID"), mkstring(buf2, VADDR_PRLEN, CENTER|LJUST, "BPF_PROG"), mkstring(buf3, VADDR_PRLEN, CENTER|LJUST, "BPF_PROG_AUX"), mkstring(buf4, bpf->bpf_prog_type_size, CENTER|LJUST, "BPF_PROG_TYPE")); strcat(bpf->prog_hdr1, " TAG USED_MAPS"); sprintf(bpf->map_hdr1, "%s %s %s MAP_FLAGS", mkstring(buf1, 4, CENTER|LJUST, "ID"), mkstring(buf2, VADDR_PRLEN, CENTER|LJUST, "BPF_MAP"), mkstring(buf3, bpf->bpf_map_map_type_size, CENTER|LJUST, "BPF_MAP_TYPE")); if (INVALID_MEMBER(idr_idr_rt)) { bpf->idr_type = IDR_ORIG; do_old_idr(IDR_ORIG_INIT, 0, NULL); } else if (STREQ(MEMBER_TYPE_NAME("idr", "idr_rt"), "radix_tree_root")) if (MEMBER_EXISTS("radix_tree_root", "rnode")) bpf->idr_type = IDR_RADIX; else if (MEMBER_EXISTS("radix_tree_root", "xa_head")) bpf->idr_type = IDR_XARRAY; else error(FATAL, "cannot determine IDR list type\n"); else if (STREQ(MEMBER_TYPE_NAME("idr", "idr_rt"), "xarray")) bpf->idr_type = IDR_XARRAY; else error(FATAL, "cannot determine IDR list type\n"); bpf->status = TRUE; break; case TRUE: break; case FALSE: command_not_supported(); } switch (bpf->idr_type) { case IDR_ORIG: bpf->progs = do_old_idr(IDR_ORIG_COUNT, symbol_value("prog_idr"), NULL); break; case IDR_RADIX: bpf->progs = do_radix_tree(symbol_value("prog_idr") + OFFSET(idr_idr_rt), RADIX_TREE_COUNT, NULL); break; case IDR_XARRAY: bpf->progs = do_xarray(symbol_value("prog_idr") + OFFSET(idr_idr_rt), XARRAY_COUNT, NULL); break; } if (bpf->progs) { len = sizeof(struct list_pair) * (bpf->progs+1); bpf->proglist = (struct list_pair *)GETBUF(len); bpf->proglist[0].index = bpf->progs; switch (bpf->idr_type) { case IDR_ORIG: bpf->progs = do_old_idr(IDR_ORIG_GATHER, symbol_value("prog_idr"), bpf->proglist); break; case IDR_RADIX: bpf->progs = do_radix_tree(symbol_value("prog_idr") + OFFSET(idr_idr_rt), RADIX_TREE_GATHER, bpf->proglist); break; case IDR_XARRAY: bpf->progs = do_xarray(symbol_value("prog_idr") + OFFSET(idr_idr_rt), XARRAY_GATHER, bpf->proglist); break; } } switch (bpf->idr_type) { case IDR_ORIG: bpf->maps = do_old_idr(IDR_ORIG_COUNT, symbol_value("map_idr"), NULL); break; case IDR_RADIX: bpf->maps = do_radix_tree(symbol_value("map_idr") + OFFSET(idr_idr_rt), RADIX_TREE_COUNT, NULL); break; case IDR_XARRAY: bpf->maps = do_xarray(symbol_value("map_idr") + OFFSET(idr_idr_rt), XARRAY_COUNT, NULL); break; } if (bpf->maps) { len = sizeof(struct list_pair) * (bpf->maps+1); bpf->maplist = (struct list_pair *)GETBUF(len); bpf->maplist[0].index = bpf->maps; switch (bpf->idr_type) { case IDR_ORIG: bpf->maps = do_old_idr(IDR_ORIG_GATHER, symbol_value("map_idr"), bpf->maplist); break; case IDR_RADIX: bpf->maps = do_radix_tree(symbol_value("map_idr") + OFFSET(idr_idr_rt), RADIX_TREE_GATHER, bpf->maplist); break; case IDR_XARRAY: bpf->maps = do_xarray(symbol_value("map_idr") + OFFSET(idr_idr_rt), XARRAY_GATHER, bpf->maplist); break; } } bpf->bpf_prog_buf = GETBUF(SIZE(bpf_prog)); bpf->bpf_prog_aux_buf = GETBUF(SIZE(bpf_prog_aux)); bpf->bpf_map_buf = GETBUF(SIZE(bpf_map)); } static void do_bpf(ulong flags, ulong prog_id, ulong map_id, int radix) { struct bpf_info *bpf; int i, c, found, entries, type; uint uid, map_pages, key_size = 0, value_size = 0, max_entries = 0; ulong bpf_prog_aux, bpf_func, end_func, addr, insnsi, user; ulong do_progs, do_maps; ulonglong load_time; char *symbol; ushort prog_pages; int jited_len, len; char *arglist[MAXARGS]; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char buf3[BUFSIZE]; char buf4[BUFSIZE]; char buf5[BUFSIZE/2]; bpf = &bpf_info; bpf->proglist = NULL; bpf->maplist = NULL; bpf->bpf_prog_buf = bpf->bpf_prog_aux_buf = bpf->bpf_map_buf = NULL; bpf->bytecode_buf = NULL; bpf_init(bpf); if (flags & PROG_ID) { for (i = found = 0; i < bpf->progs; i++) { if (prog_id == bpf->proglist[i].index) { found++; break; } } if (!found) { error(INFO, "invalid program ID: %ld\n", prog_id); goto bailout; } } if (flags & MAP_ID) { for (i = found = 0; i < bpf->maps; i++) { if (map_id == bpf->maplist[i].index) { found++; break; } } if (!found) { error(INFO, "invalid map ID: %ld\n", map_id); goto bailout; } } if (!(flags & (PROG_ID|PROG_VERBOSE|MAP_ID|MAP_VERBOSE))) do_progs = do_maps = TRUE; else { do_progs = do_maps = FALSE; if (flags & (PROG_ID|PROG_VERBOSE)) do_progs = TRUE; if (flags & (MAP_ID|MAP_VERBOSE)) do_maps = TRUE; } if (!do_progs) goto do_map_only; for (i = entries = 0; i < bpf->progs; i++) { if (bpf->proglist[i].value == 0) continue; if (((flags & (PROG_ID|PROG_VERBOSE)) == PROG_ID) && (prog_id != bpf->proglist[i].index)) continue; if (!readmem((ulong)bpf->proglist[i].value, KVADDR, bpf->bpf_prog_buf, SIZE(bpf_prog), "struct bpf_prog", RETURN_ON_ERROR)) goto bailout; bpf_prog_aux = ULONG(bpf->bpf_prog_buf + OFFSET(bpf_prog_aux)); if (!readmem(bpf_prog_aux, KVADDR, bpf->bpf_prog_aux_buf, SIZE(bpf_prog_aux), "struct bpf_prog_aux", RETURN_ON_ERROR)) goto bailout; if (entries && (flags & PROG_VERBOSE)) fprintf(fp, "\n%s\n", bpf->prog_hdr1); if (entries++ == 0) fprintf(fp, "%s\n", bpf->prog_hdr1); fprintf(fp, "%s %s %s ", mkstring(buf1, 4, CENTER|LJUST|LONG_DEC, MKSTR(bpf->proglist[i].index)), mkstring(buf2, VADDR_PRLEN, CENTER|LJUST|LONG_HEX, MKSTR(bpf->proglist[i].value)), mkstring(buf3, VADDR_PRLEN, CENTER|LJUST|LONG_HEX, MKSTR(bpf_prog_aux))); type = INT(bpf->bpf_prog_buf + OFFSET(bpf_prog_type)); fprintf(fp, "%s ", mkstring(buf1, bpf->bpf_prog_type_size, CENTER|LJUST, bpf_prog_type_string(type, buf2))); fprintf(fp, "%s ", bpf_prog_tag_string(bpf->bpf_prog_buf + OFFSET(bpf_prog_tag), buf1)); fprintf(fp, "%s ", mkstring(buf1, strlen("USED_MAPS"), CENTER|LJUST, bpf_prog_used_maps(i, buf2))); fprintf(fp, "\n"); if (flags & (PROG_ID|PROG_VERBOSE)) { jited_len = UINT(bpf->bpf_prog_buf + OFFSET(bpf_prog_jited_len)); len = UINT(bpf->bpf_prog_buf + OFFSET(bpf_prog_len)); len *= SIZE(bpf_insn); if (VALID_MEMBER(bpf_prog_pages)) { prog_pages = USHORT(bpf->bpf_prog_buf + OFFSET(bpf_prog_pages)); prog_pages *= PAGESIZE(); } else prog_pages = 0; fprintf(fp, " XLATED: %d JITED: %d MEMLOCK: ", len, jited_len); if (VALID_MEMBER(bpf_prog_pages)) { fprintf(fp, "%d\n", prog_pages); } else fprintf(fp, "(unknown)\n"); fprintf(fp, " LOAD_TIME: "); if (VALID_MEMBER(bpf_prog_aux_load_time)) { load_time = ULONGLONG(bpf->bpf_prog_aux_buf + OFFSET(bpf_prog_aux_load_time)); print_boot_time(load_time, buf5, BUFSIZE/2); fprintf(fp, "%s\n", buf5); } else fprintf(fp, "(unknown)\n"); bpf_prog_gpl_compatible(buf1, (ulong)bpf->proglist[i].value); fprintf(fp, " GPL_COMPATIBLE: %s", buf1); fprintf(fp, " NAME: "); if (VALID_MEMBER(bpf_prog_aux_name)) { BCOPY(&bpf->bpf_prog_aux_buf[OFFSET(bpf_prog_aux_name)], buf1, 16); buf1[16] = NULLCHAR; if (strlen(buf1)) fprintf(fp, "\"%s\"", buf1); else fprintf(fp, "(unused)"); } else fprintf(fp, "(unknown)"); fprintf(fp, " UID: "); if (VALID_MEMBER(bpf_prog_aux_user) && VALID_MEMBER(user_struct_uid)) { user = ULONG(bpf->bpf_prog_aux_buf + OFFSET(bpf_prog_aux_user)); if (readmem(user + OFFSET(user_struct_uid), KVADDR, &uid, sizeof(uint), "user_struct.uid", QUIET|RETURN_ON_ERROR)) fprintf(fp, "%d\n", uid); else fprintf(fp, "(unknown)\n"); } else fprintf(fp, "(unknown)\n"); } if (flags & JITED) { fprintf(fp, "\n"); jited_len = UINT(bpf->bpf_prog_buf + OFFSET(bpf_prog_jited_len)); bpf_func = ULONG(bpf->bpf_prog_buf + OFFSET(bpf_prog_bpf_func)); end_func = bpf_func + jited_len; if (jited_len) { open_tmpfile(); pc->curcmd_private = (ulonglong)end_func; sprintf(buf1, "x/%di 0x%lx", jited_len, bpf_func); gdb_pass_through(buf1, NULL, GNU_RETURN_ON_ERROR); rewind(pc->tmpfile); while (fgets(buf1, BUFSIZE, pc->tmpfile)) { strcpy(buf2, strip_linefeeds(buf1)); c = parse_line(buf1, arglist); if (STRNEQ(arglist[0], "0x") && (LASTCHAR(arglist[0]) == ':')) { addr = htol(strip_ending_char(arglist[0], ':'), RETURN_ON_ERROR, NULL); if (addr >= end_func) break; } symbol = NULL; if ((c > 1) && IS_A_NUMBER(arglist[c-1])) { addr = htol(arglist[c-1], RETURN_ON_ERROR, NULL); symbol = value_to_symstr(addr, buf3, radix); if (strlen(symbol)) { sprintf(buf4, "<%s>", symbol); symbol = buf4; } } fprintf(pc->saved_fp, "%s %s\n", buf2, symbol ? symbol : ""); } pc->curcmd_private = 0; close_tmpfile(); } else fprintf(fp, "(program not jited)\n"); } if (flags & XLATED) { fprintf(fp, "\n"); len = UINT(bpf->bpf_prog_buf + OFFSET(bpf_prog_len)); insnsi = (ulong)bpf->proglist[i].value + OFFSET(bpf_prog_insnsi); bpf->bytecode_buf = GETBUF(len * SIZE(bpf_insn)); if (CRASHDEBUG(1)) fprintf(fp, "bytecode_buf: [%lx] len %d * size %ld = %ld from: %lx\n", (ulong)bpf->bytecode_buf, len, SIZE(bpf_insn), len * SIZE(bpf_insn), insnsi); if (!readmem(insnsi, KVADDR, bpf->bytecode_buf, len * SIZE(bpf_insn), "bpf_prog.insnsi contents", RETURN_ON_ERROR)) goto bailout; dump_xlated_plain((void *)bpf->bytecode_buf, len * SIZE(bpf_insn), flags & OPCODES); } if (flags & DUMP_STRUCT) { fprintf(fp, "\n"); dump_struct("bpf_prog", (ulong)bpf->proglist[i].value, radix); fprintf(fp, "\n"); dump_struct("bpf_prog_aux", bpf_prog_aux, radix); } } if (!do_maps) goto bailout; else fprintf(fp, "\n"); do_map_only: for (i = entries = 0; i < bpf->maps; i++) { if (bpf->maplist[i].value == 0) continue; if (((flags & (MAP_ID|MAP_VERBOSE)) == MAP_ID) && (map_id != bpf->maplist[i].index)) continue; if (entries && (flags & MAP_VERBOSE)) fprintf(fp, "\n%s\n", bpf->map_hdr1); if (entries++ == 0) fprintf(fp, "%s\n", bpf->map_hdr1); if (!readmem((ulong)bpf->maplist[i].value, KVADDR, bpf->bpf_map_buf, SIZE(bpf_map), "struct bpf_map", RETURN_ON_ERROR)) goto bailout; fprintf(fp, "%s %s ", mkstring(buf1, 4, CENTER|LJUST|LONG_DEC, MKSTR(bpf->maplist[i].index)), mkstring(buf2, VADDR_PRLEN, CENTER|LJUST|LONG_HEX, MKSTR(bpf->maplist[i].value))); type = INT(bpf->bpf_map_buf + OFFSET(bpf_map_map_type)); fprintf(fp, "%s ", mkstring(buf1, bpf->bpf_map_map_type_size, CENTER|LJUST, bpf_map_map_type_string(type, buf2))); fprintf(fp, " %08x ", UINT(bpf->bpf_map_buf + OFFSET(bpf_map_map_flags))); fprintf(fp, "\n"); if (flags & (MAP_ID|MAP_VERBOSE)) { ulong msize = 0; fprintf(fp, " KEY_SIZE: "); if (VALID_MEMBER(bpf_map_key_size)) { key_size = UINT(bpf->bpf_map_buf + OFFSET(bpf_map_key_size)); fprintf(fp, "%d", key_size); } else fprintf(fp, "(unknown)"); fprintf(fp, " VALUE_SIZE: "); if (VALID_MEMBER(bpf_map_value_size)) { value_size = UINT(bpf->bpf_map_buf + OFFSET(bpf_map_value_size)); fprintf(fp, "%d", value_size); } else fprintf(fp, "(unknown)"); fprintf(fp, " MAX_ENTRIES: "); if (VALID_MEMBER(bpf_map_max_entries)) { max_entries = UINT(bpf->bpf_map_buf + OFFSET(bpf_map_max_entries)); fprintf(fp, "%d", max_entries); } else fprintf(fp, "(unknown)"); fprintf(fp, " MEMLOCK: "); if (VALID_MEMBER(bpf_map_memory) && VALID_MEMBER(bpf_map_memory_pages)) { map_pages = UINT(bpf->bpf_map_buf + OFFSET(bpf_map_memory) + OFFSET(bpf_map_memory_pages)); fprintf(fp, "%d\n", map_pages * PAGESIZE()); } else if (VALID_MEMBER(bpf_map_pages)) { map_pages = UINT(bpf->bpf_map_buf + OFFSET(bpf_map_pages)); fprintf(fp, "%d\n", map_pages * PAGESIZE()); } else if ((msize = bpf_map_memory_size(type, value_size, key_size, max_entries))) fprintf(fp, "%ld\n", msize); #define BPF_MAP_TYPE_RINGBUF (0x1BUL) else if (type == BPF_MAP_TYPE_RINGBUF) { fprintf(fp, "%ld\n", ringbuf_map_mem_usage(bpf, i)); } else fprintf(fp, "(unknown)"); fprintf(fp, " NAME: "); if (VALID_MEMBER(bpf_map_name)) { BCOPY(&bpf->bpf_map_buf[OFFSET(bpf_map_name)], buf1, 16); buf1[17] = NULLCHAR; if (strlen(buf1)) fprintf(fp, "\"%s\"", buf1); else fprintf(fp, "(unused)"); } else fprintf(fp, "(unknown)\n"); fprintf(fp, " UID: "); if (VALID_MEMBER(bpf_map_memory) && VALID_MEMBER(bpf_map_memory_user)) user = ULONG(bpf->bpf_map_buf + OFFSET(bpf_map_memory) + OFFSET(bpf_map_memory_user)); else if (VALID_MEMBER(bpf_map_user)) user = ULONG(bpf->bpf_map_buf + OFFSET(bpf_map_user)); else user = 0; if (user && VALID_MEMBER(user_struct_uid)) { if (readmem(user + OFFSET(user_struct_uid), KVADDR, &uid, sizeof(uint), "user_struct.uid", QUIET|RETURN_ON_ERROR)) fprintf(fp, "%d\n", uid); else fprintf(fp, "(unknown)\n"); } else fprintf(fp, "(unused)\n"); } if (flags & DUMP_STRUCT) { fprintf(fp, "\n"); dump_struct("bpf_map", (ulong)bpf->maplist[i].value, radix); } } bailout: if (bpf->proglist) FREEBUF(bpf->proglist); if (bpf->maplist) FREEBUF(bpf->maplist); FREEBUF(bpf->bpf_prog_buf); FREEBUF(bpf->bpf_prog_aux_buf); FREEBUF(bpf->bpf_map_buf); if (bpf->bytecode_buf) FREEBUF(bpf->bytecode_buf); } static int bpf_type_size_init(void) { int c ATTRIBUTE_UNUSED; size_t max; char *arglist[MAXARGS]; char buf[BUFSIZE]; struct bpf_info *bpf = &bpf_info; open_tmpfile(); if (dump_enumerator_list("bpf_prog_type")) { max = 0; rewind(pc->tmpfile); while (fgets(buf, BUFSIZE, pc->tmpfile)) { if (!strstr(buf, " = ")) continue; c = parse_line(buf, arglist); if (CRASHDEBUG(1)) fprintf(pc->saved_fp, "%s\n", arglist[0]); max = MAX(max, strlen(arglist[0])); } bpf->bpf_prog_type_size = max - strlen("BPF_PROG_TYPE_"); } else { close_tmpfile(); return FALSE; } /* * Keep bpf program header at 80 columns */ bpf->bpf_prog_type_size = MIN(13, bpf->bpf_prog_type_size); close_tmpfile(); open_tmpfile(); if (dump_enumerator_list("bpf_map_type")) { max = 0; rewind(pc->tmpfile); while (fgets(buf, BUFSIZE, pc->tmpfile)) { if (!strstr(buf, " = ")) continue; c = parse_line(buf, arglist); if (CRASHDEBUG(1)) fprintf(pc->saved_fp, "%s\n", arglist[0]); max = MAX(max, strlen(arglist[0])); } bpf->bpf_map_map_type_size = max - strlen("BPF_PROG_TYPE_"); } else { close_tmpfile(); return FALSE; } close_tmpfile(); return TRUE; } static char * bpf_prog_type_string(int type, char *retbuf) { char *p; int c ATTRIBUTE_UNUSED; char *arglist[MAXARGS]; char buf[BUFSIZE]; retbuf[0] = NULLCHAR; open_tmpfile(); if (dump_enumerator_list("bpf_prog_type")) { rewind(pc->tmpfile); while (fgets(buf, BUFSIZE, pc->tmpfile)) { if (!strstr(buf, " = ")) continue; c = parse_line(buf, arglist); if (atoi(arglist[2]) == type) { p = arglist[0]; p += strlen("BPF_PROG_TYPE_"); strcpy(retbuf, p); break; } } } close_tmpfile(); return retbuf; } static char * bpf_map_map_type_string(int map_type, char *retbuf) { char *p; int c ATTRIBUTE_UNUSED; char *arglist[MAXARGS]; char buf[BUFSIZE]; retbuf[0] = NULLCHAR; open_tmpfile(); if (dump_enumerator_list("bpf_map_type")) { rewind(pc->tmpfile); while (fgets(buf, BUFSIZE, pc->tmpfile)) { if (!strstr(buf, " = ")) continue; c = parse_line(buf, arglist); if (atoi(arglist[2]) == map_type) { p = arglist[0]; p += strlen("BPF_MAP_TYPE_"); strcpy(retbuf, p); break; } } } close_tmpfile(); return retbuf; } static char * bpf_prog_used_maps(int idx, char *retbuf) { int i, m, cnt; struct bpf_info *bpf = &bpf_info; uint used_map_cnt; ulong used_maps, map; retbuf[0] = NULLCHAR; used_map_cnt = UINT(bpf->bpf_prog_aux_buf + OFFSET(bpf_prog_aux_used_map_cnt)); used_maps = ULONG(bpf->bpf_prog_aux_buf + OFFSET(bpf_prog_aux_used_maps)); for (i = cnt = 0; i < used_map_cnt; i++) { if (!readmem(used_maps + (sizeof(ulong)*i), KVADDR, &map, sizeof(ulong), "bpf_prog_aux.used_maps", RETURN_ON_ERROR)) return retbuf; for (m = 0; m < bpf->maps; m++) { if (map == (ulong)bpf->maplist[m].value) { sprintf(&retbuf[strlen(retbuf)], "%s%ld", strlen(retbuf) ? "," : "", bpf->maplist[m].index); break; } } } return retbuf; } static char * bpf_prog_tag_string(char *tag, char *buf) { int i; buf[0] = NULLCHAR; for (i = 0; i < 8; i++) sprintf(&buf[strlen(buf)], "%02x", (unsigned char)tag[i]); return buf; } static void bpf_prog_gpl_compatible(char *retbuf, ulong bpf_prog) { char buf[BUFSIZE]; sprintf(retbuf, "(unknown)"); open_tmpfile(); sprintf(buf, "p (*(struct bpf_prog *)0x%lx).gpl_compatible", bpf_prog); gdb_pass_through(buf, NULL, GNU_RETURN_ON_ERROR); rewind(pc->tmpfile); while (fgets(buf, BUFSIZE, pc->tmpfile)) { if (strstr(buf, " = 1")) { sprintf(retbuf, "yes"); break; } else if (strstr(buf, " = 0")) { sprintf(retbuf, "no"); break; } } close_tmpfile(); } // #include /* * Taken from: "/usr/include/linux/bpf_common.h" */ /* * bpf_common.h */ /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ #ifndef __LINUX_BPF_COMMON_H__ #define __LINUX_BPF_COMMON_H__ /* Instruction classes */ #define BPF_CLASS(code) ((code) & 0x07) #define BPF_LD 0x00 #define BPF_LDX 0x01 #define BPF_ST 0x02 #define BPF_STX 0x03 #define BPF_ALU 0x04 #define BPF_JMP 0x05 #define BPF_RET 0x06 #define BPF_MISC 0x07 /* ld/ldx fields */ #define BPF_SIZE(code) ((code) & 0x18) #define BPF_W 0x00 /* 32-bit */ #define BPF_H 0x08 /* 16-bit */ #define BPF_B 0x10 /* 8-bit */ /* eBPF BPF_DW 0x18 64-bit */ #define BPF_MODE(code) ((code) & 0xe0) #define BPF_IMM 0x00 #define BPF_ABS 0x20 #define BPF_IND 0x40 #define BPF_MEM 0x60 #define BPF_LEN 0x80 #define BPF_MSH 0xa0 /* alu/jmp fields */ #define BPF_OP(code) ((code) & 0xf0) #define BPF_ADD 0x00 #define BPF_SUB 0x10 #define BPF_MUL 0x20 #define BPF_DIV 0x30 #define BPF_OR 0x40 #define BPF_AND 0x50 #define BPF_LSH 0x60 #define BPF_RSH 0x70 #define BPF_NEG 0x80 #define BPF_MOD 0x90 #define BPF_XOR 0xa0 #define BPF_JA 0x00 #define BPF_JEQ 0x10 #define BPF_JGT 0x20 #define BPF_JGE 0x30 #define BPF_JSET 0x40 #define BPF_SRC(code) ((code) & 0x08) #define BPF_K 0x00 #define BPF_X 0x08 #ifndef BPF_MAXINSNS #define BPF_MAXINSNS 4096 #endif #endif /* __LINUX_BPF_COMMON_H__ */ /* * Taken from: /usr/include/asm-generic/int-ll64.h */ typedef unsigned char __u8; typedef __signed__ short __s16; typedef __signed__ int __s32; /* * Taken from: "/usr/include/linux/bpf.h" */ /* Extended instruction set based on top of classic BPF */ /* instruction classes */ #define BPF_ALU64 0x07 /* alu mode in double word width */ /* ld/ldx fields */ #define BPF_DW 0x18 /* double word (64-bit) */ #define BPF_XADD 0xc0 /* exclusive add */ /* alu/jmp fields */ #define BPF_MOV 0xb0 /* mov reg to reg */ #define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */ /* change endianness of a register */ #define BPF_END 0xd0 /* flags for endianness conversion: */ #define BPF_TO_LE 0x00 /* convert to little-endian */ #define BPF_TO_BE 0x08 /* convert to big-endian */ #define BPF_FROM_LE BPF_TO_LE #define BPF_FROM_BE BPF_TO_BE /* jmp encodings */ #define BPF_JNE 0x50 /* jump != */ #define BPF_JLT 0xa0 /* LT is unsigned, '<' */ #define BPF_JLE 0xb0 /* LE is unsigned, '<=' */ #define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */ #define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */ #define BPF_JSLT 0xc0 /* SLT is signed, '<' */ #define BPF_JSLE 0xd0 /* SLE is signed, '<=' */ #define BPF_CALL 0x80 /* function call */ #define BPF_EXIT 0x90 /* function return */ /* Register numbers */ enum { BPF_REG_0 = 0, BPF_REG_1, BPF_REG_2, BPF_REG_3, BPF_REG_4, BPF_REG_5, BPF_REG_6, BPF_REG_7, BPF_REG_8, BPF_REG_9, BPF_REG_10, __MAX_BPF_REG, }; struct bpf_insn { __u8 code; /* opcode */ __u8 dst_reg:4; /* dest register */ __u8 src_reg:4; /* source register */ __s16 off; /* signed offset */ __s32 imm; /* signed immediate constant */ }; /* instruction classes */ #define BPF_ALU64 0x07 /* alu mode in double word width */ /* ld/ldx fields */ #define BPF_DW 0x18 /* double word (64-bit) */ #define BPF_XADD 0xc0 /* exclusive add */ /* alu/jmp fields */ #define BPF_MOV 0xb0 /* mov reg to reg */ #define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */ /* change endianness of a register */ #define BPF_END 0xd0 /* flags for endianness conversion: */ #define BPF_TO_LE 0x00 /* convert to little-endian */ #define BPF_TO_BE 0x08 /* convert to big-endian */ #define BPF_FROM_LE BPF_TO_LE #define BPF_FROM_BE BPF_TO_BE /* when bpf_ldimm64->src_reg == BPF_PSEUDO_MAP_FD, bpf_ldimm64->imm == fd */ #define BPF_PSEUDO_MAP_FD 1 /* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative * offset to another bpf function */ #define BPF_PSEUDO_CALL 1 static void fprint_hex(FILE *, void *, unsigned int, const char *); /* * Taken from: tools/bpf/bpftool/main.c */ void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep) { unsigned char *data = arg; unsigned int i; for (i = 0; i < n; i++) { const char *pfx = ""; if (!i) /* nothing */; else if (!(i % 16)) fprintf(f, "\n"); else if (!(i % 8)) fprintf(f, " "); else pfx = sep; fprintf(f, "%s%02hhx", i ? pfx : "", data[i]); } } static void dump_bpf_insn(struct bpf_insn *insn) { fprintf(fp, " code: 0x%x / %d\n", insn->code, insn->code); fprintf(fp, " dst_reg: 0x%x / %d\n", insn->dst_reg, insn->dst_reg); fprintf(fp, " src_reg: 0x%x / %d\n", insn->src_reg, insn->src_reg); fprintf(fp, " off: 0x%x / %d\n", insn->off, insn->off); fprintf(fp, " imm: 0x%x / %d\n", insn->imm, insn->imm); } static void print_bpf_insn(struct bpf_insn *, int); /* * Adapted from: "tools/bpf/bpftool/prog.c" */ static void dump_xlated_plain(void *buf, unsigned int len, int opcodes) { struct bpf_insn *insn = buf; int double_insn = FALSE; unsigned int i; for (i = 0; i < len / sizeof(*insn); i++) { if (double_insn) { double_insn = FALSE; continue; } double_insn = insn[i].code == (BPF_LD | BPF_IMM | BPF_DW); fprintf(fp, "% 4d: ", i); print_bpf_insn(insn + i, TRUE); if (opcodes) { fprintf(fp, " "); fprint_hex(fp, insn + i, 8, " "); if (double_insn && i < len - 1) { fprintf(fp, " "); fprint_hex(fp, insn + i + 1, 8, " "); } fprintf(fp, "\n"); } if (CRASHDEBUG(1)) dump_bpf_insn(insn + i); } } /* * Adapted from: kernel/bpf/disasm.c */ const char *const bpf_class_string[8] = { [BPF_LD] = "ld", [BPF_LDX] = "ldx", [BPF_ST] = "st", [BPF_STX] = "stx", [BPF_ALU] = "alu", [BPF_JMP] = "jmp", [BPF_RET] = "BUG", [BPF_ALU64] = "alu64", }; const char *const bpf_alu_string[16] = { [BPF_ADD >> 4] = "+=", [BPF_SUB >> 4] = "-=", [BPF_MUL >> 4] = "*=", [BPF_DIV >> 4] = "/=", [BPF_OR >> 4] = "|=", [BPF_AND >> 4] = "&=", [BPF_LSH >> 4] = "<<=", [BPF_RSH >> 4] = ">>=", [BPF_NEG >> 4] = "neg", [BPF_MOD >> 4] = "%=", [BPF_XOR >> 4] = "^=", [BPF_MOV >> 4] = "=", [BPF_ARSH >> 4] = "s>>=", [BPF_END >> 4] = "endian", }; static const char *const bpf_ldst_string[] = { [BPF_W >> 3] = "u32", [BPF_H >> 3] = "u16", [BPF_B >> 3] = "u8", [BPF_DW >> 3] = "u64", }; static const char *const bpf_jmp_string[16] = { [BPF_JA >> 4] = "jmp", [BPF_JEQ >> 4] = "==", [BPF_JGT >> 4] = ">", [BPF_JLT >> 4] = "<", [BPF_JGE >> 4] = ">=", [BPF_JLE >> 4] = "<=", [BPF_JSET >> 4] = "&", [BPF_JNE >> 4] = "!=", [BPF_JSGT >> 4] = "s>", [BPF_JSLT >> 4] = "s<", [BPF_JSGE >> 4] = "s>=", [BPF_JSLE >> 4] = "s<=", [BPF_CALL >> 4] = "call", [BPF_EXIT >> 4] = "exit", }; typedef unsigned char u8; typedef unsigned int u32; static const char *__func_imm_name(const struct bpf_insn *insn, uint64_t full_imm, char *buff, size_t len) { int m; struct bpf_info *bpf = &bpf_info; for (m = 0; m < bpf->maps; m++) { if (full_imm == (ulong)bpf->maplist[m].value) { sprintf(buff, "map[id:%ld]", bpf->maplist[m].index); if (CRASHDEBUG(1)) sprintf(&buff[strlen(buff)], " (%lx)", (ulong)bpf->maplist[m].value); return buff; } } snprintf(buff, len, "0x%llx", (unsigned long long)full_imm); return buff; } static char *__func_get_name(const struct bpf_insn *insn, char *buff, size_t len) { long __BPF_FUNC_MAX_ID; char func_id_str[BUFSIZE]; ulong func_id_ptr; struct syment *sp; ulong offset; if (!enumerator_value("__BPF_FUNC_MAX_ID", &__BPF_FUNC_MAX_ID)) return buff; if (insn->src_reg != BPF_PSEUDO_CALL && insn->imm >= 0 && insn->imm < __BPF_FUNC_MAX_ID) { // return func_id_str[insn->imm]; if (!readmem(symbol_value("func_id_str") + (insn->imm * sizeof(void *)), KVADDR, &func_id_ptr, sizeof(void *), "func_id_str pointer", QUIET|RETURN_ON_ERROR)) error(FATAL, "cannot read func_id_str[]"); if (!read_string(func_id_ptr, func_id_str, BUFSIZE-1)) error(FATAL, "cannot read func_id_str[] string"); sprintf(buff, "%s", func_id_str); return buff; } if ((insn->src_reg != BPF_PSEUDO_CALL) && (sp = value_search(symbol_value("__bpf_call_base") + insn->imm, &offset)) && !offset) return(sp->name); if (insn->src_reg == BPF_PSEUDO_CALL) snprintf(buff, len, "%+d", insn->imm); return buff; } static void print_bpf_insn(struct bpf_insn *insn, int allow_ptr_leaks) { __u8 class = BPF_CLASS(insn->code); if (class == BPF_ALU || class == BPF_ALU64) { if (BPF_OP(insn->code) == BPF_END) { if (class == BPF_ALU64) fprintf(fp, "BUG_alu64_%02x\n", insn->code); else // print_bpf_end_insn(verbose, env, insn); fprintf(fp, "(%02x) r%d = %s%d r%d\n", insn->code, insn->dst_reg, BPF_SRC(insn->code) == BPF_TO_BE ? "be" : "le", insn->imm, insn->dst_reg); } else if (BPF_OP(insn->code) == BPF_NEG) { fprintf(fp, "(%02x) r%d = %s-r%d\n", insn->code, insn->dst_reg, class == BPF_ALU ? "(u32) " : "", insn->dst_reg); } else if (BPF_SRC(insn->code) == BPF_X) { fprintf(fp, "(%02x) %sr%d %s %sr%d\n", insn->code, class == BPF_ALU ? "(u32) " : "", insn->dst_reg, bpf_alu_string[BPF_OP(insn->code) >> 4], class == BPF_ALU ? "(u32) " : "", insn->src_reg); } else { fprintf(fp, "(%02x) %sr%d %s %s%d\n", insn->code, class == BPF_ALU ? "(u32) " : "", insn->dst_reg, bpf_alu_string[BPF_OP(insn->code) >> 4], class == BPF_ALU ? "(u32) " : "", insn->imm); } } else if (class == BPF_STX) { if (BPF_MODE(insn->code) == BPF_MEM) fprintf(fp, "(%02x) *(%s *)(r%d %+d) = r%d\n", insn->code, bpf_ldst_string[BPF_SIZE(insn->code) >> 3], insn->dst_reg, insn->off, insn->src_reg); else if (BPF_MODE(insn->code) == BPF_XADD) fprintf(fp, "(%02x) lock *(%s *)(r%d %+d) += r%d\n", insn->code, bpf_ldst_string[BPF_SIZE(insn->code) >> 3], insn->dst_reg, insn->off, insn->src_reg); else fprintf(fp, "BUG_%02x\n", insn->code); } else if (class == BPF_ST) { if (BPF_MODE(insn->code) != BPF_MEM) { fprintf(fp, "BUG_st_%02x\n", insn->code); return; } fprintf(fp, "(%02x) *(%s *)(r%d %+d) = %d\n", insn->code, bpf_ldst_string[BPF_SIZE(insn->code) >> 3], insn->dst_reg, insn->off, insn->imm); } else if (class == BPF_LDX) { if (BPF_MODE(insn->code) != BPF_MEM) { fprintf(fp, "BUG_ldx_%02x\n", insn->code); return; } fprintf(fp, "(%02x) r%d = *(%s *)(r%d %+d)\n", insn->code, insn->dst_reg, bpf_ldst_string[BPF_SIZE(insn->code) >> 3], insn->src_reg, insn->off); } else if (class == BPF_LD) { if (BPF_MODE(insn->code) == BPF_ABS) { fprintf(fp, "(%02x) r0 = *(%s *)skb[%d]\n", insn->code, bpf_ldst_string[BPF_SIZE(insn->code) >> 3], insn->imm); } else if (BPF_MODE(insn->code) == BPF_IND) { fprintf(fp, "(%02x) r0 = *(%s *)skb[r%d + %d]\n", insn->code, bpf_ldst_string[BPF_SIZE(insn->code) >> 3], insn->src_reg, insn->imm); } else if (BPF_MODE(insn->code) == BPF_IMM && BPF_SIZE(insn->code) == BPF_DW) { /* At this point, we already made sure that the second * part of the ldimm64 insn is accessible. */ uint64_t imm = ((uint64_t)(insn + 1)->imm << 32) | (u32)insn->imm; int map_ptr = insn->src_reg == BPF_PSEUDO_MAP_FD; char tmp[64]; if (map_ptr && !allow_ptr_leaks) imm = 0; fprintf(fp, "(%02x) r%d = %s\n", insn->code, insn->dst_reg, __func_imm_name(insn, imm, tmp, sizeof(tmp))); } else { fprintf(fp, "BUG_ld_%02x\n", insn->code); return; } } else if (class == BPF_JMP) { u8 opcode = BPF_OP(insn->code); if (opcode == BPF_CALL) { char tmp[64]; if (insn->src_reg == BPF_PSEUDO_CALL) { fprintf(fp, "(%02x) call pc%s\n", insn->code, __func_get_name(insn, tmp, sizeof(tmp))); } else { strcpy(tmp, "unknown"); fprintf(fp, "(%02x) call %s#%d\n", insn->code, __func_get_name(insn, tmp, sizeof(tmp)), insn->imm); } } else if (insn->code == (BPF_JMP | BPF_JA)) { fprintf(fp, "(%02x) goto pc%+d\n", insn->code, insn->off); } else if (insn->code == (BPF_JMP | BPF_EXIT)) { fprintf(fp, "(%02x) exit\n", insn->code); } else if (BPF_SRC(insn->code) == BPF_X) { fprintf(fp, "(%02x) if r%d %s r%d goto pc%+d\n", insn->code, insn->dst_reg, bpf_jmp_string[BPF_OP(insn->code) >> 4], insn->src_reg, insn->off); } else { fprintf(fp, "(%02x) if r%d %s 0x%x goto pc%+d\n", insn->code, insn->dst_reg, bpf_jmp_string[BPF_OP(insn->code) >> 4], insn->imm, insn->off); } } else { fprintf(fp, "(%02x) %s\n", insn->code, bpf_class_string[class]); } } static void print_boot_time(unsigned long long nsecs, char *buf, unsigned int size) { #ifdef CLOCK_BOOTTIME struct timespec real_time_ts, boot_time_ts; time_t wallclock_secs; struct tm load_tm; buf[--size] = '\0'; if (clock_gettime(CLOCK_REALTIME, &real_time_ts) || clock_gettime(CLOCK_BOOTTIME, &boot_time_ts)) { perror("Can't read clocks"); snprintf(buf, size, "%llu", nsecs / 1000000000); return; } wallclock_secs = (real_time_ts.tv_sec - boot_time_ts.tv_sec) + nsecs / 1000000000; if (!localtime_r(&wallclock_secs, &load_tm)) { snprintf(buf, size, "%llu", nsecs / 1000000000); return; } // strftime(buf, size, "%b %d/%H:%M", &load_tm); strftime(buf, size, "%a %b %d %H:%M:%S %Y", &load_tm); #else sprintf(buf, "(unknown)"); #endif } /* * Borrow the old (pre-radix_tree) IDR facility code used by * the ipcs command. */ static int do_old_idr(int cmd, ulong idr, struct list_pair *lp) { int i, max, cur, next_id, total = 0; ulong entry; switch (cmd) { case IDR_ORIG_INIT: ipcs_init(); break; case IDR_ORIG_COUNT: readmem(idr + OFFSET(idr_cur), KVADDR, &cur, sizeof(int), "idr.cur", FAULT_ON_ERROR); for (total = next_id = 0; next_id < cur; next_id++) { entry = idr_find(idr, next_id); if (entry == 0) continue; total++; } break; case IDR_ORIG_GATHER: max = lp[0].index; readmem(idr + OFFSET(idr_cur), KVADDR, &cur, sizeof(int), "idr.cur", FAULT_ON_ERROR); for (i = total = next_id = 0; next_id < cur; next_id++) { entry = idr_find(idr, next_id); if (entry == 0) continue; total++; lp[i].index = next_id; lp[i].value = (void *)entry; if (++i == max) break; } break; } return total; } crash-utility-crash-61fe107/ci-tests/000077500000000000000000000000001517256214500175075ustar00rootroot00000000000000crash-utility-crash-61fe107/ci-tests/.fmf/000077500000000000000000000000001517256214500203355ustar00rootroot00000000000000crash-utility-crash-61fe107/ci-tests/.fmf/version000066400000000000000000000000021517256214500217350ustar00rootroot000000000000001 crash-utility-crash-61fe107/ci-tests/local.fmf000066400000000000000000000004421517256214500212730ustar00rootroot00000000000000summary: Generate vmcore and analyze it with crash tool environment: KDUMP_UTILS_RPM: kdump-utils discover+: test: - /kdump/default_crashkernel - /kdump/config-any - /kdump/crash-sysrq-c - /kdump/build-crash-utility - /kdump/analyse-crash-cmd/common_analyse crash-utility-crash-61fe107/ci-tests/main.fmf000066400000000000000000000012341517256214500211250ustar00rootroot00000000000000provision: - name: client hardware: memory: ">= 4 GiB" cpu: processors: ">= 4" prepare: # Set root password to log in as root in the console - name: Set root password how: shell script: - echo root:kdump | chpasswd - name: Use custom mirror how: shell script: - test -v CUSTOM_MIRROR && sed -e 's/^metalink=/#metalink=/g' -e "s|^#baseurl=http://download.example/pub/fedora/linux|baseurl=${CUSTOM_MIRROR}|g" -i.bak /etc/yum.repos.d/fedora{,-updates}.repo || true execute: how: tmt exit-first: true discover: how: fmf url: https://github.com/crash-utility/crash-test.git ref: main crash-utility-crash-61fe107/cmdline.c000066400000000000000000001737701517256214500175520ustar00rootroot00000000000000/* cmdline.c - core analysis suite * * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. * Copyright (C) 2002-2015,2019 David Anderson * Copyright (C) 2002-2015,2019 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #include "defs.h" static void restore_sanity(void); static void restore_ifile_sanity(void); static int pseudo_command(char *); static void check_special_handling(char *); static int is_executable_in_PATH(char *); static int is_shell_script(char *); static void list_aliases(char *); static int allocate_alias(int); static int alias_exists(char *); static void resolve_aliases(void); static int setup_redirect(int); int multiple_pipes(char **); static int output_command_to_pids(void); static void set_my_tty(void); static char *signame(int); static int setup_stdpipe(void); static void wait_for_children(ulong); #define ZOMBIES_ONLY (1) #define ALL_CHILDREN (2) int shell_command(char *); static void modify_orig_line(char *, struct args_input_file *); static void modify_expression_arg(char *, char **, struct args_input_file *); static int verify_args_input_file(char *); static char *crash_readline_completion_generator(const char *, int); static char **crash_readline_completer(const char *, int, int); #define READLINE_LIBRARY #include #include #include static void readline_init(void); static struct alias_data alias_head = { 0 }; void process_command_line(void) { /* * Restore normal environment, clearing out any excess baggage * piled up by the previous command. */ restore_sanity(); fp = stdout; BZERO(pc->command_line, BUFSIZE); if (!pc->ifile_in_progress && !(pc->flags & (TTY|SILENT|CMDLINE_IFILE|RCHOME_IFILE|RCLOCAL_IFILE))) fprintf(fp, "%s", pc->prompt); fflush(fp); /* * Input can come from five possible sources: * * 1. an .rc file located in the user's HOME directory. * 2. an .rc file located in the current directory. * 3. an input file that was designated by the -i flag at * program invocation. * 4. from a terminal. * 5. from a pipe, if stdin is a pipe rather than a terminal. * * But first, handle the interruption of an input file caused * by a FATAL error in one of its commands. * */ if (pc->ifile_in_progress) { switch (pc->ifile_in_progress) { case RCHOME_IFILE: pc->flags |= INIT_IFILE|RCHOME_IFILE; sprintf(pc->command_line, "< %s/.%src", pc->home, pc->program_name); break; case RCLOCAL_IFILE: sprintf(pc->command_line, "< .%src", pc->program_name); pc->flags |= INIT_IFILE|RCLOCAL_IFILE; break; case CMDLINE_IFILE: sprintf(pc->command_line, "< %s", pc->input_file); pc->flags |= INIT_IFILE|CMDLINE_IFILE; break; case RUNTIME_IFILE: sprintf(pc->command_line, "%s", pc->runtime_ifile_cmd); pc->flags |= IFILE_ERROR; break; default: error(FATAL, "invalid input file\n"); } } else if (pc->flags & RCHOME_IFILE) { sprintf(pc->command_line, "< %s/.%src", pc->home, pc->program_name); pc->flags |= INIT_IFILE; } else if (pc->flags & RCLOCAL_IFILE) { sprintf(pc->command_line, "< .%src", pc->program_name); pc->flags |= INIT_IFILE; } else if (pc->flags & CMDLINE_IFILE) { sprintf(pc->command_line, "< %s", pc->input_file); pc->flags |= INIT_IFILE; } else if (pc->flags & TTY) { if (!(pc->readline = readline(pc->prompt))) { args[0] = NULL; fprintf(fp, "\n"); return; } if (strlen(pc->readline) >= BUFSIZE) error(FATAL, "input line exceeds maximum of 1500 bytes\n"); else strcpy(pc->command_line, pc->readline); free(pc->readline); clean_line(pc->command_line); pseudo_command(pc->command_line); strcpy(pc->orig_line, pc->command_line); if (strlen(pc->command_line) && !iscntrl(pc->command_line[0])) add_history(pc->command_line); check_special_handling(pc->command_line); } else { if (fgets(pc->command_line, BUFSIZE-1, stdin) == NULL) clean_exit(1); if (!(pc->flags & SILENT)) { fprintf(fp, "%s", pc->command_line); fflush(fp); } clean_line(pc->command_line); strcpy(pc->orig_line, pc->command_line); } /* * First clean out all linefeeds and leading/trailing spaces. * Then substitute aliases for the real thing they represent. */ clean_line(pc->command_line); resolve_aliases(); /* * Setup output redirection based upon the command line itself or * based upon the default scrolling behavior, if any. */ switch (setup_redirect(FROM_COMMAND_LINE)) { case REDIRECT_NOT_DONE: case REDIRECT_TO_STDPIPE: case REDIRECT_TO_PIPE: case REDIRECT_TO_FILE: break; case REDIRECT_SHELL_ESCAPE: case REDIRECT_SHELL_COMMAND: case REDIRECT_FAILURE: RESTART(); break; } /* * Setup the global argcnt and args[] array for use by everybody * during the life of this command. */ argcnt = parse_line(pc->command_line, args); } /* * Allow input file redirection without having to put a space between * the < and the filename. Allow the "pointer-to" asterisk to "touch" * the structure/union name. */ static void check_special_handling(char *s) { char local[BUFSIZE]; strcpy(local, s); if ((local[0] == '*') && (!whitespace(local[1]))) { sprintf(s, "* %s", &local[1]); return; } if ((local[0] == '<') && (!whitespace(local[1]))) { sprintf(s, "< %s", &local[1]); return; } } static int is_executable_in_PATH(char *filename) { char *buf1, *buf2; char *tok, *path; int retval; if ((path = getenv("PATH"))) { buf1 = GETBUF(strlen(path)+1); buf2 = GETBUF(strlen(path)+1); strcpy(buf2, path); } else return FALSE; retval = FALSE; tok = strtok(buf2, ":"); while (tok) { sprintf(buf1, "%s/%s", tok, filename); if (file_exists(buf1, NULL) && (access(buf1, X_OK) == 0)) { retval = TRUE; break; } tok = strtok(NULL, ":"); } FREEBUF(buf1); FREEBUF(buf2); return retval; } /* * At this point the only pseudo commands are the "r" (repeat) and * the "h" (history) command: * * 1. an "r" alone, or "!!" along, just means repeat the last command. * 2. an "r" followed by a number, means repeat that command from the * history table. * 3. an "!" followed by a number that is not the name of a command * in the user's PATH, means repeat that command from the history table. * 4. an "r" followed by one or more non-decimal characters means to * seek back until a line-beginning match is found. * 5. an "h" alone, or a string beginning with "hi", means history. */ static int pseudo_command(char *input) { int i; HIST_ENTRY *entry; int idx, found; char *p; clean_line(input); /* * Just dump all commands that have been entered to date. */ if (STREQ(input, "h") || STRNEQ(input, "hi")) { dump_history(); pc->command_line[0] = NULLCHAR; return TRUE; } if (STREQ(input, "r") || STREQ(input, "!!")) { if (!history_offset) error(FATAL, "no commands entered!\n"); entry = history_get(history_offset); strcpy(input, entry->line); fprintf(fp, "%s%s\n", pc->prompt, input); return TRUE; } if ((input[0] == 'r') && decimal(&input[1], 0)) { if (!history_offset) error(FATAL, "no commands entered!\n"); p = &input[1]; goto rerun; } if ((input[0] == '!') && decimal(&input[1], 0) && !is_executable_in_PATH(first_nonspace(&input[1]))) { p = first_nonspace(&input[1]); goto rerun; } if (STRNEQ(input, "r ")) { if (!history_offset) error(FATAL, "no commands entered!\n"); p = first_nonspace(&input[1]); rerun: if (decimal(p, 0)) { idx = atoi(p); if (idx == 0) goto invalid_repeat_request; if (idx > history_offset) error(FATAL, "command %d not entered yet!\n", idx); entry = history_get(idx); strcpy(input, entry->line); fprintf(fp, "%s%s\n", pc->prompt, input); return TRUE; } idx = -1; found = FALSE; for (i = history_offset; i > 0; i--) { entry = history_get(i); if (STRNEQ(entry->line, p)) { found = TRUE; break; } } if (found) { strcpy(input, entry->line); fprintf(fp, "%s%s\n", pc->prompt, input); return TRUE; } invalid_repeat_request: fprintf(fp, "invalid repeat request: %s\n", input); strcpy(input, ""); return TRUE; } return FALSE; } /* * Dump the history table in first-to-last chronological order. */ void dump_history(void) { int i; HIST_ENTRY **the_history; HIST_ENTRY *entry; if (!history_offset) error(FATAL, "no commands entered!\n"); the_history = history_list(); for (i = 0; i < history_offset; i++) { entry = the_history[i]; fprintf(fp, "[%d] %s\n", i+1, entry->line); } } /* * Pager arguments. */ static char *less_argv[5] = { "/usr/bin/less", "-E", "-X", "-Ps -- MORE -- forward\\: , or j backward\\: b or k quit\\: q", NULL }; static char *more_argv[2] = { "/bin/more", NULL }; static char **CRASHPAGER_argv = NULL; int CRASHPAGER_valid(void) { int i, c; char *env, *CRASHPAGER_buf; char *arglist[MAXARGS]; if (CRASHPAGER_argv) return TRUE; if (!(env = getenv("CRASHPAGER"))) return FALSE; if (strstr(env, "|") || strstr(env, "<") || strstr(env, ">")) { error(INFO, "CRASHPAGER ignored: contains invalid character: \"%s\"\n", env); return FALSE; } if ((CRASHPAGER_buf = (char *)malloc(strlen(env)+1)) == NULL) return FALSE; strcpy(CRASHPAGER_buf, env); if (!(c = parse_line(CRASHPAGER_buf, arglist)) || !file_exists(arglist[0], NULL) || access(arglist[0], X_OK) || !(CRASHPAGER_argv = (char **)malloc(sizeof(char *) * (c+1)))) { free(CRASHPAGER_buf); if (strlen(env)) error(INFO, "CRASHPAGER ignored: \"%s\"\n", env); return FALSE; } for (i = 0; i < c; i++) CRASHPAGER_argv[i] = arglist[i]; CRASHPAGER_argv[i] = NULL; return TRUE; } /* * Set up a command string buffer for error/help output. */ char * setup_scroll_command(void) { char *buf; long i, len; if (!(pc->flags & SCROLL)) return NULL; switch (pc->scroll_command) { case SCROLL_LESS: buf = GETBUF(strlen(less_argv[0])+1); strcpy(buf, less_argv[0]); break; case SCROLL_MORE: buf = GETBUF(strlen(more_argv[0])+1); strcpy(buf, more_argv[0]); break; case SCROLL_CRASHPAGER: for (i = len = 0; CRASHPAGER_argv[i]; i++) len += strlen(CRASHPAGER_argv[i])+1; buf = GETBUF(len); for (i = 0; CRASHPAGER_argv[i]; i++) { sprintf(&buf[strlen(buf)], "%s%s", i ? " " : "", CRASHPAGER_argv[i]); } break; default: return NULL; } return buf; } /* * Parse the command line for pipe or redirect characters: * * 1. if a "|" character is found, popen() what comes after it, and * modify the contents of the global "fp" FILE pointer. * 2. if one or two ">" characters are found, fopen() the filename that * follows, and modify the contents of the global "fp" FILE pointer. * * Care is taken to segregate: * * 1. expressions encompassed by parentheses, or * 2. strings encompassed by single or double quotation marks * * When either of the above are in affect, no redirection is done. * * Lastly, if no redirection is requested by the user on the command line, * output is passed to the default scrolling command, which is popen()'d * and again, the contents of the global "fp" FILE pointer is modified. * This default behavior is not performed if the command is coming from * an input file, nor if scrolling has been turned off. */ static int setup_redirect(int origin) { char *p, which; int append; int expression; char string; int ret ATTRIBUTE_UNUSED; FILE *pipe; FILE *ofile; pc->redirect = origin; pc->eoc_index = 0; p = pc->command_line; if (STREQ(p, "|") || STREQ(p, "!")) { ret = system("/bin/sh"); pc->redirect |= REDIRECT_SHELL_ESCAPE; return REDIRECT_SHELL_ESCAPE; } if (FIRSTCHAR(p) == '|' || FIRSTCHAR(p) == '!') pc->redirect |= REDIRECT_SHELL_COMMAND; expression = 0; string = 0; while (*p) { if (*p == '(') expression++; if (*p == ')') expression--; if (*p == '\'' && string != '"') string = (string == '\'') ? 0 : '\''; else if (*p == '"' && string != '\'') string = (string == '"') ? 0 : '"'; if (!(expression || string) && ((*p == '|') || (*p == '!'))) { which = *p; *p = NULLCHAR; pc->eoc_index = p - pc->command_line; p++; p = strip_beginning_whitespace(p); if (!strlen(p)) { error(INFO, "no shell command after '%c'\n", which); pc->redirect |= REDIRECT_FAILURE; return REDIRECT_FAILURE; } if (LASTCHAR(p) == '|') error(FATAL_RESTART, "pipe to nowhere?\n"); if (pc->redirect & REDIRECT_SHELL_COMMAND) return shell_command(p); if ((pipe = popen(p, "w")) == NULL) { error(INFO, "cannot open pipe\n"); pc->redirect |= REDIRECT_FAILURE; return REDIRECT_FAILURE; } setbuf(pipe, NULL); switch (origin) { case FROM_COMMAND_LINE: fp = pc->pipe = pipe; break; case FROM_INPUT_FILE: fp = pc->ifile_pipe = pipe; break; } if (multiple_pipes(&p)) pc->redirect |= REDIRECT_MULTI_PIPE; strcpy(pc->pipe_command, p); null_first_space(pc->pipe_command); pc->redirect |= REDIRECT_TO_PIPE; if (!(pc->redirect & REDIRECT_SHELL_COMMAND)) { if ((pc->pipe_pid = output_command_to_pids())) pc->redirect |= REDIRECT_PID_KNOWN; else error(FATAL_RESTART, "pipe operation failed\n"); } return REDIRECT_TO_PIPE; } if (!(expression || string) && (*p == '>') && !((p > pc->command_line) && (*(p-1) == '-'))) { append = FALSE; *p = NULLCHAR; pc->eoc_index = p - pc->command_line; if (*(p+1) == '>') { append = TRUE; *p = NULLCHAR; p++; } p++; p = strip_beginning_whitespace(p); if (!strlen(p)) { error(INFO, "no file name after %s\n", append ? ">>" : ">"); pc->redirect |= REDIRECT_FAILURE; return REDIRECT_FAILURE; } if (pc->flags & IFILE_ERROR) append = TRUE; if ((ofile = fopen(p, append ? "a+" : "w+")) == NULL) { error(INFO, "unable to open %s\n", p); pc->redirect = REDIRECT_FAILURE; return REDIRECT_FAILURE; } setbuf(ofile, NULL); switch (origin) { case FROM_COMMAND_LINE: fp = pc->ofile = ofile; break; case FROM_INPUT_FILE: fp = pc->ifile_ofile = ofile; break; } pc->redirect |= REDIRECT_TO_FILE; return REDIRECT_TO_FILE; } p++; } if ((origin == FROM_COMMAND_LINE) && (pc->flags & TTY) && (pc->flags & SCROLL) && pc->scroll_command) { if (!strlen(pc->command_line) || STREQ(pc->command_line, "q") || STREQ(pc->command_line, "Q") || STREQ(pc->command_line, "exit") || STRNEQ(pc->command_line, "<")) { pc->redirect |= REDIRECT_NOT_DONE; return REDIRECT_NOT_DONE; } if (!setup_stdpipe()) { error(INFO, "cannot open pipe\n"); pc->redirect |= REDIRECT_FAILURE; return REDIRECT_FAILURE; } fp = pc->stdpipe; pc->redirect |= REDIRECT_TO_STDPIPE; switch (pc->scroll_command) { case SCROLL_LESS: strcpy(pc->pipe_command, less_argv[0]); break; case SCROLL_MORE: strcpy(pc->pipe_command, more_argv[0]); break; case SCROLL_CRASHPAGER: strcpy(pc->pipe_command, CRASHPAGER_argv[0]); break; } return REDIRECT_TO_STDPIPE; } pc->redirect |= REDIRECT_NOT_DONE; return REDIRECT_NOT_DONE; } /* * Find the last command in an input line that possibly contains * multiple pipes. */ int multiple_pipes(char **input) { char *p, *found; char quote; found = NULL; quote = 0; for (p = *input; *p; p++) { if (*p == '\'' && quote != '"') quote = (quote == '\'') ? 0 : '\''; else if (*p == '"' && quote != '\'') quote = (quote == '"') ? 0 : '"'; if (quote) continue; if (*p == '|') { if (STRNEQ(p, "||")) break; found = first_nonspace(p+1); } } if (found) { *input = found; return TRUE; } else return FALSE; } void debug_redirect(char *s) { int others; int alive; others = 0; console("%s: (", s); if (pc->redirect & FROM_COMMAND_LINE) console("%sFROM_COMMAND_LINE", others++ ? "|" : ""); if (pc->redirect & FROM_INPUT_FILE) console("%sFROM_INPUT_FILE", others++ ? "|" : ""); if (pc->redirect & REDIRECT_NOT_DONE) console("%sREDIRECT_NOT_DONE", others++ ? "|" : ""); if (pc->redirect & REDIRECT_TO_PIPE) console("%sREDIRECT_TO_PIPE", others++ ? "|" : ""); if (pc->redirect & REDIRECT_TO_STDPIPE) console("%sREDIRECT_TO_STDPIPE", others++ ? "|" : ""); if (pc->redirect & REDIRECT_TO_FILE) console("%sREDIRECT_TO_FILE", others++ ? "|" : ""); if (pc->redirect & REDIRECT_FAILURE) console("%sREDIRECT_FAILURE", others++ ? "|" : ""); if (pc->redirect & REDIRECT_SHELL_ESCAPE) console("%sREDIRECT_SHELL_ESCAPE", others++ ? "|" : ""); if (pc->redirect & REDIRECT_SHELL_COMMAND) console("%sREDIRECT_SHELL_COMMAND", others++ ? "|" : ""); if (pc->redirect & REDIRECT_PID_KNOWN) console("%sREDIRECT_PID_KNOWN", others++ ? "|" : ""); if (pc->redirect & REDIRECT_MULTI_PIPE) console("%sREDIRECT_MULTI_PIPE", others++ ? "|" : ""); console(")\n"); if (pc->pipe_pid || strlen(pc->pipe_command)) { if (pc->pipe_pid && PID_ALIVE(pc->pipe_pid)) alive = TRUE; else alive = FALSE; console("pipe_pid: %d (%s) pipe_command: %s\n", pc->pipe_pid, alive ? "alive" : "dead", pc->pipe_command); } } /* * Determine whether the pid receiving the current piped output is still * alive. * * NOTE: This routine returns TRUE by default, and only returns FALSE if * the pipe_pid exists *and* it's known to have died. Therefore the * caller must be cognizant of pc->pipe_pid or pc->stdpipe_pid. */ int output_open(void) { int waitstatus, waitret; if (!(pc->flags & TTY)) return TRUE; switch (pc->redirect & PIPE_OPTIONS) { case (REDIRECT_TO_STDPIPE|FROM_COMMAND_LINE): waitret = waitpid(pc->stdpipe_pid, &waitstatus, WNOHANG); if ((waitret == pc->stdpipe_pid) || (waitret == -1)) return FALSE; break; case (REDIRECT_TO_PIPE|FROM_INPUT_FILE): if (pc->curcmd_flags & REPEAT) break; /* FALLTHROUGH */ case (REDIRECT_TO_PIPE|FROM_COMMAND_LINE): switch (pc->redirect & (REDIRECT_MULTI_PIPE)) { case REDIRECT_MULTI_PIPE: if (!PID_ALIVE(pc->pipe_pid)) return FALSE; break; default: waitret = waitpid(pc->pipe_pid, &waitstatus, WNOHANG); if (waitret == pc->pipe_pid) return FALSE; if (waitret == -1) { /* intervening sh */ if (!PID_ALIVE(pc->pipe_pid)) return FALSE; } break; } break; default: break; } return TRUE; } /* * Determine the pids of the current popen'd shell and output command. * This is all done using /proc; the ps kludge at the bottom of this * routine is legacy, and should only get executed if /proc doesn't exist. */ static int output_command_to_pids(void) { DIR *dirp; struct dirent *dp; FILE *stp; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char lookfor[BUFSIZE+2]; char *pid, *name, *status, *p_pid, *pgrp, *comm; char *arglist[MAXARGS]; int argc; FILE *pipe; int retries, shell_has_exited; retries = 0; shell_has_exited = FALSE; pc->pipe_pid = pc->pipe_shell_pid = 0; comm = strrchr(pc->pipe_command, '/'); sprintf(lookfor, "(%s)", comm ? ++comm : pc->pipe_command); stall(1000); retry: if (is_directory("/proc") && (dirp = opendir("/proc"))) { for (dp = readdir(dirp); dp && !pc->pipe_pid; dp = readdir(dirp)) { if (!decimal(dp->d_name, 0)) continue; sprintf(buf1, "/proc/%s/stat", dp->d_name); if (file_exists(buf1, NULL) && (stp = fopen(buf1, "r"))) { if (fgets(buf2, BUFSIZE, stp)) { pid = strtok(buf2, " "); name = strtok(NULL, " "); status = strtok(NULL, " "); p_pid = strtok(NULL, " "); pgrp = strtok(NULL, " "); if (STREQ(name, "(sh)") && (atoi(p_pid) == getpid())) { pc->pipe_shell_pid = atoi(pid); if (STREQ(status, "Z")) shell_has_exited = TRUE; } if (STREQ(name, lookfor) && ((atoi(p_pid) == getpid()) || (atoi(p_pid) == pc->pipe_shell_pid) || (atoi(pgrp) == getpid()))) { pc->pipe_pid = atoi(pid); console( "FOUND[%d] (%d->%d->%d) %s %s p_pid: %s pgrp: %s\n", retries, getpid(), pc->pipe_shell_pid, pc->pipe_pid, name, status, p_pid, pgrp); } } fclose(stp); } } closedir(dirp); } if (!pc->pipe_pid && !shell_has_exited && ((retries++ < 10) || pc->pipe_shell_pid)) { stall(1000); goto retry; } console("getpid: %d pipe_shell_pid: %d pipe_pid: %d\n", getpid(), pc->pipe_shell_pid, pc->pipe_pid); if (pc->pipe_pid) return pc->pipe_pid; sprintf(buf1, "ps -ft %s", pc->my_tty); console("%s: ", buf1); if ((pipe = popen(buf1, "r")) == NULL) { error(INFO, "cannot determine output pid\n"); return 0; } while (fgets(buf1, BUFSIZE, pipe)) { argc = parse_line(buf1, arglist); if ((argc >= 8) && STREQ(arglist[7], pc->pipe_command) && STRNEQ(pc->my_tty, arglist[5])) { pc->pipe_pid = atoi(arglist[1]); break; } } pclose(pipe); console("%d\n", pc->pipe_pid); return pc->pipe_pid; } /* * Close straggling, piped-to, output commands. */ void close_output(void) { if ((pc->flags & TTY) && (pc->pipe_pid || strlen(pc->pipe_command)) && output_open()) kill(pc->pipe_pid, 9); } /* * Initialize what's needed for the command line: * * 1. termios structures for raw and cooked terminal mode. * 2. set up SIGINT and SIGPIPE handlers for aborted commands. * 3. set up the command history table. * 4. create the prompt string. */ void cmdline_init(void) { int fd = 0; /* * Stash a copy of the original termios setup. * Build a raw version for quick use for each command entry. */ if (isatty(fileno(stdin)) && ((fd = open("/dev/tty", O_RDONLY)) >= 0)) { if (tcgetattr(fd, &pc->termios_orig) == -1) error(FATAL, "tcgetattr /dev/tty: %s\n", strerror(errno)); if (tcgetattr(fd, &pc->termios_raw) == -1) error(FATAL, "tcgetattr /dev/tty: %s\n", strerror(errno)); close(fd); pc->termios_raw.c_lflag &= ~ECHO & ~ICANON; pc->termios_raw.c_cc[VMIN] = (char)1; pc->termios_raw.c_cc[VTIME] = (char)0; restore_sanity(); pc->flags |= TTY; set_my_tty(); SIGACTION(SIGINT, restart, &pc->sigaction, NULL); readline_init(); } else { if (fd < 0) error(INFO, "/dev/tty: %s\n", strerror(errno)); if (!(pc->flags & SILENT)) fprintf(fp, "NOTE: stdin: not a tty\n\n"); fflush(fp); pc->flags &= ~TTY; } SIGACTION(SIGPIPE, SIG_IGN, &pc->sigaction, NULL); set_command_prompt(NULL); } /* * Create and stash the original prompt, but allow changes during runtime. */ void set_command_prompt(char *new_prompt) { static char *orig_prompt = NULL; if (!orig_prompt) { if (!(orig_prompt = (char *)malloc(strlen(pc->program_name)+3))) error(FATAL, "cannot malloc prompt string\n"); sprintf(orig_prompt, "%s> ", pc->program_name); } if (new_prompt) pc->prompt = new_prompt; else pc->prompt = orig_prompt; } /* * SIGINT, SIGPIPE, and SIGSEGV handler. * Signal number 0 is sent for a generic restart. */ #define MAX_RECURSIVE_SIGNALS (10) #define MAX_SIGINTS_ACCEPTED (1) void restart(int sig) { static int in_restart = 0; console("restart (%s) %s\n", signame(sig), pc->flags & IN_GDB ? "(in gdb)" : "(in crash)"); if (sig == SIGUSR2) clean_exit(1); if (pc->flags & IN_RESTART) { fprintf(stderr, "\nembedded signal received (%s): recursive restart call\n", signame(sig)); if (++in_restart < MAX_RECURSIVE_SIGNALS) return; fprintf(stderr, "bailing out...\n"); clean_exit(1); } else { pc->flags |= IN_RESTART; in_restart = 0; } switch (sig) { case SIGSEGV: fflush(fp); fprintf(stderr, " \n", pc->flags & IN_GDB ? " in gdb" : ""); case 0: case SIGPIPE: restore_sanity(); break; case SIGINT: SIGACTION(SIGINT, restart, &pc->sigaction, NULL); pc->flags |= _SIGINT_; pc->sigint_cnt++; pc->flags &= ~IN_RESTART; if (pc->sigint_cnt == MAX_SIGINTS_ACCEPTED) { restore_sanity(); if (pc->ifile_in_progress) { pc->ifile_in_progress = 0; pc->ifile_offset = 0; } break; } return; default: fprintf(stderr, "unexpected signal received: %s\n", signame(sig)); restore_sanity(); close_output(); break; } fprintf(stderr, "\n"); pc->flags &= ~(IN_FOREACH|IN_GDB|IN_RESTART); longjmp(pc->main_loop_env, 1); } /* * Return a signal name string, or a number if the signal is not listed. */ static char * signame(int sig) { static char sigbuf[20]; switch (sig) { case SIGINT: sprintf(sigbuf, "SIGINT-%d", pc->sigint_cnt+1); return sigbuf; case SIGPIPE: return "SIGPIPE"; case SIGSEGV: return "SIGSEGV"; default: sprintf(sigbuf, "%d", sig); return sigbuf; } } /* * Restore the program environment to the state it was in before the * last command was executed: * * 1. close all temporarily opened pipes and output files. * 2. set the terminal back to normal cooked mode. * 3. free all temporary buffers. * 4. restore the last known output radix. */ static void restore_sanity(void) { int fd, waitstatus; struct extension_table *ext; struct command_table_entry *cp; if (pc->stdpipe) { close(fileno(pc->stdpipe)); pc->stdpipe = NULL; if (pc->stdpipe_pid && PID_ALIVE(pc->stdpipe_pid)) { while (!waitpid(pc->stdpipe_pid, &waitstatus, WNOHANG)) stall(1000); } pc->stdpipe_pid = 0; } if (pc->pipe) { close(fileno(pc->pipe)); pc->pipe = NULL; console("wait for redirect %d->%d to finish...\n", pc->pipe_shell_pid, pc->pipe_pid); if (pc->pipe_pid) while (PID_ALIVE(pc->pipe_pid)) { waitpid(pc->pipe_pid, &waitstatus, WNOHANG); stall(1000); } if (pc->pipe_shell_pid) while (PID_ALIVE(pc->pipe_shell_pid)) { waitpid(pc->pipe_shell_pid, &waitstatus, WNOHANG); stall(1000); } pc->pipe_pid = 0; } if (pc->ifile_pipe) { fflush(pc->ifile_pipe); close(fileno(pc->ifile_pipe)); pc->ifile_pipe = NULL; if (pc->pipe_pid && ((pc->redirect & (PIPE_OPTIONS|REDIRECT_PID_KNOWN)) == (FROM_INPUT_FILE|REDIRECT_TO_PIPE|REDIRECT_PID_KNOWN))) { console("wait for redirect %d->%d to finish...\n", pc->pipe_shell_pid, pc->pipe_pid); while (PID_ALIVE(pc->pipe_pid)) { waitpid(pc->pipe_pid, &waitstatus, WNOHANG); stall(1000); } if (pc->pipe_shell_pid) while (PID_ALIVE(pc->pipe_shell_pid)) { waitpid(pc->pipe_shell_pid, &waitstatus, WNOHANG); stall(1000); } if (pc->redirect & (REDIRECT_MULTI_PIPE)) wait_for_children(ALL_CHILDREN); } } if (pc->ofile) { fclose(pc->ofile); pc->ofile = NULL; } if (pc->ifile_ofile) { fclose(pc->ifile_ofile); pc->ifile_ofile = NULL; } if (pc->ifile) { fclose(pc->ifile); pc->ifile = NULL; } if (pc->args_ifile) { fclose(pc->args_ifile); pc->args_ifile = NULL; } if (pc->tmpfile) close_tmpfile(); if (pc->tmpfile2) close_tmpfile2(); if (pc->cmd_cleanup) pc->cmd_cleanup(pc->cmd_cleanup_arg); if (pc->flags & TTY) { if ((fd = open("/dev/tty", O_RDONLY)) < 0) { console("/dev/tty: %s\n", strerror(errno)); clean_exit(1); } if (tcsetattr(fd, TCSANOW, &pc->termios_orig) == -1) error(FATAL, "tcsetattr /dev/tty: %s\n", strerror(errno)); close(fd); } wait_for_children(ZOMBIES_ONLY); pc->flags &= ~(INIT_IFILE|RUNTIME_IFILE|IFILE_ERROR|_SIGINT_|PLEASE_WAIT); pc->sigint_cnt = 0; pc->redirect = 0; pc->pipe_command[0] = NULLCHAR; pc->pipe_pid = 0; pc->pipe_shell_pid = 0; pc->sbrk = sbrk(0); if ((pc->curcmd_flags & (UD2A_INSTRUCTION|BAD_INSTRUCTION)) == (UD2A_INSTRUCTION|BAD_INSTRUCTION)) error(WARNING, "A (bad) instruction was noted in last disassembly.\n" " Use \"dis -b [number]\" to set/restore the number of\n" " encoded bytes to skip after a ud2a (BUG) instruction.\n"); pc->curcmd_flags = 0; pc->curcmd_private = 0; restore_gdb_sanity(); free_all_bufs(); /* * Clear the structure cache references -- no-ops if DUMPFILE(). */ clear_task_cache(); clear_machdep_cache(); clear_swap_info_cache(); clear_file_cache(); clear_dentry_cache(); clear_inode_cache(); clear_vma_cache(); clear_active_set(); if (kt->ikconfig_flags & IKCONFIG_LOADED) read_in_kernel_config(IKCFG_FREE); /* * Call the cleanup() function of any extension. */ for (ext = extension_table; ext; ext = ext->next) { for (cp = ext->command_table; cp->name; cp++) { if (cp->flags & CLEANUP) (*cp->func)(); } } if (CRASHDEBUG(5)) { dump_filesys_table(0); dump_vma_cache(0); } if (REMOTE()) remote_clear_pipeline(); hq_close(); } /* * Similar to above, but only called in between each command that is * read from an input file. */ static void restore_ifile_sanity(void) { int fd; pc->flags &= ~IFILE_ERROR; if (pc->ifile_pipe) { close(fileno(pc->ifile_pipe)); pc->ifile_pipe = NULL; } if (pc->ifile_ofile) { fclose(pc->ifile_ofile); pc->ifile_ofile = NULL; } if (pc->flags & TTY) { if ((fd = open("/dev/tty", O_RDONLY)) < 0) { console("/dev/tty: %s\n", strerror(errno)); clean_exit(1); } if (tcsetattr(fd, TCSANOW, &pc->termios_orig) == -1) error(FATAL, "tcsetattr /dev/tty: %s\n", strerror(errno)); close(fd); } if (pc->tmpfile2) { close_tmpfile2(); } wait_for_children(ALL_CHILDREN); restore_gdb_sanity(); free_all_bufs(); hq_close(); } /* * Check whether a SIGINT was received during the execution of a command, * clearing the flag if it was set. This allows individual commands or * entities to do whatever is appropriate to handle CTRL-C. */ int received_SIGINT(void) { if (pc->flags & _SIGINT_) { pc->flags &= ~_SIGINT_; pc->sigint_cnt = 0; if (pc->ifile_in_progress) { pc->ifile_in_progress = 0; pc->ifile_offset = 0; } return TRUE; } else return FALSE; } /* * Look for an executable file that begins with #! */ static int is_shell_script(char *s) { int fd; char interp[2]; struct stat sbuf; if ((fd = open(s, O_RDONLY)) < 0) return FALSE; if (isatty(fd)) { close(fd); return FALSE; } if (read(fd, interp, 2) != 2) { close(fd); return FALSE; } if (!STRNEQ(interp, "#!")) { close(fd); return FALSE; } close(fd); if (stat(s, &sbuf) == -1) return FALSE; if (!(sbuf.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))) return FALSE; return TRUE; } /* * After verifying the user's input file, loop through each line, executing * one command at a time. This command pretty much does the same as * get_command_line(), but also kicks off the command execution as well. * It's kept self-contained, as indicated by the RUNTIME_IFILE flag, and * keeps its own internal sanity by calling restore_ifile_sanity() between * each line. */ void exec_input_file(void) { char *file; FILE *incoming_fp; char buf[BUFSIZE]; ulong this; /* * Do start-up .rc or input files in the proper order. */ if (pc->flags & RCHOME_IFILE) { this = RCHOME_IFILE; pc->flags &= ~RCHOME_IFILE; } else if (pc->flags & RCLOCAL_IFILE) { this = RCLOCAL_IFILE; pc->flags &= ~RCLOCAL_IFILE; } else if (pc->flags & CMDLINE_IFILE) { this = CMDLINE_IFILE; pc->flags &= ~CMDLINE_IFILE; } else this = 0; if (pc->flags & RUNTIME_IFILE) { error(INFO, "embedded input files not allowed!\n"); return; } if (argcnt < 2) { error(INFO, "no input file entered!\n"); return; } else file = args[1]; if (!file_exists(file, NULL)) { error(INFO, "%s: %s\n", file, strerror(ENOENT)); return; } if (is_elf_file(file)) { error(INFO, "input from executable files not supported yet!\n"); return; } if (is_shell_script(file)) { error(INFO, "input from shell scripts not supported yet!\n"); return; } if ((pc->ifile = fopen(file, "r")) == NULL) { error(INFO, "%s: %s\n", file, strerror(errno)); return; } pc->flags |= RUNTIME_IFILE; incoming_fp = fp; /* * Handle runtime commands that use input files. */ if ((pc->ifile_in_progress = this) == 0) { if (!pc->runtime_ifile_cmd) { if (!(pc->runtime_ifile_cmd = (char *)malloc(BUFSIZE))) { error(INFO, "cannot malloc input file command line buffer\n"); return; } BZERO(pc->runtime_ifile_cmd, BUFSIZE); } if (!strlen(pc->runtime_ifile_cmd)) strcpy(pc->runtime_ifile_cmd, pc->orig_line); pc->ifile_in_progress = RUNTIME_IFILE; } /* * If there's an offset, then there was a FATAL error caused * by the last command executed from the input file. */ if (pc->ifile_offset) fseek(pc->ifile, (long)pc->ifile_offset, SEEK_SET); while (fgets(buf, BUFSIZE-1, pc->ifile)) { /* * Restore normal environment. */ fp = incoming_fp; restore_ifile_sanity(); BZERO(pc->command_line, BUFSIZE); BZERO(pc->orig_line, BUFSIZE); if (this & (RCHOME_IFILE|RCLOCAL_IFILE)) pc->curcmd_flags |= FROM_RCFILE; pc->ifile_offset = ftell(pc->ifile); if (STRNEQ(buf, "#") || STREQ(buf, "\n")) continue; check_special_handling(buf); strcpy(pc->command_line, buf); clean_line(pc->command_line); strcpy(pc->orig_line, pc->command_line); strip_linefeeds(pc->orig_line); resolve_aliases(); switch (setup_redirect(FROM_INPUT_FILE)) { case REDIRECT_NOT_DONE: case REDIRECT_TO_PIPE: case REDIRECT_TO_FILE: break; case REDIRECT_SHELL_ESCAPE: case REDIRECT_SHELL_COMMAND: continue; case REDIRECT_FAILURE: goto done_input; } if (CRASHDEBUG(1)) console(buf); if (!(argcnt = parse_line(pc->command_line, args))) continue; if (!(pc->flags & SILENT)) { fprintf(incoming_fp, "%s%s", pc->prompt, buf); fflush(incoming_fp); } exec_command(); if (received_SIGINT()) goto done_input; } done_input: fclose(pc->ifile); pc->ifile = NULL; pc->flags &= ~RUNTIME_IFILE; pc->ifile_offset = 0; if (pc->runtime_ifile_cmd) BZERO(pc->runtime_ifile_cmd, BUFSIZE); pc->ifile_in_progress = 0; } /* * Prime the alias list with a few built-in's. */ void alias_init(char *inbuf) { char buf[BUFSIZE]; if (inbuf) { strcpy(buf, inbuf); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); return; } strcpy(buf, "alias man help"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias ? help"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias quit q"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias sf set scroll off"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias sn set scroll on"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias hex set radix 16"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias dec set radix 10"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias g gdb"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias px p -x"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias pd p -d"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias for foreach"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias size *"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias dmesg log"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); strcpy(buf, "alias lsmod mod"); argcnt = parse_line(buf, args); allocate_alias(ALIAS_BUILTIN); } /* * Before the command line is parsed, take a snapshot and parse the snapshot. * If args[0] is an known alias, recreate the pc->command_line string with * the alias substitution. */ static void resolve_aliases(void) { int i; struct alias_data *ad; int found; char *p1, *remainder; char buf1[BUFSIZE]; char buf2[BUFSIZE]; if (!strlen(pc->command_line)) return; strcpy(buf1, pc->command_line); argcnt = parse_line(buf1, args); if (argcnt > 1) { strcpy(buf2, &pc->command_line[args[1] - buf1]); remainder = buf2; } else remainder = NULL; found = FALSE; for (ad = alias_head.next; ad; ad = ad->next) { if (STREQ(ad->alias, args[0])) { for (i = 0; i < ad->argcnt; i++) args[i] = ad->args[i]; found = TRUE; break; } } if (!found) return; BZERO(pc->command_line, BUFSIZE); p1 = pc->command_line; for (i = 0; i < ad->argcnt; i++) { snprintf(p1, BUFSIZE - (p1-pc->command_line), "%s ", args[i]); while (*p1) p1++; if ((p1 - pc->command_line) >= BUFSIZE) break; } if (remainder) { if ((strlen(remainder)+strlen(pc->command_line)) < BUFSIZE) strcat(pc->command_line, remainder); else error(INFO, "command line overflow.\n"); } else if (strlen(pc->command_line) >= (BUFSIZE-1)) error(INFO, "command line overflow.\n"); clean_line(pc->command_line); } /* * If input string is an alias, return a pointer to the alias_data struct. */ struct alias_data * is_alias(char *s) { struct alias_data *ad; for (ad = alias_head.next; ad; ad = ad->next) { if (STREQ(ad->alias, s)) return(ad); } return NULL; } /* * .rc file commands that are "set" commands may be performed prior * to initialization, so pass them to cmd_set() for consideration. * All other commands are flagged for execution by exec_input_file() * after session initialization is complete. */ void resolve_rc_cmd(char *s, int origin) { clean_line(s); if (*s == '#') return; if ((argcnt = parse_line(s, args)) == 0) return; if (STREQ(args[0], "set")) { optind = 0; cmd_set(); } switch (origin) { case ALIAS_RCHOME: pc->flags |= RCHOME_IFILE; break; case ALIAS_RCLOCAL: pc->flags |= RCLOCAL_IFILE; break; } return; } /* * The "alias" command. With no arguments, list all aliases. With one * argument -- which must be an alias -- display the string it's aliased to. * With two or more arguments, setup a new alias, where the first argument * is the alias, and the remaining arguments make up the alias string. * If the second arg is the NULL string "", delete the alias. */ void cmd_alias(void) { if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); switch (argcnt) { case 1: list_aliases(NULL); break; case 2: list_aliases(args[1]); break; default: if (allocate_alias(ALIAS_RUNTIME)) list_aliases(args[1]); break; } } /* * Dump the current set of aliases. */ static void list_aliases(char *s) { int i; struct alias_data *ad; int found, precision; char buf[BUFSIZE]; if (!alias_head.next) { error(INFO, "alias list is empty\n"); return; } BZERO(buf, BUFSIZE); found = FALSE; precision = 7; for (ad = alias_head.next; ad; ad = ad->next) { switch (ad->origin) { case ALIAS_RCLOCAL: sprintf(buf, ".%src", pc->program_name); if (strlen(buf) > precision) precision = strlen(buf); break; case ALIAS_RCHOME: sprintf(buf, "$HOME/.%src", pc->program_name); if (strlen(buf) > precision) precision = strlen(buf); break; } } fprintf(fp, "ORIGIN"); pad_line(fp, precision-6, ' '); BZERO(buf, BUFSIZE); fprintf(fp, " ALIAS COMMAND\n"); for (ad = alias_head.next; ad; ad = ad->next) { if (s && !STREQ(s, ad->alias)) continue; found = TRUE; switch (ad->origin) { case ALIAS_RUNTIME: sprintf(buf, "runtime"); break; case ALIAS_RCLOCAL: sprintf(buf, ".%src", pc->program_name); break; case ALIAS_RCHOME: sprintf(buf, "$HOME/.%src", pc->program_name); break; case ALIAS_BUILTIN: sprintf(buf, "builtin"); break; } fprintf(fp, "%s ", buf); pad_line(fp, precision-strlen(buf), ' '); fprintf(fp, "%-7s ", ad->alias); for (i = 0; i < ad->argcnt; i++) { fprintf(fp, "%s ", ad->args[i]); } fprintf(fp, "\n"); } if (s && !found) fprintf(fp, "alias does not exist: %s\n", s); } /* * Verify the alias request set up in the args[] array: * * 1. make sure that the alias string starts with a legitimate command. * 2. if the already exists, deallocate its current version. * * Then malloc space for the alias string, and link it in to the alias list. */ static int allocate_alias(int origin) { int i; int size; struct alias_data *ad; struct alias_data *newad; char *p1, *enclosed_string; int found; if ((enclosed_string = strstr(args[2], " "))) *enclosed_string = NULLCHAR; found = FALSE; if (get_command_table_entry(args[1])) { error(INFO, "cannot alias existing command name: %s\n", args[1]); return FALSE; } if (get_command_table_entry(args[2])) found = TRUE; /* Accept the "clear" external command exceptionally. */ if (STREQ(args[2], "clear")) found = TRUE; if (!found) { if (!strlen(args[2])) { if (alias_exists(args[1])) { deallocate_alias(args[1]); fprintf(fp, "alias deleted: %s\n", args[1]); } } else { error(INFO, "invalid alias attempt on non-existent command: %s\n", args[2]); } return FALSE; } if (alias_exists(args[1])) deallocate_alias(args[1]); if (enclosed_string) *enclosed_string = ' '; size = sizeof(struct alias_data) + argcnt; for (i = 0; i < argcnt; i++) size += strlen(args[i]); if ((newad = (struct alias_data *)malloc(size+1)) == NULL) { error(INFO, "alias_data malloc: %s\n", strerror(errno)); return FALSE; } BZERO(newad, size); newad->next = NULL; newad->size = size; newad->origin = origin; p1 = newad->argbuf; for (i = 1; i < argcnt; i++) { sprintf(p1, "%s ", args[i]); while (*p1) p1++; } p1 = strstr(newad->argbuf, " "); *p1 = NULLCHAR; newad->alias = newad->argbuf; newad->argcnt = parse_line(p1+1, newad->args); for (ad = &alias_head; ad->next; ad = ad->next) ; ad->next = newad; return TRUE; } /* * Check whether the passed-in string is a currently-existing alias. */ static int alias_exists(char *s) { struct alias_data *ad; if (!alias_head.next) return FALSE; for (ad = alias_head.next; ad; ad = ad->next) if (STREQ(ad->alias, s)) return TRUE; return FALSE; } /* * If the passed-in string is an alias, delink it and free its memory. */ void deallocate_alias(char *s) { struct alias_data *ad, *lastad; for (ad = alias_head.next, lastad = &alias_head; ad; ad = ad->next) { if (!STREQ(ad->alias, s)) { lastad = ad; continue; } lastad->next = ad->next; free(ad); break; } } /* * "help -a" output */ void dump_alias_data(void) { int i; struct alias_data *ad; fprintf(fp, "alias_head.next: %lx\n\n", (ulong)alias_head.next); for (ad = alias_head.next; ad; ad = ad->next) { fprintf(fp, " next: %lx\n", (ulong)ad->next); fprintf(fp, " alias: %s\n", ad->alias); fprintf(fp, " size: %d\n", ad->size); fprintf(fp, " origin: "); switch (ad->origin) { case ALIAS_RUNTIME: fprintf(fp, "runtime setting \n"); break; case ALIAS_RCLOCAL: fprintf(fp, ".%src \n", pc->program_name); break; case ALIAS_RCHOME: fprintf(fp, "$HOME/.%src \n", pc->program_name); break; case ALIAS_BUILTIN: fprintf(fp, "builtin\n"); break; } fprintf(fp, " argcnt: %d\n", ad->argcnt); for (i = 0; i < ad->argcnt; i++) fprintf(fp, " args[%d]: %lx: %s\n", i, (ulong)ad->args[i], ad->args[i]); fprintf(fp, "\n"); } } /* * Repeat a command on a live system. */ void cmd_repeat(void) { ulong delay; char buf[BUFSIZE]; char bufsave[BUFSIZE]; FILE *incoming_fp; if (argcnt == 1) cmd_usage(pc->curcmd, SYNOPSIS); delay = 0; if (args[1][0] == '-') { switch (args[1][1]) { default: case NULLCHAR: cmd_usage(pc->curcmd, SYNOPSIS); case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': delay = dtol(&args[1][1], FAULT_ON_ERROR, NULL); concat_args(buf, 2, FALSE); break; } } else concat_args(buf, 1, FALSE); check_special_handling(buf); strcpy(pc->command_line, buf); resolve_aliases(); if (!argcnt) return; strcpy(buf, pc->command_line); strcpy(bufsave, buf); argcnt = parse_line(buf, args); if (!argcnt) return; if (STREQ(args[0], "<") && (pc->flags & TTY) && (pc->flags & SCROLL) && pc->scroll_command) error(FATAL, "scrolling must be turned off when repeating an input file\n"); pc->curcmd_flags |= REPEAT; incoming_fp = fp; while (TRUE) { optind = 0; fp = incoming_fp; exec_command(); free_all_bufs(); wait_for_children(ZOMBIES_ONLY); if (received_SIGINT() || !output_open()) break; if ((pc->flags & TTY) && !is_a_tty("/dev/tty")) break; if (!(pc->curcmd_flags & REPEAT)) break; if (delay) sleep(delay); strcpy(buf, bufsave); argcnt = parse_line(buf, args); } } /* * Initialize readline, set the editing mode, and then perform any * crash-specific bindings, etc. */ static void readline_init(void) { rl_initialize(); if (STREQ(pc->editing_mode, "vi")) { rl_editing_mode = vi_mode; rl_bind_key(CTRL('N'), rl_get_next_history); rl_bind_key(CTRL('P'), rl_get_previous_history); rl_bind_key_in_map(CTRL('P'), rl_get_previous_history, vi_insertion_keymap); rl_bind_key_in_map(CTRL('N'), rl_get_next_history, vi_insertion_keymap); rl_bind_key_in_map(CTRL('l'), rl_clear_screen, vi_insertion_keymap); rl_generic_bind(ISFUNC, "[A", (char *)rl_get_previous_history, vi_movement_keymap); rl_generic_bind(ISFUNC, "[B", (char *)rl_get_next_history, vi_movement_keymap); } if (STREQ(pc->editing_mode, "emacs")) { rl_editing_mode = emacs_mode; } rl_attempted_completion_function = crash_readline_completer; rl_attempted_completion_over = 1; } /* * Find and set the tty string of this session as seen in "ps -ef" output. */ static void set_my_tty(void) { char buf[BUFSIZE]; char *arglist[MAXARGS]; int argc; FILE *pipe; strcpy(pc->my_tty, "?"); if (file_exists("/usr/bin/tty", NULL)) { sprintf(buf, "/usr/bin/tty"); if ((pipe = popen(buf, "r")) == NULL) return; while (fgets(buf, BUFSIZE, pipe)) { if (STRNEQ(buf, "/dev/")) { strcpy(pc->my_tty, strip_line_end(&buf[strlen("/dev/")])); break; } } pclose(pipe); return; } sprintf(buf, "ps -ef | grep ' %d '", getpid()); if (CRASHDEBUG(1)) fprintf(fp, "popen(%s)\n", buf); if ((pipe = popen(buf, "r")) == NULL) return; while (fgets(buf, BUFSIZE, pipe)) { argc = parse_line(buf, arglist); if ((argc >= 8) && (atoi(arglist[1]) == getpid())) { if (strlen(arglist[5]) < 9) strcpy(pc->my_tty, arglist[5]); else strncpy(pc->my_tty, arglist[5], 9); } } pclose(pipe); } /* * Check whether SIGINT's are allowed before shipping a request off to gdb. */ int interruptible(void) { if (!(pc->flags & RUNTIME)) return FALSE; if (!(pc->flags & TTY)) return FALSE; if ((pc->redirect & (FROM_INPUT_FILE|REDIRECT_NOT_DONE)) == (FROM_INPUT_FILE|REDIRECT_NOT_DONE)) return TRUE; if (strlen(pc->pipe_command)) return FALSE; return TRUE; } /* * Set up the standard output pipe using whichever was selected during init. */ static int setup_stdpipe(void) { char *path; if (pipe(pc->pipefd) < 0) { error(INFO, "pipe system call failed: %s", strerror(errno)); return FALSE; } if ((pc->stdpipe_pid = fork()) < 0) { error(INFO, "fork system call failed: %s", strerror(errno)); return FALSE; } path = NULL; if (pc->stdpipe_pid > 0) { pc->redirect |= REDIRECT_PID_KNOWN; close(pc->pipefd[0]); /* parent closes read end */ if ((pc->stdpipe = fdopen(pc->pipefd[1], "w")) == NULL) { error(INFO, "fdopen system call failed: %s", strerror(errno)); return FALSE; } setbuf(pc->stdpipe, NULL); switch (pc->scroll_command) { case SCROLL_LESS: strcpy(pc->pipe_command, less_argv[0]); break; case SCROLL_MORE: strcpy(pc->pipe_command, more_argv[0]); break; case SCROLL_CRASHPAGER: strcpy(pc->pipe_command, CRASHPAGER_argv[0]); break; } if (CRASHDEBUG(2)) console("pipe: %lx\n", pc->stdpipe); return TRUE;; } else { close(pc->pipefd[1]); /* child closes write end */ if (dup2(pc->pipefd[0], 0) != 0) { perror("child dup2 failed"); clean_exit(1); } if (CRASHDEBUG(2)) console("execv: %d\n", getpid()); switch (pc->scroll_command) { case SCROLL_LESS: path = less_argv[0]; execv(path, less_argv); break; case SCROLL_MORE: path = more_argv[0]; execv(path, more_argv); break; case SCROLL_CRASHPAGER: path = CRASHPAGER_argv[0]; execv(path, CRASHPAGER_argv); break; } perror(path); fprintf(stderr, "execv of scroll command failed\n"); exit(1); } } static void wait_for_children(ulong waitflag) { int status, pid; while (TRUE) { switch (pid = waitpid(-1, &status, WNOHANG)) { case 0: if (CRASHDEBUG(2)) console("wait_for_children: child running...\n"); if (waitflag == ZOMBIES_ONLY) return; break; case -1: if (CRASHDEBUG(2)) console("wait_for_children: no children alive\n"); return; default: console("wait_for_children(%d): reaped %d\n", waitflag, pid); if (CRASHDEBUG(2)) fprintf(fp, "wait_for_children: reaped %d\n", pid); break; } stall(1000); } } /* * Run an escaped shell command, redirecting the output to * the current output file. */ int shell_command(char *cmd) { FILE *pipe; char buf[BUFSIZE]; if ((pipe = popen(cmd, "r")) == NULL) { error(INFO, "cannot open pipe: %s\n", cmd); pc->redirect &= ~REDIRECT_SHELL_COMMAND; pc->redirect |= REDIRECT_FAILURE; return REDIRECT_FAILURE; } while (fgets(buf, BUFSIZE, pipe)) fputs(buf, fp); pclose(pipe); return REDIRECT_SHELL_COMMAND; } static int verify_args_input_file(char *fileptr) { struct stat stat; if (!file_exists(fileptr, &stat)) { if (CRASHDEBUG(1)) error(INFO, "%s: no such file\n", fileptr); } else if (!S_ISREG(stat.st_mode)) { if (CRASHDEBUG(1)) error(INFO, "%s: not a regular file\n", fileptr); } else if (!stat.st_size) { if (CRASHDEBUG(1)) error(INFO, "%s: file is empty\n", fileptr); } else if (!file_readable(fileptr)) { if (CRASHDEBUG(1)) error(INFO, "%s: permission denied\n", fileptr); } else return TRUE; return FALSE; } /* * Verify a command line argument input file. */ #define NON_FILENAME_CHARS "*?!|\'\"{}<>;,^()$~" int is_args_input_file(struct command_table_entry *ct, struct args_input_file *aif) { int c, start, whites, args_used; char *p1, *p2, *curptr, *fileptr; char buf[BUFSIZE]; int retval; if (pc->curcmd_flags & NO_MODIFY) return FALSE; if (STREQ(ct->name, "repeat")) return FALSE; BZERO(aif, sizeof(struct args_input_file)); retval = FALSE; if (STREQ(ct->name, "gdb")) { curptr = pc->orig_line; next_gdb: if ((p1 = strstr(curptr, "<"))) { while (STRNEQ(p1, "<<")) { p2 = p1+2; if (!(p1 = strstr(p2, "<"))) return retval; } } if (!p1) return retval; start = p1 - curptr; p2 = p1+1; for (whites = 0; whitespace(*p2); whites++) p2++; if (*p2 == NULLCHAR) return retval; strcpy(buf, p2); p2 = buf; if (*p2) { fileptr = p2; while (*p2 && !whitespace(*p2) && (strpbrk(p2, NON_FILENAME_CHARS) != p2)) p2++; *p2 = NULLCHAR; if (verify_args_input_file(fileptr)) { if (retval == TRUE) { error(INFO, "ignoring multiple argument input files: " "%s and %s\n", aif->fileptr, fileptr); return FALSE; } aif->start = start; aif->resume = start + (p2-buf) + whites + 1; aif->fileptr = GETBUF(strlen(fileptr)+1); strcpy(aif->fileptr, fileptr); aif->is_gdb_cmd = TRUE; retval = TRUE; } } curptr = p1+1; goto next_gdb; } for (c = 0; c < argcnt; c++) { if (STRNEQ(args[c], "<") && !STRNEQ(args[c], "<<")) { if (strlen(args[c]) > 1) { fileptr = &args[c][1]; args_used = 1; } else { if ((c+1) == argcnt) error(FATAL, "< requires a file argument\n"); fileptr = args[c+1]; args_used = 2; } if (!verify_args_input_file(fileptr)) continue; if (retval == TRUE) error(FATAL, "multiple input files are not supported\n"); aif->index = c; aif->fileptr = GETBUF(strlen(fileptr)+1); strcpy(aif->fileptr, fileptr); aif->args_used = args_used; retval = TRUE; continue; } if (STRNEQ(args[c], "(")) { curptr = args[c]; next_expr: if ((p1 = strstr(curptr, "<"))) { while (STRNEQ(p1, "<<")) { p2 = p1+2; if (!(p1 = strstr(p2, "<"))) continue; } } if (!p1) continue; start = p1 - curptr; p2 = p1+1; for (whites = 0; whitespace(*p2); whites++) p2++; if (*p2 == NULLCHAR) continue; strcpy(buf, p2); p2 = buf; if (*p2) { fileptr = p2; while (*p2 && !whitespace(*p2) && (strpbrk(p2, NON_FILENAME_CHARS) != p2)) p2++; *p2 = NULLCHAR; if (!verify_args_input_file(fileptr)) continue; if (retval == TRUE) { error(INFO, "ignoring multiple argument input files: " "%s and %s\n", aif->fileptr, fileptr); return FALSE; } retval = TRUE; aif->in_expression = TRUE; aif->args_used = 1; aif->index = c; aif->start = start; aif->resume = start + (p2-buf) + whites + 1; aif->fileptr = GETBUF(strlen(fileptr)+1); strcpy(aif->fileptr, fileptr); } curptr = p1+1; goto next_expr; } } return retval; } static void modify_orig_line(char *inbuf, struct args_input_file *aif) { char buf[BUFSIZE]; strcpy(buf, pc->orig_line); strcpy(&buf[aif->start], inbuf); strcat(buf, &pc->orig_line[aif->resume]); strcpy(pc->orig_line, buf); } static void modify_expression_arg(char *inbuf, char **aif_args, struct args_input_file *aif) { char *old, *new; old = aif_args[aif->index]; new = GETBUF(strlen(aif_args[aif->index]) + strlen(inbuf)); strcpy(new, old); strcpy(&new[aif->start], inbuf); strcat(new, &old[aif->resume]); aif_args[aif->index] = new; } /* * Sequence through an args input file, and for each line, * reinitialize the global args[] and argcnt, and issue the command. */ void exec_args_input_file(struct command_table_entry *ct, struct args_input_file *aif) { char buf[BUFSIZE]; int i, c, aif_cnt; int orig_argcnt; char *aif_args[MAXARGS]; char *new_args[MAXARGS]; char *orig_args[MAXARGS]; char orig_line[BUFSIZE]; char *save_args[MAXARGS]; char save_line[BUFSIZE]; if ((pc->args_ifile = fopen(aif->fileptr, "r")) == NULL) error(FATAL, "%s: %s\n", aif->fileptr, strerror(errno)); if (aif->is_gdb_cmd) strcpy(orig_line, pc->orig_line); BCOPY(args, orig_args, sizeof(args)); orig_argcnt = argcnt; /* * Commands cannot be trusted to leave the arguments intact. * Stash them here and restore them each time through the loop. */ save_args[0] = save_line; for (i = 0; i < orig_argcnt; i++) { strcpy(save_args[i], orig_args[i]); save_args[i+1] = save_args[i] + strlen(save_args[i]) + 2; } while (fgets(buf, BUFSIZE-1, pc->args_ifile)) { clean_line(buf); if ((strlen(buf) == 0) || (buf[0] == '#')) continue; for (i = 1; i < orig_argcnt; i++) strcpy(orig_args[i], save_args[i]); if (aif->is_gdb_cmd) { console("(gdb) before: [%s]\n", orig_line); strcpy(pc->orig_line, orig_line); modify_orig_line(buf, aif); console("(gdb) after: [%s]\n", pc->orig_line); } else if (aif->in_expression) { console("expr before: [%s]\n", orig_args[aif->index]); BCOPY(orig_args, aif_args, sizeof(aif_args)); modify_expression_arg(buf, aif_args, aif); BCOPY(aif_args, args, sizeof(aif_args)); console("expr after: [%s]\n", args[aif->index]); } else { if (!(aif_cnt = parse_line(buf, aif_args))) continue; for (i = 0; i < orig_argcnt; i++) console("%s[%d]:%s %s", (i == 0) ? "before: " : "", i, orig_args[i], (i+1) == orig_argcnt ? "\n" : ""); for (i = 0; i < aif->index; i++) new_args[i] = orig_args[i]; for (i = aif->index, c = 0; c < aif_cnt; c++, i++) new_args[i] = aif_args[c]; for (i = aif->index + aif_cnt, c = aif->index + aif->args_used; c < orig_argcnt; c++, i++) new_args[i] = orig_args[c]; argcnt = orig_argcnt - aif->args_used + aif_cnt; new_args[argcnt] = NULL; BCOPY(new_args, args, sizeof(args)); for (i = 0; i < argcnt; i++) console("%s[%d]:%s %s", (i == 0) ? " after: " : "", i, args[i], (i+1) == argcnt ? "\n" : ""); } optind = argerrs = 0; pc->cmdgencur++; if (setjmp(pc->foreach_loop_env)) pc->flags &= ~IN_FOREACH; else { pc->flags |= IN_FOREACH; (*ct->func)(); pc->flags &= ~IN_FOREACH; } if (pc->cmd_cleanup) pc->cmd_cleanup(pc->cmd_cleanup_arg); free_all_bufs(); if (received_SIGINT()) break; } fclose(pc->args_ifile); pc->args_ifile = NULL; } static char * crash_readline_completion_generator(const char *match, int state) { static struct syment *sp_match; if (state == 0) sp_match = NULL; sp_match = symbol_complete_match(match, sp_match); if (sp_match) return(strdup(sp_match->name)); else return NULL; } static char ** crash_readline_completer(const char *match, int start, int end) { rl_attempted_completion_over = 1; return rl_completion_matches(match, crash_readline_completion_generator); } crash-utility-crash-61fe107/configure.c000066400000000000000000001512731517256214500201120ustar00rootroot00000000000000/* configure.c - core analysis suite * * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. * Copyright (C) 2002-2013 David Anderson * Copyright (C) 2002-2013 Red Hat, Inc. All rights reserved. * * 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 2 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. */ /* * define, clear and undef dynamically update the top-level Makefile: * * -b define: TARGET, GDB, GDB_FILES, GDB_OFILES, GDB_PATCH_FILES, * TARGET_CFLAGS, LDFLAGS, GDB_CONF_FLAGS and GPL_FILES * create: build_data.c * * -d define: TARGET, GDB, GDB_FILES, GDB_OFILES, GDB_PATCH_FILES, * TARGET_CFLAGS, LDFLAGS, GDB_CONF_FLAGS and PROGRAM (for daemon) * create: build_data.c * * -u clear: TARGET, GDB, GDB_FILES, GDB_OFILES, VERSION, GDB_PATCH_FILES, * TARGET_CFLAGS, LDFLAGS, GDB_CONF_FLAGS and GPL_FILES * undef: WARNING_ERROR, WARNING_OPTIONS * * -r define: GDB_FILES, VERSION, GDB_PATCH_FILES GPL_FILES * * -w define: WARNING_OPTIONS * undef: WARNING_ERROR * * -W define: WARNING_ERROR, WARNING_OPTIONS * * -n undef: WARNING_ERROR, WARNING_OPTIONS * * -g define: GDB * * -p Create or remove .rh_rpm_package file * * -q Don't print configuration * * -s Create crash.spec file * * -x Add extra libraries/flags to build */ #include #include #include #include #include #include struct supported_gdb_version; void build_configure(struct supported_gdb_version *); void release_configure(char *, struct supported_gdb_version *); void make_rh_rpm_package(char *, int); void unconfigure(void); void set_warnings(int); void show_configuration(void); void target_rebuild_instructions(struct supported_gdb_version *, char *); void arch_mismatch(struct supported_gdb_version *); void get_current_configuration(struct supported_gdb_version *); void makefile_setup(FILE **, FILE **); void makefile_create(FILE **, FILE **); char *strip_linefeeds(char *); char *upper_case(char *, char *); char *lower_case(char *, char *); char *shift_string_left(char *, int); char *shift_string_right(char *, int); char *strip_beginning_whitespace(char *); char *strip_ending_whitespace(char *); char *strip_linefeeds(char *); int file_exists(char *); int count_chars(char *, char); void make_build_data(char *); void gdb_configure(struct supported_gdb_version *); int parse_line(char *, char **); struct supported_gdb_version *setup_gdb_defaults(void); struct supported_gdb_version *store_gdb_defaults(struct supported_gdb_version *); void make_spec_file(struct supported_gdb_version *); void set_initial_target(struct supported_gdb_version *); char *target_to_name(int); int name_to_target(char *); char *get_extra_flags(char *, char *); void add_extra_lib(char *); #define TRUE 1 #define FALSE 0 #undef X86 #undef ALPHA #undef PPC #undef IA64 #undef S390 #undef S390X #undef PPC64 #undef X86_64 #undef ARM #undef ARM64 #undef MIPS #undef SPARC64 #undef MIPS64 #undef RISCV64 #undef LOONGARCH64 #define UNKNOWN 0 #define X86 1 #define ALPHA 2 #define PPC 3 #define IA64 4 #define S390 5 #define S390X 6 #define PPC64 7 #define X86_64 8 #define ARM 9 #define ARM64 10 #define MIPS 11 #define SPARC64 12 #define MIPS64 13 #define RISCV64 14 #define LOONGARCH64 15 #define TARGET_X86 "TARGET=X86" #define TARGET_ALPHA "TARGET=ALPHA" #define TARGET_PPC "TARGET=PPC" #define TARGET_IA64 "TARGET=IA64" #define TARGET_S390 "TARGET=S390" #define TARGET_S390X "TARGET=S390X" #define TARGET_PPC64 "TARGET=PPC64" #define TARGET_X86_64 "TARGET=X86_64" #define TARGET_ARM "TARGET=ARM" #define TARGET_ARM64 "TARGET=ARM64" #define TARGET_MIPS "TARGET=MIPS" #define TARGET_MIPS64 "TARGET=MIPS64" #define TARGET_SPARC64 "TARGET=SPARC64" #define TARGET_RISCV64 "TARGET=RISCV64" #define TARGET_LOONGARCH64 "TARGET=LOONGARCH64" #define TARGET_CFLAGS_X86 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" #define TARGET_CFLAGS_ALPHA "TARGET_CFLAGS=" #define TARGET_CFLAGS_PPC "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" #define TARGET_CFLAGS_IA64 "TARGET_CFLAGS=" #define TARGET_CFLAGS_S390 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" #define TARGET_CFLAGS_S390X "TARGET_CFLAGS=" #define TARGET_CFLAGS_PPC64 "TARGET_CFLAGS=-m64" #define TARGET_CFLAGS_X86_64 "TARGET_CFLAGS=" #define TARGET_CFLAGS_ARM "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" #define TARGET_CFLAGS_ARM_ON_X86 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" #define TARGET_CFLAGS_ARM_ON_X86_64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64" #define TARGET_CFLAGS_X86_ON_X86_64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64" #define TARGET_CFLAGS_PPC_ON_PPC64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64 -fPIC" #define TARGET_CFLAGS_ARM64 "TARGET_CFLAGS=" #define TARGET_CFLAGS_ARM64_ON_X86_64 "TARGET_CFLAGS=" #define TARGET_CFLAGS_PPC64_ON_X86_64 "TARGET_CFLAGS=" #define TARGET_CFLAGS_MIPS "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" #define TARGET_CFLAGS_MIPS_ON_X86 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" #define TARGET_CFLAGS_MIPS_ON_X86_64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64" #define TARGET_CFLAGS_MIPS64 "TARGET_CFLAGS=" #define TARGET_CFLAGS_SPARC64 "TARGET_CFLAGS=" #define TARGET_CFLAGS_RISCV64 "TARGET_CFLAGS=" #define TARGET_CFLAGS_RISCV64_ON_X86_64 "TARGET_CFLAGS=" #define TARGET_CFLAGS_LOONGARCH64 "TARGET_CFLAGS=" #define TARGET_CFLAGS_LOONGARCH64_ON_X86_64 "TARGET_CFLAGS=" #ifndef GDB_TARGET_DEFAULT #define GDB_TARGET_DEFAULT "GDB_CONF_FLAGS=" #endif #define GDB_TARGET_ARM_ON_X86 "GDB_CONF_FLAGS=--target=arm-elf-linux" #define GDB_TARGET_ARM_ON_X86_64 "GDB_CONF_FLAGS=--target=arm-elf-linux CFLAGS=-m32 CXXFLAGS=-m32" #define GDB_TARGET_X86_ON_X86_64 "GDB_CONF_FLAGS=--target=i686-pc-linux-gnu CFLAGS=-m32 CXXFLAGS=-m32" #define GDB_TARGET_PPC_ON_PPC64 "GDB_CONF_FLAGS=--target=ppc-elf-linux CFLAGS=-m32 CXXFLAGS=-m32" #define GDB_TARGET_ARM64_ON_X86_64 "GDB_CONF_FLAGS=--target=aarch64-elf-linux" /* TBD */ #define GDB_TARGET_PPC64_ON_X86_64 "GDB_CONF_FLAGS=--target=powerpc64le-unknown-linux-gnu" #define GDB_TARGET_MIPS_ON_X86 "GDB_CONF_FLAGS=--target=mipsel-elf-linux" #define GDB_TARGET_MIPS_ON_X86_64 "GDB_CONF_FLAGS=--target=mipsel-elf-linux CFLAGS=-m32 CXXFLAGS=-m32" #define GDB_TARGET_RISCV64_ON_X86_64 "GDB_CONF_FLAGS=--target=riscv64-unknown-linux-gnu" #define GDB_TARGET_LOONGARCH64_ON_X86_64 "GDB_CONF_FLAGS=--target=loongarch64-unknown-linux-gnu" /* * The original plan was to allow the use of a particular version * of gdb for a given architecture. But for practical purposes, * it's a one-size-fits-all scheme, and they all use the default * unless overridden. */ #define GDB_5_3 (0) #define GDB_6_0 (1) #define GDB_6_1 (2) #define GDB_7_0 (3) #define GDB_7_3_1 (4) #define GDB_7_6 (5) #define GDB_10_2 (6) #define GDB_16_2 (7) #define SUPPORTED_GDB_VERSIONS (GDB_16_2 + 1) int default_gdb = GDB_16_2; struct supported_gdb_version { char *GDB; char *GDB_VERSION_IN; char *GDB_FILES; char *GDB_OFILES; char *GDB_PATCH_FILES; char *GDB_FLAGS; char *GPL; } supported_gdb_versions[SUPPORTED_GDB_VERSIONS] = { { "GDB=gdb-5.3post-0.20021129.36rh", "Red Hat Linux (5.3post-0.20021129.36rh)", "GDB_FILES=${GDB_5.3post-0.20021129.36rh_FILES}", "GDB_OFILES=${GDB_5.3post-0.20021129.36rh_OFILES}", "GDB_PATCH_FILES=", "GDB_FLAGS=-DGDB_5_3", "GPLv2" }, { "GDB=gdb-6.0", "6.0", "GDB_FILES=${GDB_6.0_FILES}", "GDB_OFILES=${GDB_6.0_OFILES}", "GDB_PATCH_FILES=", "GDB_FLAGS=-DGDB_6_0", "GPLv2" }, { "GDB=gdb-6.1", "6.1", "GDB_FILES=${GDB_6.1_FILES}", "GDB_OFILES=${GDB_6.1_OFILES}", "GDB_PATCH_FILES=gdb-6.1.patch", "GDB_FLAGS=-DGDB_6_1", "GPLv2" }, { "GDB=gdb-7.0", "7.0", "GDB_FILES=${GDB_7.0_FILES}", "GDB_OFILES=${GDB_7.0_OFILES}", "GDB_PATCH_FILES=gdb-7.0.patch", "GDB_FLAGS=-DGDB_7_0", "GPLv3" }, { "GDB=gdb-7.3.1", "7.3.1", "GDB_FILES=${GDB_7.3.1_FILES}", "GDB_OFILES=${GDB_7.3.1_OFILES}", "GDB_PATCH_FILES=gdb-7.3.1.patch", "GDB_FLAGS=-DGDB_7_3_1", "GPLv3" }, { "GDB=gdb-7.6", "7.6", "GDB_FILES=${GDB_7.6_FILES}", "GDB_OFILES=${GDB_7.6_OFILES}", "GDB_PATCH_FILES=gdb-7.6.patch gdb-7.6-ppc64le-support.patch gdb-7.6-proc_service.h.patch", "GDB_FLAGS=-DGDB_7_6", "GPLv3" }, { "GDB=gdb-10.2", "10.2", "GDB_FILES=${GDB_10.2_FILES}", "GDB_OFILES=${GDB_10.2_OFILES}", "GDB_PATCH_FILES=gdb-10.2.patch", "GDB_FLAGS=-DGDB_10_2", "GPLv3" }, { "GDB=gdb-16.2", "16.2", "GDB_FILES=${GDB_16.2_FILES}", "GDB_OFILES=${GDB_16.2_OFILES}", "GDB_PATCH_FILES=gdb-16.2.patch", "GDB_FLAGS=-DGDB_16_2", "GPLv3" }, }; #define DAEMON 0x1 #define QUIET 0x2 #define MAXSTRLEN 256 #define MIN(a,b) (((a)<(b))?(a):(b)) struct target_data { int target; int host; int initial_gdb_target; int flags; char program[MAXSTRLEN]; char gdb_version[MAXSTRLEN]; char release[MAXSTRLEN]; struct stat statbuf; const char *target_as_param; } target_data = { 0 }; int main(int argc, char **argv) { int c; struct supported_gdb_version *sp; sp = setup_gdb_defaults(); while ((c = getopt(argc, argv, "gsqnWwubdr:p:P:t:x:")) > 0) { switch (c) { case 'q': target_data.flags |= QUIET; break; case 'u': unconfigure(); break; case 'd': target_data.flags |= DAEMON; case 'b': build_configure(sp); break; case 'r': release_configure(optarg, sp); break; case 'p': make_rh_rpm_package(optarg, 0); break; case 'P': make_rh_rpm_package(optarg, 1); break; case 'W': case 'w': case 'n': set_warnings(c); break; case 's': make_spec_file(sp); break; case 'g': gdb_configure(sp); break; case 't': target_data.target_as_param = optarg; break; case 'x': add_extra_lib(optarg); break; } } exit(0); } void target_rebuild_instructions(struct supported_gdb_version *sp, char *target) { fprintf(stderr, "\nIn order to build a crash binary for the %s architecture:\n", target); fprintf(stderr, " 1. remove the %s subdirectory\n", &sp->GDB[strlen("GDB=")]); fprintf(stderr, " 2. perform a \"make clean\"\n"); fprintf(stderr, " 3. retry the build\n\n"); } void arch_mismatch(struct supported_gdb_version *sp) { fprintf(stderr, "\nThe initial build in this source tree was for the %s architecture.\n", target_to_name(target_data.initial_gdb_target)); target_rebuild_instructions(sp, target_to_name(target_data.target)); exit(1); } void get_current_configuration(struct supported_gdb_version *sp) { FILE *fp; static char buf[512]; char *p; #ifndef CONF_TARGET_ARCH #ifdef __alpha__ target_data.target = ALPHA; #endif #ifdef __i386__ target_data.target = X86; #endif #ifdef __powerpc__ target_data.target = PPC; #endif #ifdef __ia64__ target_data.target = IA64; #endif #ifdef __s390__ target_data.target = S390; #endif #ifdef __s390x__ target_data.target = S390X; #endif #ifdef __powerpc64__ target_data.target = PPC64; #endif #ifdef __x86_64__ target_data.target = X86_64; #endif #ifdef __arm__ target_data.target = ARM; #endif #ifdef __aarch64__ target_data.target = ARM64; #endif #ifdef __mips__ #ifndef __mips64 target_data.target = MIPS; #else target_data.target = MIPS64; #endif #endif #ifdef __sparc_v9__ target_data.target = SPARC64; #endif #if defined(__riscv) && (__riscv_xlen == 64) target_data.target = RISCV64; #endif #ifdef __loongarch64 target_data.target = LOONGARCH64; #endif #else target_data.target = CONF_TARGET_ARCH; #endif set_initial_target(sp); /* * Override target if specified on command line. */ target_data.host = target_data.target; if (target_data.target_as_param) { if ((target_data.target == X86 || target_data.target == X86_64) && (name_to_target((char *)target_data.target_as_param) == ARM)) { /* * Debugging of ARM core files supported on X86, and on * X86_64 when built as a 32-bit executable. */ target_data.target = ARM; } else if ((target_data.target == X86 || target_data.target == X86_64) && (name_to_target((char *)target_data.target_as_param) == MIPS)) { /* * Debugging of MIPS little-endian core files * supported on X86, and on X86_64 when built as a * 32-bit executable. */ target_data.target = MIPS; } else if ((target_data.target == X86_64) && (name_to_target((char *)target_data.target_as_param) == X86)) { /* * Build an X86 crash binary on an X86_64 host. */ target_data.target = X86; } else if ((target_data.target == X86_64) && (name_to_target((char *)target_data.target_as_param) == ARM64)) { /* * Build an ARM64 crash binary on an X86_64 host. */ target_data.target = ARM64; } else if ((target_data.target == X86_64) && (name_to_target((char *)target_data.target_as_param) == PPC64)) { /* * Build a PPC64 little-endian crash binary on an X86_64 host. */ target_data.target = PPC64; } else if ((target_data.target == PPC64) && (name_to_target((char *)target_data.target_as_param) == PPC)) { /* * Build an PPC crash binary on an PPC64 host. */ target_data.target = PPC; } else if (name_to_target((char *)target_data.target_as_param) == target_data.host) { if ((target_data.initial_gdb_target != UNKNOWN) && (target_data.host != target_data.initial_gdb_target)) arch_mismatch(sp); } else if ((target_data.target == X86_64) && (name_to_target((char *)target_data.target_as_param) == RISCV64)) { /* * Build an RISCV64 crash binary on an X86_64 host. */ target_data.target = RISCV64; } else if ((target_data.target == X86_64) && (name_to_target((char *)target_data.target_as_param) == LOONGARCH64)) { /* * Build an LOONGARCH64 crash binary on an X86_64 host. */ target_data.target = LOONGARCH64; } else { fprintf(stderr, "\ntarget=%s is not supported on the %s host architecture\n\n", target_data.target_as_param, target_to_name(target_data.host)); exit(1); } } /* * Impose implied (sticky) target if an initial build has been * done in the source tree. */ if (target_data.initial_gdb_target && (target_data.target != target_data.initial_gdb_target)) { if ((target_data.initial_gdb_target == ARM) && (target_data.target != ARM)) { if ((target_data.target == X86) || (target_data.target == X86_64)) target_data.target = ARM; else arch_mismatch(sp); } if ((target_data.target == ARM) && (target_data.initial_gdb_target != ARM)) arch_mismatch(sp); if ((target_data.initial_gdb_target == MIPS) && (target_data.target != MIPS)) { if ((target_data.target == X86) || (target_data.target == X86_64)) target_data.target = MIPS; else arch_mismatch(sp); } if ((target_data.initial_gdb_target == MIPS64) && (target_data.target != MIPS64)) arch_mismatch(sp); if ((target_data.initial_gdb_target == LOONGARCH64) && (target_data.target != LOONGARCH64)) { if (target_data.target == X86_64) target_data.target = LOONGARCH64; else arch_mismatch(sp); } if ((target_data.initial_gdb_target == RISCV64) && (target_data.target != RISCV64)) { if (target_data.target == X86_64) target_data.target = RISCV64; else arch_mismatch(sp); } if ((target_data.initial_gdb_target == X86) && (target_data.target != X86)) { if (target_data.target == X86_64) target_data.target = X86; else arch_mismatch(sp); } if ((target_data.target == X86) && (target_data.initial_gdb_target != X86)) arch_mismatch(sp); if ((target_data.initial_gdb_target == ARM64) && (target_data.target != ARM64)) { if (target_data.target == X86_64) target_data.target = ARM64; else arch_mismatch(sp); } if ((target_data.target == ARM64) && (target_data.initial_gdb_target != ARM64)) arch_mismatch(sp); if ((target_data.initial_gdb_target == PPC64) && (target_data.target != PPC64)) { if (target_data.target == X86_64) target_data.target = PPC64; else arch_mismatch(sp); } if ((target_data.target == PPC64) && (target_data.initial_gdb_target != PPC64)) arch_mismatch(sp); if ((target_data.initial_gdb_target == PPC) && (target_data.target != PPC)) { if (target_data.target == PPC64) target_data.target = PPC; else arch_mismatch(sp); } if ((target_data.target == PPC) && (target_data.initial_gdb_target != PPC)) arch_mismatch(sp); if ((target_data.target == SPARC64) && (target_data.initial_gdb_target != SPARC64)) arch_mismatch(sp); } if ((fp = fopen("Makefile", "r")) == NULL) { perror("Makefile"); goto get_release; } while (fgets(buf, 512, fp)) { if (strncmp(buf, "PROGRAM=", strlen("PROGRAM=")) == 0) { p = strstr(buf, "=") + 1; strip_linefeeds(p); upper_case(p, target_data.program); if (target_data.flags & DAEMON) strcat(target_data.program, "D"); continue; } } fclose(fp); get_release: target_data.release[0] = '\0'; if (file_exists(".rh_rpm_package")) { if ((fp = fopen(".rh_rpm_package", "r")) == NULL) { perror(".rh_rpm_package"); } else { if (fgets(buf, 512, fp)) { strip_linefeeds(buf); if (strlen(buf)) { buf[MAXSTRLEN-1] = '\0'; strcpy(target_data.release, buf); } else fprintf(stderr, "WARNING: .rh_rpm_package file is empty!\n"); } else fprintf(stderr, "WARNING: .rh_rpm_package file is empty!\n"); fclose(fp); if (strlen(target_data.release)) return; } } else fprintf(stderr, "WARNING: .rh_rpm_package file does not exist!\n"); if ((fp = fopen("defs.h", "r")) == NULL) { perror("defs.h"); return; } while (fgets(buf, 512, fp)) { if (strncmp(buf, "#define BASELEVEL_REVISION", strlen("#define BASELEVEL_REVISION")) == 0) { p = strstr(buf, "\"") + 1; strip_linefeeds(p); p[strlen(p)-1] = '\0'; strcpy(target_data.release, p); break; } } fclose(fp); } void show_configuration(void) { int i; if (target_data.flags & QUIET) return; switch (target_data.target) { case X86: printf("TARGET: X86\n"); break; case ALPHA: printf("TARGET: ALPHA\n"); break; case PPC: printf("TARGET: PPC\n"); break; case IA64: printf("TARGET: IA64\n"); break; case S390: printf("TARGET: S390\n"); break; case S390X: printf("TARGET: S390X\n"); break; case PPC64: printf("TARGET: PPC64\n"); break; case X86_64: printf("TARGET: X86_64\n"); break; case ARM: printf("TARGET: ARM\n"); break; case ARM64: printf("TARGET: ARM64\n"); break; case MIPS: printf("TARGET: MIPS\n"); break; case MIPS64: printf("TARGET: MIPS64\n"); break; case SPARC64: printf("TARGET: SPARC64\n"); break; case RISCV64: printf("TARGET: RISCV64\n"); break; case LOONGARCH64: printf("TARGET: LOONGARCH64\n"); break; } if (strlen(target_data.program)) { for (i = 0; i < (strlen("TARGET")-strlen(target_data.program)); i++) printf(" "); printf("%s: ", target_data.program); if (strlen(target_data.release)) printf("%s\n", target_data.release); else printf("???\n"); } if (strlen(target_data.gdb_version)) printf(" GDB: %s\n\n", &target_data.gdb_version[4]); } void build_configure(struct supported_gdb_version *sp) { FILE *fp1, *fp2; char buf[512]; char *target; char *target_CFLAGS; char *gdb_conf_flags; char *ldflags; char *cflags; get_current_configuration(sp); target = target_CFLAGS = NULL; gdb_conf_flags = GDB_TARGET_DEFAULT; switch (target_data.target) { case X86: target = TARGET_X86; if (target_data.host == X86_64) { target_CFLAGS = TARGET_CFLAGS_X86_ON_X86_64; gdb_conf_flags = GDB_TARGET_X86_ON_X86_64; } else target_CFLAGS = TARGET_CFLAGS_X86; break; case ALPHA: target = TARGET_ALPHA; target_CFLAGS = TARGET_CFLAGS_ALPHA; break; case PPC: target = TARGET_PPC; if (target_data.host == PPC64) { target_CFLAGS = TARGET_CFLAGS_PPC_ON_PPC64; gdb_conf_flags = GDB_TARGET_PPC_ON_PPC64; } else target_CFLAGS = TARGET_CFLAGS_PPC; break; case IA64: target = TARGET_IA64; target_CFLAGS = TARGET_CFLAGS_IA64; break; case S390: target = TARGET_S390; target_CFLAGS = TARGET_CFLAGS_S390; break; case S390X: target = TARGET_S390X; target_CFLAGS = TARGET_CFLAGS_S390X; break; case PPC64: target = TARGET_PPC64; if (target_data.host == X86_64) { target_CFLAGS = TARGET_CFLAGS_PPC64_ON_X86_64; gdb_conf_flags = GDB_TARGET_PPC64_ON_X86_64; } else target_CFLAGS = TARGET_CFLAGS_PPC64; break; case X86_64: target = TARGET_X86_64; target_CFLAGS = TARGET_CFLAGS_X86_64; break; case ARM: target = TARGET_ARM; if (target_data.host == X86) { target_CFLAGS = TARGET_CFLAGS_ARM_ON_X86; gdb_conf_flags = GDB_TARGET_ARM_ON_X86; } else if (target_data.host == X86_64) { target_CFLAGS = TARGET_CFLAGS_ARM_ON_X86_64; gdb_conf_flags = GDB_TARGET_ARM_ON_X86_64; } else target_CFLAGS = TARGET_CFLAGS_ARM; break; case ARM64: target = TARGET_ARM64; if (target_data.host == X86_64) { target_CFLAGS = TARGET_CFLAGS_ARM64_ON_X86_64; gdb_conf_flags = GDB_TARGET_ARM64_ON_X86_64; } else target_CFLAGS = TARGET_CFLAGS_ARM64; break; case MIPS: target = TARGET_MIPS; if (target_data.host == X86) { target_CFLAGS = TARGET_CFLAGS_MIPS_ON_X86; gdb_conf_flags = GDB_TARGET_MIPS_ON_X86; } else if (target_data.host == X86_64) { target_CFLAGS = TARGET_CFLAGS_MIPS_ON_X86_64; gdb_conf_flags = GDB_TARGET_MIPS_ON_X86_64; } else target_CFLAGS = TARGET_CFLAGS_MIPS; break; case MIPS64: target = TARGET_MIPS64; target_CFLAGS = TARGET_CFLAGS_MIPS64; break; case SPARC64: target = TARGET_SPARC64; target_CFLAGS = TARGET_CFLAGS_SPARC64; break; case RISCV64: target = TARGET_RISCV64; if (target_data.host == X86_64) { target_CFLAGS = TARGET_CFLAGS_RISCV64_ON_X86_64; gdb_conf_flags = GDB_TARGET_RISCV64_ON_X86_64; } else target_CFLAGS = TARGET_CFLAGS_RISCV64; break; case LOONGARCH64: target = TARGET_LOONGARCH64; if (target_data.host == X86_64) { target_CFLAGS = TARGET_CFLAGS_LOONGARCH64_ON_X86_64; gdb_conf_flags = GDB_TARGET_LOONGARCH64_ON_X86_64; } else target_CFLAGS = TARGET_CFLAGS_LOONGARCH64; break; } ldflags = get_extra_flags("LDFLAGS.extra", NULL); cflags = get_extra_flags("CFLAGS.extra", NULL); gdb_conf_flags = get_extra_flags("GDBFLAGS.extra", gdb_conf_flags); makefile_setup(&fp1, &fp2); while (fgets(buf, 512, fp1)) { if (strncmp(buf, "TARGET=", strlen("TARGET=")) == 0) fprintf(fp2, "%s\n", target); else if (strncmp(buf, "TARGET_CFLAGS=", strlen("TARGET_CFLAGS=")) == 0) fprintf(fp2, "%s%s%s\n", target_CFLAGS, cflags ? " " : "", cflags ? cflags : ""); else if (strncmp(buf, "GDB_CONF_FLAGS=", strlen("GDB_CONF_FLAGS=")) == 0) fprintf(fp2, "%s\n", gdb_conf_flags); else if (strncmp(buf, "GDB_FILES=",strlen("GDB_FILES=")) == 0) fprintf(fp2, "%s\n", sp->GDB_FILES); else if (strncmp(buf, "GDB_OFILES=",strlen("GDB_OFILES=")) == 0) fprintf(fp2, "%s\n", sp->GDB_OFILES); else if (strncmp(buf, "GDB_PATCH_FILES=",strlen("GDB_PATCH_FILES=")) == 0) fprintf(fp2, "%s\n", sp->GDB_PATCH_FILES); else if (strncmp(buf, "GDB_FLAGS=",strlen("GDB_FLAGS=")) == 0) fprintf(fp2, "%s\n", sp->GDB_FLAGS); else if (strncmp(buf, "GPL_FILES=", strlen("GPL_FILES=")) == 0) fprintf(fp2, "GPL_FILES=%s\n", strcmp(sp->GPL, "GPLv2") == 0 ? "COPYING" : "COPYING3"); else if (strncmp(buf, "GDB=", strlen("GDB=")) == 0) { fprintf(fp2, "%s\n", sp->GDB); sprintf(target_data.gdb_version, "%s", &sp->GDB[4]); } else if (strncmp(buf, "LDFLAGS=", strlen("LDFLAGS=")) == 0) { fprintf(fp2, "LDFLAGS=%s\n", ldflags ? ldflags : ""); } else fprintf(fp2, "%s", buf); } makefile_create(&fp1, &fp2); show_configuration(); make_build_data(&target[strlen("TARGET=")]); } void release_configure(char *gdb_version, struct supported_gdb_version *sp) { FILE *fp1, *fp2; int found; char buf[512]; char gdb_files[MAXSTRLEN]; get_current_configuration(sp); sprintf(buf, "%s/gdb", gdb_version); if (!file_exists(buf)) { fprintf(stderr, "make release: no such directory: %s\n", buf); exit(1); } sprintf(gdb_files, "GDB_%s_FILES", &gdb_version[strlen("gdb-")]); makefile_setup(&fp1, &fp2); found = 0; while (fgets(buf, 512, fp1)) { if (strncmp(buf, gdb_files, strlen(gdb_files)) == 0) found++; if (strncmp(buf, "GDB_FILES=", strlen("GDB_FILES=")) == 0) fprintf(fp2, "GDB_FILES=${%s}\n", gdb_files); else if (strncmp(buf, "VERSION=", strlen("VERSION=")) == 0) fprintf(fp2, "VERSION=%s\n", target_data.release); else if (strncmp(buf, "GDB_PATCH_FILES=", strlen("GDB_PATCH_FILES=")) == 0) fprintf(fp2, "%s\n", sp->GDB_PATCH_FILES); else if (strncmp(buf, "GPL_FILES=", strlen("GPL_FILES=")) == 0) fprintf(fp2, "GPL_FILES=%s\n", strcmp(sp->GPL, "GPLv2") == 0 ? "COPYING" : "COPYING3"); else fprintf(fp2, "%s", buf); } if (!found) { fprintf(stderr, "make release: cannot find %s\n", gdb_files); exit(1); } makefile_create(&fp1, &fp2); } /* * Create an .rh_rpm_package file if the passed-in variable is set. */ void make_rh_rpm_package(char *package, int release) { char *p, *cur; FILE *fp; char buf[256]; if ((strcmp(package, "remove") == 0)) { if (file_exists(".rh_rpm_package")) { if (unlink(".rh_rpm_package")) { perror("unlink"); fprintf(stderr, "cannot remove .rh_rpm_package\n"); exit(1); } } return; } if (!(p = strstr(package, "="))) return; if (!strlen(++p)) return; if (release) { if (!(fp = popen("./crash -v", "r"))) { fprintf(stderr, "cannot execute \"crash -v\"\n"); exit(1); } cur = NULL; while (fgets(buf, 256, fp)) { if (strncmp(buf, "crash ", 6) == 0) { cur = &buf[6]; break; } } pclose(fp); if (!cur) { fprintf(stderr, "cannot get version from \"crash -v\"\n"); exit(1); } strip_linefeeds(cur); if (strcmp(cur, p) != 0) { fprintf(stderr, "./crash version: %s\n", cur); fprintf(stderr, "release version: %s\n", p); exit(1); } } if ((fp = fopen(".rh_rpm_package", "w")) == NULL) { perror("fopen"); fprintf(stderr, "cannot open .rh_rpm_package\n"); exit(1); } fprintf(fp, "%s\n", strip_linefeeds(p)); fclose(fp); } void gdb_configure(struct supported_gdb_version *sp) { FILE *fp1, *fp2; char buf[512]; get_current_configuration(sp); makefile_setup(&fp1, &fp2); while (fgets(buf, 512, fp1)) { if (strncmp(buf, "GDB=", strlen("GDB=")) == 0) fprintf(fp2, "%s\n", sp->GDB); else fprintf(fp2, "%s", buf); } makefile_create(&fp1, &fp2); } void unconfigure(void) { FILE *fp1, *fp2; char buf[512]; makefile_setup(&fp1, &fp2); while (fgets(buf, 512, fp1)) { if (strncmp(buf, "TARGET=", strlen("TARGET=")) == 0) fprintf(fp2, "TARGET=\n"); else if (strncmp(buf, "TARGET_CFLAGS=", strlen("TARGET_CFLAGS=")) == 0) fprintf(fp2, "TARGET_CFLAGS=\n"); else if (strncmp(buf, "GDB_CONF_FLAGS=", strlen("GDB_CONF_FLAGS=")) == 0) fprintf(fp2, "GDB_CONF_FLAGS=\n"); else if (strncmp(buf, "GDB_FILES=",strlen("GDB_FILES=")) == 0) fprintf(fp2, "GDB_FILES=\n"); else if (strncmp(buf, "GDB_OFILES=",strlen("GDB_OFILES=")) == 0) fprintf(fp2, "GDB_OFILES=\n"); else if (strncmp(buf, "GDB_PATCH_FILES=",strlen("GDB_PATCH_FILES=")) == 0) fprintf(fp2, "GDB_PATCH_FILES=\n"); else if (strncmp(buf, "GDB_FLAGS=",strlen("GDB_FLAGS=")) == 0) fprintf(fp2, "GDB_FLAGS=\n"); else if (strncmp(buf, "GDB=", strlen("GDB=")) == 0) fprintf(fp2, "GDB=\n"); else if (strncmp(buf, "VERSION=", strlen("VERSION=")) == 0) fprintf(fp2, "VERSION=\n"); else if (strncmp(buf, "GPL_FILES=", strlen("GPL_FILES=")) == 0) fprintf(fp2, "GPL_FILES=\n"); else if (strncmp(buf, "LDFLAGS=", strlen("LDFLAGS=")) == 0) fprintf(fp2, "LDFLAGS=\n"); else if (strncmp(buf, "WARNING_ERROR=", strlen("WARNING_ERROR=")) == 0) { shift_string_right(buf, 1); buf[0] = '#'; fprintf(fp2, "%s", buf); } else if (strncmp(buf, "WARNING_OPTIONS=", strlen("WARNING_OPTIONS=")) == 0) { shift_string_right(buf, 1); buf[0] = '#'; fprintf(fp2, "%s", buf); } else fprintf(fp2, "%s", buf); } makefile_create(&fp1, &fp2); } void set_warnings(int w) { FILE *fp1, *fp2; char buf[512]; makefile_setup(&fp1, &fp2); while (fgets(buf, 512, fp1)) { if (strncmp(buf, "#WARNING_ERROR=", strlen("#WARNING_ERROR=")) == 0) { switch (w) { case 'W': shift_string_left(buf, 1); break; case 'w': case 'n': break; } } if (strncmp(buf, "WARNING_ERROR=", strlen("WARNING_ERROR=")) == 0) { switch (w) { case 'n': case 'w': shift_string_right(buf, 1); buf[0] = '#'; break; case 'W': break; } } if (strncmp(buf, "#WARNING_OPTIONS=", strlen("#WARNING_OPTIONS=")) == 0) { switch (w) { case 'W': case 'w': shift_string_left(buf, 1); break; case 'n': break; } } if (strncmp(buf, "WARNING_OPTIONS=", strlen("WARNING_OPTIONS=")) == 0) { switch (w) { case 'w': case 'W': break; case 'n': shift_string_right(buf, 1); buf[0] = '#'; break; } } fprintf(fp2, "%s", buf); } makefile_create(&fp1, &fp2); } void makefile_setup(FILE **fp1, FILE **fp2) { if (stat("Makefile", &target_data.statbuf) == -1) { perror("Makefile"); exit(1); } if ((*fp1 = fopen("Makefile", "r")) == NULL) { perror("fopen"); fprintf(stderr, "cannot open existing Makefile\n"); exit(1); } unlink("Makefile.new"); if ((*fp2 = fopen("Makefile.new", "w+")) == NULL) { perror("fopen"); fprintf(stderr, "cannot create new Makefile\n"); exit(1); } } void makefile_create(FILE **fp1, FILE **fp2) { fclose(*fp1); fclose(*fp2); if (system("mv Makefile.new Makefile") != 0) { fprintf(stderr, "Makefile: cannot create new Makefile\n"); fprintf(stderr, "please copy Makefile.new to Makefile\n"); exit(1); } if (chown("Makefile", target_data.statbuf.st_uid, target_data.statbuf.st_gid) == -1) { fprintf(stderr, "Makefile: cannot restore original owner/group\n"); } } #define LASTCHAR(s) (s[strlen(s)-1]) char * strip_linefeeds(char *line) { char *p; if (line == NULL || strlen(line) == 0) return(line); p = &LASTCHAR(line); while (*p == '\n') *p = '\0'; return(line); } /* * Turn a string into upper-case. */ char * upper_case(char *s, char *buf) { char *p1, *p2; p1 = s; p2 = buf; while (*p1) { *p2 = toupper(*p1); p1++, p2++; } *p2 = '\0'; return(buf); } /* * Turn a string into lower-case. */ char * lower_case(char *s, char *buf) { char *p1, *p2; p1 = s; p2 = buf; while (*p1) { *p2 = tolower(*p1); p1++, p2++; } *p2 = '\0'; return(buf); } char * shift_string_left(char *s, int cnt) { int origlen; if (!cnt) return(s); origlen = strlen(s); memmove(s, s+cnt, (origlen-cnt)); *(s+(origlen-cnt)) = '\0'; return(s); } char * shift_string_right(char *s, int cnt) { int i; int origlen; if (!cnt) return(s); origlen = strlen(s); memmove(s+cnt, s, origlen); *(s+(origlen+cnt)) = '\0'; for (i = 0; i < cnt; i++) s[i] = ' '; return(s); } char * strip_beginning_whitespace(char *line) { char buf[MAXSTRLEN]; char *p; if (line == NULL || strlen(line) == 0) return(line); strcpy(buf, line); p = &buf[0]; while (*p == ' ' || *p == '\t') p++; strcpy(line, p); return(line); } char * strip_ending_whitespace(char *line) { char *p; if (line == NULL || strlen(line) == 0) return(line); p = &line[strlen(line)-1]; while (*p == ' ' || *p == '\t') { *p = '\0'; if (p == line) break; p--; } return(line); } int file_exists(char *file) { struct stat sbuf; if (stat(file, &sbuf) == 0) return TRUE; return FALSE; } int count_chars(char *s, char c) { char *p; int count; if (!s) return 0; count = 0; for (p = s; *p; p++) { if (*p == c) count++; } return count; } void make_build_data(char *target) { char *p; char hostname[MAXSTRLEN]; char progname[MAXSTRLEN]; char inbuf1[MAXSTRLEN]; char inbuf2[MAXSTRLEN]; char inbuf3[MAXSTRLEN]; FILE *fp1, *fp2, *fp3, *fp4; unlink("build_data.c"); fp1 = popen("date", "r"); fp2 = popen("id", "r"); fp3 = popen("gcc --version", "r"); if ((fp4 = fopen("build_data.c", "w")) == NULL) { perror("build_data.c"); exit(1); } if (gethostname(hostname, MAXSTRLEN) != 0) hostname[0] = '\0'; p = fgets(inbuf1, 79, fp1); p = fgets(inbuf2, 79, fp2); p = strstr(inbuf2, " "); *p = '\0'; p = fgets(inbuf3, 79, fp3); lower_case(target_data.program, progname); fprintf(fp4, "char *build_command = \"%s\";\n", progname); if (getenv("SOURCE_DATE_EPOCH")) fprintf(fp4, "char *build_data = \"reproducible build\";\n"); else if (strlen(hostname)) fprintf(fp4, "char *build_data = \"%s by %s on %s\";\n", strip_linefeeds(inbuf1), inbuf2, hostname); else fprintf(fp4, "char *build_data = \"%s by %s\";\n", strip_linefeeds(inbuf1), inbuf2); bzero(inbuf1, MAXSTRLEN); sprintf(inbuf1, "%s", target_data.release); fprintf(fp4, "char *build_target = \"%s\";\n", target); fprintf(fp4, "char *build_version = \"%s\";\n", inbuf1); fprintf(fp4, "char *compiler_version = \"%s\";\n", strip_linefeeds(inbuf3)); pclose(fp1); pclose(fp2); pclose(fp3); fclose(fp4); } void make_spec_file(struct supported_gdb_version *sp) { char *Version, *Release; char buf[512]; get_current_configuration(sp); Release = strstr(target_data.release, "-"); if (!Release) { Version = target_data.release; Release = "0"; } else { fprintf(stderr, "crash.spec: obsolete src.rpm build manner -- no dashes allowed: %s\n", target_data.release); return; } printf("#\n"); printf("# crash core analysis suite\n"); printf("#\n"); printf("Summary: crash utility for live systems; netdump, diskdump, kdump, LKCD or mcore dumpfiles\n"); printf("Name: %s\n", lower_case(target_data.program, buf)); printf("Version: %s\n", Version); printf("Release: %s\n", Release); printf("License: %s\n", sp->GPL); printf("Group: Development/Debuggers\n"); printf("Source: %%{name}-%%{version}.tar.gz\n"); printf("URL: https://github.com/crash-utility\n"); printf("Distribution: Linux 2.2 or greater\n"); printf("Vendor: Red Hat, Inc.\n"); printf("Packager: Dave Anderson \n"); printf("ExclusiveOS: Linux\n"); printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64 riscv64 loongarch64\n"); printf("Buildroot: %%{_tmppath}/%%{name}-root\n"); printf("BuildRequires: ncurses-devel zlib-devel bison\n"); printf("Requires: binutils\n"); printf("# Patch0: crash-3.3-20.installfix.patch (patch example)\n"); printf("\n"); printf("%%description\n"); printf("The core analysis suite is a self-contained tool that can be used to\n"); printf("investigate either live systems, kernel core dumps created from the\n"); printf("netdump, diskdump and kdump facilities from Red Hat Linux, the mcore kernel patch\n"); printf("offered by Mission Critical Linux, or the LKCD kernel patch.\n"); printf("\n"); printf("%%package devel\n"); printf("Requires: %%{name} = %%{version}, zlib-devel\n"); printf("Summary: crash utility for live systems; netdump, diskdump, kdump, LKCD or mcore dumpfiles\n"); printf("Group: Development/Debuggers\n"); printf("\n"); printf("%%description devel\n"); printf("The core analysis suite is a self-contained tool that can be used to\n"); printf("investigate either live systems, kernel core dumps created from the\n"); printf("netdump, diskdump and kdump packages from Red Hat Linux, the mcore kernel patch\n"); printf("offered by Mission Critical Linux, or the LKCD kernel patch.\n"); printf("\n"); printf("%%package extensions\n"); printf("Summary: Additional commands for the crash dump analysis tool\n"); printf("Group: Development/Debuggers\n"); printf("\n"); printf("%%description extensions\n"); printf("The extensions package contains plugins that provide additional crash\n"); printf("commands. The extensions can be loaded in crash via the \"extend\" command.\n"); printf("\n"); printf("The following extensions are provided:\n"); printf("* eppic: Provides C-like language for writing dump analysis scripts\n"); printf("* dminfo: Device-mapper target analyzer\n"); printf("* snap: Takes a snapshot of live memory and creates a kdump dumpfile\n"); printf("* trace: Displays kernel tracing data and traced events that occurred prior to a panic.\n"); printf("\n"); printf("%%prep\n"); printf("%%setup -n %%{name}-%%{version}\n"); printf("# %%patch0 -p1 -b .install (patch example)\n"); printf("\n"); printf("%%build\n"); printf("make RPMPKG=\"%%{version}\"\n"); printf("# make RPMPKG=\"%%{version}-%%{release}\"\n"); printf("make extensions\n"); /* printf("make crashd\n"); */ printf("\n"); printf("%%install\n"); printf("rm -rf %%{buildroot}\n"); printf("mkdir -p %%{buildroot}/usr/bin\n"); printf("make DESTDIR=%%{buildroot} install\n"); printf("mkdir -p %%{buildroot}%%{_mandir}/man8\n"); printf("cp crash.8 %%{buildroot}%%{_mandir}/man8/crash.8\n"); printf("mkdir -p %%{buildroot}%%{_includedir}/crash\n"); printf("cp defs.h %%{buildroot}%%{_includedir}/crash\n"); printf("mkdir -p %%{buildroot}%%{_libdir}/crash/extensions\n"); printf("if [ -f extensions/eppic.so ]\n"); printf("then\n"); printf("cp extensions/eppic.so %%{buildroot}%%{_libdir}/crash/extensions\n"); printf("fi\n"); printf("cp extensions/dminfo.so %%{buildroot}%%{_libdir}/crash/extensions\n"); printf("cp extensions/snap.so %%{buildroot}%%{_libdir}/crash/extensions\n"); printf("cp extensions/trace.so %%{buildroot}%%{_libdir}/crash/extensions\n"); printf("\n"); printf("%%clean\n"); printf("rm -rf %%{buildroot}\n"); printf("\n"); printf("%%files\n"); printf("%%defattr(-,root,root)\n"); printf("/usr/bin/crash\n"); printf("%%{_mandir}/man8/crash.8*\n"); /* printf("/usr/bin/crashd\n"); */ printf("%%doc README\n"); printf("\n"); printf("%%files devel\n"); printf("%%defattr(-,root,root)\n"); printf("%%{_includedir}/*\n"); printf("\n"); printf("%%files extensions\n"); printf("%%defattr(-,root,root)\n"); printf("%%{_libdir}/crash/extensions/*\n"); } /* * Use the default gdb #defines unless there's a .gdb file. */ struct supported_gdb_version * setup_gdb_defaults(void) { FILE *fp; char inbuf[512]; char buf[512]; struct supported_gdb_version *sp; /* * Use the default, allowing for an override in .gdb */ if (!file_exists(".gdb")) return store_gdb_defaults(NULL); if ((fp = fopen(".gdb", "r")) == NULL) { perror(".gdb"); return store_gdb_defaults(NULL); } while (fgets(inbuf, 512, fp)) { strip_linefeeds(inbuf); strip_beginning_whitespace(inbuf); strcpy(buf, inbuf); /* * Simple override. */ if (strcmp(buf, "5.3") == 0) { fclose(fp); sp = &supported_gdb_versions[GDB_5_3]; fprintf(stderr, ".gdb configuration: %s\n\n", sp->GDB_VERSION_IN); return store_gdb_defaults(sp); } if (strcmp(buf, "6.0") == 0) { fclose(fp); sp = &supported_gdb_versions[GDB_6_0]; fprintf(stderr, ".gdb configuration: %s\n\n", sp->GDB_VERSION_IN); return store_gdb_defaults(sp); } if (strcmp(buf, "6.1") == 0) { fclose(fp); sp = &supported_gdb_versions[GDB_6_1]; fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); return store_gdb_defaults(sp); } if (strcmp(buf, "7.0") == 0) { fclose(fp); sp = &supported_gdb_versions[GDB_7_0]; fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); return store_gdb_defaults(sp); } if (strcmp(buf, "7.3.1") == 0) { fclose(fp); sp = &supported_gdb_versions[GDB_7_3_1]; fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); return store_gdb_defaults(sp); } if (strcmp(buf, "7.6") == 0) { fclose(fp); sp = &supported_gdb_versions[GDB_7_6]; fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); return store_gdb_defaults(sp); } if (strcmp(buf, "10.2") == 0) { fclose(fp); sp = &supported_gdb_versions[GDB_10_2]; fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); return store_gdb_defaults(sp); } if (strcmp(buf, "16.2") == 0) { fclose(fp); sp = &supported_gdb_versions[GDB_16_2]; fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); return store_gdb_defaults(sp); } } fclose(fp); fprintf(stderr, ".gdb: rejected -- using default gdb\n\n"); return store_gdb_defaults(NULL); } struct supported_gdb_version * store_gdb_defaults(struct supported_gdb_version *sp) { if (!sp) sp = &supported_gdb_versions[default_gdb]; else fprintf(stderr, "WARNING: \"make clean\" may be required before rebuilding\n\n"); return sp; } void set_initial_target(struct supported_gdb_version *sp) { FILE *fp; char crash_target[512]; char buf[512]; target_data.initial_gdb_target = UNKNOWN; sprintf(crash_target, "%s/crash.target", &sp->GDB[strlen("GDB=")]); if (!file_exists(crash_target)) { if (target_data.target_as_param && file_exists(&sp->GDB[strlen("GDB=")])) { fprintf(stderr, "\nThe \"%s\" file does not exist.\n", crash_target); target_rebuild_instructions(sp, (char *)target_data.target_as_param); exit(1); } return; } if ((fp = fopen(crash_target, "r")) == NULL) { perror(crash_target); return; } if (!fgets(buf, 512, fp)) { perror(crash_target); fclose(fp); return; } fclose(fp); if (strncmp(buf, "X86_64", strlen("X86_64")) == 0) target_data.initial_gdb_target = X86_64; else if (strncmp(buf, "X86", strlen("X86")) == 0) target_data.initial_gdb_target = X86; else if (strncmp(buf, "ALPHA", strlen("ALPHA")) == 0) target_data.initial_gdb_target = ALPHA; else if (strncmp(buf, "PPC64", strlen("PPC64")) == 0) target_data.initial_gdb_target = PPC64; else if (strncmp(buf, "PPC", strlen("PPC")) == 0) target_data.initial_gdb_target = PPC; else if (strncmp(buf, "IA64", strlen("IA64")) == 0) target_data.initial_gdb_target = IA64; else if (strncmp(buf, "S390X", strlen("S390X")) == 0) target_data.initial_gdb_target = S390X; else if (strncmp(buf, "S390", strlen("S390")) == 0) target_data.initial_gdb_target = S390; else if (strncmp(buf, "ARM64", strlen("ARM64")) == 0) target_data.initial_gdb_target = ARM64; else if (strncmp(buf, "ARM", strlen("ARM")) == 0) target_data.initial_gdb_target = ARM; else if (strncmp(buf, "MIPS64", strlen("MIPS64")) == 0) target_data.initial_gdb_target = MIPS64; else if (strncmp(buf, "MIPS", strlen("MIPS")) == 0) target_data.initial_gdb_target = MIPS; else if (strncmp(buf, "SPARC64", strlen("SPARC64")) == 0) target_data.initial_gdb_target = SPARC64; else if (strncmp(buf, "RISCV64", strlen("RISCV64")) == 0) target_data.initial_gdb_target = RISCV64; else if (strncmp(buf, "LOONGARCH64", strlen("LOONGARCH64")) == 0) target_data.initial_gdb_target = LOONGARCH64; } char * target_to_name(int target) { switch (target) { case X86: return("X86"); case ALPHA: return("ALPHA"); case PPC: return("PPC"); case IA64: return("IA64"); case S390: return("S390"); case S390X: return("S390X"); case PPC64: return("PPC64"); case X86_64: return("X86_64"); case ARM: return("ARM"); case ARM64: return("ARM64"); case MIPS: return("MIPS"); case MIPS64: return("MIPS64"); case SPARC64: return("SPARC64"); case RISCV64: return("RISCV64"); case LOONGARCH64: return("LOONGARCH64"); } return "UNKNOWN"; } int name_to_target(char *name) { if (strncmp(name, "X86_64", strlen("X86_64")) == 0) return X86_64; else if (strncmp(name, "x86_64", strlen("x86_64")) == 0) return X86_64; else if (strncmp(name, "X86", strlen("X86")) == 0) return X86; else if (strncmp(name, "x86", strlen("x86")) == 0) return X86; else if (strncmp(name, "ALPHA", strlen("ALPHA")) == 0) return ALPHA; else if (strncmp(name, "alpha", strlen("alpha")) == 0) return ALPHA; else if (strncmp(name, "PPC64", strlen("PPC64")) == 0) return PPC64; else if (strncmp(name, "ppc64", strlen("ppc64")) == 0) return PPC64; else if (strncmp(name, "ppc64le", strlen("ppc64le")) == 0) return PPC64; else if (strncmp(name, "PPC64LE", strlen("PPC64LE")) == 0) return PPC64; else if (strncmp(name, "PPC", strlen("PPC")) == 0) return PPC; else if (strncmp(name, "ppc", strlen("ppc")) == 0) return PPC; else if (strncmp(name, "IA64", strlen("IA64")) == 0) return IA64; else if (strncmp(name, "ia64", strlen("ia64")) == 0) return IA64; else if (strncmp(name, "S390X", strlen("S390X")) == 0) return S390X; else if (strncmp(name, "s390x", strlen("s390x")) == 0) return S390X; else if (strncmp(name, "S390", strlen("S390")) == 0) return S390; else if (strncmp(name, "s390", strlen("s390")) == 0) return S390; else if (strncmp(name, "ARM64", strlen("ARM64")) == 0) return ARM64; else if (strncmp(name, "arm64", strlen("arm64")) == 0) return ARM64; else if (strncmp(name, "aarch64", strlen("aarch64")) == 0) return ARM64; else if (strncmp(name, "ARM", strlen("ARM")) == 0) return ARM; else if (strncmp(name, "arm", strlen("arm")) == 0) return ARM; else if (strncmp(name, "mips", strlen("mips")) == 0) return MIPS; else if (strncmp(name, "MIPS", strlen("MIPS")) == 0) return MIPS; else if (strncmp(name, "mips64", strlen("mips64")) == 0) return MIPS64; else if (strncmp(name, "MIPS64", strlen("MIPS64")) == 0) return MIPS64; else if (strncmp(name, "sparc64", strlen("sparc64")) == 0) return SPARC64; else if (strncmp(name, "RISCV64", strlen("RISCV64")) == 0) return RISCV64; else if (strncmp(name, "riscv64", strlen("riscv64")) == 0) return RISCV64; else if (strncmp(name, "loongarch64", strlen("loongarch64")) == 0) return LOONGARCH64; else if (strncmp(name, "LOONGARCH64", strlen("LOONGARCH64")) == 0) return LOONGARCH64; return UNKNOWN; } char * get_extra_flags(char *filename, char *initial) { FILE *fp; char inbuf[512]; char buf[512]; if (!file_exists(filename)) return (initial ? initial : NULL); if ((fp = fopen(filename, "r")) == NULL) { perror(filename); return (initial ? initial : NULL); } if (initial) strcpy(buf, initial); else buf[0] = '\0'; while (fgets(inbuf, 512, fp)) { strip_linefeeds(inbuf); strip_beginning_whitespace(inbuf); strip_ending_whitespace(inbuf); if (inbuf[0] == '#') continue; if (strlen(inbuf)) { if (strlen(buf)) strcat(buf, " "); strcat(buf, inbuf); } } fclose(fp); if (strlen(buf)) return strdup(buf); else return NULL; } /* * Add extra compression libraries. If not already there, create * a CFLAGS.extra file and an LDFLAGS.extra file. * For lzo: * - enter -DLZO in the CFLAGS.extra file * - enter -llzo2 in the LDFLAGS.extra file * * For snappy: * - enter -DSNAPPY in the CFLAGS.extra file * - enter -lsnappy in the LDFLAGS.extra file * * For zstd: * - enter -DZSTD in the CFLAGS.extra file * - enter -lzstd in the LDFLAGS.extra file * * For valgrind: * - enter -DVALGRIND in the CFLAGS.extra file */ void add_extra_lib(char *option) { int lzo, add_DLZO, add_llzo2; int snappy, add_DSNAPPY, add_lsnappy; int zstd, add_DZSTD, add_lzstd; int valgrind, add_DVALGRIND; char *cflags, *ldflags; FILE *fp_cflags, *fp_ldflags; char *mode; char inbuf[512]; lzo = add_DLZO = add_llzo2 = 0; snappy = add_DSNAPPY = add_lsnappy = 0; zstd = add_DZSTD = add_lzstd = 0; valgrind = add_DVALGRIND = 0; ldflags = get_extra_flags("LDFLAGS.extra", NULL); cflags = get_extra_flags("CFLAGS.extra", NULL); if (strcmp(option, "lzo") == 0) { lzo++; if (!cflags || !strstr(cflags, "-DLZO")) add_DLZO++; if (!ldflags || !strstr(ldflags, "-llzo2")) add_llzo2++; } if (strcmp(option, "snappy") == 0) { snappy++; if (!cflags || !strstr(cflags, "-DSNAPPY")) add_DSNAPPY++; if (!ldflags || !strstr(ldflags, "-lsnappy")) add_lsnappy++; } if (strcmp(option, "zstd") == 0) { zstd++; if (!cflags || !strstr(cflags, "-DZSTD")) add_DZSTD++; if (!ldflags || !strstr(ldflags, "-lzstd")) add_lzstd++; } if (strcmp(option, "valgrind") == 0) { valgrind++; if (!cflags || !strstr(cflags, "-DVALGRIND")) add_DVALGRIND++; } if ((lzo || snappy || zstd) && file_exists("diskdump.o") && (unlink("diskdump.o") < 0)) { perror("diskdump.o"); return; } if (valgrind && file_exists("tools.o") && (unlink("tools.o") < 0)) { perror("tools.o"); return; } mode = file_exists("CFLAGS.extra") ? "r+" : "w+"; if ((fp_cflags = fopen("CFLAGS.extra", mode)) == NULL) { perror("CFLAGS.extra"); return; } mode = file_exists("LDFLAGS.extra") ? "r+" : "w+"; if ((fp_ldflags = fopen("LDFLAGS.extra", mode)) == NULL) { perror("LDFLAGS.extra"); fclose(fp_cflags); return; } if (add_DLZO || add_DSNAPPY || add_DZSTD || add_DVALGRIND) { while (fgets(inbuf, 512, fp_cflags)) ; if (add_DLZO) fputs("-DLZO\n", fp_cflags); if (add_DSNAPPY) fputs("-DSNAPPY\n", fp_cflags); if (add_DZSTD) fputs("-DZSTD\n", fp_cflags); if (add_DVALGRIND) fputs("-DVALGRIND\n", fp_cflags); } if (add_llzo2 || add_lsnappy || add_lzstd) { while (fgets(inbuf, 512, fp_ldflags)) ; if (add_llzo2) fputs("-llzo2\n", fp_ldflags); if (add_lsnappy) fputs("-lsnappy\n", fp_ldflags); if (add_lzstd) fputs("-lzstd\n", fp_ldflags); } fclose(fp_cflags); fclose(fp_ldflags); } crash-utility-crash-61fe107/crash.8000066400000000000000000000563751517256214500171650ustar00rootroot00000000000000.\" .de CO \dB\\$1\fP \fI\\$2\fP .. .TH CRASH 8 .SH NAME crash \- Analyze Linux crash dump data or a live system .SH SYNOPSIS .B crash [\fIOPTION\fR]... \fINAMELIST MEMORY-IMAGE[@ADDRESS] (dumpfile form)\fR .br .B crash [\fIOPTION\fR]... \fI[NAMELIST] (live system form)\fR .SH DESCRIPTION .B Crash is a tool for interactively analyzing the state of the Linux system while it is running, or after a kernel crash has occurred and a core dump has been created by the .I netdump, .I diskdump, .I LKCD, .I kdump, .I xendump .I kvmdump or .I VMware facilities. It is loosely based on the SVR4 UNIX crash command, but has been significantly enhanced by completely merging it with the .B gdb(1) debugger. The marriage of the two effectively combines the kernel-specific nature of the traditional UNIX crash utility with the source code level debugging capabilities of .B gdb(1). In the .I dumpfile form, both a NAMELIST and a MEMORY-IMAGE argument must be entered. In the .I live system form, the NAMELIST argument must be entered if the kernel's .I vmlinux file is not located in a known location, such as the .I /usr/lib/debug/lib/modules/ directory. The .B crash utility has also been extended to support the analysis of dumpfiles generated by a crash of the Xen hypervisor. In that case, the NAMELIST argument must be that of the .I xen-syms binary. Live system analysis is not supported for the Xen hypervisor. The .B crash utility command set consists of common kernel core analysis tools such as kernel stack back traces of all processes, source code disassembly, formatted kernel structure and variable displays, virtual memory data, dumps of linked-lists, etc., along with several commands that delve deeper into specific kernel subsystems. Appropriate .B gdb commands may also be entered, which in turn are passed on to the .B gdb module for execution. If desired, commands may be placed in either a .I $HOME/.crashrc file and/or in a .I .crashrc file in the current directory. During initialization, the commands in .I $HOME/.crashrc are executed first, followed by those in the .I ./.crashrc file. The .B crash utility is designed to be independent of Linux version dependencies. When new kernel source code impacts the correct functionality of .B crash and its command set, the utility will be updated to recognize new kernel code changes, while maintaining backwards compatibility with earlier releases. .SH OPTIONS .de BS \fB\\$1\fP\ \fR\\$2\fP .. .TP .BI NAMELIST This is a pathname to an uncompressed kernel image (a .I vmlinux file), or a Xen hypervisor image (a .I xen-syms file) which has been compiled with the "-g" option. If using the .I dumpfile form, a .I vmlinux file may be compressed in either gzip or bzip2 formats. .TP .BI MEMORY-IMAGE[@ADDRESS] A kernel core dump file created by the .I netdump, .I diskdump, .I LKCD .I kdump, .I xendump .I kvmdump or .I VMware facilities. If a MEMORY-IMAGE argument is not entered, the session will be invoked on the live system, which typically requires root privileges because of the device file used to access system RAM. By default, .I /dev/crash will be used if it exists. If it does not exist, then .I /dev/mem will be used; but if the kernel has been configured with .B CONFIG_STRICT_DEVMEM, then .I /proc/kcore will be used. It is permissible to explicitly enter .I /dev/crash, .I /dev/mem or .I /proc/kcore. An @ADDRESS value must be appended to the MEMORY-IMAGE if the dumpfile is a raw RAM dumpfile that has no header information describing the file contents. Multiple MEMORY-IMAGE@ADDRESS ordered pairs may be entered, with each dumpfile containing a contiguous block of RAM, where the ADDRESS value is the physical start address of the block expressed in hexadecimal. The physical address value(s) will be used to create a temporary ELF header in /var/tmp, which will only exist during the crash session. If a raw RAM dumpile represents a live memory source, such as that specified by the QEMU mem-path argument of a memory-backend-file object, then "live:" must be prepended to the MEMORY-IMAGE name. As VMware facility, the .B crash utility is able to process VMware VM memory dump generated by VM suspend or guest core dump. In that case, .vmss or .guest file should be used as a MEMORY-IMAGE and .vmem file must be located in the same folder. .TP .BI mapfile If the NAMELIST file is not the same kernel that is running (live system form), or the kernel that was running when the system crashed (dumpfile form), then the .I System.map file of the original kernel should be entered on the command line. .P .BI -h \ [option] .br .BI \--help \ [option] .RS Without an .I option argument, display a .B crash usage help message. If the .I option argument is a .B crash command name, the help page for that command is displayed. If it is the string "input", a page describing the various .B crash command line input options is displayed. If it is the string "output", a page describing command line output options is displayed. If it is the string "all", then all of the possible help messages are displayed. After the help message is displayed, .B crash exits. .RE .TP .B \-s Silently proceed directly to the "crash>" prompt without displaying any version, GPL, or .B crash initialization data during startup, and by default, runtime command output is not passed to any scrolling command. .TP .BI \-i \ file Execute the command(s) contained in .I file prior to displaying the "crash>" prompt for interactive user input. .TP .BI \-d \ num Set the internal debug level. The higher the number, the more debugging data will be printed when .B crash initializes and runs. .TP .B \-S Use .I /boot/System.map as the .I mapfile\fP. .TP .B \-e \fIvi | emacs\fR Set the .B readline(3) command line editing mode to "vi" or "emacs". The default editing mode is "vi". .TP .B \-f Force the usage of a compressed .I vmlinux file if its original name does not start with "vmlinux". .TP .B \-k Indicate that the NAMELIST file is an LKCD "Kerntypes" debuginfo file. .TP .BI -g \ [namelist] Determine if a .I vmlinux or .I xen-syms namelist file contains debugging data. .TP .B \-t Display the system-crash timestamp and exit. .TP .B \-L Attempt to lock all of its virtual address space into memory by calling mlockall(MCL_CURRENT|MCL_FUTURE) during initialization. If the system call fails, an error message will be displayed, but the session continues. .TP .BI \-c \ tty-device Open the .I tty-device as the console used for debug messages. .TP .BI \-p \ page-size If a processor's page size cannot be determined by the dumpfile, and the processor default cannot be used, use .I page-size. .TP .BI \-o \ filename Only used with the MEMORY-IMAGE@ADDRESS format for raw RAM dumpfiles, specifies a filename of a new ELF vmcore that will be created and used as the dumpfile. It will be saved to allow future use as a standalone vmcore, replacing the original raw RAM dumpfile. .P .B -m \fIoption=value\fR .br .B --machdep \fIoption=value\fR .RS Pass an option and value pair to machine-dependent code. These architecture-specific option/pairs should only be required in very rare circumstances: .P .nf X86_64: phys_base= irq_eframe_link= irq_stack_gap= max_physmem_bits= kernel_image_size= vm=orig (pre-2.6.11 virtual memory address ranges) vm=2.6.11 (2.6.11 and later virtual memory address ranges) vm=xen (Xen kernel virtual memory address ranges) vm=xen-rhel4 (RHEL4 Xen kernel virtual address ranges) vm=5level (5-level page tables) page_offset= PPC64: vm=orig vm=2.6.14 (4-level page tables) IA64: phys_start= init_stack_size= vm=4l (4-level page tables) ARM: phys_base= ARM64: phys_offset= kimage_voffset= max_physmem_bits= vabits_actual= X86: page_offset= .fi .RE .TP .B \-x Automatically load extension modules from a particular directory. If a directory is specified in the .B CRASH_EXTENSIONS shell environment variable, then that directory will be used. Otherwise .I /usr/lib64/crash/extensions (64-bit architectures) or .I /usr/lib/crash/extensions (32-bit architectures) will be used; if they do not exist, then the .I ./extensions directory will be used. .TP .BI --active Track only the active task on each cpu. .TP .BI --buildinfo Display the crash binary's build date, the user ID of the builder, the hostname of the machine where the build was done, the target architecture, the version number, and the compiler version. .TP .BI --memory_module \ modname Use the .I modname as an alternative kernel module to the .I crash.ko module that creates the .I /dev/crash device. .TP .BI --memory_device \ device Use .I device as an alternative device to the .I /dev/crash, /dev/mem or .I /proc/kcore devices. .TP .BI --log \ dumpfile Dump the contents of the kernel log buffer. A kernel namelist argument is not necessary, but the dumpfile must contain the VMCOREINFO data taken from the original /proc/vmcore ELF header. Note: this option is deprecated and will no longer work for kernel(>=v5.10). .TP .B --no_kallsyms Do not use kallsyms-generated symbol information contained within kernel module object files. .TP .B --no_modules Do not access or display any kernel module related information. .TP .B --no_ikconf Do not attempt to read configuration data that was built into kernels configured with .B CONFIG_IKCONFIG. .TP .B --no_data_debug Do not verify the validity of all structure member offsets and structure sizes that it uses. .TP .B --no_kmem_cache Do not initialize the kernel's slab cache infrastructure, and commands that use kmem_cache-related data will not work. .TP .B --no_elf_notes Do not use the registers from the ELF NT_PRSTATUS notes saved in a compressed kdump header for backtraces. .TP .B --kmem_cache_delay Delay the initialization of the kernel's slab cache infrastructure until it is required by a run-time command. .TP .B --readnow Pass this flag to the embedded .B gdb module, which will override its two-stage strategy that it uses for reading symbol tables from the NAMELIST. .TP .B --smp Specify that the system being analyzed is an SMP kernel. .P .B -v .br .B --version .RS Display the version of the .B crash utility, the version of the embedded .B gdb module, GPL information, and copyright notices. .RE .TP .BI --cpus \ number Specify the .I number of cpus in the SMP system being analyzed. .TP .BI --osrelease \ dumpfile Display the OSRELEASE vmcoreinfo string from a kdump .I dumpfile header. .TP .BI --build-id \ dumpfile Display the BUILD-ID vmcoreinfo string from a kdump .I dumpfile header. Note: this option only works for kernel (>=v5.9); otherwise it prints "unknown" and exits with non-zero status. .TP .BI --hyper Force the session to be that of a Xen hypervisor. .TP .BI --p2m_mfn \ pfn When a Xen Hypervisor or its dom0 kernel crashes, the dumpfile is typically analyzed with either the Xen hypervisor or the dom0 kernel. It is also possible to analyze any of the guest domU kernels if the pfn_to_mfn_list_list .I pfn value of the guest kernel is passed on the command line along with its NAMELIST and the dumpfile. .TP .BI --xen_phys_start \ physical-address Supply the base physical address of the Xen hypervisor's text and static data for older xendump dumpfiles that did not pass that information in the dumpfile header. .TP .B --zero_excluded If the makedumpfile(8) facility has filtered a compressed kdump dumpfile to exclude various types of non-essential pages, or has marked a compressed or ELF kdump dumpfile as incomplete due to an ENOSPC or other error during its creation, any attempt to read missing pages will fail. With this flag, reads from any of those pages will return zero-filled memory. .TP .B --no_panic Do not attempt to find the task that was running when the kernel crashed. Set the initial context to that of the "swapper" task on cpu 0. .TP .B --more Use .I /bin/more as the command output scroller, overriding the default of .I /usr/bin/less and any settings in either .I ./.crashrc or .I $HOME/.crashrc. .TP .B --less Use .I /usr/bin/less as the command output scroller, overriding any settings in either .I ./.crashrc or .I $HOME/.crashrc. .TP .B --hex Set the default command output radix to 16, overriding the default radix of 10, and any radix settings in either .I ./.crashrc or .I $HOME/.crashrc. .TP .B --dec Set the default command output radix to 10, overriding any radix settings in either .I ./.crashrc or .I $HOME/.crashrc. This is the default radix setting. .TP .B --CRASHPAGER Use the output paging command defined in the .B CRASHPAGER shell environment variable, overriding any settings in either .I ./.crashrc or .I $HOME/.crashrc. .TP .B --no_scroll Do not pass run-time command output to any scrolling command. .TP .B --no_strip Do not strip cloned kernel text symbol names. .TP .B --no_crashrc Do not execute the commands in either .I $HOME/.crashrc or .I ./.crashrc. .TP .BI --mod \ directory When loading the debuginfo data of kernel modules with the .I mod -S command, search for their object files in .I directory instead of in the standard location. .TP .BI --src \ directory Search for the kernel source code in directory instead of in the standard location that is compiled into the debuginfo data. .TP .BI --kaslr \ offset | auto If an x86, x86_64, s390x or loongarch64 kernel was configured with .B CONFIG_RANDOMIZE_BASE, the offset value is equal to the difference between the symbol values compiled into the vmlinux file and their relocated KASLR values. If set to auto, the KASLR offset value will be automatically calculated. .TP .BI --reloc \ size When analyzing live x86 kernels that were configured with a .B CONFIG_PHYSICAL_START value that is larger than its .B CONFIG_PHYSICAL_ALIGN value, then it will be necessary to enter a relocation size equal to the difference between the two values. .TP .BI --hash \ count Set the number of internal hash queue heads used for list gathering and verification. The default count is 32768. .TP .BI --max-malloc-bufs \ size Set the value of \fBMAX_MALLOC_BUFS\fP to \fIsize\fP. The minimum allowed value is 3072. .TP .B --minimal Bring up a session that is restricted to the .I log, dis, rd, sym, eval, set and .I exit commands. This option may provide a way to extract some minimal/quick information from a corrupted or truncated dumpfile, or in situations where one of the several kernel subsystem initialization routines would abort the .B crash session. .TP .BI --kvmhost \ [32|64] When examining an x86 KVM guest dumpfile, this option specifies that the KVM host that created the dumpfile was an x86 (32-bit) or an x86_64 (64-bit) machine, overriding the automatically determined value. .TP .BI --kvmio \ override the automatically-calculated KVM guest I/O hole size. .TP .BI --offline \ [show|hide] Show or hide command output that is related to offline cpus. The default setting is show. .SH COMMANDS Each .B crash command generally falls into one of the following categories: .TP .I Symbolic display Displays of kernel text/data, which take full advantage of the power of .B gdb to format and display data structures symbolically. .TP .I System state The majority of .B crash commands consist of a set of "kernel-aware" commands, which delve into various kernel subsystems on a system-wide or per-task basis. .TP .I Utility functions A set of useful helper commands serving various purposes, some simple, others quite powerful. .TP .I Session control Commands that control the .B crash session itself. .PP The following alphabetical list consists of a very simple overview of each .B crash command. However, since individual commands often have several options resulting in significantly different output, it is suggested that the full description of each command be viewed by executing .I crash\ -h\ \fI\fP, or during a .B crash session by simply entering .B \fIhelp command\fP. .TP .I * "pointer to" is shorthand for either the .I struct or .I union commands. It displays the contents of a kernel structure or union. .TP .I alias creates a single-word alias for a command. .TP .I ascii displays an ascii chart or translates a numeric value into its ascii components. .TP .I bpf provides information on currently-loaded eBPF programs and maps. .TP .I bt displays a task's kernel-stack backtrace. If it is given the .I \-a option, it displays the stack traces of the active tasks on all CPUs. It is often used with the .I foreach command to display the backtraces of all tasks with one command. .TP .I btop translates a byte value (physical offset) to its page number. .TP .I dev displays data concerning the character and block device assignments, I/O port usage, I/O memory usage, and PCI device data. .TP .I dis disassembles memory, either entire kernel functions, from a location for a specified number of instructions, or from the start of a function up to a specified memory location. .TP .I eval evaluates an expression or numeric type and displays the result in hexadecimal, decimal, octal and binary. .TP .I exit causes .B crash to exit. .TP .I extend dynamically loads or unloads .B crash shared object extension modules. .TP .I files displays information about open files in a context. .TP .I foreach repeats a specified command for the specified (or all) tasks in the system. .TP .I fuser displays the tasks using the specified file or socket. .TP .I gdb passes its argument to the embedded .B gdb module. It is useful for executing .B gdb commands that have the same name as .B crash commands. .TP .I help alone displays the command menu; if followed by a command name, a full description of a command, its options, and examples are displayed. Its output is far more complete and useful than this man page. .TP .I ipcs displays data about the System V IPC facilities. .TP .I irq displays data concerning interrupt request numbers and bottom-half interrupt handling. .TP .I kmem displays information about the use of kernel memory. .TP .I list displays the contents of a linked list. .TP .I log displays the kernel log_buf contents in chronological order. .TP .I mach displays data specific to the machine type. .TP .I mod displays information about the currently installed kernel modules, or adds or deletes symbolic or debugging information about specified kernel modules. .TP .I mount displays information about the currently-mounted filesystems. .TP .I net display various network related data. .TP .I p passes its arguments to the .B gdb "print" command for evaluation and display. .TP .I ps displays process status for specified, or all, processes in the system. .TP .I pte translates the hexadecimal contents of a PTE into its physical page address and page bit settings. .TP .I ptob translates a page frame number to its byte value. .TP .I ptov translates a hexadecimal physical address into a kernel virtual address. .TP .I q is an alias for the "exit" command. .TP .I rd displays the contents of memory, with the output formatted in several different manners. .TP .I repeat repeats a command indefinitely, optionally delaying a given number of seconds between each command execution. .TP .I runq displays the tasks on the run queue. .TP .I sbitmapq dumps the contents of the sbitmap_queue structure and the used bits in the bitmap. Also, it shows the dump of a structure array associated with the sbitmap_queue. .TP .I search searches a range of user or kernel memory space for given value. .TP .I set either sets a new context, or gets the current context for display. .TP .I sig displays signal-handling data of one or more tasks. .TP .I struct displays either a structure definition or the contents of a kernel structure at a specified address. .TP .I swap displays information about each configured swap device. .TP .I sym translates a symbol to its virtual address, or a static kernel virtual address to its symbol -- or to a symbol-plus-offset value, if appropriate. .TP .I sys displays system-specific data. .TP .I task displays the contents of a task_struct. .TP .I tree displays the contents of a red-black tree or a radix tree. .TP .I timer displays the timer queue entries, both old- and new-style, in chronological order. .TP .I union is similar to the .I struct command, except that it works on kernel unions. .TP .I vm displays basic virtual memory information of a context. .TP .I vtop translates a user or kernel virtual address to its physical address. .TP .I waitq walks the wait queue list displaying the tasks which are blocked on the specified wait queue. .TP .I whatis displays the definition of structures, unions, typedefs or text/data symbols. .TP .I wr modifies the contents of memory on a live system. It can only be used if .I /dev/mem is the device file being used to access system RAM, and should obviously be used with great care. .PP When .B crash is invoked with a Xen hypervisor binary as the NAMELIST, the command set is slightly modified. The .I *, alias, ascii, bt, dis, eval, exit, extend, .I gdb, help, list, log, p, pte, rd, repeat, .I search, set, struct, sym, sys, union, .I whatis, wr and .I q commands are the same as above. The following commands are specific to the Xen hypervisor: .TP .I domain displays the contents of the domain structure for selected, or all, domains. .TP .I doms displays domain status for selected, or all, domains. .TP .I dumpinfo displays Xen dump information for selected, or all, cpus. .TP .I pcpus displays physical cpu information for selected, or all, cpus. .TP .I vcpus displays vcpu status for selected, or all, vcpus. .SH FILES .TP .I .crashrc Initialization commands. The file can be located in the user's .B HOME directory and/or the current directory. Commands found in the .I .crashrc file in the .B HOME directory are executed before those in the current directory's .I .crashrc file. .SH ENVIRONMENT .TP .B EDITOR Command input is read using .BR readline(3). If .B EDITOR is set to .I emacs or .I vi then suitable keybindings are used. If .B EDITOR is not set, then .I vi is used. This can be overridden by .B set vi or .B set emacs commands located in a .IR .crashrc file, or by entering .B -e emacs on the .B crash command line. .TP .B CRASHPAGER If .B CRASHPAGER is set, its value is used as the name of the program to which command output will be sent. If not, then command output is sent to .B /usr/bin/less -E -X by default. .TP .B CRASH_MODULE_PATH Specifies an alternative directory tree to search for kernel module object files. .TP .B CRASH_EXTENSIONS Specifies a directory containing extension modules that will be loaded automatically if the .B -x command line option is used. .SH NOTES .PP If .B crash does not work, look for a newer version: kernel evolution frequently makes .B crash updates necessary. .PP The command .B set scroll off will cause output to be sent directly to the terminal rather than through a paging program. This is useful, for example, if you are running .B crash in a window of .BR emacs . .SH AUTHOR Dave Anderson wrote .B crash. .TP Jay Fenlason and Dave Anderson wrote this man page. .SH "SEE ALSO" .PP The .I help command within .B crash provides more complete and accurate documentation than this man page. .PP .I https://github.com/crash-utility - the home page of the .B crash utility. .PP .BR netdump (8), .BR gdb (1), .BR makedumpfile(8) crash-utility-crash-61fe107/crash_target.c000066400000000000000000000137141517256214500205740ustar00rootroot00000000000000/* * crash_target.c * * Copyright (c) 2021 VMware, Inc. * * 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 2 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. * * Author: Alexey Makhalov */ #include #include "top.h" #include "target.h" #include "inferior.h" #include "regcache.h" #include "gdbarch.h" void crash_target_init (void); extern "C" int gdb_readmem_callback(unsigned long, void *, int, int); extern "C" int crash_get_current_task_reg (int regno, const char *regname, int regsize, void *val, int sid); extern "C" int gdb_change_thread_context (void); extern "C" int gdb_add_substack (int); extern "C" void crash_get_current_task_info(unsigned long *pid, char **comm); #if defined (X86_64) || defined (ARM64) || defined (PPC64) extern "C" void silent_call_bt(void); #endif /* The crash target. */ static const target_info crash_target_info = { "crash", N_("Local core dump file"), N_("Use a built-in crash instance as a target.") }; class crash_target final : public process_stratum_target { public: const target_info &info () const override { return crash_target_info; } void fetch_registers (struct regcache *, int) override; enum target_xfer_status xfer_partial (enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override; bool has_all_memory () override { return true; } bool has_memory () override { return true; } bool has_stack () override { return true; } bool has_registers () override { return true; } bool thread_alive (ptid_t ptid) override { return true; } std::string pid_to_str (ptid_t ptid) override { unsigned long pid; char *comm; crash_get_current_task_info(&pid, &comm); return string_printf ("%ld %s", pid, comm); } const char *extra_thread_info (thread_info *tp) override { static char buf[16] = {0}; snprintf(buf, sizeof(buf), "stack %ld", tp->ptid.tid()); return buf; } }; static void supply_registers(struct regcache *regcache, int regno) { gdb_byte regval[32]; struct gdbarch *arch = regcache->arch (); const char *regname = gdbarch_register_name(arch, regno); int regsize = register_size(arch, regno); if (regsize > sizeof (regval)) error (_("fatal error: buffer size is not enough to fit register value")); if (crash_get_current_task_reg (regno, regname, regsize, (void *)®val, inferior_thread()->ptid.tid())) regcache->raw_supply (regno, regval); else regcache->raw_supply (regno, NULL); } void crash_target::fetch_registers (struct regcache *regcache, int regno) { if (regno >= 0) { supply_registers(regcache, regno); } else if (regno == -1) { for (int r = 0; r < gdbarch_num_regs (regcache->arch ()); r++) supply_registers(regcache, r); } } enum target_xfer_status crash_target::xfer_partial (enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) { if (object != TARGET_OBJECT_MEMORY && object != TARGET_OBJECT_STACK_MEMORY && object != TARGET_OBJECT_CODE_MEMORY) return TARGET_XFER_E_IO; if (gdb_readmem_callback(offset, (void *)(readbuf ? readbuf : writebuf), len, !readbuf)) { *xfered_len = len; return TARGET_XFER_OK; } return TARGET_XFER_E_IO; } #define CRASH_INFERIOR_PID 1 void crash_target_init (void) { crash_target *target = new crash_target (); /* Own the target until it is successfully pushed. */ target_ops_up target_holder (target); current_inferior ()->push_target (std::move (target_holder)); inferior_appeared (current_inferior (), CRASH_INFERIOR_PID); /*Only create 1 gdb threads to view tasks' stack unwinding*/ thread_info *thread = add_thread_silent (target, ptid_t(CRASH_INFERIOR_PID, 0, 0)); switch_to_thread (thread); /* Fetch all registers from core file. */ target_fetch_registers (get_thread_regcache(thread), -1); /* Now, set up the frame cache. */ reinit_frame_cache (); } extern "C" int gdb_change_thread_context (void) { /* 1st, switch to tid 0 if we are not */ if (inferior_thread()->ptid.tid()) { switch_to_thread (&(current_inferior()->thread_list.front())); } /* 2nd, delete threads whose tid is not 0 */ for (thread_info *tp : current_inferior()->threads_safe()) { if (tp->ptid.tid() && tp->deletable()) { delete_thread_silent(tp); current_inferior()->highest_thread_num--; } } /* 3rd, refresh regcache for tid 0 */ target_fetch_registers(get_thread_regcache(inferior_thread()), -1); reinit_frame_cache(); #if defined (X86_64) || defined (ARM64) || defined (PPC64) /* 4th, invoke bt silently to refresh the additional stacks */ silent_call_bt(); #endif return TRUE; } /* Add a thread for each additional stack. Use stack ID as a thread ID */ extern "C" int gdb_add_substack (int sid) { thread_info *tp; thread_info *current_thread = inferior_thread(); ptid_t ptid = ptid_t(CRASH_INFERIOR_PID, 0, sid + 1); tp = current_inferior()->find_thread(ptid); if (tp == nullptr) { tp = add_thread_silent(current_inferior()->process_target(), ptid); } switch_to_thread (tp); target_fetch_registers(get_thread_regcache(tp), -1); switch_to_thread (current_thread); return TRUE; }crash-utility-crash-61fe107/defs.h000066400000000000000000007625351517256214500170700ustar00rootroot00000000000000/* defs.h - core analysis suite * * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. * Copyright (C) 2002-2020 David Anderson * Copyright (C) 2002-2020 Red Hat, Inc. All rights reserved. * Copyright (C) 2002 Silicon Graphics, Inc. * * 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 2 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. */ #ifndef GDB_COMMON #include #include #include #include #include #include #include #include #undef basename #if !defined(__USE_GNU) #define __USE_GNU #include #undef __USE_GNU #else #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* backtrace() */ #include #ifdef LZO #include #endif #ifdef SNAPPY #include #endif #ifdef ZSTD #include #endif #ifndef ATTRIBUTE_UNUSED #define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) #endif #undef TRUE #undef FALSE #define TRUE (1) #define FALSE (0) #define STR(x) #x #ifndef offsetof # define offsetof(TYPE, MEMBER) ((ulong)&((TYPE *)0)->MEMBER) #endif #if !defined(X86) && !defined(X86_64) && !defined(ALPHA) && !defined(PPC) && \ !defined(IA64) && !defined(PPC64) && !defined(S390) && !defined(S390X) && \ !defined(ARM) && !defined(ARM64) && !defined(MIPS) && !defined(MIPS64) && \ !defined(RISCV64) && !defined(LOONGARCH64) && !defined(SPARC64) #ifdef __alpha__ #define ALPHA #endif #ifdef __i386__ #define X86 #endif #ifdef __powerpc64__ #define PPC64 #else #ifdef __powerpc__ #define PPC #endif #endif #ifdef __ia64__ #define IA64 #endif #ifdef __s390__ #define S390 #endif #ifdef __s390x__ #define S390X #endif #ifdef __x86_64__ #define X86_64 #endif #ifdef __arm__ #define ARM #endif #ifdef __aarch64__ #define ARM64 #endif #ifdef __mipsel__ #ifndef __mips64 #define MIPS #else #define MIPS64 #endif #endif #ifdef __sparc_v9__ #define SPARC64 #endif #if defined(__riscv) && (__riscv_xlen == 64) #define RISCV64 #endif #ifdef __loongarch64 #define LOONGARCH64 #endif #endif #ifdef X86 #define NR_CPUS (256) #endif #ifdef X86_64 #define NR_CPUS (8192) #endif #ifdef ALPHA #define NR_CPUS (64) #endif #ifdef PPC #define NR_CPUS (32) #endif #ifdef IA64 #define NR_CPUS (4096) #endif #ifdef PPC64 #define NR_CPUS (8192) #endif #ifdef S390 #define NR_CPUS (512) #endif #ifdef S390X #define NR_CPUS (512) #endif #ifdef ARM #define NR_CPUS (32) #endif #ifdef ARM64 #define NR_CPUS (4096) /* TBD */ #endif #ifdef MIPS #define NR_CPUS (32) #endif #ifdef MIPS64 #define NR_CPUS (256) #endif #ifdef SPARC64 #define NR_CPUS (4096) #endif #ifdef RISCV64 #define NR_CPUS (256) #endif #ifdef LOONGARCH64 #define NR_CPUS (2048) #endif #define NR_DEVICE_DUMPS (64) /* Some architectures require memory accesses to be aligned. */ #if defined(SPARC64) #define NEED_ALIGNED_MEM_ACCESS #endif #define BUFSIZE (1500) #define NULLCHAR ('\0') #define MAXARGS (100) /* max number of arguments to one function */ #define MAXARGLEN (40) /* max length of argument */ #define HIST_BLKSIZE (4096) static inline int string_exists(char *s) { return (s ? TRUE : FALSE); } static inline int max(int a, int b) { if (a > b) return a; return b; } #define STREQ(A, B) (string_exists((char *)A) && string_exists((char *)B) && \ (strcmp((char *)(A), (char *)(B)) == 0)) #define STRNEQ(A, B) (string_exists((char *)A) && string_exists((char *)B) && \ (strncmp((char *)(A), (char *)(B), strlen((char *)(B))) == 0)) #define BZERO(S, N) (memset(S, NULLCHAR, N)) #define BCOPY(S, D, C) (memcpy(D, S, C)) #define BNEG(S, N) (memset(S, 0xff, N)) #define BEEP() fprintf(stderr, "%c", 0x7) #define LASTCHAR(s) (s[strlen(s)-1]) #define FIRSTCHAR(s) (s[0]) #define QUOTED_STRING(s) ((FIRSTCHAR(s) == '"') && (LASTCHAR(s) == '"')) #define SINGLE_QUOTED_STRING(s) ((FIRSTCHAR(s) == '\'') && (LASTCHAR(s) == '\'')) #define PATHEQ(A, B) ((A) && (B) && (pathcmp((char *)(A), (char *)(B)) == 0)) #ifdef roundup #undef roundup #endif #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) typedef uint64_t physaddr_t; #define PADDR_NOT_AVAILABLE (0x1ULL) #define KCORE_USE_VADDR (-1ULL) typedef unsigned long long int ulonglong; struct number_option { ulong num; ulonglong ll_num; ulong retflags; }; /* * program_context flags */ #define LIVE_SYSTEM (0x1ULL) #define TTY (0x2ULL) #define RUNTIME (0x4ULL) #define IN_FOREACH (0x8ULL) #define MCLXCD (0x10ULL) #define CMDLINE_IFILE (0x20ULL) #define MFD_RDWR (0x40ULL) #define KVMDUMP (0x80ULL) #define SILENT (0x100ULL) #define SADUMP (0x200ULL) #define HASH (0x400ULL) #define SCROLL (0x800ULL) #define NO_CONSOLE (0x1000ULL) #define RUNTIME_IFILE (0x2000ULL) #define DROP_CORE (0x4000ULL) #define LKCD (0x8000ULL) #define GDB_INIT (0x10000ULL) #define IN_GDB (0x20000ULL) #define RCLOCAL_IFILE (0x40000ULL) #define RCHOME_IFILE (0x80000ULL) #define VMWARE_VMSS (0x100000ULL) #define READLINE (0x200000ULL) #define _SIGINT_ (0x400000ULL) #define IN_RESTART (0x800000ULL) #define KERNEL_DEBUG_QUERY (0x1000000ULL) #define DEVMEM (0x2000000ULL) #define REM_LIVE_SYSTEM (0x4000000ULL) #define NAMELIST_LOCAL (0x8000000ULL) #define LIVE_RAMDUMP (0x10000000ULL) #define NAMELIST_SAVED (0x20000000ULL) #define DUMPFILE_SAVED (0x40000000ULL) #define UNLINK_NAMELIST (0x80000000ULL) #define NAMELIST_UNLINKED (0x100000000ULL) #define REM_MCLXCD (0x200000000ULL) #define REM_LKCD (0x400000000ULL) #define NAMELIST_NO_GZIP (0x800000000ULL) #define UNLINK_MODULES (0x1000000000ULL) #define S390D (0x2000000000ULL) #define REM_S390D (0x4000000000ULL) #define SYSRQ (0x8000000000ULL) #define KDUMP (0x10000000000ULL) #define NETDUMP (0x20000000000ULL) #define REM_NETDUMP (0x40000000000ULL) #define SYSMAP (0x80000000000ULL) #define SYSMAP_ARG (0x100000000000ULL) #define MEMMOD (0x200000000000ULL) #define MODPRELOAD (0x400000000000ULL) #define DISKDUMP (0x800000000000ULL) #define DATADEBUG (0x1000000000000ULL) #define FINDKERNEL (0x2000000000000ULL) #define VERSION_QUERY (0x4000000000000ULL) #define READNOW (0x8000000000000ULL) #define NOCRASHRC (0x10000000000000ULL) #define INIT_IFILE (0x20000000000000ULL) #define XENDUMP (0x40000000000000ULL) #define XEN_HYPER (0x80000000000000ULL) #define XEN_CORE (0x100000000000000ULL) #define PLEASE_WAIT (0x200000000000000ULL) #define IFILE_ERROR (0x400000000000000ULL) #define KERNTYPES (0x800000000000000ULL) #define MINIMAL_MODE (0x1000000000000000ULL) #define CRASHBUILTIN (0x2000000000000000ULL) #define PRELOAD_EXTENSIONS \ (0x4000000000000000ULL) #define PROC_KCORE (0x8000000000000000ULL) #define ACTIVE() (pc->flags & LIVE_SYSTEM) #define LOCAL_ACTIVE() ((pc->flags & (LIVE_SYSTEM|LIVE_RAMDUMP)) == LIVE_SYSTEM) #define DUMPFILE() (!(pc->flags & LIVE_SYSTEM)) #define LIVE() (pc->flags2 & LIVE_DUMP || pc->flags & LIVE_SYSTEM) #define MEMORY_SOURCES (NETDUMP|KDUMP|MCLXCD|LKCD|DEVMEM|S390D|MEMMOD|DISKDUMP|XENDUMP|CRASHBUILTIN|KVMDUMP|PROC_KCORE|SADUMP|VMWARE_VMSS|LIVE_RAMDUMP) #define DUMPFILE_TYPES (DISKDUMP|NETDUMP|KDUMP|MCLXCD|LKCD|S390D|XENDUMP|KVMDUMP|SADUMP|VMWARE_VMSS|LIVE_RAMDUMP) #define REMOTE() (pc->flags2 & REMOTE_DAEMON) #define REMOTE_ACTIVE() (pc->flags & REM_LIVE_SYSTEM) #define REMOTE_DUMPFILE() \ (pc->flags & (REM_NETDUMP|REM_MCLXCD|REM_LKCD|REM_S390D)) #define REMOTE_MEMSRC() (REMOTE_ACTIVE() || REMOTE_PAUSED() || REMOTE_DUMPFILE()) #define LKCD_DUMPFILE() (pc->flags & (LKCD|REM_LKCD)) #define NETDUMP_DUMPFILE() (pc->flags & (NETDUMP|REM_NETDUMP)) #define DISKDUMP_DUMPFILE() (pc->flags & DISKDUMP) #define KDUMP_DUMPFILE() (pc->flags & KDUMP) #define XENDUMP_DUMPFILE() (pc->flags & XENDUMP) #define XEN_HYPER_MODE() (pc->flags & XEN_HYPER) #define SYSRQ_TASK(X) ((pc->flags & SYSRQ) && is_task_active(X)) #define XEN_CORE_DUMPFILE() (pc->flags & XEN_CORE) #define LKCD_KERNTYPES() (pc->flags & KERNTYPES) #define KVMDUMP_DUMPFILE() (pc->flags & KVMDUMP) #define SADUMP_DUMPFILE() (pc->flags & SADUMP) #define VMSS_DUMPFILE() (pc->flags & VMWARE_VMSS) #define QEMU_MEM_DUMP_NO_VMCOREINFO() \ ((pc->flags2 & (QEMU_MEM_DUMP_ELF|QEMU_MEM_DUMP_COMPRESSED)) && !(pc->flags2 & VMCOREINFO)) #define NETDUMP_LOCAL (0x1) /* netdump_data flags */ #define NETDUMP_REMOTE (0x2) #define VMCORE_VALID() (nd->flags & (NETDUMP_LOCAL|NETDUMP_REMOTE|KDUMP_LOCAL)) #define NETDUMP_ELF32 (0x4) #define NETDUMP_ELF64 (0x8) #define PARTIAL_DUMP (0x10) /* netdump or diskdump */ #define KDUMP_ELF32 (0x20) #define KDUMP_ELF64 (0x40) #define KDUMP_LOCAL (0x80) #define KCORE_LOCAL (0x100) #define KCORE_ELF32 (0x200) #define KCORE_ELF64 (0x400) #define QEMU_MEM_DUMP_KDUMP_BACKUP \ (0x800) #define KVMDUMP_LOCAL (0x1) #define KVMDUMP_VALID() (kvm->flags & (KVMDUMP_LOCAL)) #define DUMPFILE_FORMAT(flags) ((flags) & \ (NETDUMP_ELF32|NETDUMP_ELF64|KDUMP_ELF32|KDUMP_ELF64)) #define DISKDUMP_LOCAL (0x1) #define KDUMP_CMPRS_LOCAL (0x2) #define ERROR_EXCLUDED (0x4) #define ZERO_EXCLUDED (0x8) #define DUMPFILE_SPLIT (0x10) #define NO_ELF_NOTES (0x20) #define LZO_SUPPORTED (0x40) #define SNAPPY_SUPPORTED (0x80) #define ZSTD_SUPPORTED (0x100) #define DISKDUMP_VALID() (dd->flags & DISKDUMP_LOCAL) #define KDUMP_CMPRS_VALID() (dd->flags & KDUMP_CMPRS_LOCAL) #define KDUMP_SPLIT() (dd->flags & DUMPFILE_SPLIT) #define XENDUMP_LOCAL (0x1) #define XENDUMP_VALID() (xd->flags & XENDUMP_LOCAL) #define SADUMP_LOCAL (0x1) #define SADUMP_DISKSET (0x2) #define SADUMP_MEDIA (0x4) #define SADUMP_ZERO_EXCLUDED (0x8) #define SADUMP_KDUMP_BACKUP (0x10) #define SADUMP_VALID() (sd->flags & SADUMP_LOCAL) #define CRASHDEBUG(x) (pc->debug >= (x)) #define CRASHDEBUG_SUSPEND(X) { pc->debug_save = pc->debug; pc->debug = X; } #define CRASHDEBUG_RESTORE() { pc->debug = pc->debug_save; } #define VERBOSE (0x1) #define ADDRESS_SPECIFIED (0x2) #define FAULT_ON_ERROR (0x1) #define RETURN_ON_ERROR (0x2) #define QUIET (0x4) #define HEX_BIAS (0x8) #define LONG_LONG (0x10) #define RETURN_PARTIAL (0x20) #define NO_DEVMEM_SWITCH (0x40) #define SEEK_ERROR (-1) #define READ_ERROR (-2) #define WRITE_ERROR (-3) #define PAGE_EXCLUDED (-4) #define PAGE_INCOMPLETE (-5) #define RESTART() (longjmp(pc->main_loop_env, 1)) #define RESUME_FOREACH() (longjmp(pc->foreach_loop_env, 1)) #define INFO (1) #define FATAL (2) #define FATAL_RESTART (3) #define WARNING (4) #define NOTE (5) #define CONT (6) #define FATAL_ERROR(x) (((x) == FATAL) || ((x) == FATAL_RESTART)) #define CONSOLE_OFF(x) ((x) = console_off()) #define CONSOLE_ON(x) (console_on(x)) #define RADIX(X) (X) #define NUM_HEX (0x1) #define NUM_DEC (0x2) #define NUM_EXPR (0x4) #define NUM_ANY (NUM_HEX|NUM_DEC|NUM_EXPR) /* * program context redirect flags */ #define FROM_COMMAND_LINE (0x1) #define FROM_INPUT_FILE (0x2) #define REDIRECT_NOT_DONE (0x4) #define REDIRECT_TO_PIPE (0x8) #define REDIRECT_TO_STDPIPE (0x10) #define REDIRECT_TO_FILE (0x20) #define REDIRECT_FAILURE (0x40) #define REDIRECT_SHELL_ESCAPE (0x80) #define REDIRECT_SHELL_COMMAND (0x100) #define REDIRECT_PID_KNOWN (0x200) #define REDIRECT_MULTI_PIPE (0x400) #define PIPE_OPTIONS (FROM_COMMAND_LINE | FROM_INPUT_FILE | REDIRECT_TO_PIPE | \ REDIRECT_TO_STDPIPE | REDIRECT_TO_FILE) #define DEFAULT_REDHAT_DEBUG_LOCATION "/usr/lib/debug/lib/modules" #define MEMORY_DRIVER_MODULE "crash" #define MEMORY_DRIVER_DEVICE "/dev/crash" #define MEMORY_DRIVER_DEVICE_MODE (S_IFCHR|S_IRUSR) /* * structure definitions */ struct program_context { char *program_name; /* this program's name */ char *program_path; /* unadulterated argv[0] */ char *program_version; /* this program's version */ char *gdb_version; /* embedded gdb version */ char *prompt; /* this program's prompt */ unsigned long long flags; /* flags from above */ char *namelist; /* linux namelist */ char *dumpfile; /* dumpfile or /dev/kmem */ char *live_memsrc; /* live memory driver */ char *system_map; /* get symbol values from System.map */ char *namelist_debug; /* namelist containing debug data */ char *debuginfo_file; /* separate debuginfo file */ char *memory_module; /* alternative to mem.c driver */ char *memory_device; /* alternative to /dev/[k]mem device */ char *machine_type; /* machine's processor type */ char *editing_mode; /* readline vi or emacs */ char *server; /* network daemon */ char *server_memsrc; /* memory source on server */ char *server_namelist; /* kernel namelist on server */ int nfd; /* linux namelist fd */ int mfd; /* /dev/mem fd */ int kfd; /* /dev/kmem fd */ int dfd; /* dumpfile fd */ int confd; /* console fd */ int sockfd; /* network daemon socket */ ushort port; /* network daemon port */ int rmfd; /* remote server memory source fd */ int rkfd; /* remote server /dev/kmem fd */ ulong program_pid; /* program pid */ ulong server_pid; /* server pid */ ulong rcvbufsize; /* client-side receive buffer size */ char *home; /* user's home directory */ char command_line[BUFSIZE]; /* possibly parsed input command line */ char orig_line[BUFSIZE]; /* original input line */ char *readline; /* pointer to last readline() return */ char my_tty[10]; /* real tty name (shown by ps -ef) */ ulong debug; /* level of debug */ ulong debug_save; /* saved level for debug-suspend */ char *console; /* current debug console device */ char *redhat_debug_loc; /* location of matching debug objects */ int pipefd[2]; /* output pipe file descriptors */ FILE *nullfp; /* bitbucket */ FILE *stdpipe; /* standard pipe for output */ FILE *pipe; /* command line specified pipe */ FILE *ofile; /* command line specified output file */ FILE *ifile; /* command line specified input file */ FILE *ifile_pipe; /* output pipe specified from file */ FILE *ifile_ofile; /* output file specified from file */ FILE *symfile; /* symbol table data file */ FILE *symfile2; /* alternate access to above */ FILE *tmpfile; /* tmpfile for selective data output */ FILE *saved_fp; /* for printing while parsing tmpfile */ FILE *tmp_fp; /* stored tmpfile pointer */ char *input_file; /* input file specified at invocation */ FILE *tmpfile2; /* tmpfile2 does not use save_fp! */ int eoc_index; /* end of redirected command index */ int scroll_command; /* default scroll command for output */ #define SCROLL_NONE 0 #define SCROLL_LESS 1 #define SCROLL_MORE 2 #define SCROLL_CRASHPAGER 3 ulong redirect; /* per-cmd origin and output flags */ pid_t stdpipe_pid; /* per-cmd standard output pipe's pid */ pid_t pipe_pid; /* per-cmd output pipe's pid */ pid_t pipe_shell_pid; /* per-cmd output pipe's shell pid */ char pipe_command[BUFSIZE]; /* pipe command line */ struct command_table_entry *cmd_table; /* linux/xen command table */ char *curcmd; /* currently-executing command */ char *lastcmd; /* previously-executed command */ ulong cmdgencur; /* current command generation number */ ulong curcmd_flags; /* general purpose per-command flag */ #define XEN_MACHINE_ADDR (0x1) #define REPEAT (0x2) #define IDLE_TASK_SHOWN (0x4) #define TASK_SPECIFIED (0x8) #define MEMTYPE_UVADDR (0x10) #define MEMTYPE_FILEADDR (0x20) #define HEADER_PRINTED (0x40) #define BAD_INSTRUCTION (0x80) #define UD2A_INSTRUCTION (0x100) #define IRQ_IN_USE (0x200) #define NO_MODIFY (0x400) #define IGNORE_ERRORS (0x800) #define FROM_RCFILE (0x1000) #define MEMTYPE_KVADDR (0x2000) #define MOD_SECTIONS (0x4000) #define MOD_READNOW (0x8000) #define MM_STRUCT_FORCE (0x10000) #define CPUMASK (0x20000) #define PARTIAL_READ_OK (0x40000) ulonglong curcmd_private; /* general purpose per-command info */ int cur_gdb_cmd; /* current gdb command */ int last_gdb_cmd; /* previously-executed gdb command */ int sigint_cnt; /* number of ignored SIGINTs */ struct gnu_request *cur_req; /* current gdb gnu_request */ struct sigaction sigaction; /* general usage sigaction. */ struct sigaction gdb_sigaction; /* gdb's SIGINT sigaction. */ jmp_buf main_loop_env; /* longjmp target default */ jmp_buf foreach_loop_env; /* longjmp target within foreach */ struct termios termios_orig; /* non-raw settings */ struct termios termios_raw; /* while gathering command input */ int ncmds; /* number of commands in menu */ char **cmdlist; /* current list of available commands */ int cmdlistsz; /* space available in cmdlist */ unsigned output_radix; /* current gdb output_radix */ void *sbrk; /* current sbrk value */ struct extension_table *curext; /* extension being loaded */ int (*readmem)(int, void *, int, ulong, physaddr_t); /* memory access */ int (*writemem)(int, void *, int, ulong, physaddr_t);/* memory access */ ulong ifile_in_progress; /* original xxx_IFILE flags */ off_t ifile_offset; /* current offset into input file */ char *runtime_ifile_cmd; /* runtime command using input file */ char *kvmdump_mapfile; /* storage of physical to file offsets */ ulonglong flags2; /* flags overrun */ #define FLAT (0x01ULL) #define ELF_NOTES (0x02ULL) #define GET_OSRELEASE (0x04ULL) #define REMOTE_DAEMON (0x08ULL) #define ERASEINFO_DATA (0x10ULL) #define GDB_CMD_MODE (0x20ULL) #define LIVE_DUMP (0x40ULL) #define FLAT_FORMAT() (pc->flags2 & FLAT) #define ELF_NOTES_VALID() (pc->flags2 & ELF_NOTES) #define RADIX_OVERRIDE (0x80ULL) #define QEMU_MEM_DUMP_ELF (0x100ULL) #define GET_LOG (0x200ULL) #define VMCOREINFO (0x400ULL) #define ALLOW_FP (0x800ULL) #define REM_PAUSED_F (0x1000ULL) #define RAMDUMP (0x2000ULL) #define REMOTE_PAUSED() (pc->flags2 & REM_PAUSED_F) #define OFFLINE_HIDE (0x4000ULL) #define INCOMPLETE_DUMP (0x8000ULL) #define is_incomplete_dump() (pc->flags2 & INCOMPLETE_DUMP) #define QEMU_MEM_DUMP_COMPRESSED (0x10000ULL) #define SNAP (0x20000ULL) #define EXCLUDED_VMEMMAP (0x40000ULL) #define is_excluded_vmemmap() (pc->flags2 & EXCLUDED_VMEMMAP) #define MEMSRC_LOCAL (0x80000ULL) #define REDZONE (0x100000ULL) #define VMWARE_VMSS_GUESTDUMP (0x200000ULL) #define GET_BUILD_ID (0x400000ULL) char *cleanup; char *namelist_orig; char *namelist_debug_orig; FILE *args_ifile; /* per-command args input file */ void (*cmd_cleanup)(void *); /* per-command cleanup function */ void *cmd_cleanup_arg; /* optional cleanup function argument */ ulong scope; /* optional text context address */ ulong nr_hash_queues; /* hash queue head count */ char *(*read_vmcoreinfo)(const char *); FILE *error_fp; /* error() message direction */ char *error_path; /* stderr path information */ }; #define READMEM pc->readmem typedef void (*cmd_func_t)(void); struct command_table_entry { /* one for each command in menu */ char *name; cmd_func_t func; char **help_data; ulong flags; }; struct args_input_file { int index; int args_used; int is_gdb_cmd; int in_expression; int start; int resume; char *fileptr; }; #define REFRESH_TASK_TABLE (0x1) /* command_table_entry flags */ #define HIDDEN_COMMAND (0x2) #define CLEANUP (0x4) /* for extensions only */ #define MINIMAL (0x8) /* * A linked list of extension table structures keeps track of the current * set of shared library extensions. */ struct extension_table { void *handle; /* handle from dlopen() */ char *filename; /* name of shared library */ struct command_table_entry *command_table; /* list of commands */ ulong flags; /* registration flags */ struct extension_table *next, *prev; /* bookkeeping */ }; #define REGISTERED (0x1) /* extension_table flags */ #define DUPLICATE_COMMAND_NAME (0x2) #define NO_MINIMAL_COMMANDS (0x4) struct new_utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char domainname[65]; }; #define NO_MODULE_ACCESS (0x1) #define TVEC_BASES_V1 (0x2) #define GCC_3_2 (0x4) #define GCC_3_2_3 (0x8) #define GCC_2_96 (0x10) #define RA_SEEK (0x20) #define NO_RA_SEEK (0x40) #define KALLSYMS_V1 (0x80) #define NO_KALLSYMS (0x100) #define PER_CPU_OFF (0x200) #define SMP (0x400) #define GCC_3_3_2 (0x800) #define KMOD_V1 (0x1000) #define KMOD_V2 (0x2000) #define KALLSYMS_V2 (0x2000) #define TVEC_BASES_V2 (0x4000) #define GCC_3_3_3 (0x8000) #define USE_OLD_BT (0x10000) #define USE_OPT_BT (0x10000) #define ARCH_XEN (0x20000) #define NO_IKCONFIG (0x40000) #define DWARF_UNWIND (0x80000) #define NO_DWARF_UNWIND (0x100000) #define DWARF_UNWIND_MEMORY (0x200000) #define DWARF_UNWIND_EH_FRAME (0x400000) #define DWARF_UNWIND_CAPABLE (DWARF_UNWIND_MEMORY|DWARF_UNWIND_EH_FRAME) #define DWARF_UNWIND_MODULES (0x800000) #define BUGVERBOSE_OFF (0x1000000) #define RELOC_SET (0x2000000) #define RELOC_FORCE (0x4000000) #define ARCH_OPENVZ (0x8000000) #define ARCH_PVOPS (0x10000000) #define PRE_KERNEL_INIT (0x20000000) #define ARCH_PVOPS_XEN (0x40000000) #define GCC_VERSION_DEPRECATED (GCC_3_2|GCC_3_2_3|GCC_2_96|GCC_3_3_2|GCC_3_3_3) /* flags2 */ #define RELOC_AUTO (0x1ULL) #define KASLR (0x2ULL) #define KASLR_CHECK (0x4ULL) #define GET_TIMESTAMP (0x8ULL) #define TVEC_BASES_V3 (0x10ULL) #define TIMER_BASES (0x20ULL) #define IRQ_DESC_TREE_RADIX (0x40ULL) #define IRQ_DESC_TREE_XARRAY (0x80ULL) #define KMOD_PAX (0x100ULL) #define KMOD_MEMORY (0x200ULL) #define IRQ_DESC_TREE_MAPLE (0x400ULL) #define XEN() (kt->flags & ARCH_XEN) #define OPENVZ() (kt->flags & ARCH_OPENVZ) #define PVOPS() (kt->flags & ARCH_PVOPS) #define PVOPS_XEN() (kt->flags & ARCH_PVOPS_XEN) #define PAX_MODULE_SPLIT() (kt->flags2 & KMOD_PAX) #define MODULE_MEMORY() (kt->flags2 & KMOD_MEMORY) #define XEN_MACHINE_TO_MFN(m) ((ulonglong)(m) >> PAGESHIFT()) #define XEN_PFN_TO_PSEUDO(p) ((ulonglong)(p) << PAGESHIFT()) #define XEN_MFN_NOT_FOUND (~0UL) #define XEN_PFNS_PER_PAGE (PAGESIZE()/sizeof(ulong)) #define XEN_FOREIGN_FRAME (1UL << (BITS()-1)) #define XEN_MACHADDR_NOT_FOUND (~0ULL) #define XEN_P2M_PER_PAGE (PAGESIZE() / sizeof(unsigned long)) #define XEN_P2M_MID_PER_PAGE (PAGESIZE() / sizeof(unsigned long *)) #define XEN_P2M_TOP_PER_PAGE (PAGESIZE() / sizeof(unsigned long **)) struct kernel_table { /* kernel data */ ulong flags; ulong stext; ulong etext; ulong stext_init; ulong etext_init; ulong init_begin; ulong init_end; ulong end; int cpus; char *cpus_override; void (*display_bh)(void); ulong module_list; ulong kernel_module; int mods_installed; struct timespec date; char proc_version[BUFSIZE]; struct new_utsname utsname; uint kernel_version[3]; uint gcc_version[3]; int runq_siblings; int kernel_NR_CPUS; long __per_cpu_offset[NR_CPUS]; long *__rq_idx; long *__cpu_idx; ulong *cpu_flags; #define POSSIBLE (0x1) #define PRESENT (0x2) #define ONLINE (0x4) #define NMI (0x8) #define POSSIBLE_MAP (POSSIBLE) #define PRESENT_MAP (PRESENT) #define ONLINE_MAP (ONLINE) #define ACTIVE_MAP (0x10) int BUG_bytes; ulong xen_flags; #define WRITABLE_PAGE_TABLES (0x1) #define SHADOW_PAGE_TABLES (0x2) #define CANONICAL_PAGE_TABLES (0x4) #define XEN_SUSPEND (0x8) char *m2p_page; ulong phys_to_machine_mapping; ulong p2m_table_size; #define P2M_MAPPING_CACHE (512) struct p2m_mapping_cache { ulong mapping; ulong pfn; ulong start; ulong end; } p2m_mapping_cache[P2M_MAPPING_CACHE]; #define P2M_MAPPING_PAGE_PFN(c) \ (PVOPS_XEN() ? kt->p2m_mapping_cache[c].pfn : \ (((kt->p2m_mapping_cache[c].mapping - kt->phys_to_machine_mapping)/PAGESIZE()) \ * XEN_PFNS_PER_PAGE)) ulong last_mapping_read; ulong p2m_cache_index; ulong p2m_pages_searched; ulong p2m_mfn_cache_hits; ulong p2m_page_cache_hits; ulong relocate; char *module_tree; struct pvops_xen_info { int p2m_top_entries; ulong p2m_top; ulong p2m_mid_missing; ulong p2m_missing; } pvops_xen; int highest_irq; #define IKCONFIG_AVAIL 0x1 /* kernel contains ikconfig data */ #define IKCONFIG_LOADED 0x2 /* ikconfig data is currently loaded */ int ikconfig_flags; int ikconfig_ents; char *hypervisor; struct vmcoreinfo_data { ulong log_buf_SYMBOL; ulong log_end_SYMBOL; ulong log_buf_len_SYMBOL; ulong logged_chars_SYMBOL; ulong log_first_idx_SYMBOL; ulong log_next_idx_SYMBOL; long log_SIZE; long log_ts_nsec_OFFSET; long log_len_OFFSET; long log_text_len_OFFSET; long log_dict_len_OFFSET; ulong phys_base_SYMBOL; ulong _stext_SYMBOL; } vmcoreinfo; ulonglong flags2; char *source_tree; struct timespec boot_date; }; /* * Aid for the two versions of the kernel's module list linkage. */ #define NEXT_MODULE(next_module, modbuf) \ { \ switch (kt->flags & (KMOD_V1|KMOD_V2)) \ { \ case KMOD_V1: \ next_module = ULONG(modbuf + OFFSET(module_next)); \ break; \ case KMOD_V2: \ next_module = ULONG(modbuf + OFFSET(module_list)); \ if (next_module != kt->kernel_module) \ next_module -= OFFSET(module_list); \ break; \ } \ } #define THIS_KERNEL_VERSION ((kt->kernel_version[0] << 24) + \ (kt->kernel_version[1] << 16) + \ (kt->kernel_version[2])) #define LINUX(x,y,z) (((uint)(x) << 24) + ((uint)(y) << 16) + (uint)(z)) #define THIS_GCC_VERSION ((kt->gcc_version[0] << 16) + \ (kt->gcc_version[1] << 8) + \ (kt->gcc_version[2])) #define GCC(x,y,z) (((uint)(x) << 16) + ((uint)(y) << 8) + (uint)(z)) #define IS_KERNEL_STATIC_TEXT(x) (((ulong)(x) >= kt->stext) && \ ((ulong)(x) < kt->etext)) #define TASK_COMM_LEN 16 /* task command name length including NULL */ struct task_context { /* context stored for each task */ ulong task; ulong thread_info; ulong pid; char comm[TASK_COMM_LEN+1]; int processor; ulong ptask; ulong mm_struct; struct task_context *tc_next; }; struct tgid_context { /* tgid and task stored for each task */ ulong tgid; ulong task; long rss_cache; }; struct task_table { /* kernel/local task table data */ struct task_context *current; struct task_context *context_array; void (*refresh_task_table)(void); ulong flags; ulong task_start; ulong task_end; void *task_local; int max_tasks; int nr_threads; ulong running_tasks; ulong retries; ulong panicmsg; int panic_processor; ulong *idle_threads; ulong *panic_threads; ulong *active_set; ulong *panic_ksp; ulong *hardirq_ctx; ulong *hardirq_tasks; ulong *softirq_ctx; ulong *softirq_tasks; ulong panic_task; ulong this_task; int pidhash_len; ulong pidhash_addr; ulong last_task_read; ulong last_thread_info_read; ulong last_mm_read; char *task_struct; char *thread_info; char *mm_struct; ulong init_pid_ns; struct tgid_context *tgid_array; struct tgid_context *last_tgid; ulong tgid_searches; ulong tgid_cache_hits; long filepages; long anonpages; ulong stack_end_magic; ulong pf_kthread; ulong pid_radix_tree; int callbacks; struct task_context **context_by_task; /* task_context sorted by task addr */ ulong pid_xarray; long shmempages; }; #define TASK_INIT_DONE (0x1) #define TASK_ARRAY_EXISTS (0x2) #define PANIC_TASK_NOT_FOUND (0x4) #define TASK_REFRESH (0x8) #define TASK_REFRESH_OFF (0x10) #define PANIC_KSP (0x20) #define ACTIVE_SET (0x40) #define POPULATE_PANIC (0x80) #define PIDHASH (0x100) #define PID_HASH (0x200) #define THREAD_INFO (0x400) #define IRQSTACKS (0x800) #define TIMESPEC (0x1000) #define NO_TIMESPEC (0x2000) #define ACTIVE_ONLY (0x4000) #define START_TIME_NSECS (0x8000) #define THREAD_INFO_IN_TASK (0x10000) #define PID_RADIX_TREE (0x20000) #define INDEXED_CONTEXTS (0x40000) #define PID_XARRAY (0x80000) #define TASK_SLUSH (20) #define NO_PROC_ID 0xFF /* No processor magic marker (from kernel) */ /* * Global "tt" points to task_table */ #define CURRENT_CONTEXT() (tt->current) #define CURRENT_TASK() (tt->current->task) #define CURRENT_PID() (tt->current->pid) #define CURRENT_COMM() (tt->current->comm) #define RUNNING_TASKS() (tt->running_tasks) #define FIRST_CONTEXT() (tt->context_array) #define NO_PID ((ulong)-1) #define NO_TASK (0) #define IS_TASK_ADDR(X) (machdep->is_task_addr(X)) #define GET_STACKBASE(X) (machdep->get_stackbase(X)) #define GET_STACKTOP(X) (machdep->get_stacktop(X)) #define STACKSIZE() (machdep->stacksize) #define LONGS_PER_STACK (machdep->stacksize/sizeof(ulong)) #define INSTACK(X,BT) \ (((ulong)(X) >= (BT)->stackbase) && ((ulong)(X) < (BT)->stacktop)) #define ALIGNED_STACK_OFFSET(task) ((ulong)(task) & (STACKSIZE()-1)) #define BITS() (machdep->bits) #define BITS32() (machdep->bits == 32) #define BITS64() (machdep->bits == 64) #define IS_KVADDR(X) (machdep->is_kvaddr(X)) #define IS_UVADDR(X,C) (machdep->is_uvaddr(X,C)) #define PID_ALIVE(x) (kill(x, 0) == 0) struct kernel_list_head { struct kernel_list_head *next, *prev; }; struct stack_hook { ulong esp; ulong eip; }; struct bt_info { ulong task; ulonglong flags; ulong instptr; ulong stkptr; ulong bptr; ulong stackbase; ulong stacktop; char *stackbuf; struct task_context *tc; struct stack_hook *hp; struct stack_hook *textlist; struct reference *ref; ulong frameptr; char *call_target; void *machdep; ulong debug; ulong eframe_ip; ulong radix; ulong *cpumask; bool need_free; }; #define STACK_OFFSET_TYPE(OFF) \ (((ulong)(OFF) > STACKSIZE()) ? \ (ulong)((ulong)(OFF) - (ulong)(bt->stackbase)) : (ulong)(OFF)) #define GET_STACK_ULONG(OFF) \ *((ulong *)((char *)(&bt->stackbuf[(ulong)(STACK_OFFSET_TYPE(OFF))]))) #define GET_STACK_DATA(OFF, LOC, SZ) memcpy((void *)(LOC), \ (void *)(&bt->stackbuf[(ulong)STACK_OFFSET_TYPE(OFF)]), (size_t)(SZ)) struct machine_specific; /* uniquely defined below each machine's area */ struct xendump_data; struct xen_kdump_data; struct vaddr_range { ulong start; ulong end; ulong type; #define KVADDR_UNITY_MAP (1) #define KVADDR_VMALLOC (2) #define KVADDR_VMEMMAP (3) #define KVADDR_START_MAP (4) #define KVADDR_MODULES (5) #define MAX_KVADDR_RANGES KVADDR_MODULES }; #define MAX_MACHDEP_ARGS 5 /* for --machdep/-m machine-specific args */ struct machdep_table { ulong flags; ulong kvbase; ulong identity_map_base; uint pagesize; uint pageshift; ulonglong pagemask; ulong pageoffset; ulong stacksize; uint hz; ulong mhz; int bits; int nr_irqs; uint64_t memsize; int (*eframe_search)(struct bt_info *); void (*back_trace)(struct bt_info *); ulong (*processor_speed)(void); int (*uvtop)(struct task_context *, ulong, physaddr_t *, int); int (*kvtop)(struct task_context *, ulong, physaddr_t *, int); ulong (*get_task_pgd)(ulong); void (*dump_irq)(int); void (*get_stack_frame)(struct bt_info *, ulong *, ulong *); ulong (*get_stackbase)(ulong); ulong (*get_stacktop)(ulong); int (*translate_pte)(ulong, void *, ulonglong); uint64_t (*memory_size)(void); ulong (*vmalloc_start)(void); int (*is_task_addr)(ulong); int (*verify_symbol)(const char *, ulong, char); int (*dis_filter)(ulong, char *, unsigned int); int (*get_smp_cpus)(void); int (*is_kvaddr)(ulong); int (*is_uvaddr)(ulong, struct task_context *); int (*verify_paddr)(uint64_t); void (*cmd_mach)(void); void (*init_kernel_pgd)(void); struct syment *(*value_to_symbol)(ulong, ulong *); struct line_number_hook { char *func; char **file; } *line_number_hooks; ulong last_pgd_read; ulong last_pud_read; ulong last_pmd_read; ulong last_ptbl_read; char *pgd; char *pud; char *pmd; char *ptbl; int ptrs_per_pgd; char *cmdline_args[MAX_MACHDEP_ARGS]; struct machine_specific *machspec; ulong section_size_bits; ulong max_physmem_bits; ulong sections_per_root; int (*xendump_p2m_create)(struct xendump_data *); ulong (*xendump_panic_task)(struct xendump_data *); void (*get_xendump_regs)(struct xendump_data *, struct bt_info *, ulong *, ulong *); void (*clear_machdep_cache)(void); int (*xen_kdump_p2m_create)(struct xen_kdump_data *); int (*in_alternate_stack)(int, ulong); void (*dumpfile_init)(int, void *); void (*process_elf_notes)(void *, unsigned long); int (*get_kvaddr_ranges)(struct vaddr_range *); int (*verify_line_number)(ulong, ulong, ulong); void (*get_irq_affinity)(int); void (*show_interrupts)(int, ulong *); int (*is_page_ptr)(ulong, physaddr_t *); int (*get_current_task_reg)(int, const char *, int, void *, int); int (*is_cpu_prstatus_valid)(int cpu); }; /* * Processor-common flags; processor-specific flags use the lower bits * as defined in their processor-specific files below. (see KSYMS_START defs). */ #define HWRESET (0x80000000) #define OMIT_FRAME_PTR (0x40000000) #define FRAMESIZE_DEBUG (0x20000000) #define MACHDEP_BT_TEXT (0x10000000) #define DEVMEMRD (0x8000000) #define INIT (0x4000000) #define VM_4_LEVEL (0x2000000) #define MCA (0x1000000) #define PAE (0x800000) #define VMEMMAP (0x400000) extern struct machdep_table *machdep; #ifndef HZ #define HZ sysconf(_SC_CLK_TCK) #endif #define IS_LAST_PGD_READ(pgd) ((ulong)(pgd) == machdep->last_pgd_read) #define IS_LAST_PMD_READ(pmd) ((ulong)(pmd) == machdep->last_pmd_read) #define IS_LAST_PTBL_READ(ptbl) ((ulong)(ptbl) == machdep->last_ptbl_read) #define IS_LAST_PUD_READ(pud) ((ulong)(pud) == machdep->last_pud_read) #define FILL_PGD(PGD, TYPE, SIZE) \ if (!IS_LAST_PGD_READ(PGD)) { \ readmem((ulonglong)((ulong)(PGD)), TYPE, machdep->pgd, \ SIZE, "pgd page", FAULT_ON_ERROR); \ machdep->last_pgd_read = (ulong)(PGD); \ } #define FILL_PUD(PUD, TYPE, SIZE) \ if (!IS_LAST_PUD_READ(PUD)) { \ readmem((ulonglong)((ulong)(PUD)), TYPE, machdep->pud, \ SIZE, "pud page", FAULT_ON_ERROR); \ machdep->last_pud_read = (ulong)(PUD); \ } #define FILL_PMD(PMD, TYPE, SIZE) \ if (!IS_LAST_PMD_READ(PMD)) { \ readmem((ulonglong)(PMD), TYPE, machdep->pmd, \ SIZE, "pmd page", FAULT_ON_ERROR); \ machdep->last_pmd_read = (ulong)(PMD); \ } #define FILL_PTBL(PTBL, TYPE, SIZE) \ if (!IS_LAST_PTBL_READ(PTBL)) { \ readmem((ulonglong)(PTBL), TYPE, machdep->ptbl, \ SIZE, "page table", FAULT_ON_ERROR); \ machdep->last_ptbl_read = (ulong)(PTBL); \ } #define SETUP_ENV (0) #define PRE_SYMTAB (1) #define PRE_GDB (2) #define POST_GDB (3) #define POST_INIT (4) #define POST_VM (5) #define LOG_ONLY (6) #define POST_RELOC (7) #define FOREACH_BT (1) #define FOREACH_VM (2) #define FOREACH_TASK (3) #define FOREACH_SET (4) #define FOREACH_FILES (5) #define FOREACH_NET (6) #define FOREACH_TEST (7) #define FOREACH_VTOP (8) #define FOREACH_SIG (9) #define FOREACH_PS (10) #define MAX_FOREACH_KEYWORDS (10) #define MAX_FOREACH_TASKS (50) #define MAX_FOREACH_PIDS (50) #define MAX_FOREACH_COMMS (50) #define MAX_FOREACH_ARGS (50) #define MAX_REGEX_ARGS (10) #define FOREACH_CMD (0x1) #define FOREACH_r_FLAG (0x2) #define FOREACH_s_FLAG (0x4) #define FOREACH_S_FLAG (0x8) #define FOREACH_i_FLAG (0x10) #define FOREACH_e_FLAG (0x20) #define FOREACH_g_FLAG (0x40) #define FOREACH_l_FLAG (0x80) #define FOREACH_p_FLAG (0x100) #define FOREACH_t_FLAG (0x200) #define FOREACH_u_FLAG (0x400) #define FOREACH_m_FLAG (0x800) #define FOREACH_v_FLAG (0x1000) #define FOREACH_KERNEL (0x2000) #define FOREACH_USER (0x4000) #define FOREACH_SPECIFIED (0x8000) #define FOREACH_ACTIVE (0x10000) #define FOREACH_k_FLAG (0x20000) #define FOREACH_c_FLAG (0x40000) #define FOREACH_f_FLAG (0x80000) #define FOREACH_o_FLAG (0x100000) #define FOREACH_T_FLAG (0x200000) #define FOREACH_F_FLAG (0x400000) #define FOREACH_x_FLAG (0x800000) #define FOREACH_d_FLAG (0x1000000) #define FOREACH_STATE (0x2000000) #define FOREACH_a_FLAG (0x4000000) #define FOREACH_G_FLAG (0x8000000) #define FOREACH_F_FLAG2 (0x10000000) #define FOREACH_y_FLAG (0x20000000) #define FOREACH_GLEADER (0x40000000) #define FOREACH_PS_EXCLUSIVE \ (FOREACH_g_FLAG|FOREACH_a_FLAG|FOREACH_t_FLAG|FOREACH_c_FLAG|FOREACH_p_FLAG|FOREACH_l_FLAG|FOREACH_r_FLAG|FOREACH_m_FLAG) struct foreach_data { ulong flags; int keyword_array[MAX_FOREACH_KEYWORDS]; ulong task_array[MAX_FOREACH_TASKS]; char *comm_array[MAX_FOREACH_COMMS]; ulong pid_array[MAX_FOREACH_PIDS]; ulong arg_array[MAX_FOREACH_ARGS]; struct regex_info { char *pattern; regex_t regex; } regex_info[MAX_REGEX_ARGS]; const char *state; char *reference; int keys; int pids; int tasks; int comms; int args; int regexs; int policy; }; struct reference { char *str; ulong cmdflags; ulong hexval; ulong decval; ulong ref1; ulong ref2; void *refp; }; struct offset_table { /* stash of commonly-used offsets */ long list_head_next; /* add new entries to end of table */ long list_head_prev; long task_struct_pid; long task_struct_state; long task_struct_comm; long task_struct_mm; long task_struct_tss; long task_struct_thread; long task_struct_active_mm; long task_struct_tss_eip; long task_struct_tss_esp; long task_struct_tss_ksp; long task_struct_processor; long task_struct_p_pptr; long task_struct_parent; long task_struct_has_cpu; long task_struct_cpus_runnable; long task_struct_thread_eip; long task_struct_thread_esp; long task_struct_thread_ksp; long task_struct_next_task; long task_struct_files; long task_struct_fs; long task_struct_pidhash_next; long task_struct_next_run; long task_struct_flags; long task_struct_sig; long task_struct_signal; long task_struct_blocked; long task_struct_sigpending; long task_struct_pending; long task_struct_sigqueue; long task_struct_sighand; long task_struct_start_time; long task_struct_times; long task_struct_utime; long task_struct_stime; long task_struct_cpu; long task_struct_run_list; long task_struct_pgrp; long task_struct_tgid; long task_struct_namespace; long task_struct_pids; long task_struct_last_run; long task_struct_timestamp; long task_struct_thread_info; long task_struct_nsproxy; long task_struct_rlim; long thread_info_task; long thread_info_cpu; long thread_info_previous_esp; long thread_info_flags; long nsproxy_mnt_ns; long mnt_namespace_root; long mnt_namespace_list; long pid_link_pid; long pid_hash_chain; long hlist_node_next; long hlist_node_pprev; long pid_pid_chain; long thread_struct_eip; long thread_struct_esp; long thread_struct_ksp; long thread_struct_fph; long thread_struct_rip; long thread_struct_rsp; long thread_struct_rsp0; long tms_tms_utime; long tms_tms_stime; long signal_struct_count; long signal_struct_action; long signal_struct_shared_pending; long signal_struct_rlim; long k_sigaction_sa; long sigaction_sa_handler; long sigaction_sa_flags; long sigaction_sa_mask; long sigpending_head; long sigpending_list; long sigpending_signal; long signal_queue_next; long signal_queue_info; long sigqueue_next; long sigqueue_list; long sigqueue_info; long sighand_struct_action; long siginfo_si_signo; long thread_struct_cr3; long thread_struct_ptbr; long thread_struct_pg_tables; long switch_stack_r26; long switch_stack_b0; long switch_stack_ar_bspstore; long switch_stack_ar_pfs; long switch_stack_ar_rnat; long switch_stack_pr; long cpuinfo_ia64_proc_freq; long cpuinfo_ia64_unimpl_va_mask; long cpuinfo_ia64_unimpl_pa_mask; long device_node_type; long device_node_allnext; long device_node_properties; long property_name; long property_value; long property_next; long machdep_calls_setup_residual; long RESIDUAL_VitalProductData; long VPD_ProcessorHz; long bd_info_bi_intfreq; long hwrpb_struct_cycle_freq; long hwrpb_struct_processor_offset; long hwrpb_struct_processor_size; long percpu_struct_halt_PC; long percpu_struct_halt_ra; long percpu_struct_halt_pv; long mm_struct_mmap; long mm_struct_pgd; long mm_struct_rss; long mm_struct_anon_rss; long mm_struct_file_rss; long mm_struct_total_vm; long mm_struct_start_code; long mm_struct_arg_start; long mm_struct_arg_end; long mm_struct_env_start; long mm_struct_env_end; long vm_area_struct_vm_mm; long vm_area_struct_vm_next; long vm_area_struct_vm_end; long vm_area_struct_vm_start; long vm_area_struct_vm_flags; long vm_area_struct_vm_file; long vm_area_struct_vm_offset; long vm_area_struct_vm_pgoff; long vm_struct_addr; long vm_struct_size; long vm_struct_next; long module_size_of_struct; long module_next; long module_size; long module_name; long module_nsyms; long module_syms; long module_flags; long module_num_syms; long module_list; long module_gpl_syms; long module_num_gpl_syms; long module_module_core; long module_core_size; long module_core_text_size; long module_num_symtab; long module_symtab; long module_strtab; long module_kallsyms_start; long kallsyms_header_sections; long kallsyms_header_section_off; long kallsyms_header_symbols; long kallsyms_header_symbol_off; long kallsyms_header_string_off; long kallsyms_symbol_section_off; long kallsyms_symbol_symbol_addr; long kallsyms_symbol_name_off; long kallsyms_section_start; long kallsyms_section_size; long kallsyms_section_name_off; long page_next; long page_prev; long page_next_hash; long page_list; long page_list_next; long page_list_prev; long page_inode; long page_offset; long page_count; long page_flags; long page_mapping; long page_index; long page_buffers; long page_lru; long page_pte; long swap_info_struct_swap_file; long swap_info_struct_swap_vfsmnt; long swap_info_struct_flags; long swap_info_struct_swap_map; long swap_info_struct_swap_device; long swap_info_struct_prio; long swap_info_struct_max; long swap_info_struct_pages; long swap_info_struct_old_block_size; long block_device_bd_inode; long block_device_bd_list; long block_device_bd_disk; long irq_desc_t_status; long irq_desc_t_handler; long irq_desc_t_chip; long irq_desc_t_action; long irq_desc_t_depth; long irqdesc_action; long irqdesc_ctl; long irqdesc_level; long irqaction_handler; long irqaction_flags; long irqaction_mask; long irqaction_name; long irqaction_dev_id; long irqaction_next; long hw_interrupt_type_typename; long hw_interrupt_type_startup; long hw_interrupt_type_shutdown; long hw_interrupt_type_handle; long hw_interrupt_type_enable; long hw_interrupt_type_disable; long hw_interrupt_type_ack; long hw_interrupt_type_end; long hw_interrupt_type_set_affinity; long irq_chip_typename; long irq_chip_startup; long irq_chip_shutdown; long irq_chip_enable; long irq_chip_disable; long irq_chip_ack; long irq_chip_end; long irq_chip_set_affinity; long irq_chip_mask; long irq_chip_mask_ack; long irq_chip_unmask; long irq_chip_eoi; long irq_chip_retrigger; long irq_chip_set_type; long irq_chip_set_wake; long irq_cpustat_t___softirq_active; long irq_cpustat_t___softirq_mask; long fdtable_max_fds; long fdtable_max_fdset; long fdtable_open_fds; long fdtable_fd; long files_struct_fdt; long files_struct_max_fds; long files_struct_max_fdset; long files_struct_open_fds; long files_struct_fd; long files_struct_open_fds_init; long file_f_dentry; long file_f_vfsmnt; long file_f_count; long file_f_path; long path_mnt; long path_dentry; long fs_struct_root; long fs_struct_pwd; long fs_struct_rootmnt; long fs_struct_pwdmnt; long dentry_d_inode; long dentry_d_parent; long dentry_d_name; long dentry_d_covers; long dentry_d_iname; long qstr_len; long qstr_name; long inode_i_mode; long inode_i_op; long inode_i_sb; long inode_u; long inode_i_flock; long inode_i_fop; long inode_i_mapping; long address_space_nrpages; long vfsmount_mnt_next; long vfsmount_mnt_devname; long vfsmount_mnt_dirname; long vfsmount_mnt_sb; long vfsmount_mnt_list; long vfsmount_mnt_mountpoint; long vfsmount_mnt_parent; long namespace_root; long namespace_list; long super_block_s_dirty; long super_block_s_type; long super_block_s_files; long file_system_type_name; long nlm_file_f_file; long file_lock_fl_owner; long nlm_host_h_exportent; long svc_client_cl_ident; long kmem_cache_s_c_nextp; long kmem_cache_s_c_name; long kmem_cache_s_c_num; long kmem_cache_s_c_org_size; long kmem_cache_s_c_flags; long kmem_cache_s_c_offset; long kmem_cache_s_c_firstp; long kmem_cache_s_c_gfporder; long kmem_cache_s_c_magic; long kmem_cache_s_num; long kmem_cache_s_next; long kmem_cache_s_name; long kmem_cache_s_objsize; long kmem_cache_s_flags; long kmem_cache_s_gfporder; long kmem_cache_s_slabs; long kmem_cache_s_slabs_full; long kmem_cache_s_slabs_partial; long kmem_cache_s_slabs_free; long kmem_cache_s_cpudata; long kmem_cache_s_c_align; long kmem_cache_s_colour_off; long cpucache_s_avail; long cpucache_s_limit; long kmem_cache_s_array; long array_cache_avail; long array_cache_limit; long kmem_cache_s_lists; long kmem_list3_slabs_partial; long kmem_list3_slabs_full; long kmem_list3_slabs_free; long kmem_list3_free_objects; long kmem_list3_shared; long kmem_slab_s_s_nextp; long kmem_slab_s_s_freep; long kmem_slab_s_s_inuse; long kmem_slab_s_s_mem; long kmem_slab_s_s_index; long kmem_slab_s_s_offset; long kmem_slab_s_s_magic; long slab_s_list; long slab_s_s_mem; long slab_s_inuse; long slab_s_free; long slab_list; long slab_s_mem; long slab_inuse; long slab_free; long net_device_next; long net_device_name; long net_device_type; long net_device_addr_len; long net_device_ip_ptr; long net_device_dev_list; long net_dev_base_head; long device_next; long device_name; long device_type; long device_ip_ptr; long device_addr_len; long socket_sk; long sock_daddr; long sock_rcv_saddr; long sock_dport; long sock_sport; long sock_num; long sock_type; long sock_family; long sock_common_skc_family; long sock_sk_type; long inet_sock_inet; long inet_opt_daddr; long inet_opt_rcv_saddr; long inet_opt_dport; long inet_opt_sport; long inet_opt_num; long ipv6_pinfo_rcv_saddr; long ipv6_pinfo_daddr; long timer_list_list; long timer_list_next; long timer_list_entry; long timer_list_expires; long timer_list_function; long timer_vec_root_vec; long timer_vec_vec; long tvec_root_s_vec; long tvec_s_vec; long tvec_t_base_s_tv1; long wait_queue_task; long wait_queue_next; long __wait_queue_task; long __wait_queue_head_task_list; long __wait_queue_task_list; long pglist_data_node_zones; long pglist_data_node_mem_map; long pglist_data_node_start_paddr; long pglist_data_node_start_mapnr; long pglist_data_node_size; long pglist_data_node_id; long pglist_data_node_next; long pglist_data_nr_zones; long pglist_data_node_start_pfn; long pglist_data_pgdat_next; long pglist_data_node_present_pages; long pglist_data_node_spanned_pages; long pglist_data_bdata; long page_cache_bucket_chain; long zone_struct_free_pages; long zone_struct_free_area; long zone_struct_zone_pgdat; long zone_struct_name; long zone_struct_size; long zone_struct_memsize; long zone_struct_zone_start_pfn; long zone_struct_zone_start_paddr; long zone_struct_zone_start_mapnr; long zone_struct_zone_mem_map; long zone_struct_inactive_clean_pages; long zone_struct_inactive_clean_list; long zone_struct_inactive_dirty_pages; long zone_struct_active_pages; long zone_struct_pages_min; long zone_struct_pages_low; long zone_struct_pages_high; long zone_free_pages; long zone_free_area; long zone_zone_pgdat; long zone_zone_mem_map; long zone_name; long zone_spanned_pages; long zone_zone_start_pfn; long zone_pages_min; long zone_pages_low; long zone_pages_high; long zone_vm_stat; long neighbour_next; long neighbour_primary_key; long neighbour_ha; long neighbour_dev; long neighbour_nud_state; long neigh_table_hash_buckets; long neigh_table_key_len; long in_device_ifa_list; long in_ifaddr_ifa_next; long in_ifaddr_ifa_address; long pci_dev_global_list; long pci_dev_next; long pci_dev_bus; long pci_dev_devfn; long pci_dev_class; long pci_dev_device; long pci_dev_vendor; long pci_bus_number; long resource_entry_t_from; long resource_entry_t_num; long resource_entry_t_name; long resource_entry_t_next; long resource_name; long resource_start; long resource_end; long resource_sibling; long resource_child; long runqueue_curr; long runqueue_idle; long runqueue_active; long runqueue_expired; long runqueue_arrays; long runqueue_cpu; long cpu_s_idle; long cpu_s_curr; long prio_array_nr_active; long prio_array_queue; long user_regs_struct_ebp; long user_regs_struct_esp; long user_regs_struct_rip; long user_regs_struct_cs; long user_regs_struct_eflags; long user_regs_struct_rsp; long user_regs_struct_ss; long e820map_nr_map; long e820entry_addr; long e820entry_size; long e820entry_type; long char_device_struct_next; long char_device_struct_name; long char_device_struct_fops; long char_device_struct_major; long gendisk_major; long gendisk_disk_name; long gendisk_fops; long blk_major_name_next; long blk_major_name_major; long blk_major_name_name; long radix_tree_root_height; long radix_tree_root_rnode; long x8664_pda_pcurrent; long x8664_pda_data_offset; long x8664_pda_kernelstack; long x8664_pda_irqrsp; long x8664_pda_irqstackptr; long x8664_pda_level4_pgt; long x8664_pda_cpunumber; long x8664_pda_me; long tss_struct_ist; long mem_section_section_mem_map; long vcpu_guest_context_user_regs; long cpu_user_regs_eip; long cpu_user_regs_esp; long cpu_user_regs_rip; long cpu_user_regs_rsp; long unwind_table_core; long unwind_table_init; long unwind_table_address; long unwind_table_size; long unwind_table_link; long unwind_table_name; long rq_cfs; long rq_rt; long rq_nr_running; long cfs_rq_rb_leftmost; long cfs_rq_nr_running; long cfs_rq_tasks_timeline; long task_struct_se; long sched_entity_run_node; long rt_rq_active; long kmem_cache_size; long kmem_cache_objsize; long kmem_cache_offset; long kmem_cache_order; long kmem_cache_local_node; long kmem_cache_objects; long kmem_cache_inuse; long kmem_cache_align; long kmem_cache_name; long kmem_cache_list; long kmem_cache_node; long kmem_cache_cpu_slab; long page_inuse; /* long page_offset; use "old" page->offset */ long page_slab; long page_first_page; long page_freelist; long kmem_cache_node_nr_partial; long kmem_cache_node_nr_slabs; long kmem_cache_node_partial; long kmem_cache_node_full; long pid_numbers; long upid_nr; long upid_ns; long upid_pid_chain; long pid_tasks; long kmem_cache_cpu_freelist; long kmem_cache_cpu_page; long kmem_cache_cpu_node; long kmem_cache_flags; long zone_nr_active; long zone_nr_inactive; long zone_all_unreclaimable; long zone_present_pages; long zone_flags; long zone_pages_scanned; long pcpu_info_vcpu; long pcpu_info_idle; long vcpu_struct_rq; long task_struct_sched_info; long sched_info_last_arrival; long page_objects; long kmem_cache_oo; long char_device_struct_cdev; long char_device_struct_baseminor; long cdev_ops; long probe_next; long probe_dev; long probe_data; long kobj_map_probes; long task_struct_prio; long zone_watermark; long module_sect_attrs; long module_sect_attrs_attrs; long module_sect_attrs_nsections; long module_sect_attr_mattr; long module_sect_attr_name; long module_sect_attr_address; long module_attribute_attr; long attribute_owner; long module_sect_attr_attr; long module_sections_attrs; long swap_info_struct_inuse_pages; long s390_lowcore_psw_save_area; long mm_struct_rss_stat; long mm_rss_stat_count; long module_module_init; long module_init_text_size; long cpu_context_save_fp; long cpu_context_save_sp; long cpu_context_save_pc; long elf_prstatus_pr_pid; long elf_prstatus_pr_reg; long irq_desc_t_name; long thread_info_cpu_context; long unwind_table_list; long unwind_table_start; long unwind_table_stop; long unwind_table_begin_addr; long unwind_table_end_addr; long unwind_idx_addr; long unwind_idx_insn; long signal_struct_nr_threads; long module_init_size; long module_percpu; long radix_tree_node_slots; long s390_stack_frame_back_chain; long s390_stack_frame_r14; long user_regs_struct_eip; long user_regs_struct_rax; long user_regs_struct_eax; long user_regs_struct_rbx; long user_regs_struct_ebx; long user_regs_struct_rcx; long user_regs_struct_ecx; long user_regs_struct_rdx; long user_regs_struct_edx; long user_regs_struct_rsi; long user_regs_struct_esi; long user_regs_struct_rdi; long user_regs_struct_edi; long user_regs_struct_ds; long user_regs_struct_es; long user_regs_struct_fs; long user_regs_struct_gs; long user_regs_struct_rbp; long user_regs_struct_r8; long user_regs_struct_r9; long user_regs_struct_r10; long user_regs_struct_r11; long user_regs_struct_r12; long user_regs_struct_r13; long user_regs_struct_r14; long user_regs_struct_r15; long sched_entity_cfs_rq; long sched_entity_my_q; long sched_entity_on_rq; long task_struct_on_rq; long cfs_rq_curr; long irq_desc_t_irq_data; long irq_desc_t_kstat_irqs; long irq_desc_t_affinity; long irq_data_chip; long irq_data_affinity; long kernel_stat_irqs; long socket_alloc_vfs_inode; long class_devices; long class_p; long class_private_devices; long device_knode_class; long device_node; long gendisk_dev; long gendisk_kobj; long gendisk_part0; long gendisk_queue; long hd_struct_dev; long klist_k_list; long klist_node_n_klist; long klist_node_n_node; long kobject_entry; long kset_list; long request_list_count; long request_queue_in_flight; long request_queue_rq; long subsys_private_klist_devices; long subsystem_kset; long mount_mnt_parent; long mount_mnt_mountpoint; long mount_mnt_list; long mount_mnt_devname; long mount_mnt; long task_struct_exit_state; long timekeeper_xtime; long file_f_op; long file_private_data; long hstate_order; long hugetlbfs_sb_info_hstate; long idr_layer_ary; long idr_layer_layer; long idr_layers; long idr_top; long ipc_id_ary_p; long ipc_ids_entries; long ipc_ids_max_id; long ipc_ids_ipcs_idr; long ipc_ids_in_use; long ipc_namespace_ids; long kern_ipc_perm_deleted; long kern_ipc_perm_key; long kern_ipc_perm_mode; long kern_ipc_perm_uid; long kern_ipc_perm_id; long kern_ipc_perm_seq; long nsproxy_ipc_ns; long shmem_inode_info_swapped; long shmem_inode_info_vfs_inode; long shm_file_data_file; long shmid_kernel_shm_file; long shmid_kernel_shm_nattch; long shmid_kernel_shm_perm; long shmid_kernel_shm_segsz; long shmid_kernel_id; long sem_array_sem_perm; long sem_array_sem_id; long sem_array_sem_nsems; long msg_queue_q_perm; long msg_queue_q_id; long msg_queue_q_cbytes; long msg_queue_q_qnum; long super_block_s_fs_info; long rq_timestamp; long radix_tree_node_height; long rb_root_rb_node; long rb_node_rb_left; long rb_node_rb_right; long rt_prio_array_queue; long task_struct_rt; long sched_rt_entity_run_list; long log_ts_nsec; long log_len; long log_text_len; long log_dict_len; long log_level; long log_flags_level; long timekeeper_xtime_sec; long neigh_table_hash_mask; long sched_rt_entity_my_q; long neigh_table_hash_shift; long neigh_table_nht_ptr; long task_group_parent; long task_group_css; long cgroup_subsys_state_cgroup; long cgroup_dentry; long task_group_rt_rq; long rt_rq_tg; long task_group_cfs_rq; long cfs_rq_tg; long task_group_siblings; long task_group_children; long task_group_cfs_bandwidth; long cfs_rq_throttled; long task_group_rt_bandwidth; long rt_rq_rt_throttled; long rt_rq_highest_prio; long rt_rq_rt_nr_running; long vmap_area_va_start; long vmap_area_va_end; long vmap_area_list; long vmap_area_flags; long vmap_area_vm; long hrtimer_cpu_base_clock_base; long hrtimer_clock_base_offset; long hrtimer_clock_base_active; long hrtimer_clock_base_first; long hrtimer_clock_base_get_time; long hrtimer_base_first; long hrtimer_base_pending; long hrtimer_base_get_time; long hrtimer_node; long hrtimer_list; long hrtimer_softexpires; long hrtimer_expires; long hrtimer_function; long timerqueue_head_next; long timerqueue_node_expires; long timerqueue_node_node; long ktime_t_tv64; long ktime_t_sec; long ktime_t_nsec; long module_taints; long module_gpgsig_ok; long module_license_gplok; long tnt_bit; long tnt_true; long tnt_false; long task_struct_thread_context_fp; long task_struct_thread_context_sp; long task_struct_thread_context_pc; long page_slab_page; long trace_print_flags_mask; long trace_print_flags_name; long task_struct_rss_stat; long task_rss_stat_count; long page_s_mem; long page_active; long hstate_nr_huge_pages; long hstate_free_huge_pages; long hstate_name; long cgroup_kn; long kernfs_node_name; long kernfs_node_parent; long kmem_cache_cpu_partial; long kmem_cache_cpu_cache; long nsproxy_net_ns; long atomic_t_counter; long percpu_counter_count; long mm_struct_mm_count; long task_struct_thread_reg29; long task_struct_thread_reg31; long pt_regs_regs; long pt_regs_cp0_badvaddr; long address_space_page_tree; long page_compound_head; long irq_desc_irq_data; long kmem_cache_node_total_objects; long timer_base_vectors; long request_queue_mq_ops; long request_queue_queue_ctx; long blk_mq_ctx_rq_dispatched; long blk_mq_ctx_rq_completed; long task_struct_stack; long tnt_mod; long radix_tree_node_shift; long kmem_cache_red_left_pad; long inactive_task_frame_ret_addr; long sk_buff_head_next; long sk_buff_head_qlen; long sk_buff_next; long sk_buff_len; long sk_buff_data; long nlmsghdr_nlmsg_type; long module_arch; long mod_arch_specific_num_orcs; long mod_arch_specific_orc_unwind_ip; long mod_arch_specific_orc_unwind; long task_struct_policy; long kmem_cache_random; long pid_namespace_idr; long idr_idr_rt; long bpf_prog_aux; long bpf_prog_type; long bpf_prog_tag; long bpf_prog_jited_len; long bpf_prog_bpf_func; long bpf_prog_len; long bpf_prog_insnsi; long bpf_prog_pages; long bpf_map_map_type; long bpf_map_map_flags; long bpf_map_pages; long bpf_map_key_size; long bpf_map_value_size; long bpf_map_max_entries; long bpf_map_user; long bpf_map_name; long bpf_prog_aux_used_map_cnt; long bpf_prog_aux_used_maps; long bpf_prog_aux_load_time; long bpf_prog_aux_user; long user_struct_uid; long idr_cur; long kmem_cache_memcg_params; long memcg_cache_params___root_caches_node; long memcg_cache_params_children; long memcg_cache_params_children_node; long task_struct_pid_links; long kernel_symbol_value; long pci_dev_dev; long pci_dev_hdr_type; long pci_dev_pcie_flags_reg; long pci_bus_node; long pci_bus_devices; long pci_bus_dev; long pci_bus_children; long pci_bus_parent; long pci_bus_self; long device_kobj; long kobject_name; long memory_block_dev; long memory_block_start_section_nr; long memory_block_end_section_nr; long memory_block_state; long memory_block_nid; long mem_section_pageblock_flags; long bus_type_p; long device_private_device; long device_private_knode_bus; long xarray_xa_head; long xa_node_slots; long xa_node_shift; long hd_struct_dkstats; long disk_stats_in_flight; long cpu_context_save_r7; long dentry_d_sb; long device_private_knode_class; long timerqueue_head_rb_root; long rb_root_cached_rb_leftmost; long bpf_map_memory; long bpf_map_memory_pages; long bpf_map_memory_user; long bpf_prog_aux_name; long page_private; long swap_info_struct_bdev; long zram_mem_pool; long zram_compressor; long zram_table_entry_flags; long zs_pool_size_class; long size_class_size; long gendisk_private_data; long zram_table_entry; /* unused; but cannot remove */ long module_core_size_rw; long module_core_size_rx; long module_init_size_rw; long module_init_size_rx; long module_module_core_rw; long module_module_core_rx; long module_module_init_rw; long module_module_init_rx; long super_block_s_inodes; long inode_i_sb_list; long irq_common_data_affinity; long irq_desc_irq_common_data; long uts_namespace_name; long printk_info_seq; long printk_info_ts_nsec; long printk_info_text_len; long printk_info_level; long printk_info_caller_id; long printk_info_dev_info; long dev_printk_info_subsystem; long dev_printk_info_device; long prb_desc_ring; long prb_text_data_ring; long prb_desc_ring_count_bits; long prb_desc_ring_descs; long prb_desc_ring_infos; long prb_desc_ring_head_id; long prb_desc_ring_tail_id; long prb_desc_state_var; long prb_desc_text_blk_lpos; long prb_data_blk_lpos_begin; long prb_data_blk_lpos_next; long prb_data_ring_size_bits; long prb_data_ring_data; long atomic_long_t_counter; long block_device_bd_device; long block_device_bd_stats; long wait_queue_entry_private; long wait_queue_head_head; long wait_queue_entry_entry; long printk_safe_seq_buf_len; long printk_safe_seq_buf_message_lost; long printk_safe_seq_buf_buffer; long sbitmap_word_depth; long sbitmap_word_word; long sbitmap_word_cleared; long sbitmap_depth; long sbitmap_shift; long sbitmap_map_nr; long sbitmap_map; long sbitmap_queue_sb; long sbitmap_queue_alloc_hint; long sbitmap_queue_wake_batch; long sbitmap_queue_wake_index; long sbitmap_queue_ws; long sbitmap_queue_ws_active; long sbitmap_queue_round_robin; long sbitmap_queue_min_shallow_depth; long sbq_wait_state_wait_cnt; long sbq_wait_state_wait; long sbitmap_alloc_hint; long sbitmap_round_robin; long request_cmd_flags; long request_q; long request_state; long request_queue_queue_hw_ctx; long request_queue_nr_hw_queues; long blk_mq_hw_ctx_tags; long blk_mq_tags_bitmap_tags; long blk_mq_tags_breserved_tags; long blk_mq_tags_nr_reserved_tags; long blk_mq_tags_rqs; long request_queue_hctx_table; long percpu_counter_counters; long slab_slab_list; long mm_struct_mm_mt; long maple_tree_ma_root; long maple_tree_ma_flags; long maple_node_parent; long maple_node_ma64; long maple_node_mr64; long maple_node_slot; long maple_arange_64_pivot; long maple_arange_64_slot; long maple_arange_64_gap; long maple_arange_64_meta; long maple_range_64_pivot; long maple_range_64_slot; long maple_metadata_end; long maple_metadata_gap; long sock_sk_common; long sock_common_skc_v6_daddr; long sock_common_skc_v6_rcv_saddr; long inactive_task_frame_bp; long net_device_ip6_ptr; long inet6_dev_addr_list; long inet6_ifaddr_addr; long inet6_ifaddr_if_list; long inet6_ifaddr_if_next; long in6_addr_in6_u; long kset_kobj; long subsys_private_subsys; long vmap_area_purge_list; long module_mem; long module_memory_base; long module_memory_size; long irq_data_irq; long zspage_huge; long zram_comp_algs; long task_struct_thread_reg01; long task_struct_thread_reg03; long mnt_namespace_mounts; long mnt_namespace_nr_mounts; long mount_mnt_node; long log_caller_id; long vmap_node_busy; long rb_list_head; long file_f_inode; long page_page_type; long inactive_task_frame_r15; long inactive_task_frame_r14; long inactive_task_frame_r13; long inactive_task_frame_r12; long inactive_task_frame_flags; long inactive_task_frame_si; long inactive_task_frame_di; long inactive_task_frame_bx; long thread_struct_es; long thread_struct_ds; long thread_struct_fsbase; long thread_struct_gsbase; long thread_struct_fs; long thread_struct_gs; long task_struct_thread_context_x19; long task_struct_thread_context_x20; long task_struct_thread_context_x21; long task_struct_thread_context_x22; long task_struct_thread_context_x23; long task_struct_thread_context_x24; long task_struct_thread_context_x25; long task_struct_thread_context_x26; long task_struct_thread_context_x27; long task_struct_thread_context_x28; long neigh_table_hash_heads; long neighbour_hash; long request_queue_tag_set; long blk_mq_tag_set_flags; long blk_mq_tag_set_shared_tags; long vfsmount_mnt_flags; long proc_mounts_cursor; long bpf_ringbuf_map_map; long bpf_ringbuf_map_rb; long bpf_ringbuf_consumer_pos; long bpf_ringbuf_nr_pages; long hrtimer_clock_base_index; long klp_patch_list; }; struct size_table { /* stash of commonly-used sizes */ long page; long free_area_struct; long zone_struct; long free_area; long zone; long kmem_slab_s; long kmem_cache_s; long kmem_bufctl_t; long slab_s; long slab; long cpucache_s; long array_cache; long swap_info_struct; long mm_struct; long vm_area_struct; long pglist_data; long page_cache_bucket; long pt_regs; long task_struct; long thread_info; long softirq_state; long desc_struct; long umode_t; long dentry; long files_struct; long fdtable; long fs_struct; long file; long inode; long vfsmount; long super_block; long irqdesc; long module; long list_head; long hlist_node; long hlist_head; long irq_cpustat_t; long cpuinfo_x86; long cpuinfo_ia64; long timer_list; long timer_vec_root; long timer_vec; long tvec_root_s; long tvec_s; long tvec_t_base_s; long wait_queue; long __wait_queue; long device; long net_device; long sock; long signal_struct; long sigpending_signal; long signal_queue; long sighand_struct; long sigqueue; long k_sigaction; long resource_entry_t; long resource; long runqueue; long irq_desc_t; long task_union; long thread_union; long prio_array; long user_regs_struct; long switch_stack; long vm_area_struct_vm_flags; long e820map; long e820entry; long cpu_s; long pgd_t; long kallsyms_header; long kallsyms_symbol; long kallsyms_section; long irq_ctx; long block_device; long blk_major_name; long gendisk; long address_space; long char_device_struct; long inet_sock; long in6_addr; long socket; long spinlock_t; long radix_tree_root; long radix_tree_node; long x8664_pda; long ppc64_paca; long gate_struct; long tss_struct; long task_struct_start_time; long cputime_t; long mem_section; long pid_link; long unwind_table; long rlimit; long kmem_cache; long kmem_cache_node; long upid; long kmem_cache_cpu; long cfs_rq; long pcpu_info; long vcpu_struct; long cdev; long probe; long kobj_map; long page_flags; long module_sect_attr; long task_struct_utime; long task_struct_stime; long cpu_context_save; long elf_prstatus; long note_buf; long unwind_idx; long softirq_action; long irq_data; long s390_stack_frame; long percpu_data; long sched_entity; long kernel_stat; long subsystem; long class_private; long rq_in_flight; long class_private_devices; long mount; long hstate; long ipc_ids; long shmid_kernel; long sem_array; long msg_queue; long log; long log_level; long rt_rq; long task_group; long vmap_area; long hrtimer_clock_base; long hrtimer_base; long tnt; long trace_print_flags; long task_struct_flags; long timer_base; long taint_flag; long nlmsghdr; long nlmsghdr_nlmsg_type; long sk_buff_head_qlen; long sk_buff_len; long orc_entry; long task_struct_policy; long pid; long bpf_prog; long bpf_prog_aux; long bpf_map; long bpf_insn; long xarray; long xa_node; long zram_table_entry; long irq_common_data; long printk_info; long printk_ringbuffer; long prb_desc; long wait_queue_entry; long task_struct_state; long printk_safe_seq_buf_buffer; long sbitmap_word; long sbitmap; long sbitmap_queue; long sbq_wait_state; long blk_mq_tags; long percpu_counter; long maple_tree; long maple_node; long module_memory; long fred_frame; long vmap_node; long cpumask_t; long task_struct_exit_state; long bpf_ringbuf_map; }; struct array_table { int kmem_cache_s_name; int kmem_cache_s_c_name; int kmem_cache_s_array; int kmem_cache_s_cpudata; int irq_desc; int irq_action; int log_buf; int timer_vec_vec; int timer_vec_root_vec; int tvec_s_vec; int tvec_root_s_vec; int page_hash_table; int net_device_name; int neigh_table_hash_buckets; int neighbour_ha; int swap_info; int pglist_data_node_zones; int zone_struct_free_area; int zone_free_area; int free_area; int free_area_DIMENSION; int prio_array_queue; int height_to_maxindex; int pid_hash; int kmem_cache_node; int kmem_cache_cpu_slab; int rt_prio_array_queue; int height_to_maxnodes; int task_struct_rlim; int signal_struct_rlim; int vm_numa_stat; int pid_numbers; }; /* * The following set of macros use gdb to determine structure, union, * or member sizes/offsets. They should be used only during initialization * of the offset_table or size_table, or with data structures whose names * or members are only known/specified during runtime. */ #define MEMBER_SIZE_REQUEST ((struct datatype_member *)(-1)) #define ANON_MEMBER_OFFSET_REQUEST ((struct datatype_member *)(-2)) #define MEMBER_TYPE_REQUEST ((struct datatype_member *)(-3)) #define STRUCT_SIZE_REQUEST ((struct datatype_member *)(-4)) #define MEMBER_TYPE_NAME_REQUEST ((struct datatype_member *)(-5)) #define ANON_MEMBER_SIZE_REQUEST ((struct datatype_member *)(-6)) #define STRUCT_SIZE(X) datatype_info((X), NULL, STRUCT_SIZE_REQUEST) #define UNION_SIZE(X) datatype_info((X), NULL, STRUCT_SIZE_REQUEST) #define STRUCT_EXISTS(X) (datatype_info((X), NULL, STRUCT_SIZE_REQUEST) >= 0) #define DATATYPE_SIZE(X) datatype_info((X)->name, NULL, (X)) #define MEMBER_OFFSET(X,Y) datatype_info((X), (Y), NULL) #define MEMBER_EXISTS(X,Y) (datatype_info((X), (Y), NULL) >= 0) #define MEMBER_SIZE(X,Y) datatype_info((X), (Y), MEMBER_SIZE_REQUEST) #define MEMBER_TYPE(X,Y) datatype_info((X), (Y), MEMBER_TYPE_REQUEST) #define MEMBER_TYPE_NAME(X,Y) ((char *)datatype_info((X), (Y), MEMBER_TYPE_NAME_REQUEST)) #define ANON_MEMBER_OFFSET(X,Y) datatype_info((X), (Y), ANON_MEMBER_OFFSET_REQUEST) #define ANON_MEMBER_SIZE(X,Y) datatype_info((X), (Y), ANON_MEMBER_SIZE_REQUEST) /* * The following set of macros can only be used with pre-intialized fields * in the offset table, size table or array_table. */ #define OFFSET(X) (OFFSET_verify(offset_table.X, (char *)__FUNCTION__, __FILE__, __LINE__, #X)) #define MODULE_OFFSET(X,Y) (PAX_MODULE_SPLIT() ? OFFSET(Y) : OFFSET(X)) #define MODULE_OFFSET2(X,T) MODULE_OFFSET(X, X##_##T) #define SIZE(X) (SIZE_verify(size_table.X, (char *)__FUNCTION__, __FILE__, __LINE__, #X)) #define INVALID_OFFSET (-1) #define INVALID_MEMBER(X) (offset_table.X == INVALID_OFFSET) #define INVALID_SIZE(X) (size_table.X == -1) #define VALID_SIZE(X) (size_table.X >= 0) #define VALID_STRUCT(X) (size_table.X >= 0) #define VALID_MEMBER(X) (offset_table.X >= 0) #define ARRAY_LENGTH(X) (array_table.X) #define ASSIGN_OFFSET(X) (offset_table.X) #define ASSIGN_SIZE(X) (size_table.X) #define OFFSET_OPTION(X,Y) (OFFSET_option(offset_table.X, offset_table.Y, (char *)__FUNCTION__, __FILE__, __LINE__, #X, #Y)) #define SIZE_OPTION(X,Y) (SIZE_option(size_table.X, size_table.Y, (char *)__FUNCTION__, __FILE__, __LINE__, #X, #Y)) #define MEMBER_OFFSET_INIT(X, Y, Z) (ASSIGN_OFFSET(X) = MEMBER_OFFSET(Y, Z)) #define STRUCT_SIZE_INIT(X, Y) (ASSIGN_SIZE(X) = STRUCT_SIZE(Y)) #define ARRAY_LENGTH_INIT(A, B, C, D, E) ((A) = get_array_length(C, D, E)) #define ARRAY_LENGTH_INIT_ALT(A, B, C, D, E) ((A) = get_array_length_alt(B, C, D, E)) #define MEMBER_SIZE_INIT(X, Y, Z) (ASSIGN_SIZE(X) = MEMBER_SIZE(Y, Z)) #define ANON_MEMBER_OFFSET_INIT(X, Y, Z) (ASSIGN_OFFSET(X) = ANON_MEMBER_OFFSET(Y, Z)) /* * For use with non-debug kernels. */ struct builtin_debug_table { char *release; char *machine_type; struct offset_table *offset_table; struct size_table *size_table; struct array_table *array_table; }; /* * Facilitators for pulling correctly-sized data out of a buffer at a * known address. */ #ifdef NEED_ALIGNED_MEM_ACCESS #define DEF_LOADER(TYPE) \ static inline TYPE \ load_##TYPE (char *addr) \ { \ TYPE ret; \ size_t i = sizeof(TYPE); \ while (i--) \ ((char *)&ret)[i] = addr[i]; \ return ret; \ } DEF_LOADER(int); DEF_LOADER(uint); DEF_LOADER(long); DEF_LOADER(ulong); DEF_LOADER(ulonglong); DEF_LOADER(ushort); DEF_LOADER(short); typedef void *pointer_t; DEF_LOADER(pointer_t); DEF_LOADER(bool); #define LOADER(TYPE) load_##TYPE #define INT(ADDR) LOADER(int) ((char *)(ADDR)) #define UINT(ADDR) LOADER(uint) ((char *)(ADDR)) #define LONG(ADDR) LOADER(long) ((char *)(ADDR)) #define ULONG(ADDR) LOADER(ulong) ((char *)(ADDR)) #define ULONGLONG(ADDR) LOADER(ulonglong) ((char *)(ADDR)) #define ULONG_PTR(ADDR) ((ulong *) (LOADER(pointer_t) ((char *)(ADDR)))) #define USHORT(ADDR) LOADER(ushort) ((char *)(ADDR)) #define SHORT(ADDR) LOADER(short) ((char *)(ADDR)) #define UCHAR(ADDR) *((unsigned char *)((char *)(ADDR))) #define VOID_PTR(ADDR) ((void *) (LOADER(pointer_t) ((char *)(ADDR)))) #define BOOL(ADDR) LOADER(bool) ((char *)(ADDR)) #else #define INT(ADDR) *((int *)((char *)(ADDR))) #define UINT(ADDR) *((uint *)((char *)(ADDR))) #define LONG(ADDR) *((long *)((char *)(ADDR))) #define ULONG(ADDR) *((ulong *)((char *)(ADDR))) #define ULONGLONG(ADDR) *((ulonglong *)((char *)(ADDR))) #define ULONG_PTR(ADDR) *((ulong **)((char *)(ADDR))) #define USHORT(ADDR) *((ushort *)((char *)(ADDR))) #define SHORT(ADDR) *((short *)((char *)(ADDR))) #define UCHAR(ADDR) *((unsigned char *)((char *)(ADDR))) #define VOID_PTR(ADDR) *((void **)((char *)(ADDR))) #define BOOL(ADDR) *((bool *)((char *)(ADDR))) #endif /* NEED_ALIGNED_MEM_ACCESS */ struct node_table { int node_id; ulong pgdat; ulong mem_map; ulong size; ulong present; ulonglong start_paddr; ulong start_mapnr; }; struct meminfo; struct slab_data; #define VMA_CACHE (20) struct vm_table { /* kernel VM-related data */ ulong flags; ulong kernel_pgd[NR_CPUS]; ulong high_memory; ulong vmalloc_start; ulong mem_map; long total_pages; ulong totalram_pages; ulong totalhigh_pages; ulong num_physpages; ulong max_mapnr; ulong kmem_max_c_num; ulong kmem_max_limit; ulong kmem_max_cpus; ulong kmem_cache_count; ulong kmem_cache_len_nodes; ulong PG_reserved; ulong PG_slab; ulong PG_head_tail_mask; int kmem_cache_namelen; ulong page_hash_table; int page_hash_table_len; int paddr_prlen; int numnodes; int nr_zones; int nr_free_areas; struct node_table *node_table; void (*dump_free_pages)(struct meminfo *); void (*dump_kmem_cache)(struct meminfo *); struct slab_data *slab_data; uint nr_swapfiles; ulong last_swap_read; char *swap_info_struct; char *vma_cache; ulong cached_vma[VMA_CACHE]; ulong cached_vma_hits[VMA_CACHE]; int vma_cache_index; ulong vma_cache_fills; void *mem_sec; char *mem_section; int ZONE_HIGHMEM; ulong *node_online_map; int node_online_map_len; int nr_vm_stat_items; char **vm_stat_items; int cpu_slab_type; int nr_vm_event_items; char **vm_event_items; int nr_bad_slab_caches; ulong *bad_slab_caches; int nr_pageflags; struct pageflags_data { ulong mask; char *name; } *pageflags_data; ulong max_mem_section_nr; ulong zero_paddr; ulong huge_zero_paddr; uint page_type_base; }; #define NODES (0x1) #define ZONES (0x2) #define PERCPU_KMALLOC_V1 (0x4) #define COMMON_VADDR (0x8) #define KMEM_CACHE_INIT (0x10) #define V_MEM_MAP (0x20) #define PERCPU_KMALLOC_V2 (0x40) #define KMEM_CACHE_UNAVAIL (0x80) #define FLATMEM (0x100) #define DISCONTIGMEM (0x200) #define SPARSEMEM (0x400) #define SPARSEMEM_EX (0x800) #define PERCPU_KMALLOC_V2_NODES (0x1000) #define KMEM_CACHE_DELAY (0x2000) #define NODES_ONLINE (0x4000) #define VM_STAT (0x8000) #define KMALLOC_SLUB (0x10000) #define CONFIG_NUMA (0x20000) #define VM_EVENT (0x40000) #define PGCNT_ADJ (0x80000) #define VM_INIT (0x100000) #define SWAPINFO_V1 (0x200000) #define SWAPINFO_V2 (0x400000) #define NODELISTS_IS_PTR (0x800000) #define KMALLOC_COMMON (0x1000000) #define USE_VMAP_AREA (0x2000000) #define PAGEFLAGS (0x4000000) #define SLAB_OVERLOAD_PAGE (0x8000000) #define SLAB_CPU_CACHE (0x10000000) #define SLAB_ROOT_CACHES (0x20000000) #define USE_VMAP_NODES (0x40000000) /* * The SLAB_PAGEFLAGS flag is introduced to detect the change of * PG_slab's type from a page flag to a page type. */ #define SLAB_PAGEFLAGS (0x80000000) #define IS_FLATMEM() (vt->flags & FLATMEM) #define IS_DISCONTIGMEM() (vt->flags & DISCONTIGMEM) #define IS_SPARSEMEM() (vt->flags & SPARSEMEM) #define IS_SPARSEMEM_EX() (vt->flags & SPARSEMEM_EX) #define COMMON_VADDR_SPACE() (vt->flags & COMMON_VADDR) #define PADDR_PRLEN (vt->paddr_prlen) struct datatype_member { /* minimal definition of a structure/union */ char *name; /* and possibly a member within it */ char *member; ulong type; long size; long member_offset; long member_size; int member_typecode; ulong flags; const char *tagname; /* tagname and value for enums */ long value; ulong vaddr; }; #define union_name struct_name struct list_data { /* generic structure used by do_list() to walk */ ulong flags; /* through linked lists in the kernel */ ulong start; long member_offset; long list_head_offset; ulong end; ulong searchfor; char **structname; int structname_args; char *header; ulong *list_ptr; int (*callback_func)(void *, void *); void *callback_data; long struct_list_offset; }; #define LIST_OFFSET_ENTERED (VERBOSE << 1) #define LIST_START_ENTERED (VERBOSE << 2) #define LIST_HEAD_FORMAT (VERBOSE << 3) #define LIST_HEAD_POINTER (VERBOSE << 4) #define RETURN_ON_DUPLICATE (VERBOSE << 5) #define RETURN_ON_LIST_ERROR (VERBOSE << 6) #define LIST_STRUCT_RADIX_10 (VERBOSE << 7) #define LIST_STRUCT_RADIX_16 (VERBOSE << 8) #define LIST_HEAD_REVERSE (VERBOSE << 9) #define LIST_ALLOCATE (VERBOSE << 10) #define LIST_CALLBACK (VERBOSE << 11) #define CALLBACK_RETURN (VERBOSE << 12) #define LIST_PARSE_MEMBER (VERBOSE << 13) #define LIST_READ_MEMBER (VERBOSE << 14) #define LIST_BRENT_ALGO (VERBOSE << 15) #define LIST_HEAD_OFFSET_ENTERED (VERBOSE << 16) struct tree_data { ulong flags; ulong start; long node_member_offset; char **structname; int structname_args; int count; }; #define TREE_ROOT_OFFSET_ENTERED (VERBOSE << 1) #define TREE_NODE_OFFSET_ENTERED (VERBOSE << 2) #define TREE_NODE_POINTER (VERBOSE << 3) #define TREE_POSITION_DISPLAY (VERBOSE << 4) #define TREE_STRUCT_RADIX_10 (VERBOSE << 5) #define TREE_STRUCT_RADIX_16 (VERBOSE << 6) #define TREE_PARSE_MEMBER (VERBOSE << 7) #define TREE_READ_MEMBER (VERBOSE << 8) #define TREE_LINEAR_ORDER (VERBOSE << 9) #define TREE_STRUCT_VERBOSE (VERBOSE << 10) #define ALIAS_RUNTIME (1) #define ALIAS_RCLOCAL (2) #define ALIAS_RCHOME (3) #define ALIAS_BUILTIN (4) struct alias_data { /* command alias storage */ struct alias_data *next; char *alias; int argcnt; int size; int origin; char *args[MAXARGS]; char argbuf[1]; }; struct rb_node { unsigned long rb_parent_color; #define RB_RED 0 #define RB_BLACK 1 struct rb_node *rb_right; struct rb_node *rb_left; }; struct rb_root { struct rb_node *rb_node; }; #define NUMBER_STACKFRAMES 4 #define SAVE_RETURN_ADDRESS(retaddr) \ { \ int i; \ int saved_stacks; \ \ saved_stacks = backtrace((void **)retaddr, NUMBER_STACKFRAMES); \ \ /* explicitely zero out the invalid addresses */ \ for (i = saved_stacks; i < NUMBER_STACKFRAMES; i++) \ retaddr[i] = 0; \ } #endif /* !GDB_COMMON */ #define SYMBOL_NAME_USED (0x1) #define MODULE_SYMBOL (0x2) #define IS_MODULE_SYMBOL(SYM) ((SYM)->flags & MODULE_SYMBOL) struct syment { ulong value; char *name; struct syment *val_hash_next; struct syment *name_hash_next; char type; unsigned char cnt; unsigned char flags; unsigned char pad2; }; #define NAMESPACE_INIT (1) #define NAMESPACE_REUSE (2) #define NAMESPACE_FREE (3) #define NAMESPACE_INSTALL (4) #define NAMESPACE_COMPLETE (5) struct symbol_namespace { char *address; size_t size; long index; long cnt; }; struct downsized { char *name; struct downsized *next; }; #define SYMVAL_HASH (512) #define SYMVAL_HASH_INDEX(vaddr) \ (((vaddr) >> machdep->pageshift) % SYMVAL_HASH) #define SYMNAME_HASH (512) #define PATCH_KERNEL_SYMBOLS_START ((char *)(1)) #define PATCH_KERNEL_SYMBOLS_STOP ((char *)(2)) #ifndef GDB_COMMON struct symbol_table_data { ulong flags; #ifdef GDB_5_3 struct _bfd *bfd; #else struct bfd *bfd; #endif struct sec *sections; struct syment *symtable; struct syment *symend; long symcnt; ulong syment_size; struct symval_hash_chain { struct syment *val_hash_head; struct syment *val_hash_last; } symval_hash[SYMVAL_HASH]; double val_hash_searches; double val_hash_iterations; struct syment *symname_hash[SYMNAME_HASH]; struct symbol_namespace kernel_namespace; struct syment *ext_module_symtable; struct syment *ext_module_symend; long ext_module_symcnt; struct symbol_namespace ext_module_namespace; int mods_installed; struct load_module *current; struct load_module *load_modules; off_t dwarf_eh_frame_file_offset; ulong dwarf_eh_frame_size; ulong first_ksymbol; ulong __per_cpu_start; ulong __per_cpu_end; off_t dwarf_debug_frame_file_offset; ulong dwarf_debug_frame_size; ulong first_section_start; ulong last_section_end; ulong _stext_vmlinux; struct downsized downsized; ulong divide_error_vmlinux; ulong idt_table_vmlinux; ulong saved_command_line_vmlinux; ulong pti_init_vmlinux; ulong kaiser_init_vmlinux; int kernel_symbol_type; ulong linux_banner_vmlinux; struct syment *mod_symname_hash[SYMNAME_HASH]; }; /* flags for st */ #define KERNEL_SYMS (0x1) #define MODULE_SYMS (0x2) #define LOAD_MODULE_SYMS (0x4) #define INSMOD_BUILTIN (0x8) #define GDB_SYMS_PATCHED (0x10) #define GDB_PATCHED() (st->flags & GDB_SYMS_PATCHED) #define NO_SEC_LOAD (0x20) #define NO_SEC_CONTENTS (0x40) #define FORCE_DEBUGINFO (0x80) #define CRC_MATCHES (0x100) #define ADD_SYMBOL_FILE (0x200) #define USE_OLD_ADD_SYM (0x400) #define PERCPU_SYMS (0x800) #define MODSECT_UNKNOWN (0x1000) #define MODSECT_V1 (0x2000) #define MODSECT_V2 (0x4000) #define MODSECT_V3 (0x8000) #define MODSECT_VMASK (MODSECT_V1|MODSECT_V2|MODSECT_V3) #define NO_STRIP (0x10000) #define NO_LINE_NUMBERS() ((st->flags & GDB_SYMS_PATCHED) && !(kt->flags2 & KASLR)) #endif /* !GDB_COMMON */ #define ALL_MODULES (0) #define MAX_MOD_NAMELIST (256) #define MAX_MOD_NAME (64) #define MAX_MOD_SEC_NAME (64) #define MOD_EXT_SYMS (0x1) #define MOD_LOAD_SYMS (0x2) #define MOD_REMOTE (0x4) #define MOD_KALLSYMS (0x8) #define MOD_INITRD (0x10) #define MOD_NOPATCH (0x20) #define MOD_INIT (0x40) #define MOD_DO_READNOW (0x80) #define SEC_FOUND (0x10000) struct mod_section_data { #if defined(GDB_5_3) || defined(GDB_6_0) struct sec *section; #else struct bfd_section *section; #endif char name[MAX_MOD_SEC_NAME]; ulong offset; ulong size; int priority; int flags; ulong addr; }; /* Emulate enum mod_mem_type in include/linux/module.h */ #define MOD_TEXT (0) #define MOD_DATA (1) #define MOD_RODATA (2) #define MOD_RO_AFTER_INIT (3) #define MOD_INIT_TEXT (4) #define MOD_INIT_DATA (5) #define MOD_INIT_RODATA (6) #define MOD_MEM_NUM_TYPES (7) #define MOD_INVALID (-1) struct module_memory { ulong base; uint size; }; struct load_module { ulong mod_base; ulong module_struct; long mod_size; char mod_namelist[MAX_MOD_NAMELIST]; char mod_name[MAX_MOD_NAME]; ulong mod_flags; struct syment *mod_symtable; struct syment *mod_symend; long mod_ext_symcnt; struct syment *mod_ext_symtable; struct syment *mod_ext_symend; long mod_load_symcnt; struct syment *mod_load_symtable; struct syment *mod_load_symend; long mod_symalloc; struct symbol_namespace mod_load_namespace; ulong mod_size_of_struct; ulong mod_text_start; ulong mod_etext_guess; ulong mod_rodata_start; ulong mod_data_start; ulong mod_bss_start; int mod_sections; struct mod_section_data *mod_section_data; ulong mod_init_text_size; ulong mod_init_module_ptr; ulong mod_init_size; struct syment *mod_init_symtable; struct syment *mod_init_symend; ulong mod_percpu; ulong mod_percpu_size; struct objfile *loaded_objfile; /* For 6.4 module_memory */ struct module_memory mem[MOD_MEM_NUM_TYPES]; struct syment **symtable; struct syment **symend; struct syment *ext_symtable[MOD_MEM_NUM_TYPES]; struct syment *ext_symend[MOD_MEM_NUM_TYPES]; struct syment *load_symtable[MOD_MEM_NUM_TYPES]; struct syment *load_symend[MOD_MEM_NUM_TYPES]; }; #define IN_MODULE(A,L) (in_module_range(A, L, MOD_TEXT, MOD_RO_AFTER_INIT) != MOD_INVALID) #define IN_MODULE_INIT(A,L) (in_module_range(A, L, MOD_INIT_TEXT, MOD_INIT_RODATA) != MOD_INVALID) #define IN_MODULE_TEXT(A,L) (in_module_range(A, L, MOD_TEXT, MOD_TEXT) == MOD_TEXT || \ in_module_range(A, L, MOD_INIT_TEXT, MOD_INIT_TEXT) == MOD_INIT_TEXT) #define IN_MODULE_PERCPU(A,L) \ (((ulong)(A) >= (L)->mod_percpu) && ((ulong)(A) < ((L)->mod_percpu+(L)->mod_percpu_size))) #define MODULE_PERCPU_SYMS_LOADED(L) ((L)->mod_percpu && (L)->mod_percpu_size) #define for_each_mod_mem_type(type) \ for ((type) = MOD_TEXT; (type) < MOD_MEM_NUM_TYPES; (type)++) #ifndef GDB_COMMON #define KVADDR (0x1) #define UVADDR (0x2) #define PHYSADDR (0x4) #define XENMACHADDR (0x8) #define FILEADDR (0x10) #define AMBIGUOUS (~0) #define USE_USER_PGD (UVADDR << 2) #define VERIFY_ADDR (0x8) /* vm_area_dump() flags -- must follow */ #define PRINT_INODES (0x10) /* KVADDR, UVADDR, and PHYSADDR */ #define PRINT_MM_STRUCT (0x20) #define PRINT_VMA_STRUCTS (0x40) #define PRINT_SINGLE_VMA (0x80) #define PRINT_RADIX_10 (0x100) #define PRINT_RADIX_16 (0x200) #define PRINT_NRPAGES (0x400) #define MIN_PAGE_SIZE (4096) #define PTOB(X) ((ulonglong)(X) << machdep->pageshift) #define BTOP(X) ((ulonglong)(X) >> machdep->pageshift) #define PAGESIZE() (machdep->pagesize) #define PAGESHIFT() (machdep->pageshift) #define PAGEOFFSET(X) (((ulong)(X)) & machdep->pageoffset) #define VIRTPAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) #define PHYSPAGEBASE(X) (((physaddr_t)(X)) & (physaddr_t)machdep->pagemask) #define IS_ZEROPAGE(paddr) ((paddr) == vt->zero_paddr || \ (paddr) == vt->huge_zero_paddr) /* * Sparse memory stuff * These must follow the definitions in the kernel mmzone.h */ #define SECTION_SIZE_BITS() (machdep->section_size_bits) #define MAX_PHYSMEM_BITS() (machdep->max_physmem_bits) #define SECTIONS_SHIFT() (MAX_PHYSMEM_BITS() - SECTION_SIZE_BITS()) #define PA_SECTION_SHIFT() (SECTION_SIZE_BITS()) #define PFN_SECTION_SHIFT() (SECTION_SIZE_BITS() - PAGESHIFT()) #define NR_MEM_SECTIONS() (1UL << SECTIONS_SHIFT()) #define PAGES_PER_SECTION() (1UL << PFN_SECTION_SHIFT()) #define PAGE_SECTION_MASK() (~(PAGES_PER_SECTION()-1)) #define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT()) #define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT()) #define SECTIONS_PER_ROOT() (machdep->sections_per_root) /* CONFIG_SPARSEMEM_EXTREME */ #define _SECTIONS_PER_ROOT_EXTREME() (PAGESIZE() / SIZE(mem_section)) /* !CONFIG_SPARSEMEM_EXTREME */ #define _SECTIONS_PER_ROOT() (1) #define SECTION_NR_TO_ROOT(sec) ((sec) / SECTIONS_PER_ROOT()) #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) #define NR_SECTION_ROOTS() (DIV_ROUND_UP(NR_MEM_SECTIONS(), SECTIONS_PER_ROOT())) #define SECTION_ROOT_MASK() (SECTIONS_PER_ROOT() - 1) struct QEMUCPUSegment { uint32_t selector; uint32_t limit; uint32_t flags; uint32_t pad; uint64_t base; }; typedef struct QEMUCPUSegment QEMUCPUSegment; struct QEMUCPUState { uint32_t version; uint32_t size; uint64_t rax, rbx, rcx, rdx, rsi, rdi, rsp, rbp; uint64_t r8, r9, r10, r11, r12, r13, r14, r15; uint64_t rip, rflags; QEMUCPUSegment cs, ds, es, fs, gs, ss; QEMUCPUSegment ldt, tr, gdt, idt; uint64_t cr[5]; }; typedef struct QEMUCPUState QEMUCPUState; /* * Machine specific stuff */ #ifdef ARM #define _32BIT_ #define MACHINE_TYPE "ARM" #define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) #define PTOV(X) \ ((unsigned long)(X)-(machdep->machspec->phys_base)+(machdep->kvbase)) #define VTOP(X) \ ((unsigned long)(X)-(machdep->kvbase)+(machdep->machspec->phys_base)) #define IS_VMALLOC_ADDR(X) arm_is_vmalloc_addr((ulong)(X)) #define DEFAULT_MODULES_VADDR (machdep->kvbase - 16 * 1024 * 1024) #define MODULES_VADDR (machdep->machspec->modules_vaddr) #define MODULES_END (machdep->machspec->modules_end) #define VMALLOC_START (machdep->machspec->vmalloc_start_addr) #define VMALLOC_END (machdep->machspec->vmalloc_end) #define PGDIR_SHIFT (21) #define PTRS_PER_PTE (512) #define PTRS_PER_PGD (2048) #define PGD_OFFSET(vaddr) ((vaddr) >> PGDIR_SHIFT) #define PTE_OFFSET(vaddr) (((vaddr) >> PAGESHIFT()) & (PTRS_PER_PTE - 1)) #define __SWP_TYPE_SHIFT 3 #define __SWP_TYPE_BITS 6 #define __SWP_TYPE_MASK ((1 << __SWP_TYPE_BITS) - 1) #define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT) #define SWP_TYPE(entry) (((entry) >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK) #define SWP_OFFSET(entry) ((entry) >> __SWP_OFFSET_SHIFT) #define __swp_type(entry) SWP_TYPE(entry) #define __swp_offset(entry) SWP_OFFSET(entry) #define TIF_SIGPENDING (THIS_KERNEL_VERSION >= LINUX(2,6,23) ? 0 : 2) #define _SECTION_SIZE_BITS 28 #define _MAX_PHYSMEM_BITS 32 /*add for LPAE*/ typedef unsigned long long u64; typedef signed int s32; typedef u64 pgd_t; typedef u64 pmd_t; typedef u64 pte_t; #define PMDSIZE() (PAGESIZE()) #define LPAE_PGDIR_SHIFT (30) #define LPAE_PMDIR_SHIFT (21) #define LPAE_PGD_OFFSET(vaddr) ((vaddr) >> LPAE_PGDIR_SHIFT) #define LPAE_PMD_OFFSET(vaddr) (((vaddr) >> LPAE_PMDIR_SHIFT) & \ ((1<<(LPAE_PGDIR_SHIFT-LPAE_PMDIR_SHIFT))-1)) #define _SECTION_SIZE_BITS_LPAE 28 #define _MAX_PHYSMEM_BITS_LPAE 36 /* * #define PTRS_PER_PTE 512 * #define PTRS_PER_PMD 512 * #define PTRS_PER_PGD 4 * */ #define LPAE_PGDIR_SIZE() 32 #define LPAE_PGDIR_OFFSET(X) (((ulong)(X)) & (LPAE_PGDIR_SIZE() - 1)) #define LPAE_PMDIR_SIZE() 4096 #define LPAE_PMDIR_OFFSET(X) (((ulong)(X)) & (LPAE_PMDIR_SIZE() - 1)) #define LPAE_PTEDIR_SIZE() 4096 #define LPAE_PTEDIR_OFFSET(X) (((ulong)(X)) & (LPAE_PTEDIR_SIZE() - 1)) /*section size for LPAE is 2MiB*/ #define LPAE_SECTION_PAGE_MASK (~((MEGABYTES(2))-1)) #define _PHYSICAL_MASK_LPAE ((1ULL << _MAX_PHYSMEM_BITS_LPAE) - 1) #define PAGE_BASE_MASK ((u64)((s32)machdep->pagemask & _PHYSICAL_MASK_LPAE)) #define LPAE_PAGEBASE(X) (((ulonglong)(X)) & PAGE_BASE_MASK) #define LPAE_VTOP(X) \ ((unsigned long long)(unsigned long)(X) - \ (machdep->kvbase) + (machdep->machspec->phys_base)) #define IS_LAST_PGD_READ_LPAE(pgd) ((pgd) == \ machdep->machspec->last_pgd_read_lpae) #define IS_LAST_PMD_READ_LPAE(pmd) ((pmd) == \ machdep->machspec->last_pmd_read_lpae) #define IS_LAST_PTBL_READ_LPAE(ptbl) ((ptbl) == \ machdep->machspec->last_ptbl_read_lpae) #define FILL_PGD_LPAE(PGD, TYPE, SIZE) \ if (!IS_LAST_PGD_READ_LPAE(PGD)) { \ readmem((ulonglong)(PGD), TYPE, machdep->pgd, \ SIZE, "pmd page", FAULT_ON_ERROR); \ machdep->machspec->last_pgd_read_lpae \ = (ulonglong)(PGD); \ } #define FILL_PMD_LPAE(PMD, TYPE, SIZE) \ if (!IS_LAST_PMD_READ_LPAE(PMD)) { \ readmem((ulonglong)(PMD), TYPE, machdep->pmd, \ SIZE, "pmd page", FAULT_ON_ERROR); \ machdep->machspec->last_pmd_read_lpae \ = (ulonglong)(PMD); \ } #define FILL_PTBL_LPAE(PTBL, TYPE, SIZE) \ if (!IS_LAST_PTBL_READ_LPAE(PTBL)) { \ readmem((ulonglong)(PTBL), TYPE, machdep->ptbl, \ SIZE, "page table", FAULT_ON_ERROR); \ machdep->machspec->last_ptbl_read_lpae \ = (ulonglong)(PTBL); \ } #endif /* ARM */ #ifndef EM_AARCH64 #define EM_AARCH64 183 #endif #ifdef ARM64 #define _64BIT_ #define MACHINE_TYPE "ARM64" #define USERSPACE_TOP (machdep->machspec->userspace_top) #define PAGE_OFFSET (machdep->machspec->page_offset) #define VMALLOC_START (machdep->machspec->vmalloc_start_addr) #define VMALLOC_END (machdep->machspec->vmalloc_end) #define VMEMMAP_VADDR (machdep->machspec->vmemmap_vaddr) #define VMEMMAP_END (machdep->machspec->vmemmap_end) #define MODULES_VADDR (machdep->machspec->modules_vaddr) #define MODULES_END (machdep->machspec->modules_end) #define PTOV(X) arm64_PTOV((ulong)(X)) #define VTOP(X) arm64_VTOP((ulong)(X)) #define IS_VMALLOC_ADDR(X) arm64_IS_VMALLOC_ADDR((ulong)(X)) #define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) /* * 48-bit physical address supported. */ #define PHYS_MASK_SHIFT (48) #define PHYS_MASK (((1UL) << PHYS_MASK_SHIFT) - 1) typedef signed int s32; /* * 3-levels / 4K pages * 39-bit VA */ #define PTRS_PER_PGD_L3_4K ((1UL) << (39 - 30)) #define PTRS_PER_PMD_L3_4K (512) #define PTRS_PER_PTE_L3_4K (512) #define PGDIR_SHIFT_L3_4K (30) #define PGDIR_SIZE_L3_4K ((1UL) << PGDIR_SHIFT_L3_4K) #define PGDIR_MASK_L3_4K (~(PGDIR_SIZE_L3_4K-1)) #define PMD_SHIFT_L3_4K (21) #define PMD_SIZE_L3_4K (1UL << PMD_SHIFT_L3_4K) #define PMD_MASK_L3_4K (~(PMD_SIZE_L3_4K-1)) /* * 4-levels / 4K pages * 48-bit VA */ #define PTRS_PER_PGD_L4_4K ((1UL) << (48 - 39)) #define PTRS_PER_PUD_L4_4K (512) #define PTRS_PER_PMD_L4_4K (512) #define PTRS_PER_PTE_L4_4K (512) #define PGDIR_SHIFT_L4_4K (39) #define PGDIR_SIZE_L4_4K ((1UL) << PGDIR_SHIFT_L4_4K) #define PGDIR_MASK_L4_4K (~(PGDIR_SIZE_L4_4K-1)) #define PUD_SHIFT_L4_4K (30) #define PUD_SIZE_L4_4K ((1UL) << PUD_SHIFT_L4_4K) #define PUD_MASK_L4_4K (~(PUD_SIZE_L4_4K-1)) #define PMD_SHIFT_L4_4K (21) #define PMD_SIZE_L4_4K (1UL << PMD_SHIFT_L4_4K) #define PMD_MASK_L4_4K (~(PMD_SIZE_L4_4K-1)) #define PGDIR_SIZE_48VA (1UL << ((48 - 39) + 3)) #define PGDIR_MASK_48VA (~(PGDIR_SIZE_48VA - 1)) #define PGDIR_OFFSET_48VA(X) (((ulong)(X)) & (PGDIR_SIZE_48VA - 1)) /* * 2-levels / 16K pages * 36-bit VA */ #define PTRS_PER_PGD_L2_16K ((1UL) << (36 - 25)) #define PTRS_PER_PTE_L2_16K (2048) #define PGDIR_SHIFT_L2_16K (25) #define PGDIR_SIZE_L2_16K ((1UL) << PGDIR_SHIFT_L2_16K) #define PGDIR_MASK_L2_16K (~(PGDIR_SIZE_L2_16K-1)) #define PGDIR_OFFSET_L2_16K(X) (((ulong)(X)) & ((machdep->ptrs_per_pgd * 8) - 1)) /* * 3-levels / 16K pages * 47-bit VA */ #define PTRS_PER_PGD_L3_16K ((1UL) << (47 - 36)) #define PTRS_PER_PMD_L3_16K (2048) #define PTRS_PER_PTE_L3_16K (2048) #define PGDIR_SHIFT_L3_16K (36) #define PGDIR_SIZE_L3_16K ((1UL) << PGDIR_SHIFT_L3_16K) #define PGDIR_MASK_L3_16K (~(PGDIR_SIZE_L3_16K-1)) #define PMD_SHIFT_L3_16K (25) #define PMD_SIZE_L3_16K (1UL << PMD_SHIFT_L3_16K) #define PMD_MASK_L3_16K (~(PMD_SIZE_L3_16K-1)) #define PGDIR_OFFSET_L3_16K(X) (((ulong)(X)) & ((machdep->ptrs_per_pgd * 8) - 1)) /* * 4-levels / 16K pages * 48-bit VA */ #define PTRS_PER_PGD_L4_16K ((1UL) << (48 - 47)) #define PTRS_PER_PUD_L4_16K (2048) #define PTRS_PER_PMD_L4_16K (2048) #define PTRS_PER_PTE_L4_16K (2048) #define PGDIR_SHIFT_L4_16K (47) #define PGDIR_SIZE_L4_16K ((1UL) << PGDIR_SHIFT_L4_16K) #define PGDIR_MASK_L4_16K (~(PGDIR_SIZE_L4_16K-1)) #define PUD_SHIFT_L4_16K (36) #define PUD_SIZE_L4_16K ((1UL) << PUD_SHIFT_L4_16K) #define PUD_MASK_L4_16K (~(PUD_SIZE_L4_16K-1)) #define PMD_SHIFT_L4_16K (25) #define PMD_SIZE_L4_16K (1UL << PMD_SHIFT_L4_16K) #define PMD_MASK_L4_16K (~(PMD_SIZE_L4_16K-1)) #define PGDIR_OFFSET_L4_16K(X) (((ulong)(X)) & ((machdep->ptrs_per_pgd * 8) - 1)) /* * 3-levels / 64K pages * 48-bit, 52-bit VA */ #define PTRS_PER_PGD_L3_64K_48 ((1UL) << (48 - 42)) #define PTRS_PER_PGD_L3_64K_52 ((1UL) << (52 - 42)) #define PTRS_PER_PMD_L3_64K (8192) #define PTRS_PER_PTE_L3_64K (8192) #define PGDIR_SHIFT_L3_64K (42) #define PGDIR_SIZE_L3_64K ((1UL) << PGDIR_SHIFT_L3_64K) #define PGDIR_MASK_L3_64K (~(PGDIR_SIZE_L3_64K-1)) #define PMD_SHIFT_L3_64K (29) #define PMD_SIZE_L3_64K (1UL << PMD_SHIFT_L3_64K) #define PMD_MASK_L3_64K (~(PMD_SIZE_L3_64K-1)) #define PGDIR_OFFSET_L3_64K(X) (((ulong)(X)) & ((machdep->ptrs_per_pgd * 8) - 1)) /* * 2-levels / 64K pages * 42-bit VA */ #define PTRS_PER_PGD_L2_64K ((1UL) << (42 - 29)) #define PTRS_PER_PTE_L2_64K (8192) #define PGDIR_SHIFT_L2_64K (29) #define PGDIR_SIZE_L2_64K ((1UL) << PGDIR_SHIFT_L2_64K) #define PGDIR_MASK_L2_64K (~(PGDIR_SIZE_L2_64K-1)) /* * Software defined PTE bits definition. * (arch/arm64/include/asm/pgtable.h) */ #define PTE_VALID (1UL << 0) #define PTE_DIRTY (1UL << 55) #define PTE_SPECIAL (1UL << 56) /* * Level 3 descriptor (PTE). * (arch/arm64/include/asm/pgtable-hwdef.h) */ #define PTE_TYPE_MASK (3UL << 0) #define PTE_TYPE_FAULT (0UL << 0) #define PTE_TYPE_PAGE (3UL << 0) #define PTE_USER (1UL << 6) /* AP[1] */ #define PTE_RDONLY (1UL << 7) /* AP[2] */ #define PTE_SHARED (3UL << 8) /* SH[1:0], inner shareable */ #define PTE_AF (1UL << 10) /* Access Flag */ #define PTE_NG (1UL << 11) /* nG */ #define PTE_PXN (1UL << 53) /* Privileged XN */ #define PTE_UXN (1UL << 54) /* User XN */ #define __swp_type(x) arm64_swp_type(x) #define __swp_offset(x) arm64_swp_offset(x) #define SWP_TYPE(x) __swp_type(x) #define SWP_OFFSET(x) __swp_offset(x) #define KSYMS_START (0x1) #define PHYS_OFFSET (0x2) #define VM_L2_64K (0x4) #define VM_L3_64K (0x8) #define VM_L3_4K (0x10) #define KDUMP_ENABLED (0x20) #define IRQ_STACKS (0x40) #define NEW_VMEMMAP (0x80) #define VM_L4_4K (0x100) #define UNW_4_14 (0x200) #define FLIPPED_VM (0x400) #define HAS_PHYSVIRT_OFFSET (0x800) #define OVERFLOW_STACKS (0x1000) #define ARM64_MTE (0x2000) #define VM_L3_16K (0x4000) #define VM_L2_16K (0x8000) #define VM_L4_16K (0x10000) /* * Get kimage_voffset from /dev/crash */ #define DEV_CRASH_ARCH_DATA _IOR('c', 1, unsigned long) /* * sources: Documentation/arm64/memory.txt * arch/arm64/include/asm/memory.h * arch/arm64/include/asm/pgtable.h */ #define ARM64_VA_START ((0xffffffffffffffffUL) \ << machdep->machspec->VA_BITS) #define _VA_START(va) ((0xffffffffffffffffUL) - \ ((1UL) << ((va) - 1)) + 1) #define TEXT_OFFSET_MASK (~((MEGABYTES(2UL))-1)) #define ARM64_PAGE_OFFSET ((0xffffffffffffffffUL) \ << (machdep->machspec->VA_BITS - 1)) /* kernels >= v5.4 the kernel VA space is flipped */ #define ARM64_FLIP_PAGE_OFFSET (-(1UL) << machdep->machspec->VA_BITS) #define ARM64_USERSPACE_TOP ((1UL) << machdep->machspec->VA_BITS) #define ARM64_USERSPACE_TOP_ACTUAL ((1UL) << machdep->machspec->VA_BITS_ACTUAL) /* only used for v4.6 or later */ #define ARM64_MODULES_VSIZE MEGABYTES(128) #define ARM64_KASAN_SHADOW_SIZE (1UL << (machdep->machspec->VA_BITS - 3)) /* * The following 3 definitions are the original values, but are obsolete * for 3.17 and later kernels because they are now build-time calculations. * They all depend on the kernel's new VMEMMAP_SIZE value, which is dependent * upon the size of struct page. Accordingly, arm64_calc_virtual_memory_ranges() * determines their values at POST_GDB time. */ #define ARM64_VMALLOC_END (ARM64_PAGE_OFFSET - 0x400000000UL - KILOBYTES(64) - 1) #define ARM64_VMEMMAP_VADDR ((ARM64_VMALLOC_END+1) + KILOBYTES(64)) #define ARM64_VMEMMAP_END (ARM64_VMEMMAP_VADDR + GIGABYTES(8UL) - 1) #define ARM64_STACK_SIZE (16384) #define ARM64_IRQ_STACK_SIZE ARM64_STACK_SIZE #define ARM64_OVERFLOW_STACK_SIZE (4096) #define _SECTION_SIZE_BITS 30 #define _SECTION_SIZE_BITS_5_12 27 #define _SECTION_SIZE_BITS_5_12_64K 29 #define _MAX_PHYSMEM_BITS 40 #define _MAX_PHYSMEM_BITS_3_17 48 #define _MAX_PHYSMEM_BITS_52 52 typedef unsigned long long __u64; typedef unsigned long long u64; struct arm64_user_pt_regs { __u64 regs[31]; __u64 sp; __u64 pc; __u64 pstate; }; struct arm64_pt_regs { union { struct arm64_user_pt_regs user_regs; struct { u64 regs[31]; u64 sp; u64 pc; u64 pstate; }; }; u64 orig_x0; u64 syscallno; }; /* AArch32 CPSR bits */ #define PSR_MODE32_BIT 0x00000010 #define TIF_SIGPENDING (0) #define display_idt_table() \ error(FATAL, "-d option is not applicable to ARM64 architecture\n") struct machine_specific { ulong flags; ulong userspace_top; ulong page_offset; ulong vmalloc_start_addr; ulong vmalloc_end; ulong vmemmap_vaddr; ulong vmemmap_end; ulong modules_vaddr; ulong modules_end; ulong phys_offset; ulong __exception_text_start; ulong __exception_text_end; struct arm64_pt_regs *panic_task_regs; ulong PTE_PROT_NONE; ulong PTE_FILE; ulong VA_BITS; ulong __SWP_TYPE_BITS; ulong __SWP_TYPE_SHIFT; ulong __SWP_TYPE_MASK; ulong __SWP_OFFSET_BITS; ulong __SWP_OFFSET_SHIFT; ulong __SWP_OFFSET_MASK; ulong crash_kexec_start; ulong crash_kexec_end; ulong crash_save_cpu_start; ulong crash_save_cpu_end; ulong kernel_flags; ulong irq_stack_size; ulong *irq_stacks; char *irq_stackbuf; ulong __irqentry_text_start; ulong __irqentry_text_end; ulong overflow_stack_size; ulong *overflow_stacks; char *overflow_stackbuf; /* for exception vector code */ ulong exp_entry1_start; ulong exp_entry1_end; ulong exp_entry2_start; ulong exp_entry2_end; /* only needed for v4.6 or later kernel */ ulong kimage_voffset; ulong kimage_text; ulong kimage_end; ulong user_eframe_offset; /* for v4.14 or later */ ulong kern_eframe_offset; ulong machine_kexec_start; ulong machine_kexec_end; ulong VA_BITS_ACTUAL; ulong CONFIG_ARM64_VA_BITS; ulong VA_START; ulong CONFIG_ARM64_KERNELPACMASK; ulong physvirt_offset; ulong struct_page_size; ulong vmemmap; }; struct arm64_stackframe { unsigned long x19; unsigned long x20; unsigned long x21; unsigned long x22; unsigned long x23; unsigned long x24; unsigned long x25; unsigned long x26; unsigned long x27; unsigned long x28; unsigned long fp; unsigned long sp; unsigned long pc; }; #endif /* ARM64 */ #ifdef MIPS #define _32BIT_ #define MACHINE_TYPE "MIPS" #define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) #define PTOV(X) ((unsigned long)(X) + 0x80000000lu) #define VTOP(X) ((unsigned long)(X) & 0x1ffffffflu) #define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start) #define DEFAULT_MODULES_VADDR (machdep->kvbase - 16 * 1024 * 1024) #define MODULES_VADDR (machdep->machspec->modules_vaddr) #define MODULES_END (machdep->machspec->modules_end) #define VMALLOC_START (machdep->machspec->vmalloc_start_addr) #define VMALLOC_END (machdep->machspec->vmalloc_end) #define __SWP_TYPE_SHIFT 3 #define __SWP_TYPE_BITS 6 #define __SWP_TYPE_MASK ((1 << __SWP_TYPE_BITS) - 1) #define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT) #define SWP_TYPE(entry) (((entry) >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK) #define SWP_OFFSET(entry) ((entry) >> __SWP_OFFSET_SHIFT) #define __swp_type(entry) SWP_TYPE(entry) #define __swp_offset(entry) SWP_OFFSET(entry) #define TIF_SIGPENDING (THIS_KERNEL_VERSION >= LINUX(2,6,23) ? 1 : 2) #define _SECTION_SIZE_BITS 26 #define _MAX_PHYSMEM_BITS 32 #endif /* MIPS */ #ifdef MIPS64 #define _64BIT_ #define MACHINE_TYPE "MIPS64" #define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) #define IS_CKPHYS(X) (((X) >= 0xffffffff80000000lu) && \ ((X) < 0xffffffffc0000000lu)) #define IS_XKPHYS(X) (((X) >= 0x8000000000000000lu) && \ ((X) < 0xc000000000000000lu)) #define PTOV(X) ((ulong)(X) + 0x9800000000000000lu) #define VTOP(X) (IS_CKPHYS(X) ? ((ulong)(X) & 0x000000001ffffffflu) \ : ((ulong)(X) & 0x0000fffffffffffflu)) #define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start && !IS_CKPHYS(X)) #define DEFAULT_MODULES_VADDR 0xffffffffc0000000lu #define MODULES_VADDR (machdep->machspec->modules_vaddr) #define MODULES_END (machdep->machspec->modules_end) #define VMALLOC_START (machdep->machspec->vmalloc_start_addr) #define VMALLOC_END (machdep->machspec->vmalloc_end) #define __SWP_TYPE_SHIFT 16 #define __SWP_TYPE_BITS 8 #define __SWP_TYPE_MASK ((1 << __SWP_TYPE_BITS) - 1) #define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT) #define SWP_TYPE(entry) (((entry) >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK) #define SWP_OFFSET(entry) ((entry) >> __SWP_OFFSET_SHIFT) #define __swp_type(entry) SWP_TYPE(entry) #define __swp_offset(entry) SWP_OFFSET(entry) #define TIF_SIGPENDING (THIS_KERNEL_VERSION >= LINUX(2,6,23) ? 1 : 2) #define _SECTION_SIZE_BITS 28 #define _MAX_PHYSMEM_BITS 48 #endif /* MIPS64 */ #ifndef EM_RISCV #define EM_RISCV 243 #endif #ifdef RISCV64 #define _64BIT_ #define MACHINE_TYPE "RISCV64" typedef struct { ulong pgd; } pgd_t; typedef struct { ulong p4d; } p4d_t; typedef struct { ulong pud; } pud_t; typedef struct { ulong pmd; } pmd_t; typedef struct { ulong pte; } pte_t; typedef signed int s32; /* arch/riscv/include/asm/pgtable-64.h */ #define PGD_SHIFT_L3 (30) #define PGD_SHIFT_L4 (39) #define PGD_SHIFT_L5 (48) #define P4D_SHIFT (39) #define PUD_SHIFT (30) #define PMD_SHIFT (21) #define PTRS_PER_PGD (512) #define PTRS_PER_P4D (512) #define PTRS_PER_PUD (512) #define PTRS_PER_PMD (512) #define PTRS_PER_PTE (512) /* * Mask for bit 0~53(PROT and PPN) of PTE * 63 6261 60 54 53 10 9 8 7 6 5 4 3 2 1 0 * N PBMT Reserved P P N RSW D A G U X W R V */ #define PTE_PFN_PROT_MASK 0x3FFFFFFFFFFFFF /* * 3-levels / 4K pages * * sv39 * PGD | PMD | PTE | OFFSET | * 9 | 9 | 9 | 12 | */ #define pgd_index_l3_4k(addr) (((addr) >> PGD_SHIFT_L3) & (PTRS_PER_PGD - 1)) #define pmd_index_l3_4k(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1)) #define pte_index_l3_4k(addr) (((addr) >> PAGESHIFT()) & (PTRS_PER_PTE - 1)) /* * 4-levels / 4K pages * * sv48 * PGD | PUD | PMD | PTE | OFFSET | * 9 | 9 | 9 | 9 | 12 | */ #define pgd_index_l4_4k(addr) (((addr) >> PGD_SHIFT_L4) & (PTRS_PER_PGD - 1)) #define pud_index_l4_4k(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1)) #define pmd_index_l4_4k(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1)) #define pte_index_l4_4k(addr) (((addr) >> PAGESHIFT()) & (PTRS_PER_PTE - 1)) /* * 5-levels / 4K pages * * sv57 * PGD | P4D | PUD | PMD | PTE | OFFSET | * 9 | 9 | 9 | 9 | 9 | 12 | */ #define pgd_index_l5_4k(addr) (((addr) >> PGD_SHIFT_L5) & (PTRS_PER_PGD - 1)) #define p4d_index_l5_4k(addr) (((addr) >> P4D_SHIFT) & (PTRS_PER_P4D - 1)) #define pud_index_l5_4k(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1)) #define pmd_index_l5_4k(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1)) #define pte_index_l5_4k(addr) (((addr) >> PAGESHIFT()) & (PTRS_PER_PTE - 1)) /* machdep->flags */ #define KSYMS_START (0x1) #define VM_L3_4K (0x2) #define VM_L3_2M (0x4) #define VM_L3_1G (0x8) #define VM_L4_4K (0x10) #define VM_L4_2M (0x20) #define VM_L4_1G (0x40) #define VM_L5_4K (0x80) #define VM_L5_2M (0x100) #define VM_L5_1G (0x200) #define IRQ_STACKS (0x400) #define OVERFLOW_STACKS (0x800) #define RISCV64_OVERFLOW_STACK_SIZE (1 << 12) #define VM_FLAGS (VM_L3_4K | VM_L3_2M | VM_L3_1G | \ VM_L4_4K | VM_L4_2M | VM_L4_1G | \ VM_L5_4K | VM_L5_2M | VM_L5_1G) /* * Direct memory mapping */ #define PTOV(X) \ (((unsigned long)(X)+(machdep->kvbase)) - machdep->machspec->phys_base) #define VTOP(X) ({ \ ulong _X = X; \ (THIS_KERNEL_VERSION >= LINUX(5,13,0) && \ (_X) >= machdep->machspec->kernel_link_addr) ? \ ((unsigned long)(_X)-(machdep->machspec->va_kernel_pa_offset)): \ (((unsigned long)(_X)-(machdep->kvbase)) + \ machdep->machspec->phys_base); \ }) #define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) /* * Stack size order */ #define THREAD_SIZE_ORDER 2 #define PAGE_OFFSET (machdep->machspec->page_offset) #define VMALLOC_START (machdep->machspec->vmalloc_start_addr) #define VMALLOC_END (machdep->machspec->vmalloc_end) #define VMEMMAP_VADDR (machdep->machspec->vmemmap_vaddr) #define VMEMMAP_END (machdep->machspec->vmemmap_end) #define MODULES_VADDR (machdep->machspec->modules_vaddr) #define MODULES_END (machdep->machspec->modules_end) #define IS_VMALLOC_ADDR(X) riscv64_IS_VMALLOC_ADDR((ulong)(X)) /* from arch/riscv/include/asm/pgtable.h */ #define __SWP_TYPE_SHIFT 6 #define __SWP_TYPE_BITS 5 #define __SWP_TYPE_MASK ((1UL << __SWP_TYPE_BITS) - 1) #define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT) #define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS) #define SWP_TYPE(entry) (((entry) >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK) #define SWP_OFFSET(entry) ((entry) >> __SWP_OFFSET_SHIFT) #define __swp_type(entry) SWP_TYPE(entry) #define __swp_offset(entry) SWP_OFFSET(entry) #define TIF_SIGPENDING (THIS_KERNEL_VERSION >= LINUX(2,6,23) ? 1 : 2) /* from arch/riscv/include/asm/sparsemem.h */ #define _SECTION_SIZE_BITS 27 #define _MAX_PHYSMEM_BITS 56 /* 56-bit physical address supported */ #define PHYS_MASK_SHIFT _MAX_PHYSMEM_BITS #define PHYS_MASK (((1UL) << PHYS_MASK_SHIFT) - 1) #define IS_LAST_P4D_READ(p4d) ((ulong)(p4d) == machdep->machspec->last_p4d_read) #define FILL_P4D(P4D, TYPE, SIZE) \ if (!IS_LAST_P4D_READ(P4D)) { \ readmem((ulonglong)((ulong)(P4D)), TYPE, machdep->machspec->p4d, \ SIZE, "p4d page", FAULT_ON_ERROR); \ machdep->machspec->last_p4d_read = (ulong)(P4D); \ } #endif /* RISCV64 */ /* fix compilation errors due to elf.h version. */ #ifndef EM_LOONGARCH #define EM_LOONGARCH 258 #endif #ifdef LOONGARCH64 #define _64BIT_ #define MACHINE_TYPE "LOONGARCH64" #define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) #define IS_XKPRANGE(X) (((X) >= 0x8000000000000000lu) && \ ((X) < 0xc000000000000000lu)) #define PTOV(X) ((ulong)(X) + 0x9000000000000000lu) #define VTOP(X) ((ulong)(X) & 0x0000fffffffffffflu) #define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start) #define DEFAULT_MODULES_VADDR 0xffff800000000000lu #define MODULES_VADDR (machdep->machspec->modules_vaddr) #define MODULES_END (machdep->machspec->modules_end) #define VMALLOC_START (machdep->machspec->vmalloc_start_addr) #define VMALLOC_END (machdep->machspec->vmalloc_end) #define __SWP_TYPE_SHIFT 16 #define __SWP_TYPE_BITS 8 #define __SWP_TYPE_MASK ((1 << __SWP_TYPE_BITS) - 1) #define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT) #define SWP_TYPE(entry) (((entry) >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK) #define SWP_OFFSET(entry) ((entry) >> __SWP_OFFSET_SHIFT) #define __swp_type(entry) SWP_TYPE(entry) #define __swp_offset(entry) SWP_OFFSET(entry) #define TIF_SIGPENDING (1) #define _SECTION_SIZE_BITS 28 #define _MAX_PHYSMEM_BITS 48 #endif /* LOONGARCH64 */ #ifdef X86 #define _32BIT_ #define MACHINE_TYPE "X86" #define PTOV(X) ((unsigned long)(X)+(machdep->kvbase)) #define VTOP(X) ((unsigned long)(X)-(machdep->kvbase)) #define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start) #define KVBASE_MASK (0x1ffffff) #define PGDIR_SHIFT_2LEVEL (22) #define PTRS_PER_PTE_2LEVEL (1024) #define PTRS_PER_PGD_2LEVEL (1024) #define PGDIR_SHIFT_3LEVEL (30) #define PTRS_PER_PTE_3LEVEL (512) #define PTRS_PER_PGD_3LEVEL (4) #define PMD_SHIFT (21) /* only used by PAE translators */ #define PTRS_PER_PMD (512) /* only used by PAE translators */ #define _PAGE_PRESENT 0x001 #define _PAGE_RW 0x002 #define _PAGE_USER 0x004 #define _PAGE_PWT 0x008 #define _PAGE_PCD 0x010 #define _PAGE_ACCESSED 0x020 #define _PAGE_DIRTY 0x040 #define _PAGE_4M 0x080 /* 4 MB page, Pentium+, if present.. */ #define _PAGE_PSE 0x080 /* 4 MB (or 2MB) page, Pentium+, if present.. */ #define _PAGE_GLOBAL 0x100 /* Global TLB entry PPro+ */ #define _PAGE_PROTNONE (machdep->machspec->page_protnone) #define _PAGE_NX (0x8000000000000000ULL) #define NONPAE_PAGEBASE(X) (((unsigned long)(X)) & (unsigned long)machdep->pagemask) #define NX_BIT_MASK (0x7fffffffffffffffULL) #define PAE_PAGEBASE(X) (((unsigned long long)(X)) & ((unsigned long long)machdep->pagemask) & NX_BIT_MASK) #define SWP_TYPE(entry) (((entry) >> 1) & 0x3f) #define SWP_OFFSET(entry) ((entry) >> 8) #define __swp_type_PAE(entry) (((entry) >> 32) & 0x1f) #define __swp_type_nonPAE(entry) (((entry) >> 1) & 0x1f) #define __swp_offset_PAE(entry) (((entry) >> 32) >> 5) #define __swp_offset_nonPAE(entry) ((entry) >> 8) #define __swp_type(entry) (machdep->flags & PAE ? \ __swp_type_PAE(entry) : __swp_type_nonPAE(entry)) #define __swp_offset(entry) (machdep->flags & PAE ? \ __swp_offset_PAE(entry) : __swp_offset_nonPAE(entry)) #define TIF_SIGPENDING (2) // CONFIG_X86_PAE #define _SECTION_SIZE_BITS_PAE_ORIG 30 #define _SECTION_SIZE_BITS_PAE_2_6_26 29 #define _MAX_PHYSMEM_BITS_PAE 36 // !CONFIG_X86_PAE #define _SECTION_SIZE_BITS 26 #define _MAX_PHYSMEM_BITS 32 #define IS_LAST_PMD_READ_PAE(pmd) ((ulong)(pmd) == machdep->machspec->last_pmd_read_PAE) #define IS_LAST_PTBL_READ_PAE(ptbl) ((ulong)(ptbl) == machdep->machspec->last_ptbl_read_PAE) #define FILL_PMD_PAE(PMD, TYPE, SIZE) \ if (!IS_LAST_PMD_READ_PAE(PMD)) { \ readmem((ulonglong)(PMD), TYPE, machdep->pmd, \ SIZE, "pmd page", FAULT_ON_ERROR); \ machdep->machspec->last_pmd_read_PAE = (ulonglong)(PMD); \ } #define FILL_PTBL_PAE(PTBL, TYPE, SIZE) \ if (!IS_LAST_PTBL_READ_PAE(PTBL)) { \ readmem((ulonglong)(PTBL), TYPE, machdep->ptbl, \ SIZE, "page table", FAULT_ON_ERROR); \ machdep->machspec->last_ptbl_read_PAE = (ulonglong)(PTBL); \ } #endif /* X86 */ #ifdef X86_64 #define _64BIT_ #define MACHINE_TYPE "X86_64" #define USERSPACE_TOP (machdep->machspec->userspace_top) #define PAGE_OFFSET (machdep->machspec->page_offset) #define VMALLOC_START (machdep->machspec->vmalloc_start_addr) #define VMALLOC_END (machdep->machspec->vmalloc_end) #define VMEMMAP_VADDR (machdep->machspec->vmemmap_vaddr) #define VMEMMAP_END (machdep->machspec->vmemmap_end) #define MODULES_VADDR (machdep->machspec->modules_vaddr) #define MODULES_END (machdep->machspec->modules_end) #define __START_KERNEL_map 0xffffffff80000000UL #define MODULES_LEN (MODULES_END - MODULES_VADDR) #define USERSPACE_TOP_ORIG 0x0000008000000000 #define PAGE_OFFSET_ORIG 0x0000010000000000 #define VMALLOC_START_ADDR_ORIG 0xffffff0000000000 #define VMALLOC_END_ORIG 0xffffff7fffffffff #define MODULES_VADDR_ORIG 0xffffffffa0000000 #define MODULES_END_ORIG 0xffffffffafffffff #define USERSPACE_TOP_2_6_11 0x0000800000000000 #define PAGE_OFFSET_2_6_11 0xffff810000000000 #define VMALLOC_START_ADDR_2_6_11 0xffffc20000000000 #define VMALLOC_END_2_6_11 0xffffe1ffffffffff #define MODULES_VADDR_2_6_11 0xffffffff88000000 #define MODULES_END_2_6_11 0xfffffffffff00000 #define VMEMMAP_VADDR_2_6_24 0xffffe20000000000 #define VMEMMAP_END_2_6_24 0xffffe2ffffffffff #define MODULES_VADDR_2_6_26 0xffffffffa0000000 #define PAGE_OFFSET_2_6_27 0xffff880000000000 #define MODULES_END_2_6_27 0xffffffffff000000 #define USERSPACE_TOP_XEN 0x0000800000000000 #define PAGE_OFFSET_XEN 0xffff880000000000 #define VMALLOC_START_ADDR_XEN 0xffffc20000000000 #define VMALLOC_END_XEN 0xffffe1ffffffffff #define MODULES_VADDR_XEN 0xffffffff88000000 #define MODULES_END_XEN 0xfffffffffff00000 #define USERSPACE_TOP_XEN_RHEL4 0x0000008000000000 #define PAGE_OFFSET_XEN_RHEL4 0xffffff8000000000 #define VMALLOC_START_ADDR_XEN_RHEL4 0xffffff0000000000 #define VMALLOC_END_XEN_RHEL4 0xffffff7fffffffff #define MODULES_VADDR_XEN_RHEL4 0xffffffffa0000000 #define MODULES_END_XEN_RHEL4 0xffffffffafffffff #define VMALLOC_START_ADDR_2_6_31 0xffffc90000000000 #define VMALLOC_END_2_6_31 0xffffe8ffffffffff #define VMEMMAP_VADDR_2_6_31 0xffffea0000000000 #define VMEMMAP_END_2_6_31 0xffffeaffffffffff #define MODULES_VADDR_2_6_31 0xffffffffa0000000 #define MODULES_END_2_6_31 0xffffffffff000000 #define USERSPACE_TOP_5LEVEL 0x0100000000000000 #define PAGE_OFFSET_5LEVEL 0xff10000000000000 #define VMALLOC_START_ADDR_5LEVEL 0xffa0000000000000 #define VMALLOC_END_5LEVEL 0xffd1ffffffffffff #define MODULES_VADDR_5LEVEL 0xffffffffa0000000 #define MODULES_END_5LEVEL 0xffffffffff5fffff #define VMEMMAP_VADDR_5LEVEL 0xffd4000000000000 #define VMEMMAP_END_5LEVEL 0xffd5ffffffffffff #define PAGE_OFFSET_4LEVEL_4_20 0xffff888000000000 #define PAGE_OFFSET_5LEVEL_4_20 0xff11000000000000 #define VSYSCALL_START 0xffffffffff600000 #define VSYSCALL_END 0xffffffffff601000 #define CPU_ENTRY_AREA_START 0xfffffe0000000000 #define CPU_ENTRY_AREA_END 0xfffffe7fffffffff #define PTOV(X) ((unsigned long)(X)+(machdep->kvbase)) #define VTOP(X) x86_64_VTOP((ulong)(X)) #define IS_VMALLOC_ADDR(X) x86_64_IS_VMALLOC_ADDR((ulong)(X)) /* * the default page table level for x86_64: * 4 level page tables */ #define PGDIR_SHIFT 39 #define PTRS_PER_PGD 512 #define PUD_SHIFT 30 #define PTRS_PER_PUD 512 #define PMD_SHIFT 21 #define PTRS_PER_PMD 512 #define PTRS_PER_PTE 512 /* 5 level page */ #define PGDIR_SHIFT_5LEVEL 48 #define PTRS_PER_PGD_5LEVEL 512 #define P4D_SHIFT 39 #define PTRS_PER_P4D 512 #define __PGDIR_SHIFT (machdep->machspec->pgdir_shift) #define __PTRS_PER_PGD (machdep->machspec->ptrs_per_pgd) #define pgd_index(address) (((address) >> __PGDIR_SHIFT) & (__PTRS_PER_PGD-1)) #define p4d_index(address) (((address) >> P4D_SHIFT) & (PTRS_PER_P4D - 1)) #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD - 1)) #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)) #define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) #define FILL_TOP_PGD() \ if (!(pc->flags & RUNTIME) || ACTIVE()) { \ FILL_PGD(vt->kernel_pgd[0], KVADDR, PAGESIZE()); \ } #define FILL_TOP_PGD_HYPER() \ unsigned long idle_pg_table = symbol_exists("idle_pg_table_4") ? \ symbol_value("idle_pg_table_4") : \ symbol_value("idle_pg_table"); \ FILL_PGD(idle_pg_table, KVADDR, PAGESIZE()); #define IS_LAST_P4D_READ(p4d) ((ulong)(p4d) == machdep->machspec->last_p4d_read) #define FILL_P4D(P4D, TYPE, SIZE) \ if (!IS_LAST_P4D_READ(P4D)) { \ readmem((ulonglong)((ulong)(P4D)), TYPE, machdep->machspec->p4d, \ SIZE, "p4d page", FAULT_ON_ERROR); \ machdep->machspec->last_p4d_read = (ulong)(P4D); \ } #define MAX_POSSIBLE_PHYSMEM_BITS 52 /* * PHYSICAL_PAGE_MASK changed (enlarged) between 2.4 and 2.6, so * for safety, use the 2.6 values to generate it. */ #define __PHYSICAL_MASK_SHIFT_XEN 52 #define __PHYSICAL_MASK_SHIFT_2_6 46 #define __PHYSICAL_MASK_SHIFT_5LEVEL 52 #define __PHYSICAL_MASK_SHIFT (machdep->machspec->physical_mask_shift) #define __PHYSICAL_MASK ((1UL << __PHYSICAL_MASK_SHIFT) - 1) #define __VIRTUAL_MASK_SHIFT 48 #define __VIRTUAL_MASK ((1UL << __VIRTUAL_MASK_SHIFT) - 1) #define PAGE_SHIFT 12 #define PAGE_SIZE (1UL << PAGE_SHIFT) #define PHYSICAL_PAGE_MASK (~(PAGE_SIZE-1) & __PHYSICAL_MASK ) #define _PAGE_BIT_NX 63 #define _PAGE_PRESENT 0x001 #define _PAGE_RW 0x002 #define _PAGE_USER 0x004 #define _PAGE_PWT 0x008 #define _PAGE_PCD 0x010 #define _PAGE_ACCESSED 0x020 #define _PAGE_DIRTY 0x040 #define _PAGE_PSE 0x080 /* 2MB page */ #define _PAGE_FILE 0x040 /* set:pagecache, unset:swap */ #define _PAGE_GLOBAL 0x100 /* Global TLB entry */ #define _PAGE_PROTNONE (machdep->machspec->page_protnone) #define _PAGE_NX (1UL<<_PAGE_BIT_NX) #define SWP_TYPE(entry) (((entry) >> 1) & 0x3f) #define SWP_OFFSET(entry) ((entry) >> 8) #define __swp_type(entry) x86_64_swp_type(entry) #define __swp_offset(entry) x86_64_swp_offset(entry) #define TIF_SIGPENDING (2) #define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) #define _CPU_PDA_READ2(CPU, BUFFER) \ ((readmem(symbol_value("_cpu_pda"), \ KVADDR, &cpu_pda_addr, sizeof(unsigned long), \ "_cpu_pda addr", RETURN_ON_ERROR)) && \ (readmem(cpu_pda_addr + ((CPU) * sizeof(void *)), \ KVADDR, &cpu_pda_addr, sizeof(unsigned long), \ "_cpu_pda addr", RETURN_ON_ERROR)) && \ (cpu_pda_addr) && \ (readmem(cpu_pda_addr, KVADDR, (BUFFER), SIZE(x8664_pda), \ "cpu_pda entry", RETURN_ON_ERROR))) #define _CPU_PDA_READ(CPU, BUFFER) \ ((STRNEQ("_cpu_pda", closest_symbol((symbol_value("_cpu_pda") + \ ((CPU) * sizeof(unsigned long)))))) && \ (readmem(symbol_value("_cpu_pda") + ((CPU) * sizeof(void *)), \ KVADDR, &cpu_pda_addr, sizeof(unsigned long), \ "_cpu_pda addr", RETURN_ON_ERROR)) && \ (readmem(cpu_pda_addr, KVADDR, (BUFFER), SIZE(x8664_pda), \ "cpu_pda entry", RETURN_ON_ERROR))) #define CPU_PDA_READ(CPU, BUFFER) \ (STRNEQ("cpu_pda", closest_symbol((symbol_value("cpu_pda") + \ ((CPU) * SIZE(x8664_pda))))) && \ readmem(symbol_value("cpu_pda") + ((CPU) * SIZE(x8664_pda)), \ KVADDR, (BUFFER), SIZE(x8664_pda), "cpu_pda entry", \ RETURN_ON_ERROR)) #define VALID_LEVEL4_PGT_ADDR(X) \ (((X) == VIRTPAGEBASE(X)) && IS_KVADDR(X) && !IS_VMALLOC_ADDR(X)) #define _SECTION_SIZE_BITS 27 #define _MAX_PHYSMEM_BITS 40 #define _MAX_PHYSMEM_BITS_2_6_26 44 #define _MAX_PHYSMEM_BITS_2_6_31 46 #define _MAX_PHYSMEM_BITS_5LEVEL 52 #endif /* X86_64 */ #ifdef ALPHA #define _64BIT_ #define MACHINE_TYPE "ALPHA" #define PAGEBASE(X) (((unsigned long)(X)) & (unsigned long)machdep->pagemask) #define PTOV(X) ((unsigned long)(X)+(machdep->kvbase)) #define VTOP(X) ((unsigned long)(X)-(machdep->kvbase)) #define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start) #define KSEG_BASE_48_BIT (0xffff800000000000) #define KSEG_BASE (0xfffffc0000000000) #define _PFN_MASK (0xFFFFFFFF00000000) #define VMALLOC_START (0xFFFFFE0000000000) #define MIN_SYMBOL_VALUE (KSEG_BASE_48_BIT) #define PGDIR_SHIFT (PAGESHIFT() + 2*(PAGESHIFT()-3)) #define PMD_SHIFT (PAGESHIFT() + (PAGESHIFT()-3)) #define PTRS_PER_PAGE (1024) #define PTRS_PER_PGD (1UL << (PAGESHIFT()-3)) /* * OSF/1 PAL-code-imposed page table bits */ #define _PAGE_VALID 0x0001 #define _PAGE_FOR 0x0002 /* used for page protection (fault on read) */ #define _PAGE_FOW 0x0004 /* used for page protection (fault on write) */ #define _PAGE_FOE 0x0008 /* used for page protection (fault on exec) */ #define _PAGE_ASM 0x0010 #define _PAGE_KRE 0x0100 /* xxx - see below on the "accessed" bit */ #define _PAGE_URE 0x0200 /* xxx */ #define _PAGE_KWE 0x1000 /* used to do the dirty bit in software */ #define _PAGE_UWE 0x2000 /* used to do the dirty bit in software */ /* .. and these are ours ... */ #define _PAGE_DIRTY 0x20000 #define _PAGE_ACCESSED 0x40000 #define SWP_TYPE(entry) (((entry) >> 32) & 0xff) #define SWP_OFFSET(entry) ((entry) >> 40) #define __swp_type(entry) SWP_TYPE(entry) #define __swp_offset(entry) SWP_OFFSET(entry) #define TIF_SIGPENDING (2) #endif /* ALPHA */ #ifdef PPC #define _32BIT_ #define MACHINE_TYPE "PPC" #define PAGEBASE(X) ((X) & machdep->pagemask) #define PTOV(X) ((unsigned long)(X)+(machdep->kvbase)) #define VTOP(X) ((unsigned long)(X)-(machdep->kvbase)) #define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start) /* Holds the platform specific info for page translation */ struct machine_specific { char *platform; /* page address translation bits */ int pte_size; int pte_rpn_shift; /* page flags */ ulong _page_present; ulong _page_user; ulong _page_rw; ulong _page_guarded; ulong _page_coherent; ulong _page_no_cache; ulong _page_writethru; ulong _page_dirty; ulong _page_accessed; ulong _page_hwwrite; ulong _page_shared; ulong _page_k_rw; /* platform special vtop */ int (*vtop_special)(ulong vaddr, physaddr_t *paddr, int verbose); void *mmu_special; }; /* machdep flags for ppc32 specific */ #define IS_PAE() (machdep->flags & PAE) #define IS_BOOKE() (machdep->flags & CPU_BOOKE) /* Page translation bits */ #define PPC_PLATFORM (machdep->machspec->platform) #define PTE_SIZE (machdep->machspec->pte_size) #define PTE_RPN_SHIFT (machdep->machspec->pte_rpn_shift) #define PAGE_SHIFT (12) #define PTE_T_LOG2 (ffs(PTE_SIZE) - 1) #define PTE_SHIFT (PAGE_SHIFT - PTE_T_LOG2) #define PGDIR_SHIFT (PAGE_SHIFT + PTE_SHIFT) #define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT)) #define PTRS_PER_PTE (1 << PTE_SHIFT) /* special vtop */ #define VTOP_SPECIAL (machdep->machspec->vtop_special) #define MMU_SPECIAL (machdep->machspec->mmu_special) /* PFN shifts */ #define BOOKE3E_PTE_RPN_SHIFT (24) /* PAGE flags */ #define _PAGE_PRESENT (machdep->machspec->_page_present) /* software: pte contains a translation */ #define _PAGE_USER (machdep->machspec->_page_user) /* matches one of the PP bits */ #define _PAGE_RW (machdep->machspec->_page_rw) /* software: user write access allowed */ #define _PAGE_GUARDED (machdep->machspec->_page_guarded) #define _PAGE_COHERENT (machdep->machspec->_page_coherent /* M: enforce memory coherence (SMP systems) */) #define _PAGE_NO_CACHE (machdep->machspec->_page_no_cache) /* I: cache inhibit */ #define _PAGE_WRITETHRU (machdep->machspec->_page_writethru) /* W: cache write-through */ #define _PAGE_DIRTY (machdep->machspec->_page_dirty) /* C: page changed */ #define _PAGE_ACCESSED (machdep->machspec->_page_accessed) /* R: page referenced */ #define _PAGE_HWWRITE (machdep->machspec->_page_hwwrite) /* software: _PAGE_RW & _PAGE_DIRTY */ #define _PAGE_SHARED (machdep->machspec->_page_shared) #define _PAGE_K_RW (machdep->machspec->_page_k_rw) /* privilege only write access allowed */ /* Default values for PAGE flags */ #define DEFAULT_PAGE_PRESENT 0x001 #define DEFAULT_PAGE_USER 0x002 #define DEFAULT_PAGE_RW 0x004 #define DEFAULT_PAGE_GUARDED 0x008 #define DEFAULT_PAGE_COHERENT 0x010 #define DEFAULT_PAGE_NO_CACHE 0x020 #define DEFAULT_PAGE_WRITETHRU 0x040 #define DEFAULT_PAGE_DIRTY 0x080 #define DEFAULT_PAGE_ACCESSED 0x100 #define DEFAULT_PAGE_HWWRITE 0x200 #define DEFAULT_PAGE_SHARED 0 /* PPC44x PAGE flags: Values from kernel asm/pte-44x.h */ #define PPC44x_PAGE_PRESENT 0x001 #define PPC44x_PAGE_RW 0x002 #define PPC44x_PAGE_ACCESSED 0x008 #define PPC44x_PAGE_DIRTY 0x010 #define PPC44x_PAGE_USER 0x040 #define PPC44x_PAGE_GUARDED 0x100 #define PPC44x_PAGE_COHERENT 0x200 #define PPC44x_PAGE_NO_CACHE 0x400 #define PPC44x_PAGE_WRITETHRU 0x800 #define PPC44x_PAGE_HWWRITE 0 #define PPC44x_PAGE_SHARED 0 /* BOOK3E */ #define BOOK3E_PAGE_PRESENT 0x000001 #define BOOK3E_PAGE_BAP_SR 0x000004 #define BOOK3E_PAGE_BAP_UR 0x000008 /* User Readable */ #define BOOK3E_PAGE_BAP_SW 0x000010 #define BOOK3E_PAGE_BAP_UW 0x000020 /* User Writable */ #define BOOK3E_PAGE_DIRTY 0x001000 #define BOOK3E_PAGE_ACCESSED 0x040000 #define BOOK3E_PAGE_GUARDED 0x100000 #define BOOK3E_PAGE_COHERENT 0x200000 #define BOOK3E_PAGE_NO_CACHE 0x400000 #define BOOK3E_PAGE_WRITETHRU 0x800000 #define BOOK3E_PAGE_HWWRITE 0 #define BOOK3E_PAGE_SHARED 0 #define BOOK3E_PAGE_USER (BOOK3E_PAGE_BAP_SR | BOOK3E_PAGE_BAP_UR) #define BOOK3E_PAGE_RW (BOOK3E_PAGE_BAP_SW | BOOK3E_PAGE_BAP_UW) #define BOOK3E_PAGE_KERNEL_RW (BOOK3E_PAGE_BAP_SW | BOOK3E_PAGE_BAP_SR | BOOK3E_PAGE_DIRTY) /* FSL BOOKE */ #define FSL_BOOKE_PAGE_PRESENT 0x00001 #define FSL_BOOKE_PAGE_USER 0x00002 #define FSL_BOOKE_PAGE_RW 0x00004 #define FSL_BOOKE_PAGE_DIRTY 0x00008 #define FSL_BOOKE_PAGE_ACCESSED 0x00020 #define FSL_BOOKE_PAGE_GUARDED 0x00080 #define FSL_BOOKE_PAGE_COHERENT 0x00100 #define FSL_BOOKE_PAGE_NO_CACHE 0x00200 #define FSL_BOOKE_PAGE_WRITETHRU 0x00400 #define FSL_BOOKE_PAGE_HWWRITE 0 #define FSL_BOOKE_PAGE_SHARED 0 #define SWP_TYPE(entry) (((entry) >> 1) & 0x7f) #define SWP_OFFSET(entry) ((entry) >> 8) #define __swp_type(entry) SWP_TYPE(entry) #define __swp_offset(entry) SWP_OFFSET(entry) #define TIF_SIGPENDING (THIS_KERNEL_VERSION >= LINUX(2,6,23) ? 1 : 2) #define _SECTION_SIZE_BITS 24 #define _MAX_PHYSMEM_BITS 44 #define STACK_FRAME_OVERHEAD 16 #define STACK_FRAME_LR_SAVE (sizeof(ulong)) #define STACK_FRAME_MARKER (2 * sizeof(ulong)) #define STACK_FRAME_REGS_MARKER 0x72656773 #define PPC_STACK_SIZE 8192 #endif /* PPC */ #ifdef IA64 #define _64BIT_ #define MACHINE_TYPE "IA64" #define PAGEBASE(X) (((unsigned long)(X)) & (unsigned long)machdep->pagemask) #define REGION_SHIFT (61) #define VADDR_REGION(X) ((ulong)(X) >> REGION_SHIFT) #define KERNEL_CACHED_REGION (7) #define KERNEL_UNCACHED_REGION (6) #define KERNEL_VMALLOC_REGION (5) #define USER_STACK_REGION (4) #define USER_DATA_REGION (3) #define USER_TEXT_REGION (2) #define USER_SHMEM_REGION (1) #define USER_IA32_EMUL_REGION (0) #define KERNEL_VMALLOC_BASE ((ulong)KERNEL_VMALLOC_REGION << REGION_SHIFT) #define KERNEL_UNCACHED_BASE ((ulong)KERNEL_UNCACHED_REGION << REGION_SHIFT) #define KERNEL_CACHED_BASE ((ulong)KERNEL_CACHED_REGION << REGION_SHIFT) #define _SECTION_SIZE_BITS 30 #define _MAX_PHYSMEM_BITS 50 /* * As of 2.6, these are no longer straight forward. */ #define PTOV(X) ia64_PTOV((ulong)(X)) #define VTOP(X) ia64_VTOP((ulong)(X)) #define IS_VMALLOC_ADDR(X) ia64_IS_VMALLOC_ADDR((ulong)(X)) #define SWITCH_STACK_ADDR(X) (ia64_get_switch_stack((ulong)(X))) #define __IA64_UL(x) ((unsigned long)(x)) #define IA64_MAX_PHYS_BITS (50) /* max # of phys address bits (architected) */ /* * How many pointers will a page table level hold expressed in shift */ #define PTRS_PER_PTD_SHIFT (PAGESHIFT()-3) /* * Definitions for fourth level: */ #define PTRS_PER_PTE (__IA64_UL(1) << (PTRS_PER_PTD_SHIFT)) /* * Definitions for third level: * * PMD_SHIFT determines the size of the area a third-level page table * can map. */ #define PMD_SHIFT (PAGESHIFT() + (PTRS_PER_PTD_SHIFT)) #define PMD_SIZE (1UL << PMD_SHIFT) #define PMD_MASK (~(PMD_SIZE-1)) #define PTRS_PER_PMD (1UL << (PTRS_PER_PTD_SHIFT)) /* * PUD_SHIFT determines the size of the area a second-level page table * can map */ #define PUD_SHIFT (PMD_SHIFT + (PTRS_PER_PTD_SHIFT)) #define PUD_SIZE (1UL << PUD_SHIFT) #define PUD_MASK (~(PUD_SIZE-1)) #define PTRS_PER_PUD (1UL << (PTRS_PER_PTD_SHIFT)) /* * Definitions for first level: * * PGDIR_SHIFT determines what a first-level page table entry can map. */ #define PGDIR_SHIFT_4L (PUD_SHIFT + (PTRS_PER_PTD_SHIFT)) #define PGDIR_SHIFT_3L (PMD_SHIFT + (PTRS_PER_PTD_SHIFT)) /* Turns out 4L & 3L PGDIR_SHIFT are the same (for now) */ #define PGDIR_SHIFT PGDIR_SHIFT_4L #define PGDIR_SIZE (__IA64_UL(1) << PGDIR_SHIFT) #define PGDIR_MASK (~(PGDIR_SIZE-1)) #define PTRS_PER_PGD_SHIFT PTRS_PER_PTD_SHIFT #define PTRS_PER_PGD (1UL << PTRS_PER_PGD_SHIFT) #define USER_PTRS_PER_PGD (5*PTRS_PER_PGD/8) /* regions 0-4 are user regions */ #define FIRST_USER_ADDRESS 0 /* * First, define the various bits in a PTE. Note that the PTE format * matches the VHPT short format, the firt doubleword of the VHPD long * format, and the first doubleword of the TLB insertion format. */ #define _PAGE_P (1 << 0) /* page present bit */ #define _PAGE_MA_WB (0x0 << 2) /* write back memory attribute */ #define _PAGE_MA_UC (0x4 << 2) /* uncacheable memory attribute */ #define _PAGE_MA_UCE (0x5 << 2) /* UC exported attribute */ #define _PAGE_MA_WC (0x6 << 2) /* write coalescing memory attribute */ #define _PAGE_MA_NAT (0x7 << 2) /* not-a-thing attribute */ #define _PAGE_MA_MASK (0x7 << 2) #define _PAGE_PL_0 (0 << 7) /* privilege level 0 (kernel) */ #define _PAGE_PL_1 (1 << 7) /* privilege level 1 (unused) */ #define _PAGE_PL_2 (2 << 7) /* privilege level 2 (unused) */ #define _PAGE_PL_3 (3 << 7) /* privilege level 3 (user) */ #define _PAGE_PL_MASK (3 << 7) #define _PAGE_AR_R (0 << 9) /* read only */ #define _PAGE_AR_RX (1 << 9) /* read & execute */ #define _PAGE_AR_RW (2 << 9) /* read & write */ #define _PAGE_AR_RWX (3 << 9) /* read, write & execute */ #define _PAGE_AR_R_RW (4 << 9) /* read / read & write */ #define _PAGE_AR_RX_RWX (5 << 9) /* read & exec / read, write & exec */ #define _PAGE_AR_RWX_RW (6 << 9) /* read, write & exec / read & write */ #define _PAGE_AR_X_RX (7 << 9) /* exec & promote / read & exec */ #define _PAGE_AR_MASK (7 << 9) #define _PAGE_AR_SHIFT 9 #define _PAGE_A (1 << 5) /* page accessed bit */ #define _PAGE_D (1 << 6) /* page dirty bit */ #define _PAGE_PPN_MASK (((__IA64_UL(1) << IA64_MAX_PHYS_BITS) - 1) & ~0xfffUL) #define _PAGE_ED (__IA64_UL(1) << 52) /* exception deferral */ #define _PAGE_PROTNONE (__IA64_UL(1) << 63) #define _PFN_MASK _PAGE_PPN_MASK #define _PAGE_CHG_MASK (_PFN_MASK | _PAGE_A | _PAGE_D) #define _PAGE_SIZE_4K 12 #define _PAGE_SIZE_8K 13 #define _PAGE_SIZE_16K 14 #define _PAGE_SIZE_64K 16 #define _PAGE_SIZE_256K 18 #define _PAGE_SIZE_1M 20 #define _PAGE_SIZE_4M 22 #define _PAGE_SIZE_16M 24 #define _PAGE_SIZE_64M 26 #define _PAGE_SIZE_256M 28 #define __ACCESS_BITS _PAGE_ED | _PAGE_A | _PAGE_P | _PAGE_MA_WB #define __DIRTY_BITS_NO_ED _PAGE_A | _PAGE_P | _PAGE_D | _PAGE_MA_WB #define __DIRTY_BITS _PAGE_ED | __DIRTY_BITS_NO_ED #define EFI_PAGE_SHIFT (12) /* * NOTE: #include'ing creates too many compiler problems, so * this stuff is hardwired here; it's probably etched in stone somewhere. */ struct efi_memory_desc_t { uint32_t type; uint32_t pad; uint64_t phys_addr; uint64_t virt_addr; uint64_t num_pages; uint64_t attribute; } desc; /* Memory types: */ #define EFI_RESERVED_TYPE 0 #define EFI_LOADER_CODE 1 #define EFI_LOADER_DATA 2 #define EFI_BOOT_SERVICES_CODE 3 #define EFI_BOOT_SERVICES_DATA 4 #define EFI_RUNTIME_SERVICES_CODE 5 #define EFI_RUNTIME_SERVICES_DATA 6 #define EFI_CONVENTIONAL_MEMORY 7 #define EFI_UNUSABLE_MEMORY 8 #define EFI_ACPI_RECLAIM_MEMORY 9 #define EFI_ACPI_MEMORY_NVS 10 #define EFI_MEMORY_MAPPED_IO 11 #define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12 #define EFI_PAL_CODE 13 #define EFI_MAX_MEMORY_TYPE 14 /* Attribute values: */ #define EFI_MEMORY_UC 0x0000000000000001 /* uncached */ #define EFI_MEMORY_WC 0x0000000000000002 /* write-coalescing */ #define EFI_MEMORY_WT 0x0000000000000004 /* write-through */ #define EFI_MEMORY_WB 0x0000000000000008 /* write-back */ #define EFI_MEMORY_WP 0x0000000000001000 /* write-protect */ #define EFI_MEMORY_RP 0x0000000000002000 /* read-protect */ #define EFI_MEMORY_XP 0x0000000000004000 /* execute-protect */ #define EFI_MEMORY_RUNTIME 0x8000000000000000 /* range requires runtime mapping */ #define SWP_TYPE(entry) (((entry) >> 1) & 0xff) #define SWP_OFFSET(entry) ((entry) >> 9) #define __swp_type(entry) ((entry >> 2) & 0x7f) #define __swp_offset(entry) ((entry << 1) >> 10) #define TIF_SIGPENDING (THIS_KERNEL_VERSION >= LINUX(2,6,23) ? 0 : 1) #define KERNEL_TR_PAGE_SIZE (1 << _PAGE_SIZE_64M) #define KERNEL_TR_PAGE_MASK (~(KERNEL_TR_PAGE_SIZE - 1)) #define UNKNOWN_PHYS_START ((ulong)(-1)) #define DEFAULT_PHYS_START (KERNEL_TR_PAGE_SIZE * 1) #define IA64_GET_STACK_ULONG(OFF) \ ((INSTACK(OFF,bt)) ? (GET_STACK_ULONG(OFF)) : get_init_stack_ulong((unsigned long)OFF)) #endif /* IA64 */ #ifdef PPC64 #define _64BIT_ #define MACHINE_TYPE "PPC64" #define PPC64_64K_PAGE_SIZE 65536 #define PPC64_STACK_SIZE 16384 #define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) #define PTOV(X) ((unsigned long)(X)+(machdep->identity_map_base)) #define VTOP(X) ((unsigned long)(X)-(machdep->identity_map_base)) #define BOOK3E_VMBASE 0x8000000000000000 #define IS_VMALLOC_ADDR(X) machdep->machspec->is_vmaddr(X) #define KERNELBASE machdep->pageoffset #define PGDIR_SHIFT (machdep->pageshift + (machdep->pageshift -3) + (machdep->pageshift - 2)) #define PMD_SHIFT (machdep->pageshift + (machdep->pageshift - 3)) #define PGD_MASK (~((1UL << PGDIR_SHIFT) - 1)) #define PMD_MASK (~((1UL << PMD_SHIFT) - 1)) /* shift to put page number into pte */ #define PTE_RPN_SHIFT_DEFAULT 16 #define PMD_TO_PTEPAGE_SHIFT 2 /* Used for 2.6 or later */ #define PTE_INDEX_SIZE 9 #define PMD_INDEX_SIZE 10 #define PGD_INDEX_SIZE 10 #define PTRS_PER_PTE (1 << PTE_INDEX_SIZE) #define PTRS_PER_PMD (1 << PMD_INDEX_SIZE) #define PTRS_PER_PGD (1 << PGD_INDEX_SIZE) #define PGD_OFFSET_24(vaddr) ((vaddr >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1)) #define PGD_OFFSET(vaddr) ((vaddr >> PGDIR_SHIFT) & 0x7ff) #define PMD_OFFSET(vaddr) ((vaddr >> PMD_SHIFT) & (PTRS_PER_PMD - 1)) /* 4-level page table support */ /* 4K pagesize */ #define PTE_INDEX_SIZE_L4_4K 9 #define PMD_INDEX_SIZE_L4_4K 7 #define PUD_INDEX_SIZE_L4_4K 7 #define PGD_INDEX_SIZE_L4_4K 9 #define PUD_INDEX_SIZE_L4_4K_3_7 9 #define PTE_INDEX_SIZE_RADIX_4K 9 #define PMD_INDEX_SIZE_RADIX_4K 9 #define PUD_INDEX_SIZE_RADIX_4K 9 #define PGD_INDEX_SIZE_RADIX_4K 13 #define PTE_RPN_SHIFT_L4_4K 17 #define PTE_RPN_SHIFT_L4_4K_4_5 18 #define PGD_MASKED_BITS_4K 0 #define PUD_MASKED_BITS_4K 0 #define PMD_MASKED_BITS_4K 0 /* 64K pagesize */ #define PTE_INDEX_SIZE_L4_64K 12 #define PMD_INDEX_SIZE_L4_64K 12 #define PUD_INDEX_SIZE_L4_64K 0 #define PGD_INDEX_SIZE_L4_64K 4 #define PTE_INDEX_SIZE_L4_64K_3_10 8 #define PMD_INDEX_SIZE_L4_64K_3_10 10 #define PGD_INDEX_SIZE_L4_64K_3_10 12 #define PMD_INDEX_SIZE_L4_64K_4_6 5 #define PUD_INDEX_SIZE_L4_64K_4_6 5 #define PMD_INDEX_SIZE_L4_64K_4_12 10 #define PUD_INDEX_SIZE_L4_64K_4_12 7 #define PGD_INDEX_SIZE_L4_64K_4_12 8 #define PUD_INDEX_SIZE_L4_64K_4_17 10 #define PTE_INDEX_SIZE_RADIX_64K 5 #define PMD_INDEX_SIZE_RADIX_64K 9 #define PUD_INDEX_SIZE_RADIX_64K 9 #define PGD_INDEX_SIZE_RADIX_64K 13 #define PTE_RPN_SHIFT_L4_64K_V1 32 #define PTE_RPN_SHIFT_L4_64K_V2 30 #define PTE_RPN_SHIFT_L4_BOOK3E_64K 28 #define PTE_RPN_SHIFT_L4_BOOK3E_4K 24 #define PGD_MASKED_BITS_64K 0 #define PUD_MASKED_BITS_64K 0x1ff #define PMD_MASKED_BITS_64K 0x1ff #define PMD_MASKED_BITS_64K_3_11 0xfff #define PMD_MASKED_BITS_BOOK3E_64K_4_5 0x7ff #define PGD_MASKED_BITS_64K_4_6 0xc0000000000000ffUL #define PUD_MASKED_BITS_64K_4_6 0xc0000000000000ffUL #define PMD_MASKED_BITS_64K_4_6 0xc0000000000000ffUL #define PTE_RPN_MASK_DEFAULT 0xffffffffffffffffUL #define PAGE_PA_MAX_L4_4_6 (THIS_KERNEL_VERSION >= LINUX(4,11,0) ? 53 : 57) #define PTE_RPN_MASK_L4_4_6 \ (((1UL << PAGE_PA_MAX_L4_4_6) - 1) & ~((1UL << PAGESHIFT()) - 1)) #define PTE_RPN_SHIFT_L4_4_6 PAGESHIFT() #define PGD_MASKED_BITS_4_7 0xc0000000000000ffUL #define PUD_MASKED_BITS_4_7 0xc0000000000000ffUL #define PMD_MASKED_BITS_4_7 0xc0000000000000ffUL #define PD_HUGE 0x8000000000000000 #define HUGE_PTE_MASK 0x03 #define HUGEPD_SHIFT_MASK 0x3f #define HUGEPD_ADDR_MASK (0x0fffffffffffffffUL & ~HUGEPD_SHIFT_MASK) #define PGD_MASK_L4 \ (THIS_KERNEL_VERSION >= LINUX(3,10,0) ? (machdep->ptrs_per_pgd - 1) : 0x1ff) #define PGD_OFFSET_L4(vaddr) \ ((vaddr >> (machdep->machspec->l4_shift)) & PGD_MASK_L4) #define PUD_OFFSET_L4(vaddr) \ ((vaddr >> (machdep->machspec->l3_shift)) & (machdep->machspec->ptrs_per_l3 - 1)) #define PMD_OFFSET_L4(vaddr) \ ((vaddr >> (machdep->machspec->l2_shift)) & (machdep->machspec->ptrs_per_l2 - 1)) #define _PAGE_PTE (machdep->machspec->_page_pte) /* distinguishes PTEs from pointers */ #define _PAGE_PRESENT (machdep->machspec->_page_present) /* software: pte contains a translation */ #define _PAGE_USER (machdep->machspec->_page_user) /* matches one of the PP bits */ #define _PAGE_RW (machdep->machspec->_page_rw) /* software: user write access allowed */ #define _PAGE_GUARDED (machdep->machspec->_page_guarded) #define _PAGE_COHERENT (machdep->machspec->_page_coherent /* M: enforce memory coherence (SMP systems) */) #define _PAGE_NO_CACHE (machdep->machspec->_page_no_cache) /* I: cache inhibit */ #define _PAGE_WRITETHRU (machdep->machspec->_page_writethru) /* W: cache write-through */ #define _PAGE_DIRTY (machdep->machspec->_page_dirty) /* C: page changed */ #define _PAGE_ACCESSED (machdep->machspec->_page_accessed) /* R: page referenced */ #define PTE_RPN_MASK (machdep->machspec->pte_rpn_mask) #define PTE_RPN_SHIFT (machdep->machspec->pte_rpn_shift) #define TIF_SIGPENDING (THIS_KERNEL_VERSION >= LINUX(2,6,23) ? 1 : 2) #define SWP_TYPE(entry) (((entry) >> 1) & 0x7f) #define SWP_OFFSET(entry) ((entry) >> 8) #define __swp_type(entry) SWP_TYPE(entry) #define __swp_offset(entry) SWP_OFFSET(entry) #define MSR_PR_LG 14 /* Problem State / Privilege Level */ /* Used to find the user or kernel-mode frame*/ #define STACK_FRAME_OVERHEAD 112 #define EXCP_FRAME_MARKER 0x7265677368657265 #define _SECTION_SIZE_BITS 24 #define _MAX_PHYSMEM_BITS 44 #define _MAX_PHYSMEM_BITS_3_7 46 #define _MAX_PHYSMEM_BITS_4_19 47 #define _MAX_PHYSMEM_BITS_4_20 51 #endif /* PPC64 */ #ifdef S390 #define _32BIT_ #define MACHINE_TYPE "S390" #define PTOV(X) ((unsigned long)(X)+(machdep->kvbase)) #define VTOP(X) ((unsigned long)(X)-(machdep->kvbase)) #define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start) #define PTRS_PER_PTE 1024 #define PTRS_PER_PMD 1 #define PTRS_PER_PGD 512 #define SEGMENT_TABLE_SIZE ((sizeof(ulong)*4) * PTRS_PER_PGD) #define SWP_TYPE(entry) (((entry) >> 2) & 0x1f) #define SWP_OFFSET(entry) ((((entry) >> 11) & 0xfffffffe) | \ (((entry) >> 7) & 0x1)) #define __swp_type(entry) SWP_TYPE(entry) #define __swp_offset(entry) SWP_OFFSET(entry) #define TIF_SIGPENDING (THIS_KERNEL_VERSION >= LINUX(3,16,0) ? 1 : 2) #define _SECTION_SIZE_BITS 25 #define _MAX_PHYSMEM_BITS 31 #endif /* S390 */ #ifdef S390X #define _64BIT_ #define MACHINE_TYPE "S390X" #define PTOV(X) s390x_PTOV((ulong)(X)) #define VTOP(X) s390x_VTOP((ulong)(X)) #define IS_VMALLOC_ADDR(X) s390x_IS_VMALLOC_ADDR(X) #define PTRS_PER_PTE 512 #define PTRS_PER_PMD 1024 #define PTRS_PER_PGD 2048 #define SEGMENT_TABLE_SIZE ((sizeof(ulong)*2) * PTRS_PER_PMD) #define SWP_TYPE(entry) (((entry) >> 2) & 0x1f) #define SWP_OFFSET(entry) ((((entry) >> 11) & 0xfffffffffffffffe) | \ (((entry) >> 7) & 0x1)) #define __swp_type(entry) SWP_TYPE(entry) #define __swp_offset(entry) SWP_OFFSET(entry) #define TIF_SIGPENDING (THIS_KERNEL_VERSION >= LINUX(3,16,0) ? 1 : 2) #define _SECTION_SIZE_BITS 28 #define _MAX_PHYSMEM_BITS_OLD 42 #define _MAX_PHYSMEM_BITS_NEW 46 #endif /* S390X */ #ifdef SPARC64 #define _64BIT_ #define MACHINE_TYPE "SPARC64" #define PTOV(X) \ ((unsigned long)(X) + machdep->machspec->page_offset) #define VTOP(X) \ ((unsigned long)(X) - machdep->machspec->page_offset) #define PAGE_OFFSET (machdep->machspec->page_offset) extern int sparc64_IS_VMALLOC_ADDR(ulong vaddr); #define IS_VMALLOC_ADDR(X) sparc64_IS_VMALLOC_ADDR((ulong)(X)) #define PAGE_SHIFT (13) #define PAGE_SIZE (1UL << PAGE_SHIFT) #define PAGE_MASK (~(PAGE_SIZE - 1)) #define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) #define THREAD_SIZE (2 * PAGE_SIZE) /* S3 Core * Core 48-bit physical address supported. * Bit 47 distinguishes memory or I/O. When set to "1" it is I/O. */ #define PHYS_MASK_SHIFT (47) #define PHYS_MASK (((1UL) << PHYS_MASK_SHIFT) - 1) typedef signed int s32; /* * This next two defines are convenience defines for normal page table. */ #define PTES_PER_PAGE (1UL << (PAGE_SHIFT - 3)) #define PTES_PER_PAGE_MASK (PTES_PER_PAGE - 1) /* 4-level page table */ #define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3)) #define PMD_SIZE (1UL << PMD_SHIFT) #define PMD_MASK (~(PMD_SIZE - 1)) #define PMD_BITS (PAGE_SHIFT - 3) #define PUD_SHIFT (PMD_SHIFT + PMD_BITS) #define PUD_SIZE (1UL << PUD_SHIFT) #define PUD_MASK (~(PUD_SIZE - 1)) #define PUD_BITS (PAGE_SHIFT - 3) #define PGDIR_SHIFT (PUD_SHIFT + PUD_BITS) #define PGDIR_SIZE (1UL << PGDIR_SHIFT) #define PGDIR_MASK (~(PGDIR_SIZE - 1)) #define PGDIR_BITS (PAGE_SHIFT - 3) #define PTRS_PER_PTE (1UL << (PAGE_SHIFT - 3)) #define PTRS_PER_PMD (1UL << PMD_BITS) #define PTRS_PER_PUD (1UL << PUD_BITS) #define PTRS_PER_PGD (1UL << PGDIR_BITS) #define HPAGE_SHIFT (23) /* Down one huge page */ #define SPARC64_USERSPACE_TOP (-(1UL << HPAGE_SHIFT)) #define PAGE_PMD_HUGE (0x0100000000000000UL) /* These are for SUN4V. */ #define _PAGE_VALID (0x8000000000000000UL) #define _PAGE_NFO_4V (0x4000000000000000UL) #define _PAGE_MODIFIED_4V (0x2000000000000000UL) #define _PAGE_ACCESSED_4V (0x1000000000000000UL) #define _PAGE_READ_4V (0x0800000000000000UL) #define _PAGE_WRITE_4V (0x0400000000000000UL) #define _PAGE_PADDR_4V (0x00FFFFFFFFFFE000UL) #define _PAGE_PFN_MASK (_PAGE_PADDR_4V) #define _PAGE_P_4V (0x0000000000000100UL) #define _PAGE_EXEC_4V (0x0000000000000080UL) #define _PAGE_W_4V (0x0000000000000040UL) #define _PAGE_PRESENT_4V (0x0000000000000010UL) #define _PAGE_SZALL_4V (0x0000000000000007UL) /* There are other page sizes. Some supported. */ #define _PAGE_SZ4MB_4V (0x0000000000000003UL) #define _PAGE_SZ512K_4V (0x0000000000000002UL) #define _PAGE_SZ64K_4V (0x0000000000000001UL) #define _PAGE_SZ8K_4V (0x0000000000000000UL) #define SPARC64_MODULES_VADDR (0x0000000010000000UL) #define SPARC64_MODULES_END (0x00000000f0000000UL) #define SPARC64_VMALLOC_START (0x0000000100000000UL) #define SPARC64_STACK_SIZE 0x4000 /* sparsemem */ #define _SECTION_SIZE_BITS 30 #define _MAX_PHYSMEM_BITS 53 #define STACK_BIAS 2047 struct machine_specific { ulong page_offset; ulong vmalloc_end; }; #define TIF_SIGPENDING (2) #define SWP_OFFSET(E) ((E) >> (PAGE_SHIFT + 8UL)) #define SWP_TYPE(E) (((E) >> PAGE_SHIFT) & 0xffUL) #define __swp_type(E) SWP_TYPE(E) #define __swp_offset(E) SWP_OFFSET(E) #endif /* SPARC64 */ #ifdef PLATFORM #define SWP_TYPE(entry) (error("PLATFORM_SWP_TYPE: TBD\n")) #define SWP_OFFSET(entry) (error("PLATFORM_SWP_OFFSET: TBD\n")) #define __swp_type(entry) SWP_TYPE(entry) #define __swp_offset(entry) SWP_OFFSET(entry) #endif /* PLATFORM */ #define KILOBYTES(x) ((x) * (1024)) #define MEGABYTES(x) ((x) * (1048576)) #define GIGABYTES(x) ((x) * (1073741824)) #define TB_SHIFT (40) #define TERABYTES(x) ((x) * (1UL << TB_SHIFT)) #define MEGABYTE_MASK (MEGABYTES(1)-1) #define SIZEOF_64BIT (8) #define SIZEOF_32BIT (4) #define SIZEOF_16BIT (2) #define SIZEOF_8BIT (1) #ifdef ARM #define MAX_HEXADDR_STRLEN (8) #define UVADDR_PRLEN (8) #endif #ifdef X86 #define MAX_HEXADDR_STRLEN (8) #define UVADDR_PRLEN (8) #endif #ifdef ALPHA #define MAX_HEXADDR_STRLEN (16) #define UVADDR_PRLEN (11) #endif #ifdef PPC #define MAX_HEXADDR_STRLEN (8) #define UVADDR_PRLEN (8) #endif #ifdef IA64 #define MAX_HEXADDR_STRLEN (16) #define UVADDR_PRLEN (16) #endif #ifdef S390 #define MAX_HEXADDR_STRLEN (8) #define UVADDR_PRLEN (8) #endif #ifdef S390X #define MAX_HEXADDR_STRLEN (16) #define UVADDR_PRLEN (16) #endif #ifdef X86_64 #define MAX_HEXADDR_STRLEN (16) #define UVADDR_PRLEN (10) #endif #ifdef PPC64 #define MAX_HEXADDR_STRLEN (16) #define UVADDR_PRLEN (16) #endif #ifdef ARM64 #define MAX_HEXADDR_STRLEN (16) #define UVADDR_PRLEN (10) #endif #ifdef MIPS #define MAX_HEXADDR_STRLEN (8) #define UVADDR_PRLEN (8) #endif #ifdef MIPS64 #define MAX_HEXADDR_STRLEN (16) #define UVADDR_PRLEN (16) #endif #ifdef SPARC64 #define MAX_HEXADDR_STRLEN (16) #define UVADDR_PRLEN (16) #endif #ifdef RISCV64 #define MAX_HEXADDR_STRLEN (16) #define UVADDR_PRLEN (16) #endif #ifdef LOONGARCH64 #define MAX_HEXADDR_STRLEN (16) #define UVADDR_PRLEN (16) #endif #define BADADDR ((ulong)(-1)) #define BADVAL ((ulong)(-1)) #define UNUSED (-1) #define UNINITIALIZED (BADVAL) #define BITS_PER_BYTE (8) #define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long)) #define NUM_TO_BIT(x) (1UL<<((x)%BITS_PER_LONG)) #define NUM_IN_BITMAP(bitmap, x) (bitmap[(x)/BITS_PER_LONG] & NUM_TO_BIT(x)) #define SET_BIT(bitmap, x) (bitmap[(x)/BITS_PER_LONG] |= NUM_TO_BIT(x)) static inline unsigned int __const_hweight8(unsigned long w) { return (!!((w) & (1ULL << 0))) + (!!((w) & (1ULL << 1))) + (!!((w) & (1ULL << 2))) + (!!((w) & (1ULL << 3))) + (!!((w) & (1ULL << 4))) + (!!((w) & (1ULL << 5))) + (!!((w) & (1ULL << 6))) + (!!((w) & (1ULL << 7))); } #define __const_hweight16(w) (__const_hweight8(w) + __const_hweight8((w) >> 8)) #define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16)) #define __const_hweight64(w) (__const_hweight32(w) + __const_hweight32((w) >> 32)) #define hweight32(w) __const_hweight32(w) #define hweight64(w) __const_hweight64(w) /* * precision lengths for fprintf */ #define VADDR_PRLEN (sizeof(char *) == 8 ? 16 : 8) #define LONG_LONG_PRLEN (16) #define LONG_PRLEN (sizeof(long) == 8 ? 16 : 8) #define INT_PRLEN (sizeof(int) == 8 ? 16 : 8) #define CHAR_PRLEN (2) #define SHORT_PRLEN (4) #define MINSPACE (-100) #define SYNOPSIS (0x1) #define COMPLETE_HELP (0x2) #define PIPE_TO_SCROLL (0x4) #define MUST_HELP (0x8) #define LEFT_JUSTIFY (1) #define RIGHT_JUSTIFY (2) #define CENTER (0x1) #define LJUST (0x2) #define RJUST (0x4) #define LONG_DEC (0x8) #define LONG_HEX (0x10) #define INT_DEC (0x20) #define INT_HEX (0x40) #define LONGLONG_HEX (0x80) #define ZERO_FILL (0x100) #define SLONG_DEC (0x200) #define INIT_TIME (1) #define RUN_TIME (2) /* * IRQ line status. * For kernels up to and including 2.6.17 */ #define IRQ_INPROGRESS_2_6_17 1 /* IRQ handler active - do not enter! */ #define IRQ_DISABLED_2_6_17 2 /* IRQ disabled - do not enter! */ #define IRQ_PENDING_2_6_17 4 /* IRQ pending - replay on enable */ #define IRQ_REPLAY_2_6_17 8 /* IRQ has been replayed but not acked yet */ #define IRQ_AUTODETECT_2_6_17 16 /* IRQ is being autodetected */ #define IRQ_WAITING_2_6_17 32 /* IRQ not yet seen - for autodetection */ #define IRQ_LEVEL_2_6_17 64 /* IRQ level triggered */ #define IRQ_MASKED_2_6_17 128 /* IRQ masked - shouldn't be seen again */ /* * For kernel 2.6.21 and later */ #define IRQ_TYPE_NONE_2_6_21 0x00000000 /* Default, unspecified type */ #define IRQ_TYPE_EDGE_RISING_2_6_21 0x00000001 /* Edge rising type */ #define IRQ_TYPE_EDGE_FALLING_2_6_21 0x00000002 /* Edge falling type */ #define IRQ_TYPE_EDGE_BOTH_2_6_21 (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING) #define IRQ_TYPE_LEVEL_HIGH_2_6_21 0x00000004 /* Level high type */ #define IRQ_TYPE_LEVEL_LOW_2_6_21 0x00000008 /* Level low type */ #define IRQ_TYPE_SENSE_MASK_2_6_21 0x0000000f /* Mask of the above */ #define IRQ_TYPE_PROBE_2_6_21 0x00000010 /* Probing in progress */ #define IRQ_INPROGRESS_2_6_21 0x00000100 /* IRQ handler active - do not enter! */ #define IRQ_DISABLED_2_6_21 0x00000200 /* IRQ disabled - do not enter! */ #define IRQ_PENDING_2_6_21 0x00000400 /* IRQ pending - replay on enable */ #define IRQ_REPLAY_2_6_21 0x00000800 /* IRQ has been replayed but not acked yet */ #define IRQ_AUTODETECT_2_6_21 0x00001000 /* IRQ is being autodetected */ #define IRQ_WAITING_2_6_21 0x00002000 /* IRQ not yet seen - for autodetection */ #define IRQ_LEVEL_2_6_21 0x00004000 /* IRQ level triggered */ #define IRQ_MASKED_2_6_21 0x00008000 /* IRQ masked - shouldn't be seen again */ #define IRQ_PER_CPU_2_6_21 0x00010000 /* IRQ is per CPU */ #define IRQ_NOPROBE_2_6_21 0x00020000 /* IRQ is not valid for probing */ #define IRQ_NOREQUEST_2_6_21 0x00040000 /* IRQ cannot be requested */ #define IRQ_NOAUTOEN_2_6_21 0x00080000 /* IRQ will not be enabled on request irq */ #define IRQ_WAKEUP_2_6_21 0x00100000 /* IRQ triggers system wakeup */ #define IRQ_MOVE_PENDING_2_6_21 0x00200000 /* need to re-target IRQ destination */ #define IRQ_NO_BALANCING_2_6_21 0x00400000 /* IRQ is excluded from balancing */ #define IRQ_SPURIOUS_DISABLED_2_6_21 0x00800000 /* IRQ was disabled by the spurious trap */ #define IRQ_MOVE_PCNTXT_2_6_21 0x01000000 /* IRQ migration from process context */ #define IRQ_AFFINITY_SET_2_6_21 0x02000000 /* IRQ affinity was set from userspace*/ /* * Select proper IRQ value depending on kernel version */ #define IRQ_TYPE_NONE \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_NONE_2_6_21 : 0) #define IRQ_TYPE_EDGE_RISING \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_EDGE_RISING_2_6_21 : 0) #define IRQ_TYPE_EDGE_FALLING \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_EDGE_FALLING_2_6_21 : 0) #define IRQ_TYPE_EDGE_BOTH \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_EDGE_BOTH_2_6_21 : 0) #define IRQ_TYPE_LEVEL_HIGH \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_LEVEL_HIGH_2_6_21 : 0) #define IRQ_TYPE_LEVEL_LOW \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_LEVEL_LOW_2_6_21 : 0) #define IRQ_TYPE_SENSE_MASK \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_SENSE_MASK_2_6_21 : 0) #define IRQ_TYPE_PROBE \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_PROBE_2_6_21 : 0) #define IRQ_INPROGRESS \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_INPROGRESS_2_6_21 : IRQ_INPROGRESS_2_6_17) #define IRQ_DISABLED \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_DISABLED_2_6_21 : IRQ_DISABLED_2_6_17) #define IRQ_PENDING \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_PENDING_2_6_21 : IRQ_PENDING_2_6_17) #define IRQ_REPLAY \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_REPLAY_2_6_21 : IRQ_REPLAY_2_6_17) #define IRQ_AUTODETECT \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_AUTODETECT_2_6_21 : IRQ_AUTODETECT_2_6_17) #define IRQ_WAITING \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_WAITING_2_6_21 : IRQ_WAITING_2_6_17) #define IRQ_LEVEL \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_LEVEL_2_6_21 : IRQ_LEVEL_2_6_17) #define IRQ_MASKED \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_MASKED_2_6_21 : IRQ_MASKED_2_6_17) #define IRQ_PER_CPU \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_PER_CPU_2_6_21 : 0) #define IRQ_NOPROBE \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_NOPROBE_2_6_21 : 0) #define IRQ_NOREQUEST \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_NOREQUEST_2_6_21 : 0) #define IRQ_NOAUTOEN \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_NOAUTOEN_2_6_21 : 0) #define IRQ_WAKEUP \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_WAKEUP_2_6_21 : 0) #define IRQ_MOVE_PENDING \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_MOVE_PENDING_2_6_21 : 0) #define IRQ_NO_BALANCING \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_NO_BALANCING_2_6_21 : 0) #define IRQ_SPURIOUS_DISABLED \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_SPURIOUS_DISABLED_2_6_21 : 0) #define IRQ_MOVE_PCNTXT \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_MOVE_PCNTXT_2_6_21 : 0) #define IRQ_AFFINITY_SET \ (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_AFFINITY_SET_2_6_21 : 0) #ifdef ARM #define SA_PROBE SA_ONESHOT #define SA_SAMPLE_RANDOM SA_RESTART #define SA_SHIRQ 0x04000000 #define SA_RESTORER 0x04000000 #endif #ifdef X86 #define SA_PROBE SA_ONESHOT #define SA_SAMPLE_RANDOM SA_RESTART #define SA_SHIRQ 0x04000000 #define SA_RESTORER 0x04000000 #endif #ifdef X86_64 #define SA_PROBE SA_ONESHOT #define SA_SAMPLE_RANDOM SA_RESTART #define SA_SHIRQ 0x04000000 #define SA_RESTORER 0x04000000 #endif #ifdef ALPHA #define SA_PROBE SA_ONESHOT #define SA_SAMPLE_RANDOM SA_RESTART #define SA_SHIRQ 0x40000000 #endif #ifdef PPC #define SA_PROBE SA_ONESHOT #define SA_SAMPLE_RANDOM SA_RESTART #define SA_SHIRQ 0x04000000 #define SA_RESTORER 0x04000000 #endif #ifdef PPC64 #define SA_PROBE SA_ONESHOT #define SA_SAMPLE_RANDOM SA_RESTART #define SA_SHIRQ 0x04000000 #define SA_RESTORER 0x04000000u #endif #ifdef IA64 #define SA_PROBE SA_ONESHOT #define SA_SAMPLE_RANDOM SA_RESTART #define SA_SHIRQ 0x04000000 #define SA_RESTORER 0x04000000 #endif #ifdef S390 #define SA_PROBE SA_ONESHOT #define SA_SAMPLE_RANDOM SA_RESTART #define SA_SHIRQ 0x04000000 #define SA_RESTORER 0x04000000 #endif #ifdef S390X #define SA_PROBE SA_ONESHOT #define SA_SAMPLE_RANDOM SA_RESTART #define SA_SHIRQ 0x04000000 #define SA_RESTORER 0x04000000 #endif #define ACTION_FLAGS (SA_INTERRUPT|SA_PROBE|SA_SAMPLE_RANDOM|SA_SHIRQ) #endif /* !GDB_COMMON */ typedef enum drill_ops_s { EOP_MEMBER_SIZES, EOP_MEMBER_NAME, EOP_POINTER, EOP_TYPEDEF, EOP_INT, EOP_VALUE, EOP_ARRAY, EOP_UNION, EOP_ENUM, EOP_ENUMVAL, EOP_STRUCT, EOP_FUNCTION, EOP_DONE, EOP_OOPS } drill_ops_t; /* * Common request structure for BFD or GDB data or commands. */ struct gnu_request { int command; char *buf; FILE *fp; ulong addr; ulong addr2; ulong count; ulong flags; char *name; ulong length; int typecode; #if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) || defined(GDB_7_0) char *typename; #else char *type_name; #endif char *target_typename; ulong target_length; int target_typecode; int is_typedef; char *member; long member_offset; long member_length; int member_typecode; long value; const char *tagname; ulong pc; ulong sp; ulong ra; int curframe; ulong frame; ulong prevsp; ulong prevpc; ulong lastsp; ulong task; ulong debug; struct stack_hook *hookp; ulong lowest; ulong highest; void (*callback) (struct gnu_request *req, void *data); void *callback_data; struct load_module *lm; char *member_main_type_name; char *member_main_type_tag_name; char *member_target_type_name; char *member_target_type_tag_name; char *type_tag_name; /* callback function for 3rd party symbol and type (EPPIC for now) */ void *priv; int (*tcb)(drill_ops_t, struct gnu_request *, const void *, const void *, const void *, const void *); }; /* * GNU commands */ #define GNU_DATATYPE_INIT (1) #define GNU_DISASSEMBLE (2) #define GNU_GET_LINE_NUMBER (3) #define GNU_PASS_THROUGH (4) #define GNU_GET_DATATYPE (5) #define GNU_COMMAND_EXISTS (6) #define GNU_STACK_TRACE (7) #define GNU_ALPHA_FRAME_OFFSET (8) #define GNU_FUNCTION_NUMARGS (9) #define GNU_RESOLVE_TEXT_ADDR (10) #define GNU_ADD_SYMBOL_FILE (11) #define GNU_DELETE_SYMBOL_FILE (12) #define GNU_VERSION (13) #define GNU_PATCH_SYMBOL_VALUES (14) #define GNU_GET_SYMBOL_TYPE (15) #define GNU_USER_PRINT_OPTION (16) #define GNU_SET_CRASH_BLOCK (17) #define GNU_GET_FUNCTION_RANGE (18) #define GNU_ITERATE_DATATYPES (19) #define GNU_LOOKUP_STRUCT_CONTENTS (20) #define GNU_DEBUG_COMMAND (100) /* * GNU flags */ #define GNU_PRINT_LINE_NUMBERS (0x1) #define GNU_FUNCTION_ONLY (0x2) #define GNU_PRINT_ENUMERATORS (0x4) #define GNU_RETURN_ON_ERROR (0x8) #define GNU_COMMAND_FAILED (0x10) #define GNU_FROM_TTY_OFF (0x20) #define GNU_NO_READMEM (0x40) #define GNU_VAR_LENGTH_TYPECODE (0x80) #undef TRUE #undef FALSE #define TRUE (1) #define FALSE (0) #ifdef GDB_COMMON /* * function prototypes required by modified gdb source files. */ extern "C" int console(const char *, ...); extern "C" int gdb_CRASHDEBUG(ulong); int gdb_readmem_callback(ulong, void *, int, int); void patch_load_module(struct objfile *objfile, struct minimal_symbol *msymbol); extern "C" int patch_kernel_symbol(struct gnu_request *); struct syment *symbol_search(char *); int gdb_line_number_callback(ulong, ulong, ulong); int gdb_print_callback(ulong); char *gdb_lookup_module_symbol(ulong, ulong *); extern "C" int same_file(char *, char *); #endif #ifndef GDB_COMMON /* * WARNING: the following type codes are type_code enums from gdb/gdbtypes.h */ enum type_code { TYPE_CODE_UNDEF, /* Not used; catches errors */ TYPE_CODE_PTR, /* Pointer type */ TYPE_CODE_ARRAY, /* Array type with lower & upper bounds. */ TYPE_CODE_STRUCT, /* C struct or Pascal record */ TYPE_CODE_UNION, /* C union or Pascal variant part */ TYPE_CODE_ENUM, /* Enumeration type */ #if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) || defined(GDB_7_0) || defined(GDB_7_3_1) || defined(GDB_7_6) || defined(GDB_10_2) || defined(GDB_16_2) #if defined(GDB_7_0) || defined(GDB_7_3_1) || defined(GDB_7_6) || defined(GDB_10_2) || defined(GDB_16_2) TYPE_CODE_FLAGS, /* Bit flags type */ #endif TYPE_CODE_FUNC, /* Function type */ TYPE_CODE_INT, /* Integer type */ /* Floating type. This is *NOT* a complex type. Beware, there are parts of GDB which bogusly assume that TYPE_CODE_FLT can mean complex. */ TYPE_CODE_FLT, /* Void type. The length field specifies the length (probably always one) which is used in pointer arithmetic involving pointers to this type, but actually dereferencing such a pointer is invalid; a void type has no length and no actual representation in memory or registers. A pointer to a void type is a generic pointer. */ TYPE_CODE_VOID, TYPE_CODE_SET, /* Pascal sets */ TYPE_CODE_RANGE, /* Range (integers within spec'd bounds) */ /* * NOTE: the remainder of the type codes are not list or used here... */ TYPE_CODE_BOOL = 20, #endif }; /* * include/linux/sched.h */ #define PF_EXITING 0x00000004 /* getting shut down */ #define PF_KTHREAD 0x00200000 /* I am a kernel thread */ #define SCHED_NORMAL 0 #define SCHED_FIFO 1 #define SCHED_RR 2 #define SCHED_BATCH 3 #define SCHED_ISO 4 #define SCHED_IDLE 5 #define SCHED_DEADLINE 6 extern long _ZOMBIE_; #define IS_ZOMBIE(task) (task_state(task) & _ZOMBIE_) #define IS_EXITING(task) (task_flags(task) & PF_EXITING) /* * ps command options. */ #define PS_BY_PID (0x1) #define PS_BY_TASK (0x2) #define PS_BY_CMD (0x4) #define PS_SHOW_ALL (0x8) #define PS_PPID_LIST (0x10) #define PS_CHILD_LIST (0x20) #define PS_KERNEL (0x40) #define PS_USER (0x80) #define PS_TIMES (0x100) #define PS_KSTACKP (0x200) #define PS_LAST_RUN (0x400) #define PS_ARGV_ENVP (0x800) #define PS_TGID_LIST (0x1000) #define PS_RLIMIT (0x2000) #define PS_GROUP (0x4000) #define PS_BY_REGEX (0x8000) #define PS_NO_HEADER (0x10000) #define PS_MSECS (0x20000) #define PS_SUMMARY (0x40000) #define PS_POLICY (0x80000) #define PS_ACTIVE (0x100000) #define PS_EXCLUSIVE (PS_TGID_LIST|PS_ARGV_ENVP|PS_TIMES|PS_CHILD_LIST|PS_PPID_LIST|PS_LAST_RUN|PS_RLIMIT|PS_MSECS|PS_SUMMARY|PS_ACTIVE) #define MAX_PS_ARGS (100) /* maximum command-line specific requests */ struct psinfo { int argc; ulong pid[MAX_PS_ARGS]; int type[MAX_PS_ARGS]; ulong task[MAX_PS_ARGS]; char comm[MAX_PS_ARGS][TASK_COMM_LEN+1]; struct regex_data { char *pattern; regex_t regex; } regex_data[MAX_PS_ARGS]; int regexs; ulong *cpus; int policy; }; #define IS_A_NUMBER(X) (decimal(X, 0) || hexadecimal(X, 0)) #define AMBIGUOUS_NUMBER(X) (decimal(X, 0) && hexadecimal(X, 0)) #define is_mclx_compressed_dump(X) (va_server_init((X), 0, 0, 0) == 0) struct task_mem_usage { ulong rss; ulong total_vm; double pct_physmem; ulong mm_struct_addr; ulong pgd_addr; }; /* * Global data (global_data.c) */ extern FILE *fp; extern struct program_context program_context, *pc; extern struct task_table task_table, *tt; extern struct kernel_table kernel_table, *kt; extern struct command_table_entry linux_command_table[]; extern char *args[MAXARGS]; extern int argcnt; extern int argerrs; extern struct offset_table offset_table; extern struct size_table size_table; extern struct array_table array_table; extern struct vm_table vm_table, *vt; extern struct machdep_table *machdep; extern struct symbol_table_data symbol_table_data, *st; extern struct extension_table *extension_table; /* * Generated in build_data.c */ extern char *build_command; extern char *build_data; extern char *build_target; extern char *build_version; extern char *compiler_version; /* * command prototypes */ void cmd_quit(void); /* main.c */ void cmd_mach(void); /* main.c */ void cmd_help(void); /* help.c */ void cmd_test(void); /* test.c */ void cmd_ascii(void); /* tools.c */ void cmd_sbitmapq(void); /* sbitmap.c */ void cmd_bpf(void); /* bfp.c */ void cmd_set(void); /* tools.c */ void cmd_eval(void); /* tools.c */ void cmd_list(void); /* tools.c */ void cmd_tree(void); /* tools.c */ void cmd_template(void); /* tools.c */ void cmd_alias(void); /* cmdline.c */ void cmd_repeat(void); /* cmdline.c */ void cmd_rd(void); /* memory.c */ void cmd_wr(void); /* memory.c */ void cmd_ptov(void); /* memory.c */ void cmd_vtop(void); /* memory.c */ void cmd_vm(void); /* memory.c */ void cmd_ptob(void); /* memory.c */ void cmd_btop(void); /* memory.c */ void cmd_kmem(void); /* memory.c */ void cmd_search(void); /* memory.c */ void cmd_swap(void); /* memory.c */ void cmd_pte(void); /* memory.c */ void cmd_ps(void); /* task.c */ void cmd_task(void); /* task.c */ void cmd_foreach(void); /* task.c */ void cmd_runq(void); /* task.c */ void cmd_sig(void); /* task.c */ void cmd_bt(void); /* kernel.c */ void cmd_dis(void); /* kernel.c */ void cmd_mod(void); /* kernel.c */ void cmd_log(void); /* kernel.c */ void cmd_sys(void); /* kernel.c */ void cmd_irq(void); /* kernel.c */ void cmd_timer(void); /* kernel.c */ void cmd_waitq(void); /* kernel.c */ void cmd_sym(void); /* symbols.c */ void cmd_struct(void); /* symbols.c */ void cmd_union(void); /* symbols.c */ void cmd_pointer(void); /* symbols.c */ void cmd_whatis(void); /* symbols.c */ void cmd_p(void); /* symbols.c */ void cmd_mount(void); /* filesys.c */ void cmd_files(void); /* filesys.c */ void cmd_fuser(void); /* filesys.c */ void cmd_dev(void); /* dev.c */ void cmd_gdb(void); /* gdb_interface.c */ void cmd_net(void); /* net.c */ void cmd_extend(void); /* extensions.c */ #if defined(S390) || defined(S390X) void cmd_s390dbf(void); #endif void cmd_map(void); /* kvmdump.c */ void cmd_ipcs(void); /* ipcs.c */ void cmd_rustfilt(void); /* symbols.c */ /* * main.c */ void main_loop(void); void exec_command(void); struct command_table_entry *get_command_table_entry(char *); void program_usage(int); #define LONG_FORM (1) #define SHORT_FORM (0) void dump_program_context(void); void dump_build_data(void); #ifdef ARM #define machdep_init(X) arm_init(X) #endif #ifdef ARM64 #define machdep_init(X) arm64_init(X) #endif #ifdef X86 #define machdep_init(X) x86_init(X) #endif #ifdef ALPHA #define machdep_init(X) alpha_init(X) #endif #ifdef PPC #define machdep_init(X) ppc_init(X) #endif #ifdef IA64 #define machdep_init(X) ia64_init(X) #endif #ifdef S390 #define machdep_init(X) s390_init(X) #endif #ifdef S390X #define machdep_init(X) s390x_init(X) #endif #ifdef X86_64 #define machdep_init(X) x86_64_init(X) #endif #ifdef PPC64 #define machdep_init(X) ppc64_init(X) #endif #ifdef MIPS #define machdep_init(X) mips_init(X) #endif #ifdef MIPS64 #define machdep_init(X) mips64_init(X) #endif #ifdef RISCV64 #define machdep_init(X) riscv64_init(X) #endif #ifdef SPARC64 #define machdep_init(X) sparc64_init(X) #endif #ifdef LOONGARCH64 #define machdep_init(X) loongarch64_init(X) #endif int clean_exit(int); int untrusted_file(FILE *, char *); char *readmem_function_name(void); char *writemem_function_name(void); char *no_vmcoreinfo(const char *); /* * cmdline.c */ void restart(int); void alias_init(char *); struct alias_data *is_alias(char *); void deallocate_alias(char *); void cmdline_init(void); void set_command_prompt(char *); void exec_input_file(void); void process_command_line(void); void dump_history(void); void resolve_rc_cmd(char *, int); void dump_alias_data(void); int output_open(void); #define output_closed() (!output_open()) void close_output(void); int interruptible(void); int received_SIGINT(void); void debug_redirect(char *); int CRASHPAGER_valid(void); char *setup_scroll_command(void); int minimal_functions(char *); int is_args_input_file(struct command_table_entry *, struct args_input_file *); void exec_args_input_file(struct command_table_entry *, struct args_input_file *); /* * tools.c */ extern int MAX_MALLOC_BUFS; FILE *set_error(char *); int __error(int, char *, ...); #define error __error /* avoid conflict with gdb error() */ int console(const char *, ...); void create_console_device(char *); int console_off(void); int console_on(int); int console_verbatim(char *); int whitespace(int); int ascii(int); int ascii_string(char *); int printable_string(char *); char *clean_line(char *); char *strip_line_end(char *); char *strip_linefeeds(char *); char *strip_beginning_whitespace(char *); char *strip_ending_whitespace(char *); char *strip_ending_char(char *, char); char *strip_beginning_char(char *, char); char *strip_comma(char *); char *strip_hex(char *); char *upper_case(const char *, char *); char *first_nonspace(char *); char *first_space(char *); char *replace_string(char *, char *, char); void string_insert(char *, char *); char *strstr_rightmost(char *, char *); char *null_first_space(char *); int parse_line(char *, char **); void print_verbatim(FILE *, char *); char *fixup_percent(char *); int can_eval(char *); ulong eval(char *, int, int *); ulonglong evall(char *, int, int *); int eval_common(char *, int, int *, struct number_option *); ulong htol(char *, int, int *); ulong dtol(char *, int, int *); unsigned int dtoi(char *, int, int *); ulong stol(char *, int, int *); ulonglong stoll(char *, int, int *); ulonglong htoll(char *, int, int *); ulonglong dtoll(char *, int, int *); int decimal(char *, int); int hexadecimal(char *, int); int hexadecimal_only(char *, int); ulong convert(char *, int, int *, ulong); void pad_line(FILE *, int, char); #define INDENT(x) pad_line(fp, x, ' ') char *mkstring(char *, int, ulong, const char *); #define MKSTR(X) ((const char *)(X)) int count_leading_spaces(char *); int count_chars(char *, char); long count_buffer_chars(char *, char, long); char *space(int); char *concat_args(char *, int, int); char *shift_string_left(char *, int); char *shift_string_right(char *, int); int bracketed(char *, char *, int); void backspace(int); int do_list(struct list_data *); int do_list_no_hash(struct list_data *); struct radix_tree_ops { void (*entry)(ulong node, ulong slot, const char *path, ulong index, void *private); uint radix; void *private; }; int do_radix_tree_traverse(ulong ptr, int is_root, struct radix_tree_ops *ops); struct xarray_ops { void (*entry)(ulong node, ulong slot, const char *path, ulong index, void *private); uint radix; void *private; }; int do_xarray_traverse(ulong ptr, int is_root, struct xarray_ops *ops); int do_rdtree(struct tree_data *); int do_rbtree(struct tree_data *); int do_xatree(struct tree_data *); int retrieve_list(ulong *, int); long power(long, int); long long ll_power(long long, long long); void hq_init(void); int hq_open(void); int hq_close(void); int hq_enter(ulong); int hq_entry_exists(ulong); int hq_is_open(void); int hq_is_inuse(void); long get_embedded(void); void dump_embedded(char *); char *ordinal(ulong, char *); char *first_nonspace(char *); void dump_hash_table(int); void dump_shared_bufs(void); void drop_core(char *); int extract_hex(char *, ulong *, char, ulong); int count_bits_int(int); int count_bits_long(ulong); int highest_bit_long(ulong); int lowest_bit_long(ulong); void buf_init(void); void sym_buf_init(void); void free_all_bufs(void); char *getbuf(long); void freebuf(char *); char *resizebuf(char *, long, long); char *strdupbuf(char *); #define GETBUF(X) getbuf((long)(X)) #define FREEBUF(X) freebuf((char *)(X)) #define RESIZEBUF(X,Y,Z) (X) = (typeof(X))resizebuf((char *)(X), (long)(Y), (long)(Z)); #define STRDUPBUF(X) strdupbuf((char *)(X)) void sigsetup(int, void *, struct sigaction *, struct sigaction *); #define SIGACTION(s, h, a, o) sigsetup(s, h, a, o) char *convert_time(ulonglong, char *); char *ctime_tz(time_t *); void stall(ulong); char *pages_to_size(ulong, char *); int clean_arg(void); int empty_list(ulong); int machine_type(char *); int machine_type_mismatch(char *, char *, char *, ulong); void command_not_supported(void); void option_not_supported(int); void please_wait(char *); void please_wait_done(void); int pathcmp(char *, char *); int calculate(char *, ulong *, ulonglong *, ulong); int endian_mismatch(char *, char, ulong); uint16_t swap16(uint16_t, int); uint32_t swap32(uint32_t, int); uint64_t swap64(uint64_t, int); ulong *get_cpumask_buf(void); int make_cpumask(char *, ulong *, int, int *); size_t strlcpy(char *, const char *, size_t) __attribute__ ((__weak__)); struct rb_node *rb_first(struct rb_root *); struct rb_node *rb_parent(struct rb_node *, struct rb_node *); struct rb_node *rb_right(struct rb_node *, struct rb_node *); struct rb_node *rb_left(struct rb_node *, struct rb_node *); struct rb_node *rb_next(struct rb_node *); struct rb_node *rb_last(struct rb_root *); long percpu_counter_sum_positive(ulong fbc); ulong get_subsys_private(char *, char *); /* * symbols.c */ void symtab_init(void); char *check_specified_kernel_debug_file(void); void no_debugging_data(int); void get_text_init_space(void); int is_kernel_text(ulong); int is_kernel_data(ulong); int is_init_data(ulong value); int is_kernel_text_offset(ulong); int is_symbol_text(struct syment *); int is_rodata(ulong, struct syment **); int get_text_function_range(ulong, ulong *, ulong *); void datatype_init(void); struct syment *symbol_search(char *); struct syment *value_search(ulong, ulong *); struct syment *value_search_base_kernel(ulong, ulong *); struct syment *value_search_module(ulong, ulong *); struct syment *symbol_search_next(char *, struct syment *); ulong highest_bss_symbol(void); int in_ksymbol_range(ulong); int module_symbol(ulong, struct syment **, struct load_module **, char *, ulong); #define IS_MODULE_VADDR(X) \ (module_symbol((ulong)(X), NULL, NULL, NULL, *gdb_output_radix)) char *closest_symbol(ulong); ulong closest_symbol_value(ulong); #define SAME_FUNCTION(X,Y) (closest_symbol_value(X) == closest_symbol_value(Y)) void show_symbol(struct syment *, ulong, ulong); #define SHOW_LINENUM (0x1) #define SHOW_SECTION (0x2) #define SHOW_HEX_OFFS (0x4) #define SHOW_DEC_OFFS (0x8) #define SHOW_RADIX() (*gdb_output_radix == 16 ? SHOW_HEX_OFFS : SHOW_DEC_OFFS) #define SHOW_MODULE (0x10) int symbol_name_count(char *); int symbol_query(char *, char *, struct syment **); struct syment *next_symbol(char *, struct syment *); struct syment *prev_symbol(char *, struct syment *); void get_symbol_data(char *, long, void *); int try_get_symbol_data(char *, long, void *); char *value_to_symstr(ulong, char *, ulong); char *value_symbol(ulong); ulong symbol_value(char *); ulong symbol_value_module(char *, char *); struct syment *per_cpu_symbol_search(char *); int symbol_exists(char *s); int kernel_symbol_exists(char *s); struct syment *kernel_symbol_search(char *); ulong symbol_value_from_proc_kallsyms(char *); int get_syment_array(char *, struct syment **, int); void set_temporary_radix(unsigned int, unsigned int *); void restore_current_radix(unsigned int); void dump_struct(char *, ulong, unsigned); void dump_struct_member(char *, ulong, unsigned); void dump_union(char *, ulong, unsigned); void store_module_symbols_v1(ulong, int); void store_module_symbols_v2(ulong, int); void store_module_symbols_6_4(ulong, int); int is_datatype_command(void); int is_typedef(char *); int arg_to_datatype(char *, struct datatype_member *, ulong); void dump_symbol_table(void); void dump_struct_table(ulong); void dump_offset_table(char *, ulong); int is_elf_file(char *); int is_kernel(char *); int is_shared_object(char *); int file_elf_version(char *); int is_system_map(char *); int is_compressed_kernel(char *, char **); int select_namelist(char *); int get_array_length(char *, int *, long); int get_array_length_alt(char *, char *, int *, long); int builtin_array_length(char *, int, int *); char *get_line_number(ulong, char *, int); char *get_build_directory(char *); int datatype_exists(char *); int get_function_numargs(ulong); int is_module_name(char *, ulong *, struct load_module **); int is_module_address(ulong, char *); ulong lowest_module_address(void); ulong highest_module_address(void); int load_module_symbols(char *, char *, ulong); void delete_load_module(ulong); ulong gdb_load_module_callback(ulong, char *); char *load_module_filter(char *, int); #define LM_P_FILTER (1) #define LM_DIS_FILTER (2) long datatype_info(char *, char *, struct datatype_member *); int get_symbol_type(char *, char *, struct gnu_request *); int get_symbol_length(char *); void dump_numargs_cache(void); int patch_kernel_symbol(struct gnu_request *); struct syment *generic_machdep_value_to_symbol(ulong, ulong *); long OFFSET_verify(long, char *, char *, int, char *); long SIZE_verify(long, char *, char *, int, char *); long OFFSET_option(long, long, char *, char *, int, char *, char *); long SIZE_option(long, long, char *, char *, int, char *, char *); void dump_trace(void **); int enumerator_value(char *, long *); int dump_enumerator_list(char *); struct load_module *init_module_function(ulong); struct struct_member_data { char *structure; char *member; long type; long unsigned_type; long length; long offset; long bitpos; long bitsize; }; int fill_struct_member_data(struct struct_member_data *); void parse_for_member_extended(struct datatype_member *, ulong); void add_to_downsized(char *); int is_downsized(char *); int is_string(char *, char *); struct syment *symbol_complete_match(const char *, struct syment *); /* * memory.c */ void mem_init(void); void vm_init(void); int readmem(ulonglong, int, void *, long, char *, ulong); int writemem(ulonglong, int, void *, long, char *, ulong); int generic_verify_paddr(uint64_t); int read_dev_mem(int, void *, int, ulong, physaddr_t); int read_memory_device(int, void *, int, ulong, physaddr_t); int read_mclx_dumpfile(int, void *, int, ulong, physaddr_t); int read_lkcd_dumpfile(int, void *, int, ulong, physaddr_t); int read_daemon(int, void *, int, ulong, physaddr_t); int write_dev_mem(int, void *, int, ulong, physaddr_t); int write_memory_device(int, void *, int, ulong, physaddr_t); int write_mclx_dumpfile(int, void *, int, ulong, physaddr_t); int write_lkcd_dumpfile(int, void *, int, ulong, physaddr_t); int write_daemon(int, void *, int, ulong, physaddr_t); int kvtop(struct task_context *, ulong, physaddr_t *, int); int uvtop(struct task_context *, ulong, physaddr_t *, int); void do_vtop(ulong, struct task_context *, ulong); void raw_stack_dump(ulong, ulong); void raw_data_dump(ulong, long, int); int accessible(ulong); ulong vm_area_dump(ulong, ulong, ulong, struct reference *); #define IN_TASK_VMA(TASK,VA) (vm_area_dump((TASK), UVADDR|VERIFY_ADDR, (VA), 0)) char *fill_vma_cache(ulong); void clear_vma_cache(void); void dump_vma_cache(ulong); int generic_is_page_ptr(ulong, physaddr_t *); int is_page_ptr(ulong, physaddr_t *); void dump_vm_table(int); int read_string(ulong, char *, int); void get_task_mem_usage(ulong, struct task_mem_usage *); char *get_memory_size(char *); uint64_t generic_memory_size(void); char *swap_location(ulonglong, char *); void clear_swap_info_cache(void); uint memory_page_size(void); void force_page_size(char *); ulong first_vmalloc_address(void); ulong last_vmalloc_address(void); int in_vmlist_segment(ulong); int phys_to_page(physaddr_t, ulong *); int generic_get_kvaddr_ranges(struct vaddr_range *); int l1_cache_size(void); int dumpfile_memory(int); #define DUMPFILE_MEM_USED (1) #define DUMPFILE_FREE_MEM (2) #define DUMPFILE_MEM_DUMP (3) #define DUMPFILE_ENVIRONMENT (4) uint64_t total_node_memory(void); int generic_is_kvaddr(ulong); int generic_is_uvaddr(ulong, struct task_context *); void fill_stackbuf(struct bt_info *); void alter_stackbuf(struct bt_info *); int vaddr_type(ulong, struct task_context *); char *format_stack_entry(struct bt_info *bt, char *, ulong, ulong); int in_user_stack(ulong, ulong); int dump_inode_page(ulong); ulong valid_section_nr(ulong); void display_memory_from_file_offset(ulonglong, long, void *); void swap_info_init(void); /* * filesys.c */ void fd_init(void); void vfs_init(void); int is_a_tty(char *); int file_exists(char *, struct stat *); int file_readable(char *); int is_directory(char *); char *search_directory_tree(char *, char *, int); void open_tmpfile(void); void close_tmpfile(void); void open_tmpfile2(void); void set_tmpfile2(FILE *); void close_tmpfile2(void); void open_files_dump(ulong, int, struct reference *); void get_pathname(ulong, char *, int, int, ulong); ulong *get_mount_list(int *, struct task_context *); char *vfsmount_devname(ulong, char *, int); ulong file_to_dentry(ulong); ulong file_to_vfsmnt(ulong); int get_proc_version(void); int file_checksum(char *, long *); void dump_filesys_table(int); char *fill_file_cache(ulong); void clear_file_cache(void); char *fill_dentry_cache(ulong); void clear_dentry_cache(void); char *fill_inode_cache(ulong); void clear_inode_cache(void); int monitor_memory(long *, long *, long *, long *); int is_readable(char *); struct list_pair { ulong index; void *value; }; #define radix_tree_pair list_pair ulong do_radix_tree(ulong, int, struct list_pair *); #define RADIX_TREE_COUNT (1) #define RADIX_TREE_SEARCH (2) #define RADIX_TREE_DUMP (3) #define RADIX_TREE_GATHER (4) #define RADIX_TREE_DUMP_CB (5) /* * from: "include/linux/radix-tree.h" */ #define RADIX_TREE_ENTRY_MASK 3UL #define RADIX_TREE_EXCEPTIONAL_ENTRY 2 ulong do_xarray(ulong, int, struct list_pair *); #define XARRAY_COUNT (1) #define XARRAY_SEARCH (2) #define XARRAY_DUMP (3) #define XARRAY_GATHER (4) #define XARRAY_DUMP_CB (5) #define XARRAY_TAG_MASK (3UL) #define XARRAY_TAG_INTERNAL (2UL) int file_dump(ulong, ulong, ulong, int, int); #define DUMP_FULL_NAME 0x1 #define DUMP_INODE_ONLY 0x2 #define DUMP_DENTRY_ONLY 0x4 #define DUMP_EMPTY_FILE 0x8 #define DUMP_FILE_NRPAGES 0x10 int same_file(char *, char *); int cleanup_memory_driver(void); void maple_init(void); int do_mptree(struct tree_data *); ulong do_maple_tree(ulong, int, struct list_pair *); #define MAPLE_TREE_COUNT (1) #define MAPLE_TREE_SEARCH (2) #define MAPLE_TREE_DUMP (3) #define MAPLE_TREE_GATHER (4) #define MAPLE_TREE_DUMP_CB (5) /* * help.c */ #define HELP_COLUMNS 5 #define START_OF_HELP_DATA(X) "START_OF_HELP_DATA" X #define END_OF_HELP_DATA "END_OF_HELP_DATA" void help_init(void); void cmd_usage(char *, int); void display_version(void); void display_help_screen(char *); #ifdef ARM #define dump_machdep_table(X) arm_dump_machdep_table(X) #endif #ifdef ARM64 #define dump_machdep_table(X) arm64_dump_machdep_table(X) #endif #ifdef X86 #define dump_machdep_table(X) x86_dump_machdep_table(X) #endif #ifdef ALPHA #define dump_machdep_table(X) alpha_dump_machdep_table(X) #endif #ifdef PPC #define dump_machdep_table(X) ppc_dump_machdep_table(X) #endif #ifdef IA64 #define dump_machdep_table(X) ia64_dump_machdep_table(X) #endif #ifdef S390 #define dump_machdep_table(X) s390_dump_machdep_table(X) #endif #ifdef S390X #define dump_machdep_table(X) s390x_dump_machdep_table(X) #endif #ifdef X86_64 #define dump_machdep_table(X) x86_64_dump_machdep_table(X) #endif #ifdef PPC64 #define dump_machdep_table(X) ppc64_dump_machdep_table(X) #endif #ifdef MIPS #define dump_machdep_table(X) mips_dump_machdep_table(X) #endif #ifdef MIPS64 #define dump_machdep_table(X) mips64_dump_machdep_table(X) #endif #ifdef SPARC64 #define dump_machdep_table(X) sparc64_dump_machdep_table(X) #endif #ifdef RISCV64 #define dump_machdep_table(X) riscv64_dump_machdep_table(X) #endif #ifdef LOONGARCH64 #define dump_machdep_table(X) loongarch64_dump_machdep_table(X) #endif extern char *help_pointer[]; extern char *help_alias[]; extern char *help_ascii[]; extern char *help_bpf[]; extern char *help_bt[]; extern char *help_btop[]; extern char *help_dev[]; extern char *help_dis[]; extern char *help_eval[]; extern char *help_exit[]; extern char *help_extend[]; extern char *help_files[]; extern char *help_foreach[]; extern char *help_fuser[]; extern char *help_gdb[]; extern char *help_help[]; extern char *help_irq[]; extern char *help_kmem[]; extern char *help__list[]; extern char *help_tree[]; extern char *help_log[]; extern char *help_mach[]; extern char *help_mod[]; extern char *help_mount[]; extern char *help_net[]; extern char *help_p[]; extern char *help_ps[]; extern char *help_pte[]; extern char *help_ptob[]; extern char *help_ptov[]; extern char *help_quit[]; extern char *help_rd[]; extern char *help_repeat[]; extern char *help_runq[]; extern char *help_ipcs[]; extern char *help_sbitmapq[]; extern char *help_search[]; extern char *help_set[]; extern char *help_sig[]; extern char *help_struct[]; extern char *help_swap[]; extern char *help_sym[]; extern char *help_sys[]; extern char *help_task[]; extern char *help_timer[]; extern char *help_union[]; extern char *help_vm[]; extern char *help_vtop[]; extern char *help_waitq[]; extern char *help_whatis[]; extern char *help_wr[]; #if defined(S390) || defined(S390X) extern char *help_s390dbf[]; #endif extern char *help_map[]; extern char *help_rustfilt[]; /* * task.c */ void task_init(void); int set_context(ulong, ulong, uint); void show_context(struct task_context *); ulong pid_to_task(ulong); ulong task_to_pid(ulong); int task_exists(ulong); int is_kernel_thread(ulong); int is_idle_thread(ulong); void get_idle_threads(ulong *, int); char *task_state_string(ulong, char *, int); ulong task_flags(ulong); ulong task_state(ulong); ulong task_mm(ulong, int); ulong task_tgid(ulong); ulonglong task_last_run(ulong); ulong vaddr_in_task_struct(ulong); int comm_exists(char *); struct task_context *task_to_context(ulong); struct task_context *pid_to_context(ulong); struct task_context *tgid_to_context(ulong); ulong stkptr_to_task(ulong); ulong task_to_thread_info(ulong); ulong task_to_stackbase(ulong); int str_to_context(char *, ulong *, struct task_context **); #define STR_PID (0x1) #define STR_TASK (0x2) #define STR_INVALID (0x4) char *get_panicmsg(char *); char *task_cpu(int, char *, int); void print_task_header(FILE *, struct task_context *, int); ulong get_active_task(int); int is_task_active(ulong); int is_panic_thread(ulong); int get_panic_ksp(struct bt_info *, ulong *); void foreach(struct foreach_data *); int pid_exists(ulong); #define TASKS_PER_PID(x) pid_exists(x) char *fill_task_struct(ulong); #define IS_LAST_TASK_READ(task) ((ulong)(task) == tt->last_task_read) char *fill_thread_info(ulong); #define IS_LAST_THREAD_INFO_READ(ti) ((ulong)(ti) == tt->last_thread_info_read) char *fill_mm_struct(ulong); #define IS_LAST_MM_READ(mm) ((ulong)(mm) == tt->last_mm_read) void do_task(ulong, ulong, struct reference *, unsigned int); void clear_task_cache(void); int get_active_set(void); void clear_active_set(void); void do_sig(ulong, ulong, struct reference *); void modify_signame(int, char *, char *); ulong generic_get_stackbase(ulong); ulong generic_get_stacktop(ulong); void dump_task_table(int); void sort_context_array(void); void sort_tgid_array(void); int sort_by_tgid(const void *, const void *); int in_irq_ctx(ulonglong, int, ulong); void check_stack_overflow(void); /* * extensions.c */ void register_extension(struct command_table_entry *); void dump_extension_table(int); void load_extension(char *); void unload_extension(char *); void preload_extensions(void); /* Hooks for sial */ unsigned long get_curtask(void); char *crash_global_cmd(void); struct command_table_entry *crash_cmd_table(void); /* * kernel.c */ void kernel_init(void); void module_init(void); void verify_version(void); void verify_spinlock(void); void non_matching_kernel(void); struct load_module *modref_to_load_module(char *); int load_module_symbols_helper(char *); void unlink_module(struct load_module *); int check_specified_module_tree(char *, char *); int is_system_call(char *, ulong); void get_dumpfile_regs(struct bt_info*, ulong*, ulong*); void generic_dump_irq(int); void generic_get_irq_affinity(int); void generic_show_interrupts(int, ulong *); int generic_dis_filter(ulong, char *, unsigned int); int kernel_BUG_encoding_bytes(void); void display_sys_stats(void); char *get_uptime(char *, ulonglong *); void clone_bt_info(struct bt_info *, struct bt_info *, struct task_context *); void dump_kernel_table(int); void dump_bt_info(struct bt_info *, char *where); void dump_log(int); void parse_kernel_version(char *); char *vmcoreinfo_read_from_memory(const char *); #define LOG_LEVEL(v) ((v) & 0x07) #define SHOW_LOG_LEVEL (0x1) #define SHOW_LOG_DICT (0x2) #define SHOW_LOG_TEXT (0x4) #define SHOW_LOG_AUDIT (0x8) #define SHOW_LOG_CTIME (0x10) #define SHOW_LOG_SAFE (0x20) #define SHOW_LOG_CALLER (0x40) #define SHOW_LOG_RUST (0x80) void set_cpu(int); void clear_machdep_cache(void); struct stack_hook *gather_text_list(struct bt_info *); int get_cpus_online(void); int get_cpus_active(void); int get_cpus_present(void); int get_cpus_possible(void); int check_offline_cpu(int); int hide_offline_cpu(int); int get_highest_cpu_online(void); int get_highest_cpu_present(void); int get_cpus_to_display(void); void get_log_from_vmcoreinfo(char *file); int in_cpu_map(int, int); void paravirt_init(void); void print_stack_text_syms(struct bt_info *, ulong, ulong); void back_trace(struct bt_info *); int in_alternate_stack(int, ulong); ulong cpu_map_addr(const char *type); #define BT_RAW (0x1ULL) #define BT_SYMBOLIC_ARGS (0x2ULL) #define BT_FULL (0x4ULL) #define BT_TEXT_SYMBOLS (0x8ULL) #define BT_TEXT_SYMBOLS_PRINT (0x10ULL) #define BT_TEXT_SYMBOLS_NOPRINT (0x20ULL) #define BT_USE_GDB (0x40ULL) #define BT_EXCEPTION_FRAME (0x80ULL) #define BT_LINE_NUMBERS (0x100ULL) #define BT_USER_EFRAME (0x200ULL) #define BT_INCOMPLETE_USER_EFRAME (BT_USER_EFRAME) #define BT_SAVE_LASTSP (0x400ULL) #define BT_FROM_EXCEPTION (0x800ULL) #define BT_FROM_CALLFRAME (0x1000ULL) #define BT_EFRAME_SEARCH (0x2000ULL) #define BT_SPECULATE (0x4000ULL) #define BT_FRAMESIZE_DISABLE (BT_SPECULATE) #define BT_RESCHEDULE (0x8000ULL) #define BT_SCHEDULE (BT_RESCHEDULE) #define BT_RET_FROM_SMP_FORK (0x10000ULL) #define BT_STRACE (0x20000ULL) #define BT_KDUMP_ADJUST (BT_STRACE) #define BT_KSTACKP (0x40000ULL) #define BT_LOOP_TRAP (0x80000ULL) #define BT_BUMP_FRAME_LEVEL (0x100000ULL) #define BT_EFRAME_COUNT (0x200000ULL) #define BT_CPU_IDLE (0x400000ULL) #define BT_WRAP_TRAP (0x800000ULL) #define BT_KERNEL_THREAD (0x1000000ULL) #define BT_ERROR_MASK (BT_LOOP_TRAP|BT_WRAP_TRAP|BT_KERNEL_THREAD|BT_CPU_IDLE) #define BT_UNWIND_ERROR (0x2000000ULL) #define BT_OLD_BACK_TRACE (0x4000000ULL) #define BT_OPT_BACK_TRACE (0x4000000ULL) #define BT_FRAMESIZE_DEBUG (0x8000000ULL) #define BT_CONTEXT_SWITCH (0x10000000ULL) #define BT_HARDIRQ (0x20000000ULL) #define BT_SOFTIRQ (0x40000000ULL) #define BT_CHECK_CALLER (0x80000000ULL) #define BT_NO_CHECK_CALLER (0x100000000ULL) #define BT_EXCEPTION_STACK (0x200000000ULL) #define BT_IRQSTACK (0x400000000ULL) #define BT_DUMPFILE_SEARCH (0x800000000ULL) #define BT_EFRAME_SEARCH2 (0x1000000000ULL) #define BT_START (0x2000000000ULL) #define BT_TEXT_SYMBOLS_ALL (0x4000000000ULL) #define BT_XEN_STOP_THIS_CPU (0x8000000000ULL) #define BT_THREAD_GROUP (0x10000000000ULL) #define BT_SAVE_EFRAME_IP (0x20000000000ULL) #define BT_FULL_SYM_SLAB (0x40000000000ULL) #define BT_KDUMP_ELF_REGS (0x80000000000ULL) #define BT_USER_SPACE (0x100000000000ULL) #define BT_KERNEL_SPACE (0x200000000000ULL) #define BT_FULL_SYM_SLAB2 (0x400000000000ULL) #define BT_EFRAME_TARGET (0x800000000000ULL) #define BT_CPUMASK (0x1000000000000ULL) #define BT_SHOW_ALL_REGS (0x2000000000000ULL) #define BT_REGS_NOT_FOUND (0x4000000000000ULL) #define BT_OVERFLOW_STACK (0x8000000000000ULL) #define BT_SKIP_IDLE (0x10000000000000ULL) #define BT_NO_PRINT_REGS (0x20000000000000ULL) #define BT_SYMBOL_OFFSET (BT_SYMBOLIC_ARGS) #define BT_REF_HEXVAL (0x1) #define BT_REF_SYMBOL (0x2) #define BT_REF_FOUND (0x4) #define BT_REFERENCE_CHECK(X) ((X)->ref) #define BT_REFERENCE_FOUND(X) ((X)->ref && ((X)->ref->cmdflags & BT_REF_FOUND)) #define NO_MODULES() \ (!kt->module_list || (kt->module_list == kt->kernel_module)) #define USER_EFRAME_ADDR(task) \ ((ulong)task + UNION_SIZE("task_union") - SIZE(pt_regs)) struct remote_file { char *filename; char *local; int fd; int flags; int type; long csum; off_t size; }; #define REMOTE_VERBOSE (O_RDWR << 1) #define REMOTE_COPY_DONE (REMOTE_VERBOSE << 1) #define TYPE_ELF (REMOTE_VERBOSE << 2) #define TYPE_DEVMEM (REMOTE_VERBOSE << 3) #define TYPE_MCLXCD (REMOTE_VERBOSE << 4) #define TYPE_LKCD (REMOTE_VERBOSE << 5) #define TYPE_S390D (REMOTE_VERBOSE << 6) #define TYPE_NETDUMP (REMOTE_VERBOSE << 7) ulonglong xen_m2p(ulonglong); void read_in_kernel_config(int); #define IKCFG_INIT (0) #define IKCFG_READ (1) #define IKCFG_SETUP (2) #define IKCFG_FREE (3) int get_kernel_config(char *, char **); enum { IKCONFIG_N, IKCONFIG_Y, IKCONFIG_M, IKCONFIG_STR, }; #define MAGIC_START "IKCFG_ST" #define MAGIC_END "IKCFG_ED" #define MAGIC_SIZE (sizeof(MAGIC_START) - 1) /* * dev.c */ void dev_init(void); void dump_dev_table(void); void devdump_extract(void *, ulonglong, char *, FILE *); void devdump_info(void *, ulonglong, FILE *); /* * ipcs.c */ void ipcs_init(void); ulong idr_find(ulong, int); /* * sbitmap.c */ /* sbitmap helpers */ struct sbitmap_context { unsigned depth; unsigned shift; unsigned map_nr; ulong map_addr; ulong alloc_hint; bool round_robin; }; typedef bool (*sbitmap_for_each_fn)(unsigned int idx, void *p); void sbitmap_for_each_set(const struct sbitmap_context *sc, sbitmap_for_each_fn fn, void *data); void sbitmap_context_load(ulong addr, struct sbitmap_context *sc); /* sbitmap_queue helpers */ typedef bool (*sbitmapq_for_each_fn)(unsigned int idx, ulong addr, void *p); struct sbitmapq_ops { /* array params associated with the bitmap */ ulong addr; ulong size; /* callback params */ sbitmapq_for_each_fn fn; void *p; }; void sbitmapq_init(void); void sbitmapq_for_each_set(ulong addr, struct sbitmapq_ops *ops); #ifdef ARM void arm_init(int); void arm_dump_machdep_table(ulong); int arm_is_vmalloc_addr(ulong); void arm_dump_backtrace_entry(struct bt_info *, int, ulong, ulong); #define display_idt_table() \ error(FATAL, "-d option is not applicable to ARM architecture\n") struct arm_pt_regs { ulong uregs[18]; }; #define ARM_cpsr uregs[16] #define ARM_pc uregs[15] #define ARM_lr uregs[14] #define ARM_sp uregs[13] #define ARM_ip uregs[12] #define ARM_fp uregs[11] #define ARM_r10 uregs[10] #define ARM_r9 uregs[9] #define ARM_r8 uregs[8] #define ARM_r7 uregs[7] #define ARM_r6 uregs[6] #define ARM_r5 uregs[5] #define ARM_r4 uregs[4] #define ARM_r3 uregs[3] #define ARM_r2 uregs[2] #define ARM_r1 uregs[1] #define ARM_r0 uregs[0] #define ARM_ORIG_r0 uregs[17] #define KSYMS_START (0x1) #define PHYS_BASE (0x2) #define PGTABLE_V2 (0x4) #define IDMAP_PGD (0x8) #define KVBASE_MASK (0x1ffffff) struct machine_specific { ulong phys_base; ulong vmalloc_start_addr; ulong modules_vaddr; ulong modules_end; ulong kernel_text_start; ulong kernel_text_end; ulong exception_text_start; ulong exception_text_end; ulonglong last_pgd_read_lpae; ulonglong last_pmd_read_lpae; ulonglong last_ptbl_read_lpae; struct arm_pt_regs *crash_task_regs; int unwind_index_prel31; }; int init_unwind_tables(void); void unwind_backtrace(struct bt_info *); #endif /* ARM */ /* * arm64.c */ #ifdef ARM64 void arm64_init(int); void arm64_dump_machdep_table(ulong); ulong arm64_VTOP(ulong); ulong arm64_PTOV(ulong); int arm64_IS_VMALLOC_ADDR(ulong); ulong arm64_swp_type(ulong); ulong arm64_swp_offset(ulong); #endif /* * alpha.c */ #ifdef ALPHA void alpha_init(int); void alpha_dump_machdep_table(ulong); #define display_idt_table() \ error(FATAL, "-d option is not applicable to alpha architecture\n") #define HWRESET_TASK(X) ((machdep->flags & HWRESET) && is_task_active(X) && \ (task_to_context(X)->processor == 0)) #endif /* * x86.c */ #ifdef X86 void x86_init(int); void x86_dump_machdep_table(ulong); void x86_display_idt_table(void); #define display_idt_table() x86_display_idt_table() #define KSYMS_START (0x1) void x86_dump_eframe_common(struct bt_info *bt, ulong *, int); char *x86_function_called_by(ulong); struct syment *x86_jmp_error_code(ulong); struct syment *x86_text_lock_jmp(ulong, ulong *); struct machine_specific { ulong *idt_table; ulong entry_tramp_start; ulong entry_tramp_end; physaddr_t entry_tramp_start_phys; ulonglong last_pmd_read_PAE; ulonglong last_ptbl_read_PAE; ulong page_protnone; int max_numnodes; ulong *remap_start_vaddr; ulong *remap_end_vaddr; ulong *remap_start_pfn; }; struct syment *x86_is_entry_tramp_address(ulong, ulong *); #endif /* * x86_64.c */ #ifdef X86_64 void x86_64_init(int); void x86_64_dump_machdep_table(ulong); ulong x86_64_PTOV(ulong); ulong x86_64_VTOP(ulong); int x86_64_IS_VMALLOC_ADDR(ulong); ulong x86_64_swp_type(ulong); ulong x86_64_swp_offset(ulong); void x86_64_display_idt_table(void); #define display_idt_table() x86_64_display_idt_table() long x86_64_exception_frame(ulong, ulong, char *, struct bt_info *, FILE *); #define EFRAME_INIT (0) struct x86_64_pt_regs_offsets { long r15; long r14; long r13; long r12; long rbp; long rbx; /* arguments: non interrupts/non tracing syscalls only save upto here*/ long r11; long r10; long r9; long r8; long rax; long rcx; long rdx; long rsi; long rdi; long orig_rax; /* end of arguments */ /* cpu exception frame or undefined */ long rip; long cs; long eflags; long rsp; long ss; }; #define MAX_EXCEPTION_STACKS 7 #define NMI_STACK (machdep->machspec->stkinfo.NMI_stack_index) struct x86_64_stkinfo { ulong ebase[NR_CPUS][MAX_EXCEPTION_STACKS]; int esize[MAX_EXCEPTION_STACKS]; char available[NR_CPUS][MAX_EXCEPTION_STACKS]; ulong ibase[NR_CPUS]; int isize; int NMI_stack_index; char *exception_stacks[MAX_EXCEPTION_STACKS]; }; typedef struct __attribute__((__packed__)) { signed short sp_offset; signed short bp_offset; unsigned int sp_reg:4; unsigned int bp_reg:4; unsigned int type:2; unsigned int signal:1; unsigned int end:1; } kernel_orc_entry; typedef struct __attribute__((__packed__)) { signed short sp_offset; signed short bp_offset; unsigned int sp_reg:4; unsigned int bp_reg:4; unsigned int type:3; unsigned int signal:1; } kernel_orc_entry_6_4; typedef struct orc_entry { signed short sp_offset; signed short bp_offset; unsigned int sp_reg; unsigned int bp_reg; unsigned int type; unsigned int signal; unsigned int end; } orc_entry; struct ORC_data { int module_ORC; uint lookup_num_blocks; ulong __start_orc_unwind_ip; ulong __stop_orc_unwind_ip; ulong __start_orc_unwind; ulong __stop_orc_unwind; ulong orc_lookup; ulong ip_entry; ulong orc_entry; orc_entry orc_entry_data; int has_signal; int has_end; }; #define ORC_TYPE_CALL ((machdep->flags & ORC_6_4) ? 2 : 0) /* The below entries are not used and must be updated if we use them. */ #define ORC_TYPE_REGS 1 #define ORC_TYPE_REGS_IRET 2 #define UNWIND_HINT_TYPE_SAVE 3 #define UNWIND_HINT_TYPE_RESTORE 4 #define ORC_REG_UNDEFINED 0 #define ORC_REG_PREV_SP 1 #define ORC_REG_DX 2 #define ORC_REG_DI 3 #define ORC_REG_BP 4 #define ORC_REG_SP 5 #define ORC_REG_R10 6 #define ORC_REG_R13 7 #define ORC_REG_BP_INDIRECT 8 #define ORC_REG_SP_INDIRECT 9 #define ORC_REG_MAX 15 struct machine_specific { ulong userspace_top; ulong page_offset; ulong vmalloc_start_addr; ulong vmalloc_end; ulong vmemmap_vaddr; ulong vmemmap_end; ulong modules_vaddr; ulong modules_end; ulong phys_base; char *pml4; char *upml; ulong last_upml_read; ulong last_pml4_read; char *irqstack; ulong irq_eframe_link; struct x86_64_pt_regs_offsets pto; struct x86_64_stkinfo stkinfo; ulong *current; ulong *crash_nmi_rsp; ulong vsyscall_page; ulong thread_return; ulong page_protnone; ulong GART_start; ulong GART_end; ulong kernel_image_size; ulong physical_mask_shift; ulong pgdir_shift; char *p4d; ulong last_p4d_read; struct ORC_data orc; ulong irq_stack_gap; ulong kpti_entry_stack; ulong kpti_entry_stack_size; ulong ptrs_per_pgd; ulong cpu_entry_area_start; ulong cpu_entry_area_end; ulong page_offset_force; char **exception_functions; ulong sme_mask; }; #define KSYMS_START (0x1) #define PT_REGS_INIT (0x2) #define VM_ORIG (0x4) #define VM_2_6_11 (0x8) #define VM_XEN (0x10) #define NO_TSS (0x20) #define SCHED_TEXT (0x40) #define PHYS_BASE (0x80) #define VM_XEN_RHEL4 (0x100) #define FRAMEPOINTER (0x200) #define GART_REGION (0x400) #define NESTED_NMI (0x800) #define RANDOMIZED (0x1000) #define VM_5LEVEL (0x2000) #define ORC (0x4000) #define KPTI (0x8000) #define L1TF (0x10000) #define ORC_6_4 (0x20000) #define VM_FLAGS (VM_ORIG|VM_2_6_11|VM_XEN|VM_XEN_RHEL4|VM_5LEVEL) #define _2MB_PAGE_MASK (~((MEGABYTES(2))-1)) #define _1GB_PAGE_MASK (~((GIGABYTES(1))-1)) #endif #if defined(X86) || defined(X86_64) /* * unwind_x86_32_64.c */ void init_unwind_table(void); int dwarf_backtrace(struct bt_info *, int, ulong); void dwarf_debug(struct bt_info *); int dwarf_print_stack_entry(struct bt_info *, int); #endif /* * ppc64.c */ /* * This structure was copied from kernel source * in include/asm-ppc/ptrace.h */ struct ppc64_pt_regs { long gpr[32]; long nip; long msr; long orig_gpr3; /* Used for restarting system calls */ long ctr; long link; long xer; long ccr; long mq; /* 601 only (not used at present) */ /* Used on APUS to hold IPL value. */ long trap; /* Reason for being here */ long dar; /* Fault registers */ long dsisr; long result; /* Result of a system call */ }; struct ppc64_elf_siginfo { int si_signo; int si_code; int si_errno; }; struct ppc64_elf_prstatus { struct ppc64_elf_siginfo pr_info; short pr_cursig; unsigned long pr_sigpend; unsigned long pr_sighold; pid_t pr_pid; pid_t pr_ppid; pid_t pr_pgrp; pid_t pr_sid; struct timeval pr_utime; struct timeval pr_stime; struct timeval pr_cutime; struct timeval pr_cstime; struct ppc64_pt_regs pr_reg; int pr_fpvalid; }; #ifdef PPC64 enum emergency_stack_type { NONE_STACK = 0, EMERGENCY_STACK, NMI_EMERGENCY_STACK, MC_EMERGENCY_STACK }; struct ppc64_opal { uint64_t base; uint64_t entry; uint64_t size; }; struct ppc64_vmemmap { unsigned long phys; unsigned long virt; }; /* * Used to store the HW interrupt stack. It is only for 2.4. */ struct machine_specific { ulong *hwintrstack; char *hwstackbuf; uint hwstacksize; /* Emergency stacks */ ulong *emergency_sp; ulong *nmi_emergency_sp; ulong *mc_emergency_sp; uint l4_index_size; uint l3_index_size; uint l2_index_size; uint l1_index_size; uint ptrs_per_l4; uint ptrs_per_l3; uint ptrs_per_l2; uint ptrs_per_l1; uint l4_shift; uint l3_shift; uint l2_shift; uint l1_shift; uint pte_rpn_shift; ulong pte_rpn_mask; ulong pgd_masked_bits; ulong pud_masked_bits; ulong pmd_masked_bits; int vmemmap_cnt; int vmemmap_psize; ulong vmemmap_base; struct ppc64_vmemmap *vmemmap_list; ulong _page_pte; ulong _page_present; ulong _page_user; ulong _page_rw; ulong _page_guarded; ulong _page_coherent; ulong _page_no_cache; ulong _page_writethru; ulong _page_dirty; ulong _page_accessed; int (*is_kvaddr)(ulong); int (*is_vmaddr)(ulong); struct ppc64_opal opal; }; void ppc64_init(int); void ppc64_dump_machdep_table(ulong); #define display_idt_table() \ error(FATAL, "-d option is not applicable to PowerPC architecture\n") #define KSYMS_START (0x1) #define VM_ORIG (0x2) #define VMEMMAP_AWARE (0x4) #define BOOK3E (0x8) #define PHYS_ENTRY_L4 (0x10) #define SWAP_ENTRY_L4 (0x20) /* * The flag bit for radix MMU in cpu_spec.mmu_features * in the kernel is also 0x40. */ #define RADIX_MMU (0x40) #define OPAL_FW (0x80) #define REGION_SHIFT (60UL) #define REGION_ID(addr) (((unsigned long)(addr)) >> REGION_SHIFT) #define VMEMMAP_REGION_ID (0xfUL) #endif /* * ppc.c */ #ifdef PPC void ppc_init(int); void ppc_dump_machdep_table(ulong); void ppc_relocate_nt_prstatus_percpu(void **, uint *); #define display_idt_table() \ error(FATAL, "-d option is not applicable to PowerPC architecture\n") #define KSYMS_START (0x1) /* This should match PPC_FEATURE_BOOKE from include/asm-powerpc/cputable.h */ #define CPU_BOOKE (0x00008000) #else #define ppc_relocate_nt_prstatus_percpu(X,Y) do {} while (0) #endif /* * lkcd_fix_mem.c */ struct _dump_header_asm_s; struct _dump_header_s; ulong get_lkcd_switch_stack(ulong); int fix_addr_v8(struct _dump_header_asm_s *); int lkcd_dump_init_v8_arch(struct _dump_header_s *dh); int fix_addr_v7(int); int get_lkcd_regs_for_cpu_arch(int cpu, ulong *eip, ulong *esp); int lkcd_get_kernel_start_v8(ulong *addr); /* * lkcd_v8.c */ int get_lkcd_regs_for_cpu_v8(struct bt_info *bt, ulong *eip, ulong *esp); /* * ia64.c */ #ifdef IA64 void ia64_init(int); void ia64_dump_machdep_table(ulong); void ia64_dump_line_number(ulong); ulong ia64_get_switch_stack(ulong); void ia64_exception_frame(ulong, struct bt_info *bt); ulong ia64_PTOV(ulong); ulong ia64_VTOP(ulong); int ia64_IS_VMALLOC_ADDR(ulong); #define display_idt_table() \ error(FATAL, "-d option TBD on ia64 architecture\n"); int ia64_in_init_stack(ulong addr); int ia64_in_mca_stack_hyper(ulong addr, struct bt_info *bt); physaddr_t ia64_xen_kdump_p2m(struct xen_kdump_data *xkd, physaddr_t pseudo); #define OLD_UNWIND (0x1) /* CONFIG_IA64_NEW_UNWIND not turned on */ #define NEW_UNWIND (0x2) /* CONFIG_IA64_NEW_UNWIND turned on */ #define NEW_UNW_V1 (0x4) #define NEW_UNW_V2 (0x8) #define NEW_UNW_V3 (0x10) #define UNW_OUT_OF_SYNC (0x20) /* shared data structures out of sync */ #define UNW_READ (0x40) /* kernel unw has been read successfully */ #define MEM_LIMIT (0x80) #define UNW_PTREGS (0x100) #define UNW_R0 (0x200) #undef IA64_RBS_OFFSET #undef IA64_STK_OFFSET #define IA64_RBS_OFFSET ((SIZE(task_struct) + 15) & ~15) #define IA64_STK_OFFSET (STACKSIZE()) struct machine_specific { ulong cpu_data_address; ulong unimpl_va_mask; ulong unimpl_pa_mask; long unw_tables_offset; long unw_kernel_table_offset; long unw_pt_regs_offsets; int script_index; struct unw_script *script_cache; ulong script_cache_fills; ulong script_cache_hits; void *unw; ulong mem_limit; ulong kernel_region; ulong kernel_start; ulong phys_start; ulong vmalloc_start; char *ia64_memmap; uint64_t efi_memmap_size; uint64_t efi_memdesc_size; void (*unwind_init)(void); void (*unwind)(struct bt_info *); void (*dump_unwind_stats)(void); int (*unwind_debug)(ulong); int ia64_init_stack_size; }; /* * unwind.c */ void unwind_init_v1(void); void unwind_v1(struct bt_info *); void dump_unwind_stats_v1(void); int unwind_debug_v1(ulong); void unwind_init_v2(void); void unwind_v2(struct bt_info *); void dump_unwind_stats_v2(void); int unwind_debug_v2(ulong); void unwind_init_v3(void); void unwind_v3(struct bt_info *); void dump_unwind_stats_v3(void); int unwind_debug_v3(ulong); #endif /* IA64 */ /* * s390.c */ #ifdef S390 void s390_init(int); void s390_dump_machdep_table(ulong); #define display_idt_table() \ error(FATAL, "-d option is not applicable to S390 architecture\n") #define KSYMS_START (0x1) #endif /* * s390_dump.c */ int is_s390_dump(char *); FILE* s390_dump_init(char *); int read_s390_dumpfile(int, void *, int, ulong, physaddr_t); int write_s390_dumpfile(int, void *, int, ulong, physaddr_t); uint s390_page_size(void); int s390_memory_used(void); int s390_free_memory(void); int s390_memory_dump(FILE *); ulong get_s390_panic_task(void); void get_s390_panicmsg(char *); /* * s390x.c */ #ifdef S390X struct machine_specific { ulong (*virt_to_phys)(ulong vaddr); ulong (*phys_to_virt)(ulong paddr); int (*is_vmalloc_addr)(ulong vaddr); ulong __kaslr_offset_phys; ulong amode31_start; ulong amode31_end; }; void s390x_init(int); ulong s390x_PTOV(ulong); ulong s390x_VTOP(ulong); int s390x_IS_VMALLOC_ADDR(ulong); void s390x_dump_machdep_table(ulong); #define display_idt_table() \ error(FATAL, "-d option is not applicable to S390X architecture\n") #define KSYMS_START (0x1) #endif /* * mips.c */ void mips_display_regs_from_elf_notes(int, FILE *); #ifdef MIPS void mips_init(int); void mips_dump_machdep_table(ulong); #define display_idt_table() \ error(FATAL, "-d option is not applicable to MIPS architecture\n") struct mips_regset { ulong regs[45]; }; struct mips_pt_regs_main { ulong regs[32]; ulong cp0_status; ulong hi; ulong lo; }; struct mips_pt_regs_cp0 { ulong cp0_badvaddr; ulong cp0_cause; ulong cp0_epc; }; #define KSYMS_START (0x1) #define PHYS_BASE (0x2) #define KVBASE_MASK (0x1ffffff) struct machine_specific { ulong phys_base; ulong vmalloc_start_addr; ulong modules_vaddr; ulong modules_end; ulong _page_present; ulong _page_read; ulong _page_write; ulong _page_accessed; ulong _page_modified; ulong _page_global; ulong _page_valid; ulong _page_no_read; ulong _page_no_exec; ulong _page_dirty; ulong _pfn_shift; #define _PAGE_PRESENT (machdep->machspec->_page_present) #define _PAGE_READ (machdep->machspec->_page_read) #define _PAGE_WRITE (machdep->machspec->_page_write) #define _PAGE_ACCESSED (machdep->machspec->_page_accessed) #define _PAGE_MODIFIED (machdep->machspec->_page_modified) #define _PAGE_GLOBAL (machdep->machspec->_page_global) #define _PAGE_VALID (machdep->machspec->_page_valid) #define _PAGE_NO_READ (machdep->machspec->_page_no_read) #define _PAGE_NO_EXEC (machdep->machspec->_page_no_exec) #define _PAGE_DIRTY (machdep->machspec->_page_dirty) #define _PFN_SHIFT (machdep->machspec->_pfn_shift) struct mips_regset *crash_task_regs; }; #endif /* MIPS */ /* * mips64.c */ void mips64_display_regs_from_elf_notes(int, FILE *); #ifdef MIPS64 void mips64_init(int); void mips64_dump_machdep_table(ulong); #define display_idt_table() \ error(FATAL, "-d option is not applicable to MIPS64 architecture\n") /* from arch/mips/include/asm/ptrace.h */ struct mips64_register { ulong regs[45]; }; struct mips64_pt_regs_main { ulong regs[32]; ulong cp0_status; ulong hi; ulong lo; }; struct mips64_pt_regs_cp0 { ulong cp0_badvaddr; ulong cp0_cause; ulong cp0_epc; }; struct mips64_unwind_frame { unsigned long sp; unsigned long pc; unsigned long ra; }; #define KSYMS_START (0x1) struct machine_specific { ulong phys_base; ulong vmalloc_start_addr; ulong modules_vaddr; ulong modules_end; ulong _page_present; ulong _page_read; ulong _page_write; ulong _page_accessed; ulong _page_modified; ulong _page_huge; ulong _page_special; ulong _page_protnone; ulong _page_global; ulong _page_valid; ulong _page_no_read; ulong _page_no_exec; ulong _page_dirty; ulong _pfn_shift; struct mips64_register *crash_task_regs; }; /* from arch/mips/include/asm/pgtable-bits.h */ #define _PAGE_PRESENT (machdep->machspec->_page_present) #define _PAGE_READ (machdep->machspec->_page_read) #define _PAGE_WRITE (machdep->machspec->_page_write) #define _PAGE_ACCESSED (machdep->machspec->_page_accessed) #define _PAGE_MODIFIED (machdep->machspec->_page_modified) #define _PAGE_HUGE (machdep->machspec->_page_huge) #define _PAGE_SPECIAL (machdep->machspec->_page_special) #define _PAGE_PROTNONE (machdep->machspec->_page_protnone) #define _PAGE_GLOBAL (machdep->machspec->_page_global) #define _PAGE_VALID (machdep->machspec->_page_valid) #define _PAGE_NO_READ (machdep->machspec->_page_no_read) #define _PAGE_NO_EXEC (machdep->machspec->_page_no_exec) #define _PAGE_DIRTY (machdep->machspec->_page_dirty) #define _PFN_SHIFT (machdep->machspec->_pfn_shift) #endif /* MIPS64 */ /* * riscv64.c */ void riscv64_display_regs_from_elf_notes(int, FILE *); #ifdef RISCV64 void riscv64_init(int); void riscv64_dump_machdep_table(ulong); int riscv64_IS_VMALLOC_ADDR(ulong); #define display_idt_table() \ error(FATAL, "-d option is not applicable to RISCV64 architecture\n") /* * regs[0,31] : struct user_regs_struct * from arch/riscv/include/uapi/asm/ptrace.h * regs[0,35] : struct pt_regs * from arch/riscv/include/asm/ptrace.h */ struct riscv64_register { ulong regs[36]; }; struct riscv64_unwind_frame { ulong fp; ulong sp; ulong pc; }; struct machine_specific { ulong phys_base; ulong page_offset; ulong vmalloc_start_addr; ulong vmalloc_end; ulong vmemmap_vaddr; ulong vmemmap_end; ulong modules_vaddr; ulong modules_end; ulong kernel_link_addr; ulong va_kernel_pa_offset; ulong _page_present; ulong _page_read; ulong _page_write; ulong _page_exec; ulong _page_user; ulong _page_global; ulong _page_accessed; ulong _page_dirty; ulong _page_soft; ulong _pfn_shift; ulong va_bits; char *p4d; ulong last_p4d_read; ulong struct_page_size; struct riscv64_register *crash_task_regs; ulong irq_stack_size; ulong *irq_stacks; ulong overflow_stack_size; ulong *overflow_stacks; }; /* from arch/riscv/include/asm/pgtable-bits.h */ #define _PAGE_PRESENT (machdep->machspec->_page_present) #define _PAGE_READ (machdep->machspec->_page_read) #define _PAGE_WRITE (machdep->machspec->_page_write) #define _PAGE_EXEC (machdep->machspec->_page_exec) #define _PAGE_USER (machdep->machspec->_page_user) #define _PAGE_GLOBAL (machdep->machspec->_page_global) #define _PAGE_ACCESSED (machdep->machspec->_page_accessed) #define _PAGE_DIRTY (machdep->machspec->_page_dirty) #define _PAGE_SOFT (machdep->machspec->_page_soft) #define _PAGE_SEC (machdep->machspec->_page_sec) #define _PAGE_SHARE (machdep->machspec->_page_share) #define _PAGE_BUF (machdep->machspec->_page_buf) #define _PAGE_CACHE (machdep->machspec->_page_cache) #define _PAGE_SO (machdep->machspec->_page_so) #define _PAGE_SPECIAL _PAGE_SOFT #define _PAGE_TABLE _PAGE_PRESENT #define _PAGE_PROT_NONE _PAGE_READ #define _PAGE_PFN_SHIFT 10 /* from 'struct pt_regs' definitions of RISC-V arch */ #define RISCV64_REGS_EPC 0 #define RISCV64_REGS_RA 1 #define RISCV64_REGS_SP 2 #define RISCV64_REGS_FP 8 #define RISCV64_REGS_STATUS 32 #define RISCV64_REGS_CAUSE 34 #endif /* RISCV64 */ /* * sparc64.c */ #ifdef SPARC64 void sparc64_init(int); void sparc64_dump_machdep_table(ulong); int sparc64_vmalloc_addr(ulong); #define display_idt_table() \ error(FATAL, "The -d option is not applicable to sparc64.\n") #endif /* * loongarch64.c */ void loongarch64_display_regs_from_elf_notes(int, FILE *); #ifdef LOONGARCH64 void loongarch64_init(int); void loongarch64_dump_machdep_table(ulong); #define display_idt_table() \ error(FATAL, "-d option is not applicable to LOONGARCH64 architecture\n") #define KSYMS_START (0x1) struct machine_specific { ulong phys_base; ulong vmalloc_start_addr; ulong modules_vaddr; ulong modules_end; struct loongarch64_pt_regs *crash_task_regs; }; /* * Basic page table format: * * 63 62 61 PALEN-1 12 10 9 8 7 6 5 4 3 2 1 0 * +----+--+--+------+--------------------+----+--+--+-+-+-+---+---+-+-+ * |RPLV|NX|NR| | PA[PALEN-1:12] | |SP|PN|W|P|G|MAT|PLV|D|V| * +----+--+--+------+--------------------+----+--+--+-+-+-+---+---+-+-+ * * * Huge page table format: * * 63 62 61 PALEN-1 12 10 9 8 7 6 5 4 3 2 1 0 * +----+--+--+------+-----------------+--+----+--+--+-+-+-+---+---+-+-+ * |RPLV|NX|NR| | PA[PALEN-1:12] | G| |SP|PN|W|P|H|MAT|PLV|D|V| * +----+--+--+------+-----------------+--+----+--+--+-+-+-+---+---+-+-+ * */ /* from arch/loongarch/include/asm/pgtable-bits.h */ /* Page table bits */ #define _PAGE_VALID_SHIFT 0 #define _PAGE_ACCESSED_SHIFT 0 /* Reuse Valid for Accessed */ #define _PAGE_DIRTY_SHIFT 1 #define _PAGE_PLV_SHIFT 2 /* 2~3, two bits */ #define _CACHE_SHIFT 4 /* 4~5, two bits */ #define _PAGE_GLOBAL_SHIFT 6 #define _PAGE_HUGE_SHIFT 6 /* HUGE is a PMD bit */ #define _PAGE_PRESENT_SHIFT 7 #define _PAGE_WRITE_SHIFT 8 #define _PAGE_MODIFIED_SHIFT 9 #define _PAGE_PROTNONE_SHIFT 10 #define _PAGE_SPECIAL_SHIFT 11 #define _PAGE_HGLOBAL_SHIFT 12 /* HGlobal is a PMD bit */ #define _PAGE_PFN_SHIFT 12 #define _PAGE_SWP_EXCLUSIVE_SHIFT 23 #define _PAGE_PFN_END_SHIFT 48 #define _PAGE_PRESENT_INVALID_SHIFT 60 #define _PAGE_NO_READ_SHIFT 61 #define _PAGE_NO_EXEC_SHIFT 62 #define _PAGE_RPLV_SHIFT 63 #ifndef _ULCAST_ #define _ULCAST_ (unsigned long) #endif /* Used by software */ #define _PAGE_PRESENT (_ULCAST_(1) << _PAGE_PRESENT_SHIFT) #define _PAGE_PRESENT_INVALID (_ULCAST_(1) << _PAGE_PRESENT_INVALID_SHIFT) #define _PAGE_WRITE (_ULCAST_(1) << _PAGE_WRITE_SHIFT) #define _PAGE_ACCESSED (_ULCAST_(1) << _PAGE_ACCESSED_SHIFT) #define _PAGE_MODIFIED (_ULCAST_(1) << _PAGE_MODIFIED_SHIFT) #define _PAGE_PROTNONE (_ULCAST_(1) << _PAGE_PROTNONE_SHIFT) #define _PAGE_SPECIAL (_ULCAST_(1) << _PAGE_SPECIAL_SHIFT) /* We borrow bit 23 to store the exclusive marker in swap PTEs. */ #define _PAGE_SWP_EXCLUSIVE (_ULCAST_(1) << _PAGE_SWP_EXCLUSIVE_SHIFT) /* Used by TLB hardware (placed in EntryLo*) */ #define _PAGE_VALID (_ULCAST_(1) << _PAGE_VALID_SHIFT) #define _PAGE_DIRTY (_ULCAST_(1) << _PAGE_DIRTY_SHIFT) #define _PAGE_PLV (_ULCAST_(3) << _PAGE_PLV_SHIFT) #define _PAGE_GLOBAL (_ULCAST_(1) << _PAGE_GLOBAL_SHIFT) #define _PAGE_HUGE (_ULCAST_(1) << _PAGE_HUGE_SHIFT) #define _PAGE_HGLOBAL (_ULCAST_(1) << _PAGE_HGLOBAL_SHIFT) #define _PAGE_NO_READ (_ULCAST_(1) << _PAGE_NO_READ_SHIFT) #define _PAGE_NO_EXEC (_ULCAST_(1) << _PAGE_NO_EXEC_SHIFT) #define _PAGE_RPLV (_ULCAST_(1) << _PAGE_RPLV_SHIFT) #define _CACHE_MASK (_ULCAST_(3) << _CACHE_SHIFT) #define _PFN_SHIFT (PAGESHIFT() - 12 + _PAGE_PFN_SHIFT) #define _PAGE_USER (PLV_USER << _PAGE_PLV_SHIFT) #define _PAGE_KERN (PLV_KERN << _PAGE_PLV_SHIFT) #define _PFN_MASK (~((_ULCAST_(1) << (_PFN_SHIFT)) - 1) & \ ((_ULCAST_(1) << (_PAGE_PFN_END_SHIFT)) - 1)) #endif /* LOONGARCH64 */ /* * netdump.c */ int is_netdump(char *, ulong); uint netdump_page_size(void); int read_netdump(int, void *, int, ulong, physaddr_t); int write_netdump(int, void *, int, ulong, physaddr_t); int netdump_free_memory(void); int netdump_memory_used(void); int netdump_init(char *, FILE *); ulong get_netdump_panic_task(void); ulong get_netdump_switch_stack(ulong); FILE *set_netdump_fp(FILE *); int netdump_memory_dump(FILE *); void get_netdump_regs(struct bt_info *, ulong *, ulong *); int is_partial_netdump(void); void get_netdump_regs_x86(struct bt_info *, ulong *, ulong *); void get_netdump_regs_x86_64(struct bt_info *, ulong *, ulong *); void dump_registers_for_elf_dumpfiles(void); struct vmcore_data; struct vmcore_data *get_kdump_vmcore_data(void); int read_kdump(int, void *, int, ulong, physaddr_t); int write_kdump(int, void *, int, ulong, physaddr_t); int is_kdump(char *, ulong); int kdump_init(char *, FILE *); ulong get_kdump_panic_task(void); uint kdump_page_size(void); int kdump_free_memory(void); int kdump_memory_used(void); int kdump_memory_dump(FILE *); void get_kdump_regs(struct bt_info *, ulong *, ulong *); void xen_kdump_p2m_mfn(char *); int is_sadump_xen(void); void set_xen_phys_start(char *); ulong xen_phys_start(void); int xen_major_version(void); int xen_minor_version(void); int get_netdump_arch(void); int exist_regs_in_elf_notes(struct task_context *); void *get_regs_from_elf_notes(struct task_context *); void map_cpus_to_prstatus(void); int kdump_phys_base(ulong *); int kdump_set_phys_base(ulong); int arm_kdump_phys_base(ulong *); int arm_kdump_phys_end(ulong *); int is_proc_kcore(char *, ulong); int proc_kcore_init(FILE *, int); int read_proc_kcore(int, void *, int, ulong, physaddr_t); int write_proc_kcore(int, void *, int, ulong, physaddr_t); int kcore_memory_dump(FILE *); void dump_registers_for_qemu_mem_dump(void); void kdump_backup_region_init(void); void display_regs_from_elf_notes(int, FILE *); void display_ELF_note(int, int, void *, FILE *); void *netdump_get_prstatus_percpu(int); int kdump_kaslr_check(void); void display_vmcoredd_note(void *ptr, FILE *ofp); int kdump_get_nr_cpus(void); QEMUCPUState *kdump_get_qemucpustate(int); void kdump_device_dump_info(FILE *); void kdump_device_dump_extract(int, char *, FILE *); #define PRSTATUS_NOTE (1) #define QEMU_NOTE (2) /* * ramdump.c */ int is_ramdump(char *pattern); char *ramdump_to_elf(void); void ramdump_elf_output_file(char *opt); void ramdump_cleanup(void); int read_ramdump(int fd, void *bufptr, int cnt, ulong addr, physaddr_t paddr); void show_ramdump_files(void); void dump_ramdump_data(void); int is_ramdump_image(void); /* * diskdump.c */ int is_diskdump(char *); uint diskdump_page_size(void); int read_diskdump(int, void *, int, ulong, physaddr_t); int write_diskdump(int, void *, int, ulong, physaddr_t); int diskdump_free_memory(void); int diskdump_memory_used(void); int diskdump_init(char *, FILE *); ulong get_diskdump_panic_task(void); ulong get_diskdump_switch_stack(ulong); int diskdump_memory_dump(FILE *); FILE *set_diskdump_fp(FILE *); void get_diskdump_regs(struct bt_info *, ulong *, ulong *); int diskdump_phys_base(unsigned long *); int diskdump_set_phys_base(unsigned long); extern ulong *diskdump_flags; int is_partial_diskdump(void); int get_dump_level(void); int dumpfile_is_split(void); void show_split_dumpfiles(void); void x86_process_elf_notes(void *, unsigned long); void *diskdump_get_prstatus_percpu(int); int diskdump_is_cpu_prstatus_valid(int cpu); int have_crash_notes(int cpu); void map_cpus_to_prstatus_kdump_cmprs(void); void diskdump_display_regs(int, FILE *); void process_elf32_notes(void *, ulong); void process_elf64_notes(void *, ulong); void dump_registers_for_compressed_kdump(void); int diskdump_kaslr_check(void); int diskdump_get_nr_cpus(void); QEMUCPUState *diskdump_get_qemucpustate(int); void diskdump_device_dump_info(FILE *); void diskdump_device_dump_extract(int, char *, FILE *); ulong readswap(ulonglong pte_val, char *buf, ulong len, ulonglong vaddr); /*support for zram*/ ulong try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong vaddr); #define OBJ_TAG_BITS 1 #ifndef MAX_POSSIBLE_PHYSMEM_BITS #define MAX_POSSIBLE_PHYSMEM_BITS (MAX_PHYSMEM_BITS()) #endif #define _PFN_BITS (MAX_POSSIBLE_PHYSMEM_BITS - PAGESHIFT()) #define OBJ_INDEX_BITS (BITS_PER_LONG - _PFN_BITS - OBJ_TAG_BITS) #define OBJ_INDEX_MASK ((1 << OBJ_INDEX_BITS) - 1) #define ZS_HANDLE_SIZE (sizeof(unsigned long)) #define ZSPAGE_MAGIC 0x58 #define SWAP_ADDRESS_SPACE_SHIFT 14 #define SECTOR_SHIFT 9 #define SECTORS_PER_PAGE_SHIFT (PAGESHIFT() - SECTOR_SHIFT) #define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT) struct zspage { union { unsigned int flag_bits; struct { unsigned int fullness : 2; unsigned int class : 9; unsigned int isolated : 3; unsigned int magic : 8; } v0; struct { unsigned int huge : 1; unsigned int fullness : 2; unsigned int class : 9; unsigned int isolated : 3; unsigned int magic : 8; } v5_17; }; unsigned int inuse; unsigned int freeobj; }; /* * makedumpfile.c */ void check_flattened_format(char *file); int is_flattened_format(char *file); int read_flattened_format(int fd, off_t offset, void *buf, size_t size); void dump_flat_header(FILE *); /* * xendump.c */ int is_xendump(char *); int read_xendump(int, void *, int, ulong, physaddr_t); int write_xendump(int, void *, int, ulong, physaddr_t); uint xendump_page_size(void); int xendump_free_memory(void); int xendump_memory_used(void); int xendump_init(char *, FILE *); int xendump_memory_dump(FILE *); ulong get_xendump_panic_task(void); void get_xendump_regs(struct bt_info *, ulong *, ulong *); char *xc_core_mfn_to_page(ulong, char *); int xc_core_mfn_to_page_index(ulong); void xendump_panic_hook(char *); int read_xendump_hyper(int, void *, int, ulong, physaddr_t); struct xendump_data *get_xendump_data(void); /* * kvmdump.c */ int is_kvmdump(char *); int is_kvmdump_mapfile(char *); int kvmdump_init(char *, FILE *); int read_kvmdump(int, void *, int, ulong, physaddr_t); int write_kvmdump(int, void *, int, ulong, physaddr_t); int kvmdump_free_memory(void); int kvmdump_memory_used(void); int kvmdump_memory_dump(FILE *); void get_kvmdump_regs(struct bt_info *, ulong *, ulong *); ulong get_kvmdump_panic_task(void); int kvmdump_phys_base(unsigned long *); void kvmdump_display_regs(int, FILE *); void set_kvmhost_type(char *); void set_kvm_iohole(char *); struct kvm_register_set { union { uint32_t cs; uint32_t ss; uint32_t ds; uint32_t es; uint32_t fs; uint32_t gs; uint64_t ip; uint64_t flags; uint64_t regs[16]; } x86; }; int get_kvm_register_set(int, struct kvm_register_set *); /* * sadump.c */ int is_sadump(char *); uint sadump_page_size(void); int read_sadump(int, void *, int, ulong, physaddr_t); int write_sadump(int, void *, int, ulong, physaddr_t); int sadump_init(char *, FILE *); int sadump_is_diskset(void); ulong get_sadump_panic_task(void); ulong get_sadump_switch_stack(ulong); int sadump_memory_used(void); int sadump_free_memory(void); int sadump_memory_dump(FILE *); FILE *set_sadump_fp(FILE *); void get_sadump_regs(struct bt_info *bt, ulong *ipp, ulong *spp); void sadump_display_regs(int, FILE *); int sadump_phys_base(ulong *); int sadump_set_phys_base(ulong); void sadump_show_diskset(void); int sadump_is_zero_excluded(void); void sadump_set_zero_excluded(void); void sadump_unset_zero_excluded(void); struct sadump_data; struct sadump_data *get_sadump_data(void); int sadump_calc_kaslr_offset(ulong *); int sadump_get_nr_cpus(void); int sadump_get_cr3_cr4_idtr(int, ulong *, ulong *, ulong *); /* * qemu.c */ int qemu_init(char *); /* * qemu-load.c */ int is_qemu_vm_file(char *); void dump_qemu_header(FILE *); /* * net.c */ void net_init(void); void dump_net_table(void); void dump_sockets_workhorse(ulong, ulong, struct reference *); /* * remote.c */ int is_remote_daemon(char *); physaddr_t get_remote_phys_base(physaddr_t, physaddr_t); physaddr_t remote_vtop(int, physaddr_t); int get_remote_regs(struct bt_info *, ulong *, ulong *); physaddr_t get_remote_cr3(int); void remote_fd_init(void); int get_remote_file(struct remote_file *); uint remote_page_size(void); int find_remote_module_objfile(struct load_module *lm, char *, char *); int remote_free_memory(void); int remote_memory_dump(int); int remote_memory_used(void); void remote_exit(void); int remote_execute(void); void remote_clear_pipeline(void); int remote_memory_read(int, char *, int, physaddr_t, int); /* * vmware_vmss.c */ int is_vmware_vmss(char *filename); int vmware_vmss_init(char *filename, FILE *ofp); uint vmware_vmss_page_size(void); int read_vmware_vmss(int, void *, int, ulong, physaddr_t); int write_vmware_vmss(int, void *, int, ulong, physaddr_t); void vmware_vmss_display_regs(int, FILE *); void get_vmware_vmss_regs(struct bt_info *, ulong *, ulong *); int vmware_vmss_memory_dump(FILE *); void dump_registers_for_vmss_dump(void); int vmware_vmss_valid_regs(struct bt_info *); int vmware_vmss_get_nr_cpus(void); int vmware_vmss_get_cr3_cr4_idtr(int, ulong *, ulong *, ulong *); int vmware_vmss_phys_base(ulong *phys_base); int vmware_vmss_set_phys_base(ulong); int vmware_vmss_get_cpu_reg(int, int, const char *, int, void *); /* * vmware_guestdump.c */ int is_vmware_guestdump(char *filename); int vmware_guestdump_init(char *filename, FILE *ofp); int vmware_guestdump_memory_dump(FILE *); /* * kaslr_helper.c */ int calc_kaslr_offset(ulong *, ulong *); /* * printk.c */ void dump_lockless_record_log(int); /* caller_id default and max character sizes based on pid field size */ #define PID_CHARS_MAX 16 /* Max Number of PID characters */ #define PID_CHARS_DEFAULT 8 /* Default number of PID characters */ /* * gnu_binutils.c */ /* NO LONGER IN USE */ /* * test.c */ void cmd_template(void); void foreach_test(ulong, ulong); /* * va_server.c */ int mclx_page_size(void); int vas_memory_used(void); int vas_memory_dump(FILE *); int vas_free_memory(char *); void set_vas_debug(ulong); size_t vas_write(void *, size_t); int va_server_init(char *, ulong *, ulong *, ulong *); size_t vas_read(void *, size_t); int vas_lseek(ulong, int); /* * lkcd_x86_trace.c */ int lkcd_x86_back_trace(struct bt_info *, int, FILE *); /* * lkcd_common.c */ int lkcd_dump_init(FILE *, int, char *); ulong get_lkcd_panic_task(void); void get_lkcd_panicmsg(char *); int is_lkcd_compressed_dump(char *); void dump_lkcd_environment(ulong); int lkcd_lseek(physaddr_t); long lkcd_read(void *, long); void set_lkcd_debug(ulong); FILE *set_lkcd_fp(FILE *); uint lkcd_page_size(void); int lkcd_memory_used(void); int lkcd_memory_dump(FILE *); int lkcd_free_memory(void); void lkcd_print(char *, ...); void set_remote_lkcd_panic_data(ulong, char *); void set_lkcd_nohash(void); int lkcd_load_dump_page_header(void *, ulong); void lkcd_dumpfile_complaint(uint32_t, uint32_t, int); int set_mb_benchmark(ulong); ulonglong fix_lkcd_address(ulonglong); int lkcd_get_kernel_start(ulong *addr); int get_lkcd_regs_for_cpu(struct bt_info *bt, ulong *eip, ulong *esp); /* * lkcd_v1.c */ int lkcd_dump_init_v1(FILE *, int); void dump_dump_page_v1(char *, void *); void dump_lkcd_environment_v1(ulong); uint32_t get_dp_size_v1(void); uint32_t get_dp_flags_v1(void); uint64_t get_dp_address_v1(void); /* * lkcd_v2_v3.c */ int lkcd_dump_init_v2_v3(FILE *, int); void dump_dump_page_v2_v3(char *, void *); void dump_lkcd_environment_v2_v3(ulong); uint32_t get_dp_size_v2_v3(void); uint32_t get_dp_flags_v2_v3(void); uint64_t get_dp_address_v2_v3(void); /* * lkcd_v5.c */ int lkcd_dump_init_v5(FILE *, int); void dump_dump_page_v5(char *, void *); void dump_lkcd_environment_v5(ulong); uint32_t get_dp_size_v5(void); uint32_t get_dp_flags_v5(void); uint64_t get_dp_address_v5(void); /* * lkcd_v7.c */ int lkcd_dump_init_v7(FILE *, int, char *); void dump_dump_page_v7(char *, void *); void dump_lkcd_environment_v7(ulong); uint32_t get_dp_size_v7(void); uint32_t get_dp_flags_v7(void); uint64_t get_dp_address_v7(void); /* * lkcd_v8.c */ int lkcd_dump_init_v8(FILE *, int, char *); void dump_dump_page_v8(char *, void *); void dump_lkcd_environment_v8(ulong); uint32_t get_dp_size_v8(void); uint32_t get_dp_flags_v8(void); uint64_t get_dp_address_v8(void); #ifdef LKCD_COMMON /* * Until they differ across versions, these remain usable in the common * routines in lkcd_common.c */ #define LKCD_DUMP_MAGIC_NUMBER (0xa8190173618f23edULL) #define LKCD_DUMP_MAGIC_LIVE (0xa8190173618f23cdULL) #define LKCD_DUMP_V1 (0x1) /* DUMP_VERSION_NUMBER */ #define LKCD_DUMP_V2 (0x2) /* DUMP_VERSION_NUMBER */ #define LKCD_DUMP_V3 (0x3) /* DUMP_VERSION_NUMBER */ #define LKCD_DUMP_V5 (0x5) /* DUMP_VERSION_NUMBER */ #define LKCD_DUMP_V6 (0x6) /* DUMP_VERSION_NUMBER */ #define LKCD_DUMP_V7 (0x7) /* DUMP_VERSION_NUMBER */ #define LKCD_DUMP_V8 (0x8) /* DUMP_VERSION_NUMBER */ #define LKCD_DUMP_V9 (0x9) /* DUMP_VERSION_NUMBER */ #define LKCD_DUMP_V10 (0xa) /* DUMP_VERSION_NUMBER */ #define LKCD_DUMP_VERSION_NUMBER_MASK (0xf) #define LKCD_DUMP_RAW (0x1) /* DUMP_[DH_]RAW */ #define LKCD_DUMP_COMPRESSED (0x2) /* DUMP_[DH_]COMPRESSED */ #define LKCD_DUMP_END (0x4) /* DUMP_[DH_]END */ #define LKCD_DUMP_COMPRESS_NONE (0x0) /* DUMP_COMPRESS_NONE */ #define LKCD_DUMP_COMPRESS_RLE (0x1) /* DUMP_COMPRESS_RLE */ #define LKCD_DUMP_COMPRESS_GZIP (0x2) /* DUMP_COMPRESS_GZIP */ #define LKCD_DUMP_MCLX_V0 (0x80000000) /* MCLX mod of LKCD */ #define LKCD_DUMP_MCLX_V1 (0x40000000) /* Extra page header data */ #define LKCD_OFFSET_TO_FIRST_PAGE (65536) #define MCLX_PAGE_HEADERS (4096) #define MCLX_V1_PAGE_HEADER_CACHE ((sizeof(uint64_t)) * MCLX_PAGE_HEADERS) /* * lkcd_load_dump_page_header() return values */ #define LKCD_DUMPFILE_OK (0) #define LKCD_DUMPFILE_EOF (1) #define LKCD_DUMPFILE_END (2) /* * Common handling of LKCD dump environment */ #define LKCD_CACHED_PAGES (16) #define LKCD_PAGE_HASH (32) #define LKCD_DUMP_HEADER_ONLY (1) /* arguments to lkcd_dump_environment */ #define LKCD_DUMP_PAGE_ONLY (2) #define LKCD_VALID (0x1) /* flags */ #define LKCD_REMOTE (0x2) #define LKCD_NOHASH (0x4) #define LKCD_MCLX (0x8) #define LKCD_BAD_DUMP (0x10) struct page_hash_entry { uint32_t pg_flags; uint64_t pg_addr; off_t pg_hdr_offset; struct page_hash_entry *next; }; struct page_desc { off_t offset; /* lseek offset in dump file */ }; struct physmem_zone { uint64_t start; struct page_desc *pages; }; struct fix_addrs { ulong task; ulong saddr; ulong sw; }; struct lkcd_environment { int fd; /* dumpfile file descriptor */ ulong flags; /* flags from above */ ulong debug; /* shadow of pc->debug */ FILE *fp; /* abstracted fp for fprintf */ void *dump_header; /* header stash, v1 or v2 */ void *dump_header_asm; /* architecture specific header for v2 */ void *dump_header_asm_smp; /* architecture specific header for v7 & v8 */ void *dump_page; /* current page header holder */ uint32_t version; /* version number of this dump */ uint32_t page_size; /* size of a Linux memory page */ int page_shift; /* byte address to page */ int bits; /* processor bitsize */ ulong panic_task; /* panic task address */ char *panic_string; /* pointer to stashed panic string */ uint32_t compression; /* compression type */ uint32_t (*get_dp_size)(void); /* returns current page's dp_size */ uint32_t (*get_dp_flags)(void); /* returns current page's dp_size */ uint64_t (*get_dp_address)(void); /* returns current page's dp_address*/ size_t page_header_size; /* size of version's page header */ unsigned long curpos; /* offset into current page */ uint64_t curpaddr; /* current page's physical address */ off_t curhdroffs; /* current page's header offset */ char *curbufptr; /* pointer to uncompressed page buffer */ uint64_t kvbase; /* physical-to-LKCD page address format*/ char *page_cache_buf; /* base of cached buffer pages */ char *compressed_page; /* copy of compressed page data */ int evict_index; /* next page to evict */ ulong evictions; /* total evictions done */ struct page_cache_hdr { /* header for each cached page */ uint32_t pg_flags; uint64_t pg_addr; char *pg_bufptr; ulong pg_hit_count; } page_cache_hdr[LKCD_CACHED_PAGES]; struct page_hash_entry *page_hash; ulong total_pages; ulong benchmark_pages; ulong benchmarks_done; off_t *mb_hdr_offsets; ulong total_reads; ulong cached_reads; ulong hashed_reads; ulong hashed; ulong compressed; ulong raw; /* lkcd_v7 additions */ char *dumpfile_index; /* array of offsets for each page */ int ifd; /* index file for dump (LKCD V7+) */ long memory_pages; /* Mamimum index of dump pages */ off_t page_offset_max; /* Offset of page with greatest offset seen so far */ long page_index_max; /* Index of page with greatest offset seen so far */ off_t *page_offsets; /* Pointer to huge array with seek offsets */ /* NB: There are no holes in the array */ struct physmem_zone *zones; /* Array of physical memory zones */ int num_zones; /* Number of zones initialized */ int max_zones; /* Size of the zones array */ long zoned_offsets; /* Number of stored page offsets */ uint64_t zone_mask; int zone_shift; int fix_addr_num; /* Number of active stacks to switch to saved values */ struct fix_addrs *fix_addr; /* Array of active stacks to switch to saved values */ }; #define ZONE_ALLOC 128 #define ZONE_SIZE (MEGABYTES(512)) #define MEGABYTE_ALIGNED(vaddr) (!((uint64_t)(vaddr) & MEGABYTE_MASK)) #define LKCD_PAGE_HASH_INDEX(paddr) \ (((paddr) >> lkcd->page_shift) % LKCD_PAGE_HASH) #define LKCD_PAGES_PER_MEGABYTE() (MEGABYTES(1) / lkcd->page_size) #define LKCD_PAGE_MEGABYTE(page) ((page) / LKCD_PAGES_PER_MEGABYTE()) #define LKCD_BENCHMARKS_DONE() (lkcd->benchmarks_done >= lkcd->benchmark_pages) #define LKCD_VALID_PAGE(flags) ((flags) & LKCD_VALID) extern struct lkcd_environment *lkcd; #define LKCD_DEBUG(x) (lkcd->debug >= (x)) #undef BITS #undef BITS32 #undef BITS64 #define BITS() (lkcd->bits) #define BITS32() (lkcd->bits == 32) #define BITS64() (lkcd->bits == 64) #endif /* LKCD_COMMON */ /* * gdb_interface.c */ void gdb_main_loop(int, char **); void display_gdb_banner(void); void get_gdb_version(void); void gdb_session_init(void); void gdb_interface(struct gnu_request *); int gdb_pass_through(char *, FILE *, ulong); int gdb_readmem_callback(ulong, void *, int, int); int gdb_line_number_callback(ulong, ulong, ulong); int gdb_print_callback(ulong); char *gdb_lookup_module_symbol(ulong, ulong *); void gdb_error_hook(void); void restore_gdb_sanity(void); int is_gdb_command(int, ulong); char *gdb_command_string(int, char *, int); void dump_gnu_request(struct gnu_request *, int); int gdb_CRASHDEBUG(ulong); void dump_gdb_data(void); void update_gdb_hooks(void); void gdb_readnow_warning(void); int gdb_set_crash_scope(ulong, char *); extern int *gdb_output_format; extern unsigned int *gdb_print_max; extern unsigned char *gdb_prettyprint_structs; extern unsigned char *gdb_prettyprint_arrays; extern unsigned int *gdb_repeat_count_threshold; extern unsigned char *gdb_stop_print_at_null; extern unsigned int *gdb_output_radix; int is_kvaddr(ulong); /* * gdb/top.c */ extern void execute_command (char *, int); #if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) extern void (*command_loop_hook)(void); extern void (*error_hook)(void); #else extern void (*deprecated_command_loop_hook)(void); /* * gdb/exceptions.c */ extern void (*error_hook)(void); #endif /* * gdb/symtab.c */ extern void gdb_command_funnel(struct gnu_request *); /* * gdb/symfile.c */ #if defined(GDB_6_0) || defined(GDB_6_1) struct objfile; extern void (*target_new_objfile_hook)(struct objfile *); #endif /* * gdb/valprint.c */ extern unsigned output_radix; #if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) extern int output_format; extern int prettyprint_structs; extern int prettyprint_arrays; extern int repeat_count_threshold; extern unsigned int print_max; extern int stop_print_at_null; #endif #ifdef GDB_7_6 /* * gdb/cleanups.c */ struct cleanup; extern struct cleanup *all_cleanups(void); extern void do_cleanups(struct cleanup *); #else /* * gdb/utils.c */ extern void do_cleanups(void *); #endif /* * gdb/version.c */ extern char *version; /* * gdb/disasm.c */ #ifdef GDB_5_3 extern int gdb_disassemble_from_exec; #endif /* * readline/readline.c */ #ifdef GDB_5_3 extern char *readline(char *); #else extern char *readline(const char *); #endif extern int rl_editing_mode; /* * readline/history.c */ extern int history_offset; /* * external gdb routines */ extern int gdb_main_entry(int, char **); #ifdef GDB_5_3 extern unsigned long calc_crc32(unsigned long, unsigned char *, size_t); #else extern unsigned long gnu_debuglink_crc32 (unsigned long, unsigned char *, size_t); #endif extern int have_partial_symbols(void *); extern int have_full_symbols(void *); #if defined(X86) || defined(X86_64) || defined(IA64) #define XEN_HYPERVISOR_ARCH #endif #ifndef offsetof #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #endif #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) #define REG_SEQ(TYPE, MEMBER) \ (offsetof(struct TYPE, MEMBER) / FIELD_SIZEOF(struct TYPE, MEMBER)) /* * Register numbers must be in sync with gdb/features/i386/64bit-core.c * to make crash_target->fetch_registers() ---> machdep->get_current_task_reg() * working properly. */ enum x86_64_regnum { RAX_REGNUM, RBX_REGNUM, RCX_REGNUM, RDX_REGNUM, RSI_REGNUM, RDI_REGNUM, RBP_REGNUM, RSP_REGNUM, R8_REGNUM, R9_REGNUM, R10_REGNUM, R11_REGNUM, R12_REGNUM, R13_REGNUM, R14_REGNUM, R15_REGNUM, RIP_REGNUM, EFLAGS_REGNUM, CS_REGNUM, SS_REGNUM, DS_REGNUM, ES_REGNUM, FS_REGNUM, GS_REGNUM, ST0_REGNUM, ST1_REGNUM, ST2_REGNUM, ST3_REGNUM, ST4_REGNUM, ST5_REGNUM, ST6_REGNUM, ST7_REGNUM, FCTRL_REGNUM, FSTAT_REGNUM, FTAG_REGNUM, FISEG_REGNUM, FIOFF_REGNUM, FOSEG_REGNUM, FOOFF_REGNUM, FOP_REGNUM, FS_BASE_REGNUM = 152, GS_BASE_REGNUM, ORIG_RAX_REGNUM, LAST_REGNUM }; enum arm64_regnum { X0_REGNUM, X1_REGNUM, X2_REGNUM, X3_REGNUM, X4_REGNUM, X5_REGNUM, X6_REGNUM, X7_REGNUM, X8_REGNUM, X9_REGNUM, X10_REGNUM, X11_REGNUM, X12_REGNUM, X13_REGNUM, X14_REGNUM, X15_REGNUM, X16_REGNUM, X17_REGNUM, X18_REGNUM, X19_REGNUM, X20_REGNUM, X21_REGNUM, X22_REGNUM, X23_REGNUM, X24_REGNUM, X25_REGNUM, X26_REGNUM, X27_REGNUM, X28_REGNUM, X29_REGNUM, X30_REGNUM, SP_REGNUM, PC_REGNUM, }; /* * Register numbers to make crash_target->fetch_registers() * ---> machdep->get_current_task_reg() work properly. * * These register numbers and names are given according to output of * `rs6000_register_name`, because that is what was being used by * crash_target::fetch_registers in case of PPC64 */ enum ppc64_regnum { PPC64_R0_REGNUM = 0, PPC64_R1_REGNUM, PPC64_R2_REGNUM, PPC64_R3_REGNUM, PPC64_R4_REGNUM, PPC64_R5_REGNUM, PPC64_R6_REGNUM, PPC64_R7_REGNUM, PPC64_R8_REGNUM, PPC64_R9_REGNUM, PPC64_R10_REGNUM, PPC64_R11_REGNUM, PPC64_R12_REGNUM, PPC64_R13_REGNUM, PPC64_R14_REGNUM, PPC64_R15_REGNUM, PPC64_R16_REGNUM, PPC64_R17_REGNUM, PPC64_R18_REGNUM, PPC64_R19_REGNUM, PPC64_R20_REGNUM, PPC64_R21_REGNUM, PPC64_R22_REGNUM, PPC64_R23_REGNUM, PPC64_R24_REGNUM, PPC64_R25_REGNUM, PPC64_R26_REGNUM, PPC64_R27_REGNUM, PPC64_R28_REGNUM, PPC64_R29_REGNUM, PPC64_R30_REGNUM, PPC64_R31_REGNUM, PPC64_F0_REGNUM = 32, PPC64_F1_REGNUM, PPC64_F2_REGNUM, PPC64_F3_REGNUM, PPC64_F4_REGNUM, PPC64_F5_REGNUM, PPC64_F6_REGNUM, PPC64_F7_REGNUM, PPC64_F8_REGNUM, PPC64_F9_REGNUM, PPC64_F10_REGNUM, PPC64_F11_REGNUM, PPC64_F12_REGNUM, PPC64_F13_REGNUM, PPC64_F14_REGNUM, PPC64_F15_REGNUM, PPC64_F16_REGNUM, PPC64_F17_REGNUM, PPC64_F18_REGNUM, PPC64_F19_REGNUM, PPC64_F20_REGNUM, PPC64_F21_REGNUM, PPC64_F22_REGNUM, PPC64_F23_REGNUM, PPC64_F24_REGNUM, PPC64_F25_REGNUM, PPC64_F26_REGNUM, PPC64_F27_REGNUM, PPC64_F28_REGNUM, PPC64_F29_REGNUM, PPC64_F30_REGNUM, PPC64_F31_REGNUM, PPC64_PC_REGNUM = 64, PPC64_MSR_REGNUM = 65, PPC64_CR_REGNUM = 66, PPC64_LR_REGNUM = 67, PPC64_CTR_REGNUM = 68, PPC64_XER_REGNUM = 69, PPC64_FPSCR_REGNUM = 70, PPC64_VR0_REGNUM = 106, PPC64_VR1_REGNUM, PPC64_VR2_REGNUM, PPC64_VR3_REGNUM, PPC64_VR4_REGNUM, PPC64_VR5_REGNUM, PPC64_VR6_REGNUM, PPC64_VR7_REGNUM, PPC64_VR8_REGNUM, PPC64_VR9_REGNUM, PPC64_VR10_REGNUM, PPC64_VR11_REGNUM, PPC64_VR12_REGNUM, PPC64_VR13_REGNUM, PPC64_VR14_REGNUM, PPC64_VR15_REGNUM, PPC64_VR16_REGNUM, PPC64_VR17_REGNUM, PPC64_VR18_REGNUM, PPC64_VR19_REGNUM, PPC64_VR20_REGNUM, PPC64_VR21_REGNUM, PPC64_VR22_REGNUM, PPC64_VR23_REGNUM, PPC64_VR24_REGNUM, PPC64_VR25_REGNUM, PPC64_VR26_REGNUM, PPC64_VR27_REGNUM, PPC64_VR28_REGNUM, PPC64_VR29_REGNUM, PPC64_VR30_REGNUM, PPC64_VR31_REGNUM, PPC64_VSCR_REGNUM = 138, PPC64_VRSAVE_REGNU = 139 }; /* crash_target.c */ extern int gdb_change_thread_context (void); extern int gdb_add_substack (int); #endif /* !GDB_COMMON */ crash-utility-crash-61fe107/dev.c000066400000000000000000004616421517256214500167130ustar00rootroot00000000000000/* dev.c - core analysis suite * * Copyright (C) 2001, 2002 Mission Critical Linux, Inc. * Copyright (C) 2002-2013 David Anderson * Copyright (C) 2002-2013 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #include "defs.h" #include "vmcore.h" static void dump_blkdevs(ulong); static void dump_chrdevs(ulong); static void dump_blkdevs_v2(ulong); static void dump_blkdevs_v3(ulong); static ulong search_cdev_map_probes(char *, int, int, ulong *); static ulong search_bdev_map_probes(char *, int, int, ulong *); static ulong search_blockdev_inodes(int, ulong *); static void do_pci(void); static void do_pci2(void); static void do_io(void); static void do_resource_list(ulong, char *, int); static const char *pci_strclass (uint, char *); static const char *pci_strvendor(uint, char *); static const char *pci_strdev(uint, uint, char *); static void diskio_option(ulong flags); static struct dev_table { ulong flags; } dev_table = { 0 }; struct dev_table *dt = &dev_table; #define DEV_INIT 0x1 #define DISKIO_INIT 0x2 #define DIOF_ALL 1 << 0 #define DIOF_NONZERO 1 << 1 void dev_init(void) { MEMBER_OFFSET_INIT(pci_dev_global_list, "pci_dev", "global_list"); MEMBER_OFFSET_INIT(pci_dev_next, "pci_dev", "next"); MEMBER_OFFSET_INIT(pci_dev_bus, "pci_dev", "bus"); MEMBER_OFFSET_INIT(pci_dev_dev, "pci_dev", "dev"); MEMBER_OFFSET_INIT(pci_dev_devfn, "pci_dev", "devfn"); MEMBER_OFFSET_INIT(pci_dev_class, "pci_dev", "class"); MEMBER_OFFSET_INIT(pci_dev_device, "pci_dev", "device"); MEMBER_OFFSET_INIT(pci_dev_hdr_type, "pci_dev", "hdr_type"); MEMBER_OFFSET_INIT(pci_dev_pcie_flags_reg, "pci_dev", "pcie_flags_reg"); MEMBER_OFFSET_INIT(pci_dev_vendor, "pci_dev", "vendor"); MEMBER_OFFSET_INIT(pci_bus_number, "pci_bus", "number"); MEMBER_OFFSET_INIT(pci_bus_node, "pci_bus", "node"); MEMBER_OFFSET_INIT(pci_bus_devices, "pci_bus", "devices"); MEMBER_OFFSET_INIT(pci_bus_dev, "pci_bus", "dev"); MEMBER_OFFSET_INIT(pci_bus_children, "pci_bus", "children"); MEMBER_OFFSET_INIT(pci_bus_parent, "pci_bus", "parent"); MEMBER_OFFSET_INIT(pci_bus_self, "pci_bus", "self"); MEMBER_OFFSET_INIT(device_kobj, "device", "kobj"); MEMBER_OFFSET_INIT(kobject_name, "kobject", "name"); STRUCT_SIZE_INIT(resource, "resource"); if ((VALID_STRUCT(resource) && symbol_exists("do_resource_list")) || (VALID_STRUCT(resource) && symbol_exists("iomem_resource") && symbol_exists("ioport_resource"))) { MEMBER_OFFSET_INIT(resource_name, "resource", "name"); MEMBER_OFFSET_INIT(resource_start, "resource", "start"); MEMBER_OFFSET_INIT(resource_end, "resource", "end"); MEMBER_OFFSET_INIT(resource_sibling, "resource", "sibling"); MEMBER_OFFSET_INIT(resource_child, "resource", "child"); } else { STRUCT_SIZE_INIT(resource_entry_t, "resource_entry_t"); if (VALID_SIZE(resource_entry_t)) { MEMBER_OFFSET_INIT(resource_entry_t_from, "resource_entry_t", "from"); MEMBER_OFFSET_INIT(resource_entry_t_num, "resource_entry_t", "num"); MEMBER_OFFSET_INIT(resource_entry_t_name, "resource_entry_t", "name"); MEMBER_OFFSET_INIT(resource_entry_t_next, "resource_entry_t", "next"); } } dt->flags |= DEV_INIT; } /* * Generic command for character and block device data. */ void cmd_dev(void) { int c; int dd_index = -1; char *outputfile = NULL; ulong flags; flags = 0; while ((c = getopt(argcnt, args, "dDpiVv:")) != EOF) { switch(c) { case 'd': diskio_option(DIOF_ALL); return; case 'D': diskio_option(DIOF_NONZERO); return; case 'i': if (machine_type("S390X")) option_not_supported(c); do_io(); return; case 'p': if (machine_type("S390X")) option_not_supported(c); if (symbol_exists("pci_devices")) do_pci(); else if (symbol_exists("pci_root_buses")) do_pci2(); else option_not_supported(c); return; case 'V': if (KDUMP_DUMPFILE()) kdump_device_dump_info(fp); else if (DISKDUMP_DUMPFILE()) diskdump_device_dump_info(fp); else if (ACTIVE()) error(INFO, "-V option not supported on a live system\n"); else error(INFO, "-V option not supported on this dumpfile type\n"); return; case 'v': dd_index = atoi(optarg); break; default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); while (args[optind]) { if (dd_index >= 0) { if (!outputfile) outputfile = args[optind]; else cmd_usage(pc->curcmd, SYNOPSIS); } else cmd_usage(pc->curcmd, SYNOPSIS); optind++; } if (dd_index >= 0) { if (KDUMP_DUMPFILE()) kdump_device_dump_extract(dd_index, outputfile, fp); else if (DISKDUMP_DUMPFILE()) diskdump_device_dump_extract(dd_index, outputfile, fp); else if (ACTIVE()) error(INFO, "-v option not supported on a live system\n"); else error(INFO, "-v option not supported on this dumpfile type\n"); return; } dump_chrdevs(flags); fprintf(fp, "\n"); dump_blkdevs(flags); } #define MAX_DEV (255) #define MINORBITS 20 #define MINORMASK ((1U << MINORBITS) - 1) #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS)) #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK)) char *chrdev_hdr = "CHRDEV NAME "; char *blkdev_hdr = "BLKDEV NAME "; /* * Dump the character device data. */ static void dump_chrdevs(ulong flags) { int i; ulong addr, size; char buf[BUFSIZE]; char buf2[BUFSIZE]; struct chrdevs { ulong name; ulong ops; } chrdevs[MAX_DEV], *cp; ulong *cdp; char *char_device_struct_buf; ulong next, savenext, name, fops, cdev; int major, minor; int name_typecode; size_t name_size; if (!symbol_exists("chrdevs")) error(FATAL, "chrdevs: symbol does not exist\n"); addr = symbol_value("chrdevs"); size = VALID_STRUCT(char_device_struct) ? sizeof(void *) : sizeof(struct chrdevs); readmem(addr, KVADDR, &chrdevs[0], size * MAX_DEV, "chrdevs array", FAULT_ON_ERROR); fprintf(fp, "%s %s", chrdev_hdr, VADDR_PRLEN == 8 ? " " : ""); fprintf(fp, "%s ", mkstring(buf, VADDR_PRLEN, CENTER, "CDEV")); fprintf(fp, "%s\n", mkstring(buf, VADDR_PRLEN, LJUST, "OPERATIONS")); if (VALID_STRUCT(char_device_struct)) goto char_device_struct; for (i = 0, cp = &chrdevs[0]; i < MAX_DEV; i++, cp++) { if (!cp->ops) continue; fprintf(fp, " %3d ", i); if (cp->name) { if (read_string(cp->name, buf, BUFSIZE-1)) fprintf(fp, "%-11s ", buf); else fprintf(fp, "%-11s ", "(unknown)"); } else fprintf(fp, "%-11s ", "(unknown)"); sprintf(buf, "%s%%%dlx ", strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", VADDR_PRLEN); fprintf(fp, buf, cp->ops); value_to_symstr(cp->ops, buf, 0); if (strlen(buf)) fprintf(fp, "<%s>", buf); fprintf(fp, "\n"); } return; char_device_struct: char_device_struct_buf = GETBUF(SIZE(char_device_struct)); cdp = (ulong *)&chrdevs[0]; name_typecode = MEMBER_TYPE("char_device_struct", "name"); name_size = (size_t)MEMBER_SIZE("char_device_struct", "name"); for (i = 0; i < MAX_DEV; i++, cdp++) { if (!(*cdp)) continue; readmem(*cdp, KVADDR, char_device_struct_buf, SIZE(char_device_struct), "char_device_struct", FAULT_ON_ERROR); next = ULONG(char_device_struct_buf + OFFSET(char_device_struct_next)); name = ULONG(char_device_struct_buf + OFFSET(char_device_struct_name)); switch (name_typecode) { case TYPE_CODE_ARRAY: snprintf(buf, name_size, "%s", char_device_struct_buf + OFFSET(char_device_struct_name)); break; case TYPE_CODE_PTR: default: if (!name || !read_string(name, buf, BUFSIZE-1)) break; } major = INT(char_device_struct_buf + OFFSET(char_device_struct_major)); minor = INT(char_device_struct_buf + OFFSET(char_device_struct_baseminor)); cdev = fops = 0; if (VALID_MEMBER(char_device_struct_cdev) && VALID_STRUCT(cdev)) { cdev = ULONG(char_device_struct_buf + OFFSET(char_device_struct_cdev)); if (cdev) { addr = cdev + OFFSET(cdev_ops); readmem(addr, KVADDR, &fops, sizeof(void *), "cdev ops", FAULT_ON_ERROR); } } else { fops = ULONG(char_device_struct_buf + OFFSET(char_device_struct_fops)); } if (!fops) fops = search_cdev_map_probes(buf, major, minor, &cdev); if (!fops) { fprintf(fp, " %3d ", major); fprintf(fp, "%-13s ", buf); fprintf(fp, "%s%s\n", VADDR_PRLEN == 8 ? " " : " ", mkstring(buf, VADDR_PRLEN, CENTER, "(none)")); } else { fprintf(fp, " %3d ", major); fprintf(fp, "%-13s ", buf); sprintf(buf2, "%s%%%dlx ", strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", VADDR_PRLEN); fprintf(fp, buf2, cdev); value_to_symstr(fops, buf2, 0); if (strlen(buf2)) fprintf(fp, "%s", buf2); else fprintf(fp, "%lx", fops); fprintf(fp, "\n"); } if (CRASHDEBUG(1)) fprintf(fp, "%lx: major: %d minor: %d name: %s next: %lx cdev: %lx fops: %lx\n", *cdp, major, minor, buf, next, cdev, fops); while (next) { readmem(savenext = next, KVADDR, char_device_struct_buf, SIZE(char_device_struct), "char_device_struct", FAULT_ON_ERROR); next = ULONG(char_device_struct_buf + OFFSET(char_device_struct_next)); name = ULONG(char_device_struct_buf + OFFSET(char_device_struct_name)); switch (name_typecode) { case TYPE_CODE_ARRAY: snprintf(buf, name_size, "%s", char_device_struct_buf + OFFSET(char_device_struct_name)); break; case TYPE_CODE_PTR: default: if (!name || !read_string(name, buf, BUFSIZE-1)) sprintf(buf, "(unknown)"); break; } major = INT(char_device_struct_buf + OFFSET(char_device_struct_major)); minor = INT(char_device_struct_buf + OFFSET(char_device_struct_baseminor)); fops = cdev = 0; if (VALID_MEMBER(char_device_struct_cdev) && VALID_STRUCT(cdev)) { cdev = ULONG(char_device_struct_buf + OFFSET(char_device_struct_cdev)); if (cdev) { addr = cdev + OFFSET(cdev_ops); readmem(addr, KVADDR, &fops, sizeof(void *), "cdev ops", FAULT_ON_ERROR); } } else { fops = ULONG(char_device_struct_buf + OFFSET(char_device_struct_fops)); } if (!fops) fops = search_cdev_map_probes(buf, major, minor, &cdev); if (!fops) { fprintf(fp, " %3d ", major); fprintf(fp, "%-13s ", buf); fprintf(fp, "%s%s\n", VADDR_PRLEN == 8 ? " " : " ", mkstring(buf, VADDR_PRLEN, CENTER, "(none)")); } else { fprintf(fp, " %3d ", major); fprintf(fp, "%-13s ", buf); sprintf(buf2, "%s%%%dlx ", strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", VADDR_PRLEN); fprintf(fp, buf2, cdev); value_to_symstr(fops, buf2, 0); if (strlen(buf2)) fprintf(fp, "%s", buf2); else fprintf(fp, "%lx", fops); fprintf(fp, "\n"); } if (CRASHDEBUG(1)) fprintf(fp, "%lx: major: %d minor: %d name: %s next: %lx cdev: %lx fops: %lx\n", savenext, major, minor, buf, next, cdev, fops); } } FREEBUF(char_device_struct_buf); } /* * Search for a major/minor match by following the list headed * by the kobj_map.probes[major] array entry. The "data" member * points to a cdev structure containing the file_operations * pointer. */ static ulong search_cdev_map_probes(char *name, int major, int minor, ulong *cdev) { char *probe_buf; ulong probes[MAX_DEV]; ulong cdev_map, addr, next, ops, probe_data; uint probe_dev; if (kernel_symbol_exists("cdev_map")) get_symbol_data("cdev_map", sizeof(ulong), &cdev_map); else return 0; addr = cdev_map + OFFSET(kobj_map_probes); if (!readmem(addr, KVADDR, &probes[0], sizeof(void *) * MAX_DEV, "cdev_map.probes[]", QUIET|RETURN_ON_ERROR)) return 0; ops = 0; probe_buf = GETBUF(SIZE(probe)); next = probes[major]; while (next) { if (!readmem(next, KVADDR, probe_buf, SIZE(probe), "struct probe", QUIET|RETURN_ON_ERROR)) break; probe_dev = UINT(probe_buf + OFFSET(probe_dev)); if ((MAJOR(probe_dev) == major) && (MINOR(probe_dev) == minor)) { probe_data = ULONG(probe_buf + OFFSET(probe_data)); addr = probe_data + OFFSET(cdev_ops); if (!readmem(addr, KVADDR, &ops, sizeof(void *), "cdev ops", QUIET|RETURN_ON_ERROR)) ops = 0; else *cdev = probe_data; break; } next = ULONG(probe_buf + OFFSET(probe_next)); } FREEBUF(probe_buf); return ops; } /* * Dump the block device data. */ static void dump_blkdevs(ulong flags) { int i; ulong addr; char buf[BUFSIZE]; struct blkdevs { ulong name; ulong ops; } blkdevs[MAX_DEV], *bp; if (kernel_symbol_exists("major_names") && (kernel_symbol_exists("bdev_map") || kernel_symbol_exists("blockdev_superblock"))) { dump_blkdevs_v3(flags); return; } if (symbol_exists("all_bdevs")) { dump_blkdevs_v2(flags); return; } if (!symbol_exists("blkdevs")) error(FATAL, "blkdevs or all_bdevs: symbols do not exist\n"); addr = symbol_value("blkdevs"); readmem(addr, KVADDR, &blkdevs[0], sizeof(struct blkdevs) * MAX_DEV, "blkdevs array", FAULT_ON_ERROR); fprintf(fp, "%s%s\n", blkdev_hdr, mkstring(buf, VADDR_PRLEN, CENTER, "OPERATIONS")); for (i = 0, bp = &blkdevs[0]; i < MAX_DEV; i++, bp++) { if (!bp->ops) continue; fprintf(fp, " %3d ", i); if (bp->name) { if (read_string(bp->name, buf, BUFSIZE-1)) fprintf(fp, "%-11s ", buf); else fprintf(fp, "%-11s ", "(unknown)"); } else fprintf(fp, "%-11s ", "(unknown)"); sprintf(buf, "%s%%%dlx ", strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", VADDR_PRLEN); fprintf(fp, buf, bp->ops); value_to_symstr(bp->ops, buf, 0); if (strlen(buf)) fprintf(fp, "<%s>", buf); fprintf(fp, "\n"); } } /* * block device dump for 2.6 */ static void dump_blkdevs_v2(ulong flags) { struct list_data list_data, *ld; ulong *major_fops, *bdevlist, *gendisklist, *majorlist; int i, j, bdevcnt, len; char *block_device_buf, *gendisk_buf, *blk_major_name_buf; ulong next, savenext, fops; int major, total; char buf[BUFSIZE]; if (!symbol_exists("major_names")) error(FATAL, "major_names[] array doesn't exist in this kernel\n"); len = get_array_length("major_names", NULL, 0); block_device_buf = GETBUF(SIZE(block_device)); gendisk_buf = GETBUF(SIZE(gendisk)); ld = &list_data; BZERO(ld, sizeof(struct list_data)); get_symbol_data("all_bdevs", sizeof(void *), &ld->start); ld->end = symbol_value("all_bdevs"); ld->list_head_offset = OFFSET(block_device_bd_list); hq_open(); bdevcnt = do_list(ld); bdevlist = (ulong *)GETBUF(bdevcnt * sizeof(ulong)); gendisklist = (ulong *)GETBUF(bdevcnt * sizeof(ulong)); bdevcnt = retrieve_list(bdevlist, bdevcnt); hq_close(); total = MAX(len, bdevcnt); major_fops = (ulong *)GETBUF(sizeof(void *) * total); /* * go through the block_device list, emulating: * * ret += bdev->bd_inode->i_mapping->nrpages; */ for (i = 0; i < bdevcnt; i++) { readmem(bdevlist[i], KVADDR, block_device_buf, SIZE(block_device), "block_device buffer", FAULT_ON_ERROR); gendisklist[i] = ULONG(block_device_buf + OFFSET(block_device_bd_disk)); if (CRASHDEBUG(1)) fprintf(fp, "[%d] %lx -> %lx\n", i, bdevlist[i], gendisklist[i]); } for (i = 1; i < bdevcnt; i++) { for (j = 0; j < i; j++) { if (gendisklist[i] == gendisklist[j]) gendisklist[i] = 0; } } for (i = 0; i < bdevcnt; i++) { if (!gendisklist[i]) continue; readmem(gendisklist[i], KVADDR, gendisk_buf, SIZE(gendisk), "gendisk buffer", FAULT_ON_ERROR); fops = ULONG(gendisk_buf + OFFSET(gendisk_fops)); major = UINT(gendisk_buf + OFFSET(gendisk_major)); strncpy(buf, gendisk_buf + OFFSET(gendisk_disk_name), 32); if (CRASHDEBUG(1)) fprintf(fp, "%lx: name: [%s] major: %d fops: %lx\n", gendisklist[i], buf, major, fops); if (fops && (major < total)) major_fops[major] = fops; } FREEBUF(bdevlist); FREEBUF(gendisklist); FREEBUF(block_device_buf); FREEBUF(gendisk_buf); if (CRASHDEBUG(1)) fprintf(fp, "major_names[%d]\n", len); majorlist = (ulong *)GETBUF(len * sizeof(void *)); blk_major_name_buf = GETBUF(SIZE(blk_major_name)); readmem(symbol_value("major_names"), KVADDR, &majorlist[0], sizeof(void *) * len, "major_names array", FAULT_ON_ERROR); fprintf(fp, "%s%s\n", blkdev_hdr, mkstring(buf, VADDR_PRLEN, CENTER, "OPERATIONS")); for (i = 0; i < len; i++) { if (!majorlist[i]) continue; readmem(majorlist[i], KVADDR, blk_major_name_buf, SIZE(blk_major_name), "blk_major_name buffer", FAULT_ON_ERROR); major = UINT(blk_major_name_buf + OFFSET(blk_major_name_major)); buf[0] = NULLCHAR; strncpy(buf, blk_major_name_buf + OFFSET(blk_major_name_name), 16); next = ULONG(blk_major_name_buf + OFFSET(blk_major_name_next)); if (CRASHDEBUG(1)) fprintf(fp, "[%d] %lx major: %d name: %s next: %lx fops: %lx\n", i, majorlist[i], major, buf, next, major_fops[major]); fprintf(fp, " %3d ", major); fprintf(fp, "%-12s ", strlen(buf) ? buf : "(unknown)"); if (major_fops[major]) { sprintf(buf, "%s%%%dlx ", strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", VADDR_PRLEN); fprintf(fp, buf, major_fops[major]); value_to_symstr(major_fops[major], buf, 0); if (strlen(buf)) fprintf(fp, "<%s>", buf); } else fprintf(fp, " (unknown)"); fprintf(fp, "\n"); while (next) { readmem(savenext = next, KVADDR, blk_major_name_buf, SIZE(blk_major_name), "blk_major_name buffer", FAULT_ON_ERROR); major = UINT(blk_major_name_buf + OFFSET(blk_major_name_major)); strncpy(buf, blk_major_name_buf + OFFSET(blk_major_name_name), 16); next = ULONG(blk_major_name_buf + OFFSET(blk_major_name_next)); if (CRASHDEBUG(1)) fprintf(fp, "[%d] %lx major: %d name: %s next: %lx fops: %lx\n", i, savenext, major, buf, next, major_fops[major]); fprintf(fp, " %3d ", major); fprintf(fp, "%-12s ", strlen(buf) ? buf : "(unknown)"); if (major_fops[major]) { sprintf(buf, "%s%%%dlx ", strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", VADDR_PRLEN); fprintf(fp, buf, major_fops[major]); value_to_symstr(major_fops[major], buf, 0); if (strlen(buf)) fprintf(fp, "<%s>", buf); } else fprintf(fp, " (unknown)"); fprintf(fp, "\n"); } } FREEBUF(majorlist); FREEBUF(major_fops); FREEBUF(blk_major_name_buf); } static void dump_blkdevs_v3(ulong flags) { int i, len; ulong blk_major_name; char *blk_major_name_buf; char buf[BUFSIZE]; uint major; ulong gendisk, addr, fops; int use_bdev_map = kernel_symbol_exists("bdev_map"); if (!(len = get_array_length("major_names", NULL, 0))) len = MAX_DEV; fprintf(fp, "%s %s", blkdev_hdr, VADDR_PRLEN == 8 ? " " : ""); fprintf(fp, "%s ", mkstring(buf, VADDR_PRLEN, CENTER|RJUST, "GENDISK")); fprintf(fp, "%s\n", mkstring(buf, VADDR_PRLEN, LJUST, "OPERATIONS")); blk_major_name_buf = GETBUF(SIZE(blk_major_name)); gendisk = 0; for (i = 0; i < len; i++) { addr = symbol_value("major_names") + (i * sizeof(void *)); readmem(addr, KVADDR, &blk_major_name, sizeof(void *), "major_names[] entry", FAULT_ON_ERROR); if (!blk_major_name) continue; readmem(blk_major_name, KVADDR, blk_major_name_buf, SIZE(blk_major_name), "blk_major_name", FAULT_ON_ERROR); major = UINT(blk_major_name_buf + OFFSET(blk_major_name_major)); buf[0] = NULLCHAR; strncpy(buf, blk_major_name_buf + OFFSET(blk_major_name_name), 16); if (use_bdev_map) fops = search_bdev_map_probes(buf, major == i ? major : i, UNUSED, &gendisk); else /* v5.11 and later */ fops = search_blockdev_inodes(major, &gendisk); if (CRASHDEBUG(1)) fprintf(fp, "blk_major_name: %lx block major: %d name: %s gendisk: %lx fops: %lx\n", blk_major_name, major, buf, gendisk, fops); if (!fops) { fprintf(fp, " %3d ", major); fprintf(fp, "%-13s ", strlen(buf) ? buf : "(unknown)"); fprintf(fp, "%s%s\n", VADDR_PRLEN == 8 ? " " : " ", mkstring(buf, VADDR_PRLEN, CENTER, "(none)")); continue; } fprintf(fp, " %3d ", major); fprintf(fp, "%-13s ", strlen(buf) ? buf : "(unknown)"); sprintf(buf, "%s%%%dlx ", strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", VADDR_PRLEN); fprintf(fp, buf, gendisk); value_to_symstr(fops, buf, 0); if (strlen(buf)) fprintf(fp, "%s", buf); else fprintf(fp, "%lx", fops); fprintf(fp, "\n"); } } static ulong search_bdev_map_probes(char *name, int major, int minor, ulong *gendisk) { char *probe_buf, *gendisk_buf; ulong probes[MAX_DEV]; ulong bdev_map, addr, next, probe_data, fops; uint probe_dev; get_symbol_data("bdev_map", sizeof(ulong), &bdev_map); addr = bdev_map + OFFSET(kobj_map_probes); if (!readmem(addr, KVADDR, &probes[0], sizeof(void *) * MAX_DEV, "bdev_map.probes[]", QUIET|RETURN_ON_ERROR)) return 0; probe_buf = GETBUF(SIZE(probe)); gendisk_buf = GETBUF(SIZE(gendisk)); fops = 0; for (next = probes[major]; next; next = ULONG(probe_buf + OFFSET(probe_next))) { if (!readmem(next, KVADDR, probe_buf, SIZE(probe), "struct probe", QUIET|RETURN_ON_ERROR)) break; probe_data = ULONG(probe_buf + OFFSET(probe_data)); if (!probe_data) continue; probe_dev = UINT(probe_buf + OFFSET(probe_dev)); if (MAJOR(probe_dev) != major) continue; if (!readmem(probe_data, KVADDR, gendisk_buf, SIZE(gendisk), "gendisk buffer", QUIET|RETURN_ON_ERROR)) break; fops = ULONG(gendisk_buf + OFFSET(gendisk_fops)); if (fops) { *gendisk = probe_data; break; } } FREEBUF(probe_buf); FREEBUF(gendisk_buf); return fops; } /* For bdev_inode. See block/bdev.c */ #define I_BDEV(inode) (inode - SIZE(block_device)) static ulong search_blockdev_inodes(int major, ulong *gendisk) { struct list_data list_data, *ld; ulong addr, bd_sb, disk, fops = 0; int i, inode_count, gendisk_major; char *gendisk_buf; ld = &list_data; BZERO(ld, sizeof(struct list_data)); get_symbol_data("blockdev_superblock", sizeof(void *), &bd_sb); addr = bd_sb + OFFSET(super_block_s_inodes); if (!readmem(addr, KVADDR, &ld->start, sizeof(ulong), "blockdev_superblock.s_inodes", QUIET|RETURN_ON_ERROR)) return 0; if (empty_list(ld->start)) return 0; ld->flags |= LIST_ALLOCATE; ld->end = bd_sb + OFFSET(super_block_s_inodes); ld->list_head_offset = OFFSET(inode_i_sb_list); inode_count = do_list(ld); gendisk_buf = GETBUF(SIZE(gendisk)); for (i = 0; i < inode_count; i++) { addr = I_BDEV(ld->list_ptr[i]) + OFFSET(block_device_bd_disk); if (!readmem(addr, KVADDR, &disk, sizeof(ulong), "block_device.bd_disk", QUIET|RETURN_ON_ERROR)) continue; if (!disk) continue; if (!readmem(disk, KVADDR, gendisk_buf, SIZE(gendisk), "gendisk buffer", QUIET|RETURN_ON_ERROR)) continue; gendisk_major = INT(gendisk_buf + OFFSET(gendisk_major)); if (gendisk_major != major) continue; fops = ULONG(gendisk_buf + OFFSET(gendisk_fops)); if (fops) { *gendisk = disk; break; } } FREEBUF(ld->list_ptr); FREEBUF(gendisk_buf); return fops; } void dump_dev_table(void) { struct dev_table *dt; int others; dt = &dev_table; others = 0; fprintf(fp, " flags: %lx (", dt->flags); if (dt->flags & DEV_INIT) fprintf(fp, "%sDEV_INIT", others++ ? "|" : ""); if (dt->flags & DISKIO_INIT) fprintf(fp, "%sDISKIO_INIT", others++ ? "|" : ""); fprintf(fp, ")\n"); } /* * Dump the I/O ports. */ static void do_io(void) { int i, c, len, wrap, cnt, size; ulong *resource_list, name, start, end; char *resource_buf, *p1; struct list_data list_data, *ld; char buf1[BUFSIZE]; char buf2[BUFSIZE]; if (symbol_exists("get_ioport_list")) /* linux 2.2 */ goto ioport_list; if (symbol_exists("do_resource_list")) /* linux 2.4 */ goto resource_list; if (symbol_exists("iomem_resource") && symbol_exists("ioport_resource")) goto resource_list; return; ioport_list: /* * ioport */ fprintf(fp, "%s %s NAME\n", mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "RESOURCE"), mkstring(buf2, 9, CENTER|LJUST, "RANGE")); wrap = VADDR_PRLEN + 2 + 9 + 2; resource_buf = GETBUF(SIZE(resource_entry_t)); ld = &list_data; BZERO(ld, sizeof(struct list_data)); ld->start = 0xc026cf20; readmem(symbol_value("iolist") + OFFSET(resource_entry_t_next), KVADDR, &ld->start, sizeof(void *), "iolist.next", FAULT_ON_ERROR); ld->member_offset = OFFSET(resource_entry_t_next); hq_open(); cnt = do_list(ld); if (!cnt) return; resource_list = (ulong *)GETBUF(cnt * sizeof(ulong)); cnt = retrieve_list(resource_list, cnt); hq_close(); for (i = 0; i < cnt; i++) { fprintf(fp, "%lx ", resource_list[i]); readmem(resource_list[i], KVADDR, resource_buf, SIZE(resource_entry_t), "resource_entry_t", FAULT_ON_ERROR); start = ULONG(resource_buf + OFFSET(resource_entry_t_from)); end = ULONG(resource_buf + OFFSET(resource_entry_t_num)); end += start; fprintf(fp, "%04lx-%04lx ", start, end); name = ULONG(resource_buf + OFFSET(resource_entry_t_name)); if (!read_string(name, buf1, BUFSIZE-1)) sprintf(buf1, "(unknown)"); if (wrap + strlen(buf1) <= 80) fprintf(fp, "%s\n", buf1); else { len = wrap + strlen(buf1) - 80; for (c = 0, p1 = &buf1[strlen(buf1)-1]; p1 > buf1; p1--, c++) { if (*p1 != ' ') continue; if (c >= len) { *p1 = NULLCHAR; break; } } fprintf(fp, "%s\n", buf1); if (*p1 == NULLCHAR) { pad_line(fp, wrap, ' '); fprintf(fp, "%s\n", p1+1); } } } return; resource_list: resource_buf = GETBUF(SIZE(resource)); /* * ioport */ readmem(symbol_value("ioport_resource") + OFFSET(resource_end), KVADDR, &end, sizeof(long), "ioport_resource.end", FAULT_ON_ERROR); size = (end > 0xffff) ? 8 : 4; fprintf(fp, "%s %s NAME\n", mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "RESOURCE"), mkstring(buf2, (size*2) + 1, CENTER|LJUST, "RANGE")); do_resource_list(symbol_value("ioport_resource"), resource_buf, size); /* * iomem */ readmem(symbol_value("iomem_resource") + OFFSET(resource_end), KVADDR, &end, sizeof(long), "iomem_resource.end", FAULT_ON_ERROR); size = (end > 0xffff) ? 8 : 4; fprintf(fp, "\n%s %s NAME\n", mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "RESOURCE"), mkstring(buf2, (size*2) + 1, CENTER|LJUST, "RANGE")); do_resource_list(symbol_value("iomem_resource"), resource_buf, size); return; } static void do_resource_list(ulong first_entry, char *resource_buf, int size) { ulong entry, name, start, end, child, sibling; int c, wrap, len; char buf1[BUFSIZE]; char *fmt, *p1; fmt = NULL; switch (size) { case 4: fmt = "%8lx %04lx-%04lx"; break; case 8: fmt = "%8lx %08lx-%08lx"; break; } wrap = VADDR_PRLEN + 2 + ((size*2)+1) + 2; entry = first_entry; while (entry) { readmem(entry, KVADDR, resource_buf, SIZE(resource), "resource", FAULT_ON_ERROR); start = ULONG(resource_buf + OFFSET(resource_start)); end = ULONG(resource_buf + OFFSET(resource_end)); name = ULONG(resource_buf + OFFSET(resource_name)); child = ULONG(resource_buf + OFFSET(resource_child)); sibling = ULONG(resource_buf + OFFSET(resource_sibling)); if (!read_string(name, buf1, BUFSIZE-1)) sprintf(buf1, "(unknown)"); fprintf(fp, fmt, entry, start, end); if (wrap + strlen(buf1) <= 80) fprintf(fp, " %s\n", buf1); else { len = wrap + strlen(buf1) - 80; for (c = 0, p1 = &buf1[strlen(buf1)-1]; p1 > buf1; p1--, c++) { if (*p1 != ' ') continue; if (c >= len) { *p1 = NULLCHAR; break; } } fprintf(fp, " %s\n", buf1); if (*p1 == NULLCHAR) { pad_line(fp, wrap, ' '); fprintf(fp, "%s\n", p1+1); } } if (child && (child != entry)) do_resource_list(child, resource_buf, size); entry = sibling; } } /* * PCI defines taken from 2.2.17 version of pci.h */ #define USE_2_2_17_PCI_H #ifdef USE_2_2_17_PCI_H /* * PCI defines and function prototypes * Copyright 1994, Drew Eckhardt * Copyright 1997--1999 Martin Mares * * For more information, please consult the following manuals (look at * http://www.pcisig.com/ for how to get them): * * PCI BIOS Specification * PCI Local Bus Specification * PCI to PCI Bridge Specification * PCI System Design Guide */ /* * Under PCI, each device has 256 bytes of configuration address space, * of which the first 64 bytes are standardized as follows: */ #define PCI_VENDOR_ID 0x00 /* 16 bits */ #define PCI_DEVICE_ID 0x02 /* 16 bits */ #define PCI_COMMAND 0x04 /* 16 bits */ #define PCI_COMMAND_IO 0x1 /* Enable response in I/O space */ #define PCI_COMMAND_MEMORY 0x2 /* Enable response in Memory space */ #define PCI_COMMAND_MASTER 0x4 /* Enable bus mastering */ #define PCI_COMMAND_SPECIAL 0x8 /* Enable response to special cycles */ #define PCI_COMMAND_INVALIDATE 0x10 /* Use memory write and invalidate */ #define PCI_COMMAND_VGA_PALETTE 0x20 /* Enable palette snooping */ #define PCI_COMMAND_PARITY 0x40 /* Enable parity checking */ #define PCI_COMMAND_WAIT 0x80 /* Enable address/data stepping */ #define PCI_COMMAND_SERR 0x100 /* Enable SERR */ #define PCI_COMMAND_FAST_BACK 0x200 /* Enable back-to-back writes */ #define PCI_STATUS 0x06 /* 16 bits */ #define PCI_STATUS_CAP_LIST 0x10 /* Support Capability List */ #define PCI_STATUS_66MHZ 0x20 /* Support 66 Mhz PCI 2.1 bus */ #define PCI_STATUS_UDF 0x40 /* Support User Definable Features */ #define PCI_STATUS_FAST_BACK 0x80 /* Accept fast-back to back */ #define PCI_STATUS_PARITY 0x100 /* Detected parity error */ #define PCI_STATUS_DEVSEL_MASK 0x600 /* DEVSEL timing */ #define PCI_STATUS_DEVSEL_FAST 0x000 #define PCI_STATUS_DEVSEL_MEDIUM 0x200 #define PCI_STATUS_DEVSEL_SLOW 0x400 #define PCI_STATUS_SIG_TARGET_ABORT 0x800 /* Set on target abort */ #define PCI_STATUS_REC_TARGET_ABORT 0x1000 /* Master ack of " */ #define PCI_STATUS_REC_MASTER_ABORT 0x2000 /* Set on master abort */ #define PCI_STATUS_SIG_SYSTEM_ERROR 0x4000 /* Set when we drive SERR */ #define PCI_STATUS_DETECTED_PARITY 0x8000 /* Set on parity error */ #define PCI_CLASS_REVISION 0x08 /* High 24 bits are class, low 8 revision */ #define PCI_REVISION_ID 0x08 /* Revision ID */ #define PCI_CLASS_PROG 0x09 /* Reg. Level Programming Interface */ #define PCI_CLASS_DEVICE 0x0a /* Device class */ #define PCI_CACHE_LINE_SIZE 0x0c /* 8 bits */ #define PCI_LATENCY_TIMER 0x0d /* 8 bits */ #define PCI_HEADER_TYPE 0x0e /* 8 bits */ #define PCI_HEADER_TYPE_NORMAL 0 #define PCI_HEADER_TYPE_BRIDGE 1 #define PCI_HEADER_TYPE_CARDBUS 2 #define PCI_BIST 0x0f /* 8 bits */ #define PCI_BIST_CODE_MASK 0x0f /* Return result */ #define PCI_BIST_START 0x40 /* 1 to start BIST, 2 secs or less */ #define PCI_BIST_CAPABLE 0x80 /* 1 if BIST capable */ /* * Base addresses specify locations in memory or I/O space. * Decoded size can be determined by writing a value of * 0xffffffff to the register, and reading it back. Only * 1 bits are decoded. */ #define PCI_BASE_ADDRESS_0 0x10 /* 32 bits */ #define PCI_BASE_ADDRESS_1 0x14 /* 32 bits [htype 0,1 only] */ #define PCI_BASE_ADDRESS_2 0x18 /* 32 bits [htype 0 only] */ #define PCI_BASE_ADDRESS_3 0x1c /* 32 bits */ #define PCI_BASE_ADDRESS_4 0x20 /* 32 bits */ #define PCI_BASE_ADDRESS_5 0x24 /* 32 bits */ #define PCI_BASE_ADDRESS_SPACE 0x01 /* 0 = memory, 1 = I/O */ #define PCI_BASE_ADDRESS_SPACE_IO 0x01 #define PCI_BASE_ADDRESS_SPACE_MEMORY 0x00 #define PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x06 #define PCI_BASE_ADDRESS_MEM_TYPE_32 0x00 /* 32 bit address */ #define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02 /* Below 1M */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04 /* 64 bit address */ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08 /* prefetchable? */ #define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) #define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) /* bit 1 is reserved if address_space = 1 */ /* Header type 0 (normal devices) */ #define PCI_CARDBUS_CIS 0x28 #define PCI_SUBSYSTEM_VENDOR_ID 0x2c #define PCI_SUBSYSTEM_ID 0x2e #define PCI_ROM_ADDRESS 0x30 /* Bits 31..11 are address, 10..1 reserved */ #define PCI_ROM_ADDRESS_ENABLE 0x01 #define PCI_ROM_ADDRESS_MASK (~0x7ffUL) #define PCI_CAPABILITY_LIST 0x34 /* Offset of first capability list entry */ /* 0x35-0x3b are reserved */ #define PCI_INTERRUPT_LINE 0x3c /* 8 bits */ #define PCI_INTERRUPT_PIN 0x3d /* 8 bits */ #define PCI_MIN_GNT 0x3e /* 8 bits */ #define PCI_MAX_LAT 0x3f /* 8 bits */ /* Header type 1 (PCI-to-PCI bridges) */ #define PCI_PRIMARY_BUS 0x18 /* Primary bus number */ #define PCI_SECONDARY_BUS 0x19 /* Secondary bus number */ #define PCI_SUBORDINATE_BUS 0x1a /* Highest bus number behind the bridge */ #define PCI_SEC_LATENCY_TIMER 0x1b /* Latency timer for secondary interface */ #define PCI_IO_BASE 0x1c /* I/O range behind the bridge */ #define PCI_IO_LIMIT 0x1d #define PCI_IO_RANGE_TYPE_MASK 0x0f /* I/O bridging type */ #define PCI_IO_RANGE_TYPE_16 0x00 #define PCI_IO_RANGE_TYPE_32 0x01 #define PCI_IO_RANGE_MASK ~0x0f #define PCI_SEC_STATUS 0x1e /* Secondary status register, only bit 14 used */ #define PCI_MEMORY_BASE 0x20 /* Memory range behind */ #define PCI_MEMORY_LIMIT 0x22 #define PCI_MEMORY_RANGE_TYPE_MASK 0x0f #define PCI_MEMORY_RANGE_MASK ~0x0f #define PCI_PREF_MEMORY_BASE 0x24 /* Prefetchable memory range behind */ #define PCI_PREF_MEMORY_LIMIT 0x26 #define PCI_PREF_RANGE_TYPE_MASK 0x0f #define PCI_PREF_RANGE_TYPE_32 0x00 #define PCI_PREF_RANGE_TYPE_64 0x01 #define PCI_PREF_RANGE_MASK ~0x0f #define PCI_PREF_BASE_UPPER32 0x28 /* Upper half of prefetchable memory range */ #define PCI_PREF_LIMIT_UPPER32 0x2c #define PCI_IO_BASE_UPPER16 0x30 /* Upper half of I/O addresses */ #define PCI_IO_LIMIT_UPPER16 0x32 /* 0x34-0x3b is reserved */ #define PCI_ROM_ADDRESS1 0x38 /* Same as PCI_ROM_ADDRESS, but for htype 1 */ /* 0x3c-0x3d are same as for htype 0 */ #define PCI_BRIDGE_CONTROL 0x3e #define PCI_BRIDGE_CTL_PARITY 0x01 /* Enable parity detection on secondary interface */ #define PCI_BRIDGE_CTL_SERR 0x02 /* The same for SERR forwarding */ #define PCI_BRIDGE_CTL_NO_ISA 0x04 /* Disable bridging of ISA ports */ #define PCI_BRIDGE_CTL_VGA 0x08 /* Forward VGA addresses */ #define PCI_BRIDGE_CTL_MASTER_ABORT 0x20 /* Report master aborts */ #define PCI_BRIDGE_CTL_BUS_RESET 0x40 /* Secondary bus reset */ #define PCI_BRIDGE_CTL_FAST_BACK 0x80 /* Fast Back2Back enabled on secondary interface */ /* Header type 2 (CardBus bridges) */ /* 0x14-0x15 reserved */ #define PCI_CB_SEC_STATUS 0x16 /* Secondary status */ #define PCI_CB_PRIMARY_BUS 0x18 /* PCI bus number */ #define PCI_CB_CARD_BUS 0x19 /* CardBus bus number */ #define PCI_CB_SUBORDINATE_BUS 0x1a /* Subordinate bus number */ #define PCI_CB_LATENCY_TIMER 0x1b /* CardBus latency timer */ #define PCI_CB_MEMORY_BASE_0 0x1c #define PCI_CB_MEMORY_LIMIT_0 0x20 #define PCI_CB_MEMORY_BASE_1 0x24 #define PCI_CB_MEMORY_LIMIT_1 0x28 #define PCI_CB_IO_BASE_0 0x2c #define PCI_CB_IO_BASE_0_HI 0x2e #define PCI_CB_IO_LIMIT_0 0x30 #define PCI_CB_IO_LIMIT_0_HI 0x32 #define PCI_CB_IO_BASE_1 0x34 #define PCI_CB_IO_BASE_1_HI 0x36 #define PCI_CB_IO_LIMIT_1 0x38 #define PCI_CB_IO_LIMIT_1_HI 0x3a #define PCI_CB_IO_RANGE_MASK ~0x03 /* 0x3c-0x3d are same as for htype 0 */ #define PCI_CB_BRIDGE_CONTROL 0x3e #define PCI_CB_BRIDGE_CTL_PARITY 0x01 /* Similar to standard bridge control register */ #define PCI_CB_BRIDGE_CTL_SERR 0x02 #define PCI_CB_BRIDGE_CTL_ISA 0x04 #define PCI_CB_BRIDGE_CTL_VGA 0x08 #define PCI_CB_BRIDGE_CTL_MASTER_ABORT 0x20 #define PCI_CB_BRIDGE_CTL_CB_RESET 0x40 /* CardBus reset */ #define PCI_CB_BRIDGE_CTL_16BIT_INT 0x80 /* Enable interrupt for 16-bit cards */ #define PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 0x100 /* Prefetch enable for both memory regions */ #define PCI_CB_BRIDGE_CTL_PREFETCH_MEM1 0x200 #define PCI_CB_BRIDGE_CTL_POST_WRITES 0x400 #define PCI_CB_SUBSYSTEM_VENDOR_ID 0x40 #define PCI_CB_SUBSYSTEM_ID 0x42 #define PCI_CB_LEGACY_MODE_BASE 0x44 /* 16-bit PC Card legacy mode base address (ExCa) */ /* 0x48-0x7f reserved */ /* Capability lists */ #define PCI_CAP_LIST_ID 0 /* Capability ID */ #define PCI_CAP_ID_PM 0x01 /* Power Management */ #define PCI_CAP_ID_AGP 0x02 /* Accelerated Graphics Port */ #define PCI_CAP_LIST_NEXT 1 /* Next capability in the list */ /* Device classes and subclasses */ #define PCI_CLASS_NOT_DEFINED 0x0000 #define PCI_CLASS_NOT_DEFINED_VGA 0x0001 #define PCI_BASE_CLASS_STORAGE 0x01 #define PCI_CLASS_STORAGE_SCSI 0x0100 #define PCI_CLASS_STORAGE_IDE 0x0101 #define PCI_CLASS_STORAGE_FLOPPY 0x0102 #define PCI_CLASS_STORAGE_IPI 0x0103 #define PCI_CLASS_STORAGE_RAID 0x0104 #define PCI_CLASS_STORAGE_OTHER 0x0180 #define PCI_BASE_CLASS_NETWORK 0x02 #define PCI_CLASS_NETWORK_ETHERNET 0x0200 #define PCI_CLASS_NETWORK_TOKEN_RING 0x0201 #define PCI_CLASS_NETWORK_FDDI 0x0202 #define PCI_CLASS_NETWORK_ATM 0x0203 #define PCI_CLASS_NETWORK_OTHER 0x0280 #define PCI_BASE_CLASS_DISPLAY 0x03 #define PCI_CLASS_DISPLAY_VGA 0x0300 #define PCI_CLASS_DISPLAY_XGA 0x0301 #define PCI_CLASS_DISPLAY_OTHER 0x0380 #define PCI_BASE_CLASS_MULTIMEDIA 0x04 #define PCI_CLASS_MULTIMEDIA_VIDEO 0x0400 #define PCI_CLASS_MULTIMEDIA_AUDIO 0x0401 #define PCI_CLASS_MULTIMEDIA_OTHER 0x0480 #define PCI_BASE_CLASS_MEMORY 0x05 #define PCI_CLASS_MEMORY_RAM 0x0500 #define PCI_CLASS_MEMORY_FLASH 0x0501 #define PCI_CLASS_MEMORY_OTHER 0x0580 #define PCI_BASE_CLASS_BRIDGE 0x06 #define PCI_CLASS_BRIDGE_HOST 0x0600 #define PCI_CLASS_BRIDGE_ISA 0x0601 #define PCI_CLASS_BRIDGE_EISA 0x0602 #define PCI_CLASS_BRIDGE_MC 0x0603 #define PCI_CLASS_BRIDGE_PCI 0x0604 #define PCI_CLASS_BRIDGE_PCMCIA 0x0605 #define PCI_CLASS_BRIDGE_NUBUS 0x0606 #define PCI_CLASS_BRIDGE_CARDBUS 0x0607 #define PCI_CLASS_BRIDGE_OTHER 0x0680 #define PCI_BASE_CLASS_COMMUNICATION 0x07 #define PCI_CLASS_COMMUNICATION_SERIAL 0x0700 #define PCI_CLASS_COMMUNICATION_PARALLEL 0x0701 #define PCI_CLASS_COMMUNICATION_OTHER 0x0780 #define PCI_BASE_CLASS_SYSTEM 0x08 #define PCI_CLASS_SYSTEM_PIC 0x0800 #define PCI_CLASS_SYSTEM_DMA 0x0801 #define PCI_CLASS_SYSTEM_TIMER 0x0802 #define PCI_CLASS_SYSTEM_RTC 0x0803 #define PCI_CLASS_SYSTEM_OTHER 0x0880 #define PCI_BASE_CLASS_INPUT 0x09 #define PCI_CLASS_INPUT_KEYBOARD 0x0900 #define PCI_CLASS_INPUT_PEN 0x0901 #define PCI_CLASS_INPUT_MOUSE 0x0902 #define PCI_CLASS_INPUT_OTHER 0x0980 #define PCI_BASE_CLASS_DOCKING 0x0a #define PCI_CLASS_DOCKING_GENERIC 0x0a00 #define PCI_CLASS_DOCKING_OTHER 0x0a01 #define PCI_BASE_CLASS_PROCESSOR 0x0b #define PCI_CLASS_PROCESSOR_386 0x0b00 #define PCI_CLASS_PROCESSOR_486 0x0b01 #define PCI_CLASS_PROCESSOR_PENTIUM 0x0b02 #define PCI_CLASS_PROCESSOR_ALPHA 0x0b10 #define PCI_CLASS_PROCESSOR_POWERPC 0x0b20 #define PCI_CLASS_PROCESSOR_CO 0x0b40 #define PCI_BASE_CLASS_SERIAL 0x0c #define PCI_CLASS_SERIAL_FIREWIRE 0x0c00 #define PCI_CLASS_SERIAL_ACCESS 0x0c01 #define PCI_CLASS_SERIAL_SSA 0x0c02 #define PCI_CLASS_SERIAL_USB 0x0c03 #define PCI_CLASS_SERIAL_FIBER 0x0c04 #define PCI_CLASS_SERIAL_SMBUS 0x0c05 #define PCI_BASE_CLASS_INTELLIGENT 0x0e #define PCI_CLASS_INTELLIGENT_I2O 0x0e00 #define PCI_CLASS_HOT_SWAP_CONTROLLER 0xff00 #define PCI_CLASS_OTHERS 0xff /* * Vendor and card ID's: sort these numerically according to vendor * (and according to card ID within vendor). Send all updates to * . */ #define PCI_VENDOR_ID_COMPAQ 0x0e11 #define PCI_DEVICE_ID_COMPAQ_TOKENRING 0x0508 #define PCI_DEVICE_ID_COMPAQ_1280 0x3033 #define PCI_DEVICE_ID_COMPAQ_TRIFLEX 0x4000 #define PCI_DEVICE_ID_COMPAQ_6010 0x6010 #define PCI_DEVICE_ID_COMPAQ_SMART2P 0xae10 #define PCI_DEVICE_ID_COMPAQ_NETEL100 0xae32 #define PCI_DEVICE_ID_COMPAQ_NETEL10 0xae34 #define PCI_DEVICE_ID_COMPAQ_NETFLEX3I 0xae35 #define PCI_DEVICE_ID_COMPAQ_NETEL100D 0xae40 #define PCI_DEVICE_ID_COMPAQ_NETEL100PI 0xae43 #define PCI_DEVICE_ID_COMPAQ_NETEL100I 0xb011 #define PCI_DEVICE_ID_COMPAQ_THUNDER 0xf130 #define PCI_DEVICE_ID_COMPAQ_NETFLEX3B 0xf150 #define PCI_VENDOR_ID_NCR 0x1000 #define PCI_DEVICE_ID_NCR_53C810 0x0001 #define PCI_DEVICE_ID_NCR_53C820 0x0002 #define PCI_DEVICE_ID_NCR_53C825 0x0003 #define PCI_DEVICE_ID_NCR_53C815 0x0004 #define PCI_DEVICE_ID_NCR_53C860 0x0006 #define PCI_DEVICE_ID_NCR_53C1510D 0x000a #define PCI_DEVICE_ID_NCR_53C896 0x000b #define PCI_DEVICE_ID_NCR_53C895 0x000c #define PCI_DEVICE_ID_NCR_53C885 0x000d #define PCI_DEVICE_ID_NCR_53C875 0x000f #define PCI_DEVICE_ID_NCR_53C1510 0x0010 #define PCI_DEVICE_ID_NCR_53C875J 0x008f #define PCI_VENDOR_ID_ATI 0x1002 #define PCI_DEVICE_ID_ATI_68800 0x4158 #define PCI_DEVICE_ID_ATI_215CT222 0x4354 #define PCI_DEVICE_ID_ATI_210888CX 0x4358 #define PCI_DEVICE_ID_ATI_215GB 0x4742 #define PCI_DEVICE_ID_ATI_215GD 0x4744 #define PCI_DEVICE_ID_ATI_215GI 0x4749 #define PCI_DEVICE_ID_ATI_215GP 0x4750 #define PCI_DEVICE_ID_ATI_215GQ 0x4751 #define PCI_DEVICE_ID_ATI_215GT 0x4754 #define PCI_DEVICE_ID_ATI_215GTB 0x4755 #define PCI_DEVICE_ID_ATI_210888GX 0x4758 #define PCI_DEVICE_ID_ATI_RAGE128_LE 0x4c45 #define PCI_DEVICE_ID_ATI_RAGE128_LF 0x4c46 #define PCI_DEVICE_ID_ATI_215LG 0x4c47 #define PCI_DEVICE_ID_ATI_264LT 0x4c54 #define PCI_DEVICE_ID_ATI_RAGE128_PF 0x5046 #define PCI_DEVICE_ID_ATI_RAGE128_PR 0x5052 #define PCI_DEVICE_ID_ATI_RAGE128_RE 0x5245 #define PCI_DEVICE_ID_ATI_RAGE128_RF 0x5246 #define PCI_DEVICE_ID_ATI_RAGE128_RK 0x524b #define PCI_DEVICE_ID_ATI_RAGE128_RL 0x524c #define PCI_DEVICE_ID_ATI_264VT 0x5654 #define PCI_VENDOR_ID_VLSI 0x1004 #define PCI_DEVICE_ID_VLSI_82C592 0x0005 #define PCI_DEVICE_ID_VLSI_82C593 0x0006 #define PCI_DEVICE_ID_VLSI_82C594 0x0007 #define PCI_DEVICE_ID_VLSI_82C597 0x0009 #define PCI_DEVICE_ID_VLSI_82C541 0x000c #define PCI_DEVICE_ID_VLSI_82C543 0x000d #define PCI_DEVICE_ID_VLSI_82C532 0x0101 #define PCI_DEVICE_ID_VLSI_82C534 0x0102 #define PCI_DEVICE_ID_VLSI_82C535 0x0104 #define PCI_DEVICE_ID_VLSI_82C147 0x0105 #define PCI_DEVICE_ID_VLSI_VAS96011 0x0702 #define PCI_VENDOR_ID_ADL 0x1005 #define PCI_DEVICE_ID_ADL_2301 0x2301 #define PCI_VENDOR_ID_NS 0x100b #define PCI_DEVICE_ID_NS_87415 0x0002 #define PCI_DEVICE_ID_NS_87410 0xd001 #define PCI_VENDOR_ID_TSENG 0x100c #define PCI_DEVICE_ID_TSENG_W32P_2 0x3202 #define PCI_DEVICE_ID_TSENG_W32P_b 0x3205 #define PCI_DEVICE_ID_TSENG_W32P_c 0x3206 #define PCI_DEVICE_ID_TSENG_W32P_d 0x3207 #define PCI_DEVICE_ID_TSENG_ET6000 0x3208 #define PCI_VENDOR_ID_WEITEK 0x100e #define PCI_DEVICE_ID_WEITEK_P9000 0x9001 #define PCI_DEVICE_ID_WEITEK_P9100 0x9100 #define PCI_VENDOR_ID_DEC 0x1011 #define PCI_DEVICE_ID_DEC_BRD 0x0001 #define PCI_DEVICE_ID_DEC_TULIP 0x0002 #define PCI_DEVICE_ID_DEC_TGA 0x0004 #define PCI_DEVICE_ID_DEC_TULIP_FAST 0x0009 #define PCI_DEVICE_ID_DEC_TGA2 0x000D #define PCI_DEVICE_ID_DEC_FDDI 0x000F #define PCI_DEVICE_ID_DEC_TULIP_PLUS 0x0014 #define PCI_DEVICE_ID_DEC_21142 0x0019 #define PCI_DEVICE_ID_DEC_21052 0x0021 #define PCI_DEVICE_ID_DEC_21150 0x0022 #define PCI_DEVICE_ID_DEC_21152 0x0024 #define PCI_DEVICE_ID_DEC_21153 0x0025 #define PCI_DEVICE_ID_DEC_21154 0x0026 #define PCI_DEVICE_ID_DEC_21285 0x1065 #define PCI_DEVICE_ID_DEC_21554 0x0046 #define PCI_DEVICE_ID_COMPAQ_42XX 0x0046 #define PCI_VENDOR_ID_CIRRUS 0x1013 #define PCI_DEVICE_ID_CIRRUS_7548 0x0038 #define PCI_DEVICE_ID_CIRRUS_5430 0x00a0 #define PCI_DEVICE_ID_CIRRUS_5434_4 0x00a4 #define PCI_DEVICE_ID_CIRRUS_5434_8 0x00a8 #define PCI_DEVICE_ID_CIRRUS_5436 0x00ac #define PCI_DEVICE_ID_CIRRUS_5446 0x00b8 #define PCI_DEVICE_ID_CIRRUS_5480 0x00bc #define PCI_DEVICE_ID_CIRRUS_5464 0x00d4 #define PCI_DEVICE_ID_CIRRUS_5465 0x00d6 #define PCI_DEVICE_ID_CIRRUS_6729 0x1100 #define PCI_DEVICE_ID_CIRRUS_6832 0x1110 #define PCI_DEVICE_ID_CIRRUS_7542 0x1200 #define PCI_DEVICE_ID_CIRRUS_7543 0x1202 #define PCI_DEVICE_ID_CIRRUS_7541 0x1204 #define PCI_VENDOR_ID_IBM 0x1014 #define PCI_DEVICE_ID_IBM_FIRE_CORAL 0x000a #define PCI_DEVICE_ID_IBM_TR 0x0018 #define PCI_DEVICE_ID_IBM_82G2675 0x001d #define PCI_DEVICE_ID_IBM_MCA 0x0020 #define PCI_DEVICE_ID_IBM_82351 0x0022 #define PCI_DEVICE_ID_IBM_PYTHON 0x002d #define PCI_DEVICE_ID_IBM_SERVERAID 0x002e #define PCI_DEVICE_ID_IBM_TR_WAKE 0x003e #define PCI_DEVICE_ID_IBM_MPIC 0x0046 #define PCI_DEVICE_ID_IBM_3780IDSP 0x007d #define PCI_DEVICE_ID_IBM_MPIC_2 0xffff #define PCI_VENDOR_ID_WD 0x101c #define PCI_DEVICE_ID_WD_7197 0x3296 #define PCI_VENDOR_ID_AMD 0x1022 #define PCI_DEVICE_ID_AMD_LANCE 0x2000 #define PCI_DEVICE_ID_AMD_LANCE_HOME 0x2001 #define PCI_DEVICE_ID_AMD_SCSI 0x2020 #define PCI_VENDOR_ID_TRIDENT 0x1023 #define PCI_DEVICE_ID_TRIDENT_9397 0x9397 #define PCI_DEVICE_ID_TRIDENT_9420 0x9420 #define PCI_DEVICE_ID_TRIDENT_9440 0x9440 #define PCI_DEVICE_ID_TRIDENT_9660 0x9660 #define PCI_DEVICE_ID_TRIDENT_9750 0x9750 #define PCI_VENDOR_ID_AI 0x1025 #define PCI_DEVICE_ID_AI_M1435 0x1435 #define PCI_VENDOR_ID_MATROX 0x102B #define PCI_DEVICE_ID_MATROX_MGA_2 0x0518 #define PCI_DEVICE_ID_MATROX_MIL 0x0519 #define PCI_DEVICE_ID_MATROX_MYS 0x051A #define PCI_DEVICE_ID_MATROX_MIL_2 0x051b #define PCI_DEVICE_ID_MATROX_MIL_2_AGP 0x051f #define PCI_DEVICE_ID_MATROX_G200_PCI 0x0520 #define PCI_DEVICE_ID_MATROX_G200_AGP 0x0521 #define PCI_DEVICE_ID_MATROX_MGA_IMP 0x0d10 #define PCI_DEVICE_ID_MATROX_G100_MM 0x1000 #define PCI_DEVICE_ID_MATROX_G100_AGP 0x1001 #define PCI_VENDOR_ID_CT 0x102c #define PCI_DEVICE_ID_CT_65545 0x00d8 #define PCI_DEVICE_ID_CT_65548 0x00dc #define PCI_DEVICE_ID_CT_65550 0x00e0 #define PCI_DEVICE_ID_CT_65554 0x00e4 #define PCI_DEVICE_ID_CT_65555 0x00e5 #define PCI_VENDOR_ID_MIRO 0x1031 #define PCI_DEVICE_ID_MIRO_36050 0x5601 #define PCI_VENDOR_ID_NEC 0x1033 #define PCI_DEVICE_ID_NEC_PCX2 0x0046 #define PCI_VENDOR_ID_FD 0x1036 #define PCI_DEVICE_ID_FD_36C70 0x0000 #define PCI_VENDOR_ID_SI 0x1039 #define PCI_DEVICE_ID_SI_5591_AGP 0x0001 #define PCI_DEVICE_ID_SI_6202 0x0002 #define PCI_DEVICE_ID_SI_503 0x0008 #define PCI_DEVICE_ID_SI_ACPI 0x0009 #define PCI_DEVICE_ID_SI_5597_VGA 0x0200 #define PCI_DEVICE_ID_SI_6205 0x0205 #define PCI_DEVICE_ID_SI_501 0x0406 #define PCI_DEVICE_ID_SI_496 0x0496 #define PCI_DEVICE_ID_SI_601 0x0601 #define PCI_DEVICE_ID_SI_5107 0x5107 #define PCI_DEVICE_ID_SI_5511 0x5511 #define PCI_DEVICE_ID_SI_5513 0x5513 #define PCI_DEVICE_ID_SI_5571 0x5571 #define PCI_DEVICE_ID_SI_5591 0x5591 #define PCI_DEVICE_ID_SI_5597 0x5597 #define PCI_DEVICE_ID_SI_7001 0x7001 #define PCI_VENDOR_ID_HP 0x103c #define PCI_DEVICE_ID_HP_J2585A 0x1030 #define PCI_DEVICE_ID_HP_J2585B 0x1031 #define PCI_VENDOR_ID_PCTECH 0x1042 #define PCI_DEVICE_ID_PCTECH_RZ1000 0x1000 #define PCI_DEVICE_ID_PCTECH_RZ1001 0x1001 #define PCI_DEVICE_ID_PCTECH_SAMURAI_0 0x3000 #define PCI_DEVICE_ID_PCTECH_SAMURAI_1 0x3010 #define PCI_DEVICE_ID_PCTECH_SAMURAI_IDE 0x3020 #define PCI_VENDOR_ID_DPT 0x1044 #define PCI_DEVICE_ID_DPT 0xa400 #define PCI_VENDOR_ID_OPTI 0x1045 #define PCI_DEVICE_ID_OPTI_92C178 0xc178 #define PCI_DEVICE_ID_OPTI_82C557 0xc557 #define PCI_DEVICE_ID_OPTI_82C558 0xc558 #define PCI_DEVICE_ID_OPTI_82C621 0xc621 #define PCI_DEVICE_ID_OPTI_82C700 0xc700 #define PCI_DEVICE_ID_OPTI_82C701 0xc701 #define PCI_DEVICE_ID_OPTI_82C814 0xc814 #define PCI_DEVICE_ID_OPTI_82C822 0xc822 #define PCI_DEVICE_ID_OPTI_82C861 0xc861 #define PCI_DEVICE_ID_OPTI_82C825 0xd568 #define PCI_VENDOR_ID_SGS 0x104a #define PCI_DEVICE_ID_SGS_2000 0x0008 #define PCI_DEVICE_ID_SGS_1764 0x0009 #define PCI_VENDOR_ID_BUSLOGIC 0x104B #define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC 0x0140 #define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER 0x1040 #define PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT 0x8130 #define PCI_VENDOR_ID_TI 0x104c #define PCI_DEVICE_ID_TI_TVP4010 0x3d04 #define PCI_DEVICE_ID_TI_TVP4020 0x3d07 #define PCI_DEVICE_ID_TI_PCI1130 0xac12 #define PCI_DEVICE_ID_TI_PCI1031 0xac13 #define PCI_DEVICE_ID_TI_PCI1131 0xac15 #define PCI_DEVICE_ID_TI_PCI1250 0xac16 #define PCI_DEVICE_ID_TI_PCI1220 0xac17 #define PCI_VENDOR_ID_OAK 0x104e #define PCI_DEVICE_ID_OAK_OTI107 0x0107 /* Winbond have two vendor IDs! See 0x10ad as well */ #define PCI_VENDOR_ID_WINBOND2 0x1050 #define PCI_DEVICE_ID_WINBOND2_89C940 0x0940 #define PCI_VENDOR_ID_MOTOROLA 0x1057 #define PCI_VENDOR_ID_MOTOROLA_OOPS 0x1507 #define PCI_DEVICE_ID_MOTOROLA_MPC105 0x0001 #define PCI_DEVICE_ID_MOTOROLA_MPC106 0x0002 #define PCI_DEVICE_ID_MOTOROLA_RAVEN 0x4801 #define PCI_DEVICE_ID_MOTOROLA_FALCON 0x4802 #define PCI_DEVICE_ID_MOTOROLA_CPX8216 0x4806 #define PCI_VENDOR_ID_PROMISE 0x105a #define PCI_DEVICE_ID_PROMISE_20246 0x4d33 #define PCI_DEVICE_ID_PROMISE_5300 0x5300 #define PCI_VENDOR_ID_N9 0x105d #define PCI_DEVICE_ID_N9_I128 0x2309 #define PCI_DEVICE_ID_N9_I128_2 0x2339 #define PCI_DEVICE_ID_N9_I128_T2R 0x493d #define PCI_VENDOR_ID_UMC 0x1060 #define PCI_DEVICE_ID_UMC_UM8673F 0x0101 #define PCI_DEVICE_ID_UMC_UM8891A 0x0891 #define PCI_DEVICE_ID_UMC_UM8886BF 0x673a #define PCI_DEVICE_ID_UMC_UM8886A 0x886a #define PCI_DEVICE_ID_UMC_UM8881F 0x8881 #define PCI_DEVICE_ID_UMC_UM8886F 0x8886 #define PCI_DEVICE_ID_UMC_UM9017F 0x9017 #define PCI_DEVICE_ID_UMC_UM8886N 0xe886 #define PCI_DEVICE_ID_UMC_UM8891N 0xe891 #define PCI_VENDOR_ID_X 0x1061 #define PCI_DEVICE_ID_X_AGX016 0x0001 #define PCI_VENDOR_ID_PICOP 0x1066 #define PCI_DEVICE_ID_PICOP_PT86C52X 0x0001 #define PCI_DEVICE_ID_PICOP_PT80C524 0x8002 #define PCI_VENDOR_ID_MYLEX 0x1069 #define PCI_DEVICE_ID_MYLEX_DAC960_P 0x0001 #define PCI_DEVICE_ID_MYLEX_DAC960_PD 0x0002 #define PCI_DEVICE_ID_MYLEX_DAC960_PG 0x0010 #define PCI_DEVICE_ID_MYLEX_DAC960_LA 0x0020 #define PCI_DEVICE_ID_MYLEX_DAC960_LP 0x0050 #define PCI_DEVICE_ID_MYLEX_DAC960_BA 0xBA56 #define PCI_VENDOR_ID_APPLE 0x106b #define PCI_DEVICE_ID_APPLE_BANDIT 0x0001 #define PCI_DEVICE_ID_APPLE_GC 0x0002 #define PCI_DEVICE_ID_APPLE_HYDRA 0x000e #define PCI_VENDOR_ID_NEXGEN 0x1074 #define PCI_DEVICE_ID_NEXGEN_82C501 0x4e78 #define PCI_VENDOR_ID_QLOGIC 0x1077 #define PCI_DEVICE_ID_QLOGIC_ISP1020 0x1020 #define PCI_DEVICE_ID_QLOGIC_ISP1022 0x1022 #define PCI_DEVICE_ID_QLOGIC_ISP2100 0x2100 #define PCI_DEVICE_ID_QLOGIC_ISP2200 0x2200 #define PCI_VENDOR_ID_CYRIX 0x1078 #define PCI_DEVICE_ID_CYRIX_5510 0x0000 #define PCI_DEVICE_ID_CYRIX_PCI_MASTER 0x0001 #define PCI_DEVICE_ID_CYRIX_5520 0x0002 #define PCI_DEVICE_ID_CYRIX_5530_LEGACY 0x0100 #define PCI_DEVICE_ID_CYRIX_5530_SMI 0x0101 #define PCI_DEVICE_ID_CYRIX_5530_IDE 0x0102 #define PCI_DEVICE_ID_CYRIX_5530_AUDIO 0x0103 #define PCI_DEVICE_ID_CYRIX_5530_VIDEO 0x0104 #define PCI_VENDOR_ID_LEADTEK 0x107d #define PCI_DEVICE_ID_LEADTEK_805 0x0000 #define PCI_VENDOR_ID_CONTAQ 0x1080 #define PCI_DEVICE_ID_CONTAQ_82C599 0x0600 #define PCI_DEVICE_ID_CONTAQ_82C693 0xc693 #define PCI_VENDOR_ID_FOREX 0x1083 #define PCI_VENDOR_ID_OLICOM 0x108d #define PCI_DEVICE_ID_OLICOM_OC3136 0x0001 #define PCI_DEVICE_ID_OLICOM_OC2315 0x0011 #define PCI_DEVICE_ID_OLICOM_OC2325 0x0012 #define PCI_DEVICE_ID_OLICOM_OC2183 0x0013 #define PCI_DEVICE_ID_OLICOM_OC2326 0x0014 #define PCI_DEVICE_ID_OLICOM_OC6151 0x0021 #define PCI_VENDOR_ID_SUN 0x108e #define PCI_DEVICE_ID_SUN_EBUS 0x1000 #define PCI_DEVICE_ID_SUN_HAPPYMEAL 0x1001 #define PCI_DEVICE_ID_SUN_SIMBA 0x5000 #define PCI_DEVICE_ID_SUN_PBM 0x8000 #define PCI_DEVICE_ID_SUN_SABRE 0xa000 #define PCI_VENDOR_ID_CMD 0x1095 #define PCI_DEVICE_ID_CMD_640 0x0640 #define PCI_DEVICE_ID_CMD_643 0x0643 #define PCI_DEVICE_ID_CMD_646 0x0646 #define PCI_DEVICE_ID_CMD_647 0x0647 #define PCI_DEVICE_ID_CMD_670 0x0670 #define PCI_VENDOR_ID_VISION 0x1098 #define PCI_DEVICE_ID_VISION_QD8500 0x0001 #define PCI_DEVICE_ID_VISION_QD8580 0x0002 #define PCI_VENDOR_ID_BROOKTREE 0x109e #define PCI_DEVICE_ID_BROOKTREE_848 0x0350 #define PCI_DEVICE_ID_BROOKTREE_849A 0x0351 #define PCI_DEVICE_ID_BROOKTREE_878_1 0x036e #define PCI_DEVICE_ID_BROOKTREE_878 0x0878 #define PCI_DEVICE_ID_BROOKTREE_8474 0x8474 #define PCI_VENDOR_ID_SIERRA 0x10a8 #define PCI_DEVICE_ID_SIERRA_STB 0x0000 #define PCI_VENDOR_ID_ACC 0x10aa #define PCI_DEVICE_ID_ACC_2056 0x0000 #define PCI_VENDOR_ID_WINBOND 0x10ad #define PCI_DEVICE_ID_WINBOND_83769 0x0001 #define PCI_DEVICE_ID_WINBOND_82C105 0x0105 #define PCI_DEVICE_ID_WINBOND_83C553 0x0565 #define PCI_VENDOR_ID_DATABOOK 0x10b3 #define PCI_DEVICE_ID_DATABOOK_87144 0xb106 #define PCI_VENDOR_ID_PLX 0x10b5 #define PCI_DEVICE_ID_PLX_9050 0x9050 #define PCI_DEVICE_ID_PLX_9060 0x9060 #define PCI_DEVICE_ID_PLX_9060ES 0x906E #define PCI_DEVICE_ID_PLX_9060SD 0x906D #define PCI_DEVICE_ID_PLX_9080 0x9080 #define PCI_VENDOR_ID_MADGE 0x10b6 #define PCI_DEVICE_ID_MADGE_MK2 0x0002 #define PCI_DEVICE_ID_MADGE_C155S 0x1001 #define PCI_VENDOR_ID_3COM 0x10b7 #define PCI_DEVICE_ID_3COM_3C985 0x0001 #define PCI_DEVICE_ID_3COM_3C339 0x3390 #define PCI_DEVICE_ID_3COM_3C590 0x5900 #define PCI_DEVICE_ID_3COM_3C595TX 0x5950 #define PCI_DEVICE_ID_3COM_3C595T4 0x5951 #define PCI_DEVICE_ID_3COM_3C595MII 0x5952 #define PCI_DEVICE_ID_3COM_3C900TPO 0x9000 #define PCI_DEVICE_ID_3COM_3C900COMBO 0x9001 #define PCI_DEVICE_ID_3COM_3C905TX 0x9050 #define PCI_DEVICE_ID_3COM_3C905T4 0x9051 #define PCI_DEVICE_ID_3COM_3C905B_TX 0x9055 #define PCI_VENDOR_ID_SMC 0x10b8 #define PCI_DEVICE_ID_SMC_EPIC100 0x0005 #define PCI_VENDOR_ID_AL 0x10b9 #define PCI_DEVICE_ID_AL_M1445 0x1445 #define PCI_DEVICE_ID_AL_M1449 0x1449 #define PCI_DEVICE_ID_AL_M1451 0x1451 #define PCI_DEVICE_ID_AL_M1461 0x1461 #define PCI_DEVICE_ID_AL_M1489 0x1489 #define PCI_DEVICE_ID_AL_M1511 0x1511 #define PCI_DEVICE_ID_AL_M1513 0x1513 #define PCI_DEVICE_ID_AL_M1521 0x1521 #define PCI_DEVICE_ID_AL_M1523 0x1523 #define PCI_DEVICE_ID_AL_M1531 0x1531 #define PCI_DEVICE_ID_AL_M1533 0x1533 #define PCI_DEVICE_ID_AL_M3307 0x3307 #define PCI_DEVICE_ID_AL_M4803 0x5215 #define PCI_DEVICE_ID_AL_M5219 0x5219 #define PCI_DEVICE_ID_AL_M5229 0x5229 #define PCI_DEVICE_ID_AL_M5237 0x5237 #define PCI_DEVICE_ID_AL_M7101 0x7101 #define PCI_VENDOR_ID_MITSUBISHI 0x10ba #define PCI_VENDOR_ID_SURECOM 0x10bd #define PCI_DEVICE_ID_SURECOM_NE34 0x0e34 #define PCI_VENDOR_ID_NEOMAGIC 0x10c8 #define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_NM2070 0x0001 #define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_128V 0x0002 #define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_128ZV 0x0003 #define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_NM2160 0x0004 #define PCI_DEVICE_ID_NEOMAGIC_MAGICMEDIA_256AV 0x0005 #define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_128ZVPLUS 0x0083 #define PCI_VENDOR_ID_ASP 0x10cd #define PCI_DEVICE_ID_ASP_ABP940 0x1200 #define PCI_DEVICE_ID_ASP_ABP940U 0x1300 #define PCI_DEVICE_ID_ASP_ABP940UW 0x2300 #define PCI_VENDOR_ID_MACRONIX 0x10d9 #define PCI_DEVICE_ID_MACRONIX_MX98713 0x0512 #define PCI_DEVICE_ID_MACRONIX_MX987x5 0x0531 #define PCI_VENDOR_ID_CERN 0x10dc #define PCI_DEVICE_ID_CERN_SPSB_PMC 0x0001 #define PCI_DEVICE_ID_CERN_SPSB_PCI 0x0002 #define PCI_DEVICE_ID_CERN_HIPPI_DST 0x0021 #define PCI_DEVICE_ID_CERN_HIPPI_SRC 0x0022 #define PCI_VENDOR_ID_NVIDIA 0x10de #define PCI_VENDOR_ID_IMS 0x10e0 #define PCI_DEVICE_ID_IMS_8849 0x8849 #define PCI_VENDOR_ID_TEKRAM2 0x10e1 #define PCI_DEVICE_ID_TEKRAM2_690c 0x690c #define PCI_VENDOR_ID_TUNDRA 0x10e3 #define PCI_DEVICE_ID_TUNDRA_CA91C042 0x0000 #define PCI_VENDOR_ID_AMCC 0x10e8 #define PCI_DEVICE_ID_AMCC_MYRINET 0x8043 #define PCI_DEVICE_ID_AMCC_PARASTATION 0x8062 #define PCI_DEVICE_ID_AMCC_S5933 0x807d #define PCI_DEVICE_ID_AMCC_S5933_HEPC3 0x809c #define PCI_VENDOR_ID_INTERG 0x10ea #define PCI_DEVICE_ID_INTERG_1680 0x1680 #define PCI_DEVICE_ID_INTERG_1682 0x1682 #define PCI_VENDOR_ID_REALTEK 0x10ec #define PCI_DEVICE_ID_REALTEK_8029 0x8029 #define PCI_DEVICE_ID_REALTEK_8129 0x8129 #define PCI_DEVICE_ID_REALTEK_8139 0x8139 #define PCI_VENDOR_ID_TRUEVISION 0x10fa #define PCI_DEVICE_ID_TRUEVISION_T1000 0x000c #define PCI_VENDOR_ID_INIT 0x1101 #define PCI_DEVICE_ID_INIT_320P 0x9100 #define PCI_DEVICE_ID_INIT_360P 0x9500 #define PCI_VENDOR_ID_TTI 0x1103 #define PCI_DEVICE_ID_TTI_HPT343 0x0003 #define PCI_VENDOR_ID_VIA 0x1106 #define PCI_DEVICE_ID_VIA_82C505 0x0505 #define PCI_DEVICE_ID_VIA_82C561 0x0561 #define PCI_DEVICE_ID_VIA_82C586_1 0x0571 #define PCI_DEVICE_ID_VIA_82C576 0x0576 #define PCI_DEVICE_ID_VIA_82C585 0x0585 #define PCI_DEVICE_ID_VIA_82C586_0 0x0586 #define PCI_DEVICE_ID_VIA_82C595 0x0595 #define PCI_DEVICE_ID_VIA_82C596_0 0x0596 #define PCI_DEVICE_ID_VIA_82C597_0 0x0597 #define PCI_DEVICE_ID_VIA_82C598_0 0x0598 #define PCI_DEVICE_ID_VIA_82C926 0x0926 #define PCI_DEVICE_ID_VIA_82C416 0x1571 #define PCI_DEVICE_ID_VIA_82C595_97 0x1595 #define PCI_DEVICE_ID_VIA_82C586_2 0x3038 #define PCI_DEVICE_ID_VIA_82C586_3 0x3040 #define PCI_DEVICE_ID_VIA_82C686_5 0x3058 #define PCI_DEVICE_ID_VIA_86C100A 0x6100 #define PCI_DEVICE_ID_VIA_82C597_1 0x8597 #define PCI_DEVICE_ID_VIA_82C598_1 0x8598 #define PCI_VENDOR_ID_SMC2 0x1113 #define PCI_DEVICE_ID_SMC2_1211TX 0x1211 #define PCI_VENDOR_ID_VORTEX 0x1119 #define PCI_DEVICE_ID_VORTEX_GDT60x0 0x0000 #define PCI_DEVICE_ID_VORTEX_GDT6000B 0x0001 #define PCI_DEVICE_ID_VORTEX_GDT6x10 0x0002 #define PCI_DEVICE_ID_VORTEX_GDT6x20 0x0003 #define PCI_DEVICE_ID_VORTEX_GDT6530 0x0004 #define PCI_DEVICE_ID_VORTEX_GDT6550 0x0005 #define PCI_DEVICE_ID_VORTEX_GDT6x17 0x0006 #define PCI_DEVICE_ID_VORTEX_GDT6x27 0x0007 #define PCI_DEVICE_ID_VORTEX_GDT6537 0x0008 #define PCI_DEVICE_ID_VORTEX_GDT6557 0x0009 #define PCI_DEVICE_ID_VORTEX_GDT6x15 0x000a #define PCI_DEVICE_ID_VORTEX_GDT6x25 0x000b #define PCI_DEVICE_ID_VORTEX_GDT6535 0x000c #define PCI_DEVICE_ID_VORTEX_GDT6555 0x000d #define PCI_DEVICE_ID_VORTEX_GDT6x17RP 0x0100 #define PCI_DEVICE_ID_VORTEX_GDT6x27RP 0x0101 #define PCI_DEVICE_ID_VORTEX_GDT6537RP 0x0102 #define PCI_DEVICE_ID_VORTEX_GDT6557RP 0x0103 #define PCI_DEVICE_ID_VORTEX_GDT6x11RP 0x0104 #define PCI_DEVICE_ID_VORTEX_GDT6x21RP 0x0105 #define PCI_DEVICE_ID_VORTEX_GDT6x17RP1 0x0110 #define PCI_DEVICE_ID_VORTEX_GDT6x27RP1 0x0111 #define PCI_DEVICE_ID_VORTEX_GDT6537RP1 0x0112 #define PCI_DEVICE_ID_VORTEX_GDT6557RP1 0x0113 #define PCI_DEVICE_ID_VORTEX_GDT6x11RP1 0x0114 #define PCI_DEVICE_ID_VORTEX_GDT6x21RP1 0x0115 #define PCI_DEVICE_ID_VORTEX_GDT6x17RP2 0x0120 #define PCI_DEVICE_ID_VORTEX_GDT6x27RP2 0x0121 #define PCI_DEVICE_ID_VORTEX_GDT6537RP2 0x0122 #define PCI_DEVICE_ID_VORTEX_GDT6557RP2 0x0123 #define PCI_DEVICE_ID_VORTEX_GDT6x11RP2 0x0124 #define PCI_DEVICE_ID_VORTEX_GDT6x21RP2 0x0125 #define PCI_VENDOR_ID_EF 0x111a #define PCI_DEVICE_ID_EF_ATM_FPGA 0x0000 #define PCI_DEVICE_ID_EF_ATM_ASIC 0x0002 #define PCI_VENDOR_ID_FORE 0x1127 #define PCI_DEVICE_ID_FORE_PCA200PC 0x0210 #define PCI_DEVICE_ID_FORE_PCA200E 0x0300 #define PCI_VENDOR_ID_IMAGINGTECH 0x112f #define PCI_DEVICE_ID_IMAGINGTECH_ICPCI 0x0000 #define PCI_VENDOR_ID_PHILIPS 0x1131 #define PCI_DEVICE_ID_PHILIPS_SAA7145 0x7145 #define PCI_DEVICE_ID_PHILIPS_SAA7146 0x7146 #define PCI_VENDOR_ID_CYCLONE 0x113c #define PCI_DEVICE_ID_CYCLONE_SDK 0x0001 #define PCI_VENDOR_ID_ALLIANCE 0x1142 #define PCI_DEVICE_ID_ALLIANCE_PROMOTIO 0x3210 #define PCI_DEVICE_ID_ALLIANCE_PROVIDEO 0x6422 #define PCI_DEVICE_ID_ALLIANCE_AT24 0x6424 #define PCI_DEVICE_ID_ALLIANCE_AT3D 0x643d #define PCI_VENDOR_ID_SYSKONNECT 0x1148 #define PCI_DEVICE_ID_SYSKONNECT_FP 0x4000 #define PCI_DEVICE_ID_SYSKONNECT_TR 0x4200 #define PCI_DEVICE_ID_SYSKONNECT_GE 0x4300 #define PCI_VENDOR_ID_VMIC 0x114a #define PCI_DEVICE_ID_VMIC_VME 0x7587 #define PCI_VENDOR_ID_DIGI 0x114f #define PCI_DEVICE_ID_DIGI_EPC 0x0002 #define PCI_DEVICE_ID_DIGI_RIGHTSWITCH 0x0003 #define PCI_DEVICE_ID_DIGI_XEM 0x0004 #define PCI_DEVICE_ID_DIGI_XR 0x0005 #define PCI_DEVICE_ID_DIGI_CX 0x0006 #define PCI_DEVICE_ID_DIGI_XRJ 0x0009 #define PCI_DEVICE_ID_DIGI_EPCJ 0x000a #define PCI_DEVICE_ID_DIGI_XR_920 0x0027 #define PCI_VENDOR_ID_MUTECH 0x1159 #define PCI_DEVICE_ID_MUTECH_MV1000 0x0001 #define PCI_VENDOR_ID_RENDITION 0x1163 #define PCI_DEVICE_ID_RENDITION_VERITE 0x0001 #define PCI_DEVICE_ID_RENDITION_VERITE2100 0x2000 #define PCI_VENDOR_ID_SERVERWORKS 0x1166 #define PCI_DEVICE_ID_SERVERWORKS_HE 0x0008 #define PCI_DEVICE_ID_SERVERWORKS_LE 0x0009 #define PCI_DEVICE_ID_SERVERWORKS_CIOB30 0x0010 #define PCI_DEVICE_ID_SERVERWORKS_CMIC_HE 0x0011 #define PCI_DEVICE_ID_SERVERWORKS_CSB5 0x0201 #define PCI_VENDOR_ID_SBE 0x1176 #define PCI_DEVICE_ID_SBE_WANXL100 0x0301 #define PCI_DEVICE_ID_SBE_WANXL200 0x0302 #define PCI_DEVICE_ID_SBE_WANXL400 0x0104 #define PCI_VENDOR_ID_TOSHIBA 0x1179 #define PCI_DEVICE_ID_TOSHIBA_601 0x0601 #define PCI_DEVICE_ID_TOSHIBA_TOPIC95 0x060a #define PCI_DEVICE_ID_TOSHIBA_TOPIC97 0x060f #define PCI_VENDOR_ID_RICOH 0x1180 #define PCI_DEVICE_ID_RICOH_RL5C465 0x0465 #define PCI_DEVICE_ID_RICOH_RL5C466 0x0466 #define PCI_DEVICE_ID_RICOH_RL5C475 0x0475 #define PCI_DEVICE_ID_RICOH_RL5C478 0x0478 #define PCI_VENDOR_ID_ARTOP 0x1191 #define PCI_DEVICE_ID_ARTOP_ATP8400 0x0004 #define PCI_DEVICE_ID_ARTOP_ATP850UF 0x0005 #define PCI_VENDOR_ID_ZEITNET 0x1193 #define PCI_DEVICE_ID_ZEITNET_1221 0x0001 #define PCI_DEVICE_ID_ZEITNET_1225 0x0002 #define PCI_VENDOR_ID_OMEGA 0x119b #define PCI_DEVICE_ID_OMEGA_82C092G 0x1221 #define PCI_VENDOR_ID_GALILEO 0x11ab #define PCI_DEVICE_ID_GALILEO_GT64011 0x4146 #define PCI_VENDOR_ID_LITEON 0x11ad #define PCI_DEVICE_ID_LITEON_LNE100TX 0x0002 #define PCI_VENDOR_ID_NP 0x11bc #define PCI_DEVICE_ID_NP_PCI_FDDI 0x0001 #define PCI_VENDOR_ID_ATT 0x11c1 #define PCI_DEVICE_ID_ATT_L56XMF 0x0440 #define PCI_DEVICE_ID_ATT_L56DVP 0x0480 #define PCI_VENDOR_ID_SPECIALIX 0x11cb #define PCI_DEVICE_ID_SPECIALIX_IO8 0x2000 #define PCI_DEVICE_ID_SPECIALIX_XIO 0x4000 #define PCI_DEVICE_ID_SPECIALIX_RIO 0x8000 #define PCI_VENDOR_ID_AURAVISION 0x11d1 #define PCI_DEVICE_ID_AURAVISION_VXP524 0x01f7 #define PCI_VENDOR_ID_IKON 0x11d5 #define PCI_DEVICE_ID_IKON_10115 0x0115 #define PCI_DEVICE_ID_IKON_10117 0x0117 #define PCI_VENDOR_ID_ZORAN 0x11de #define PCI_DEVICE_ID_ZORAN_36057 0x6057 #define PCI_DEVICE_ID_ZORAN_36120 0x6120 #define PCI_VENDOR_ID_KINETIC 0x11f4 #define PCI_DEVICE_ID_KINETIC_2915 0x2915 #define PCI_VENDOR_ID_COMPEX 0x11f6 #define PCI_DEVICE_ID_COMPEX_ENET100VG4 0x0112 #define PCI_DEVICE_ID_COMPEX_RL2000 0x1401 #define PCI_VENDOR_ID_RP 0x11fe #define PCI_DEVICE_ID_RP32INTF 0x0001 #define PCI_DEVICE_ID_RP8INTF 0x0002 #define PCI_DEVICE_ID_RP16INTF 0x0003 #define PCI_DEVICE_ID_RP4QUAD 0x0004 #define PCI_DEVICE_ID_RP8OCTA 0x0005 #define PCI_DEVICE_ID_RP8J 0x0006 #define PCI_DEVICE_ID_RPP4 0x000A #define PCI_DEVICE_ID_RPP8 0x000B #define PCI_DEVICE_ID_RP8M 0x000C #define PCI_VENDOR_ID_CYCLADES 0x120e #define PCI_DEVICE_ID_CYCLOM_Y_Lo 0x0100 #define PCI_DEVICE_ID_CYCLOM_Y_Hi 0x0101 #define PCI_DEVICE_ID_CYCLOM_4Y_Lo 0x0102 #define PCI_DEVICE_ID_CYCLOM_4Y_Hi 0x0103 #define PCI_DEVICE_ID_CYCLOM_8Y_Lo 0x0104 #define PCI_DEVICE_ID_CYCLOM_8Y_Hi 0x0105 #define PCI_DEVICE_ID_CYCLOM_Z_Lo 0x0200 #define PCI_DEVICE_ID_CYCLOM_Z_Hi 0x0201 #define PCI_DEVICE_ID_PC300_RX_2 0x0300 #define PCI_DEVICE_ID_PC300_RX_1 0x0301 #define PCI_DEVICE_ID_PC300_TE_2 0x0310 #define PCI_DEVICE_ID_PC300_TE_1 0x0311 #define PCI_VENDOR_ID_ESSENTIAL 0x120f #define PCI_DEVICE_ID_ESSENTIAL_ROADRUNNER 0x0001 #define PCI_VENDOR_ID_O2 0x1217 #define PCI_DEVICE_ID_O2_6729 0x6729 #define PCI_DEVICE_ID_O2_6730 0x673a #define PCI_DEVICE_ID_O2_6832 0x6832 #define PCI_DEVICE_ID_O2_6836 0x6836 #define PCI_VENDOR_ID_3DFX 0x121a #define PCI_DEVICE_ID_3DFX_VOODOO 0x0001 #define PCI_DEVICE_ID_3DFX_VOODOO2 0x0002 #define PCI_DEVICE_ID_3DFX_BANSHEE 0x0003 #define PCI_VENDOR_ID_SIGMADES 0x1236 #define PCI_DEVICE_ID_SIGMADES_6425 0x6401 #define PCI_VENDOR_ID_CCUBE 0x123f #define PCI_VENDOR_ID_AVM 0x1244 #define PCI_DEVICE_ID_AVM_A1 0x0a00 #define PCI_VENDOR_ID_DIPIX 0x1246 #define PCI_VENDOR_ID_STALLION 0x124d #define PCI_DEVICE_ID_STALLION_ECHPCI832 0x0000 #define PCI_DEVICE_ID_STALLION_ECHPCI864 0x0002 #define PCI_DEVICE_ID_STALLION_EIOPCI 0x0003 #define PCI_VENDOR_ID_OPTIBASE 0x1255 #define PCI_DEVICE_ID_OPTIBASE_FORGE 0x1110 #define PCI_DEVICE_ID_OPTIBASE_FUSION 0x1210 #define PCI_DEVICE_ID_OPTIBASE_VPLEX 0x2110 #define PCI_DEVICE_ID_OPTIBASE_VPLEXCC 0x2120 #define PCI_DEVICE_ID_OPTIBASE_VQUEST 0x2130 #define PCI_VENDOR_ID_SATSAGEM 0x1267 #define PCI_DEVICE_ID_SATSAGEM_PCR2101 0x5352 #define PCI_DEVICE_ID_SATSAGEM_TELSATTURBO 0x5a4b #define PCI_VENDOR_ID_HUGHES 0x1273 #define PCI_DEVICE_ID_HUGHES_DIRECPC 0x0002 #define PCI_VENDOR_ID_ENSONIQ 0x1274 #define PCI_DEVICE_ID_ENSONIQ_AUDIOPCI 0x5000 #define PCI_DEVICE_ID_ENSONIQ_ES1371 0x1371 #define PCI_VENDOR_ID_ALTEON 0x12ae #define PCI_DEVICE_ID_ALTEON_ACENIC 0x0001 #define PCI_VENDOR_ID_PICTUREL 0x12c5 #define PCI_DEVICE_ID_PICTUREL_PCIVST 0x0081 #define PCI_VENDOR_ID_NVIDIA_SGS 0x12d2 #define PCI_DEVICE_ID_NVIDIA_SGS_RIVA128 0x0018 #define PCI_VENDOR_ID_CBOARDS 0x1307 #define PCI_DEVICE_ID_CBOARDS_DAS1602_16 0x0001 #define PCI_VENDOR_ID_SIIG 0x131f #define PCI_DEVICE_ID_SIIG_1S1P_10x_550 0x1010 #define PCI_DEVICE_ID_SIIG_1S1P_10x_650 0x1011 #define PCI_DEVICE_ID_SIIG_1S1P_10x_850 0x1012 #define PCI_DEVICE_ID_SIIG_1P_10x 0x1020 #define PCI_DEVICE_ID_SIIG_2P_10x 0x1021 #define PCI_DEVICE_ID_SIIG_2S1P_10x_550 0x1034 #define PCI_DEVICE_ID_SIIG_2S1P_10x_650 0x1035 #define PCI_DEVICE_ID_SIIG_2S1P_10x_850 0x1036 #define PCI_DEVICE_ID_SIIG_1P_20x 0x2020 #define PCI_DEVICE_ID_SIIG_2P_20x 0x2021 #define PCI_DEVICE_ID_SIIG_2P1S_20x_550 0x2040 #define PCI_DEVICE_ID_SIIG_2P1S_20x_650 0x2041 #define PCI_DEVICE_ID_SIIG_2P1S_20x_850 0x2042 #define PCI_DEVICE_ID_SIIG_1S1P_20x_550 0x2010 #define PCI_DEVICE_ID_SIIG_1S1P_20x_650 0x2011 #define PCI_DEVICE_ID_SIIG_1S1P_20x_850 0x2012 #define PCI_DEVICE_ID_SIIG_2S1P_20x_550 0x2060 #define PCI_DEVICE_ID_SIIG_2S1P_20x_650 0x2061 #define PCI_DEVICE_ID_SIIG_2S1P_20x_850 0x2062 #define PCI_VENDOR_ID_NETGEAR 0x1385 #define PCI_DEVICE_ID_NETGEAR_GA620 0x620a #define PCI_VENDOR_ID_LAVA 0x1407 #define PCI_DEVICE_ID_LAVA_PARALLEL 0x8000 #define PCI_DEVICE_ID_LAVA_DUAL_PAR_A 0x8002 /* The Lava Dual Parallel is */ #define PCI_DEVICE_ID_LAVA_DUAL_PAR_B 0x8003 /* two PCI devices on a card */ #define PCI_VENDOR_ID_TIMEDIA 0x1409 #define PCI_DEVICE_ID_TIMEDIA_1889 0x7168 #define PCI_DEVICE_ID_TIMEDIA_4008A 0x7268 #define PCI_VENDOR_ID_AFAVLAB 0x14db #define PCI_DEVICE_ID_AFAVLAB_TK9902 0x2120 #define PCI_VENDOR_ID_SYMPHONY 0x1c1c #define PCI_DEVICE_ID_SYMPHONY_101 0x0001 #define PCI_VENDOR_ID_TEKRAM 0x1de1 #define PCI_DEVICE_ID_TEKRAM_DC290 0xdc29 #define PCI_VENDOR_ID_3DLABS 0x3d3d #define PCI_DEVICE_ID_3DLABS_300SX 0x0001 #define PCI_DEVICE_ID_3DLABS_500TX 0x0002 #define PCI_DEVICE_ID_3DLABS_DELTA 0x0003 #define PCI_DEVICE_ID_3DLABS_PERMEDIA 0x0004 #define PCI_DEVICE_ID_3DLABS_MX 0x0006 #define PCI_DEVICE_ID_3DLABS_PERMEDIA2 0x0007 #define PCI_DEVICE_ID_3DLABS_GAMMA 0x0008 #define PCI_DEVICE_ID_3DLABS_PERMEDIA2V 0x0009 #define PCI_VENDOR_ID_AVANCE 0x4005 #define PCI_DEVICE_ID_AVANCE_ALG2064 0x2064 #define PCI_DEVICE_ID_AVANCE_2302 0x2302 #define PCI_VENDOR_ID_NETVIN 0x4a14 #define PCI_DEVICE_ID_NETVIN_NV5000SC 0x5000 #define PCI_VENDOR_ID_S3 0x5333 #define PCI_DEVICE_ID_S3_PLATO_PXS 0x0551 #define PCI_DEVICE_ID_S3_ViRGE 0x5631 #define PCI_DEVICE_ID_S3_TRIO 0x8811 #define PCI_DEVICE_ID_S3_AURORA64VP 0x8812 #define PCI_DEVICE_ID_S3_TRIO64UVP 0x8814 #define PCI_DEVICE_ID_S3_ViRGE_VX 0x883d #define PCI_DEVICE_ID_S3_868 0x8880 #define PCI_DEVICE_ID_S3_928 0x88b0 #define PCI_DEVICE_ID_S3_864_1 0x88c0 #define PCI_DEVICE_ID_S3_864_2 0x88c1 #define PCI_DEVICE_ID_S3_964_1 0x88d0 #define PCI_DEVICE_ID_S3_964_2 0x88d1 #define PCI_DEVICE_ID_S3_968 0x88f0 #define PCI_DEVICE_ID_S3_TRIO64V2 0x8901 #define PCI_DEVICE_ID_S3_PLATO_PXG 0x8902 #define PCI_DEVICE_ID_S3_ViRGE_DXGX 0x8a01 #define PCI_DEVICE_ID_S3_ViRGE_GX2 0x8a10 #define PCI_DEVICE_ID_S3_ViRGE_MX 0x8c01 #define PCI_DEVICE_ID_S3_ViRGE_MXP 0x8c02 #define PCI_DEVICE_ID_S3_ViRGE_MXPMV 0x8c03 #define PCI_DEVICE_ID_S3_SONICVIBES 0xca00 #define PCI_VENDOR_ID_DCI 0x6666 #define PCI_DEVICE_ID_DCI_PCCOM4 0x0001 #define PCI_VENDOR_ID_GENROCO 0x5555 #define PCI_DEVICE_ID_GENROCO_HFP832 0x0003 #define PCI_VENDOR_ID_INTEL 0x8086 #define PCI_DEVICE_ID_INTEL_21145 0x0039 #define PCI_DEVICE_ID_INTEL_82375 0x0482 #define PCI_DEVICE_ID_INTEL_82424 0x0483 #define PCI_DEVICE_ID_INTEL_82378 0x0484 #define PCI_DEVICE_ID_INTEL_82430 0x0486 #define PCI_DEVICE_ID_INTEL_82434 0x04a3 #define PCI_DEVICE_ID_INTEL_I960 0x0960 #define PCI_DEVICE_ID_INTEL_I960RN 0x0964 #define PCI_DEVICE_ID_INTEL_82559ER 0x1209 #define PCI_DEVICE_ID_INTEL_82092AA_0 0x1221 #define PCI_DEVICE_ID_INTEL_82092AA_1 0x1222 #define PCI_DEVICE_ID_INTEL_7116 0x1223 #define PCI_DEVICE_ID_INTEL_82596 0x1226 #define PCI_DEVICE_ID_INTEL_82865 0x1227 #define PCI_DEVICE_ID_INTEL_82557 0x1229 #define PCI_DEVICE_ID_INTEL_82437 0x122d #define PCI_DEVICE_ID_INTEL_82371FB_0 0x122e #define PCI_DEVICE_ID_INTEL_82371FB_1 0x1230 #define PCI_DEVICE_ID_INTEL_82371MX 0x1234 #define PCI_DEVICE_ID_INTEL_82437MX 0x1235 #define PCI_DEVICE_ID_INTEL_82441 0x1237 #define PCI_DEVICE_ID_INTEL_82380FB 0x124b #define PCI_DEVICE_ID_INTEL_82439 0x1250 #define PCI_DEVICE_ID_INTEL_MEGARAID 0x1960 #define PCI_DEVICE_ID_INTEL_82371SB_0 0x7000 #define PCI_DEVICE_ID_INTEL_82371SB_1 0x7010 #define PCI_DEVICE_ID_INTEL_82371SB_2 0x7020 #define PCI_DEVICE_ID_INTEL_82437VX 0x7030 #define PCI_DEVICE_ID_INTEL_82439TX 0x7100 #define PCI_DEVICE_ID_INTEL_82371AB_0 0x7110 #define PCI_DEVICE_ID_INTEL_82371AB 0x7111 #define PCI_DEVICE_ID_INTEL_82371AB_2 0x7112 #define PCI_DEVICE_ID_INTEL_82371AB_3 0x7113 #define PCI_DEVICE_ID_INTEL_82443LX_0 0x7180 #define PCI_DEVICE_ID_INTEL_82443LX_1 0x7181 #define PCI_DEVICE_ID_INTEL_82443BX_0 0x7190 #define PCI_DEVICE_ID_INTEL_82443BX_1 0x7191 #define PCI_DEVICE_ID_INTEL_82443BX_2 0x7192 #define PCI_DEVICE_ID_INTEL_P6 0x84c4 #define PCI_DEVICE_ID_INTEL_82450GX 0x84c4 #define PCI_DEVICE_ID_INTEL_82453GX 0x84c5 #define PCI_DEVICE_ID_INTEL_82451NX 0x84ca #define PCI_DEVICE_ID_INTEL_82454NX 0x84cb #define PCI_VENDOR_ID_COMPUTONE 0x8e0e #define PCI_DEVICE_ID_COMPUTONE_IP2EX 0x0291 #define PCI_VENDOR_ID_KTI 0x8e2e #define PCI_DEVICE_ID_KTI_ET32P2 0x3000 #define PCI_VENDOR_ID_ADAPTEC 0x9004 #define PCI_DEVICE_ID_ADAPTEC_7810 0x1078 #define PCI_DEVICE_ID_ADAPTEC_7821 0x2178 #define PCI_DEVICE_ID_ADAPTEC_38602 0x3860 #define PCI_DEVICE_ID_ADAPTEC_7850 0x5078 #define PCI_DEVICE_ID_ADAPTEC_7855 0x5578 #define PCI_DEVICE_ID_ADAPTEC_5800 0x5800 #define PCI_DEVICE_ID_ADAPTEC_3860 0x6038 #define PCI_DEVICE_ID_ADAPTEC_1480A 0x6075 #define PCI_DEVICE_ID_ADAPTEC_7860 0x6078 #define PCI_DEVICE_ID_ADAPTEC_7861 0x6178 #define PCI_DEVICE_ID_ADAPTEC_7870 0x7078 #define PCI_DEVICE_ID_ADAPTEC_7871 0x7178 #define PCI_DEVICE_ID_ADAPTEC_7872 0x7278 #define PCI_DEVICE_ID_ADAPTEC_7873 0x7378 #define PCI_DEVICE_ID_ADAPTEC_7874 0x7478 #define PCI_DEVICE_ID_ADAPTEC_7895 0x7895 #define PCI_DEVICE_ID_ADAPTEC_7880 0x8078 #define PCI_DEVICE_ID_ADAPTEC_7881 0x8178 #define PCI_DEVICE_ID_ADAPTEC_7882 0x8278 #define PCI_DEVICE_ID_ADAPTEC_7883 0x8378 #define PCI_DEVICE_ID_ADAPTEC_7884 0x8478 #define PCI_DEVICE_ID_ADAPTEC_7885 0x8578 #define PCI_DEVICE_ID_ADAPTEC_7886 0x8678 #define PCI_DEVICE_ID_ADAPTEC_7887 0x8778 #define PCI_DEVICE_ID_ADAPTEC_7888 0x8878 #define PCI_DEVICE_ID_ADAPTEC_1030 0x8b78 #define PCI_VENDOR_ID_ADAPTEC2 0x9005 #define PCI_DEVICE_ID_ADAPTEC2_2940U2 0x0010 #define PCI_DEVICE_ID_ADAPTEC2_2930U2 0x0011 #define PCI_DEVICE_ID_ADAPTEC2_7890B 0x0013 #define PCI_DEVICE_ID_ADAPTEC2_7890 0x001f #define PCI_DEVICE_ID_ADAPTEC2_3940U2 0x0050 #define PCI_DEVICE_ID_ADAPTEC2_3950U2D 0x0051 #define PCI_DEVICE_ID_ADAPTEC2_7896 0x005f #define PCI_DEVICE_ID_ADAPTEC2_7892A 0x0080 #define PCI_DEVICE_ID_ADAPTEC2_7892B 0x0081 #define PCI_DEVICE_ID_ADAPTEC2_7892D 0x0083 #define PCI_DEVICE_ID_ADAPTEC2_7892P 0x008f #define PCI_DEVICE_ID_ADAPTEC2_7899A 0x00c0 #define PCI_DEVICE_ID_ADAPTEC2_7899B 0x00c1 #define PCI_DEVICE_ID_ADAPTEC2_7899D 0x00c3 #define PCI_DEVICE_ID_ADAPTEC2_7899P 0x00cf #define PCI_VENDOR_ID_ATRONICS 0x907f #define PCI_DEVICE_ID_ATRONICS_2015 0x2015 #define PCI_VENDOR_ID_HOLTEK 0x9412 #define PCI_DEVICE_ID_HOLTEK_6565 0x6565 #define PCI_VENDOR_ID_TIGERJET 0xe159 #define PCI_DEVICE_ID_TIGERJET_300 0x0001 #define PCI_VENDOR_ID_ARK 0xedd8 #define PCI_DEVICE_ID_ARK_STING 0xa091 #define PCI_DEVICE_ID_ARK_STINGARK 0xa099 #define PCI_DEVICE_ID_ARK_2000MT 0xa0a1 #define PCI_VENDOR_ID_INTERPHASE 0x107e #define PCI_DEVICE_ID_INTERPHASE_5526 0x0004 #define PCI_DEVICE_ID_INTERPHASE_55x6 0x0005 /* * The PCI interface treats multi-function devices as independent * devices. The slot/function address of each device is encoded * in a single byte as follows: * * 7:3 = slot * 2:0 = function */ #define PCI_DEVFN(slot,func) ((((slot) & 0x1f) << 3) | ((func) & 0x07)) #define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) #define PCI_FUNC(devfn) ((devfn) & 0x07) #endif /* USE_2_2_17_PCI_H */ #define PCI_EXP_FLAGS_TYPE 0x00f0 /* Device/Port type */ #define PCI_EXP_TYPE_ENDPOINT 0x0 /* Express Endpoint */ #define PCI_EXP_TYPE_LEG_END 0x1 /* Legacy Endpoint */ #define PCI_EXP_TYPE_ROOT_PORT 0x4 /* Root Port */ #define PCI_EXP_TYPE_UPSTREAM 0x5 /* Upstream Port */ #define PCI_EXP_TYPE_DOWNSTREAM 0x6 /* Downstream Port */ #define PCI_EXP_TYPE_PCI_BRIDGE 0x7 /* PCIe to PCI/PCI-X Bridge */ #define PCI_EXP_TYPE_PCIE_BRIDGE 0x8 /* PCI/PCI-X to PCIe Bridge */ #define PCI_EXP_TYPE_RC_END 0x9 /* Root Complex Integrated Endpoint */ #define PCI_EXP_TYPE_RC_EC 0xa /* Root Complex Event Collector */ static void fill_dev_name(ulong pci_dev, char *name) { ulong kobj, value; memset(name, 0, sizeof(*name) * BUFSIZE); kobj = pci_dev + OFFSET(pci_dev_dev) + OFFSET(device_kobj); readmem(kobj + OFFSET(kobject_name), KVADDR, &value, sizeof(void *), "kobject name", FAULT_ON_ERROR); read_string(value, name, BUFSIZE-1); } static void fill_bus_name(ulong pci_bus, char *name) { ulong kobj, value; memset(name, 0, sizeof(*name) * BUFSIZE); kobj = pci_bus + OFFSET(pci_bus_dev) + OFFSET(device_kobj); readmem(kobj + OFFSET(kobject_name), KVADDR, &value, sizeof(void *), "kobject name", FAULT_ON_ERROR); read_string(value, name, BUFSIZE-1); } static void fill_dev_id(ulong pci_dev, char *id) { unsigned short device, vendor; memset(id, 0, sizeof(*id) * BUFSIZE); readmem(pci_dev + OFFSET(pci_dev_device), KVADDR, &device, sizeof(short), "pci dev device", FAULT_ON_ERROR); readmem(pci_dev + OFFSET(pci_dev_vendor), KVADDR, &vendor, sizeof(short), "pci dev vendor", FAULT_ON_ERROR); sprintf(id, "%x:%x", vendor, device); } static void fill_dev_class(ulong pci_dev, char *c) { unsigned int class; memset(c, 0, sizeof(*c) * BUFSIZE); readmem(pci_dev + OFFSET(pci_dev_class), KVADDR, &class, sizeof(int), "pci class", FAULT_ON_ERROR); class >>= 8; sprintf(c, "%04x", class); } static int pci_pcie_type(ulong cap) { return (cap & PCI_EXP_FLAGS_TYPE) >> 4; } static int pci_is_bridge(unsigned char hdr_type) { return hdr_type == PCI_HEADER_TYPE_BRIDGE || hdr_type == PCI_HEADER_TYPE_CARDBUS; } static void fill_pcie_type(ulong pcidev, char *t) { int type, bufidx = 0; unsigned short pciecap; unsigned char hdr_type; memset(t, 0, sizeof(*t) * BUFSIZE); readmem(pcidev + OFFSET(pci_dev_hdr_type), KVADDR, &hdr_type, sizeof(char), "pci dev hdr_type", FAULT_ON_ERROR); if (!VALID_MEMBER(pci_dev_pcie_flags_reg)) goto bridge_chk; readmem(pcidev + OFFSET(pci_dev_pcie_flags_reg), KVADDR, &pciecap, sizeof(unsigned short), "pci dev pcie_flags_reg", FAULT_ON_ERROR); type = pci_pcie_type(pciecap); if (type == PCI_EXP_TYPE_ENDPOINT) bufidx = sprintf(t, "ENDPOINT"); else if (type == PCI_EXP_TYPE_LEG_END) bufidx = sprintf(t, "LEG_END"); else if (type == PCI_EXP_TYPE_ROOT_PORT) bufidx = sprintf(t, "ROOT_PORT"); else if (type == PCI_EXP_TYPE_UPSTREAM) bufidx = sprintf(t, "UPSTREAM"); else if (type == PCI_EXP_TYPE_DOWNSTREAM) bufidx = sprintf(t, "DOWNSTREAM"); else if (type == PCI_EXP_TYPE_PCI_BRIDGE) bufidx = sprintf(t, "PCI_BRIDGE"); else if (type == PCI_EXP_TYPE_PCIE_BRIDGE) bufidx = sprintf(t, "PCIE_BRIDGE"); else if (type == PCI_EXP_TYPE_RC_END) bufidx = sprintf(t, "RC_END"); else if (type == PCI_EXP_TYPE_RC_EC) bufidx = sprintf(t, "RC_EC"); bridge_chk: if (pci_is_bridge(hdr_type)) sprintf(t + bufidx, " [BRIDGE]"); } static void walk_devices(ulong pci_bus) { struct list_data list_data, *ld; int devcnt, i; ulong *devlist, self; char name[BUFSIZE], class[BUFSIZE], id[BUFSIZE], type[BUFSIZE]; char pcidev_hdr[BUFSIZE]; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char buf3[BUFSIZE]; char buf4[BUFSIZE]; char buf5[BUFSIZE]; ld = &list_data; BZERO(ld, sizeof(struct list_data)); readmem(pci_bus + OFFSET(pci_bus_devices), KVADDR, &ld->start, sizeof(void *), "pci bus devices", FAULT_ON_ERROR); if (VALID_MEMBER(pci_dev_pcie_flags_reg)) snprintf(pcidev_hdr, sizeof(pcidev_hdr), "%s %s %s %s %s\n", mkstring(buf1, VADDR_PRLEN, CENTER, "PCI DEV"), mkstring(buf2, strlen("0000:00:00.0"), CENTER, "DO:BU:SL.FN"), mkstring(buf3, strlen("0000") + 2, CENTER, "CLASS"), mkstring(buf4, strlen("0000:0000"), CENTER, "PCI_ID"), mkstring(buf5, 10, CENTER, "TYPE")); else snprintf(pcidev_hdr, sizeof(pcidev_hdr), "%s %s %s %s\n", mkstring(buf1, VADDR_PRLEN, CENTER, "PCI DEV"), mkstring(buf2, strlen("0000:00:00.0"), CENTER, "DO:BU:SL.FN"), mkstring(buf3, strlen("0000") + 2, CENTER, "CLASS"), mkstring(buf4, strlen("0000:0000"), CENTER, "PCI_ID")); fprintf(fp, " %s", pcidev_hdr); readmem(pci_bus + OFFSET(pci_bus_self), KVADDR, &self, sizeof(void *), "pci bus self", FAULT_ON_ERROR); if (self) { fill_dev_name(self, name); fill_dev_class(self, class); fill_dev_id(self, id); fill_pcie_type(self, type); fprintf(fp, " %s %s %s %s %s\n", mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(self)), mkstring(buf2, strlen("0000:00:00.0"), CENTER, name), mkstring(buf3, strlen("0000") + 2, CENTER, class), mkstring(buf4, strlen("0000:0000"), CENTER, id), mkstring(buf5, 10, CENTER, type)); } if (ld->start == (pci_bus + OFFSET(pci_bus_devices))) return; ld->end = pci_bus + OFFSET(pci_bus_devices); hq_open(); devcnt = do_list(ld); devlist = (ulong *)GETBUF(devcnt * sizeof(ulong)); devcnt = retrieve_list(devlist, devcnt); hq_close(); for (i = 0; i < devcnt; i++) { fill_dev_name(devlist[i], name); fill_dev_class(devlist[i], class); fill_dev_id(devlist[i], id); fill_pcie_type(devlist[i], type); fprintf(fp, " %s %s %s %s %s\n", mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(devlist[i])), mkstring(buf2, strlen("0000:00:00.0"), CENTER, name), mkstring(buf3, strlen("0000") + 2, CENTER, class), mkstring(buf4, strlen("0000:0000"), CENTER, id), mkstring(buf5, 10, CENTER, type)); } FREEBUF(devlist); } static void walk_buses(ulong pci_bus) { struct list_data list_data, *ld; int buscnt, i; ulong *buslist, parent; char pcibus_hdr[BUFSIZE]; char buf1[BUFSIZE]; char buf2[BUFSIZE]; ld = &list_data; BZERO(ld, sizeof(struct list_data)); readmem(pci_bus + OFFSET(pci_bus_children), KVADDR, &ld->start, sizeof(void *), "pci bus children", FAULT_ON_ERROR); if (ld->start == (pci_bus + OFFSET(pci_bus_children))) return; ld->end = pci_bus + OFFSET(pci_bus_children); hq_open(); buscnt = do_list(ld); buslist = (ulong *)GETBUF(buscnt * sizeof(ulong)); buscnt = retrieve_list(buslist, buscnt); hq_close(); snprintf(pcibus_hdr, sizeof(pcibus_hdr), "%s %s\n", mkstring(buf1, VADDR_PRLEN, CENTER, "PCI BUS"), mkstring(buf2, VADDR_PRLEN, CENTER, "PARENT BUS")); for (i = 0; i < buscnt; i++) { readmem(buslist[i] + OFFSET(pci_bus_parent), KVADDR, &parent, sizeof(void *), "pci bus parent", FAULT_ON_ERROR); fprintf(fp, " %s", pcibus_hdr); fprintf(fp, " %s %s\n", mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(buslist[i])), mkstring(buf2, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(parent))); walk_devices(buslist[i]); fprintf(fp, "\n"); walk_buses(buslist[i]); } FREEBUF(buslist); } static void do_pci2(void) { struct list_data list_data, *ld; int rootbuscnt, i; ulong *rootbuslist; unsigned long pci_root_bus_addr = symbol_value("pci_root_buses"); char name[BUFSIZE]; char pcirootbus_hdr[BUFSIZE]; char buf1[BUFSIZE]; char buf2[BUFSIZE]; ld = &list_data; BZERO(ld, sizeof(struct list_data)); get_symbol_data("pci_root_buses", sizeof(void *), &ld->start); if (ld->start == pci_root_bus_addr) error(FATAL, "no PCI devices found on this system.\n"); ld->end = pci_root_bus_addr; hq_open(); rootbuscnt = do_list(ld); rootbuslist = (ulong *)GETBUF(rootbuscnt * sizeof(ulong)); rootbuscnt = retrieve_list(rootbuslist, rootbuscnt); hq_close(); snprintf(pcirootbus_hdr, sizeof(pcirootbus_hdr), "%s %s\n", mkstring(buf1, VADDR_PRLEN, CENTER, "ROOT BUS"), mkstring(buf2, strlen("0000:00"), CENTER, "BUSNAME")); for (i = 0; i < rootbuscnt; i++) { fprintf(fp, "%s", pcirootbus_hdr); fill_bus_name(rootbuslist[i], name); fprintf(fp, "%s %s\n", mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(rootbuslist[i])), mkstring(buf2, strlen("0000:00"), CENTER, name)); walk_devices(rootbuslist[i]); walk_buses(rootbuslist[i]); fprintf(fp, "\n"); } FREEBUF(rootbuslist); } static void do_pci(void) { struct list_data pcilist_data; int devcnt, i; unsigned int class; unsigned short device, vendor; unsigned char busno; ulong *devlist, bus, devfn, prev, next; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char buf3[BUFSIZE]; BZERO(&pcilist_data, sizeof(struct list_data)); if (VALID_MEMBER(pci_dev_global_list)) { get_symbol_data("pci_devices", sizeof(void *), &pcilist_data.start); pcilist_data.end = symbol_value("pci_devices"); pcilist_data.list_head_offset = OFFSET(pci_dev_global_list); readmem(symbol_value("pci_devices") + OFFSET(list_head_prev), KVADDR, &prev, sizeof(void *), "list head prev", FAULT_ON_ERROR); /* * Check if this system does not have any PCI devices. */ if ((pcilist_data.start == pcilist_data.end) && (prev == pcilist_data.end)) error(FATAL, "no PCI devices found on this system.\n"); } else if (VALID_MEMBER(pci_dev_next)) { get_symbol_data("pci_devices", sizeof(void *), &pcilist_data.start); pcilist_data.member_offset = OFFSET(pci_dev_next); /* * Check if this system does not have any PCI devices. */ readmem(pcilist_data.start + pcilist_data.member_offset, KVADDR, &next, sizeof(void *), "pci dev next", FAULT_ON_ERROR); if (!next) error(FATAL, "no PCI devices found on this system.\n"); } else option_not_supported('p'); hq_open(); devcnt = do_list(&pcilist_data); devlist = (ulong *)GETBUF(devcnt * sizeof(ulong)); devcnt = retrieve_list(devlist, devcnt); hq_close(); fprintf(fp, "%s BU:SL.FN CLASS: VENDOR-DEVICE\n", mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "PCI_DEV")); for (i = 0; i < devcnt; i++) { /* * Get the pci bus number */ readmem(devlist[i] + OFFSET(pci_dev_bus), KVADDR, &bus, sizeof(void *), "pci bus", FAULT_ON_ERROR); readmem(bus + OFFSET(pci_bus_number), KVADDR, &busno, sizeof(char), "pci bus number", FAULT_ON_ERROR); readmem(devlist[i] + OFFSET(pci_dev_devfn), KVADDR, &devfn, sizeof(ulong), "pci devfn", FAULT_ON_ERROR); fprintf(fp, "%lx %02x:%02lx.%lx ", devlist[i], busno, PCI_SLOT(devfn), PCI_FUNC(devfn)); /* * Now read in the class, device, and vendor. */ readmem(devlist[i] + OFFSET(pci_dev_class), KVADDR, &class, sizeof(int), "pci class", FAULT_ON_ERROR); readmem(devlist[i] + OFFSET(pci_dev_device), KVADDR, &device, sizeof(short), "pci device", FAULT_ON_ERROR); readmem(devlist[i] + OFFSET(pci_dev_vendor),KVADDR, &vendor, sizeof(short), "pci vendor", FAULT_ON_ERROR); fprintf(fp, "%s: %s %s", pci_strclass(class, buf1), pci_strvendor(vendor, buf2), pci_strdev(vendor, device, buf3)); fprintf(fp, "\n"); } FREEBUF(devlist); } /* * Taken from drivers/pci/oldproc.c, kernel ver 2.2.17 */ struct pci_dev_info { unsigned short vendor; /* vendor id */ unsigned short device; /* device id */ const char *name; /* device name */ }; #define DEVICE(vid,did,name) \ {PCI_VENDOR_ID_##vid, PCI_DEVICE_ID_##did, (name)} /* * Sorted in ascending order by vendor and device. * Use binary search for lookup. If you add a device make sure * it is sequential by both vendor and device id. */ struct pci_dev_info dev_info[] = { DEVICE( COMPAQ, COMPAQ_1280, "QVision 1280/p"), DEVICE( COMPAQ, COMPAQ_6010, "Hot Plug PCI Bridge"), DEVICE( COMPAQ, COMPAQ_SMART2P, "Smart-2/P RAID Controller"), DEVICE( COMPAQ, COMPAQ_NETEL100,"Netelligent 10/100"), DEVICE( COMPAQ, COMPAQ_NETEL10, "Netelligent 10"), DEVICE( COMPAQ, COMPAQ_NETFLEX3I,"NetFlex 3"), DEVICE( COMPAQ, COMPAQ_NETEL100D,"Netelligent 10/100 Dual"), DEVICE( COMPAQ, COMPAQ_NETEL100PI,"Netelligent 10/100 ProLiant"), DEVICE( COMPAQ, COMPAQ_NETEL100I,"Netelligent 10/100 Integrated"), DEVICE( COMPAQ, COMPAQ_THUNDER, "ThunderLAN"), DEVICE( COMPAQ, COMPAQ_NETFLEX3B,"NetFlex 3 BNC"), DEVICE( NCR, NCR_53C810, "53c810"), DEVICE( NCR, NCR_53C820, "53c820"), DEVICE( NCR, NCR_53C825, "53c825"), DEVICE( NCR, NCR_53C815, "53c815"), DEVICE( NCR, NCR_53C860, "53c860"), DEVICE( NCR, NCR_53C896, "53c896"), DEVICE( NCR, NCR_53C895, "53c895"), DEVICE( NCR, NCR_53C885, "53c885"), DEVICE( NCR, NCR_53C875, "53c875"), DEVICE( NCR, NCR_53C875J, "53c875J"), DEVICE( ATI, ATI_68800, "68800AX"), DEVICE( ATI, ATI_215CT222, "215CT222"), DEVICE( ATI, ATI_210888CX, "210888CX"), DEVICE( ATI, ATI_215GB, "Mach64 GB"), DEVICE( ATI, ATI_215GD, "Mach64 GD (Rage Pro)"), DEVICE( ATI, ATI_215GI, "Mach64 GI (Rage Pro)"), DEVICE( ATI, ATI_215GP, "Mach64 GP (Rage Pro)"), DEVICE( ATI, ATI_215GQ, "Mach64 GQ (Rage Pro)"), DEVICE( ATI, ATI_215GT, "Mach64 GT (Rage II)"), DEVICE( ATI, ATI_215GTB, "Mach64 GT (Rage II)"), DEVICE( ATI, ATI_210888GX, "210888GX"), DEVICE( ATI, ATI_215LG, "Mach64 LG (Rage Pro)"), DEVICE( ATI, ATI_264LT, "Mach64 LT"), DEVICE( ATI, ATI_264VT, "Mach64 VT"), DEVICE( VLSI, VLSI_82C592, "82C592-FC1"), DEVICE( VLSI, VLSI_82C593, "82C593-FC1"), DEVICE( VLSI, VLSI_82C594, "82C594-AFC2"), DEVICE( VLSI, VLSI_82C597, "82C597-AFC2"), DEVICE( VLSI, VLSI_82C541, "82C541 Lynx"), DEVICE( VLSI, VLSI_82C543, "82C543 Lynx ISA"), DEVICE( VLSI, VLSI_82C532, "82C532"), DEVICE( VLSI, VLSI_82C534, "82C534"), DEVICE( VLSI, VLSI_82C535, "82C535"), DEVICE( VLSI, VLSI_82C147, "82C147"), DEVICE( VLSI, VLSI_VAS96011, "VAS96011 (Golden Gate II)"), DEVICE( ADL, ADL_2301, "2301"), DEVICE( NS, NS_87415, "87415"), DEVICE( NS, NS_87410, "87410"), DEVICE( TSENG, TSENG_W32P_2, "ET4000W32P"), DEVICE( TSENG, TSENG_W32P_b, "ET4000W32P rev B"), DEVICE( TSENG, TSENG_W32P_c, "ET4000W32P rev C"), DEVICE( TSENG, TSENG_W32P_d, "ET4000W32P rev D"), DEVICE( TSENG, TSENG_ET6000, "ET6000"), DEVICE( WEITEK, WEITEK_P9000, "P9000"), DEVICE( WEITEK, WEITEK_P9100, "P9100"), DEVICE( DEC, DEC_BRD, "DC21050"), DEVICE( DEC, DEC_TULIP, "DC21040"), DEVICE( DEC, DEC_TGA, "TGA"), DEVICE( DEC, DEC_TULIP_FAST, "DC21140"), DEVICE( DEC, DEC_TGA2, "TGA2"), DEVICE( DEC, DEC_FDDI, "DEFPA"), DEVICE( DEC, DEC_TULIP_PLUS, "DC21041"), DEVICE( DEC, DEC_21142, "DC21142"), DEVICE( DEC, DEC_21052, "DC21052"), DEVICE( DEC, DEC_21150, "DC21150"), DEVICE( DEC, DEC_21152, "DC21152"), DEVICE( DEC, DEC_21153, "DC21153"), DEVICE( DEC, DEC_21154, "DC21154"), DEVICE( DEC, DEC_21285, "DC21285 Footbridge"), DEVICE( DEC, DEC_21554, "DC21554 DrawBridge"), DEVICE( CIRRUS, CIRRUS_7548, "GD 7548"), DEVICE( CIRRUS, CIRRUS_5430, "GD 5430"), DEVICE( CIRRUS, CIRRUS_5434_4, "GD 5434"), DEVICE( CIRRUS, CIRRUS_5434_8, "GD 5434"), DEVICE( CIRRUS, CIRRUS_5436, "GD 5436"), DEVICE( CIRRUS, CIRRUS_5446, "GD 5446"), DEVICE( CIRRUS, CIRRUS_5480, "GD 5480"), DEVICE( CIRRUS, CIRRUS_5464, "GD 5464"), DEVICE( CIRRUS, CIRRUS_5465, "GD 5465"), DEVICE( CIRRUS, CIRRUS_6729, "CL 6729"), DEVICE( CIRRUS, CIRRUS_6832, "PD 6832"), DEVICE( CIRRUS, CIRRUS_7542, "CL 7542"), DEVICE( CIRRUS, CIRRUS_7543, "CL 7543"), DEVICE( CIRRUS, CIRRUS_7541, "CL 7541"), DEVICE( IBM, IBM_FIRE_CORAL, "Fire Coral"), DEVICE( IBM, IBM_TR, "Token Ring"), DEVICE( IBM, IBM_82G2675, "82G2675"), DEVICE( IBM, IBM_MCA, "MicroChannel"), DEVICE( IBM, IBM_82351, "82351"), DEVICE( IBM, IBM_PYTHON, "Python"), DEVICE( IBM, IBM_SERVERAID, "ServeRAID"), DEVICE( IBM, IBM_TR_WAKE, "Wake On LAN Token Ring"), DEVICE( IBM, IBM_MPIC, "MPIC-2 Interrupt Controller"), DEVICE( IBM, IBM_3780IDSP, "MWave DSP"), DEVICE( IBM, IBM_MPIC_2, "MPIC-2 ASIC Interrupt Controller"), DEVICE( WD, WD_7197, "WD 7197"), DEVICE( AMD, AMD_LANCE, "79C970"), DEVICE( AMD, AMD_SCSI, "53C974"), DEVICE( TRIDENT, TRIDENT_9397, "Cyber9397"), DEVICE( TRIDENT, TRIDENT_9420, "TG 9420"), DEVICE( TRIDENT, TRIDENT_9440, "TG 9440"), DEVICE( TRIDENT, TRIDENT_9660, "TG 9660 / Cyber9385"), DEVICE( TRIDENT, TRIDENT_9750, "Image 975"), DEVICE( AI, AI_M1435, "M1435"), DEVICE( MATROX, MATROX_MGA_2, "Atlas PX2085"), DEVICE( MATROX, MATROX_MIL, "Millennium"), DEVICE( MATROX, MATROX_MYS, "Mystique"), DEVICE( MATROX, MATROX_MIL_2, "Millennium II"), DEVICE( MATROX, MATROX_MIL_2_AGP,"Millennium II AGP"), DEVICE( MATROX, MATROX_G200_PCI,"Matrox G200 PCI"), DEVICE( MATROX, MATROX_G200_AGP,"Matrox G200 AGP"), DEVICE( MATROX, MATROX_MGA_IMP, "MGA Impression"), DEVICE( MATROX, MATROX_G100_MM, "Matrox G100 multi monitor"), DEVICE( MATROX, MATROX_G100_AGP,"Matrox G100 AGP"), DEVICE( CT, CT_65545, "65545"), DEVICE( CT, CT_65548, "65548"), DEVICE( CT, CT_65550, "65550"), DEVICE( CT, CT_65554, "65554"), DEVICE( CT, CT_65555, "65555"), DEVICE( MIRO, MIRO_36050, "ZR36050"), DEVICE( NEC, NEC_PCX2, "PowerVR PCX2"), DEVICE( FD, FD_36C70, "TMC-18C30"), DEVICE( SI, SI_5591_AGP, "5591/5592 AGP"), DEVICE( SI, SI_6202, "6202"), DEVICE( SI, SI_503, "85C503"), DEVICE( SI, SI_ACPI, "ACPI"), DEVICE( SI, SI_5597_VGA, "5597/5598 VGA"), DEVICE( SI, SI_6205, "6205"), DEVICE( SI, SI_501, "85C501"), DEVICE( SI, SI_496, "85C496"), DEVICE( SI, SI_601, "85C601"), DEVICE( SI, SI_5107, "5107"), DEVICE( SI, SI_5511, "85C5511"), DEVICE( SI, SI_5513, "85C5513"), DEVICE( SI, SI_5571, "5571"), DEVICE( SI, SI_5591, "5591/5592 Host"), DEVICE( SI, SI_5597, "5597/5598 Host"), DEVICE( SI, SI_7001, "7001 USB"), DEVICE( HP, HP_J2585A, "J2585A"), DEVICE( HP, HP_J2585B, "J2585B (Lassen)"), DEVICE( PCTECH, PCTECH_RZ1000, "RZ1000 (buggy)"), DEVICE( PCTECH, PCTECH_RZ1001, "RZ1001 (buggy?)"), DEVICE( PCTECH, PCTECH_SAMURAI_0,"Samurai 0"), DEVICE( PCTECH, PCTECH_SAMURAI_1,"Samurai 1"), DEVICE( PCTECH, PCTECH_SAMURAI_IDE,"Samurai IDE"), DEVICE( DPT, DPT, "SmartCache/Raid"), DEVICE( OPTI, OPTI_92C178, "92C178"), DEVICE( OPTI, OPTI_82C557, "82C557 Viper-M"), DEVICE( OPTI, OPTI_82C558, "82C558 Viper-M ISA+IDE"), DEVICE( OPTI, OPTI_82C621, "82C621"), DEVICE( OPTI, OPTI_82C700, "82C700"), DEVICE( OPTI, OPTI_82C701, "82C701 FireStar Plus"), DEVICE( OPTI, OPTI_82C814, "82C814 Firebridge 1"), DEVICE( OPTI, OPTI_82C822, "82C822"), DEVICE( OPTI, OPTI_82C825, "82C825 Firebridge 2"), DEVICE( SGS, SGS_2000, "STG 2000X"), DEVICE( SGS, SGS_1764, "STG 1764X"), DEVICE( BUSLOGIC, BUSLOGIC_MULTIMASTER_NC, "MultiMaster NC"), DEVICE( BUSLOGIC, BUSLOGIC_MULTIMASTER, "MultiMaster"), DEVICE( BUSLOGIC, BUSLOGIC_FLASHPOINT, "FlashPoint"), DEVICE( TI, TI_TVP4010, "TVP4010 Permedia"), DEVICE( TI, TI_TVP4020, "TVP4020 Permedia 2"), DEVICE( TI, TI_PCI1130, "PCI1130"), DEVICE( TI, TI_PCI1131, "PCI1131"), DEVICE( TI, TI_PCI1250, "PCI1250"), DEVICE( OAK, OAK_OTI107, "OTI107"), DEVICE( WINBOND2, WINBOND2_89C940,"NE2000-PCI"), DEVICE( MOTOROLA, MOTOROLA_MPC105,"MPC105 Eagle"), DEVICE( MOTOROLA, MOTOROLA_MPC106,"MPC106 Grackle"), DEVICE( MOTOROLA, MOTOROLA_RAVEN, "Raven"), DEVICE( MOTOROLA, MOTOROLA_FALCON,"Falcon"), DEVICE( MOTOROLA, MOTOROLA_CPX8216,"CPX8216"), DEVICE( PROMISE, PROMISE_20246, "IDE UltraDMA/33"), DEVICE( PROMISE, PROMISE_5300, "DC5030"), DEVICE( N9, N9_I128, "Imagine 128"), DEVICE( N9, N9_I128_2, "Imagine 128v2"), DEVICE( N9, N9_I128_T2R, "Revolution 3D"), DEVICE( UMC, UMC_UM8673F, "UM8673F"), DEVICE( UMC, UMC_UM8891A, "UM8891A"), DEVICE( UMC, UMC_UM8886BF, "UM8886BF"), DEVICE( UMC, UMC_UM8886A, "UM8886A"), DEVICE( UMC, UMC_UM8881F, "UM8881F"), DEVICE( UMC, UMC_UM8886F, "UM8886F"), DEVICE( UMC, UMC_UM9017F, "UM9017F"), DEVICE( UMC, UMC_UM8886N, "UM8886N"), DEVICE( UMC, UMC_UM8891N, "UM8891N"), DEVICE( X, X_AGX016, "ITT AGX016"), DEVICE( PICOP, PICOP_PT86C52X, "PT86C52x Vesuvius"), DEVICE( PICOP, PICOP_PT80C524, "PT80C524 Nile"), DEVICE( MYLEX, MYLEX_DAC960_P, "DAC960 P Series"), DEVICE( MYLEX, MYLEX_DAC960_PD,"DAC960 PD Series"), DEVICE( MYLEX, MYLEX_DAC960_PG,"DAC960 PG Series"), DEVICE( MYLEX, MYLEX_DAC960_LP,"DAC960 LP Series"), DEVICE( MYLEX, MYLEX_DAC960_BA,"DAC960 BA Series"), DEVICE( APPLE, APPLE_BANDIT, "Bandit"), DEVICE( APPLE, APPLE_GC, "Grand Central"), DEVICE( APPLE, APPLE_HYDRA, "Hydra"), DEVICE( NEXGEN, NEXGEN_82C501, "82C501"), DEVICE( QLOGIC, QLOGIC_ISP1020, "ISP1020"), DEVICE( QLOGIC, QLOGIC_ISP1022, "ISP1022"), DEVICE( CYRIX, CYRIX_5510, "5510"), DEVICE( CYRIX, CYRIX_PCI_MASTER,"PCI Master"), DEVICE( CYRIX, CYRIX_5520, "5520"), DEVICE( CYRIX, CYRIX_5530_LEGACY,"5530 Kahlua Legacy"), DEVICE( CYRIX, CYRIX_5530_SMI, "5530 Kahlua SMI"), DEVICE( CYRIX, CYRIX_5530_IDE, "5530 Kahlua IDE"), DEVICE( CYRIX, CYRIX_5530_AUDIO,"5530 Kahlua Audio"), DEVICE( CYRIX, CYRIX_5530_VIDEO,"5530 Kahlua Video"), DEVICE( LEADTEK, LEADTEK_805, "S3 805"), DEVICE( CONTAQ, CONTAQ_82C599, "82C599"), DEVICE( CONTAQ, CONTAQ_82C693, "82C693"), DEVICE( OLICOM, OLICOM_OC3136, "OC-3136/3137"), DEVICE( OLICOM, OLICOM_OC2315, "OC-2315"), DEVICE( OLICOM, OLICOM_OC2325, "OC-2325"), DEVICE( OLICOM, OLICOM_OC2183, "OC-2183/2185"), DEVICE( OLICOM, OLICOM_OC2326, "OC-2326"), DEVICE( OLICOM, OLICOM_OC6151, "OC-6151/6152"), DEVICE( SUN, SUN_EBUS, "PCI-EBus Bridge"), DEVICE( SUN, SUN_HAPPYMEAL, "Happy Meal Ethernet"), DEVICE( SUN, SUN_SIMBA, "Advanced PCI Bridge"), DEVICE( SUN, SUN_PBM, "PCI Bus Module"), DEVICE( SUN, SUN_SABRE, "Ultra IIi PCI"), DEVICE( CMD, CMD_640, "640 (buggy)"), DEVICE( CMD, CMD_643, "643"), DEVICE( CMD, CMD_646, "646"), DEVICE( CMD, CMD_670, "670"), DEVICE( VISION, VISION_QD8500, "QD-8500"), DEVICE( VISION, VISION_QD8580, "QD-8580"), DEVICE( BROOKTREE, BROOKTREE_848, "Bt848"), DEVICE( BROOKTREE, BROOKTREE_849A, "Bt849"), DEVICE( BROOKTREE, BROOKTREE_878_1,"Bt878 2nd Contr. (?)"), DEVICE( BROOKTREE, BROOKTREE_878, "Bt878"), DEVICE( BROOKTREE, BROOKTREE_8474, "Bt8474"), DEVICE( SIERRA, SIERRA_STB, "STB Horizon 64"), DEVICE( ACC, ACC_2056, "2056"), DEVICE( WINBOND, WINBOND_83769, "W83769F"), DEVICE( WINBOND, WINBOND_82C105, "SL82C105"), DEVICE( WINBOND, WINBOND_83C553, "W83C553"), DEVICE( DATABOOK, DATABOOK_87144, "DB87144"), DEVICE( PLX, PLX_9050, "PCI9050 I2O"), DEVICE( PLX, PLX_9080, "PCI9080 I2O"), DEVICE( MADGE, MADGE_MK2, "Smart 16/4 BM Mk2 Ringnode"), DEVICE( MADGE, MADGE_C155S, "Collage 155 Server"), DEVICE( 3COM, 3COM_3C339, "3C339 TokenRing"), DEVICE( 3COM, 3COM_3C590, "3C590 10bT"), DEVICE( 3COM, 3COM_3C595TX, "3C595 100bTX"), DEVICE( 3COM, 3COM_3C595T4, "3C595 100bT4"), DEVICE( 3COM, 3COM_3C595MII, "3C595 100b-MII"), DEVICE( 3COM, 3COM_3C900TPO, "3C900 10bTPO"), DEVICE( 3COM, 3COM_3C900COMBO,"3C900 10b Combo"), DEVICE( 3COM, 3COM_3C905TX, "3C905 100bTX"), DEVICE( 3COM, 3COM_3C905T4, "3C905 100bT4"), DEVICE( 3COM, 3COM_3C905B_TX, "3C905B 100bTX"), DEVICE( SMC, SMC_EPIC100, "9432 TX"), DEVICE( AL, AL_M1445, "M1445"), DEVICE( AL, AL_M1449, "M1449"), DEVICE( AL, AL_M1451, "M1451"), DEVICE( AL, AL_M1461, "M1461"), DEVICE( AL, AL_M1489, "M1489"), DEVICE( AL, AL_M1511, "M1511"), DEVICE( AL, AL_M1513, "M1513"), DEVICE( AL, AL_M1521, "M1521"), DEVICE( AL, AL_M1523, "M1523"), DEVICE( AL, AL_M1531, "M1531 Aladdin IV"), DEVICE( AL, AL_M1533, "M1533 Aladdin IV"), DEVICE( AL, AL_M3307, "M3307 MPEG-1 decoder"), DEVICE( AL, AL_M4803, "M4803"), DEVICE( AL, AL_M5219, "M5219"), DEVICE( AL, AL_M5229, "M5229 TXpro"), DEVICE( AL, AL_M5237, "M5237 USB"), DEVICE( SURECOM, SURECOM_NE34, "NE-34PCI LAN"), DEVICE( NEOMAGIC, NEOMAGIC_MAGICGRAPH_NM2070, "Magicgraph NM2070"), DEVICE( NEOMAGIC, NEOMAGIC_MAGICGRAPH_128V, "MagicGraph 128V"), DEVICE( NEOMAGIC, NEOMAGIC_MAGICGRAPH_128ZV, "MagicGraph 128ZV"), DEVICE( NEOMAGIC, NEOMAGIC_MAGICGRAPH_NM2160, "MagicGraph NM2160"), DEVICE( NEOMAGIC, NEOMAGIC_MAGICGRAPH_128ZVPLUS, "MagicGraph 128ZV+"), DEVICE( ASP, ASP_ABP940, "ABP940"), DEVICE( ASP, ASP_ABP940U, "ABP940U"), DEVICE( ASP, ASP_ABP940UW, "ABP940UW"), DEVICE( MACRONIX, MACRONIX_MX98713,"MX98713"), DEVICE( MACRONIX, MACRONIX_MX987x5,"MX98715 / MX98725"), DEVICE( CERN, CERN_SPSB_PMC, "STAR/RD24 SCI-PCI (PMC)"), DEVICE( CERN, CERN_SPSB_PCI, "STAR/RD24 SCI-PCI (PMC)"), DEVICE( CERN, CERN_HIPPI_DST, "HIPPI destination"), DEVICE( CERN, CERN_HIPPI_SRC, "HIPPI source"), DEVICE( IMS, IMS_8849, "8849"), DEVICE( TEKRAM2, TEKRAM2_690c, "DC690c"), DEVICE( TUNDRA, TUNDRA_CA91C042,"CA91C042 Universe"), DEVICE( AMCC, AMCC_MYRINET, "Myrinet PCI (M2-PCI-32)"), DEVICE( AMCC, AMCC_PARASTATION,"ParaStation Interface"), DEVICE( AMCC, AMCC_S5933, "S5933 PCI44"), DEVICE( AMCC, AMCC_S5933_HEPC3,"S5933 Traquair HEPC3"), DEVICE( INTERG, INTERG_1680, "IGA-1680"), DEVICE( INTERG, INTERG_1682, "IGA-1682"), DEVICE( REALTEK, REALTEK_8029, "8029"), DEVICE( REALTEK, REALTEK_8129, "8129"), DEVICE( REALTEK, REALTEK_8139, "8139"), DEVICE( TRUEVISION, TRUEVISION_T1000,"TARGA 1000"), DEVICE( INIT, INIT_320P, "320 P"), DEVICE( INIT, INIT_360P, "360 P"), DEVICE( TTI, TTI_HPT343, "HPT343"), DEVICE( VIA, VIA_82C505, "VT 82C505"), DEVICE( VIA, VIA_82C561, "VT 82C561"), DEVICE( VIA, VIA_82C586_1, "VT 82C586 Apollo IDE"), DEVICE( VIA, VIA_82C576, "VT 82C576 3V"), DEVICE( VIA, VIA_82C585, "VT 82C585 Apollo VP1/VPX"), DEVICE( VIA, VIA_82C586_0, "VT 82C586 Apollo ISA"), DEVICE( VIA, VIA_82C595, "VT 82C595 Apollo VP2"), DEVICE( VIA, VIA_82C596_0, "VT 82C596 Apollo Pro"), DEVICE( VIA, VIA_82C597_0, "VT 82C597 Apollo VP3"), DEVICE( VIA, VIA_82C598_0, "VT 82C598 Apollo MVP3"), DEVICE( VIA, VIA_82C926, "VT 82C926 Amazon"), DEVICE( VIA, VIA_82C416, "VT 82C416MV"), DEVICE( VIA, VIA_82C595_97, "VT 82C595 Apollo VP2/97"), DEVICE( VIA, VIA_82C586_2, "VT 82C586 Apollo USB"), DEVICE( VIA, VIA_82C586_3, "VT 82C586B Apollo ACPI"), DEVICE( VIA, VIA_86C100A, "VT 86C100A"), DEVICE( VIA, VIA_82C597_1, "VT 82C597 Apollo VP3 AGP"), DEVICE( VIA, VIA_82C598_1, "VT 82C598 Apollo MVP3 AGP"), DEVICE( SMC2, SMC2_1211TX, "1211 TX"), DEVICE( VORTEX, VORTEX_GDT60x0, "GDT 60x0"), DEVICE( VORTEX, VORTEX_GDT6000B,"GDT 6000b"), DEVICE( VORTEX, VORTEX_GDT6x10, "GDT 6110/6510"), DEVICE( VORTEX, VORTEX_GDT6x20, "GDT 6120/6520"), DEVICE( VORTEX, VORTEX_GDT6530, "GDT 6530"), DEVICE( VORTEX, VORTEX_GDT6550, "GDT 6550"), DEVICE( VORTEX, VORTEX_GDT6x17, "GDT 6117/6517"), DEVICE( VORTEX, VORTEX_GDT6x27, "GDT 6127/6527"), DEVICE( VORTEX, VORTEX_GDT6537, "GDT 6537"), DEVICE( VORTEX, VORTEX_GDT6557, "GDT 6557"), DEVICE( VORTEX, VORTEX_GDT6x15, "GDT 6115/6515"), DEVICE( VORTEX, VORTEX_GDT6x25, "GDT 6125/6525"), DEVICE( VORTEX, VORTEX_GDT6535, "GDT 6535"), DEVICE( VORTEX, VORTEX_GDT6555, "GDT 6555"), DEVICE( VORTEX, VORTEX_GDT6x17RP,"GDT 6117RP/6517RP"), DEVICE( VORTEX, VORTEX_GDT6x27RP,"GDT 6127RP/6527RP"), DEVICE( VORTEX, VORTEX_GDT6537RP,"GDT 6537RP"), DEVICE( VORTEX, VORTEX_GDT6557RP,"GDT 6557RP"), DEVICE( VORTEX, VORTEX_GDT6x11RP,"GDT 6111RP/6511RP"), DEVICE( VORTEX, VORTEX_GDT6x21RP,"GDT 6121RP/6521RP"), DEVICE( VORTEX, VORTEX_GDT6x17RP1,"GDT 6117RP1/6517RP1"), DEVICE( VORTEX, VORTEX_GDT6x27RP1,"GDT 6127RP1/6527RP1"), DEVICE( VORTEX, VORTEX_GDT6537RP1,"GDT 6537RP1"), DEVICE( VORTEX, VORTEX_GDT6557RP1,"GDT 6557RP1"), DEVICE( VORTEX, VORTEX_GDT6x11RP1,"GDT 6111RP1/6511RP1"), DEVICE( VORTEX, VORTEX_GDT6x21RP1,"GDT 6121RP1/6521RP1"), DEVICE( VORTEX, VORTEX_GDT6x17RP2,"GDT 6117RP2/6517RP2"), DEVICE( VORTEX, VORTEX_GDT6x27RP2,"GDT 6127RP2/6527RP2"), DEVICE( VORTEX, VORTEX_GDT6537RP2,"GDT 6537RP2"), DEVICE( VORTEX, VORTEX_GDT6557RP2,"GDT 6557RP2"), DEVICE( VORTEX, VORTEX_GDT6x11RP2,"GDT 6111RP2/6511RP2"), DEVICE( VORTEX, VORTEX_GDT6x21RP2,"GDT 6121RP2/6521RP2"), DEVICE( EF, EF_ATM_FPGA, "155P-MF1 (FPGA)"), DEVICE( EF, EF_ATM_ASIC, "155P-MF1 (ASIC)"), DEVICE( FORE, FORE_PCA200PC, "PCA-200PC"), DEVICE( FORE, FORE_PCA200E, "PCA-200E"), DEVICE( IMAGINGTECH, IMAGINGTECH_ICPCI, "MVC IC-PCI"), DEVICE( PHILIPS, PHILIPS_SAA7145,"SAA7145"), DEVICE( PHILIPS, PHILIPS_SAA7146,"SAA7146"), DEVICE( CYCLONE, CYCLONE_SDK, "SDK"), DEVICE( ALLIANCE, ALLIANCE_PROMOTIO, "Promotion-6410"), DEVICE( ALLIANCE, ALLIANCE_PROVIDEO, "Provideo"), DEVICE( ALLIANCE, ALLIANCE_AT24, "AT24"), DEVICE( ALLIANCE, ALLIANCE_AT3D, "AT3D"), DEVICE( SYSKONNECT, SYSKONNECT_FP, "SK-FDDI-PCI"), DEVICE( SYSKONNECT, SYSKONNECT_TR, "SK-TR-PCI"), DEVICE( SYSKONNECT, SYSKONNECT_GE, "SK-98xx"), DEVICE( VMIC, VMIC_VME, "VMIVME-7587"), DEVICE( DIGI, DIGI_EPC, "AccelPort EPC"), DEVICE( DIGI, DIGI_RIGHTSWITCH, "RightSwitch SE-6"), DEVICE( DIGI, DIGI_XEM, "AccelPort Xem"), DEVICE( DIGI, DIGI_XR, "AccelPort Xr"), DEVICE( DIGI, DIGI_CX, "AccelPort C/X"), DEVICE( DIGI, DIGI_XRJ, "AccelPort Xr/J"), DEVICE( DIGI, DIGI_EPCJ, "AccelPort EPC/J"), DEVICE( DIGI, DIGI_XR_920, "AccelPort Xr 920"), DEVICE( MUTECH, MUTECH_MV1000, "MV-1000"), DEVICE( RENDITION, RENDITION_VERITE,"Verite 1000"), DEVICE( RENDITION, RENDITION_VERITE2100,"Verite 2100"), DEVICE( SERVERWORKS, SERVERWORKS_HE, "CNB20HE PCI Bridge"), DEVICE( SERVERWORKS, SERVERWORKS_LE, "CNB30LE PCI Bridge"), DEVICE( SERVERWORKS, SERVERWORKS_CMIC_HE, "CMIC-HE PCI Bridge"), DEVICE( SERVERWORKS, SERVERWORKS_CIOB30, "CIOB30 I/O Bridge"), DEVICE( SERVERWORKS, SERVERWORKS_CSB5, "CSB5 PCI Bridge"), DEVICE( TOSHIBA, TOSHIBA_601, "Laptop"), DEVICE( TOSHIBA, TOSHIBA_TOPIC95,"ToPIC95"), DEVICE( TOSHIBA, TOSHIBA_TOPIC97,"ToPIC97"), DEVICE( RICOH, RICOH_RL5C466, "RL5C466"), DEVICE( ARTOP, ARTOP_ATP8400, "ATP8400"), DEVICE( ARTOP, ARTOP_ATP850UF, "ATP850UF"), DEVICE( ZEITNET, ZEITNET_1221, "1221"), DEVICE( ZEITNET, ZEITNET_1225, "1225"), DEVICE( OMEGA, OMEGA_82C092G, "82C092G"), DEVICE( LITEON, LITEON_LNE100TX,"LNE100TX"), DEVICE( NP, NP_PCI_FDDI, "NP-PCI"), DEVICE( ATT, ATT_L56XMF, "L56xMF"), DEVICE( ATT, ATT_L56DVP, "L56DV+P"), DEVICE( SPECIALIX, SPECIALIX_IO8, "IO8+/PCI"), DEVICE( SPECIALIX, SPECIALIX_XIO, "XIO/SIO host"), DEVICE( SPECIALIX, SPECIALIX_RIO, "RIO host"), DEVICE( AURAVISION, AURAVISION_VXP524,"VXP524"), DEVICE( IKON, IKON_10115, "10115 Greensheet"), DEVICE( IKON, IKON_10117, "10117 Greensheet"), DEVICE( ZORAN, ZORAN_36057, "ZR36057"), DEVICE( ZORAN, ZORAN_36120, "ZR36120"), DEVICE( KINETIC, KINETIC_2915, "2915 CAMAC"), DEVICE( COMPEX, COMPEX_ENET100VG4, "Readylink ENET100-VG4"), DEVICE( COMPEX, COMPEX_RL2000, "ReadyLink 2000"), DEVICE( RP, RP32INTF, "RocketPort 32 Intf"), DEVICE( RP, RP8INTF, "RocketPort 8 Intf"), DEVICE( RP, RP16INTF, "RocketPort 16 Intf"), DEVICE( RP, RP4QUAD, "Rocketport 4 Quad"), DEVICE( RP, RP8OCTA, "RocketPort 8 Oct"), DEVICE( RP, RP8J, "RocketPort 8 J"), DEVICE( RP, RPP4, "RocketPort Plus 4 Quad"), DEVICE( RP, RPP8, "RocketPort Plus 8 Oct"), DEVICE( RP, RP8M, "RocketModem 8 J"), DEVICE( CYCLADES, CYCLOM_Y_Lo, "Cyclom-Y below 1Mbyte"), DEVICE( CYCLADES, CYCLOM_Y_Hi, "Cyclom-Y above 1Mbyte"), DEVICE( CYCLADES, CYCLOM_4Y_Lo, "Cyclom-4Y below 1Mbyte"), DEVICE( CYCLADES, CYCLOM_4Y_Hi, "Cyclom-4Y above 1Mbyte"), DEVICE( CYCLADES, CYCLOM_8Y_Lo, "Cyclom-8Y below 1Mbyte"), DEVICE( CYCLADES, CYCLOM_8Y_Hi, "Cyclom-8Y above 1Mbyte"), DEVICE( CYCLADES, CYCLOM_Z_Lo, "Cyclades-Z below 1Mbyte"), DEVICE( CYCLADES, CYCLOM_Z_Hi, "Cyclades-Z above 1Mbyte"), DEVICE( CYCLADES, PC300_RX_2, "PC300/RSV or /X21 (2 ports)"), DEVICE( CYCLADES, PC300_RX_1, "PC300/RSV or /X21 (1 port)"), DEVICE( CYCLADES, PC300_TE_2, "PC300/TE (2 ports)"), DEVICE( CYCLADES, PC300_TE_1, "PC300/TE (1 port)"), DEVICE( ESSENTIAL, ESSENTIAL_ROADRUNNER,"Roadrunner serial HIPPI"), DEVICE( O2, O2_6832, "6832"), DEVICE( 3DFX, 3DFX_VOODOO, "Voodoo"), DEVICE( 3DFX, 3DFX_VOODOO2, "Voodoo2"), DEVICE( 3DFX, 3DFX_BANSHEE, "Banshee"), DEVICE( SIGMADES, SIGMADES_6425, "REALmagic64/GX"), DEVICE( AVM, AVM_A1, "A1 (Fritz)"), DEVICE( STALLION, STALLION_ECHPCI832,"EasyConnection 8/32"), DEVICE( STALLION, STALLION_ECHPCI864,"EasyConnection 8/64"), DEVICE( STALLION, STALLION_EIOPCI,"EasyIO"), DEVICE( OPTIBASE, OPTIBASE_FORGE, "MPEG Forge"), DEVICE( OPTIBASE, OPTIBASE_FUSION,"MPEG Fusion"), DEVICE( OPTIBASE, OPTIBASE_VPLEX, "VideoPlex"), DEVICE( OPTIBASE, OPTIBASE_VPLEXCC,"VideoPlex CC"), DEVICE( OPTIBASE, OPTIBASE_VQUEST,"VideoQuest"), DEVICE( SATSAGEM, SATSAGEM_PCR2101,"PCR2101 DVB receiver"), DEVICE( SATSAGEM, SATSAGEM_TELSATTURBO,"Telsat Turbo DVB"), DEVICE( HUGHES, HUGHES_DIRECPC, "DirecPC"), DEVICE( ENSONIQ, ENSONIQ_ES1371, "ES1371"), DEVICE( ENSONIQ, ENSONIQ_AUDIOPCI,"AudioPCI"), DEVICE( ALTEON, ALTEON_ACENIC, "AceNIC"), DEVICE( PICTUREL, PICTUREL_PCIVST,"PCIVST"), DEVICE( NVIDIA_SGS, NVIDIA_SGS_RIVA128, "Riva 128"), DEVICE( CBOARDS, CBOARDS_DAS1602_16,"DAS1602/16"), DEVICE( MOTOROLA_OOPS, MOTOROLA_FALCON,"Falcon"), DEVICE( TIMEDIA, TIMEDIA_4008A, "Noname 4008A"), DEVICE( SYMPHONY, SYMPHONY_101, "82C101"), DEVICE( TEKRAM, TEKRAM_DC290, "DC-290"), DEVICE( 3DLABS, 3DLABS_300SX, "GLINT 300SX"), DEVICE( 3DLABS, 3DLABS_500TX, "GLINT 500TX"), DEVICE( 3DLABS, 3DLABS_DELTA, "GLINT Delta"), DEVICE( 3DLABS, 3DLABS_PERMEDIA,"PERMEDIA"), DEVICE( 3DLABS, 3DLABS_MX, "GLINT MX"), DEVICE( AVANCE, AVANCE_ALG2064, "ALG2064i"), DEVICE( AVANCE, AVANCE_2302, "ALG-2302"), DEVICE( NETVIN, NETVIN_NV5000SC,"NV5000"), DEVICE( S3, S3_PLATO_PXS, "PLATO/PX (system)"), DEVICE( S3, S3_ViRGE, "ViRGE"), DEVICE( S3, S3_TRIO, "Trio32/Trio64"), DEVICE( S3, S3_AURORA64VP, "Aurora64V+"), DEVICE( S3, S3_TRIO64UVP, "Trio64UV+"), DEVICE( S3, S3_ViRGE_VX, "ViRGE/VX"), DEVICE( S3, S3_868, "Vision 868"), DEVICE( S3, S3_928, "Vision 928-P"), DEVICE( S3, S3_864_1, "Vision 864-P"), DEVICE( S3, S3_864_2, "Vision 864-P"), DEVICE( S3, S3_964_1, "Vision 964-P"), DEVICE( S3, S3_964_2, "Vision 964-P"), DEVICE( S3, S3_968, "Vision 968"), DEVICE( S3, S3_TRIO64V2, "Trio64V2/DX or /GX"), DEVICE( S3, S3_PLATO_PXG, "PLATO/PX (graphics)"), DEVICE( S3, S3_ViRGE_DXGX, "ViRGE/DX or /GX"), DEVICE( S3, S3_ViRGE_GX2, "ViRGE/GX2"), DEVICE( S3, S3_ViRGE_MX, "ViRGE/MX"), DEVICE( S3, S3_ViRGE_MXP, "ViRGE/MX+"), DEVICE( S3, S3_ViRGE_MXPMV, "ViRGE/MX+MV"), DEVICE( S3, S3_SONICVIBES, "SonicVibes"), DEVICE( DCI, DCI_PCCOM4, "PC COM PCI Bus 4 port serial Adapter"), DEVICE( GENROCO, GENROCO_HFP832, "TURBOstor HFP832"), DEVICE( INTEL, INTEL_82375, "82375EB"), DEVICE( INTEL, INTEL_82424, "82424ZX Saturn"), DEVICE( INTEL, INTEL_82378, "82378IB"), DEVICE( INTEL, INTEL_82430, "82430ZX Aries"), DEVICE( INTEL, INTEL_82434, "82434LX Mercury/Neptune"), DEVICE( INTEL, INTEL_I960, "i960"), DEVICE( INTEL, INTEL_I960RN, "i960 RN"), DEVICE( INTEL, INTEL_82559ER, "82559ER"), DEVICE( INTEL, INTEL_82092AA_0,"82092AA PCMCIA bridge"), DEVICE( INTEL, INTEL_82092AA_1,"82092AA EIDE"), DEVICE( INTEL, INTEL_7116, "SAA7116"), DEVICE( INTEL, INTEL_82596, "82596"), DEVICE( INTEL, INTEL_82865, "82865"), DEVICE( INTEL, INTEL_82557, "82557"), DEVICE( INTEL, INTEL_82437, "82437"), DEVICE( INTEL, INTEL_82371FB_0,"82371FB PIIX ISA"), DEVICE( INTEL, INTEL_82371FB_1,"82371FB PIIX IDE"), DEVICE( INTEL, INTEL_82371MX, "430MX - 82371MX MPIIX"), DEVICE( INTEL, INTEL_82437MX, "430MX - 82437MX MTSC"), DEVICE( INTEL, INTEL_82441, "82441FX Natoma"), DEVICE( INTEL, INTEL_82380FB, "82380FB Mobile"), DEVICE( INTEL, INTEL_82439, "82439HX Triton II"), DEVICE( INTEL, INTEL_MEGARAID, "OEM MegaRAID Controller"), DEVICE( INTEL, INTEL_82371SB_0,"82371SB PIIX3 ISA"), DEVICE( INTEL, INTEL_82371SB_1,"82371SB PIIX3 IDE"), DEVICE( INTEL, INTEL_82371SB_2,"82371SB PIIX3 USB"), DEVICE( INTEL, INTEL_82437VX, "82437VX Triton II"), DEVICE( INTEL, INTEL_82439TX, "82439TX"), DEVICE( INTEL, INTEL_82371AB_0,"82371AB PIIX4 ISA"), DEVICE( INTEL, INTEL_82371AB, "82371AB PIIX4 IDE"), DEVICE( INTEL, INTEL_82371AB_2,"82371AB PIIX4 USB"), DEVICE( INTEL, INTEL_82371AB_3,"82371AB PIIX4 ACPI"), DEVICE( INTEL, INTEL_82443LX_0,"440LX - 82443LX PAC Host"), DEVICE( INTEL, INTEL_82443LX_1,"440LX - 82443LX PAC AGP"), DEVICE( INTEL, INTEL_82443BX_0,"440BX - 82443BX Host"), DEVICE( INTEL, INTEL_82443BX_1,"440BX - 82443BX AGP"), DEVICE( INTEL, INTEL_82443BX_2,"440BX - 82443BX Host (no AGP)"), DEVICE( INTEL, INTEL_P6, "Orion P6"), DEVICE( INTEL, INTEL_82450GX, "450KX/GX [Orion] - 82454KX/GX PCI Bridge"), DEVICE( INTEL, INTEL_82453GX, "450KX/GX [Orion] - 82453KX/GX Memory Controller"), DEVICE( INTEL, INTEL_82451NX, "450NX - 82451NX Memory & I/O Controller"), DEVICE( INTEL, INTEL_82454NX, "450NX - 82454NX PCI Expander Bridge"), DEVICE( COMPUTONE, COMPUTONE_IP2EX, "Computone IntelliPort Plus"), DEVICE( KTI, KTI_ET32P2, "ET32P2"), DEVICE( ADAPTEC, ADAPTEC_7810, "AIC-7810 RAID"), DEVICE( ADAPTEC, ADAPTEC_7821, "AIC-7860"), DEVICE( ADAPTEC, ADAPTEC_38602, "AIC-7860"), DEVICE( ADAPTEC, ADAPTEC_7850, "AIC-7850"), DEVICE( ADAPTEC, ADAPTEC_7855, "AIC-7855"), DEVICE( ADAPTEC, ADAPTEC_5800, "AIC-5800"), DEVICE( ADAPTEC, ADAPTEC_3860, "AIC-7860"), DEVICE( ADAPTEC, ADAPTEC_7860, "AIC-7860"), DEVICE( ADAPTEC, ADAPTEC_7861, "AIC-7861"), DEVICE( ADAPTEC, ADAPTEC_7870, "AIC-7870"), DEVICE( ADAPTEC, ADAPTEC_7871, "AIC-7871"), DEVICE( ADAPTEC, ADAPTEC_7872, "AIC-7872"), DEVICE( ADAPTEC, ADAPTEC_7873, "AIC-7873"), DEVICE( ADAPTEC, ADAPTEC_7874, "AIC-7874"), DEVICE( ADAPTEC, ADAPTEC_7895, "AIC-7895U"), DEVICE( ADAPTEC, ADAPTEC_7880, "AIC-7880U"), DEVICE( ADAPTEC, ADAPTEC_7881, "AIC-7881U"), DEVICE( ADAPTEC, ADAPTEC_7882, "AIC-7882U"), DEVICE( ADAPTEC, ADAPTEC_7883, "AIC-7883U"), DEVICE( ADAPTEC, ADAPTEC_7884, "AIC-7884U"), DEVICE( ADAPTEC, ADAPTEC_7885, "AIC-7885U"), DEVICE( ADAPTEC, ADAPTEC_7886, "AIC-7886U"), DEVICE( ADAPTEC, ADAPTEC_7887, "AIC-7887U"), DEVICE( ADAPTEC, ADAPTEC_7888, "AIC-7888U"), DEVICE( ADAPTEC, ADAPTEC_1030, "ABA-1030 DVB receiver"), DEVICE( ADAPTEC2, ADAPTEC2_2940U2,"AHA-2940U2"), DEVICE( ADAPTEC2, ADAPTEC2_2930U2,"AHA-2930U2"), DEVICE( ADAPTEC2, ADAPTEC2_7890B, "AIC-7890/1"), DEVICE( ADAPTEC2, ADAPTEC2_7890, "AIC-7890/1"), DEVICE( ADAPTEC2, ADAPTEC2_3940U2,"AHA-3940U2"), DEVICE( ADAPTEC2, ADAPTEC2_3950U2D,"AHA-3950U2D"), DEVICE( ADAPTEC2, ADAPTEC2_7896, "AIC-7896/7"), DEVICE( ADAPTEC2, ADAPTEC2_7892A, "AIC-7892"), DEVICE( ADAPTEC2, ADAPTEC2_7892B, "AIC-7892"), DEVICE( ADAPTEC2, ADAPTEC2_7892D, "AIC-7892"), DEVICE( ADAPTEC2, ADAPTEC2_7892P, "AIC-7892"), DEVICE( ADAPTEC2, ADAPTEC2_7899A, "AIC-7899"), DEVICE( ADAPTEC2, ADAPTEC2_7899B, "AIC-7899"), DEVICE( ADAPTEC2, ADAPTEC2_7899D, "AIC-7899"), DEVICE( ADAPTEC2, ADAPTEC2_7899P, "AIC-7899"), DEVICE( ATRONICS, ATRONICS_2015, "IDE-2015PL"), DEVICE( TIGERJET, TIGERJET_300, "Tiger300 ISDN"), DEVICE( ARK, ARK_STING, "Stingray"), DEVICE( ARK, ARK_STINGARK, "Stingray ARK 2000PV"), DEVICE( ARK, ARK_2000MT, "2000MT") }; /* * device_info[] is sorted so we can use binary search */ static struct pci_dev_info * pci_lookup_dev(unsigned int vendor, unsigned int dev) { int min = 0, max = sizeof(dev_info)/sizeof(dev_info[0]) - 1; for ( ; ; ) { int i = (min + max) >> 1; long order; order = dev_info[i].vendor - (long) vendor; if (!order) order = dev_info[i].device - (long) dev; if (order < 0) { min = i + 1; if ( min > max ) return 0; continue; } if (order > 0) { max = i - 1; if ( min > max ) return 0; continue; } return & dev_info[ i ]; } } static const char * pci_strclass (unsigned int class, char *buf) { char *s; switch (class >> 8) { case PCI_CLASS_NOT_DEFINED: s = "Non-VGA device"; break; case PCI_CLASS_NOT_DEFINED_VGA: s = "VGA compatible device"; break; case PCI_CLASS_STORAGE_SCSI: s = "SCSI storage controller"; break; case PCI_CLASS_STORAGE_IDE: s = "IDE interface"; break; case PCI_CLASS_STORAGE_FLOPPY: s = "Floppy disk controller"; break; case PCI_CLASS_STORAGE_IPI: s = "IPI storage controller"; break; case PCI_CLASS_STORAGE_RAID: s = "RAID storage controller"; break; case PCI_CLASS_STORAGE_OTHER: s = "Unknown mass storage controller"; break; case PCI_CLASS_NETWORK_ETHERNET: s = "Ethernet controller"; break; case PCI_CLASS_NETWORK_TOKEN_RING: s = "Token ring network controller"; break; case PCI_CLASS_NETWORK_FDDI: s = "FDDI network controller"; break; case PCI_CLASS_NETWORK_ATM: s = "ATM network controller"; break; case PCI_CLASS_NETWORK_OTHER: s = "Network controller"; break; case PCI_CLASS_DISPLAY_VGA: s = "VGA compatible controller"; break; case PCI_CLASS_DISPLAY_XGA: s = "XGA compatible controller"; break; case PCI_CLASS_DISPLAY_OTHER: s = "Display controller"; break; case PCI_CLASS_MULTIMEDIA_VIDEO: s = "Multimedia video controller"; break; case PCI_CLASS_MULTIMEDIA_AUDIO: s = "Multimedia audio controller"; break; case PCI_CLASS_MULTIMEDIA_OTHER: s = "Multimedia controller"; break; case PCI_CLASS_MEMORY_RAM: s = "RAM memory"; break; case PCI_CLASS_MEMORY_FLASH: s = "FLASH memory"; break; case PCI_CLASS_MEMORY_OTHER: s = "Memory"; break; case PCI_CLASS_BRIDGE_HOST: s = "Host bridge"; break; case PCI_CLASS_BRIDGE_ISA: s = "ISA bridge"; break; case PCI_CLASS_BRIDGE_EISA: s = "EISA bridge"; break; case PCI_CLASS_BRIDGE_MC: s = "MicroChannel bridge"; break; case PCI_CLASS_BRIDGE_PCI: s = "PCI bridge"; break; case PCI_CLASS_BRIDGE_PCMCIA: s = "PCMCIA bridge"; break; case PCI_CLASS_BRIDGE_NUBUS: s = "NuBus bridge"; break; case PCI_CLASS_BRIDGE_CARDBUS: s = "CardBus bridge"; break; case PCI_CLASS_BRIDGE_OTHER: s = "Bridge"; break; case PCI_CLASS_COMMUNICATION_SERIAL: s = "Serial controller"; break; case PCI_CLASS_COMMUNICATION_PARALLEL: s = "Parallel controller"; break; case PCI_CLASS_COMMUNICATION_OTHER: s = "Communication controller"; break; case PCI_CLASS_SYSTEM_PIC: s = "PIC"; break; case PCI_CLASS_SYSTEM_DMA: s = "DMA controller"; break; case PCI_CLASS_SYSTEM_TIMER: s = "Timer"; break; case PCI_CLASS_SYSTEM_RTC: s = "RTC"; break; case PCI_CLASS_SYSTEM_OTHER: s = "System peripheral"; break; case PCI_CLASS_INPUT_KEYBOARD: s = "Keyboard controller"; break; case PCI_CLASS_INPUT_PEN: s = "Digitizer Pen"; break; case PCI_CLASS_INPUT_MOUSE: s = "Mouse controller"; break; case PCI_CLASS_INPUT_OTHER: s = "Input device controller"; break; case PCI_CLASS_DOCKING_GENERIC: s = "Generic Docking Station"; break; case PCI_CLASS_DOCKING_OTHER: s = "Docking Station"; break; case PCI_CLASS_PROCESSOR_386: s = "386"; break; case PCI_CLASS_PROCESSOR_486: s = "486"; break; case PCI_CLASS_PROCESSOR_PENTIUM: s = "Pentium"; break; case PCI_CLASS_PROCESSOR_ALPHA: s = "Alpha"; break; case PCI_CLASS_PROCESSOR_POWERPC: s = "Power PC"; break; case PCI_CLASS_PROCESSOR_CO: s = "Co-processor"; break; case PCI_CLASS_SERIAL_FIREWIRE: s = "FireWire (IEEE 1394)"; break; case PCI_CLASS_SERIAL_ACCESS: s = "ACCESS Bus"; break; case PCI_CLASS_SERIAL_SSA: s = "SSA"; break; case PCI_CLASS_SERIAL_USB: s = "USB Controller"; break; case PCI_CLASS_SERIAL_FIBER: s = "Fiber Channel"; break; case PCI_CLASS_SERIAL_SMBUS: s = "SM Bus"; break; case PCI_CLASS_HOT_SWAP_CONTROLLER: s = "Hot Swap Controller"; break; default: sprintf(buf, "[PCI_CLASS %x]", class); s = buf; break; } return s; } static const char * pci_strvendor(unsigned int vendor, char *buf) { char *s; switch (vendor) { case PCI_VENDOR_ID_COMPAQ: s = "Compaq"; break; case PCI_VENDOR_ID_NCR: s = "NCR"; break; case PCI_VENDOR_ID_ATI: s = "ATI"; break; case PCI_VENDOR_ID_VLSI: s = "VLSI"; break; case PCI_VENDOR_ID_ADL: s = "Avance Logic"; break; case PCI_VENDOR_ID_NS: s = "NS"; break; case PCI_VENDOR_ID_TSENG: s = "Tseng'Lab"; break; case PCI_VENDOR_ID_WEITEK: s = "Weitek"; break; case PCI_VENDOR_ID_DEC: s = "DEC"; break; case PCI_VENDOR_ID_CIRRUS: s = "Cirrus Logic"; break; case PCI_VENDOR_ID_IBM: s = "IBM"; break; case PCI_VENDOR_ID_WD: s = "Western Digital"; break; case PCI_VENDOR_ID_AMD: s = "AMD"; break; case PCI_VENDOR_ID_TRIDENT: s = "Trident"; break; case PCI_VENDOR_ID_AI: s = "Acer Incorporated"; break; case PCI_VENDOR_ID_MATROX: s = "Matrox"; break; case PCI_VENDOR_ID_CT: s = "Chips & Technologies"; break; case PCI_VENDOR_ID_MIRO: s = "Miro"; break; case PCI_VENDOR_ID_NEC: s = "NEC"; break; case PCI_VENDOR_ID_FD: s = "Future Domain"; break; case PCI_VENDOR_ID_SI: s = "Silicon Integrated Systems"; break; case PCI_VENDOR_ID_HP: s = "Hewlett Packard"; break; case PCI_VENDOR_ID_PCTECH: s = "PCTECH"; break; case PCI_VENDOR_ID_DPT: s = "DPT"; break; case PCI_VENDOR_ID_OPTI: s = "OPTi"; break; case PCI_VENDOR_ID_SGS: s = "SGS Thomson"; break; case PCI_VENDOR_ID_BUSLOGIC: s = "BusLogic"; break; case PCI_VENDOR_ID_TI: s = "Texas Instruments"; break; case PCI_VENDOR_ID_OAK: s = "OAK"; break; case PCI_VENDOR_ID_WINBOND2: s = "Winbond"; break; case PCI_VENDOR_ID_MOTOROLA: s = "Motorola"; break; case PCI_VENDOR_ID_MOTOROLA_OOPS: s = "Motorola"; break; case PCI_VENDOR_ID_PROMISE: s = "Promise Technology"; break; case PCI_VENDOR_ID_N9: s = "Number Nine"; break; case PCI_VENDOR_ID_UMC: s = "UMC"; break; case PCI_VENDOR_ID_X: s = "X TECHNOLOGY"; break; case PCI_VENDOR_ID_MYLEX: s = "Mylex"; break; case PCI_VENDOR_ID_PICOP: s = "PicoPower"; break; case PCI_VENDOR_ID_APPLE: s = "Apple"; break; case PCI_VENDOR_ID_NEXGEN: s = "Nexgen"; break; case PCI_VENDOR_ID_QLOGIC: s = "Q Logic"; break; case PCI_VENDOR_ID_CYRIX: s = "Cyrix"; break; case PCI_VENDOR_ID_LEADTEK: s = "Leadtek Research"; break; case PCI_VENDOR_ID_CONTAQ: s = "Contaq"; break; case PCI_VENDOR_ID_FOREX: s = "Forex"; break; case PCI_VENDOR_ID_OLICOM: s = "Olicom"; break; case PCI_VENDOR_ID_SUN: s = "Sun Microsystems"; break; case PCI_VENDOR_ID_CMD: s = "CMD"; break; case PCI_VENDOR_ID_VISION: s = "Vision"; break; case PCI_VENDOR_ID_BROOKTREE: s = "Brooktree"; break; case PCI_VENDOR_ID_SIERRA: s = "Sierra"; break; case PCI_VENDOR_ID_ACC: s = "ACC MICROELECTRONICS"; break; case PCI_VENDOR_ID_WINBOND: s = "Winbond"; break; case PCI_VENDOR_ID_DATABOOK: s = "Databook"; break; case PCI_VENDOR_ID_PLX: s = "PLX"; break; case PCI_VENDOR_ID_MADGE: s = "Madge Networks"; break; case PCI_VENDOR_ID_3COM: s = "3Com"; break; case PCI_VENDOR_ID_SMC: s = "SMC"; break; case PCI_VENDOR_ID_AL: s = "Acer Labs"; break; case PCI_VENDOR_ID_MITSUBISHI: s = "Mitsubishi"; break; case PCI_VENDOR_ID_SURECOM: s = "Surecom"; break; case PCI_VENDOR_ID_NEOMAGIC: s = "Neomagic"; break; case PCI_VENDOR_ID_ASP: s = "Advanced System Products"; break; case PCI_VENDOR_ID_MACRONIX: s = "Macronix"; break; case PCI_VENDOR_ID_CERN: s = "CERN"; break; case PCI_VENDOR_ID_NVIDIA: s = "NVidia"; break; case PCI_VENDOR_ID_IMS: s = "IMS"; break; case PCI_VENDOR_ID_TEKRAM2: s = "Tekram"; break; case PCI_VENDOR_ID_TUNDRA: s = "Tundra"; break; case PCI_VENDOR_ID_AMCC: s = "AMCC"; break; case PCI_VENDOR_ID_INTERG: s = "Intergraphics"; break; case PCI_VENDOR_ID_REALTEK: s = "Realtek"; break; case PCI_VENDOR_ID_TRUEVISION: s = "Truevision"; break; case PCI_VENDOR_ID_INIT: s = "Initio Corp"; break; case PCI_VENDOR_ID_TTI: s = "Triones Technologies, Inc."; break; case PCI_VENDOR_ID_VIA: s = "VIA Technologies"; break; case PCI_VENDOR_ID_SMC2: s = "SMC"; break; case PCI_VENDOR_ID_VORTEX: s = "VORTEX"; break; case PCI_VENDOR_ID_EF: s = "Efficient Networks"; break; case PCI_VENDOR_ID_FORE: s = "Fore Systems"; break; case PCI_VENDOR_ID_IMAGINGTECH: s = "Imaging Technology"; break; case PCI_VENDOR_ID_PHILIPS: s = "Philips"; break; case PCI_VENDOR_ID_CYCLONE: s = "Cyclone"; break; case PCI_VENDOR_ID_ALLIANCE: s = "Alliance"; break; case PCI_VENDOR_ID_VMIC: s = "VMIC"; break; case PCI_VENDOR_ID_DIGI: s = "Digi Intl."; break; case PCI_VENDOR_ID_MUTECH: s = "Mutech"; break; case PCI_VENDOR_ID_RENDITION: s = "Rendition"; break; case PCI_VENDOR_ID_TOSHIBA: s = "Toshiba"; break; case PCI_VENDOR_ID_RICOH: s = "Ricoh"; break; case PCI_VENDOR_ID_ARTOP: s = "Artop Electronics"; break; case PCI_VENDOR_ID_ZEITNET: s = "ZeitNet"; break; case PCI_VENDOR_ID_OMEGA: s = "Omega Micro"; break; case PCI_VENDOR_ID_LITEON: s = "LiteOn"; break; case PCI_VENDOR_ID_NP: s = "Network Peripherals"; break; case PCI_VENDOR_ID_ATT: s = "Lucent (ex-AT&T) Microelectronics"; break; case PCI_VENDOR_ID_SPECIALIX: s = "Specialix"; break; case PCI_VENDOR_ID_AURAVISION: s = "Auravision"; break; case PCI_VENDOR_ID_IKON: s = "Ikon"; break; case PCI_VENDOR_ID_ZORAN: s = "Zoran"; break; case PCI_VENDOR_ID_KINETIC: s = "Kinetic"; break; case PCI_VENDOR_ID_COMPEX: s = "Compex"; break; case PCI_VENDOR_ID_RP: s = "Comtrol"; break; case PCI_VENDOR_ID_CYCLADES: s = "Cyclades"; break; case PCI_VENDOR_ID_ESSENTIAL: s = "Essential Communications"; break; case PCI_VENDOR_ID_O2: s = "O2 Micro"; break; case PCI_VENDOR_ID_3DFX: s = "3Dfx"; break; case PCI_VENDOR_ID_SIGMADES: s = "Sigma Designs"; break; case PCI_VENDOR_ID_AVM: s = "AVM"; break; case PCI_VENDOR_ID_CCUBE: s = "C-Cube"; break; case PCI_VENDOR_ID_DIPIX: s = "Dipix"; break; case PCI_VENDOR_ID_STALLION: s = "Stallion Technologies"; break; case PCI_VENDOR_ID_OPTIBASE: s = "Optibase"; break; case PCI_VENDOR_ID_SATSAGEM: s = "SatSagem"; break; case PCI_VENDOR_ID_HUGHES: s = "Hughes"; break; case PCI_VENDOR_ID_ENSONIQ: s = "Ensoniq"; break; case PCI_VENDOR_ID_ALTEON: s = "Alteon"; break; case PCI_VENDOR_ID_PICTUREL: s = "Picture Elements"; break; case PCI_VENDOR_ID_NVIDIA_SGS: s = "NVidia/SGS Thomson"; break; case PCI_VENDOR_ID_CBOARDS: s = "ComputerBoards"; break; case PCI_VENDOR_ID_TIMEDIA: s = "Timedia Technology"; break; case PCI_VENDOR_ID_SYMPHONY: s = "Symphony"; break; case PCI_VENDOR_ID_COMPUTONE: s = "Computone Corporation"; break; case PCI_VENDOR_ID_TEKRAM: s = "Tekram"; break; case PCI_VENDOR_ID_3DLABS: s = "3Dlabs"; break; case PCI_VENDOR_ID_AVANCE: s = "Avance"; break; case PCI_VENDOR_ID_NETVIN: s = "NetVin"; break; case PCI_VENDOR_ID_S3: s = "S3 Inc."; break; case PCI_VENDOR_ID_DCI: s = "Decision Computer Int."; break; case PCI_VENDOR_ID_GENROCO: s = "Genroco"; break; case PCI_VENDOR_ID_INTEL: s = "Intel"; break; case PCI_VENDOR_ID_KTI: s = "KTI"; break; case PCI_VENDOR_ID_ADAPTEC: s = "Adaptec"; break; case PCI_VENDOR_ID_ADAPTEC2: s = "Adaptec"; break; case PCI_VENDOR_ID_ATRONICS: s = "Atronics"; break; case PCI_VENDOR_ID_TIGERJET: s = "TigerJet"; break; case PCI_VENDOR_ID_ARK: s = "ARK Logic"; break; case PCI_VENDOR_ID_SYSKONNECT: s = "SysKonnect"; break; default: sprintf(buf, "[PCI_VENDOR %x]", vendor); s = buf; break; } return s; } static const char * pci_strdev(unsigned int vendor, unsigned int device, char *buf) { struct pci_dev_info *info; if ((info = pci_lookup_dev(vendor, device))) return info->name; else { sprintf(buf, "[PCI_DEVICE %x]", device); return buf; } } /* * If the disk's name is started with these strings, we will skip it and do not * display its statistics. */ static char *skipped_disk_name[] = { "ram", "loop", NULL }; static int is_skipped_disk(char *name) { char **p = skipped_disk_name; while (*p) { if (strncmp(name, *p, strlen(*p)) == 0) return TRUE; p++; } return FALSE; } struct diskio { int read; int write; }; struct iter { /* If the kernel uses klist, the address should be klist.k_list */ long head_address; long current_address; long type_address; /* the address of symbol "disk_type" */ /* * If it is true, it means request_list.count[2] contains async/sync * requests. */ int sync_count; int diskname_len; unsigned long (*next_disk)(struct iter *); /* * The argument is the address of request_queue, and the function * returns the total requests in the driver(not ended) */ unsigned int (*get_in_flight)(unsigned long); /* * this function reads request_list.count[2], and the first argument * is the address of request_queue. */ void (*get_diskio)(unsigned long , unsigned long, struct diskio *); /* * check if device.type == &disk_type * * old kernel(version <= 2.6.24) does not have the symbol "disk_type", * and this callback should be null. */ int (*match)(struct iter *, unsigned long); /* * If the kernel uses list, the argument is the address of list_head, * otherwise, the argument is the address of klist_node. */ unsigned long (*get_gendisk)(unsigned long); }; /* kernel version <= 2.6.24 */ static unsigned long get_gendisk_1(unsigned long entry) { return entry - OFFSET(kobject_entry) - OFFSET(gendisk_kobj); } /* 2.6.24 < kernel version <= 2.6.27 */ static unsigned long get_gendisk_2(unsigned long entry) { return entry - OFFSET(device_node) - OFFSET(gendisk_dev); } /* kernel version > 2.6.27 && struct gendisk contains dev/__dev */ static unsigned long get_gendisk_3(unsigned long entry) { return entry - OFFSET(device_knode_class) - OFFSET(gendisk_dev); } /* kernel version > 2.6.27 && struct gendisk does not contain dev/__dev */ static unsigned long get_gendisk_4(unsigned long entry) { return entry - OFFSET(device_knode_class) - OFFSET(hd_struct_dev) - OFFSET(gendisk_part0); } /* kernel version >= 5.1 */ static unsigned long get_gendisk_5(unsigned long entry) { unsigned long device_address; unsigned long device_private_address; unsigned long gendisk; device_private_address = entry - OFFSET(device_private_knode_class); readmem(device_private_address + OFFSET(device_private_device), KVADDR, &device_address, sizeof(device_address), "device_private.device", FAULT_ON_ERROR); if (VALID_MEMBER(hd_struct_dev)) return device_address - OFFSET(hd_struct_dev) - OFFSET(gendisk_part0); /* kernel version >= 5.11 */ readmem(device_address - OFFSET(block_device_bd_device) + OFFSET(block_device_bd_disk), KVADDR, &gendisk, sizeof(ulong), "block_device.bd_disk", FAULT_ON_ERROR); return gendisk; } /* 2.6.24 < kernel version <= 2.6.27 */ static int match_list(struct iter *i, unsigned long entry) { unsigned long device_address; unsigned long device_type; device_address = entry - OFFSET(device_node); readmem(device_address + OFFSET(device_type), KVADDR, &device_type, sizeof(device_type), "device.type", FAULT_ON_ERROR); if (device_type != i->type_address) return FALSE; return TRUE; } /* kernel version > 2.6.27 */ static int match_klist(struct iter *i, unsigned long entry) { unsigned long device_address; unsigned long device_type; unsigned long device_private_address; if (VALID_MEMBER(device_knode_class)) device_address = entry - OFFSET(device_knode_class); else { /* kernel version >= 5.1 */ device_private_address = entry - OFFSET(device_private_knode_class); readmem(device_private_address + OFFSET(device_private_device), KVADDR, &device_address, sizeof(device_address), "device_private.device", FAULT_ON_ERROR); } readmem(device_address + OFFSET(device_type), KVADDR, &device_type, sizeof(device_type), "device.type", FAULT_ON_ERROR); if (device_type != i->type_address) return FALSE; return TRUE; } /* old kernel(version <= 2.6.27): list */ static unsigned long next_disk_list(struct iter *i) { unsigned long list_head_address, next_address; if (i->current_address) { list_head_address = i->current_address; } else { list_head_address = i->head_address; } again: /* read list_head.next */ readmem(list_head_address + OFFSET(list_head_next), KVADDR, &next_address, sizeof(next_address), "list_head.next", FAULT_ON_ERROR); if (next_address == i->head_address) return 0; if (i->match && !i->match(i, next_address)) { list_head_address = next_address; goto again; } i->current_address = next_address; return i->get_gendisk(next_address); } /* new kernel(version > 2.6.27): klist */ static unsigned long next_disk_klist(struct iter* i) { unsigned long klist_node_address, list_head_address, next_address; unsigned long n_klist; if (i->current_address) { list_head_address = i->current_address; } else { list_head_address = i->head_address; } again: /* read list_head.next */ readmem(list_head_address + OFFSET(list_head_next), KVADDR, &next_address, sizeof(next_address), "list_head.next", FAULT_ON_ERROR); /* skip dead klist_node */ while(next_address != i->head_address) { klist_node_address = next_address - OFFSET(klist_node_n_node); readmem(klist_node_address + OFFSET(klist_node_n_klist), KVADDR, &n_klist, sizeof(n_klist), "klist_node.n_klist", FAULT_ON_ERROR); if (!(n_klist & 1)) break; /* the klist_node is dead, skip to next klist_node */ readmem(next_address + OFFSET(list_head_next), KVADDR, &next_address, sizeof(next_address), "list_head.next", FAULT_ON_ERROR); } if (next_address == i->head_address) return 0; if (i->match && !i->match(i, klist_node_address)) { list_head_address = next_address; goto again; } i->current_address = next_address; return i->get_gendisk(klist_node_address); } static int use_mq_interface(unsigned long q) { unsigned long mq_ops; if (!VALID_MEMBER(request_queue_mq_ops)) return 0; readmem(q + OFFSET(request_queue_mq_ops), KVADDR, &mq_ops, sizeof(ulong), "request_queue.mq_ops", FAULT_ON_ERROR); if (mq_ops == 0) return 0; else return 1; } static void get_one_mctx_diskio(unsigned long mctx, struct diskio *io) { unsigned long dispatch[2]; unsigned long comp[2]; readmem(mctx + OFFSET(blk_mq_ctx_rq_dispatched), KVADDR, dispatch, sizeof(ulong) * 2, "blk_mq_ctx.rq_dispatched", FAULT_ON_ERROR); readmem(mctx + OFFSET(blk_mq_ctx_rq_completed), KVADDR, comp, sizeof(ulong) * 2, "blk_mq_ctx.rq_completed", FAULT_ON_ERROR); io->read = (dispatch[0] - comp[0]); io->write = (dispatch[1] - comp[1]); } typedef bool (busy_tag_iter_fn)(ulong rq, void *data); struct mq_inflight { ulong q; struct diskio *dio; }; struct bt_iter_data { ulong tags; uint reserved; uint nr_reserved_tags; busy_tag_iter_fn *fn; void *data; }; /* * See the include/linux/blk_types.h and include/linux/blk-mq.h */ #define MQ_RQ_IN_FLIGHT 1 #define REQ_OP_BITS 8 #define REQ_OP_MASK ((1 << REQ_OP_BITS) - 1) static long blk_hctx_shared = 0; static bool blk_mq_is_shared_tags(unsigned int flags) { return flags & blk_hctx_shared; } static uint op_is_write(uint op) { return (op & REQ_OP_MASK) & 1; } static bool mq_check_inflight(ulong rq, void *data) { uint cmd_flags = 0, state = 0; ulong addr = 0, queue = 0; struct mq_inflight *mi = data; if (!IS_KVADDR(rq)) return TRUE; addr = rq + OFFSET(request_q); if (!readmem(addr, KVADDR, &queue, sizeof(ulong), "request.q", RETURN_ON_ERROR)) return FALSE; addr = rq + OFFSET(request_cmd_flags); if (!readmem(addr, KVADDR, &cmd_flags, sizeof(uint), "request.cmd_flags", RETURN_ON_ERROR)) return FALSE; addr = rq + OFFSET(request_state); if (!readmem(addr, KVADDR, &state, sizeof(uint), "request.state", RETURN_ON_ERROR)) return FALSE; if (queue == mi->q && state == MQ_RQ_IN_FLIGHT) { if (op_is_write(cmd_flags)) mi->dio->write++; else mi->dio->read++; } return TRUE; } static bool bt_iter(uint bitnr, void *data) { ulong addr = 0, rqs_addr = 0, rq = 0; struct bt_iter_data *iter_data = data; ulong tag = iter_data->tags; if (!iter_data->reserved) bitnr += iter_data->nr_reserved_tags; /* rqs */ addr = tag + OFFSET(blk_mq_tags_rqs); if (!readmem(addr, KVADDR, &rqs_addr, sizeof(void *), "blk_mq_tags.rqs", RETURN_ON_ERROR)) return FALSE; addr = rqs_addr + bitnr * sizeof(ulong); /* rqs[bitnr] */ if (!readmem(addr, KVADDR, &rq, sizeof(ulong), "blk_mq_tags.rqs[]", RETURN_ON_ERROR)) return FALSE; return iter_data->fn(rq, iter_data->data); } static void bt_for_each(ulong q, ulong tags, ulong sbq, uint reserved, uint nr_resvd_tags, struct diskio *dio) { struct sbitmap_context sc = {0}; struct mq_inflight mi = { .q = q, .dio = dio, }; struct bt_iter_data iter_data = { .tags = tags, .reserved = reserved, .nr_reserved_tags = nr_resvd_tags, .fn = mq_check_inflight, .data = &mi, }; sbitmap_context_load(sbq + OFFSET(sbitmap_queue_sb), &sc); sbitmap_for_each_set(&sc, bt_iter, &iter_data); } static bool queue_for_each_hw_ctx(ulong q, ulong blk_mq_tags_ptr, bool bitmap_tags_is_ptr, struct diskio *dio) { uint nr_reserved_tags = 0; ulong tags = 0, addr = 0; bool ret = FALSE; if (!readmem(blk_mq_tags_ptr, KVADDR, &tags, sizeof(ulong), "blk_mq_hw_ctx.tags", RETURN_ON_ERROR)) goto out; addr = tags + OFFSET(blk_mq_tags_nr_reserved_tags); if (!readmem(addr, KVADDR, &nr_reserved_tags, sizeof(uint), "blk_mq_tags_nr_reserved_tags", RETURN_ON_ERROR)) goto out; if (nr_reserved_tags) { addr = tags + OFFSET(blk_mq_tags_breserved_tags); if (bitmap_tags_is_ptr && !readmem(addr, KVADDR, &addr, sizeof(ulong), "blk_mq_tags.bitmap_tags", RETURN_ON_ERROR)) goto out; bt_for_each(q, tags, addr, 1, nr_reserved_tags, dio); } addr = tags + OFFSET(blk_mq_tags_bitmap_tags); if (bitmap_tags_is_ptr && !readmem(addr, KVADDR, &addr, sizeof(ulong), "blk_mq_tags.bitmap_tags", RETURN_ON_ERROR)) goto out; bt_for_each(q, tags, addr, 0, nr_reserved_tags, dio); ret = TRUE; out: return ret; } /* * Replica of kernel block/blk-mq-tag.c:blk_mq_queue_tag_busy_iter() */ static void blk_mq_queue_tag_busy_iter(ulong q, ulong *hctx, uint cnt, struct diskio *dio) { uint i, flags; int bitmap_tags_is_ptr = 0; ulong addr = 0; if (MEMBER_TYPE("blk_mq_tags", "bitmap_tags") == TYPE_CODE_PTR) bitmap_tags_is_ptr = 1; readmem(q + OFFSET(request_queue_tag_set), KVADDR, &addr, sizeof(ulong), "request_queue.tag_set", RETURN_ON_ERROR); readmem(addr + OFFSET(blk_mq_tag_set_flags), KVADDR, &flags, sizeof(uint), "blk_mq_tag_set.flags", RETURN_ON_ERROR); if (blk_mq_is_shared_tags(flags) && VALID_MEMBER(blk_mq_tag_set_shared_tags)) { addr = addr + OFFSET(blk_mq_tag_set_shared_tags); queue_for_each_hw_ctx(q, addr, bitmap_tags_is_ptr, dio); return; } for (i = 0; i < cnt; i++) { /* Tags owned by the block driver */ addr = hctx[i] + OFFSET(blk_mq_hw_ctx_tags); if (queue_for_each_hw_ctx(q, addr, bitmap_tags_is_ptr, dio) == FALSE) return; } } static void get_mq_diskio_from_hw_queues(ulong q, struct diskio *dio) { uint cnt = 0; ulong addr = 0, hctx_addr = 0; ulong *hctx_array = NULL; struct list_pair *lp = NULL; if (VALID_MEMBER(request_queue_hctx_table)) { addr = q + OFFSET(request_queue_hctx_table); cnt = do_xarray(addr, XARRAY_COUNT, NULL); lp = (struct list_pair *)GETBUF(sizeof(struct list_pair) * (cnt + 1)); if (!lp) error(FATAL, "fail to get memory for list_pair.\n"); lp[0].index = cnt; cnt = do_xarray(addr, XARRAY_GATHER, lp); } else { addr = q + OFFSET(request_queue_nr_hw_queues); readmem(addr, KVADDR, &cnt, sizeof(uint), "request_queue.nr_hw_queues", FAULT_ON_ERROR); addr = q + OFFSET(request_queue_queue_hw_ctx); readmem(addr, KVADDR, &hctx_addr, sizeof(void *), "request_queue.queue_hw_ctx", FAULT_ON_ERROR); } hctx_array = (ulong *)GETBUF(sizeof(void *) * cnt); if (!hctx_array) { if (lp) FREEBUF(lp); error(FATAL, "fail to get memory for the hctx_array\n"); } if (lp && hctx_array) { uint i; /* copy it from list_pair to hctx_array */ for (i = 0; i < cnt; i++) hctx_array[i] = (ulong)lp[i].value; FREEBUF(lp); } else if (!readmem(hctx_addr, KVADDR, hctx_array, sizeof(void *) * cnt, "request_queue.queue_hw_ctx[]", RETURN_ON_ERROR)) { FREEBUF(hctx_array); return; } blk_mq_queue_tag_busy_iter(q, hctx_array, cnt, dio); FREEBUF(hctx_array); } static void get_mq_diskio(unsigned long q, unsigned long *mq_count) { int cpu; unsigned long queue_ctx; unsigned long mctx_addr; struct diskio tmp = {0}; /* * Currently this function does not support old blk-mq implementation * before 12f5b9314545 ("blk-mq: Remove generation seqeunce"), so * filter them out. */ if (VALID_MEMBER(request_state)) { if (CRASHDEBUG(1)) fprintf(fp, "mq: using sbitmap\n"); get_mq_diskio_from_hw_queues(q, &tmp); mq_count[0] = tmp.read; mq_count[1] = tmp.write; return; } if (CRASHDEBUG(1)) fprintf(fp, "mq: using blk_mq_ctx.rq_{completed,dispatched} counters\n"); readmem(q + OFFSET(request_queue_queue_ctx), KVADDR, &queue_ctx, sizeof(ulong), "request_queue.queue_ctx", FAULT_ON_ERROR); for (cpu = 0; cpu < kt->cpus; cpu++) { if ((kt->flags & SMP) && (kt->flags & PER_CPU_OFF)) { mctx_addr = queue_ctx + kt->__per_cpu_offset[cpu]; get_one_mctx_diskio(mctx_addr, &tmp); mq_count[0] += tmp.read; mq_count[1] += tmp.write; } } } static void get_one_diskio_from_dkstats(unsigned long dkstats, unsigned long *count) { int cpu; unsigned long dkstats_addr; unsigned long in_flight[2]; for (cpu = 0; cpu < kt->cpus; cpu++) { if ((kt->flags & SMP) && (kt->flags & PER_CPU_OFF)) { dkstats_addr = dkstats + kt->__per_cpu_offset[cpu]; readmem(dkstats_addr + OFFSET(disk_stats_in_flight), KVADDR, in_flight, sizeof(long) * 2, "disk_stats.in_flight", FAULT_ON_ERROR); count[0] += in_flight[0]; count[1] += in_flight[1]; } } } /* read request_queue.rq.count[2] */ static void get_diskio_1(unsigned long rq, unsigned long gendisk, struct diskio *io) { int count[2]; unsigned long io_counts[2] = { 0 }; unsigned long dkstats; if (!use_mq_interface(rq)) { if (VALID_MEMBER(request_queue_rq)) { readmem(rq + OFFSET(request_queue_rq) + OFFSET(request_list_count), KVADDR, count, sizeof(int) * 2, "request_list.count", FAULT_ON_ERROR); io->read = count[0]; io->write = count[1]; } else { if (VALID_MEMBER(hd_struct_dkstats)) readmem(gendisk + OFFSET(gendisk_part0) + OFFSET(hd_struct_dkstats), KVADDR, &dkstats, sizeof(ulong), "gendisk.part0.dkstats", FAULT_ON_ERROR); else { /* kernel version >= 5.11 */ ulong block_device; readmem(gendisk + OFFSET(gendisk_part0), KVADDR, &block_device, sizeof(ulong), "gendisk.part0", FAULT_ON_ERROR); readmem(block_device + OFFSET(block_device_bd_stats), KVADDR, &dkstats, sizeof(ulong), "block_device.bd_stats", FAULT_ON_ERROR); } get_one_diskio_from_dkstats(dkstats, io_counts); io->read = io_counts[0]; io->write = io_counts[1]; } } else { get_mq_diskio(rq, io_counts); io->read = io_counts[0]; io->write = io_counts[1]; } } /* request_queue.in_flight contains total requests */ static unsigned int get_in_flight_1(unsigned long rq) { unsigned int in_flight; readmem(rq+ OFFSET(request_queue_in_flight), KVADDR, &in_flight, sizeof(uint), "request_queue.in_flight", FAULT_ON_ERROR); return in_flight; } /* request_queue.in_flight[2] contains read/write requests */ static unsigned int get_in_flight_2(unsigned long rq) { unsigned int in_flight[2]; readmem(rq+ OFFSET(request_queue_in_flight), KVADDR, in_flight, sizeof(uint) * 2, "request_queue.in_flight", FAULT_ON_ERROR); return in_flight[0] + in_flight[1]; } static void init_iter(struct iter *i) { ARRAY_LENGTH_INIT(i->diskname_len, gendisk.disk_name, "gendisk.disk_name", NULL, sizeof(char)); if (i->diskname_len < 0 || i->diskname_len > BUFSIZE) { option_not_supported('d'); return; } i->current_address = 0; /* check whether BLK_RW_SYNC exists */ i->sync_count = get_symbol_type("BLK_RW_SYNC", NULL, NULL) == TYPE_CODE_ENUM; if (SIZE(rq_in_flight) == sizeof(int)) { i->get_in_flight = get_in_flight_1; } else if (SIZE(rq_in_flight) == sizeof(int) * 2) { i->get_in_flight = get_in_flight_2; } i->get_diskio = get_diskio_1; if (symbol_exists("block_subsys") || symbol_exists("block_kset")) { /* kernel version <= 2.6.24 */ unsigned long block_subsys_addr; if (symbol_exists("block_subsys")) block_subsys_addr = symbol_value("block_subsys"); else block_subsys_addr = symbol_value("block_kset"); if (VALID_STRUCT(subsystem)) i->head_address = block_subsys_addr + OFFSET(subsystem_kset) + OFFSET(kset_list); else i->head_address = block_subsys_addr + OFFSET(kset_list); i->type_address = 0; i->next_disk = next_disk_list; i->match = NULL; i->get_gendisk = get_gendisk_1; } else if (symbol_exists("block_class")) { unsigned long block_class_addr = symbol_value("block_class"); i->type_address = symbol_value("disk_type"); if (VALID_MEMBER(class_devices) || (VALID_MEMBER(class_private_devices) && SIZE(class_private_devices) == SIZE(list_head))) { /* 2.6.24 < kernel version <= 2.6.27, list */ if (!VALID_STRUCT(class_private)) { /* 2.6.24 < kernel version <= 2.6.26 */ i->head_address = block_class_addr + OFFSET(class_devices); } else { /* kernel version is 2.6.27 */ unsigned long class_private_addr; readmem(block_class_addr + OFFSET(class_p), KVADDR, &class_private_addr, sizeof(class_private_addr), "class.p", FAULT_ON_ERROR); i->head_address = class_private_addr + OFFSET(class_private_devices); } i->next_disk = next_disk_list; i->match = match_list; i->get_gendisk = get_gendisk_2; } else { /* kernel version > 2.6.27, klist */ unsigned long class_private_addr; if (INVALID_MEMBER(class_p)) /* kernel version >= 6.4 */ class_private_addr = get_subsys_private("class_kset", "block"); else readmem(block_class_addr + OFFSET(class_p), KVADDR, &class_private_addr, sizeof(class_private_addr), "class.p", FAULT_ON_ERROR); if (!class_private_addr) error(FATAL, "cannot determine subsys_private for block.\n"); if (VALID_STRUCT(class_private)) { /* 2.6.27 < kernel version <= 2.6.37-rc2 */ i->head_address = class_private_addr + OFFSET(class_private_devices); } else { /* kernel version > 2.6.37-rc2 */ i->head_address = class_private_addr + OFFSET(subsys_private_klist_devices); } i->head_address += OFFSET(klist_k_list); i->next_disk = next_disk_klist; i->match = match_klist; if (VALID_MEMBER(gendisk_dev)) i->get_gendisk = get_gendisk_3; else if (VALID_MEMBER(device_knode_class)) i->get_gendisk = get_gendisk_4; else i->get_gendisk = get_gendisk_5; } } else { option_not_supported('d'); return; } } static void display_one_diskio(struct iter *i, unsigned long gendisk, ulong flags) { char disk_name[BUFSIZE + 1]; char buf0[BUFSIZE]; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char buf3[BUFSIZE]; char buf4[BUFSIZE]; char buf5[BUFSIZE]; int major; unsigned long queue_addr; unsigned int in_flight; struct diskio io; memset(disk_name, 0, BUFSIZE + 1); readmem(gendisk + OFFSET(gendisk_disk_name), KVADDR, disk_name, i->diskname_len, "gen_disk.disk_name", FAULT_ON_ERROR); if (is_skipped_disk(disk_name)) return; readmem(gendisk + OFFSET(gendisk_queue), KVADDR, &queue_addr, sizeof(ulong), "gen_disk.queue", FAULT_ON_ERROR); readmem(gendisk + OFFSET(gendisk_major), KVADDR, &major, sizeof(int), "gen_disk.major", FAULT_ON_ERROR); i->get_diskio(queue_addr, gendisk, &io); if ((flags & DIOF_NONZERO) && (io.read + io.write == 0)) return; fprintf(fp, "%s%s%s %s%s%s%s %s%5d%s%s%s%s%s", mkstring(buf0, 5, RJUST|INT_DEC, (char *)(unsigned long)major), space(MINSPACE), mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, (char *)gendisk), space(MINSPACE), mkstring(buf2, 10, LJUST, disk_name), space(MINSPACE), mkstring(buf3, VADDR_PRLEN <= 11 ? 11 : VADDR_PRLEN, LJUST|LONG_HEX, (char *)queue_addr), space(MINSPACE), io.read + io.write, space(MINSPACE), mkstring(buf4, 5, RJUST|INT_DEC, (char *)(unsigned long)io.read), space(MINSPACE), mkstring(buf5, 5, RJUST|INT_DEC, (char *)(unsigned long)io.write), space(MINSPACE)); if (VALID_MEMBER(request_queue_in_flight)) { if (!use_mq_interface(queue_addr)) { in_flight = i->get_in_flight(queue_addr); fprintf(fp, "%5u\n", in_flight); } else fprintf(fp, "%s\n", "N/A(MQ)"); } else fprintf(fp, "\n"); } static void display_all_diskio(ulong flags) { struct iter i; unsigned long gendisk; char buf0[BUFSIZE]; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char buf3[BUFSIZE]; char buf4[BUFSIZE]; char buf5[BUFSIZE]; init_iter(&i); fprintf(fp, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", "MAJOR", space(MINSPACE), mkstring(buf0, VADDR_PRLEN + 2, LJUST, "GENDISK"), space(MINSPACE), "NAME ", space(MINSPACE), mkstring(buf1, VADDR_PRLEN <= 11 ? 13 : VADDR_PRLEN + 2, LJUST, "REQUEST_QUEUE"), space(MINSPACE), mkstring(buf2, 5, RJUST, "TOTAL"), space(MINSPACE), i.sync_count ? mkstring(buf3, 5, RJUST, "ASYNC") : mkstring(buf3, 5, RJUST, "READ"), space(MINSPACE), i.sync_count ? mkstring(buf4, 5, RJUST, "SYNC") : mkstring(buf4, 5, RJUST, "WRITE"), space(MINSPACE), VALID_MEMBER(request_queue_in_flight) ? mkstring(buf5, 5, RJUST, "DRV") : ""); while ((gendisk = i.next_disk(&i)) != 0) display_one_diskio(&i, gendisk, flags); } static void diskio_init(void) { if (dt->flags & DISKIO_INIT) return; MEMBER_OFFSET_INIT(class_devices, "class", "class_devices"); if (INVALID_MEMBER(class_devices)) MEMBER_OFFSET_INIT(class_devices, "class", "devices"); MEMBER_OFFSET_INIT(class_p, "class", "p"); if (INVALID_MEMBER(class_p)) { MEMBER_OFFSET_INIT(kset_list, "kset", "list"); MEMBER_OFFSET_INIT(kset_kobj, "kset", "kobj"); MEMBER_OFFSET_INIT(kobject_name, "kobject", "name"); MEMBER_OFFSET_INIT(kobject_entry, "kobject", "entry"); MEMBER_OFFSET_INIT(subsys_private_subsys, "subsys_private", "subsys"); } MEMBER_OFFSET_INIT(class_private_devices, "class_private", "class_devices"); MEMBER_OFFSET_INIT(device_knode_class, "device", "knode_class"); MEMBER_OFFSET_INIT(device_node, "device", "node"); MEMBER_OFFSET_INIT(device_type, "device", "type"); MEMBER_OFFSET_INIT(device_private_device, "device_private", "device"); MEMBER_OFFSET_INIT(device_private_knode_class, "device_private", "knode_class"); MEMBER_OFFSET_INIT(gendisk_dev, "gendisk", "dev"); if (INVALID_MEMBER(gendisk_dev)) MEMBER_OFFSET_INIT(gendisk_dev, "gendisk", "__dev"); MEMBER_OFFSET_INIT(gendisk_kobj, "gendisk", "kobj"); MEMBER_OFFSET_INIT(gendisk_part0, "gendisk", "part0"); MEMBER_OFFSET_INIT(gendisk_queue, "gendisk", "queue"); MEMBER_OFFSET_INIT(hd_struct_dev, "hd_struct", "__dev"); MEMBER_OFFSET_INIT(hd_struct_dkstats, "hd_struct", "dkstats"); MEMBER_OFFSET_INIT(block_device_bd_device, "block_device", "bd_device"); MEMBER_OFFSET_INIT(block_device_bd_stats, "block_device", "bd_stats"); MEMBER_OFFSET_INIT(klist_k_list, "klist", "k_list"); MEMBER_OFFSET_INIT(klist_node_n_klist, "klist_node", "n_klist"); MEMBER_OFFSET_INIT(klist_node_n_node, "klist_node", "n_node"); MEMBER_OFFSET_INIT(kobject_entry, "kobject", "entry"); MEMBER_OFFSET_INIT(kset_list, "kset", "list"); MEMBER_OFFSET_INIT(request_list_count, "request_list", "count"); MEMBER_OFFSET_INIT(request_cmd_flags, "request", "cmd_flags"); MEMBER_OFFSET_INIT(request_q, "request", "q"); MEMBER_OFFSET_INIT(request_state, "request", "state"); MEMBER_OFFSET_INIT(request_queue_in_flight, "request_queue", "in_flight"); if (MEMBER_EXISTS("request_queue", "rq")) MEMBER_OFFSET_INIT(request_queue_rq, "request_queue", "rq"); else MEMBER_OFFSET_INIT(request_queue_rq, "request_queue", "root_rl"); if (MEMBER_EXISTS("request_queue", "mq_ops")) { MEMBER_OFFSET_INIT(request_queue_mq_ops, "request_queue", "mq_ops"); ANON_MEMBER_OFFSET_INIT(request_queue_queue_ctx, "request_queue", "queue_ctx"); MEMBER_OFFSET_INIT(request_queue_queue_hw_ctx, "request_queue", "queue_hw_ctx"); MEMBER_OFFSET_INIT(request_queue_nr_hw_queues, "request_queue", "nr_hw_queues"); MEMBER_OFFSET_INIT(request_queue_hctx_table, "request_queue", "hctx_table"); MEMBER_OFFSET_INIT(blk_mq_ctx_rq_dispatched, "blk_mq_ctx", "rq_dispatched"); MEMBER_OFFSET_INIT(blk_mq_ctx_rq_completed, "blk_mq_ctx", "rq_completed"); MEMBER_OFFSET_INIT(blk_mq_hw_ctx_tags, "blk_mq_hw_ctx", "tags"); MEMBER_OFFSET_INIT(blk_mq_tags_bitmap_tags, "blk_mq_tags", "bitmap_tags"); MEMBER_OFFSET_INIT(blk_mq_tags_breserved_tags, "blk_mq_tags", "breserved_tags"); MEMBER_OFFSET_INIT(blk_mq_tags_nr_reserved_tags, "blk_mq_tags", "nr_reserved_tags"); MEMBER_OFFSET_INIT(blk_mq_tags_rqs, "blk_mq_tags", "rqs"); STRUCT_SIZE_INIT(blk_mq_tags, "blk_mq_tags"); STRUCT_SIZE_INIT(sbitmap, "sbitmap"); STRUCT_SIZE_INIT(sbitmap_word, "sbitmap_word"); MEMBER_OFFSET_INIT(sbitmap_word_word, "sbitmap_word", "word"); MEMBER_OFFSET_INIT(sbitmap_word_cleared, "sbitmap_word", "cleared"); MEMBER_OFFSET_INIT(sbitmap_depth, "sbitmap", "depth"); MEMBER_OFFSET_INIT(sbitmap_shift, "sbitmap", "shift"); MEMBER_OFFSET_INIT(sbitmap_map_nr, "sbitmap", "map_nr"); MEMBER_OFFSET_INIT(sbitmap_map, "sbitmap", "map"); MEMBER_OFFSET_INIT(sbitmap_queue_sb, "sbitmap_queue", "sb"); } MEMBER_OFFSET_INIT(subsys_private_klist_devices, "subsys_private", "klist_devices"); MEMBER_OFFSET_INIT(subsystem_kset, "subsystem", "kset"); STRUCT_SIZE_INIT(subsystem, "subsystem"); STRUCT_SIZE_INIT(class_private, "class_private"); MEMBER_SIZE_INIT(rq_in_flight, "request_queue", "in_flight"); MEMBER_SIZE_INIT(class_private_devices, "class_private", "class_devices"); MEMBER_OFFSET_INIT(disk_stats_in_flight, "disk_stats", "in_flight"); MEMBER_OFFSET_INIT(request_queue_tag_set, "request_queue", "tag_set"); MEMBER_OFFSET_INIT(blk_mq_tag_set_flags, "blk_mq_tag_set", "flags"); MEMBER_OFFSET_INIT(blk_mq_tag_set_shared_tags, "blk_mq_tag_set", "shared_tags"); enumerator_value("BLK_MQ_F_TAG_HCTX_SHARED", &blk_hctx_shared); dt->flags |= DISKIO_INIT; } static void diskio_option(ulong flags) { diskio_init(); display_all_diskio(flags); } void devdump_extract(void *_note, ulonglong offset, char *dump_file, FILE *ofp) { struct vmcoredd_header *vh = (struct vmcoredd_header *)_note; ulong dump_size, count; FILE *tmpfp; if (vh->n_type != NT_VMCOREDD) error(FATAL, "unsupported note type: 0x%x", vh->n_type); dump_size = vh->n_descsz - VMCOREDD_MAX_NAME_BYTES; if (dump_file) { tmpfp = fopen(dump_file, "w"); if (!tmpfp) { error(FATAL, "cannot open output file: %s\n", dump_file); return; } set_tmpfile2(tmpfp); } fprintf(ofp, "DEVICE: %s\n", vh->dump_name); if (dump_file) count = dump_size; else count = dump_size/sizeof(uint64_t) + (dump_size % sizeof(uint64_t) ? 1 : 0); display_memory_from_file_offset(offset + sizeof(struct vmcoredd_header), count, dump_file); } void devdump_info(void *_note, ulonglong offset, FILE *ofp) { struct vmcoredd_header *vh = (struct vmcoredd_header *)_note; char buf[BUFSIZE]; ulong dump_size; if (vh->n_type != NT_VMCOREDD) return; dump_size = vh->n_descsz - VMCOREDD_MAX_NAME_BYTES; offset += sizeof(struct vmcoredd_header); fprintf(ofp, "0x%s ", mkstring(buf, LONG_LONG_PRLEN, LJUST | LONGLONG_HEX, MKSTR(&offset))); fprintf(ofp, "%s ", mkstring(buf, LONG_PRLEN, LJUST | LONG_DEC, MKSTR(dump_size))); fprintf(ofp, "%s\n", vh->dump_name); } crash-utility-crash-61fe107/diskdump.c000066400000000000000000002651471517256214500177570ustar00rootroot00000000000000/* * diskdump.c * * The diskdump module optionally creates either ELF vmcore * dumpfiles, or compressed dumpfiles derived from the LKCD format. * In the case of ELF vmcore files, since they are identical to * netdump dumpfiles, the facilities in netdump.c are used. For * compressed dumpfiles, the facilities in this file are used. * * Copyright (C) 2004-2015 David Anderson * Copyright (C) 2004-2015 Red Hat, Inc. All rights reserved. * Copyright (C) 2005 FUJITSU LIMITED * Copyright (C) 2005 NEC Corporation * * 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 2 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. */ #include "defs.h" #include "diskdump.h" #include "xen_dom0.h" #include "vmcore.h" #include "maple_tree.h" #include "lzorle_decompress.h" #define BITMAP_SECT_LEN 4096 struct diskdump_data { char *filename; ulong flags; /* DISKDUMP_LOCAL, plus anything else... */ int dfd; /* dumpfile file descriptor */ FILE *ofp; /* fprintf(dd->ofp, "xxx"); */ int machine_type; /* machine type identifier */ /* header */ struct disk_dump_header *header; struct disk_dump_sub_header *sub_header; struct kdump_sub_header *sub_header_kdump; unsigned long long max_mapnr; /* 64bit max_mapnr */ size_t data_offset; int block_size; int block_shift; char *bitmap; off_t bitmap_len; char *dumpable_bitmap; int byte, bit; char *compressed_page; /* copy of compressed page data */ char *curbufptr; /* ptr to uncompressed page buffer */ unsigned char *notes_buf; /* copy of elf notes */ void **nt_prstatus_percpu; uint num_prstatus_notes; void **nt_qemu_percpu; void **nt_qemucs_percpu; uint num_qemu_notes; void **nt_vmcoredd_array; uint num_vmcoredd_notes; /* page cache */ struct page_cache_hdr { /* header for each cached page */ uint32_t pg_flags; uint64_t pg_addr; char *pg_bufptr; ulong pg_hit_count; } page_cache_hdr[DISKDUMP_CACHED_PAGES]; char *page_cache_buf; /* base of cached buffer pages */ int evict_index; /* next page to evict */ ulong evictions; /* total evictions done */ ulong cached_reads; ulong *valid_pages; int max_sect_len; /* highest bucket of valid_pages */ ulong accesses; ulong snapshot_task; }; static struct diskdump_data diskdump_data = { 0 }; static struct diskdump_data *dd = &diskdump_data; ulong *diskdump_flags = &diskdump_data.flags; static int __diskdump_memory_dump(FILE *); static void dump_vmcoreinfo(FILE *); static void dump_note_offsets(FILE *); static char *vmcoreinfo_read_string(const char *); static void diskdump_get_osrelease(void); static void diskdump_get_build_id(void); static int valid_note_address(unsigned char *); /* For split dumpfile */ static struct diskdump_data **dd_list = NULL; static int num_dd = 0; static int num_dumpfiles = 0; int dumpfile_is_split(void) { return KDUMP_SPLIT(); } int have_crash_notes(int cpu) { ulong crash_notes, notes_ptr; char *buf, *p; Elf64_Nhdr *note = NULL; if (!readmem(symbol_value("crash_notes"), KVADDR, &crash_notes, sizeof(crash_notes), "crash_notes", RETURN_ON_ERROR)) { error(WARNING, "cannot read \"crash_notes\"\n"); return FALSE; } if ((kt->flags & SMP) && (kt->flags & PER_CPU_OFF)) notes_ptr = crash_notes + kt->__per_cpu_offset[cpu]; else notes_ptr = crash_notes; buf = GETBUF(SIZE(note_buf)); if (!readmem(notes_ptr, KVADDR, buf, SIZE(note_buf), "note_buf_t", RETURN_ON_ERROR)) { error(WARNING, "cpu %d: cannot read NT_PRSTATUS note\n", cpu); return FALSE; } note = (Elf64_Nhdr *)buf; p = buf + sizeof(Elf64_Nhdr); if (note->n_type != NT_PRSTATUS) { error(WARNING, "cpu %d: invalid NT_PRSTATUS note (n_type != NT_PRSTATUS)\n", cpu); return FALSE; } if (!STRNEQ(p, "CORE")) { error(WARNING, "cpu %d: invalid NT_PRSTATUS note (name != \"CORE\")\n", cpu); return FALSE; } return TRUE; } int diskdump_is_cpu_prstatus_valid(int cpu) { static int crash_notes_exists = -1; if (crash_notes_exists == -1) crash_notes_exists = kernel_symbol_exists("crash_notes"); return (!crash_notes_exists || have_crash_notes(cpu)); } void map_cpus_to_prstatus_kdump_cmprs(void) { void **nt_ptr; int online, i, j, nrcpus; size_t size; if (pc->flags2 & QEMU_MEM_DUMP_COMPRESSED) /* notes exist for all cpus */ goto resize_note_pointers; if (!(online = get_cpus_online()) || (online == kt->cpus)) goto resize_note_pointers; if (CRASHDEBUG(1)) error(INFO, "cpus: %d online: %d NT_PRSTATUS notes: %d (remapping)\n", kt->cpus, online, dd->num_prstatus_notes); size = NR_CPUS * sizeof(void *); nt_ptr = (void **)GETBUF(size); BCOPY(dd->nt_prstatus_percpu, nt_ptr, size); BZERO(dd->nt_prstatus_percpu, size); /* * Re-populate the array with the notes mapping to present cpus */ nrcpus = (kt->kernel_NR_CPUS ? kt->kernel_NR_CPUS : NR_CPUS); for (i = 0, j = 0; i < nrcpus; i++) { if (in_cpu_map(PRESENT_MAP, i) && machdep->is_cpu_prstatus_valid(i)) { dd->nt_prstatus_percpu[i] = nt_ptr[j++]; dd->num_prstatus_notes = MAX(dd->num_prstatus_notes, i+1); } } FREEBUF(nt_ptr); resize_note_pointers: /* * For architectures that only utilize the note pointers * within this file, resize the arrays accordingly. */ if (machine_type("X86_64") || machine_type("X86") || machine_type("ARM64")) { if ((dd->nt_prstatus_percpu = realloc(dd->nt_prstatus_percpu, dd->num_prstatus_notes * sizeof(void *))) == NULL) error(FATAL, "compressed kdump: cannot realloc NT_PRSTATUS note pointers\n"); if (dd->num_qemu_notes) { if ((dd->nt_qemu_percpu = realloc(dd->nt_qemu_percpu, dd->num_qemu_notes * sizeof(void *))) == NULL) error(FATAL, "compressed kdump: cannot realloc QEMU note pointers\n"); if ((dd->nt_qemucs_percpu = realloc(dd->nt_qemucs_percpu, dd->num_qemu_notes * sizeof(void *))) == NULL) error(FATAL, "compressed kdump: cannot realloc QEMU note pointers\n"); } else { free(dd->nt_qemu_percpu); free(dd->nt_qemucs_percpu); } } } static void add_diskdump_data(char* name) { #define DDL_SIZE 16 int i; int sz = sizeof(void *); struct diskdump_data *ddp; if (dd_list == NULL) { dd_list = calloc(DDL_SIZE, sz); num_dd = DDL_SIZE; } else { for (i = 0; i < num_dumpfiles; i++) { ddp = dd_list[i]; if (same_file(ddp->filename, name)) error(FATAL, "split dumpfiles are identical:\n" " %s\n %s\n", ddp->filename, name); if (memcmp(ddp->header, dd->header, sizeof(struct disk_dump_header))) error(FATAL, "split dumpfiles derived from different vmcores:\n" " %s\n %s\n", ddp->filename, name); } } if (num_dumpfiles == num_dd) { /* expand list */ struct diskdump_data **tmp; tmp = calloc(num_dd*2, sz); memcpy(tmp, dd_list, sz*num_dd); free(dd_list); dd_list = tmp; num_dd *= 2; } dd_list[num_dumpfiles] = dd; dd->flags |= DUMPFILE_SPLIT; dd->filename = name; if (CRASHDEBUG(1)) fprintf(fp, "%s: start_pfn=%llu, end_pfn=%llu\n", name, dd->sub_header_kdump->start_pfn_64, dd->sub_header_kdump->end_pfn_64); } static void clean_diskdump_data(void) { int i; if (dd_list == NULL) return; for (i=1; ibitmap, nr >> 3, nr & 7); } static inline int page_is_dumpable(unsigned long nr) { return dd->dumpable_bitmap[nr>>3] & (1 << (nr & 7)); } static inline int dump_is_partial(const struct disk_dump_header *header) { return header->bitmap_blocks >= divideup(divideup(dd->max_mapnr, 8), dd->block_size) * 2; } static int open_dump_file(char *file) { int fd; fd = open(file, O_RDONLY); if (fd < 0) { error(INFO, "diskdump / compressed kdump: unable to open dump file %s\n", file); return FALSE; } if (KDUMP_SPLIT()) dd = calloc(1, sizeof(*dd)); dd->dfd = fd; return TRUE; } void process_elf32_notes(void *note_buf, unsigned long size_note) { Elf32_Nhdr *nt; size_t index, len = 0; int num = 0; int vmcoredd_num = 0; int qemu_num = 0; for (index = 0; index < size_note; index += len) { nt = note_buf + index; if (nt->n_type == NT_PRSTATUS) { dd->nt_prstatus_percpu[num] = nt; num++; } len = sizeof(Elf32_Nhdr); if (STRNEQ((char *)nt + len, "QEMU")) { ulong *ptr = (ulong *)((char *)nt + sizeof(Elf32_Nhdr) + nt->n_namesz); dd->nt_qemucs_percpu[qemu_num] = (ulong *)roundup((ulong) ptr, 4); dd->nt_qemu_percpu[qemu_num] = nt; qemu_num++; } if (nt->n_type == NT_XEN_KDUMP_CR3 || nt->n_type == XEN_ELFNOTE_CRASH_INFO) { void *data = (char*)(nt + 1) + roundup(nt->n_namesz, 4); process_xen_note(nt->n_type, data, nt->n_descsz); } if (nt->n_type == NT_VMCOREDD && vmcoredd_num < NR_DEVICE_DUMPS) { dd->nt_vmcoredd_array[vmcoredd_num] = nt; vmcoredd_num++; } len = roundup(len + nt->n_namesz, 4); len = roundup(len + nt->n_descsz, 4); } if (num > 0) { pc->flags2 |= ELF_NOTES; dd->num_prstatus_notes = num; } if (qemu_num > 0) { pc->flags2 |= QEMU_MEM_DUMP_COMPRESSED; dd->num_qemu_notes = qemu_num; } if (vmcoredd_num > 0) dd->num_vmcoredd_notes = vmcoredd_num; return; } void process_elf64_notes(void *note_buf, unsigned long size_note) { Elf64_Nhdr *nt; size_t index, len = 0; int num = 0; int vmcoredd_num = 0; int qemu_num = 0; for (index = 0; index < size_note; index += len) { nt = note_buf + index; if (nt->n_type == NT_PRSTATUS) { dd->nt_prstatus_percpu[num] = nt; num++; } if ((nt->n_type == NT_TASKSTRUCT) && (STRNEQ((char *)nt + sizeof(Elf64_Nhdr), "SNAP"))) { pc->flags2 |= (LIVE_DUMP|SNAP); dd->snapshot_task = *((ulong *)((char *)nt + sizeof(Elf64_Nhdr) + nt->n_namesz)); } len = sizeof(Elf64_Nhdr); if (STRNEQ((char *)nt + len, "QEMU")) { ulong *ptr = (ulong *)((char *)nt + sizeof(Elf64_Nhdr) + nt->n_namesz); dd->nt_qemucs_percpu[qemu_num] = (ulong *)roundup((ulong) ptr, 4); dd->nt_qemu_percpu[qemu_num] = nt; qemu_num++; } if (nt->n_type == NT_XEN_KDUMP_CR3 || nt->n_type == XEN_ELFNOTE_CRASH_INFO) { void *data = (char*)(nt + 1) + roundup(nt->n_namesz, 4); process_xen_note(nt->n_type, data, nt->n_descsz); } if (nt->n_type == NT_VMCOREDD && vmcoredd_num < NR_DEVICE_DUMPS) { dd->nt_vmcoredd_array[vmcoredd_num] = nt; vmcoredd_num++; } len = roundup(len + nt->n_namesz, 4); len = roundup(len + nt->n_descsz, 4); } if (num > 0) { pc->flags2 |= ELF_NOTES; dd->num_prstatus_notes = num; } if (qemu_num > 0) { pc->flags2 |= QEMU_MEM_DUMP_COMPRESSED; dd->num_qemu_notes = qemu_num; } if (vmcoredd_num > 0) dd->num_vmcoredd_notes = vmcoredd_num; return; } void x86_process_elf_notes(void *note_ptr, unsigned long size_note) { if (machine_type("X86_64")) process_elf64_notes(note_ptr, size_note); else if (machine_type("X86")) process_elf32_notes(note_ptr, size_note); } #if defined(__i386__) && (defined(ARM) || defined(MIPS)) /* * The kdump_sub_header member offsets are different when the crash * binary is built natively on an ARM host vs. when built with * "make target=ARM" on an x86/x86_64 host. This is because the * off_t structure members will be aligned on an 8-byte boundary when * compiled as an ARM binary -- which will be reflected in the * kdump_sub_header in a compressed ARM kdump. * * When crash is compiled as an x86 binary, these are the * structure's offsets: * * struct kdump_sub_header { * [0] unsigned long phys_base; * [4] int dump_level; / header_version 1 and later / * [8] int split; / header_version 2 and later / * [12] unsigned long start_pfn; / header_version 2 and later / * [16] unsigned long end_pfn; / header_version 2 and later / * [20] off_t offset_vmcoreinfo; / header_version 3 and later / * [28] unsigned long size_vmcoreinfo; / header_version 3 and later / * [32] off_t offset_note; / header_version 4 and later / * [40] unsigned long size_note; / header_version 4 and later / * [44] off_t offset_eraseinfo; / header_version 5 and later / * [52] unsigned long size_eraseinfo; / header_version 5 and later / * [56] unsigned long long start_pfn_64; / header_version 6 and later / * [64] unsigned long long end_pfn_64; / header_version 6 and later / * [72] unsigned long long max_mapnr_64; / header_version 6 and later / * }; * * But when compiled on an ARM processor, each 64-bit "off_t" would be pushed * up to an 8-byte boundary: * * struct kdump_sub_header { * [0] unsigned long phys_base; * [4] int dump_level; / header_version 1 and later / * [8] int split; / header_version 2 and later / * [12] unsigned long start_pfn; / header_version 2 and later / * [16] unsigned long end_pfn; / header_version 2 and later / * [24] off_t offset_vmcoreinfo; / header_version 3 and later / * [32] unsigned long size_vmcoreinfo; / header_version 3 and later / * [40] off_t offset_note; / header_version 4 and later / * [48] unsigned long size_note; / header_version 4 and later / * [56] off_t offset_eraseinfo; / header_version 5 and later / * [64] unsigned long size_eraseinfo; / header_version 5 and later / * [72] unsigned long long start_pfn_64; / header_version 6 and later / * [80] unsigned long long end_pfn_64; / header_version 6 and later / * [88] unsigned long long max_mapnr_64; / header_version 6 and later / * }; * */ struct kdump_sub_header_ARM_target { unsigned long phys_base; int dump_level; /* header_version 1 and later */ int split; /* header_version 2 and later */ unsigned long start_pfn; /* header_version 2 and later */ unsigned long end_pfn; /* header_version 2 and later */ int pad1; off_t offset_vmcoreinfo; /* header_version 3 and later */ unsigned long size_vmcoreinfo; /* header_version 3 and later */ int pad2; off_t offset_note; /* header_version 4 and later */ unsigned long size_note; /* header_version 4 and later */ int pad3; off_t offset_eraseinfo; /* header_version 5 and later */ unsigned long size_eraseinfo; /* header_version 5 and later */ int pad4; unsigned long long start_pfn_64; /* header_version 6 and later */ unsigned long long end_pfn_64; /* header_version 6 and later */ unsigned long long max_mapnr_64; /* header_version 6 and later */ }; static void arm_kdump_header_adjust(int header_version) { struct kdump_sub_header *kdsh; struct kdump_sub_header_ARM_target *kdsh_ARM_target; kdsh = dd->sub_header_kdump; kdsh_ARM_target = (struct kdump_sub_header_ARM_target *)kdsh; if (header_version >= 3) { kdsh->offset_vmcoreinfo = kdsh_ARM_target->offset_vmcoreinfo; kdsh->size_vmcoreinfo = kdsh_ARM_target->size_vmcoreinfo; } if (header_version >= 4) { kdsh->offset_note = kdsh_ARM_target->offset_note; kdsh->size_note = kdsh_ARM_target->size_note; } if (header_version >= 5) { kdsh->offset_eraseinfo = kdsh_ARM_target->offset_eraseinfo; kdsh->size_eraseinfo = kdsh_ARM_target->size_eraseinfo; } if (header_version >= 6) { kdsh->start_pfn_64 = kdsh_ARM_target->start_pfn_64; kdsh->end_pfn_64 = kdsh_ARM_target->end_pfn_64; kdsh->max_mapnr_64 = kdsh_ARM_target->max_mapnr_64; } else { kdsh->start_pfn_64 = kdsh_ARM_target->start_pfn; kdsh->end_pfn_64 = kdsh_ARM_target->end_pfn; kdsh->max_mapnr_64 = dd->max_mapnr; } } #endif /* __i386__ && (ARM || MIPS) */ /* * Read page descriptor. */ static int read_pd(int fd, off_t offset, page_desc_t *pd) { int ret; if (FLAT_FORMAT()) { if (!read_flattened_format(fd, offset, pd, sizeof(*pd))) return READ_ERROR; } else { if (offset < 0) { if (CRASHDEBUG(8)) fprintf(fp, "read_pd: invalid offset: %lx\n", offset); return SEEK_ERROR; } if ((ret = pread(fd, pd, sizeof(*pd), offset)) != sizeof(*pd)) { if (ret == -1 && CRASHDEBUG(8)) fprintf(fp, "read_pd: pread error: %s\n", strerror(errno)); return READ_ERROR; } } return 0; } static int read_dump_header(char *file) { struct disk_dump_header *header = NULL; struct disk_dump_sub_header *sub_header = NULL; struct kdump_sub_header *sub_header_kdump = NULL; size_t size; off_t bitmap_len; int block_size = (int)sysconf(_SC_PAGESIZE); off_t offset; const off_t failed = (off_t)-1; ulong pfn; int i, j, max_sect_len; int is_split = 0; ulonglong tmp, *bitmap; if (block_size < 0) return FALSE; restart: if ((header = realloc(header, block_size)) == NULL) error(FATAL, "diskdump / compressed kdump: cannot malloc block_size buffer\n"); if (FLAT_FORMAT()) { if (!read_flattened_format(dd->dfd, 0, header, block_size)) { error(FATAL, "diskdump / compressed kdump: cannot read header\n"); goto err; } } else { if (lseek(dd->dfd, 0, SEEK_SET) == failed) { if (CRASHDEBUG(1)) error(INFO, "diskdump / compressed kdump: cannot lseek dump header\n"); goto err; } if (read(dd->dfd, header, block_size) < block_size) { if (CRASHDEBUG(1)) error(INFO, "diskdump / compressed kdump: cannot read dump header\n"); goto err; } } /* validate dump header */ if (!memcmp(header->signature, DISK_DUMP_SIGNATURE, sizeof(header->signature))) { dd->flags |= DISKDUMP_LOCAL; } else if (!memcmp(header->signature, KDUMP_SIGNATURE, sizeof(header->signature))) { dd->flags |= KDUMP_CMPRS_LOCAL; if (header->header_version >= 1) dd->flags |= ERROR_EXCLUDED; } else { if (CRASHDEBUG(1)) error(INFO, "diskdump / compressed kdump: dump does not have panic dump header\n"); goto err; } if (CRASHDEBUG(1)) fprintf(fp, "%s: header->utsname.machine: %s\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump", header->utsname.machine); if (STRNEQ(header->utsname.machine, "i686") && machine_type_mismatch(file, "X86", NULL, 0)) goto err; else if (STRNEQ(header->utsname.machine, "x86_64") && machine_type_mismatch(file, "X86_64", NULL, 0)) goto err; else if (STRNEQ(header->utsname.machine, "ia64") && machine_type_mismatch(file, "IA64", NULL, 0)) goto err; else if (STREQ(header->utsname.machine, "ppc") && machine_type_mismatch(file, "PPC", NULL, 0)) goto err; else if (STRNEQ(header->utsname.machine, "ppc64") && machine_type_mismatch(file, "PPC64", NULL, 0)) goto err; else if (STRNEQ(header->utsname.machine, "arm") && machine_type_mismatch(file, "ARM", NULL, 0)) goto err; else if (STREQ(header->utsname.machine, "mips") && machine_type_mismatch(file, "MIPS", NULL, 0)) goto err; else if (STRNEQ(header->utsname.machine, "mips64") && machine_type_mismatch(file, "MIPS64", NULL, 0)) goto err; else if (STRNEQ(header->utsname.machine, "s390x") && machine_type_mismatch(file, "S390X", NULL, 0)) goto err; else if (STRNEQ(header->utsname.machine, "aarch64") && machine_type_mismatch(file, "ARM64", NULL, 0)) goto err; else if (STRNEQ(header->utsname.machine, "riscv64") && machine_type_mismatch(file, "RISCV64", NULL, 0)) goto err; else if (STRNEQ(header->utsname.machine, "loongarch64") && machine_type_mismatch(file, "LOONGARCH64", NULL, 0)) goto err; if (header->block_size != block_size) { block_size = header->block_size; if (CRASHDEBUG(1)) fprintf(fp, "retrying with different block/page size: %d\n", header->block_size); goto restart; } dd->block_size = header->block_size; dd->block_shift = ffs(header->block_size) - 1; if ((DISKDUMP_VALID() && (sizeof(*header) + sizeof(void *) * header->nr_cpus > block_size)) || header->nr_cpus <= 0) { error(WARNING, "%s: invalid nr_cpus value: %d\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump", header->nr_cpus); if (!machine_type("S390") && !machine_type("S390X") && !machine_type("X86") && !machine_type("X86_64")) { if (DISKDUMP_VALID()) goto err; } } /* read sub header */ offset = (off_t)block_size; if (DISKDUMP_VALID()) { if ((sub_header = malloc(block_size)) == NULL) error(FATAL, "diskdump: cannot malloc sub_header buffer\n"); if (FLAT_FORMAT()) { if (!read_flattened_format(dd->dfd, offset, sub_header, block_size)) { error(INFO, "diskdump: cannot read dump sub header\n"); goto err; } } else { if (lseek(dd->dfd, offset, SEEK_SET) == failed) { error(INFO, "diskdump: cannot lseek dump sub header\n"); goto err; } if (read(dd->dfd, sub_header, block_size) < block_size) { error(INFO, "diskdump: cannot read dump sub header\n"); goto err; } } dd->sub_header = sub_header; /* the 64bit max_mapnr only exists in sub-header of compressed * kdump file, if it's not a compressed kdump file, we have to * use the old 32bit max_mapnr in dumpfile header. * max_mapnr may be truncated here. */ dd->max_mapnr = header->max_mapnr; } else if (KDUMP_CMPRS_VALID()) { if ((sub_header_kdump = malloc(block_size)) == NULL) error(FATAL, "compressed kdump: cannot malloc sub_header_kdump buffer\n"); if (FLAT_FORMAT()) { if (!read_flattened_format(dd->dfd, offset, sub_header_kdump, block_size)) { error(INFO, "compressed kdump: cannot read dump sub header\n"); goto err; } } else { if (lseek(dd->dfd, offset, SEEK_SET) == failed) { error(INFO, "compressed kdump: cannot lseek dump sub header\n"); goto err; } if (read(dd->dfd, sub_header_kdump, block_size) < block_size) { error(INFO, "compressed kdump: cannot read dump sub header\n"); goto err; } } dd->sub_header_kdump = sub_header_kdump; #if defined(__i386__) && (defined(ARM) || defined(MIPS)) arm_kdump_header_adjust(header->header_version); #endif /* use 64bit max_mapnr in compressed kdump file sub-header */ if (header->header_version >= 6) dd->max_mapnr = dd->sub_header_kdump->max_mapnr_64; else { dd->sub_header_kdump->start_pfn_64 = dd->sub_header_kdump->start_pfn; dd->sub_header_kdump->end_pfn_64 = dd->sub_header_kdump->end_pfn; } } if (header->header_version < 6) dd->max_mapnr = header->max_mapnr; /* read memory bitmap */ bitmap_len = (off_t)block_size * header->bitmap_blocks; dd->bitmap_len = bitmap_len; offset = (off_t)block_size * (1 + header->sub_hdr_size); dd->dumpable_bitmap = calloc(bitmap_len, 1); if (CRASHDEBUG(8)) fprintf(fp, "%s: memory bitmap offset: %llx\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump", (ulonglong)offset); if (FLAT_FORMAT()) { if ((dd->bitmap = malloc(bitmap_len)) == NULL) error(FATAL, "%s: cannot malloc bitmap buffer\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); if (!read_flattened_format(dd->dfd, offset, dd->bitmap, bitmap_len)) { error(INFO, "%s: cannot read memory bitmap\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); goto err; } } else { struct stat sbuf; if (fstat(dd->dfd, &sbuf) != 0) { error(INFO, "Cannot fstat the dump file\n"); goto err; } /* * For memory regions mapped with the mmap(), attempts access to * a page of the buffer that lies beyond the end of the mapped file, * which may cause SIGBUS(see the mmap() man page). */ if (bitmap_len + offset > sbuf.st_size) { error(INFO, "Mmap: Beyond the end of mapped file, corrupted?\n"); goto err; } dd->bitmap = mmap(NULL, bitmap_len, PROT_READ, MAP_SHARED, dd->dfd, offset); if (dd->bitmap == MAP_FAILED) error(FATAL, "%s: cannot mmap bitmap buffer\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); madvise(dd->bitmap, bitmap_len, MADV_WILLNEED); } if (dump_is_partial(header)) memcpy(dd->dumpable_bitmap, dd->bitmap + bitmap_len/2, bitmap_len/2); else memcpy(dd->dumpable_bitmap, dd->bitmap, bitmap_len); dd->data_offset = (1UL + header->sub_hdr_size + header->bitmap_blocks) * header->block_size; dd->header = header; if (machine_type("ARM")) dd->machine_type = EM_ARM; else if (machine_type("MIPS") || machine_type("MIPS64")) dd->machine_type = EM_MIPS; else if (machine_type("X86")) dd->machine_type = EM_386; else if (machine_type("X86_64")) dd->machine_type = EM_X86_64; else if (machine_type("IA64")) dd->machine_type = EM_IA_64; else if (machine_type("PPC")) dd->machine_type = EM_PPC; else if (machine_type("PPC64")) dd->machine_type = EM_PPC64; else if (machine_type("S390X")) dd->machine_type = EM_S390; else if (machine_type("ARM64")) dd->machine_type = EM_AARCH64; else if (machine_type("SPARC64")) dd->machine_type = EM_SPARCV9; else if (machine_type("RISCV64")) dd->machine_type = EM_RISCV; else if (machine_type("LOONGARCH64")) dd->machine_type = EM_LOONGARCH; else { error(INFO, "%s: unsupported machine type: %s\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump", MACHINE_TYPE); goto err; } /* process elf notes data */ if (KDUMP_CMPRS_VALID() && !(dd->flags & NO_ELF_NOTES) && (dd->header->header_version >= 4) && (sub_header_kdump->offset_note) && (sub_header_kdump->size_note) && (machdep->process_elf_notes)) { size = sub_header_kdump->size_note; offset = sub_header_kdump->offset_note; if ((dd->notes_buf = malloc(size)) == NULL) error(FATAL, "compressed kdump: cannot malloc notes" " buffer\n"); if ((dd->nt_prstatus_percpu = malloc(NR_CPUS * sizeof(void *))) == NULL) error(FATAL, "compressed kdump: cannot malloc pointer" " to NT_PRSTATUS notes\n"); if ((dd->nt_qemu_percpu = malloc(NR_CPUS * sizeof(void *))) == NULL) error(FATAL, "qemu mem dump compressed: cannot malloc pointer" " to QEMU notes\n"); if ((dd->nt_qemucs_percpu = malloc(NR_CPUS * sizeof(void *))) == NULL) error(FATAL, "qemu mem dump compressed: cannot malloc pointer" " to QEMUCS notes\n"); if ((dd->nt_vmcoredd_array = malloc(NR_DEVICE_DUMPS * sizeof(void *))) == NULL) error(FATAL, "compressed kdump: cannot malloc array for " "vmcore device dump notes\n"); if (FLAT_FORMAT()) { if (!read_flattened_format(dd->dfd, offset, dd->notes_buf, size)) { error(INFO, "compressed kdump: cannot read notes data" "\n"); goto err; } } else { if (lseek(dd->dfd, offset, SEEK_SET) == failed) { error(INFO, "compressed kdump: cannot lseek notes data\n"); goto err; } if (read(dd->dfd, dd->notes_buf, size) < size) { error(INFO, "compressed kdump: cannot read notes data" "\n"); goto err; } } machdep->process_elf_notes(dd->notes_buf, size); } /* Check if dump file contains erasesinfo data */ if (KDUMP_CMPRS_VALID() && (dd->header->header_version >= 5) && (sub_header_kdump->offset_eraseinfo) && (sub_header_kdump->size_eraseinfo)) pc->flags2 |= ERASEINFO_DATA; if (KDUMP_CMPRS_VALID() && (dd->header->header_version >= 3) && dd->sub_header_kdump->offset_vmcoreinfo && dd->sub_header_kdump->size_vmcoreinfo) pc->flags2 |= VMCOREINFO; if (KDUMP_CMPRS_VALID() && (dd->header->status & DUMP_DH_COMPRESSED_INCOMPLETE)) pc->flags2 |= INCOMPLETE_DUMP; if (KDUMP_CMPRS_VALID() && (dd->header->status & DUMP_DH_EXCLUDED_VMEMMAP)) pc->flags2 |= EXCLUDED_VMEMMAP; /* For split dumpfile */ if (KDUMP_CMPRS_VALID()) { is_split = ((dd->header->header_version >= 2) && (sub_header_kdump->split)); if ((is_split && (num_dumpfiles != 0) && (dd_list == NULL))|| (!is_split && (num_dumpfiles != 0))) { clean_diskdump_data(); goto err; } if (is_split) add_diskdump_data(file); num_dumpfiles++; } if (!is_split) { max_sect_len = divideup(dd->max_mapnr, BITMAP_SECT_LEN); pfn = 0; dd->filename = file; } else { unsigned long long start = sub_header_kdump->start_pfn_64; unsigned long long end = sub_header_kdump->end_pfn_64; max_sect_len = divideup(end - start + 1, BITMAP_SECT_LEN); pfn = start; } dd->valid_pages = calloc(sizeof(ulong), max_sect_len + 1); dd->max_sect_len = max_sect_len; /* It is safe to convert it to (ulonglong *). */ bitmap = (ulonglong *)dd->dumpable_bitmap; for (i = 1; i < max_sect_len + 1; i++) { dd->valid_pages[i] = dd->valid_pages[i - 1]; for (j = 0; j < BITMAP_SECT_LEN; j += 64, pfn += 64) { tmp = bitmap[pfn >> 6]; if (tmp) dd->valid_pages[i] += hweight64(tmp); } } return TRUE; err: free(header); if (sub_header) free(sub_header); if (sub_header_kdump) free(sub_header_kdump); if (dd->bitmap) { if (FLAT_FORMAT()) free(dd->bitmap); else munmap(dd->bitmap, dd->bitmap_len); } if (dd->dumpable_bitmap) free(dd->dumpable_bitmap); if (dd->notes_buf) free(dd->notes_buf); if (dd->nt_prstatus_percpu) free(dd->nt_prstatus_percpu); if (dd->nt_qemu_percpu) free(dd->nt_qemu_percpu); if (dd->nt_qemucs_percpu) free(dd->nt_qemucs_percpu); if (dd->nt_vmcoredd_array) free(dd->nt_vmcoredd_array); dd->flags &= ~(DISKDUMP_LOCAL|KDUMP_CMPRS_LOCAL); pc->flags2 &= ~ELF_NOTES; return FALSE; } static ulong pfn_to_pos(ulong pfn) { ulong desc_pos, j, valid; ulong p1, p2; if (KDUMP_SPLIT()) { p1 = pfn - dd->sub_header_kdump->start_pfn_64; p2 = round(p1, BITMAP_SECT_LEN) + dd->sub_header_kdump->start_pfn_64; } else { p1 = pfn; p2 = round(pfn, BITMAP_SECT_LEN); } valid = dd->valid_pages[p1 / BITMAP_SECT_LEN]; for (j = p2, desc_pos = valid; j <= pfn; j++) if (page_is_dumpable(j)) desc_pos++; return desc_pos; } /* * Determine whether a file is a diskdump creation, and if TRUE, * initialize the diskdump_data structure based upon the contents * of the diskdump header data. */ int is_diskdump(char *file) { int sz, i; if (!open_dump_file(file) || !read_dump_header(file)) return FALSE; sz = dd->block_size * (DISKDUMP_CACHED_PAGES); if ((dd->page_cache_buf = malloc(sz)) == NULL) error(FATAL, "%s: cannot malloc compressed page_cache_buf\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); for (i = 0; i < DISKDUMP_CACHED_PAGES; i++) dd->page_cache_hdr[i].pg_bufptr = &dd->page_cache_buf[i * dd->block_size]; if ((dd->compressed_page = (char *)malloc(dd->block_size)) == NULL) error(FATAL, "%s: cannot malloc compressed page space\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); if (CRASHDEBUG(1)) __diskdump_memory_dump(fp); if (pc->flags2 & GET_OSRELEASE) diskdump_get_osrelease(); if (pc->flags2 & GET_BUILD_ID) diskdump_get_build_id(); #ifdef LZO if (lzo_init() == LZO_E_OK) dd->flags |= LZO_SUPPORTED; #endif #ifdef SNAPPY dd->flags |= SNAPPY_SUPPORTED; #endif #ifdef ZSTD dd->flags |= ZSTD_SUPPORTED; #endif pc->read_vmcoreinfo = vmcoreinfo_read_string; if ((pc->flags2 & GET_LOG) && KDUMP_CMPRS_VALID()) { pc->dfd = dd->dfd; pc->readmem = read_diskdump; pc->flags |= DISKDUMP; get_log_from_vmcoreinfo(file); } return TRUE; } /* * Perform any post-dumpfile determination stuff here. * At a minimum */ int diskdump_init(char *unused, FILE *fptr) { if (!DISKDUMP_VALID() && !KDUMP_CMPRS_VALID()) return FALSE; machdep->is_cpu_prstatus_valid = diskdump_is_cpu_prstatus_valid; dd->ofp = fptr; return TRUE; } /* * Get the relocational offset from the sub header of kdump. */ int diskdump_phys_base(unsigned long *phys_base) { if (KDUMP_CMPRS_VALID()) { *phys_base = dd->sub_header_kdump->phys_base; return TRUE; } return FALSE; } int diskdump_set_phys_base(unsigned long phys_base) { if (diskdump_kaslr_check()) { dd->sub_header_kdump->phys_base = phys_base; return TRUE; } return FALSE; } /* * Check whether paddr is already cached. */ static int page_is_cached(physaddr_t paddr) { int i; struct page_cache_hdr *pgc; dd->accesses++; for (i = 0; i < DISKDUMP_CACHED_PAGES; i++) { pgc = &dd->page_cache_hdr[i]; if (!DISKDUMP_VALID_PAGE(pgc->pg_flags)) continue; if (pgc->pg_addr == paddr) { pgc->pg_hit_count++; dd->curbufptr = pgc->pg_bufptr; dd->cached_reads++; return TRUE; } } return FALSE; } /* * Translate physical address in paddr to PFN number. This means normally that * we just shift paddr by some constant. Some architectures need special * handling for this, however. */ static ulong paddr_to_pfn(physaddr_t paddr) { #ifdef ARM /* * In ARM, PFN 0 means first page in kernel direct-mapped view. * This is also first page in mem_map as well. */ return (paddr - machdep->machspec->phys_base) >> dd->block_shift; #else return paddr >> dd->block_shift; #endif } /* * Cache the page's data. * * If an empty page cache location is available, take it. Otherwise, evict * the entry indexed by evict_index, and then bump evict index. The hit_count * is only gathered for dump_diskdump_environment(). * * If the page is compressed, uncompress it into the selected page cache entry. * If the page is raw, just copy it into the selected page cache entry. * If all works OK, update diskdump->curbufptr to point to the page's * uncompressed data. */ static int cache_page(physaddr_t paddr) { int i, ret; int found; ulong pfn; ulong desc_pos; off_t seek_offset; page_desc_t pd; const int block_size = dd->block_size; ulong retlen; #ifdef ZSTD static ZSTD_DCtx *dctx = NULL; #endif for (i = found = 0; i < DISKDUMP_CACHED_PAGES; i++) { if (DISKDUMP_VALID_PAGE(dd->page_cache_hdr[i].pg_flags)) continue; found = TRUE; break; } if (!found) { i = dd->evict_index; dd->page_cache_hdr[i].pg_hit_count = 0; dd->evict_index = (dd->evict_index+1) % DISKDUMP_CACHED_PAGES; dd->evictions++; } dd->page_cache_hdr[i].pg_flags = 0; dd->page_cache_hdr[i].pg_addr = paddr; dd->page_cache_hdr[i].pg_hit_count++; /* find page descriptor */ pfn = paddr_to_pfn(paddr); desc_pos = pfn_to_pos(pfn); seek_offset = dd->data_offset + (off_t)(desc_pos - 1)*sizeof(page_desc_t); /* read page descriptor */ ret = read_pd(dd->dfd, seek_offset, &pd); if (ret) return ret; /* sanity check */ if (pd.size > block_size) return READ_ERROR; /* read page data */ if (FLAT_FORMAT()) { if (!read_flattened_format(dd->dfd, pd.offset, dd->compressed_page, pd.size)) return READ_ERROR; } else if (0 == pd.offset) { /* * First check whether zero_excluded has been set. */ if (*diskdump_flags & ZERO_EXCLUDED) { if (CRASHDEBUG(8)) fprintf(fp, "read_diskdump/cache_page: zero-fill: " "paddr/pfn: %llx/%lx\n", (ulonglong)paddr, pfn); memset(dd->compressed_page, 0, dd->block_size); } else { if (CRASHDEBUG(8)) fprintf(fp, "read_diskdump/cache_page: " "descriptor with zero offset found at " "paddr/pfn/pos: %llx/%lx/%lx\n", (ulonglong)paddr, pfn, desc_pos); return PAGE_INCOMPLETE; } } else { if (pd.offset < 0) { if (CRASHDEBUG(8)) fprintf(fp, "read_diskdump/cache_page: invalid offset: %lx\n", pd.offset); return SEEK_ERROR; } if ((ret = pread(dd->dfd, dd->compressed_page, pd.size, pd.offset)) != pd.size) { if (ret == -1 && CRASHDEBUG(8)) fprintf(fp, "read_diskdump/cache_page: pread error: %s\n", strerror(errno)); return READ_ERROR; } } if (pd.flags & DUMP_DH_COMPRESSED_ZLIB) { retlen = block_size; ret = uncompress((unsigned char *)dd->page_cache_hdr[i].pg_bufptr, &retlen, (unsigned char *)dd->compressed_page, pd.size); if ((ret != Z_OK) || (retlen != block_size)) { error(INFO, "%s: uncompress failed: %d\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump", ret); return READ_ERROR; } } else if (pd.flags & DUMP_DH_COMPRESSED_LZO) { if (!(dd->flags & LZO_SUPPORTED)) { error(INFO, "%s: uncompress failed: no lzo compression support\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); return READ_ERROR; } #ifdef LZO retlen = block_size; ret = lzo1x_decompress_safe((unsigned char *)dd->compressed_page, pd.size, (unsigned char *)dd->page_cache_hdr[i].pg_bufptr, &retlen, LZO1X_MEM_DECOMPRESS); if ((ret != LZO_E_OK) || (retlen != block_size)) { error(INFO, "%s: uncompress failed: %d\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump", ret); return READ_ERROR; } #endif } else if (pd.flags & DUMP_DH_COMPRESSED_SNAPPY) { if (!(dd->flags & SNAPPY_SUPPORTED)) { error(INFO, "%s: uncompress failed: no snappy compression support\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); return READ_ERROR; } #ifdef SNAPPY ret = snappy_uncompressed_length((char *)dd->compressed_page, pd.size, (size_t *)&retlen); if (ret != SNAPPY_OK) { error(INFO, "%s: uncompress failed: %d\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump", ret); return READ_ERROR; } ret = snappy_uncompress((char *)dd->compressed_page, pd.size, (char *)dd->page_cache_hdr[i].pg_bufptr, (size_t *)&retlen); if ((ret != SNAPPY_OK) || (retlen != block_size)) { error(INFO, "%s: uncompress failed: %d\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump", ret); return READ_ERROR; } #endif } else if (pd.flags & DUMP_DH_COMPRESSED_ZSTD) { if (!(dd->flags & ZSTD_SUPPORTED)) { error(INFO, "%s: uncompress failed: no zstd compression support\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); return READ_ERROR; } #ifdef ZSTD if (!dctx) { dctx = ZSTD_createDCtx(); if (!dctx) { error(INFO, "%s: uncompress failed: cannot create ZSTD_DCtx\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); return READ_ERROR; } } retlen = ZSTD_decompressDCtx(dctx, dd->page_cache_hdr[i].pg_bufptr, block_size, dd->compressed_page, pd.size); if (ZSTD_isError(retlen) || (retlen != block_size)) { error(INFO, "%s: uncompress failed: %d (%s)\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump", retlen, ZSTD_getErrorName(retlen)); return READ_ERROR; } #endif } else memcpy(dd->page_cache_hdr[i].pg_bufptr, dd->compressed_page, block_size); dd->page_cache_hdr[i].pg_flags |= PAGE_VALID; dd->curbufptr = dd->page_cache_hdr[i].pg_bufptr; return TRUE; } /* * Read from a diskdump-created dumpfile. */ int read_diskdump(int fd, void *bufptr, int cnt, ulong addr, physaddr_t paddr) { int ret; physaddr_t curpaddr; ulong pfn, page_offset; physaddr_t paddr_in = paddr; if (XEN_CORE_DUMPFILE() && !XEN_HYPER_MODE()) { if ((paddr = xen_kdump_p2m(paddr)) == P2M_FAILURE) { if (CRASHDEBUG(8)) fprintf(fp, "read_diskdump: xen_kdump_p2m(%llx): " "P2M_FAILURE\n", (ulonglong)paddr_in); return READ_ERROR; } if (CRASHDEBUG(8)) fprintf(fp, "read_diskdump: xen_kdump_p2m(%llx): %llx\n", (ulonglong)paddr_in, (ulonglong)paddr); } pfn = paddr_to_pfn(paddr); if (KDUMP_SPLIT()) { /* Find proper dd */ int i; unsigned long long start_pfn; unsigned long long end_pfn; for (i=0; isub_header_kdump->start_pfn_64; end_pfn = dd_list[i]->sub_header_kdump->end_pfn_64; if ((pfn >= start_pfn) && (pfn < end_pfn)) { dd = dd_list[i]; break; } } if (i == num_dumpfiles) { if (CRASHDEBUG(8)) fprintf(fp, "read_diskdump: SEEK_ERROR: " "paddr/pfn %llx/%lx beyond last dumpfile\n", (ulonglong)paddr, pfn); return SEEK_ERROR; } } curpaddr = paddr & ~((physaddr_t)(dd->block_size-1)); page_offset = paddr & ((physaddr_t)(dd->block_size-1)); if ((pfn >= dd->max_mapnr) || !page_is_ram(pfn)) { if (CRASHDEBUG(8)) { fprintf(fp, "read_diskdump: SEEK_ERROR: " "paddr/pfn: %llx/%lx ", (ulonglong)paddr, pfn); if (pfn >= dd->max_mapnr) fprintf(fp, "max_mapnr: %llx\n", dd->max_mapnr); else fprintf(fp, "!page_is_ram\n"); } return SEEK_ERROR; } if (!page_is_dumpable(pfn)) { if ((dd->flags & (ZERO_EXCLUDED|ERROR_EXCLUDED)) == ERROR_EXCLUDED) { if (CRASHDEBUG(8)) fprintf(fp, "read_diskdump: PAGE_EXCLUDED: " "paddr/pfn: %llx/%lx\n", (ulonglong)paddr, pfn); return PAGE_EXCLUDED; } if (CRASHDEBUG(8)) fprintf(fp, "read_diskdump: zero-fill: " "paddr/pfn: %llx/%lx\n", (ulonglong)paddr, pfn); memset(bufptr, 0, cnt); return cnt; } if (!page_is_cached(curpaddr)) { if (CRASHDEBUG(8)) fprintf(fp, "read_diskdump: paddr/pfn: %llx/%lx" " -> cache physical page: %llx\n", (ulonglong)paddr, pfn, (ulonglong)curpaddr); if ((ret = cache_page(curpaddr)) < 0) { if (CRASHDEBUG(8)) fprintf(fp, "read_diskdump: " "%s: cannot cache page: %llx\n", ret == SEEK_ERROR ? "SEEK_ERROR" : "READ_ERROR", (ulonglong)curpaddr); return ret; } } else if (CRASHDEBUG(8)) fprintf(fp, "read_diskdump: paddr/pfn: %llx/%lx" " -> physical page is cached: %llx\n", (ulonglong)paddr, pfn, (ulonglong)curpaddr); memcpy(bufptr, dd->curbufptr + page_offset, cnt); return cnt; } /* * Write to a diskdump-created dumpfile. */ int write_diskdump(int fd, void *bufptr, int cnt, ulong addr, physaddr_t paddr) { return 0; } ulong get_diskdump_panic_task(void) { int i; if ((!DISKDUMP_VALID() && !KDUMP_CMPRS_VALID()) || !get_active_set()) return NO_TASK; if (pc->flags2 & SNAP) return (task_exists(dd->snapshot_task) ? dd->snapshot_task : NO_TASK); if (DISKDUMP_VALID()) return (ulong)dd->header->tasks[dd->header->current_cpu]; if (KDUMP_CMPRS_VALID()) { if (kernel_symbol_exists("crashing_cpu") && cpu_map_addr("online")) { get_symbol_data("crashing_cpu", sizeof(int), &i); if ((i >= 0) && in_cpu_map(ONLINE_MAP, i)) { if (CRASHDEBUG(1)) error(INFO, "get_diskdump_panic_task: " "active_set[%d]: %lx\n", i, tt->active_set[i]); return (tt->active_set[i]); } } } return NO_TASK; } extern void get_netdump_regs_x86(struct bt_info *, ulong *, ulong *); extern void get_netdump_regs_x86_64(struct bt_info *, ulong *, ulong *); static void get_diskdump_regs_32(struct bt_info *bt, ulong *eip, ulong *esp) { Elf32_Nhdr *note; int len; if (KDUMP_CMPRS_VALID() && (bt->task == tt->panic_task || (is_task_active(bt->task) && dd->num_prstatus_notes > 1))) { note = (Elf32_Nhdr*) dd->nt_prstatus_percpu[bt->tc->processor]; if (!note) error(FATAL, "cannot determine NT_PRSTATUS ELF note " "for %s task: %lx\n", (bt->task == tt->panic_task) ? "panic" : "active", bt->task); len = sizeof(Elf32_Nhdr); len = roundup(len + note->n_namesz, 4); bt->machdep = (void *)((char *)note + len + MEMBER_OFFSET("elf_prstatus", "pr_reg")); } machdep->get_stack_frame(bt, eip, esp); } static void get_diskdump_regs_ppc(struct bt_info *bt, ulong *eip, ulong *esp) { if (KDUMP_CMPRS_VALID()) ppc_relocate_nt_prstatus_percpu(dd->nt_prstatus_percpu, &dd->num_prstatus_notes); get_diskdump_regs_32(bt, eip, esp); } static void get_diskdump_regs_ppc64(struct bt_info *bt, ulong *eip, ulong *esp) { int cpu; Elf64_Nhdr *note; size_t len; if ((bt->task == tt->panic_task) && DISKDUMP_VALID()) bt->machdep = &dd->sub_header->elf_regs; else if (KDUMP_CMPRS_VALID() && (bt->task == tt->panic_task || (is_task_active(bt->task) && dd->num_prstatus_notes > 1))) { cpu = bt->tc->processor; if (dd->nt_prstatus_percpu[cpu] == NULL) { if(CRASHDEBUG(1)) error(INFO, "registers not collected for cpu %d\n", cpu); } else { note = (Elf64_Nhdr *) dd->nt_prstatus_percpu[cpu]; len = sizeof(Elf64_Nhdr); len = roundup(len + note->n_namesz, 4); bt->machdep = (void *)((char *)note + len + MEMBER_OFFSET("elf_prstatus", "pr_reg")); } } machdep->get_stack_frame(bt, eip, esp); } static void get_diskdump_regs_arm(struct bt_info *bt, ulong *eip, ulong *esp) { machdep->get_stack_frame(bt, eip, esp); } static void get_diskdump_regs_arm64(struct bt_info *bt, ulong *eip, ulong *esp) { machdep->get_stack_frame(bt, eip, esp); } static void get_diskdump_regs_mips(struct bt_info *bt, ulong *eip, ulong *esp) { machdep->get_stack_frame(bt, eip, esp); } static void get_diskdump_regs_riscv64(struct bt_info *bt, ulong *eip, ulong *esp) { machdep->get_stack_frame(bt, eip, esp); } static void get_diskdump_regs_loongarch64(struct bt_info *bt, ulong *eip, ulong *esp) { machdep->get_stack_frame(bt, eip, esp); } static void get_diskdump_regs_sparc64(struct bt_info *bt, ulong *eip, ulong *esp) { Elf64_Nhdr *note; int len; if (KDUMP_CMPRS_VALID() && (bt->task == tt->panic_task || (is_task_active(bt->task) && dd->num_prstatus_notes > 1))) { note = (Elf64_Nhdr *)dd->nt_prstatus_percpu[bt->tc->processor]; if (!note) error(FATAL, "cannot determine NT_PRSTATUS ELF note " "for %s task: %lx\n", (bt->task == tt->panic_task) ? "panic" : "active", bt->task); len = sizeof(Elf64_Nhdr); len = roundup(len + note->n_namesz, 4); bt->machdep = (void *)((char *)note + len + MEMBER_OFFSET("elf_prstatus", "pr_reg")); } machdep->get_stack_frame(bt, eip, esp); } /* * Send the request to the proper architecture hander. */ void get_diskdump_regs(struct bt_info *bt, ulong *eip, ulong *esp) { switch (dd->machine_type) { case EM_ARM: get_diskdump_regs_arm(bt, eip, esp); break; case EM_MIPS: return get_diskdump_regs_mips(bt, eip, esp); break; case EM_386: return get_netdump_regs_x86(bt, eip, esp); break; case EM_IA_64: /* For normal backtraces, this information will be obtained * frome the switch_stack structure, which is pointed to by * the thread.ksp field of the task_struct. But it's still * needed by the "bt -t" option. */ machdep->get_stack_frame(bt, eip, esp); break; case EM_PPC: return get_diskdump_regs_ppc(bt, eip, esp); break; case EM_PPC64: return get_diskdump_regs_ppc64(bt, eip, esp); break; case EM_X86_64: return get_netdump_regs_x86_64(bt, eip, esp); break; case EM_S390: return machdep->get_stack_frame(bt, eip, esp); break; case EM_AARCH64: get_diskdump_regs_arm64(bt, eip, esp); break; case EM_SPARCV9: get_diskdump_regs_sparc64(bt, eip, esp); break; case EM_RISCV: get_diskdump_regs_riscv64(bt, eip, esp); break; case EM_LOONGARCH: get_diskdump_regs_loongarch64(bt, eip, esp); break; default: error(FATAL, "%s: unsupported machine type: %s\n", DISKDUMP_VALID() ? "diskdump" : "compressed kdump", MACHINE_TYPE); } } /* * Return the processor page size. */ uint diskdump_page_size(void) { if (!DISKDUMP_VALID() && !KDUMP_CMPRS_VALID()) return 0; return dd->header->block_size; } /* * diskdump_free_memory(), and diskdump_memory_used() * are debug only, and probably unnecessary to implement. */ int diskdump_free_memory(void) { return 0; } int diskdump_memory_used(void) { return 0; } static void dump_vmcoreinfo(FILE *fp) { char *buf = NULL; unsigned long i = 0; unsigned long size_vmcoreinfo = dd->sub_header_kdump->size_vmcoreinfo; off_t offset = dd->sub_header_kdump->offset_vmcoreinfo; const off_t failed = (off_t)-1; if ((buf = malloc(size_vmcoreinfo)) == NULL) { error(FATAL, "compressed kdump: cannot malloc vmcoreinfo" " buffer\n"); } if (FLAT_FORMAT()) { if (!read_flattened_format(dd->dfd, offset, buf, size_vmcoreinfo)) { error(INFO, "compressed kdump: cannot read vmcoreinfo data\n"); goto err; } } else { if (lseek(dd->dfd, offset, SEEK_SET) == failed) { error(INFO, "compressed kdump: cannot lseek dump vmcoreinfo\n"); goto err; } if (read(dd->dfd, buf, size_vmcoreinfo) < size_vmcoreinfo) { error(INFO, "compressed kdump: cannot read vmcoreinfo data\n"); goto err; } } fprintf(fp, " "); for (i = 0; i < size_vmcoreinfo; i++) { fprintf(fp, "%c", buf[i]); if ((buf[i] == '\n') && ((i+1) != size_vmcoreinfo)) fprintf(fp, " "); } if (buf[i-1] != '\n') fprintf(fp, "\n"); err: if (buf) free(buf); return; } static void dump_eraseinfo(FILE *fp) { char *buf = NULL; unsigned long i = 0; unsigned long size_eraseinfo = dd->sub_header_kdump->size_eraseinfo; off_t offset = dd->sub_header_kdump->offset_eraseinfo; const off_t failed = (off_t)-1; if ((buf = malloc(size_eraseinfo)) == NULL) { error(FATAL, "compressed kdump: cannot malloc eraseinfo" " buffer\n"); } if (FLAT_FORMAT()) { if (!read_flattened_format(dd->dfd, offset, buf, size_eraseinfo)) { error(INFO, "compressed kdump: cannot read eraseinfo data\n"); goto err; } } else { if (lseek(dd->dfd, offset, SEEK_SET) == failed) { error(INFO, "compressed kdump: cannot lseek dump eraseinfo\n"); goto err; } if (read(dd->dfd, buf, size_eraseinfo) < size_eraseinfo) { error(INFO, "compressed kdump: cannot read eraseinfo data\n"); goto err; } } fprintf(fp, " "); for (i = 0; i < size_eraseinfo; i++) { fprintf(fp, "%c", buf[i]); if (buf[i] == '\n') fprintf(fp, " "); } if (buf[i - 1] != '\n') fprintf(fp, "\n"); err: if (buf) free(buf); return; } static void dump_note_offsets(FILE *fp) { struct kdump_sub_header *sub_header_kdump = dd->sub_header_kdump; size_t size; off_t offset; Elf32_Nhdr *note32 = NULL; Elf64_Nhdr *note64 = NULL; size_t tot, len = 0; int qemu, cnt; if (KDUMP_CMPRS_VALID() && !(dd->flags & NO_ELF_NOTES) && (dd->header->header_version >= 4) && (sub_header_kdump->offset_note) && (sub_header_kdump->size_note) && (machdep->process_elf_notes)) { size = sub_header_kdump->size_note; offset = sub_header_kdump->offset_note; fprintf(fp, " NOTE offsets: "); for (tot = cnt = 0; tot < size; tot += len) { qemu = FALSE; if (machine_type("X86_64") || machine_type("S390X") || machine_type("ARM64") || machine_type("PPC64") || machine_type("SPARC64") || machine_type("MIPS64") || machine_type("RISCV64") || machine_type("LOONGARCH64")) { note64 = (void *)dd->notes_buf + tot; len = sizeof(Elf64_Nhdr); if (STRNEQ((char *)note64 + len, "QEMU")) qemu = TRUE; len = roundup(len + note64->n_namesz, 4); len = roundup(len + note64->n_descsz, 4); if (note64->n_type == NT_PRSTATUS) { fprintf(fp, "%s%lx (NT_PRSTATUS)\n", tot ? space(22) : "", (ulong)(offset + tot)); cnt++; } if (qemu) { fprintf(fp, "%s%lx (QEMU)\n", tot ? space(22) : "", (ulong)(offset + tot)); cnt++; } } else if (machine_type("X86") || machine_type("PPC")) { note32 = (void *)dd->notes_buf + tot; len = sizeof(Elf32_Nhdr); if (STRNEQ((char *)note32 + len, "QEMU")) qemu = TRUE; len = roundup(len + note32->n_namesz, 4); len = roundup(len + note32->n_descsz, 4); if (note32->n_type == NT_PRSTATUS) { fprintf(fp, "%s%lx (NT_PRSTATUS)\n", tot ? space(22) : "", (ulong)(offset + tot)); cnt++; } if (qemu) { fprintf(fp, "%s%lx (QEMU)\n", tot ? space(22) : "", (ulong)(offset + tot)); cnt++; } } } if (!cnt) fprintf(fp, "\n"); } } /* * This function is dump-type independent, and could be used * to dump the diskdump_data structure contents and perhaps * the diskdump header data. */ int __diskdump_memory_dump(FILE *fp) { int i, others, dump_level; struct disk_dump_header *dh; struct disk_dump_sub_header *dsh; struct kdump_sub_header *kdsh; ulong *tasks; if (FLAT_FORMAT()) dump_flat_header(fp); fprintf(fp, "diskdump_data: \n"); fprintf(fp, " filename: %s\n", dd->filename); fprintf(fp, " flags: %lx (", dd->flags); others = 0; if (dd->flags & DISKDUMP_LOCAL) fprintf(fp, "%sDISKDUMP_LOCAL", others++ ? "|" : ""); if (dd->flags & KDUMP_CMPRS_LOCAL) fprintf(fp, "%sKDUMP_CMPRS_LOCAL", others++ ? "|" : ""); if (dd->flags & ERROR_EXCLUDED) fprintf(fp, "%sERROR_EXCLUDED", others++ ? "|" : ""); if (dd->flags & ZERO_EXCLUDED) fprintf(fp, "%sZERO_EXCLUDED", others++ ? "|" : ""); if (dd->flags & NO_ELF_NOTES) fprintf(fp, "%sNO_ELF_NOTES", others++ ? "|" : ""); if (dd->flags & LZO_SUPPORTED) fprintf(fp, "%sLZO_SUPPORTED", others++ ? "|" : ""); if (dd->flags & SNAPPY_SUPPORTED) fprintf(fp, "%sSNAPPY_SUPPORTED", others++ ? "|" : ""); if (dd->flags & ZSTD_SUPPORTED) fprintf(fp, "%sZSTD_SUPPORTED", others++ ? "|" : ""); fprintf(fp, ") %s\n", FLAT_FORMAT() ? "[FLAT]" : ""); fprintf(fp, " dfd: %d\n", dd->dfd); fprintf(fp, " ofp: %lx\n", (ulong)dd->ofp); fprintf(fp, " machine_type: %d ", dd->machine_type); switch (dd->machine_type) { case EM_ARM: fprintf(fp, "(EM_ARM)\n"); break; case EM_MIPS: fprintf(fp, "(EM_MIPS)\n"); break; case EM_386: fprintf(fp, "(EM_386)\n"); break; case EM_X86_64: fprintf(fp, "(EM_X86_64)\n"); break; case EM_IA_64: fprintf(fp, "(EM_IA_64)\n"); break; case EM_PPC: fprintf(fp, "(EM_PPC)\n"); break; case EM_PPC64: fprintf(fp, "(EM_PPC64)\n"); break; case EM_S390: fprintf(fp, "(EM_S390)\n"); break; case EM_AARCH64: fprintf(fp, "(EM_AARCH64)\n"); break; case EM_SPARCV9: fprintf(fp, "(EM_SPARCV9)\n"); break; case EM_LOONGARCH: fprintf(fp, "(EM_LOONGARCH)\n"); break; default: fprintf(fp, "(unknown)\n"); break; } fprintf(fp, "\n header: %lx\n", (ulong)dd->header); dh = dd->header; fprintf(fp, " signature: \""); for (i = 0; i < SIG_LEN; i++) if (dh->signature[i]) fprintf(fp, "%c", dh->signature[i]); fprintf(fp, "\"\n"); fprintf(fp, " header_version: %d\n", dh->header_version); fprintf(fp, " utsname:\n"); fprintf(fp, " sysname: %s\n", dh->utsname.sysname); fprintf(fp, " nodename: %s\n", dh->utsname.nodename); fprintf(fp, " release: %s\n", dh->utsname.release); fprintf(fp, " version: %s\n", dh->utsname.version); fprintf(fp, " machine: %s\n", dh->utsname.machine); fprintf(fp, " domainname: %s\n", dh->utsname.domainname); fprintf(fp, " timestamp:\n"); fprintf(fp, " tv_sec: %lx\n", dh->timestamp.tv_sec); fprintf(fp, " tv_usec: %lx\n", dh->timestamp.tv_usec); fprintf(fp, " status: %x (", dh->status); switch (dd->flags & (DISKDUMP_LOCAL|KDUMP_CMPRS_LOCAL)) { case DISKDUMP_LOCAL: if (dh->status == DUMP_HEADER_COMPLETED) fprintf(fp, "DUMP_HEADER_COMPLETED"); else if (dh->status == DUMP_HEADER_INCOMPLETED) fprintf(fp, "DUMP_HEADER_INCOMPLETED"); else if (dh->status == DUMP_HEADER_COMPRESSED) fprintf(fp, "DUMP_HEADER_COMPRESSED"); break; case KDUMP_CMPRS_LOCAL: if (dh->status & DUMP_DH_COMPRESSED_ZLIB) fprintf(fp, "DUMP_DH_COMPRESSED_ZLIB"); if (dh->status & DUMP_DH_COMPRESSED_LZO) fprintf(fp, "DUMP_DH_COMPRESSED_LZO"); if (dh->status & DUMP_DH_COMPRESSED_SNAPPY) fprintf(fp, "DUMP_DH_COMPRESSED_SNAPPY"); if (dh->status & DUMP_DH_COMPRESSED_ZSTD) fprintf(fp, "DUMP_DH_COMPRESSED_ZSTD"); if (dh->status & DUMP_DH_COMPRESSED_INCOMPLETE) fprintf(fp, "DUMP_DH_COMPRESSED_INCOMPLETE"); if (dh->status & DUMP_DH_EXCLUDED_VMEMMAP) fprintf(fp, "DUMP_DH_EXCLUDED_VMEMMAP"); break; } fprintf(fp, ")\n"); fprintf(fp, " block_size: %d\n", dh->block_size); fprintf(fp, " sub_hdr_size: %d\n", dh->sub_hdr_size); fprintf(fp, " bitmap_blocks: %u\n", dh->bitmap_blocks); fprintf(fp, " max_mapnr: %u\n", dh->max_mapnr); fprintf(fp, " total_ram_blocks: %u\n", dh->total_ram_blocks); fprintf(fp, " device_blocks: %u\n", dh->device_blocks); fprintf(fp, " written_blocks: %u\n", dh->written_blocks); fprintf(fp, " current_cpu: %u\n", dh->current_cpu); fprintf(fp, " nr_cpus: %d\n", dh->nr_cpus); tasks = (ulong *)&dh->tasks[0]; fprintf(fp, " tasks[nr_cpus]: %lx\n", *tasks); for (tasks++, i = 1; i < dh->nr_cpus; i++) { fprintf(fp, " %lx\n", *tasks); tasks++; } fprintf(fp, "\n"); fprintf(fp, " sub_header: %lx ", (ulong)dd->sub_header); if ((dsh = dd->sub_header)) { fprintf(fp, "\n elf_regs: %lx\n", (ulong)&dsh->elf_regs); fprintf(fp, " dump_level: "); if ((pc->flags & RUNTIME) && ((dump_level = get_dump_level()) >= 0)) { fprintf(fp, "%d (0x%x) %s", dump_level, dump_level, dump_level ? "(" : ""); #define DUMP_EXCLUDE_CACHE 0x00000001 /* Exclude LRU & SwapCache pages*/ #define DUMP_EXCLUDE_CLEAN 0x00000002 /* Exclude all-zero pages */ #define DUMP_EXCLUDE_FREE 0x00000004 /* Exclude free pages */ #define DUMP_EXCLUDE_ANON 0x00000008 /* Exclude Anon pages */ #define DUMP_SAVE_PRIVATE 0x00000010 /* Save private pages */ others = 0; if (dump_level & DUMP_EXCLUDE_CACHE) fprintf(fp, "%sDUMP_EXCLUDE_CACHE", others++ ? "|" : ""); if (dump_level & DUMP_EXCLUDE_CLEAN) fprintf(fp, "%sDUMP_EXCLUDE_CLEAN", others++ ? "|" : ""); if (dump_level & DUMP_EXCLUDE_FREE) fprintf(fp, "%sDUMP_EXCLUDE_FREE", others++ ? "|" : ""); if (dump_level & DUMP_EXCLUDE_ANON) fprintf(fp, "%sDUMP_EXCLUDE_ANON", others++ ? "|" : ""); if (dump_level & DUMP_SAVE_PRIVATE) fprintf(fp, "%sDUMP_SAVE_PRIVATE", others++ ? "|" : ""); fprintf(fp, "%s\n\n", dump_level ? ")" : ""); } else fprintf(fp, "%s\n\n", pc->flags & RUNTIME ? "(unknown)" : "(undetermined)"); } else fprintf(fp, "(n/a)\n\n"); fprintf(fp, " sub_header_kdump: %lx ", (ulong)dd->sub_header_kdump); if ((kdsh = dd->sub_header_kdump)) { fprintf(fp, "\n phys_base: %lx\n", (ulong)kdsh->phys_base); fprintf(fp, " dump_level: "); if ((dump_level = get_dump_level()) >= 0) { fprintf(fp, "%d (0x%x) %s", dump_level, dump_level, dump_level ? "(" : ""); #define DL_EXCLUDE_ZERO (0x001) /* Exclude Pages filled with Zeros */ #define DL_EXCLUDE_CACHE (0x002) /* Exclude Cache Pages without Private Pages */ #define DL_EXCLUDE_CACHE_PRI (0x004) /* Exclude Cache Pages with Private Pages */ #define DL_EXCLUDE_USER_DATA (0x008) /* Exclude UserProcessData Pages */ #define DL_EXCLUDE_FREE (0x010) /* Exclude Free Pages */ others = 0; if (dump_level & DL_EXCLUDE_ZERO) fprintf(fp, "%sDUMP_EXCLUDE_ZERO", others++ ? "|" : ""); if (dump_level & DL_EXCLUDE_CACHE) fprintf(fp, "%sDUMP_EXCLUDE_CACHE", others++ ? "|" : ""); if (dump_level & DL_EXCLUDE_CACHE_PRI) fprintf(fp, "%sDUMP_EXCLUDE_CACHE_PRI", others++ ? "|" : ""); if (dump_level & DL_EXCLUDE_USER_DATA) fprintf(fp, "%sDUMP_EXCLUDE_USER_DATA", others++ ? "|" : ""); if (dump_level & DL_EXCLUDE_FREE) fprintf(fp, "%sDUMP_EXCLUDE_FREE", others++ ? "|" : ""); others = 0; fprintf(fp, "%s\n", dump_level ? ")" : ""); } else fprintf(fp, "(unknown)\n"); if (dh->header_version >= 2) { fprintf(fp, " split: %d\n", kdsh->split); fprintf(fp, " start_pfn: "); if (KDUMP_SPLIT()) fprintf(fp, "%ld (0x%lx)\n", kdsh->start_pfn, kdsh->start_pfn); else fprintf(fp, "(unused)\n"); fprintf(fp, " end_pfn: "); if (KDUMP_SPLIT()) fprintf(fp, "%ld (0x%lx)\n", kdsh->end_pfn, kdsh->end_pfn); else fprintf(fp, "(unused)\n"); } if (dh->header_version >= 3) { fprintf(fp, " offset_vmcoreinfo: %llu (0x%llx)\n", (ulonglong)dd->sub_header_kdump->offset_vmcoreinfo, (ulonglong)dd->sub_header_kdump->offset_vmcoreinfo); fprintf(fp, " size_vmcoreinfo: %lu (0x%lx)\n", dd->sub_header_kdump->size_vmcoreinfo, dd->sub_header_kdump->size_vmcoreinfo); if (dd->sub_header_kdump->offset_vmcoreinfo && dd->sub_header_kdump->size_vmcoreinfo) { dump_vmcoreinfo(fp); } } if (dh->header_version >= 4) { fprintf(fp, " offset_note: %llu (0x%llx)\n", (ulonglong)dd->sub_header_kdump->offset_note, (ulonglong)dd->sub_header_kdump->offset_note); fprintf(fp, " size_note: %lu (0x%lx)\n", dd->sub_header_kdump->size_note, dd->sub_header_kdump->size_note); fprintf(fp, " notes_buf: %lx\n", (ulong)dd->notes_buf); fprintf(fp, " num_vmcoredd_notes: %d\n", dd->num_vmcoredd_notes); for (i = 0; i < dd->num_vmcoredd_notes; i++) { fprintf(fp, " notes[%d]: %lx %s\n", i, (ulong)dd->nt_vmcoredd_array[i], dd->nt_vmcoredd_array[i] ? "(NT_VMCOREDD)" : ""); display_vmcoredd_note(dd->nt_vmcoredd_array[i], fp); } fprintf(fp, " num_prstatus_notes: %d\n", dd->num_prstatus_notes); for (i = 0; i < dd->num_prstatus_notes; i++) { fprintf(fp, " notes[%d]: %lx %s\n", i, (ulong)dd->nt_prstatus_percpu[i], dd->nt_prstatus_percpu[i] ? "(NT_PRSTATUS)" : ""); display_ELF_note(dd->machine_type, PRSTATUS_NOTE, dd->nt_prstatus_percpu[i], fp); } fprintf(fp, " snapshot_task: %lx %s\n", dd->snapshot_task, dd->snapshot_task ? "(NT_TASKSTRUCT)" : ""); fprintf(fp, " num_qemu_notes: %d\n", dd->num_qemu_notes); for (i = 0; i < dd->num_qemu_notes; i++) { fprintf(fp, " notes[%d]: %lx (QEMUCPUState)\n", i, (ulong)dd->nt_qemu_percpu[i]); display_ELF_note(dd->machine_type, QEMU_NOTE, dd->nt_qemu_percpu[i], fp); } dump_note_offsets(fp); } if (dh->header_version >= 5) { fprintf(fp, " offset_eraseinfo: %llu (0x%llx)\n", (ulonglong)dd->sub_header_kdump->offset_eraseinfo, (ulonglong)dd->sub_header_kdump->offset_eraseinfo); fprintf(fp, " size_eraseinfo: %lu (0x%lx)\n", dd->sub_header_kdump->size_eraseinfo, dd->sub_header_kdump->size_eraseinfo); if (dd->sub_header_kdump->offset_eraseinfo && dd->sub_header_kdump->size_eraseinfo) { dump_eraseinfo(fp); } } if (dh->header_version >= 6) { fprintf(fp, " start_pfn_64: "); if (KDUMP_SPLIT()) fprintf(fp, "%lld (0x%llx)\n", kdsh->start_pfn_64, kdsh->start_pfn_64); else fprintf(fp, "(unused)\n"); fprintf(fp, " end_pfn_64: "); if (KDUMP_SPLIT()) fprintf(fp, "%lld (0x%llx)\n", kdsh->end_pfn_64, kdsh->end_pfn_64); else fprintf(fp, "(unused)\n"); fprintf(fp, " max_mapnr_64: %llu (0x%llx)\n", kdsh->max_mapnr_64, kdsh->max_mapnr_64); } fprintf(fp, "\n"); } else fprintf(fp, "(n/a)\n\n"); fprintf(fp, " data_offset: %lx\n", (ulong)dd->data_offset); fprintf(fp, " block_size: %d\n", dd->block_size); fprintf(fp, " block_shift: %d\n", dd->block_shift); fprintf(fp, " bitmap: %lx\n", (ulong)dd->bitmap); fprintf(fp, " bitmap_len: %lld\n", (ulonglong)dd->bitmap_len); fprintf(fp, " max_mapnr: %lld (0x%llx)\n", dd->max_mapnr, dd->max_mapnr); fprintf(fp, " dumpable_bitmap: %lx\n", (ulong)dd->dumpable_bitmap); fprintf(fp, " byte: %d\n", dd->byte); fprintf(fp, " bit: %d\n", dd->bit); fprintf(fp, " compressed_page: %lx\n", (ulong)dd->compressed_page); fprintf(fp, " curbufptr: %lx\n\n", (ulong)dd->curbufptr); for (i = 0; i < DISKDUMP_CACHED_PAGES; i++) { fprintf(fp, "%spage_cache_hdr[%d]:\n", i < 10 ? " " : "", i); fprintf(fp, " pg_flags: %x (", dd->page_cache_hdr[i].pg_flags); others = 0; if (dd->page_cache_hdr[i].pg_flags & PAGE_VALID) fprintf(fp, "%sPAGE_VALID", others++ ? "|" : ""); fprintf(fp, ")\n"); fprintf(fp, " pg_addr: %llx\n", (ulonglong)dd->page_cache_hdr[i].pg_addr); fprintf(fp, " pg_bufptr: %lx\n", (ulong)dd->page_cache_hdr[i].pg_bufptr); fprintf(fp, " pg_hit_count: %ld\n", dd->page_cache_hdr[i].pg_hit_count); } fprintf(fp, "\n page_cache_buf: %lx\n", (ulong)dd->page_cache_buf); fprintf(fp, " evict_index: %d\n", dd->evict_index); fprintf(fp, " evictions: %ld\n", dd->evictions); fprintf(fp, " accesses: %ld\n", dd->accesses); fprintf(fp, " cached_reads: %ld ", dd->cached_reads); if (dd->accesses) fprintf(fp, "(%ld%%)\n", dd->cached_reads * 100 / dd->accesses); else fprintf(fp, "\n"); fprintf(fp, " valid_pages: %lx\n", (ulong)dd->valid_pages); fprintf(fp, " total_valid_pages: %ld\n", dd->valid_pages[dd->max_sect_len]); return 0; } /* * Wrapper of __diskdump_memory_dump() */ int diskdump_memory_dump(FILE *fp) { int i; if (KDUMP_SPLIT() && (dd_list != NULL)) for (i = 0; i < num_dumpfiles; i++) { dd = dd_list[i]; __diskdump_memory_dump(fp); fprintf(fp, "\n"); } else __diskdump_memory_dump(fp); return 0; } /* * Get the switch_stack address of the passed-in task. */ ulong get_diskdump_switch_stack(ulong task) { return 0; } /* * Versions of disk_dump that support it contain the "dump_level" symbol. * Version 1 and later compressed kdump dumpfiles contain the dump level * in an additional field of the sub_header_kdump structure. */ int get_dump_level(void) { int dump_level; if (DISKDUMP_VALID()) { if (symbol_exists("dump_level") && readmem(symbol_value("dump_level"), KVADDR, &dump_level, sizeof(dump_level), "dump_level", QUIET|RETURN_ON_ERROR)) return dump_level; } else if (KDUMP_CMPRS_VALID()) { if (dd->header->header_version >= 1) return dd->sub_header_kdump->dump_level; } return -1; } /* * Used by the "sys" command to display [PARTIAL DUMP] * after the dumpfile name. */ int is_partial_diskdump(void) { return (get_dump_level() > 0 ? TRUE : FALSE); } /* * Used by "sys" command to dump multiple split dumpfiles. */ void show_split_dumpfiles(void) { int i; struct diskdump_data *ddp; struct disk_dump_header *dh; for (i = 0; i < num_dumpfiles; i++) { ddp = dd_list[i]; dh = ddp->header; fprintf(fp, "%s%s%s%s%s", i ? " " : "", ddp->filename, is_partial_diskdump() ? " [PARTIAL DUMP]" : "", dh->status & DUMP_DH_COMPRESSED_INCOMPLETE ? " [INCOMPLETE]" : "", dh->status & DUMP_DH_EXCLUDED_VMEMMAP ? " [EXCLUDED VMEMMAP]" : ""); if ((i+1) < num_dumpfiles) fprintf(fp, "\n"); } } void * diskdump_get_prstatus_percpu(int cpu) { int online; if ((cpu < 0) || (cpu >= dd->num_prstatus_notes)) return NULL; /* * If no cpu mapping was done, then there must be * a one-to-one relationship between the number * of online cpus and the number of notes. */ if ((online = get_cpus_online()) && (online == kt->cpus) && (online != dd->num_prstatus_notes)) return NULL; return dd->nt_prstatus_percpu[cpu]; } /* * Reads a string value from VMCOREINFO. * * Returns a string (that has to be freed by the caller) that contains the * value for key or NULL if the key has not been found. */ static char * vmcoreinfo_read_string(const char *key) { char *buf, *value_string, *p1, *p2; size_t value_length; ulong size_vmcoreinfo; off_t offset; char keybuf[BUFSIZE]; const off_t failed = (off_t)-1; bool info_found = false; if (dd->header->header_version < 3) return NULL; buf = value_string = NULL; size_vmcoreinfo = dd->sub_header_kdump->size_vmcoreinfo; offset = dd->sub_header_kdump->offset_vmcoreinfo; sprintf(keybuf, "%s=", key); if ((buf = malloc(size_vmcoreinfo+1)) == NULL) { error(INFO, "compressed kdump: cannot malloc vmcoreinfo" " buffer\n"); goto err; } if (FLAT_FORMAT()) { if (!read_flattened_format(dd->dfd, offset, buf, size_vmcoreinfo)) { error(INFO, "compressed kdump: cannot read vmcoreinfo data\n"); goto err; } } else { if (lseek(dd->dfd, offset, SEEK_SET) == failed) { error(INFO, "compressed kdump: cannot lseek dump vmcoreinfo\n"); goto err; } if (read(dd->dfd, buf, size_vmcoreinfo) < size_vmcoreinfo) { error(INFO, "compressed kdump: cannot read vmcoreinfo data\n"); goto err; } } buf[size_vmcoreinfo] = '\n'; info_found = true; if ((p1 = strstr(buf, keybuf))) { p2 = p1 + strlen(keybuf); p1 = strstr(p2, "\n"); value_length = p1-p2; value_string = calloc(value_length+1, sizeof(char)); strncpy(value_string, p2, value_length); value_string[value_length] = NULLCHAR; } err: if (buf) free(buf); if (!info_found && value_string == NULL) return vmcoreinfo_read_from_memory(key); return value_string; } static void diskdump_get_osrelease(void) { char *string; if ((string = vmcoreinfo_read_string("OSRELEASE"))) { fprintf(fp, "%s\n", string); free(string); } else pc->flags2 &= ~GET_OSRELEASE; } static void diskdump_get_build_id(void) { char *string; if ((string = vmcoreinfo_read_string("BUILD-ID"))) { fprintf(fp, "%s\n", string); free(string); } else pc->flags2 &= ~GET_BUILD_ID; } static int valid_note_address(unsigned char *offset) { if (offset > (dd->notes_buf + dd->sub_header_kdump->size_note)) return FALSE; return TRUE; } void diskdump_display_regs(int cpu, FILE *ofp) { Elf32_Nhdr *note32; Elf64_Nhdr *note64; char *user_regs; size_t len; if ((cpu < 0) || (cpu >= dd->num_prstatus_notes) || (dd->nt_prstatus_percpu[cpu] == NULL)) { error(INFO, "registers not collected for cpu %d\n", cpu); return; } if (machine_type("X86_64")) { note64 = dd->nt_prstatus_percpu[cpu]; len = sizeof(Elf64_Nhdr); len = roundup(len + note64->n_namesz, 4); len = roundup(len + note64->n_descsz, 4); if (!valid_note_address((unsigned char *)note64 + len)) { error(INFO, "invalid NT_PRSTATUS note for cpu %d\n", cpu); return; } user_regs = (char *)note64 + len - SIZE(user_regs_struct) - sizeof(long); fprintf(ofp, " RIP: %016llx RSP: %016llx RFLAGS: %08llx\n" " RAX: %016llx RBX: %016llx RCX: %016llx\n" " RDX: %016llx RSI: %016llx RDI: %016llx\n" " RBP: %016llx R8: %016llx R9: %016llx\n" " R10: %016llx R11: %016llx R12: %016llx\n" " R13: %016llx R14: %016llx R15: %016llx\n" " CS: %04x SS: %04x\n", ULONGLONG(user_regs + OFFSET(user_regs_struct_rip)), ULONGLONG(user_regs + OFFSET(user_regs_struct_rsp)), ULONGLONG(user_regs + OFFSET(user_regs_struct_eflags)), ULONGLONG(user_regs + OFFSET(user_regs_struct_rax)), ULONGLONG(user_regs + OFFSET(user_regs_struct_rbx)), ULONGLONG(user_regs + OFFSET(user_regs_struct_rcx)), ULONGLONG(user_regs + OFFSET(user_regs_struct_rdx)), ULONGLONG(user_regs + OFFSET(user_regs_struct_rsi)), ULONGLONG(user_regs + OFFSET(user_regs_struct_rdi)), ULONGLONG(user_regs + OFFSET(user_regs_struct_rbp)), ULONGLONG(user_regs + OFFSET(user_regs_struct_r8)), ULONGLONG(user_regs + OFFSET(user_regs_struct_r9)), ULONGLONG(user_regs + OFFSET(user_regs_struct_r10)), ULONGLONG(user_regs + OFFSET(user_regs_struct_r11)), ULONGLONG(user_regs + OFFSET(user_regs_struct_r12)), ULONGLONG(user_regs + OFFSET(user_regs_struct_r13)), ULONGLONG(user_regs + OFFSET(user_regs_struct_r14)), ULONGLONG(user_regs + OFFSET(user_regs_struct_r15)), USHORT(user_regs + OFFSET(user_regs_struct_cs)), USHORT(user_regs + OFFSET(user_regs_struct_ss)) ); } if (machine_type("PPC64")) { struct ppc64_elf_prstatus *prs; struct ppc64_pt_regs *pr; note64 = dd->nt_prstatus_percpu[cpu]; len = sizeof(Elf64_Nhdr); len = roundup(len + note64->n_namesz, 4); len = roundup(len + note64->n_descsz, 4); if (!valid_note_address((unsigned char *)note64 + len)) { error(INFO, "invalid NT_PRSTATUS note for cpu %d\n", cpu); return; } prs = (struct ppc64_elf_prstatus *) ((char *)note64 + sizeof(Elf64_Nhdr) + note64->n_namesz); prs = (struct ppc64_elf_prstatus *)roundup((ulong)prs, 4); pr = &prs->pr_reg; fprintf(ofp, " R0: %016lx R1: %016lx R2: %016lx\n" " R3: %016lx R4: %016lx R5: %016lx\n" " R6: %016lx R7: %016lx R8: %016lx\n" " R9: %016lx R10: %016lx R11: %016lx\n" " R12: %016lx R13: %016lx R14: %016lx\n" " R15: %016lx R16: %016lx R16: %016lx\n" " R18: %016lx R19: %016lx R20: %016lx\n" " R21: %016lx R22: %016lx R23: %016lx\n" " R24: %016lx R25: %016lx R26: %016lx\n" " R27: %016lx R28: %016lx R29: %016lx\n" " R30: %016lx R31: %016lx\n" " NIP: %016lx MSR: %016lx\n" " OGPR3: %016lx CTR: %016lx\n" " LINK: %016lx XER: %016lx\n" " CCR: %016lx MQ: %016lx\n" " TRAP: %016lx DAR: %016lx\n" " DSISR: %016lx RESULT: %016lx\n", pr->gpr[0], pr->gpr[1], pr->gpr[2], pr->gpr[3], pr->gpr[4], pr->gpr[5], pr->gpr[6], pr->gpr[7], pr->gpr[8], pr->gpr[9], pr->gpr[10], pr->gpr[11], pr->gpr[12], pr->gpr[13], pr->gpr[14], pr->gpr[15], pr->gpr[16], pr->gpr[17], pr->gpr[18], pr->gpr[19], pr->gpr[20], pr->gpr[21], pr->gpr[22], pr->gpr[23], pr->gpr[24], pr->gpr[25], pr->gpr[26], pr->gpr[27], pr->gpr[28], pr->gpr[29], pr->gpr[30], pr->gpr[31], pr->nip, pr->msr, pr->orig_gpr3, pr->ctr, pr->link, pr->xer, pr->ccr, pr->mq, pr->trap, pr->dar, pr->dsisr, pr->result); } if (machine_type("ARM64")) { note64 = dd->nt_prstatus_percpu[cpu]; len = sizeof(Elf64_Nhdr); len = roundup(len + note64->n_namesz, 4); len = roundup(len + note64->n_descsz, 4); if (!valid_note_address((unsigned char *)note64 + len)) { error(INFO, "invalid NT_PRSTATUS note for cpu %d\n", cpu); return; } user_regs = (char *)note64 + len - SIZE(elf_prstatus) + OFFSET(elf_prstatus_pr_reg); fprintf(ofp, " X0: %016lx X1: %016lx X2: %016lx\n" " X3: %016lx X4: %016lx X5: %016lx\n" " X6: %016lx X7: %016lx X8: %016lx\n" " X9: %016lx X10: %016lx X11: %016lx\n" " X12: %016lx X13: %016lx X14: %016lx\n" " X15: %016lx X16: %016lx X17: %016lx\n" " X18: %016lx X19: %016lx X20: %016lx\n" " X21: %016lx X22: %016lx X23: %016lx\n" " X24: %016lx X25: %016lx X26: %016lx\n" " X27: %016lx X28: %016lx X29: %016lx\n" " LR: %016lx SP: %016lx PC: %016lx\n" " PSTATE: %08lx FPVALID: %08x\n", ULONG(user_regs + sizeof(ulong) * 0), ULONG(user_regs + sizeof(ulong) * 1), ULONG(user_regs + sizeof(ulong) * 2), ULONG(user_regs + sizeof(ulong) * 3), ULONG(user_regs + sizeof(ulong) * 4), ULONG(user_regs + sizeof(ulong) * 5), ULONG(user_regs + sizeof(ulong) * 6), ULONG(user_regs + sizeof(ulong) * 7), ULONG(user_regs + sizeof(ulong) * 8), ULONG(user_regs + sizeof(ulong) * 9), ULONG(user_regs + sizeof(ulong) * 10), ULONG(user_regs + sizeof(ulong) * 11), ULONG(user_regs + sizeof(ulong) * 12), ULONG(user_regs + sizeof(ulong) * 13), ULONG(user_regs + sizeof(ulong) * 14), ULONG(user_regs + sizeof(ulong) * 15), ULONG(user_regs + sizeof(ulong) * 16), ULONG(user_regs + sizeof(ulong) * 17), ULONG(user_regs + sizeof(ulong) * 18), ULONG(user_regs + sizeof(ulong) * 19), ULONG(user_regs + sizeof(ulong) * 20), ULONG(user_regs + sizeof(ulong) * 21), ULONG(user_regs + sizeof(ulong) * 22), ULONG(user_regs + sizeof(ulong) * 23), ULONG(user_regs + sizeof(ulong) * 24), ULONG(user_regs + sizeof(ulong) * 25), ULONG(user_regs + sizeof(ulong) * 26), ULONG(user_regs + sizeof(ulong) * 27), ULONG(user_regs + sizeof(ulong) * 28), ULONG(user_regs + sizeof(ulong) * 29), ULONG(user_regs + sizeof(ulong) * 30), ULONG(user_regs + sizeof(ulong) * 31), ULONG(user_regs + sizeof(ulong) * 32), ULONG(user_regs + sizeof(ulong) * 33), UINT(user_regs + sizeof(ulong) * 34)); } if (machine_type("X86")) { note32 = dd->nt_prstatus_percpu[cpu]; len = sizeof(Elf32_Nhdr); len = roundup(len + note32->n_namesz, 4); len = roundup(len + note32->n_descsz, 4); user_regs = (char *)note32 + len - SIZE(user_regs_struct) - sizeof(int); if (!valid_note_address((unsigned char *)note32 + len)) { error(INFO, "invalid NT_PRSTATUS note for cpu %d\n", cpu); return; } fprintf(ofp, " EAX: %08x EBX: %08x ECX: %08x EDX: %08x\n" " ESP: %08x EIP: %08x ESI: %08x EDI: %08x\n" " CS: %04x DS: %04x ES: %04x FS: %04x\n" " GS: %04x SS: %04x\n" " EBP: %08x EFLAGS: %08x\n", UINT(user_regs + OFFSET(user_regs_struct_eax)), UINT(user_regs + OFFSET(user_regs_struct_ebx)), UINT(user_regs + OFFSET(user_regs_struct_ecx)), UINT(user_regs + OFFSET(user_regs_struct_edx)), UINT(user_regs + OFFSET(user_regs_struct_esp)), UINT(user_regs + OFFSET(user_regs_struct_eip)), UINT(user_regs + OFFSET(user_regs_struct_esi)), UINT(user_regs + OFFSET(user_regs_struct_edi)), USHORT(user_regs + OFFSET(user_regs_struct_cs)), USHORT(user_regs + OFFSET(user_regs_struct_ds)), USHORT(user_regs + OFFSET(user_regs_struct_es)), USHORT(user_regs + OFFSET(user_regs_struct_fs)), USHORT(user_regs + OFFSET(user_regs_struct_gs)), USHORT(user_regs + OFFSET(user_regs_struct_ss)), UINT(user_regs + OFFSET(user_regs_struct_ebp)), UINT(user_regs + OFFSET(user_regs_struct_eflags)) ); } if (machine_type("MIPS")) mips_display_regs_from_elf_notes(cpu, ofp); if (machine_type("MIPS64")) mips64_display_regs_from_elf_notes(cpu, ofp); if (machine_type("LOONGARCH64")) loongarch64_display_regs_from_elf_notes(cpu, ofp); } void dump_registers_for_compressed_kdump(void) { int c; if (!KDUMP_CMPRS_VALID() || (dd->header->header_version < 4) || !(machine_type("X86") || machine_type("X86_64") || machine_type("ARM64") || machine_type("PPC64") || machine_type("MIPS") || machine_type("MIPS64") || machine_type("RISCV64") || machine_type("LOONGARCH64"))) error(FATAL, "-r option not supported for this dumpfile\n"); if (machine_type("ARM64") && (kt->cpus != dd->num_prstatus_notes)) fprintf(fp, "NOTE: cpus: %d NT_PRSTATUS notes: %d " "(note-to-cpu mapping is questionable)\n\n", kt->cpus, dd->num_prstatus_notes); for (c = 0; c < kt->cpus; c++) { if (hide_offline_cpu(c)) { fprintf(fp, "%sCPU %d: [OFFLINE]\n", c ? "\n" : "", c); continue; } else fprintf(fp, "%sCPU %d:\n", c ? "\n" : "", c); diskdump_display_regs(c, fp); } } int diskdump_kaslr_check() { if (!QEMU_MEM_DUMP_NO_VMCOREINFO()) return FALSE; if (dd->num_qemu_notes) return TRUE; return FALSE; } int diskdump_get_nr_cpus(void) { if (dd->num_prstatus_notes) return dd->num_prstatus_notes; else if (dd->num_qemu_notes) return dd->num_qemu_notes; else if (dd->num_vmcoredd_notes) return dd->num_vmcoredd_notes; else if (dd->header->nr_cpus) return dd->header->nr_cpus; return 1; } #ifdef X86_64 QEMUCPUState * diskdump_get_qemucpustate(int cpu) { if (cpu >= dd->num_qemu_notes) { if (CRASHDEBUG(1)) error(INFO, "Invalid index for QEMU Note: %d (>= %d)\n", cpu, dd->num_qemu_notes); return NULL; } if (dd->machine_type != EM_X86_64) { if (CRASHDEBUG(1)) error(INFO, "Only x86_64 64bit is supported.\n"); return NULL; } return (QEMUCPUState *)dd->nt_qemucs_percpu[cpu]; } #endif /* * extract hardware specific device dumps from coredump. */ void diskdump_device_dump_extract(int index, char *outfile, FILE *ofp) { ulonglong offset; if (!dd->num_vmcoredd_notes) error(FATAL, "no device dumps found in this dumpfile\n"); else if (index >= dd->num_vmcoredd_notes) error(FATAL, "no device dump found at index: %d", index); offset = dd->sub_header_kdump->offset_note + ((unsigned char *)dd->nt_vmcoredd_array[index] - dd->notes_buf); devdump_extract(dd->nt_vmcoredd_array[index], offset, outfile, ofp); } /* * list all hardware specific device dumps present in coredump. */ void diskdump_device_dump_info(FILE *ofp) { ulonglong offset; char buf[BUFSIZE]; ulong i; if (!dd->num_vmcoredd_notes) error(FATAL, "no device dumps found in this dumpfile\n"); fprintf(fp, "%s ", mkstring(buf, strlen("INDEX"), LJUST, "INDEX")); fprintf(fp, " %s ", mkstring(buf, LONG_LONG_PRLEN, LJUST, "OFFSET")); fprintf(fp, " %s ", mkstring(buf, LONG_PRLEN, LJUST, "SIZE")); fprintf(fp, "NAME\n"); for (i = 0; i < dd->num_vmcoredd_notes; i++) { fprintf(fp, "%s ", mkstring(buf, strlen("INDEX"), CENTER | INT_DEC, MKSTR(i))); offset = dd->sub_header_kdump->offset_note + ((unsigned char *)dd->nt_vmcoredd_array[i] - dd->notes_buf); devdump_info(dd->nt_vmcoredd_array[i], offset, ofp); } } static ulong ZRAM_FLAG_SHIFT; static ulong ZRAM_FLAG_SAME_BIT; static ulong ZRAM_COMP_PRIORITY_BIT1; static ulong ZRAM_COMP_PRIORITY_MASK; static void zram_init(void) { long zram_flag_shift; MEMBER_OFFSET_INIT(zram_mem_pool, "zram", "mem_pool"); MEMBER_OFFSET_INIT(zram_compressor, "zram", "compressor"); if (INVALID_MEMBER(zram_compressor)) MEMBER_OFFSET_INIT(zram_comp_algs, "zram", "comp_algs"); MEMBER_OFFSET_INIT(zram_table_entry_flags, "zram_table_entry", "flags"); if (INVALID_MEMBER(zram_table_entry_flags)) MEMBER_OFFSET_INIT(zram_table_entry_flags, "zram_table_entry", "value"); STRUCT_SIZE_INIT(zram_table_entry, "zram_table_entry"); MEMBER_OFFSET_INIT(zs_pool_size_class, "zs_pool", "size_class"); MEMBER_OFFSET_INIT(size_class_size, "size_class", "size"); MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge"); if (enumerator_value("ZRAM_LOCK", &zram_flag_shift)) ; else if (THIS_KERNEL_VERSION >= LINUX(6,1,0)) zram_flag_shift = PAGESHIFT() + 1; else zram_flag_shift = 24; ZRAM_FLAG_SHIFT = 1 << zram_flag_shift; ZRAM_FLAG_SAME_BIT = 1 << (zram_flag_shift+1); ZRAM_COMP_PRIORITY_BIT1 = ZRAM_FLAG_SHIFT + 7; ZRAM_COMP_PRIORITY_MASK = 0x3; if (CRASHDEBUG(1)) fprintf(fp, "zram_flag_shift: %ld\n", zram_flag_shift); } static unsigned char * zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf) { ulong obj, off, class, page, zspage; struct zspage zspage_s; physaddr_t paddr; unsigned int obj_idx, class_idx, size; ulong pages[2], sizes[2]; ulong zs_magic; readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR); obj >>= OBJ_TAG_BITS; phys_to_page(PTOB(obj >> OBJ_INDEX_BITS), &page); obj_idx = (obj & OBJ_INDEX_MASK); readmem(page + OFFSET(page_private), KVADDR, &zspage, sizeof(void *), "page_private", FAULT_ON_ERROR); readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR); if (VALID_MEMBER(zspage_huge)) { class_idx = zspage_s.v5_17.class; zs_magic = zspage_s.v5_17.magic; } else { class_idx = zspage_s.v0.class; zs_magic = zspage_s.v0.magic; } if (zs_magic != ZSPAGE_MAGIC) error(FATAL, "zspage magic incorrect: %x\n", zs_magic); class = pool + OFFSET(zs_pool_size_class); class += (class_idx * sizeof(void *)); readmem(class, KVADDR, &class, sizeof(void *), "size_class", FAULT_ON_ERROR); readmem(class + OFFSET(size_class_size), KVADDR, &size, sizeof(unsigned int), "size of class_size", FAULT_ON_ERROR); off = (size * obj_idx) & (~machdep->pagemask); if (off + size <= PAGESIZE()) { if (!is_page_ptr(page, &paddr)) { error(WARNING, "zspage: %lx: not a page pointer\n", page); return NULL; } readmem(paddr + off, PHYSADDR, zram_buf, size, "zram buffer", FAULT_ON_ERROR); goto out; } pages[0] = page; if (VALID_MEMBER(page_freelist)) readmem(page + OFFSET(page_freelist), KVADDR, &pages[1], sizeof(void *), "page_freelist", FAULT_ON_ERROR); else readmem(page + OFFSET(page_index), KVADDR, &pages[1], sizeof(void *), "page_index", FAULT_ON_ERROR); sizes[0] = PAGESIZE() - off; sizes[1] = size - sizes[0]; if (!is_page_ptr(pages[0], &paddr)) { error(WARNING, "pages[0]: %lx: not a page pointer\n", pages[0]); return NULL; } readmem(paddr + off, PHYSADDR, zram_buf, sizes[0], "zram buffer[0]", FAULT_ON_ERROR); if (!is_page_ptr(pages[1], &paddr)) { error(WARNING, "pages[1]: %lx: not a page pointer\n", pages[1]); return NULL; } readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR); out: if (VALID_MEMBER(zspage_huge)) { if (!zspage_s.v5_17.huge) return (zram_buf + ZS_HANDLE_SIZE); } else { readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR); if (!(obj & (1<<10))) // PG_OwnerPriv1 flag return (zram_buf + ZS_HANDLE_SIZE); } return zram_buf; } static inline bool radix_tree_exceptional_entry(ulong entry) { return entry & RADIX_TREE_EXCEPTIONAL_ENTRY; } static unsigned char * lookup_swap_cache(ulonglong pte_val, unsigned char *zram_buf) { ulonglong swp_offset; ulong swp_type, swp_space; struct list_pair lp; physaddr_t paddr; static int is_xarray = -1; if (is_xarray < 0) { is_xarray = STREQ(MEMBER_TYPE_NAME("address_space", "i_pages"), "xarray"); } swp_type = __swp_type(pte_val); if (THIS_KERNEL_VERSION >= LINUX(2,6,0)) { swp_offset = (ulonglong)__swp_offset(pte_val); } else { swp_offset = (ulonglong)SWP_OFFSET(pte_val); } if (!symbol_exists("swapper_spaces")) return NULL; swp_space = symbol_value("swapper_spaces"); swp_space += swp_type * sizeof(void *); readmem(swp_space, KVADDR, &swp_space, sizeof(void *), "swp_spaces", FAULT_ON_ERROR); swp_space += (swp_offset >> SWAP_ADDRESS_SPACE_SHIFT) * SIZE(address_space); lp.index = swp_offset; if ((is_xarray ? do_xarray : do_radix_tree) (swp_space+OFFSET(address_space_page_tree), RADIX_TREE_SEARCH, &lp)) { if ((is_xarray ? xa_is_value : radix_tree_exceptional_entry)((ulong)lp.value)) { /* ignore shadow values */ return NULL; } if (!is_page_ptr((ulong)lp.value, &paddr)) { error(WARNING, "radix page: %lx: not a page pointer\n", lp.value); return NULL; } readmem(paddr, PHYSADDR, zram_buf, PAGESIZE(), "zram buffer", FAULT_ON_ERROR); return zram_buf; } return NULL; } static int get_disk_name_private_data(ulonglong pte_val, ulonglong vaddr, char *name, ulong *private_data) { ulong swap_info, bdev, bd_disk; if (!symbol_exists("swap_info")) return FALSE; swap_info = symbol_value("swap_info"); swap_info_init(); if (vt->flags & SWAPINFO_V2) { swap_info += (__swp_type(pte_val) * sizeof(void *)); readmem(swap_info, KVADDR, &swap_info, sizeof(void *), "swap_info", FAULT_ON_ERROR); } else { swap_info += (SIZE(swap_info_struct) * __swp_type(pte_val)); } readmem(swap_info + OFFSET(swap_info_struct_bdev), KVADDR, &bdev, sizeof(void *), "swap_info_struct_bdev", FAULT_ON_ERROR); readmem(bdev + OFFSET(block_device_bd_disk), KVADDR, &bd_disk, sizeof(void *), "block_device_bd_disk", FAULT_ON_ERROR); if (name) readmem(bd_disk + OFFSET(gendisk_disk_name), KVADDR, name, strlen("zram"), "gendisk_disk_name", FAULT_ON_ERROR); if (private_data) readmem(bd_disk + OFFSET(gendisk_private_data), KVADDR, private_data, sizeof(void *), "gendisk_private_data", FAULT_ON_ERROR); return TRUE; } ulong readswap(ulonglong pte_val, char *buf, ulong len, ulonglong vaddr) { char name[32] = {0}; if (!get_disk_name_private_data(pte_val, vaddr, name, NULL)) return 0; if (!strncmp(name, "zram", 4)) { return try_zram_decompress(pte_val, (unsigned char *)buf, len, vaddr); } else { if (CRASHDEBUG(2)) error(WARNING, "this page has been swapped to %s\n", name); return 0; } } ulong (*decompressor)(unsigned char *in_addr, ulong in_size, unsigned char *out_addr, ulong *out_size, void *other/* NOT USED */); /* * If userspace address was swapped out to zram, this function is called to decompress the object. * try_zram_decompress returns decompressed page data and data length */ ulong try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong vaddr) { char name[32] = {0}; ulonglong swp_offset; unsigned char *obj_addr = NULL; unsigned char *zram_buf = NULL; unsigned char *outbuf = NULL; ulong zram, zram_table_entry, sector, index, entry, flags, size, outsize, off; if (INVALID_MEMBER(zram_mem_pool)) { zram_init(); if (INVALID_MEMBER(zram_mem_pool)) { error(WARNING, "Some pages are swapped out to zram. " "Please run mod -s zram.\n"); return 0; } } if (CRASHDEBUG(2)) error(WARNING, "this page has swapped to zram\n"); if (!get_disk_name_private_data(pte_val, vaddr, NULL, &zram)) return 0; if (THIS_KERNEL_VERSION >= LINUX(2, 6, 0)) swp_offset = (ulonglong)__swp_offset(pte_val); else swp_offset = (ulonglong)SWP_OFFSET(pte_val); sector = swp_offset << (PAGESHIFT() - 9); index = sector >> SECTORS_PER_PAGE_SHIFT; readmem(zram, KVADDR, &zram_table_entry, sizeof(void *), "zram_table_entry", FAULT_ON_ERROR); zram_table_entry += (index * SIZE(zram_table_entry)); readmem(zram_table_entry + OFFSET(zram_table_entry_flags), KVADDR, &flags, sizeof(void *), "zram_table_entry.flags", FAULT_ON_ERROR); if (VALID_MEMBER(zram_compressor)) readmem(zram + OFFSET(zram_compressor), KVADDR, name, sizeof(name), "zram compressor", FAULT_ON_ERROR); else { ulong comp_alg_addr; uint32_t prio = (flags >> ZRAM_COMP_PRIORITY_BIT1) & ZRAM_COMP_PRIORITY_MASK; readmem(zram + OFFSET(zram_comp_algs) + sizeof(const char *) * prio, KVADDR, &comp_alg_addr, sizeof(comp_alg_addr), "zram comp_algs", FAULT_ON_ERROR); read_string(comp_alg_addr, name, sizeof(name)); } if (STREQ(name, "lzo")) { #ifdef LZO if (!(dd->flags & LZO_SUPPORTED)) { if (lzo_init() == LZO_E_OK) dd->flags |= LZO_SUPPORTED; else return 0; } decompressor = (void *)lzo1x_decompress_safe; #else error(WARNING, "zram decompress error: this executable needs to be built" " with lzo library\n"); return 0; #endif } else if (STREQ(name, "lzo-rle")) { decompressor = (void *)&lzorle_decompress_safe; } else { /* todo: support more compressor */ error(WARNING, "only the lzo compressor is supported\n"); return 0; } zram_buf = (unsigned char *)GETBUF(PAGESIZE()); /* lookup page from swap cache */ off = PAGEOFFSET(vaddr); obj_addr = lookup_swap_cache(pte_val, zram_buf); if (obj_addr != NULL) { memcpy(buf, obj_addr + off, len); goto out; } readmem(zram_table_entry, KVADDR, &entry, sizeof(void *), "entry of table", FAULT_ON_ERROR); if (!entry || (flags & ZRAM_FLAG_SAME_BIT)) { int count; ulong *same_buf = (ulong *)GETBUF(PAGESIZE()); for (count = 0; count < PAGESIZE() / sizeof(ulong); count++) { same_buf[count] = entry; } memcpy(buf, same_buf + off, len); FREEBUF(same_buf); goto out; } size = flags & (ZRAM_FLAG_SHIFT -1); if (size == 0) { len = 0; goto out; } readmem(zram + OFFSET(zram_mem_pool), KVADDR, &zram, sizeof(void *), "zram.mem_pool", FAULT_ON_ERROR); obj_addr = zram_object_addr(zram, entry, zram_buf); if (obj_addr == NULL) { len = 0; goto out; } if (size == PAGESIZE()) { memcpy(buf, obj_addr + off, len); } else { outbuf = (unsigned char *)GETBUF(PAGESIZE()); outsize = PAGESIZE(); if (!decompressor(obj_addr, size, outbuf, &outsize, NULL)) memcpy(buf, outbuf + off, len); else { error(WARNING, "zram decompress error\n"); len = 0; } FREEBUF(outbuf); } out: if (len && CRASHDEBUG(2)) error(INFO, "%lx: zram decompress success\n", vaddr); FREEBUF(zram_buf); return len; } crash-utility-crash-61fe107/diskdump.h000066400000000000000000000077141517256214500177560ustar00rootroot00000000000000/* * diskdump.h * * Copyright (C) 2004, 2005, 2006 David Anderson * Copyright (C) 2004, 2005, 2006 Red Hat, Inc. All rights reserved. * Copyright (C) 2005 FUJITSU LIMITED * Copyright (C) 2005 NEC Corporation * * 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 2 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. */ #include #define divideup(x, y) (((x) + ((y) - 1)) / (y)) #define round(x, y) (((x) / (y)) * (y)) #define DUMP_PARTITION_SIGNATURE "diskdump" #define SIG_LEN (sizeof(DUMP_PARTITION_SIGNATURE) - 1) #define DISK_DUMP_SIGNATURE "DISKDUMP" #define KDUMP_SIGNATURE "KDUMP " #define DUMP_HEADER_COMPLETED 0 #define DUMP_HEADER_INCOMPLETED 1 #define DUMP_HEADER_COMPRESSED 8 struct disk_dump_header { char signature[SIG_LEN]; /* = "DISKDUMP" */ int header_version; /* Dump header version */ struct new_utsname utsname; /* copy of system_utsname */ struct timeval timestamp; /* Time stamp */ unsigned int status; /* Above flags */ int block_size; /* Size of a block in byte */ int sub_hdr_size; /* Size of arch dependent header in blocks */ unsigned int bitmap_blocks; /* Size of Memory bitmap in block */ unsigned int max_mapnr; /* = max_mapnr, OBSOLETE! 32bit only, full 64bit in sub header. */ unsigned int total_ram_blocks;/* Number of blocks should be written */ unsigned int device_blocks; /* Number of total blocks in * the dump device */ unsigned int written_blocks; /* Number of written blocks */ unsigned int current_cpu; /* CPU# which handles dump */ int nr_cpus; /* Number of CPUs */ struct task_struct *tasks[0]; }; struct disk_dump_sub_header { long elf_regs; }; struct kdump_sub_header { unsigned long phys_base; int dump_level; /* header_version 1 and later */ int split; /* header_version 2 and later */ unsigned long start_pfn; /* header_version 2 and later, OBSOLETE! 32bit only, full 64bit in start_pfn_64. */ unsigned long end_pfn; /* header_version 2 and later, OBSOLETE! 32bit only, full 64bit in end_pfn_64. */ off_t offset_vmcoreinfo; /* header_version 3 and later */ unsigned long size_vmcoreinfo; /* header_version 3 and later */ off_t offset_note; /* header_version 4 and later */ unsigned long size_note; /* header_version 4 and later */ off_t offset_eraseinfo; /* header_version 5 and later */ unsigned long size_eraseinfo; /* header_version 5 and later */ unsigned long long start_pfn_64; /* header_version 6 and later */ unsigned long long end_pfn_64; /* header_version 6 and later */ unsigned long long max_mapnr_64; /* header_version 6 and later */ }; /* page flags */ #define DUMP_DH_COMPRESSED_ZLIB 0x1 /* page is compressed with zlib */ #define DUMP_DH_COMPRESSED_LZO 0x2 /* page is compressed with lzo */ #define DUMP_DH_COMPRESSED_SNAPPY 0x4 /* page is compressed with snappy */ #define DUMP_DH_COMPRESSED_INCOMPLETE 0x8 /* dumpfile is incomplete */ #define DUMP_DH_EXCLUDED_VMEMMAP 0x10 /* unused vmemmap pages are excluded */ #define DUMP_DH_COMPRESSED_ZSTD 0x20 /* page is compressed with zstd */ /* descriptor of each page for vmcore */ typedef struct page_desc { off_t offset; /* the offset of the page data*/ unsigned int size; /* the size of this dump page */ unsigned int flags; /* flags */ unsigned long long page_flags; /* page flags */ } page_desc_t; #define DISKDUMP_CACHED_PAGES (16) #define PAGE_VALID (0x1) /* flags */ #define DISKDUMP_VALID_PAGE(flags) ((flags) & PAGE_VALID) crash-utility-crash-61fe107/extensions.c000066400000000000000000000350031517256214500203200ustar00rootroot00000000000000/* extensions.c - core analysis suite * * Copyright (C) 2001, 2002 Mission Critical Linux, Inc. * Copyright (C) 2002-2013, 2018 David Anderson * Copyright (C) 2002-2013, 2018 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #include "defs.h" #include static int in_extensions_library(char *, char *); static char *get_extensions_directory(char *, bool *); static void show_all_extensions(void); static void show_extensions(char *); #define DUMP_EXTENSIONS (0) #define LOAD_EXTENSION (1) #define UNLOAD_EXTENSION (2) #define SHOW_ALL_EXTENSIONS (4) /* * Load, unload, or list the extension libaries. */ void cmd_extend(void) { int c; int flag; flag = DUMP_EXTENSIONS; while ((c = getopt(argcnt, args, "lus")) != EOF) { switch(c) { case 's': if (flag & UNLOAD_EXTENSION) { error(INFO, "-s and -u are mutually exclusive\n"); argerrs++; }else if (flag & LOAD_EXTENSION) { error(INFO, "-s and -l are mutually exclusive\n"); argerrs++; } else flag |= SHOW_ALL_EXTENSIONS; break; case 'l': if (flag & UNLOAD_EXTENSION) { error(INFO, "-l and -u are mutually exclusive\n"); argerrs++; } else if (flag & SHOW_ALL_EXTENSIONS) { error(INFO, "-l and -s are mutually exclusive\n"); argerrs++; } else flag |= LOAD_EXTENSION; break; case 'u': if (flag & LOAD_EXTENSION) { error(INFO, "-u and -l are mutually exclusive\n"); argerrs++; } else if (flag & SHOW_ALL_EXTENSIONS) { error(INFO, "-u and -s are mutually exclusive\n"); argerrs++; } else flag |= UNLOAD_EXTENSION; break; default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); switch (flag) { case DUMP_EXTENSIONS: if (!args[optind]) { dump_extension_table(!VERBOSE); return; } /* FALLTHROUGH */ case LOAD_EXTENSION: if (!args[optind]) { error(INFO, "-l requires one or more extension library arguments\n"); cmd_usage(pc->curcmd, SYNOPSIS); break; } while (args[optind]) { load_extension(args[optind]); optind++; } break; case UNLOAD_EXTENSION: if (!args[optind]) { unload_extension(NULL); break; } while (args[optind]) { unload_extension(args[optind]); optind++; } break; case SHOW_ALL_EXTENSIONS: show_all_extensions(); break; } } /* * List all extension libaries and their commands in either the extend * command format or for "help -e" (verbose). */ void dump_extension_table(int verbose) { int i; struct extension_table *ext; struct command_table_entry *cp; char buf[BUFSIZE]; int longest, others; if (!extension_table) return; if (verbose) { for (ext = extension_table; ext; ext = ext->next) { fprintf(fp, " filename: %s\n", ext->filename); fprintf(fp, " handle: %lx\n", (ulong)ext->handle); fprintf(fp, " flags: %lx (", ext->flags); others = 0; if (ext->flags & REGISTERED) fprintf(fp, "%sREGISTERED", others++ ? "|" : ""); fprintf(fp, ")\n"); fprintf(fp, " next: %lx\n", (ulong)ext->next); fprintf(fp, " prev: %lx\n", (ulong)ext->prev); for (i = 0, cp = ext->command_table; cp->name; cp++, i++) { fprintf(fp, "command_table[%d]: %lx\n", i, (ulong)cp); fprintf(fp, " name: %s\n", cp->name); fprintf(fp, " func: %lx\n", (ulong)cp->func); fprintf(fp, " help_data: %lx\n", (ulong)cp->help_data); fprintf(fp, " flags: %lx (", cp->flags); others = 0; if (cp->flags & CLEANUP) fprintf(fp, "%sCLEANUP", others++ ? "|" : ""); if (cp->flags & REFRESH_TASK_TABLE) fprintf(fp, "%sREFRESH_TASK_TABLE", others++ ? "|" : ""); if (cp->flags & HIDDEN_COMMAND) fprintf(fp, "%sHIDDEN_COMMAND", others++ ? "|" : ""); fprintf(fp, ")\n"); } if (ext->next) fprintf(fp, "\n"); } return; } /* * Print them out in the order they were loaded. */ for (longest = 0, ext = extension_table; ext; ext = ext->next) { if (strlen(ext->filename) > longest) longest = strlen(ext->filename); } fprintf(fp, "%s COMMANDS\n", mkstring(buf, longest, LJUST, "SHARED OBJECT")); longest = MAX(longest, strlen("SHARED OBJECT")); for (ext = extension_table; ext; ext = ext->next) if (ext->next == NULL) break; do { fprintf(fp, "%s ", mkstring(buf, longest, LJUST, ext->filename)); for (cp = ext->command_table; cp->name; cp++) fprintf(fp, "%s ", cp->name); fprintf(fp, "\n"); } while ((ext = ext->prev)); } static void show_extensions(char *dir) { DIR *dirp; struct dirent *dp; char filename[BUFSIZE*2]; dirp = opendir(dir); if (!dirp) return; for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { sprintf(filename, "%s%s%s", dir, LASTCHAR(dir) == '/' ? "" : "/", dp->d_name); if (!is_shared_object(filename)) continue; fprintf(fp, "%s\n", filename); } closedir(dirp); } static void show_all_extensions(void) { char *dir; show_extensions("./"); if ((dir = getenv("CRASH_EXTENSIONS"))) show_extensions(dir); if (BITS64()) show_extensions("/usr/lib64/crash/extensions/"); show_extensions("/usr/lib/crash/extensions/"); show_extensions("./extensions/"); } /* * Load an extension library. */ void load_extension(char *lib) { struct extension_table *ext, *curext; char buf[BUFSIZE]; size_t size; char *env; int env_len; if ((env = getenv("CRASH_EXTENSIONS"))) env_len = strlen(env)+1; else env_len = 0; size = sizeof(struct extension_table) + strlen(lib) + MAX(env_len, strlen("/usr/lib64/crash/extensions/")) + 1; if ((ext = (struct extension_table *)malloc(size)) == NULL) error(FATAL, "cannot malloc extension_table space."); BZERO(ext, size); ext->filename = (char *)((ulong)ext + sizeof(struct extension_table)); /* * If the library is not specified by an absolute pathname, dlopen() * does not look in the current directory, so modify the filename. * If it's not in the current directory, check the extensions library * directory. */ if ((*lib != '.') && (*lib != '/')) { if (file_exists(lib, NULL)) sprintf(ext->filename, "./%s", lib); else if (in_extensions_library(lib, buf)) strcpy(ext->filename, buf); else { error(INFO, "%s: %s\n", lib, strerror(ENXIO)); free(ext); return; } } else strcpy(ext->filename, lib); if (!is_shared_object(ext->filename)) { error(INFO, "%s: not an ELF format object file\n", ext->filename); free(ext); return; } for (curext = extension_table; curext; curext = curext->next) { if (same_file(curext->filename, ext->filename)) { fprintf(fp, "%s: shared object already loaded\n", ext->filename); free(ext); return; } } /* * register_extension() will be called by the shared object's * _init() function before dlopen() returns below. */ pc->curext = ext; ext->handle = dlopen(ext->filename, RTLD_NOW|RTLD_GLOBAL); if (!ext->handle) { strcpy(buf, dlerror()); error(INFO, "%s\n", buf); if (strstr(buf, "undefined symbol: register_extension")) { error(INFO, "%s may be statically linked: ", pc->program_name); fprintf(fp, "recompile without the -static flag\n"); } free(ext); return; } if (!(ext->flags & REGISTERED)) { dlclose(ext->handle); if (ext->flags & (DUPLICATE_COMMAND_NAME | NO_MINIMAL_COMMANDS)) error(INFO, "%s: shared object unloaded\n", ext->filename); else error(INFO, "%s: no commands registered: shared object unloaded\n", ext->filename); free(ext); return; } fprintf(fp, "%s: shared object loaded\n", ext->filename); /* * Put new libraries at the head of the list. */ if (extension_table) { extension_table->prev = ext; ext->next = extension_table; } extension_table = ext; help_init(); } /* * Check the extensions library directories. */ static int in_extensions_library(char *lib, char *buf) { char *env; if ((env = getenv("CRASH_EXTENSIONS"))) { sprintf(buf, "%s%s%s", env, LASTCHAR(env) == '/' ? "" : "/", lib); if (file_exists(buf, NULL)) return TRUE; } if (BITS64()) { sprintf(buf, "/usr/lib64/crash/extensions/%s", lib); if (file_exists(buf, NULL)) return TRUE; } sprintf(buf, "/usr/lib/crash/extensions/%s", lib); if (file_exists(buf, NULL)) return TRUE; sprintf(buf, "./extensions/%s", lib); if (file_exists(buf, NULL)) return TRUE; return FALSE; } /* * Look for an extensions directory using the proper order. */ static char * get_extensions_directory(char *dirbuf, bool *end) { static int index = 0; char *dirs[] = { getenv("CRASH_EXTENSIONS"), BITS64() ? "/usr/lib64/crash/extensions" : NULL, "/usr/lib/crash/extensions", "./extensions", }; char *dir; if (index >= sizeof(dirs) / sizeof(char *)) { *end = true; return NULL; } *end = false; dir = dirs[index++]; if (is_directory(dir)) { snprintf(dirbuf, BUFSIZE, "%s", dir); return dir; } else { return NULL; } } void preload_extensions(void) { DIR *dirp; struct dirent *dp; char dirbuf[BUFSIZE]; char filename[BUFSIZE*2]; int found; bool end; next_dir: if (!get_extensions_directory(dirbuf, &end)) { if (end) return; else goto next_dir; } dirp = opendir(dirbuf); if (!dirp) { error(INFO, "%s: %s\n", dirbuf, strerror(errno)); goto next_dir; } pc->curcmd = pc->program_name; for (found = 0, dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { sprintf(filename, "%s%s%s", dirbuf, LASTCHAR(dirbuf) == '/' ? "" : "/", dp->d_name); if (!is_shared_object(filename)) continue; found++; load_extension(dp->d_name); } closedir(dirp); if (found) fprintf(fp, "\n"); else { error(NOTE, "%s: no extension modules found in directory\n\n", dirbuf); goto next_dir; } } /* * Unload all, or as specified, extension libraries. */ void unload_extension(char *lib) { struct extension_table *ext; int found; char buf[BUFSIZE]; if (!lib) { while (extension_table) { ext = extension_table; if (dlclose(ext->handle)) error(FATAL, "dlclose: %s: shared object not open\n", ext->filename); fprintf(fp, "%s: shared object unloaded\n", ext->filename); extension_table = ext->next; free(ext); } help_init(); return; } if ((*lib != '.') && (*lib != '/')) { if (!file_exists(lib, NULL) && in_extensions_library(lib, buf)) lib = buf; } if (!file_exists(lib, NULL)) { error(INFO, "%s: %s\n", lib, strerror(ENXIO)); return; } for (ext = extension_table, found = FALSE; ext; ext = ext->next) { if (same_file(lib, ext->filename)) { found = TRUE; if (dlclose(ext->handle)) error(INFO, "dlclose: %s: shared object not open\n", ext->filename); else { fprintf(fp, "%s: shared object unloaded\n", ext->filename); if (extension_table == ext) { /* first */ extension_table = ext->next; if (ext->next) ext->next->prev = NULL; } else if (ext->next == NULL) /* last */ ext->prev->next = NULL; else { /* middle */ ext->prev->next = ext->next; ext->next->prev = ext->prev; } free(ext); help_init(); break; } } else if (STREQ(basename(lib), basename(ext->filename))) { error(INFO, "%s and %s are different object files\n", lib, ext->filename); found = TRUE; } } if (!found) error(INFO, "%s: not loaded\n", lib); } /* * Register the command_table as long as there are no command namespace * clashes with the currently-existing command set. Also delete any aliases * that clash, giving the registered command name priority. * * This function is called from the shared object's _init() function * before the dlopen() call returns back to load_extension() above. * The mark of approval for load_extension() is the setting of the * REGISTERED bit in the "current" extension_table structure flags. */ void register_extension(struct command_table_entry *command_table) { struct command_table_entry *cp; pc->curext->flags |= NO_MINIMAL_COMMANDS; for (cp = command_table; cp->name; cp++) { if (get_command_table_entry(cp->name)) { error(INFO, "%s: \"%s\" is a duplicate of a currently-existing command\n", pc->curext->filename, cp->name); pc->curext->flags |= DUPLICATE_COMMAND_NAME; return; } if (cp->flags & MINIMAL) pc->curext->flags &= ~NO_MINIMAL_COMMANDS; } if ((pc->flags & MINIMAL_MODE) && (pc->curext->flags & NO_MINIMAL_COMMANDS)) { error(INFO, "%s: does not contain any commands which support minimal mode\n", pc->curext->filename); return; } if (pc->flags & MINIMAL_MODE) { for (cp = command_table; cp->name; cp++) { if (!(cp->flags & MINIMAL)) { error(WARNING, "%s: command \"%s\" does not support minimal mode\n", pc->curext->filename, cp->name); } } } for (cp = command_table; cp->name; cp++) { if (is_alias(cp->name)) { error(INFO, "alias \"%s\" deleted: name clash with extension command\n", cp->name); deallocate_alias(cp->name); } } pc->curext->command_table = command_table; pc->curext->flags |= REGISTERED; /* Mark of approval */ } /* * Hooks for sial. */ unsigned long get_curtask(void) { return CURRENT_TASK(); } char * crash_global_cmd(void) { return pc->curcmd; } struct command_table_entry * crash_cmd_table(void) { return pc->cmd_table; } crash-utility-crash-61fe107/extensions/000077500000000000000000000000001517256214500201535ustar00rootroot00000000000000crash-utility-crash-61fe107/extensions/Makefile000066400000000000000000000036351517256214500216220ustar00rootroot00000000000000# # Makefile for building crash shared object extensions # # Copyright (C) 2005, 2007, 2009, 2011, 2013 David Anderson # Copyright (C) 2005, 2007, 2009, 2011, 2013 Red Hat, Inc. All rights reserved. # # 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 2 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. # # To build the extension shared objects in this directory, run # "make extensions" from the top-level directory. # # To add a new extension object, simply copy your module's .c file # to this directory, and it will be built automatically using # the "standard" compile line. If that compile line does not # suffice, create a .mk file with the same prefix as the .c file, # and that makefile will be invoked. # CC ?= gcc CONTRIB_SO := $(patsubst %.c,%.so,$(wildcard *.c)) all: link_defs $(CONTRIB_SO) link_defs: @rm -f defs.h @ln ../defs.h $(CONTRIB_SO): %.so: %.c defs.h @if [ -f $*.mk ]; then \ $(MAKE) -f $*.mk; \ else \ grep -q '((constructor))' $*.c && { \ echo "$(CC) -Wall -g -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS)"; \ $(CC) -Wall -g -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS); \ } || { \ echo "$(CC) -Wall -g -nostartfiles -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS)"; \ $(CC) -Wall -g -nostartfiles -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS); \ }; \ fi clean: rm -f $(CONTRIB_SO) @for MAKEFILE in `grep -sl "^clean:" *.mk`; \ do $(MAKE) -f $$MAKEFILE clean; \ done crash-utility-crash-61fe107/extensions/dminfo.c000066400000000000000000001230751517256214500216030ustar00rootroot00000000000000/* dminfo.c - crash extension module for device-mapper analysis * * Copyright (C) 2005 NEC Corporation * Copyright (C) 2005 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #include "defs.h" /* From the crash source top-level directory */ void dminfo_init(void); void dminfo_fini(void); /* * Indices of size-offset array (Used by GET_xxx macros) * * DM__ */ enum { DM_hash_cell_name_list = 0, DM_hash_cell_name, DM_hash_cell_md, DM_mapped_device_disk, DM_mapped_device_map, DM_gendisk_major, DM_gendisk_first_minor, DM_gendisk_disk_name, DM_dm_table_num_targets, DM_dm_table_targets, DM_dm_table_devices, DM_dm_target_type, DM_dm_target_begin, DM_dm_target_len, DM_dm_target_private, DM_dm_dev_count, DM_dm_dev_bdev, DM_dm_dev_name, DM_dm_io_md, DM_dm_io_bio, DM_target_type_name, DM_target_io_io, DM_block_device_bd_disk, DM_bio_bi_private, DM_bio_list_head, DM_linear_c_dev, DM_linear_c_start, DM_multipath_hw_handler, DM_multipath_nr_priority_groups, DM_multipath_priority_groups, DM_multipath_nr_valid_paths, DM_multipath_current_pg, DM_multipath_queue_if_no_path, DM_multipath_queue_size, DM_hw_handler_type, DM_hw_handler_type_name, DM_priority_group_ps, DM_priority_group_pg_num, DM_priority_group_bypassed, DM_priority_group_nr_pgpaths, DM_priority_group_pgpaths, DM_path_selector_type, DM_path_selector_type_name, DM_pgpath_fail_count, DM_pgpath_path, DM_path_dev, DM_path_is_active, DM_mirror_set_rh, DM_mirror_set_reads, DM_mirror_set_writes, DM_mirror_set_in_sync, DM_mirror_set_nr_mirrors, DM_mirror_set_mirror, DM_region_hash_log, DM_region_hash_quiesced_regions, DM_region_hash_recovered_regions, DM_dirty_log_type, DM_dirty_log_type_name, DM_mirror_error_count, DM_mirror_dev, DM_mirror_offset, DM_crypt_config_dev, DM_crypt_config_iv_mode, DM_crypt_config_tfm, DM_crypt_config_key_size, DM_crypt_config_key, DM_crypto_tfm_crt_u, DM_crypto_tfm___crt_alg, DM_crypto_alg_cra_name, DM_cipher_tfm_cit_mode, DM_stripe_c_stripes, DM_stripe_c_chunk_mask, DM_stripe_c_stripe, DM_stripe_dev, DM_dm_snapshot_origin, DM_dm_snapshot_cow, DM_dm_snapshot_chunk_size, DM_dm_snapshot_valid, DM_dm_snapshot_type, NR_DMINFO_MEMBER_TABLE_ENTRY }; /* Size-offset array for structure's member */ static struct dminfo_member_entry { unsigned long offset; unsigned long size; } mbr_ary[NR_DMINFO_MEMBER_TABLE_ENTRY]; /* * Macros to retrieve data of given structure's member * * Macros except for the MSG assume 'struct s' is at 'addr' */ #define MSG(msg, s, m) msg ": " s "." m /* Initialize the size-offset array */ #define INIT_MBR_TABLE(s, m) \ do { \ if (!mbr_ary[DM_##s##_##m].size) { \ mbr_ary[DM_##s##_##m].offset = MEMBER_OFFSET("struct " #s, #m); \ mbr_ary[DM_##s##_##m].size = MEMBER_SIZE("struct " #s, #m); \ } \ } while (0) /* * Store the data of member m in ret. * Initialize the size-offset array for the member m if needed. */ #define GET_VALUE(addr, s, m, ret) \ do { \ INIT_MBR_TABLE(s, m); \ if (sizeof(ret) < mbr_ary[DM_##s##_##m].size) \ fprintf(fp, "%s\n", \ MSG("ERROR: GET_VALUE size_check", #s, #m)); \ readmem(addr + mbr_ary[DM_##s##_##m].offset, KVADDR, &ret, \ mbr_ary[DM_##s##_##m].size, MSG("GET_VALUE", #s, #m), \ FAULT_ON_ERROR);\ } while (0) /* * Store the address of member m in ret. * Initialize the size-offset array for the member m if needed. */ #define GET_ADDR(addr, s, m, ret) \ do { \ INIT_MBR_TABLE(s, m); \ ret = addr + mbr_ary[DM_##s##_##m].offset; \ } while (0) /* * Store the string data of member m in ret. * Initialize the size-offset array for the member m if needed. */ #define GET_STR(addr, s, m, ret, len) \ do { \ INIT_MBR_TABLE(s, m); \ if (!read_string(addr + mbr_ary[DM_##s##_##m].offset, ret, len - 1)) \ fprintf(fp, "%s\n", MSG("ERROR: GET_STR", #s, #m)); \ } while (0) /* * Store the string data pointed by member m in ret. * Initialize the size-offset array for the member m if needed. */ #define GET_PTR_STR(addr, s, m, ret, len) \ do { \ unsigned long tmp; \ INIT_MBR_TABLE(s, m); \ readmem(addr + mbr_ary[DM_##s##_##m].offset, KVADDR, &tmp, \ mbr_ary[DM_##s##_##m].size, MSG("GET_PTR_STR", #s, #m),\ FAULT_ON_ERROR);\ if (!read_string(tmp, ret, len - 1)) \ fprintf(fp, "%s\n", MSG("ERROR: GET_PTR_STR", #s, #m));\ } while (0) /* * Utility function/macro to walk the list */ static unsigned long get_next_from_list_head(unsigned long addr) { unsigned long ret; readmem(addr + OFFSET(list_head_next), KVADDR, &ret, sizeof(void *), MSG("get_next_from_list_head", "list_head", "next"), FAULT_ON_ERROR); return ret; } #define list_for_each(next, head, last) \ for (next = get_next_from_list_head(head), last = 0UL; \ next && next != head && next != last; \ last = next, next = get_next_from_list_head(next)) /* * device-mapper target analyzer * * device-mapper has various target driver: linear, mirror, multipath, etc. * Information specific to target is stored in its own way. * Target-specific analyzer is provided for each target driver for this reason. */ static struct dminfo_target_analyzer { struct dminfo_target_analyzer *next; char *target_name; int (*ready) (void); /* returns true if analyzer is available */ void (*show_table) (unsigned long); /* display table info */ void (*show_status) (unsigned long); /* display status info */ void (*show_queue) (unsigned long); /* display queued I/O info */ } analyzers_head; static void dminfo_register_target_analyzer(struct dminfo_target_analyzer *ta) { ta->next = analyzers_head.next; analyzers_head.next = ta; } static struct dminfo_target_analyzer *find_target_analyzer(char *target_type) { struct dminfo_target_analyzer *ta; for (ta = analyzers_head.next; ta; ta = ta->next) if (!strcmp(ta->target_name, target_type)) return ta; return NULL; } /* * zero target */ static int zero_ready(void) { return 1; } static void zero_show_table(unsigned long target) { unsigned long long start, len; /* Get target information */ GET_VALUE(target, dm_target, begin, start); GET_VALUE(target, dm_target, len, len); fprintf(fp, " begin:%llu len:%llu", start, len); } static void zero_show_status(unsigned long target) { /* zero target has no status */ fprintf(fp, " No status info"); } static void zero_show_queue(unsigned long target) { /* zero target has no queue */ fprintf(fp, " No queue info"); } static struct dminfo_target_analyzer zero_analyzer = { .target_name = "zero", .ready = zero_ready, .show_table = zero_show_table, .show_status = zero_show_status, .show_queue = zero_show_queue }; /* * error target */ static int error_ready(void) { return 1; } static void error_show_table(unsigned long target) { unsigned long long start, len; /* Get target information */ GET_VALUE(target, dm_target, begin, start); GET_VALUE(target, dm_target, len, len); fprintf(fp, " begin:%llu len:%llu", start, len); } static void error_show_status(unsigned long target) { /* error target has no status */ fprintf(fp, " No status info"); } static void error_show_queue(unsigned long target) { /* error target has no queue */ fprintf(fp, " No queue info"); } static struct dminfo_target_analyzer error_analyzer = { .target_name = "error", .ready = error_ready, .show_table = error_show_table, .show_status = error_show_status, .show_queue = error_show_queue }; /* * linear target */ static int linear_ready(void) { static int debuginfo = 0; if (debuginfo) return 1; if (STRUCT_EXISTS("struct linear_c")) { debuginfo = 1; return 1; } else fprintf(fp, "No such struct info: linear_c"); return 0; } static void linear_show_table(unsigned long target) { unsigned long lc, dm_dev; unsigned long long start, len, offset; char devt[BUFSIZE]; /* Get target information */ GET_VALUE(target, dm_target, begin, start); GET_VALUE(target, dm_target, len, len); GET_VALUE(target, dm_target, private, lc); GET_VALUE(lc, linear_c, dev, dm_dev); GET_STR(dm_dev, dm_dev, name, devt, BUFSIZE); GET_VALUE(lc, linear_c, start, offset); fprintf(fp, " begin:%llu len:%llu dev:%s offset:%llu", start, len, devt, offset); } static void linear_show_status(unsigned long target) { /* linear target has no status */ fprintf(fp, " No status info"); } static void linear_show_queue(unsigned long target) { /* linear target has no I/O queue */ fprintf(fp, " No queue info"); } static struct dminfo_target_analyzer linear_analyzer = { .target_name = "linear", .ready = linear_ready, .show_table = linear_show_table, .show_status = linear_show_status, .show_queue = linear_show_queue }; /* * mirror target */ static int mirror_ready(void) { static int debuginfo = 0; if (debuginfo) return 1; if (STRUCT_EXISTS("struct mirror_set")) { debuginfo = 1; return 1; } else fprintf(fp, "No such struct info: mirror_set"); return 0; } static void mirror_show_table(unsigned long target) { unsigned int i, nr_mir; unsigned long ms, rh, log, log_type, mir_size, mir_head, mir, dm_dev; unsigned long long offset; char buf[BUFSIZE]; /* Get the address of struct mirror_set */ GET_VALUE(target, dm_target, private, ms); /* Get the log-type name of the mirror_set */ GET_ADDR(ms, mirror_set, rh, rh); GET_VALUE(rh, region_hash, log, log); GET_VALUE(log, dirty_log, type, log_type); GET_PTR_STR(log_type, dirty_log_type, name, buf, BUFSIZE); fprintf(fp, " log:%s", buf); /* * Display information for each mirror disks. * * mir_head = mirror_set.mirror. * This is the head of struct mirror array. */ fprintf(fp, " dev:"); mir_size = STRUCT_SIZE("struct mirror"); GET_ADDR(ms, mirror_set, mirror, mir_head); GET_VALUE(ms, mirror_set, nr_mirrors, nr_mir); for (i = 0; i < nr_mir; i++) { mir = mir_head + mir_size * i; /* Get next mirror */ /* Get the devt of the mirror disk */ GET_VALUE(mir, mirror, dev, dm_dev); GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); /* Get the offset of the mirror disk */ GET_VALUE(mir, mirror, offset, offset); fprintf(fp, "%s(%llu)%s", buf, offset, i == nr_mir - 1 ? "" : ","); } if (i != nr_mir) fprintf(fp, " ERROR: dev are less than nr_mir:%d", nr_mir); } static void mirror_show_status(unsigned long target) { unsigned int i, nr_mir, synced, nr_error; unsigned long ms, mir_size, mir_head, mir, dm_dev; char buf[BUFSIZE]; /* Get the address of struct mirror_set */ GET_VALUE(target, dm_target, private, ms); /* Get the status info of the mirror_set */ GET_VALUE(ms, mirror_set, in_sync, synced); fprintf(fp, " in_sync:%d", synced); /* * Display information for each mirror disks. * * mir_head = mirror_set.mirror. * This is the head of struct mirror array. */ fprintf(fp, " dev:"); mir_size = STRUCT_SIZE("struct mirror"); GET_ADDR(ms, mirror_set, mirror, mir_head); GET_VALUE(ms, mirror_set, nr_mirrors, nr_mir); for (i = 0; i < nr_mir; i++) { mir = mir_head + mir_size * i; /* Get next mirror */ /* Get the devt of the mirror disk */ GET_VALUE(mir, mirror, dev, dm_dev); GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); /* Get the offset of the mirror disk */ GET_VALUE(mir, mirror, error_count, nr_error); fprintf(fp, "%s(%c,%d)%s", buf, nr_error ? 'D' : 'A', nr_error, i == nr_mir - 1 ? "" : ","); } if (i != nr_mir) fprintf(fp, " ERROR: dev are less than nr_mir:%d", nr_mir); } static void mirror_show_queue(unsigned long target) { unsigned long ms, rlist, wlist, rhead, whead; unsigned long rh, quis_head, rcov_head, quis_next, rcov_next; /* Get the address of struct mirror_set */ GET_VALUE(target, dm_target, private, ms); /* Get the address of queued I/O lists in struct mirror_set */ GET_ADDR(ms, mirror_set, reads, rlist); GET_ADDR(ms, mirror_set, writes, wlist); /* Get the head of queued I/O lists */ GET_VALUE(rlist, bio_list, head, rhead); GET_VALUE(wlist, bio_list, head, whead); fprintf(fp, " %s", rhead ? "reads" : "(reads)"); fprintf(fp, " %s", whead ? "writes" : "(writes)"); /* Get the address of the struct region_hash */ GET_ADDR(ms, mirror_set, rh, rh); /* Get the address of recover region lists in struct region_hash */ GET_ADDR(rh, region_hash, quiesced_regions, quis_head); GET_ADDR(rh, region_hash, recovered_regions, rcov_head); /* Get the head of recover region lists */ quis_next = get_next_from_list_head(quis_head); rcov_next = get_next_from_list_head(rcov_head); fprintf(fp, " %s", quis_next != quis_head ? "quiesced" : "(quiesced)"); fprintf(fp, " %s", rcov_next != rcov_head ? "recovered" : "(recovered)"); } static struct dminfo_target_analyzer mirror_analyzer = { .target_name = "mirror", .ready = mirror_ready, .show_table = mirror_show_table, .show_status = mirror_show_status, .show_queue = mirror_show_queue }; /* * multipath target */ static int multipath_ready(void) { static int debuginfo = 0; if (debuginfo) return 1; if (STRUCT_EXISTS("struct multipath")) { debuginfo = 1; return 1; } else fprintf(fp, "No such struct info: multipath"); return 0; } static void multipath_show_table(unsigned long target) { int i, j; unsigned int queue_if_no_path, nr_pgs, pg_id, nr_paths; unsigned long mp, hwh, hwh_type, ps, ps_type, path, dm_dev; unsigned long pg_head, pg_next, pg_last; unsigned long path_head, path_next, path_last; char name[BUFSIZE]; /* Get the address of struct multipath */ GET_VALUE(target, dm_target, private, mp); /* Get features information */ GET_VALUE(mp, multipath, queue_if_no_path, queue_if_no_path); /* Get the hardware-handler information */ GET_ADDR(mp, multipath, hw_handler, hwh); GET_VALUE(hwh, hw_handler, type, hwh_type); if (hwh_type) GET_PTR_STR(hwh_type, hw_handler_type, name, name, BUFSIZE); else strcpy(name, "none"); /* Get the number of priority groups */ GET_VALUE(mp, multipath, nr_priority_groups, nr_pgs); fprintf(fp, " queue_if_no_path:%d hwh:%s nr_pgs:%d\n", queue_if_no_path, name, nr_pgs); /* Display information for each priority group */ fprintf(fp, " %-2s %-13s %-8s %s", "PG", "PATH_SELECTOR", "NR_PATHS", "PATHS"); GET_ADDR(mp, multipath, priority_groups, pg_head); i = 0; list_for_each (pg_next, pg_head, pg_last) { /* pg_next == struct priority_group */ /* Get the index of the priority group */ GET_VALUE(pg_next, priority_group, pg_num, pg_id); /* Get the name of path selector */ GET_ADDR(pg_next, priority_group, ps, ps); GET_VALUE(ps, path_selector, type, ps_type); GET_PTR_STR(ps_type, path_selector_type, name, name, BUFSIZE); /* Get the number of paths in the priority group */ GET_VALUE(pg_next, priority_group, nr_pgpaths, nr_paths); fprintf(fp, "\n %-2d %-13s %-8d ", pg_id, name, nr_paths); /* Display information for each path */ GET_ADDR(pg_next, priority_group, pgpaths, path_head); j = 0; list_for_each (path_next, path_head, path_last) { /* path_next == struct pgpath */ /* Get the devt of the pgpath */ GET_ADDR(path_next, pgpath, path, path); GET_VALUE(path, path, dev, dm_dev); GET_STR(dm_dev, dm_dev, name, name, BUFSIZE); fprintf(fp, " %s", name); j++; } if (j != nr_paths) fprintf(fp, " ERROR: paths are less than nr_paths:%d", nr_paths); i++; } if (i != nr_pgs) fprintf(fp, " ERROR: pgs are less than nr_pgs:%d", nr_pgs); } static void multipath_show_status(unsigned long target) { int i, j; unsigned int queue_if_no_path, nr_pgs, pg_id, nr_paths; unsigned int bypassed_pg, path_active, nr_fails; unsigned long mp, hwh, hwh_type, cur_pg, path, dm_dev; unsigned long pg_head, pg_next, pg_last; unsigned long path_head, path_next, path_last; char buf[BUFSIZE], path_status; /* Get the address of struct multipath */ GET_VALUE(target, dm_target, private, mp); /* Get features information */ GET_VALUE(mp, multipath, queue_if_no_path, queue_if_no_path); /* Get the hardware-handler information */ GET_ADDR(mp, multipath, hw_handler, hwh); GET_VALUE(hwh, hw_handler, type, hwh_type); if (hwh_type) GET_PTR_STR(hwh_type, hw_handler_type, name, buf, BUFSIZE); else strcpy(buf, "none"); /* Get the number of priority groups */ GET_VALUE(mp, multipath, nr_priority_groups, nr_pgs); fprintf(fp, " queue_if_no_path:%d hwh:%s nr_pgs:%d\n", queue_if_no_path, buf, nr_pgs); /* Display information for each priority group */ fprintf(fp, " %-2s %-9s %-8s %s", "PG", "PG_STATUS", "NR_PATHS", "PATHS"); GET_ADDR(mp, multipath, priority_groups, pg_head); i = 0; list_for_each (pg_next, pg_head, pg_last) { /* pg_next == struct priority_group */ /* Get the index of the priority group */ GET_VALUE(pg_next, priority_group, pg_num, pg_id); /* Get the status of the priority group */ GET_VALUE(pg_next, priority_group, bypassed, bypassed_pg); if (bypassed_pg) strcpy(buf, "disabled"); else { GET_VALUE(mp, multipath, current_pg, cur_pg); if (pg_next == cur_pg) strcpy(buf, "active"); else strcpy(buf, "enabled"); } /* Get the number of paths in the priority group */ GET_VALUE(pg_next, priority_group, nr_pgpaths, nr_paths); fprintf(fp, "\n %-2d %-9s %-8d ", pg_id, buf, nr_paths); /* Display information for each path */ GET_ADDR(pg_next, priority_group, pgpaths, path_head); j = 0; list_for_each (path_next, path_head, path_last) { /* path_next == struct pgpath */ /* Get the devt of the pgpath */ GET_ADDR(path_next, pgpath, path, path); GET_VALUE(path, path, dev, dm_dev); GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); /* Get the status of the path */ GET_VALUE(path, path, is_active, path_active); GET_VALUE(path_next, pgpath, fail_count, nr_fails); path_status = path_active ? 'A' : 'F'; fprintf(fp, " %s(%c,%u)", buf, path_status, nr_fails); j++; } if (j != nr_paths) fprintf(fp, " ERROR: paths are less than nr_paths:%d", nr_paths); i++; } if (i != nr_pgs) fprintf(fp, " ERROR: pgs are less than nr_pgs:%d", nr_pgs); } static void multipath_show_queue(unsigned long target) { unsigned int queue_size; unsigned long mp; /* Get the address of struct multipath */ GET_VALUE(target, dm_target, private, mp); /* Get the size of queued I/Os in this 'target' */ GET_VALUE(mp, multipath, queue_size, queue_size); fprintf(fp, " queue_size:%d", queue_size); } static struct dminfo_target_analyzer multipath_analyzer = { .target_name = "multipath", .ready = multipath_ready, .show_table = multipath_show_table, .show_status = multipath_show_status, .show_queue = multipath_show_queue }; /* * crypt target */ static int crypt_ready(void) { static int debuginfo = 0; if (debuginfo) return 1; if (STRUCT_EXISTS("struct crypt_config")) { debuginfo = 1; return 1; } else fprintf(fp, "No such struct info: crypt_config"); return 0; } #define DMINFO_CRYPTO_TFM_MODE_ECB 0x00000001 #define DMINFO_CRYPTO_TFM_MODE_CBC 0x00000002 static void crypt_show_table(unsigned long target) { int i, cit_mode, key_size; unsigned long cc, tfm, crt_alg, cipher, iv_mode, dm_dev; char buf[BUFSIZE], *chainmode; /* Get the address of struct crypt_config */ GET_VALUE(target, dm_target, private, cc); /* Get the cipher name of the crypt_tfm */ GET_VALUE(cc, crypt_config, tfm, tfm); GET_VALUE(tfm, crypto_tfm, __crt_alg, crt_alg); GET_STR(crt_alg, crypto_alg, cra_name, buf, BUFSIZE); fprintf(fp, " type:%s", buf); /* Get the cit_mode of the crypt_tfm */ GET_ADDR(tfm, crypto_tfm, crt_u, cipher); GET_VALUE(cipher, cipher_tfm, cit_mode, cit_mode); if (MEMBER_EXISTS("struct crypt_config", "iv_mode")) { if (cit_mode == DMINFO_CRYPTO_TFM_MODE_CBC) chainmode = "cbc"; else if (cit_mode == DMINFO_CRYPTO_TFM_MODE_ECB) chainmode = "ecb"; else chainmode = "unknown"; /* Get the iv_mode of the crypt_config */ GET_VALUE(cc, crypt_config, iv_mode, iv_mode); if (iv_mode) { GET_PTR_STR(cc, crypt_config, iv_mode, buf, BUFSIZE); fprintf(fp, "-%s-%s", chainmode, buf); } else fprintf(fp, "-%s", chainmode); } else { /* Compatibility mode for old dm-crypt cipher strings */ if (cit_mode == DMINFO_CRYPTO_TFM_MODE_CBC) chainmode = "plain"; else if (cit_mode == DMINFO_CRYPTO_TFM_MODE_ECB) chainmode = "ecb"; else chainmode = "unknown"; fprintf(fp, "-%s", chainmode); } /* Get the devt of the crypt_config */ GET_VALUE(cc, crypt_config, dev, dm_dev); GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); fprintf(fp, " dev:%s", buf); /* * Get the key of the crypt_config. */ GET_VALUE(cc, crypt_config, key_size, key_size); GET_STR(cc, crypt_config, key, buf, MIN(key_size + 1, BUFSIZE)); fprintf(fp, " key:"); for (i = 0; i < key_size; i++) fprintf(fp, "%02x", (unsigned char)buf[i]); } static void crypt_show_status(unsigned long target) { /* crypt target has no status */ fprintf(fp, " No status info"); } static void crypt_show_queue(unsigned long target) { /* crypt target has no queue */ fprintf(fp, " No queue info"); } static struct dminfo_target_analyzer crypt_analyzer = { .target_name = "crypt", .ready = crypt_ready, .show_table = crypt_show_table, .show_status = crypt_show_status, .show_queue = crypt_show_queue }; /* * stripe target */ static int stripe_ready(void) { static int debuginfo = 0; if (debuginfo) return 1; if (STRUCT_EXISTS("struct stripe_c")) { debuginfo = 1; return 1; } else fprintf(fp, "No such struct info: stripe_c"); return 0; } static void stripe_show_table(unsigned long target) { unsigned int i, n_stripe; unsigned long sc, stripe_size, s, head, dm_dev; unsigned long long mask; char buf[BUFSIZE]; /* Get the address of struct stripe_c */ GET_VALUE(target, dm_target, private, sc); /* Get the chunk_size of the stripe_c */ GET_VALUE(sc, stripe_c, chunk_mask, mask); fprintf(fp, " chunk_size:%llu", mask + 1); /* * Display the information of each stripe disks. * * head = stripe_c.stripe. * This is the head of struct stripe array. */ stripe_size = STRUCT_SIZE("struct stripe"); GET_ADDR(sc, stripe_c, stripe, head); GET_VALUE(sc, stripe_c, stripes, n_stripe); fprintf(fp, " dev:"); for (i = 0; i < n_stripe; i++) { s = head + stripe_size * i; /* Get next stripe */ /* Get the devt of the stripe disk */ GET_VALUE(s, stripe, dev, dm_dev); GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); fprintf(fp, "%s%s", buf, i == n_stripe - 1 ? "" : ","); } if (i != n_stripe) fprintf(fp, " ERROR: dev are less than n_stripe:%d", n_stripe); } static void stripe_show_status(unsigned long target) { /* stripe target has no status */ fprintf(fp, " No status info"); } static void stripe_show_queue(unsigned long target) { /* stripe target has no queue */ fprintf(fp, " No queue info"); } static struct dminfo_target_analyzer stripe_analyzer = { .target_name = "striped", .ready = stripe_ready, .show_table = stripe_show_table, .show_status = stripe_show_status, .show_queue = stripe_show_queue }; /* * snapshot target */ static int snapshot_ready(void) { static int debuginfo = 0; if (debuginfo) return 1; if (STRUCT_EXISTS("struct dm_snapshot")) { debuginfo = 1; return 1; } else fprintf(fp, "No such struct info: dm_snapshot"); return 0; } static void snapshot_show_table(unsigned long target) { unsigned long snap, orig_dev, cow_dev; unsigned long long chunk_size; char orig_name[BUFSIZE], cow_name[BUFSIZE], type; /* Get the address of struct dm_snapshot */ GET_VALUE(target, dm_target, private, snap); /* Get snapshot parameters of the dm_snapshot */ GET_VALUE(snap, dm_snapshot, origin, orig_dev); GET_STR(orig_dev, dm_dev, name, orig_name, BUFSIZE); GET_VALUE(snap, dm_snapshot, cow, cow_dev); GET_STR(cow_dev, dm_dev, name, cow_name, BUFSIZE); GET_VALUE(snap, dm_snapshot, type, type); GET_VALUE(snap, dm_snapshot, chunk_size, chunk_size); fprintf(fp, " orig:%s cow:%s type:%c chunk_size:%llu", orig_name, cow_name, type, chunk_size); } static void snapshot_show_status(unsigned long target) { int valid; unsigned long snap; /* Get the address of struct dm_snapshot */ GET_VALUE(target, dm_target, private, snap); /* Get snapshot parameters of the dm_snapshot */ GET_VALUE(snap, dm_snapshot, valid, valid); fprintf(fp, " vaild:%d", valid); } static void snapshot_show_queue(unsigned long target) { fprintf(fp, " No queue info"); } static struct dminfo_target_analyzer snapshot_analyzer = { .target_name = "snapshot", .ready = snapshot_ready, .show_table = snapshot_show_table, .show_status = snapshot_show_status, .show_queue = snapshot_show_queue }; /* * snapshot-origin target */ static int origin_ready(void) { return 1; } static void origin_show_table(unsigned long target) { unsigned long dm_dev; char buf[BUFSIZE]; /* Get the name of the struct dm_dev */ GET_VALUE(target, dm_target, private, dm_dev); GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); fprintf(fp, " orig_dev:%s", buf); } static void origin_show_status(unsigned long target) { /* snapshot-origin target has no status */ fprintf(fp, " No status info"); } static void origin_show_queue(unsigned long target) { /* snapshot-origin target has no queue */ fprintf(fp, " No queue info"); } static struct dminfo_target_analyzer snapshot_origin_analyzer = { .target_name = "snapshot-origin", .ready = origin_ready, .show_table = origin_show_table, .show_status = origin_show_status, .show_queue = origin_show_queue }; /* * Core part of dminfo */ #define DMINFO_LIST 0 #define DMINFO_DEPS 1 #define DMINFO_TABLE 2 #define DMINFO_STATUS 3 #define DMINFO_QUEUE 4 static int dm_core_ready(void) { static int debuginfo = 0; if (debuginfo) return 1; if (STRUCT_EXISTS("struct hash_cell")) { debuginfo = 1; return 1; } else fprintf(fp, "No such struct info: hash_cell\n"); return 0; } /* Display dependency information of the 'table' */ static void dminfo_show_deps(unsigned long table) { int major, minor, count; unsigned long head, next, last, dev, bdev; char buf[BUFSIZE]; /* head = dm_table.devices */ GET_ADDR(table, dm_table, devices, head); fprintf(fp, " %-3s %-3s %-16s %-5s %s\n", "MAJ", "MIN", "GENDISK", "COUNT", "DEVNAME"); list_for_each (next, head, last) { /* Get dependency information. (next == struct *dm_dev) */ GET_VALUE(next, dm_dev, count, count); GET_VALUE(next, dm_dev, bdev, bdev); GET_VALUE(bdev, block_device, bd_disk, dev); GET_VALUE(dev, gendisk, major, major); GET_VALUE(dev, gendisk, first_minor, minor); GET_STR(dev, gendisk, disk_name, buf, BUFSIZE); fprintf(fp, " %-3d %-3d %-16lx %-5d %s\n", major, minor, dev, count, buf); } } /* * Display target specific information in the 'table', if the target * analyzer is registered and available. */ static void dminfo_show_details(unsigned long table, unsigned int num_targets, int info_type) { unsigned int i; unsigned long head, target_size, target, target_type; struct dminfo_target_analyzer *ta; char buf[BUFSIZE]; /* * head = dm_table.targets. * This is the head of struct dm_target array. */ GET_VALUE(table, dm_table, targets, head); target_size = STRUCT_SIZE("struct dm_target"); fprintf(fp, " %-16s %-11s %s\n", "TARGET", "TARGET_TYPE", "PRIVATE_DATA"); for (i = 0; i < num_targets; i++, fprintf(fp, "\n")) { target = head + target_size * i; /* Get next target */ /* Get target information */ GET_VALUE(target, dm_target, type, target_type); GET_PTR_STR(target_type, target_type, name, buf, BUFSIZE); fprintf(fp, " %-16lx %-11s", target, buf); if (!(ta = find_target_analyzer(buf)) || !ta->ready || !ta->ready()) continue; switch (info_type) { case DMINFO_TABLE: if (ta->show_table) ta->show_table(target); break; case DMINFO_STATUS: if (ta->show_status) ta->show_status(target); break; case DMINFO_QUEUE: if (ta->show_queue) ta->show_queue(target); break; default: break; } } if (i != num_targets) fprintf(fp, " ERROR: targets are less than num_targets:%d", num_targets); } /* * Display lists (and detail information if specified) of existing * dm devices. */ static void dminfo_show_list(int additional_info) { int i, major, minor, array_len; unsigned int num_targets; unsigned long _name_buckets, head, next, last, md, dev, table; char buf[BUFSIZE]; _name_buckets = symbol_value("_name_buckets"); array_len = get_array_length("_name_buckets", NULL, 0); if (additional_info == DMINFO_LIST) fprintf(fp, "%-3s %-3s %-16s %-16s %-7s %s\n", "MAJ", "MIN", "MAP_DEV", "DM_TABLE", "TARGETS", "MAPNAME"); for (i = 0; i < array_len; i++) { /* head = _name_buckets[i] */ head = _name_buckets + (i * SIZE(list_head)); list_for_each (next, head, last) { /* next == hash_cell */ /* Get device and table information */ GET_PTR_STR(next, hash_cell, name, buf, BUFSIZE); GET_VALUE(next, hash_cell, md, md); GET_VALUE(md, mapped_device, disk, dev); GET_VALUE(dev, gendisk, major, major); GET_VALUE(dev, gendisk, first_minor, minor); GET_VALUE(md, mapped_device, map, table); GET_VALUE(table, dm_table, num_targets, num_targets); if (additional_info != DMINFO_LIST) fprintf(fp, "%-3s %-3s %-16s %-16s %-7s %s\n", "MAJ", "MIN", "MAP_DEV", "DM_TABLE", "TARGETS", "MAPNAME"); fprintf(fp, "%-3d %-3d %-16lx %-16lx %-7d %s\n", major, minor, md, table, num_targets, buf); switch(additional_info) { case DMINFO_DEPS: dminfo_show_deps(table); break; case DMINFO_TABLE: case DMINFO_STATUS: case DMINFO_QUEUE: dminfo_show_details(table, num_targets, additional_info); break; default: break; } if (additional_info != DMINFO_LIST) fprintf(fp, "\n"); } } } /* * Display the original bio information for the 'bio'. * If the 'bio' is for dm devices, the original bio information is pointed * by bio.bi_private as struct target_io. */ static void dminfo_show_bio(unsigned long bio) { int major, minor; unsigned long target_io, dm_io, dm_bio, md, dev; char buf[BUFSIZE]; /* Get original bio and device information */ GET_VALUE(bio, bio, bi_private, target_io); GET_VALUE(target_io, target_io, io, dm_io); GET_VALUE(dm_io, dm_io, bio, dm_bio); GET_VALUE(dm_io, dm_io, md, md); GET_VALUE(md, mapped_device, disk, dev); GET_VALUE(dev, gendisk, major, major); GET_VALUE(dev, gendisk, first_minor, minor); GET_STR(dev, gendisk, disk_name, buf, BUFSIZE); fprintf(fp, "%-16s %-3s %-3s %-16s %s\n", "DM_BIO_ADDRESS", "MAJ", "MIN", "MAP_DEV", "DEVNAME"); fprintf(fp, "%-16lx %-3d %-3d %-16lx %s\n", dm_bio, major, minor, md, buf); } static void cmd_dminfo(void) { int c, additional_info = DMINFO_LIST; unsigned long bio; if (!dm_core_ready()) return; /* Parse command line option */ while ((c = getopt(argcnt, args, "b:dlqst")) != EOF) { switch(c) { case 'b': bio = stol(optarg, FAULT_ON_ERROR, NULL); dminfo_show_bio(bio); return; case 'd': additional_info = DMINFO_DEPS; break; case 'l': additional_info = DMINFO_LIST; break; case 'q': additional_info = DMINFO_QUEUE; break; case 's': additional_info = DMINFO_STATUS; break; case 't': additional_info = DMINFO_TABLE; break; default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); dminfo_show_list(additional_info); } /* * dminfo help */ static char *help_dminfo[] = { "dminfo", /* command name */ "device mapper (dm) information", /* short description */ "[-b bio | -d | -l | -q | -s | -t]", /* argument synopsis */ " This command displays information about device-mapper mapped ", " devices (dm devices).", " If no argument is entered, displays lists of existing dm devices.", " It's same as -l option.", "", " -b bio displays the information of the dm device which the bio", " is submitted in. If the bio isn't for dm devices,", " results will be error.", " -d displays dependency information for existing dm devices.", " -l displays lists of existing dm devices.", " -q displays queued I/O information for each target of", " existing dm devices.", " -s displays status information for each target of existing", " dm devices.", " -t displays table information for each target of existing", " dm devices.", "", "EXAMPLE", " Display lists of dm devices. \"MAP_DEV\" is the address of the", " struct mapped_device. \"DM_TABLE\" is the address of the struct", " dm_table. \"TARGETS\" is the number of targets which are in", " the struct dm_table.", "", " %s> dminfo", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 8 c4866c80 c4866280 1 vg0-snap0", " 253 6 f6a04a80 f6a04580 1 vg0-lv0-real", " 253 0 c4840380 c4841880 1 mp0", " 253 5 f7c50c80 c488e480 1 via_cbeheddbdd", " 253 7 c4866a80 c4866380 1 vg0-snap0-cow", " 253 4 d441e280 c919ed80 1 dummy1", " 253 3 f5dc4280 cba81d80 1 dummy0", " 253 2 f7c53180 c4866180 1 vg0-lv0", " 253 1 f746d280 f746cd80 1 mp0p1", "", " Display the dm device information which the bio is submitted in.", " The bio (ceacee80) is a clone of the bio (ceacee00) which is", " submitted in the dm-3 (dummy0). And the bio (ceacee00) is a clone", " of the bio (ceaced80) which is submitted in the dm-4 (dummy1), too.", " The bio (ceaced80) is the original bio.", "", " %s> dminfo -b ceacee80", " DM_BIO_ADDRESS MAJ MIN MAP_DEV DEVNAME", " ceacee00 253 3 f5dc4280 dm-3", " crash> dminfo -b ceacee00", " DM_BIO_ADDRESS MAJ MIN MAP_DEV DEVNAME", " ceaced80 253 4 d441e280 dm-4", " crash> dminfo -b ceaced80", " dminfo: invalid kernel virtual address: 64 type: \"GET_VALUE: dm_io.bio\"", "", " Display dependency information for each target.", " The vg0-snap0 depends on thd dm-6 (vg0-lv0-real) and the dm-7", " (vg0-snap0-cow)", "", " %s> dminfo -d", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 8 c4866c80 c4866280 1 vg0-snap0", " MAJ MIN GENDISK COUNT DEVNAME", " 253 7 c4866980 1 dm-7", " 253 6 f6a04280 1 dm-6", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 6 f6a04a80 f6a04580 1 vg0-lv0-real", " MAJ MIN GENDISK COUNT DEVNAME", " 8 0 f7f24c80 1 sda", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 7 c4866a80 c4866380 1 vg0-snap0-cow", " MAJ MIN GENDISK COUNT DEVNAME", " 8 0 f7f24c80 1 sda", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 2 f7c53180 c4866180 1 vg0-lv0", " MAJ MIN GENDISK COUNT DEVNAME", " 253 6 f6a04280 1 dm-6", "", " Display queued I/O information for each target.", " The information is displayed under the \"PRIVATE_DATA\" column.", "", " %s> dminfo -q", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 5 f7c50c80 c488e480 1 via_cbeheddbdd", " TARGET TARGET_TYPE PRIVATE_DATA", " f8961080 mirror (reads) (writes) (quiesced) (recovered)", "", " --------------------------------------------------------------", " \"reads/writes\" are members of the struct mirror_set, and", " \"quiesced/recovered\" are members of the struct region_hash.", " If the list is empty, the member is bracketed by \"()\".", " --------------------------------------------------------------", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 0 c4840380 c4841880 1 mp0", " TARGET TARGET_TYPE PRIVATE_DATA", " f8802080 multipath queue_size:0", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 1 f746d280 f746cd80 1 mp0p1", " TARGET TARGET_TYPE PRIVATE_DATA", " f8821080 linear No queue info", "", " Display status information for each target.", " The information is displayed under the \"PRIVATE_DATA\" column.", "", " %s> dminfo -s", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 0 c4840380 c4841880 1 mp0", " TARGET TARGET_TYPE PRIVATE_DATA", " f8802080 multipath queue_if_no_path:0 hwh:none nr_pgs:1", " PG PG_STATUS NR_PATHS PATHS", " 1 active 2 8:16(A,0) 8:32(A,0)", "", " --------------------------------------------------------------", " Format of \"PATHS\": :(,)", " Status: A:active, F:faulty", " Fail_count: the value of the struct pgpath.fail_count", " --------------------------------------------------------------", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 5 f7c50c80 c488e480 1 via_cbeheddbdd", " TARGET TARGET_TYPE PRIVATE_DATA", " f8961080 mirror in_sync:1 dev:8:16(A,0),8:32(A,0)", "", " --------------------------------------------------------------", " Format of \"dev\": :(,)", " Status: A:active, D:degraded", " Error_count: the value of the struct mirror.error_count", " --------------------------------------------------------------", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 1 f746d280 f746cd80 1 mp0p1", " TARGET TARGET_TYPE PRIVATE_DATA", " f8821080 linear No status info", "", " Display table information for each target.", " The information is displayed under the \"PRIVATE_DATA\" column.", "", " %s> dminfo -t", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 8 c4866c80 c4866280 1 vg0-snap0", " TARGET TARGET_TYPE PRIVATE_DATA", " f89b4080 snapshot orig:253:6 cow:253:7 type:P chunk_size:16", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 6 f6a04a80 f6a04580 1 vg0-lv0-real", " TARGET TARGET_TYPE PRIVATE_DATA", " f890f080 linear begin:0 len:204800 dev:8:5 offset:384", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 0 c4840380 c4841880 1 mp0", " TARGET TARGET_TYPE PRIVATE_DATA", " f8802080 multipath queue_if_no_path:0 hwh:none nr_pgs:1", " PG PATH_SELECTOR NR_PATHS PATHS", " 1 round-robin 2 8:16 8:32", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 5 f7c50c80 c488e480 1 via_cbeheddbdd", " TARGET TARGET_TYPE PRIVATE_DATA", " f8961080 mirror log:core dev:8:16(0),8:32(0)", "", " --------------------------------------------------------------", " Format of \"dev\": :()", " Offset: the value of the struct mirror.offset", " --------------------------------------------------------------", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 7 c4866a80 c4866380 1 vg0-snap0-cow", " TARGET TARGET_TYPE PRIVATE_DATA", " f899d080 linear begin:0 len:8192 dev:8:5 offset:205184", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 2 f7c53180 c4866180 1 vg0-lv0", " TARGET TARGET_TYPE PRIVATE_DATA", " f8bbc080 snapshot-origin orig_dev:253:6", "", " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", " 253 1 f746d280 f746cd80 1 mp0p1", " TARGET TARGET_TYPE PRIVATE_DATA", " f8821080 linear begin:0 len:2040192 dev:253:0 offset:63", NULL }; /* * Registering command extension */ static struct command_table_entry command_table[] = { {"dminfo", cmd_dminfo, help_dminfo, 0}, {NULL, NULL, NULL, 0}, }; void __attribute__((constructor)) dminfo_init(void) { register_extension(command_table); dminfo_register_target_analyzer(&zero_analyzer); dminfo_register_target_analyzer(&error_analyzer); dminfo_register_target_analyzer(&linear_analyzer); dminfo_register_target_analyzer(&mirror_analyzer); dminfo_register_target_analyzer(&multipath_analyzer); dminfo_register_target_analyzer(&crypt_analyzer); dminfo_register_target_analyzer(&stripe_analyzer); dminfo_register_target_analyzer(&snapshot_analyzer); dminfo_register_target_analyzer(&snapshot_origin_analyzer); } void __attribute__((destructor)) dminfo_fini(void) { } crash-utility-crash-61fe107/extensions/echo.c000066400000000000000000000067251517256214500212470ustar00rootroot00000000000000/* echo.c - simple example of a crash extension * * Copyright (C) 2001, 2002 Mission Critical Linux, Inc. * Copyright (C) 2002-2005, 2007, 2013 David Anderson * Copyright (C) 2002-2005, 2007, 2013 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #include "defs.h" /* From the crash source top-level directory */ static void echo_init(void); /* constructor function */ static void echo_fini(void); /* destructor function (optional) */ static void cmd_echo(void); /* Declare the commands and their help data. */ static char *help_echo[]; /* * Please making the functions and global variables static within your * extension if you don't want to make them visiable to subsequently * loaded extensions. Otherwise, non-static symbols within 2 extensions * that have the same name can cause confliction. */ static struct command_table_entry command_table[] = { { "echo", cmd_echo, help_echo, 0}, /* One or more commands, */ { NULL }, /* terminated by NULL, */ }; static void __attribute__((constructor)) echo_init(void) /* Register the command set. */ { register_extension(command_table); } /* * This function is called if the shared object is unloaded. * If desired, perform any cleanups here. */ static void __attribute__((destructor)) echo_fini(void) { } /* * Arguments are passed to the command functions in the global args[argcnt] * array. See getopt(3) for info on dash arguments. Check out defs.h and * other crash commands for usage of the myriad of utility routines available * to accomplish what your task. */ static void cmd_echo(void) { int c; while ((c = getopt(argcnt, args, "")) != EOF) { switch(c) { default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); while (args[optind]) fprintf(fp, "%s ", args[optind++]); fprintf(fp, "\n"); } /* * The optional help data is simply an array of strings in a defined format. * For example, the "help echo" command will use the help_echo[] string * array below to create a help page that looks like this: * * NAME * echo - echoes back its arguments * * SYNOPSIS * echo arg ... * * DESCRIPTION * This command simply echoes back its arguments. * * EXAMPLE * Echo back all command arguments: * * crash> echo hello, world * hello, world * */ static char *help_echo[] = { "echo", /* command name */ "echoes back its arguments", /* short description */ "arg ...", /* argument synopsis, or " " if none */ " This command simply echoes back its arguments.", "\nEXAMPLE", " Echo back all command arguments:\n", " crash> echo hello, world", " hello, world", NULL }; crash-utility-crash-61fe107/extensions/eppic.c000066400000000000000000000002131517256214500214130ustar00rootroot00000000000000/* Place holder for proper working of the extension Makefile. Eppic crash application file is in eppic/applications/crash/eppic.c */ crash-utility-crash-61fe107/extensions/eppic.mk000066400000000000000000000042441517256214500216100ustar00rootroot00000000000000# # 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 2 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. TARGET_FLAGS = -D$(TARGET) ifeq ($(TARGET), PPC64) TARGET_FLAGS += -m64 endif ifeq ($(TARGET), ARM) TARGET_FLAGS += -m32 endif ifeq ($(TARGET), MIPS) TARGET_FLAGS += -m32 endif ifeq ($(TARGET), X86) TARGET_FLAGS += -m32 endif APPFILE=eppic/applications/crash/eppic.c GIT := $(shell which git 2> /dev/null) # crash 8 with gdb 10 uses new third party callback (tcb) API EPPIC_BRANCH=v5.0 all: @if [ -f /usr/bin/flex ] && [ -f /usr/bin/bison ]; \ then \ if [ -f ../$(GDB)/crash.target ]; \ then \ if [ ! -f $(APPFILE) ]; \ then \ if [ -f "$(GIT)" ]; \ then \ if [ -n "$(EPPIC_GIT_URL)" ]; \ then \ git clone $(EPPIC_GIT_OPTIONS) $(EPPIC_GIT_URL) eppic; \ else \ if ping -c 1 -W 5 github.com >/dev/null ; then \ git clone -b $(EPPIC_BRANCH) $(EPPIC_GIT_OPTIONS) https://github.com/lucchouina/eppic.git eppic; \ fi; \ fi; \ else \ if [ ! -f "$(GIT)" ]; then \ echo "eppic.so: git command is needed for pulling eppic extension code"; \ fi; \ fi; \ fi; \ if [ -f $(APPFILE) ]; \ then \ make -f eppic.mk eppic.so; \ else \ echo "eppic.so: failed to pull eppic code from git repo"; \ fi; \ else \ echo "eppic.so: build failed: requires the crash $(GDB) module"; \ fi ;\ else \ echo "eppic.so: build failed: requires /usr/bin/flex and /usr/bin/bison"; \ fi lib-eppic: cd eppic/libeppic && make eppic.so: ../defs.h $(APPFILE) lib-eppic $(CC) -g -O0 -Ieppic/libeppic -I.. -nostartfiles -shared -rdynamic -o eppic.so $(APPFILE) -fPIC $(TARGET_FLAGS) $(GDB_FLAGS) -Leppic/libeppic -leppic clean: if [ -d eppic/libeppic ]; \ then \ cd eppic/libeppic && make -i clean; \ fi rm -f eppic.so crash-utility-crash-61fe107/extensions/snap.c000066400000000000000000000500451517256214500212640ustar00rootroot00000000000000/* snap.c - capture live memory into a kdump or netdump dumpfile * * Copyright (C) 2009, 2013, 2014, 2017 David Anderson * Copyright (C) 2009, 2013, 2014, 2017 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #include "defs.h" #include #include #include void snap_init(void); void snap_fini(void); void cmd_snap(void); char *help_snap[]; static struct command_table_entry command_table[] = { { "snap", cmd_snap, help_snap, 0 }, { NULL } }; static char *generate_elf_header(int, int, char *); static int verify_paddr(physaddr_t); static void init_ram_segments(void); static int print_progress(const char *, ulong); #if defined(X86) || defined(X86_64) || defined(IA64) || defined(PPC64) || defined(ARM64) int supported = TRUE; #else int supported = FALSE; #endif void __attribute__((constructor)) snap_init(void) /* Register the command set. */ { register_extension(command_table); } void __attribute__((destructor)) snap_fini(void) { } /* * Just pass in an unused filename. */ void cmd_snap(void) { int c, fd, n; physaddr_t paddr; size_t offset; char *buf; char *filename; struct node_table *nt; int type; char *elf_header; Elf64_Phdr *load; int load_index; if (!supported) error(FATAL, "command not supported on the %s architecture\n", pc->machine_type); filename = NULL; buf = GETBUF(PAGESIZE()); type = KDUMP_ELF64; while ((c = getopt(argcnt, args, "n")) != EOF) { switch(c) { case 'n': if (machine_type("X86_64")) option_not_supported('n'); else type = NETDUMP_ELF64; break; default: argerrs++; break; } } if (argerrs || !args[optind]) cmd_usage(pc->curcmd, SYNOPSIS); while (args[optind]) { if (filename) cmd_usage(pc->curcmd, SYNOPSIS); if (file_exists(args[optind], NULL)) error(FATAL, "%s: file already exists\n", args[optind]); else if ((fd = open(args[optind], O_RDWR|O_CREAT, 0644)) < 0) error(FATAL, args[optind]); filename = args[optind]; optind++; } if (!filename) cmd_usage(pc->curcmd, SYNOPSIS); init_ram_segments(); if (!(elf_header = generate_elf_header(type, fd, filename))) error(FATAL, "cannot generate ELF header\n"); load = (Elf64_Phdr *)(elf_header + sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr)); load_index = machine_type("X86_64") || machine_type("IA64") ? 1 : 0; for (n = 0; n < vt->numnodes; n++) { nt = &vt->node_table[n]; paddr = nt->start_paddr; offset = load[load_index + n].p_offset; for (c = 0; c < nt->size; c++, paddr += PAGESIZE()) { if (!verify_paddr(paddr)) continue; if (!readmem(paddr, PHYSADDR, &buf[0], PAGESIZE(), "memory page", QUIET|RETURN_ON_ERROR)) continue; lseek(fd, (off_t)(paddr + offset - nt->start_paddr), SEEK_SET); if (write(fd, &buf[0], PAGESIZE()) != PAGESIZE()) error(FATAL, "write to dumpfile failed\n"); if (!print_progress(filename, BTOP(paddr))) return; } } fprintf(stderr, "\r%s: [100%%] ", filename); fprintf(fp, "\n"); sprintf(buf, "/bin/ls -l %s\n", filename); system(buf); FREEBUF(elf_header); FREEBUF(buf); } char *help_snap[] = { "snap", /* command name */ "take a memory snapshot", /* short description */ "[-n] dumpfile", /* filename */ " This command takes a snapshot of physical memory and creates an ELF vmcore.", " The default vmcore is a kdump-style dumpfile. Supported on x86, x86_64,", " ia64 and ppc64 architectures only.", " ", " -n create a netdump-style vmcore (n/a on x86_64).", NULL }; /* * Architecture-specific and -generic ELF header data borrowed from the * netdump.h file in the netdump package, modified slightly to also create * a kdump-style vmcore. */ /****************************************************************************** * Elf core dumping * ******************************************************************************/ /* * Host-platform independent data */ #define ELF_PRARGSZ (80) /* Number of chars for args */ struct elf_prpsinfo_64 { char pr_state; /* numeric process state */ char pr_sname; /* char for pr_state */ char pr_zomb; /* zombie */ char pr_nice; /* nice val */ __u64 pr_flag; /* flags */ __u32 pr_uid; __u32 pr_gid; __u32 pr_pid, pr_ppid, pr_pgrp, pr_sid; /* Lots missing */ char pr_fname[16]; /* filename of executable */ char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */ }; /* * i386 specific */ struct user_regs_struct_i386 { __u32 ebx, ecx, edx, esi, edi, ebp, eax; __u16 ds, __ds, es, __es; __u16 fs, __fs, gs, __gs; __u32 orig_eax, eip; __u16 cs, __cs; __u32 eflags, esp; __u16 ss, __ss; }; #define ELF_NGREG_I386 (sizeof (struct user_regs_struct_i386) / sizeof(__u32)) typedef __u32 elf_gregset_i386_t[ELF_NGREG_I386]; struct elf_prstatus_i386 { char pad[72]; elf_gregset_i386_t pr_reg; /* GP registers */ __u32 pr_fpvalid; /* True if math co-processor being used. */ }; /* * x86_64 specific */ struct user_regs_struct_x86_64 { __u64 r15,r14,r13,r12,rbp,rbx,r11,r10; __u64 r9,r8,rax,rcx,rdx,rsi,rdi,orig_rax; __u64 rip,cs,eflags; __u64 rsp,ss; __u64 fs_base, gs_base; __u64 ds,es,fs,gs; }; #define ELF_NGREG_X86_64 (sizeof (struct user_regs_struct_x86_64) / sizeof(__u64)) typedef __u64 elf_gregset_x86_64_t[ELF_NGREG_X86_64]; struct elf_prstatus_x86_64 { char pad[112]; elf_gregset_x86_64_t pr_reg; /* GP registers */ __u32 pr_fpvalid; /* True if math co-processor being used. */ }; /* * ppc64 specific */ struct user_regs_struct_ppc64 { __u64 gpr[32]; __u64 nip; __u64 msr; __u64 orig_gpr3; __u64 ctr; __u64 link; __u64 xer; __u64 ccr; __u64 softe; __u64 trap; __u64 dar; __u64 dsisr; __u64 result; }; #define ELF_NGREG_PPC64 (sizeof (struct user_regs_struct_ppc64) / sizeof(__u64)) typedef __u64 elf_gregset_ppc64_t[ELF_NGREG_PPC64]; struct elf_prstatus_ppc64 { char pad[112]; elf_gregset_ppc64_t pr_reg; /* GP registers */ __u32 pr_fpvalid; /* True if math co-processor being used. */ }; /* * ia64 specific */ struct _ia64_fpreg { union { __u64 bits[2]; } u; } __attribute__ ((aligned (16))); struct user_regs_struct_ia64 { /* The following registers are saved by SAVE_MIN: */ __u64 b6; /* scratch */ __u64 b7; /* scratch */ __u64 ar_csd; /* used by cmp8xchg16 (scratch) */ __u64 ar_ssd; /* reserved for future use (scratch) */ __u64 r8; /* scratch (return value register 0) */ __u64 r9; /* scratch (return value register 1) */ __u64 r10; /* scratch (return value register 2) */ __u64 r11; /* scratch (return value register 3) */ __u64 cr_ipsr; /* interrupted task's psr */ __u64 cr_iip; /* interrupted task's instruction pointer */ __u64 cr_ifs; /* interrupted task's function state */ __u64 ar_unat; /* interrupted task's NaT register (preserved) */ __u64 ar_pfs; /* prev function state */ __u64 ar_rsc; /* RSE configuration */ /* The following two are valid only if cr_ipsr.cpl > 0: */ __u64 ar_rnat; /* RSE NaT */ __u64 ar_bspstore; /* RSE bspstore */ __u64 pr; /* 64 predicate registers (1 bit each) */ __u64 b0; /* return pointer (bp) */ __u64 loadrs; /* size of dirty partition << 16 */ __u64 r1; /* the gp pointer */ __u64 r12; /* interrupted task's memory stack pointer */ __u64 r13; /* thread pointer */ __u64 ar_fpsr; /* floating point status (preserved) */ __u64 r15; /* scratch */ /* The remaining registers are NOT saved for system calls. */ __u64 r14; /* scratch */ __u64 r2; /* scratch */ __u64 r3; /* scratch */ /* The following registers are saved by SAVE_REST: */ __u64 r16; /* scratch */ __u64 r17; /* scratch */ __u64 r18; /* scratch */ __u64 r19; /* scratch */ __u64 r20; /* scratch */ __u64 r21; /* scratch */ __u64 r22; /* scratch */ __u64 r23; /* scratch */ __u64 r24; /* scratch */ __u64 r25; /* scratch */ __u64 r26; /* scratch */ __u64 r27; /* scratch */ __u64 r28; /* scratch */ __u64 r29; /* scratch */ __u64 r30; /* scratch */ __u64 r31; /* scratch */ __u64 ar_ccv; /* compare/exchange value (scratch) */ /* * Floating point registers that the kernel considers scratch: */ struct _ia64_fpreg f6; /* scratch */ struct _ia64_fpreg f7; /* scratch */ struct _ia64_fpreg f8; /* scratch */ struct _ia64_fpreg f9; /* scratch */ struct _ia64_fpreg f10; /* scratch */ struct _ia64_fpreg f11; /* scratch */ }; #define ELF_NGREG_IA64 (sizeof (struct user_regs_struct_ia64) / sizeof(__u64)) typedef __u64 elf_gregset_ia64_t[ELF_NGREG_IA64]; struct elf_prstatus_ia64 { char pad[112]; elf_gregset_ia64_t pr_reg; /* GP registers */ __u32 pr_fpvalid; /* True if math co-processor being used. */ }; /* * arm64 specific */ struct user_pt_regs_arm64 { __u64 regs[31]; __u64 sp; __u64 pc; __u64 pstate; }; #define ELF_NGREG_ARM64 (sizeof (struct user_pt_regs_arm64) / sizeof(elf_greg_t)) #ifndef elf_greg_t typedef unsigned long elf_greg_t; #endif typedef elf_greg_t elf_gregset_arm64_t[ELF_NGREG_ARM64]; struct elf_prstatus_arm64 { char pad[112]; elf_gregset_arm64_t pr_reg; int pr_fpvalid; }; union prstatus { struct elf_prstatus_i386 x86; struct elf_prstatus_x86_64 x86_64; struct elf_prstatus_ppc64 ppc64; struct elf_prstatus_ia64 ia64; struct elf_prstatus_arm64 arm64; }; static size_t dump_elf_note(char *buf, Elf64_Word type, char *name, char *desc, int d_len) { Elf64_Nhdr *note; size_t len; note = (Elf64_Nhdr *)buf; note->n_namesz = strlen(name); note->n_descsz = d_len; note->n_type = type; len = sizeof(Elf64_Nhdr); memcpy(buf + len, name, note->n_namesz); len = roundup(len + note->n_namesz, 4); memcpy(buf + len, desc, note->n_descsz); len = roundup(len + note->n_descsz, 4); return len; } char * generate_elf_header(int type, int fd, char *filename) { int i, n; char *buffer, *ptr; Elf64_Ehdr *elf; Elf64_Phdr *notes; Elf64_Phdr *load; size_t offset, len, l_offset; size_t data_offset; struct elf_prpsinfo_64 prpsinfo; union prstatus prstatus; int prstatus_len; ushort e_machine; int num_segments; struct node_table *nt; struct SNAP_info { ulonglong task_struct; ulonglong arch_data1; ulonglong arch_data2; } SNAP_info; num_segments = vt->numnodes; if (machine_type("X86_64")) { e_machine = EM_X86_64; prstatus_len = sizeof(prstatus.x86_64); num_segments += 1; /* mapped kernel section for phys_base */ } else if (machine_type("X86")) { e_machine = EM_386; prstatus_len = sizeof(prstatus.x86); } else if (machine_type("IA64")) { e_machine = EM_IA_64; prstatus_len = sizeof(prstatus.ia64); num_segments += 1; /* mapped kernel section for phys_start */ } else if (machine_type("PPC64")) { e_machine = EM_PPC64; prstatus_len = sizeof(prstatus.ppc64); } else if (machine_type("ARM64")) { e_machine = EM_AARCH64; prstatus_len = sizeof(prstatus.arm64); } else return NULL; /* should be enought for the notes + roundup + two blocks */ buffer = (char *)GETBUF(sizeof(Elf64_Ehdr) + num_segments * sizeof(Elf64_Phdr) + PAGESIZE() * 2); offset = 0; ptr = buffer; /* Elf header */ elf = (Elf64_Ehdr *)ptr; memcpy(elf->e_ident, ELFMAG, SELFMAG); elf->e_ident[EI_CLASS] = ELFCLASS64; #if __BYTE_ORDER == __BIG_ENDIAN elf->e_ident[EI_DATA] = ELFDATA2MSB; #else elf->e_ident[EI_DATA] = ELFDATA2LSB; #endif elf->e_ident[EI_VERSION] = EV_CURRENT; elf->e_ident[EI_OSABI] = ELFOSABI_SYSV; elf->e_ident[EI_ABIVERSION] = 0; memset(elf->e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD); elf->e_type = ET_CORE; elf->e_machine = e_machine; elf->e_version = EV_CURRENT; elf->e_entry = 0; elf->e_phoff = sizeof(Elf64_Ehdr); elf->e_shoff = 0; elf->e_flags = 0; elf->e_ehsize = sizeof(Elf64_Ehdr); elf->e_phentsize = sizeof(Elf64_Phdr); elf->e_phnum = 1 + num_segments; elf->e_shentsize = 0; elf->e_shnum = 0; elf->e_shstrndx = 0; offset += sizeof(Elf64_Ehdr); ptr += sizeof(Elf64_Ehdr); /* PT_NOTE */ notes = (Elf64_Phdr *)ptr; notes->p_type = PT_NOTE; notes->p_offset = 0; /* TO BE FILLED IN */ notes->p_vaddr = 0; notes->p_paddr = 0; notes->p_filesz = 0; /* TO BE FILLED IN */ notes->p_memsz = 0; notes->p_flags = 0; notes->p_align = 0; offset += sizeof(Elf64_Phdr); ptr += sizeof(Elf64_Phdr); /* PT_LOAD */ load = (Elf64_Phdr *)ptr; for (i = n = 0; i < num_segments; i++) { load[i].p_type = PT_LOAD; load[i].p_offset = 0; /* TO BE FILLED IN */ switch (e_machine) { case EM_X86_64: nt = &vt->node_table[n]; if (i == 0) { #ifdef X86_64 load[i].p_vaddr = __START_KERNEL_map; load[i].p_paddr = machdep->machspec->phys_base; #endif load[i].p_filesz = 0; load[i].p_memsz = load[i].p_filesz; } else { load[i].p_vaddr = PTOV(nt->start_paddr); load[i].p_paddr = nt->start_paddr; load[i].p_filesz = nt->size * PAGESIZE(); load[i].p_memsz = load[i].p_filesz; n++; } load[i].p_flags = PF_R | PF_W | PF_X; load[i].p_align = 0; break; case EM_386: nt = &vt->node_table[n++]; load[i].p_vaddr = 0; load[i].p_paddr = nt->start_paddr; load[i].p_filesz = nt->size * PAGESIZE(); load[i].p_memsz = load[i].p_filesz; load[i].p_flags = PF_R | PF_W | PF_X; load[i].p_align = (type == NETDUMP_ELF64) ? PAGESIZE() : 0; break; case EM_IA_64: nt = &vt->node_table[n]; if (i == 0) { #ifdef IA64 load[i].p_vaddr = machdep->machspec->kernel_start; load[i].p_paddr = machdep->machspec->phys_start; #endif load[i].p_filesz = 0; load[i].p_memsz = load[i].p_filesz; } else { load[i].p_vaddr = PTOV(nt->start_paddr); load[i].p_paddr = nt->start_paddr; load[i].p_filesz = nt->size * PAGESIZE(); load[i].p_memsz = load[i].p_filesz; n++; } load[i].p_flags = PF_R | PF_W | PF_X; load[i].p_align = (type == NETDUMP_ELF64) ? PAGESIZE() : 0; break; case EM_PPC64: nt = &vt->node_table[n++]; load[i].p_vaddr = PTOV(nt->start_paddr); load[i].p_paddr = nt->start_paddr; load[i].p_filesz = nt->size * PAGESIZE(); load[i].p_memsz = load[i].p_filesz; load[i].p_flags = PF_R | PF_W | PF_X; load[i].p_align = (type == NETDUMP_ELF64) ? PAGESIZE() : 0; break; case EM_AARCH64: nt = &vt->node_table[n++]; load[i].p_vaddr = PTOV(nt->start_paddr); load[i].p_paddr = nt->start_paddr; load[i].p_filesz = nt->size * PAGESIZE(); load[i].p_memsz = load[i].p_filesz; load[i].p_flags = PF_R | PF_W | PF_X; load[i].p_align = (type == NETDUMP_ELF64) ? PAGESIZE() : 0; break; } // l_offset += load[i].p_filesz; offset += sizeof(Elf64_Phdr); ptr += sizeof(Elf64_Phdr); } notes->p_offset = offset; /* NT_PRSTATUS note */ memset(&prstatus, 0, sizeof(prstatus)); len = dump_elf_note(ptr, NT_PRSTATUS, "CORE", (char *)&prstatus, prstatus_len); offset += len; ptr += len; notes->p_filesz += len; /* NT_PRPSINFO note */ memset(&prpsinfo, 0, sizeof(struct elf_prpsinfo_64)); prpsinfo.pr_state = 0; prpsinfo.pr_sname = 'R'; prpsinfo.pr_zomb = 0; strcpy(prpsinfo.pr_fname, "vmlinux"); len = dump_elf_note(ptr, NT_PRPSINFO, "CORE", (char *)&prpsinfo, sizeof(prpsinfo)); offset += len; ptr += len; notes->p_filesz += len; /* NT_TASKSTRUCT note */ SNAP_info.task_struct = CURRENT_TASK(); #ifdef X86_64 SNAP_info.arch_data1 = kt->relocate; SNAP_info.arch_data2 = 0; #elif ARM64 SNAP_info.arch_data1 = machdep->machspec->kimage_voffset; SNAP_info.arch_data2 = (machdep->machspec->VA_BITS_ACTUAL << 32) | machdep->machspec->CONFIG_ARM64_VA_BITS; #else SNAP_info.arch_data1 = 0; SNAP_info.arch_data2 = 0; #endif len = dump_elf_note (ptr, NT_TASKSTRUCT, "SNAP", (char *)&SNAP_info, sizeof(struct SNAP_info)); offset += len; ptr += len; notes->p_filesz += len; if (type == NETDUMP_ELF64) offset = roundup (offset, PAGESIZE()); l_offset = offset; for (i = 0; i < num_segments; i++) { load[i].p_offset = l_offset; l_offset += load[i].p_filesz; } data_offset = offset; while (offset > 0) { len = write(fd, buffer + (data_offset - offset), offset); if (len < 0) { perror(filename); FREEBUF(buffer); return NULL; } offset -= len; } return buffer; } struct ram_segments { physaddr_t start; physaddr_t end; }; static struct ram_segments *ram_segments = NULL; static int nr_segments = 0; static void init_ram_segments(void) { int i, errflag; FILE *iomem; char buf[BUFSIZE], *p1, *p2; physaddr_t start, end; if ((iomem = fopen("/proc/iomem", "r")) == NULL) goto fail_iomem; while (fgets(buf, BUFSIZE, iomem)) { if (strstr(buf, "System RAM")) { console(buf); nr_segments++; } } if (!nr_segments) goto fail_iomem; ram_segments = (struct ram_segments *) GETBUF(sizeof(struct ram_segments) * nr_segments); rewind(iomem); i = 0; while (fgets(buf, BUFSIZE, iomem)) { if (strstr(buf, "System RAM")) { if (!(p1 = strstr(buf, ":"))) goto fail_iomem; *p1 = NULLCHAR; clean_line(buf); if (strstr(buf, " ")) goto fail_iomem; p1 = buf; if (!(p2 = strstr(buf, "-"))) goto fail_iomem; *p2 = NULLCHAR; p2++; errflag = 0; start = htoll(p1, RETURN_ON_ERROR|QUIET, &errflag); end = htoll(p2, RETURN_ON_ERROR|QUIET, &errflag); if (errflag) goto fail_iomem; ram_segments[i].start = PHYSPAGEBASE(start); if (PAGEOFFSET(start)) ram_segments[i].start += PAGESIZE(); ram_segments[i].end = PHYSPAGEBASE(end); if (PAGEOFFSET(end) == (PAGESIZE()-1)) ram_segments[i].end += PAGESIZE(); console("ram_segments[%d]: %016llx %016llx [%s-%s]\n", i, (ulonglong)ram_segments[i].start, (ulonglong)ram_segments[i].end, p1, p2); i++; } } fclose(iomem); return; fail_iomem: fclose(iomem); nr_segments = 0; if (ram_segments) FREEBUF(ram_segments); return; } static int verify_paddr(physaddr_t paddr) { int i, ok; if (!machdep->verify_paddr(paddr)) return FALSE; if (!nr_segments) return TRUE; for (i = ok = 0; i < nr_segments; i++) { if ((paddr >= ram_segments[i].start) && (paddr < ram_segments[i].end)) { ok++; break; } } /* * Pre-2.6.13 x86_64 /proc/iomem was restricted to 4GB, * so just accept it. */ if ((paddr >= 0x100000000ULL) && machine_type("X86_64") && (THIS_KERNEL_VERSION < LINUX(2,6,13))) ok++; if (!ok) { if (CRASHDEBUG(1)) console("reject: %llx\n", (ulonglong)paddr); return FALSE; } return TRUE; } /* * Borrowed from makedumpfile, prints a percentage-done value * once per second. */ static int print_progress(const char *filename, ulong current) { int n, progress; time_t tm; struct node_table *nt; static time_t last_time = 0; static ulong total_pages = 0; static ulong written_pages = 0; if (!total_pages) { for (n = 0; n < vt->numnodes; n++) { nt = &vt->node_table[n]; total_pages += nt->size; } } if (received_SIGINT()) { fprintf(stderr, "\n\n"); return FALSE; } if (++written_pages < total_pages) { tm = time(NULL); if (tm - last_time < 1) return TRUE; last_time = tm; progress = written_pages * 100 / total_pages; } else progress = 100; fprintf(stderr, "\r%s: [%2d%%] ", filename, progress); return TRUE; } crash-utility-crash-61fe107/extensions/snap.mk000066400000000000000000000026011517256214500214440ustar00rootroot00000000000000# # Copyright (C) 2009, 2011, 2013 David Anderson # Copyright (C) 2009, 2011, 2013 Red Hat, Inc. All rights reserved. # # 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 2 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. # ifeq ($(shell arch), i686) TARGET=X86 TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64 endif ifeq ($(shell arch), ppc64) TARGET=PPC64 TARGET_CFLAGS=-m64 endif ifeq ($(shell arch), ppc64le) TARGET=PPC64 TARGET_CFLAGS=-m64 endif ifeq ($(shell arch), ia64) TARGET=IA64 TARGET_CFLAGS= endif ifeq ($(shell arch), x86_64) TARGET=X86_64 TARGET_CFLAGS= endif ifeq ($(shell /bin/ls /usr/include/crash/defs.h 2>/dev/null), /usr/include/crash/defs.h) INCDIR=/usr/include/crash endif ifeq ($(shell /bin/ls ../defs.h 2> /dev/null), ../defs.h) INCDIR=.. endif ifeq ($(shell /bin/ls ./defs.h 2> /dev/null), ./defs.h) INCDIR=. endif all: snap.so snap.so: $(INCDIR)/defs.h snap.c $(CC) -Wall -g -I$(INCDIR) -shared -rdynamic -o snap.so snap.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS) crash-utility-crash-61fe107/filesys.c000066400000000000000000003500531517256214500176040ustar00rootroot00000000000000/* filesys.c - core analysis suite * * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. * Copyright (C) 2002-2019 David Anderson * Copyright (C) 2002-2019 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #include "defs.h" #include #include #include #include static void show_mounts(ulong, int, struct task_context *); static int find_booted_kernel(void); static int find_booted_system_map(void); static int verify_utsname(char *); static char **build_searchdirs(int, int *); static int build_kernel_directory(char *); static int redhat_kernel_directory_v1(char *); static int redhat_kernel_directory_v2(char *); static int redhat_debug_directory(char *); static ulong *create_dentry_array(ulong, int *); static ulong *create_dentry_array_percpu(ulong, int *); static void show_fuser(char *, char *); static int mount_point(char *); static int open_file_reference(struct reference *); static void memory_source_init(void); static int get_pathname_component(ulong, ulong, int, char *, char *); char *inode_type(char *, char *); static void match_proc_version(void); static void get_live_memory_source(void); static int memory_driver_module_loaded(int *); static int insmod_memory_driver_module(void); static int get_memory_driver_dev(dev_t *); static int memory_driver_init(void); static int create_memory_device(dev_t); static int match_file_string(char *, char *, char *); static ulong get_root_vfsmount(char *); static void check_live_arch_mismatch(void); static long get_inode_nrpages(ulong); static void dump_inode_page_cache_info(ulong); #define DENTRY_CACHE (20) #define INODE_CACHE (20) #define FILE_CACHE (20) static struct filesys_table { char *dentry_cache; ulong cached_dentry[DENTRY_CACHE]; ulong cached_dentry_hits[DENTRY_CACHE]; int dentry_cache_index; ulong dentry_cache_fills; char *inode_cache; ulong cached_inode[INODE_CACHE]; ulong cached_inode_hits[INODE_CACHE]; int inode_cache_index; ulong inode_cache_fills; char *file_cache; ulong cached_file[FILE_CACHE]; ulong cached_file_hits[FILE_CACHE]; int file_cache_index; ulong file_cache_fills; } filesys_table = { 0 }; static struct filesys_table *ft = &filesys_table; /* * Open the namelist, dumpfile and output devices. */ void fd_init(void) { pc->nfd = pc->kfd = pc->mfd = pc->dfd = -1; if ((pc->nullfp = fopen("/dev/null", "w+")) == NULL) error(INFO, "cannot open /dev/null (for extraneous output)"); if (REMOTE()) remote_fd_init(); else { if (pc->namelist && pc->namelist_debug && pc->system_map) { error(INFO, "too many namelist options:\n %s\n %s\n %s\n", pc->namelist, pc->namelist_debug, pc->system_map); program_usage(SHORT_FORM); } if (pc->namelist) { if (XEN_HYPER_MODE() && !pc->dumpfile) error(FATAL, "Xen hypervisor mode requires a dumpfile\n"); if (!pc->dumpfile && !get_proc_version()) error(INFO, "/proc/version: %s\n", strerror(errno)); } else { if (pc->dumpfile) { error(INFO, "namelist argument required\n"); program_usage(SHORT_FORM); } if (!pc->dumpfile) check_live_arch_mismatch(); if (!find_booted_kernel()) program_usage(SHORT_FORM); } if (!pc->dumpfile) { pc->flags |= LIVE_SYSTEM; get_live_memory_source(); } if ((pc->nfd = open(pc->namelist, O_RDONLY)) < 0) error(FATAL, "%s: %s\n", pc->namelist, strerror(errno)); else { close(pc->nfd); pc->nfd = -1; } if (LOCAL_ACTIVE() && !(pc->namelist_debug || pc->system_map)) { memory_source_init(); match_proc_version(); } } memory_source_init(); if (ACTIVE()) proc_kcore_init(fp, UNUSED); if (CRASHDEBUG(1)) { fprintf(fp, "readmem: %s() ", readmem_function_name()); if (ACTIVE()) { fprintf(fp, "-> %s ", pc->live_memsrc); if (pc->flags & MEMMOD) fprintf(fp, "(module)"); else if (pc->flags & CRASHBUILTIN) fprintf(fp, "(built-in)"); } fprintf(fp, "\n"); } } /* * Do whatever's necessary to handle the memory source. */ static void memory_source_init(void) { if (REMOTE() && !(pc->flags2 & MEMSRC_LOCAL)) return; if (pc->flags & KERNEL_DEBUG_QUERY) return; if (LOCAL_ACTIVE()) { if (pc->mfd != -1) /* already been here */ return; if (!STREQ(pc->live_memsrc, "/dev/mem") && STREQ(pc->live_memsrc, pc->memory_device)) { if (memory_driver_init()) return; error(INFO, "cannot initialize crash memory driver\n"); error(INFO, "using /dev/mem\n\n"); pc->flags &= ~MEMMOD; pc->flags |= DEVMEM; pc->readmem = read_dev_mem; pc->writemem = write_dev_mem; pc->live_memsrc = "/dev/mem"; } if (STREQ(pc->live_memsrc, "/dev/mem")) { if ((pc->mfd = open("/dev/mem", O_RDWR)) < 0) { if ((pc->mfd = open("/dev/mem", O_RDONLY)) < 0) error(FATAL, "/dev/mem: %s\n", strerror(errno)); } else pc->flags |= MFD_RDWR; } else if (STREQ(pc->live_memsrc, "/proc/kcore")) { if ((pc->mfd = open("/proc/kcore", O_RDONLY)) < 0) error(FATAL, "/proc/kcore: %s\n", strerror(errno)); if (!proc_kcore_init(fp, pc->mfd)) error(FATAL, "/proc/kcore: initialization failed\n"); } else { if (!pc->live_memsrc) error(FATAL, "cannot find a live memory device\n"); else error(FATAL, "unknown memory device: %s\n", pc->live_memsrc); } return; } if (pc->dumpfile) { if (!file_exists(pc->dumpfile, NULL)) error(FATAL, "%s: %s\n", pc->dumpfile, strerror(ENOENT)); if (!(pc->flags & DUMPFILE_TYPES)) error(FATAL, "%s: dump format not supported!\n", pc->dumpfile); if (pc->flags & NETDUMP) { if (!netdump_init(pc->dumpfile, fp)) error(FATAL, "%s: initialization failed\n", pc->dumpfile); } else if (pc->flags & KDUMP) { if (!kdump_init(pc->dumpfile, fp)) error(FATAL, "%s: initialization failed\n", pc->dumpfile); } else if (pc->flags & XENDUMP) { if (!xendump_init(pc->dumpfile, fp)) error(FATAL, "%s: initialization failed\n", pc->dumpfile); } else if (pc->flags & KVMDUMP) { if (!kvmdump_init(pc->dumpfile, fp)) error(FATAL, "%s: initialization failed\n", pc->dumpfile); } else if (pc->flags & DISKDUMP) { if (!diskdump_init(pc->dumpfile, fp)) error(FATAL, "%s: initialization failed\n", pc->dumpfile); } else if (pc->flags & LKCD) { if ((pc->dfd = open(pc->dumpfile, O_RDONLY)) < 0) error(FATAL, "%s: %s\n", pc->dumpfile, strerror(errno)); if (!lkcd_dump_init(fp, pc->dfd, pc->dumpfile)) error(FATAL, "%s: initialization failed\n", pc->dumpfile); } else if (pc->flags & S390D) { if (!s390_dump_init(pc->dumpfile)) error(FATAL, "%s: initialization failed\n", pc->dumpfile); } else if (pc->flags & VMWARE_VMSS) { if (pc->flags2 & VMWARE_VMSS_GUESTDUMP) { if (!vmware_guestdump_init(pc->dumpfile, fp)) error(FATAL, "%s: initialization failed\n", pc->dumpfile); } else { if (!vmware_vmss_init(pc->dumpfile, fp)) error(FATAL, "%s: initialization failed\n", pc->dumpfile); } } } } /* * If only a namelist argument is entered for a live system, and the * version string doesn't match /proc/version, try to avert a failure * by assigning it to a matching System.map. */ static void match_proc_version(void) { char buffer[BUFSIZE], *p1, *p2; if (pc->flags & KERNEL_DEBUG_QUERY) return; if (!strlen(kt->proc_version)) return; if (match_file_string(pc->namelist, kt->proc_version, buffer)) { if (CRASHDEBUG(1)) { fprintf(fp, "/proc/version:\n%s\n", kt->proc_version); fprintf(fp, "%s:\n%s", pc->namelist, buffer); } return; } error(WARNING, "%s%sand /proc/version do not match!\n\n", pc->namelist, strlen(pc->namelist) > 39 ? "\n " : " "); /* * find_booted_system_map() requires VTOP(), which used to be a * hardwired masking of the kernel address. But some architectures * may not know what their physical base address is at this point, * and others may have different machdep->kvbase values, so for all * but the 0-based kernel virtual address architectures, bail out * here with a relevant error message. */ if (!machine_type("S390") && !machine_type("S390X")) { p1 = &kt->proc_version[strlen("Linux version ")]; p2 = strstr(p1, " "); *p2 = NULLCHAR; error(WARNING, "/proc/version indicates kernel version: %s\n", p1); error(FATAL, "please use the vmlinux file for that kernel version, or try using\n" " the System.map for that kernel version as an additional argument.\n", p1); clean_exit(1); } if (find_booted_system_map()) pc->flags |= SYSMAP; } #define CREATE 1 #define DESTROY 0 #define DEFAULT_SEARCHDIRS 6 #define EXTRA_SEARCHDIRS 5 static char ** build_searchdirs(int create, int *preferred) { int i; int cnt, start; DIR *dirp; struct dirent *dp; char dirbuf[BUFSIZE]; static char **searchdirs = { 0 }; static char *default_searchdirs[DEFAULT_SEARCHDIRS+1] = { "/usr/src/linux/", "/boot/", "/boot/efi/redhat", "/boot/efi/EFI/redhat", "/usr/lib/debug/boot/", "/", NULL }; if (!create) { if (searchdirs) { for (i = DEFAULT_SEARCHDIRS; searchdirs[i]; i++) free(searchdirs[i]); free(searchdirs); } return NULL; } if (preferred) *preferred = 0; /* * Allow, at a minimum, the defaults plus an extra four directories: * * /lib/modules * /usr/src/redhat/BUILD/kernel-/linux * /usr/src/redhat/BUILD/kernel-/linux- * /usr/lib/debug/lib/modules * */ cnt = DEFAULT_SEARCHDIRS + EXTRA_SEARCHDIRS; if ((dirp = opendir("/usr/src"))) { for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) cnt++; if ((searchdirs = calloc(cnt, sizeof(char *))) == NULL) { error(INFO, "/usr/src/ directory list malloc: %s\n", strerror(errno)); closedir(dirp); return default_searchdirs; } for (i = 0; i < DEFAULT_SEARCHDIRS; i++) searchdirs[i] = default_searchdirs[i]; cnt = DEFAULT_SEARCHDIRS; rewinddir(dirp); for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { if (STREQ(dp->d_name, "linux") || STREQ(dp->d_name, "redhat") || STREQ(dp->d_name, ".") || STREQ(dp->d_name, "..")) continue; sprintf(dirbuf, "/usr/src/%s", dp->d_name); if (mount_point(dirbuf)) continue; if (!is_directory(dirbuf)) continue; if ((searchdirs[cnt] = (char *) malloc(strlen(dirbuf)+2)) == NULL) { error(INFO, "/usr/src/ directory entry malloc: %s\n", strerror(errno)); break; } sprintf(searchdirs[cnt], "%s/", dirbuf); cnt++; } closedir(dirp); searchdirs[cnt] = NULL; } else { if ((searchdirs = calloc(cnt, sizeof(char *))) == NULL) { error(INFO, "search directory list malloc: %s\n", strerror(errno)); return default_searchdirs; } for (i = 0; i < DEFAULT_SEARCHDIRS; i++) searchdirs[i] = default_searchdirs[i]; cnt = DEFAULT_SEARCHDIRS; } if (build_kernel_directory(dirbuf)) { if ((searchdirs[cnt] = (char *) malloc(strlen(dirbuf)+2)) == NULL) { error(INFO, "/lib/modules/ directory entry malloc: %s\n", strerror(errno)); } else { sprintf(searchdirs[cnt], "%s/", dirbuf); cnt++; } } if (redhat_kernel_directory_v1(dirbuf)) { if ((searchdirs[cnt] = (char *) malloc(strlen(dirbuf)+2)) == NULL) { error(INFO, "/usr/src/redhat directory entry malloc: %s\n", strerror(errno)); } else { sprintf(searchdirs[cnt], "%s/", dirbuf); cnt++; } } if (redhat_kernel_directory_v2(dirbuf)) { if ((searchdirs[cnt] = (char *) malloc(strlen(dirbuf)+2)) == NULL) { error(INFO, "/usr/src/redhat directory entry malloc: %s\n", strerror(errno)); } else { sprintf(searchdirs[cnt], "%s/", dirbuf); cnt++; } } if (redhat_debug_directory(dirbuf)) { if ((searchdirs[cnt] = (char *) malloc(strlen(dirbuf)+2)) == NULL) { error(INFO, "%s directory entry malloc: %s\n", dirbuf, strerror(errno)); } else { sprintf(searchdirs[cnt], "%s/", dirbuf); if (preferred) *preferred = cnt; cnt++; } } searchdirs[cnt] = NULL; if (CRASHDEBUG(1)) { i = start = preferred ? *preferred : 0; do { fprintf(fp, "searchdirs[%d]: %s\n", i, searchdirs[i]); if (++i == cnt) { if (start != 0) i = 0; else break; } } while (i != start); } return searchdirs; } static int build_kernel_directory(char *buf) { char *p1, *p2; if (!strstr(kt->proc_version, "Linux version ")) return FALSE; BZERO(buf, BUFSIZE); sprintf(buf, "/lib/modules/"); p1 = &kt->proc_version[strlen("Linux version ")]; p2 = &buf[strlen(buf)]; while (*p1 != ' ') *p2++ = *p1++; strcat(buf, "/build"); return TRUE; } static int redhat_kernel_directory_v1(char *buf) { char *p1, *p2; if (!strstr(kt->proc_version, "Linux version ")) return FALSE; BZERO(buf, BUFSIZE); sprintf(buf, "/usr/src/redhat/BUILD/kernel-"); p1 = &kt->proc_version[strlen("Linux version ")]; p2 = &buf[strlen(buf)]; while (((*p1 >= '0') && (*p1 <= '9')) || (*p1 == '.')) *p2++ = *p1++; strcat(buf, "/linux"); return TRUE; } static int redhat_kernel_directory_v2(char *buf) { char *p1, *p2; if (!strstr(kt->proc_version, "Linux version ")) return FALSE; BZERO(buf, BUFSIZE); sprintf(buf, "/usr/src/redhat/BUILD/kernel-"); p1 = &kt->proc_version[strlen("Linux version ")]; p2 = &buf[strlen(buf)]; while (((*p1 >= '0') && (*p1 <= '9')) || (*p1 == '.')) *p2++ = *p1++; strcat(buf, "/linux-"); p1 = &kt->proc_version[strlen("Linux version ")]; p2 = &buf[strlen(buf)]; while (((*p1 >= '0') && (*p1 <= '9')) || (*p1 == '.')) *p2++ = *p1++; return TRUE; } static int redhat_debug_directory(char *buf) { char *p1, *p2; if (!strstr(kt->proc_version, "Linux version ")) return FALSE; BZERO(buf, BUFSIZE); sprintf(buf, "%s/", pc->redhat_debug_loc); p1 = &kt->proc_version[strlen("Linux version ")]; p2 = &buf[strlen(buf)]; while (*p1 != ' ') *p2++ = *p1++; return TRUE; } /* * If a namelist was not entered, presume we're using the currently-running * kernel. Read its version string from /proc/version, and then look in * the search directories for a kernel with the same version string embedded * in it. */ static int find_booted_kernel(void) { char kernel[BUFSIZE]; char buffer[BUFSIZE]; char **searchdirs; int i, preferred, wrapped; DIR *dirp; struct dirent *dp; int found; pc->flags |= FINDKERNEL; fflush(fp); if (!file_exists("/proc/version", NULL)) { error(INFO, "/proc/version: %s: cannot determine booted kernel\n", strerror(ENOENT)); return FALSE; } if (!get_proc_version()) { error(INFO, "/proc/version: %s\n", strerror(errno)); return FALSE; } if (CRASHDEBUG(1)) fprintf(fp, "\nfind_booted_kernel: search for [%s]\n", kt->proc_version); searchdirs = build_searchdirs(CREATE, &preferred); for (i = preferred, wrapped = found = FALSE; !found; i++) { if (!searchdirs[i]) { if (preferred && !wrapped) { wrapped = TRUE; i = 0; } else break; } else if (wrapped && (preferred == i)) break; dirp = opendir(searchdirs[i]); if (!dirp) continue; for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { if (dp->d_name[0] == '.') continue; sprintf(kernel, "%s%s", searchdirs[i], dp->d_name); if (mount_point(kernel) || !file_readable(kernel) || !is_kernel(kernel)) continue; if (CRASHDEBUG(1)) fprintf(fp, "find_booted_kernel: check: %s\n", kernel); found = match_file_string(kernel, kt->proc_version, buffer); if (found) break; } closedir(dirp); } mount_point(DESTROY); build_searchdirs(DESTROY, NULL); if (found) { if ((pc->namelist = (char *)malloc (strlen(kernel)+1)) == NULL) error(FATAL, "booted kernel name malloc: %s\n", strerror(errno)); else { strcpy(pc->namelist, kernel); if (CRASHDEBUG(1)) fprintf(fp, "find_booted_kernel: found: %s\n", pc->namelist); return TRUE; } } error(INFO, "cannot find booted kernel -- please enter namelist argument\n\n"); return FALSE; } /* * Determine whether a file is a mount point, without the benefit of stat(). * This horrendous kludge is necessary to avoid uninterruptible stat() or * fstat() calls on nfs mount-points where the remote directory is no longer * available. */ static int mount_point(char *name) { int i; static int mount_points_gathered = -1; static char **mount_points; char *arglist[MAXARGS]; char buf[BUFSIZE]; char mntfile[BUFSIZE]; int argc, found; FILE *mp; /* * The first time through, stash a list of mount points. */ if (mount_points_gathered < 0) { found = mount_points_gathered = 0; if (file_exists("/proc/mounts", NULL)) sprintf(mntfile, "/proc/mounts"); else if (file_exists("/etc/mtab", NULL)) sprintf(mntfile, "/etc/mtab"); else return FALSE; if ((mp = fopen(mntfile, "r")) == NULL) return FALSE; while (fgets(buf, BUFSIZE, mp)) { argc = parse_line(buf, arglist); if (argc < 2) continue; found++; } fclose(mp); if (!(mount_points = (char **)malloc(sizeof(char *) * found))) return FALSE; if ((mp = fopen(mntfile, "r")) == NULL) return FALSE; i = 0; while (fgets(buf, BUFSIZE, mp) && (mount_points_gathered < found)) { argc = parse_line(buf, arglist); if (argc < 2) continue; if ((mount_points[i] = (char *) malloc(strlen(arglist[1])*2))) { strcpy(mount_points[i], arglist[1]); mount_points_gathered++, i++; } } fclose(mp); if (CRASHDEBUG(2)) for (i = 0; i < mount_points_gathered; i++) fprintf(fp, "mount_points[%d]: %s (%lx)\n", i, mount_points[i], (ulong)mount_points[i]); } /* * A null name string means we're done with this routine forever, * so the malloc'd memory can be freed. */ if (!name) { for (i = 0; i < mount_points_gathered; i++) free(mount_points[i]); free(mount_points); return FALSE; } for (i = 0; i < mount_points_gathered; i++) { if (STREQ(name, mount_points[i])) return TRUE; } return FALSE; } /* * If /proc/version exists, get it for verification purposes later. */ int get_proc_version(void) { FILE *version; if (strlen(kt->proc_version)) /* been here, done that... */ return TRUE; if (!file_exists("/proc/version", NULL)) return FALSE; if ((version = fopen("/proc/version", "r")) == NULL) return FALSE; if (fread(&kt->proc_version, sizeof(char), BUFSIZE-1, version) <= 0) { fclose(version); return FALSE; } fclose(version); strip_linefeeds(kt->proc_version); return TRUE; } /* * Given a non-matching kernel namelist, try to find a System.map file * that has a system_utsname whose contents match /proc/version. */ static int find_booted_system_map(void) { char system_map[BUFSIZE]; char **searchdirs; int i; DIR *dirp; struct dirent *dp; int found; fflush(fp); if (!file_exists("/proc/version", NULL)) { error(INFO, "/proc/version: %s: cannot determine booted System.map\n", strerror(ENOENT)); return FALSE; } if (!get_proc_version()) { error(INFO, "/proc/version: %s\n", strerror(errno)); return FALSE; } found = FALSE; /* * To avoid a search, try the obvious first. */ sprintf(system_map, "/boot/System.map"); if (file_readable(system_map) && verify_utsname(system_map)) { found = TRUE; } else { searchdirs = build_searchdirs(CREATE, NULL); for (i = 0; !found && searchdirs[i]; i++) { dirp = opendir(searchdirs[i]); if (!dirp) continue; for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { if (!strstr(dp->d_name, "System.map")) continue; sprintf(system_map, "%s%s", searchdirs[i], dp->d_name); if (mount_point(system_map) || !file_readable(system_map) || !is_system_map(system_map)) continue; if (verify_utsname(system_map)) { found = TRUE; break; } } closedir(dirp); } mount_point(DESTROY); build_searchdirs(DESTROY, NULL); } if (found) { if ((pc->system_map = (char *)malloc (strlen(system_map)+1)) == NULL) error(FATAL, "booted system map name malloc: %s\n", strerror(errno)); strcpy(pc->system_map, system_map); if (CRASHDEBUG(1)) fprintf(fp, "find_booted_system_map: found: %s\n", pc->system_map); return TRUE; } error(INFO, "cannot find booted system map -- please enter namelist or system map\n\n"); return FALSE; } /* * Read the system_utsname from /dev/mem, based upon the address found * in the passed-in System.map file, and compare it to /proc/version. */ static int verify_utsname(char *system_map) { char buffer[BUFSIZE]; ulong value; struct new_utsname new_utsname; if (CRASHDEBUG(1)) fprintf(fp, "verify_utsname: check: %s\n", system_map); if (!match_file_string(system_map, "D system_utsname", buffer)) return FALSE; if (extract_hex(buffer, &value, NULLCHAR, TRUE) && (READMEM(pc->mfd, &new_utsname, sizeof(struct new_utsname), value, VTOP(value)) > 0) && ascii_string(new_utsname.release) && ascii_string(new_utsname.version) && STRNEQ(new_utsname.release, "2.") && (strlen(new_utsname.release) > 4) && (strlen(new_utsname.version) > 27)) { if (CRASHDEBUG(1)) { fprintf(fp, "release: [%s]\n", new_utsname.release); fprintf(fp, "version: [%s]\n", new_utsname.version); } if (strstr(kt->proc_version, new_utsname.release) && strstr(kt->proc_version, new_utsname.version)) { return TRUE; } } return FALSE; } /* * Determine whether a file exists, using the caller's stat structure if * one was passed in. */ int file_exists(char *file, struct stat *sp) { struct stat sbuf; if (stat(file, sp ? sp : &sbuf) == 0) return TRUE; return FALSE; } /* * Determine whether a file exists, and if so, if it's readable. */ int file_readable(char *file) { char tmp; int fd; if (!file_exists(file, NULL)) return FALSE; if ((fd = open(file, O_RDONLY)) < 0) return FALSE; if (read(fd, &tmp, sizeof(tmp)) != sizeof(tmp)) { close(fd); return FALSE; } close(fd); return TRUE; } /* * Quick file checksummer. */ int file_checksum(char *file, long *retsum) { int i; int fd; ssize_t cnt; char buf[MIN_PAGE_SIZE]; long csum; if ((fd = open(file, O_RDONLY)) < 0) return FALSE; csum = 0; BZERO(buf, MIN_PAGE_SIZE); while ((cnt = read(fd, buf, MIN_PAGE_SIZE)) > 0) { for (i = 0; i < cnt; i++) csum += buf[i]; BZERO(buf, MIN_PAGE_SIZE); } close(fd); *retsum = csum; return TRUE; } int is_directory(char *file) { struct stat sbuf; if (!file || !strlen(file)) return(FALSE); if (stat(file, &sbuf) == -1) return(FALSE); /* This file doesn't exist. */ return((sbuf.st_mode & S_IFMT) == S_IFDIR ? TRUE : FALSE); } /* * Search a directory tree for filename, and if found, return a temporarily * allocated buffer containing the full pathname. The "done" business is * protection against fgets() prematurely returning NULL before the find * command completes. (I thought this was impossible until I saw it happen...) * When time permits, rewrite this doing the search by hand. */ char * search_directory_tree(char *directory, char *file, int follow_links) { char command[BUFSIZE]; char buf[BUFSIZE]; char *retbuf, *start, *end, *module; FILE *pipe; regex_t regex; int regex_used, done; if (!file_exists("/usr/bin/find", NULL) || !file_exists("/bin/echo", NULL) || !is_directory(directory) || (*file == '(')) return NULL; sprintf(command, "/usr/bin/find %s %s -name %s -print; /bin/echo search done", follow_links ? "-L" : "", directory, file); if ((pipe = popen(command, "r")) == NULL) { error(INFO, "%s: %s\n", command, strerror(errno)); return NULL; } done = FALSE; retbuf = NULL; regex_used = ((start = strstr(file, "[")) && (end = strstr(file, "]")) && (start < end) && (regcomp(®ex, file, 0) == 0)); while (fgets(buf, BUFSIZE-1, pipe) || !done) { if (STREQ(buf, "search done\n")) { done = TRUE; break; } if (!retbuf && !regex_used && STREQ((char *)basename(strip_linefeeds(buf)), file)) { retbuf = GETBUF(strlen(buf)+1); strcpy(retbuf, buf); } if (!retbuf && regex_used) { module = basename(strip_linefeeds(buf)); if (regexec(®ex, module, 0, NULL, 0) == 0) { retbuf = GETBUF(strlen(buf)+1); strcpy(retbuf, buf); } } } if (regex_used) regfree(®ex); pclose(pipe); return retbuf; } /* * Determine whether a file exists, and if so, if it's a tty. */ int is_a_tty(char *filename) { int fd; if ((fd = open(filename, O_RDONLY)) < 0) return FALSE; if (isatty(fd)) { close(fd); return TRUE; } close(fd); return FALSE; } /* * Open a tmpfile for command output. fp is stashed in pc->saved_fp, and * temporarily set to the new FILE pointer. This allows a command to still * print to the original output while the tmpfile is still open. */ #define OPEN_ONLY_ONCE #ifdef OPEN_ONLY_ONCE void open_tmpfile(void) { int ret ATTRIBUTE_UNUSED; if (pc->tmpfile) error(FATAL, "recursive temporary file usage\n"); if (!pc->tmp_fp) { if ((pc->tmp_fp = tmpfile()) == NULL) error(FATAL, "cannot open temporary file\n"); } fflush(pc->tmpfile); ret = ftruncate(fileno(pc->tmp_fp), 0); rewind(pc->tmp_fp); pc->tmpfile = pc->tmp_fp; pc->saved_fp = fp; fp = pc->tmpfile; } #else void open_tmpfile(void) { if (pc->tmpfile) error(FATAL, "recursive temporary file usage\n"); if ((pc->tmpfile = tmpfile()) == NULL) { error(FATAL, "cannot open temporary file\n"); } else { pc->saved_fp = fp; fp = pc->tmpfile; } } #endif /* * Destroy the reference to the tmpfile, and restore fp to the state * it had when open_tmpfile() was called. */ #ifdef OPEN_ONLY_ONCE void close_tmpfile(void) { int ret ATTRIBUTE_UNUSED; if (pc->tmpfile) { fflush(pc->tmpfile); ret = ftruncate(fileno(pc->tmpfile), 0); rewind(pc->tmpfile); pc->tmpfile = NULL; fp = pc->saved_fp; } else error(FATAL, "trying to close an unopened temporary file\n"); } #else void close_tmpfile(void) { if (pc->tmpfile) { fp = pc->saved_fp; fclose(pc->tmpfile); pc->tmpfile = NULL; } else error(FATAL, "trying to close an unopened temporary file\n"); } #endif /* * open_tmpfile2(), set_tmpfile2() and close_tmpfile2() do not use a * permanent tmpfile, and do NOT modify the global fp pointer or pc->saved_fp. * That being the case, all wrapped functions must be aware of it, or the * global fp pointer has to explicitly manipulated by the calling function. * The secondary tmpfile should only be used by common functions that might * be called by a higher-level function using the primary permanent tmpfile, * or alternatively a caller may pass in a FILE pointer to set_tmpfile2(). */ void open_tmpfile2(void) { if (pc->tmpfile2) error(FATAL, "recursive secondary temporary file usage\n"); if ((pc->tmpfile2 = tmpfile()) == NULL) error(FATAL, "cannot open secondary temporary file\n"); rewind(pc->tmpfile2); } void close_tmpfile2(void) { if (pc->tmpfile2) { fflush(pc->tmpfile2); fclose(pc->tmpfile2); pc->tmpfile2 = NULL; } } void set_tmpfile2(FILE *fptr) { if (pc->tmpfile2) error(FATAL, "secondary temporary file already in use\n"); pc->tmpfile2 = fptr; } #define MOUNT_PRINT_INODES 0x1 #define MOUNT_PRINT_FILES 0x2 /* * Display basic information about the currently mounted filesystems. * The -f option lists the open files for the filesystem(s). * The -i option dumps the dirty inodes of the filesystem(s). * If an inode address, mount, vfsmount, superblock, device name or * directory name is also entered, just show the data for the * filesystem indicated by the argument. */ static char mount_hdr[BUFSIZE] = { 0 }; void cmd_mount(void) { int i; int c, found; struct task_context *tc, *namespace_context; ulong value1, value2; char *spec_string; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char *arglist[MAXARGS*2]; ulong vfsmount = 0; int flags = 0; int save_next; ulong pid; /* find a context */ pid = 1; while ((namespace_context = pid_to_context(pid)) == NULL) pid++; while ((c = getopt(argcnt, args, "ifn:")) != EOF) { switch(c) { case 'i': if (INVALID_MEMBER(super_block_s_dirty)) { error(INFO, "the super_block.s_dirty linked list does " "not exist in this kernel\n"); option_not_supported(c); } flags |= MOUNT_PRINT_INODES; break; case 'f': flags |= MOUNT_PRINT_FILES; break; case 'n': switch (str_to_context(optarg, &value1, &tc)) { case STR_PID: case STR_TASK: namespace_context = tc; break; case STR_INVALID: error(FATAL, "invalid task or pid value: %s\n", optarg); break; } break; default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); if (args[optind] == 0) { show_mounts(0, flags, namespace_context); return; } /* * Dump everything into a tmpfile, and then walk * through it for each search argument entered. */ open_tmpfile(); show_mounts(0, (VALID_MEMBER(super_block_s_files) ? MOUNT_PRINT_FILES : 0) | (VALID_MEMBER(super_block_s_dirty) ? MOUNT_PRINT_INODES : 0), namespace_context); pc->curcmd_flags &= ~HEADER_PRINTED; do { spec_string = args[optind]; if (STRNEQ(spec_string, "0x") && hexadecimal(spec_string, 0)) shift_string_left(spec_string, 2); found = FALSE; rewind(pc->tmpfile); save_next = 0; while (fgets(buf1, BUFSIZE, pc->tmpfile)) { if (STRNEQ(buf1, mount_hdr)) { save_next = TRUE; continue; } if (save_next) { strcpy(buf2, buf1); save_next = FALSE; } if (!(c = parse_line(buf1, arglist))) continue; for (i = 0; i < c; i++) { if (PATHEQ(arglist[i], spec_string)) found = TRUE; /* * Check for a vfsmount address * embedded in a struct mount. */ if ((i == 0) && (c == 5) && VALID_MEMBER(mount_mnt) && hexadecimal(spec_string, 0) && hexadecimal(arglist[i], 0)) { value1 = htol(spec_string, FAULT_ON_ERROR, NULL); value2 = htol(arglist[i], FAULT_ON_ERROR, NULL) + OFFSET(mount_mnt); if (value1 == value2) found = TRUE; } } if (found) { fp = pc->saved_fp; if (flags) { sscanf(buf2,"%lx", &vfsmount); show_mounts(vfsmount, flags, namespace_context); } else { if (!(pc->curcmd_flags & HEADER_PRINTED)) { fprintf(fp, "%s", mount_hdr); pc->curcmd_flags |= HEADER_PRINTED; } fprintf(fp, "%s", buf2); } found = FALSE; fp = pc->tmpfile; } } } while (args[++optind]); close_tmpfile(); } /* For kernels 5.8-6.7, we're skipping show mount cursor entries. */ #define MNT_CURSOR 0x10000000 /* * Do the work for cmd_mount(); */ static void show_mounts(ulong one_vfsmount, int flags, struct task_context *namespace_context) { ulong one_vfsmount_list; long sb_s_files; long s_dirty; ulong devp, dirp, sbp, dirty, type, name; struct list_data list_data, *ld; char buf1[BUFSIZE*2]; char buf2[BUFSIZE]; char buf3[BUFSIZE]; char buf4[BUFSIZE/2]; ulong *dentry_list, *dp, *mntlist; ulong *vfsmnt; char *vfsmount_buf, *super_block_buf, *mount_buf; ulong dentry, inode, inode_sb, mnt_parent; char *dentry_buf, *inode_buf; int cnt, i, m, files_header_printed; int mount_cnt; int devlen; char mount_files_header[BUFSIZE]; long per_cpu_s_files; sprintf(mount_files_header, "%s%s%s%sTYPE%sPATH\n", mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "DENTRY"), space(MINSPACE), mkstring(buf2, VADDR_PRLEN, CENTER|LJUST, "INODE"), space(MINSPACE), space(MINSPACE)); dirp = dentry = mnt_parent = sb_s_files = s_dirty = 0; if (VALID_MEMBER(super_block_s_dirty)) s_dirty = OFFSET(super_block_s_dirty); per_cpu_s_files = MEMBER_EXISTS("file", "f_sb_list_cpu"); dentry_list = NULL; mntlist = 0; ld = &list_data; if (one_vfsmount) { one_vfsmount_list = one_vfsmount; mount_cnt = 1; mntlist = &one_vfsmount_list; } else mntlist = get_mount_list(&mount_cnt, namespace_context); devlen = strlen("DEVNAME")+2; if (!strlen(mount_hdr)) { snprintf(mount_hdr, sizeof(mount_hdr), "%s %s %s %s DIRNAME\n", mkstring(buf1, VADDR_PRLEN, CENTER, VALID_STRUCT(mount) ? "MOUNT" : "VFSMOUNT"), mkstring(buf2, VADDR_PRLEN, CENTER, "SUPERBLK"), mkstring(buf3, strlen("rootfs"), LJUST, "TYPE"), mkstring(buf4, devlen, LJUST, "DEVNAME")); } if (flags == 0) fprintf(fp, "%s", mount_hdr); sb_s_files = VALID_MEMBER(super_block_s_files) ? OFFSET(super_block_s_files) : INVALID_OFFSET; if ((flags & MOUNT_PRINT_FILES) && (sb_s_files == INVALID_OFFSET)) { /* * super_block.s_files deprecated */ if (!kernel_symbol_exists("inuse_filps")) { error(INFO, "the super_block.s_files linked list does " "not exist in this kernel\n"); option_not_supported('f'); } /* * No open files list in super_block (2.2). * Use inuse_filps list instead. */ dentry_list = create_dentry_array(symbol_value("inuse_filps"), &cnt); } if (VALID_STRUCT(mount)) { mount_buf = GETBUF(SIZE(mount)); vfsmount_buf = mount_buf + OFFSET(mount_mnt); } else { mount_buf = NULL; vfsmount_buf = GETBUF(SIZE(vfsmount)); } super_block_buf = GETBUF(SIZE(super_block)); for (m = 0, vfsmnt = mntlist; m < mount_cnt; m++, vfsmnt++) { if (VALID_STRUCT(mount)) { readmem(*vfsmnt, KVADDR, mount_buf, SIZE(mount), "mount buffer", FAULT_ON_ERROR); devp = ULONG(mount_buf + OFFSET(mount_mnt_devname)); } else { readmem(*vfsmnt, KVADDR, vfsmount_buf, SIZE(vfsmount), "vfsmount buffer", FAULT_ON_ERROR); devp = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_devname)); } if (VALID_MEMBER(vfsmount_mnt_dirname)) { dirp = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_dirname)); } else { if (VALID_STRUCT(mount)) { mnt_parent = ULONG(mount_buf + OFFSET(mount_mnt_parent)); dentry = ULONG(mount_buf + OFFSET(mount_mnt_mountpoint)); } else { mnt_parent = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_parent)); dentry = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_mountpoint)); } } sbp = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_sb)); if (!IS_KVADDR(sbp)) { if (sbp == 0 && VALID_MEMBER(proc_mounts_cursor) && VALID_MEMBER(vfsmount_mnt_flags)) { int mnt_flags = INT(vfsmount_buf + OFFSET(vfsmount_mnt_flags)); if (mnt_flags == MNT_CURSOR) { if (CRASHDEBUG(1)) fprintf(stderr,"skipped cursor vfsmnt: 0x%lx\n", *vfsmnt); continue; } } error(WARNING, "cannot get super_block from vfsmnt: 0x%lx\n", *vfsmnt); continue; } if (flags) fprintf(fp, "%s", mount_hdr); fprintf(fp, "%s %s ", mkstring(buf1, VADDR_PRLEN, RJUST|LONG_HEX, MKSTR(*vfsmnt)), mkstring(buf2, VADDR_PRLEN, RJUST|LONG_HEX, MKSTR(sbp))); readmem(sbp, KVADDR, super_block_buf, SIZE(super_block), "super_block buffer", FAULT_ON_ERROR); type = ULONG(super_block_buf + OFFSET(super_block_s_type)); readmem(type + OFFSET(file_system_type_name), KVADDR, &name, sizeof(void *), "file_system_type name", FAULT_ON_ERROR); if (read_string(name, buf4, (BUFSIZE/2)-1)) sprintf(buf3, "%-6s ", buf4); else sprintf(buf3, "unknown "); if (read_string(devp, buf1, BUFSIZE-1)) sprintf(buf4, "%s ", mkstring(buf2, devlen, LJUST, buf1)); else sprintf(buf4, "%s ", mkstring(buf2, devlen, LJUST, "(unknown)")); sprintf(buf1, "%s%s", buf3, buf4); while ((strlen(buf1) > 17) && (buf1[strlen(buf1)-2] == ' ')) strip_ending_char(buf1, ' '); fprintf(fp, "%s", buf1); if (VALID_MEMBER(vfsmount_mnt_dirname)) { if (read_string(dirp, buf1, BUFSIZE-1)) fprintf(fp, "%-10s\n", buf1); else fprintf(fp, "%-10s\n", "(unknown)"); } else { get_pathname(dentry, buf1, BUFSIZE, 1, VALID_STRUCT(mount) ? mnt_parent + OFFSET(mount_mnt) : mnt_parent); fprintf(fp, "%-10s\n", buf1); } if (flags & MOUNT_PRINT_FILES) { if (sb_s_files != INVALID_OFFSET) { dentry_list = per_cpu_s_files ? create_dentry_array_percpu(sbp+ sb_s_files, &cnt) : create_dentry_array(sbp+sb_s_files, &cnt); } files_header_printed = 0; for (i=0, dp = dentry_list; iflags = VERBOSE; ld->start = dirty; ld->end = (sbp+s_dirty); ld->header = "DIRTY INODES\n"; hq_open(); do_list(ld); hq_close(); } else { fprintf(fp, "DIRTY INODES\nNo dirty inodes found\n"); } } if (flags && !one_vfsmount) fprintf(fp, "\n"); } if (!one_vfsmount) FREEBUF(mntlist); if (VALID_STRUCT(mount)) FREEBUF(mount_buf); else FREEBUF(vfsmount_buf); FREEBUF(super_block_buf); } /* * Allocate and fill a list of the currently-mounted vfsmount pointers. */ ulong * get_mount_list(int *cntptr, struct task_context *namespace_context) { struct list_data list_data, *ld; ulong namespace, root, nsproxy, mnt_ns; struct task_context *tc; ld = &list_data; BZERO(ld, sizeof(struct list_data)); ld->flags |= LIST_ALLOCATE; if (symbol_exists("vfsmntlist")) { get_symbol_data("vfsmntlist", sizeof(void *), &ld->start); ld->end = symbol_value("vfsmntlist"); } else if (VALID_MEMBER(task_struct_nsproxy)) { tc = namespace_context; readmem(tc->task + OFFSET(task_struct_nsproxy), KVADDR, &nsproxy, sizeof(void *), "task nsproxy", FAULT_ON_ERROR); if (!readmem(nsproxy + OFFSET(nsproxy_mnt_ns), KVADDR, &mnt_ns, sizeof(void *), "nsproxy mnt_ns", RETURN_ON_ERROR|QUIET)) error(FATAL, "cannot determine mount list location!\n"); /* Linux 6.8 and later keep list of mounts in an rbtree. */ if (VALID_MEMBER(mnt_namespace_nr_mounts)) { uint nr_mounts; ulong *mntlist, *l; struct rb_root *mounts; struct rb_node *node; readmem(mnt_ns + OFFSET(mnt_namespace_nr_mounts), KVADDR, &nr_mounts, sizeof(uint), "mnt_namespace.nr_mounts", FAULT_ON_ERROR); if (!nr_mounts) return NULL; mounts = (struct rb_root *)(mnt_ns + OFFSET(mnt_namespace_mounts)); mntlist = (ulong *)GETBUF(sizeof(ulong) * nr_mounts); l = mntlist; for (node = rb_first(mounts); node; l++, node = rb_next(node)) *l = (ulong)node - OFFSET(mount_mnt_node); *cntptr = nr_mounts; return mntlist; } if (!readmem(mnt_ns + OFFSET(mnt_namespace_root), KVADDR, &root, sizeof(void *), "mnt_namespace root", RETURN_ON_ERROR|QUIET)) error(FATAL, "cannot determine mount list location!\n"); ld->start = root + OFFSET_OPTION(vfsmount_mnt_list, mount_mnt_list); ld->end = mnt_ns + OFFSET(mnt_namespace_list); } else if (VALID_MEMBER(namespace_root)) { tc = namespace_context; readmem(tc->task + OFFSET(task_struct_namespace), KVADDR, &namespace, sizeof(void *), "task namespace", FAULT_ON_ERROR); if (!readmem(namespace + OFFSET(namespace_root), KVADDR, &root, sizeof(void *), "namespace root", RETURN_ON_ERROR|QUIET)) error(FATAL, "cannot determine mount list location!\n"); if (CRASHDEBUG(1)) console("namespace: %lx => root: %lx\n", namespace, root); ld->start = root + OFFSET_OPTION(vfsmount_mnt_list, mount_mnt_list); ld->end = namespace + OFFSET(namespace_list); } else error(FATAL, "cannot determine mount list location!\n"); if (VALID_MEMBER(vfsmount_mnt_list)) ld->list_head_offset = OFFSET(vfsmount_mnt_list); else if (VALID_STRUCT(mount)) ld->list_head_offset = OFFSET(mount_mnt_list); else ld->member_offset = OFFSET(vfsmount_mnt_next); *cntptr = do_list(ld); return(ld->list_ptr); } /* * Given a dentry, display its address, inode, super_block, pathname. */ static void display_dentry_info(ulong dentry) { int m, found; char *dentry_buf, *inode_buf, *vfsmount_buf, *mount_buf; ulong inode, superblock, sb, vfs; ulong *mntlist, *vfsmnt; char pathname[BUFSIZE]; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char buf3[BUFSIZE]; int mount_cnt; fprintf(fp, "%s%s%s%s%s%sTYPE%sPATH\n", mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "DENTRY"), space(MINSPACE), mkstring(buf2, VADDR_PRLEN, CENTER|LJUST, "INODE"), space(MINSPACE), mkstring(buf3, VADDR_PRLEN, CENTER|LJUST, "SUPERBLK"), space(MINSPACE), space(MINSPACE)); dentry_buf = fill_dentry_cache(dentry); inode = ULONG(dentry_buf + OFFSET(dentry_d_inode)); pathname[0] = NULLCHAR; if (inode) { inode_buf = fill_inode_cache(inode); superblock = ULONG(inode_buf + OFFSET(inode_i_sb)); } else { inode_buf = NULL; superblock = ULONG(dentry_buf + OFFSET(dentry_d_sb)); } if (!superblock) goto nopath; if (VALID_MEMBER(file_f_vfsmnt)) { mntlist = get_mount_list(&mount_cnt, pid_to_context(1)); if (VALID_STRUCT(mount)) { mount_buf = GETBUF(SIZE(mount)); vfsmount_buf = mount_buf + OFFSET(mount_mnt); } else { mount_buf = NULL; vfsmount_buf = GETBUF(SIZE(vfsmount)); } for (m = found = 0, vfsmnt = mntlist; m < mount_cnt; m++, vfsmnt++) { if (VALID_STRUCT(mount)) readmem(*vfsmnt, KVADDR, mount_buf, SIZE(mount), "mount buffer", FAULT_ON_ERROR); else readmem(*vfsmnt, KVADDR, vfsmount_buf, SIZE(vfsmount), "vfsmount buffer", FAULT_ON_ERROR); sb = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_sb)); if (superblock && (sb == superblock)) { get_pathname(dentry, pathname, BUFSIZE, 1, VALID_STRUCT(mount) ? *vfsmnt+OFFSET(mount_mnt) : *vfsmnt); found = TRUE; } } if (!found && symbol_exists("pipe_mnt")) { get_symbol_data("pipe_mnt", sizeof(long), &vfs); if (VALID_STRUCT(mount)) readmem(vfs - OFFSET(mount_mnt), KVADDR, mount_buf, SIZE(mount), "mount buffer", FAULT_ON_ERROR); else readmem(vfs, KVADDR, vfsmount_buf, SIZE(vfsmount), "vfsmount buffer", FAULT_ON_ERROR); sb = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_sb)); if (superblock && (sb == superblock)) { get_pathname(dentry, pathname, BUFSIZE, 1, vfs); found = TRUE; } } if (!found && symbol_exists("sock_mnt")) { get_symbol_data("sock_mnt", sizeof(long), &vfs); if (VALID_STRUCT(mount)) readmem(vfs - OFFSET(mount_mnt), KVADDR, mount_buf, SIZE(mount), "mount buffer", FAULT_ON_ERROR); else readmem(vfs, KVADDR, vfsmount_buf, SIZE(vfsmount), "vfsmount buffer", FAULT_ON_ERROR); sb = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_sb)); if (superblock && (sb == superblock)) { get_pathname(dentry, pathname, BUFSIZE, 1, vfs); found = TRUE; } } } else { mntlist = 0; get_pathname(dentry, pathname, BUFSIZE, 1, 0); } if (mntlist) { FREEBUF(mntlist); if (VALID_STRUCT(mount)) FREEBUF(mount_buf); else FREEBUF(vfsmount_buf); } nopath: fprintf(fp, "%s%s%s%s%s%s%s%s%s\n", mkstring(buf1, VADDR_PRLEN, RJUST|LONG_HEX, MKSTR(dentry)), space(MINSPACE), mkstring(buf2, VADDR_PRLEN, RJUST|LONG_HEX, MKSTR(inode)), space(MINSPACE), mkstring(buf3, VADDR_PRLEN, CENTER|LONG_HEX, MKSTR(superblock)), space(MINSPACE), inode ? inode_type(inode_buf, pathname) : "N/A", space(MINSPACE), pathname); } /* * Return a 4-character type string of an inode, modifying a previously * gathered pathname if necessary. */ char * inode_type(char *inode_buf, char *pathname) { char *type; uint32_t umode32; uint16_t umode16; uint mode; ulong inode_i_op; ulong inode_i_fop; long i_fop_off; mode = umode16 = umode32 = 0; switch (SIZE(umode_t)) { case SIZEOF_32BIT: umode32 = UINT(inode_buf + OFFSET(inode_i_mode)); mode = umode32; break; case SIZEOF_16BIT: umode16 = USHORT(inode_buf + OFFSET(inode_i_mode)); mode = (uint)umode16; break; } type = "UNKN"; if (S_ISREG(mode)) type = "REG "; if (S_ISLNK(mode)) type = "LNK "; if (S_ISDIR(mode)) type = "DIR "; if (S_ISCHR(mode)) type = "CHR "; if (S_ISBLK(mode)) type = "BLK "; if (S_ISFIFO(mode)) { type = "FIFO"; if (symbol_exists("pipe_inode_operations")) { inode_i_op = ULONG(inode_buf + OFFSET(inode_i_op)); if (inode_i_op == symbol_value("pipe_inode_operations")) { type = "PIPE"; pathname[0] = NULLCHAR; } } else { if (symbol_exists("rdwr_pipe_fops") && (i_fop_off = OFFSET(inode_i_fop)) > 0) { inode_i_fop = ULONG(inode_buf + i_fop_off); if (inode_i_fop == symbol_value("rdwr_pipe_fops")) { type = "PIPE"; pathname[0] = NULLCHAR; } } } } if (S_ISSOCK(mode)) { type = "SOCK"; if (STREQ(pathname, "/")) pathname[0] = NULLCHAR; } return type; } /* * Walk an open file list and return an array of open dentries. */ static ulong * create_dentry_array(ulong list_addr, int *count) { struct list_data list_data, *ld; ulong *file, *files_list, *dentry_list; ulong dentry, inode; char *file_buf, *dentry_buf; int cnt, f_count, i; int dentry_cnt = 0; ld = &list_data; BZERO(ld, sizeof(struct list_data)); readmem(list_addr, KVADDR, &ld->start, sizeof(void *), "file list head", FAULT_ON_ERROR); if (list_addr == ld->start) { /* empty list? */ *count = 0; return NULL; } ld->end = list_addr; hq_open(); cnt = do_list(ld); if (cnt == 0) { hq_close(); *count = 0; return NULL; } files_list = (ulong *)GETBUF(cnt * sizeof(ulong)); cnt = retrieve_list(files_list, cnt); hq_close(); hq_open(); for (i=0, file = files_list; i__per_cpu_offset[c]; percpu_list[c].dentry_list = create_dentry_array(list_addr, &percpu_list[c].count); total += percpu_list[c].count; } if (total) { dentry_list = (ulong *)GETBUF(total * sizeof(ulong)); for (c = i = 0; c < (cpu+1); c++) { if (percpu_list[c].count == 0) continue; for (j = 0; j < percpu_list[c].count; j++) dentry_list[i++] = percpu_list[c].dentry_list[j]; FREEBUF(percpu_list[c].dentry_list); } } else dentry_list = NULL; FREEBUF(percpu_list); *count = total; return dentry_list; } /* * Stash vfs structure offsets */ void vfs_init(void) { MEMBER_OFFSET_INIT(nlm_file_f_file, "nlm_file", "f_file"); MEMBER_OFFSET_INIT(task_struct_files, "task_struct", "files"); MEMBER_OFFSET_INIT(task_struct_fs, "task_struct", "fs"); MEMBER_OFFSET_INIT(fs_struct_root, "fs_struct", "root"); MEMBER_OFFSET_INIT(fs_struct_pwd, "fs_struct", "pwd"); MEMBER_OFFSET_INIT(fs_struct_rootmnt, "fs_struct", "rootmnt"); MEMBER_OFFSET_INIT(fs_struct_pwdmnt, "fs_struct", "pwdmnt"); MEMBER_OFFSET_INIT(files_struct_open_fds_init, "files_struct", "open_fds_init"); MEMBER_OFFSET_INIT(files_struct_fdt, "files_struct", "fdt"); if (VALID_MEMBER(files_struct_fdt)) { MEMBER_OFFSET_INIT(fdtable_max_fds, "fdtable", "max_fds"); MEMBER_OFFSET_INIT(fdtable_max_fdset, "fdtable", "max_fdset"); MEMBER_OFFSET_INIT(fdtable_open_fds, "fdtable", "open_fds"); MEMBER_OFFSET_INIT(fdtable_fd, "fdtable", "fd"); } else { MEMBER_OFFSET_INIT(files_struct_max_fds, "files_struct", "max_fds"); MEMBER_OFFSET_INIT(files_struct_max_fdset, "files_struct", "max_fdset"); MEMBER_OFFSET_INIT(files_struct_open_fds, "files_struct", "open_fds"); MEMBER_OFFSET_INIT(files_struct_fd, "files_struct", "fd"); } MEMBER_OFFSET_INIT(file_f_dentry, "file", "f_dentry"); MEMBER_OFFSET_INIT(file_f_vfsmnt, "file", "f_vfsmnt"); MEMBER_OFFSET_INIT(file_f_count, "file", "f_count"); MEMBER_OFFSET_INIT(file_f_inode, "file", "f_inode"); MEMBER_OFFSET_INIT(path_mnt, "path", "mnt"); MEMBER_OFFSET_INIT(path_dentry, "path", "dentry"); if (INVALID_MEMBER(file_f_dentry)) { MEMBER_OFFSET_INIT(file_f_path, "file", "f_path"); ASSIGN_OFFSET(file_f_dentry) = OFFSET(file_f_path) + OFFSET(path_dentry); ASSIGN_OFFSET(file_f_vfsmnt) = OFFSET(file_f_path) + OFFSET(path_mnt); } MEMBER_OFFSET_INIT(dentry_d_inode, "dentry", "d_inode"); MEMBER_OFFSET_INIT(dentry_d_parent, "dentry", "d_parent"); MEMBER_OFFSET_INIT(dentry_d_covers, "dentry", "d_covers"); MEMBER_OFFSET_INIT(dentry_d_name, "dentry", "d_name"); MEMBER_OFFSET_INIT(dentry_d_iname, "dentry", "d_iname"); if (INVALID_MEMBER(dentry_d_iname)) { MEMBER_OFFSET_INIT(dentry_d_iname, "dentry", "d_shortname"); } MEMBER_OFFSET_INIT(dentry_d_sb, "dentry", "d_sb"); MEMBER_OFFSET_INIT(inode_i_mode, "inode", "i_mode"); MEMBER_OFFSET_INIT(inode_i_op, "inode", "i_op"); MEMBER_OFFSET_INIT(inode_i_sb, "inode", "i_sb"); MEMBER_OFFSET_INIT(inode_u, "inode", "u"); MEMBER_OFFSET_INIT(qstr_name, "qstr", "name"); MEMBER_OFFSET_INIT(qstr_len, "qstr", "len"); if (INVALID_MEMBER(qstr_len)) ANON_MEMBER_OFFSET_INIT(qstr_len, "qstr", "len"); MEMBER_OFFSET_INIT(vfsmount_mnt_next, "vfsmount", "mnt_next"); MEMBER_OFFSET_INIT(vfsmount_mnt_devname, "vfsmount", "mnt_devname"); if (INVALID_MEMBER(vfsmount_mnt_devname)) MEMBER_OFFSET_INIT(mount_mnt_devname, "mount", "mnt_devname"); MEMBER_OFFSET_INIT(vfsmount_mnt_dirname, "vfsmount", "mnt_dirname"); MEMBER_OFFSET_INIT(vfsmount_mnt_sb, "vfsmount", "mnt_sb"); MEMBER_OFFSET_INIT(vfsmount_mnt_list, "vfsmount", "mnt_list"); if (INVALID_MEMBER(vfsmount_mnt_devname)) MEMBER_OFFSET_INIT(mount_mnt_list, "mount", "mnt_list"); MEMBER_OFFSET_INIT(vfsmount_mnt_parent, "vfsmount", "mnt_parent"); if (INVALID_MEMBER(vfsmount_mnt_devname)) MEMBER_OFFSET_INIT(mount_mnt_parent, "mount", "mnt_parent"); MEMBER_OFFSET_INIT(vfsmount_mnt_mountpoint, "vfsmount", "mnt_mountpoint"); if (INVALID_MEMBER(vfsmount_mnt_devname)) MEMBER_OFFSET_INIT(mount_mnt_mountpoint, "mount", "mnt_mountpoint"); MEMBER_OFFSET_INIT(vfsmount_mnt_flags, "vfsmount", "mnt_flags"); MEMBER_OFFSET_INIT(proc_mounts_cursor, "proc_mounts", "cursor"); MEMBER_OFFSET_INIT(mount_mnt, "mount", "mnt"); MEMBER_OFFSET_INIT(namespace_root, "namespace", "root"); MEMBER_OFFSET_INIT(task_struct_nsproxy, "task_struct", "nsproxy"); if (VALID_MEMBER(namespace_root)) { MEMBER_OFFSET_INIT(namespace_list, "namespace", "list"); MEMBER_OFFSET_INIT(task_struct_namespace, "task_struct", "namespace"); } else if (VALID_MEMBER(task_struct_nsproxy)) { MEMBER_OFFSET_INIT(nsproxy_mnt_ns, "nsproxy", "mnt_ns"); MEMBER_OFFSET_INIT(mnt_namespace_root, "mnt_namespace", "root"); MEMBER_OFFSET_INIT(mnt_namespace_list, "mnt_namespace", "list"); /* Linux 6.8 and later */ MEMBER_OFFSET_INIT(mnt_namespace_mounts, "mnt_namespace", "mounts"); MEMBER_OFFSET_INIT(mnt_namespace_nr_mounts, "mnt_namespace", "nr_mounts"); MEMBER_OFFSET_INIT(mount_mnt_node, "mount", "mnt_node"); } else if (THIS_KERNEL_VERSION >= LINUX(2,4,20)) { if (CRASHDEBUG(2)) fprintf(fp, "hardwiring namespace stuff\n"); ASSIGN_OFFSET(task_struct_namespace) = OFFSET(task_struct_files) + sizeof(void *); ASSIGN_OFFSET(namespace_root) = sizeof(void *); ASSIGN_OFFSET(namespace_list) = sizeof(void *) * 2; } MEMBER_OFFSET_INIT(super_block_s_dirty, "super_block", "s_dirty"); MEMBER_OFFSET_INIT(super_block_s_type, "super_block", "s_type"); MEMBER_OFFSET_INIT(file_system_type_name, "file_system_type", "name"); MEMBER_OFFSET_INIT(super_block_s_files, "super_block", "s_files"); MEMBER_OFFSET_INIT(inode_i_flock, "inode", "i_flock"); MEMBER_OFFSET_INIT(file_lock_fl_owner, "file_lock", "fl_owner"); MEMBER_OFFSET_INIT(nlm_host_h_exportent, "nlm_host", "h_exportent"); MEMBER_OFFSET_INIT(svc_client_cl_ident, "svc_client", "cl_ident"); MEMBER_OFFSET_INIT(inode_i_fop, "inode","i_fop"); STRUCT_SIZE_INIT(umode_t, "umode_t"); STRUCT_SIZE_INIT(dentry, "dentry"); STRUCT_SIZE_INIT(files_struct, "files_struct"); if (VALID_MEMBER(files_struct_fdt)) STRUCT_SIZE_INIT(fdtable, "fdtable"); STRUCT_SIZE_INIT(file, "file"); STRUCT_SIZE_INIT(inode, "inode"); STRUCT_SIZE_INIT(mount, "mount"); STRUCT_SIZE_INIT(vfsmount, "vfsmount"); STRUCT_SIZE_INIT(fs_struct, "fs_struct"); STRUCT_SIZE_INIT(super_block, "super_block"); if (!(ft->file_cache = (char *)malloc(SIZE(file)*FILE_CACHE))) error(FATAL, "cannot malloc file cache\n"); if (!(ft->dentry_cache = (char *)malloc(SIZE(dentry)*DENTRY_CACHE))) error(FATAL, "cannot malloc dentry cache\n"); if (!(ft->inode_cache = (char *)malloc(SIZE(inode)*INODE_CACHE))) error(FATAL, "cannot malloc inode cache\n"); MEMBER_OFFSET_INIT(rb_root_rb_node, "rb_root","rb_node"); MEMBER_OFFSET_INIT(rb_node_rb_left, "rb_node","rb_left"); MEMBER_OFFSET_INIT(rb_node_rb_right, "rb_node","rb_right"); } void dump_filesys_table(int verbose) { int i; ulong fhits, dhits, ihits; if (!verbose) goto show_hit_rates; for (i = 0; i < FILE_CACHE; i++) fprintf(fp, " cached_file[%2d]: %lx (%ld)\n", i, ft->cached_file[i], ft->cached_file_hits[i]); fprintf(fp, " file_cache: %lx\n", (ulong)ft->file_cache); fprintf(fp, " file_cache_index: %d\n", ft->file_cache_index); fprintf(fp, " file_cache_fills: %ld\n", ft->file_cache_fills); for (i = 0; i < DENTRY_CACHE; i++) fprintf(fp, " cached_dentry[%2d]: %lx (%ld)\n", i, ft->cached_dentry[i], ft->cached_dentry_hits[i]); fprintf(fp, " dentry_cache: %lx\n", (ulong)ft->dentry_cache); fprintf(fp, "dentry_cache_index: %d\n", ft->dentry_cache_index); fprintf(fp, "dentry_cache_fills: %ld\n", ft->dentry_cache_fills); for (i = 0; i < INODE_CACHE; i++) fprintf(fp, " cached_inode[%2d]: %lx (%ld)\n", i, ft->cached_inode[i], ft->cached_inode_hits[i]); fprintf(fp, " inode_cache: %lx\n", (ulong)ft->inode_cache); fprintf(fp, " inode_cache_index: %d\n", ft->inode_cache_index); fprintf(fp, " inode_cache_fills: %ld\n", ft->inode_cache_fills); show_hit_rates: if (ft->file_cache_fills) { for (i = fhits = 0; i < FILE_CACHE; i++) fhits += ft->cached_file_hits[i]; fprintf(fp, " file hit rate: %2ld%% (%ld of %ld)\n", (fhits * 100)/ft->file_cache_fills, fhits, ft->file_cache_fills); } if (ft->dentry_cache_fills) { for (i = dhits = 0; i < DENTRY_CACHE; i++) dhits += ft->cached_dentry_hits[i]; fprintf(fp, " dentry hit rate: %2ld%% (%ld of %ld)\n", (dhits * 100)/ft->dentry_cache_fills, dhits, ft->dentry_cache_fills); } if (ft->inode_cache_fills) { for (i = ihits = 0; i < INODE_CACHE; i++) ihits += ft->cached_inode_hits[i]; fprintf(fp, " inode hit rate: %2ld%% (%ld of %ld)\n", (ihits * 100)/ft->inode_cache_fills, ihits, ft->inode_cache_fills); } } /* * Get the page count for the specific mapping */ static long get_inode_nrpages(ulong i_mapping) { char *address_space_buf; ulong nrpages; address_space_buf = GETBUF(SIZE(address_space)); readmem(i_mapping, KVADDR, address_space_buf, SIZE(address_space), "address_space buffer", FAULT_ON_ERROR); nrpages = ULONG(address_space_buf + OFFSET(address_space_nrpages)); FREEBUF(address_space_buf); return nrpages; } static void dump_inode_page_cache_info(ulong inode) { char *inode_buf; ulong i_mapping, nrpages, root_rnode, xarray, count; struct list_pair lp; char header[BUFSIZE]; char buf1[BUFSIZE]; char buf2[BUFSIZE]; inode_buf = GETBUF(SIZE(inode)); readmem(inode, KVADDR, inode_buf, SIZE(inode), "inode buffer", FAULT_ON_ERROR); i_mapping = ULONG(inode_buf + OFFSET(inode_i_mapping)); nrpages = get_inode_nrpages(i_mapping); sprintf(header, "%s NRPAGES\n", mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "INODE")); fprintf(fp, "%s", header); fprintf(fp, "%s %s\n\n", mkstring(buf1, VADDR_PRLEN, CENTER|RJUST|LONG_HEX, MKSTR(inode)), mkstring(buf2, strlen("NRPAGES"), RJUST|LONG_DEC, MKSTR(nrpages))); FREEBUF(inode_buf); if (!nrpages) return; xarray = root_rnode = count = 0; if (MEMBER_EXISTS("address_space", "i_pages") && (STREQ(MEMBER_TYPE_NAME("address_space", "i_pages"), "xarray") || (STREQ(MEMBER_TYPE_NAME("address_space", "i_pages"), "radix_tree_root") && MEMBER_EXISTS("radix_tree_root", "xa_head")))) xarray = i_mapping + OFFSET(address_space_page_tree); else root_rnode = i_mapping + OFFSET(address_space_page_tree); lp.index = 0; lp.value = (void *)&dump_inode_page; if (root_rnode) count = do_radix_tree(root_rnode, RADIX_TREE_DUMP_CB, &lp); else if (xarray) count = do_xarray(xarray, XARRAY_DUMP_CB, &lp); if (count != nrpages) error(INFO, "%s page count: %ld nrpages: %ld\n", root_rnode ? "radix tree" : "xarray", count, nrpages); return; } /* * This command displays information about the open files of a context. * For each open file descriptor the file descriptor number, a pointer * to the file struct, pointer to the dentry struct, pointer to the inode * struct, indication of file type and pathname are printed. * The argument can be a task address or a PID number; if no args, the * current context is used. * If the flag -l is passed, any files held open in the kernel by the * lockd server on behalf of an NFS client are displayed. */ void cmd_files(void) { int c; ulong value; struct task_context *tc; int subsequent; struct reference reference, *ref; char *refarg; int open_flags = 0; ref = NULL; refarg = NULL; while ((c = getopt(argcnt, args, "d:R:p:c")) != EOF) { switch(c) { case 'R': if (ref) { error(INFO, "only one -R option allowed\n"); argerrs++; } else { ref = &reference; BZERO(ref, sizeof(struct reference)); ref->str = refarg = optarg; } break; case 'd': value = htol(optarg, FAULT_ON_ERROR, NULL); display_dentry_info(value); return; case 'p': if (VALID_MEMBER(address_space_page_tree) && VALID_MEMBER(inode_i_mapping)) { value = htol(optarg, FAULT_ON_ERROR, NULL); dump_inode_page_cache_info(value); } else option_not_supported('p'); return; case 'c': if (VALID_MEMBER(address_space_nrpages) && VALID_MEMBER(inode_i_mapping)) open_flags |= PRINT_NRPAGES; else option_not_supported('c'); break; default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); if (!args[optind]) { if (!ref) print_task_header(fp, CURRENT_CONTEXT(), 0); open_files_dump(CURRENT_TASK(), open_flags, ref); return; } subsequent = 0; while (args[optind]) { if (ref && subsequent) { BZERO(ref, sizeof(struct reference)); ref->str = refarg; } switch (str_to_context(args[optind], &value, &tc)) { case STR_PID: for (tc = pid_to_context(value); tc; tc = tc->tc_next) { if (!ref) print_task_header(fp, tc, subsequent); open_files_dump(tc->task, open_flags, ref); fprintf(fp, "\n"); } break; case STR_TASK: if (!ref) print_task_header(fp, tc, subsequent); open_files_dump(tc->task, open_flags, ref); break; case STR_INVALID: error(INFO, "invalid task or pid value: %s\n", args[optind]); break; } subsequent++; optind++; } } #define FILES_REF_HEXNUM (0x1) #define FILES_REF_DECNUM (0x2) #define FILES_REF_FOUND (0x4) #define PRINT_FILE_REFERENCE() \ if (!root_pwd_printed) { \ print_task_header(fp, tc, 0); \ fprintf(fp, "%s", root_pwd); \ root_pwd_printed = TRUE; \ } \ if (!header_printed) { \ fprintf(fp, "%s", files_header);\ header_printed = TRUE; \ } \ fprintf(fp, "%s", buf4); \ ref->cmdflags |= FILES_REF_FOUND; #define FILENAME_COMPONENT(P,C) \ ((STREQ((P), "/") && STREQ((C), "/")) || \ (!STREQ((C), "/") && strstr((P),(C)))) /* * open_files_dump() does the work for cmd_files(). */ void open_files_dump(ulong task, int flags, struct reference *ref) { struct task_context *tc; ulong files_struct_addr; ulong fdtable_addr = 0; char *files_struct_buf, *fdtable_buf = NULL; ulong fs_struct_addr; char *dentry_buf, *fs_struct_buf; char *ret ATTRIBUTE_UNUSED; ulong root_dentry, pwd_dentry; ulong root_inode, pwd_inode; ulong vfsmnt; int max_fdset = 0; int max_fds = 0; ulong open_fds_addr; int open_fds_size; ulong *open_fds; ulong fd; ulong file; ulong value; int i, j, use_path; int header_printed = 0; char root_pathname[BUFSIZE]; char pwd_pathname[BUFSIZE]; char files_header[BUFSIZE]; char buf1[BUFSIZE]; char buf2[BUFSIZE]; char buf3[BUFSIZE]; char buf4[BUFSIZE]; char root_pwd[BUFSIZE*4]; int root_pwd_printed = 0; int file_dump_flags = 0; BZERO(root_pathname, BUFSIZE); BZERO(pwd_pathname, BUFSIZE); files_struct_buf = GETBUF(SIZE(files_struct)); if (VALID_STRUCT(fdtable)) fdtable_buf = GETBUF(SIZE(fdtable)); fill_task_struct(task); if (flags & PRINT_NRPAGES) { sprintf(files_header, " FD%s%s%s%s%sNRPAGES%sTYPE%sPATH\n", space(MINSPACE), mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "INODE"), space(MINSPACE), mkstring(buf2, MAX(VADDR_PRLEN, strlen("I_MAPPING")), BITS32() ? (CENTER|RJUST) : (CENTER|LJUST), "I_MAPPING"), space(MINSPACE), space(MINSPACE), space(MINSPACE)); } else { sprintf(files_header, " FD%s%s%s%s%s%s%sTYPE%sPATH\n", space(MINSPACE), mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "FILE"), space(MINSPACE), mkstring(buf2, VADDR_PRLEN, CENTER|LJUST, "DENTRY"), space(MINSPACE), mkstring(buf3, VADDR_PRLEN, CENTER|LJUST, "INODE"), space(MINSPACE), space(MINSPACE)); } tc = task_to_context(task); if (ref) ref->cmdflags = 0; fs_struct_addr = ULONG(tt->task_struct + OFFSET(task_struct_fs)); if (fs_struct_addr) { fs_struct_buf = GETBUF(SIZE(fs_struct)); readmem(fs_struct_addr, KVADDR, fs_struct_buf, SIZE(fs_struct), "fs_struct buffer", FAULT_ON_ERROR); use_path = (MEMBER_TYPE("fs_struct", "root") == TYPE_CODE_STRUCT); if (use_path) root_dentry = ULONG(fs_struct_buf + OFFSET(fs_struct_root) + OFFSET(path_dentry)); else root_dentry = ULONG(fs_struct_buf + OFFSET(fs_struct_root)); if (root_dentry) { if (VALID_MEMBER(fs_struct_rootmnt)) { vfsmnt = ULONG(fs_struct_buf + OFFSET(fs_struct_rootmnt)); get_pathname(root_dentry, root_pathname, BUFSIZE, 1, vfsmnt); } else if (use_path) { vfsmnt = ULONG(fs_struct_buf + OFFSET(fs_struct_root) + OFFSET(path_mnt)); get_pathname(root_dentry, root_pathname, BUFSIZE, 1, vfsmnt); } else { get_pathname(root_dentry, root_pathname, BUFSIZE, 1, 0); } } if (use_path) pwd_dentry = ULONG(fs_struct_buf + OFFSET(fs_struct_pwd) + OFFSET(path_dentry)); else pwd_dentry = ULONG(fs_struct_buf + OFFSET(fs_struct_pwd)); if (pwd_dentry) { if (VALID_MEMBER(fs_struct_pwdmnt)) { vfsmnt = ULONG(fs_struct_buf + OFFSET(fs_struct_pwdmnt)); get_pathname(pwd_dentry, pwd_pathname, BUFSIZE, 1, vfsmnt); } else if (use_path) { vfsmnt = ULONG(fs_struct_buf + OFFSET(fs_struct_pwd) + OFFSET(path_mnt)); get_pathname(pwd_dentry, pwd_pathname, BUFSIZE, 1, vfsmnt); } else { get_pathname(pwd_dentry, pwd_pathname, BUFSIZE, 1, 0); } } if ((flags & PRINT_INODES) && root_dentry && pwd_dentry) { dentry_buf = fill_dentry_cache(root_dentry); root_inode = ULONG(dentry_buf + OFFSET(dentry_d_inode)); dentry_buf = fill_dentry_cache(pwd_dentry); pwd_inode = ULONG(dentry_buf + OFFSET(dentry_d_inode)); fprintf(fp, "ROOT: %lx %s CWD: %lx %s\n", root_inode, root_pathname, pwd_inode, pwd_pathname); } else if (ref) { snprintf(root_pwd, sizeof(root_pwd), "ROOT: %s CWD: %s \n", root_pathname, pwd_pathname); if (FILENAME_COMPONENT(root_pathname, ref->str) || FILENAME_COMPONENT(pwd_pathname, ref->str)) { print_task_header(fp, tc, 0); fprintf(fp, "%s", root_pwd); root_pwd_printed = TRUE; ref->cmdflags |= FILES_REF_FOUND; } } else fprintf(fp, "ROOT: %s CWD: %s\n", root_pathname, pwd_pathname); FREEBUF(fs_struct_buf); } files_struct_addr = ULONG(tt->task_struct + OFFSET(task_struct_files)); if (files_struct_addr) { readmem(files_struct_addr, KVADDR, files_struct_buf, SIZE(files_struct), "files_struct buffer", FAULT_ON_ERROR); if (VALID_MEMBER(files_struct_max_fdset)) { max_fdset = INT(files_struct_buf + OFFSET(files_struct_max_fdset)); max_fds = INT(files_struct_buf + OFFSET(files_struct_max_fds)); } } if (VALID_MEMBER(files_struct_fdt)) { fdtable_addr = ULONG(files_struct_buf + OFFSET(files_struct_fdt)); if (fdtable_addr) { readmem(fdtable_addr, KVADDR, fdtable_buf, SIZE(fdtable), "fdtable buffer", FAULT_ON_ERROR); if (VALID_MEMBER(fdtable_max_fdset)) max_fdset = INT(fdtable_buf + OFFSET(fdtable_max_fdset)); else max_fdset = -1; max_fds = INT(fdtable_buf + OFFSET(fdtable_max_fds)); } } if ((VALID_MEMBER(files_struct_fdt) && !fdtable_addr) || !files_struct_addr || max_fdset == 0 || max_fds == 0) { if (ref) { if (ref->cmdflags & FILES_REF_FOUND) fprintf(fp, "\n"); } else fprintf(fp, "No open files\n"); if (fdtable_buf) FREEBUF(fdtable_buf); FREEBUF(files_struct_buf); return; } if (ref && IS_A_NUMBER(ref->str)) { if (hexadecimal_only(ref->str, 0)) { ref->hexval = htol(ref->str, FAULT_ON_ERROR, NULL); ref->cmdflags |= FILES_REF_HEXNUM; } else { value = dtol(ref->str, FAULT_ON_ERROR, NULL); if (value <= MAX(max_fdset, max_fds)) { ref->decval = value; ref->cmdflags |= FILES_REF_DECNUM; } else { ref->hexval = htol(ref->str, FAULT_ON_ERROR, NULL); ref->cmdflags |= FILES_REF_HEXNUM; } } } if (VALID_MEMBER(fdtable_open_fds)) open_fds_addr = ULONG(fdtable_buf + OFFSET(fdtable_open_fds)); else open_fds_addr = ULONG(files_struct_buf + OFFSET(files_struct_open_fds)); open_fds_size = MAX(max_fdset, max_fds) / BITS_PER_BYTE; open_fds = (ulong *)GETBUF(open_fds_size); if (!open_fds) { if (fdtable_buf) FREEBUF(fdtable_buf); FREEBUF(files_struct_buf); return; } if (open_fds_addr) { if (VALID_MEMBER(files_struct_open_fds_init) && (open_fds_addr == (files_struct_addr + OFFSET(files_struct_open_fds_init)))) BCOPY(files_struct_buf + OFFSET(files_struct_open_fds_init), open_fds, open_fds_size); else readmem(open_fds_addr, KVADDR, open_fds, open_fds_size, "fdtable open_fds", FAULT_ON_ERROR); } if (VALID_MEMBER(fdtable_fd)) fd = ULONG(fdtable_buf + OFFSET(fdtable_fd)); else fd = ULONG(files_struct_buf + OFFSET(files_struct_fd)); if (!open_fds_addr || !fd) { if (ref && (ref->cmdflags & FILES_REF_FOUND)) fprintf(fp, "\n"); if (fdtable_buf) FREEBUF(fdtable_buf); FREEBUF(files_struct_buf); FREEBUF(open_fds); return; } file_dump_flags = DUMP_FULL_NAME | DUMP_EMPTY_FILE; if (flags & PRINT_NRPAGES) file_dump_flags |= DUMP_FILE_NRPAGES; j = 0; for (;;) { unsigned long set; i = j * BITS_PER_LONG; if (((max_fdset >= 0) && (i >= max_fdset)) || (i >= max_fds)) break; set = open_fds[j++]; while (set) { if (set & 1) { readmem(fd + i*sizeof(struct file *), KVADDR, &file, sizeof(struct file *), "fd file", FAULT_ON_ERROR); if (ref && file) { open_tmpfile(); if (file_dump(file, 0, 0, i, file_dump_flags)) { BZERO(buf4, BUFSIZE); rewind(pc->tmpfile); ret = fgets(buf4, BUFSIZE, pc->tmpfile); close_tmpfile(); ref->refp = buf4; if (open_file_reference(ref)) { PRINT_FILE_REFERENCE(); } } else close_tmpfile(); } else if (file) { if (!header_printed) { fprintf(fp, "%s", files_header); header_printed = 1; } file_dump(file, 0, 0, i, file_dump_flags); } } i++; set >>= 1; } } if (!header_printed && !ref) fprintf(fp, "No open files\n"); if (ref && (ref->cmdflags & FILES_REF_FOUND)) fprintf(fp, "\n"); if (fdtable_buf) FREEBUF(fdtable_buf); FREEBUF(files_struct_buf); FREEBUF(open_fds); } /* * Check an open file string for references. */ static int open_file_reference(struct reference *ref) { char buf[BUFSIZE]; char *arglist[MAXARGS]; int i, fd, argcnt; ulong vaddr; strcpy(buf, ref->refp); if ((argcnt = parse_line(buf, arglist)) < 5) return FALSE; if (ref->cmdflags & (FILES_REF_HEXNUM|FILES_REF_DECNUM)) { fd = dtol(arglist[0], FAULT_ON_ERROR, NULL); if (((ref->cmdflags & FILES_REF_HEXNUM) && (fd == ref->hexval)) || ((ref->cmdflags & FILES_REF_DECNUM) && (fd == ref->decval))) { return TRUE; } for (i = 1; i < 4; i++) { if (STREQ(arglist[i], "?")) continue; vaddr = htol(arglist[i], FAULT_ON_ERROR, NULL); if (vaddr == ref->hexval) return TRUE; } } if (STREQ(ref->str, arglist[4])) { return TRUE; } if ((argcnt == 6) && FILENAME_COMPONENT(arglist[5], ref->str)) { return TRUE; } return FALSE; } #ifdef DEPRECATED /* * nlm_files_dump() prints files held open by lockd server on behalf * of NFS clients */ #define FILE_NRHASH 32 char nlm_files_header[BUFSIZE] = { 0 }; char *nlm_header = \ "Files open by lockd for client discretionary file locks:\n"; void nlm_files_dump(void) { int header_printed = 0; int i, j, cnt; ulong nlmsvc_ops, nlm_files; struct syment *nsp; ulong nlm_files_array[FILE_NRHASH]; struct list_data list_data, *ld; ulong *file, *files_list; ulong dentry, inode, flock, host, client; char buf1[BUFSIZE]; char buf2[BUFSIZE]; if (!strlen(nlm_files_header)) { sprintf(nlm_files_header, "CLIENT %s %s%sTYPE%sPATH\n", mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "NLM_FILE"), mkstring(buf2, VADDR_PRLEN, CENTER|LJUST, "INODE"), space(MINSPACE), space(MINSPACE)); } if (!symbol_exists("nlm_files") || !symbol_exists("nlmsvc_ops") || !symbol_exists("nfsd_nlm_ops")) { goto out; } get_symbol_data("nlmsvc_ops", sizeof(void *), &nlmsvc_ops); if (nlmsvc_ops != symbol_value("nfsd_nlm_ops")) { goto out; } if ((nsp = next_symbol("nlm_files", NULL)) == NULL) { error(WARNING, "cannot find next symbol after nlm_files\n"); goto out; } nlm_files = symbol_value("nlm_files"); if (((nsp->value - nlm_files) / sizeof(void *)) != FILE_NRHASH ) { error(WARNING, "FILE_NRHASH has changed from %d\n", FILE_NRHASH); if (((nsp->value - nlm_files) / sizeof(void *)) < FILE_NRHASH ) goto out; } readmem(nlm_files, KVADDR, nlm_files_array, sizeof(ulong) * FILE_NRHASH, "nlm_files array", FAULT_ON_ERROR); for (i = 0; i < FILE_NRHASH; i++) { if (nlm_files_array[i] == 0) { continue; } ld = &list_data; BZERO(ld, sizeof(struct list_data)); ld->start = nlm_files_array[i]; hq_open(); cnt = do_list(ld); files_list = (ulong *)GETBUF(cnt * sizeof(ulong)); cnt = retrieve_list(files_list, cnt); hq_close(); for (j=0, file = files_list; j 1 || !STREQ(buf, "/")) && !STRNEQ(tmpname, "/")) { sprintf(pathname, "%s%s%s", buf, "/", tmpname); } else { sprintf(pathname, "%s%s", buf, tmpname); } } } else { strncpy(pathname, buf, BUFSIZE); } parent = ULONG(dentry_buf + OFFSET(dentry_d_parent)); if (tmp_dentry == parent && full) { if (VALID_MEMBER(vfsmount_mnt_mountpoint)) { if (tmp_vfsmnt) { if (strncmp(pathname, "//", 2) == 0) shift_string_left(pathname, 1); readmem(tmp_vfsmnt, KVADDR, vfsmnt_buf, SIZE(vfsmount), "vfsmount buffer", FAULT_ON_ERROR); parent = ULONG(vfsmnt_buf + OFFSET(vfsmount_mnt_mountpoint)); mnt_parent = ULONG(vfsmnt_buf + OFFSET(vfsmount_mnt_parent)); if (tmp_vfsmnt == mnt_parent) break; else tmp_vfsmnt = mnt_parent; goto more_vfsmnt; } } else if (VALID_STRUCT(mount)) { if (tmp_vfsmnt) { if (strncmp(pathname, "//", 2) == 0) shift_string_left(pathname, 1); readmem(tmp_vfsmnt - OFFSET(mount_mnt), KVADDR, mnt_buf, SIZE(mount), "mount buffer", FAULT_ON_ERROR); parent = ULONG(mnt_buf + OFFSET(mount_mnt_mountpoint)); mnt_parent = ULONG(mnt_buf + OFFSET(mount_mnt_parent)); if ((tmp_vfsmnt - OFFSET(mount_mnt)) == mnt_parent) break; else tmp_vfsmnt = mnt_parent + OFFSET(mount_mnt); goto more_vfsmnt; } } else { parent = ULONG(dentry_buf + OFFSET(dentry_d_covers)); } } } while (tmp_dentry != parent && parent); if (!STREQ(pathname, "/") && LASTCHAR(pathname) == '/') { LASTCHAR(pathname) = '\0'; } if (mnt_buf) FREEBUF(mnt_buf); else if (vfsmnt_buf) FREEBUF(vfsmnt_buf); } /* * If the pathname component, which may be internal or external to the * dentry, has string length equal to what's expected, copy it into the * passed-in buffer, and return its length. If it doesn't match, return 0. */ static int get_pathname_component(ulong dentry, ulong d_name_name, int d_name_len, char *dentry_buf, char *pathbuf) { int len = d_name_len; /* presume success */ if (d_name_name == (dentry + OFFSET(dentry_d_iname))) { if (strlen(dentry_buf + OFFSET(dentry_d_iname)) == d_name_len) strcpy(pathbuf, dentry_buf + OFFSET(dentry_d_iname)); else len = 0; } else if ((read_string(d_name_name, pathbuf, BUFSIZE)) != d_name_len) len = 0; return len; } /* * Cache the passed-in file structure. */ char * fill_file_cache(ulong file) { int i; char *cache; ft->file_cache_fills++; for (i = 0; i < DENTRY_CACHE; i++) { if (ft->cached_file[i] == file) { ft->cached_file_hits[i]++; cache = ft->file_cache + (SIZE(file)*i); return(cache); } } cache = ft->file_cache + (SIZE(file)*ft->file_cache_index); readmem(file, KVADDR, cache, SIZE(file), "fill_file_cache", FAULT_ON_ERROR); ft->cached_file[ft->file_cache_index] = file; ft->file_cache_index = (ft->file_cache_index+1) % DENTRY_CACHE; return(cache); } /* * If active, clear the file references. */ void clear_file_cache(void) { int i; if (DUMPFILE()) return; for (i = 0; i < DENTRY_CACHE; i++) { ft->cached_file[i] = 0; ft->cached_file_hits[i] = 0; } ft->file_cache_fills = 0; ft->file_cache_index = 0; } /* * Cache the passed-in dentry structure. */ char * fill_dentry_cache(ulong dentry) { int i; char *cache; ft->dentry_cache_fills++; for (i = 0; i < DENTRY_CACHE; i++) { if (ft->cached_dentry[i] == dentry) { ft->cached_dentry_hits[i]++; cache = ft->dentry_cache + (SIZE(dentry)*i); return(cache); } } cache = ft->dentry_cache + (SIZE(dentry)*ft->dentry_cache_index); readmem(dentry, KVADDR, cache, SIZE(dentry), "fill_dentry_cache", FAULT_ON_ERROR); ft->cached_dentry[ft->dentry_cache_index] = dentry; ft->dentry_cache_index = (ft->dentry_cache_index+1) % DENTRY_CACHE; return(cache); } /* * If active, clear the dentry references. */ void clear_dentry_cache(void) { int i; if (DUMPFILE()) return; for (i = 0; i < DENTRY_CACHE; i++) { ft->cached_dentry[i] = 0; ft->cached_dentry_hits[i] = 0; } ft->dentry_cache_fills = 0; ft->dentry_cache_index = 0; } /* * Cache the passed-in inode structure. */ char * fill_inode_cache(ulong inode) { int i; char *cache; ft->inode_cache_fills++; for (i = 0; i < INODE_CACHE; i++) { if (ft->cached_inode[i] == inode) { ft->cached_inode_hits[i]++; cache = ft->inode_cache + (SIZE(inode)*i); return(cache); } } cache = ft->inode_cache + (SIZE(inode)*ft->inode_cache_index); readmem(inode, KVADDR, cache, SIZE(inode), "fill_inode_cache", FAULT_ON_ERROR); ft->cached_inode[ft->inode_cache_index] = inode; ft->inode_cache_index = (ft->inode_cache_index+1) % INODE_CACHE; return(cache); } /* * If active, clear the inode references. */ void clear_inode_cache(void) { int i; if (DUMPFILE()) return; for (i = 0; i < DENTRY_CACHE; i++) { ft->cached_inode[i] = 0; ft->cached_inode_hits[i] = 0; } ft->inode_cache_fills = 0; ft->inode_cache_index = 0; } /* * This command displays the tasks using specified files or sockets. * Tasks will be listed that reference the file as the current working * directory, root directory, an open file descriptor, or that mmap the * file. * The argument can be a full pathname without symbolic links, or inode * address. */ void cmd_fuser(void) { int c; char *spec_string, *tmp; struct foreach_data foreach_data, *fd; char task_buf[BUFSIZE]; char buf[BUFSIZE]; char uses[20]; char fuser_header[BUFSIZE]; int doing_fds, doing_mmap, len; int fuser_header_printed, lockd_header_printed; ulong spec_addr; while ((c = getopt(argcnt, args, "")) != EOF) { switch(c) { default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, SYNOPSIS); if (!args[optind]) { cmd_usage(pc->curcmd, SYNOPSIS); return; } sprintf(fuser_header, " PID %s COMM USAGE\n", mkstring(buf, VADDR_PRLEN, CENTER, "TASK")); doing_fds = doing_mmap = 0; while (args[optind]) { spec_string = args[optind]; spec_addr = htol(spec_string, RETURN_ON_ERROR|QUIET, NULL); if ((spec_addr == BADADDR || !IS_KVADDR(spec_addr)) && spec_string[0] != '/') error(FATAL, "invalid argument: %s\n", args[optind]); if (STRNEQ(spec_string, "0x") && hexadecimal(spec_string, 0)) shift_string_left(spec_string, 2); len = strlen(spec_string); fuser_header_printed = 0; lockd_header_printed = 0; open_tmpfile(); BZERO(&foreach_data, sizeof(struct foreach_data)); fd = &foreach_data; fd->keyword_array[0] = FOREACH_FILES; fd->keyword_array[1] = FOREACH_VM; fd->keys = 2; fd->flags |= FOREACH_i_FLAG; foreach(fd); rewind(pc->tmpfile); BZERO(uses, 20); while (fgets(buf, BUFSIZE, pc->tmpfile)) { if (STRNEQ(buf, "PID:")) { if (!STREQ(uses, "")) { if (!fuser_header_printed) { fprintf(pc->saved_fp, "%s", fuser_header); fuser_header_printed = 1; } show_fuser(task_buf, uses); BZERO(uses, 20); } BZERO(task_buf, BUFSIZE); strcpy(task_buf, buf); doing_fds = doing_mmap = 0; continue; } if (STRNEQ(buf, "ROOT:")) { if ((tmp = strstr(buf, spec_string)) && (tmp[len] == ' ' || tmp[len] == '\n')) { if (strstr(tmp, "CWD:")) { strcat(uses, "root "); if ((tmp = strstr(tmp+len, spec_string)) && (tmp[len] == ' ' || tmp[len] == '\n')) { strcat(uses, "cwd "); } } else { strcat(uses, "cwd "); } } continue; } if (strstr(buf, "DENTRY")) { doing_fds = 1; continue; } if (strstr(buf, "TOTAL_VM")) { doing_fds = 0; continue; } if (strstr(buf, " VMA ")) { doing_mmap = 1; doing_fds = 0; continue; } if ((tmp = strstr(buf, spec_string)) && (tmp[len] == ' ' || tmp[len] == '\n')) { if (doing_fds) { strcat(uses, "fd "); doing_fds = 0; } if (doing_mmap) { strcat(uses, "mmap "); doing_mmap = 0; } } } if (!STREQ(uses, "")) { if (!fuser_header_printed) { fprintf(pc->saved_fp, "%s", fuser_header); fuser_header_printed = 1; } show_fuser(task_buf, uses); BZERO(uses, 20); } close_tmpfile(); optind++; if (!fuser_header_printed && !lockd_header_printed) { fprintf(fp, "No users of %s found\n", spec_string); } } } static void show_fuser(char *buf, char *uses) { char pid[10]; char task[20]; char command[20]; char *p; int i; BZERO(pid, 10); BZERO(task, 20); BZERO(command, 20); p = strstr(buf, "PID: ") + strlen("PID: "); i = 0; while (*p != ' ' && i < 10) { pid[i++] = *p++; } pid[i] = NULLCHAR; p = strstr(buf, "TASK: ") + strlen("TASK: "); while (*p == ' ') p++; i = 0; while (*p != ' ' && i < 20) { task[i++] = *p++; } task[i] = NULLCHAR; mkstring(task, VADDR_PRLEN, RJUST, task); p = strstr(buf, "COMMAND: ") + strlen("COMMAND: "); strncpy(command, p, 16); i = strlen(command) - 1; while (i < 16) { command[i++] = ' '; } command[16] = NULLCHAR; fprintf(pc->saved_fp, "%5s %s %s %s\n", pid, task, command, uses); } /* * Gather some host memory/swap statistics, passing back whatever the * caller requires. */ int monitor_memory(long *freemem_pages, long *freeswap_pages, long *mem_usage, long *swap_usage) { FILE *mp; char buf[BUFSIZE]; char *arglist[MAXARGS]; int argc ATTRIBUTE_UNUSED; int params; ulong freemem, memtotal, freeswap, swaptotal; if (!file_exists("/proc/meminfo", NULL)) return FALSE; if ((mp = fopen("/proc/meminfo", "r")) == NULL) return FALSE; params = 0; freemem = memtotal = freeswap = swaptotal = 0; while (fgets(buf, BUFSIZE, mp)) { if (strstr(buf, "SwapFree")) { params++; argc = parse_line(buf, arglist); if (decimal(arglist[1], 0)) freeswap = (atol(arglist[1]) * 1024)/PAGESIZE(); } if (strstr(buf, "MemFree")) { params++; argc = parse_line(buf, arglist); if (decimal(arglist[1], 0)) freemem = (atol(arglist[1]) * 1024)/PAGESIZE(); } if (strstr(buf, "MemTotal")) { params++; argc = parse_line(buf, arglist); if (decimal(arglist[1], 0)) memtotal = (atol(arglist[1]) * 1024)/PAGESIZE(); } if (strstr(buf, "SwapTotal")) { params++; argc = parse_line(buf, arglist); if (decimal(arglist[1], 0)) swaptotal = (atol(arglist[1]) * 1024)/PAGESIZE(); } } fclose(mp); if (params != 4) return FALSE; if (freemem_pages) *freemem_pages = freemem; if (freeswap_pages) *freeswap_pages = freeswap; if (mem_usage) *mem_usage = ((memtotal-freemem)*100) / memtotal; if (swap_usage) *swap_usage = ((swaptotal-freeswap)*100) / swaptotal; return TRUE; } /* * Determine whether two filenames reference the same file. */ int same_file(char *f1, char *f2) { struct stat stat1, stat2; if ((stat(f1, &stat1) != 0) || (stat(f2, &stat2) != 0)) return FALSE; if ((stat1.st_dev == stat2.st_dev) && (stat1.st_ino == stat2.st_ino)) return TRUE; return FALSE; } /* * Determine which live memory source to use. */ #define MODPROBE_CMD "/sbin/modprobe -l --type drivers/char 2>&1" static void get_live_memory_source(void) { FILE *pipe; char buf[BUFSIZE]; char modname1[BUFSIZE/2]; char modname2[BUFSIZE/2]; char *name; int use_module, crashbuiltin; struct stat stat1, stat2; struct utsname utsname; if (!(pc->flags & PROC_KCORE)) pc->flags |= DEVMEM; if (pc->live_memsrc) goto live_report; if (file_readable("/dev/mem")) pc->live_memsrc = "/dev/mem"; else if (file_exists("/proc/kcore", NULL)) { pc->flags &= ~DEVMEM; pc->flags |= PROC_KCORE; pc->live_memsrc = "/proc/kcore"; } use_module = crashbuiltin = FALSE; if (file_exists("/dev/mem", &stat1) && file_exists(pc->memory_device, &stat2) && S_ISCHR(stat1.st_mode) && S_ISCHR(stat2.st_mode) && (stat1.st_rdev == stat2.st_rdev)) { if (!STREQ(pc->memory_device, "/dev/mem")) error(INFO, "%s: same device as /dev/mem\n%s", pc->memory_device, pc->memory_module ? "" : "\n"); if (pc->memory_module) error(INFO, "ignoring --memory_module %s request\n\n", pc->memory_module); } else if (pc->memory_module && memory_driver_module_loaded(NULL)) { error(INFO, "using pre-loaded \"%s\" module\n\n", pc->memory_module); pc->flags |= MODPRELOAD; use_module = TRUE; } else { pc->memory_module = MEMORY_DRIVER_MODULE; if ((pipe = popen(MODPROBE_CMD, "r")) == NULL) { error(INFO, "%s: %s\n", MODPROBE_CMD, strerror(errno)); return; } sprintf(modname1, "%s.o", pc->memory_module); sprintf(modname2, "%s.ko", pc->memory_module); while (fgets(buf, BUFSIZE, pipe)) { if (strstr(buf, "invalid option") && (uname(&utsname) == 0)) { sprintf(buf, "/lib/modules/%s/kernel/drivers/char/%s", utsname.release, modname2); if (file_exists(buf, &stat1)) use_module = TRUE; else { strcat(buf, ".xz"); if (file_exists(buf, &stat1)) use_module = TRUE; } break; } name = basename(strip_linefeeds(buf)); if (STREQ(name, modname1) || STREQ(name, modname2)) { use_module = TRUE; break; } } pclose(pipe); if (!use_module && file_exists("/dev/crash", &stat1) && S_ISCHR(stat1.st_mode)) crashbuiltin = TRUE; } if (use_module) { pc->flags &= ~(DEVMEM|PROC_KCORE); pc->flags |= MEMMOD; pc->readmem = read_memory_device; pc->writemem = write_memory_device; pc->live_memsrc = pc->memory_device; } if (crashbuiltin) { pc->flags &= ~(DEVMEM|PROC_KCORE); pc->flags |= CRASHBUILTIN; pc->readmem = read_memory_device; pc->writemem = write_memory_device; pc->live_memsrc = pc->memory_device; pc->memory_module = NULL; } live_report: if (CRASHDEBUG(1)) fprintf(fp, "get_live_memory_source: %s\n", pc->live_memsrc); } /* * Read /proc/modules to determine whether the crash driver module * has been loaded. */ static int memory_driver_module_loaded(int *count) { FILE *modules; int argcnt, module_loaded; char *arglist[MAXARGS]; char buf[BUFSIZE]; if ((modules = fopen("/proc/modules", "r")) == NULL) { error(INFO, "/proc/modules: %s\n", strerror(errno)); return FALSE; } module_loaded = FALSE; while (fgets(buf, BUFSIZE, modules)) { console("%s", buf); argcnt = parse_line(buf, arglist); if (argcnt < 3) continue; if (STREQ(arglist[0], pc->memory_module)) { module_loaded = TRUE; if (CRASHDEBUG(1)) fprintf(stderr, "\"%s\" module loaded: [%s][%s][%s]\n", arglist[0], arglist[0], arglist[1], arglist[2]); if (count) *count = atoi(arglist[2]); break; } } fclose(modules); return module_loaded; } /* * Insmod the memory driver module. */ static int insmod_memory_driver_module(void) { FILE *pipe; char buf[BUFSIZE]; char command[BUFSIZE]; sprintf(command, "/sbin/modprobe %s", pc->memory_module); if (CRASHDEBUG(1)) fprintf(fp, "%s\n", command); if ((pipe = popen(command, "r")) == NULL) { error(INFO, "%s: %s", command, strerror(errno)); return FALSE; } while (fgets(buf, BUFSIZE, pipe)) fprintf(fp, "%s\n", buf); pclose(pipe); if (!memory_driver_module_loaded(NULL)) { error(INFO, "cannot insmod \"%s\" module\n", pc->memory_module); return FALSE; } return TRUE; } /* * Return the dev_t for the memory device driver. The major number will * be that of the kernel's misc driver; the minor is dynamically created * when the module at inmod time, and found in /proc/misc. */ static int get_memory_driver_dev(dev_t *devp) { char buf[BUFSIZE]; char *arglist[MAXARGS]; int argcnt; FILE *misc; int minor; dev_t dev; dev = 0; if ((misc = fopen("/proc/misc", "r")) == NULL) { error(INFO, "/proc/misc: %s", strerror(errno)); } else { while (fgets(buf, BUFSIZE, misc)) { argcnt = parse_line(buf, arglist); if ((argcnt == 2) && STREQ(arglist[1], pc->memory_module)) { minor = atoi(arglist[0]); dev = makedev(MISC_MAJOR, minor); if (CRASHDEBUG(1)) fprintf(fp, "/proc/misc: %s %s => %d/%d\n", arglist[0], arglist[1], major(dev), minor(dev)); break; } } fclose(misc); } if (!dev) { error(INFO, "cannot determine minor number of %s driver\n", pc->memory_module); return FALSE; } *devp = dev; return TRUE; } /* * Deal with the creation or verification of the memory device file: * * 1. If the device exists, and has the correct major/minor device numbers, * nothing needs to be done. * 2. If the filename exists, but it's not a device file, has the wrong * major/minor device numbers, or the wrong permissions, advise the * user to delete it. * 3. Otherwise, create it. */ static int create_memory_device(dev_t dev) { struct stat stat; if (file_exists(pc->live_memsrc, &stat)) { /* * It already exists -- just use it. */ if ((stat.st_mode == MEMORY_DRIVER_DEVICE_MODE) && (stat.st_rdev == dev)) return TRUE; /* * Either it's not a device special file, or it's got * the wrong major/minor numbers, or the wrong permissions. * Unlink the file -- it shouldn't be there. */ if (!S_ISCHR(stat.st_mode)) error(FATAL, "%s: not a character device -- please delete it!\n", pc->live_memsrc); else if (dev != stat.st_rdev) error(FATAL, "%s: invalid device: %d/%d -- please delete it!\n", pc->live_memsrc, major(stat.st_rdev), minor(stat.st_rdev)); else unlink(pc->live_memsrc); } /* * Either it doesn't exist or it was just unlinked. * In either case, try to create it. */ if (mknod(pc->live_memsrc, MEMORY_DRIVER_DEVICE_MODE, dev)) { error(INFO, "%s: mknod: %s\n", pc->live_memsrc, strerror(errno)); return FALSE; } return TRUE; } /* * If we're here, the memory driver module is being requested: * * 1. If /dev/crash is built into the kernel, just open it. * 2. If the module is not already loaded, insmod it. * 3. Determine the misc driver minor device number that it was assigned. * 4. Create (or verify) the device file. * 5. Then just open it. */ static int memory_driver_init(void) { dev_t dev; if (pc->flags & CRASHBUILTIN) goto open_device; if (!memory_driver_module_loaded(NULL)) { if (!insmod_memory_driver_module()) return FALSE; } else pc->flags |= MODPRELOAD; if (!get_memory_driver_dev(&dev)) return FALSE; if (!create_memory_device(dev)) return FALSE; open_device: if ((pc->mfd = open(pc->memory_device, O_RDONLY)) < 0) { error(INFO, "%s: open: %s\n", pc->memory_device, strerror(errno)); return FALSE; } return TRUE; } /* * Remove the memory driver module and associated file. */ int cleanup_memory_driver(void) { int errors, count; char command[BUFSIZE]; count = errors = 0; if (pc->flags & KERNEL_DEBUG_QUERY) return TRUE; close(pc->mfd); if (file_exists(pc->memory_device, NULL) && unlink(pc->memory_device)) { error(INFO, "%s: %s\n", pc->memory_device, strerror(errno)); errors++; } if (!(pc->flags & MODPRELOAD) && memory_driver_module_loaded(&count) && !count) { sprintf(command, "/sbin/rmmod %s", pc->memory_module); if (CRASHDEBUG(1)) fprintf(fp, "%s\n", command); errors += system(command); } if (errors) error(NOTE, "cleanup_memory_driver failed\n"); return errors ? FALSE : TRUE; } struct do_radix_tree_info { ulong maxcount; ulong count; void *data; }; static void do_radix_tree_count(ulong node, ulong slot, const char *path, ulong index, void *private) { struct do_radix_tree_info *info = private; info->count++; } static void do_radix_tree_search(ulong node, ulong slot, const char *path, ulong index, void *private) { struct do_radix_tree_info *info = private; struct list_pair *rtp = info->data; if (rtp->index == index) { rtp->value = (void *)slot; info->count = 1; } } static void do_radix_tree_dump(ulong node, ulong slot, const char *path, ulong index, void *private) { struct do_radix_tree_info *info = private; fprintf(fp, "[%ld] %lx\n", index, slot); info->count++; } static void do_radix_tree_gather(ulong node, ulong slot, const char *path, ulong index, void *private) { struct do_radix_tree_info *info = private; struct list_pair *rtp = info->data; if (info->maxcount) { rtp[info->count].index = index; rtp[info->count].value = (void *)slot; info->count++; info->maxcount--; } } static void do_radix_tree_dump_cb(ulong node, ulong slot, const char *path, ulong index, void *private) { struct do_radix_tree_info *info = private; struct list_pair *rtp = info->data; int (*cb)(ulong) = rtp->value; /* Caller defined operation */ if (!cb(slot)) { if ((slot & RADIX_TREE_ENTRY_MASK) == RADIX_TREE_EXCEPTIONAL_ENTRY) { if (CRASHDEBUG(1)) error(INFO, "RADIX_TREE_EXCEPTIONAL_ENTRY: %lx\n", slot); return; } error(FATAL, "do_radix_tree: callback " "operation failed: entry: %ld item: %lx\n", info->count, slot); } info->count++; } /* * do_radix_tree argument usage: * * root: Address of a radix_tree_root structure * * flag: RADIX_TREE_COUNT - Return the number of entries in the tree. * RADIX_TREE_SEARCH - Search for an entry at rtp->index; if found, * store the entry in rtp->value and return a count of 1; otherwise * return a count of 0. * RADIX_TREE_DUMP - Dump all existing index/value pairs. * RADIX_TREE_GATHER - Store all existing index/value pairs in the * passed-in array of list_pair structs starting at rtp, * returning the count of entries stored; the caller can/should * limit the number of returned entries by putting the array size * (max count) in the rtp->index field of the first structure * in the passed-in array. * RADIX_TREE_DUMP_CB - Similar with RADIX_TREE_DUMP, but for each * radix tree entry, a user defined callback at rtp->value will * be invoked. * * rtp: Unused by RADIX_TREE_COUNT and RADIX_TREE_DUMP. * A pointer to a list_pair structure for RADIX_TREE_SEARCH. * A pointer to an array of list_pair structures for * RADIX_TREE_GATHER; the dimension (max count) of the array may * be stored in the index field of the first structure to avoid * any chance of an overrun. * For RADIX_TREE_DUMP_CB, the rtp->value must be initialized as a * callback function. The callback prototype must be: int (*)(ulong); */ ulong do_radix_tree(ulong root, int flag, struct list_pair *rtp) { struct do_radix_tree_info info = { .count = 0, .data = rtp, }; struct radix_tree_ops ops = { .radix = 16, .private = &info, }; switch (flag) { case RADIX_TREE_COUNT: ops.entry = do_radix_tree_count; break; case RADIX_TREE_SEARCH: /* * FIXME: do_radix_tree_traverse() traverses whole * radix tree, not binary search. So this search is * not efficient. */ ops.entry = do_radix_tree_search; break; case RADIX_TREE_DUMP: ops.entry = do_radix_tree_dump; break; case RADIX_TREE_GATHER: if (!(info.maxcount = rtp->index)) info.maxcount = (ulong)(-1); /* caller beware */ ops.entry = do_radix_tree_gather; break; case RADIX_TREE_DUMP_CB: if (rtp->value == NULL) { error(FATAL, "do_radix_tree: need set callback function"); return -EINVAL; } ops.entry = do_radix_tree_dump_cb; break; default: error(FATAL, "do_radix_tree: invalid flag: %lx\n", flag); } do_radix_tree_traverse(root, 1, &ops); return info.count; } struct do_xarray_info { ulong maxcount; ulong count; void *data; }; static void do_xarray_count(ulong node, ulong slot, const char *path, ulong index, void *private) { struct do_xarray_info *info = private; info->count++; } static void do_xarray_search(ulong node, ulong slot, const char *path, ulong index, void *private) { struct do_xarray_info *info = private; struct list_pair *xp = info->data; if (xp->index == index) { xp->value = (void *)slot; info->count = 1; } } static void do_xarray_dump(ulong node, ulong slot, const char *path, ulong index, void *private) { struct do_xarray_info *info = private; fprintf(fp, "[%ld] %lx\n", index, slot); info->count++; } static void do_xarray_gather(ulong node, ulong slot, const char *path, ulong index, void *private) { struct do_xarray_info *info = private; struct list_pair *xp = info->data; if (info->maxcount) { xp[info->count].index = index; xp[info->count].value = (void *)slot; info->count++; info->maxcount--; } } static void do_xarray_dump_cb(ulong node, ulong slot, const char *path, ulong index, void *private) { struct do_xarray_info *info = private; struct list_pair *xp = info->data; int (*cb)(ulong) = xp->value; /* Caller defined operation */ if (!cb(slot)) { if (slot & XARRAY_TAG_MASK) { if (CRASHDEBUG(1)) error(INFO, "entry has XARRAY_TAG_MASK bits set: %lx\n", slot); return; } error(FATAL, "do_xarray: callback " "operation failed: entry: %ld item: %lx\n", info->count, slot); } info->count++; } /* * do_xarray argument usage: * * root: Address of a xarray structure * * flag: XARRAY_COUNT - Return the number of entries in the tree. * XARRAY_SEARCH - Search for an entry at xp->index; if found, * store the entry in xp->value and return a count of 1; otherwise * return a count of 0. * XARRY_DUMP - Dump all existing index/value pairs. * XARRAY_GATHER - Store all existing index/value pairs in the * passed-in array of list_pair structs starting at xp, * returning the count of entries stored; the caller can/should * limit the number of returned entries by putting the array size * (max count) in the xp->index field of the first structure * in the passed-in array. * XARRAY_DUMP_CB - Similar with XARRAY_DUMP, but for each * xarray entry, a user defined callback at xp->value will * be invoked. * * xp: Unused by XARRAY_COUNT and XARRAY_DUMP. * A pointer to a list_pair structure for XARRAY_SEARCH. * A pointer to an array of list_pair structures for * XARRAY_GATHER; the dimension (max count) of the array may * be stored in the index field of the first structure to avoid * any chance of an overrun. * For XARRAY_DUMP_CB, the rtp->value must be initialized as a * callback function. The callback prototype must be: int (*)(ulong); */ ulong do_xarray(ulong root, int flag, struct list_pair *xp) { struct do_xarray_info info = { .count = 0, .data = xp, }; struct xarray_ops ops = { .radix = 16, .private = &info, }; switch (flag) { case XARRAY_COUNT: ops.entry = do_xarray_count; break; case XARRAY_SEARCH: ops.entry = do_xarray_search; break; case XARRAY_DUMP: ops.entry = do_xarray_dump; break; case XARRAY_GATHER: if (!(info.maxcount = xp->index)) info.maxcount = (ulong)(-1); /* caller beware */ ops.entry = do_xarray_gather; break; case XARRAY_DUMP_CB: if (xp->value == NULL) { error(FATAL, "do_xarray: no callback function specified"); return -EINVAL; } ops.entry = do_xarray_dump_cb; break; default: error(FATAL, "do_xarray: invalid flag: %lx\n", flag); } do_xarray_traverse(root, 1, &ops); return info.count; } int is_readable(char *filename) { int fd; if ((fd = open(filename, O_RDONLY)) < 0) { error(INFO, "%s: %s\n", filename, strerror(errno)); return FALSE; } else close(fd); return TRUE; } static int match_file_string(char *filename, char *string, char *buffer) { int found; char command[BUFSIZE]; FILE *pipe; sprintf(command, "/usr/bin/strings %s", filename); if ((pipe = popen(command, "r")) == NULL) { error(INFO, "%s: %s\n", filename, strerror(errno)); return FALSE; } found = FALSE; while (fgets(buffer, BUFSIZE-1, pipe)) { if (strstr(buffer, string)) { found = TRUE; break; } } pclose(pipe); return found; } char * vfsmount_devname(ulong vfsmnt, char *buf, int maxlen) { ulong devp; BZERO(buf, maxlen); if (VALID_STRUCT(mount)) { if (!readmem(vfsmnt - OFFSET(mount_mnt) + OFFSET(mount_mnt_devname), KVADDR, &devp, sizeof(void *), "mount mnt_devname", QUIET|RETURN_ON_ERROR)) return buf; } else { if (!readmem(vfsmnt + OFFSET(vfsmount_mnt_devname), KVADDR, &devp, sizeof(void *), "vfsmount mnt_devname", QUIET|RETURN_ON_ERROR)) return buf; } if (read_string(devp, buf, BUFSIZE-1)) return buf; return buf; } static ulong get_root_vfsmount(char *file_buf) { char buf1[BUFSIZE]; char buf2[BUFSIZE]; ulong vfsmnt; ulong mnt_parent; vfsmnt = ULONG(file_buf + OFFSET(file_f_vfsmnt)); if (!strlen(vfsmount_devname(vfsmnt, buf1, BUFSIZE))) return vfsmnt; if (STREQ(buf1, "udev") || STREQ(buf1, "devtmpfs")) { if (VALID_STRUCT(mount)) { if (!readmem(vfsmnt - OFFSET(mount_mnt) + OFFSET(mount_mnt_parent), KVADDR, &mnt_parent, sizeof(void *), "mount mnt_parent", QUIET|RETURN_ON_ERROR)) return vfsmnt; } else { if (!readmem(vfsmnt + OFFSET(vfsmount_mnt_parent), KVADDR, &mnt_parent, sizeof(void *), "vfsmount mnt_parent", QUIET|RETURN_ON_ERROR)) return vfsmnt; } if (!strlen(vfsmount_devname(mnt_parent, buf2, BUFSIZE))) return vfsmnt; if (STREQ(buf1, "udev") && STREQ(buf2, "udev")) return mnt_parent; if (STREQ(buf1, "devtmpfs") && STREQ(buf2, "devtmpfs")) return mnt_parent; } return vfsmnt; } void check_live_arch_mismatch(void) { struct utsname utsname; if (machine_type("X86") && (uname(&utsname) == 0) && STRNEQ(utsname.machine, "x86_64")) error(FATAL, "compiled for the X86 architecture\n"); #if defined(__i386__) || defined(__x86_64__) if (machine_type("ARM")) error(FATAL, "compiled for the ARM architecture\n"); #endif #ifdef __x86_64__ if (machine_type("ARM64")) error(FATAL, "compiled for the ARM64 architecture\n"); #endif #ifdef __x86_64__ if (machine_type("PPC64")) error(FATAL, "compiled for the PPC64 architecture\n"); #endif #ifdef __powerpc64__ if (machine_type("PPC")) error(FATAL, "compiled for the PPC architecture\n"); #endif } crash-utility-crash-61fe107/gdb-16.2.patch000066400000000000000000002077171517256214500201330ustar00rootroot00000000000000 # When this file is updated in an existing source tree, it gets re-applied # during the next build using "patch -N --fuzz=0", which ignores patches # that have already been applied. However, if a gdb file has been modified # multiple times, the subsequent patching may fail to recognize that a # given patch has been previously applied, and will attempt to re-apply it. # To prevent any unintended consequences, this file also acts as a # shell script that can restore any gdb file to its original state prior # to all subsequent patch applications. tar xvzmf gdb-16.2.tar.gz \ gdb-16.2/gdb/symfile.c \ gdb-16.2/gdb/symtab.c exit 0 --- gdb-16.2/Makefile.in.orig +++ gdb-16.2/Makefile.in @@ -369,6 +369,9 @@ CC_FOR_BUILD = @CC_FOR_BUILD@ CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@ CPP_FOR_BUILD = @CPP_FOR_BUILD@ CPPFLAGS_FOR_BUILD = @CPPFLAGS_FOR_BUILD@ +ifeq (${CRASH_TARGET}, PPC64) +CFLAGS_FOR_BUILD += -m64 -fPIC +endif CXXFLAGS_FOR_BUILD = @CXXFLAGS_FOR_BUILD@ CXX_FOR_BUILD = @CXX_FOR_BUILD@ DLLTOOL_FOR_BUILD = @DLLTOOL_FOR_BUILD@ @@ -441,6 +444,9 @@ GNATBIND = @GNATBIND@ GNATMAKE = @GNATMAKE@ CFLAGS = @CFLAGS@ +ifeq (${CRASH_TARGET}, PPC64) +CFLAGS += -m64 -fPIC +endif LDFLAGS = @LDFLAGS@ LIBCFLAGS = $(CFLAGS) CXXFLAGS = @CXXFLAGS@ --- gdb-16.2/gdb/Makefile.in.orig +++ gdb-16.2/gdb/Makefile.in @@ -603,7 +603,7 @@ CONFIG_DEP_SUBDIR = $(addsuffix /$(DEPDIR),$(CONFIG_SRC_SUBDIR)) # It is also possible that you will need to add -I/usr/include/sys if # your system doesn't have fcntl.h in /usr/include (which is where it # should be according to Posix). -DEFS = @DEFS@ +DEFS = -DCRASH_MERGE -D${CRASH_TARGET} @DEFS@ GDB_INCLUDED_HEADER = -include $(srcdir)/defs.h GDB_CFLAGS = \ -I. \ @@ -1220,6 +1220,7 @@ COMMON_SFILES = \ symmisc.c \ symtab.c \ target.c \ + ../../crash_target.c \ target-connection.c \ target-dcache.c \ target-descriptions.c \ @@ -1906,7 +1907,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \ $(SUBDIR_TARGET_OBS) \ $(SUBDIR_GCC_COMPILE_OBS) -SUBDIRS = doc @subdirs@ data-directory +SUBDIRS = build_no_subdirs CLEANDIRS = $(SUBDIRS) # List of subdirectories in the build tree that must exist. @@ -1947,8 +1948,8 @@ generated_files = \ # Flags needed to compile Python code PYTHON_CFLAGS = @PYTHON_CFLAGS@ -all: gdb$(EXEEXT) $(CONFIG_ALL) gdb-gdb.py gdb-gdb.gdb gcore gstack - @$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=$(SUBDIRS)" subdir_do +all: gdb$(EXEEXT) gdb-gdb.py gdb-gdb.gdb gcore gstack + @$(MAKE) -s $(FLAGS_TO_PASS) DO=all "DODIRS=$(SUBDIRS)" subdir_do # Rule for compiling .c files in the top-level gdb directory. # The order-only dependencies ensure that we create the build subdirectories. @@ -2230,9 +2231,10 @@ libgdb.a: $(LIBGDB_OBS) # Removing the old gdb first works better if it is running, at least on SunOS. gdb$(EXEEXT): gdb.o $(LIBGDB_OBS) $(CDEPS) $(TDEPLIBS) $(SILENCE) rm -f gdb$(EXEEXT) + @$(MAKE) -C ../.. GDB_FLAGS=-DGDB_16_2 library $(ECHO_CXXLD) $(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \ - -o gdb$(EXEEXT) gdb.o $(LIBGDB_OBS) \ - $(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES) + -o $(shell /bin/cat mergeobj) $(LIBGDB_OBS) \ + $(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES) $(shell /bin/cat mergelibs) ifneq ($(CODESIGN_CERT),) $(ECHO_SIGN) $(CODESIGN) -s $(CODESIGN_CERT) gdb$(EXEEXT) endif @@ -2699,9 +2701,9 @@ ifeq ($(DEPMODE),depmode=gcc3) # into place if the compile succeeds. We need this because gcc does # not atomically write the dependency output file. override COMPILE.post = -c -o $@ -MT $@ -MMD -MP \ - -MF $(@D)/$(DEPDIR)/$(basename $(@F)).Tpo -override POSTCOMPILE = @mv $(@D)/$(DEPDIR)/$(basename $(@F)).Tpo \ - $(@D)/$(DEPDIR)/$(basename $(@F)).Po + -MF $(subst ../..,.,$(@D))/$(DEPDIR)/$(basename $(@F)).Tpo +override POSTCOMPILE = @mv $(subst ../..,.,$(@D))/$(DEPDIR)/$(basename $(@F)).Tpo \ + $(subst ../..,.,$(@D))/$(DEPDIR)/$(basename $(@F)).Po else override COMPILE.pre = source='$<' object='$@' libtool=no \ DEPDIR=$(DEPDIR) $(DEPMODE) $(depcomp) \ --- gdb-16.2/gdb/c-typeprint.c.orig +++ gdb-16.2/gdb/c-typeprint.c @@ -1066,6 +1066,9 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, = podata->end_bitpos - type->field (i).type ()->length () * TARGET_CHAR_BIT; } + else if (strlen(type->field(i).name()) == 0) + /* crash: Print details for unnamed struct and union. */ + newshow = show; c_print_type_1 (type->field (i).type (), type->field (i).name (), --- gdb-16.2/gdb/cli/cli-cmds.c.orig +++ gdb-16.2/gdb/cli/cli-cmds.c @@ -427,6 +427,11 @@ complete_command (const char *arg, int from_tty) } } +#ifdef CRASH_MERGE +static int crash_from_tty = 0; +extern "C" void untrusted_file(FILE *, char *); +#endif + int is_complete_command (struct cmd_list_element *c) { @@ -659,8 +664,32 @@ find_and_open_script (const char *script_file, int search_path) close (fd); errno = save_errno; } - else - opened.emplace (gdb_file_up (result), std::move (full_path)); +#ifdef CRASH_MERGE + /* + * Only allow trusted versions of .gdbinit files to be + * sourced during session initialization. + */ + if (crash_from_tty == -1) + { + struct stat statbuf; + FILE *stream = result; + int _fd = fileno (stream); + if (fstat (_fd, &statbuf) < 0) + { + perror_with_name (full_path.get()); + fclose (stream); + return opened; + } + if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH)) + { + untrusted_file(NULL, full_path.get()); + fclose (stream); + return opened; + } + } +#endif + opened.emplace (gdb_file_up (result), std::move (full_path)); + return opened; } @@ -724,7 +753,11 @@ source_script_with_search (const char *file, int from_tty, int search_path) If the source command was invoked interactively, throw an error. Otherwise (e.g. if it was invoked by a script), just emit a warning, rather than cause an error. */ +#ifdef CRASH_MERGE + if (from_tty > 0) +#else if (from_tty) +#endif perror_with_name (file); else { @@ -756,7 +789,14 @@ source_script_with_search (const char *file, int from_tty, int search_path) void source_script (const char *file, int from_tty) { +#ifdef CRASH_MERGE + crash_from_tty = from_tty; +#endif source_script_with_search (file, from_tty, 0); +#ifdef CRASH_MERGE + crash_from_tty = 0; +#endif + } static void --- gdb-16.2/gdb/completer.c.orig +++ gdb-16.2/gdb/completer.c @@ -3315,6 +3315,8 @@ gdb_display_match_list_1 (char **matches, int len, int max, /* How many items of MAX length can we fit in the screen window? */ cols = gdb_complete_get_screenwidth (displayer); + rl_reset_screen_size(); + rl_get_screen_size(NULL, &cols); max += 2; limit = cols / max; if (limit != 1 && (limit * max == cols)) --- gdb-16.2/gdb/defs.h.orig +++ gdb-16.2/gdb/defs.h @@ -407,4 +407,7 @@ DEF_ENUM_FLAGS_TYPE (enum user_selected_what_flag, user_selected_what); #include "utils.h" +#ifdef CRASH_MERGE +extern "C" int gdb_main_entry(int, char **); +#endif #endif /* GDB_DEFS_H */ --- gdb-16.2/gdb/dwarf2/read-gdb-index.c.orig +++ gdb-16.2/gdb/dwarf2/read-gdb-index.c @@ -369,7 +369,11 @@ read_gdb_index_from_buffer (const char *filename, indices. */ if (version < 4) { +#ifdef CRASH_MERGE + static int warning_printed = 1; +#else static int warning_printed = 0; +#endif if (!warning_printed) { warning (_("Skipping obsolete .gdb_index section in %s."), @@ -388,7 +392,11 @@ read_gdb_index_from_buffer (const char *filename, "set use-deprecated-index-sections on". */ if (version < 6 && !deprecated_ok) { +#ifdef CRASH_MERGE + static int warning_printed = 1; +#else static int warning_printed = 0; +#endif if (!warning_printed) { warning (_("\ --- gdb-16.2/gdb/event-top.c.orig +++ gdb-16.2/gdb/event-top.c @@ -1558,6 +1558,10 @@ gdb_setup_readline (int editing) { struct ui *ui = current_ui; + if (!batch_silent) + gdb_stdout = new stdio_file (ui->outstream); + gdb_stderr = new stderr_file (ui->errstream); + /* If the input stream is connected to a terminal, turn on editing. However, that is only allowed on the main UI, as we can only have one instance of readline. Also, INSTREAM might be nullptr when --- gdb-16.2/gdb/frame.c.orig +++ gdb-16.2/gdb/frame.c @@ -966,6 +966,10 @@ frame_find_by_id (struct frame_id id) return NULL; } +#if defined(CRASH_MERGE) && defined(ARM64) +extern "C" void crash_decode_ptrauth_pc(ulong* pc); +#endif + static CORE_ADDR frame_unwind_pc (const frame_info_ptr &this_frame) { @@ -996,6 +1000,9 @@ frame_unwind_pc (const frame_info_ptr &this_frame) try { pc = gdbarch_unwind_pc (prev_gdbarch, this_frame); +#if defined(CRASH_MERGE) && defined(ARM64) + crash_decode_ptrauth_pc(&pc); +#endif pc_p = true; } catch (const gdb_exception_error &ex) --- gdb-16.2/gdb/main.c.orig +++ gdb-16.2/gdb/main.c @@ -442,6 +442,14 @@ start_event_loop () return; } +#ifdef CRASH_MERGE +extern "C" void update_gdb_hooks(void); +extern "C" void main_loop(void); +extern "C" unsigned long crash_get_kaslr_offset(void); +extern "C" int console(const char *, ...); +void crash_target_init (void); +#endif + /* Call command_loop. */ /* Prevent inlining this function for the benefit of GDB's selftests @@ -1031,7 +1039,11 @@ captured_main_1 (struct captured_main_args *context) } } +#ifdef CRASH_MERGE + save_original_signals_state (1); +#else save_original_signals_state (quiet); +#endif /* Try to set up an alternate signal stack for SIGSEGV handlers. */ gdb::alternate_signal_stack signal_stack; @@ -1129,7 +1141,7 @@ captured_main_1 (struct captured_main_args *context) if (print_version) { print_gdb_version (gdb_stdout, false); - gdb_printf ("\n"); + gdb_printf ("\n\n"); exit (0); } @@ -1150,6 +1162,10 @@ captured_main_1 (struct captured_main_args *context) look at things by now. Initialize the default interpreter. */ set_top_level_interpreter (interpreter_p.c_str (), false); +#ifdef CRASH_MERGE + update_gdb_hooks(); +#endif + /* The interpreter should have installed the real uiout by now. */ gdb_assert (current_uiout != temp_uiout.get ()); temp_uiout = nullptr; @@ -1177,7 +1193,11 @@ captured_main_1 (struct captured_main_args *context) if (!system_gdbinit.empty () && !inhibit_gdbinit) { for (const std::string &file : system_gdbinit) +#ifdef CRASH_MERGE + ret = catch_command_errors (source_script, file.c_str (), -1); +#else ret = catch_command_errors (source_script, file.c_str (), 0); +#endif } /* Read and execute $HOME/.gdbinit file, if it exists. This is done @@ -1186,7 +1206,11 @@ captured_main_1 (struct captured_main_args *context) debugging or what directory you are in. */ if (!home_gdbinit.empty () && !inhibit_gdbinit && !inhibit_home_gdbinit) +#ifdef CRASH_MERGE + ret = catch_command_errors (source_script, home_gdbinit.c_str (), -1); +#else ret = catch_command_errors (source_script, home_gdbinit.c_str (), 0); +#endif /* Process '-ix' and '-iex' options early. */ execute_cmdargs (&cmdarg_vec, CMDARG_INIT_FILE, CMDARG_INIT_COMMAND, &ret); @@ -1217,7 +1241,11 @@ captured_main_1 (struct captured_main_args *context) !batch_flag); if (ret != 0) ret = catch_command_errors (symbol_file_add_main_adapter, +#ifdef CRASH_MERGE + symarg, 0); +#else symarg, !batch_flag); +#endif } else { @@ -1291,7 +1319,11 @@ captured_main_1 (struct captured_main_args *context) { auto_load_local_gdbinit_loaded = 1; +#ifdef CRASH_MERGE + ret = catch_command_errors (source_script, local_gdbinit.c_str (), -1); +#else ret = catch_command_errors (source_script, local_gdbinit.c_str (), 0); +#endif } } } @@ -1332,6 +1364,16 @@ captured_main (void *data) captured_main_1 (context); +#ifdef CRASH_MERGE + /* Relocate the vmlinux. */ + objfile_rebase (current_program_space->symfile_object_file, crash_get_kaslr_offset()); + + crash_target_init(); + + /* Back to crash. */ + main_loop(); +#endif + /* NOTE: cagney/1999-11-07: There is probably no reason for not moving this loop and the code found in captured_command_loop() into the command_loop() proper. The main thing holding back that @@ -1350,6 +1392,9 @@ captured_main (void *data) { exception_print (gdb_stderr, ex); } +#ifdef CRASH_MERGE + console("\n"); +#endif } /* No exit -- exit is through quit_command. */ } @@ -1371,6 +1416,24 @@ gdb_main (struct captured_main_args *args) return 1; } +#ifdef CRASH_MERGE +/* + * NOTE: adapted from gdb.c, which is no longer built in; changed name of + * original main() to gdb_main_entry() for use as crash entry point + */ +extern bool is_main_thread (); +int +gdb_main_entry (int argc, char **argv) +{ + struct captured_main_args args; + gdb_assert (is_main_thread ()); + memset (&args, 0, sizeof args); + args.argc = argc; + args.argv = argv; + args.interpreter_p = INTERP_CONSOLE; + return gdb_main (&args); +} +#endif /* Don't use *_filtered for printing help. We don't want to prompt for continue no matter how small the screen or how much we're going --- gdb-16.2/gdb/objfiles.h.orig +++ gdb-16.2/gdb/objfiles.h @@ -891,6 +891,8 @@ struct objfile : intrusive_list_node mechanism as ELF should set this flag too. This flag is used in conjunction with the minimal_symbol::maybe_copied method. */ bool object_format_has_copy_relocs = false; + + bool all_symtabs_expanded = false; }; /* A deleter for objfile. */ @@ -951,11 +953,11 @@ extern bool objfile_has_symbols (objfile *objfile); /* Return true if any objfile of PSPACE has partial symbols. */ -extern bool have_partial_symbols (program_space *pspace); +extern "C" bool have_partial_symbols (program_space *pspace); /* Return true if any objfile of PSPACE has full symbols. */ -extern bool have_full_symbols (program_space *pspace); +extern "C" bool have_full_symbols (program_space *pspace); extern void objfile_set_sym_fns (struct objfile *objfile, const struct sym_fns *sf); --- gdb-16.2/gdb/printcmd.c.orig +++ gdb-16.2/gdb/printcmd.c @@ -552,6 +552,9 @@ set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr) form. However note that DO_DEMANGLE can be overridden by the specific settings of the demangle and asm_demangle variables. Returns non-zero if anything was printed; zero otherwise. */ +#ifdef CRASH_MERGE +extern "C" int gdb_print_callback(unsigned long); +#endif int print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr, @@ -563,6 +566,12 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr, int offset = 0; int line = 0; +#ifdef CRASH_MERGE + if (!gdb_print_callback(addr)) { + return 0; + } +#endif + if (build_address_symbolic (gdbarch, addr, do_demangle, false, &name, &offset, &filename, &line, &unmapped)) return 0; @@ -595,6 +604,10 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr, /* See valprint.h. */ +#ifdef CRASH_MERGE +extern "C" char *gdb_lookup_module_symbol(unsigned long, unsigned long *); +#endif + int build_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr, /* IN */ @@ -701,7 +714,19 @@ build_address_symbolic (struct gdbarch *gdbarch, } } if (symbol == NULL && msymbol.minsym == NULL) +#ifdef CRASH_MERGE + { + char *name_ptr = gdb_lookup_module_symbol(addr, (unsigned long *)offset); + if (name_ptr) { + *name = name_ptr; + return 0; + } else { + return 1; + } + } +#else return 1; +#endif /* If the nearest symbol is too far away, don't print anything symbolic. */ @@ -1242,6 +1267,42 @@ print_command_parse_format (const char **expp, const char *cmdname, *expp = exp; } +static void +print_command_2 (const char *args, int voidprint) +{ + struct value *val; + value_print_options print_opts; + + get_user_print_options (&print_opts); + /* Override global settings with explicit options, if any. */ + auto group = make_value_print_options_def_group (&print_opts); + gdb::option::process_options + (&args, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER, group); + + print_command_parse_format (&args, "print", &print_opts); + + const char *exp = args; + + if (exp != nullptr && *exp) + { + expression_up expr = parse_expression (exp); + val = expr->evaluate (); + } else + val = access_value_history (0); + + gdb_printf("%d %d %ld %ld %ld %ld\n", + check_typedef(val->type ())->code(), + check_typedef(val->type ())->is_unsigned(), + check_typedef(val->type ())->length(), + val->offset(), val->bitpos(), val->bitsize()); +} + +static void +printm_command (const char *exp, int from_tty) +{ + print_command_2 (exp, 1); +} + /* See valprint.h. */ void @@ -3357,6 +3418,12 @@ but no count or size letter (see \"x\" command)."), = add_com ("print", class_vars, print_command, print_help.c_str ()); set_cmd_completer_handle_brkchars (print_cmd, print_command_completer); add_com_alias ("p", print_cmd, class_vars, 1); + + c = add_com ("printm", class_vars, printm_command, _("\ +Similar to \"print\" command, but it used to print the type, size, offset,\n\ +bitpos and bitsize of the expression EXP.")); + set_cmd_completer (c, expression_completer); + add_com_alias ("inspect", print_cmd, class_vars, 1); add_setshow_uinteger_cmd ("max-symbolic-offset", no_class, --- gdb-16.2/gdb/psymtab.c.orig +++ gdb-16.2/gdb/psymtab.c @@ -80,6 +80,9 @@ psymbol_functions::partial_symbols (struct objfile *objfile) return m_partial_symtabs->range (); } +#ifdef CRASH_MERGE + extern "C" int gdb_line_number_callback(unsigned long, unsigned long, unsigned long); +#endif /* Find which partial symtab contains PC and SECTION starting at psymtab PST. We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */ @@ -170,7 +173,12 @@ psymbol_functions::find_pc_sect_psymtab (struct objfile *objfile, best_pst = find_pc_sect_psymtab_closer (objfile, pc, section, pst, msymbol); +#ifdef CRASH_MERGE + if ((best_pst != NULL) && + gdb_line_number_callback(pc, pst->text_low (objfile), pst->text_high (objfile))) +#else if (best_pst != NULL) +#endif return best_pst; } --- gdb-16.2/gdb/stack.c.orig +++ gdb-16.2/gdb/stack.c @@ -1968,6 +1968,11 @@ static frame_command_helper select_frame_cmd; /* Print briefly all stack frames or just the innermost COUNT_EXP frames. */ +#ifdef CRASH_MERGE +extern "C" int is_kvaddr(ulong); +extern "C" int gdb_CRASHDEBUG(ulong); +#endif + static void backtrace_command_1 (const frame_print_options &fp_opts, const backtrace_cmd_options &bt_opts, @@ -2062,6 +2067,17 @@ backtrace_command_1 (const frame_print_options &fp_opts, hand, perhaps the code does or could be fixed to make sure the frame->prev field gets set to NULL in that case). */ +#ifdef CRASH_MERGE + CORE_ADDR pc = 0; + get_frame_pc_if_available (fi, &pc); + if (!is_kvaddr(pc)) { + if (gdb_CRASHDEBUG(1)) { + gdb_printf(_("Backtrace stopped: due to non-kernel addr: 0x%lx\n"),pc); + } + fi = NULL; + break; + } +#endif print_frame_info (fp_opts, fi, 1, LOCATION, 1, 0); if ((flags & PRINT_LOCALS) != 0) print_frame_local_vars (fi, false, NULL, NULL, 1, gdb_stdout); @@ -2081,7 +2097,7 @@ backtrace_command_1 (const frame_print_options &fp_opts, enum unwind_stop_reason reason; reason = get_frame_unwind_stop_reason (trailing); - if (reason >= UNWIND_FIRST_ERROR) + if (reason >= UNWIND_FIRST_ERROR && gdb_CRASHDEBUG(1)) gdb_printf (_("Backtrace stopped: %s\n"), frame_stop_reason_string (trailing)); } --- gdb-16.2/gdb/symfile.c.orig +++ gdb-16.2/gdb/symfile.c @@ -633,7 +633,26 @@ default_symfile_offsets (struct objfile *objfile, for (cur_sec = abfd->sections; cur_sec != NULL; cur_sec = cur_sec->next) /* We do not expect this to happen; just skip this step if the relocatable file has a section with an assigned VMA. */ - if (bfd_section_vma (cur_sec) != 0) + if (bfd_section_vma (cur_sec) != 0 + /* + * Kernel modules may have some non-zero VMAs, i.e., like the + * __ksymtab and __ksymtab_gpl sections in this example: + * + * Section Headers: + * [Nr] Name Type Address Offset + * Size EntSize Flags Link Info Align + * ... + * [ 8] __ksymtab PROGBITS 0000000000000060 0000ad90 + * 0000000000000010 0000000000000000 A 0 0 16 + * [ 9] .rela__ksymtab RELA 0000000000000000 0000ada0 + * 0000000000000030 0000000000000018 43 8 8 + * [10] __ksymtab_gpl PROGBITS 0000000000000070 0000add0 + * 00000000000001a0 0000000000000000 A 0 0 16 + * ... + * + * but they should be treated as if they are NULL. + */ + && strncmp (bfd_section_name (cur_sec), "__k", 3) != 0) break; if (cur_sec == NULL) @@ -1069,6 +1088,12 @@ symbol_file_add_with_addrs (const gdb_bfd_ref_ptr &abfd, const char *name, objfile *objfile = objfile::make (abfd, current_program_space, name, flags, parent); +#ifdef CRASH_MERGE + if (add_flags & SYMFILE_MAINLINE) { + extern struct objfile *gdb_kernel_objfile; + gdb_kernel_objfile = objfile; + } +#endif /* We either created a new mapped symbol table, mapped an existing symbol table file which has not had initial symbol reading @@ -1095,6 +1120,7 @@ symbol_file_add_with_addrs (const gdb_bfd_ref_ptr &abfd, const char *name, styled_string (file_name_style.style (), name)); objfile->expand_all_symtabs (); + objfile->all_symtabs_expanded = true; } /* Note that we only print a message if we have no symbols and have @@ -1352,6 +1378,10 @@ show_debug_file_directory (struct ui_file *file, int from_tty, #if ! defined (DEBUG_SUBDIRECTORY) #define DEBUG_SUBDIRECTORY ".debug" #endif +#ifdef CRASH_MERGE +extern "C" int check_specified_module_tree(const char *, const char *); +extern "C" char *check_specified_kernel_debug_file(); +#endif /* Find a separate debuginfo file for OBJFILE, using DIR as the directory where the original file resides (may not be the same as @@ -1390,6 +1420,15 @@ find_separate_debug_file (const char *dir, if (separate_debug_file_exists (debugfile, crc32, objfile, warnings)) return debugfile; +#ifdef CRASH_MERGE +{ + if (check_specified_module_tree(objfile_name (objfile), debugfile.c_str()) && + separate_debug_file_exists(debugfile, crc32, objfile, warnings)) { + return debugfile; + } +} +#endif + /* Then try in the global debugfile directories. Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will @@ -1545,6 +1584,14 @@ find_separate_debug_file_by_debuglink } } +#ifdef CRASH_MERGE + if (debugfile.empty ()) { + char *name_copy; + name_copy = check_specified_kernel_debug_file(); + return name_copy ? std::string (name_copy) : std::string (); + } +#endif + return debugfile; } @@ -2318,8 +2365,10 @@ add_symbol_file_command (const char *args, int from_tty) else if (section_addrs.empty ()) gdb_printf ("\n"); +#ifndef CRASH_MERGE if (from_tty && (!query ("%s", ""))) error (_("Not confirmed.")); +#endif objf = symbol_file_add (filename.get (), add_flags, §ion_addrs, flags); @@ -2660,6 +2709,7 @@ reread_symbols (int from_tty) objfile_name (objfile))); objfile->expand_all_symtabs (); + objfile->all_symtabs_expanded = true; } if (!objfile_has_symbols (objfile)) @@ -3638,6 +3688,15 @@ bfd_byte * symfile_relocate_debug_section (struct objfile *objfile, asection *sectp, bfd_byte *buf) { +#ifdef CRASH_MERGE + /* Executable files have all the relocations already resolved. + * Handle files linked with --emit-relocs. + * http://sources.redhat.com/ml/gdb/2006-08/msg00137.html + */ + bfd *abfd = objfile->obfd.get(); + if ((abfd->flags & EXEC_P) != 0) + return NULL; +#endif gdb_assert (objfile->sf->sym_relocate); return (*objfile->sf->sym_relocate) (objfile, sectp, buf); --- gdb-16.2/gdb/symtab.c.orig +++ gdb-16.2/gdb/symtab.c @@ -2012,6 +2012,10 @@ search_name_hash (enum language language, const char *search_name) variable and thus can probably assume it will never hit the C++ code). */ +#ifdef CRASH_MERGE +static void gdb_bait_and_switch(char *, struct symbol *); +#endif + struct block_symbol lookup_symbol_in_language (const char *name, const struct block *block, const domain_search_flags domain, @@ -2020,22 +2024,37 @@ lookup_symbol_in_language (const char *name, const struct block *block, { SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT; + struct block_symbol result; demangle_result_storage storage; const char *modified_name = demangle_for_lookup (name, lang, storage); - return lookup_symbol_aux (modified_name, + result = lookup_symbol_aux (modified_name, symbol_name_match_type::FULL, block, domain, lang, is_a_field_of_this); +#ifdef CRASH_MERGE + if (result.symbol && (domain & SEARCH_TYPE_DOMAIN)) + gdb_bait_and_switch((char *)modified_name, result.symbol); +#endif + return result; } /* See symtab.h. */ +#ifdef CRASH_MERGE +static const struct block *gdb_get_crash_block(void); +#endif + struct block_symbol lookup_symbol (const char *name, const struct block *block, domain_search_flags domain, struct field_of_this_result *is_a_field_of_this) { +#ifdef CRASH_MERGE + if (!block) + block = gdb_get_crash_block(); +#endif + return lookup_symbol_in_language (name, block, domain, current_language->la_language, is_a_field_of_this); @@ -3004,7 +3023,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) for (objfile *objf : current_program_space->objfiles ()) { struct compunit_symtab *result - = objf->find_pc_sect_compunit_symtab (msymbol, pc, section, 1); + = objf->find_pc_sect_compunit_symtab (msymbol, pc, section, 0); if (result != NULL) return result; } @@ -7320,3 +7339,914 @@ the use of prologue scanners."), "symtab"); gdb::observers::free_objfile.attach (symtab_free_objfile_observer, "symtab"); } + +#ifdef CRASH_MERGE +#include "gdb-stabs.h" +#include "gdbsupport/version.h" +#define GDB_COMMON +#include "../../defs.h" + +static void get_member_data(struct gnu_request *, struct type *, long, int); +static void walk_enum(struct type *, struct gnu_request *); +static void eval_enum(struct type *, struct gnu_request *); +static void gdb_get_line_number(struct gnu_request *); +static void gdb_get_datatype(struct gnu_request *); +static void gdb_get_symbol_type(struct gnu_request *); +static void gdb_command_exists(struct gnu_request *); +static void gdb_debug_command(struct gnu_request *); +static void gdb_function_numargs(struct gnu_request *); +static void gdb_add_symbol_file(struct gnu_request *); +static void gdb_delete_symbol_file(struct gnu_request *); +static void gdb_patch_symbol_values(struct gnu_request *); +static void get_user_print_option_address(struct gnu_request *); +extern int get_frame_offset(CORE_ADDR); +static void gdb_set_crash_block(struct gnu_request *); +extern "C" void gdb_command_funnel(struct gnu_request *); +void gdb_command_funnel_1(struct gnu_request *); +static long lookup_struct_contents(struct gnu_request *); +static void iterate_datatypes(struct gnu_request *); +extern void execute_command (const char *, int); + +struct objfile *gdb_kernel_objfile = { 0 }; + +static ulong gdb_merge_flags = 0; +#define KERNEL_SYMBOLS_PATCHED (0x1) + +#undef STREQ +#define STREQ(A, B) (A && B && (strcmp(A, B) == 0)) +#define TYPE_CODE(t) (t->code ()) +#define TYPE_TAG_NAME(t) (TYPE_MAIN_TYPE(t)->name) +#define TYPE_NFIELDS(t) (t->num_fields ()) +#define TYPE_NAME(t) (t->name ()) + +/* + * All commands from above come through here. + */ +void +gdb_command_funnel(struct gnu_request *req) +{ + try { + gdb_command_funnel_1(req); + } catch (const gdb_exception &ex) { + if (req->flags & GNU_RETURN_ON_ERROR) + req->flags |= GNU_COMMAND_FAILED; + else + throw ex; + } +} + +void +gdb_command_funnel_1(struct gnu_request *req) +{ + struct symbol *sym; + FILE *original_stdout_stream = nullptr; + FILE *original_stderr_stream = nullptr; + + if (req->command != GNU_VERSION && req->command != GNU_USER_PRINT_OPTION) { + original_stdout_stream = (dynamic_cast< stdio_file * >gdb_stdout)->get_stream(); + original_stderr_stream = (dynamic_cast< stdio_file * >gdb_stderr)->get_stream(); + (dynamic_castgdb_stdout)->set_stream(req->fp); + (dynamic_castgdb_stderr)->set_stream(req->fp); + } + + switch (req->command) + { + case GNU_VERSION: + req->buf = (char *)version; + break; + + case GNU_PASS_THROUGH: + execute_command(req->buf, + req->flags & GNU_FROM_TTY_OFF ? FALSE : TRUE); + break; + + case GNU_USER_PRINT_OPTION: + get_user_print_option_address(req); + break; + + case GNU_RESOLVE_TEXT_ADDR: + sym = find_pc_function(req->addr); + if (!sym || TYPE_CODE(sym->type()) != TYPE_CODE_FUNC) + req->flags |= GNU_COMMAND_FAILED; + break; + + case GNU_DISASSEMBLE: + if (req->addr2) + sprintf(req->buf, "disassemble 0x%lx 0x%lx", + req->addr, req->addr2); + else + sprintf(req->buf, "disassemble 0x%lx", req->addr); + execute_command(req->buf, TRUE); + break; + + case GNU_ADD_SYMBOL_FILE: + gdb_add_symbol_file(req); + break; + + case GNU_DELETE_SYMBOL_FILE: + gdb_delete_symbol_file(req); + break; + + case GNU_GET_LINE_NUMBER: + gdb_get_line_number(req); + break; + + case GNU_GET_DATATYPE: + gdb_get_datatype(req); + break; + + case GNU_GET_SYMBOL_TYPE: + gdb_get_symbol_type(req); + break; + + case GNU_COMMAND_EXISTS: + gdb_command_exists(req); + break; + + case GNU_ALPHA_FRAME_OFFSET: + req->value = 0; + break; + + case GNU_FUNCTION_NUMARGS: + gdb_function_numargs(req); + break; + + case GNU_DEBUG_COMMAND: + gdb_debug_command(req); + break; + + case GNU_PATCH_SYMBOL_VALUES: + gdb_patch_symbol_values(req); + break; + + case GNU_SET_CRASH_BLOCK: + gdb_set_crash_block(req); + break; + + case GNU_GET_FUNCTION_RANGE: + { + CORE_ADDR start, end; + if (!find_pc_partial_function(req->pc, NULL, &start, &end)) + req->flags |= GNU_COMMAND_FAILED; + else { + req->addr = (ulong)start; + req->addr2 = (ulong)end; + } + } + break; + + case GNU_LOOKUP_STRUCT_CONTENTS: + req->value = lookup_struct_contents(req); + break; + + case GNU_ITERATE_DATATYPES: + iterate_datatypes(req); + break; + + default: + req->flags |= GNU_COMMAND_FAILED; + break; + } + + /* Restore the streams gdb output was using */ + if (original_stdout_stream) + (dynamic_castgdb_stdout)->set_stream(original_stdout_stream); + if (original_stderr_stream) + (dynamic_castgdb_stderr)->set_stream(original_stderr_stream); +} + +/* + * Given a PC value, return the file and line number. + */ +static void +gdb_get_line_number(struct gnu_request *req) +{ + struct symtab_and_line sal; + struct objfile *objfile; + CORE_ADDR pc; + +#define LASTCHAR(s) (s[strlen(s)-1]) + + /* + * Prime the addrmap pump. + */ + pc = req->addr; + + sal = find_pc_line(pc, 0); + + if (!sal.symtab) { + /* + * If a module address line number can't be found, it's typically + * due to its addrmap still containing offset values because its + * objfile doesn't have full symbols loaded. + */ + if (req->lm) { + objfile = req->lm->loaded_objfile; + if (!objfile->all_symtabs_expanded && objfile->sf) { + objfile->expand_all_symtabs(); + objfile->all_symtabs_expanded = true; + sal = find_pc_line(pc, 0); + } + } + if (!sal.symtab) { + req->buf[0] = '\0'; + return; + } + } + + if (sal.symtab->filename && (sal.symtab)->compunit ()->dirname ()) { + if (sal.symtab->filename[0] == '/') + sprintf(req->buf, "%s: %d", + sal.symtab->filename, sal.line); + else + sprintf(req->buf, "%s%s%s: %d", + (sal.symtab)->compunit ()->dirname (), + LASTCHAR((sal.symtab)->compunit ()->dirname ()) == '/' ? "" : "/", + sal.symtab->filename, sal.line); + } +} + + +/* + * Follow the type linkage for full member and value type resolution, with callback + */ +static void drillDownType(struct gnu_request *req, struct type *type) +{ + while (type) + { + /* check out for stub types and pull in the definition instead */ + if (type->is_stub() && TYPE_TAG_NAME(type)) { + struct symbol *sym; + sym = lookup_symbol(TYPE_TAG_NAME(type), 0, SEARCH_STRUCT_DOMAIN, 0).symbol; + if (sym) + type = sym->type(); + } + switch (TYPE_CODE(type)) { + drill_ops_t op; + long l1, l2; + int typecode; + + case TYPE_CODE_PTR: + req->tcb(EOP_POINTER, req, 0, 0, 0, 0); + break; + + case TYPE_CODE_TYPEDEF: + req->is_typedef = 1; + req->typecode = TYPE_CODE(type); + if (!req->tcb(EOP_TYPEDEF, req, TYPE_NAME(type), 0, 0, 0)) + return; + break; + + case TYPE_CODE_FUNC: + req->tcb(EOP_FUNCTION, req, 0, 0, 0, 0); + break; + + case TYPE_CODE_ARRAY: + l1 = type->length(); + l2 = check_typedef(type->target_type())->length(); + req->tcb(EOP_ARRAY, req, &l1, &l2, 0, 0); + break; + + case TYPE_CODE_VOID: + case TYPE_CODE_INT: + case TYPE_CODE_BOOL: + l1 = type->length(); + req->tcb(EOP_INT, req, &l1, 0, 0, 0); + break; + + case TYPE_CODE_UNION: + op = EOP_UNION; + goto label; + + case TYPE_CODE_ENUM: + op = EOP_ENUM; + goto label; + + case TYPE_CODE_STRUCT: + op = EOP_STRUCT; + goto label; + + default: + typecode = TYPE_CODE(type); + req->tcb(EOP_OOPS, req, &typecode, "Unknown typecode", 0, 0); + return; /* not reached */ + + label: + l1 = type->length(); + req->tcb(op, req, &l1, type, TYPE_TAG_NAME(type), 0); + } + type = type->target_type(); + } + req->tcb(EOP_DONE, req, 0, 0, 0, 0); +} + +/* + * General purpose routine for determining datatypes. + */ + +static void +gdb_get_datatype(struct gnu_request *req) +{ + struct type *type; + struct type *typedef_type; + expression_up expr; + struct symbol *sym; + struct value *val; + + if (gdb_CRASHDEBUG(2)) + console("gdb_get_datatype [%s] (a)\n", req->name); + + req->typecode = TYPE_CODE_UNDEF; + + /* + * lookup_symbol() will pick up struct and union names. + */ + sym = lookup_symbol(req->name, 0, SEARCH_STRUCT_DOMAIN, 0).symbol; + if (sym) { + req->typecode = TYPE_CODE(sym->type()); + req->length = sym->type()->length(); + if (req->member) + get_member_data(req, sym->type(), 0, 1); + + if (TYPE_CODE(sym->type()) == TYPE_CODE_ENUM) + walk_enum(sym->type(), req); + + return; + } + + /* + * Otherwise parse the expression. + */ + if (gdb_CRASHDEBUG(2)) + console("gdb_get_datatype [%s] (b)\n", req->name); + + expr = parse_expression(req->name); + + + switch (expr->first_opcode()) + { + case OP_VAR_VALUE: + if (gdb_CRASHDEBUG(2)) + console("expr->first_opcode(): OP_VAR_VALUE\n"); + type = expr->evaluate_type()->type(); + if (req->tcb) { + long value = value_as_long(expr->evaluate()); + /* callback with symbol value */ + req->typecode = TYPE_CODE(type); + req->tcb(EOP_VALUE, req, &value, 0, 0, 0); + drillDownType(req, type); + } else { + if (req->flags & GNU_VAR_LENGTH_TYPECODE) { + req->typecode = TYPE_CODE(type); + req->length = type->length(); + } + if (TYPE_CODE(type) == TYPE_CODE_ENUM) { + req->typecode = TYPE_CODE(type); + req->value = value_as_long(expr->evaluate()); + req->tagname = (char *)TYPE_TAG_NAME(type); + if (!req->tagname) { + val = expr->evaluate_type(); + eval_enum(val->type(), req); + } + } + } + break; + + case OP_TYPE: + if (gdb_CRASHDEBUG(2)) + console("expr->first_opcode(): OP_TYPE\n"); + type = expr->evaluate_type()->type(); + + if (req->tcb) { + drillDownType(req, type); + } else { + req->typecode = TYPE_CODE(type); + req->length = type->length(); + if (TYPE_CODE(type) == TYPE_CODE_TYPEDEF) { + req->is_typedef = TYPE_CODE_TYPEDEF; + if ((typedef_type = check_typedef(type))) { + req->typecode = TYPE_CODE(typedef_type); + req->length = typedef_type->length(); + type = typedef_type; + } + } + if (TYPE_CODE(type) == TYPE_CODE_ENUM) + walk_enum(type, req); + } + + if (req->member) + get_member_data(req, type, 0, 1); + + break; + + default: + if (gdb_CRASHDEBUG(2)) + console("expr->first_opcode(): %d (?)\n", + expr->first_opcode()); + break; + + } +} + +/* + * More robust enum list dump that gdb's, showing the value of each + * identifier, each on its own line. + */ +static void +walk_enum(struct type *type, struct gnu_request *req) +{ + int i; + int len, print = (req->flags & GNU_PRINT_ENUMERATORS); + long long lastval; + + if (print) { + if (req->is_typedef) + gdb_printf(gdb_stdout, "typedef "); + if (TYPE_TAG_NAME(type)) + gdb_printf(gdb_stdout, "enum %s {\n", TYPE_TAG_NAME (type)); + else + gdb_printf(gdb_stdout, "enum {\n"); + } + + len = TYPE_NFIELDS (type); + for (i = 0; i < len; i++) { + if (print) + gdb_printf(gdb_stdout, " %s", type->field(i).name()); + lastval = type->field(i).loc_enumval(); + if (print) { + gdb_printf(gdb_stdout, " = %s", plongest(lastval)); + gdb_printf(gdb_stdout, "\n"); + } else if (req->tcb) + req->tcb(EOP_ENUMVAL, req, type->field(i).name(), &lastval, 0, 0); + } + if (print) { + if (TYPE_TAG_NAME(type)) + gdb_printf(gdb_stdout, "};\n"); + else + gdb_printf(gdb_stdout, "} %s;\n", req->name); + } +} + +/* + * Given an enum type with no tagname, determine its value. + */ +static void +eval_enum(struct type *type, struct gnu_request *req) +{ + int i; + int len; + long long lastval; + + len = TYPE_NFIELDS (type); + lastval = 0; + + for (i = 0; i < len; i++) { + if (lastval != type->field(i).loc_enumval()) + lastval = type->field(i).loc_enumval(); + + if (STREQ(type->field(i).name(), req->name)) { + req->tagname = "(unknown)"; + req->value = lastval; + return; + } + lastval++; + } +} + +/* + * Walk through a struct type's list of fields looking for the desired + * member field, and when found, return its relevant data. + */ +static void +get_member_data(struct gnu_request *req, struct type *type, long offset, int is_first) +{ + short i; + struct field *nextfield; + short nfields; + struct type *typedef_type, *target_type; + + req->member_offset = -1; + + nfields = TYPE_MAIN_TYPE(type)->m_nfields; + nextfield = TYPE_MAIN_TYPE(type)->flds_bnds.fields; + + if (nfields == 0 && is_first /* The first call */) { + struct type *newtype; + newtype = lookup_transparent_type(req->name); + if (newtype) { + console("get_member_data(%s.%s): switching type from %lx to %lx\n", + req->name, req->member, type, newtype); + nfields = TYPE_MAIN_TYPE(newtype)->m_nfields; + nextfield = TYPE_MAIN_TYPE(newtype)->flds_bnds.fields; + } + } + + for (i = 0; i < nfields; i++) { + if (*nextfield->m_name == 0) { /* Anonymous struct/union */ + get_member_data(req, nextfield->type(), + offset + nextfield->m_loc.bitpos, 0); + if (req->member_offset != -1) + return; + } else { + /* callback may be just looking for a specific member name */ + if (req->tcb) { + if (req->tcb(EOP_MEMBER_NAME, req, nextfield->m_name, 0, 0, 0)) { + long bitpos = nextfield->loc_bitpos(); + long bitsize = nextfield->bitsize(); + long len = nextfield->type()->length(); + long byteOffset; + offset += nextfield->m_loc.bitpos; + byteOffset = offset/8; + console("EOP_MEMBER_SIZES\n"); + req->tcb(EOP_MEMBER_SIZES, req, &byteOffset, &len, &bitpos, &bitsize); + /* callback with full type info */ + drillDownType(req, nextfield->type()); + } + } else if (STREQ(req->member, nextfield->m_name)) { + req->member_offset = offset + nextfield->m_loc.bitpos; + req->member_length = nextfield->type()->length(); + req->member_typecode = TYPE_CODE(nextfield->type()); + req->member_main_type_name = (char *)TYPE_NAME(nextfield->type()); + req->member_main_type_tag_name = (char *)TYPE_TAG_NAME(nextfield->type()); + target_type = nextfield->type()->target_type(); + if (target_type) { + req->member_target_type_name = (char *)TYPE_NAME(target_type); + req->member_target_type_tag_name = (char *)TYPE_TAG_NAME(target_type); + } + if ((req->member_typecode == TYPE_CODE_TYPEDEF) && + (typedef_type = check_typedef(nextfield->type()))) { + req->member_length = typedef_type->length(); + } + return; + } + } + nextfield++; + } +} + +/* + * Check whether a command exists. If it doesn't, the command will be + * returned indirectly via the error_hook. + */ +static void +gdb_command_exists(struct gnu_request *req) +{ + extern struct cmd_list_element *cmdlist; + + req->value = FALSE; + lookup_cmd((const char **)&req->name, cmdlist, "", NULL, 0, 1); + req->value = TRUE; +} + +static void +gdb_function_numargs(struct gnu_request *req) +{ + struct symbol *sym; + + sym = find_pc_function(req->pc); + + if (!sym || TYPE_CODE(sym->type()) != TYPE_CODE_FUNC) { + req->flags |= GNU_COMMAND_FAILED; + return; + } + + req->value = (ulong)TYPE_NFIELDS(sym->type()); +} + +struct load_module *gdb_current_load_module = NULL; + +static void +gdb_add_symbol_file(struct gnu_request *req) +{ + struct load_module *lm; + int i; + int allsect = 0; + char *secname; + char buf[96]; + + gdb_current_load_module = lm = (struct load_module *)req->addr; + + req->name = lm->mod_namelist; + gdb_delete_symbol_file(req); + lm->loaded_objfile = NULL; + + if ((lm->mod_flags & MOD_NOPATCH) == 0) { + for (i = 0 ; i < lm->mod_sections; i++) { + if (STREQ(lm->mod_section_data[i].name, ".text") && + (lm->mod_section_data[i].flags & SEC_FOUND)) + allsect = 1; + } + + if (!allsect) { + sprintf(req->buf, "add-symbol-file %s 0x%lx %s", lm->mod_namelist, + lm->mod_text_start ? lm->mod_text_start : lm->mod_base, + lm->mod_flags & MOD_DO_READNOW ? "-readnow" : ""); + if (lm->mod_data_start) { + sprintf(buf, " -s .data 0x%lx", lm->mod_data_start); + strcat(req->buf, buf); + } + if (lm->mod_bss_start) { + sprintf(buf, " -s .bss 0x%lx", lm->mod_bss_start); + strcat(req->buf, buf); + } + if (lm->mod_rodata_start) { + sprintf(buf, " -s .rodata 0x%lx", lm->mod_rodata_start); + strcat(req->buf, buf); + } + } else { + sprintf(req->buf, "add-symbol-file %s 0x%lx %s", lm->mod_namelist, + lm->mod_text_start, lm->mod_flags & MOD_DO_READNOW ? + "-readnow" : ""); + for (i = 0; i < lm->mod_sections; i++) { + secname = lm->mod_section_data[i].name; + if ((lm->mod_section_data[i].flags & SEC_FOUND) && + !STREQ(secname, ".text")) { + if (lm->mod_section_data[i].addr) + sprintf(buf, " -s %s 0x%lx", secname, lm->mod_section_data[i].addr); + else + sprintf(buf, " -s %s 0x%lx", secname, + lm->mod_section_data[i].offset + lm->mod_base); + strcat(req->buf, buf); + } + } + } + } + + if (gdb_CRASHDEBUG(1)) + gdb_printf(gdb_stdout, "%s\n", req->buf); + + execute_command(req->buf, FALSE); + + for (objfile *objfile : current_program_space->objfiles ()) { + if (same_file((char *)objfile_name(objfile), lm->mod_namelist)) { + if (objfile->separate_debug_objfile) + lm->loaded_objfile = objfile->separate_debug_objfile; + else + lm->loaded_objfile = objfile; + break; + } + } + + if (!lm->loaded_objfile) + req->flags |= GNU_COMMAND_FAILED; +} + +static void +gdb_delete_symbol_file(struct gnu_request *req) +{ + for (objfile *objfile : current_program_space->objfiles ()) { + if (STREQ(objfile_name(objfile), req->name) || + same_file((char *)objfile_name(objfile), req->name)) { + objfile->unlink (); + break; + } + } + + if (gdb_CRASHDEBUG(2)) { + gdb_printf(gdb_stdout, "current object files:\n"); + for (objfile *objfile : current_program_space->objfiles ()) + gdb_printf(gdb_stdout, " %s\n", objfile_name(objfile)); + } +} + +/* + * Walk through all minimal_symbols, patching their values with the + * correct addresses. + */ +static void +gdb_patch_symbol_values(struct gnu_request *req) +{ + req->name = PATCH_KERNEL_SYMBOLS_START; + patch_kernel_symbol(req); + + for (objfile *objfile : current_program_space->objfiles ()) + for (minimal_symbol *msymbol : objfile->msymbols ()) + { + req->name = (char *)msymbol->m_name; + req->addr = (ulong)(&msymbol->m_value.ivalue); + if (!patch_kernel_symbol(req)) { + req->flags |= GNU_COMMAND_FAILED; + break; + } + } + + req->name = PATCH_KERNEL_SYMBOLS_STOP; + patch_kernel_symbol(req); + + clear_symtab_users(0); + gdb_merge_flags |= KERNEL_SYMBOLS_PATCHED; +} + +static void +gdb_get_symbol_type(struct gnu_request *req) +{ + expression_up expr; + struct value *val; + struct type *type; + struct type *target_type; + + req->typecode = TYPE_CODE_UNDEF; + + expr = parse_expression (req->name); + val = expr->evaluate_type(); + + type = val->type(); + + req->type_name = (char *)TYPE_MAIN_TYPE(type)->name; + req->typecode = TYPE_MAIN_TYPE(type)->code; + req->length = type->m_length; + req->type_tag_name = (char *)TYPE_TAG_NAME(type); + target_type = TYPE_MAIN_TYPE(type)->m_target_type; + + if (target_type) { + req->target_typename = (char *)TYPE_MAIN_TYPE(target_type)->name; + req->target_typecode = TYPE_MAIN_TYPE(target_type)->code; + req->target_length = target_type->m_length; + } + + if (req->member) + get_member_data(req, type, 0, 1); +} + +static void +gdb_debug_command(struct gnu_request *req) +{ + +} + +/* + * Only necessary on "patched" kernel symbol sessions, and called only by + * lookup_symbol(), pull a symbol value bait-and-switch operation by altering + * either a data symbol's address value or a text symbol's block start address. + */ +static void +gdb_bait_and_switch(char *name, struct symbol *sym) +{ + struct bound_minimal_symbol msym; + struct block *block; + + if ((gdb_merge_flags & KERNEL_SYMBOLS_PATCHED) && + (msym = lookup_minimal_symbol(current_program_space, name, gdb_kernel_objfile, NULL)).minsym) { + if (sym->aclass() == LOC_BLOCK) { + block = (struct block *)(sym->value_block()); + block->set_start(msym.value_address()); + } else + sym->set_value_address(msym.value_address()); + } +} + +#include "valprint.h" + +void +get_user_print_option_address(struct gnu_request *req) +{ + extern struct value_print_options user_print_options; + + req->addr = 0; + + if (strcmp(req->name, "output_format") == 0) + req->addr = (ulong)&user_print_options.output_format; + if (strcmp(req->name, "print_max") == 0) + req->addr = (ulong)&user_print_options.print_max; + if (strcmp(req->name, "prettyprint_structs") == 0) + req->addr = (ulong)&user_print_options.prettyformat_structs; + if (strcmp(req->name, "prettyprint_arrays") == 0) + req->addr = (ulong)&user_print_options.prettyformat_arrays; + if (strcmp(req->name, "repeat_count_threshold") == 0) + req->addr = (ulong)&user_print_options.repeat_count_threshold; + if (strcmp(req->name, "stop_print_at_null") == 0) + req->addr = (ulong)&user_print_options.stop_print_at_null; + if (strcmp(req->name, "output_radix") == 0) + req->addr = (ulong)&output_radix; +} + +CORE_ADDR crash_text_scope; + +static void +gdb_set_crash_block(struct gnu_request *req) +{ + if (!req->addr) { /* debug */ + crash_text_scope = 0; + return; + } + + if ((req->addr2 = (ulong)block_for_pc(req->addr))) + crash_text_scope = req->addr; + else { + crash_text_scope = 0; + req->flags |= GNU_COMMAND_FAILED; + } +} + +static const struct block * +gdb_get_crash_block(void) +{ + if (crash_text_scope) + return block_for_pc(crash_text_scope); + else + return NULL; +} + +static long +lookup_struct_contents(struct gnu_request *req) +{ + int i; + long r; + struct field *f; + struct main_type *m; + const char *n; + struct main_type *top_m = (struct main_type *)req->addr; + char *type_name = req->type_name; + + if (!top_m || !type_name) + return 0; + + for (i = 0; i < top_m->m_nfields; i++) + { + f = top_m->flds_bnds.fields + i; + if (!f->type()) + continue; + m = f->type()->main_type; + + // If the field is an array, check the target type - + // it might be structure, or might not be. + // - struct request_sock *syn_table[0]; + // here m->target_type->main_type->code is expected + // to be TYPE_CODE_PTR + // - struct list_head vec[TVN_SIZE]; + // here m->target_type->main_type->code should be + // TYPE_CODE_STRUCT + if (m->code == TYPE_CODE_ARRAY && m->m_target_type) + m = m->m_target_type->main_type; + + /* Here is a recursion. + * If we have struct variable (not pointer), + * scan this inner structure + */ + if (m->code == TYPE_CODE_STRUCT) { + req->addr = (ulong)m; + r = lookup_struct_contents(req); + req->addr = (ulong)top_m; + if (r) + return 1; + } + + if (m->code == TYPE_CODE_PTR && m->m_target_type) + m = m->m_target_type->main_type; + if (m->name) + n = m->name; + else + continue; + + if (strstr(n, type_name)) + return 1; + } + + return 0; +} + +static void +iterate_datatypes (struct gnu_request *req) +{ + for (objfile *objfile : current_program_space->objfiles ()) + { + if (objfile->sf) { + objfile->expand_all_symtabs(); + objfile->all_symtabs_expanded = true; + } + + for (compunit_symtab *cust : objfile->compunits ()) + { + const struct blockvector *bv = cust->blockvector(); + + for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i) + { + const struct block *b = bv->block(i); + + for (struct symbol *sym : block_iterator_range (b)) + { + QUIT; + + if (sym->aclass() != LOC_TYPEDEF) + continue; + + if (req->highest && + !(req->lowest <= sym->type()->m_length && sym->type()->m_length <= req->highest)) + continue; + + req->addr = (ulong)(sym->type()->main_type); + req->name = (char *)(sym->m_name); + req->length = sym->type()->m_length; + + if (req->member) { + req->value = lookup_struct_contents(req); + if (!req->value) + continue; + } + req->callback(req, req->callback_data); + } + } + } + } +} +#endif --- gdb-16.2/gdb/ui-file.c.orig +++ gdb-16.2/gdb/ui-file.c @@ -251,6 +251,12 @@ stdio_file::~stdio_file () fclose (m_file); } +FILE* +stdio_file::get_stream(void) +{ + return m_file; +} + void stdio_file::set_stream (FILE *file) { --- gdb-16.2/gdb/ui-file.h.orig +++ gdb-16.2/gdb/ui-file.h @@ -273,10 +273,11 @@ class stdio_file : public ui_file int fd () const override { return m_fd; } -private: + FILE *get_stream(void); /* Sets the internal stream to FILE, and saves the FILE's file descriptor in M_FD. */ void set_stream (FILE *file); +private: /* The file. */ FILE *m_file; --- gdb-16.2/gdb/xml-syscall.c.orig +++ gdb-16.2/gdb/xml-syscall.c @@ -36,7 +36,11 @@ static void syscall_warn_user (void) { +#ifdef CRASH_MERGE + static int have_warned = 1; +#else static int have_warned = 0; +#endif if (!have_warned) { have_warned = 1; --- gdb-16.2/libiberty/Makefile.in.orig +++ gdb-16.2/libiberty/Makefile.in @@ -181,6 +181,7 @@ REQUIRED_OFILES = \ ./getruntime.$(objext) ./hashtab.$(objext) ./hex.$(objext) \ ./lbasename.$(objext) ./lrealpath.$(objext) \ ./make-relative-prefix.$(objext) ./make-temp-file.$(objext) \ + ./mkstemps.$(objext) \ ./objalloc.$(objext) \ ./obstack.$(objext) \ ./partition.$(objext) ./pexecute.$(objext) ./physmem.$(objext) \ @@ -214,7 +215,7 @@ CONFIGURED_OFILES = ./asprintf.$(objext) ./atexit.$(objext) \ ./index.$(objext) ./insque.$(objext) \ ./memchr.$(objext) ./memcmp.$(objext) ./memcpy.$(objext) \ ./memmem.$(objext) ./memmove.$(objext) \ - ./mempcpy.$(objext) ./memset.$(objext) ./mkstemps.$(objext) \ + ./mempcpy.$(objext) ./memset.$(objext) \ ./pex-djgpp.$(objext) ./pex-msdos.$(objext) \ ./pex-unix.$(objext) ./pex-win32.$(objext) \ ./putenv.$(objext) \ --- gdb-16.2/opcodes/i386-dis.c.orig +++ gdb-16.2/opcodes/i386-dis.c @@ -9589,6 +9589,10 @@ print_insn (bfd_vma pc, disassemble_info *info, int intel_syntax) dp = &dis386_twobyte[*ins.codep]; ins.need_modrm = twobyte_has_modrm[*ins.codep]; + if (dp->name && ((strcmp(dp->name, "ud2a") == 0) || (strcmp(dp->name, "ud2") == 0))) { + extern int kernel_BUG_encoding_bytes(void); + ins.codep += kernel_BUG_encoding_bytes(); + } } else { --- gdb-16.2/readline/readline/misc.c.orig +++ gdb-16.2/readline/readline/misc.c @@ -411,7 +411,7 @@ _rl_history_set_point (void) #if defined (VI_MODE) if (rl_editing_mode == vi_mode && _rl_keymap != vi_insertion_keymap) - rl_point = 0; + rl_point = rl_end; #endif /* VI_MODE */ if (rl_editing_mode == emacs_mode) --- gdb-16.2/readline/readline/readline.h.orig +++ gdb-16.2/readline/readline/readline.h @@ -407,7 +407,7 @@ extern int rl_mark_active_p (void); #if defined (USE_VARARGS) && defined (PREFER_STDARG) extern int rl_message (const char *, ...) __attribute__((__format__ (printf, 1, 2))); #else -extern int rl_message (); +extern int rl_message (void); #endif extern int rl_show_char (int); --- gdb-16.2/readline/readline/rltypedefs.h.orig +++ gdb-16.2/readline/readline/rltypedefs.h @@ -32,10 +32,10 @@ extern "C" { # define _FUNCTION_DEF #if defined(__GNUC__) || defined(__clang__) -typedef int Function () __attribute__((deprecated)); -typedef void VFunction () __attribute__((deprecated)); -typedef char *CPFunction () __attribute__((deprecated)); -typedef char **CPPFunction () __attribute__((deprecated)); +typedef int Function (void) __attribute__ ((deprecated)); +typedef void VFunction (void) __attribute__ ((deprecated)); +typedef char *CPFunction (void) __attribute__ ((deprecated)); +typedef char **CPPFunction (void) __attribute__ ((deprecated)); #else typedef int Function (); typedef void VFunction (); --- gdb-16.2/readline/readline/util.c.orig +++ gdb-16.2/readline/readline/util.c @@ -489,10 +489,13 @@ _rl_trace (va_alist) if (_rl_tracefp == 0) _rl_tropen (); + if (!_rl_tracefp) + goto out; vfprintf (_rl_tracefp, format, args); fprintf (_rl_tracefp, "\n"); fflush (_rl_tracefp); +out: va_end (args); } @@ -512,16 +515,17 @@ _rl_tropen (void) #endif snprintf (fnbuf, sizeof (fnbuf), "%s/rltrace.%ld", x, (long)getpid()); unlink(fnbuf); - _rl_tracefp = fopen (fnbuf, "w+"); + _rl_tracefp = fopen (fnbuf, "w+xe"); return _rl_tracefp != 0; } int _rl_trclose (void) { - int r; + int r = 0; - r = fclose (_rl_tracefp); + if (_rl_tracefp) + r = fclose (_rl_tracefp); _rl_tracefp = 0; return r; } --- gdb-16.2/configure.orig +++ gdb-16.2/configure @@ -3620,6 +3620,9 @@ case "${target}" in ;; esac +#disable gdbserver build in crash-utility +enable_gdbserver=no + # Only allow gdbserver on some systems. if test -d ${srcdir}/gdbserver; then if test x$enable_gdbserver = x; then --- gdb-16.2/gdb/symfile.c.orig +++ gdb-16.2/gdb/symfile.c @@ -341,8 +341,15 @@ place_section (bfd *abfd, asection *sect, section_offsets &offsets, return; /* If the user specified an offset, honor it. */ - if (offsets[gdb_bfd_section_index (abfd, sect)] != 0) + if (offsets[gdb_bfd_section_index (abfd, sect)] != 0) { + /* + * addr_info_make_relative() subtracts out the section VMA. But if the user + * specified an offset, they have already taken this into account. Add it + * back in + */ + offsets[gdb_bfd_section_index (abfd, sect)] += bfd_section_vma(sect); return; + } /* Otherwise, let's try to find a place for the section. */ start_addr = (lowest + align - 1) & -align; @@ -630,33 +637,6 @@ default_symfile_offsets (struct objfile *objfile, bfd *abfd = objfile->obfd.get (); asection *cur_sec; - for (cur_sec = abfd->sections; cur_sec != NULL; cur_sec = cur_sec->next) - /* We do not expect this to happen; just skip this step if the - relocatable file has a section with an assigned VMA. */ - if (bfd_section_vma (cur_sec) != 0 - /* - * Kernel modules may have some non-zero VMAs, i.e., like the - * __ksymtab and __ksymtab_gpl sections in this example: - * - * Section Headers: - * [Nr] Name Type Address Offset - * Size EntSize Flags Link Info Align - * ... - * [ 8] __ksymtab PROGBITS 0000000000000060 0000ad90 - * 0000000000000010 0000000000000000 A 0 0 16 - * [ 9] .rela__ksymtab RELA 0000000000000000 0000ada0 - * 0000000000000030 0000000000000018 43 8 8 - * [10] __ksymtab_gpl PROGBITS 0000000000000070 0000add0 - * 00000000000001a0 0000000000000000 A 0 0 16 - * ... - * - * but they should be treated as if they are NULL. - */ - && strncmp (bfd_section_name (cur_sec), "__k", 3) != 0) - break; - - if (cur_sec == NULL) - { section_offsets &offsets = objfile->section_offsets; /* Pick non-overlapping offsets for sections the user did not @@ -704,7 +684,6 @@ default_symfile_offsets (struct objfile *objfile, offsets[cur_sec->index]); offsets[cur_sec->index] = 0; } - } } /* Remember the bfd indexes for the .text, .data, .bss and --- gdb-16.2/gdb/symtab.c.orig +++ gdb-16.2/gdb/symtab.c @@ -7690,7 +7690,11 @@ console("expr->first_opcode(): OP_VAR_VALUE\n"); type = expr->evaluate_type()->type(); if (req->tcb) { - long value = value_as_long(expr->evaluate()); + expr::var_value_operation *vvop + = (gdb::checked_static_cast + (expr->op.get ())); + sym = vvop->get_symbol (); + long value = sym->value_longest (); /* callback with symbol value */ req->typecode = TYPE_CODE(type); req->tcb(EOP_VALUE, req, &value, 0, 0, 0); @@ -7701,8 +7705,12 @@ req->length = type->length(); } if (TYPE_CODE(type) == TYPE_CODE_ENUM) { + expr::var_value_operation *vvop + = (gdb::checked_static_cast + (expr->op.get ())); + sym = vvop->get_symbol (); req->typecode = TYPE_CODE(type); - req->value = value_as_long(expr->evaluate()); + req->value = sym->value_longest (); req->tagname = (char *)TYPE_TAG_NAME(type); if (!req->tagname) { val = expr->evaluate_type(); --- gdb-16.2/gdb/solib-svr4.c.orig +++ gdb-16.2/gdb/solib-svr4.c @@ -741,13 +741,13 @@ return 0; return extract_typed_address (pbuf, ptr_type); } - +#ifndef CRASH_MERGE /* Find DT_DEBUG. */ if (gdb_bfd_scan_elf_dyntag (DT_DEBUG, current_program_space->exec_bfd (), &dyn_ptr, NULL) || scan_dyntag_auxv (DT_DEBUG, &dyn_ptr, NULL)) return dyn_ptr; - +#endif /* This may be a static executable. Look for the symbol conventionally named _r_debug, as a last resort. */ bound_minimal_symbol msymbol --- gdb-16.2/gdb/symtab.c.orig +++ gdb-16.2/gdb/symtab.c @@ -7726,6 +7726,7 @@ type = expr->evaluate_type()->type(); if (req->tcb) { + req->typecode = TYPE_CODE(type); drillDownType(req, type); } else { req->typecode = TYPE_CODE(type); crash-utility-crash-61fe107/gdb_interface.c000066400000000000000000000713131517256214500207010ustar00rootroot00000000000000/* gdb_interface.c - core analysis suite * * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. * Copyright (C) 2002-2015,2018-2019 David Anderson * Copyright (C) 2002-2015,2018-2019 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #include "defs.h" #if !defined(GDB_10_2) && !defined(GDB_16_2) static void exit_after_gdb_info(void); #endif static int is_restricted_command(char *, ulong); static void strip_redirection(char *); int get_frame_offset(ulong); int *gdb_output_format; unsigned int *gdb_print_max; unsigned char *gdb_prettyprint_structs; unsigned char *gdb_prettyprint_arrays; unsigned int *gdb_repeat_count_threshold; unsigned char *gdb_stop_print_at_null; unsigned int *gdb_output_radix; static void gdb_error_debug(void); static ulong gdb_user_print_option_address(char *); /* * Called from main() this routine sets up the call-back hook such that * gdb's main() routine -- renamed gdb_main() -- will call back to * our main_loop() after gdb initializes. */ void gdb_main_loop(int argc, char **argv) { argc = 1; if (pc->flags & SILENT) { if (pc->flags & READNOW) argv[argc++] = "--readnow"; argv[argc++] = "--quiet"; argv[argc++] = pc->namelist_debug ? pc->namelist_debug : (pc->debuginfo_file && (st->flags & CRC_MATCHES) ? pc->debuginfo_file : pc->namelist); } else { if (pc->flags & READNOW) argv[argc++] = "--readnow"; argv[argc++] = pc->namelist_debug ? pc->namelist_debug : (pc->debuginfo_file && (st->flags & CRC_MATCHES) ? pc->debuginfo_file : pc->namelist); } if (CRASHDEBUG(1)) { int i; fprintf(fp, "gdb "); for (i = 1; i < argc; i++) fprintf(fp, "%s ", argv[i]); fprintf(fp, "\n"); } optind = 0; #if !defined(GDB_10_2) && !defined(GDB_16_2) #if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) command_loop_hook = main_loop; #else deprecated_command_loop_hook = main_loop; #endif #endif gdb_main_entry(argc, argv); } /* * Update any hooks that gdb has set. */ void update_gdb_hooks(void) { #if defined(GDB_6_0) || defined(GDB_6_1) command_loop_hook = pc->flags & VERSION_QUERY ? exit_after_gdb_info : main_loop; target_new_objfile_hook = NULL; #endif #if defined(GDB_7_0) || defined(GDB_7_3_1) || defined(GDB_7_6) deprecated_command_loop_hook = pc->flags & VERSION_QUERY ? exit_after_gdb_info : main_loop; #endif } void gdb_readnow_warning(void) { if ((THIS_GCC_VERSION >= GCC(3,4,0)) && (THIS_GCC_VERSION < GCC(4,0,0)) && !(pc->flags & READNOW)) { fprintf(stderr, "WARNING: Because this kernel was compiled with gcc version %d.%d.%d, certain\n" " commands or command options may fail unless crash is invoked with\n" " the \"--readnow\" command line option.\n\n", kt->gcc_version[0], kt->gcc_version[1], kt->gcc_version[2]); } } /* * Used only by the -v command line option, get gdb to initialize itself * with no arguments, print its version and GPL paragraph, and then call * back to exit_after_gdb_info(). */ void display_gdb_banner(void) { optind = 0; #if !defined(GDB_10_2) && !defined(GDB_16_2) #if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) command_loop_hook = exit_after_gdb_info; #else deprecated_command_loop_hook = exit_after_gdb_info; #endif #endif args[0] = "gdb"; args[1] = "-version"; gdb_main_entry(2, args); } #if !defined(GDB_10_2) && !defined(GDB_16_2) static void exit_after_gdb_info(void) { fprintf(fp, "\n"); clean_exit(0); } #endif /* * Stash a copy of the gdb version locally. This can be called before * gdb gets initialized, so bypass gdb_interface(). */ void get_gdb_version(void) { struct gnu_request request; if (!pc->gdb_version) { request.command = GNU_VERSION; gdb_command_funnel(&request); /* bypass gdb_interface() */ pc->gdb_version = request.buf; } } extern void *current_program_space; void gdb_session_init(void) { struct gnu_request *req; int debug_data_pulled_in; if (!have_partial_symbols(current_program_space) && !have_full_symbols(current_program_space)) no_debugging_data(FATAL); /* * Restore the SIGINT and SIGPIPE handlers, which got temporarily * re-assigned by gdb. The SIGINT call also initializes GDB's * SIGINT sigaction. */ SIGACTION(SIGINT, restart, &pc->sigaction, &pc->gdb_sigaction); SIGACTION(SIGPIPE, SIG_IGN, &pc->sigaction, NULL); if (!(pc->flags & DROP_CORE)) SIGACTION(SIGSEGV, restart, &pc->sigaction, NULL); /* * Set up pointers to gdb variables. */ #if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) gdb_output_format = &output_format; gdb_print_max = &print_max; gdb_prettyprint_structs = &prettyprint_structs; gdb_prettyprint_arrays = &prettyprint_arrays; gdb_repeat_count_threshold = &repeat_count_threshold; gdb_stop_print_at_null = &stop_print_at_null; gdb_output_radix = &output_radix; #else gdb_output_format = (int *) gdb_user_print_option_address("output_format"); gdb_print_max = (unsigned int *) gdb_user_print_option_address("print_max"); gdb_prettyprint_structs = (unsigned char *) gdb_user_print_option_address("prettyprint_structs"); gdb_prettyprint_arrays = (unsigned char *) gdb_user_print_option_address("prettyprint_arrays"); gdb_repeat_count_threshold = (unsigned int *) gdb_user_print_option_address("repeat_count_threshold"); gdb_stop_print_at_null = (unsigned char *) gdb_user_print_option_address("stop_print_at_null"); gdb_output_radix = (unsigned int *) gdb_user_print_option_address("output_radix"); #endif /* * If the output radix is set via the --hex or --dec command line * option, then pc->output_radix will be non-zero; otherwise use * the gdb default. */ if (pc->output_radix) { *gdb_output_radix = pc->output_radix; *gdb_output_format = (*gdb_output_radix == 10) ? 0 : 'x'; } switch (*gdb_output_radix) { case 10: case 16: pc->output_radix = *gdb_output_radix; break; default: pc->output_radix = *gdb_output_radix = 10; *gdb_output_format = 0; } *gdb_prettyprint_structs = 1; *gdb_repeat_count_threshold = 0x7fffffff; *gdb_print_max = 256; #ifdef GDB_5_3 gdb_disassemble_from_exec = 0; #endif pc->flags |= GDB_INIT; /* set here so gdb_interface will work */ req = (struct gnu_request *)GETBUF(sizeof(struct gnu_request)); req->buf = GETBUF(BUFSIZE); /* * Make sure the namelist has symbolic data. Later versions of * gcc may require that debug data be pulled in by printing a * static kernel data structure. */ debug_data_pulled_in = FALSE; retry: BZERO(req->buf, BUFSIZE); req->command = GNU_GET_DATATYPE; req->name = XEN_HYPER_MODE() ? "page_info" : "task_struct"; req->flags = GNU_RETURN_ON_ERROR; gdb_interface(req); if (req->flags & GNU_COMMAND_FAILED) { if (XEN_HYPER_MODE()) no_debugging_data(WARNING); /* just bail out */ if (!debug_data_pulled_in) { if (CRASHDEBUG(1)) error(INFO, "gdb_session_init: pulling in debug data by accessing init_mm.mmap %s\n", symbol_exists("sysfs_mount") ? "and syfs_mount" : ""); debug_data_pulled_in = TRUE; req->command = GNU_PASS_THROUGH; req->flags = GNU_RETURN_ON_ERROR|GNU_NO_READMEM; req->name = NULL; if (symbol_exists("sysfs_mount")) sprintf(req->buf, "print sysfs_mount, init_mm.mmap"); else sprintf(req->buf, "print init_mm.mmap"); gdb_interface(req); if (!(req->flags & GNU_COMMAND_FAILED)) goto retry; } no_debugging_data(WARNING); } if (pc->flags & KERNEL_DEBUG_QUERY) { fprintf(fp, "\n%s: %s: contains debugging data\n\n", pc->program_name, pc->namelist); if (REMOTE()) remote_exit(); clean_exit(0); } /* * Set up any pre-ordained gdb settings here that can't be * accessed directly. */ req->command = GNU_PASS_THROUGH; req->name = NULL, req->flags = 0; sprintf(req->buf, "set height 0"); gdb_interface(req); req->command = GNU_PASS_THROUGH; req->name = NULL, req->flags = 0; sprintf(req->buf, "set width 0"); gdb_interface(req); #if defined(GDB_10_2) || defined(GDB_16_2) req->command = GNU_PASS_THROUGH; req->name = NULL, req->flags = 0; sprintf(req->buf, "set max-value-size unlimited"); gdb_interface(req); req->command = GNU_PASS_THROUGH; req->name = NULL, req->flags = 0; sprintf(req->buf, "set max-completions unlimited"); gdb_interface(req); #endif #if 0 /* * Patch gdb's symbol values with the correct values from either * the System.map or non-debug vmlinux, whichever is in effect. */ if ((pc->flags & SYSMAP) || (kt->flags & (RELOC_SET|RELOC_FORCE)) || (pc->namelist_debug && !pc->debuginfo_file)) { req->command = GNU_PATCH_SYMBOL_VALUES; req->flags = GNU_RETURN_ON_ERROR; gdb_interface(req); if (req->flags & GNU_COMMAND_FAILED) error(FATAL, "patching of gdb symbol values failed\n"); } else if (!(pc->flags & SILENT)) #else if (!(pc->flags & SILENT)) #endif fprintf(fp, "\n"); FREEBUF(req->buf); FREEBUF(req); } /* * Quickest way to gdb -- just pass a command string to pass through. */ int gdb_pass_through(char *cmd, FILE *fptr, ulong flags) { struct gnu_request *req; int retval; if (CRASHDEBUG(1)) console("gdb_pass_through: [%s]\n", cmd); req = (struct gnu_request *)GETBUF(sizeof(struct gnu_request)); req->buf = cmd; if (fptr) req->fp = fptr; req->command = GNU_PASS_THROUGH; req->flags = flags; gdb_interface(req); if ((req->flags & (GNU_RETURN_ON_ERROR|GNU_COMMAND_FAILED)) == (GNU_RETURN_ON_ERROR|GNU_COMMAND_FAILED)) retval = FALSE; else retval = TRUE; FREEBUF(req); return retval; } /* * General purpose routine for passing commands to gdb. All gdb commands * come through here, where they are passed to gdb_command_funnel(). */ void gdb_interface(struct gnu_request *req) { if (!(pc->flags & GDB_INIT)) error(FATAL, "gdb_interface: gdb not initialized?\n"); if (output_closed()) restart(0); if (!req->fp) { req->fp = ((pc->flags & RUNTIME) || (pc->flags2 & ALLOW_FP)) ? fp : CRASHDEBUG(1) ? fp : pc->nullfp; } pc->cur_req = req; pc->cur_gdb_cmd = req->command; if (CRASHDEBUG(2)) dump_gnu_request(req, IN_GDB); if (!(pc->flags & DROP_CORE)) SIGACTION(SIGSEGV, restart, &pc->sigaction, NULL); else SIGACTION(SIGSEGV, SIG_DFL, &pc->sigaction, NULL); if (interruptible()) { SIGACTION(SIGINT, pc->gdb_sigaction.sa_handler, &pc->gdb_sigaction, NULL); } else { SIGACTION(SIGINT, SIG_IGN, &pc->sigaction, NULL); SIGACTION(SIGPIPE, SIG_IGN, &pc->sigaction, NULL); } pc->flags |= IN_GDB; gdb_command_funnel(req); pc->flags &= ~IN_GDB; SIGACTION(SIGINT, restart, &pc->sigaction, NULL); SIGACTION(SIGSEGV, SIG_DFL, &pc->sigaction, NULL); if (req->flags & GNU_COMMAND_FAILED) gdb_error_debug(); if (CRASHDEBUG(2)) dump_gnu_request(req, !IN_GDB); pc->last_gdb_cmd = pc->cur_gdb_cmd; pc->cur_gdb_cmd = 0; pc->cur_req = NULL; } /* * help -g output */ void dump_gdb_data(void) { fprintf(fp, " prettyprint_arrays: %d\n", *gdb_prettyprint_arrays); fprintf(fp, " prettyprint_structs: %d\n", *gdb_prettyprint_structs); fprintf(fp, "repeat_count_threshold: %x\n", *gdb_repeat_count_threshold); fprintf(fp, " stop_print_at_null: %d\n", *gdb_stop_print_at_null); fprintf(fp, " print_max: %d\n", *gdb_print_max); fprintf(fp, " output_radix: %d\n", *gdb_output_radix); fprintf(fp, " output_format: "); switch (*gdb_output_format) { case 'x': fprintf(fp, "hex\n"); break; case 'o': fprintf(fp, "octal\n"); break; case 0: fprintf(fp, "decimal\n"); break; } } void dump_gnu_request(struct gnu_request *req, int in_gdb) { int others; char buf[BUFSIZE]; if (pc->flags & KERNEL_DEBUG_QUERY) return; console("%scommand: %d (%s)\n", in_gdb ? "GDB IN: " : "GDB OUT: ", req->command, gdb_command_string(req->command, buf, TRUE)); console("buf: %lx ", req->buf); if (req->buf && ascii_string(req->buf)) console(" \"%s\"", req->buf); console("\n"); console("fp: %lx ", req->fp); if (req->fp == pc->nullfp) console("(pc->nullfp) "); if (req->fp == pc->stdpipe) console("(pc->stdpipe) "); if (req->fp == pc->pipe) console("(pc->pipe) "); if (req->fp == pc->ofile) console("(pc->ofile) "); if (req->fp == pc->ifile) console("(pc->ifile) "); if (req->fp == pc->ifile_pipe) console("(pc->ifile_pipe) "); if (req->fp == pc->ifile_ofile) console("(pc->ifile_ofile) "); if (req->fp == pc->tmpfile) console("(pc->tmpfile) "); if (req->fp == pc->saved_fp) console("(pc->saved_fp) "); if (req->fp == pc->tmp_fp) console("(pc->tmp_fp) "); console("flags: %lx (", req->flags); others = 0; if (req->flags & GNU_PRINT_LINE_NUMBERS) console("%sGNU_PRINT_LINE_NUMBERS", others++ ? "|" : ""); if (req->flags & GNU_FUNCTION_ONLY) console("%sGNU_FUNCTION_ONLY", others++ ? "|" : ""); if (req->flags & GNU_PRINT_ENUMERATORS) console("%sGNU_PRINT_ENUMERATORS", others++ ? "|" : ""); if (req->flags & GNU_RETURN_ON_ERROR) console("%sGNU_RETURN_ON_ERROR", others++ ? "|" : ""); if (req->flags & GNU_FROM_TTY_OFF) console("%sGNU_FROM_TTY_OFF", others++ ? "|" : ""); if (req->flags & GNU_NO_READMEM) console("%sGNU_NO_READMEM", others++ ? "|" : ""); if (req->flags & GNU_VAR_LENGTH_TYPECODE) console("%sGNU_VAR_LENGTH_TYPECODE", others++ ? "|" : ""); console(")\n"); console("addr: %lx ", req->addr); console("addr2: %lx ", req->addr2); console("count: %ld\n", req->count); if ((ulong)req->name > (ulong)PATCH_KERNEL_SYMBOLS_STOP) console("name: \"%s\" ", req->name); else console("name: %lx ", (ulong)req->name); console("length: %ld ", req->length); console("typecode: %d\n", req->typecode); #if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) || defined(GDB_7_0) console("typename: %s\n", req->typename); #else console("type_name: %s\n", req->type_name); #endif console("target_typename: %s\n", req->target_typename); console("target_length: %ld ", req->target_length); console("target_typecode: %d ", req->target_typecode); console("is_typedef: %d ", req->is_typedef); console("member: \"%s\" ", req->member); console("member_offset: %ld\n", req->member_offset); console("member_length: %ld\n", req->member_length); console("member_typecode: %d\n", req->member_typecode); console("member_main_type_name: %s\n", req->member_main_type_name); console("member_main_type_tag_name: %s\n", req->member_main_type_tag_name); console("member_target_type_name: %s\n", req->member_target_type_name); console("member_target_type_tag_name: %s\n", req->member_target_type_tag_name); console("value: %lx ", req->value); console("tagname: \"%s\" ", req->tagname); console("pc: %lx ", req->pc); if (is_kernel_text(req->pc)) console("(%s)", value_to_symstr(req->pc, buf, 0)); console("\n"); console("sp: %lx ", req->sp); console("ra: %lx ", req->ra); console("frame: %ld ", req->frame); console("prevsp: %lx\n", req->prevsp); console("prevpc: %lx ", req->prevpc); console("lastsp: %lx ", req->lastsp); console("task: %lx ", req->task); console("debug: %lx\n", req->debug); console("\n"); } char * gdb_command_string(int cmd, char *buf, int live) { switch (cmd) { case GNU_PASS_THROUGH: sprintf(buf, "GNU_PASS_THROUGH"); break; case GNU_DATATYPE_INIT: sprintf(buf, "GNU_DATATYPE_INIT"); break; case GNU_DISASSEMBLE: sprintf(buf, "GNU_DISASSEMBLE"); break; case GNU_GET_LINE_NUMBER: sprintf(buf, "GNU_GET_LINE_NUMBER"); break; case GNU_GET_DATATYPE: if (live) sprintf(buf, "GNU_GET_DATATYPE[%s]", pc->cur_req->name ? pc->cur_req->name : "?"); else sprintf(buf, "GNU_GET_DATATYPE"); break; case GNU_STACK_TRACE: sprintf(buf, "GNU_STACK_TRACE"); break; case GNU_ALPHA_FRAME_OFFSET: sprintf(buf, "GNU_ALPHA_FRAME_OFFSET"); break; case GNU_COMMAND_EXISTS: sprintf(buf, "GNU_COMMAND_EXISTS"); break; case GNU_FUNCTION_NUMARGS: sprintf(buf, "GNU_FUNCTION_NUMARGS"); break; case GNU_RESOLVE_TEXT_ADDR: sprintf(buf, "GNU_RESOLVE_TEXT_ADDR"); break; case GNU_DEBUG_COMMAND: sprintf(buf, "GNU_DEBUG_COMMAND"); break; case GNU_ADD_SYMBOL_FILE: sprintf(buf, "GNU_ADD_SYMBOL_FILE"); break; case GNU_DELETE_SYMBOL_FILE: sprintf(buf, "GNU_DELETE_SYMBOL_FILE"); break; case GNU_VERSION: sprintf(buf, "GNU_VERSION"); break; case GNU_GET_SYMBOL_TYPE: sprintf(buf, "GNU_GET_SYMBOL_TYPE"); break; case GNU_PATCH_SYMBOL_VALUES: sprintf(buf, "GNU_PATCH_SYMBOL_VALUES"); break; case GNU_USER_PRINT_OPTION: sprintf(buf, "GNU_USER_PRINT_OPTION"); break; case GNU_SET_CRASH_BLOCK: sprintf(buf, "GNU_SET_CRASH_BLOCK"); break; case GNU_GET_FUNCTION_RANGE: sprintf(buf, "GNU_GET_FUNCTION_RANGE"); break; case 0: buf[0] = NULLCHAR; break; default: sprintf(buf, "(?)\n"); break; } return buf; } /* * Restore known gdb state. */ void restore_gdb_sanity(void) { if (!(pc->flags & GDB_INIT)) return; if (pc->output_radix) { *gdb_output_radix = pc->output_radix; *gdb_output_format = (*gdb_output_radix == 10) ? 0 : 'x'; } *gdb_prettyprint_structs = 1; /* these may piss somebody off... */ *gdb_repeat_count_threshold = 0x7fffffff; if (st->flags & ADD_SYMBOL_FILE) { error(INFO, "%s\n gdb add-symbol-file command failed\n", st->current->mod_namelist); delete_load_module(st->current->mod_base); st->flags &= ~ADD_SYMBOL_FILE; } if (pc->cur_gdb_cmd) { pc->last_gdb_cmd = pc->cur_gdb_cmd; pc->cur_gdb_cmd = 0; } } /* * Check whether string in args[0] is a valid gdb command. */ int is_gdb_command(int merge_orig_args, ulong flags) { int retval; struct gnu_request *req; if (!args[0]) return FALSE; if (STREQ(args[0], "Q")) { args[0] = "q"; return TRUE; } if (is_restricted_command(args[0], flags)) return FALSE; req = (struct gnu_request *)GETBUF(sizeof(struct gnu_request)); req->buf = GETBUF(strlen(args[0])+1); req->command = GNU_COMMAND_EXISTS; req->name = args[0]; req->flags = GNU_RETURN_ON_ERROR; req->fp = pc->nullfp; gdb_interface(req); if (req->flags & GNU_COMMAND_FAILED) retval = FALSE; else retval = req->value; FREEBUF(req->buf); FREEBUF(req); if (retval && merge_orig_args) { int i; for (i = argcnt; i; i--) args[i] = args[i-1]; args[0] = "gdb"; argcnt++; } return retval; } /* * Check whether a command is on the gdb-prohibited list. */ static char *prohibited_list[] = { "run", "r", "break", "b", "tbreak", "hbreak", "thbreak", "rbreak", "watch", "rwatch", "awatch", "attach", "continue", "c", "fg", "detach", "finish", "handle", "interrupt", "jump", "kill", "next", "nexti", "signal", "step", "s", "stepi", "target", "until", "delete", "clear", "disable", "enable", "condition", "ignore", "catch", "tcatch", "return", "file", "exec-file", "core-file", "symbol-file", "load", "si", "ni", "shell", "sy", NULL /* must be last */ }; static char *restricted_list[] = { "define", "document", "while", "if", NULL /* must be last */ }; #define RESTRICTED_GDB_COMMAND \ "restricted gdb command: %s\n%s\"%s\" may only be used in a .gdbinit file or in a command file.\n%sThe .gdbinit file is read automatically during %s initialization.\n%sOther user-defined command files may be read interactively during\n%s%s runtime by using the gdb \"source\" command.\n" static int is_restricted_command(char *cmd, ulong flags) { int i; char *newline; for (i = 0; prohibited_list[i]; i++) { if (STREQ(prohibited_list[i], cmd)) { if (flags == RETURN_ON_ERROR) return TRUE; pc->curcmd = pc->program_name; error(FATAL, "prohibited gdb command: %s\n", cmd); } } for (i = 0; restricted_list[i]; i++) { if (STREQ(restricted_list[i], cmd)) { if (flags == RETURN_ON_ERROR) return TRUE; newline = space(strlen(pc->program_name)+2); pc->curcmd = pc->program_name; error(FATAL, RESTRICTED_GDB_COMMAND, cmd, newline, cmd, newline, pc->program_name, newline, newline, pc->program_name); } } return FALSE; } /* * Remove pipe/redirection stuff from the end of the command line. */ static void strip_redirection(char *buf) { char *p1, *p2; p1 = strstr_rightmost(buf, args[argcnt-1]); p2 = p1 + strlen(args[argcnt-1]); console("strip_redirection: [%s]\n", p2); if ((p1 = strpbrk(p2, "|!>"))) *p1 = NULLCHAR; strip_ending_whitespace(buf); } /* * Command for passing strings directly to gdb. */ void cmd_gdb(void) { char buf[BUFSIZE]; char **argv; argv = STREQ(args[0], "gdb") ? &args[1] : &args[0]; if (*argv == NULL) cmd_usage(pc->curcmd, SYNOPSIS); if (STREQ(*argv, "set") && argv[1]) { /* * Intercept set commands in case something has to be done * here or elsewhere. */ if (STREQ(argv[1], "gdb")) { cmd_set(); return; } if (STREQ(argv[1], "output-radix") && argv[2]) pc->output_radix = stol(argv[2], FAULT_ON_ERROR, NULL); } /* * If the command is not restricted, pass it on. */ if (!is_restricted_command(*argv, FAULT_ON_ERROR)) { if (STREQ(pc->command_line, "gdb")) { strcpy(buf, first_space(pc->orig_line)); strip_beginning_whitespace(buf); } else strcpy(buf, pc->orig_line); if (pc->redirect & (REDIRECT_TO_FILE|REDIRECT_TO_PIPE)) strip_redirection(buf); if (!gdb_pass_through(buf, NULL, GNU_RETURN_ON_ERROR)) error(INFO, "gdb request failed: %s\n", buf); } } /* * The gdb target_xfer_memory() has a hook installed to re-route * all memory accesses back here; reads of 1 or 4 bytes come primarily * from text disassembly requests, and are diverted to the text cache. */ int gdb_readmem_callback(ulong addr, void *buf, int len, int write) { char locbuf[SIZEOF_32BIT], *p1; int memtype; ulong readflags; if (write) return FALSE; if (!(pc->cur_req)) { return(readmem(addr, KVADDR, buf, len, "gdb_readmem_callback", RETURN_ON_ERROR)); } if (pc->cur_req->flags & GNU_NO_READMEM) return TRUE; readflags = pc->curcmd_flags & PARTIAL_READ_OK ? RETURN_ON_ERROR|RETURN_PARTIAL : RETURN_ON_ERROR; if (STREQ(pc->curcmd, "bpf") && pc->curcmd_private && (addr > (ulong)pc->curcmd_private)) readflags |= QUIET; if (pc->curcmd_flags & MEMTYPE_UVADDR) memtype = UVADDR; else if (pc->curcmd_flags & MEMTYPE_FILEADDR) memtype = FILEADDR; else if (!IS_KVADDR(addr)) { if (STREQ(pc->curcmd, "gdb") && STRNEQ(pc->cur_req->buf, "x/")) { memtype = UVADDR; } else { if (CRASHDEBUG(1)) console("gdb_readmem_callback: %lx %d FAILED\n", addr, len); return FALSE; } } else memtype = KVADDR; if (CRASHDEBUG(1)) console("gdb_readmem_callback[%d]: %lx %d\n", memtype, addr, len); if (memtype == FILEADDR) return(readmem(pc->curcmd_private, memtype, buf, len, "gdb_readmem_callback", readflags)); switch (len) { case SIZEOF_8BIT: if (STREQ(pc->curcmd, "bt")) { if (readmem(addr, memtype, buf, SIZEOF_8BIT, "gdb_readmem_callback", readflags)) return TRUE; } p1 = (char *)buf; if (!readmem(addr, memtype, locbuf, SIZEOF_32BIT, "gdb_readmem_callback", readflags)) return FALSE; *p1 = locbuf[0]; return TRUE; case SIZEOF_32BIT: if (STREQ(pc->curcmd, "bt")) { if (readmem(addr, memtype, buf, SIZEOF_32BIT, "gdb_readmem_callback", readflags)) return TRUE; } if (!readmem(addr, memtype, buf, SIZEOF_32BIT, "gdb_readmem callback", readflags)) return FALSE; return TRUE; } return(readmem(addr, memtype, buf, len, "gdb_readmem_callback", readflags)); } /* * Machine-specific line-number pc section range verifier. */ int gdb_line_number_callback(ulong pc, ulong low, ulong high) { if (machdep->verify_line_number) return machdep->verify_line_number(pc, low, high); return TRUE; } /* * Prevent gdb from trying to translate and print pointers * that are not kernel virtual addresses. */ int gdb_print_callback(ulong addr) { if (!addr) return FALSE; else return IS_KVADDR(addr); } char * gdb_lookup_module_symbol(ulong addr, ulong *offset) { struct syment *sp; if ((sp = value_search_module(addr, offset))) { return sp->name; } else { return NULL; } } int is_kvaddr(ulong addr) { return IS_KVADDR(addr); } /* * Used by gdb_interface() to catch gdb-related errors, if desired. */ static void gdb_error_debug(void) { char buf1[BUFSIZE]; char buf2[BUFSIZE]; int buffers; if (CRASHDEBUG(2)) { sprintf(buf2, "\n"); if (CRASHDEBUG(5) && (buffers = get_embedded())) sprintf(buf2, "(%d buffer%s in use)\n", buffers, buffers > 1 ? "s" : ""); fprintf(stderr, "%s: returned via gdb_error_hook %s", gdb_command_string(pc->cur_gdb_cmd, buf1, TRUE), buf2); console("%s: returned via gdb_error_hook %s", gdb_command_string(pc->cur_gdb_cmd, buf1, TRUE), buf2); } } /* * gdb callback to access debug mode. */ int gdb_CRASHDEBUG(ulong dval) { if (CRASHDEBUG(dval)) return TRUE; return (pc->cur_req && (pc->cur_req->debug >= dval)); } static ulong gdb_user_print_option_address(char *name) { struct gnu_request request; request.command = GNU_USER_PRINT_OPTION; request.name = name; gdb_command_funnel(&request); return request.addr; } /* * Try to set a crash scope block based upon the vaddr. */ int gdb_set_crash_scope(ulong vaddr, char *arg) { struct gnu_request request, *req = &request; char name[BUFSIZE]; struct load_module *lm; if (vaddr) { if (!is_kernel_text(vaddr)) { error(INFO, "invalid text address: %s\n", arg); return FALSE; } if (module_symbol(vaddr, NULL, &lm, name, 0)) { if (!(lm->mod_flags & MOD_LOAD_SYMS)) { error(INFO, "attempting to find/load \"%s\" module debuginfo\n", lm->mod_name); if (!load_module_symbols_helper(lm->mod_name)) { error(INFO, "cannot find/load \"%s\" module debuginfo\n", lm->mod_name); return FALSE; } } } } req->command = GNU_SET_CRASH_BLOCK; req->addr = vaddr; req->flags = 0; req->addr2 = 0; req->fp = pc->nullfp; gdb_command_funnel(req); if (CRASHDEBUG(1)) fprintf(fp, "gdb_set_crash_scope: %s addr: %lx block: %lx\n", req->flags & GNU_COMMAND_FAILED ? "FAILED" : "OK", req->addr, req->addr2); if (req->flags & GNU_COMMAND_FAILED) { error(INFO, "gdb cannot find text block for address: %s\n", arg); return FALSE; } return TRUE; } #ifndef ALPHA /* * Stub routine needed for resolution by non-alpha, modified gdb code. */ int get_frame_offset(ulong pc) { return (error(FATAL, "get_frame_offset: invalid request for non-alpha systems!\n")); } #endif /* !ALPHA */ unsigned long crash_get_kaslr_offset(void); unsigned long crash_get_kaslr_offset(void) { return kt->relocate * -1; } /* Callbacks for crash_target */ int crash_get_current_task_reg (int regno, const char *regname, int regsize, void *value, int sid); int crash_get_current_task_reg (int regno, const char *regname, int regsize, void *value, int sid) { if (!machdep->get_current_task_reg) return FALSE; return machdep->get_current_task_reg(regno, regname, regsize, value, sid); } /* arm64 kernel lr maybe has patuh */ #ifdef ARM64 void crash_decode_ptrauth_pc(ulong *pc); void crash_decode_ptrauth_pc(ulong *pc) { struct machine_specific *ms = machdep->machspec; if (is_kernel_text(*pc | ms->CONFIG_ARM64_KERNELPACMASK)) *pc |= ms->CONFIG_ARM64_KERNELPACMASK; } #endif /* !ARM64 */ crash-utility-crash-61fe107/global_data.c000066400000000000000000000133401517256214500203520ustar00rootroot00000000000000/* global_data.c - core analysis suite * * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. * Copyright (C) 2002-2006, 2010, 2012-2013, 2018 David Anderson * Copyright (C) 2002-2006, 2010, 2012-2013, 2018 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #include "defs.h" /* * Data output FILE pointer. The contents of fp are changed on the fly * depending upon whether the output is going to stdout, redirected to a * user-designated pipe or file, or to the "standard" scrolling pipe. * Regardless of where it ends up, fprintf(fp, ...) is used throughout * instead of printf(). */ FILE *fp; /* * The state of the program is kept in the program_context structure. * Given that it's consulted so often, "pc" is globally available to * quickly access the structure contents. */ struct program_context program_context = { 0 }; struct program_context *pc = &program_context; /* * The same thing goes for accesses to the frequently-accessed task_table, * kernel_table, vm_table, symbol_table_data and machdep_table, making the * "tt", "kt", "vt", "st" and "machdep" pointers globally available. */ struct task_table task_table = { 0 }; struct task_table *tt = &task_table; struct kernel_table kernel_table = { 0 }; struct kernel_table *kt = &kernel_table; struct vm_table vm_table = { 0 }; struct vm_table *vt = &vm_table; struct symbol_table_data symbol_table_data = { 0 }; struct symbol_table_data *st = &symbol_table_data; struct machdep_table machdep_table = { 0 }; struct machdep_table *machdep = &machdep_table; /* * Command functions are entered with the args[] array and argcnt value * pre-set for issuance to getopt(). */ char *args[MAXARGS]; /* argument array */ int argcnt; /* argument count */ int argerrs; /* argument error counter */ /* * To add a new command, declare it in defs.h and enter it in this table. */ struct command_table_entry linux_command_table[] = { {"*", cmd_pointer, help_pointer, 0}, {"alias", cmd_alias, help_alias, 0}, {"ascii", cmd_ascii, help_ascii, 0}, {"bpf", cmd_bpf, help_bpf, 0}, {"bt", cmd_bt, help_bt, REFRESH_TASK_TABLE}, {"btop", cmd_btop, help_btop, 0}, {"dev", cmd_dev, help_dev, 0}, {"dis", cmd_dis, help_dis, MINIMAL}, {"eval", cmd_eval, help_eval, MINIMAL}, {"exit", cmd_quit, help_exit, MINIMAL}, {"extend", cmd_extend, help_extend, MINIMAL}, {"files", cmd_files, help_files, REFRESH_TASK_TABLE}, {"foreach", cmd_foreach, help_foreach, REFRESH_TASK_TABLE}, {"fuser", cmd_fuser, help_fuser, REFRESH_TASK_TABLE}, {"gdb", cmd_gdb, help_gdb, REFRESH_TASK_TABLE}, {"help", cmd_help, help_help, MINIMAL}, {"ipcs", cmd_ipcs, help_ipcs, REFRESH_TASK_TABLE}, {"irq", cmd_irq, help_irq, 0}, {"kmem", cmd_kmem, help_kmem, 0}, {"list", cmd_list, help__list, REFRESH_TASK_TABLE}, {"log", cmd_log, help_log, MINIMAL}, {"mach", cmd_mach, help_mach, 0}, {"map", cmd_map, help_map, HIDDEN_COMMAND}, {"mod", cmd_mod, help_mod, 0}, {"mount", cmd_mount, help_mount, REFRESH_TASK_TABLE}, {"net", cmd_net, help_net, REFRESH_TASK_TABLE}, {"p", cmd_p, help_p, 0}, {"ps", cmd_ps, help_ps, REFRESH_TASK_TABLE}, {"pte", cmd_pte, help_pte, 0}, {"ptob", cmd_ptob, help_ptob, 0}, {"ptov", cmd_ptov, help_ptov, 0}, {"q", cmd_quit, help_quit, MINIMAL}, {"tree", cmd_tree, help_tree, REFRESH_TASK_TABLE}, {"rd", cmd_rd, help_rd, MINIMAL}, {"repeat", cmd_repeat, help_repeat, 0}, {"runq", cmd_runq, help_runq, REFRESH_TASK_TABLE}, {"sbitmapq", cmd_sbitmapq, help_sbitmapq, 0}, {"search", cmd_search, help_search, 0}, {"set", cmd_set, help_set, REFRESH_TASK_TABLE | MINIMAL}, {"sig", cmd_sig, help_sig, REFRESH_TASK_TABLE}, {"struct", cmd_struct, help_struct, 0}, {"swap", cmd_swap, help_swap, 0}, {"sym", cmd_sym, help_sym, MINIMAL}, {"sys", cmd_sys, help_sys, REFRESH_TASK_TABLE}, {"task", cmd_task, help_task, REFRESH_TASK_TABLE}, {"test", cmd_test, NULL, HIDDEN_COMMAND}, {"timer", cmd_timer, help_timer, 0}, {"union", cmd_union, help_union, 0}, {"vm", cmd_vm, help_vm, REFRESH_TASK_TABLE}, {"vtop", cmd_vtop, help_vtop, REFRESH_TASK_TABLE}, {"waitq", cmd_waitq, help_waitq, REFRESH_TASK_TABLE}, {"whatis", cmd_whatis, help_whatis, 0}, {"wr", cmd_wr, help_wr, 0}, #if defined(S390) || defined(S390X) {"s390dbf", cmd_s390dbf, help_s390dbf, 0}, #endif {"rustfilt", cmd_rustfilt, help_rustfilt, MINIMAL}, {(char *)NULL} }; struct extension_table *extension_table = NULL; /* * The offset_table and size_table structure contents are referenced * through several OFFSET- and SIZE-related macros. The array_table * is a shortcut used by get_array_length(). */ struct offset_table offset_table = { 0 }; struct size_table size_table = { 0 }; struct array_table array_table = { 0 }; crash-utility-crash-61fe107/help.c000066400000000000000000015327611517256214500170670ustar00rootroot00000000000000/* help.c - core analysis suite * * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. * Copyright (C) 2002-2020 David Anderson * Copyright (C) 2002-2020 Red Hat, Inc. All rights reserved. * * 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 2 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. */ #include "defs.h" static void reshuffle_cmdlist(void); static int sort_command_name(const void *, const void *); static void display_commands(void); static void display_copying_info(void); static void display_warranty_info(void); static void display_output_info(void); static void display_input_info(void); static void display_README(void); static char *gnu_public_license[]; static char *gnu_public_license_v3[]; static char *version_info[]; static char *output_info[]; static char *input_info[]; static char *README[]; static void dump_registers(void); #define GPLv2 2 #define GPLv3 3 #if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) static int GPL_version = GPLv2; #else static int GPL_version = GPLv3; #endif static char *program_usage_info[] = { "", "USAGE:", "", " crash [OPTION]... NAMELIST MEMORY-IMAGE[@ADDRESS] (dumpfile form)", " crash [OPTION]... [NAMELIST] (live system form)", "", "OPTIONS:", "", " NAMELIST", " This is a pathname to an uncompressed kernel image (a vmlinux", " file), or a Xen hypervisor image (a xen-syms file) which has", " been compiled with the \"-g\" option. If using the dumpfile form,", " a vmlinux file may be compressed in either gzip or bzip2 formats.", "", " MEMORY-IMAGE", " A kernel core dump file created by the netdump, diskdump, LKCD", " kdump, xendump or kvmdump facilities.", "", " If a MEMORY-IMAGE argument is not entered, the session will be", " invoked on the live system, which typically requires root privileges", " because of the device file used to access system RAM. By default, ", " /dev/crash will be used if it exists. If it does not exist, then ", " /dev/mem will be used; but if the kernel has been configured with ", " CONFIG_STRICT_DEVMEM, then /proc/kcore will be used. It is permissible", " to explicitly enter /dev/crash, /dev/mem or /proc/kcore.", "", " An @ADDRESS value must be appended to the MEMORY-IMAGE if the dumpfile", " is a raw RAM dumpfile that has no header information describing the file", " contents. Multiple MEMORY-IMAGE@ADDRESS ordered pairs may be entered,", " with each dumpfile containing a contiguous block of RAM, where the ADDRESS", " value is the physical start address of the block expressed in hexadecimal.", " The physical address value(s) will be used to create a temporary ELF header", " in /var/tmp, which will only exist during the crash session. If a raw RAM", " dumpfile represents a live memory source, such as that specified by the QEMU", " mem-path argument of a memory-backend-file object, then \"live:\" must be", " prepended to the MEMORY-IMAGE name.", "", " mapfile", " If the NAMELIST file is not the same kernel that is running", " (live system form), or the kernel that was running when the system", " crashed (dumpfile form), then the System.map file of the original ", " kernel should be entered on the command line.", "", " -h [option]", " --help [option]", " Without an option argument, display a crash usage help message.", " If the option argument is a crash command name, the help page", " for that command is displayed. If it is the string \"input\", a", " page describing the various crash command line input options is", " displayed. If it is the string \"output\", a page describing command", " line output options is displayed. If it is the string \"all\", then", " all of the possible help messages are displayed. After the help", " message is displayed, crash exits.", "", " -s ", " Silently proceed directly to the \"crash>\" prompt without displaying", " any version, GPL, or crash initialization data during startup, and by", " default, runtime command output is not passed to any scrolling command.", "", " -i file", " Execute the command(s) contained in \"file\" prior to displaying ", " the \"crash>\" prompt for interactive user input.", "", " -d num ", " Set the internal debug level. The higher the number, the more", " debugging data will be printed when crash initializes and runs.", "", " -S ", " Use /boot/System.map as the mapfile.", "", " -e vi | emacs", " Set the readline(3) command line editing mode to \"vi\" or \"emacs\". ", " The default editing mode is \"vi\".", "", " -f ", " Force the usage of a compressed vmlinux file if its original", " name does not start with \"vmlinux\".", "", " -k ", " Indicate that the NAMELIST file is an LKCD \"Kerntypes\" debuginfo file.", "", " -g [namelist]", " Determine if a vmlinux or xen-syms namelist file contains debugging data.", "", " -t ", " Display the system-crash timestamp and exit.", "", " -L ", " Attempt to lock all of its virtual address space into memory by", " calling mlockall(MCL_CURRENT|MCL_FUTURE) during initialization.", " If the system call fails, an error message will be displayed,", " but the session continues.", "", " -c tty-device", " Open the tty-device as the console used for debug messages.", "", " -p page-size", " If a processor's page size cannot be determined by the dumpfile, ", " and the processor default cannot be used, use page-size.", "", " -o filename", " Only used with the MEMORY-IMAGE@ADDRESS format for raw RAM dumpfiles,", " specifies a filename of a new ELF vmcore that will be created and used", " as the dumpfile. It will be saved to allow future use as a standalone", " vmcore, replacing the original raw RAM dumpfile.", "", " -m option=value", " --machdep option=value", " Pass an option and value pair to machine-dependent code. These", " architecture-specific option/pairs should only be required in", " very rare circumstances:", "", " X86_64:", " phys_base=", " irq_eframe_link=", " irq_stack_gap=", " max_physmem_bits=", " kernel_image_size=", " vm=orig (pre-2.6.11 virtual memory address ranges)", " vm=2.6.11 (2.6.11 and later virtual memory address ranges)", " vm=xen (Xen kernel virtual memory address ranges)", " vm=xen-rhel4 (RHEL4 Xen kernel virtual address ranges)", " vm=5level (5-level page tables)", " page_offset=", " PPC64:", " vm=orig", " vm=2.6.14 (4-level page tables)", " IA64:", " phys_start=", " init_stack_size=", " vm=4l (4-level page tables)", " ARM:", " phys_base=", " ARM64:", " phys_offset=", " kimage_voffset=", " max_physmem_bits=", " vabits_actual=", " X86:", " page_offset=", "", " -x ", " Automatically load extension modules from a particular directory.", " The directory is determined by the following order of precedence:", "", " (1) the directory specified in the CRASH_EXTENSIONS shell ", " environment variable", " (2) /usr/lib64/crash/extensions (64-bit architectures)", " (3) /usr/lib/crash/extensions (32-bit architectures)", " (4) the ./extensions subdirectory of the current directory", "", " --active", " Track only the active task on each cpu.", "", " --buildinfo", " Display the crash binary's build date, the user ID of the builder,", " the hostname of the machine where the build was done, the target", " architecture, the version number, and the compiler version.", "", " --memory_module modname", " Use the modname as an alternative kernel module to the crash.ko", " module that creates the /dev/crash device.", "", " --memory_device device", " Use device as an alternative device to the /dev/crash, /dev/mem", " or /proc/kcore devices.", "", " --log dumpfile", " Dump the contents of the kernel log buffer. A kernel namelist", " argument is not necessary, but the dumpfile must contain the", " VMCOREINFO data taken from the original /proc/vmcore ELF header.", " Note: this option is deprecated and will no longer work for", " kernel(>=v5.10).", "", " --no_kallsyms", " Do not use kallsyms-generated symbol information contained within", " kernel module object files.", "", " --no_modules", " Do not access or display any kernel module related information.", "", " --no_ikconfig", " Do not attempt to read configuration data that was built into", " kernels configured with CONFIG_IKCONFIG.", "", " --no_data_debug", " Do not verify the validity of all structure member offsets and", " structure sizes that it uses.", "", " --no_kmem_cache", " Do not initialize the kernel's slab cache infrastructure, and", " commands that use kmem_cache-related data will not work.", "", " --no_elf_notes", " Do not use the registers from the ELF NT_PRSTATUS notes saved", " in a compressed kdump header for backtraces.", "", " --kmem_cache_delay", " Delay the initialization of the kernel's slab cache infrastructure", " until it is required by a run-time command.", "", " --readnow", " Pass this flag to the embedded gdb module, which will override", " the two-stage strategy that it uses for reading symbol tables", " from the NAMELIST. If module symbol tables are loaded during", " runtime with the \"mod\" command, the same override will occur.", "", " --smp ", " Specify that the system being analyzed is an SMP kernel.", "", " -v", " --version", " Display the version of the crash utility, the version of the", " embedded gdb module, GPL information, and copyright notices.", "", " --cpus number", " Specify the number of cpus in the SMP system being analyzed.", "", " --osrelease dumpfile", " Display the OSRELEASE vmcoreinfo string from a kdump dumpfile", " header.", "", " --build-id dumpfile", " Display the BUILD-ID vmcoreinfo string from a kdump dumpfile", " header.", " Note: this option only works for kernel(>=v5.9); otherwise it", " prints \"unknown\" and exits with non-zero status", "", " --hyper", " Force the session to be that of a Xen hypervisor.", "", " --p2m_mfn pfn", " When a Xen Hypervisor or its dom0 kernel crashes, the dumpfile", " is typically analyzed with either the Xen hypervisor or the dom0", " kernel. It is also possible to analyze any of the guest domU", " kernels if the pfn_to_mfn_list_list pfn value of the guest kernel", " is passed on the command line along with its NAMELIST and the ", " dumpfile.", "", " --xen_phys_start physical-address", " Supply the base physical address of the Xen hypervisor's text", " and static data for older xendump dumpfiles that did not pass", " that information in the dumpfile header.", "", " --zero_excluded", " If the makedumpfile(8) facility has filtered a compressed kdump", " dumpfile to exclude various types of non-essential pages, or has", " marked a compressed or ELF kdump dumpfile as incomplete due to", " an ENOSPC or other error during its creation, any attempt to", " read missing pages will fail. With this flag, reads from any", " of those pages will return zero-filled memory.", "", " --no_panic", " Do not attempt to find the task that was running when the kernel", " crashed. Set the initial context to that of the \"swapper\" task", " on cpu 0.", "", " --more ", " Use /bin/more as the command output scroller, overriding the", " default of /usr/bin/less and any settings in either ./.crashrc", " or $HOME/.crashrc.", "", " --less ", " Use /usr/bin/less as the command output scroller, overriding any", " settings in either ./.crashrc or $HOME/.crashrc.", "", " --CRASHPAGER", " Use the output paging command defined in the CRASHPAGER shell", " environment variable, overriding any settings in either ./.crashrc ", " or $HOME/.crashrc.", "", " --no_scroll", " Do not pass run-time command output to any scrolling command.", "", " --no_strip", " Do not strip cloned kernel text symbol names.", "", " --no_crashrc", " Do not execute the commands in either $HOME/.crashrc or ./.crashrc.", "", " --mod directory", " When loading the debuginfo data of kernel modules with the \"mod -S\"", " command, search for their object files in directory instead of in ", " the standard location.", "", " --src directory", " Search for the kernel source code in directory instead of in the", " standard location that is compiled into the debuginfo data.", "", " --reloc size", " When analyzing live x86 kernels configured with a CONFIG_PHYSICAL_START ", " value that is larger than its CONFIG_PHYSICAL_ALIGN value, then it will", " be necessary to enter a relocation size equal to the difference between", " the two values.", "", " --hash count", " Set the number of internal hash queue heads used for list gathering", " and verification. The default count is 32768.", "", " --kaslr offset | auto", " If x86, x86_64, s390x or loongarch64 kernel was configured with", " CONFIG_RANDOMIZE_BASE, the offset value is equal to the difference", " between the symbol values compiled into the vmlinux file and their", " relocated KASLR value. If set to auto, the KASLR offset value will", " be automatically calculated.", "", " --max-malloc-bufs ", " Set the value of MAX_MALLOC_BUFS to size.", " The minimum allowed value is 3072.", "", " --minimal", " Bring up a session that is restricted to the log, dis, rd, sym,", " eval, set and exit commands. This option may provide a way to", " extract some minimal/quick information from a corrupted or truncated", " dumpfile, or in situations where one of the several kernel subsystem ", " initialization routines would abort the crash session.", "", " --kvmhost [32|64]", " When examining an x86 KVM guest dumpfile, this option specifies", " that the KVM host that created the dumpfile was an x86 (32-bit)", " or an x86_64 (64-bit) machine, overriding the automatically", " determined value.", "", " --kvmio ", " override the automatically-calculated KVM guest I/O hole size.", "", " --offline [show|hide]", " Show or hide command output that is associated with offline cpus,", " overriding any settings in either ./.crashrc or $HOME/.crashrc.", "", "FILES:", "", " .crashrc", " Initialization commands. The file can be located in the user's", " HOME directory and/or the current directory. Commands found in", " the .crashrc file in the HOME directory are executed before", " those in the current directory's .crashrc file.", "", "ENVIRONMENT VARIABLES:", "", " EDITOR ", " Command input is read using readline(3). If EDITOR is set to", " emacs or vi then suitable keybindings are used. If EDITOR is", " not set, then vi is used. This can be overridden by \"set vi\" or", " \"set emacs\" commands located in a .crashrc file, or by entering", " \"-e emacs\" on the crash command line.", "", " CRASHPAGER", " If CRASHPAGER is set, its value is used as the name of the program", " to which command output will be sent. If not, then command output", " output is sent to \"/usr/bin/less -E -X\" by default.", "", " CRASH_MODULE_PATH", " Specifies an alternative directory tree to search for kernel", " module object files.", "", " CRASH_EXTENSIONS", " Specifies a directory containing extension modules that will be", " loaded automatically if the -x command line option is used.", "", NULL }; void program_usage(int form) { if (form == SHORT_FORM) { fprintf(fp, "\nUsage:\n\n"); fprintf(fp, "%s\n%s\n", program_usage_info[3], program_usage_info[4]); fprintf(fp, "\nEnter \"%s -h\" for details.\n", pc->program_name); clean_exit(1); } else { FILE *scroll; char *scroll_command; char **p; if ((scroll_command = setup_scroll_command()) && (scroll = popen(scroll_command, "w"))) fp = scroll; else scroll = NULL; for (p = program_usage_info; *p; p++) { fprintf(fp, *p, pc->program_name); fprintf(fp, "\n"); } fflush(fp); if (scroll) pclose(scroll); clean_exit(0); } } /* * Get an updated count of commands for subsequent help menu display, * reshuffling the deck if this is the first time or if something's changed. */ void help_init(void) { struct command_table_entry *cp; struct extension_table *ext; for (pc->ncmds = 0, cp = pc->cmd_table; cp->name; cp++) { if (!(cp->flags & HIDDEN_COMMAND)) pc->ncmds++; } for (ext = extension_table; ext; ext = ext->next) { for (cp = ext->command_table; cp->name; cp++) { if (!(cp->flags & (CLEANUP|HIDDEN_COMMAND))) pc->ncmds++; } } if (!pc->cmdlist) { pc->cmdlistsz = pc->ncmds; if ((pc->cmdlist = (char **) malloc(sizeof(char *) * pc->cmdlistsz)) == NULL) error(FATAL, "cannot malloc command list space\n"); } else if (pc->ncmds > pc->cmdlistsz) { pc->cmdlistsz = pc->ncmds; if ((pc->cmdlist = (char **)realloc(pc->cmdlist, sizeof(char *) * pc->cmdlistsz)) == NULL) error(FATAL, "cannot realloc command list space\n"); } reshuffle_cmdlist(); } /* * If the command list is modified during runtime, re-shuffle the list * for proper help menu display. */ static void reshuffle_cmdlist(void) { int i, cnt; struct command_table_entry *cp; struct extension_table *ext; for (i = 0; i < pc->cmdlistsz; i++) pc->cmdlist[i] = NULL; for (cnt = 0, cp = pc->cmd_table; cp->name; cp++) { if (!(cp->flags & HIDDEN_COMMAND)) pc->cmdlist[cnt++] = cp->name; } for (ext = extension_table; ext; ext = ext->next) { for (cp = ext->command_table; cp->name; cp++) { if (!(cp->flags & (CLEANUP|HIDDEN_COMMAND))) pc->cmdlist[cnt++] = cp->name; } } if (cnt > pc->cmdlistsz) error(FATAL, "help table malfunction!\n"); qsort((void *)pc->cmdlist, (size_t)cnt, sizeof(char *), sort_command_name); } /* * The help list is in alphabetical order, with exception of the "q" command, * which has historically always been the last command in the list. */ static int sort_command_name(const void *name1, const void *name2) { char **s1, **s2; s1 = (char **)name1; s2 = (char **)name2; if (STREQ(*s1, "q")) return 1; return strcmp(*s1, *s2); } /* * Get help for a command, to dump an internal table, or the GNU public * license copying/warranty information. */ void cmd_help(void) { int c; int oflag; oflag = 0; while ((c = getopt(argcnt, args, "efNDdmM:ngcaBbHhkKsvVoptTzLOr")) != EOF) { switch(c) { case 'e': dump_extension_table(VERBOSE); return; case 'f': dump_filesys_table(VERBOSE); return; case 'n': case 'D': dumpfile_memory(DUMPFILE_MEM_DUMP); return; case 'd': dump_dev_table(); return; case 'M': dump_machdep_table(stol(optarg, FAULT_ON_ERROR, NULL)); return; case 'm': dump_machdep_table(0); return; case 'g': dump_gdb_data(); return; case 'N': dump_net_table(); return; case 'a': dump_alias_data(); return; case 'b': dump_shared_bufs(); return; case 'B': dump_build_data(); return; case 'c': dump_numargs_cache(); return; case 'H': dump_hash_table(VERBOSE); return; case 'h': dump_hash_table(!VERBOSE); return; case 'k': dump_kernel_table(!VERBOSE); return; case 'K': dump_kernel_table(VERBOSE); return; case 's': dump_symbol_table(); return; case 'V': dump_vm_table(VERBOSE); return; case 'v': dump_vm_table(!VERBOSE); return; case 'O': dump_offset_table(NULL, TRUE); return; case 'o': oflag = TRUE; break; case 'T': dump_task_table(VERBOSE); return; case 't': dump_task_table(!VERBOSE); return; case 'p': dump_program_context(); return; case 'z': fprintf(fp, "help options:\n"); fprintf(fp, " -a - alias data\n"); fprintf(fp, " -b - shared buffer data\n"); fprintf(fp, " -B - build data\n"); fprintf(fp, " -c - numargs cache\n"); fprintf(fp, " -d - device table\n"); fprintf(fp, " -D - dumpfile contents/statistics\n"); fprintf(fp, " -e - extension table data\n"); fprintf(fp, " -f - filesys table\n"); fprintf(fp, " -g - gdb data\n"); fprintf(fp, " -h - hash_table data\n"); fprintf(fp, " -H - hash_table data (verbose)\n"); fprintf(fp, " -k - kernel_table\n"); fprintf(fp, " -K - kernel_table (verbose)\n"); fprintf(fp, " -L - LKCD page cache environment\n"); fprintf(fp, " -M machine specific\n"); fprintf(fp, " -m - machdep_table\n"); fprintf(fp, " -N - net_table\n"); fprintf(fp, " -n - dumpfile contents/statistics\n"); fprintf(fp, " -o - offset_table and size_table\n"); fprintf(fp, " -p - program_context\n"); fprintf(fp, " -r - dump registers from dumpfile header\n"); fprintf(fp, " -s - symbol table data\n"); fprintf(fp, " -t - task_table\n"); fprintf(fp, " -T - task_table plus context_array\n"); fprintf(fp, " -v - vm_table\n"); fprintf(fp, " -V - vm_table (verbose)\n"); fprintf(fp, " -z - help options\n"); return; case 'L': dumpfile_memory(DUMPFILE_ENVIRONMENT); return; case 'r': dump_registers(); return; default: argerrs++; break; } } if (argerrs) cmd_usage(pc->curcmd, COMPLETE_HELP); if (!args[optind]) { if (oflag) dump_offset_table(NULL, FALSE); else display_help_screen(""); return; } do { if (oflag) dump_offset_table(args[optind], FALSE); else cmd_usage(args[optind], COMPLETE_HELP|MUST_HELP); optind++; } while (args[optind]); } static void dump_registers(void) { if (pc->flags2 & QEMU_MEM_DUMP_ELF) { dump_registers_for_qemu_mem_dump(); return; } else if (DISKDUMP_DUMPFILE()) { dump_registers_for_compressed_kdump(); return; } else if (NETDUMP_DUMPFILE() || KDUMP_DUMPFILE()) { dump_registers_for_elf_dumpfiles(); return; } else if (VMSS_DUMPFILE()) { dump_registers_for_vmss_dump(); return; } error(FATAL, "-r option not supported on %s\n", ACTIVE() ? "a live system" : "this dumpfile type"); } /* * Format and display the help menu. */ void display_help_screen(char *indent) { int i, j, rows; char **namep; help_init(); fprintf(fp, "\n%s", indent); rows = (pc->ncmds + (HELP_COLUMNS-1)) / HELP_COLUMNS; for (i = 0; i < rows; i++) { namep = &pc->cmdlist[i]; for (j = 0; j < HELP_COLUMNS; j++) { fprintf(fp,"%-15s", *namep); namep += rows; if ((namep - pc->cmdlist) >= pc->ncmds) break; } fprintf(fp,"\n%s", indent); } fprintf(fp, "\n%s%s version: %-6s gdb version: %s\n", indent, pc->program_name, pc->program_version, pc->gdb_version); fprintf(fp, "%sFor help on any command above, enter \"help \".\n", indent); fprintf(fp, "%sFor help on input options, enter \"help input\".\n", indent); fprintf(fp, "%sFor help on output options, enter \"help output\".\n", indent); #ifdef NO_LONGER_TRUE fprintf(fp, "%sFor the most recent version: " "http://www.missioncriticallinux.com/download\n\n", indent); #else fprintf(fp, "\n"); #endif } /* * Used for generating HTML pages, dump the commands in the order * they would be seen on the help menu, i.e., from left-to-right, row-by-row. * Line ends are signaled with a "BREAK" string. */ static void display_commands(void) { int i, j, rows; char **namep; help_init(); rows = (pc->ncmds + (HELP_COLUMNS-1)) / HELP_COLUMNS; for (i = 0; i < rows; i++) { namep = &pc->cmdlist[i]; for (j = 0; j < HELP_COLUMNS; j++) { fprintf(fp,"%s\n", *namep); namep += rows; if ((namep - pc->cmdlist) >= pc->ncmds) { fprintf(fp, "BREAK\n"); break; } } } } /* * Help data for a command must be formatted using the following template: "command-name", "command description line", "argument-usage line", "description...", "description...", "description...", NULL, * The first line is concatenated with the second line, and will follow the * help command's "NAME" header. * The first and third lines will also be concatenated, and will follow the * help command's "SYNOPSIS" header. If the command has no arguments, enter * a string consisting of a space, i.e., " ". * The fourth and subsequent lines will follow the help command's "DESCRIPTION" * header. * * The program name can be referenced by using the %%s format. The final * entry in each command's help data string list must be a NULL. */ char *help_foreach[] = { "foreach", "display command data for multiple tasks in the system", "[[pid | taskp | name | state | [kernel | user | gleader]] ...]\n" " command [flag] [argument]", " This command allows for an examination of various kernel data associated", " with any, or all, tasks in the system, without having to set the context", " to each targeted task.\n", " pid perform the command(s) on this PID.", " taskp perform the command(s) on task referenced by this hexadecimal", " task_struct pointer.", " name perform the command(s) on all tasks with this name. If the", " task name can be confused with a foreach command name, then", " precede the name string with a \"\\\". If the name string is", " enclosed within \"'\" characters, then the encompassed string", " must be a POSIX extended regular expression that will be used", " to match task names.", " user perform the command(s) on all user (non-kernel) threads.", " gleader perform the command(s) on all user (non-kernel) thread group leaders.", " kernel perform the command(s) on all kernel threads.", " active perform the command(s) on the active thread on each CPU.", " state perform the command(s) on all tasks in the specified state, which", " may be one of: RU, IN, UN, ST, ZO, TR, SW, DE, WA, PA, ID or NE.\n", " If none of the task-identifying arguments above are entered, the command", " will be performed on all tasks.\n", " command select one or more of the following commands to be run on the tasks", " selected, or on all tasks:\n", " bt run the \"bt\" command (optional flags: -r -t -l -e -R -f -F", " -o -s -x -d)", " vm run the \"vm\" command (optional flags: -p -v -m -R -d -x)", " task run the \"task\" command (optional flags: -R -d -x)", " files run the \"files\" command (optional flag: -c -R)", " net run the \"net\" command (optional flags: -s -S -R -d -x)", " set run the \"set\" command", " ps run the \"ps\" command (optional flags: -G -s -p -c -t -l -a", " -g -r -y)", " sig run the \"sig\" command (optional flag: -g)", " vtop run the \"vtop\" command (optional flags: -c -u -k)\n", " flag Pass this optional flag to the command selected.", " argument Pass this argument to the command selected.", " ", " A header containing the PID, task address, cpu and command name will be", " pre-pended before the command output for each selected task. Consult the", " help page of each of the command types above for details.", "\nEXAMPLES", " Display the stack traces for all tasks:\n", " %s> foreach bt", " PID: 4752 TASK: c7680000 CPU: 1 COMMAND: \"xterm\"", " #0 [c7681edc] schedule at c01135f6", " (void)", " #1 [c7681f34] schedule_timeout at c01131ff", " (24)", " #2 [c7681f64] do_select at c0132838", " (5, c7681fa4, c7681fa0)", " #3 [c7681fbc] sys_select at c0132dad", " (5, 8070300, 8070380, 0, 0)", " #4 [bffffb0c] system_call at c0109944", " EAX: 0000008e EBX: 00000005 ECX: 08070300 EDX: 08070380 ", " DS: 002b ESI: 00000000 ES: 002b EDI: 00000000 ", " SS: 002b ESP: bffffadc EBP: bffffb0c ", " CS: 0023 EIP: 402259ee ERR: 0000008e EFLAGS: 00000246 ", " ", " PID: 557 TASK: c5600000 CPU: 0 COMMAND: \"nfsd\"", " #0 [c5601f38] schedule at c01135f6", " (void)", " #1 [c5601f90] schedule_timeout at c01131ff", " (c5600000)", " #2 [c5601fb8] svc_recv at c805363a", " (c0096f40, c5602800, 7fffffff, 100, c65c9f1c)", " #3 [c5601fec] (nfsd module) at c806e303", " (c5602800, c5602800, c0096f40, 6c6e0002, 50)", " #4 [c65c9f24] kernel_thread at c010834f", " (0, 0, ext2_file_inode_operations)", " ", " PID: 824 TASK: c7c84000 CPU: 0 COMMAND: \"mingetty\"", " ...\n", " Display the task_struct structure for each \"bash\" command:\n", " %s> foreach bash task", " ...\n", " Display the open files for all tasks:\n", " %s> foreach files", " ...\n", " Display the state of tasks whose name contains a match to \"event.*\":\n", " %s> foreach 'event.*' task -R state", " PID: 99 TASK: ffff8804750d5500 CPU: 0 COMMAND: \"events/0\"", " state = 1,", " ", " PID: 100 TASK: ffff8804750d4ac0 CPU: 1 COMMAND: \"events/1\"", " state = 1,", " ", " PID: 101 TASK: ffff8804750d4080 CPU: 2 COMMAND: \"events/2\"", " state = 1,", " ...\n", " Display the stack traces for all blocked (TASK_UNINTERRUPTIBLE) tasks:\n", " %s> foreach UN bt", " PID: 428 TASK: ffff880036b6c560 CPU: 1 COMMAND: \"jbd2/dm-1-8\"", " #0 [ffff880035779a70] __schedule at ffffffff815df272", " #1 [ffff880035779b08] schedule at ffffffff815dfacf", " #2 [ffff880035779b18] io_schedule at ffffffff815dfb7f", " #3 [ffff880035779b38] sleep_on_page at ffffffff81119a4e", " #4 [ffff880035779b48] __wait_on_bit at ffffffff815e039f", " #5 [ffff880035779b98] wait_on_page_bit at ffffffff81119bb8", " #6 [ffff880035779be8] filemap_fdatawait_range at ffffffff81119ccc", " #7 [ffff880035779cd8] filemap_fdatawait at ffffffff81119d8b", " #8 [ffff880035779ce8] jbd2_journal_commit_transaction at ffffffff8123a99c", " #9 [ffff880035779e58] kjournald2 at ffffffff8123ee7b", " #10 [ffff880035779ee8] kthread at ffffffff8108fb9c", " #11 [ffff880035779f48] kernel_thread_helper at ffffffff815ebaf4", " ...\n", NULL }; char *help_ascii[] = { "ascii", "translate a hexadecimal string to ASCII", "value ...", " Translates 32-bit or 64-bit hexadecimal values to ASCII. If no argument", " is entered, an ASCII chart is displayed.", "\nEXAMPLES", " Translate the hexadecimal value of 0x62696c2f7273752f to ASCII:", "\n %s> ascii 62696c2f7273752f", " 62696c2f7273752f: /usr/lib", "\n Display an ASCII chart:", "\n %s> ascii", " ", " 0 1 2 3 4 5 6 7", " +-------------------------------", " 0 | NUL DLE SP 0 @ P ' p", " 1 | SOH DC1 ! 1 A Q a q", " 2 | STX DC2 \" 2 B R b r", " 3 | ETX DC3 # 3 C S c s", " 4 | EOT DC4 $ 4 D T d t", " 5 | ENQ NAK \% 5 E U e u", " 6 | ACK SYN & 6 F V f v", " 7 | BEL ETB ` 7 G W g w", " 8 | BS CAN ( 8 H X h x", " 9 | HT EM ) 9 I Y i y", " A | LF SUB * : J Z j z", " B | VT ESC + ; K [ k {", " C | FF FS , < L \\ l |", " D | CR GS _ = M ] m }", " E | SO RS . > N ^ n ~", " F | SI US / ? O - o DEL", NULL }; char *help_sbitmapq[] = { "sbitmapq", "sbitmap_queue struct contents", "[-s struct[.member[,member]] -a address [-p] [-v]] -[x|d] address", " The command dumps the contents of the sbitmap_queue structure and", " the used bits in the bitmap. Also, it shows the dump of a structure", " array associated with the sbitmap_queue.", "", " The arguments are as follows:", "", " -s struct name of a C-code structure, that is stored in an array", " associated with sbitmap_queue structure. Use the", " \"struct.member\" format in order to display a particular", " member of the structure. -s option requires -a option", " -a address address of a structure array associated with sbitmap_queue", " structure. The set bits in sbitmap are used for the index", " in an associated array.", " -p associated with sbitmap_queue array contains the points of", " structure.", " -x override default output format with hexadecimal format.", " -d override default output format with decimal format.", " -v By default, the sbitmap command shows only a used sbitmap", " index and a structure address in the associated array.", " This flag says to print a formatted display of the", " contents of a structure in an associated array. -v option", " requires of -s.", "", "EXAMPLES", "", " All examples are shown on the base of Linux Target system with iSCSI", " transport.", "", " Display the common sbitmap information for target session:", "", " %s> struct -oh se_session 0xc0000000e118c760 | grep sbitmap_queue", " [c0000000e118c808] struct sbitmap_queue sess_tag_pool;", " %s>", " %s> sbitmapq c0000000e118c808", " depth = 136", " busy = 4", " cleared = 26", " bits_per_word = 32", " map_nr = 5", " alloc_hint = {74, 36, 123, 101}", " wake_batch = 8", " wake_index = 0", " ws_active = 0", " ws = {", " { .wait_cnt = 8, .wait = inactive },", " { .wait_cnt = 8, .wait = inactive },", " { .wait_cnt = 8, .wait = inactive },", " { .wait_cnt = 8, .wait = inactive },", " { .wait_cnt = 8, .wait = inactive },", " { .wait_cnt = 8, .wait = inactive },", " { .wait_cnt = 8, .wait = inactive },", " { .wait_cnt = 8, .wait = inactive },", " }", " round_robin = 0", " min_shallow_depth = 4294967295", "", " 00000000: 0000 0000 0000 0000 0030 0000 0000 0000", " 00000010: 00", "", " Display the addresses of structure are associated with", " sbitmap_queue (for iscsi it is 'iscsi_cmd' structure):", "", " %s> struct se_session 0xc0000000e118c760 | grep sess_cmd_map", " sess_cmd_map = 0xc0000000671c0000,", " %s>", " %s> sbitmapq -s iscsi_cmd -a 0xc0000000671c0000 c0000000e118c808", " 76: 0xc0000000671d5600", " 77: 0xc0000000671d5a80", "", " Dump of formatted content of structures:", "", " %s> sbitmapq -s iscsi_cmd -a 0xc0000000671c0000 -v c0000000e118c808", " 76 (0xc0000000671d5600):", " struct iscsi_cmd {", " dataout_timer_flags = 0,", " dataout_timeout_retries = 0 '\\000',", " error_recovery_count = 0 '\\000',", " deferred_i_state = ISTATE_NO_STATE,", " i_state = ISTATE_SENT_STATUS,", " ...", " first_data_sg = 0xc0000000e306b080,", " first_data_sg_off = 0,", " kmapped_nents = 1,", " sense_reason = 0", " }", " 77 (0xc0000000671d5a80):", " struct iscsi_cmd {", " dataout_timer_flags = 0,", " dataout_timeout_retries = 0 '\\000',", " error_recovery_count = 0 '\\000',", " deferred_i_state = ISTATE_NO_STATE,", " i_state = ISTATE_NEW_CMD,", " ...", " first_data_sg = 0x0,", " first_data_sg_off = 0,", " kmapped_nents = 0,", " sense_reason = 0", " }", NULL }; char *help_quit[] = { "quit", "exit this session", " ", " Bail out of the current %s session.", "\nNOTE", " This command is equivalent to the \"exit\" command.", NULL }; char *help_exit[] = { "exit", "exit this session", " ", " Bail out of the current %s session.", "\nNOTE", " This command is equivalent to the \"q\" command.", NULL }; char *help_help[] = { "help", "get help", "[command | all] [-