uti: Allocate memory area directly to uti_desc->wp

Change-Id: Ia5a1dbf56b937d9d05cd7fa1c5eec4a5b4b7b196
This commit is contained in:
Masamichi Takagi
2018-09-02 11:49:17 +09:00
parent 35300e7b4f
commit 56da7e2de9

View File

@ -1964,8 +1964,7 @@ struct uti_desc {
static int create_tracer(); static int create_tracer();
int uti_pfd[2]; int uti_pfd[2];
void *uti_wp; struct uti_desc *uti_desc = (void*)-1;
struct uti_desc *uti_desc;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -2899,9 +2898,9 @@ create_tracer()
memset(uti_desc, 0, sizeof(struct uti_desc)); memset(uti_desc, 0, sizeof(struct uti_desc));
sem_init(&uti_desc->arg, 1, 0); sem_init(&uti_desc->arg, 1, 0);
sem_init(&uti_desc->attach, 1, 0); sem_init(&uti_desc->attach, 1, 0);
uti_wp = mmap(NULL, PAGE_SIZE * 3, PROT_READ | PROT_WRITE, uti_desc->wp = mmap(NULL, PAGE_SIZE * 3, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0); MAP_SHARED | MAP_ANONYMOUS, -1, 0);
if (uti_wp == (void *)-1) { if (uti_desc->wp == (void *)-1) {
return -1; return -1;
} }
@ -3184,17 +3183,17 @@ util_thread(struct thread_data_s *my_thread, unsigned long uctx_pa, int remote_t
} }
#endif #endif
#ifdef POSTK_DEBUG_ARCH_DEP_35 #ifdef POSTK_DEBUG_ARCH_DEP_35
lctx = (char *)uti_wp + page_size; lctx = (char *)uti_desc->wp + page_size;
rctx = (char *)lctx + page_size; rctx = (char *)lctx + page_size;
#else #else
lctx = (char *)uti_wp + PAGE_SIZE; lctx = (char *)uti_desc->wp + PAGE_SIZE;
rctx = (char *)lctx + PAGE_SIZE; rctx = (char *)lctx + PAGE_SIZE;
#endif /* POSTK_DEBUG_ARCH_DEP_35 */ #endif /* POSTK_DEBUG_ARCH_DEP_35 */
param[0] = (void *)uctx_pa; param[0] = (void *)uctx_pa;
param[1] = rctx; param[1] = rctx;
param[2] = lctx; param[2] = lctx;
param[4] = uti_wp; param[4] = uti_desc->wp;
#ifdef POSTK_DEBUG_ARCH_DEP_35 #ifdef POSTK_DEBUG_ARCH_DEP_35
param[5] = (void *)(page_size * 3); param[5] = (void *)(page_size * 3);
#else /* POSTK_DEBUG_ARCH_DEP_35 */ #else /* POSTK_DEBUG_ARCH_DEP_35 */
@ -3209,7 +3208,7 @@ util_thread(struct thread_data_s *my_thread, unsigned long uctx_pa, int remote_t
create_worker_thread(NULL); create_worker_thread(NULL);
/* Pass info to the tracer so that it can masquerade as the tracee */ /* Pass info to the tracer so that it can masquerade as the tracee */
uti_desc->wp = uti_wp; uti_desc->wp = uti_desc->wp;
uti_desc->mck_tid = remote_tid; uti_desc->mck_tid = remote_tid;
uti_desc->key = (unsigned long)param[3]; uti_desc->key = (unsigned long)param[3];
uti_desc->pid = getpid(); uti_desc->pid = getpid();
@ -3260,11 +3259,11 @@ util_thread(struct thread_data_s *my_thread, unsigned long uctx_pa, int remote_t
pthread_exit(NULL); pthread_exit(NULL);
out: out:
if (uti_wp != (void*)-1) if (uti_desc != (void*)-1 && uti_desc->wp != (void*)-1)
#ifdef POSTK_DEBUG_ARCH_DEP_35 #ifdef POSTK_DEBUG_ARCH_DEP_35
munmap(uti_wp, page_size * 3); munmap(uti_desc->wp, page_size * 3);
#else /* POSTK_DEBUG_ARCH_DEP_35 */ #else /* POSTK_DEBUG_ARCH_DEP_35 */
munmap(uti_wp, PAGE_SIZE * 3); munmap(uti_desc->wp, PAGE_SIZE * 3);
#endif /* POSTK_DEBUG_ARCH_DEP_35 */ #endif /* POSTK_DEBUG_ARCH_DEP_35 */
return rc; return rc;
} }