Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Windows. #3

Open
cshanjib opened this issue Dec 25, 2018 · 5 comments
Open

Support for Windows. #3

cshanjib opened this issue Dec 25, 2018 · 5 comments

Comments

@cshanjib
Copy link

Worked well with Unix and Darwin. Need a support for windows as well.

@rosunshrestha
Copy link

Similar issue with me. I think this is an issue with dependency offheap uses. https://github.com/tysonmote/gommap/pull/3/files
This might be the case what you are looking for. But it need to be tested,

@glycerine
Copy link
Owner

I welcome PRs to improve portability.

@cshanjib
Copy link
Author

I went through the pull request https://github.com/tysonmote/gommap/pull/3/files which claims the support for the windows of gommap. I tried it and again got stucked in the offheap/malloc.go.
Here is the log if anybody could help,

..\..\..\..\github.com\glycerine\offheap\malloc.go:41:30: cannot use int(mm.File.Fd()) (type int) as type syscall.Handle in argument to syscall.Ftruncate
..\..\..\..\github.com\glycerine\offheap\malloc.go:81:11: undefined: syscall.MAP_SHARED
..\..\..\..\github.com\glycerine\offheap\malloc.go:83:11: undefined: syscall.MAP_ANON
..\..\..\..\github.com\glycerine\offheap\malloc.go:83:30: undefined: syscall.MAP_PRIVATE
..\..\..\..\github.com\glycerine\offheap\malloc.go:117:13: undefined: syscall.Stat_t
..\..\..\..\github.com\glycerine\offheap\malloc.go:118:14: undefined: syscall.Fstat
..\..\..\..\github.com\glycerine\offheap\malloc.go:125:31: cannot use mm.Fd (type int) as type syscall.Handle in argument to syscall.Ftruncate
..\..\..\..\github.com\glycerine\offheap\malloc.go:136:10: undefined: syscall.PROT_READ
..\..\..\..\github.com\glycerine\offheap\malloc.go:136:30: undefined: syscall.PROT_WRITE
..\..\..\..\github.com\glycerine\offheap\malloc.go:144:11: undefined: syscall.MAP_ANON
..\..\..\..\github.com\glycerine\offheap\malloc.go:144:11: too many errors

@glycerine
Copy link
Owner

consts_win.go defines the MAP_SHARED, etc; so we just need a consts_posix.go that does the same and then have malloc.go use those constants instead of the syscall ones that vary between OS.

The int vs syscall.Handle looks like a conversion problem that should be easy to solve by looking at the expected signature of Ftruncate, and converting to the correct type.

@exapsy
Copy link

exapsy commented Jan 9, 2024

syscall is not specific to Windows. So, in malloc.go you would need a malloc_unix and a malloc_windows most likely, each with their corresponding

//go:build windows

or

//go:build darwin || dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris

You would have to have different implementations as well, since POSIX systems use flags such as these

		syscall.PROT_READ|syscall.PROT_WRITE,
		syscall.MAP_ANONYMOUS|syscall.MAP_PRIVATE,

while windows uses more like these

	kernel32 := windows.NewLazySystemDLL("kernel32.dll")
	virtualAlloc := kernel32.NewProc("VirtualAlloc")

	r1, _, err := virtualAlloc.Call(
		0,
		size,
		uintptr(0x1000), // MEM_COMMIT
		uintptr(0x04),   // PAGE_READWRITE
	)

In general, that's how I'm implementing, my incomplete for now, memory allocator. Separate implementations for the syscalls for separate systems, as mmap is specific to POSIX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants