Skip to content

Commit

Permalink
i#1680 large pages: Remove bad uses of PAGE_SIZE.
Browse files Browse the repository at this point in the history
In a few places PAGE_SIZE was used to define a value that does not
depend on the granularity of memory allocation. In preparation for the
page size not being known at compile time, replace those uses with a
proper constant.

Review-URL: https://codereview.appspot.com/307280043
  • Loading branch information
egrimley-arm committed Sep 16, 2016
1 parent f43e120 commit 9ae3828
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion clients/drcov/postprocess/drcov2lcov.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ null_terminate_path(char *path)

#define LINE_HASH_TABLE_BITS 10
#define LINE_TABLE_INIT_SIZE 1024 /* first chunk holds 1024 lines */
#define LINE_TABLE_INIT_PRINT_BUF_SIZE (4*PAGE_SIZE)
#define LINE_TABLE_INIT_PRINT_BUF_SIZE (16*1024)
#define SOURCE_FILE_START_LINE_SIZE (MAXIMUM_PATH + 10) /* "SF:%s\n" */
#define SOURCE_FILE_END_LINE_SIZE 20 /* "end_of_record\n" */
#define MAX_CHAR_PER_LINE 256 /* large enough to hold the test function name */
Expand Down
2 changes: 1 addition & 1 deletion core/arch/x86_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ safe_read_resume_pc(void)
#if defined(STANDALONE_UNIT_TEST)

# define CONST_BYTE 0x1f
# define TEST_STACK_SIZE PAGE_SIZE
# define TEST_STACK_SIZE 4096
/* Align stack to 16 bytes: sufficient for all current architectures. */
byte ALIGN_VAR(16) test_stack[TEST_STACK_SIZE];
static dcontext_t *static_dc;
Expand Down
21 changes: 13 additions & 8 deletions core/unix/loader_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ typedef struct _tls_info_t {
} tls_info_t;
static tls_info_t tls_info;

static size_t max_client_tls_size = 2 * PAGE_SIZE;
/* Maximum size of TLS for client private libraries.
* We will round this up to a multiple of the page size.
*/
static size_t client_tls_size = 2 * 4096;

/* The actual tcb size is the size of struct pthread from nptl/descr.h, which is
* a glibc internal header that we can't include. We hardcode a guess for the
Expand Down Expand Up @@ -244,6 +247,7 @@ privload_mod_tls_init(privmod_t *mod)
void *
privload_tls_init(void *app_tp)
{
size_t client_tls_alloc_size = ALIGN_FORWARD(client_tls_size, PAGE_SIZE);
app_pc dr_tp;
tcb_head_t *dr_tcb;
uint i;
Expand All @@ -252,8 +256,8 @@ privload_tls_init(void *app_tp)
/* FIXME: These should be a thread logs, but dcontext is not ready yet. */
LOG(GLOBAL, LOG_LOADER, 2, "%s: app TLS segment base is "PFX"\n",
__FUNCTION__, app_tp);
dr_tp = heap_mmap(max_client_tls_size);
ASSERT(APP_LIBC_TLS_SIZE + TLS_PRE_TCB_SIZE + tcb_size <= max_client_tls_size);
dr_tp = heap_mmap(client_tls_alloc_size);
ASSERT(APP_LIBC_TLS_SIZE + TLS_PRE_TCB_SIZE + tcb_size <= client_tls_alloc_size);
#ifdef AARCHXX
/* GDB reads some pthread members (e.g., pid, tid), so we must make sure
* the size and member locations match to avoid gdb crash.
Expand All @@ -262,8 +266,8 @@ privload_tls_init(void *app_tp)
ASSERT(LIBC_PTHREAD_TID_OFFSET == offsetof(dr_pthread_t, tid));
#endif
LOG(GLOBAL, LOG_LOADER, 2, "%s: allocated %d at "PFX"\n",
__FUNCTION__, max_client_tls_size, dr_tp);
dr_tp = dr_tp + max_client_tls_size - tcb_size;
__FUNCTION__, client_tls_alloc_size, dr_tp);
dr_tp = dr_tp + client_tls_alloc_size - tcb_size;
dr_tcb = (tcb_head_t *) dr_tp;
LOG(GLOBAL, LOG_LOADER, 2, "%s: adjust thread pointer to "PFX"\n",
__FUNCTION__, dr_tp);
Expand Down Expand Up @@ -296,7 +300,7 @@ privload_tls_init(void *app_tp)
* + our over-estimate crosses a page boundary (our estimate is for latest
* libc and is larger than on older libc versions): i#855.
*/
ASSERT(tls_info.offset <= max_client_tls_size - TLS_PRE_TCB_SIZE - tcb_size);
ASSERT(tls_info.offset <= client_tls_alloc_size - TLS_PRE_TCB_SIZE - tcb_size);
#ifdef X86
/* Update two self pointers. */
dr_tcb->tcb = dr_tcb;
Expand Down Expand Up @@ -329,10 +333,11 @@ privload_tls_init(void *app_tp)
void
privload_tls_exit(void *dr_tp)
{
size_t client_tls_alloc_size = ALIGN_FORWARD(client_tls_size, PAGE_SIZE);
if (dr_tp == NULL)
return;
dr_tp = dr_tp + tcb_size - max_client_tls_size;
heap_munmap(dr_tp, max_client_tls_size);
dr_tp = dr_tp + tcb_size - client_tls_alloc_size;
heap_munmap(dr_tp, client_tls_alloc_size);
}

/****************************************************************************
Expand Down

0 comments on commit 9ae3828

Please sign in to comment.