Randomized implementation method, device and equipment for emulated bare-metal c program

CN122547436BActive Publication Date: 2026-09-29SIENGINE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611036850.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-07-13
Publication Date
2026-09-29
Estimated Expiration
2046-07-13

AI Technical Summary

Technical Problem

但这类方案一般缺乏完整的框架化设计,难以满足仿真环境中对随机性、可控性、可重复性和验证系统性的综合要求

Benefits of technology

[0015]第三方面,本申请实施例提供一种用于仿真的裸机C程序的随机化实现设备,所述用于仿真的裸机C程序的随机化实现设备包括处理器、存储器、以及存储在所述存储器上并可被所述处理器执行的用于仿真的裸机C程序的随机化实现程序,其中所述用于仿真的裸机C程序的随机化实现程序被所述处理器执行时,实现上述所述的用于仿真的裸机C程序的随机化实现方法的步骤。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122547436B_ABST
    Figure CN122547436B_ABST
Patent Text Reader

Abstract

The application discloses a randomization implementation method, device and equipment for emulating a bare machine C program, relates to the technical field of simulation, and comprises the following steps: acquiring a random seed and continuously generating random numbers in combination with random number generation constraint conditions, and generating a random address according to the random seed and a preset constraint condition; performing disorder processing on a to-be-disordered object set based on a shuffle algorithm, randomly rearranging functions in a function set in the to-be-disordered object set based on the shuffle algorithm and the random seed, and generating a random execution sequence; and sequentially calling the functions in the function set according to the random execution sequence, so as to realize the randomization of the function execution sequence. The application can effectively improve the randomization capability, verification completeness and problem reproduction capability of C program integrated verification, and simultaneously reduces the consumption of additional CPU resources and simulation time overhead.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of simulation technology, specifically to a method, apparatus, and device for randomizing bare-metal C programs for simulation. Background Technology

[0002] The randomization method used in existing baremetal C programs during simulation is usually based on functions such as rand (random number generation function) and srand (random number seed setting function) in the standard C library, combined with manually specifying the seed or generating the seed through time (used to obtain the current system time), and then using the generated random value as test data, conditional branches or parameter input.

[0003] In some scenarios, developers may manually implement simple randomization logic, such as randomly assigning values ​​to test data, simply perturbing certain configuration items, switching between different test paths by writing fixed rules, or manually orchestrating combinations of different functions. However, these solutions generally lack a complete framework design and are difficult to meet the comprehensive requirements of randomness, controllability, repeatability, and verification systematization in simulation environments.

[0004] Specifically, the following problems exist: (1) The random seed acquisition method is not suitable for the simulation environment. Standard random functions often rely on time or similar time sources to generate random seeds. However, in the bare metal simulation environment, the acquisition of time information often requires additional adaptation, and may even introduce additional CPU (central processing unit) execution steps and simulation time overhead, affecting simulation efficiency; (2) Random seeds are difficult to manage uniformly and lack controllability and repeatability. If the random seed is generated by the program itself or changes dynamically each time it runs, it is difficult to accurately replay the random scene at that time after an abnormal problem is discovered, which makes it difficult to locate and debug the problem; (3) The ability to control the range of random values ​​is limited. Standard random functions mainly generate basic random numbers, although they can be generated by simple modulo operation. The operation is limited in scope, but lacks a unified constrained random mechanism, making it difficult to meet the verification requirements such as address boundaries, memory alignment, and candidate set selection, and may even produce illegal or invalid test values; (4) It does not support systematic randomization at the address and pointer levels. Existing solutions mainly focus on random generation of ordinary integers or test parameters, lacking unified randomization support for addresses, buffers, and pointer objects, which is not conducive to improving the verification coverage of storage access paths and boundary access scenarios; (5) It does not support randomization of function execution order. Existing baremetal programs usually call test functions or function functions in a preset fixed order, and cannot disturb the function execution order. Therefore, it is difficult to find implicit dependencies between functions, initialization order dependencies, and problems that are only exposed under specific execution paths. Summary of the Invention

