From 79248ee88b39eb1a5b730f3bc0a995efed4d6a2c Mon Sep 17 00:00:00 2001 From: David Pursell Date: Wed, 30 Oct 2019 10:00:55 -0700 Subject: sys/fuchsia: remove deprecated exception APIs The port-based exception APIs have been deprecated on Fuchsia and will be removed shortly. Delete them from the syscall definitions and modify the Fuchsia executor to use the new channel-based APIs instead. --- pkg/csource/generated.go | 91 +++++++++++++++++++++-------------- pkg/report/testdata/fuchsia/report/24 | 65 ------------------------- 2 files changed, 54 insertions(+), 102 deletions(-) delete mode 100644 pkg/report/testdata/fuchsia/report/24 (limited to 'pkg') diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index 9de67e97e..4bac21f5d 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -799,7 +799,6 @@ static int do_sandbox_setuid(void) #include #include #include -#include static __thread int skip_segv; static __thread jmp_buf segv_env; @@ -814,49 +813,69 @@ static void segv_handler(void) doexit(SIGSEGV); } +static zx_status_t update_exception_thread_regs(zx_handle_t exception) +{ + zx_handle_t thread; + zx_status_t status = zx_exception_get_thread(exception, &thread); + if (status != ZX_OK) { + debug("zx_exception_get_thread failed: %d\n", status); + return status; + } + + zx_thread_state_general_regs_t regs; + status = zx_thread_read_state(thread, ZX_THREAD_STATE_GENERAL_REGS, + ®s, sizeof(regs)); + if (status != ZX_OK) { + debug("zx_thread_read_state failed: %d (%d)\n", + (int)sizeof(regs), status); + } else { +#if GOARCH_amd64 + regs.rip = (uint64)(void*)&segv_handler; +#elif GOARCH_arm64 + regs.pc = (uint64)(void*)&segv_handler; +#else +#error "unsupported arch" +#endif + status = zx_thread_write_state(thread, ZX_THREAD_STATE_GENERAL_REGS, ®s, sizeof(regs)); + if (status != ZX_OK) { + debug("zx_thread_write_state failed: %d\n", status); + } + } + + zx_handle_close(thread); + return status; +} + static void* ex_handler(void* arg) { - zx_handle_t port = (zx_handle_t)(long)arg; + zx_handle_t exception_channel = (zx_handle_t)(long)arg; for (int i = 0; i < 10000; i++) { - zx_port_packet_t packet = {}; - zx_status_t status = zx_port_wait(port, ZX_TIME_INFINITE, &packet); + zx_status_t status = zx_object_wait_one(exception_channel, ZX_CHANNEL_READABLE, ZX_TIME_INFINITE, NULL); if (status != ZX_OK) { - debug("zx_port_wait failed: %d\n", status); + debug("zx_object_wait_one failed: %d\n", status); continue; } - debug("got exception packet: type=%d status=%d tid=%llu\n", - packet.type, packet.status, (unsigned long long)(packet.exception.tid)); - zx_handle_t thread; - status = zx_object_get_child(zx_process_self(), packet.exception.tid, - ZX_RIGHT_SAME_RIGHTS, &thread); + + zx_exception_info_t info; + zx_handle_t exception; + status = zx_channel_read(exception_channel, 0, &info, &exception, sizeof(info), 1, NULL, NULL); if (status != ZX_OK) { - debug("zx_object_get_child failed: %d\n", status); + debug("zx_channel_read failed: %d\n", status); continue; } - zx_thread_state_general_regs_t regs; - status = zx_thread_read_state(thread, ZX_THREAD_STATE_GENERAL_REGS, - ®s, sizeof(regs)); + + debug("got exception: type=%d tid=%llu\n", info.type, (unsigned long long)(info.tid)); + status = update_exception_thread_regs(exception); if (status != ZX_OK) { - debug("zx_thread_read_state failed: %d (%d)\n", - (int)sizeof(regs), status); - } else { -#if GOARCH_amd64 - regs.rip = (uint64)(void*)&segv_handler; -#elif GOARCH_arm64 - regs.pc = (uint64)(void*)&segv_handler; -#else -#error "unsupported arch" -#endif - status = zx_thread_write_state(thread, ZX_THREAD_STATE_GENERAL_REGS, ®s, sizeof(regs)); - if (status != ZX_OK) { - debug("zx_thread_write_state failed: %d\n", status); - } + debug("failed to update exception thread registers: %d\n", status); } - status = zx_task_resume_from_exception(thread, port, 0); + + uint32 state = ZX_EXCEPTION_STATE_HANDLED; + status = zx_object_set_property(exception, ZX_PROP_EXCEPTION_STATE, &state, sizeof(state)); if (status != ZX_OK) { - debug("zx_task_resume_from_exception failed: %d\n", status); + debug("zx_object_set_property(ZX_PROP_EXCEPTION_STATE) failed: %d\n", status); } - zx_handle_close(thread); + zx_handle_close(exception); } doexit(1); return 0; @@ -865,13 +884,11 @@ static void* ex_handler(void* arg) static void install_segv_handler(void) { zx_status_t status; - zx_handle_t port; - if ((status = zx_port_create(0, &port)) != ZX_OK) - fail("zx_port_create failed: %d", status); - if ((status = zx_task_bind_exception_port(zx_process_self(), port, 0, 0)) != ZX_OK) - fail("zx_task_bind_exception_port failed: %d", status); + zx_handle_t exception_channel; + if ((status = zx_task_create_exception_channel(zx_process_self(), 0, &exception_channel)) != ZX_OK) + fail("zx_task_create_exception_channel failed: %d", status); pthread_t th; - if (pthread_create(&th, 0, ex_handler, (void*)(long)port)) + if (pthread_create(&th, 0, ex_handler, (void*)(long)exception_channel)) fail("pthread_create failed"); } diff --git a/pkg/report/testdata/fuchsia/report/24 b/pkg/report/testdata/fuchsia/report/24 deleted file mode 100644 index be444d057..000000000 --- a/pkg/report/testdata/fuchsia/report/24 +++ /dev/null @@ -1,65 +0,0 @@ -TITLE: ASSERT FAILED in ExceptionPort::SetTarget - -ZIRCON KERNEL PANIC -panic (caller 0xffffffff00187dc2 frame 0xffffff9b59433ef0): DEBUG ASSERT FAILED at (kernel/object/excp_port.cpp:84): port_ != n -ullptr -platform_halt suggested_action 0 reason 2 -bt#00: 0x00105e46 platform_halt platform/pc/power.cpp:122 -bt#01: 0x001aa1a4 _panic lib/debug/debug.cpp:39 -bt#02: 0x0014feb8 ExceptionPort::SetTarget object/excp_port.cpp:83 -bt#03: [ inline ] task_bind_exception_port syscalls/exceptions.cpp:90 -bt#03: 0x00187dc2 sys_task_bind_exception_port syscalls/exceptions.cpp:149 -bt#04: [ inline ] operator() syscall-kernel-wrappers.inc:328 -bt#04: [ inline ] lambda syscalls/syscalls.cpp:60 -bt#04: 0x001767ff wrapper_task_bind_exception_port syscall-kernel-wrappers.inc:330 -bt#05: 0x00116af0 x86_syscall syscall-kernel-branches.S:51 -bt#06: end - Instruction Pointer = 0x10:0xffffffff00139911 - Stack Pointer = 0x18:0xffffff9b59433da0 - Fault Linear Address = 0x90 - Error Code Value = 0x0 - Error Code Type = supervisor read data, page not present -dump_thread: t 0xffffff800c1a6b88 (/tmp/syz-executor13:pthread_t:0x4d4bcf6e3b30) - state run, curr/last cpu 0/0, cpu_affinity 0xffffffff, priority 19 [16:3,-1], remaining time slice 10000000 - runtime_ns 252291478, runtime_s 0 - stack 0xffffff9b59432000, stack_size 8192 - entry 0xffffffff00169788, arg 0xffffff800c1a6a10, flags 0x0 - wait queue 0, blocked_status 0, interruptable 0, mutexes held 1 - aspace 0xffffff800d03fd40 - user_thread 0xffffff800c1a6a10, pid 822439, tid 823621 -vector 14 -Supervisor Page Fault exception, halting - RIP: 0x00139911 crashlog_to_string lib/crashlog/crashlog.cpp:131 - CS: 0x10 RIP: 0xffffffff00139911 EFL: 0x10092 CR2: 0x90 - RAX: 0 RBX: 0x1000 RCX: 0x20 RDX: 0x3191ab138c90 - RSI: 0x2 RDI: 0xffffffff0020c55b RBP: 0xffffff9b59433e00 RSP: 0xffffff9b59433da0 - R8: 0xffffffff0020c55b R9: 0xffffffff002a98ef R10: 0xa R11: 0x21 - R12: 0xffffffff002a9910 R13: 0x15 R14: 0xf40 R15: 0x15 -errc: 0 -bottom of kernel stack at 0xffffff9b59433cf0: -0xffffff9b59433cf0: 0020c55b ffffffff 00000002 00000000 |[. .............| -0xffffff9b59433d00: 59433e00 ffffff9b 00001000 00000000 |.>CY............| -0xffffff9b59433d10: ab138c90 00003191 00000020 00000000 |.....1.. .......| -0xffffff9b59433d20: 00000000 00000000 0020c55b ffffffff |........[. .....| -0xffffff9b59433d30: 002a98ef ffffffff 0000000a 00000000 |..*.............| -0xffffff9b59433d40: 00000021 00000000 002a9910 ffffffff |!.........*.....| -0xffffff9b59433d50: 00000015 00000000 00000f40 00000000 |........@.......| -0xffffff9b59433d60: 00000015 00000000 0000000e 00000000 |................| -platform_halt suggested_action 0 reason 2 -bt#00: 0x00105e46 platform_halt platform/pc/power.cpp:122 -bt#01: 0x00108b08 exception_die arch/x86/faults.cpp:100 -bt#02: [ inline ] x86_fatal_pfe_handler arch/x86/faults.cpp:240 -bt#02: [ inline ] handle_exception_types arch/x86/faults.cpp:371 -bt#02: 0x0010968f x86_exception_handler arch/x86/faults.cpp:458 -bt#03: 0x001164b7 interrupt_common arch/x86/exceptions.S:127 -bt#04: 0x001a5ed5 dlog_bluescreen_halt system/ulib/fbl/include/fbl/ref_counted_internal.h:119 -bt#05: 0x00105e4b platform_halt platform/pc/power.cpp:123 -bt#06: 0x001aa1a4 _panic lib/debug/debug.cpp:39 -bt#07: 0x0014feb8 ExceptionPort::SetTarget object/excp_port.cpp:83 -bt#08: [ inline ] task_bind_exception_port syscalls/exceptions.cpp:90 -bt#08: 0x00187dc2 sys_task_bind_exception_port syscalls/exceptions.cpp:149 -bt#09: [ inline ] operator() syscall-kernel-wrappers.inc:328 -bt#09: [ inline ] lambda syscalls/syscalls.cpp:60 -bt#09: 0x001767ff wrapper_task_bind_exception_port syscall-kernel-wrappers.inc:330 -bt#10: 0x00116af0 x86_syscall syscall-kernel-branches.S:51 -bt#11: end -- cgit mrf-deployment