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

Add support for AF_UNIX SOCK_DGRAM #602

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

djs55
Copy link
Collaborator

@djs55 djs55 commented Oct 5, 2022

Unfortunately these aren't supported by libuv directly, so we need to implement our own separate system. It doesn't need to be particularly scalable as the expected use-case is to send and receive ethernet frames.

The server will listen on a Unix domain socket and receive connected SOCK_DGRAM sockets which will have ethernet frames on them.

Signed-off-by: David Scott dave@recoil.org

@djs55
Copy link
Collaborator Author

djs55 commented Oct 9, 2022

CircleCI caught this:

  thread #1, queue = 'com.apple.main-thread'
    frame #0: 0x00007ff806b273a2 libsystem_kernel.dylib`close + 10
    frame #1: 0x00000001007a3e98 inline_test_runner_hostnet.exe`unix_close(fd=<unavailable>) at close.c:24:9 [opt]
    frame #2: 0x0000000100014be7 inline_test_runner_hostnet.exe`camlHost_unix_dgram__close_927 + 103
    frame #3: 0x0000000100015063 inline_test_runner_hostnet.exe`camlHost_unix_dgram__fun_2409 + 211
    frame #4: 0x00000001006c48c1 inline_test_runner_hostnet.exe`camlLwt__callback_1391 + 129
    frame #5: 0x00000001006c35d8 inline_test_runner_hostnet.exe`camlLwt__iter_callback_list_954 + 120
    frame #6: 0x00000001006c3745 inline_test_runner_hostnet.exe`camlLwt__run_in_resolution_loop_1024 + 37
    frame #7: 0x00000001006c38e3 inline_test_runner_hostnet.exe`camlLwt__resolve_1044 + 83
    frame #8: 0x00000001006c3cd2 inline_test_runner_hostnet.exe`camlLwt__wakeup_later_general_1141 + 178
    frame #9: 0x0000000100721a74 inline_test_runner_hostnet.exe`camlStdlib__Queue__iter_329 + 52
    frame #10: 0x0000000100710b15 inline_test_runner_hostnet.exe`camlStdlib__Array__iter_330 + 117
    frame #11: 0x00000001006c20b2 inline_test_runner_hostnet.exe`camlLwt_sequence__loop_344 + 50
    frame #12: 0x00000001007061e0 inline_test_runner_hostnet.exe`camlStdlib__List__iter_507 + 48
    frame #13: 0x00000001000b5370 inline_test_runner_hostnet.exe`camlLwt_engine__fun_2681 + 640
    frame #14: 0x00000001000b7b8a inline_test_runner_hostnet.exe`camlLwt_main__run_loop_436 + 154
    frame #15: 0x00000001000b7e1c inline_test_runner_hostnet.exe`camlLwt_main__run_494 + 268
    frame #16: 0x000000010005c212 inline_test_runner_hostnet.exe`camlPpx_inline_test_lib__Runtime__fun_2843 + 18
    frame #17: 0x00000001002946cd inline_test_runner_hostnet.exe`camlBase__Exn__protectx_1498 + 45
    frame #18: 0x000000010005b694 inline_test_runner_hostnet.exe`camlPpx_inline_test_lib__Runtime__time_and_reset_random_seeds_2302 + 212
    frame #19: 0x000000010005be01 inline_test_runner_hostnet.exe`camlPpx_inline_test_lib__Runtime__test_2359 + 737
    frame #20: 0x0000000100016388 inline_test_runner_hostnet.exe`camlHost_unix_dgram__entry + 296
    frame #21: 0x0000000100005179 inline_test_runner_hostnet.exe`caml_program + 13001
    frame #22: 0x00000001007d58e5 inline_test_runner_hostnet.exe`caml_start_program + 73
    frame #23: 0x00000001007ac8e6 inline_test_runner_hostnet.exe`caml_startup_common(argv=0x00007ff7bfeff008, pooling=<unavailable>) at startup_nat.c:160:9 [opt]
    frame #24: 0x00000001007ac95b inline_test_runner_hostnet.exe`caml_main [inlined] caml_startup_exn(argv=<unavailable>) at startup_nat.c:167:10 [opt]
    frame #25: 0x00000001007ac954 inline_test_runner_hostnet.exe`caml_main [inlined] caml_startup(argv=<unavailable>) at startup_nat.c:172:15 [opt]
    frame #26: 0x00000001007ac954 inline_test_runner_hostnet.exe`caml_main(argv=<unavailable>) at startup_nat.c:179:3 [opt]
    frame #27: 0x00000001007ac9cc inline_test_runner_hostnet.exe`main(argc=<unavailable>, argv=<unavailable>) at main.c:37:3 [opt]
    frame #28: 0x00000001016ed52e dyld`start + 462
  thread #2
    frame #0: 0x00007ff806b2ed5a libsystem_kernel.dylib`__select + 10
    frame #1: 0x000000010079d06f inline_test_runner_hostnet.exe`caml_thread_tick(arg=<unavailable>) at st_posix.h:388:5 [opt]
    frame #2: 0x00007ff806b634e1 libsystem_pthread.dylib`_pthread_start + 125
    frame #3: 0x00007ff806b5ef6b libsystem_pthread.dylib`thread_start + 15
