diff options
author | hunt <hunt> | 2006-07-11 20:37:18 +0000 |
---|---|---|
committer | hunt <hunt> | 2006-07-11 20:37:18 +0000 |
commit | 6d66b0c445045e559c2b7eaf9a6931e24a90cc6a (patch) | |
tree | 7443aaddff17081f971208b04c33171c44642fc3 | |
parent | 7813b63f5f737c9d4e47142d690966651ed8678b (diff) | |
download | systemtap-steved-6d66b0c445045e559c2b7eaf9a6931e24a90cc6a.tar.gz systemtap-steved-6d66b0c445045e559c2b7eaf9a6931e24a90cc6a.tar.xz systemtap-steved-6d66b0c445045e559c2b7eaf9a6931e24a90cc6a.zip |
2006-07-11 Martin Hunt <hunt@redhat.com>
* string.c (_stp_text_str): Add a parameter to support
userspace strings too.
* string.h: (_stp_text_str): Fix proto.
-rw-r--r-- | runtime/ChangeLog | 6 | ||||
-rw-r--r-- | runtime/copy.c | 3 | ||||
-rw-r--r-- | runtime/string.c | 48 | ||||
-rw-r--r-- | runtime/string.h | 2 |
4 files changed, 42 insertions, 17 deletions
diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 61d7ed72..c9c573da 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,9 @@ +2006-07-11 Martin Hunt <hunt@redhat.com> + + * string.c (_stp_text_str): Add a parameter to support + userspace strings too. + * string.h: (_stp_text_str): Fix proto. + 2006-07-11 Li Guanglei <guanglei@cn.ibm.com> * lket/b2a/lket_b2a.c: modified to be sync with diff --git a/runtime/copy.c b/runtime/copy.c index 75a185c4..f4d906b3 100644 --- a/runtime/copy.c +++ b/runtime/copy.c @@ -124,7 +124,7 @@ _stp_strncpy_from_user(char *dst, const char __user *src, long count) * */ -void _stp_string_from_user (String str, const char __user *src, long count) +long _stp_string_from_user (String str, const char __user *src, long count) { long res = -EFAULT; if (count > STP_STRING_SIZE - str->len - 1) @@ -136,6 +136,7 @@ void _stp_string_from_user (String str, const char __user *src, long count) str->buf[str->len] = '\0'; } } + return res; } /** Copy a block of data from user space. diff --git a/runtime/string.c b/runtime/string.c index c354d86f..21a6c70e 100644 --- a/runtime/string.c +++ b/runtime/string.c @@ -212,22 +212,27 @@ char * _stp_string_ptr (String str) } \ }) +#include "loc2c-runtime.h" + /** Return a printable text string. * * Takes a string, and any ASCII characters that are not printable are * replaced by the corresponding escape sequence in the returned * string. * - * @param out Output string pointer + * @param outstr Output string pointer * @param in Input string pointer * @param len Maximum length of string to return not including terminating 0. * 0 means MAXSTRINGLEN. * @param quoted Put double quotes around the string. If input string is truncated * in will have "..." after the second quote. + * @param user Set this to indicate the input string pointer is a userspace pointer. */ -void _stp_text_str(char *out, char *in, int len, int quoted) +void _stp_text_str(char *outstr, char *in, int len, int quoted, int user) { const int length = len; + char c, *out = outstr; + if (len == 0 || len > STP_STRING_SIZE-1) len = STP_STRING_SIZE-1; if (quoted) { @@ -235,12 +240,17 @@ void _stp_text_str(char *out, char *in, int len, int quoted) *out++ = '\"'; } - while (*in && len > 0) { + if (user) + c = deref(1,(char __user *)in); + else + c = *in; + + while (c && len > 0) { int num = 1; - if (isprint(*in) && isascii(*in)) - *out++ = *in; + if (isprint(c) && isascii(c)) + *out++ = c; else { - switch (*in) { + switch (c) { case '\a': case '\b': case '\f': @@ -251,9 +261,9 @@ void _stp_text_str(char *out, char *in, int len, int quoted) num = 2; break; default: - if (*in > 077) + if (c > 077) num = 4; - else if (*in > 07) + else if (c > 07) num = 3; else num = 2; @@ -264,7 +274,7 @@ void _stp_text_str(char *out, char *in, int len, int quoted) break; *out++ = '\\'; - switch (*in) { + switch (c) { case '\a': *out++ = 'a'; break; @@ -287,20 +297,24 @@ void _stp_text_str(char *out, char *in, int len, int quoted) *out++ = 'v'; break; default: /* output octal representation */ - if (*in > 077) - *out++ = to_oct_digit(*in >> 6); - if (*in > 07) - *out++ = to_oct_digit((*in & 070) >> 3); - *out++ = to_oct_digit(*in & 07); + if (c > 077) + *out++ = to_oct_digit(c >> 6); + if (c > 07) + *out++ = to_oct_digit((c & 070) >> 3); + *out++ = to_oct_digit(c & 07); break; } } len -= num; in++; + if (user) + c = deref(1,(char __user *)in); + else + c = *in; } if (quoted) { - if (*in) { + if (c) { out = out - 3 + len; *out++ = '\"'; *out++ = '.'; @@ -310,6 +324,10 @@ void _stp_text_str(char *out, char *in, int len, int quoted) *out++ = '\"'; } *out = '\0'; + return; +deref_fault: + strlcpy (outstr, "<unknown>", len); } + /** @} */ #endif /* _STRING_C_ */ diff --git a/runtime/string.h b/runtime/string.h index 699873af..b4411411 100644 --- a/runtime/string.h +++ b/runtime/string.h @@ -35,6 +35,6 @@ String _stp_stdout = &__stp_stdout; #define to_oct_digit(c) ((c) + '0') void _stp_vsprintf (String str, const char *fmt, va_list args); void _stp_string_cat_char (String str1, const char c); -void _stp_text_str(char *out, char *in, int len, int quoted); +void _stp_text_str(char *out, char *in, int len, int quoted, int user); #endif /* _STRING_H_ */ |