Skip to content
  • Ian Jackson's avatar
    libxl: Do not pass NULL as gc_opt; introduce NOGC · 0a3ba01f
    Ian Jackson authored
    
    
    In 25182:6c3345d7e9d9 the practice of passing NULL to gc-using memory
    allocation functions was introduced.  However, the arrangements there
    were not correct as committed, because the error handling and logging
    depends on getting a ctx from the gc - so an allocation error would in
    fact result in libxl dereferencing NULL.
    
    Instead, provide a special dummy gc in the ctx, called `nogc_gc'.  It
    is marked out specially by having alloc_maxsize==-1, which is
    otherwise invalid.
    
    Functions which need to actually look into the gc use the new test
    function gc_is_real (whose purpose is mainly clarity of the code) to
    check whether the gc is the dummy one, and do nothing if it is.  And
    we provide a helper macro NOGC which uses the in-scope real gc to find
    the ctx and hence the dummy gc (and which replaces the previous
    #define NOGC NULL).
    
    Change all callers which pass 0 or NULL to an allocation function to
    use NOGC or &ctx->nogc_gc, as applicable in the context.
    
    We add a comment near the definition of LIBXL_INIT_GC pointing out
    that it isn't any more the only place a libxl__gc struct is
    initialised, for the benefit of anyone changing the contents of gc's
    in the future.
    
    Also, actually document that libxl__ptr_add is legal with ptr==NULL,
    and change a couple of calls not to check for NULL argument.
    
    Reported-by: default avatarBamvor Jian Zhang <bjzhang@suse.com>
    Signed-off-by: default avatarIan Jackson <ian.jackson@eu.citrix.com>
    Cc: Bamvor Jian Zhang <bjzhang@suse.com>
    Acked-by: default avatarIan Campbell <Ian.Campbell@citrix.com>
    Committed-by: default avatarIan Jackson <Ian.Jackson@eu.citrix.com>
    0a3ba01f