Is there any way to query the address space of a process on Mac?
On Windows, we use VirtualQuery, and on Linux, we parse /proc/self/maps (ugh).
Is there a system call or similar functionality on Mac?
The vmmap command-line utility will give you this information. I'm not sure that the APIs behind it are public, though.
mach_vm_region_info can be used for this. See http://www.newosxbook.com/src.jl?tree=listings&file=12-1-vmmap.c
Related
I love pow for mac (http://pow.cx) however I have a few co-workers that are on Windows, is there anything that they can use to have the power of pow?
I doubt there's anything directly comparable available for Windows. In general, Windows just isn't as friendly to develop ruby applications on. That said, pow seems to be documented very well, so there's probably enough information there to port it to work on WIndows.
Assuming your co-workers can't easily get a Mac or linux machine to develop on, another option might be to run Linux in a VM using something like VMware or VirtualBox.
Sadly, no. Your best bet is to just update the hostname file, but that's not anywhere near as elegant.
I have some code that using UNIX sockets. But I need to compile it for winodws(using mingw32 on mac os x) but I don't want to use winsock because I'm worried about compatibility! Is there is a way to use UNIX sockets on windows?
If you stick to the BSD API that Winsock provides then you wont have that many problems. A small amount of start up and shutdown code will be Windows specific but most of the socket code will be cross platform.
I'd suggest looking into cygwin (http://www.cygwin.com/), they make every effort to be compatible. However, I have no idea how you would cross-compile for that environment on Mac OSX.
I need to detect whether NFS is installed or not on the running server in my Ruby code.
If there is any way I can do this in cross-platform way(or at least in unix/linux)?
I can't think of a cross platform way to do it as there's no standards for getting kernel info. I think it would have to be specific to the guest OS type. Linux you could do "modinfo nfs". Solaris boxes you could also use modinfo and search for nfs in the output or look in /etc/dfs/fstypes. Using "uname -s" will tell you which method to use.
How can I retrieve the information shown in the Mac's System Profiler app programatically? I'm actually interested in the USB section if that matters.
The OSX command line tool "ioreg" might give you want you want.
man ioreg
ioreg displays the I/O Kit registry. It shows the heirarchical registry as an inverted tree.
Also if you can/want to use Cocoa look at IOKit. IOKit is the OSX framework that talks to USB hardware.
Take a look at the system_profiler(8) command.
How does one go about creating a virtual CD driver on Mac OS X programatically?
I can't find any relevant Cocoa APIs or any pure C BSD solutions.
Any help or information is appreciated.
You would need to use the I/O Kit framework to develop your own device driver that would emulate a virtual CD drive. Here are some links to the relevant APIs to get you started.
I/O Kit Fundamentals
I/O Kit Device Driver Guidelines
Kernel Extension Programming Topics
There are several different answers people have proposed here. The issue at hand is what are you trying to accomplish. If you really want to emulate a CD ROM (down to the commandset) you will need to write a device driver. If your goal is merely to emulate a block device with contents similiar to a CD you can create a disk image using disk utility and let the builtin disk image driver handle it for you.
MacFUSE is useful if you want to present some sort of custom filesystem functionality, but if what you are looking for is something that has the same semantics as an optical disc (whether that is and block or command set level) it is the wrong tool.
If you're simply looking to mount an ISO or something then it's done through the Disk Utility, simply drag it into the side-bar and then select it and choose mount.
If you want to do it from code you can issue the hdiutil command, as shown here. I'm not sure if there's an API call to do it, but getting that command to do the work is quite painless.
The simplest way to mount a custom volume is MacFUSE. It handles the IOKit details for you and lets you write the implementation in user space. However, I don’t think you can make a MacFUSE “look like” a CD; you’d have to modify FUSE to achieve that.
I had a nosey around DAEMON Tools for Mac's driver:
/Library/Extensions/DAEMONToolsVirtualSCSIBus.kext/Contents/MacOS/DAEMONToolsVirtualSCSIBus
I disassembled the binary using Hopper and discovered they are using
IOSCSIProtocolServices.