<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Security",
  "identifier" : "/documentation/Security/SecCodeCopySelf(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Security"
    ],
    "preciseIdentifier" : "c:@F@SecCodeCopySelf"
  },
  "title" : "SecCodeCopySelf(_:_:)"
}
-->

# SecCodeCopySelf(_:_:)

Retrieves the code object for the code making the call.

```
func SecCodeCopySelf(_ flags: SecCSFlags, _ self: UnsafeMutablePointer<SecCode?>) -> OSStatus
```

## Parameters

`flags`

Optional flags; see [`SecCSFlags`](/documentation/Security/SecCSFlags) for possible values. Pass [`kSecCSDefaultFlags`](/documentation/Security/SecCSFlags/kSecCSDefaultFlags) for standard behavior.

`self`

On return, a code object representing the caller.

## Return Value

A result code. See [Code Signing Services Result Codes](/documentation/Security/code-signing-services-result-codes).

## Discussion

A code object (that is, an object of type [`SecCode`](/documentation/Security/SecCode)) represents code that is running on the system. The code can be a UNIX process, a script, an applet, a widget, or any other separately-identifiable code. You can use the code object returned by this function as input to other functions in the Code Signing Services API. This function returns a code object for the code that calls it regardless of whether the code is signed. Call the [`SecCodeCheckValidity(_:_:_:)`](/documentation/Security/SecCodeCheckValidity(_:_:_:)) or [`SecCodeCheckValidityWithErrors(_:_:_:_:)`](/documentation/Security/SecCodeCheckValidityWithErrors(_:_:_:_:)) function to determine whether the code has a valid signature.

If the code calling this function is either a dedicated host or has called the [`SecHostSelectGuest`](/documentation/Security/SecHostSelectGuest) function, then the host is considered to be acting as a proxy for its dedicated or selected guest and the [`SecCodeCopySelf(_:_:)`](/documentation/Security/SecCodeCopySelf(_:_:)) function returns a code object for that guest.  See [`kSecCSDedicatedHost`](/documentation/Security/kSecCSDedicatedHost) for a discussion of dedicated hosts.

## See Also

[`SecCodeCopyGuestWithAttributes(_:_:_:_:)`](/documentation/Security/SecCodeCopyGuestWithAttributes(_:_:_:_:))

Asks a code host to identify one of its guests given the type and value of specific attributes of the guest code.

[`SecCodeCopyHost(_:_:_:)`](/documentation/Security/SecCodeCopyHost(_:_:_:))

Retrieves the code object for the host of specified guest code.

[`SecCodeCopyStaticCode(_:_:_:)`](/documentation/Security/SecCodeCopyStaticCode(_:_:_:))

Returns a static code object representing the on-disk version of the given running code.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)