Earlier quoted context omitted.
Well, the man page says otherwise, and I'd hate to rely on undocumented safety buried in the standard library. Edit: upon re-reading the man page, this bit caught my eye: "If you need to use these frameworks in the child process, you must exec. In this situation it is reasonable to exec yourself." So that would be one (highly painful) way to handle this safely. Fork, then self-exec, passing in arguments that tell the…
Seems like you're right. Whoops, time to go fix some of my code, which is why I really want a non-broken posix_spawn(). Another silly way to do things is to have the parent process send a list of fds to close over a pipe, which at least doesn't require a second call to exec(). I think the problem with close-on-exec is always going to be simple though: you have to make sure every library you use sets the flag.
Hacking the OS X Kernel for Fun and Profiles
21–30 of 38 posts
Re: Hacking the OS X Kernel for Fun and Profiles
#22Earlier quoted context omitted.
I think the "hacking X for fun and profit" is a pretty well-known trope.
For me, the origin of this was from "Smashing the stack for fun and profit (1996)"[1], which does actually refer to somewhat malicious purposes. Apparently it has existed in literature for a long time before that though[2]. [1] http://www.phrack.org/issues.html?id=14&issue=49 [2] http://english.stackexchange.com/questions/25205/what-is-the...
Re: Hacking the OS X Kernel for Fun and Profiles
#23Can someone explain what this patch actually does? I have an old Macbook Air with a malfunctioning sensor that cause the CPU to always run in powersaving mode (capped at 800 mhz), so it's basically unusable under OS X. I have walked around this issue by installing Linux which allows me to tune the CPU governor manually, and it uncaps the artificial limit that the malfunctioning sensor puts. Would this patch allow me…
Re: Hacking the OS X Kernel for Fun and Profiles
#24 http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/task_sample.htmlRe: Hacking the OS X Kernel for Fun and Profiles
#25Can someone explain what this patch actually does? I have an old Macbook Air with a malfunctioning sensor that cause the CPU to always run in powersaving mode (capped at 800 mhz), so it's basically unusable under OS X. I have walked around this issue by installing Linux which allows me to tune the CPU governor manually, and it uncaps the artificial limit that the malfunctioning sensor puts. Would this patch allow me…
Re: Hacking the OS X Kernel for Fun and Profiles
#26Cool, that was a bug, and not too difficult to fix and must have felt great when figured-out. But sometimes on darwin you run into stuff that just is so crufty in the BSD emulation, that it's better to use the mach stuff. In this case these class of routines: http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/task_sample.html
Re: Hacking the OS X Kernel for Fun and Profiles
#27Cool, that was a bug, and not too difficult to fix and must have felt great when figured-out. But sometimes on darwin you run into stuff that just is so crufty in the BSD emulation, that it's better to use the mach stuff. In this case these class of routines: http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/task_sample.html
I don't think that has a way to get stacks. See http://research.swtch.com/pprof for why stacks are important.
Re: Hacking the OS X Kernel for Fun and Profiles
#28Re: Hacking the OS X Kernel for Fun and Profiles
#29> In order for the open file not to be inherited by the new program, we must introduce a new variant of open(2) that can open a file descriptor atomically marked "close on exec." This is incorrect, because you can prevent fds from getting inherited even without "close on exec". Simply list the files in /dev/fd and you'll see all the file descriptors your program has open, and then you can close all of the ones that t…
Re: Hacking the OS X Kernel for Fun and Profiles
#30> In order for the open file not to be inherited by the new program, we must introduce a new variant of open(2) that can open a file descriptor atomically marked "close on exec." This is incorrect, because you can prevent fds from getting inherited even without "close on exec". Simply list the files in /dev/fd and you'll see all the file descriptors your program has open, and then you can close all of the ones that t…
Last time I checked on this, there was no safe way (i.e. using only async-signal-safe calls) to list the contents of /dev/fd post-fork. Did I miss something?
I suppose if I am not mistaken you could go the pre-readdir() route and open a directory with open() and read it with read(). Probably a portability mess though.