FAQ
I'm getting the following panic when I use gopacket's SocketStats method
wit hAF_PACKET mode.

panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 18 [running]:
panic(0x854de0, 0xc82212c820)
         /usr/local/go/src/runtime/panic.go:464 +0x3e6
github.com/google/gopacket/afpacket._cgoCheckPointer0(0x7906e0, 0xc82221c0a0
, 0xc82212c800, 0x1, 0x1, 0x0)
         ??:0 +0x4d
github.com/google/gopacket/afpacket.(*TPacket).SocketStats(0xc82221c000, 0x0
, 0x0, 0x0, 0x0, 0x0)
         /home/lars/dev/go/src/github.com/google/gopacket/afpacket/afpacket.
go:307 +0x22a

....


The panic happens
here: https://github.com/google/gopacket/blob/master/afpacket/afpacket.go#L293

Basically, a pointer to a struct "h.socketStatsV3" of type
"C.struct_tpacket_stats_v3" is passed to "C.getsockopt()"
(http://man7.org/linux/man-pages/man2/setsockopt.2.html) and is filled with
socket statistics data.

After reading a little about how the new cgo pointer restrictions are
enforced in Go 1.6, I'm thinking that the passing
of unsafe.Pointer(&h.socketStatsV3) is the culprit, but I'm not sure. I'm
also not sure how to fix this. I am the one that originally contributed
this code to the project, so I feel like I need to help. Compiling with an
older Go version gives no errors.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at Mar 18, 2016 at 5:09 pm

    On Fri, Mar 18, 2016 at 9:24 AM, Lars Kulseng wrote:
    I'm getting the following panic when I use gopacket's SocketStats method wit
    hAF_PACKET mode.

    panic: runtime error: cgo argument has Go pointer to Go pointer

    goroutine 18 [running]:
    panic(0x854de0, 0xc82212c820)
    /usr/local/go/src/runtime/panic.go:464 +0x3e6
    github.com/google/gopacket/afpacket._cgoCheckPointer0(0x7906e0,
    0xc82221c0a0, 0xc82212c800, 0x1, 0x1, 0x0)
    ??:0 +0x4d
    github.com/google/gopacket/afpacket.(*TPacket).SocketStats(0xc82221c000,
    0x0, 0x0, 0x0, 0x0, 0x0)

    /home/lars/dev/go/src/github.com/google/gopacket/afpacket/afpacket.go:307
    +0x22a

    ....


    The panic happens here:
    https://github.com/google/gopacket/blob/master/afpacket/afpacket.go#L293

    Basically, a pointer to a struct "h.socketStatsV3" of type
    "C.struct_tpacket_stats_v3" is passed to "C.getsockopt()"
    (http://man7.org/linux/man-pages/man2/setsockopt.2.html) and is filled with
    socket statistics data.

    After reading a little about how the new cgo pointer restrictions are
    enforced in Go 1.6, I'm thinking that the passing of
    unsafe.Pointer(&h.socketStatsV3) is the culprit, but I'm not sure. I'm also
    not sure how to fix this. I am the one that originally contributed this code
    to the project, so I feel like I need to help. Compiling with an older Go
    version gives no errors.
    What does the h.socketStatsV3 field contain when the failing call is made?

    The fix may be as simple as clearing that field before the call--I
    assume that getsockopt is going to set its contents anyhow.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Lars Kulseng at Mar 18, 2016 at 5:18 pm
    The structs in use look like this in if_packet.h:

    struct tpacket_stats {
         unsigned int tp_packets;
         unsigned int tp_drops;
    };

    struct tpacket_stats_v3 {
         unsigned int tp_packets;
         unsigned int tp_drops;
         unsigned int tp_freeze_q_cnt;
    };

    The panic seems to happen on the first call to func (h *TPacket) SocketStats()
    and since I've managed to see this behavior while doing simple tests, the
    tp_packets field should have a small number in it and the rest should be 0.












    fredag 18. mars 2016 18.09.31 UTC+1 skrev Ian Lance Taylor følgende:
    On Fri, Mar 18, 2016 at 9:24 AM, Lars Kulseng <larsk...@gmail.com
    <javascript:>> wrote:
    I'm getting the following panic when I use gopacket's SocketStats method wit
    hAF_PACKET mode.

    panic: runtime error: cgo argument has Go pointer to Go pointer

    goroutine 18 [running]:
    panic(0x854de0, 0xc82212c820)
    /usr/local/go/src/runtime/panic.go:464 +0x3e6
    github.com/google/gopacket/afpacket._cgoCheckPointer0(0x7906e0,
    0xc82221c0a0, 0xc82212c800, 0x1, 0x1, 0x0)
    ??:0 +0x4d
    github.com/google/gopacket/afpacket.(*TPacket).SocketStats(0xc82221c000,
    0x0, 0x0, 0x0, 0x0, 0x0)

    /home/lars/dev/go/src/
    github.com/google/gopacket/afpacket/afpacket.go:307
    +0x22a

    ....


    The panic happens here:
    https://github.com/google/gopacket/blob/master/afpacket/afpacket.go#L293

    Basically, a pointer to a struct "h.socketStatsV3" of type
    "C.struct_tpacket_stats_v3" is passed to "C.getsockopt()"
    (http://man7.org/linux/man-pages/man2/setsockopt.2.html) and is filled with
    socket statistics data.

    After reading a little about how the new cgo pointer restrictions are
    enforced in Go 1.6, I'm thinking that the passing of
    unsafe.Pointer(&h.socketStatsV3) is the culprit, but I'm not sure. I'm also
    not sure how to fix this. I am the one that originally contributed this code
    to the project, so I feel like I need to help. Compiling with an older Go
    version gives no errors.
    What does the h.socketStatsV3 field contain when the failing call is made?

    The fix may be as simple as clearing that field before the call--I
    assume that getsockopt is going to set its contents anyhow.

    Ian
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ian Lance Taylor at Mar 18, 2016 at 5:31 pm

    On Fri, Mar 18, 2016 at 10:18 AM, Lars Kulseng wrote:
    The structs in use look like this in if_packet.h:

    struct tpacket_stats {
    unsigned int tp_packets;
    unsigned int tp_drops;
    };

    struct tpacket_stats_v3 {
    unsigned int tp_packets;
    unsigned int tp_drops;
    unsigned int tp_freeze_q_cnt;
    };

    The panic seems to happen on the first call to func (h *TPacket)
    SocketStats() and since I've managed to see this behavior while doing simple
    tests, the tp_packets field should have a small number in it and the rest
    should be 0.
    Those structs don't contain any pointers, so they can't be the problem.

    OK, I think the problem may be that calling unsafe.Pointer(&s.f)
    causes the checker to check all of s, because it doesn't know the type
    of s.f. It that is the problem, then the code is OK, but there is a
    weakness in the checker--it's too conservative. In that case, the
    workaround is going to be something like
         var s tpacket_stats
         C.getsockopt(..., &s, ...)
         h.socketStats = s

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Lars Kulseng at Mar 18, 2016 at 6:54 pm
    That did the trick. Thank you Ian!


    fredag 18. mars 2016 18.31.58 UTC+1 skrev Ian Lance Taylor følgende:
    On Fri, Mar 18, 2016 at 10:18 AM, Lars Kulseng <larsk...@gmail.com
    <javascript:>> wrote:
    The structs in use look like this in if_packet.h:

    struct tpacket_stats {
    unsigned int tp_packets;
    unsigned int tp_drops;
    };

    struct tpacket_stats_v3 {
    unsigned int tp_packets;
    unsigned int tp_drops;
    unsigned int tp_freeze_q_cnt;
    };

    The panic seems to happen on the first call to func (h *TPacket)
    SocketStats() and since I've managed to see this behavior while doing simple
    tests, the tp_packets field should have a small number in it and the rest
    should be 0.
    Those structs don't contain any pointers, so they can't be the problem.

    OK, I think the problem may be that calling unsafe.Pointer(&s.f)
    causes the checker to check all of s, because it doesn't know the type
    of s.f. It that is the problem, then the code is OK, but there is a
    weakness in the checker--it's too conservative. In that case, the
    workaround is going to be something like
    var s tpacket_stats
    C.getsockopt(..., &s, ...)
    h.socketStats = s

    Ian
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 18, '16 at 4:43p
activeMar 18, '16 at 6:54p
posts5
users2
websitegolang.org

2 users in discussion

Lars Kulseng: 3 posts Ian Lance Taylor: 2 posts

People

Translate

site design / logo © 2021 Grokbase