[0005] This application provides a method, apparatus, and device for randomizing bare-metal C programs for simulation, which can effectively improve the randomization capability, verification completeness, and problem reproducibility of C program integration verification, while reducing additional CPU resource consumption and simulation time overhead.

[0006] In a first aspect, embodiments of this application provide a method for randomizing a bare-metal C program for simulation, the method comprising: Obtain a random seed and continuously generate random numbers by combining random number generation constraints; generate random addresses based on the random seed and preset constraints. The shuffle algorithm is used to shuffle the set of objects to be shuffled, and the functions in the function set in the set of objects to be shuffled are randomly rearranged based on the shuffle algorithm and random seed to generate a random execution order. Based on the aforementioned random execution order, functions within the function set are called sequentially to achieve randomization of the function execution order.

[0007] In conjunction with the first aspect, in one implementation, the step of obtaining a random seed and generating random numbers in combination with random number generation constraints specifically includes: A random seed is generated based on a simulation tool, and a definite or random value is assigned to the random seed based on whether there is a controllable requirement for the random seed. The random seed is passed to the random function, and random numbers are continuously generated by combining the LCG pseudo-random algorithm and random number generation constraints. The random number generation constraints include minimum value, maximum value, step size, alignment requirements, and candidate value set.

[0008] In conjunction with the first aspect, in one implementation, the preset constraints include upper and lower limits of address, address alignment method, accessibility attributes, and read / write permission restrictions.

[0009] In conjunction with the first aspect, in one implementation, the set of objects to be out of order includes a set of test data, a set of addresses, a set of pointers, a set of functions, and a set of test tasks.

[0010] In conjunction with the first aspect, in one implementation, the random rearrangement of functions within the function set of the set of objects to be shuffled based on the shuffling algorithm and random seed to generate a random execution order specifically includes: The functions to be executed are registered to the function set of the set of objects to be out of order. The functions to be executed include test functions, functional functions, and task functions. The functions in the function set are randomly rearranged based on the shuffling algorithm and random seed to generate a random execution order.

[0011] In conjunction with the first aspect, in one implementation, the step of randomly rearranging the functions in the function set based on the shuffling algorithm and a random seed to generate a random execution order specifically includes: Define a function pointer type ParamFunctionPtr, which is used to point to a void* function with no parameters and no return value; Define a structure FunctionCall to pack function pointers and their corresponding parameters, forming an array of structures FunctionCall. Each structure FunctionCall corresponds to a function call to be executed, and each structure FunctionCall is used to record the function to be called and the parameters to be passed when calling the function. A random seed is initialized based on a static variable, and a replica array is created in memory, copying the FunctionCall structure array to the replica array. The shuffle_functions function is called to randomly rearrange the elements in the replica array, generating a random execution order.

[0012] In conjunction with the first aspect, in one implementation, the invocation of the shuffle_functions function to randomly rearrange the elements within the replica array specifically includes: Starting from the last element of the replica array, iterate backwards. When the current element is reached, select an element randomly from the replica array based on a random seed, and swap the positions of the current element and the randomly selected element. Continue in this manner until all elements in the replica array have been traversed, thus completing the random sorting of the elements in the replica array.

[0013] In conjunction with the first aspect, in one implementation, the step of sequentially calling functions within the function set according to the random execution order to achieve randomization of the function execution order specifically includes: Iterate through the randomly rearranged elements in the copy array and execute each element in the order of the random rearrangement to randomize the execution order of the function. After all elements in the copy array have been processed, release the copy array from memory.

