From: Andrew Cooper Subject: [PATCH v5] coverity: Store the modelling file in the source tree. Date: Thu, 23 Jan 2014 14:28:22 +0000 Message-ID: <1390487303-31765-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Keir Fraser , Ian Campbell , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Jan Beulich List-Id: xen-devel@lists.xenproject.org Signed-off-by: Andrew Cooper CC: Keir Fraser CC: Jan Beulich CC: Tim Deegan CC: Ian Campbell CC: Ian Jackson CC: George Dunlap --- George: This is just documentation, and it would be nice to include it as part of the 4.4 release. --- misc/coverity_model.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 misc/coverity_model.c diff --git a/misc/coverity_model.c b/misc/coverity_model.c new file mode 100644 index 0000000..418d25e --- /dev/null +++ b/misc/coverity_model.c @@ -0,0 +1,98 @@ +/* Coverity Scan model + * + * This is a modelling file for Coverity Scan. Modelling helps to avoid false + * positives. + * + * - A model file can't import any header files. + * - Therefore only some built-in primitives like int, char and void are + * available but not NULL etc. + * - Mode-ling doesn't need full structs and typedefs. Rudimentary structs + * and similar types are sufficient. + * - An uninitialized local pointer is not an error. It signifies that the + * variable could be either NULL or have some data. + * + * Coverity Scan doesn't pick up modifications automatically. The model file + * must be uploaded by an admin in the analysis. + * + * Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, + * 2011, 2012, 2013 Python Software Foundation; All Rights Reserved + * + * The Xen Coverity Scan modelling file used the cpython modelling file as a + * reference to get started (suggested by Coverty Scan themselves as a good + * example), but all content is Xen specific. + */ + +/* + * Useful references: + * https://scan.coverity.com/models + */ + +/* Definitions */ +#define NULL (void *)0 +#define PAGE_SIZE 4096UL +#define PAGE_MASK (~(PAGE_SIZE-1)) + +#define assert(cond) /* empty */ + +struct page_info {}; + +/* + * Xen malloc. Behaves exactly like regular malloc(), except it also contains + * an alignment parameter. + * + * TODO: work out how to correctly model bad alignments as errors. + */ +void *_xmalloc(unsigned long size, unsigned long align) +{ + int has_memory; + + __coverity_negative_sink__(size); + __coverity_negative_sink__(align); + + if ( has_memory ) + return __coverity_alloc__(size); + else + return NULL; +} + +/* + * Xen free. Frees a pointer allocated by _xmalloc(). + */ +void xfree(void *va) +{ + __coverity_free__(va); +} + + +/* + * map_domain_page() takes an existing domain page and possibly maps it into + * the Xen pagetables, to allow for direct access. Model this as a memory + * allocation of exactly 1 page. + * + * map_domain_page() never fails. (It will BUG() before returning NULL) + * + * TODO: work out how to correctly model the behaviour that this function will + * only ever return page aligned pointers. + */ +void *map_domain_page(unsigned long mfn) +{ + return __coverity_alloc__(PAGE_SIZE); +} + +/* + * unmap_domain_page() will unmap a page. Model it as a free(). + */ +void unmap_domain_page(const void *va) +{ + __coverity_free__(va); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ -- 1.7.10.4