mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-20 22:23:16 +00:00
libc: support syscall(SYS_thr_self,...)
This syscall returns the thread ID / light-weight PID of the calling thread under FreeBSD. Issue #2791
This commit is contained in:
parent
ea6b4a0caf
commit
a6e0fdd505
@ -1,4 +1,19 @@
|
||||
/*
|
||||
* This file is just here to prevent a compiler warning about the missing include file.
|
||||
* On Genode, we do not support calling syscalls directly via a libc mechanism.
|
||||
* \brief Minimal support for FreeBSD-specific syscalls
|
||||
* \author Christian Helmuth
|
||||
* \date 2018-05-16
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__LIBC_GENODE__SYS__SYSCALL_H_
|
||||
#define _INCLUDE__LIBC_GENODE__SYS__SYSCALL_H_
|
||||
|
||||
#define SYS_thr_self 432 /* pid_t gettid() */
|
||||
|
||||
#endif /* _INCLUDE__LIBC_GENODE__SYS__SYSCALL_H_ */
|
||||
|
@ -16,7 +16,7 @@ SRC_CC = atexit.cc dummies.cc rlimit.cc sysctl.cc \
|
||||
plugin.cc plugin_registry.cc select.cc exit.cc environ.cc nanosleep.cc \
|
||||
pread_pwrite.cc readv_writev.cc poll.cc \
|
||||
libc_pdbg.cc vfs_plugin.cc rtc.cc dynamic_linker.cc signal.cc \
|
||||
socket_operations.cc task.cc socket_fs_plugin.cc
|
||||
socket_operations.cc task.cc socket_fs_plugin.cc syscall.cc
|
||||
|
||||
CC_OPT_sysctl += -Wno-write-strings
|
||||
|
||||
|
@ -755,6 +755,7 @@ sys_nerr R 4
|
||||
sys_nsig R 4
|
||||
sys_siglist D 256
|
||||
sys_signame D 256
|
||||
syscall T
|
||||
sysconf T
|
||||
sysctl T
|
||||
sysctlbyname T
|
||||
|
44
repos/libports/src/lib/libc/syscall.cc
Normal file
44
repos/libports/src/lib/libc/syscall.cc
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* \brief Minimal support for FreeBSD-specific syscalls
|
||||
* \author Christian Helmuth
|
||||
* \date 2018-05-16
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/thread.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
|
||||
static int sys_thr_self()
|
||||
{
|
||||
using Genode::addr_t;
|
||||
|
||||
addr_t const base = Genode::Thread::stack_area_virtual_base();
|
||||
addr_t const size = Genode::Thread::stack_virtual_size();
|
||||
addr_t const stack = (addr_t)Genode::Thread::myself()->stack_base();
|
||||
|
||||
return int((stack - base) / size + 1);
|
||||
}
|
||||
|
||||
|
||||
extern "C" int syscall(int nr, ...)
|
||||
{
|
||||
switch (nr) {
|
||||
case SYS_thr_self: return sys_thr_self();
|
||||
|
||||
default:
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
}
|
@ -24,6 +24,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -117,5 +120,22 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
pid_t const tid = syscall(SYS_thr_self);
|
||||
if (tid == -1) {
|
||||
printf("syscall(SYS_thr_self) returned %d (%s) - ERROR\n", tid, strerror(errno));
|
||||
++error_count;
|
||||
} else {
|
||||
printf("syscall(SYS_thr_self) returned %d\n", tid);
|
||||
}
|
||||
int const ret = syscall(0xffff);
|
||||
if (ret != -1) {
|
||||
printf("syscall(unknown) returned %d - ERROR\n", ret);
|
||||
++error_count;
|
||||
} else {
|
||||
printf("syscall(unknown) returned %d (%s)\n", ret, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
exit(error_count);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user