!lheuhImcToQZYTQTuI:nixos.org

Nix on macOS

1173 Members
“There are still many issues with the Darwin platform but most of it is quite usable.” — http://yves.gnu-darwin.org190 Servers

Load older messages


SenderMessageTime
22 Dec 2025
@reckenrode:matrix.orgRandy Eckenrode * https://devblogs.microsoft.com/oldnewthing/20221102-00/? 17:34:30
@reckenrode:matrix.orgRandy Eckenrode * 17:34:35
@ihar.hrachyshka:matrix.orgIhar Hrachyshka

claims on how this works

Apple's libc has a pretty wild feature (guarded by _DARWIN_UNLIMITED_SELECT, on by default) which allows fds above FD_SETSIZE. It works by checking the address of the fd_set: if it's within the current thread's stack, then the call will fail, under the assumption that it's a stack-allocated fd_set.
But if the address is NOT within the current thread's stack, select() assumes you know what you're doing and will allow the call, trusting you have allocated sufficient memory for the high fds in the fd_set.

so there may be some condition to fulfill to make it work.

which I think is not satisfied for qemu main loop fds?

17:34:35
@reckenrode:matrix.orgRandy EckenrodeThat Old New Thing article provides a good explanation why things are the way they are.17:37:21
@ihar.hrachyshka:matrix.orgIhar Hrachyshka(taht said, in my test program I also define fds[] on stack and it "succeeds" so maybe claims are wrong)17:38:40
@reckenrode:matrix.orgRandy EckenrodeWhat about the emulation? How does it allocate the set?17:39:46
@ihar.hrachyshka:matrix.orgIhar Hrachyshka"emulation"? you mean g_poll macos implementation?17:40:35
@reckenrode:matrix.orgRandy EckenrodeThe implication in the Darwin headers seems to suggest that it’s using a 64-bit type, which is a lot of fds.17:40:36
@reckenrode:matrix.orgRandy EckenrodeYeah.17:40:45
@ihar.hrachyshka:matrix.orgIhar Hrachyshkanot sure I understand. the fds are passed by caller. it's up to caller.17:41:44
@ihar.hrachyshka:matrix.orgIhar Hrachyshka

complete macos g_poll:

gint
g_poll (GPollFD *fds,
	guint    nfds,
	gint     timeout)
{
  struct timeval tv;
  fd_set rset, wset, xset;
  GPollFD *f;
  int ready;
  int maxfd = 0;

  FD_ZERO (&rset);
  FD_ZERO (&wset);
  FD_ZERO (&xset);

  for (f = fds; f < &fds[nfds]; ++f)
    if (f->fd >= 0)
      {
	if (f->events & G_IO_IN)
	  FD_SET (f->fd, &rset);
	if (f->events & G_IO_OUT)
	  FD_SET (f->fd, &wset);
	if (f->events & G_IO_PRI)
	  FD_SET (f->fd, &xset);
	if (f->fd > maxfd && (f->events & (G_IO_IN|G_IO_OUT|G_IO_PRI)))
	  maxfd = f->fd;
      }

  tv.tv_sec = timeout / 1000;
  tv.tv_usec = (timeout % 1000) * 1000;

  ready = select (maxfd + 1, &rset, &wset, &xset,
		  timeout == -1 ? NULL : &tv);
  if (ready > 0)
    for (f = fds; f < &fds[nfds]; ++f)
      {
	f->revents = 0;
	if (f->fd >= 0)
	  {
	    if (FD_ISSET (f->fd, &rset))
	      f->revents |= G_IO_IN;
	    if (FD_ISSET (f->fd, &wset))
	      f->revents |= G_IO_OUT;
	    if (FD_ISSET (f->fd, &xset))
	      f->revents |= G_IO_PRI;
	  }
      }

  return ready;
}
17:42:17
@ihar.hrachyshka:matrix.orgIhar Hrachyshka you mean fd_sets? 17:43:04
@reckenrode:matrix.orgRandy EckenrodeYeah.17:43:51
@reckenrode:matrix.orgRandy EckenrodeThat comment about where the sets are allocated doesn’t make sense to me.17:44:42
@ihar.hrachyshka:matrix.orgIhar Hrachyshkaguess I should just test and see. I have a reproducer, just need to recompile glib to qemu and see.17:44:57
@reckenrode:matrix.orgRandy Eckenrode * 17:44:59
@ihar.hrachyshka:matrix.orgIhar Hrachyshka source == hacker news nobody 17:45:27
@reckenrode:matrix.orgRandy Eckenrodehttps://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/bsd/sys/_types/_fd_def.h#L52_L5417:46:06
@reckenrode:matrix.orgRandy EckenrodeFish shell developer?17:47:01
@ihar.hrachyshka:matrix.orgIhar HrachyshkaI was actually also looking at the same struct def. so looks like we may need to also define the __DARWIN_FD_SETSIZE otherwise we write past the end of the struct (I think)17:47:57
@reckenrode:matrix.orgRandy EckenrodeOr malloc it based on the size of the incoming set.17:49:12
@reckenrode:matrix.orgRandy EckenrodeGlib supports using cleanup functions to make that less messy.17:49:27
@reckenrode:matrix.orgRandy Eckenrode Though if it’s a mask for all fds, you don’t really know the needed size. 17:50:00
@reckenrode:matrix.orgRandy Eckenrodehttps://man.freebsd.org/cgi/man.cgi?select17:52:21
@reckenrode:matrix.orgRandy Eckenrode Apple mentioned FreeBSD being unlimited. I agree we should probably increase the amount of memory it’s using (either by defining FD_SETSIZE or some other way). 17:53:19
@reckenrode:matrix.orgRandy Eckenrode

Looks like (unsurprisingly) FreeBSD has a similar implementation.

https://github.com/freebsd/freebsd-src/blob/f51e9d0e0988df58c94db586ab5c8b5fd091c004/sys/sys/select.h#L65

17:55:17
@reckenrode:matrix.orgRandy EckenrodeI guess FreeBSD doesn’t enforce the limit if you define it to something non-default.17:55:46
@ihar.hrachyshka:matrix.orgIhar Hrachyshkaso darwin just broke the api to pass posix17:56:22
@ihar.hrachyshka:matrix.orgIhar Hrachyshkawell, broke -> adjusted to standard17:56:33
@hexa:lossy.networkhexa Randy Eckenrode, emily any reason I should not update the darwin buildfarm to tahoe? 21:45:40

Show newer messages


Back to Room ListRoom Version: 6