How to use syscall in C language

use syscall to call the function to report an error. The following code shows whether there is something wrong with my writing

-sharpinclude <stdio.h>
-sharpinclude <fcntl.h>
-sharpinclude <unistd.h>
-sharpinclude <sys/syscall.h>
-sharpinclude <sys/types.h>
-sharpinclude <unistd.h>
-sharpinclude <sys/mman.h>

int main(){    
    int size = 10;  
    int fd = open ("test.txt", O_RDONLY); 

    // //    
    char *f1 = (char *)  mmap( 0, size, PROT_READ, MAP_PRIVATE, fd, 0);
    printf("[1]  mmap result : %s", f1); 
    // //    
    char *f2 = (char *)  syscall(SYS_mmap, 0, size, PROT_READ, MAP_PRIVATE, fd, 0);
    printf("[2]  mmap result : %s", f2); 

    // int fd_ = syscall(SYS_open, "test.txt", 0);
    // printf("%d ----", fd_);
    return 0;
}

or can you provide a helloworld reference for syscall calling mmap. Thank you-sharp-sharp-sharp problem description

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

CPP c
Aug.29,2021

mmap2 is not mmap when the system call to mmap is called, so you should also use mmap2

    char *f2 = (char *)  syscall(SYS_mmap2, 0, size, PROT_READ, MAP_PRIVATE, fd, 0);
Menu