* thread #3, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00000001007d24bf inline_test_runner_hostnet.exe`caml_memprof_set_suspended(s=1) at memprof.c:561:20 [opt]
    frame #1: 0x00000001007c9677 inline_test_runner_hostnet.exe`caml_fatal_uncaught_exception(exn=4326427160) at printexc.c:149:3 [opt]
    frame #2: 0x00000001007aca35 inline_test_runner_hostnet.exe`caml_raise(v=4326427160) at fail_nat.c:76:5 [opt]
    frame #3: 0x00000001007aa926 inline_test_runner_hostnet.exe`unix_error(errcode=9, cmdname="recv", cmdarg=<unavailable>) at unixsupport.c:309:3 [opt]
    frame #4: 0x000000010076a5f2 inline_test_runner_hostnet.exe`stub_cstruct_recv(val_fd=<unavailable>, val_buf=<unavailable>, val_ofs=<unavailable>, val_len=<unavailable>) at stubs_utils.c:93:14 [opt]
    frame #5: 0x0000000100013ade inline_test_runner_hostnet.exe`camlUtils__cstruct_recv_731 + 30
    frame #6: 0x00000001000141e5 inline_test_runner_hostnet.exe`camlHost_unix_dgram__receive_thread_861 + 117
    frame #7: 0x00000001000f6785 inline_test_runner_hostnet.exe`camlThread__fun_850 + 37
    frame #8: 0x00000001007d58e5 inline_test_runner_hostnet.exe`caml_start_program + 73
    frame #9: 0x00000001007c9785 inline_test_runner_hostnet.exe`caml_callback_exn(closure=<unavailable>, arg=1) at callback.c:111:10 [opt]
    frame #10: 0x000000010079cfff inline_test_runner_hostnet.exe`caml_thread_start(arg=<unavailable>) at st_stubs.c:548:5 [opt]
    frame #11: 0x00007ff806b634e1 libsystem_pthread.dylib`_pthread_start + 125
    frame #12: 0x00007ff806b5ef6b libsystem_pthread.dylib`thread_start + 15
  thread #4, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00000001007d59a0 inline_test_runner_hostnet.exe`caml_raise_exception + 72

Edit: fixed by moving the caml_acquire_runtime_system up one line 😅

Unfortunately these aren't supported by libuv directly, so we need to
implement our own separate system. It doesn't need to be particularly
scalable as the expected use-case is to send and receive ethernet frames.

The server will listen on a Unix domain socket and receive connected
SOCK_DGRAM sockets which will have ethernet frames on them.

Signed-off-by: David Scott <dave@recoil.org>
@djs55 djs55 changed the title WIP: Add support for AF_UNIX SOCK_DGRAM Add support for AF_UNIX SOCK_DGRAM Oct 10, 2022
@@ -7,3 +7,9 @@ val rtlGenRandom: int -> bytes option

val setSocketTTL: Unix.file_descr -> int -> unit
(** [setSocketTTL s ttl] sets the TTL on the socket [s] to [ttl] *)

val cstruct_send: Unix.file_descr -> Cstruct.t -> int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really would prefer to get these stubs into Cstruct_unix. It seems safe enough to put these alongside Cstruct_unix.of_fd

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah makes sense, I'm about to write writev and readv too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Successfully merging this pull request may close these issues.

None yet

2 participants