[0014] Secondly, embodiments of this application provide a randomization implementation apparatus for a bare-metal C program used in simulation, the randomization implementation apparatus for the bare-metal C program used in simulation comprising: The generation module is used to obtain a random seed and continuously generate random numbers by combining random number generation constraints, and generate random addresses based on the random seed and preset constraints. The out-of-order processing module is used to process the out-of-order set of objects to be out-of-order based on the shuffle algorithm, and to randomly rearrange the functions in the function set of the out-of-order set of objects to be out-of-order based on the shuffle algorithm and the random seed to generate a random execution order. The execution module is used to sequentially call functions within the function set according to the random execution order, thereby randomizing the execution order of functions.

[0015] Thirdly, embodiments of this application provide a randomization implementation device for a bare-metal C program for simulation. The randomization implementation device for a bare-metal C program for simulation includes a processor, a memory, and a randomization implementation program for a bare-metal C program for simulation stored in the memory and executable by the processor. When the randomization implementation program for a bare-metal C program for simulation is executed by the processor, it implements the steps of the randomization implementation method for a bare-metal C program for simulation described above.

[0016] The beneficial effects of the technical solutions provided in this application include: (1) Simplify the random seed acquisition process: By generating and transmitting seeds in a unified manner, the baremetal program does not need to rely on time sources or additional logic to generate seeds, saving simulation resources and shortening simulation time; (2) It simultaneously possesses randomness, controllability, and repeatability: It supports automatic generation of random seeds, manual specification, and replay of failure scenarios, which is beneficial for regression testing and problem localization; (3) Reduce CPU execution overhead and simulation time overhead: Avoid relying on mechanisms such as time to obtain seeds, which is more suitable for simulation environments; (4) Supports constrained random number generation: It can generate valid random values ​​based on conditions such as range, boundary, and alignment, avoiding invalid tests; (5) Supports address and pointer randomization: This can improve the verification coverage of memory access and boundary access scenarios; (6) Supports randomization of function execution order: can significantly enhance the ability to disrupt processes and discover more defects related to the execution order of functions; (7) Form an integrated randomization framework for baremetal simulation: unify seed acquisition, random generation, constraint control, address / pointer randomization and function scrambling in one framework to improve the systematicity and completeness of verification. Attached Figure Description

[0017] Figure 1 This is a flowchart illustrating the randomization implementation method of the bare-metal C program used for simulation in this application; Figure 2 This is a schematic diagram of the functional modules of the randomization implementation device for the bare-metal C program used in this application for simulation; Figure 3 This is a schematic diagram of the hardware structure of the device used for the randomization of the bare-metal C program for simulation in this application. Detailed Implementation

[0018] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.

[0019] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0020] In a first aspect, embodiments of this application provide a method for randomizing bare-metal C programs for simulation, specifically a method for randomizing baremetal C programs suitable for CPU-based SoC or subsystem simulation. This method enables baremetal C programs to easily obtain controllable and repeatable random seeds in simulation environments without operating system support, and on this basis, implement random number range control, address and pointer randomization, and function execution order randomization. This improves the randomization capability, verification completeness, and problem reproducibility of C program integration verification, while reducing additional CPU resource consumption and simulation time overhead.

