-
Notifications
You must be signed in to change notification settings - Fork 76
Posix-based windows implementation #497
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
29d41d4
Posix-based windows implementation
patricoferris cf6ba07
Remove unused process module
patricoferris e609295
Remove deprecated FD module
patricoferris a9e2943
Update comments
patricoferris 4bd46b5
Update CI
patricoferris ec54ccb
More posix to windows clean up
patricoferris 40d758b
Remove incorrect Obj.magic
patricoferris 0917e26
Update comments and stubs
patricoferris 7fe1080
Remove Fs from windows
patricoferris 4610543
Add tuareg condition to windows test
patricoferris 106ea8a
Fix bug introduced in fork_actions
patricoferris fa934d0
Use ifndef
patricoferris 695499e
Disable MDX tests on Windows
patricoferris f3d7051
Add more windows tests and fix network code
patricoferris e5b57fa
Fix rebase mistake in stubs
patricoferris 9a9c02b
Support DLA on Windows
patricoferris 393ec68
Add kcas
patricoferris cab124d
Don't allocate OCaml exceptions in Windows fork actions
patricoferris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
(mdx | ||
(package eio_main) | ||
(deps (package eio_main) (env_var "EIO_BACKEND")) | ||
(enabled_if (<> %{os_type} "Win32")) | ||
(files multicore.md)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# This file is generated by dune, edit dune-project instead | ||
opam-version: "2.0" | ||
synopsis: "Eio implementation for Windows" | ||
description: "An Eio implementation using I/O Completion Ports" | ||
description: "An Eio implementation using OCaml's Unix.select" | ||
maintainer: ["[email protected]"] | ||
authors: ["Anil Madhavapeddy" "Thomas Leonard"] | ||
license: "ISC" | ||
|
@@ -11,6 +11,9 @@ bug-reports: "https://github.com/ocaml-multicore/eio/issues" | |
depends: [ | ||
"dune" {>= "3.7"} | ||
"eio" {= version} | ||
"cstruct-unix" {= "dev"} | ||
"kcas" {>= "0.3.0" & with-test} | ||
"alcotest" {>= "1.4.0" & with-test} | ||
"odoc" {with-doc} | ||
] | ||
build: [ | ||
|
@@ -28,3 +31,10 @@ build: [ | |
] | ||
] | ||
dev-repo: "git+https://github.com/ocaml-multicore/eio.git" | ||
pin-depends: [ | ||
# Removes base bytes for crowbar | ||
[ "ocplib-endian.dev" "git+https://github.com/Leonidas-from-XIV/ocplib-endian#fda4d5525063c8444020be369c63de23d39c246e" ] | ||
# Needed for the cstruct read and writes without copying | ||
[ "cstruct.dev" "git+https://github.com/djs55/ocaml-cstruct#471ca03b49b3a372945fcf13c89e0447a8bd3932" ] | ||
[ "cstruct-unix.dev" "git+https://github.com/djs55/ocaml-cstruct#471ca03b49b3a372945fcf13c89e0447a8bd3932" ] | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pin-depends: [ | ||
# Removes base bytes for crowbar | ||
[ "ocplib-endian.dev" "git+https://github.com/Leonidas-from-XIV/ocplib-endian#fda4d5525063c8444020be369c63de23d39c246e" ] | ||
# Needed for the cstruct read and writes without copying | ||
[ "cstruct.dev" "git+https://github.com/djs55/ocaml-cstruct#471ca03b49b3a372945fcf13c89e0447a8bd3932" ] | ||
[ "cstruct-unix.dev" "git+https://github.com/djs55/ocaml-cstruct#471ca03b49b3a372945fcf13c89e0447a8bd3932" ] | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
(mdx | ||
(package eio) | ||
(enabled_if (<> %{os_type} "Win32")) | ||
(deps | ||
(package eio) | ||
(file ./dscheck/fake_sched.ml) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
(* | ||
* Copyright (C) 2023 Thomas Leonard | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*) | ||
|
||
open Eio.Std | ||
|
||
[@@@alert "-unstable"] | ||
|
||
module Fd = Eio_unix.Fd | ||
|
||
(* Run an event loop in the current domain, using [fn x] as the root fiber. *) | ||
let run_event_loop fn x = | ||
Sched.with_sched @@ fun sched -> | ||
let open Effect.Deep in | ||
let extra_effects : _ effect_handler = { | ||
effc = fun (type a) (e : a Effect.t) : ((a, Sched.exit) continuation -> Sched.exit) option -> | ||
match e with | ||
| Eio_unix.Private.Get_monotonic_clock -> Some (fun k -> continue k (Time.mono_clock : Eio.Time.Mono.t)) | ||
| Eio_unix.Private.Socket_of_fd (sw, close_unix, unix_fd) -> Some (fun k -> | ||
let fd = Fd.of_unix ~sw ~blocking:false ~close_unix unix_fd in | ||
(* TODO: On Windows, if the FD from Unix.pipe () is passed this will fail *) | ||
(try Unix.set_nonblock unix_fd with Unix.Unix_error (Unix.ENOTSOCK, _, _) -> ()); | ||
continue k (Flow.of_fd fd :> Eio_unix.socket) | ||
) | ||
| Eio_unix.Private.Socketpair (sw, domain, ty, protocol) -> Some (fun k -> | ||
match | ||
let unix_a, unix_b = Unix.socketpair ~cloexec:true domain ty protocol in | ||
let a = Fd.of_unix ~sw ~blocking:false ~close_unix:true unix_a in | ||
let b = Fd.of_unix ~sw ~blocking:false ~close_unix:true unix_b in | ||
Unix.set_nonblock unix_a; | ||
Unix.set_nonblock unix_b; | ||
(Flow.of_fd a :> Eio_unix.socket), (Flow.of_fd b :> Eio_unix.socket) | ||
with | ||
| r -> continue k r | ||
| exception Unix.Unix_error (code, name, arg) -> | ||
discontinue k (Err.wrap code name arg) | ||
) | ||
| Eio_unix.Private.Pipe sw -> Some (fun k -> | ||
match | ||
let r, w = Low_level.pipe ~sw in | ||
let source = (Flow.of_fd r :> Eio_unix.source) in | ||
let sink = (Flow.of_fd w :> Eio_unix.sink) in | ||
(source, sink) | ||
with | ||
| r -> continue k r | ||
| exception Unix.Unix_error (code, name, arg) -> | ||
discontinue k (Err.wrap code name arg) | ||
) | ||
| _ -> None | ||
} | ||
in | ||
Sched.run ~extra_effects sched fn x | ||
|
||
let v = object | ||
inherit Eio.Domain_manager.t | ||
|
||
method run_raw fn = | ||
let domain = ref None in | ||
Eio.Private.Suspend.enter (fun _ctx enqueue -> | ||
domain := Some (Domain.spawn (fun () -> Fun.protect fn ~finally:(fun () -> enqueue (Ok ())))) | ||
); | ||
Domain.join (Option.get !domain) | ||
|
||
method run fn = | ||
let domain = ref None in | ||
Eio.Private.Suspend.enter (fun ctx enqueue -> | ||
let cancelled, set_cancelled = Promise.create () in | ||
Eio.Private.Fiber_context.set_cancel_fn ctx (Promise.resolve set_cancelled); | ||
domain := Some (Domain.spawn (fun () -> | ||
Fun.protect (run_event_loop (fun () -> fn ~cancelled)) | ||
~finally:(fun () -> enqueue (Ok ())))) | ||
); | ||
Domain.join (Option.get !domain) | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
(library | ||
(name eio_windows) | ||
(public_name eio_windows) | ||
(library_flags :standard -ccopt -lbcrypt) | ||
(enabled_if (= %{os_type} "Win32")) | ||
(libraries eio eio.utils fmt)) | ||
(foreign_stubs | ||
(language c) | ||
(include_dirs ../lib_eio/unix/include) | ||
patricoferris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(names eio_windows_stubs)) | ||
(libraries eio eio.unix eio.utils fmt cstruct-unix)) | ||
|
||
(rule | ||
(targets config.ml) | ||
(action (run ./include/discover.exe))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,49 @@ | ||
(* Can base this on the eio_posix directory structure. | ||
See HACKING.md for instructions on creating a new backend. *) | ||
let run _main = failwith "TODO: Windows support." | ||
(* | ||
* Copyright (C) 2023 Thomas Leonard | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*) | ||
|
||
module Low_level = Low_level | ||
|
||
type stdenv = < | ||
stdin : <Eio.Flow.source; Eio_unix.Resource.t>; | ||
stdout : <Eio.Flow.sink; Eio_unix.Resource.t>; | ||
stderr : <Eio.Flow.sink; Eio_unix.Resource.t>; | ||
net : Eio.Net.t; | ||
domain_mgr : Eio.Domain_manager.t; | ||
clock : Eio.Time.clock; | ||
mono_clock : Eio.Time.Mono.t; | ||
fs : Eio.Fs.dir Eio.Path.t; | ||
cwd : Eio.Fs.dir Eio.Path.t; | ||
secure_random : Eio.Flow.source; | ||
debug : Eio.Debug.t; | ||
> | ||
|
||
let run main = | ||
let stdin = (Flow.of_fd Eio_unix.Fd.stdin :> <Eio.Flow.source; Eio_unix.Resource.t>) in | ||
let stdout = (Flow.of_fd Eio_unix.Fd.stdout :> <Eio.Flow.sink; Eio_unix.Resource.t>) in | ||
let stderr = (Flow.of_fd Eio_unix.Fd.stderr :> <Eio.Flow.sink; Eio_unix.Resource.t>) in | ||
Domain_mgr.run_event_loop main @@ object (_ : stdenv) | ||
method stdin = stdin | ||
method stdout = stdout | ||
method stderr = stderr | ||
method debug = Eio.Private.Debug.v | ||
method clock = Time.clock | ||
method mono_clock = Time.mono_clock | ||
method net = Net.v | ||
method domain_mgr = Domain_mgr.v | ||
method cwd = failwith "file-system operations not supported on Windows yet" | ||
method fs = failwith "file-system operations not supported on Windows yet" | ||
method secure_random = Flow.secure_random | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(** Fallback Eio backend for Windows using OCaml's [Unix.select]. *) | ||
|
||
type stdenv = < | ||
stdin : <Eio.Flow.source; Eio_unix.Resource.t>; | ||
stdout : <Eio.Flow.sink; Eio_unix.Resource.t>; | ||
stderr : <Eio.Flow.sink; Eio_unix.Resource.t>; | ||
net : Eio.Net.t; | ||
domain_mgr : Eio.Domain_manager.t; | ||
clock : Eio.Time.clock; | ||
mono_clock : Eio.Time.Mono.t; | ||
fs : Eio.Fs.dir Eio.Path.t; | ||
cwd : Eio.Fs.dir Eio.Path.t; | ||
secure_random : Eio.Flow.source; | ||
debug : Eio.Debug.t; | ||
> | ||
(** An extended version of {!Eio.Stdenv.t} with some extra features available on Windows. *) | ||
|
||
val run : (stdenv -> 'a) -> 'a | ||
(** [run main] runs an event loop and calls [main stdenv] inside it. | ||
|
||
For portable code, you should use {!Eio_main.run} instead, which will call this for you if appropriate. *) | ||
|
||
module Low_level = Low_level | ||
(** Low-level API. *) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.