Kernel FAQ 2 (2001.05.26 ~ 2001.06.06)

zhaozj2021-02-11  224

Kernel FAQ (2001.05.26 ~ 2001.06.06) http://linuxaid.com.cn

Axing

Back to〗 Forward〗

1, the contents of the mm / slab.c file 2, how to get the full path of the intercept file in the kernel 3, LKM write primary issues 4, INSMOD can uninstall the kernel problem 5, one question 1, MM / SLAB. The C file is about a certain aspect of storage management. If you can briefly analyze the content, I am grateful! ! The implementation of the SLAB Allocator allocation algorithm based on object caching mechanism, which is superior to the object multiplexing technology used than the traditional allocation memory block. This algorithm is based on such a fact that some core data structures are often used frequently, so they can be reused. Therefore, the algorithm allocates memory for these frequently used kernel data structures, and treats them as an object to perform unified management. After being created and used, it is not immediately released, but it is temporarily reserved, and it is for the same object. When there is a new requirement, you can use the reserved object immediately, so you can save a lot of core memory allocation and recycling operations, reducing the work burden on the kernel. In addition, the SLAB Allocator allocation algorithm can control the particle size of the assigned memory, which can be customized to the specific data structure, greatly reduced the waste of memory. This algorithm is  莩 莩 莩 莩 莩 螅 捍? KMEM_CACHE_T), SLAB (KMEM_SLAB_T), object (kmem_bufctl_s). Cache centrally manages SLAB, SLAB centralized management objects. Each of the unloaded 鯯 Labs, while each SLAB contains multiple identical types of objects. Cache has two types: universal cache and special Cache. Universal Cache is only used by the SLAB dispenser for its specific purpose, while dedicated Cache is used for the remaining parts of the kernel. General Cache is established when the KMEM_CACHE_INIT () and KMEM_CACHE_SIZES_INIT () are initialized. Dedicated Cache is created by the KMEM_CACHE_CREATE () function. In a universal cache, the first Cache is called Cache_Cache, the content inside is a descriptor for special cache. The second cache name is cache_slabp, which is the SLAB descriptor that is not saved in the SLAB. There are 13 cache, the size from 2 ^ 5 ----- 2 ^ 17 bytes, points from 13 elements in cache_sizes [], respectively. Dedicated Cache is created for specific application requirements. When the system is initialized, it is necessary to build universal cache and some dedicated cache. The descriptor for each new Cache will be inserted into a universal cache cache_cache. It should be noted that once the cache is created, it cannot be deleted. 2. How to get the full path to the intercept file in the kernel, I intercept the Open system call in the kernel. After intercepting the file path, when someone uses a relative path, only others use the full path when calling Open. I can intercept the absolute path to open the file in the kernel. I don't know how to open the file with a relative path, how can I get the absolute path of the open file in the kernel? Since it is a relative path, it is naturally for the current path. There are two variables fs in the task_struct of the current process. Files contains the current open file information, and the specific content looks at the two data structures.

3, LKM writing primary questions I am now learning the kernel of the necropoligate? But even a simple Hello World is not only: I am a redhat7.0 core is 2.2.16. My program is as follows #include #include #if config_modversions == 1 # define modversions # include #ndifint init_module () {printk ("Hello, World"); return 0;} void cleanup_module ) {Printk ("Short is the life of a kenergy module);} makefile is cc = gccmodcflags: = -wall -dmodule -d__kernel__ -dlinuxhello.o: hello.c /usr/include/linux/Version.h $ CC) $ (MODCFLAGS) -C Hello.c then compiles the prompt header file There is a fault I found my modversions.h for the following #Error Modules Shoulders, # error but headers from an appropriate kernel-Source I use the modversions.h in the source SRC instead, and then copy the results of the models in the source code. Although the results are compiled, it will prompt Hello.o: kernel -Module Version mismatchHello.4.0 -0.26while this kernel is version 2.2.16-22 Hope, don't tell me to upgrade the kernel, because what I want to do must run down at 2.2.16 If I just contain #include #include Two header files, then compile with gcc -c -o3 hello.c and prompting what version number is wrong !! i know why !! Hmmm ... you are programming in kernel and its v Ersion IS 2.2.16, SO You Should Do Following: (I Have Just Said IT: <) CD / USR / includemv Linux Linux.bakmv asm asm.bakln -s / usr / src / linux / include / linux linuxln -s / USR / SRC / Linux / include / asm asmthen try ... good luck! Do you do this? Only include two headers, plus -i / usr / include / linux / version.h, I can copy the source code in Includ! In fact, the reason is very simple. RedHat is wrong when publishing the software. It refers to version 2.2.16, so you can do the following CD / usr / includerm -rf Linux asmcp -a / usr / src / linux / include / linux .cp - A / USR / SRC / Linux / include / asm. The main purpose is to replace the kernel.Headers package 4, Insmod can uninstall the kernel problem I found a package filter firewall source program, compiled, but Insmod error. Reporting the error in Unresolved Symbol Htons But if you don't need this (htons) function, I cannot replace the host byte to sort network byte.

I also use ip_fw.c to use NTOHS this function, why can he use I can't use? What is MM_SEGMENT_T? GET_FS (), set_fs ()? This is the solution to me, but maybe I use it wrong, still mistaken. Module programming belongs to the kernel programming, must use the function (kernel function) of the kernel to open outward, htons belongs to user-level, so INSMOD is not found in the kernel public symbol table (see Ksyms), the kernel, how to be in the kernel Level or user-level, mainly through the process of Task_Struct, addr_limit, get_fs, and set_fs, actually to her. Use: MEM_SEGMENT_T OLD_FS; OLD_FS = GET_FS (); // Save. . . . . . . . Set_fs (get_ds ()) ;. . . . . . . SET_FS (OLD_FS) Restore my original article introduces this article, I can't find it, and I can find it in the post. You can refer to it. Suggestion: You can track the HTONS source code, find functions open by kernel, use directly, this is a kernel programming method. Your old man seems to be a -O3 option when using GCC, plus it again. I followed the heroic point. I put MEM_SEGMENT_T OLD_FS OLD_FS = GET_FS () set_fs (GET_FS ()) in the function start set_fs (OLD_FS) in the final. Still there or wrong. Is it mm_segment_t? After correcting the error gcc -Wall said warning -02 -c myfirewall.c time: implicit declaration of function get _fsimcompatale types in assignmentwarning: implicit declaration of function get _fs I checked htons he __bswap16 () but this function seems, in the application Level operation. I can't check the source code of __bswap16. 5. A question about Bootsect.s I found a problem when I study Linux's startup code, I have to solve it, I hope that the high-end people give pointed: As bootloader, bootsect.s is read into absolute address: 0x7C00, Self-relocating immediately, moved to 0x900,000. I think this relocation is meaningless, because the 0x7C00 and the nearby memory area are not written during the bootsect.s execution, although it is possible to relocate the kernel in Setup.s, At 0x1000, it has not existed it at that time, because it has already read Setup.s and kernel into memory, and its task is completed. So it is not a matter of coverage. Therefore, the self-relocation of bootsect.s is meaningless. I suspect that this may be in order to abide by some of the agreement or agree, but I can't find relevant materials. If the master has research, can it give each other? You are right, no relocation is also possible. I have changed it before, and I can use it. However, bootsect.s is a small problem, just use this code when you use the floppy disk, the LILO on the hard disk will not pay attention to it. That is, the hard disk LILO is directly skipped through all the code of bootsect.s to enter setup.s.

转载请注明原文地址:https://www.9cbs.com/read-3492.html

New Post(0)