Skip to content
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

mysterious native stack overflow check calculation #3297

Closed
yamt opened this issue Apr 9, 2024 · 4 comments
Closed

mysterious native stack overflow check calculation #3297

yamt opened this issue Apr 9, 2024 · 4 comments

Comments

@yamt
Copy link
Collaborator

yamt commented Apr 9, 2024

invoke_native_with_hw_bound_check and call_wasm_with_hw_bound_check have native stack overflow checks
against native_stack_boundary + page_size * (guard_page_count + 1).
i don't understand where this + 1 came from. @wenyongh do you remember?

@yamt yamt changed the title mysterious native stack check calculation mysterious native stack overflow check calculation Apr 9, 2024
@wenyongh
Copy link
Contributor

wenyongh commented Apr 9, 2024

invoke_native_with_hw_bound_check and call_wasm_with_hw_bound_check have native stack overflow checks against native_stack_boundary + page_size * (guard_page_count + 1). i don't understand where this + 1 came from. @wenyongh do you remember?

@yamt I remember that it is to reserve some stack space to ensure the runtime can successfully call to the AOT function, for example, avoiding core dump at os_setjmp, since wasm_exec_env_push_jmpbuf has been executed before it, if os_setjmp failed, then in the signal handler, the wrong jmpbuf will be popped for os_longjmp to jump. And we had better let stack overflow occurs in AOT code, not sure whether occurring in runtime part (e.g. wasm_runtime_invoke_native) will cause unexpected behavior.

@yamt
Copy link
Collaborator Author

yamt commented Apr 9, 2024

invoke_native_with_hw_bound_check and call_wasm_with_hw_bound_check have native stack overflow checks against native_stack_boundary + page_size * (guard_page_count + 1). i don't understand where this + 1 came from. @wenyongh do you remember?

@yamt I remember that it is to reserve some stack space to ensure the runtime can successfully call to the AOT function, for example, avoiding core dump at os_setjmp, since wasm_exec_env_push_jmpbuf has been executed before it, if os_setjmp failed, then in the signal handler, the wrong jmpbuf will be popped for os_longjmp to jump.

it doesn't seem to make much sense to me because native_stack_boundary at this point already includes WASM_STACK_GUARD_SIZE adjustment, which should be enough for the jmpbuf setup.

And we had better let stack overflow occurs in AOT code, not sure whether occurring in runtime part (e.g. wasm_runtime_invoke_native) will cause unexpected behavior.

it makes sense.
i'm thinking to separate stack consumption of native functions from WASM_STACK_GUARD_SIZE.

@wenyongh
Copy link
Contributor

wenyongh commented Apr 9, 2024

Yes, after some amendings, the code may look a little confusing, please help enhance it if you are glad to.

yamt added a commit to yamt/wasm-micro-runtime that referenced this issue Apr 19, 2024
This is a test code to examine native stack overflow detection logic.

The current output on my environment (macOS amd64):

```shell
====== Interpreter
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 14704 | failed | leaked | Exception: native stack overflow
14704 - 17904 | failed |     ok | Exception: native stack overflow
17904 - 24576 |     ok |     ok |

====== AOT
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 18176 | failed | leaked | Exception: native stack overflow
18176 - 24576 |     ok |     ok |

====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 -  1968 | failed |     ok | Exception: native stack overflow
 1968 - 24576 |     ok |     ok |
```

This is a preparation to work on relevant issues, including:

bytecodealliance#3325
bytecodealliance#3320
bytecodealliance#3314
bytecodealliance#3297
wenyongh pushed a commit that referenced this issue Apr 19, 2024
This is a test code to examine native stack overflow detection logic.

The current output on my environment (macOS amd64):

```shell
====== Interpreter
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 14704 | failed | leaked | Exception: native stack overflow
14704 - 17904 | failed |     ok | Exception: native stack overflow
17904 - 24576 |     ok |     ok |

====== AOT
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 18176 | failed | leaked | Exception: native stack overflow
18176 - 24576 |     ok |     ok |

====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 -  1968 | failed |     ok | Exception: native stack overflow
 1968 - 24576 |     ok |     ok |
```

This is a preparation to work on relevant issues, including:

#3325
#3320
#3314
#3297
yamt added a commit to yamt/wasm-micro-runtime that referenced this issue Apr 24, 2024
@yamt
Copy link
Collaborator Author

yamt commented Apr 25, 2024

fixed by #3351

@yamt yamt closed this as completed Apr 25, 2024
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this issue May 1, 2024
This is a test code to examine native stack overflow detection logic.

The current output on my environment (macOS amd64):

```shell
====== Interpreter
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 14704 | failed | leaked | Exception: native stack overflow
14704 - 17904 | failed |     ok | Exception: native stack overflow
17904 - 24576 |     ok |     ok |

====== AOT
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 18176 | failed | leaked | Exception: native stack overflow
18176 - 24576 |     ok |     ok |

====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 -  1968 | failed |     ok | Exception: native stack overflow
 1968 - 24576 |     ok |     ok |
```

This is a preparation to work on relevant issues, including:

bytecodealliance#3325
bytecodealliance#3320
bytecodealliance#3314
bytecodealliance#3297
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this issue May 2, 2024
This is a test code to examine native stack overflow detection logic.

The current output on my environment (macOS amd64):

```shell
====== Interpreter
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 14704 | failed | leaked | Exception: native stack overflow
14704 - 17904 | failed |     ok | Exception: native stack overflow
17904 - 24576 |     ok |     ok |

====== AOT
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 18176 | failed | leaked | Exception: native stack overflow
18176 - 24576 |     ok |     ok |

====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 -  1968 | failed |     ok | Exception: native stack overflow
 1968 - 24576 |     ok |     ok |
```

This is a preparation to work on relevant issues, including:

bytecodealliance#3325
bytecodealliance#3320
bytecodealliance#3314
bytecodealliance#3297
Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this issue May 27, 2024
This is a test code to examine native stack overflow detection logic.

The current output on my environment (macOS amd64):

```shell
====== Interpreter
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 14704 | failed | leaked | Exception: native stack overflow
14704 - 17904 | failed |     ok | Exception: native stack overflow
17904 - 24576 |     ok |     ok |

====== AOT
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 18176 | failed | leaked | Exception: native stack overflow
18176 - 24576 |     ok |     ok |

====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 -  1968 | failed |     ok | Exception: native stack overflow
 1968 - 24576 |     ok |     ok |
```

This is a preparation to work on relevant issues, including:

bytecodealliance#3325
bytecodealliance#3320
bytecodealliance#3314
bytecodealliance#3297
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this issue May 27, 2024
This is a test code to examine native stack overflow detection logic.

The current output on my environment (macOS amd64):

```shell
====== Interpreter
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 14704 | failed | leaked | Exception: native stack overflow
14704 - 17904 | failed |     ok | Exception: native stack overflow
17904 - 24576 |     ok |     ok |

====== AOT
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 18176 | failed | leaked | Exception: native stack overflow
18176 - 24576 |     ok |     ok |

====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 -  1968 | failed |     ok | Exception: native stack overflow
 1968 - 24576 |     ok |     ok |
```

This is a preparation to work on relevant issues, including:

bytecodealliance#3325
bytecodealliance#3320
bytecodealliance#3314
bytecodealliance#3297
Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants