| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kern_ktrace.c,v 1.148 2009/01/11 02:45:52 christos Exp $ */ | | 1 | /* $NetBSD: kern_ktrace.c,v 1.149 2009/08/05 19:53:42 dsl Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Andrew Doran. | | 8 | * by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -51,27 +51,27 @@ | | | @@ -51,27 +51,27 @@ |
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 | * SUCH DAMAGE. | | 58 | * SUCH DAMAGE. |
59 | * | | 59 | * |
60 | * @(#)kern_ktrace.c 8.5 (Berkeley) 5/14/95 | | 60 | * @(#)kern_ktrace.c 8.5 (Berkeley) 5/14/95 |
61 | */ | | 61 | */ |
62 | | | 62 | |
63 | #include <sys/cdefs.h> | | 63 | #include <sys/cdefs.h> |
64 | __KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.148 2009/01/11 02:45:52 christos Exp $"); | | 64 | __KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.149 2009/08/05 19:53:42 dsl Exp $"); |
65 | | | 65 | |
66 | #include <sys/param.h> | | 66 | #include <sys/param.h> |
67 | #include <sys/systm.h> | | 67 | #include <sys/systm.h> |
68 | #include <sys/proc.h> | | 68 | #include <sys/proc.h> |
69 | #include <sys/file.h> | | 69 | #include <sys/file.h> |
70 | #include <sys/namei.h> | | 70 | #include <sys/namei.h> |
71 | #include <sys/vnode.h> | | 71 | #include <sys/vnode.h> |
72 | #include <sys/kernel.h> | | 72 | #include <sys/kernel.h> |
73 | #include <sys/kthread.h> | | 73 | #include <sys/kthread.h> |
74 | #include <sys/ktrace.h> | | 74 | #include <sys/ktrace.h> |
75 | #include <sys/kmem.h> | | 75 | #include <sys/kmem.h> |
76 | #include <sys/syslog.h> | | 76 | #include <sys/syslog.h> |
77 | #include <sys/filedesc.h> | | 77 | #include <sys/filedesc.h> |
| @@ -663,46 +663,47 @@ ktr_kmem(lwp_t *l, int type, const void | | | @@ -663,46 +663,47 @@ ktr_kmem(lwp_t *l, int type, const void |
663 | | | 663 | |
664 | if (ktealloc(&kte, &buf, l, type, len)) | | 664 | if (ktealloc(&kte, &buf, l, type, len)) |
665 | return; | | 665 | return; |
666 | memcpy(buf, bf, len); | | 666 | memcpy(buf, bf, len); |
667 | ktraddentry(l, kte, KTA_WAITOK); | | 667 | ktraddentry(l, kte, KTA_WAITOK); |
668 | } | | 668 | } |
669 | | | 669 | |
670 | static void | | 670 | static void |
671 | ktr_io(lwp_t *l, int fd, enum uio_rw rw, struct iovec *iov, size_t len) | | 671 | ktr_io(lwp_t *l, int fd, enum uio_rw rw, struct iovec *iov, size_t len) |
672 | { | | 672 | { |
673 | struct ktrace_entry *kte; | | 673 | struct ktrace_entry *kte; |
674 | struct ktr_genio *ktp; | | 674 | struct ktr_genio *ktp; |
675 | size_t resid = len, cnt, buflen; | | 675 | size_t resid = len, cnt, buflen; |
676 | void *cp; | | 676 | char *cp; |
677 | | | 677 | |
678 | next: | | 678 | next: |
679 | buflen = min(PAGE_SIZE, resid + sizeof(struct ktr_genio)); | | 679 | buflen = min(PAGE_SIZE, resid + sizeof(struct ktr_genio)); |
680 | | | 680 | |
681 | if (ktealloc(&kte, (void *)&ktp, l, KTR_GENIO, buflen)) | | 681 | if (ktealloc(&kte, (void *)&ktp, l, KTR_GENIO, buflen)) |
682 | return; | | 682 | return; |
683 | | | 683 | |
684 | ktp->ktr_fd = fd; | | 684 | ktp->ktr_fd = fd; |
685 | ktp->ktr_rw = rw; | | 685 | ktp->ktr_rw = rw; |
686 | | | 686 | |
687 | cp = (void *)(ktp + 1); | | 687 | cp = (void *)(ktp + 1); |
688 | buflen -= sizeof(struct ktr_genio); | | 688 | buflen -= sizeof(struct ktr_genio); |
689 | kte->kte_kth.ktr_len = sizeof(struct ktr_genio); | | 689 | kte->kte_kth.ktr_len = sizeof(struct ktr_genio); |
690 | | | 690 | |
691 | while (buflen > 0) { | | 691 | while (buflen > 0) { |
692 | cnt = min(iov->iov_len, buflen); | | 692 | cnt = min(iov->iov_len, buflen); |
693 | if (copyin(iov->iov_base, cp, cnt) != 0) | | 693 | if (copyin(iov->iov_base, cp, cnt) != 0) |
694 | goto out; | | 694 | goto out; |
695 | kte->kte_kth.ktr_len += cnt; | | 695 | kte->kte_kth.ktr_len += cnt; |
| | | 696 | cp += cnt; |
696 | buflen -= cnt; | | 697 | buflen -= cnt; |
697 | resid -= cnt; | | 698 | resid -= cnt; |
698 | iov->iov_len -= cnt; | | 699 | iov->iov_len -= cnt; |
699 | if (iov->iov_len == 0) | | 700 | if (iov->iov_len == 0) |
700 | iov++; | | 701 | iov++; |
701 | else | | 702 | else |
702 | iov->iov_base = (char *)iov->iov_base + cnt; | | 703 | iov->iov_base = (char *)iov->iov_base + cnt; |
703 | } | | 704 | } |
704 | | | 705 | |
705 | /* | | 706 | /* |
706 | * Don't push so many entry at once. It will cause kmem map | | 707 | * Don't push so many entry at once. It will cause kmem map |
707 | * shortage. | | 708 | * shortage. |
708 | */ | | 709 | */ |