[0021] In one embodiment, reference is made to Figure 1 , Figure 1 This is a flowchart illustrating the randomization implementation method of the bare-metal C program used for simulation in this application. Figure 1 As shown, the randomization implementation methods for the bare-metal C program used in the simulation include: S1: Obtain a random seed and continuously generate random numbers by combining random number generation constraints, and generate random addresses based on the random seed and preset constraints; The preset constraints include upper and lower limits of address, address alignment, accessibility attributes, and read / write permission restrictions; where the address is a memory address or register address in the SoC. It should be noted that accessibility attributes refer to the characteristics of the storage area corresponding to the address in the hardware system, such as cache attributes (cacheable and non-cacheable, device type and security attributes); read and write permission restrictions refer to the legality rules for reading or writing operations on a certain address, such as read-only, write-only, and read and write. For example, when accessing a random address, the preset constraint can be set to: base_addr + offset, where offset is limited to 0x0-0xFF (address upper and lower limits), addr % 4 = 0 (address alignment), the accessibility attribute is non-cacheable, and the read and write permission restriction is read and write. S2: Based on the shuffling algorithm, the set of objects to be disordered is disordered, and based on the shuffling algorithm and random seed, the functions in the function set in the set of objects to be disordered are randomly rearranged to generate a random execution order; The set of objects to be shuffled includes a set of test data, a set of addresses, a set of pointers, a set of functions, and a set of test tasks; that is, the elements in the set of objects to be shuffled are shuffled using a shuffling algorithm. It should be noted that the test data set is a group of data blocks that need to be processed in random order. For example, the transaction payload set {8'h00, 8'hFF, 32'hDEADBEEF} might be sent in the order of 8'hFF - 32'hDEADBEEF - 8'h00 after being out of order. The address set is a group of memory or register addresses that need to be accessed in random order. For example, the DMA test address set {0x0000_0000, 0xFFFF_0000, 0x2000_0000, 0x4000_0000} might be accessed in the order of 0x4000_0000 - 0x0000_0000 - after being out of order. 0x2000_0000-0xFFFF_0000; The pointer set is a list of pointers to data, functions, or objects; The test task set is a group of test tasks that need to be called in a random order. For example, the cache consistency test task set {task_write_line(); task_read_line(); task_flush_line(); task_invalidate_line();} can be executed in the following out-of-order order: task_invalidate_line()-task_write_line()-task_read_line()-task_flush_line(); S3: According to the random execution order, the functions within the function set are called sequentially to randomize the execution order of the functions.

[0022] Furthermore, in one embodiment, obtaining a random seed and generating random numbers in conjunction with random number generation constraints specifically includes: S101: Generate a random seed based on a simulation tool, and assign a definite or random value to the random seed based on whether there is a controllable requirement for the random seed; S102: Pass the random seed to the random function, and continuously generate random numbers by combining the LCG pseudo-random algorithm and random number generation constraints; wherein, the random number generation constraints include minimum value, maximum value, step size, alignment requirements, and candidate value set.

[0023] Specifically, the random seed generation process begins by generating a random seed using a simulation tool. Then, it's determined whether the random seed needs to be controllable. If so, a definite value is assigned to the random seed when executing the simulation command; otherwise, a random value is assigned. After initializing the random interface, random numbers are continuously generated based on the read random seed. Constraints can be added during random number generation, including minimum value, maximum value, step size, alignment requirements, and candidate value set. It's important to note that the random number is calculated from the random seed using the formula X_(n+1) = (a*X_n + c), and this process is repeated continuously. The random number generated in the current round serves as the random seed for the next round of random number generation.

[0024] Furthermore, in one embodiment, functions within the function set of the set of objects to be shuffled are randomly rearranged based on a shuffling algorithm and a random seed to generate a random execution order, specifically including: S201: Register the functions to be executed to the function set of the set of objects to be reordered, wherein the functions to be executed include test functions, functional functions, and task functions; Among them, the test function is the top-level function that executes a complete test case and calls different task functions; the function function is the function that implements a specific function; and the task function is the step in completing a test and calls different function functions. S202: Based on the shuffling algorithm and random seed, the functions in the function set are randomly rearranged to generate a random execution order.

[0025] Specifically, test functions, functional functions, and task functions to be executed are registered in a function set. The specific form in which test functions, functional functions, and task functions exist in the function set can be a function pointer, a function index, or a function description structure. Then, before the functions are executed, a shuffling algorithm and a random seed are called to randomly rearrange the functions in the function set and generate a random execution order.

[0026] Furthermore, in one embodiment, the functions in the function set are randomly rearranged based on a shuffling algorithm and a random seed to generate a random execution order, specifically including: S2021: Define a function pointer type ParamFunctionPtr, which is used to point to a void* function with no parameters and no return value; Specifically, we define a function pointer type ParamFunctionPtr, which points to a void* function with no parameters and no return value. The void* is used here to achieve the universality of parameter types, so that pointers of any data type can be passed in. S2022: Define a structure FunctionCall to pack function pointers and corresponding parameters, forming an array of structures FunctionCall. Each structure FunctionCall corresponds to a function call to be executed, and each structure FunctionCall is used to record the function to be called and the parameters to be passed when calling the function. Specifically, define a structure FunctionCall. Each instance of the FunctionCall structure represents a "function call to be executed", which records which function to call (func field) and what parameters to pass when calling (param field). S2023: Initialize the random seed based on static variables (static variables are variables that are initialized only once during program execution, remain alive, and do not disappear), and at the same time create a copy array in memory, copying the FunctionCall structure array to the copy array; Specifically, a random seed is initialized using a static variable to ensure that the random number seed is initialized only once throughout the entire program, thus avoiding the generation of the same random sequence when called repeatedly. Then, memory is dynamically allocated, a copy array is created, and the FunctionCall structure array is copied to the copy array. This method avoids directly modifying the original data and keeps the original order unchanged. S2024: Call the shuffle_functions function (a function used to shuffle the order of the function pointer array) to randomly rearrange the elements in the copy array and generate a random execution order.

[0027] Furthermore, in one embodiment, the shuffle_functions function is called to randomly rearrange the elements within the replica array, specifically including: Starting from the last element of the replica array, iterate backwards. When the current element is encountered, select an element randomly from the replica array based on a random seed, and swap the positions of the current element and the randomly selected element. Continue this process until all elements in the replica array have been traversed. After the traversal is completed, the elements in the replica array will be in a completely random order, thus completing the random sorting of the elements in the replica array.

[0028] Furthermore, in one embodiment, functions within the function set are called sequentially according to the random execution order to randomize the execution order of function functions, specifically including: S301: Traverse the randomly rearranged elements in the copy array and execute each element in the order of the random rearrangement to randomize the execution order of the function. S302: After all elements in the replica array have been executed, release the replica array from memory.

[0029] This application obtains random seeds through a testbench (testing platform), simplifying the random seed acquisition process and achieving randomness, repeatability, and controllability of the random seed. It provides a unified constrained randomization interface in the baremetal environment, supporting control over the range, boundaries, alignment, step size, and candidate set of random values. Address and pointer randomization supports boundary, alignment, and legal access constraints. Based on testing requirements, it sets the range, boundaries, alignment, or candidate value set for random numbers, achieving constrained random generation. It supports a shuffling algorithm to shuffle object sets. It organizes functions to be executed into a function set and uses a shuffling algorithm to randomize the function execution order, thereby improving verification coverage and process perturbation capabilities.

[0030] Secondly, embodiments of this application also provide a randomization implementation apparatus for a bare-metal C program used in simulation.

[0031] In one embodiment, reference is made to Figure 2 , Figure 2 This is a schematic diagram of the functional modules of the randomization implementation device for the bare-metal C program used in this application for simulation. Figure 2 As shown, the randomization implementation device for the bare-metal C program used for simulation includes: a generation module, a scrambling module, and an execution module.

[0032] The generation module is used to obtain a random seed and continuously generate random numbers by combining random number generation constraints, and generate random addresses based on the random seed and preset constraints; the disorder processing module is used to disorder the set of objects to be disordered based on the shuffling algorithm, and randomly rearrange the functions in the function set in the set of objects to be disordered based on the shuffling algorithm and the random seed to generate a random execution order; the execution module is used to call the functions in the function set in sequence according to the random execution order, so as to realize the randomization of the function execution order.

[0033] Thirdly, embodiments of this application provide a randomization implementation device for a bare-metal C program used for simulation. The randomization implementation device for a bare-metal C program used for simulation can be a personal computer (PC), a laptop computer, a server, or other device with data processing capabilities.

[0034] Reference Figure 3 , Figure 3 This is a schematic diagram of the hardware structure of the randomization implementation device for bare-metal C programs used in the embodiments of this application. In the embodiments of this application, the randomization implementation device for bare-metal C programs used in the simulation may include a processor, a memory, a communication interface, and a communication bus.

[0035] The communication bus can be of any type and is used to interconnect the processor, memory, and communication interface.

[0036] Communication interfaces include input / output (I / O) interfaces, physical interfaces, and logical interfaces. These interfaces facilitate the randomization of bare-metal C programs used for simulation, enabling interconnection of internal devices within the device. They also facilitate the interconnection of the device with other devices (such as other computing devices or user equipment). Physical interfaces can be Ethernet interfaces, fiber optic interfaces, ATM interfaces, etc.; user equipment can be displays, keyboards, etc.

[0037] Memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.

[0038] The processor can be a general-purpose processor, which can call a randomized implementation program of a bare-metal C program for simulation stored in memory and execute the randomized implementation method of the bare-metal C program for simulation provided in the embodiments of this application. For example, the general-purpose processor can be a central processing unit (CPU). The method executed when the randomized implementation program of the bare-metal C program for simulation is called can refer to the various embodiments of the randomized implementation method of the bare-metal C program for simulation in this application, and will not be repeated here.

[0039] Those skilled in the art will understand that Figure 3 The hardware structure shown does not constitute a limitation of this application and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0040] The terms "comprising" and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus. The terms "first," "second," and "third," etc., are used to distinguish different objects, etc., and do not indicate a sequence, nor do they limit "first," "second," and "third" to different types.

