Minimal launchd-like behavior to start up

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

Minimal launchd-like behavior to start up

Postby copumpkin » Tue Oct 10, 2017 12:49 am

Hi all,

I'm trying to boot XNU into userspace with a process of my own that isn't launchd (for reasons I won't get into). For now I've just been experimenting with a selection of "hello world"-style programs I wrote in C but all of them seem to crash without doing much (even if I tell them to write to disk in case output to /dev/console isn't enough).

I'm guessing that the real launchd does some magic kernel appeasement dance for being granted the privilege of being pid1, and indeed going by the latest source release pre-XPC (https://opensource.apple.com/source/launchd/launchd-842.92.1/src/launchd.c.auto.html), it seems like there's a pid1_magic_init function that fools around with some mach ports and kqueue stuff. I tried to replicate some of its behavior but the kernel still doesn't appear to like my program. Has anyone looked into the exact contract between the kernel and launchd, and has that changed much since XPC? I'd be interested in seeing the smallest launchd-like program that xnu (post-10.10) will actually launch happily.
copumpkin
 
Posts: 12
Joined: Tue Oct 10, 2017 12:43 am

Re: Minimal launchd-like behavior to start up

Postby morpheus » Tue Oct 10, 2017 4:30 pm

The contract is mostly just that launchd doesn't die, because if it does the kernel panics.

But what might be stumping you is that launchd claims the Mach Special ports, which the kernel relies on? It's hard to know why your programs crash. Get back to me with some core dump, maybe? (which you can do if your mini launchd sets the core limit on AS_CORE before forking your test programs.

Incidentally, I plan on open sourcing the post-XPC launchd soon (along with libXPC). And then you can just use that implementation as a base and strip it . Stay tuned.
morpheus
Site Admin
 
Posts: 532
Joined: Thu Apr 11, 2013 6:24 pm

Re: Minimal launchd-like behavior to start up

Postby copumpkin » Tue Oct 10, 2017 5:02 pm

Yeah, my program definitely dies (maybe I'll just make it loop) but I was trying to make it do some visible work before dying. So I had it e.g., write to a file in the root and spit stuff out to /dev/console, in the hopes that I could see it actually running before dying. Unfortunately I saw no evidence of the file appearing on the root or any messages on the boot console, so I figured my program was crashing before it got to doing observable stuff.

I don't have a core dump yet, but will try to get one later.

Also, when you say open sourcing post-XPC launchd, do you have control over what Apple does in that space? Or are you saying that like your other stuff, you reverse engineered how it works and reimplemented it?
copumpkin
 
Posts: 12
Joined: Tue Oct 10, 2017 12:43 am

Re: Minimal launchd-like behavior to start up

Postby morpheus » Tue Oct 10, 2017 6:22 pm

Me? Control? AAPL? Not even close. Not only am I or this website NOT IN ANY WAY AFFILIATED WITH APPLE , they don't really seem to acknowledge my existence. So no. I mean an open sourced implementation , directly reversed.
morpheus
Site Admin
 
Posts: 532
Joined: Thu Apr 11, 2013 6:24 pm

Re: Minimal launchd-like behavior to start up

Postby copumpkin » Tue Oct 10, 2017 6:53 pm

That's what I thought :) but yeah, that would be amazing! For PureDarwin, weirdos like me, and probably a bunch of others.
copumpkin
 
Posts: 12
Joined: Tue Oct 10, 2017 12:43 am


Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 2 guests

cron