Self-writing system call debug application process

In this section we will discuss in detail how to use our own system call to debug the application.

First, principle

To make a system call, of course, the prime minister has to understand the process of system calls:

We take the open function to give an example: When the user space to perform the open function, will eventually call sys_open function through the role of the glibc library, sys_open function will eventually call our specific registered open function! So what's the main thing here is the glibc library? In fact, its role is to perform a swi #val instruction when the user space executes the open function. This instruction causes the cpu to behave abnormally, and jumps to the exception vector entry: vector_swi to execute, after which the code will be triggered. Abnormal instructions to take out the parameters, and call the corresponding processing function based on this parameter! Sys_open, sys_read, sys_write these functions are placed in an array, which is based on the val value of the sys_open function to find the index!

That is a bit messy, we have to reason: app call open-"swi #val-" throw cpu exception - "jump to the exception vector entry-" according to the instruction that caused the exception to call the corresponding processing function!

Then we need to implement two points when we make system calls:

1, write an application function: swi #val

2, in the kernel inside sys_xxx write a function, into the array!

The former is used to throw an exception, the latter is used for concrete realization!

Second, to achieve

1, the kernel function

(1) Add an item at the end of the CALL() list in the arch/arm/kernel/call.S file, such as: CALL(sys_hello)

Here is used to call sys_hello

(2) Add the following code in fs/read_write.c file:

Asmlinkage void sys_hello(const char __user * buf, size_t count)

{

Char ker_buf[100];

If(buf)

{

// The goal is to copy data from user space to kernel space, failing to return the number of bytes that were not copied, successfully returning 0

Third, steps

1, modify the application's executable file, replace the code of a place for the swi val

2, the implementation of the program

3, enter sys_hello-> print information in sys_hello -> execute the original instruction -> return

Fourth, the specific realization

Our application is:

//file:test_sc.c

#include

Int cnt = 0;

Void C(void)

{

Int i = 0;

While (1)

{

Printf("Hello, cnt = %d, i = %d", cnt, i);

Cnt++;

i = i + 2;

Sleep(5);

}

}

Void B(void)

{

C();

}

Void A(void)

{

B();

}

Int main(int argc, char **argv)

{

A();

Return 0;

}

Specific steps:

(1) compile: arm-linux-gcc test_sc.c -o test_sc

(2) Disassembler: arm-linux-objdump -D test_sc > test_sc.dis

(3) We open the above executable and disassembled files

For example, if we want to breakpoint at the i=i+2; point of the C function, we first find the corresponding instruction in the disassembly file:

84d4: e2833002 add r3, r3, #2 ; 0x2

Among them: e2833002 is a machine code, which is what we need!

We go to the executable file and search for the machine code. The corresponding machine code in the executable file should be: 02 30 83 e2

We changed this machine code to the machine code of the swi instruction!

We can disassemble the files in the previous section, and then get the swi machine code: ef900160

(4) After the above modification, when the program is executed to i=i+2; this instruction will generate a system call and finally execute the sys_hello function.

Inside the sys_hello function, we can do the most necessary work. The specific procedure is as follows:
Self-writing system call debug application process

You also need to change the function declaration in the file include/linux/syscalls.h to: asmlinkage void sys_hello(const char __user * buf, int count);

(5) compile the kernel, start with a new kernel

(6) Run the test program (before modifying the test program's permission: chmod 777 test_sc_swi), the output information is as follows:

Hello, cnt = 0, i = 0

Sys_hello: cnt = 1

Sys_hello: i = 0

Hello, cnt = 1, i = 2

Sys_hello: cnt = 2

Sys_hello: i = 2

Hello, cnt = 2, i = 4

Sys_hello: cnt = 3

Sys_hello: i = 4

Test success!

The debugging method described in this section is rather obscure and generally not used!

Line Array

Line array sound is a speaker system, and its technology and manufacturing have been developing steadily for many years. Recently, the situation has changed, and linear array speaker systems have appeared at many major sports events and large performances in the world.Linear array is a group of radiating elements arranged in a straight line and closely spaced, and has the same amplitude and phase. Through linear transmission, the transmission distance is increased and the attenuation during sound transmission is reduced.The advantages of linear array sound reinforcement systems are obvious.

(1) Due to the characteristics of the linear array, the directivity in the vertical plane of the main axis is a narrow beam, and the energy superposition can be radiated at a long distance. The lower end of the curved part of the linear column covers the near area, forming a coverage from near to far.(2) The improvement of the linear array amplifier is more in line with the requirements of technology, process and installation. The middle high-frequency part is more special, 2 (JBL) or 3 (V) tweeter outlets are connected together fJ2j, JBL company called it a sound wave generator, E-V company called it a plane wave generator. According to the analysis with MAPP software, the directivity of the linear array becomes more and more uniform with the increase of frequency. When a certain frequency is reached, such as 1000Hz, the directivity is radial, that is, the flap appears in the directivity map. At this time, the acoustic waveformer composed of the tweeter comes into play, so that the high-frequency directivity is superimposed. (3) Linear arrays cannot ignore mutual interference, and linear arrays themselves do not improve sound quality.

Our company's line array products not only have high quality and competitive prices, is a Chinese supplier trusted by buyers all over the world market, choose us and you have chosen a bright and brilliant future

Line Array,J8 Line Array,Portable Line Array System,Line Array Speakers,Linear Array Speaker Systems

NINGBO LOUD&CLEAR ELECTRONICS CO.,LIMITED , https://www.loudclearaudio.com

Posted on