#include<gnu/libc-version.h>
#include<sys/syscall.h>
#include<sys/types.h>
#include<iostream>
#include<signal.h>
using namespace std;
int main(){
//gnu_get_libc_version() returns a string that identifies the
//glibc version available on the system.
cout << "The GNU libc version is " << gnu_get_libc_version() << endl;
// process id tid is thread identifier
// look inside sys/syscall.h for System Call Numbers
pid_t tid; //pid_t is of type integer
tid = syscall(SYS_gettid); // make a system call to get the process id
cout << "The Current PID is: " << tid << endl;
//can also get by calling getpid() function from signal.h
cout << "The Current PID is: " << getpid() << endl;
// Can get current UserID by using:
int uid = syscall(SYS_getuid);
cout << "It is being run by user with ID: " << uid << endl;
// or getting the value from syscalls.kernelgrok.com
uid = syscall(0xc7);
cout << "It is being run by user with ID: " << uid << endl;
return 0;
}
On Tue, 8 Sep 2020 04:12:05 -0700 (PDT), in
gmane.comp.hardware.beagleboard.user Pavel Yermolenko
<py.ohayo-FOWRGOYEGZlyDzI6CaY1VQ@public.gmane.org> wrote:
>Hello,
>
>Here is an example from chapter 5 of the book "Explore BeagleBone" by Derek
>Molloy:
First or second edition? I don't find your (following) example in the
second edition -- though there /is/ a program using syscall
>
>debian@beaglebone:~/exploringbb/chp05/syscall$ g++ syscall.cpp -o syscall
>syscall.cpp: In function ‘int main()’:
>syscall.cpp:22:10: error: ‘syscall’ was not declared in this scope
Note that your source file appears to be named syscall, along with the
output executable. That may be confusing the compiler some. Especially
since the header file that appears to provide the function is syscall.h
(which could imply there is a syscall.c (or .cpp) somewhere in the system.
The example in the second edition is a file named glibcTest.cpp in a
DIRECTORY named syscall.
>Indeed, I searched for syscall declaration in the toolchain ... and didn't
>find it:
>
>debian@beaglebone:~/exploringbb/chp05/syscall$ sudo grep -rn
>/usr/include/arm-linux-gnueabihf/ -e "syscall("
The odds are good that there is a space between syscall and the (
debian@beaglebone:~$ sudo find / -iname "syscall.h"
/usr/include/syscall.h
/usr/include/arm-linux-gnueabihf/sys/syscall.h
/usr/include/arm-linux-gnueabihf/bits/syscall.h
debian@beaglebone:~$
Though it turns out to be a definition in /usr/include/unistd.h which is
invoked by /sys/syscall.h (itself invoked by /syscall.h)
#ifdef __USE_MISC
/* Invoke `system call' number SYSNO, passing it the remaining arguments.
This is completely system-dependent, and not often useful.
In Unix, `syscall' sets `errno' for all errors and most calls return -1
for errors; in many systems you cannot pass arguments or get return
values for all system calls (`pipe', `fork', and `getppid' typically
among them).
In Mach, all system calls take normal arguments and always return an
error code (zero for success). */
extern long int syscall (long int __sysno, ...) __THROW;
#endif /* Use misc. */
(NOTE the space I predicted)
debian@beaglebone:~$ sudo grep -rn /usr/include/arm-linux-gnueabihf/ -e
"syscall ("
/usr/include/arm-linux-gnueabihf/asm/unistd-common.h:4:#define
__NR_restart_syscall (__NR_SYSCALL_BASE + 0)
/usr/include/arm-linux-gnueabihf/asm/unistd-oabi.h:14:#define __NR_syscall
(__NR_SYSCALL_BASE + 113)
debian@beaglebone:~$ sudo grep -rn /usr/include/ -e "syscall ("
/usr/include/arm-linux-gnueabihf/asm/unistd-common.h:4:#define
__NR_restart_syscall (__NR_SYSCALL_BASE + 0)
/usr/include/arm-linux-gnueabihf/asm/unistd-oabi.h:14:#define __NR_syscall
(__NR_SYSCALL_BASE + 113)
/usr/include/unistd.h:1056:extern long int syscall (long int __sysno, ...)
__THROW;
debian@beaglebone:~$
--
Dennis L Bieber
On Tue, 08 Sep 2020 10:24:06 -0400, in gmane.comp.hardware.beagleboard.user
Dennis Lee Bieber <dennis.l.bieber-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
On Tuesday, September 8, 2020 at 4:35:43 PM UTC+2, Dennis Bieber wrote:
On Tue, 08 Sep 2020 10:24:06 -0400, in gmane.comp.hardware.beagleboard.user
Dennis Lee Bieber <dennis.l.bieber-Re5...@public.gmane.org>
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/d28ca569-05a8-4d40-845b-385f89105ea2o%40googlegroups.com.
What worked for you? I cloned the code from the link you provided and the syscall code has build errors.What I did to clear this out was:1. In "syscall.cpp", I added 'unistd.h' to the includes:Ex:#include <unistd.h>2. I did the same in callchmod.cpp,3. Run ./buildApparently there is an issue with unistd.h not being added in certain areas with gcc.Cheers,Jon
On Tue, Sep 8, 2020 at 9:05 AM Pavel Yermolenko <py....@sunrise.ch> wrote:
On Tuesday, September 8, 2020 at 4:35:43 PM UTC+2, Dennis Bieber wrote:
On Tue, 08 Sep 2020 10:24:06 -0400, in gmane.comp.hardware.beagleboard.user
Dennis Lee Bieber <dennis.l.bieber-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To unsubscribe from this group and stop receiving emails from it, send an email to beagl...@googlegroups.com.
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/g3thlf15sthqjajpiia5q64opdadr915vp%404ax.com.
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/CAOCHtYjC3jsb-F%2BJoCWkNT0aKRxtKFxO75AuJD%2BcT8KSvyn4cQ%40mail.gmail.com.