Skip to content

Commit b1777b1

Browse files
committed
[SE-0112] Teach MachError to store the underlying NSError.
The error code is now specified by MachErrorCode.
1 parent d3f077e commit b1777b1

File tree

2 files changed

+310
-2
lines changed

2 files changed

+310
-2
lines changed

stdlib/public/Platform/MachError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#if os(OSX) || os(iOS) || os(tvOS) || os(watchOS)
22
/// Enumeration describing Mach error codes.
3-
@objc public enum MachError : Int32 {
3+
@objc public enum MachErrorCode : Int32 {
44
case KERN_SUCCESS = 0
55

66
/// Specified address is not currently valid.

stdlib/public/SDK/Foundation/NSError.swift

Lines changed: 309 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,8 +2199,316 @@ extension POSIXError {
21992199
}
22002200
}
22012201

2202-
extension MachError : _BridgedNSError {
2202+
/// Describes an error in the Mach error domain.
2203+
public struct MachError : _BridgedStoredNSError {
2204+
public let _nsError: NSError
2205+
2206+
public init(_nsError error: NSError) {
2207+
precondition(error.domain == NSMachErrorDomain)
2208+
self._nsError = error
2209+
}
2210+
22032211
public static var _nsErrorDomain: String { return NSMachErrorDomain }
2212+
2213+
public typealias Code = MachErrorCode
2214+
}
2215+
2216+
extension MachErrorCode : _ErrorCodeProtocol {
2217+
public typealias ErrorType = MachError
2218+
}
2219+
2220+
extension MachError {
2221+
public static var KERN_SUCCESS: MachError.Code {
2222+
return .KERN_SUCCESS
2223+
}
2224+
2225+
/// Specified address is not currently valid.
2226+
public static var KERN_INVALID_ADDRESS: MachError.Code {
2227+
return .KERN_INVALID_ADDRESS
2228+
}
2229+
2230+
/// Specified memory is valid, but does not permit the required
2231+
/// forms of access.
2232+
public static var KERN_PROTECTION_FAILURE: MachError.Code {
2233+
return .KERN_PROTECTION_FAILURE
2234+
}
2235+
2236+
/// The address range specified is already in use, or no address
2237+
/// range of the size specified could be found.
2238+
public static var KERN_NO_SPACE: MachError.Code {
2239+
return .KERN_NO_SPACE
2240+
}
2241+
2242+
/// The function requested was not applicable to this type of
2243+
/// argument, or an argument is invalid.
2244+
public static var KERN_INVALID_ARGUMENT: MachError.Code {
2245+
return .KERN_INVALID_ARGUMENT
2246+
}
2247+
2248+
/// The function could not be performed. A catch-all.
2249+
public static var KERN_FAILURE: MachError.Code {
2250+
return .KERN_FAILURE
2251+
}
2252+
2253+
/// A system resource could not be allocated to fulfill this
2254+
/// request. This failure may not be permanent.
2255+
public static var KERN_RESOURCE_SHORTAGE: MachError.Code {
2256+
return .KERN_RESOURCE_SHORTAGE
2257+
}
2258+
2259+
/// The task in question does not hold receive rights for the port
2260+
/// argument.
2261+
public static var KERN_NOT_RECEIVER: MachError.Code {
2262+
return .KERN_NOT_RECEIVER
2263+
}
2264+
2265+
/// Bogus access restriction.
2266+
public static var KERN_NO_ACCESS: MachError.Code {
2267+
return .KERN_NO_ACCESS
2268+
}
2269+
2270+
/// During a page fault, the target address refers to a memory
2271+
/// object that has been destroyed. This failure is permanent.
2272+
public static var KERN_MEMORY_FAILURE: MachError.Code {
2273+
return .KERN_MEMORY_FAILURE
2274+
}
2275+
2276+
/// During a page fault, the memory object indicated that the data
2277+
/// could not be returned. This failure may be temporary; future
2278+
/// attempts to access this same data may succeed, as defined by the
2279+
/// memory object.
2280+
public static var KERN_MEMORY_ERROR: MachError.Code {
2281+
return .KERN_MEMORY_ERROR
2282+
}
2283+
2284+
/// The receive right is already a member of the portset.
2285+
public static var KERN_ALREADY_IN_SET: MachError.Code {
2286+
return .KERN_ALREADY_IN_SET
2287+
}
2288+
2289+
/// The receive right is not a member of a port set.
2290+
public static var KERN_NOT_IN_SET: MachError.Code {
2291+
return .KERN_NOT_IN_SET
2292+
}
2293+
2294+
/// The name already denotes a right in the task.
2295+
public static var KERN_NAME_EXISTS: MachError.Code {
2296+
return .KERN_NAME_EXISTS
2297+
}
2298+
2299+
/// The operation was aborted. Ipc code will catch this and reflect
2300+
/// it as a message error.
2301+
public static var KERN_ABORTED: MachError.Code {
2302+
return .KERN_ABORTED
2303+
}
2304+
2305+
/// The name doesn't denote a right in the task.
2306+
public static var KERN_INVALID_NAME: MachError.Code {
2307+
return .KERN_INVALID_NAME
2308+
}
2309+
2310+
/// Target task isn't an active task.
2311+
public static var KERN_INVALID_TASK: MachError.Code {
2312+
return .KERN_INVALID_TASK
2313+
}
2314+
2315+
/// The name denotes a right, but not an appropriate right.
2316+
public static var KERN_INVALID_RIGHT: MachError.Code {
2317+
return .KERN_INVALID_RIGHT
2318+
}
2319+
2320+
/// A blatant range error.
2321+
public static var KERN_INVALID_VALUE: MachError.Code {
2322+
return .KERN_INVALID_VALUE
2323+
}
2324+
2325+
/// Operation would overflow limit on user-references.
2326+
public static var KERN_UREFS_OVERFLOW: MachError.Code {
2327+
return .KERN_UREFS_OVERFLOW
2328+
}
2329+
2330+
/// The supplied (port) capability is improper.
2331+
public static var KERN_INVALID_CAPABILITY: MachError.Code {
2332+
return .KERN_INVALID_CAPABILITY
2333+
}
2334+
2335+
/// The task already has send or receive rights for the port under
2336+
/// another name.
2337+
public static var KERN_RIGHT_EXISTS: MachError.Code {
2338+
return .KERN_RIGHT_EXISTS
2339+
}
2340+
2341+
/// Target host isn't actually a host.
2342+
public static var KERN_INVALID_HOST: MachError.Code {
2343+
return .KERN_INVALID_HOST
2344+
}
2345+
2346+
/// An attempt was made to supply "precious" data for memory that is
2347+
/// already present in a memory object.
2348+
public static var KERN_MEMORY_PRESENT: MachError.Code {
2349+
return .KERN_MEMORY_PRESENT
2350+
}
2351+
2352+
/// A page was requested of a memory manager via
2353+
/// memory_object_data_request for an object using a
2354+
/// MEMORY_OBJECT_COPY_CALL strategy, with the VM_PROT_WANTS_COPY
2355+
/// flag being used to specify that the page desired is for a copy
2356+
/// of the object, and the memory manager has detected the page was
2357+
/// pushed into a copy of the object while the kernel was walking
2358+
/// the shadow chain from the copy to the object. This error code is
2359+
/// delivered via memory_object_data_error and is handled by the
2360+
/// kernel (it forces the kernel to restart the fault). It will not
2361+
/// be seen by users.
2362+
public static var KERN_MEMORY_DATA_MOVED: MachError.Code {
2363+
return .KERN_MEMORY_DATA_MOVED
2364+
}
2365+
2366+
/// A strategic copy was attempted of an object upon which a quicker
2367+
/// copy is now possible. The caller should retry the copy using
2368+
/// vm_object_copy_quickly. This error code is seen only by the
2369+
/// kernel.
2370+
public static var KERN_MEMORY_RESTART_COPY: MachError.Code {
2371+
return .KERN_MEMORY_RESTART_COPY
2372+
}
2373+
2374+
/// An argument applied to assert processor set privilege was not a
2375+
/// processor set control port.
2376+
public static var KERN_INVALID_PROCESSOR_SET: MachError.Code {
2377+
return .KERN_INVALID_PROCESSOR_SET
2378+
}
2379+
2380+
/// The specified scheduling attributes exceed the thread's limits.
2381+
public static var KERN_POLICY_LIMIT: MachError.Code {
2382+
return .KERN_POLICY_LIMIT
2383+
}
2384+
2385+
/// The specified scheduling policy is not currently enabled for the
2386+
/// processor set.
2387+
public static var KERN_INVALID_POLICY: MachError.Code {
2388+
return .KERN_INVALID_POLICY
2389+
}
2390+
2391+
/// The external memory manager failed to initialize the memory object.
2392+
public static var KERN_INVALID_OBJECT: MachError.Code {
2393+
return .KERN_INVALID_OBJECT
2394+
}
2395+
2396+
/// A thread is attempting to wait for an event for which there is
2397+
/// already a waiting thread.
2398+
public static var KERN_ALREADY_WAITING: MachError.Code {
2399+
return .KERN_ALREADY_WAITING
2400+
}
2401+
2402+
/// An attempt was made to destroy the default processor set.
2403+
public static var KERN_DEFAULT_SET: MachError.Code {
2404+
return .KERN_DEFAULT_SET
2405+
}
2406+
2407+
/// An attempt was made to fetch an exception port that is
2408+
/// protected, or to abort a thread while processing a protected
2409+
/// exception.
2410+
public static var KERN_EXCEPTION_PROTECTED: MachError.Code {
2411+
return .KERN_EXCEPTION_PROTECTED
2412+
}
2413+
2414+
/// A ledger was required but not supplied.
2415+
public static var KERN_INVALID_LEDGER: MachError.Code {
2416+
return .KERN_INVALID_LEDGER
2417+
}
2418+
2419+
/// The port was not a memory cache control port.
2420+
public static var KERN_INVALID_MEMORY_CONTROL: MachError.Code {
2421+
return .KERN_INVALID_MEMORY_CONTROL
2422+
}
2423+
2424+
/// An argument supplied to assert security privilege was not a host
2425+
/// security port.
2426+
public static var KERN_INVALID_SECURITY: MachError.Code {
2427+
return .KERN_INVALID_SECURITY
2428+
}
2429+
2430+
/// thread_depress_abort was called on a thread which was not
2431+
/// currently depressed.
2432+
public static var KERN_NOT_DEPRESSED: MachError.Code {
2433+
return .KERN_NOT_DEPRESSED
2434+
}
2435+
2436+
/// Object has been terminated and is no longer available.
2437+
public static var KERN_TERMINATED: MachError.Code {
2438+
return .KERN_TERMINATED
2439+
}
2440+
2441+
/// Lock set has been destroyed and is no longer available.
2442+
public static var KERN_LOCK_SET_DESTROYED: MachError.Code {
2443+
return .KERN_LOCK_SET_DESTROYED
2444+
}
2445+
2446+
/// The thread holding the lock terminated before releasing the lock.
2447+
public static var KERN_LOCK_UNSTABLE: MachError.Code {
2448+
return .KERN_LOCK_UNSTABLE
2449+
}
2450+
2451+
/// The lock is already owned by another thread.
2452+
public static var KERN_LOCK_OWNED: MachError.Code {
2453+
return .KERN_LOCK_OWNED
2454+
}
2455+
2456+
/// The lock is already owned by the calling thread.
2457+
public static var KERN_LOCK_OWNED_SELF: MachError.Code {
2458+
return .KERN_LOCK_OWNED_SELF
2459+
}
2460+
2461+
/// Semaphore has been destroyed and is no longer available.
2462+
public static var KERN_SEMAPHORE_DESTROYED: MachError.Code {
2463+
return .KERN_SEMAPHORE_DESTROYED
2464+
}
2465+
2466+
/// Return from RPC indicating the target server was terminated
2467+
/// before it successfully replied.
2468+
public static var KERN_RPC_SERVER_TERMINATED: MachError.Code {
2469+
return .KERN_RPC_SERVER_TERMINATED
2470+
}
2471+
2472+
/// Terminate an orphaned activation.
2473+
public static var KERN_RPC_TERMINATE_ORPHAN: MachError.Code {
2474+
return .KERN_RPC_TERMINATE_ORPHAN
2475+
}
2476+
2477+
/// Allow an orphaned activation to continue executing.
2478+
public static var KERN_RPC_CONTINUE_ORPHAN: MachError.Code {
2479+
return .KERN_RPC_CONTINUE_ORPHAN
2480+
}
2481+
2482+
/// Empty thread activation (No thread linked to it).
2483+
public static var KERN_NOT_SUPPORTED: MachError.Code {
2484+
return .KERN_NOT_SUPPORTED
2485+
}
2486+
2487+
/// Remote node down or inaccessible.
2488+
public static var KERN_NODE_DOWN: MachError.Code {
2489+
return .KERN_NODE_DOWN
2490+
}
2491+
2492+
/// A signalled thread was not actually waiting.
2493+
public static var KERN_NOT_WAITING: MachError.Code {
2494+
return .KERN_NOT_WAITING
2495+
}
2496+
2497+
/// Some thread-oriented operation (semaphore_wait) timed out.
2498+
public static var KERN_OPERATION_TIMED_OUT: MachError.Code {
2499+
return .KERN_OPERATION_TIMED_OUT
2500+
}
2501+
2502+
/// During a page fault, indicates that the page was rejected as a
2503+
/// result of a signature check.
2504+
public static var KERN_CODESIGN_ERROR: MachError.Code {
2505+
return .KERN_CODESIGN_ERROR
2506+
}
2507+
2508+
/// The requested property cannot be changed at this time.
2509+
public static var KERN_POLICY_STATIC: MachError.Code {
2510+
return .KERN_POLICY_STATIC
2511+
}
22042512
}
22052513

22062514
public struct ErrorUserInfoKey : RawRepresentable, _SwiftNewtypeWrapper, Equatable, Hashable, _ObjectiveCBridgeable {

0 commit comments

Comments
 (0)