TWI408605B - Method for executing process in user space and computer system using the same and recording medium - Google Patents
Method for executing process in user space and computer system using the same and recording medium Download PDFInfo
- Publication number
- TWI408605B TWI408605B TW99146146A TW99146146A TWI408605B TW I408605 B TWI408605 B TW I408605B TW 99146146 A TW99146146 A TW 99146146A TW 99146146 A TW99146146 A TW 99146146A TW I408605 B TWI408605 B TW I408605B
- Authority
- TW
- Taiwan
- Prior art keywords
- program
- library
- file system
- user space
- operation request
- Prior art date
Links
Landscapes
- Stored Programmes (AREA)
Abstract
Description
本發明是有關於一種使用者空間程式的使用方法,且特別是有關於一種可連結不同編譯器所編譯之函式庫的執行使用者空間程式的方法、使用其之電腦系統及紀錄媒體。The present invention relates to a method for using a user space program, and more particularly to a method for executing a user space program that can be linked to a library compiled by different compilers, a computer system using the same, and a recording medium.
在電腦科學中,函式庫(library)是用於開發軟體的子程式集合。函式庫是向其他程式提供服務的程式碼,而非獨立程式。函式庫鏈結(link)則是指把一個或多個函式庫包括到程式中。而不同編譯器所編譯出的動態函式庫,由於定址方式不同,因此在不同編譯器所編譯的程式中便無法直接連結。In computer science, a library is a collection of subroutines used to develop software. A library is a code that provides services to other programs, not a stand-alone program. A library link refers to the inclusion of one or more libraries into a program. The dynamic libraries compiled by different compilers cannot be directly linked in programs compiled by different compilers because of different addressing methods.
例如,一般Linux核心通用的編譯器為GNU編譯器集合(GNU Compiler Collection,底下稱為GCC編譯器)與GNU的GLIBC裝載程式。而Android系統是基於Linux核心的軟體平台與作業系統,其是採用自行研發的BIONIC編譯器與BIONIC的裝載程式。而由BIONIC編譯器所編譯的裝載程式無法在裝載時更新GCC編譯器所編譯的動態函式庫記憶體位址,導致原本Linux的動態函式庫無法連結,所有的程式都必須透過BIONIC編譯器重新編譯,以正確連結。但是在沒有原始碼的情況下,BIONIC編譯器無法重新編譯。For example, the general compiler for the Linux kernel is the GNU Compiler Collection (GNU Compiler Collection, under the GCC compiler) and GNU's GLIBC loader. The Android system is a software platform and operating system based on the Linux kernel. It uses the self-developed BIONIC compiler and BIONIC loader. The loader compiled by the BIONIC compiler cannot update the dynamic library memory address compiled by the GCC compiler at load time. As a result, the original Linux dynamic library cannot be linked. All programs must be re-enabled by the BIONIC compiler. Compile to properly link. But without the source code, the BIONIC compiler cannot be recompiled.
本發明提供一種執行使用者空間程式的方法及使用其之電腦系統,在不重新編譯的情況之下,可連結不同編譯器所編譯的函式庫。The present invention provides a method for executing a user space program and a computer system using the same, and can link a library compiled by different compilers without recompiling.
具體而言,本發明提出一種執行使用者空間程式的方法,適用於電腦系統。此電腦系統包括使用者空間與核心,使用者空間包括第一程式,其中第一程式連結至第一標準函式庫,且第一程式與第一標準函式庫由第一編譯器所編譯。在此,於使用者空間中提供第二程式以及第三方函式庫,其中第二程式連結至第二標準函式庫,且第二程式與第二標準函式庫由第二編譯器所編譯,而第三方函式庫相依於第二標準函式庫。第一程式藉由核心所提供檔案系統模組與第二程式溝通,以透過第二程式連結至第三方函式庫,其中檔案系統模組於使用者空間中有對應的檔案系統函式庫。而第一程式透過第二程式連結至第三方函式庫的步驟包括:第二程式透過檔案系統函式庫向檔案系統模組註冊虛擬檔案系統;第一程式透過虛擬檔案系統傳送操作請求至第二程式;第二程式依據操作請求連結至第三方函式庫,藉以執行第三方函式庫中對應的函式;第二程式透過虛擬檔案系統傳送回應至第一程式。In particular, the present invention provides a method of executing a user space program suitable for use in a computer system. The computer system includes a user space and a core, and the user space includes a first program, wherein the first program is linked to the first standard library, and the first program and the first standard library are compiled by the first compiler. Here, a second program and a third-party library are provided in the user space, wherein the second program is linked to the second standard library, and the second program and the second standard library are compiled by the second compiler. The third-party library depends on the second standard library. The first program communicates with the second program through the file system module provided by the core to connect to the third-party library through the second program. The file system module has a corresponding file system library in the user space. The step of linking the first program to the third-party library through the second program includes: the second program registers the virtual file system with the file system module through the file system library; the first program transmits the operation request to the first file through the virtual file system. The second program is linked to the third-party library according to the operation request to execute the corresponding function in the third-party library; the second program transmits the response to the first program through the virtual file system.
在本發明之一實施例中,上述第二程式透過檔案系統函式庫向檔案系統模組註冊虛擬檔案系統的步驟包括:第二程式呼叫檔案系統函式庫的註冊函式,以傳送檔案系統路徑以及第二標準函式庫的函式指標;註冊函式透過第二標準函式庫的開啟函式向核心傳送開啟請求;核心依據開啟請求,開啟虛擬裝置,使得虛擬裝置傳送運算描述子至第二程式;第二程式透過第二標準函式庫的控制函式向核心傳送建立請求,以依據檔案系統路徑建立虛擬檔案系統。In an embodiment of the present invention, the step of registering the virtual file system with the file system module through the file system library includes: the second program calls the registration function of the file system library to transmit the file system The path and the function indicator of the second standard library; the registration function transmits the open request to the core through the open function of the second standard library; the core opens the virtual device according to the open request, so that the virtual device transmits the operation descriptor to The second program; the second program transmits a setup request to the core through the control function of the second standard library to establish a virtual file system according to the file system path.
在本發明之一實施例中,在上述第二程式透過檔案系統函式庫向檔案系統模組註冊虛擬檔案系統的步驟之後,第二程式會呼叫檔案系統函式庫的等待函式,以輪詢虛擬檔案系統是否接收到操作請求。In an embodiment of the present invention, after the step of registering the virtual file system with the file system module by the second program through the file system library, the second program calls the wait function of the file system library to turn Ask the virtual file system whether it receives an operation request.
在本發明之一實施例中,在上述第二程式依據操作請求連結至第三方函式庫,藉以執行第三方函式庫中對應的函式的步驟之前,倘若等待程式輪詢到虛擬檔案系統接收到操作請求時,呼叫檔案系統函式庫的處理函式來解析操作請求。In an embodiment of the present invention, before the second program is linked to the third-party library according to the operation request, before the step of executing the corresponding function in the third-party library, if the waiting program polls the virtual file system When an operation request is received, the processing function of the file system library is called to parse the operation request.
在本發明之一實施例中,上述第一程式透過虛擬檔案系統傳送操作請求至第二程式的步驟包括:第一程式呼叫第一標準函式庫的函式以透過虛擬檔案系統傳送操作請求至檔案系統模組,其中操作請求包括檔案系統路徑;檔案系統模組依據檔案系統路徑傳送操作請求至第二程式。In an embodiment of the present invention, the step of transmitting, by the first program, the operation request to the second program through the virtual file system comprises: the first program calling the function of the first standard library to transmit the operation request to the virtual file system to The file system module, wherein the operation request includes a file system path; the file system module transmits the operation request to the second program according to the file system path.
在本發明之一實施例中,上述檔案系統模組為使用者空間檔案系統(Filesystem in Userspace,FUSE)模組。另外,操作請求的格式為可擴展標記語言(Extensible Markup Language,XML)。In an embodiment of the invention, the file system module is a file system in user space (FUSE) module. In addition, the format of the operation request is Extensible Markup Language (XML).
另外,本發明提出一種電腦系統,包括核心與使用者空間。核心提供一檔案系統模組。使用者空間中包括對應於檔案系統模組的檔案系統函式庫、第一程式、第一標準函式庫、第二程式、第二標準函式庫以及第三方函式庫。其中,第一程式連結至第一標準函式庫,其皆由第一編譯器所編譯;而第二程式連結至第二標準函式庫,其皆由第二編譯器所編譯;第三方函式庫是相依於第二標準函式庫。第二程式透過檔案系統函式庫向檔案系統模組註冊虛擬檔案系統,使得第一程式得以透過虛擬檔案系統傳送操作請求至第二程式。而第二程式依據操作請求連結至第三方函式庫,藉以執行第三方函式庫中對應的函式。之後,第二程式透過虛擬檔案系統傳送回應至第一程式。Additionally, the present invention provides a computer system including a core and user space. The core provides a file system module. The user space includes a file system library corresponding to the file system module, a first program, a first standard library, a second program, a second standard library, and a third-party library. Wherein, the first program is linked to the first standard library, which is compiled by the first compiler; and the second program is linked to the second standard library, which is compiled by the second compiler; The library is dependent on the second standard library. The second program registers the virtual file system with the file system module through the file system library, so that the first program can transmit the operation request to the second program through the virtual file system. The second program is linked to the third-party library according to the operation request, so as to execute the corresponding function in the third-party library. After that, the second program transmits a response to the first program through the virtual file system.
本發明更提出一種電腦可讀取紀錄媒體,用以儲存使用者空間程式並適用於載入電腦系統以執行之。其中,使用者空間程式包括第一程式與第二程式,電腦系統包括使用者空間與核心。而使用者空間包括第一程式,其中第一程式連結至第一標準函式庫,且第一程式與第一標準函式庫由第一編譯器所編譯。而執行使用者空間程式的方法包括:於使用者空間中提供第二程式以及第三方函式庫,其中第二程式連結至第二標準函式庫,且第二程式與第二標準函式庫由第二編譯器所編譯,而第三方函式庫相依於第二標準函式庫。第一程式會藉由核心所提供檔案系統模組與第二程式溝通,以透過第二程式連結至第三方函式庫,其中檔案系統模組於使用者空間中具有對應的檔案系統函式庫。而第一程式透過第二程式連結至第三方函式庫的步驟包括:第二程式透過檔案系統函式庫向檔案系統模組註冊虛擬檔案系統;第一程式透過虛擬檔案系統傳送操作請求至第二程式;第二程式依據操作請求連結至第三方函式庫,藉以執行第三方函式庫中對應的函式;第二程式透過虛擬檔案系統傳送一回應至第一程式。The invention further provides a computer readable recording medium for storing a user space program and for loading into a computer system for execution. The user space program includes a first program and a second program, and the computer system includes a user space and a core. The user space includes a first program, wherein the first program is linked to the first standard library, and the first program and the first standard library are compiled by the first compiler. The method for executing the user space program includes: providing a second program and a third-party library in the user space, wherein the second program is linked to the second standard library, and the second program and the second standard library are Compiled by the second compiler, and the third-party library is dependent on the second standard library. The first program will communicate with the second program through the file system module provided by the core to connect to the third-party library through the second program. The file system module has a corresponding file system library in the user space. . The step of linking the first program to the third-party library through the second program includes: the second program registers the virtual file system with the file system module through the file system library; the first program transmits the operation request to the first file through the virtual file system. The second program is linked to the third-party library according to the operation request to execute the corresponding function in the third-party library; the second program transmits a response to the first program through the virtual file system.
基於上述,本發明透過核心所提供的檔案系統模組使得使用者空間中不同編譯器所編譯的第一程式與第二程式能夠進行溝通,進而利用此一溝通模式讓第一程式呼叫第二程式,而透過第二程式來連結至第三方函式庫。據此,在不重新編譯第三方函式庫之下,第一程式透過第二程式的幫忙,便能夠呼叫第三方函式庫。Based on the above, the file system module provided by the core enables the first program compiled by different compilers in the user space to communicate with the second program, and then uses the communication mode to cause the first program to call the second program. And through the second program to link to the third-party library. Accordingly, without recompiling the third-party library, the first program can call the third-party library through the help of the second program.
為讓本發明之上述特徵和優點能更明顯易懂,下文特舉實施例,並配合所附圖式作詳細說明如下。The above described features and advantages of the present invention will be more apparent from the following description.
不同編譯器所編譯的函式庫,由於定址方式不同,因此第一編譯器所編譯的程式若想連結至第二編譯器所編譯的函式庫,則要先透過第一編譯器重新編譯上述函式庫。然而,在沒有原始碼的情況下,並無法對上述函式庫重新編譯。為此,本發明提出一種執行使用者空間程式的方法及使用其之電腦系統,可在不重新編譯的情況之下,連結不同編譯器所編譯之函式庫。為了使本發明之內容更為明瞭,以下特舉實施例作為本發明確實能夠據以實施的範例。The libraries compiled by different compilers have different addressing methods. Therefore, if the program compiled by the first compiler wants to link to the library compiled by the second compiler, it must first recompile the above through the first compiler. Library. However, in the absence of the source code, the above library cannot be recompiled. To this end, the present invention proposes a method of executing a user space program and a computer system using the same, which can link a library compiled by different compilers without recompiling. In order to clarify the content of the present invention, the following specific examples are given as examples in which the present invention can be implemented.
圖1是依照本發明第一實施例之一種電腦系統的示意圖。請參照圖1,電腦系統100具有使用者空間110與核心130。電腦系統100例如為嵌入式系統。1 is a schematic diagram of a computer system in accordance with a first embodiment of the present invention. Referring to FIG. 1 , the computer system 100 has a user space 110 and a core 130 . Computer system 100 is, for example, an embedded system.
在使用者空間110中具有第一程式111、第二程式121。其中,第一程式111連結至第一標準函式庫113,第一程式111與第一標準函式庫113是由第一編譯器所編譯。第二程式121連結至第二標準函式庫123,第二程式121與第二標準函式庫123則是由第二編譯器所編譯。The user space 110 has a first program 111 and a second program 121. The first program 111 is coupled to the first standard library 113, and the first program 111 and the first standard library 113 are compiled by the first compiler. The second program 121 is coupled to the second standard library 123, and the second program 121 and the second standard library 123 are compiled by the second compiler.
而在使用者空間110中更可包括例如由廠商所提供的第三方函式庫141,可控制電腦系統100上硬體輸出介面,其相依於第二標準函式庫123。In the user space 110, the third-party library 141 provided by the manufacturer may be included, and the hardware output interface on the computer system 100 may be controlled, which is dependent on the second standard library 123.
核心150提供檔案系統模組151,使得第一程式111藉由核心150所提供檔案系統模組151與第二程式121,與透過第二程式121溝通,進而利用第二程式121來連結至第三方函式庫141。這是因為第一標準函式庫113與第二標準函式庫123並不相容,所以第一程式111無法直接連結至第三方函式庫141來使用其所提供之函式。I另外,在使用者空間110中更存在核心150提供的檔案系統模組151所對應的檔案系統函式庫131。The core 150 provides the file system module 151, so that the first program 111 communicates with the second program 121 through the file system module 151 and the second program 121 provided by the core 150, and then connects to the third party by using the second program 121. Library 141. This is because the first standard library 113 is not compatible with the second standard library 123, so the first program 111 cannot directly link to the third party library 141 to use the functions it provides. In addition, in the user space 110, the file system library 131 corresponding to the file system module 151 provided by the core 150 is further present.
檔案系統模組151例如是使用者空間檔案系統(Filesystem in Userspace,FUSE)模組,其提供開發者一個在Linux系統中開發檔案系統的框架,讓開發者能夠在使用者空間110上快速開發與測試檔案系統。而FUSE架構主要有兩個工具,一個是於核心150內的檔案系統模組151,另一個則是架構在使用者空間中110用以提供檔案系統模組151的相關函式給開發者使用的檔案系統函式庫131。The file system module 151 is, for example, a Filesystem in Userspace (FUSE) module, which provides a framework for developers to develop a file system in a Linux system, enabling developers to quickly develop and use in the user space 110. Test the file system. The FUSE architecture mainly has two tools, one is the file system module 151 in the core 150, and the other is the structure in the user space 110 for providing the relevant functions of the file system module 151 to the developer. File System Library 131.
第二程式121會透過檔案系統函式庫131向檔案系統模組151註冊虛擬檔案系統153,使得第一程式111得以利用虛擬檔案系統153並透過第二程式121來使用第三方函式庫141。The second program 121 registers the virtual file system 153 with the file system module 151 through the file system library 131, so that the first program 111 can use the virtual file system 153 and use the third program library 141 through the second program 121.
在此,利用系統呼叫(System Call)的方式,可以讓不同編譯器所編譯的第一標準函式庫113及第二標準函式庫123來使用核心150的檔案系統模組151。系統呼叫提供了使用者空間110中的程式與核心150之間的介面。大多數系統互動式操作需求在核心150執行,例如設備操作或是不同程式通信。而作業系統的空間可分為使用者空間110和核心150,它們需要不同的執行許可權。而系統呼叫運行在核心150。Here, the file system module 151 of the core 150 can be used by the first standard library 113 and the second standard library 123 compiled by different compilers by means of a system call. The system call provides an interface between the program in user space 110 and core 150. Most system interactive operation requirements are performed at core 150, such as device operations or different program communications. The space of the operating system can be divided into user space 110 and core 150, which require different execution permissions. The system call runs on core 150.
以下即搭配上述電腦系統100來詳細說明執行使用者空間程式的方法各步驟。圖2是依照本發明第一實施例之一種執行使用者空間程式的方法流程圖。請同時參照圖1及圖2,在步驟S205中,第二程式121透過檔案系統函式庫131向檔案系統模組151註冊虛擬檔案系統153。The following is a detailed description of the steps of the method for executing the user space program in conjunction with the computer system 100 described above. 2 is a flow chart of a method of executing a user space program in accordance with a first embodiment of the present invention. Referring to FIG. 1 and FIG. 2 simultaneously, in step S205, the second program 121 registers the virtual file system 153 with the file system module 151 through the file system library 131.
具體而言,第二程式121會呼叫檔案系統函式庫131的註冊函式,透過註冊函式來傳送檔案系統路徑以及第二標準函式庫123的函式指標。接著,註冊函式再透過第二標準函式庫123的開啟函式向核心150傳送開啟請求。當核心150接收到開啟請求時,依據開啟請求來開啟檔案系統模組151所提供的虛擬裝置,利用虛擬裝置傳送運算描述子(file descriptor)至第二程式121。此時,第二程式121會透過第二標準函式庫123的控制函式向核心150傳送建立請求,以依據虛擬裝置路徑來建立虛擬檔案系統153。Specifically, the second program 121 calls the registration function of the file system library 131, and transmits the file system path and the function index of the second standard library 123 through the registration function. Then, the registration function transmits an open request to the core 150 through the open function of the second standard library 123. When the core 150 receives the open request, the virtual device provided by the file system module 151 is opened according to the open request, and the virtual device is used to transfer the file descriptor to the second program 121. At this time, the second program 121 transmits a setup request to the core 150 through the control function of the second standard library 123 to establish the virtual file system 153 according to the virtual device path.
在第二程式121註冊完成之後,在步驟S210中,第一程式111透過虛擬檔案系統153傳送操作請求至第二程式121,用以通知第二程式121其欲使用第三方函式庫141。操作請求中包括第二程式121的檔案系統路徑。例如,第一程式111呼叫第一標準函式庫111的函式以透過虛擬檔案系統153傳送操作請求至檔案系統模組151。之後,檔案系統模組151依據檔案系統路徑傳送操作請求至第二程式121。After the registration of the second program 121 is completed, in step S210, the first program 111 transmits an operation request to the second program 121 through the virtual file system 153 to notify the second program 121 that it wants to use the third party library 141. The file system path of the second program 121 is included in the operation request. For example, the first program 111 calls the function of the first standard library 111 to transmit an operation request to the file system module 151 through the virtual file system 153. Thereafter, the file system module 151 transfers the operation request to the second program 121 in accordance with the file system path.
在第二程式121接收到操作請求之後,如步驟S215所示,第二程式121依據操作請求連結至第三方函式庫141,藉以執行第三方函式庫141中對應的函式。具體而言,第二程式111在向檔案系統模組151註冊完之後,其會呼叫檔案系統函式庫131的等待函式,以輪詢虛擬檔案系統153是否有接收到操作請求。倘若第二程式111輪詢到虛擬檔案系統153接收到操作請求,則呼叫檔案系統函式庫131的處理函式來解析操作請求,以依據操作請求而連結至第三方函式庫141。After the second program 121 receives the operation request, as shown in step S215, the second program 121 is linked to the third-party library 141 according to the operation request, thereby executing the corresponding function in the third-party library 141. Specifically, after registering with the file system module 151, the second program 111 calls the wait function of the file system library 131 to poll the virtual file system 153 for receiving an operation request. If the second program 111 polls the virtual file system 153 to receive the operation request, the processing function of the call file system library 131 parses the operation request to link to the third party library 141 according to the operation request.
之後,在步驟S220中,第二程式121透過虛擬檔案系統153傳送回應至第一程式111。例如,第二程式121透過核心150將執行操作請求所獲得的檔案描述子(File Descriptor)回傳至第一程式111。Thereafter, in step S220, the second program 121 transmits a response to the first program 111 through the virtual file system 153. For example, the second program 121 passes back the file descriptor (File Descriptor) obtained by executing the operation request to the first program 111 through the core 150.
圖3A~圖3C是依照本發明第二實施例之一種執行使用者空間程式方法的示意圖。其中,圖3A為註冊虛擬檔案系統流程的示意圖,圖3B及圖3C為開啟虛擬檔案系統流程的示意圖。3A-3C are schematic diagrams showing a method of executing a user space program according to a second embodiment of the present invention. FIG. 3A is a schematic diagram of a process of registering a virtual file system, and FIG. 3B and FIG. 3C are schematic diagrams showing a process of opening a virtual file system.
一般Linux核心通用的編譯器為GNU編譯器集合(GNU Compiler Collection,底下稱為GCC編譯器)與GNU的GLIBC裝載程式。而Android系統是基於Linux核心的軟體平台與作業系統,其是採用自行研發的BIONIC編譯器與BIONIC的裝載程式。The general Linux kernel common compilers are the GNU Compiler Collection (GNU Compiler Collection, called GCC compiler) and GNU's GLIBC loader. The Android system is a software platform and operating system based on the Linux kernel. It uses the self-developed BIONIC compiler and BIONIC loader.
在本實施例中,Android系統的核心304提供FUSE模組305,FUSE模組305在使用者空間中具有對應的FUSE函式庫302。使用者空間中包括第一程式306與第二程式301。第一程式306為BIONIC編譯器所編譯的程式,其可連結至BIONIC編譯器所編譯的BIONIC函式庫307。第二程式301為GCC編譯器所編譯的程式,其可連結至GCC編譯器所編譯的GLIBC函式庫303。In this embodiment, the core 304 of the Android system provides a FUSE module 305, and the FUSE module 305 has a corresponding FUSE library 302 in the user space. The user space includes a first program 306 and a second program 301. The first program 306 is a program compiled by the BIONIC compiler that can be linked to the BIONIC library 307 compiled by the BIONIC compiler. The second program 301 is a program compiled by the GCC compiler, which can be linked to the GLIBC library 303 compiled by the GCC compiler.
在此,第二程式301可向核心304的FUSE模組305註冊一虛擬檔案系統。請參照圖3A,如步驟S311所示,第二程式會301會呼叫FUSE函式庫302的註冊函式“fuse_register”向FUSE模組305註冊。而第二程式301在呼叫註冊函式“fuse_register”時,會傳入一檔案系統路徑(例如在根目錄下面的“/root/FS2”)與其檔案操作的函式指標(例如,vfs_open、vfs_read與vfs_close等)。接著,在步驟S313中,註冊函式“fuse_register”會透過GLIBC函式庫303的開啟函式“open”來開啟FUSE模組305所提供的虛擬裝置(例如“/dev/fuse”)。Here, the second program 301 can register a virtual file system with the FUSE module 305 of the core 304. Referring to FIG. 3A, as shown in step S311, the second program 301 will call the FUSE library 302 registration function "fuse_register" to register with the FUSE module 305. The second program 301, when calling the registration function "fuse_register", will pass in a file system path (for example, "/root/FS2" under the root directory) and its file operation function indicators (for example, vfs_open, vfs_read and Vfs_close, etc.). Next, in step S313, the registration function "fuse_register" will open the virtual device (for example, "/dev/fuse") provided by the FUSE module 305 through the open function "open" of the GLIBC library 303.
之後,GLIBC函式庫303的開啟函式“open”會使用系統呼叫(system call)“syscall_open”向核心304發出開啟請求,如步驟S315所示。然後,核心304根據所欲開啟的檔案是屬於FUSE模組305所提供的虛擬裝置,所以將開啟請求“syscall_open”交由FUSE模組305的開啟函式“fuse_open”處理,其結果將回傳一個檔案描述子“fd”給使用者空間的第二程式301,表示開啟檔案的資訊,如步驟S319。Thereafter, the open function "open" of the GLIBC library 303 issues a start request to the core 304 using the system call "syscall_open", as shown in step S315. Then, the core 304 belongs to the virtual device provided by the FUSE module 305 according to the file to be opened, so the open request "syscall_open" is handed over to the open function "fuse_open" of the FUSE module 305, and the result is returned. The file descriptor "fd" is given to the second program 301 of the user space, indicating that the file information is opened, as in step S319.
而後,在步驟S321中,第二程式301會透過GLIBC函式庫303的控制函式“ioctl”對已開啟的FUSE模組305的虛擬裝置的檔案描述子“fd”發出建立請求“CREAT”。接著,GLIBC函式庫303的控制函式“ioctl”會使用系統呼叫“syscall_ioctl”向核心304發出建立請求,如步驟S323所示。之後,核心304根據所開啟的檔案描述子“fd”是屬於FUSE模組305的虛擬裝置,而將建立請求交由FUSE模組305的控制函式“fuse_ioctl”來處理,如步驟S325所示。Then, in step S321, the second program 301 issues a setup request "CREAT" to the file descriptor "fd" of the virtual device of the opened FUSE module 305 through the control function "ioctl" of the GLIBC library 303. Next, the control function "ioctl" of the GLIBC library 303 will issue a setup request to the core 304 using the system call "syscall_ioctl", as shown in step S323. Thereafter, the core 304 processes the setup request to the virtual device of the FUSE module 305 according to the opened file description "fd", and passes the setup request to the control function "fuse_ioctl" of the FUSE module 305, as shown in step S325.
然後,在步驟S327中,FUSE模組305的控制函式“fuse_ioctl”會根據參數“CREATE”的編號與檔案系統路徑(如在根目錄下面的“/root/GmailFS”),確實地建立虛擬檔案系統的樹狀結構。之後,回傳成功與否,如步驟S329所示。Then, in step S327, the control function "fuse_ioctl" of the FUSE module 305 will surely create a virtual file according to the number of the parameter "CREATE" and the file system path (such as "/root/GmailFS" under the root directory). The tree structure of the system. After that, the return is successful or not, as shown in step S329.
然後,第二程式301會持續地呼叫FUSE函式庫302的等待函式“fuse_wait_req”藉以等待另一程式來操作虛擬檔案系統。例如,藉由等待函式“fuse_wait_req”輪詢(polling)虛擬檔案系統是否有接收到任何程式的操作請求,如步驟S331~步驟S339所示。在步驟S331中,第二程式201呼叫FUSE函式庫302的等待函式“fuse_wait_req”。接著,在步驟S333中,等待函式“fuse_wait_req”會透過GLIBC函式庫303的控制函式“ioctl”而根據檔案描述子“fd”發出等待請求“wait_req”。之後,GLIBC函式庫303的控制函式“ioctl”會向核心304使用系統呼叫“syscall_ioctl”,如步驟S335所示。然後,核心304將系統呼叫“syscall_ioctl”交由FUSE模組305的等待函式“fuse_wait_req”處理。Then, the second program 301 will continuously call the wait function "fuse_wait_req" of the FUSE library 302 to wait for another program to operate the virtual file system. For example, by waiting for the function "fuse_wait_req" to poll the virtual file system for receiving an operation request for any program, as shown in steps S331 to S339. In step S331, the second program 201 calls the wait function "fuse_wait_req" of the FUSE library 302. Next, in step S333, the wait function "fuse_wait_req" issues a wait request "wait_req" according to the file descriptor "fd" through the control function "ioctl" of the GLIBC library 303. Thereafter, the control function "ioctl" of the GLIBC library 303 will use the system call "syscall_ioctl" to the core 304, as shown in step S335. The core 304 then hands the system call "syscall_ioctl" to the wait function "fuse_wait_req" of the FUSE module 305.
此時,可以在檔案系統上看到第二程式301透過FUSE模組305所建立出的虛擬檔案系統。據此,其他程式便能夠透過FUSE模組305來操作已註冊的虛擬檔案系統。At this time, the virtual file system established by the second program 301 through the FUSE module 305 can be seen on the file system. Accordingly, other programs can operate the registered virtual file system through the FUSE module 305.
請參照圖3B,第一程式306透過FUSE模組305來開啟虛擬檔案系統。在步驟S341中,第一程式306會先呼叫BIONIC函式庫307的開啟函式“open”來傳送操作請求(操作請求例如為開啟檔案),並傳入欲開啟的檔案系統路徑為參數。接著,如步驟S343所示,BIONIC函式庫307的開啟函式“open”會採用系統呼叫“syscall_open”將檔案系統路徑傳給核心304。然後,核心304接收到操作要求,會判斷其檔案系統路徑的檔案是向FUSE模組305所註冊的檔案格式,因此將開啟檔案的動作交由FUSE模組305處理,於是呼叫FUSE模組305的開啟函式“fuse_req_open”,如步驟S345所示。Referring to FIG. 3B, the first program 306 opens the virtual file system through the FUSE module 305. In step S341, the first program 306 first calls the open function "open" of the BIONIC library 307 to transmit an operation request (the operation request is, for example, to open the file), and passes the file system path to be opened as a parameter. Next, as shown in step S343, the open function "open" of the BIONIC library 307 transmits the file system path to the core 304 using the system call "syscall_open". Then, the core 304 receives the operation request, and determines that the file of the file system path is the file format registered with the FUSE module 305. Therefore, the action of opening the file is processed by the FUSE module 305, and then the FUSE module 305 is called. The function "fuse_req_open" is opened, as shown in step S345.
FUSE模組305收到操作請求的檔案位置是屬於第二程式301的虛擬檔案系統,所以利用轉發函式“fuse_redirect_req”將操作請求轉發給第二程式301,如步驟S347所示。此時,FUSE模組305會結束圖3A中的步驟S339的等待。也就是說,當等待函式“fuse_wait_req”輪詢到虛擬檔案系統接收到第一程式301的操作請求時,會呼叫FUSE函式庫302的處理函式“fuse_proce_req”來解析操作請求。並且,FUSE模組305呼叫等待回應函式“fuse_wait_resp”,如步驟S349所示。之後,FUSE模組305將回傳一個檔案描述子“fd”至第一程式306,如步驟S351所示。The file location where the FUSE module 305 receives the operation request is the virtual file system belonging to the second program 301, so the operation request is forwarded to the second program 301 by using the forwarding function "fuse_redirect_req", as shown in step S347. At this time, the FUSE module 305 will end the waiting of step S339 in FIG. 3A. That is, when the wait function "fuse_wait_req" polls the virtual file system to receive the operation request of the first program 301, the processing function "fuse_proce_req" of the FUSE library 302 is called to parse the operation request. And, the FUSE module 305 calls the wait response function "fuse_wait_resp" as shown in step S349. Thereafter, the FUSE module 305 will return a file descriptor "fd" to the first program 306, as shown in step S351.
接著請參照圖3C,在步驟S353中,FUSE函式庫302會依據等待回應函式“fuse_wait_req”的結果來呼叫處理函式“fuse_proce_req”,其操作請求為開啟檔案,FUSE函式庫302根據第二程式301先前所註冊的檔案操作的函式指標來呼叫相對應的開啟函式“vfs_open”,其結果將回傳一個檔案描述子“fd”,如步驟S357所示,據此便能夠開啟檔案。Referring to FIG. 3C, in step S353, the FUSE library 302 calls the processing function "fuse_proce_req" according to the result of the wait response function "fuse_wait_req", and the operation request is to open the file, and the FUSE library 302 is based on the The function indicator of the file operation previously registered by the second program 301 calls the corresponding open function "vfs_open", and the result will return a file descriptor "fd", as shown in step S357, according to which the file can be opened. .
之後,在步驟S359中,FUSE函式庫302會呼叫回應函式“fuse_resp_req”。並且,在步驟S361中,呼叫GLIBC函式庫303的控制函式“ioctl”。接著,在步驟S363中,GLIBC函式庫303的控制函式“ioctl”會採用系統呼叫“syscall_ioctl”將開啟函式“vfs_open”的檔案描述子傳給核心304。然後,在步驟S365中,呼叫FUSE模組305的控制函式“fuse_ioctl”。此時,FUSE模組305會結束圖3B中的步驟S349的等待。最後,由核心304回傳開啟檔案的資訊。Thereafter, in step S359, the FUSE library 302 calls the response function "fuse_resp_req". And, in step S361, the control function "ioctl" of the GLIBC library 303 is called. Next, in step S363, the control function "ioctl" of the GLIBC library 303 transmits the file descriptor of the open function "vfs_open" to the core 304 using the system call "syscall_ioctl". Then, in step S365, the control function "fuse_ioctl" of the FUSE module 305 is called. At this time, the FUSE module 305 will end the waiting of step S349 in FIG. 3B. Finally, the core 304 returns the information of the open file.
也就是說,第二程式301向FUSE模組305註冊其所提供的檔案系統。據此,第一程式306便可以開啟(open)、讀取(read)、寫入(write)、控制(ioctl)與關閉(close)第二程式301透過FUSE模組305所建立的虛擬檔案系統,其所有的過程最後都會呼叫到第二程式301在先前註冊的函式指標(例如,vfs_open、vfs_read與vfs_close等)。That is, the second program 301 registers the file system provided by the FUSE module 305. Accordingly, the first program 306 can open, read, write, control (ioctl) and close (close) the virtual file system created by the second program 301 through the FUSE module 305. All of its processes will eventually call the previously registered function indicators of the second program 301 (for example, vfs_open, vfs_read, vfs_close, etc.).
圖4是依照本發明第三實施例之一種電腦系統的示意圖。請參照圖4,電腦系統400具有使用者空間410與核心430。在使用者空間410中具有第一程式411、第二程式421。第一程式411為BIONIC編譯器所編譯的程式,其可連結至BIONIC編譯器所編譯的BIONIC函式庫413。第二程式421為GCC編譯器所編譯的程式,其可連結至GCC編譯器所編譯的GLIBC函式庫423。4 is a schematic diagram of a computer system in accordance with a third embodiment of the present invention. Referring to FIG. 4, the computer system 400 has a user space 410 and a core 430. The user space 410 has a first program 411 and a second program 421. The first program 411 is a program compiled by the BIONIC compiler, which can be linked to the BIONIC library 413 compiled by the BIONIC compiler. The second program 421 is a program compiled by the GCC compiler that can be linked to the GLIBC library 423 compiled by the GCC compiler.
而在使用者空間110中更可包括例如由廠商所提供的相依於GLIBC函式庫423的第三方函式庫141、核心450提供之FUSE模組451所對應的FUSE函式庫431以及一可擴展標記語言(Extensible Markup Language,XML)函式庫433。In the user space 110, for example, the third-party library 141 corresponding to the GLIBC library 423 provided by the manufacturer, the FUSE library 431 corresponding to the FUSE module 451 provided by the core 450, and the like may be included. Extensible Markup Language (XML) library 433.
在電腦系統400中,自訂一種FUSE遠端程序呼叫請求(FUSE_RPCQ)的XML格式,其包含所呼叫的函式庫名稱、函式名稱、參數型態、參數資料。圖5是依照本發明第三實施例之一種XML格式的示意圖。請參照圖5,XML的根標籤為<FuseRpcq>,其表示文件的開始。標籤“Library”的屬性“name”用來定義所呼叫的函式庫名稱;標籤“Function”的屬性“name”用來定義呼叫的函式名稱;標籤“Param”的屬性“type”用來定義呼叫函式的參數型態,屬性“name”用來定義參數名稱。在此,假設第三方函式庫441的函式庫名稱為“libgbt_display.so“。而在此X ML文件中,函式“clear_screen“用來清除螢幕畫面,函式“show_image”用來顯示圖片,而函式“show_image”的參數包含了顯示圖片的位置、大小與檔案路徑。In the computer system 400, an XML format of a FUSE remote program call request (FUSE_RPCQ) is customized, which includes the called library name, function name, parameter type, and parameter data. Figure 5 is a diagram showing an XML format in accordance with a third embodiment of the present invention. Referring to Figure 5, the root tag of the XML is <FuseRpcq>, which indicates the beginning of the file. The attribute "name" of the label "Library" is used to define the name of the library to be called; the attribute "name" of the label "Function" is used to define the name of the function of the call; the attribute "type" of the label "Param" is used to define The parameter type of the call function, the attribute "name" is used to define the parameter name. Here, assume that the library name of the third-party library 441 is "libgbt_display.so". In this X ML file, the function "clear_screen" is used to clear the screen, the function "show_image" is used to display the image, and the function "show_image" contains the position, size and file path of the displayed image.
返回圖4,第二程式421會先向FUSE模組451註冊虛擬檔案系統453。之後,第一程式411開啟FUSE模組451所建立出的虛擬檔案系統,而第一程式再透過BIONIC函式庫413的控制函式“ioctl”來執行系統呼叫,並將XML文件“FuseRpcq”當作參數傳送至FUSE模組451,然後第一程式411便等待FUSE模組451的回應。Returning to FIG. 4, the second program 421 registers the virtual file system 453 with the FUSE module 451. After that, the first program 411 starts the virtual file system established by the FUSE module 451, and the first program executes the system call through the control function "ioctl" of the BIONIC library 413, and the XML file "FuseRpcq" is used as the XML file. The parameters are passed to the FUSE module 451, and the first program 411 then waits for a response from the FUSE module 451.
而FUSE模組451在接收到第一程式411的請求之後,轉發請求給第二程式421。此時,第二程式421會去呼叫FUSE函式庫431的處理函式並依據XML函式庫433來解析XML文件“FuseRpcq”,藉以依據XML文件“FuseRpcq”中的函式庫名稱動態連結至第三方函式庫441來呼叫第三方函式庫441的函式“clear_screen”以及呼叫函式“show_image”。之後,第二程式421會回傳一回應至第一程式411。第一程式411在接收到回應至後便會結束控制函式“ioctl”所執行的系統呼叫。The FUSE module 451, after receiving the request of the first program 411, forwards the request to the second program 421. At this time, the second program 421 will call the processing function of the FUSE library 431 and parse the XML file "FuseRpcq" according to the XML library 433, thereby dynamically linking to the library name in the XML file "FuseRpcq". The third party library 441 calls the function "clear_screen" of the third party library 441 and the call function "show_image". After that, the second program 421 will return a response to the first program 411. The first program 411 will end the system call performed by the control function "ioctl" upon receiving the response.
藉由上述方式,第一程式411可以順利的呼叫無法與BIONIC所編譯之程式連結的函式庫,並且減化程式碼大小,將呼叫流程變成XML文件交換。並且,多個程式可以同時間使用虛擬檔案系統453。In the above manner, the first program 411 can smoothly call a library that cannot be linked with the program compiled by BIONIC, and reduce the code size to change the call flow into an XML file exchange. Also, multiple programs can use the virtual file system 453 at the same time.
另外,還可以電腦程式產品(例如:軟體、韌體等)的形式實現上述諸實施例,並利用電腦可讀取紀錄媒體(例如:光碟、硬碟、記憶體等)儲存使用者空間程式,以利電腦系統執行之,而以電子自動化的方式完成。具體而言,電腦可讀取紀錄媒體用以儲存使用者空間程式以載入電腦系統來執行之。其中,使用者空間程式包括第一程式與第二程式,電腦系統包括使用者空間與核心。而使用者空間包括第一程式,其中第一程式連結至第一標準函式庫,且第一程式與第一標準函式庫由第一編譯器所編譯。而執行使用者空間程式的方法包括:於使用者空間中提供第二程式以及第三方函式庫,其中第二程式連結至第二標準函式庫,且第二程式與第二標準函式庫由第二編譯器所編譯,而第三方函式庫相依於第二標準函式庫。第一程式會藉由核心所提供檔案系統模組與第二程式溝通,以透過第二程式連結至第三方函式庫,其中檔案系統模組於使用者空間中具有對應的檔案系統函式庫。而第一程式透過第二程式連結至第三方函式庫的步驟則如上述第一實施例之步驟S205~S220,故,在此不再贅述。In addition, the above embodiments may be implemented in the form of a computer program product (eg, software, firmware, etc.), and the user space program may be stored by using a computer-readable recording medium (eg, a CD, a hard disk, a memory, etc.). Eli is implemented by the computer system and is done electronically. Specifically, the computer can read the recording medium for storing the user space program to load the computer system to execute. The user space program includes a first program and a second program, and the computer system includes a user space and a core. The user space includes a first program, wherein the first program is linked to the first standard library, and the first program and the first standard library are compiled by the first compiler. The method for executing the user space program includes: providing a second program and a third-party library in the user space, wherein the second program is linked to the second standard library, and the second program and the second standard library are Compiled by the second compiler, and the third-party library is dependent on the second standard library. The first program will communicate with the second program through the file system module provided by the core to connect to the third-party library through the second program. The file system module has a corresponding file system library in the user space. . The steps of the first program to be linked to the third-party library through the second program are as shown in steps S205 to S220 of the first embodiment, and therefore are not described herein again.
綜上所述,上述實施例中,透過核心所提供的檔案系統模組使得使用者空間中不同編譯器所編譯的第一程式與第二程式能夠進行溝通,進而利用此一溝通模式讓第一程式呼叫第二程式,而透過第二程式來連結至第三方函式庫。據此,在不重新編譯第三方函式庫之下,第一程式透過第二程式的幫忙,便能夠呼叫第三方函式庫。並且,無需修改核心,進而保持系統穩定,並且亦能降低開發成本。In summary, in the above embodiment, the file system module provided by the core enables the first program and the second program compiled by different compilers in the user space to communicate, and then utilizes the communication mode to make the first The program calls the second program and connects to the third-party library through the second program. Accordingly, without recompiling the third-party library, the first program can call the third-party library through the help of the second program. Moreover, there is no need to modify the core to keep the system stable and also reduce development costs.
雖然本發明已以實施例揭露如上,然其並非用以限定本發明,任何所屬技術領域中具有通常知識者,在不脫離本發明之精神和範圍內,當可作些許之更動與潤飾,故本發明之保護範圍當視後附之申請專利範圍所界定者為準。Although the present invention has been disclosed in the above embodiments, it is not intended to limit the invention, and any one of ordinary skill in the art can make some modifications and refinements without departing from the spirit and scope of the invention. The scope of the invention is defined by the scope of the appended claims.
100、400...電腦系統100, 400. . . computer system
110、410...使用者空間110, 410. . . User space
111、306、411...第一程式111, 306, 411. . . First program
113...第一標準函式庫113. . . First standard library
121、301、421...第二程式121, 301, 421. . . Second program
123...第二標準函式庫123. . . Second standard library
131...檔案系統函式庫131. . . File system library
141、441...第三方函式庫141, 441. . . Third-party library
150、304、450...核心150, 304, 450. . . core
151...檔案系統模組151. . . File system module
153、453...虛擬檔案系統153, 453. . . Virtual file system
302、431...FUSE函式庫302, 431. . . FUSE library
303、423...GLIBC函式庫303, 423. . . GLIBC library
305、451...FUSE模組305, 451. . . FUSE module
307、413...BIONIC函式庫307, 413. . . BIONIC library
433...XML函式庫433. . . XML library
S205~S220...本發明第一實施例之執行使用者空間程式的方法各步驟S205~S220. . . Each step of the method for executing a user space program in the first embodiment of the present invention
S311~S365...本發明第二實施例之執行使用者空間程式的方法各步驟S311~S365. . . Method for performing a user space program according to a second embodiment of the present invention
圖1是依照本發明第一實施例之一種電腦系統的示意圖。1 is a schematic diagram of a computer system in accordance with a first embodiment of the present invention.
圖2是依照本發明第一實施例之一種執行使用者空間程式的方法流程圖。2 is a flow chart of a method of executing a user space program in accordance with a first embodiment of the present invention.
圖3A~圖3C是依照本發明第二實施例之一種執行使用者空間程式方法的示意圖。3A-3C are schematic diagrams showing a method of executing a user space program according to a second embodiment of the present invention.
圖4是依照本發明第三實施例之一種電腦系統的示意圖。4 is a schematic diagram of a computer system in accordance with a third embodiment of the present invention.
圖5是依照本發明第三實施例之一種XML格式的示意圖。Figure 5 is a diagram showing an XML format in accordance with a third embodiment of the present invention.
S205~S220...本發明第一實施例之執行使用者空間程式的方法各步驟S205~S220. . . Each step of the method for executing a user space program in the first embodiment of the present invention
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
TW99146146A TWI408605B (en) | 2010-12-27 | 2010-12-27 | Method for executing process in user space and computer system using the same and recording medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
TW99146146A TWI408605B (en) | 2010-12-27 | 2010-12-27 | Method for executing process in user space and computer system using the same and recording medium |
Publications (2)
Publication Number | Publication Date |
---|---|
TW201227518A TW201227518A (en) | 2012-07-01 |
TWI408605B true TWI408605B (en) | 2013-09-11 |
Family
ID=46933288
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
TW99146146A TWI408605B (en) | 2010-12-27 | 2010-12-27 | Method for executing process in user space and computer system using the same and recording medium |
Country Status (1)
Country | Link |
---|---|
TW (1) | TWI408605B (en) |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
TW200638263A (en) * | 2005-04-29 | 2006-11-01 | Ind Tech Res Inst | Method and corresponding apparatus for compiling high-level languages into specific processor architectures |
TW200739421A (en) * | 2006-04-07 | 2007-10-16 | Sunplus Technology Co Ltd | Method of dynamically linking function database software devices and sharing static linked source codes with main application program |
TWI334573B (en) * | 2007-07-06 | 2010-12-11 | Via Tech Inc | Application procedure processing methods and systems, and machine readable medium thereof |
-
2010
- 2010-12-27 TW TW99146146A patent/TWI408605B/en active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
TW200638263A (en) * | 2005-04-29 | 2006-11-01 | Ind Tech Res Inst | Method and corresponding apparatus for compiling high-level languages into specific processor architectures |
TW200739421A (en) * | 2006-04-07 | 2007-10-16 | Sunplus Technology Co Ltd | Method of dynamically linking function database software devices and sharing static linked source codes with main application program |
TWI334573B (en) * | 2007-07-06 | 2010-12-11 | Via Tech Inc | Application procedure processing methods and systems, and machine readable medium thereof |
Also Published As
Publication number | Publication date |
---|---|
TW201227518A (en) | 2012-07-01 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2022002030A1 (en) | Data processing method, apparatus, and device, and computer readable storage medium | |
US20090254881A1 (en) | Code generation techniques for administrative tasks | |
WO2020019490A1 (en) | Interface testing method, electronic device and storage medium | |
CN103793432A (en) | Method and device for splitting database reading and writing | |
CN113688186B (en) | Intelligent contract execution method, engine and block link point | |
WO2016095570A1 (en) | Debugging method and apparatus for embedded system, and storage medium | |
CN110083342A (en) | A kind of program creating method, device and computer readable storage medium | |
US9128886B2 (en) | Computer implemented method, computer system, electronic interface, mobile computing device and computer readable medium | |
CN113658591B (en) | Voice interaction adaptation system for intelligent home | |
WO2024027240A1 (en) | Calling method, apparatus and system for diagnosis module | |
WO2023213263A1 (en) | Program compiling method, program starting method, and device and storage medium | |
US20070157194A1 (en) | Post-deployment user interface update in a mobile device | |
US20070156841A1 (en) | Platform independent user interface for a mobile device | |
CN111158646A (en) | SQL lightweight persistent layer framework and configuration method | |
CN113448643B (en) | Configuration data management system and method | |
CN104991857B (en) | Trace debug method and device | |
CN113238739A (en) | Plug-in development and data acquisition method, device, electronic equipment and medium | |
CN106453250B (en) | A kind of processing method of big data RPC | |
TWI408605B (en) | Method for executing process in user space and computer system using the same and recording medium | |
CN106371848B (en) | Implementation method for web development framework to support Odata | |
CN107239265B (en) | Binding method and device of Java function and C function | |
JP2001344127A (en) | System developing method, storage medium, information processor, information terminal device, information processing system, and information processing method | |
CN110659022B (en) | Method for automatically calling Python script based on Java | |
US20070155425A1 (en) | Enabling rapid and de-coupled ui development for a cellular telephone | |
US20070155426A1 (en) | Application access to cellular telephone settings |