Memory delay dynamic allocation method and system, equipment and storage medium
By adopting a delayed dynamic allocation method in memory allocation and pre-setting and allocating the memory pool, the problem of insufficient flexibility is solved, and efficient memory utilization and waste reduction is achieved.
Patent Information
- Application Number
- CN202311578649.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-23
- Publication Date
- 2025-05-23
AI Technical Summary
The prior art lacks flexibility in memory allocation and cannot effectively allocate multiple small memory blocks, resulting in low memory utilization and waste.
The memory delay dynamic allocation method is adopted to pre-set the secure memory pool and pre-allocate the memory to form multiple data blocks. Use the file descriptor to determine whether the data to be decrypted can be accommodated by the data block. If it is contained, it will be decrypted directly. If it is not contained, it will be reapplied for the data block.
It maximizes memory utilization, reduces the probability of memory waste, and improves memory usage efficiency.
Smart Images

Figure CN120029928A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of memory allocation, and in particular to a memory delayed dynamic allocation method and system, device and storage medium. Background Art
[0002] With the rapid development of information technology, DRM (digital rights management) has been widely used. The current mainstream DRMs include Google's Widevine, Microsoft's Playready, China's ChinaDRM and other DRM manufacturers. The implementation of each DRM system needs to ensure the safe storage and use of decrypted plaintext data, so realizing a pool for secure storage of plaintext is one of the important links.
[0003] Different chip manufacturers have different security pool implementations. Due to the limitations of different chip designs, different chips may have different implementations. For example, some chips are limited in the number of continuous physical memory that can be used to protect a section, and cannot flexibly provide multiple small memory blocks for direct use. Some products do not have enough physical memory available, so it is necessary to introduce a memory pool that can allocate multiple small memory blocks and support dynamic allocation to minimize memory usage. Summary of the invention
[0004] The problem solved by the embodiments of the present invention is to provide a memory delay dynamic allocation method and system, device and storage medium, which are conducive to further improving the use of memory.
[0005] To solve the above problems, an embodiment of the present invention provides a method for dynamic allocation of memory delay, comprising: pre-setting a secure memory pool; pre-allocating memory for the secure memory pool to form multiple data blocks; obtaining data to be decrypted, and obtaining a file descriptor corresponding to the data to be decrypted; judging, based on the file descriptor, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, if the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, directly decrypting the data to be decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, re-applying for a data block of the size required to store the data to be decrypted from the secure memory pool.
[0006] Optionally, in the step of pre-allocating memory for the secure memory pool, memory for the secure memory pool is pre-allocated according to upper-layer application requirements, and the upper-layer application requirements include those for playing videos.
[0007] Optionally, the step of pre-allocating memory for the secure memory pool includes: setting a dma-buf data structure and a dma-buf private data structure corresponding to the data block, the dma-buf data structure is used to record the size of the data block, and the dma-buf private data structure is used to record the allocation status and other private information.
[0008] Optionally, the step of determining, based on the file descriptor, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block includes: obtaining, based on the file descriptor, a corresponding dma-buf private data structure; and determining, based on information recorded in the dma-buf private data structure, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block.
[0009] Optionally, if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of a size required to store the data to be decrypted is requested from the secure memory pool through a direct file mapping method.
[0010] Optionally, if the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the step of directly decrypting the data to be decrypted to form decrypted data further includes: recording the memory address and size of the decrypted data through the file descriptor.
[0011] Optionally, after determining, based on the file descriptor, whether the to-be-decrypted data corresponding to the file descriptor can be accommodated by the data block, the memory delay dynamic allocation method further comprises: decoding the decrypted data by a decoder to form decoded data.
[0012] Optionally, the step of decoding the decrypted data through a decoder includes: passing the file descriptor to the decoder; the decoder obtains the memory address and size of the decrypted data through the file descriptor; and obtains the corresponding decrypted data from the memory address and decodes it.
[0013] Optionally, after the decrypted data is decoded by a decoder to form decoded data, the memory delay dynamic allocation method further includes: releasing the memory of the data block to return the secure memory pool to a preset state.
[0014] Optionally, the memory of the data block is released by using the close system call of the file descriptor.
[0015] Accordingly, an embodiment of the present invention provides a memory delayed dynamic allocation system, comprising: a pre-setting module, used to pre-set a secure memory pool; a memory pre-allocation module, used to perform memory pre-allocation on the secure memory pool to form multiple data blocks; an acquisition module, used to acquire data to be decrypted and acquire a file descriptor corresponding to the data to be decrypted; a dynamic allocation module, used to determine, based on the file descriptor, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block; if the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, directly decrypting the data to be decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, re-applying for a data block of the size required to store the data to be decrypted from the secure memory pool.
[0016] Optionally, the memory delay dynamic allocation system further includes: a decoding module, used to decode the decrypted data to form decoded data.
[0017] Optionally, the decoding module includes: a transmission unit, used to transmit the file descriptor to the decoding module; an acquisition unit, used to obtain the memory address and size of the decrypted data through the file descriptor; and a decoding unit, used to obtain the corresponding decrypted data from the memory address and decode it.
[0018] Optionally, the memory delayed dynamic allocation system further includes: a release module, configured to perform memory release on the data block to return the secure memory pool to a preset state.
[0019] Correspondingly, an embodiment of the present invention also provides a device, comprising at least one memory and at least one processor, wherein the memory stores one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the memory delay dynamic allocation method provided in an embodiment of the present invention.
[0020] Correspondingly, an embodiment of the present invention further provides a storage medium, wherein the storage medium stores one or more computer instructions, and the one or more computer instructions are used to implement the memory delay dynamic allocation method provided by the embodiment of the present invention.
[0021] Compared with the prior art, the technical solution of the embodiment of the present invention has the following advantages:
[0022] The embodiment of the present invention provides a method for dynamic memory delayed allocation, which pre-allocates memory for a secure memory pool to form multiple data blocks, obtains data to be decrypted, and obtains a file descriptor corresponding to the data to be decrypted, and judges whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block according to the file descriptor. If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of a memory size required to store the data to be decrypted is applied for again from the secure memory pool. That is to say, the present invention The embodiment adopts a delayed dynamic allocation mechanism, which allocates data blocks from a secure memory pool and uses file descriptors to transfer data block information allocated for the data to be decrypted. When decrypting the data to be decrypted, the data block information allocated to the data to be decrypted is obtained through the file descriptor. If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data. If the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is applied for again from the secure memory pool, thereby maximizing memory utilization and reducing the probability of memory waste. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 is a flow chart of an embodiment of a method for dynamic allocation of memory delays of the present invention;
[0024] Figures 2 to 3 is a functional block diagram of an embodiment of a memory delay dynamic allocation system of the present invention;
[0025] Figure 4 This is an optional hardware structure diagram of the terminal device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0026] It is known from the prior art that when the available physical memory is insufficient, a product needs to introduce a memory pool to allocate multiple data blocks. In the process of allocating a data block, since the data block is allocated according to the situation with the greatest demand, there is a waste of memory.
[0027] In order to solve the technical problem, an embodiment of the present invention provides a method for dynamically allocating memory delays. Figure 1 , showing a flow chart of an embodiment of a method for dynamic allocation of memory delays of the present invention.
[0028] Step S1: pre-set the secure memory pool;
[0029] Step S2: pre-allocating memory in the secure memory pool to form multiple data blocks;
[0030] Step S3: Obtain the data to be decrypted, and obtain the file descriptor corresponding to the data to be decrypted;
[0031] Step S4: According to the file descriptor, determine whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block. If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, directly decrypt the data to be decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, re-apply for a data block of the size required to store the data to be decrypted from the secure memory pool.
[0032] The embodiment of the present invention provides a method for dynamic memory delayed allocation, which pre-allocates memory for a secure memory pool to form multiple data blocks, obtains data to be decrypted, and obtains a file descriptor corresponding to the data to be decrypted, and judges whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block according to the file descriptor. If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of a memory size required to store the data to be decrypted is applied for again from the secure memory pool. That is to say, the present invention The embodiment adopts a delayed dynamic allocation mechanism, which allocates data blocks from a secure memory pool and uses file descriptors to transfer data block information allocated for the data to be decrypted. When decrypting the data to be decrypted, the data block information allocated to the data to be decrypted is obtained through the file descriptor. If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data. If the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is applied for again from the secure memory pool, thereby maximizing memory utilization and reducing the probability of memory waste.
[0033] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0034] Figure 1 It is a flowchart corresponding to an embodiment of a memory delay dynamic allocation method of the present invention.
[0035] refer to Figure 1 , execute step S1 to pre-set a secure memory pool.
[0036] Specifically, by setting up a secure memory pool, it is convenient to manage a continuous secure physical memory. At the same time, after the secure memory pool is subsequently pre-allocated with memory to form multiple data blocks, it is determined whether the data to be decrypted corresponding to the subsequently obtained file descriptor can be accommodated by the data block. If the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is applied for again from the secure memory pool.
[0037] In this embodiment, the size of the secure memory pool is preset to 16M.
[0038] Specifically, in the multimedia framework design, the size of the largest frame of video identified in a UHD video stream is 6M, and the size of most video data frames is far less than 6M. Accordingly, a delayed dynamic allocation mechanism is adopted in the subsequent process to ensure that at least two data blocks (12M) can be allocated for rotation. With the remaining 4M data, the total 16M security memory pool can basically meet the rotation requirements, thereby saving the memory size of the security memory pool.
[0039] In other embodiments, the pre-set size of the secure memory pool may also be 22M or 28M, etc.
[0040] refer to Figure 1 , execute step S2 to pre-allocate memory for the secure memory pool to form multiple data blocks.
[0041] Specifically, by pre-allocating memory in the secure memory pool, a plurality of data blocks are formed for the flow of the buffer. In the subsequent process of determining whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, if the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is re-applied from the secure memory pool.
[0042] In this embodiment, in the step of pre-allocating memory for the secure memory pool, memory is pre-allocated for the secure memory pool according to upper-layer application requirements, and the upper-layer application requirements include being used for playing videos.
[0043] In this embodiment, memory pre-allocation is performed on the secure memory pool through a pre-allocation mechanism. Specifically, the pre-allocation mechanism is limited by the size of the secure memory pool.
[0044] In this embodiment, the step of pre-allocating memory for the secure memory pool includes: setting a dma-buf data structure and a dma-buf private data structure corresponding to the data block, the dma-buf data structure is used to record the size of the data block, and the dma-buf private data structure is used to record the allocation status and other private information.
[0045] Specifically, a dma-buf data structure can represent a data block allocated from the secure memory pool and record the size of the data block. A dma-buf private data structure can export a file descriptor (Filedescriptor, Fd). The exported file descriptor is used for information transmission at the application layer and records the allocation status and other private information.
[0046] refer to Figure 1 , execute step S3, obtain the data to be decrypted, and obtain the file descriptor corresponding to the data to be decrypted.
[0047] Specifically, the data to be decrypted is obtained, and the file descriptor corresponding to the data to be decrypted is obtained, so as to facilitate the subsequent judgment on whether the data to be decrypted can be accommodated by the data block. If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is applied for again from the secure memory pool.
[0048] In this embodiment, the step of obtaining the data to be decrypted includes: using the shared memory storing the encrypted data as the data to be decrypted.
[0049] As an example, the data to be decrypted is obtained through DRM.
[0050] It should be noted that when obtaining the data to be decrypted, the kernel returns a file descriptor (returned by the open system call). Therefore, in the process of obtaining the data to be decrypted, the file descriptor corresponding to the data to be decrypted can be obtained.
[0051] refer to Figure 1 , execute step S4, and determine whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block according to the file descriptor. If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, directly decrypt the data to be decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, directly apply for a data block of the memory size required to store the data to be decrypted from the secure memory pool.
[0052] Specifically, the present embodiment adopts a delayed dynamic allocation mechanism, which allocates data blocks from a secure memory pool and uses a file descriptor to transfer the data block information allocated for the data to be decrypted. When the data to be decrypted is to be decrypted, the data block information allocated to the data to be decrypted is obtained through the file descriptor. If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data. If the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is applied for again from the secure memory pool, thereby maximizing memory utilization and reducing the probability of memory waste.
[0053] In this embodiment, the step of determining, based on the file descriptor, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block includes: obtaining, based on the file descriptor, the corresponding dma-buf private data structure; and determining, based on the information recorded in the dma-buf private data structure, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block.
[0054] As an example, if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is requested from the secure memory pool through direct file mapping (mmap).
[0055] Specifically, in the process of using the direct file mapping method (mmap), a specific flag is passed to apply for allocation of secure physical memory from the secure memory pool, and the secure physical memory is used to store data blocks of the memory size required for the data to be decrypted.
[0056] In this embodiment, if the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the step of directly decrypting the data to be decrypted to form decrypted data further includes: recording the memory address and size of the decrypted data through the file descriptor.
[0057] Specifically, the memory address and size of the decrypted data are recorded through the file descriptor. In the subsequent decoding process of the decrypted data, the decoder can obtain the memory address and size of the decrypted data through the file descriptor, so that the decrypted data can be decoded according to the memory address.
[0058] refer to Figure 1 After judging whether the to-be-decrypted data corresponding to the file descriptor can be accommodated by the data block according to the file descriptor, the memory delay dynamic allocation method further includes: executing step S5, decoding the decrypted data by a decoder to form decoded data.
[0059] Specifically, by decoding the decrypted data, it is convenient for an upper layer application (such as a player) to play it.
[0060] In this embodiment, the step of decoding the decrypted data through a decoder includes: passing the file descriptor to the decoder; the decoder obtains the memory address and size of the decrypted data through the file descriptor; obtains the corresponding decrypted data from the memory address and decodes it.
[0061] In other embodiments, the step of decoding the decrypted data through the decoder can also be: the file descriptor directly obtains the dma-buf private data structure of the decrypted data through the direct mapping file method, and directly passes the address and size of the decrypted data to the decoder for decoding through the dma-buf private data structure.
[0062] refer to Figure 1 After the decrypted data is decoded by a decoder to form decoded data, the memory delay dynamic allocation method also includes: executing step S6, releasing the memory of the data block, so that the secure memory pool returns to a preset state.
[0063] It should be noted that since the data size is in a fluctuating state and the allocated data blocks are constantly circulating as a whole, timely memory release of data blocks, that is, timely release of space back to the memory pool, can increase the available space for the next memory allocation and improve the allocation hit rate.
[0064] As an example, the memory release of the data block is realized by using the close system call of the file descriptor.
[0065] Specifically, the close system call of the file descriptor is used to directly release the memory of the data block represented by the dma-buf data structure, return the memory for use in the secure memory pool, and complete the release of the dma-buf data structure and the dma-buf private data structure, so that the secure memory pool returns to the pre-set state.
[0066] Accordingly, an embodiment of the present invention also provides a memory delay dynamic allocation system. Figures 2 to 3 It is a functional block diagram of an embodiment of a memory delay dynamic allocation system of the present invention.
[0067] The memory delayed dynamic allocation system 204 includes: a pre-setting module 200, which is used to pre-set a secure memory pool; a memory pre-allocation module 201, which is used to pre-allocate memory for the secure memory pool to form multiple data blocks; an acquisition module 202, which is used to acquire the data to be decrypted and acquire the file descriptor corresponding to the data to be decrypted; a dynamic allocation module 203, which is used to determine, based on the file descriptor, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block; if the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the size required to store the data to be decrypted is applied for again from the secure memory pool.
[0068] Specifically, the pre-setting module 200 facilitates the management of a continuous secure physical memory by setting up a secure memory pool. At the same time, after the secure memory pool is subsequently pre-allocated to form multiple data blocks, it is determined whether the data to be decrypted corresponding to the subsequently obtained file descriptor can be accommodated by the data block. If the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is applied for again from the secure memory pool.
[0069] In this embodiment, the size of the secure memory pool is preset to 16M.
[0070] Specifically, in the multimedia framework design, the size of the largest frame of video identified in a UHD video stream is 6M, and the size of most video data frames is far less than 6M. Accordingly, a delayed dynamic allocation mechanism is adopted in the subsequent process to ensure that at least two data blocks (12M) can be allocated for rotation. With the remaining 4M data, the total 16M security memory pool can basically meet the rotation requirements, thereby saving the memory size of the security memory pool.
[0071] In other embodiments, the pre-set size of the secure memory pool may also be 22M or 28M, etc.
[0072] It should be noted that the memory pre-allocation module 201 forms multiple data blocks for the flow of the buffer by pre-allocating memory in the secure memory pool. In the subsequent process of determining whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, if the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is re-applied from the secure memory pool.
[0073] In this embodiment, in the step of pre-allocating memory for the secure memory pool, memory is pre-allocated for the secure memory pool according to upper-layer application requirements, and the upper-layer application requirements include being used for playing videos.
[0074] In this embodiment, memory pre-allocation is performed on the secure memory pool through a pre-allocation mechanism. Specifically, the pre-allocation mechanism is limited by the size of the secure memory pool.
[0075] In this embodiment, the step of pre-allocating memory for the secure memory pool includes: setting a dma-buf data structure and a dma-buf private data structure corresponding to the data block, the dma-buf data structure is used to record the size of the data block, and the dma-buf private data structure is used to record the allocation status and other private information.
[0076] Specifically, a dma-buf data structure can represent a data block allocated from the secure memory pool and record the size of the data block. A dma-buf private data structure can export a file descriptor (Filedescriptor, Fd). The exported file descriptor is used for information transmission at the application layer and records the allocation status and other private information.
[0077] The acquisition module 202 is used to obtain the data to be decrypted. By obtaining the data to be decrypted and the file descriptor corresponding to the data to be decrypted, it is helpful to subsequently determine whether the data to be decrypted can be accommodated by the data block. If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is applied for again from the secure memory pool.
[0078] In this embodiment, the step of obtaining the data to be decrypted includes: using the shared memory storing the encrypted data as the data to be decrypted.
[0079] As an example, the data to be decrypted is obtained through DRM.
[0080] It should be noted that when obtaining the data to be decrypted, the kernel returns a file descriptor (returned by the open system call). Therefore, in the process of obtaining the data to be decrypted, the file descriptor corresponding to the data to be decrypted can be obtained.
[0081] As an example, the dynamic allocation module 203 is used to determine whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block based on the file descriptor. If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data; if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the size required to store the data to be decrypted is applied for again from the secure memory pool.
[0082] In this embodiment, a delayed dynamic allocation mechanism is adopted, which allocates data blocks from the secure memory pool and uses file descriptors to transfer data block information allocated for the data to be decrypted. When decrypting the data to be decrypted, the data block information allocated to the data to be decrypted is obtained through the file descriptor. If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the data to be decrypted is directly decrypted to form decrypted data. If the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is applied for again from the secure memory pool, thereby maximizing memory utilization and reducing the probability of memory waste.
[0083] In this embodiment, the step of determining, based on the file descriptor, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block includes: obtaining, based on the file descriptor, the corresponding dma-buf private data structure; and determining, based on the information recorded in the dma-buf private data structure, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block.
[0084] As an example, if the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of the memory size required to store the data to be decrypted is requested from the secure memory pool through direct file mapping (mmap).
[0085] Specifically, in the process of using the direct file mapping method (mmap), a specific flag is passed to apply for allocation of secure physical memory from the secure memory pool, and the secure physical memory is used to store data blocks of the memory size required for the data to be decrypted.
[0086] In this embodiment, if the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the step of directly decrypting the data to be decrypted to form decrypted data further includes: recording the memory address and size of the decrypted data through the file descriptor.
[0087] Specifically, the memory address and size of the decrypted data are recorded through the file descriptor. In the subsequent decoding process of the decrypted data, the decoder can obtain the memory address and size of the decrypted data through the file descriptor, so that the decrypted data can be decoded according to the memory address.
[0088] In this embodiment, the memory delay dynamic allocation system 204 further includes: a decoding module 205, which is used to decode the decrypted data to form decoded data.
[0089] Specifically, the decoding module 205 decodes the decrypted data to facilitate playback by an upper layer application (eg, a player).
[0090] refer to Figure 3 In this embodiment, the decoding module 205 includes: a transmission unit 2051, used to transmit the file descriptor to the decoding module 205; an acquisition unit 2052, used to obtain the memory address and size of the decrypted data through the file descriptor; a decoding unit 2053, used to obtain the corresponding decrypted data from the memory address and decode it.
[0091] In other embodiments, the decoding module may also include: an acquisition unit, used for the file descriptor to directly acquire the dma-buf private data structure of the decrypted data through a direct mapping file method; a transfer unit, used for directly transferring the address and size of the decrypted data to the decoder for decoding through the dma-buf private data structure.
[0092] In this embodiment, the memory delayed dynamic allocation system 204 further includes: a release module 206, which is used to perform memory release on the data block to return the secure memory pool to a preset state.
[0093] It should be noted that since the data size is in a fluctuating state and the allocated data blocks are constantly circulating as a whole, timely memory release of data blocks, that is, timely release of space back to the memory pool, can increase the available space for the next memory allocation and improve the allocation hit rate.
[0094] As an example, the memory release of the data block is realized by using the close system call of the file descriptor.
[0095] Specifically, the close system call of the file descriptor is used to directly release the memory of the data block represented by the dma-buf data structure, return the memory for use in the secure memory pool, and complete the release of the dma-buf data structure and the dma-buf private data structure, so that the secure memory pool returns to the pre-set state.
[0096] The embodiment of the present invention further provides a device, which can implement the memory delay dynamic allocation method provided by the embodiment of the present invention by loading the above memory delay dynamic allocation method in the form of a program. An optional hardware structure of the terminal device provided by the embodiment of the present invention can be as follows Figure 4 As shown, it includes: at least one processor 01, at least one communication interface 02, at least one memory 03 and at least one communication bus 04.
[0097] In this embodiment, the number of processor 01, communication interface 02, memory 03, and communication bus 04 is at least one, and the processor 01, communication interface 02, and memory 03 communicate with each other through the communication bus 04. The communication interface 02 can be an interface of a communication module for network communication, such as an interface of a GSM module. The processor 01 may be a central processing unit CPU, or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement an embodiment of the present invention. The memory 03 may include a high-speed RAM memory, and may also include a non-volatile memory (NVM), such as at least one disk storage. Among them, the memory 03 stores one or more computer instructions, and the one or more computer instructions are executed by the processor 01 to implement the memory delay dynamic allocation method provided in an embodiment of the present invention.
[0098] It should be noted that the above-mentioned terminal device may also include other devices (not shown) that may not be necessary for understanding the contents disclosed in the embodiments of the present invention; given that these other devices may not be necessary for understanding the contents disclosed in the embodiments of the present invention, the embodiments of the present invention will not introduce them one by one.
[0099] An embodiment of the present invention further provides a storage medium, wherein the storage medium stores one or more computer instructions, and the one or more computer instructions are used to implement the memory delay dynamic allocation method provided by the embodiment of the present invention.
[0100] Embodiments of the present invention may be implemented by various means such as hardware, firmware, software or a combination thereof. In a hardware configuration, the method according to an exemplary embodiment of the present invention may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), processors, controllers, microcontrollers, microprocessors, etc. In a firmware or software configuration, embodiments of the present invention may be implemented in the form of modules, processes, functions, etc. The software code may be stored in a memory unit and executed by a processor. The memory unit is located inside or outside the processor and may send data to the processor and receive data from the processor via various known means.
[0101] Although the present invention is disclosed as above, the present invention is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the scope defined by the claims.
Claims
1. A memory delay dynamic allocation method, It is characterized in that include: Pre-set secure memory pool; Pre-allocating memory in the secure memory pool to form multiple data blocks; Obtaining data to be decrypted, and obtaining a file descriptor corresponding to the data to be decrypted; According to the file descriptor, determining whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, and if the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, directly decrypting the data to be decrypted to form decrypted data; If the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of a memory size required to store the data to be decrypted is applied for again from the secure memory pool.
2. The memory delay dynamic allocation method as claimed in claim 1, It is characterized in that In the step of pre-allocating memory for the secure memory pool, memory for the secure memory pool is pre-allocated according to upper-layer application requirements, and the upper-layer application requirements include those for playing videos.
3. The memory delay dynamic allocation method as claimed in claim 1, It is characterized in that The step of pre-allocating memory for the secure memory pool includes: setting a dma-buf data structure and a dma-buf private data structure corresponding to the data block, the dma-buf data structure is used to record the size of the data block, and the dma-buf private data structure is used to record the allocation status and other private information.
4. The memory delay dynamic allocation method as claimed in claim 3, It is characterized in that The step of judging, according to the file descriptor, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block comprises: obtaining, according to the file descriptor, the corresponding dma-buf private data structure; judging, according to the information recorded in the dma-buf private data structure, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block.
5. The memory delay dynamic allocation method as claimed in claim 1, It is characterized in that If the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of a size required to store the data to be decrypted is requested from the secure memory pool through a direct mapping file method.
6. The memory delay dynamic allocation method according to claim 1, It is characterized in that If the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, the step of directly decrypting the data to be decrypted to form decrypted data further includes: recording the memory address and size of the decrypted data through the file descriptor.
7. The memory delay dynamic allocation method according to claim 1, It is characterized in that After determining, according to the file descriptor, whether the to-be-decrypted data corresponding to the file descriptor can be accommodated by the data block, the memory delay dynamic allocation method further comprises: decoding the decrypted data by a decoder to form decoded data.
8. The memory delay dynamic allocation method as claimed in claim 7, It is characterized in that The step of decoding the decrypted data by a decoder comprises: passing the file descriptor to the decoder; The decoder obtains the memory address and size of the decrypted data through the file descriptor; The corresponding decrypted data is obtained from the memory address and decoded.
9. The memory delay dynamic allocation method as claimed in claim 7, It is characterized in that After the decrypted data is decoded by a decoder to form decoded data, the memory delay dynamic allocation method further includes: releasing the memory of the data block to return the secure memory pool to a preset state.
10. The memory delay dynamic allocation method according to claim 9, It is characterized in that The memory of the data block is released by using the close system call of the file descriptor.
11. A memory delay dynamic allocation system, It is characterized in that include: A pre-setting module for pre-setting the secure memory pool; A memory pre-allocation module, used for pre-allocating memory in the secure memory pool to form a data block; An acquisition module, used to acquire the data to be decrypted and acquire the file descriptor corresponding to the data to be decrypted; a dynamic allocation module, used for judging, according to the file descriptor, whether the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, and if the data to be decrypted corresponding to the file descriptor can be accommodated by the data block, directly decrypting the data to be decrypted to form decrypted data; If the data to be decrypted corresponding to the file descriptor cannot be accommodated by the data block, a data block of a size required to store the data to be decrypted is requested from the secure memory pool again.
12. The memory delay dynamic allocation system as claimed in claim 11, It is characterized in that The memory delay dynamic allocation system also includes: a decoding module, which is used to decode the decrypted data to form decoded data.
13. The memory delay dynamic allocation system as claimed in claim 12, It is characterized in that The decoding module includes: a transmission unit, used to transmit the file descriptor to the decoding module; an acquisition unit, used to obtain the memory address and size of the decrypted data through the file descriptor; and a decoding unit, used to obtain the corresponding decrypted data from the memory address and decode it.
14. The memory delay dynamic allocation system as claimed in claim 12, It is characterized in that The memory delayed dynamic allocation system also includes: a release module, which is used to perform memory release on the data block to return the secure memory pool to a preset state.
15. A device, It is characterized in that It comprises at least one memory and at least one processor, wherein the memory stores one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the memory delay dynamic allocation method as described in any one of claims 1 to 10.
16. A storage medium, It is characterized in that The storage medium stores one or more computer instructions, and the one or more computer instructions are used to implement the memory delay dynamic allocation method according to any one of claims 1 to 10.