1. Register a hypercall call number first.
Xen/include/public/xen. h
# DEFINE _ hypervisor_kexec_op 37
+ # DEFINE _ hypervisor_print 38
2. Update the system call table
/Xen/ARCH/x86/x86_32/entry. s
Entry (hypercall_table)
. Long do_kexec_op
+. Long do_print_string
Entry (hypercall_args_table)
. Byte 2/* do_kexec_op */
+. Byte 1
3. Define the function header file
/Xen/include/asm-x86/hypercall. h
Extern int
Do_kexec (
Unsigned long op, unsigned arg1, xen_guest_handle (void) UARG );
+ Extern int
+ Do_print (void );
4. In/xen/ARCH/x86/traps. c
Add a global variable
Long mynr_page_fault = 0;
Count the number of times in the do_page_fault () function. After each execution, add 1 to mynr_page_fault.
Custom Functions
Int do_print (void)
{
Printk ("#################### test begin/N ");
Printk ("nr_page_fault: % LD/N", mynr_page_fault );
Return 1;
}
Then make DIST and make install to create the initialization boot disk.
5. edit a print. c file for testing in the user space.
# Include <stdio. h>
# Include <stdlib. h>
# Include <errno. h>
# Include <sys/IOCTL. h>
# Include <sys/types. h>
# Include <fcntl. h>
# Include <string. h>
# Include <xenctrl. h>
# Include <xen/sys/privcmd. h>
Int main ()
{
Int FD, RET;
Private_hypercall_t hcall = {
_ Hypervisor_print_string,
{0, 0, 0, 0}
};
FD = open ("/proc/xen/privcmd", o_rdwr );
If (FD <0)
{
Perror ("open ");
Exit (1 );
} Else
Printf ("FD = % d/N", FD );
Ret = IOCTL (FD, ioctl_private_hypercall, & hcall );
Printf ("ret = % d/N", RET );
}
6. Test
[Root @ locahost ~] Gcc-o a print. c
[Root @ locahost ~] ./
[Root @ locahost ~] Xm dm | tail-N 1