Skip to content

Repo sync for protected branch #5153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/cpp/declspec.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
description: "Learn more about: `__declspec`"
title: "__declspec"
ms.date: 03/01/2022
ms.date: 1/14/2025
f1_keywords: ["__declspec_cpp", "__declspec", "_declspec"]
helpviewer_keywords: ["__declspec keyword [C++]"]
---
# `__declspec`

**Microsoft Specific**

The extended attribute syntax for specifying storage-class information uses the **`__declspec`** keyword, which specifies that an instance of a given type is to be stored with a Microsoft-specific storage-class attribute listed below. Examples of other storage-class modifiers include the **`static`** and **`extern`** keywords. However, these keywords are part of the ANSI specification of the C and C++ languages, and as such aren't covered by extended attribute syntax. The extended attribute syntax simplifies and standardizes Microsoft-specific extensions to the C and C++ languages.
The extended attribute syntax for specifying storage-class information uses the `__declspec` keyword, which specifies that an instance of a given type is to be stored with a Microsoft-specific storage-class attribute listed below. Examples of other storage-class modifiers include the `static` and `extern` keywords. However, these keywords are part of the ANSI specification of the C and C++ languages, and as such aren't covered by extended attribute syntax. The extended attribute syntax simplifies and standardizes Microsoft-specific extensions to the C and C++ languages.

## Grammar

Expand All @@ -30,6 +30,7 @@ The extended attribute syntax for specifying storage-class information uses the
 **`dllimport`**\
 **`dllexport`**\
 **`empty_bases`**\
 **`hybrid_patchable`**\
 **`jitintrinsic`**\
 **`naked`**\
 **`noalias`**\
Expand Down
49 changes: 49 additions & 0 deletions docs/cpp/hybrid-patchable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
description: "Learn more about: hybrid_patchable (C++)"
title: "hybrid_patchable (C++)"
ms.date: 1/15/2025
f1_keywords: ["hybrid_patchable"]
helpviewer_keywords: ["__declspec keyword [C++], hybrid_patchable", "hybrid_patchable __declspec keyword"]
---
# `hybrid_patchable` (C++)

**Microsoft Specific**

Use `__declspec(hybrid_patchable)` to mark a function as a hybrid patchable function. This attribute generates a fast-forward sequence. Fast-forward sequences are small x64 functions which contain no real logic, and tail-call the real Arm64EC function. Because fast-forward sequences are primarily used for hooking, if they are unaltered, execution is transferred directly to the Arm64EC function.

## Syntax

> `__declspec(hybrid_patchable)`

## Remarks

`__declspec(hybrid_patchable)` is an ARM64EC-only feature.

**Example:**

```cpp
__declspec(hybrid_patchable) int Example()
{
return 1;
}
```

Generates the following fast-forward sequence:

```
EXP+#Example:
00000001400CE000: 48 8B C4 mov rax,rsp
00000001400CE003: 48 89 58 20 mov qword ptr [rax+20h],rbx
00000001400CE007: 55 push rbp
00000001400CE008: 5D pop rbp
00000001400CE009: E9 BA 7A F3 FF jmp #Example
00000001400CE00E: CC int 3
00000001400CE00F: CC int 3
```

**END Microsoft Specific**

## See also

[`__declspec`](../cpp/declspec.md)\
[Fast-Forward sequences](/windows/arm/arm64ec-abi#fast-forward-sequences)
2 changes: 2 additions & 0 deletions docs/cpp/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,8 @@ items:
href: ../cpp/using-dllimport-and-dllexport-in-cpp-classes.md
- name: empty_bases
href: ../cpp/empty-bases.md
- name: hybrid_patchable
href: ../cpp/hybrid-patchable.md
- name: jitintrinsic
href: ../cpp/jitintrinsic.md
- name: naked
Expand Down