348 size_t guard_bytes; |
348 size_t guard_bytes; |
349 res = pthread_attr_getguardsize(&attr, &guard_bytes); |
349 res = pthread_attr_getguardsize(&attr, &guard_bytes); |
350 if (res != 0) { |
350 if (res != 0) { |
351 fatal("pthread_attr_getguardsize failed with errno = %d", res); |
351 fatal("pthread_attr_getguardsize failed with errno = %d", res); |
352 } |
352 } |
353 int guard_pages = align_size_up(guard_bytes, page_bytes) / page_bytes; |
353 int guard_pages = align_up(guard_bytes, page_bytes) / page_bytes; |
354 assert(guard_bytes == guard_pages * page_bytes, "unaligned guard"); |
354 assert(guard_bytes == guard_pages * page_bytes, "unaligned guard"); |
355 |
355 |
356 #ifdef IA64 |
356 #ifdef IA64 |
357 // IA64 has two stacks sharing the same area of memory, a normal |
357 // IA64 has two stacks sharing the same area of memory, a normal |
358 // stack growing downwards and a register stack growing upwards. |
358 // stack growing downwards and a register stack growing upwards. |
359 // Guard pages, if present, are in the centre. This code splits |
359 // Guard pages, if present, are in the centre. This code splits |
360 // the stack in two even without guard pages, though in theory |
360 // the stack in two even without guard pages, though in theory |
361 // there's nothing to stop us allocating more to the normal stack |
361 // there's nothing to stop us allocating more to the normal stack |
362 // or more to the register stack if one or the other were found |
362 // or more to the register stack if one or the other were found |
363 // to grow faster. |
363 // to grow faster. |
364 int total_pages = align_size_down(stack_bytes, page_bytes) / page_bytes; |
364 int total_pages = align_down(stack_bytes, page_bytes) / page_bytes; |
365 stack_bottom += (total_pages - guard_pages) / 2 * page_bytes; |
365 stack_bottom += (total_pages - guard_pages) / 2 * page_bytes; |
366 #endif // IA64 |
366 #endif // IA64 |
367 |
367 |
368 stack_bottom += guard_bytes; |
368 stack_bottom += guard_bytes; |
369 |
369 |