Resources-CudaManagedMemory¶
Representation of managed device memory as allocated by cudaMallocManaged
This rule describes a resource which can by dynamically allocated and released in the program being analyzed. Together with the corresponding configuration of the allocator/deallocator functions under the Externals rulegroup, this knowledge is used by the pointer/semantic analysis and several error checks. To add your own resource, proceed as follows:- Copy an existing resource rule and rename the copy appropriately.
For example, copy
Resources-CustomResource and
name the new rule
Resources-AdditionalResource. - Set the options of this new resource rule, especially the names
of allocator and deallocator functions. In our example, let us assume
that you have to call a function called
allocate_additional_resourcein order to create an instance of the resource, and that a call todeallocate_additional_resourceis needed to release it again. Then you would setResources-AdditionalResource/allocatorsto a set containing justallocate_additional_resource, and you would setResources-AdditionalResource/deallocatorsto the set consisting ofdeallocate_additional_resource. If the analysis includes the implementation of the (de)allocator functions, optionResources-AdditionalResource/allow_defined_functionsshould be set. - Create external function summaries for the allocator and deallocator
functions (copy or edit existing rules). These summaries provide details
about the specific function, e.g. whether they always return a fresh
allocation or also sometimes
nullptr, the semantics of their parameters, etc. With those summaries you can also distinguish different overloads, e.g. foroperator new. If there is no external function summary for the (de)allocators, a default behavior is assumed (freeing the first argument, returning a freshly allocated object). In our example we just addallocate_additional_resourceto option Externals-C++STL.NonNullAllocator/functions to signal that this function returns a freshly created instance, and that it cannot returnnullptr; for the deallocation we use the default behavior and thus do not have to modify any rule. - Add the new resource to the set of resources being checked at those
checks that should respect it. In our example we want to include
the additional resource in check
MisraC2023Directive-4.1
and thus add the resource name
AdditionalResourceto the already existing list of resources in option MisraC2023Directive-4.1/resources.
Possible Messages
This rule has no predefined messages.
Options¶
The following places define options that affect this rule: Analysis-GlobalOptions
allocators¶
allocators : set[bauhaus.analysis.config.QualifiedName] = {'cudaMallocManaged'}
allow_defined_functions¶
allow_defined_functions : bool = True
deallocators¶
deallocators : set[bauhaus.analysis.config.QualifiedName] = {'cudaFree'}
description¶
description : str = 'CUDA managed device memory'
requires_check¶
requires_check : bool = False
singleton¶
singleton : bool = False