From patchwork Sun Sep 2 12:36:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoni Bettan X-Patchwork-Id: 10585171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B40F95A4 for ; Sun, 2 Sep 2018 13:50:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96EE029A28 for ; Sun, 2 Sep 2018 13:50:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8810429A2A; Sun, 2 Sep 2018 13:50:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,RDNS_NONE autolearn=ham version=3.3.1 Received: from lists.gnu.org (unknown [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D6E4D29A28 for ; Sun, 2 Sep 2018 13:50:25 +0000 (UTC) Received: from localhost ([::1]:40747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwSlQ-00066U-H9 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 02 Sep 2018 09:50:04 -0400 Received: from [208.118.235.92] (port=42999 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwSjp-0005F3-FV for qemu-devel@nongnu.org; Sun, 02 Sep 2018 09:49:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fwSU3-0005G8-DO for qemu-devel@nongnu.org; Sun, 02 Sep 2018 09:32:17 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43207 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fwSU2-0005EK-T6 for qemu-devel@nongnu.org; Sun, 02 Sep 2018 09:32:07 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE6BF4021704 for ; Sun, 2 Sep 2018 12:36:21 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 099312166BA1; Sun, 2 Sep 2018 12:36:20 +0000 (UTC) From: Yoni Bettan To: qemu-devel@nongnu.org Date: Sun, 2 Sep 2018 15:36:05 +0300 Message-Id: <20180902123608.124586-2-ybettan@redhat.com> In-Reply-To: <20180902123608.124586-1-ybettan@redhat.com> References: <20180902123608.124586-1-ybettan@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 02 Sep 2018 12:36:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 02 Sep 2018 12:36:21 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ybettan@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 1/4] README.md : Reformatted to fit the Markdown (.md) format. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yoni Bettan , ehabkost@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Yoni Bettan --- README => README.md | 87 +++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 43 deletions(-) rename README => README.md (68%) diff --git a/README b/README.md similarity index 68% rename from README rename to README.md index 49a9fd09cd..ac0e0528fb 100644 --- a/README +++ b/README.md @@ -1,5 +1,4 @@ - QEMU README - =========== +# Qemu QEMU is a generic and open source machine & userspace emulator and virtualizer. @@ -30,86 +29,90 @@ QEMU as a whole is released under the GNU General Public License, version 2. For full licensing details, consult the LICENSE file. -Building -======== +## Building QEMU is multi-platform software intended to be buildable on all modern Linux platforms, OS-X, Win32 (via the Mingw64 toolchain) and a variety of other UNIX targets. The simple steps to build QEMU are: - mkdir build - cd build - ../configure - make +``` +mkdir build +cd build +../configure +make +``` Additional information can also be found online via the QEMU website: - https://qemu.org/Hosts/Linux - https://qemu.org/Hosts/Mac - https://qemu.org/Hosts/W32 +* https://qemu.org/Hosts/Linux +* https://qemu.org/Hosts/Mac +* https://qemu.org/Hosts/W32 -Submitting patches -================== +## Submitting patches The QEMU source code is maintained under the GIT version control system. - git clone git://git.qemu.org/qemu.git +`git clone git://git.qemu.org/qemu.git` -When submitting patches, one common approach is to use 'git -format-patch' and/or 'git send-email' to format & send the mail to the -qemu-devel@nongnu.org mailing list. All patches submitted must contain -a 'Signed-off-by' line from the author. Patches should follow the -guidelines set out in the HACKING and CODING_STYLE files. +When submitting patches, one common approach is to use `git format-patch` +and/or `git send-email` to format & send the mail to the +[qemu-devel@nongnu.org](https://lists.nongnu.org/mailman/listinfo/qemu-devel) +mailing list. All patches submitted must contain a 'Signed-off-by' line from +the author. Patches should follow the guidelines set out in the +[HACKING.md](HACKING.md) and [CODING_STYLE.md](CODING_STYLE.md) files. Additional information on submitting patches can be found online via the QEMU website - https://qemu.org/Contribute/SubmitAPatch - https://qemu.org/Contribute/TrivialPatches +* https://qemu.org/Contribute/SubmitAPatch +* https://qemu.org/Contribute/TrivialPatches The QEMU website is also maintained under source control. - git clone git://git.qemu.org/qemu-web.git - https://www.qemu.org/2017/02/04/the-new-qemu-website-is-up/ +`git clone git://git.qemu.org/qemu-web.git` +* https://www.qemu.org/2017/02/04/the-new-qemu-website-is-up/ -A 'git-publish' utility was created to make above process less +A `git-publish` utility was created to make above process less cumbersome, and is highly recommended for making regular contributions, or even just for sending consecutive patch series revisions. It also -requires a working 'git send-email' setup, and by default doesn't +requires a working `git send-email` setup, and by default doesn't automate everything, so you may want to go through the above steps manually for once. For installation instructions, please go to - https://github.com/stefanha/git-publish +* https://github.com/stefanha/git-publish The workflow with 'git-publish' is: - $ git checkout master -b my-feature - $ # work on new commits, add your 'Signed-off-by' lines to each - $ git publish +``` +git checkout master -b my-feature +# work on new commits, add your 'Signed-off-by' lines to each +git publish +``` Your patch series will be sent and tagged as my-feature-v1 if you need to refer back to it in the future. Sending v2: - $ git checkout my-feature # same topic branch - $ # making changes to the commits (using 'git rebase', for example) - $ git publish +``` +git checkout my-feature # same topic branch +# making changes to the commits (using 'git rebase', for example) +git publish +``` Your patch series will be sent with 'v2' tag in the subject and the git tip will be tagged as my-feature-v2. -Bug reporting -============= +## Bug reporting The QEMU project uses Launchpad as its primary upstream bug tracker. Bugs found when running code built from QEMU git or upstream released sources should be reported via: - https://bugs.launchpad.net/qemu/ +* https://bugs.launchpad.net/qemu/ If using QEMU via an operating system vendor pre-built binary package, it is preferable to report bugs to the vendor's own bug tracker first. If @@ -118,22 +121,20 @@ reported via launchpad. For additional information on bug reporting consult: - https://qemu.org/Contribute/ReportABug +* https://qemu.org/Contribute/ReportABug -Contact -======= +## Contact The QEMU community can be contacted in a number of ways, with the two main methods being email and IRC - - qemu-devel@nongnu.org - https://lists.nongnu.org/mailman/listinfo/qemu-devel - - #qemu on irc.oftc.net +* [qemu-devel@nongnu.org](https://lists.nongnu.org/mailman/listinfo/qemu-devel) +* #qemu on irc.oftc.net Information on additional methods of contacting the community can be found online via the QEMU website: - https://qemu.org/Contribute/StartHere +* https://qemu.org/Contribute/StartHere --- End +## End From patchwork Sun Sep 2 12:36:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoni Bettan X-Patchwork-Id: 10585133 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D29114BD for ; Sun, 2 Sep 2018 12:41:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F031429B34 for ; Sun, 2 Sep 2018 12:41:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E423F29B39; Sun, 2 Sep 2018 12:41:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C258429B34 for ; Sun, 2 Sep 2018 12:41:08 +0000 (UTC) Received: from localhost ([::1]:40575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwRgd-000341-14 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 02 Sep 2018 08:41:03 -0400 Received: from [2001:4830:134:3::10] (port=53301 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwRfM-00020c-CB for qemu-devel@nongnu.org; Sun, 02 Sep 2018 08:39:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fwRf2-0006Tu-Fr for qemu-devel@nongnu.org; Sun, 02 Sep 2018 08:39:34 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41938 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fwRe1-0006CT-MI for qemu-devel@nongnu.org; Sun, 02 Sep 2018 08:39:24 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 540244021705 for ; Sun, 2 Sep 2018 12:36:23 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54C7F2166BA1; Sun, 2 Sep 2018 12:36:22 +0000 (UTC) From: Yoni Bettan To: qemu-devel@nongnu.org Date: Sun, 2 Sep 2018 15:36:06 +0300 Message-Id: <20180902123608.124586-3-ybettan@redhat.com> In-Reply-To: <20180902123608.124586-1-ybettan@redhat.com> References: <20180902123608.124586-1-ybettan@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 02 Sep 2018 12:36:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 02 Sep 2018 12:36:23 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ybettan@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 2/4] CODING_STYLE.md : Reformatted to fit the Markdown (.md) format. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yoni Bettan , ehabkost@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Yoni Bettan --- CODING_STYLE => CODING_STYLE.md | 151 +++++++++++++++++--------------- 1 file changed, 80 insertions(+), 71 deletions(-) rename CODING_STYLE => CODING_STYLE.md (50%) diff --git a/CODING_STYLE b/CODING_STYLE.md similarity index 50% rename from CODING_STYLE rename to CODING_STYLE.md index ec075dedc4..5b1523ba63 100644 --- a/CODING_STYLE +++ b/CODING_STYLE.md @@ -1,10 +1,9 @@ -QEMU Coding Style -================= +# QEMU Coding Style Please use the script checkpatch.pl in the scripts directory to check patches before submitting. -1. Whitespace +## Whitespace Of course, the most important aspect in any coding style is whitespace. Crusty old coders who have trouble spotting the glasses on their noses @@ -16,20 +15,20 @@ QEMU indents are four spaces. Tabs are never used, except in Makefiles where they have been irreversibly coded into the syntax. Spaces of course are superior to tabs because: - - You have just one way to specify whitespace, not two. Ambiguity breeds +* You have just one way to specify whitespace, not two. Ambiguity breeds mistakes. - - The confusion surrounding 'use tabs to indent, spaces to justify' is gone. - - Tab indents push your code to the right, making your screen seriously +* The confusion surrounding 'use tabs to indent, spaces to justify' is gone. +* Tab indents push your code to the right, making your screen seriously unbalanced. - - Tabs will be rendered incorrectly on editors who are misconfigured not +* Tabs will be rendered incorrectly on editors who are misconfigured not to use tab stops of eight positions. - - Tabs are rendered badly in patches, causing off-by-one errors in almost +* Tabs are rendered badly in patches, causing off-by-one errors in almost every line. - - It is the QEMU coding style. +* It is the QEMU coding style. Do not leave whitespace dangling off the ends of lines. -2. Line width +## Line width Lines should be 80 characters; try not to make them longer. @@ -38,28 +37,28 @@ that use long function or symbol names. Even in that case, do not make lines much longer than 80 characters. Rationale: - - Some people like to tile their 24" screens with a 6x4 matrix of 80x24 - xterms and use vi in all of them. The best way to punish them is to - let them keep doing it. - - Code and especially patches is much more readable if limited to a sane - line length. Eighty is traditional. - - The four-space indentation makes the most common excuse ("But look - at all that white space on the left!") moot. - - It is the QEMU coding style. +* Some people like to tile their 24" screens with a 6x4 matrix of 80x24 + xterms and use vi in all of them. The best way to punish them is to + let them keep doing it. +* Code and especially patches is much more readable if limited to a sane + line length. Eighty is traditional. +* The four-space indentation makes the most common excuse ("But look + at all that white space on the left!") moot. +* It is the QEMU coding style. -3. Naming +## Naming -Variables are lower_case_with_underscores; easy to type and read. Structured -type names are in CamelCase; harder to type but standing out. Enum type -names and function type names should also be in CamelCase. Scalar type -names are lower_case_with_underscores_ending_with_a_t, like the POSIX -uint64_t and family. Note that this last convention contradicts POSIX +Variables are `lower_case_with_underscores`; easy to type and read. Structured +type names are in `CamelCase`; harder to type but standing out. Enum type +names and function type names should also be in `CamelCase`. Scalar type +names are `lower_case_with_underscores_ending_with_a_t`, like the POSIX +`uint64_t` and family. Note that this last convention contradicts POSIX and is therefore likely to be changed. -When wrapping standard library functions, use the prefix qemu_ to alert +When wrapping standard library functions, use the prefix `qemu_` to alert readers that they are seeing a wrapped version; otherwise avoid this prefix. -4. Block structure +## Block structure Every indented statement is braced; even if the block contains just one statement. The opening brace is on the line that contains the control @@ -67,69 +66,79 @@ flow statement that introduces the new block; the closing brace is on the same line as the else keyword, or on a line by itself if there is no else keyword. Example: - if (a == 5) { - printf("a was 5.\n"); - } else if (a == 6) { - printf("a was 6.\n"); - } else { - printf("a was something else entirely.\n"); - } +``` +if (a == 5) { + printf("a was 5.\n"); +} else if (a == 6) { + printf("a was 6.\n"); +} else { + printf("a was something else entirely.\n"); +} +``` -Note that 'else if' is considered a single statement; otherwise a long if/ -else if/else if/.../else sequence would need an indent for every else +Note that `else if` is considered a single statement; otherwise a long `if/ +else` `if/else` `if/.../else` sequence would need an indent for every else statement. An exception is the opening brace for a function; for reasons of tradition and clarity it comes on a line by itself: - void a_function(void) - { - do_something(); - } +``` +void a_function(void) +{ + do_something(); +} +``` Rationale: a consistent (except for functions...) bracing style reduces ambiguity and avoids needless churn when lines are added or removed. Furthermore, it is the QEMU coding style. -5. Declarations +## Declarations Mixed declarations (interleaving statements and declarations within blocks) are generally not allowed; declarations should be at the beginning of blocks. Every now and then, an exception is made for declarations inside a -#ifdef or #ifndef block: if the code looks nicer, such declarations can +`#ifdef` or `#ifndef` block: if the code looks nicer, such declarations can be placed at the top of the block even if there are statements above. -On the other hand, however, it's often best to move that #ifdef/#ifndef +On the other hand, however, it's often best to move that `#ifdef/#ifndef` block to a separate function altogether. -6. Conditional statements +## Conditional statements When comparing a variable for (in)equality with a constant, list the constant on the right, as in: +``` if (a == 1) { /* Reads like: "If a equals 1" */ do_something(); } +``` -Rationale: Yoda conditions (as in 'if (1 == a)') are awkward to read. -Besides, good compilers already warn users when '==' is mis-typed as '=', +Rationale: Yoda conditions (as in `if (1 == a)`) are awkward to read. +Besides, good compilers already warn users when `==` is mis-typed as `=`, even when the constant is on the right. -7. Comment style +## Comment style -We use traditional C-style /* */ comments and avoid // comments. +We use traditional C-style `/* comment */` and avoid `// comment`. -Rationale: The // form is valid in C99, so this is purely a matter of +Rationale: The `// comment` form is valid in C99, so this is purely a matter of consistency of style. The checkpatch script will warn you about this. Multiline comment blocks should have a row of stars on the left, -and the initial /* and terminating */ both on their own lines: - /* - * like - * this - */ +and the initial `/*` and terminating `*/` both on their own lines: + +``` +/* + * like + * this + */ +``` + This is the same format required by the Linux kernel coding style. (Some of the existing comments in the codebase use the GNU Coding @@ -141,37 +150,37 @@ comment anyway.) Rationale: Consistency, and ease of visually picking out a multiline comment from the surrounding code. -8. trace-events style +## trace-events style -8.1 0x prefix +### 0x prefix -In trace-events files, use a '0x' prefix to specify hex numbers, as in: +In trace-events files, use a `0x` prefix to specify hex numbers, as in: -some_trace(unsigned x, uint64_t y) "x 0x%x y 0x" PRIx64 +`some_trace(unsigned x, uint64_t y) "x 0x%x y 0x" PRIx64` An exception is made for groups of numbers that are hexadecimal by -convention and separated by the symbols '.', '/', ':', or ' ' (such as +convention and separated by the symbols `.`, `/`, `:`, or ` ` (such as PCI bus id): -another_trace(int cssid, int ssid, int dev_num) "bus id: %x.%x.%04x" +`another_trace(int cssid, int ssid, int dev_num) "bus id: %x.%x.%04x"` -However, you can use '0x' for such groups if you want. Anyway, be sure that +However, you can use `0x` for such groups if you want. Anyway, be sure that it is obvious that numbers are in hex, ex.: -data_dump(uint8_t c1, uint8_t c2, uint8_t c3) "bytes (in hex): %02x %02x %02x" +`data_dump(uint8_t c1, uint8_t c2, uint8_t c3) "bytes (in hex): %02x %02x %02x"` -Rationale: hex numbers are hard to read in logs when there is no 0x prefix, +Rationale: hex numbers are hard to read in logs when there is no `0x` prefix, especially when (occasionally) the representation doesn't contain any letters and especially in one line with other decimal numbers. Number groups are allowed -to not use '0x' because for some things notations like %x.%x.%x are used not -only in Qemu. Also dumping raw data bytes with '0x' is less readable. +to not use `0x` because for some things notations like `%x.%x.%x` are used not +only in Qemu. Also dumping raw data bytes with `0x` is less readable. -8.2 '#' printf flag +### '#' printf flag -Do not use printf flag '#', like '%#x'. +Do not use printf flag `#'`, like `%#x`. -Rationale: there are two ways to add a '0x' prefix to printed number: '0x%...' -and '%#...'. For consistency the only one way should be used. Arguments for -'0x%' are: - - it is more popular - - '%#' omits the 0x for the value 0 which makes output inconsistent +Rationale: there are two ways to add a `0x` prefix to printed number: `0x%...` +and `%#...`. For consistency the only one way should be used. Arguments for +`0x%` are: +* it is more popular +* `%#` omits the `0x` for the value 0 which makes output inconsistent From patchwork Sun Sep 2 12:36:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoni Bettan X-Patchwork-Id: 10585177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3416713AC for ; Sun, 2 Sep 2018 14:47:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EA28297C0 for ; Sun, 2 Sep 2018 14:47:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1273A29814; Sun, 2 Sep 2018 14:47:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DD7BF297C0 for ; Sun, 2 Sep 2018 14:47:00 +0000 (UTC) Received: from localhost ([::1]:41135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwTeW-0005iX-AB for patchwork-qemu-devel@patchwork.kernel.org; Sun, 02 Sep 2018 10:47:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwTa4-0001X0-OA for qemu-devel@nongnu.org; Sun, 02 Sep 2018 10:42:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fwTZR-0007bG-C9 for qemu-devel@nongnu.org; Sun, 02 Sep 2018 10:42:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44512 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fwTZR-0007ak-04 for qemu-devel@nongnu.org; Sun, 02 Sep 2018 10:41:45 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C893C4021706 for ; Sun, 2 Sep 2018 12:36:24 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADC392166BA1; Sun, 2 Sep 2018 12:36:23 +0000 (UTC) From: Yoni Bettan To: qemu-devel@nongnu.org Date: Sun, 2 Sep 2018 15:36:07 +0300 Message-Id: <20180902123608.124586-4-ybettan@redhat.com> In-Reply-To: <20180902123608.124586-1-ybettan@redhat.com> References: <20180902123608.124586-1-ybettan@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 02 Sep 2018 12:36:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 02 Sep 2018 12:36:24 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ybettan@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 3/4] HACKING.md : Reformatted to fit the Markdown (.md) format. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yoni Bettan , ehabkost@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Yoni Bettan --- HACKING => HACKING.md | 186 ++++++++++++++++++++++-------------------- 1 file changed, 97 insertions(+), 89 deletions(-) rename HACKING => HACKING.md (53%) diff --git a/HACKING b/HACKING.md similarity index 53% rename from HACKING rename to HACKING.md index 0fc3e0fc04..f9d7631e64 100644 --- a/HACKING +++ b/HACKING.md @@ -1,86 +1,90 @@ -1. Preprocessor +## Preprocessor -1.1. Variadic macros +### Variadic macros For variadic macros, stick with this C99-like syntax: +``` #define DPRINTF(fmt, ...) \ do { printf("IRQ: " fmt, ## __VA_ARGS__); } while (0) +``` -1.2. Include directives +### Include directives Order include directives as follows: +``` #include "qemu/osdep.h" /* Always first... */ #include <...> /* then system headers... */ #include "..." /* and finally QEMU headers. */ +``` -The "qemu/osdep.h" header contains preprocessor macros that affect the behavior -of core system headers like . It must be the first include so that +The `qemu/osdep.h` header contains preprocessor macros that affect the behavior +of core system headers like ``. It must be the first include so that core system headers included by external libraries get the preprocessor macros that QEMU depends on. -Do not include "qemu/osdep.h" from header files since the .c file will have +Do not include `qemu/osdep.h` from header files since the .c file will have already included it. -2. C types +## C types It should be common sense to use the right type, but we have collected a few useful guidelines here. -2.1. Scalars +### Scalars -If you're using "int" or "long", odds are good that there's a better type. -If a variable is counting something, it should be declared with an -unsigned type. +If you're using `int` or `long`, odds are good that there's a better type. +If a variable is counting something, it should be declared with +`unsigned `. -If it's host memory-size related, size_t should be a good choice (use -ssize_t only if required). Guest RAM memory offsets must use ram_addr_t, +If it's host memory-size related, `size_t` should be a good choice (use +`ssize_t` only if required). Guest RAM memory offsets must use `ram_addr_t`, but only for RAM, it may not cover whole guest address space. -If it's file-size related, use off_t. -If it's file-offset related (i.e., signed), use off_t. -If it's just counting small numbers use "unsigned int"; +If it's file-size related, use `off_t`. +If it's file-offset related (i.e., signed), `use off_t`. +If it's just counting small numbers use `unsigned int`; (on all but oddball embedded systems, you can assume that that type is at least four bytes wide). In the event that you require a specific width, use a standard type -like int32_t, uint32_t, uint64_t, etc. The specific types are +like `int32_t`, `uint32_t`, `uint64_t`, etc. The specific types are mandatory for VMState fields. -Don't use Linux kernel internal types like u32, __u32 or __le32. +Don't use Linux kernel internal types like `u32`, `__u32` or `__le32`. -Use hwaddr for guest physical addresses except pcibus_t -for PCI addresses. In addition, ram_addr_t is a QEMU internal address +Use `hwaddr` for guest physical addresses except `pcibus_t` +for PCI addresses. In addition, `ram_addr_t` is a QEMU internal address space that maps guest RAM physical addresses into an intermediate address space that can map to host virtual address spaces. Generally -speaking, the size of guest memory can always fit into ram_addr_t but +speaking, the size of guest memory can always fit into `ram_addr_t` but it would not be correct to store an actual guest physical address in a -ram_addr_t. +`ram_addr_t`. For CPU virtual addresses there are several possible types. -vaddr is the best type to use to hold a CPU virtual address in +`vaddr` is the best type to use to hold a CPU virtual address in target-independent code. It is guaranteed to be large enough to hold a virtual address for any target, and it does not change size from target to target. It is always unsigned. -target_ulong is a type the size of a virtual address on the CPU; this means +`target_ulong` is a type the size of a virtual address on the CPU; this means it may be 32 or 64 bits depending on which target is being built. It should therefore be used only in target-specific code, and in some performance-critical built-per-target core code such as the TLB code. -There is also a signed version, target_long. -abi_ulong is for the *-user targets, and represents a type the size of -'void *' in that target's ABI. (This may not be the same as the size of a +There is also a signed version, `target_long`. +`abi_ulong` is for the `*-user` targets, and represents a type the size of +`void *` in that target's ABI. (This may not be the same as the size of a full CPU virtual address in the case of target ABIs which use 32 bit pointers -on 64 bit CPUs, like sparc32plus.) Definitions of structures that must match +on 64 bit CPUs, like `sparc32plus`.) Definitions of structures that must match the target's ABI must use this type for anything that on the target is defined -to be an 'unsigned long' or a pointer type. -There is also a signed version, abi_long. +to be an `unsigned long` or a pointer type. +There is also a signed version, `abi_long`. Of course, take all of the above with a grain of salt. If you're about -to use some system interface that requires a type like size_t, pid_t or -off_t, use matching types for any corresponding variables. +to use some system interface that requires a type like `size_t`, `pid_t` or +`off_t`, use matching types for any corresponding variables. -Also, if you try to use e.g., "unsigned int" as a type, and that +Also, if you try to use e.g., `unsigned int` as a type, and that conflicts with the signedness of a related variable, sometimes it's best just to use the *wrong* type, if "pulling the thread" and fixing all related variables would be too invasive. @@ -89,83 +93,86 @@ Finally, while using descriptive types is important, be careful not to go overboard. If whatever you're doing causes warnings, or requires casts, then reconsider or ask for help. -2.2. Pointers +### Pointers Ensure that all of your pointers are "const-correct". Unless a pointer is used to modify the pointed-to storage, -give it the "const" attribute. That way, the reader knows +give it the `const` attribute. That way, the reader knows up-front that this is a read-only pointer. Perhaps more importantly, if we're diligent about this, when you see a non-const pointer, you're guaranteed that it is used to modify the storage it points to, or it is aliased to another pointer that is. -2.3. Typedefs -Typedefs are used to eliminate the redundant 'struct' keyword. +### Typedefs +Typedefs are used to eliminate the redundant `struct` keyword. -2.4. Reserved namespaces in C and POSIX -Underscore capital, double underscore, and underscore 't' suffixes should be +### Reserved namespaces in C and POSIX +`_`, `__`, and underscore `*_t` suffixes should be avoided. -3. Low level memory management +## Low level memory management -Use of the malloc/free/realloc/calloc/valloc/memalign/posix_memalign +Use of the `malloc/free/realloc/calloc/valloc/memalign/posix_memalign` APIs is not allowed in the QEMU codebase. Instead of these routines, -use the GLib memory allocation routines g_malloc/g_malloc0/g_new/ -g_new0/g_realloc/g_free or QEMU's qemu_memalign/qemu_blockalign/qemu_vfree +use the GLib memory allocation routines `g_malloc/g_malloc0/g_new/ +g_new0/g_realloc/g_free or QEMU's qemu_memalign/qemu_blockalign/qemu_vfree` APIs. -Please note that g_malloc will exit on allocation failure, so there +Please note that `g_malloc` will exit on allocation failure, so there is no need to test for failure (as you would have to with malloc). -Calling g_malloc with a zero size is valid and will return NULL. +Calling `g_malloc` with a zero size is valid and will return `NULL`. -Prefer g_new(T, n) instead of g_malloc(sizeof(T) * n) for the following +Prefer `g_new(T, n)` instead of `g_malloc(sizeof(T) * n)` for the following reasons: - a. It catches multiplication overflowing size_t; - b. It returns T * instead of void *, letting compiler catch more type + a. It catches multiplication overflowing `size_t`; + b. It returns `T *` instead of `void *`, letting compiler catch more type errors. -Declarations like T *v = g_malloc(sizeof(*v)) are acceptable, though. +Declarations like `T *v = g_malloc(sizeof(*v))` are acceptable, though. -Memory allocated by qemu_memalign or qemu_blockalign must be freed with -qemu_vfree, since breaking this will cause problems on Win32. +Memory allocated by `qemu_memalign` or `qemu_blockalign` must be freed with +`qemu_vfree`, since breaking this will cause problems on Win32. -4. String manipulation +## String manipulation -Do not use the strncpy function. As mentioned in the man page, it does *not* +Do not use the `strncpy` function. As mentioned in the man page, it does *not* guarantee a NULL-terminated buffer, which makes it extremely dangerous to use. It also zeros trailing destination bytes out to the specified length. Instead, use this similar function when possible, but note its different signature: -void pstrcpy(char *dest, int dest_buf_size, const char *src) +`void pstrcpy(char *dest, int dest_buf_size, const char *src)` -Don't use strcat because it can't check for buffer overflows, but: -char *pstrcat(char *buf, int buf_size, const char *s) +Don't use `strcat` because it can't check for buffer overflows, but: +`char *pstrcat(char *buf, int buf_size, const char *s)` -The same limitation exists with sprintf and vsprintf, so use snprintf and -vsnprintf. +The same limitation exists with `sprintf` and `vsprintf`, so use `snprintf` and +`vsnprintf`. QEMU provides other useful string functions: + +``` int strstart(const char *str, const char *val, const char **ptr) int stristart(const char *str, const char *val, const char **ptr) int qemu_strnlen(const char *s, int max_len) +``` -There are also replacement character processing macros for isxyz and toxyz, -so instead of e.g. isalnum you should use qemu_isalnum. +There are also replacement character processing macros for `isxyz` and `toxyz`, +so instead of e.g. `isalnum` you should use `qemu_isalnum`. -Because of the memory management rules, you must use g_strdup/g_strndup -instead of plain strdup/strndup. +Because of the memory management rules, you must use `g_strdup/g_strndup` +instead of plain `strdup/strndup`. -5. Printf-style functions +## Printf-style functions Whenever you add a new printf-style function, i.e., one with a format -string argument and following "..." in its prototype, be sure to use +string argument and following `...` in its prototype, be sure to use gcc's printf attribute directive in the prototype. -This makes it so gcc's -Wformat and -Wformat-security options can do +This makes it so gcc's `-Wformat` and `-Wformat-security` options can do their jobs and cross-check format strings with the number and types of arguments. -6. C standard, implementation defined and undefined behaviors +## C standard, implementation defined and undefined behaviors C code in QEMU should be written to the C99 language specification. A copy of the final version of the C99 standard with corrigenda TC1, TC2, and TC3 @@ -181,37 +188,38 @@ argument...) However there are a few areas where we allow ourselves to assume certain behaviors because in practice all the platforms we care about behave in the same way and writing strictly conformant code would be painful. These are: - * you may assume that integers are 2s complement representation - * you may assume that right shift of a signed integer duplicates - the sign bit (ie it is an arithmetic shift, not a logical shift) + +* you may assume that integers are 2s complement representation +* you may assume that right shift of a signed integer duplicates + the sign bit (ie it is an arithmetic shift, not a logical shift) In addition, QEMU assumes that the compiler does not use the latitude -given in C99 and C11 to treat aspects of signed '<<' as undefined, as +given in C99 and C11 to treat aspects of signed `<<` as undefined, as documented in the GNU Compiler Collection manual starting at version 4.0. -7. Error handling and reporting +## Error handling and reporting -7.1 Reporting errors to the human user +### Reporting errors to the human user -Do not use printf(), fprintf() or monitor_printf(). Instead, use -error_report() or error_vreport() from error-report.h. This ensures the +Do not use `printf()`, `fprintf()` or `monitor_printf()`. Instead, use +`error_report()` or `error_vreport()` from `error-report.h`. This ensures the error is reported in the right place (current monitor or stderr), and in a uniform format. -Use error_printf() & friends to print additional information. +Use `error_printf()` & friends to print additional information. -error_report() prints the current location. In certain common cases +`error_report()` prints the current location. In certain common cases like command line parsing, the current location is tracked -automatically. To manipulate it manually, use the loc_*() from -error-report.h. +automatically. To manipulate it manually, use the `loc_*()` from +`error-report.h`. -7.2 Propagating errors +### Propagating errors An error can't always be reported to the user right where it's detected, but often needs to be propagated up the call chain to a place that can handle it. This can be done in various ways. -The most flexible one is Error objects. See error.h for usage +The most flexible one is Error objects. See `error.h` for usage information. Use the simplest suitable method to communicate success / failure to @@ -220,26 +228,26 @@ error, non-negative / -errno, non-null / null, or Error objects. Example: when a function returns a non-null pointer on success, and it can fail only in one way (as far as the caller is concerned), returning -null on failure is just fine, and certainly simpler and a lot easier on -the eyes than propagating an Error object through an Error ** parameter. +`NULL` on failure is just fine, and certainly simpler and a lot easier on +the eyes than propagating an Error object through an `Error ** parameter`. Example: when a function's callers need to report details on failure -only the function really knows, use Error **, and set suitable errors. +only the function really knows, use `Error **`, and set suitable errors. Do not report an error to the user when you're also returning an error for somebody else to handle. Leave the reporting to the place that consumes the error returned. -7.3 Handling errors +### Handling errors -Calling exit() is fine when handling configuration errors during +Calling `exit()` is fine when handling configuration errors during startup. It's problematic during normal operation. In particular, -monitor commands should never exit(). +monitor commands should never `exit()`. -Do not call exit() or abort() to handle an error that can be triggered +Do not call `exit()` or `abort()` to handle an error that can be triggered by the guest (e.g., some unimplemented corner case in guest code translation or device emulation). Guests should not be able to terminate QEMU. -Note that &error_fatal is just another way to exit(1), and &error_abort -is just another way to abort(). +Note that `&error_fatal` is just another way to `exit(1)`, and `&error_abort` +is just another way to `abort()`. From patchwork Sun Sep 2 12:36:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoni Bettan X-Patchwork-Id: 10585131 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E65F14E0 for ; Sun, 2 Sep 2018 12:40:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41DE529B34 for ; Sun, 2 Sep 2018 12:40:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33C2A29B39; Sun, 2 Sep 2018 12:40:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,RDNS_NONE autolearn=ham version=3.3.1 Received: from lists.gnu.org (unknown [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0BD1829B34 for ; Sun, 2 Sep 2018 12:40:04 +0000 (UTC) Received: from localhost ([::1]:40567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwRfL-00022Q-OF for patchwork-qemu-devel@patchwork.kernel.org; Sun, 02 Sep 2018 08:39:43 -0400 Received: from [2001:4830:134:3::10] (port=53255 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwReW-0001gN-CP for qemu-devel@nongnu.org; Sun, 02 Sep 2018 08:39:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fwReI-0006PS-Q5 for qemu-devel@nongnu.org; Sun, 02 Sep 2018 08:38:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41948 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fwRe9-0006CG-Ul for qemu-devel@nongnu.org; Sun, 02 Sep 2018 08:38:38 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F6E5402170B for ; Sun, 2 Sep 2018 12:36:26 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 318952166BA1; Sun, 2 Sep 2018 12:36:25 +0000 (UTC) From: Yoni Bettan To: qemu-devel@nongnu.org Date: Sun, 2 Sep 2018 15:36:08 +0300 Message-Id: <20180902123608.124586-5-ybettan@redhat.com> In-Reply-To: <20180902123608.124586-1-ybettan@redhat.com> References: <20180902123608.124586-1-ybettan@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 02 Sep 2018 12:36:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 02 Sep 2018 12:36:26 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ybettan@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 4/4] LICENSE.md : Reformatted to fit the Markdown (.md) format. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yoni Bettan , ehabkost@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Yoni Bettan --- LICENSE => LICENSE.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename LICENSE => LICENSE.md (90%) diff --git a/LICENSE b/LICENSE.md similarity index 90% rename from LICENSE rename to LICENSE.md index 0e0b4b9553..644e953429 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,3 +1,5 @@ +# License + The following points clarify the QEMU license: 1) QEMU as a whole is released under the GNU General Public License, @@ -11,7 +13,7 @@ option) any later version. As of July 2013, contributions under version 2 of the GNU General Public License (and no later version) are only accepted for the following files -or directories: bsd-user/, linux-user/, hw/vfio/, hw/xen/xen_pt*. +or directories: `bsd-user/`, `linux-user/`, `hw/vfio/`, `hw/xen/xen_pt*`. 3) The Tiny Code Generator (TCG) is released under the BSD license (see license headers in files).