Skip to content

Instantly share code, notes, and snippets.

@orion160
Last active September 1, 2024 18:16
Show Gist options
  • Select an option

  • Save orion160/4049fe811aae0e333c630cd13a7d8ed5 to your computer and use it in GitHub Desktop.

Select an option

Save orion160/4049fe811aae0e333c630cd13a7d8ed5 to your computer and use it in GitHub Desktop.

Revisions

  1. orion160 revised this gist Sep 1, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -118,6 +118,8 @@ Special care is taken with `X18` register which is reserved as a platform regist
    [LLVM LIBC cmake build rules](https://libc.llvm.org/dev/cmake_build_rules.html)
    [add_entrypoint_object definition](https://github.com/llvm/llvm-project/blob/main/libc/cmake/modules/LLVMLibCObjectRules.cmake)
    ### gnu naked
    `[[gnu::naked]]` attribute
    > Use this attribute on the ARM, AVR, MCORE, MSP430, NDS32, RL78, RX and SPU ports to indicate that the specified function does not need prologue/epilogue sequences generated by the compiler. It is up to the programmer to provide these sequences. The only statements that can be safely included in naked functions are asm statements that do not have operands. All other statements, including declarations of local variables, if statements, and so forth, should be avoided. Naked functions should be used to implement the body of an assembly function, while allowing the compiler to construct the requisite function declaration for the assembler.
  2. orion160 revised this gist Sep 1, 2024. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -114,8 +114,11 @@ Special care is taken with `X18` register which is reserved as a platform regist
    ## Misc
    TODO: investigate on `add_entrypoint_object` cmake
    ### add_entrypoint_object
    [LLVM LIBC cmake build rules](https://libc.llvm.org/dev/cmake_build_rules.html)
    ### gnu naked
    `[[gnu::naked]]` attribute
    > Use this attribute on the ARM, AVR, MCORE, MSP430, NDS32, RL78, RX and SPU ports to indicate that the specified function does not need prologue/epilogue sequences generated by the compiler. It is up to the programmer to provide these sequences. The only statements that can be safely included in naked functions are asm statements that do not have operands. All other statements, including declarations of local variables, if statements, and so forth, should be avoided. Naked functions should be used to implement the body of an assembly function, while allowing the compiler to construct the requisite function declaration for the assembler.
  3. orion160 revised this gist Sep 1, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,8 @@

    > Pointer Authentication
    [USENIX Security '19 - PAC it up: Towards Pointer Integrity using ARM Pointer Authentication](https://www.youtube.com/watch?v=UD1KKHyPnZ4)

    ### Instructions

    > There are two main operations needed for Pointer Authentication: computing and adding a PAC, and verifying a
  4. orion160 revised this gist Sep 1, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,8 @@ exception and an authentication failure by checking the pattern that the AUT ins
    ### PACIBSP & AUTIBSP

    > Pointer Authentication Code for Instruction Base Stack Pointer
    >
    ## BTI

    > Branch Target Identification
  5. orion160 revised this gist Sep 1, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@

    > Pointer Authentication
    ## Instructions
    ### Instructions

    > There are two main operations needed for Pointer Authentication: computing and adding a PAC, and verifying a
    PAC and restoring the pointer value. These are handled by the PAC* and AUT* sets of instructions respectively. If
  6. orion160 revised this gist Sep 1, 2024. 1 changed file with 10 additions and 8 deletions.
    18 changes: 10 additions & 8 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -10,17 +10,19 @@
    ## Instructions

    ### PACIASP
    > There are two main operations needed for Pointer Authentication: computing and adding a PAC, and verifying a
    PAC and restoring the pointer value. These are handled by the PAC* and AUT* sets of instructions respectively. If
    verification fails during the AUT instruction, the processor replaces the PAC with a specific pattern that makes the
    pointer value an illegal address. The actual error detection happens through the illegal address exception when an
    invalid pointer is dereferenced. This design decouples error handling from the instruction and removes the need
    to use additional instructions for error handling. The exception handler can distinguish between an illegal address
    exception and an authentication failure by checking the pattern that the AUT instruction uses to signal the error.

    > Pointer Authentication Code for Instruction Address Stack Pointer
    ### PACIBSP
    ### PACIASP & AUTIASP

    > Pointer Authentication Code for Instruction Address Base Stack Pointer
    ### AUTIASP
    > Pointer Authentication Code for Instruction Address Stack Pointer
    ### AUTIBSP
    ### PACIBSP & AUTIBSP

    ## BTI

  7. orion160 revised this gist Sep 1, 2024. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -12,12 +12,16 @@

    ### PACIASP

    > Pointer Authentication Code for Instruction Address Stack Pointer)
    > Pointer Authentication Code for Instruction Address Stack Pointer
    ### PACIBSP

    > Pointer Authentication Code for Instruction Address Base Stack Pointer
    ### AUTIASP

    ### AUTIBSP

    ## BTI

    > Branch Target Identification
  8. orion160 revised this gist Sep 1, 2024. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,16 @@

    > Pointer Authentication
    ## Instructions

    ### PACIASP

    > Pointer Authentication Code for Instruction Address Stack Pointer)
    ### PACIBSP

    > Pointer Authentication Code for Instruction Address Base Stack Pointer
    ## BTI

    > Branch Target Identification
  9. orion160 revised this gist Sep 1, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -97,6 +97,7 @@ Special care is taken with `X18` register which is reserved as a platform regist
    TODO: investigate on `add_entrypoint_object` cmake
    `[[gnu::naked]]` attribute
    > Use this attribute on the ARM, AVR, MCORE, MSP430, NDS32, RL78, RX and SPU ports to indicate that the specified function does not need prologue/epilogue sequences generated by the compiler. It is up to the programmer to provide these sequences. The only statements that can be safely included in naked functions are asm statements that do not have operands. All other statements, including declarations of local variables, if statements, and so forth, should be avoided. Naked functions should be used to implement the body of an assembly function, while allowing the compiler to construct the requisite function declaration for the assembler.
    [Attributes reference](https://clang.llvm.org/docs/AttributeReference.html)
  10. orion160 revised this gist Sep 1, 2024. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -97,3 +97,7 @@ Special care is taken with `X18` register which is reserved as a platform regist
    TODO: investigate on `add_entrypoint_object` cmake
    `[[gnu::naked]]` attribute
    [Attributes reference](https://clang.llvm.org/docs/AttributeReference.html)
    ![image](https://gist.github.com/user-attachments/assets/5445e4c2-c15a-457a-87a3-1e5cc8dd2886)
  11. orion160 revised this gist Sep 1, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -96,4 +96,4 @@ Special care is taken with `X18` register which is reserved as a platform regist
    TODO: investigate on `add_entrypoint_object` cmake
    [[gnu::naked]] attribute
    `[[gnu::naked]]` attribute
  12. orion160 revised this gist Sep 1, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -95,3 +95,5 @@ Special care is taken with `X18` register which is reserved as a platform regist
    ## Misc
    TODO: investigate on `add_entrypoint_object` cmake
    [[gnu::naked]] attribute
  13. orion160 revised this gist Sep 1, 2024. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -28,10 +28,14 @@ These routines can be used for error handling recovery, and are included in `<se

    Saves the current execution context into a variable of type `jmp_buf`. It returns `0` on the first call, and a value different from zero if program control is restored with `longjmp`.

    [impl](https://github.com/llvm/llvm-project/blob/main/libc/src/setjmp/aarch64/setjmp.cpp)

    ### longjmp

    Loads the execution context env saved by a previous call to `setjmp`. **If the function that called setjmp has exited, the behavior is undefined (in other words, only long jumps up the call stack are allowed).**

    [impl](https://github.com/llvm/llvm-project/blob/main/libc/src/setjmp/aarch64/longjmp.cpp)

    ## Example

    [GODBOLT](https://godbolt.org/z/je9qEYYYx)
  14. orion160 revised this gist Sep 1, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -86,7 +86,7 @@ int main(int argc, char **argv) {
    Special care is taken with `X18` register which is reserved as a platform register.
    `jmp_buf` is defined at [src](https://github.com/llvm/llvm-project/blob/2a6268d8f999d56a557079e7fd8ee8c4a4e9ac0c/libc/include/llvm-libc-types/jmp_buf.h). Which stores register states.
    `jmp_buf` is defined at [src](https://github.com/llvm/llvm-project/blob/main/libc/include/llvm-libc-types/jmp_buf.h). Which stores register states.
    ## Misc
  15. orion160 revised this gist Sep 1, 2024. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -87,3 +87,7 @@ int main(int argc, char **argv) {
    Special care is taken with `X18` register which is reserved as a platform register.
    `jmp_buf` is defined at [src](https://github.com/llvm/llvm-project/blob/2a6268d8f999d56a557079e7fd8ee8c4a4e9ac0c/libc/include/llvm-libc-types/jmp_buf.h). Which stores register states.
    ## Misc
    TODO: investigate on `add_entrypoint_object` cmake
  16. orion160 revised this gist Sep 1, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -86,4 +86,4 @@ int main(int argc, char **argv) {
    Special care is taken with `X18` register which is reserved as a platform register.
    `jmp_buf` is defined at [src](https://github.com/llvm/llvm-project/blob/2a6268d8f999d56a557079e7fd8ee8c4a4e9ac0c/libc/include/llvm-libc-types/jmp_buf.h).
    `jmp_buf` is defined at [src](https://github.com/llvm/llvm-project/blob/2a6268d8f999d56a557079e7fd8ee8c4a4e9ac0c/libc/include/llvm-libc-types/jmp_buf.h). Which stores register states.
  17. orion160 revised this gist Sep 1, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -85,3 +85,5 @@ int main(int argc, char **argv) {
    ## Implementation
    Special care is taken with `X18` register which is reserved as a platform register.
    `jmp_buf` is defined at [src](https://github.com/llvm/llvm-project/blob/2a6268d8f999d56a557079e7fd8ee8c4a4e9ac0c/libc/include/llvm-libc-types/jmp_buf.h).
  18. orion160 revised this gist Sep 1, 2024. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -80,4 +80,8 @@ int main(int argc, char **argv) {

    return 0;
    }
    ```
    ```
    ## Implementation
    Special care is taken with `X18` register which is reserved as a platform register.
  19. orion160 revised this gist Sep 1, 2024. 1 changed file with 50 additions and 0 deletions.
    50 changes: 50 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -31,3 +31,53 @@ Saves the current execution context into a variable of type `jmp_buf`. It return
    ### longjmp

    Loads the execution context env saved by a previous call to `setjmp`. **If the function that called setjmp has exited, the behavior is undefined (in other words, only long jumps up the call stack are allowed).**

    ## Example

    [GODBOLT](https://godbolt.org/z/je9qEYYYx)

    ```c
    #include <math.h>
    #include <setjmp.h>
    #include <stdio.h>

    typedef enum { DIV_BY_ZERO = 1 } division_exceptions;

    jmp_buf divide_exception_h;

    float divide(float x, float y) {
    if (y < 1e-6) {
    longjmp(divide_exception_h, DIV_BY_ZERO);
    }

    return x / y;
    }

    int main(int argc, char **argv) {
    switch (setjmp(divide_exception_h)) {
    case 0:
    float a = 1.0f;
    float b = 2.0f;
    float r = divide(a, b);
    printf("%f = %f / %f\n", r, a, b);
    break;
    case DIV_BY_ZERO:
    printf("Cannot divide by zero...\n");
    break;
    }

    switch (setjmp(divide_exception_h)) {
    case 0:
    float a = 1.0f;
    float b = 0.0f;
    float r = divide(a, b);
    printf("%f = %f / %f\n", r, a, b);
    break;
    case DIV_BY_ZERO:
    printf("Cannot divide by zero...\n");
    break;
    }

    return 0;
    }
    ```
  20. orion160 revised this gist Sep 1, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,4 @@ Saves the current execution context into a variable of type `jmp_buf`. It return

    ### longjmp

    Loads the execution context env saved by a previous call to `setjmp`.
    Loads the execution context env saved by a previous call to `setjmp`. **If the function that called setjmp has exited, the behavior is undefined (in other words, only long jumps up the call stack are allowed).**
  21. orion160 revised this gist Sep 1, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -29,3 +29,5 @@ These routines can be used for error handling recovery, and are included in `<se
    Saves the current execution context into a variable of type `jmp_buf`. It returns `0` on the first call, and a value different from zero if program control is restored with `longjmp`.

    ### longjmp

    Loads the execution context env saved by a previous call to `setjmp`.
  22. orion160 revised this gist Sep 1, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -26,4 +26,6 @@ These routines can be used for error handling recovery, and are included in `<se

    ### setjmp

    Saves the current execution context into a variable of type `jmp_buf`. It returns `0` on the first call, and a value different from zero if program control is restored with `longjmp`.

    ### longjmp
  23. orion160 revised this gist Sep 1, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@

    ## libc functions

    These routines can be used for error handling recovery, and are included int ´<setjmp.h>´
    These routines can be used for error handling recovery, and are included in `<setjmp.h>`

    ### setjmp

  24. orion160 revised this gist Sep 1, 2024. No changes.
  25. orion160 revised this gist Sep 1, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,8 @@

    ## libc functions

    These routines can be used for error handling recovery, and are included int ´<setjmp.h>´

    ### setjmp

    ### longjmp
  26. orion160 revised this gist Sep 1, 2024. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -19,3 +19,9 @@
    ## Procedura call

    **AAPCS64** -> ARM Architecture Procedure Call Standard for 64-bit

    ## libc functions

    ### setjmp

    ### longjmp
  27. orion160 revised this gist Sep 1, 2024. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -15,3 +15,7 @@
    ## MTE

    > Memory Tagging Extension
    ## Procedura call

    **AAPCS64** -> ARM Architecture Procedure Call Standard for 64-bit
  28. orion160 revised this gist Sep 1, 2024. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@
    ## BTI

    > Branch Target Identification
    ## MTE

    > Memory tagging extension
    > Memory Tagging Extension
  29. orion160 revised this gist Sep 1, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # LLVM libc AArch64 setjmp/longjmp

    [commit](https://github.com/llvm/llvm-project/commit/2a6268d8f999)

    ## AArch64 extensions

    ## PAC
  30. orion160 revised this gist Sep 1, 2024. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions llvm_aarch64_libc_setjmp+longjmp.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,13 @@
    # LLVM libc AArch64 setjmp/longjmp

    ## AArch64 extensions

    ## PAC

    > Pointer Authentication
    ## BTI

    ## MTE

    > Memory tagging extension