From a8db8d48a805c89d6f10593a37650122cae176b3 Mon Sep 17 00:00:00 2001
From: Dhruwat Bhagat <unitedronaldo@yahoo.com>
Date: Fri, 20 Jan 2012 19:10:40 -0500
Subject: [PATCH] Patch for pthread_attr_getguardsize
---
headers/posix/pthread.h | 6 ++++--
headers/private/libroot/pthread_private.h | 1 +
headers/private/system/thread_defs.h | 1 +
src/system/libroot/posix/pthread/pthread.cpp | 1 +
src/system/libroot/posix/pthread/pthread_attr.c | 13 +++++++++++++
5 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/headers/posix/pthread.h b/headers/posix/pthread.h
index cc5b900..b62bbd7 100644
a
|
b
|
extern int pthread_attr_getschedparam(const pthread_attr_t *attr,
|
185 | 185 | extern int pthread_attr_setschedparam(pthread_attr_t *attr, |
186 | 186 | const struct sched_param *param); |
187 | 187 | |
| 188 | extern int pthread_attr_getguardsize(const pthread_attr_t *attr, |
| 189 | size_t *guardsize); |
| 190 | |
188 | 191 | #if 0 /* Unimplemented attribute functions: */ |
189 | 192 | |
190 | 193 | /* [TPS] */ |
… |
… |
extern int pthread_attr_getschedpolicy(const pthread_attr_t *attr,
|
197 | 200 | extern int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy); |
198 | 201 | |
199 | 202 | /* [XSI] */ |
200 | | extern int pthread_attr_getguardsize(const pthread_attr_t *attr, |
201 | | size_t *guardsize); |
| 203 | |
202 | 204 | extern int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize); |
203 | 205 | |
204 | 206 | /* [TSA] */ |
diff --git a/headers/private/libroot/pthread_private.h b/headers/private/libroot/pthread_private.h
index f50bd28..1ddc00c 100644
a
|
b
|
typedef struct _pthread_attr {
|
40 | 40 | int32 detach_state; |
41 | 41 | int32 sched_priority; |
42 | 42 | size_t stack_size; |
| 43 | size_t guard_size; |
43 | 44 | } pthread_attr; |
44 | 45 | |
45 | 46 | typedef struct _pthread_rwlockattr { |
diff --git a/headers/private/system/thread_defs.h b/headers/private/system/thread_defs.h
index 9f1b527..5d43c90 100644
a
|
b
|
struct thread_creation_attributes {
|
50 | 50 | void* args2; |
51 | 51 | void* stack_address; |
52 | 52 | size_t stack_size; |
| 53 | size_t guard_size; |
53 | 54 | pthread_t pthread; |
54 | 55 | uint32 flags; |
55 | 56 | }; |
diff --git a/src/system/libroot/posix/pthread/pthread.cpp b/src/system/libroot/posix/pthread/pthread.cpp
index 4c5104a..988e570 100644
a
|
b
|
__pthread_init_creation_attributes(const pthread_attr_t* pthreadAttributes,
|
119 | 119 | attributes->stack_size = attr->stack_size; |
120 | 120 | attributes->pthread = thread; |
121 | 121 | attributes->flags = 0; |
| 122 | attributes->guard_size = attr->guard_size; |
122 | 123 | |
123 | 124 | if (thread != NULL && attr->detach_state == PTHREAD_CREATE_DETACHED) |
124 | 125 | thread->flags |= THREAD_DETACHED; |
diff --git a/src/system/libroot/posix/pthread/pthread_attr.c b/src/system/libroot/posix/pthread/pthread_attr.c
index 3054690..9d16698 100644
a
|
b
|
pthread_attr_init(pthread_attr_t *_attr)
|
30 | 30 | attr->detach_state = PTHREAD_CREATE_JOINABLE; |
31 | 31 | attr->sched_priority = B_NORMAL_PRIORITY; |
32 | 32 | attr->stack_size = USER_STACK_SIZE; |
| 33 | attr->guard_size = USER_STACK_GUARD_PAGES * PAGE_SIZE; |
33 | 34 | |
34 | 35 | *_attr = attr; |
35 | 36 | return B_OK; |
… |
… |
pthread_attr_setstacksize(pthread_attr_t *_attr, size_t stacksize)
|
112 | 113 | return 0; |
113 | 114 | } |
114 | 115 | |
| 116 | int |
| 117 | pthread_attr_getguardsize(const pthread_attr_t *_attr, size_t *guardsize) |
| 118 | { |
| 119 | pthread_attr *attr; |
| 120 | |
| 121 | if (_attr == NULL || (attr = *_attr) == NULL) |
| 122 | return B_BAD_VALUE; |
| 123 | |
| 124 | *guardsize = attr->guard_size; |
| 125 | |
| 126 | return 0; |
| 127 | } |
115 | 128 | |
116 | 129 | int |
117 | 130 | pthread_attr_getscope(const pthread_attr_t *attr, int *contentionScope) |