[0041] In the description of the embodiments of this application, terms such as "exemplary," "for example," or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplary," "for example," or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary," "for example," or "for instance" is intended to present the relevant concepts in a concrete manner.

[0042] In the description of the embodiments of this application, unless otherwise stated, " / " means "or". For example, A / B can mean A or B. The "and / or" in the text is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of this application, "multiple" means two or more.

[0043] In some processes described in the embodiments of this application, multiple operations or steps are included in a specific order. However, it should be understood that these operations or steps may not be executed in the order they appear in the embodiments of this application, or they may be executed in parallel. The sequence number of the operation is only used to distinguish different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed sequentially or in parallel, and these operations or steps may be combined.

[0044] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of this application.

[0045] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A method for randomizing a bare-metal C program for simulation, characterized in that, The randomization implementation method of the bare-metal C program used for simulation includes: Obtain a random seed and continuously generate random numbers by combining random number generation constraints; generate random addresses based on the random seed and preset constraints. The shuffle algorithm is used to shuffle the set of objects to be shuffled, and the functions in the function set in the set of objects to be shuffled are randomly rearranged based on the shuffle algorithm and random seed to generate a random execution order. Based on the random execution order, functions within the function set are called sequentially to randomize the execution order of function functions. The set of objects to be disordered includes a set of test data, a set of addresses, a set of pointers, a set of functions, and a set of test tasks. Specifically, the step of randomly rearranging the functions within the function set of the set of objects to be shuffled based on the shuffling algorithm and random seed to generate a random execution order includes: The functions to be executed are registered to the function set of the set of objects to be out of order. The functions to be executed include test functions, functional functions, and task functions. The functions in the function set are randomly rearranged based on the shuffling algorithm and random seed to generate a random execution order; Specifically, the step of randomly rearranging the functions in the function set based on the shuffling algorithm and random seed to generate a random execution order includes: Define a function pointer type ParamFunctionPtr, which is used to point to a void* function with no parameters and no return value; Define a structure FunctionCall to pack function pointers and their corresponding parameters, forming an array of structures FunctionCall. Each structure FunctionCall corresponds to a function call to be executed, and each structure FunctionCall is used to record the function to be called and the parameters to be passed when calling the function. A random seed is initialized based on a static variable, and a replica array is created in memory, copying the FunctionCall structure array to the replica array. The shuffle_functions function is called to randomly rearrange the elements in the replica array, generating a random execution order.

