dsbckxk165039 2018-10-01 11:18
浏览 334

未定义:Windows 10上的syscall.Mmap

I have this function in my Go project and I am getting the error as:

undefined syscall.Mmap

func memMap(fd uintptr, base int64) (mem []uint32, mem8 []byte, err error) {
    mem8, err = syscall.Mmap(
        int(fd),
        base,
        memLength,
        syscall.PROT_READ|syscall.PROT_WRITE,
        syscall.MAP_SHARED,
    )
    if err != nil {
        return
    }
    // Convert mapped byte memory to unsafe []uint32 pointer, adjust length as needed
    header := *(*reflect.SliceHeader)(unsafe.Pointer(&mem8))
    header.Len /= (32 / 8) // (32 bit = 4 bytes)
    header.Cap /= (32 / 8)
    mem = *(*[]uint32)(unsafe.Pointer(&header))
    return
}
  • 写回答

1条回答 默认 最新

  • dqdmvg7332 2018-10-01 11:55
    关注

    The problem

    Windows does not have the mmap(2) syscall—it's POSIX-specific (just in case: what "POSIX" is).

    Windows has MapViewOfFile() and friends.

    Solutions

    There are two approaches, I reckon:

    • Use a "wrapper" package such as golang.org/x/exp/mmap which tries to provide a generic memory-mapping API which is cross-platform (that is, on POSIX platforms it will use mmap(2) and on Windows is will use Windows-specific API).

    • Use the appropriate Win32 API functions directly instead of syscall.Mmap.

      Should you take this route, the golang.org/x/sys/windows package has the relevant functions readily available.

    A third approach is to have your own custom implementation working with memory-mapped data which calls either syscall.Mmap and friends of Windows-specific API. Such implementation should supposedly involve using so-called build constraints to conditionally compile a particular target platform-specific implementation—just like golang.org/x/exp/mmap does.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。