The use of information in the core mmap of the internal components of the computer

                                           The mmap function is very important, alsa drives uac uvc audio and video and this entire application becomes a process, this function also plays a key role.         

root@instance-tau7o2q5:~/app_modules# strace  ./a.out .
execve("./a.out", ["./a.out", "."], 0x7ffc78e587b8 /* 27 vars */) = 0
brk(NULL)                               = 0x559be8915000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=46616, ...}) = 0
mmap(NULL, 46616, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f4f4d50d000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\34\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2030544, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f4f4d50b000
mmap(NULL, 4131552, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f4f4cf01000
mprotect(0x7f4f4d0e8000, 2097152, PROT_NONE) = 0
mmap(0x7f4f4d2e8000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f4f4d2e8000
mmap(0x7f4f4d2ee000, 15072, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f4f4d2ee000
close(3)                                = 0
arch_prctl(ARCH_SET_FS, 0x7f4f4d50c4c0) = 0
mprotect(0x7f4f4d2e8000, 16384, PROT_READ) = 0
mprotect(0x559be7d71000, 4096, PROT_READ) = 0
mprotect(0x7f4f4d519000, 4096, PROT_READ) = 0
munmap(0x7f4f4d50d000, 46616)           = 0
openat(AT_FDCWD, "./file_mmap", O_RDWR|O_CREAT, 0600) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=294, ...}) = 0
mmap(NULL, 294, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0x7f4f4d518000
close(3)                                = 0
munmap(0x7f4f4d518000, 294)             = 0
exit_group(0)                           = ?
+++ exited with 0 +++

                           Did a file modification operation

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>


struct Card_Messge
{
   char number1;
   char number2;
   char number3;
   char number4;
   char number5;

};

struct Card_Messge* Card ;
int main(int argc, char *argv[])
{
    int fd;
    char *buf;
    off_t len;
    struct stat sb;
    char *fname = "./file_mmap";
 
    fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
    if (fd == -1)
    {
        perror("open");
        return 1;
    }
    if (fstat(fd, &sb) == -1)
    {
        perror("fstat");
        return 1;
    }
 
    buf = mmap(0, sb.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
    if (buf == MAP_FAILED)
    {
        perror("mmap");
        return 1;
    }
    
    Card  = (struct Card_Messge*)buf;
    
    if (close(fd) == -1)
    {
        perror("close");
        return 1;
    }
 
    for (len = 0; len < sb.st_size; ++len)
    {
        buf[len] = toupper(buf[len]);
        /*putchar(buf[len]);*/
    }
    
    buf[0] = '1';
    buf[1] = '2';
    buf[2] = '3';
    buf[3] = '4';
    
    
    Card->number1 = 'a';
    Card->number2 = 'b';
    Card->number3 = 'c';
    Card->number4 = 'd';
    
 
    if (munmap(buf, sb.st_size) == -1)
    {
        perror("munmap");
        return 1;
    }
    return 0;


                                          

Guess you like

Origin www.cnblogs.com/nowroot/p/12689045.html