2. The randomization implementation method of a bare-metal C program for simulation as described in claim 1, characterized in that, The process of obtaining a random seed and generating random numbers in conjunction with random number generation constraints specifically includes: A random seed is generated based on a simulation tool, and a definite or random value is assigned to the random seed based on whether there is a controllable requirement for the random seed. The random seed is passed to the random function, and random numbers are continuously generated by combining the LCG pseudo-random algorithm and random number generation constraints. The random number generation constraints include minimum value, maximum value, step size, alignment requirements, and candidate value set.

3. The randomization implementation method of a bare-metal C program for simulation as described in claim 1, characterized in that: The preset constraints include upper and lower limits of address, address alignment method, accessibility attributes, and read / write permission restrictions.

4. The randomization implementation method of a bare-metal C program for simulation as described in claim 1, characterized in that, The call to the shuffle_functions function to randomly rearrange the elements in the replica array specifically includes: Starting from the last element of the replica array, iterate backwards. When the current element is reached, select an element randomly from the replica array based on a random seed, and swap the positions of the current element and the randomly selected element. Continue in this manner until all elements in the replica array have been traversed, thus completing the random sorting of the elements in the replica array.

5. The randomization implementation method of a bare-metal C program for simulation as described in claim 1, characterized in that, The step of sequentially calling functions within the function set according to the random execution order to randomize the execution order of function functions specifically includes: Iterate through the randomly rearranged elements in the copy array and execute each element in the order of the random rearrangement to randomize the execution order of the function. After all elements in the copy array have been processed, release the copy array from memory.

