#include <asm/unistd.h>
static void
-dump_str(const char *str, const unsigned int len)
+dump_str_ex(const char *str, const unsigned int len, const int idx_w)
{
static const char chars[256] =
"................................"
unsigned int n = len - i > 16 ? 16 : len - i;
const char *dump = hexdump_memdup(str + i, n);
- tprintf(" | %05x %-49s %-16.*s |\n",
- i, dump, n, chars + i);
+ tprintf(" | %0*x %-49s %-16.*s |\n",
+ idx_w, i, dump, n, chars + i % 0x100);
free((void *) dump);
}
}
+static inline void
+dump_str(const char *str, const unsigned int len)
+{
+ dump_str_ex(str, len, 5);
+}
+
static void
print_hex(const char *str, const unsigned int len)
{
tprintf("write(1, \"%s\", %u) = %ld\n"
" | 00000 %-49s %-16s |\n",
w_c, w_len, rc, w_d, w_c);
- close(1);
rc = k_read(0, r0, 0);
if (rc)
r1_c, w_len, rc, r1_d, r1_c);
close(0);
+ /*
+ * Check partial dump; relies on dumpstr() implementation details
+ * (maximum size of chunk to be copied at once).
+ */
+ static const size_t six_wide_size = 1 << 20;
+ static const size_t fetch_size = 1 << 16;
+ static const char big_buf_str[] =
+ "\\0\\1\\2\\3\\4\\5\\6\\7"
+ "\\10\\t\\n\\v\\f\\r\\16\\17"
+ "\\20\\21\\22\\23\\24\\25\\26\\27"
+ "\\30\\31\\32\\33\\34\\35\\36\\37";
+ const size_t buf_size = six_wide_size + fetch_size;
+ const size_t sizes[] = {
+ six_wide_size,
+ six_wide_size + 1,
+ buf_size,
+ buf_size + 1,
+ buf_size + 2,
+ };
+ char *big_buf = tail_alloc(buf_size);
+
+ fill_memory_ex(big_buf, buf_size, 0, 0x100);
+
+ for (size_t i = 0; i < ARRAY_SIZE(sizes); i++) {
+ rc = k_write(1, big_buf, sizes[i]);
+ tprintf("write(1, \"%s\"..., %zu) = %s\n",
+ big_buf_str, sizes[i], sprintrc(rc));
+ dump_str_ex(big_buf, MIN(sizes[i], buf_size),
+ sizes[i] > six_wide_size ? 6 : 5);
+
+ if (sizes[i] == buf_size + 1)
+ tprintf(" | <Cannot fetch 1 byte from pid %d @%p>\n",
+ getpid(), big_buf + buf_size);
+
+ if (sizes[i] == buf_size + 2)
+ tprintf(" | <Cannot fetch 2 bytes from pid %d @%p>\n",
+ getpid(), big_buf + buf_size);
+ }
+
+ close(1);
+
if (open("/dev/zero", O_RDONLY))
perror_msg_and_fail("open");