From 56d9a530202979fed9544131aa2e53bf2da0c7de Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Wed, 7 May 2008 19:23:18 -0400 Subject: PR5648: Fix memcpy's endianess issue. --- runtime/ChangeLog | 5 +++++ runtime/vsprintf.c | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'runtime') diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 8410b918..0a66a28b 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,8 @@ +2008-05-06 Masami Hiramatsu + + PR 5648 + * vsprintf.c (_stp_vsnprintf): Fix memcpy's endianess issue. + 2008-05-05 Frank Ch. Eigler PR 6481. diff --git a/runtime/vsprintf.c b/runtime/vsprintf.c index dcaa1bc3..4ffcf72e 100644 --- a/runtime/vsprintf.c +++ b/runtime/vsprintf.c @@ -248,6 +248,11 @@ int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args) ++str; } } +#ifdef __ia64__ + if ((str + precision - 1) <= end) + memcpy(str, &num, precision); //to prevent unaligned access + str += precision; +#else switch(precision) { case 1: if(str <= end) @@ -256,21 +261,22 @@ int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args) break; case 2: if((str + 1) <= end) - memcpy(str, &num, 2); + *(int16_t *)str = (int16_t)num; str+=2; break; case 4: if((str + 3) <= end) - memcpy(str, &num, 4); + *(int32_t *)str = num; str+=4; break; default: // "%.8b" by default case 8: if((str + 7) <= end) - memcpy(str, &num, 8); + *(int64_t *)str = num; str+=8; break; } +#endif while (len < field_width--) { if (str <= end) *str = '\0'; -- cgit From 3e2a19a9f57fe40b872f5084c5c60ba1a45f087c Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Wed, 7 May 2008 19:23:44 -0400 Subject: PR5648: Fix unaligned access warning in stp_print_flush on ia64 --- runtime/ChangeLog | 7 +++++++ runtime/print_new.c | 12 +++++++----- runtime/print_old.c | 12 +++++++----- 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'runtime') diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 0a66a28b..f0f65215 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,10 @@ +2008-05-06 Masami Hiramatsu + + PR 5648 + * print_old.c (stp_print_flush): Fix unaligned access warning on + ia64. + * print_new.c (stp_print_flush): Ditto. + 2008-05-06 Masami Hiramatsu PR 5648 diff --git a/runtime/print_new.c b/runtime/print_new.c index 75bbd82b..07af2e33 100644 --- a/runtime/print_new.c +++ b/runtime/print_new.c @@ -40,11 +40,13 @@ void EXPORT_FN(stp_print_flush) (_stp_pbuf *pb) else atomic_inc (&_stp_transport_failures); #else - struct _stp_trace *t = relay_reserve(_stp_utt->rchan, sizeof(*t) + len); - if (likely(t)) { - t->sequence = _stp_seq_inc(); - t->pdu_len = len; - memcpy((void *) t + sizeof(*t), pb->buf, len); + void *buf = relay_reserve(_stp_utt->rchan, + sizeof(struct _stp_trace) + len); + if (likely(buf)) { + struct _stp_trace t = { .sequence = _stp_seq_inc(), + .pdu_len = len}; + memcpy(buf, &t, sizeof(t)); // prevent unaligned access + memcpy(buf + sizeof(t), pb->buf, len); } else atomic_inc (&_stp_transport_failures); #endif diff --git a/runtime/print_old.c b/runtime/print_old.c index 5ee050b5..5c117e5f 100644 --- a/runtime/print_old.c +++ b/runtime/print_old.c @@ -35,11 +35,13 @@ void EXPORT_FN(stp_print_flush) (_stp_pbuf *pb) else atomic_inc (&_stp_transport_failures); #else - struct _stp_trace *t = relay_reserve(_stp_utt->rchan, sizeof(*t) + len); - if (likely(t)) { - t->sequence = _stp_seq_inc(); - t->pdu_len = len; - memcpy((void *) t + sizeof(*t), pb->buf, len); + void *buf = relay_reserve(_stp_utt->rchan, + sizeof(struct _stp_trace) + len); + if (likely(buf)) { + struct _stp_trace t = { .sequence = _stp_seq_inc(), + .pdu_len = len}; + memcpy(buf, &t, sizeof(t)); // prevent unaligned access + memcpy(buf + sizeof(t), pb->buf, len); } else atomic_inc (&_stp_transport_failures); #endif -- cgit From 22bf9dc8f992e30e325fcad9b5af77db190e977f Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 8 May 2008 16:19:08 -0500 Subject: Fix for PR 6500. 2008-05-08 David Smith PR 6500. * task_finder.c (__stp_utrace_task_finder_report_exec): Moved attach logic to __stp_utrace_attach_match_filename(). (__stp_utrace_attach_match_filename): New function. (__stp_utrace_task_finder_report_clone): Calls __stp_utrace_attach_match_filename() to attach to newly cloned threads. --- runtime/ChangeLog | 10 +++++ runtime/task_finder.c | 110 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 88 insertions(+), 32 deletions(-) (limited to 'runtime') diff --git a/runtime/ChangeLog b/runtime/ChangeLog index f0f65215..aab6a862 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,13 @@ +2008-05-08 David Smith + + PR 6500. + * task_finder.c (__stp_utrace_task_finder_report_exec): Moved + attach logic to __stp_utrace_attach_match_filename(). + (__stp_utrace_attach_match_filename): New function. + (__stp_utrace_task_finder_report_clone): Calls + __stp_utrace_attach_match_filename() to attach to newly cloned + threads. + 2008-05-06 Masami Hiramatsu PR 5648 diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 6d79c98a..2c27e4a3 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -231,43 +231,16 @@ __stp_utrace_attach(struct task_struct *tsk, return rc; } -static u32 -__stp_utrace_task_finder_report_clone(struct utrace_attached_engine *engine, - struct task_struct *parent, - unsigned long clone_flags, - struct task_struct *child) -{ - struct utrace_attached_engine *child_engine; - struct mm_struct *mm; - - if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) - return UTRACE_ACTION_RESUME; - - // On clone, attach to the child. - (void) __stp_utrace_attach(child, engine->ops, 0, - __STP_UTRACE_TASK_FINDER_EVENTS); - return UTRACE_ACTION_RESUME; -} - -static u32 -__stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine, - struct task_struct *tsk, - const struct linux_binprm *bprm, - struct pt_regs *regs) +static inline void +__stp_utrace_attach_match_filename(struct task_struct *tsk, + const char * const filename) { size_t filelen; struct list_head *tgt_node; struct stap_task_finder_target *tgt; int found_node = 0; - if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) - return UTRACE_ACTION_RESUME; - - // On exec, check bprm - if (bprm->filename == NULL) - return UTRACE_ACTION_RESUME; - - filelen = strlen(bprm->filename); + filelen = strlen(filename); list_for_each(tgt_node, &__stp_task_finder_list) { tgt = list_entry(tgt_node, struct stap_task_finder_target, list); @@ -275,7 +248,7 @@ __stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine, // here, since they are handled at startup. if (tgt != NULL && tgt->pathlen > 0 && tgt->pathlen == filelen - && strcmp(tgt->pathname, bprm->filename) == 0) { + && strcmp(tgt->pathname, filename) == 0) { found_node = 1; break; } @@ -309,6 +282,79 @@ __stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine, cb_tgt->engine_attached = 1; } } +} + +static u32 +__stp_utrace_task_finder_report_clone(struct utrace_attached_engine *engine, + struct task_struct *parent, + unsigned long clone_flags, + struct task_struct *child) +{ + int rc; + struct mm_struct *mm; + char *mmpath_buf; + char *mmpath; + + if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) + return UTRACE_ACTION_RESUME; + + // On clone, attach to the child. + rc = __stp_utrace_attach(child, engine->ops, 0, + __STP_UTRACE_TASK_FINDER_EVENTS); + if (rc != 0 && rc != EPERM) + return UTRACE_ACTION_RESUME; + + /* Grab the path associated with this task. */ + mm = get_task_mm(child); + if (! mm) { + /* If the thread doesn't have a mm_struct, it is + * a kernel thread which we need to skip. */ + return UTRACE_ACTION_RESUME; + } + + // Allocate space for a path + mmpath_buf = _stp_kmalloc(PATH_MAX); + if (mmpath_buf == NULL) { + _stp_error("Unable to allocate space for path"); + return UTRACE_ACTION_RESUME; + } + + // Grab the path associated with the new task + mmpath = __stp_get_mm_path(mm, mmpath_buf, PATH_MAX); + mmput(mm); /* We're done with mm */ + if (IS_ERR(mmpath)) { + rc = -PTR_ERR(mmpath); + _stp_error("Unable to get path (error %d) for pid %d", + rc, (int)child->pid); + } + else { + __stp_utrace_attach_match_filename(child, mmpath); + } + + _stp_kfree(mmpath_buf); + return UTRACE_ACTION_RESUME; +} + +static u32 +__stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine, + struct task_struct *tsk, + const struct linux_binprm *bprm, + struct pt_regs *regs) +{ + size_t filelen; + struct list_head *tgt_node; + struct stap_task_finder_target *tgt; + int found_node = 0; + + if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) + return UTRACE_ACTION_RESUME; + + // On exec, check bprm + if (bprm->filename == NULL) + return UTRACE_ACTION_RESUME; + + __stp_utrace_attach_match_filename(tsk, bprm->filename); + return UTRACE_ACTION_RESUME; } -- cgit