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_resource in order to create an instance of the resource, and that a call to deallocate_additional_resource is needed to release it again. Then you would set Resources-AdditionalResource/allocators to a set containing just allocate_additional_resource, and you would set Resources-AdditionalResource/deallocators to the set consisting of deallocate_additional_resource. If the analysis includes the implementation of the (de)allocator functions, option Resources-AdditionalResource/allow_defined_functions should 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. for operator 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 add allocate_additional_resource to option Externals-C++STL.NonNullAllocator/functions to signal that this function returns a freshly created instance, and that it cannot return nullptr; 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 AdditionalResource to the already existing list of resources in option MisraC2023Directive-4.1/resources.
The name of the resource is the rule name (after the last hyphen, if any).

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'}

Set of quaified names of functions allocating/creating this resource. Typically there should then also be a function summary for these functions under the Externals rulegroup to specify more details about them.
 

allow_defined_functions

allow_defined_functions : bool = True

Whether (de)allocator functions implemented within the analyzed project should be supported. If not, only external functions being declared but not defined are supported.
 

deallocators

deallocators : set[bauhaus.analysis.config.QualifiedName] = {'cudaFree'}

Set of quaified names of functions deallocating/destroying this resource. Typically there should then also be a function summary for these functions under the Externals rulegroup to specify more details about them.
 

description

description : str = 'CUDA managed device memory'

Text to be used to describe such a resource when it appears in findings.
 

requires_check

requires_check : bool = False

Whether this resource should be detected and tracked unconditionally or only when there is at least one check naming it as a relevant resource.
 

singleton

singleton : bool = False

If true, deallocator does not take a resource argument (global static instance, as for getenv).