blob: 26164d832abd2d7d8bb72e07469a0797b718e6fe [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 Felker0b44a032011-02-12 00:22:29 -050025 pid_t tid, pid;
Rich Felker0b2006c2011-02-15 03:24:58 -050026 int tsd_used, errno_val, *errno_ptr;
Rich Felkerfeee9892011-04-17 11:43:03 -040027 volatile uintptr_t cp_sp, cp_ip;
28 volatile int cancel, canceldisable, cancelasync;
Rich Felker0b44a032011-02-12 00:22:29 -050029 unsigned char *map_base;
30 size_t map_size;
31 void *start_arg;
32 void *(*start)(void *);
33 void *result;
Rich Felker0b44a032011-02-12 00:22:29 -050034 int detached;
35 int exitlock;
Rich Felker0b44a032011-02-12 00:22:29 -050036 struct __ptcb *cancelbuf;
37 void **tsd;
Rich Felker0b44a032011-02-12 00:22:29 -050038 pthread_attr_t attr;
Rich Felker5fcebcd2011-03-10 18:31:37 -050039 volatile int dead;
Rich Felker047e4342011-03-17 20:41:37 -040040 struct {
41 void **head;
42 long off;
43 void *pending;
44 } robust_list;
Rich Felkerbf619d82011-03-29 12:58:22 -040045 int unblock_cancel;
Rich Felker82171d62011-04-09 02:23:33 -040046 int delete_timer;
Rich Felker11c531e2011-05-30 01:41:23 -040047 locale_t locale;
Rich Felker7779dbd2011-06-14 01:35:51 -040048 int killlock;
Rich Felker0b44a032011-02-12 00:22:29 -050049};
50
Rich Felker70c31c72011-03-29 10:05:57 -040051struct __timer {
Rich Felkerbf619d82011-03-29 12:58:22 -040052 int timerid;
Rich Felkerbf619d82011-03-29 12:58:22 -040053 pthread_t thread;
Rich Felker70c31c72011-03-29 10:05:57 -040054};
55
Rich Felkere8827562011-02-17 17:16:20 -050056#define __SU (sizeof(size_t)/sizeof(int))
57
58#define _a_stacksize __u.__s[0]
59#define _a_guardsize __u.__s[1]
60#define _a_detach __u.__i[2*__SU+0]
61#define _m_type __u.__i[0]
62#define _m_lock __u.__i[1]
63#define _m_waiters __u.__i[2]
Rich Felker93cc9862011-03-17 13:17:15 -040064#define _m_prev __u.__p[3]
65#define _m_next __u.__p[4]
66#define _m_count __u.__i[5]
Rich Felkere8827562011-02-17 17:16:20 -050067#define _c_block __u.__i[0]
Rich Felker5fd4a982011-03-07 17:39:13 -050068#define _c_clock __u.__i[1]
Rich Felker50304f22011-08-03 10:21:32 -040069#define _rw_lock __u.__i[0]
70#define _rw_waiters __u.__i[1]
Rich Felkerf16a3082011-05-06 20:00:59 -040071#define _b_inst __u.__p[0]
72#define _b_limit __u.__i[2]
73#define _b_lock __u.__i[3]
74#define _b_waiters __u.__i[4]
Rich Felkere8827562011-02-17 17:16:20 -050075
Rich Felker7b2dd222011-02-15 03:56:52 -050076#include "pthread_arch.h"
Rich Felker0b44a032011-02-12 00:22:29 -050077
Rich Felker99b8a252011-05-07 23:23:58 -040078#define SIGTIMER 32
79#define SIGCANCEL 33
Rich Felkeracb04802011-07-29 22:59:44 -040080#define SIGSYNCCALL 34
Rich Felker99b8a252011-05-07 23:23:58 -040081
Rich Felker4c4e22d2011-05-07 23:37:10 -040082#define SIGPT_SET ((sigset_t *)(unsigned long [1+(sizeof(long)==4)]){ \
Rich Felkerf09e78d2011-06-13 20:37:52 -040083 [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) })
Rich Felker4c4e22d2011-05-07 23:37:10 -040084#define SIGTIMER_SET ((sigset_t *)(unsigned long [1+(sizeof(long)==4)]){ \
85 0x80000000 })
Rich Felker0b44a032011-02-12 00:22:29 -050086
Rich Felkerdba68bf2011-07-30 08:02:14 -040087pthread_t __pthread_self_init(void);
88
Rich Felker3f72cda2011-09-18 10:14:37 -040089int __clone(int (*)(void *), void *, int, void *, ...);
Rich Felker7b2dd222011-02-15 03:56:52 -050090int __set_thread_area(void *);
Rich Felker0b44a032011-02-12 00:22:29 -050091int __libc_sigaction(int, const struct sigaction *, struct sigaction *);
92int __libc_sigprocmask(int, const sigset_t *, sigset_t *);
93void __lock(volatile int *);
94void __unmapself(void *, size_t);
95
Rich Felkerec381af2011-08-02 21:11:36 -040096int __timedwait(volatile int *, int, clockid_t, const struct timespec *, void (*)(void *), void *, int);
Rich Felker0b44a032011-02-12 00:22:29 -050097void __wait(volatile int *, volatile int *, int, int);
98void __wake(volatile int *, int, int);
99
Rich Felkeracb04802011-07-29 22:59:44 -0400100void __synccall_lock();
101void __synccall_unlock();
Rich Felkerb2486a82011-04-06 20:27:07 -0400102
Rich Felker0b44a032011-02-12 00:22:29 -0500103#define DEFAULT_STACK_SIZE (16384-PAGE_SIZE)
104#define DEFAULT_GUARD_SIZE PAGE_SIZE
105
106#endif