Post

Replies

Boosts

Views

Activity

/System/Library/Frameworks dylibs are ... not quite there
While playing with this app I found something odd: let dylib1 = dlopen("/System/Library/Frameworks/CreateMLComponents.framework/CreateMLComponents", O_RDONLY)! let s1 = dlsym(dylib1, "CreateMLComponentsVersionString")! var info1 = Dl_info() let success1 = dladdr(s1, &info1) precondition(success1 != 0) print(String(cString: info1.dli_sname!)) // CreateMLComponentsVersionString let path1 = String(cString: info1.dli_fname!) print(path1) // /System/Library/Frameworks/CreateMLComponents.framework/Versions/A/CreateMLComponents let exists1 = FileManager.default.fileExists(atPath: path1) print(exists1) // true let dylib2 = dlopen("/System/Library/Frameworks/Foundation.framework/Foundation", O_RDONLY)! let s2 = dlsym(dylib2, "NSAllocateMemoryPages")! // var info2 = Dl_info() let success2 = dladdr(s2, &info2) precondition(success2 != 0) print(String(cString: info2.dli_sname!)) // NSAllocateMemoryPages let path2 = String(cString: info2.dli_fname!) print(path2) // /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation let exists2 = FileManager.default.fileExists(atPath: path2) print(exists2) // false The app runs fine and prints true for exists1 and false for exists2. That means that while both dlsym calls succeed and both dladdr calls return paths (within CreateMLComponents.framework and Foundation.framework correspondingly) the first file exists while the second file doesn't exist. This raises quite a few questions: Why some of the dylib files (in fact – most dylibs inside /System/Library/Frameworks hirerarchy) don't exist at the expected locations? Why do we have symbolic link files (like Foundation.framework/Foundation) that point to those non-existent locations? What is the purpose of those symbols links? Where are those missing dylib files in fact? They must be somewhere, no?! I guess to figure out the answer I could search the whole disk raw bytes for a particular byte pattern to know the answer but hope there's an easier way to know the truth! Why do we have some exceptional cases like "CreateMLComponents.framework" and a couple of others that don't follow the rules established by the rest? Thanks!
4
0
528
Jul ’24
Network framework on macOS
This was mentioned in another thread 4 years ago: This whole discussion assumes that every network connection requires a socket. This isn’t the case on most Apple platforms, which have a user-space networking stack that you can access via the Network framework [1]. [1] The one exception here is macOS, where Network framework has to run through the kernel in order to support NKEs. This is one of the reasons we’re in the process of phasing out NKE support, starting with their deprecation in the macOS 10.15 SDK. Is macOS still an unfortunate exception that requires a socket per Network framework's connection?
22
1
1.4k
May ’24
We need more RAM
Posting this on behalf of my colleague, who has a project in mind that requires a huge amount of RAM. Is it true that modern Mac Pro's can only have up to 192GB of RAM which is about 8 times less than 5 years old intel based Mac Pros?
3
0
545
May ’24
`getifaddrs` "struct ifa_data"
The man page for getifaddrs states: The ifa_data field references address family specific data. For AF_LINK addresses it contains a pointer to the struct if_data (as defined in include file <net/if.h>) which contains various interface attributes and statistics. For all other address families, it contains a pointer to the struct ifa_data (as defined in include file <net/if.h>) which contains per-address interface statistics. I assume that "AF_LINK address" is the one that has AF_LINK in the p.ifa_addr.sa_family field. However I do not see "struct ifa_data" anywehere. Is this a documentation bug and if so how do I read this documentation right?
5
0
626
Apr ’24
Bluetooth: prohibiting or detecting unwanted pairing request alert on connect
When calling CBCentralManager's connectPeripheral:options: with some Bluetooth devices I'm getting the "Bluetooth Pairing Request" alert on iOS and a similar "Connection Request from:" alert on macOS. Is there a way to determine upfront if the alert is going to be presented or not? Alternatively is there a way to prohibit presenting this alert (in which case the connect request could fail, which is totally fine)? I tried specifying these options: var manager: CBCentralManager ... manager.connect( peripheral, options: [ CBConnectPeripheralOptionNotifyOnConnectionKey: false, CBConnectPeripheralOptionNotifyOnDisconnectionKey: false, CBConnectPeripheralOptionNotifyOnNotificationKey: false ] ) but those didn't help (and by the doc they shouldn't help as they relate to the use case of app running in background, which is not applicable in my case – my app runs and calls connect when it is in foreground, the unwanted alert is displayed immediately).
2
0
604
Mar ’24
CoreBluetooth: txPowerLevel + rssi = distance?
Using CoreBluetooth I am getting these values from CBCentralManagerDelegate's didDiscover peripheral delegate method: kCBAdvDataTxPowerLevel: 12 (could be other number like 7, 0 or a small negative number) This one is taken from advertisementData parameter. This key might be absent. rssi: -68 (or -60, -100, etc) this is taken from the "rssi" parameter (always present). I am looking for a formula to calculate approximate distance based on these two numbers. Is that possible? I know that ideally I need to know rssi0 (rssi at 1 meter), but I don't see how I can get that via CoreBluetooth API or other means (without actually measuring rssi at one meter distance which is not good for me). How could I approximate rssi0 value with "kCBAdvDataTxPowerLevel"?
4
0
912
Feb ’24
Low level audio recording on macOS. Please Help!
I am struggling to see why the following low-level audio recording function - which is based on tn2091 - Device input using the HAL Output Audio Unit - (a great article, btw, although a bit dated, and it would be wonderful if it was updated to use Swift and non deprecated stuff at some point!) fails to work under macOS: func createMicUnit() -> AUAudioUnit { let compDesc = AudioComponentDescription( componentType: kAudioUnitType_Output, componentSubType: kAudioUnitSubType_HALOutput, // I am on macOS, os this is good componentManufacturer: kAudioUnitManufacturer_Apple, componentFlags: 0, componentFlagsMask: 0) return try! AUAudioUnit(componentDescription: compDesc, options: []) } func startMic() { // mic permision is already granted at this point, but let's check let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.audio) precondition(status == .authorized) // yes, all good let unit = createMicUnit() unit.isInputEnabled = true unit.isOutputEnabled = false precondition(!unit.canPerformInput) // can't record yet, and know why? print(deviceName(unit.deviceID)) // "MacBook Pro Speakers" - this is why let micDeviceID = defaultInputDeviceID print(deviceName(micDeviceID)) // "MacBook Pro Microphone" - this is better try! unit.setDeviceID(micDeviceID) // let's switch device to mic precondition(unit.canPerformInput) // now we can record print("\(String(describing: unit.channelMap))") // channel map is "nil" by default unit.channelMap = [0] // not sure if this helps or not let sampleRate = deviceActualFrameRate(micDeviceID) print(sampleRate) // 48000.0 let format = AVAudioFormat( commonFormat: .pcmFormatFloat32, sampleRate: sampleRate, channels: 1, interleaved: false)! try! unit.outputBusses[1].setFormat(format) unit.inputHandler = { flags, timeStamp, frameCount, bus in fatalError("never gets here") // now the weird part - this is never called! } try! unit.allocateRenderResources() try! unit.startHardware() // let's go! print("mic should be working now... why it doesn't?") // from now on the (UI) app continues its normal run loop } All sanity checks pass with flying colors but unit's inputHandler is not being called. Any idea why? Thank you!
3
0
1.7k
Jan ’23