Home > Blockchain >  How can I find the corresponding .h file which includes the "cacheflush" function?
How can I find the corresponding .h file which includes the "cacheflush" function?

Time:11-18

I tried to use the cacheflush function in my Linux X86 computer. However, while the man pages states that the function can be found in the ".h" files <sys/cachectl.h> <asm/cachectl.h> or <asm-generic/cachectl.h>, my GCC compiler cannot found these files.

What can I do? i.e., how can I include the function in my program so that GCC will recognize it?

CodePudding user response:

I'm not sure, but read man cacheflush, I think you can't.

Note: On some architectures, there is no glibc wrapper for this system call; see NOTES.

Architecture-specific variants Glibc provides a wrapper for this system call, with the prototype shown in SYNOPSIS, for the following architectures: ARC, CSKY, MIPS, and NIOS2.

On some other architectures, Linux provides this system call, with different arguments:

M68K:

  int cacheflush(unsigned long addr, int scope, int cache,
                 unsigned long len);

SH:

  int cacheflush(unsigned long addr, unsigned long len, int op);

NDS32:

  int cacheflush(unsigned int start, unsigned int end, int cache);

On the above architectures, glibc does not provide a wrapper for this system call; call it using syscall(2).

If I understand well, glic does only provide cacheflush for 4 architectures.


If you really want to call this function, gcc specifically provide __builtin___clear_cache() (look for it in man page), but again, that won't be portable to other compilers.

CodePudding user response:

You can simply search for cacheflush functions in headers file with a grep : grep -rin cacheflush /usr/include

Depending on your compiler, headers files can be located in /opt/path/to/your/compiler, check include path given to your linker.

  • Related