mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] Add gettid and tgkill syscall wrappers.
@ 2019-08-01 20:31 James Y Knight
  2019-08-02 20:25 ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: James Y Knight @ 2019-08-01 20:31 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #1.2: Type: text/html, Size: 26 bytes --]

[-- Attachment #2: 0001-Add-gettid-and-tgkill-syscall-wrappers.patch --]
[-- Type: text/x-patch, Size: 1882 bytes --]

From bdb4f28edece4b81e99becf4ffcdc69449211764 Mon Sep 17 00:00:00 2001
From: James Y Knight <jyknight@google.com>
Date: Thu, 1 Aug 2019 12:43:08 -0400
Subject: [PATCH] Add gettid and tgkill syscall wrappers.

---
 include/signal.h   | 1 +
 include/unistd.h   | 1 +
 src/linux/gettid.c | 8 ++++++++
 src/linux/tgkill.c | 8 ++++++++
 4 files changed, 18 insertions(+)
 create mode 100644 src/linux/gettid.c
 create mode 100644 src/linux/tgkill.c

diff --git a/include/signal.h b/include/signal.h
index 5c48cb83..6843323a 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -257,6 +257,7 @@ void (*bsd_signal(int, void (*)(int)))(int);
 int sigisemptyset(const sigset_t *);
 int sigorset (sigset_t *, const sigset_t *, const sigset_t *);
 int sigandset(sigset_t *, const sigset_t *, const sigset_t *);
+int tgkill(pid_t, pid_t, int);
 
 #define SA_NOMASK SA_NODEFER
 #define SA_ONESHOT SA_RESETHAND
diff --git a/include/unistd.h b/include/unistd.h
index 9485da7a..4764f157 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -188,6 +188,7 @@ char *get_current_dir_name(void);
 int syncfs(int);
 int euidaccess(const char *, int);
 int eaccess(const char *, int);
+pid_t gettid(void);
 #endif
 
 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
diff --git a/src/linux/gettid.c b/src/linux/gettid.c
new file mode 100644
index 00000000..6490101d
--- /dev/null
+++ b/src/linux/gettid.c
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE
+#include <unistd.h>
+#include "syscall.h"
+
+pid_t gettid(void)
+{
+	return __syscall(SYS_gettid);
+}
diff --git a/src/linux/tgkill.c b/src/linux/tgkill.c
new file mode 100644
index 00000000..97365d58
--- /dev/null
+++ b/src/linux/tgkill.c
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE
+#include <signal.h>
+#include "syscall.h"
+
+int tgkill(pid_t pid, pid_t tid, int sig)
+{
+	return syscall(SYS_tgkill, pid, tid, sig);
+}
-- 
2.22.0.770.g0f2c4a37fd-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add gettid and tgkill syscall wrappers.
  2019-08-01 20:31 [PATCH] Add gettid and tgkill syscall wrappers James Y Knight
@ 2019-08-02 20:25 ` Rich Felker
  2019-08-02 21:46   ` Szabolcs Nagy
  2019-08-07 16:16   ` Florian Weimer
  0 siblings, 2 replies; 4+ messages in thread
From: Rich Felker @ 2019-08-02 20:25 UTC (permalink / raw)
  To: musl

On Thu, Aug 01, 2019 at 04:31:11PM -0400, James Y Knight wrote:
> 

> From bdb4f28edece4b81e99becf4ffcdc69449211764 Mon Sep 17 00:00:00 2001
> From: James Y Knight <jyknight@google.com>
> Date: Thu, 1 Aug 2019 12:43:08 -0400
> Subject: [PATCH] Add gettid and tgkill syscall wrappers.
> 
> ---
>  include/signal.h   | 1 +
>  include/unistd.h   | 1 +
>  src/linux/gettid.c | 8 ++++++++
>  src/linux/tgkill.c | 8 ++++++++
>  4 files changed, 18 insertions(+)
>  create mode 100644 src/linux/gettid.c
>  create mode 100644 src/linux/tgkill.c
> 
> diff --git a/include/signal.h b/include/signal.h
> index 5c48cb83..6843323a 100644
> --- a/include/signal.h
> +++ b/include/signal.h
> @@ -257,6 +257,7 @@ void (*bsd_signal(int, void (*)(int)))(int);
>  int sigisemptyset(const sigset_t *);
>  int sigorset (sigset_t *, const sigset_t *, const sigset_t *);
>  int sigandset(sigset_t *, const sigset_t *, const sigset_t *);
> +int tgkill(pid_t, pid_t, int);
>  
>  #define SA_NOMASK SA_NODEFER
>  #define SA_ONESHOT SA_RESETHAND
> diff --git a/include/unistd.h b/include/unistd.h
> index 9485da7a..4764f157 100644
> --- a/include/unistd.h
> +++ b/include/unistd.h
> @@ -188,6 +188,7 @@ char *get_current_dir_name(void);
>  int syncfs(int);
>  int euidaccess(const char *, int);
>  int eaccess(const char *, int);
> +pid_t gettid(void);
>  #endif
>  
>  #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
> diff --git a/src/linux/gettid.c b/src/linux/gettid.c
> new file mode 100644
> index 00000000..6490101d
> --- /dev/null
> +++ b/src/linux/gettid.c
> @@ -0,0 +1,8 @@
> +#define _GNU_SOURCE
> +#include <unistd.h>
> +#include "syscall.h"
> +
> +pid_t gettid(void)
> +{
> +	return __syscall(SYS_gettid);
> +}
> diff --git a/src/linux/tgkill.c b/src/linux/tgkill.c
> new file mode 100644
> index 00000000..97365d58
> --- /dev/null
> +++ b/src/linux/tgkill.c
> @@ -0,0 +1,8 @@
> +#define _GNU_SOURCE
> +#include <signal.h>
> +#include "syscall.h"
> +
> +int tgkill(pid_t pid, pid_t tid, int sig)
> +{
> +	return syscall(SYS_tgkill, pid, tid, sig);
> +}
> -- 
> 2.22.0.770.g0f2c4a37fd-goog

Is pid_t the right type for this? Fundamentally the futex interface
imposes a requirement that tids fit in 29 bits of int. pid_t *is* int
anyway, but it's more a matter of figuring out what the right semantic
type for this is.

I also question whether tgkill should be a supported API. The idea of
being able to address threads of other processes is dubious. Before we
start adding these, I think we should think about which ones make
sense as APIs that applications can safely use.

Also, pthread_gettid_np or something like that is probably important
to being able to use any interfaces involving tids; otherwise you can
only address yourself without explicit communication with a thread to
query its tid.

Is there a list of which interfaces glibc will be adding and their
rationale?

Rich


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add gettid and tgkill syscall wrappers.
  2019-08-02 20:25 ` Rich Felker
@ 2019-08-02 21:46   ` Szabolcs Nagy
  2019-08-07 16:16   ` Florian Weimer
  1 sibling, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2019-08-02 21:46 UTC (permalink / raw)
  To: musl

* Rich Felker <dalias@libc.org> [2019-08-02 16:25:16 -0400]:
> On Thu, Aug 01, 2019 at 04:31:11PM -0400, James Y Knight wrote:
> > +++ b/src/linux/tgkill.c
> > @@ -0,0 +1,8 @@
> > +#define _GNU_SOURCE
> > +#include <signal.h>
> > +#include "syscall.h"
> > +
> > +int tgkill(pid_t pid, pid_t tid, int sig)
> > +{
> > +	return syscall(SYS_tgkill, pid, tid, sig);
> > +}
> > -- 
> > 2.22.0.770.g0f2c4a37fd-goog
> 
> Is pid_t the right type for this? Fundamentally the futex interface
> imposes a requirement that tids fit in 29 bits of int. pid_t *is* int
> anyway, but it's more a matter of figuring out what the right semantic
> type for this is.

https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/bits/signal_ext.h

> I also question whether tgkill should be a supported API. The idea of
> being able to address threads of other processes is dubious. Before we
> start adding these, I think we should think about which ones make
> sense as APIs that applications can safely use.

i think the idea is that there will be thin wrappers for linux syscalls
even if they may be misused.

> Also, pthread_gettid_np or something like that is probably important
> to being able to use any interfaces involving tids; otherwise you can
> only address yourself without explicit communication with a thread to
> query its tid.

i dont think glibc has such api now.

> Is there a list of which interfaces glibc will be adding and their
> rationale?

not that i know of, the apis are added one by one with separate reviews.

https://sourceware.org/glibc/wiki/Consensus#WIP:_Kernel_syscalls_wrappers


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add gettid and tgkill syscall wrappers.
  2019-08-02 20:25 ` Rich Felker
  2019-08-02 21:46   ` Szabolcs Nagy
@ 2019-08-07 16:16   ` Florian Weimer
  1 sibling, 0 replies; 4+ messages in thread
From: Florian Weimer @ 2019-08-07 16:16 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

* Rich Felker:

> Is there a list of which interfaces glibc will be adding and their
> rationale?

No.  I will keep posting system call wrappers.  I cannot predict to
which there will be objections.  Once there is an objection (any
objection), it is currently not possible to add the wrapper because the
current glibc policies on overriding objections are unworkable for
various reasons.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-07 16:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01 20:31 [PATCH] Add gettid and tgkill syscall wrappers James Y Knight
2019-08-02 20:25 ` Rich Felker
2019-08-02 21:46   ` Szabolcs Nagy
2019-08-07 16:16   ` Florian Weimer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).