Search

CN-121996306-A - Method and system for adapting interface of open instrument controller

CN121996306ACN 121996306 ACN121996306 ACN 121996306ACN-121996306-A

Abstract

The invention provides an interface adapting method and a system of an open instrument controller, in particular to an interface driver library of an instrument to be adapted, which is characterized in that the interface driver library is subjected to static analysis, unique fingerprints of derived functions are extracted, a function index is built, the driver library is loaded in an independent logic address space, address relocation and symbol analysis are completed, safe residence of a driver in a user state is realized, when an upper layer application issues a standardized instruction, the corresponding function fingerprints are matched according to instruction semantics, the index is searched to obtain a function entry address, a calling context containing parameter push rules and an entry pointer is built, logic verification is carried out on the instruction through a virtual state machine before execution, the fact that actual hardware calling is triggered after the state transition is legal is ensured, and return data is written into a protected shared buffer area.

Inventors

  • LI XIAONA
  • LI XIAORUI

Assignees

  • 云知尚(西安)智能科技有限公司

Dates

Publication Date
20260508
Application Date
20260410

Claims (10)

  1. 1. An open instrument controller interface adaptation method, comprising the steps of: Performing static binary analysis on an interface driving library file of an instrument to be adapted, which is connected through a physical interface, traversing a derived function symbol table, extracting function names and parameter type lists, generating unique identification fingerprints of each derived function, and constructing a functional feature index containing the corresponding relation between the fingerprints and the relative offset address of a function entry; According to the memory page allocation granularity of the current operating system and the paragraph space requirement of the interface driver library file, applying for an independent logic virtual address space, loading a code segment and a data segment of the interface driver library file into the space, and executing address relocation repair and external symbol dependence analysis based on a loading base address to complete memory residence of a driver library; Receiving a standard operation instruction sent by an upper control application, analyzing an operation Fu Yuyi and an operand sequence of the instruction, searching a corresponding local execution function entry address in the functional feature index according to a mapping rule of preset instruction semantics and function fingerprints, and constructing a calling context containing a parameter push rule and a function entry pointer; And maintaining a virtual state machine representing the current working logic of the instrument hardware in a memory, before triggering a local execution function through the calling context, deducing the state transition of the virtual state machine by using an operator of a standard operation instruction as an input event, updating the state of the virtual state machine if the target state after the transition is positioned in a preset legal state set, executing the local execution function in the logic virtual address space through the calling context, and writing hardware return data into a shared data buffer area protected by mutual exclusion.
  2. 2. The method of claim 1, wherein traversing the derived function symbol table, extracting a list of function names and parameter types, generating a unique identification fingerprint for each derived function, comprises: Reading a function name character string of the derived function, traversing a parameter list of the derived function to obtain the data type name of each parameter, and connecting the data type names into a parameter type signature character string according to the statement sequence of the parameters in the list; and splicing the function name character string and the parameter type signature character string to obtain feature metadata, executing SHA-256 hash operation on the feature metadata, and intercepting the first 16 bytes of an operation result as a unique identification fingerprint of the derived function.
  3. 3. The method of claim 1, wherein constructing the functional feature index containing correspondence between fingerprints and function entry relative offset addresses comprises: Creating a hash mapping table, taking the unique identification fingerprint as a hash key, and taking the relative offset address of the export function in a section of an interface drive library file as a hash value; and adopting an open addressing method to solve hash collision, filling the corresponding relation between fingerprints and offset addresses of all derived functions into the Ha Xiying table, and serializing and storing the hash mapping table as a binary index file.
  4. 4. A method according to claim 1 or 3, wherein loading the code segments and data segments of the interface driver library file into the space and performing address relocation repair and external symbol dependent parsing based on a loading base address comprises: Analyzing file header information of the interface drive library file, obtaining loading size and memory alignment requirement of each section, calculating total target memory space size, and applying for a continuous virtual memory area with read, write and execute authorities to an operating system; Copying binary contents of code sections and data sections to corresponding relative addresses of the continuous virtual memory area byte by byte according to the section offset defined by the file header; Traversing a relocation table of an interface driving library file, and carrying out numerical correction on all instruction operands related to absolute address references in a code segment according to the starting address of the continuous virtual memory area; Traversing an import table of the interface driving library file, loading an external link library relied by the library, acquiring a memory address of an external symbol, and backfilling the memory address into the import address table.
  5. 5. The method of claim 1, wherein receiving a standard operation instruction issued by an upper control application, resolving operations Fu Yuyi and operand sequences of the instruction, comprises: Detecting a first space separator in a received standard operation instruction character string, and extracting a sub character string at the left side of the separator as an operator semantic identifier; Detecting comma separators in the residual character strings, and dividing the residual character strings into a plurality of operand substrings according to the positions of the comma separators; The numerical value format of each operand substring is identified, integer data is converted according with integer format, double-precision floating point data is converted according with floating point format, and the converted data is stored in an operand numerical value list.
  6. 6. The method according to claim 1 or 5, wherein the retrieving, according to a mapping rule of a preset instruction semantic and a function fingerprint, a corresponding local execution function entry address in the function feature index, and constructing a call context including a parameter push rule and a function entry pointer, includes: based on the operation Fu Yuyi identification, searching a corresponding target function fingerprint in a preset semantic mapping configuration table; Searching the relative offset address of the local execution function in the functional feature index by utilizing the target function fingerprint, and calculating the memory absolute address of the local execution function by combining the loading base address of the logic virtual address space; generating a parameter push instruction sequence adapting to the calling convention of the current CPU architecture or constructing a parameter pointer array according to the parameter type signature of the local execution function; And instantiating a structural body containing the memory absolute address and the parameter push instruction sequence as the calling context.
  7. 7. The method according to claim 1, wherein the deriving the state transition of the virtual state machine using the operator of the standard operation instruction as the input event, if the target state after the transition is within the preset legal state set, comprises: Reading a state value of a current virtual state machine, wherein the current state value is a row index in a pre-constructed state transition two-dimensional matrix, and the operator ID of the standard operation instruction is a column index to search a numerical value in a target cell; Taking the numerical value in the target cell as the next state value to be changed; and querying a legal state set list, checking whether the next state value to be changed exists in the legal state set list, and if so, judging that the legal constraint condition is met.
  8. 8. The method of claim 1, wherein writing hardware return data to the mutually exclusive protected shared data buffer comprises: acquiring a mutually exclusive lock object of a shared data buffer area and executing locking operation to prevent concurrent writing conflict; Calculating the byte length of returned data of the local execution function, and detecting whether the residual available space between a write pointer and a read pointer of the shared data buffer is larger than the byte length; When the remaining available space is sufficient, writing the returned data into a memory address pointed by the write pointer in a binary stream form, and updating the position of the write pointer to point to the tail of the data; unlocking the mutually exclusive lock object and triggering a data ready signal to inform an upper control application of reading.
  9. 9. An open instrument controller interface adaptation system, comprising the following modules: The generating module is used for carrying out static binary analysis on an interface driving library file of the instrument to be adapted, which is connected through a physical interface, traversing the derived function symbol table, extracting function names and parameter type lists, generating unique identification fingerprints of each derived function, and constructing a functional feature index containing the corresponding relation between the fingerprints and the relative offset addresses of the function inlets; the execution module is used for applying for an independent logic virtual address space according to the memory page allocation granularity of the current operating system and the paragraph space requirement of the interface driver library file, loading the code segment and the data segment of the interface driver library file into the space, and executing address relocation repair and external symbol dependence analysis based on a loading base address to complete memory residence of the driver library; the construction module is used for receiving standard operation instructions sent by an upper control application, analyzing operation Fu Yuyi and an operand sequence of the instructions, searching and matching corresponding local execution function entry addresses in the function feature index according to a mapping rule of preset instruction semantics and function fingerprints, and constructing a calling context containing parameter stacking rules and function entry pointers; And the updating module is used for maintaining a virtual state machine representing the current working logic of the instrument hardware in the memory, deducing the state transition of the virtual state machine by using an operator of a standard operation instruction as an input event before triggering the local execution function through the calling context, updating the state of the virtual state machine if the target state after the transition is positioned in a preset legal state set, executing the local execution function in the logic virtual address space through the calling context, and writing hardware return data into a shared data buffer area protected by mutual exclusion.
  10. 10. The system of claim 9, wherein traversing the derived function symbol table, extracting a list of function names and parameter types, generating a unique identification fingerprint for each derived function, comprises: Reading a function name character string of the derived function, traversing a parameter list of the derived function to obtain the data type name of each parameter, and connecting the data type names into a parameter type signature character string according to the statement sequence of the parameters in the list; and splicing the function name character string and the parameter type signature character string to obtain feature metadata, executing SHA-256 hash operation on the feature metadata, and intercepting the first 16 bytes of an operation result as a unique identification fingerprint of the derived function.

