Search code examples
c++prototypeglibc

arch_prtcl C++ prototype


For arch_prctl the man page states:

As of version 2.7, glibc provides no prototype for arch_prctl(). You have to declare it yourself for now. This may be fixed in future glibc versions.

Compiling a C programm with clang works well but throws a warning

warning: implicit declaration of function 'arch_prctl' is invalid in C99

However trying to compile a C++ with clang++ fails with

error: use of undeclared identifier 'arch_prctl'

So, how can I declare the required prototype myself?


Solution

  • It took me some time to realise, that glibc probably does not support arch_prctl at all. So one has to do the coresponding syscall yourself:

    #include <unistd.h>
    #include <sys/syscall.h>
    #include <sys/types.h>
    
    int arch_prctl(int code, unsigned long addr)
    {    
        return syscall(SYS_arch_prctl, code, addr);
    }