blob: 56b92b22cca20d9fd1b4b91ad818d34e8d9ef8d5 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#ifndef _PTHREAD_IMPL_H
2#define _PTHREAD_IMPL_H
3
4#include <pthread.h>
5#include <sched.h>
6#include <signal.h>
7#include <unistd.h>
8#include <sys/mman.h>
9#include <errno.h>
10#include <limits.h>
11#include <inttypes.h>
12#include <setjmp.h>
13#include <string.h>
14#include <time.h>
Rich Felker11c531e2011-05-30 01:41:23 -040015#include <locale.h>
Rich Felker0b44a032011-02-12 00:22:29 -050016#include "libc.h"
17#include "syscall.h"
18#include "atomic.h"
19#include "futex.h"
20
21#define pthread __pthread
22
23struct pthread {
Rich Felker0b2006c2011-02-15 03:24:58 -050024 struct pthread *self;
Rich Felker58aa5f42012-05-03 20:42:45 -040025 void *dtv, *unused1, *unused2;
26 uintptr_t sysinfo;
27 uintptr_t canary;
Rich Felker0b44a032011-02-12 00:22:29 -050028 pid_t tid, pid;
Rich Felker0b2006c2011-02-15 03:24:58 -050029 int tsd_used, errno_val, *errno_ptr;
Rich Felkerfeee9892011-04-17 11:43:03 -040030 volatile int cancel, canceldisable, cancelasync;
Rich Felkerbbbe87e2012-07-12 11:23:43 -040031 int detached;
Rich Felker0b44a032011-02-12 00:22:29 -050032 unsigned char *map_base;
33 size_t map_size;
34 void *start_arg;
35 void *(*start)(void *);
36 void *result;
Rich Felker0b44a032011-02-12 00:22:29 -050037 struct __ptcb *cancelbuf;
38 void **tsd;
Rich Felker0b44a032011-02-12 00:22:29 -050039 pthread_attr_t attr;
Rich Felker5fcebcd2011-03-10 18:31:37 -050040 volatile int dead;
Rich Felker047e4342011-03-17 20:41:37 -040041 struct {
42 void **head;
43 long off;
44 void *pending;
45 } robust_list;
Rich Felkerbf619d82011-03-29 12:58:22 -040046 int unblock_cancel;
Rich Felker82171d62011-04-09 02:23:33 -040047 int delete_timer;
Rich Felker11c531e2011-05-30 01:41:23 -040048 locale_t locale;
Rich Felkerbbbe87e2012-07-12 11:23:43 -040049 int killlock[2];
50 int exitlock[2];
Rich Felker0b44a032011-02-12 00:22:29 -050051};
52
Rich Felker70c31c72011-03-29 10:05:57 -040053struct __timer {
Rich Felkerbf619d82011-03-29 12:58:22 -040054 int timerid;
Rich Felkerbf619d82011-03-29 12:58:22 -040055 pthread_t thread;
Rich Felker70c31c72011-03-29 10:05:57 -040056};
57
Rich Felkere8827562011-02-17 17:16:20 -050058#define __SU (sizeof(size_t)/sizeof(int))
59
60#define _a_stacksize __u.__s[0]
61#define _a_guardsize __u.__s[1]
Rich Felker819006a2012-06-09 19:53:29 -040062#define _a_stackaddr __u.__s[2]
63#define _a_detach __u.__i[3*__SU+0]
Rich Felkere8827562011-02-17 17:16:20 -050064#define _m_type __u.__i[0]
65#define _m_lock __u.__i[1]
66#define _m_waiters __u.__i[2]
Rich Felker93cc9862011-03-17 13:17:15 -040067#define _m_prev __u.__p[3]
68#define _m_next __u.__p[4]
69#define _m_count __u.__i[5]
Rich Felkercba4e1c2011-09-25 02:38:03 -040070#define _c_mutex __u.__p[0]
Rich Felker729d6362011-09-26 00:25:13 -040071#define _c_seq __u.__i[2]
Rich Felkercba4e1c2011-09-25 02:38:03 -040072#define _c_waiters __u.__i[3]
73#define _c_clock __u.__i[4]
Rich Felker729d6362011-09-26 00:25:13 -040074#define _c_lock __u.__i[5]
75#define _c_lockwait __u.__i[6]
Rich Felker1fa05212011-09-26 12:54:28 -040076#define _c_waiters2 __u.__i[7]
Rich Felker5a2e1802011-10-02 22:58:28 -040077#define _c_destroy __u.__i[8]
Rich Felker50304f22011-08-03 10:21:32 -040078#define _rw_lock __u.__i[0]
79#define _rw_waiters __u.__i[1]
Rich Felker60164572011-09-27 13:50:29 -040080#define _b_lock __u.__i[0]
81#define _b_waiters __u.__i[1]
Rich Felkerf16a3082011-05-06 20:00:59 -040082#define _b_limit __u.__i[2]
Rich Felker60164572011-09-27 13:50:29 -040083#define _b_count __u.__i[3]
Rich Felker9cee9302011-09-28 18:57:18 -040084#define _b_waiters2 __u.__i[4]
Rich Felker9ae1cf62012-05-21 22:51:30 -040085#define _b_inst __u.__p[3]
Rich Felkere8827562011-02-17 17:16:20 -050086
Rich Felker7b2dd222011-02-15 03:56:52 -050087#include "pthread_arch.h"
Rich Felker0b44a032011-02-12 00:22:29 -050088
Rich Felker99b8a252011-05-07 23:23:58 -040089#define SIGTIMER 32
90#define SIGCANCEL 33
Rich Felkeracb04802011-07-29 22:59:44 -040091#define SIGSYNCCALL 34
Rich Felker99b8a252011-05-07 23:23:58 -040092
Rich Felker2f437042012-08-09 22:52:13 -040093#define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 })
94#define SIGPT_SET \
95 ((sigset_t *)(const unsigned long [__SYSCALL_SSLEN/sizeof(long)]){ \
Rich Felkerf09e78d2011-06-13 20:37:52 -040096 [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) })
Rich Felker2f437042012-08-09 22:52:13 -040097#define SIGTIMER_SET \
98 ((sigset_t *)(const unsigned long [__SYSCALL_SSLEN/sizeof(long)]){ \
Rich Felker4c4e22d2011-05-07 23:37:10 -040099 0x80000000 })
Rich Felker0b44a032011-02-12 00:22:29 -0500100
Rich Felkerdba68bf2011-07-30 08:02:14 -0400101pthread_t __pthread_self_init(void);
102
Rich Felker3f72cda2011-09-18 10:14:37 -0400103int __clone(int (*)(void *), void *, int, void *, ...);
Rich Felker7b2dd222011-02-15 03:56:52 -0500104int __set_thread_area(void *);
Rich Felker0b44a032011-02-12 00:22:29 -0500105int __libc_sigaction(int, const struct sigaction *, struct sigaction *);
106int __libc_sigprocmask(int, const sigset_t *, sigset_t *);
107void __lock(volatile int *);
108void __unmapself(void *, size_t);
109
Rich Felkerec381af2011-08-02 21:11:36 -0400110int __timedwait(volatile int *, int, clockid_t, const struct timespec *, void (*)(void *), void *, int);
Rich Felker0b44a032011-02-12 00:22:29 -0500111void __wait(volatile int *, volatile int *, int, int);
112void __wake(volatile int *, int, int);
113
Rich Felkeracb04802011-07-29 22:59:44 -0400114void __synccall_lock();
115void __synccall_unlock();
Rich Felkerb2486a82011-04-06 20:27:07 -0400116
Rich Felker13b36452012-06-02 20:15:37 -0400117#define DEFAULT_STACK_SIZE 81920
Rich Felker0b44a032011-02-12 00:22:29 -0500118#define DEFAULT_GUARD_SIZE PAGE_SIZE
119
120#endif