Description

Method and system for adapting interface of open instrument controller Technical Field The application belongs to the field of interface adaptation, and particularly relates to an interface adaptation method and system of an open instrument controller. Background The open instrument controller breaks the limitation of the traditional closed special system, supports a standardized hardware interface, third-party software integration and a control system platform for user-defined development, has the core advantages of high flexibility, strong expansibility, adaptation to an intelligent instrument, and provides an open development architecture of a real-time level, thereby meeting the requirements of the intelligent instrument on high precision, high openness and high flexibility of the controller. In order to realize unified control over heterogeneous hardware, existing software architecture generally adopts hierarchical planning, that is, communication is performed between an upper control application and a bottom hardware device through an interface driver library. In conventional adaptation schemes, control applications typically rely on standard loaders provided by the operating system to load vendor-provided interface driver libraries into the host process's memory space or to develop specific adaptation layer code based on standard specifications such as VISA, IVI, etc. The control application and the drive library have coupling degree, the drive library usually operates in the same address space of the main process, once the third party drive program has memory leakage, illegal pointer access or breakdown, abnormal termination of the whole control software is caused, the stability of a test system is seriously influenced, the drive libraries of different manufacturers possibly depend on the bottom base libraries of different versions, and the problem of 'DLL prison' or symbol conflict is easily caused by loading, so that partial instruments cannot be initialized normally. The existing instrument interface adaptation technology focuses on static mapping of function symbols, and does not have a depth analysis and a safety control mechanism in running of a binary file of a drive library. In practical applications, many legacy devices or non-standard devices only provide a binary format driving file, and lack complete header or source support, so that interface adaptation cannot be performed through conventional compiling means. The traditional drive calling mode is 'stateless' or 'blind', when an upper layer application issues a control instruction, the current state of the hardware of the instrument cannot be perceived, and a calling drive function is easy to cause hardware error reporting and even damage due to time sequence errors or state mismatch. Therefore, how to realize an open interface adaptation method which can analyze binary drive during running, realize memory level isolation loading and ensure hardware operation safety through a state machine becomes a technical problem to be solved in the current instrument control field. Disclosure of Invention The invention provides an open type instrument controller interface adapting method, which is used for solving the problems that the prior art can not analyze binary drive in running, realize memory level isolation loading and can ensure the safety of hardware operation through a state machine, and comprises the following steps: Performing static binary analysis on an interface driving library file of an instrument to be adapted, which is connected through a physical interface, traversing a derived function symbol table, extracting function names and parameter type lists, generating unique identification fingerprints of each derived function, and constructing a functional feature index containing the corresponding relation between the fingerprints and the relative offset address of a function entry; According to the memory page allocation granularity of the current operating system and the paragraph space requirement of the interface driver library file, applying for an independent logic virtual address space, loading a code segment and a data segment of the interface driver library file into the space, and executing address relocation repair and external symbol dependence analysis based on a loading base address to complete memory residence of a driver library; Receiving a standard operation instruction sent by an upper control application, analyzing an operation Fu Yuyi and an operand sequence of the instruction, searching a corresponding local execution function entry address in the functional feature index according to a mapping rule of preset instruction semantics and function fingerprints, and constructing a calling context containing a parameter push rule and a function entry pointer; And maintaining a virtual state machine representing the current working logic of the instrument hardware in a memory, before triggering a local execution fun