6. A randomized implementation device for a bare-metal C program used in simulation, characterized in that, The randomization implementation device for the bare-metal C program used for simulation includes: The generation module is used to obtain a random seed and continuously generate random numbers by combining random number generation constraints, and generate random addresses based on the random seed and preset constraints. The out-of-order processing module is used to process the out-of-order set of objects to be out-of-order based on the shuffle algorithm, and to randomly rearrange the functions in the function set of the out-of-order set of objects to be out-of-order based on the shuffle algorithm and the random seed to generate a random execution order. An execution module is used to sequentially call functions within a function set according to the random execution order, thereby randomizing the execution order of function functions; The set of objects to be disordered includes a set of test data, a set of addresses, a set of pointers, a set of functions, and a set of test tasks. Specifically, the step of randomly rearranging the functions within the function set of the set of objects to be shuffled based on the shuffling algorithm and random seed to generate a random execution order includes: The functions to be executed are registered to the function set of the set of objects to be out of order. The functions to be executed include test functions, functional functions, and task functions. The functions in the function set are randomly rearranged based on the shuffling algorithm and random seed to generate a random execution order; Specifically, the step of randomly rearranging the functions in the function set based on the shuffling algorithm and random seed to generate a random execution order includes: Define a function pointer type ParamFunctionPtr, which is used to point to a void* function with no parameters and no return value; Define a structure FunctionCall to pack function pointers and their corresponding parameters, forming an array of structures FunctionCall. Each structure FunctionCall corresponds to a function call to be executed, and each structure FunctionCall is used to record the function to be called and the parameters to be passed when calling the function. A random seed is initialized based on a static variable, and a replica array is created in memory, copying the FunctionCall structure array to the replica array. The shuffle_functions function is called to randomly rearrange the elements in the replica array, generating a random execution order.

7. A randomized implementation device for bare-metal C programs used in simulation, characterized in that, The randomization implementation device for the bare-metal C program for simulation includes a processor, a memory, and a randomization implementation program for the bare-metal C program for simulation stored in the memory and executable by the processor, wherein when the randomization implementation program for the bare-metal C program for simulation is executed by the processor, it implements the steps of the randomization implementation method for the bare-metal C program for simulation as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • System and methods for post mortem debugging of transformed binaries

    US20220197778A1

  • Method and device for generating program having random layout

    WO2017016087A1