From patchwork Wed Jul 27 14:02:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Vary X-Patchwork-Id: 37007 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp374791pzb; Wed, 27 Jul 2022 07:03:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uUSFI7ZACEhS+URXnrPRxSK3jfbfMgx7nP1LDl/BuwHU1r/Abf6BprzkmnjL8x5PyaUtEh X-Received: by 2002:a05:6402:5008:b0:437:7f01:82a with SMTP id p8-20020a056402500800b004377f01082amr23494250eda.220.1658930602879; Wed, 27 Jul 2022 07:03:22 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s3-20020a056402520300b0043bca1b6462si18495978edd.44.2022.07.27.07.03.09; Wed, 27 Jul 2022 07:03:22 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@genetec.com header.s=selector1 header.b=d1nMbCrR; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=genetec.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F95F680039; Wed, 27 Jul 2022 17:03:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2045.outbound.protection.outlook.com [40.107.244.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DBD2E68B8F9 for ; Wed, 27 Jul 2022 17:02:55 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mbe/cmFiaXOYGEU+p0QfwqHmqbbx/asIzhTpGu3ALupbVO6x0fOIJs5pD3aZwJLChIRRQdR0z+0bPqo1GvokKM/t6fg0Ydtf7Rj5rgUkOIGaV6AYJJHmQF594pq1QcqKG4bHDZ9gXRu8iExow0VLAP+eJowsy0v+gr6UvKqmNwVdlI2hGZrKB7LLXDa13kp2VPwispfzWD7ud2RDUMCoAl16XslUiYhYwEFYecG1+7pWNCSqFUpplptYmExSJpaMuio7W4+4rJaXW/2UdTt6RfNJI424XUyW9L8oLI6qpB1u7mM/lks6GL+Kfxn6pfWxl2ak5+9csF4gY+T5qLr29A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ke1tF1EkzTO0vAwc+U9Pud4GivmivvOo6UvzgSZ2fpU=; b=Sq2Q5hyNc2PwIkJekuH3hha2BELb0B6X+Wy9A/PnHPh7eOyEVcYpzLJoXpOyc5zUvTMt5sFH/JKNldlNqhSFEQwLu7CkXXtFOvIeUpSDuxvjM2Yh3Uo6Ba9D1I0yJCpH8f2sTb1Cfh3mPaNqxsFL5vIotyiIdTqiOOm6S7T6IIgHRcOqc+PKNOacxjhVS3WBP7hgsoLv3dz9WJ/FasjYyPs911d/d+fuGhJWRuhonxfbnlbsvqB92wWxPyJZtXxslvKTe1jpB4HtdZFIO7T4y98AUaccbouwdhl0iONV9UUCubv+nirpctLPhBh2sE3GA2UOfK486nZ9+K/LuOS3Pw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=genetec.com; dmarc=pass action=none header.from=genetec.com; dkim=pass header.d=genetec.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=genetec.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ke1tF1EkzTO0vAwc+U9Pud4GivmivvOo6UvzgSZ2fpU=; b=d1nMbCrRRW3KcTfLbKeYbHeAo/2yYVU8wST54abGt4uu14/ulz1hYvxmYqnC92kqxx1c2nJdGneH+sd3WLOFh9qaWoLQ/A1StEIA5p4zKo83yDY85e7Tby6YZafXKxE85Xu5nhErGbAdVF/M2fLk/VNnKyO5Yj1SFHdxKQscvd0= Received: from DM4PR18MB4128.namprd18.prod.outlook.com (2603:10b6:5:38b::11) by SJ0PR18MB4945.namprd18.prod.outlook.com (2603:10b6:a03:40c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.25; Wed, 27 Jul 2022 14:02:51 +0000 Received: from DM4PR18MB4128.namprd18.prod.outlook.com ([fe80::9905:dcb9:da51:4391]) by DM4PR18MB4128.namprd18.prod.outlook.com ([fe80::9905:dcb9:da51:4391%5]) with mapi id 15.20.5458.025; Wed, 27 Jul 2022 14:02:51 +0000 From: Julien Vary To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH] Adding av_abort() : adding custom handlers for abort(). Thread-Index: AdihM3vPBGgCa10HQDiOIdb5/ojUOw== Date: Wed, 27 Jul 2022 14:02:51 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=genetec.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ae5441ea-7205-4a1c-015c-08da6fd8b1fc x-ms-traffictypediagnostic: SJ0PR18MB4945:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: pmuNTauwi4jjmoH6cYWfN8H7eEccYwYumaBuTVYmVzSuEyPKywMfd/Xs2JW0h86YB/YxaqJUMgRcItHouwxMpj2ZbuJR5cgBGzcL0ldhBrROmxCwB/VMJ1tFY/utAVPyIAOvETnke/do5H4eRBa6uozIViF/Nog9yl2Asj1CdKWVLDsT8/LB3FepipGWlSyyu91nR+UbzZg/Mj1QclJZg5iuG86VBRXSIgkno+X+RLThvsD16fkIOA7v7h/850yvt0fI29upW6i/kKXYSxd4/opNvNsH+ovjSSU6NmILTHsMZ8rOE1b2a+0kWK320NMxEp3KGO5Z8I4E8YqtcMtKN8jfRUE6eq/vJpIru5m72OBl7RvUs5sAsh8SWKNWEFXQbJoy6yc+JKdlmBH1caCAs97xxe4aW0W/z+RqgWLrdVbmpZ0zKygKviBSUOL+NfXUngWgi4QeDt83YeBrQIh7ZaJr58pXmR1TegoqvQ9EP2CSP03iASUUqcR4ZOeSbD5wcBRMq6X/xtb/9TaciJ1EWNZIi6GruW5cI66ceB/5TK4INArmiDCZ0rebX8AY6fGrjg6qNcwG7pELTfD8bzutK2d65B4omj++Dpc414JWWbkD0GQiWtnM0kdm1rbQCyu+f8owtbFt75B1EPWjmFjJir4q+YFcPoNFUR+qMw1XQa+ebRXOZABIJiySI7mMMLubx0mC/iLPI0A1uSHadwdLHVreA6i/3H4rQdiuBJPkmlEava/+hp9Ax9AMvm7aTZdv4KM2kA/Do6EhtvDo1oJRMfzngJWUI8lrovh5Q9GV75KyPoHqiTXcw8Ar0mSK1PQYvrUz5XL9wtWZ5r7csk2tWQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR18MB4128.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(396003)(39860400002)(346002)(376002)(136003)(2906002)(478600001)(122000001)(186003)(86362001)(7696005)(316002)(6506007)(41300700001)(30864003)(38070700005)(38100700002)(5660300002)(9686003)(66476007)(83380400001)(8936002)(55016003)(33656002)(71200400001)(26005)(6916009)(76116006)(66946007)(64756008)(52536014)(66446008)(8676002)(66556008)(2004002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: /oYIzt8ESY0HqLt4Lv21c51/+f4ooLiDNm9efMOhW2qxC5qzfuliopoGUn6ZVQYR6Y61HD2euCD+uv3w9amzJcevJxG++bRyuzq9TiHVVQ7RxOW6rpb0uSX2bY95qZYYZELWDby4lKhpBtnyzaNM6pg2uFk1i54ytQXjVTlhZCJoD90/02e49EcwlgnXvGbDVl3nIQNN/PAgw+K5CZ2gXpnUNyYB2BhaHAGppM1ipLzqpwn0/soyUamNc7ltR7rW5osV9wFQ+8/w5jcx8/t0gN7Vu1W7YU8msXuBaJYfHHzazRnomRrgf5IHrjOllK3zaN83ykazIJqWk9RcAwbDQiiOuen0t3R2UdTj3aeHdjd+3kIlCggnir7O66VCJn1tmgm34RVpqkuBStJnjoTK6KZb+WVZzEYW6u+PkK5QqTGNoFsDl4pX6ggW8+JEQ/azz8uG5ZJgxJXkhbdvzicHdWIgidIbsJdY4bWutGVf1KjcWwna/R8HVR9PpObf9yOlTPgYDYE6ysoMU2DHNMiVJ+ekJKLsMNpZIj8XEE4RA5sqkNfQo4DP8pJClLrFgaheT4cwEAwIeWEg/oI59gdK+2kAhxrnf63h1PaauRaDf0S+5C/5R6+FV0wSNdl8QO47QOmrN9a1fj1fMEDbgR2IciE1BxApOFIfvXojmxZ3VgeY7/onGUVFmP5hBeIDE4RaOw65AX0trgemZNuRpRgFP1dehR7zSJUisOVie8ciZSCSq4r1Gk/WdSBaYwaQwzqZxGdkslp0uDrR2wZlG3kbDQCyyPmCc9KHA2gEpQt7+KqCHEegDCLdBfG0RM/8Hq0Ux9livVyri56bOOM+rdOUC+BrB0IKqRwzD/+orENBRm4/4gxba3u6Q8RbUZsmqaSLKUS6cGt1G++d80Q5gzoQ5EfY6wQR83y8O2ebyl07D/+cEtz3CHKf6p97PdL85WWvVAwssHft89ZKD6VMuiAHmwF+KgmuLngiG6+5Df3n64twbIi0YG+CIWgeKE1wkIBevGgM49yIqrqOy78RvVamtSJZHk+iTcC7tdjDS/GJrdUkcbBxRI+m7JCqGvQ9wB7xP6xUi1x8CVycNyIK7/KnJSYS8YV/iernPrJOp6OnW6YZrFM+AKLH1LmowLmem4dQLIspdS8rCORJRyM1Jp/K80BY3KUokUBX21C7jsBUE0K+uwIwboGSLwOH69cKjog+LzNkeI/re74VtNZk9jzgeGFpRKoC3pRylBkeeu0yJZjNjV/ofXxq82jr/OnxQ30CnmNj/rHHYnfvK6v5mk5pPbb6uKScNE3clYh9wLlJtzV224CeME0nXTXSp851W5OtolMmFXtN+aYST1P+b8oLM+s1q4vZdZD0sM0DKUsNPE3qHNZRnkk0CKAkMWu9XbMqkict442TG/ipi6Rph+0m+KM3dD6qHuANmWxZ28wHfQ1JA76148uLQO+J8wjlWbfCs/6TQgAy+dYPpfPXMWu0K+Nx5OOXVAP1fhDbShCB6XLoJp7sMNKH06csFcUf8k0ig4voPmqzT+SRAgBRVxTrFgwLdSAMd5VEnSlqnKR0ubg= MIME-Version: 1.0 X-OriginatorOrg: genetec.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR18MB4128.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae5441ea-7205-4a1c-015c-08da6fd8b1fc X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Jul 2022 14:02:51.5579 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7ba8d2fb-4660-4a19-802e-4d015a17e167 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: HvJxHxjk0dl3ki+urLizZ6LIowSpsB0GZz6GZrLhPeuD+OBL1CgdiAS7epmO42e/7Bdiz7AOAGtiTjL9wJSpTw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR18MB4945 Subject: [FFmpeg-devel] [PATCH] Adding av_abort() : adding custom handlers for abort(). X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KhcD1H4IkIV4 Replaced all abort() by av_abort() in the code. On production systems, when dealing with malformed data, avcodec was sometime aborting, with no core/memory dump available to troubleshoot after-the-fact. Adding av_abort_set_callback to register a custom function (instead of the default straight abort() behavior), to allow dumping before the actual abort(). Also 'av_logging' the av_abort() location. Signed-off-by: Julien Vary --- fftools/ffmpeg.c | 2 +- fftools/ffmpeg_opt.c | 2 +- libavcodec/mpegpicture.c | 2 +- libavcodec/ppc/hevcdsp.c | 4 ++-- libavcodec/vlc.c | 2 +- libavcodec/vp8.c | 2 +- libavformat/avformat.h | 10 ++++----- libavutil/Makefile | 6 ++++-- libavutil/aarch64/neontest.h | 2 +- libavutil/abort.c | 39 ++++++++++++++++++++++++++++++++++++ libavutil/abort.h | 36 +++++++++++++++++++++++++++++++++ libavutil/arm/neontest.h | 2 +- libavutil/avassert.h | 3 ++- libavutil/avutil.h | 1 + libavutil/common.h | 9 +++++---- libavutil/internal.h | 3 ++- libavutil/softfloat.h | 2 +- libavutil/thread.h | 3 ++- libavutil/version.c | 3 ++- libavutil/x86/intmath.h | 9 +++++---- libavutil/x86/w64xmmtest.h | 2 +- 21 files changed, 114 insertions(+), 30 deletions(-) create mode 100644 libavutil/abort.c create mode 100644 libavutil/abort.h diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index b03f18cfea..99abf9672b 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3136,7 +3136,7 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) case AVMEDIA_TYPE_DATA: break; default: - abort(); + av_abort(); break; } diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 8ac73c0efc..b24ab4df0b 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1061,7 +1061,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) case AVMEDIA_TYPE_UNKNOWN: break; default: - abort(); + av_abort(); } ret = avcodec_parameters_from_context(par, ist->dec_ctx); diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index aaa1df0bd8..c505bff820 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -455,7 +455,7 @@ static int find_unused_picture(AVCodecContext *avctx, Picture *picture, int shar * all. Similarly, missing reference frames have to be replaced by * interpolated/MC frames, anything else is a bug in the codec ... */ - abort(); + av_abort(); return -1; } diff --git a/libavcodec/ppc/hevcdsp.c b/libavcodec/ppc/hevcdsp.c index c1d562a409..2b36327b1e 100644 --- a/libavcodec/ppc/hevcdsp.c +++ b/libavcodec/ppc/hevcdsp.c @@ -62,7 +62,7 @@ static av_always_inline void transform4x4(vec_s16 src_01, vec_s16 src_23, case 7: add = vec_sl(vec_splat_s32(1), vec_splat_u32( 7 - 1)); break; case 10: add = vec_sl(vec_splat_s32(1), vec_splat_u32(10 - 1)); break; case 12: add = vec_sl(vec_splat_s32(1), vec_splat_u32(12 - 1)); break; - default: abort(); + default: av_abort(); } e0 = vec_add(e0, add); @@ -84,7 +84,7 @@ static av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], case 7: v_shift = vec_splat_u32(7) ; break; case 10: v_shift = vec_splat_u32(10); break; case 12: v_shift = vec_splat_u32(12); break; - default: abort(); + default: av_abort(); } for (i = 0; i < 4; i++) diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c index 96f2b28c7e..adf0c18d81 100644 --- a/libavcodec/vlc.c +++ b/libavcodec/vlc.c @@ -63,7 +63,7 @@ static int alloc_table(VLC *vlc, int size, int use_static) vlc->table_size += size; if (vlc->table_size > vlc->table_allocated) { if (use_static) - abort(); // cannot do anything, init_vlc() is used with too little memory + av_abort(); // cannot do anything, init_vlc() is used with too little memory vlc->table_allocated += (1 << vlc->bits); vlc->table = av_realloc_f(vlc->table, vlc->table_allocated, sizeof(*vlc->table)); if (!vlc->table) { diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index 10de962118..30cbbd7458 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -164,7 +164,7 @@ static VP8Frame *vp8_find_free_buffer(VP8Context *s) } if (i == 5) { av_log(s->avctx, AV_LOG_FATAL, "Ran out of free frames!\n"); - abort(); + av_abort(); } if (frame->tf.f->buf[0]) vp8_release_frame(s, frame); diff --git a/libavformat/avformat.h b/libavformat/avformat.h index f12fa7d904..24d1469be8 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -107,7 +107,7 @@ * AVFormatContext *s = NULL; * int ret = avformat_open_input(&s, url, NULL, NULL); * if (ret < 0) - * abort(); + * av_abort(); * @endcode * The above code attempts to allocate an AVFormatContext, open the * specified file (autodetecting the format) and read the header, exporting the @@ -134,7 +134,7 @@ * av_dict_set(&options, "pixel_format", "rgb24", 0); * * if (avformat_open_input(&s, url, NULL, &options) < 0) - * abort(); + * av_abort(); * av_dict_free(&options); * @endcode * This code passes the private options 'video_size' and 'pixel_format' to the @@ -149,7 +149,7 @@ * AVDictionaryEntry *e; * if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) { * fprintf(stderr, "Option %s not recognized by the demuxer.\n", e->key); - * abort(); + * av_abort(); * } * @endcode * @@ -258,7 +258,7 @@ * AVIODirContext *ctx = NULL; * if (avio_open_dir(&ctx, "smb://example.com/some_dir", NULL) < 0) { * fprintf(stderr, "Cannot open directory.\n"); - * abort(); + * av_abort(); * } * @endcode * @@ -279,7 +279,7 @@ * for (;;) { * if (avio_read_dir(ctx, &entry) < 0) { * fprintf(stderr, "Cannot list directory.\n"); - * abort(); + * av_abort(); * } * if (!entry) * break; diff --git a/libavutil/Makefile b/libavutil/Makefile index 9435a0bfb0..230f5996ef 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -1,7 +1,8 @@ NAME = avutil DESC = FFmpeg utility library -HEADERS = adler32.h \ +HEADERS = abort.h \ + adler32.h \ aes.h \ aes_ctr.h \ attributes.h \ @@ -99,7 +100,8 @@ ARCH_HEADERS = bswap.h \ BUILT_HEADERS = avconfig.h \ ffversion.h -OBJS = adler32.o \ +OBJS = abort.o \ + adler32.o \ aes.o \ aes_ctr.o \ audio_fifo.o \ diff --git a/libavutil/aarch64/neontest.h b/libavutil/aarch64/neontest.h index 2d0fc19994..b53c688a28 100644 --- a/libavutil/aarch64/neontest.h +++ b/libavutil/aarch64/neontest.h @@ -58,7 +58,7 @@ " -> %016"PRIx64"\n", \ av_bswap64(neon[1][i])); \ } \ - abort(); \ + av_abort(); \ } \ return ret diff --git a/libavutil/abort.c b/libavutil/abort.c new file mode 100644 index 0000000000..12974d23bf --- /dev/null +++ b/libavutil/abort.c @@ -0,0 +1,39 @@ +/* + * copyright (c) 2022 Genetec inc. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include "abort.h" + +void av_abort_default_callback(void) +{ + abort(); +} + +static void (*av_abort_callback)(void) = av_abort_default_callback; + +void av_abort_internal(void) +{ + av_abort_callback(); +} + +void av_abort_set_callback(void (*callback)(void)) +{ + av_abort_callback = callback; +} diff --git a/libavutil/abort.h b/libavutil/abort.h new file mode 100644 index 0000000000..1a00e81794 --- /dev/null +++ b/libavutil/abort.h @@ -0,0 +1,36 @@ +/* + * copyright (c) 2022 Genetec inc. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_ABORT_H +#define AVUTIL_ABORT_H + +/** + * Causes abnormal program termination. By default, av_abort_callback calls + * abort() from the stdlib. This behavior can be altered by setting a + * different av_abort callback function. + */ + +void av_abort_internal(void); +void av_abort_set_callback(void (*)(void)); +void av_abort_default_callback(void); + +#define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); av_abort_internal(); } while(0) + +#endif /* AVUTIL_ABORT_H */ diff --git a/libavutil/arm/neontest.h b/libavutil/arm/neontest.h index d75ab8380b..603c68a5a1 100644 --- a/libavutil/arm/neontest.h +++ b/libavutil/arm/neontest.h @@ -55,7 +55,7 @@ " -> %016"PRIx64"\n", \ av_bswap64(neon[1][i])); \ } \ - abort(); \ + av_abort(); \ } \ return ret diff --git a/libavutil/avassert.h b/libavutil/avassert.h index 51e462bbae..6d528b4555 100644 --- a/libavutil/avassert.h +++ b/libavutil/avassert.h @@ -28,6 +28,7 @@ #define AVUTIL_AVASSERT_H #include +#include "abort.h" #include "log.h" #include "macros.h" @@ -38,7 +39,7 @@ if (!(cond)) { \ av_log(NULL, AV_LOG_PANIC, "Assertion %s failed at %s:%d\n", \ AV_STRINGIFY(cond), __FILE__, __LINE__); \ - abort(); \ + av_abort_internal(); \ } \ } while (0) diff --git a/libavutil/avutil.h b/libavutil/avutil.h index 64b68bdbd3..2f9f83b960 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -301,6 +301,7 @@ char av_get_picture_type_char(enum AVPictureType pict_type); #include "mathematics.h" #include "log.h" #include "pixfmt.h" +#include "abort.h" /** * Return x default pointer in case p is NULL. diff --git a/libavutil/common.h b/libavutil/common.h index fd1404be6c..16a83bc798 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -41,6 +41,7 @@ #include "attributes.h" #include "macros.h" +#include "abort.h" //rounded division & shift #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) @@ -173,7 +174,7 @@ av_const int av_log2_16bit(unsigned v); static av_always_inline av_const int av_clip_c(int a, int amin, int amax) { #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 - if (amin > amax) abort(); + if (amin > amax) av_abort(); #endif if (a < amin) return amin; else if (a > amax) return amax; @@ -190,7 +191,7 @@ static av_always_inline av_const int av_clip_c(int a, int amin, int amax) static av_always_inline av_const int64_t av_clip64_c(int64_t a, int64_t amin, int64_t amax) { #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 - if (amin > amax) abort(); + if (amin > amax) av_abort(); #endif if (a < amin) return amin; else if (a > amax) return amax; @@ -388,7 +389,7 @@ static av_always_inline int64_t av_sat_sub64_c(int64_t a, int64_t b) { static av_always_inline av_const float av_clipf_c(float a, float amin, float amax) { #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 - if (amin > amax) abort(); + if (amin > amax) av_abort(); #endif return FFMIN(FFMAX(a, amin), amax); } @@ -405,7 +406,7 @@ static av_always_inline av_const float av_clipf_c(float a, float amin, float ama static av_always_inline av_const double av_clipd_c(double a, double amin, double amax) { #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 - if (amin > amax) abort(); + if (amin > amax) av_abort(); #endif return FFMIN(FFMAX(a, amin), amax); } diff --git a/libavutil/internal.h b/libavutil/internal.h index b44cbaaa7b..5b85d52176 100644 --- a/libavutil/internal.h +++ b/libavutil/internal.h @@ -38,6 +38,7 @@ #include #include #include +#include "abort.h" #include "config.h" #include "attributes.h" #include "timer.h" @@ -235,7 +236,7 @@ static av_always_inline av_const int64_t ff_rint64_clip(double a, int64_t amin, { int64_t res; #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 - if (amin > amax) abort(); + if (amin > amax) av_abort(); #endif // INT64_MAX+1,INT64_MIN are exactly representable as IEEE doubles // do range checks first diff --git a/libavutil/softfloat.h b/libavutil/softfloat.h index a651406f74..f220e69bfb 100644 --- a/libavutil/softfloat.h +++ b/libavutil/softfloat.h @@ -211,7 +211,7 @@ static av_always_inline SoftFloat av_sqrt_sf(SoftFloat val) if (val.mant == 0) val.exp = MIN_EXP; else if (val.mant < 0) - abort(); + av_abort(); else { tabIndex = (val.mant - 0x20000000) >> 20; diff --git a/libavutil/thread.h b/libavutil/thread.h index 7106fd0d47..464fbe6996 100644 --- a/libavutil/thread.h +++ b/libavutil/thread.h @@ -33,6 +33,7 @@ #include +#include "abort.h" #include "error.h" #include "log.h" #include "macros.h" @@ -43,7 +44,7 @@ " failed with error: %s\n", \ av_make_error_string(errbuf, AV_ERROR_MAX_STRING_SIZE, \ AVERROR(ret))); \ - abort(); \ + av_abort_internal(); \ } while (0) #define ASSERT_PTHREAD_NORET(func, ...) do { \ diff --git a/libavutil/version.c b/libavutil/version.c index b0f4f94a7a..971335a779 100644 --- a/libavutil/version.c +++ b/libavutil/version.c @@ -20,6 +20,7 @@ #include +#include "abort.h" #include "config.h" #include "avassert.h" #include "avutil.h" @@ -49,7 +50,7 @@ unsigned avutil_version(void) if (av_sat_dadd32(1, 2) != 5) { av_log(NULL, AV_LOG_FATAL, "Libavutil has been built with a broken binutils, please upgrade binutils and rebuild\n"); - abort(); + av_abort(); } if (llrint(1LL<<60) != 1LL<<60) { diff --git a/libavutil/x86/intmath.h b/libavutil/x86/intmath.h index 8a6b5ae261..d729c3c800 100644 --- a/libavutil/x86/intmath.h +++ b/libavutil/x86/intmath.h @@ -30,6 +30,7 @@ #include #endif #endif +#include "../abort.h" #include "config.h" #if HAVE_FAST_CLZ @@ -108,7 +109,7 @@ static av_always_inline av_const unsigned av_mod_uintp2_bmi2(unsigned a, unsigne static av_always_inline av_const double av_clipd_sse2(double a, double amin, double amax) { #if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 - if (amin > amax) abort(); + if (amin > amax) av_abort(); #endif __asm__ ("maxsd %1, %0 \n\t" "minsd %2, %0 \n\t" @@ -124,7 +125,7 @@ static av_always_inline av_const double av_clipd_sse2(double a, double amin, dou static av_always_inline av_const float av_clipf_sse(float a, float amin, float amax) { #if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 - if (amin > amax) abort(); + if (amin > amax) av_abort(); #endif __asm__ ("maxss %1, %0 \n\t" "minss %2, %0 \n\t" @@ -141,7 +142,7 @@ static av_always_inline av_const float av_clipf_sse(float a, float amin, float a static av_always_inline av_const double av_clipd_avx(double a, double amin, double amax) { #if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 - if (amin > amax) abort(); + if (amin > amax) av_abort(); #endif __asm__ ("vmaxsd %1, %0, %0 \n\t" "vminsd %2, %0, %0 \n\t" @@ -154,7 +155,7 @@ static av_always_inline av_const double av_clipd_avx(double a, double amin, doub static av_always_inline av_const float av_clipf_avx(float a, float amin, float amax) { #if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 - if (amin > amax) abort(); + if (amin > amax) av_abort(); #endif __asm__ ("vmaxss %1, %0, %0 \n\t" "vminss %2, %0, %0 \n\t" diff --git a/libavutil/x86/w64xmmtest.h b/libavutil/x86/w64xmmtest.h index a4a05b0419..8171baaff5 100644 --- a/libavutil/x86/w64xmmtest.h +++ b/libavutil/x86/w64xmmtest.h @@ -66,7 +66,7 @@ av_bswap64(xmm[1][i][0]), \ av_bswap64(xmm[1][i][1])); \ } \ - abort(); \ + av_abort(); \ } \ return ret