[{"id":1769879,"web_url":"http://patchwork.ozlabs.org/comment/1769879/","msgid":"<1835b614-f375-dedc-9e88-9a238a904283@gmx.de>","list_archive_url":null,"date":"2017-09-18T06:01:15","subject":"Re: [U-Boot] [PATCH 08/16] sandbox: Add a setjmp() implementation","submitter":{"id":61270,"url":"http://patchwork.ozlabs.org/api/people/61270/","name":"Heinrich Schuchardt","email":"xypron.glpk@gmx.de"},"content":"On 09/18/2017 12:59 AM, Simon Glass wrote:\n> Add an implementation of setjmp() and longjmp() which rely on the\n> underlying host C library. Since we cannot know how large the jump buffer\n> needs to be, pick something that should be suitable and check it at\n> runtime. At present we need access to the underlying struct as well.\n> \n> Signed-off-by: Simon Glass <sjg@chromium.org>\n> ---\n> \n>  arch/sandbox/cpu/cpu.c            | 13 +++++++++++++\n>  arch/sandbox/cpu/os.c             | 17 +++++++++++++++++\n>  arch/sandbox/include/asm/setjmp.h | 21 +++++++++++++++++++++\n>  include/os.h                      | 21 +++++++++++++++++++++\n>  4 files changed, 72 insertions(+)\n>  create mode 100644 arch/sandbox/include/asm/setjmp.h\n> \n> diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c\n> index 01991049cc..de5862a53b 100644\n> --- a/arch/sandbox/cpu/cpu.c\n> +++ b/arch/sandbox/cpu/cpu.c\n> @@ -9,6 +9,7 @@\n>  #include <libfdt.h>\n>  #include <os.h>\n>  #include <asm/io.h>\n> +#include <asm/setjmp.h>\n>  #include <asm/state.h>\n>  #include <dm/root.h>\n>  \n> @@ -154,3 +155,15 @@ ulong timer_get_boot_us(void)\n>  \n>  \treturn (count - base_count) / 1000;\n>  }\n> +\n> +int setjmp(jmp_buf jmp)\n> +{\n> +\treturn os_setjmp((ulong *)jmp, sizeof(jmp));\n> +}\n> +\n> +void longjmp(jmp_buf jmp, int ret)\n> +{\n> +\tos_longjmp((ulong *)jmp, ret);\n> +\twhile (1)\n> +\t\t;\n> +}\n> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c\n> index 22d6aab534..909034fa4b 100644\n> --- a/arch/sandbox/cpu/os.c\n> +++ b/arch/sandbox/cpu/os.c\n> @@ -7,6 +7,7 @@\n>  #include <errno.h>\n>  #include <fcntl.h>\n>  #include <getopt.h>\n> +#include <setjmp.h>\n>  #include <stdio.h>\n>  #include <stdint.h>\n>  #include <stdlib.h>\n> @@ -609,3 +610,19 @@ void os_localtime(struct rtc_time *rt)\n>  \trt->tm_yday = tm->tm_yday;\n>  \trt->tm_isdst = tm->tm_isdst;\n>  }\n> +\n> +int os_setjmp(ulong *jmp, int size)\n> +{\n> +\tif (size < sizeof(jmp_buf)) {\n> +\t\tprintf(\"setjmp: jmpbuf is too small (%d bytes, need %d)\\n\",\n> +\t\t       size, sizeof(jmp_buf));\n> +\t\treturn -ENOSPC;\n> +\t}\n> +\n> +\treturn setjmp((struct __jmp_buf_tag *)jmp);\n> +}\n> +\n> +void os_longjmp(ulong *jmp, int ret)\n> +{\n> +\tlongjmp((struct __jmp_buf_tag *)jmp, ret);\n> +}\n> diff --git a/arch/sandbox/include/asm/setjmp.h b/arch/sandbox/include/asm/setjmp.h\n> new file mode 100644\n> index 0000000000..e25f50107c\n> --- /dev/null\n> +++ b/arch/sandbox/include/asm/setjmp.h\n> @@ -0,0 +1,21 @@\n> +/*\n> + * (C) Copyright 2016\n> + * Alexander Graf <agraf@suse.de>\n> + *\n> + * SPDX-License-Identifier:\tGPL-2.0+\n> + */\n> +\n> +#ifndef _SETJMP_H_\n> +#define _SETJMP_H_\t1\n> +\n> +struct jmp_buf_data {\n> +\t/* We're not sure how long this should be */\n> +\tulong data[32];\n> +};\n> +\n> +typedef struct jmp_buf_data jmp_buf[1];\n> +\n> +int setjmp(jmp_buf jmp);\n> +__noreturn void longjmp(jmp_buf jmp, int ret);\n> +\n> +#endif /* _SETJMP_H_ */\n> diff --git a/include/os.h b/include/os.h\n> index 2bf4bdb1b8..ad1836ac9f 100644\n> --- a/include/os.h\n> +++ b/include/os.h\n> @@ -310,4 +310,25 @@ int os_spl_to_uboot(const char *fname);\n>   */\n>  void os_localtime(struct rtc_time *rt);\n>  \n> +/**\n> + * os_setjmp() - Call setjmp()\n> + *\n> + * Call the host system's setjmp() function.\n> + *\n> + * @jmp: Buffer to store current execution state\n> + * @size: Size of buffer\n> + * @return normal setjmp() value if OK, -ENOSPC if @size is too small\n> + */\n> +int os_setjmp(ulong *jmp, int size);\n> +\n> +/**\n> + * os_longjmp() - Call longjmp()\n> + *\n> + * Call the host system's longjmp() function.\n> + *\n> + * @jmp: Buffer where previous execution state was stored\n> + * @ret: Value to pass to longjmp()\n> + */\n> +void os_longjmp(ulong *jmp, int ret);\n> +\n>  #endif\n> \n\nPlease, fix this warning:\n\narch/sandbox/cpu/cpu.c: In function ‘setjmp’:\narch/sandbox/cpu/cpu.c:161:39: warning: ‘sizeof’ on array function\nparameter ‘jmp’ will return size of ‘struct jmp_buf_data *’\n[-Wsizeof-array-argument]\n  return os_setjmp((ulong *)jmp, sizeof(jmp));\n                                       ^\narch/sandbox/cpu/cpu.c:159:20: note: declared here\n int setjmp(jmp_buf jmp)\n\nRegards\n\nHeinrich","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xwb3x0Gn8z9s7g\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 18 Sep 2017 16:01:32 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid C5E81C21ED7; Mon, 18 Sep 2017 06:01:27 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id D4D66C21D5D;\n\tMon, 18 Sep 2017 06:01:24 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 8E0F5C21D5D; Mon, 18 Sep 2017 06:01:23 +0000 (UTC)","from mout.gmx.net (mout.gmx.net [212.227.17.20])\n\tby lists.denx.de (Postfix) with ESMTPS id 33F24C21D57\n\tfor <u-boot@lists.denx.de>; Mon, 18 Sep 2017 06:01:23 +0000 (UTC)","from [192.168.123.58] ([84.118.154.110]) by mail.gmx.com (mrgmx102\n\t[212.227.17.168]) with ESMTPSA (Nemesis) id\n\t0M7UUd-1dVzZp0rGZ-00xGjT; Mon, 18 Sep 2017 08:01:18 +0200"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-0.7 required=5.0 tests=FREEMAIL_FROM,\n\tRCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,\n\tRCVD_IN_MSPIKE_WL autolearn=unavailable\n\tautolearn_force=no version=3.4.0","To":"Simon Glass <sjg@chromium.org>,\n\tU-Boot Mailing List <u-boot@lists.denx.de>","References":"<20170917225927.117917-1-sjg@chromium.org>\n\t<20170917225927.117917-9-sjg@chromium.org>","From":"Heinrich Schuchardt <xypron.glpk@gmx.de>","Message-ID":"<1835b614-f375-dedc-9e88-9a238a904283@gmx.de>","Date":"Mon, 18 Sep 2017 08:01:15 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170917225927.117917-9-sjg@chromium.org>","Content-Language":"en-US","X-Provags-ID":"V03:K0:Sq0F/l1F0Iy6+25QgJ++uqMCPihFkJ20S7YhIsQdIet1FptFILt\n\t0PrVJnrzCfGAFoPGYJ3h9hMotFTFx5t4vEW/vLmMqaslBJt5hzl/T65bOIQdvbryA8IF9qj\n\tPUej1LdEhI70Yfc8bl/WTB6dlp38ybeQ9dRzoBk3iudrNbj75q2rGXJiEIYSLgs5G9aWlwT\n\tjyINLocgsidIqLfTV6dhA==","X-UI-Out-Filterresults":"notjunk:1; V01:K0:9yWYvWv59NY=:g2kWUEoZUCQN6I8p6ph7U1\n\tst7Gm/sbwq5NQtHRhxLTUGWNE1UbOIhqwdrivm1ZS/ioFCBFEp3cpMUy2SPSZAA6IsraNfS3d\n\tPzNCvsmROgpLN3F5LRN8FzV8WU9QDycE1km9rjLqqbKABqfYmZRFXXq/6jaL5v0CJpK0eNgyc\n\tr3/MFBvhaHksE9bwl/o9X+1EW2b1kcdWFLK7oKiozSecS4vBKks1orrzfVDwrLu9K6pRiSSWi\n\tU+9IGXSN8d48tEopf5Jzo/90IRsDryeU/dLhAhRgeR8TwGn+TNY5MMyOswk1PKVRZb1ZlNQBh\n\t+m97u694hjUZZChTB+1VDSoUIrXyQMfgycIMm1YWMJNB/IxyjLHRCs8O82Enj9ILRiW+pBhK6\n\txQWwllTSl1nT8s/xLQ3A5PXOQfnQaZPKsQlDEYLr0jrtv6slid5jzuP3u2ak02Ikn77HTyjDE\n\tFxD9oAP1XpuAt3LDwGh0dnZai56VlynzI9ESaeJslwJm6PdSZOQ1nq9+wC16qGbKL43x1sj+B\n\tRilHuRstYzVy+pWnjYVeDeLrw7rNBL+NvmkRJuYWjxMYifItmzXKmwQ7bZ280ySrIPC6+jI/9\n\tjzZvWUCkH3ryz4Zm0KhDE9HtKCc6W/t4gkCmnrbNPk1jbMx2kETC+KYbdu9f5kYP0FGHv888i\n\tP+xgO62WZBfaOhmqoAzahJNA9JmovklDNKU9WLe8Gtx7eYkU0EWCrF8pCb+2N2IspgQx0LWLR\n\tehEhP0+JH9kKbPoadYyhgpZJdzre3hkS/XX00LPtB203OEDTgXDdhbVtfqfIuSGqBkxiypXEU\n\tsHL4pYBfYIrbv+efT/5s7uH0oaK3UAk2haVlYpbliG1hcy5Rm4=","Cc":"Heinrich Schuchardt <xypron.glpk@gmx.de>,\n\tAndy Shevchenko <andriy.shevchenko@linux.intel.com>","Subject":"Re: [U-Boot] [PATCH 08/16] sandbox: Add a setjmp() implementation","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}},{"id":1770435,"web_url":"http://patchwork.ozlabs.org/comment/1770435/","msgid":"<CAF6AEGub4RmtLxwZAUcWn2De67xT-mSNJ6xvjVReNPfWRJfb0A@mail.gmail.com>","list_archive_url":null,"date":"2017-09-18T19:10:29","subject":"Re: [U-Boot] [PATCH 08/16] sandbox: Add a setjmp() implementation","submitter":{"id":18760,"url":"http://patchwork.ozlabs.org/api/people/18760/","name":"Rob Clark","email":"robdclark@gmail.com"},"content":"On Mon, Sep 18, 2017 at 2:01 AM, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:\n> On 09/18/2017 12:59 AM, Simon Glass wrote:\n>> Add an implementation of setjmp() and longjmp() which rely on the\n>> underlying host C library. Since we cannot know how large the jump buffer\n>> needs to be, pick something that should be suitable and check it at\n>> runtime. At present we need access to the underlying struct as well.\n>>\n>> Signed-off-by: Simon Glass <sjg@chromium.org>\n>> ---\n>>\n>>  arch/sandbox/cpu/cpu.c            | 13 +++++++++++++\n>>  arch/sandbox/cpu/os.c             | 17 +++++++++++++++++\n>>  arch/sandbox/include/asm/setjmp.h | 21 +++++++++++++++++++++\n>>  include/os.h                      | 21 +++++++++++++++++++++\n>>  4 files changed, 72 insertions(+)\n>>  create mode 100644 arch/sandbox/include/asm/setjmp.h\n>>\n>> diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c\n>> index 01991049cc..de5862a53b 100644\n>> --- a/arch/sandbox/cpu/cpu.c\n>> +++ b/arch/sandbox/cpu/cpu.c\n>> @@ -9,6 +9,7 @@\n>>  #include <libfdt.h>\n>>  #include <os.h>\n>>  #include <asm/io.h>\n>> +#include <asm/setjmp.h>\n>>  #include <asm/state.h>\n>>  #include <dm/root.h>\n>>\n>> @@ -154,3 +155,15 @@ ulong timer_get_boot_us(void)\n>>\n>>       return (count - base_count) / 1000;\n>>  }\n>> +\n>> +int setjmp(jmp_buf jmp)\n>> +{\n>> +     return os_setjmp((ulong *)jmp, sizeof(jmp));\n>> +}\n>> +\n>> +void longjmp(jmp_buf jmp, int ret)\n>> +{\n>> +     os_longjmp((ulong *)jmp, ret);\n>> +     while (1)\n>> +             ;\n>> +}\n>> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c\n>> index 22d6aab534..909034fa4b 100644\n>> --- a/arch/sandbox/cpu/os.c\n>> +++ b/arch/sandbox/cpu/os.c\n>> @@ -7,6 +7,7 @@\n>>  #include <errno.h>\n>>  #include <fcntl.h>\n>>  #include <getopt.h>\n>> +#include <setjmp.h>\n>>  #include <stdio.h>\n>>  #include <stdint.h>\n>>  #include <stdlib.h>\n>> @@ -609,3 +610,19 @@ void os_localtime(struct rtc_time *rt)\n>>       rt->tm_yday = tm->tm_yday;\n>>       rt->tm_isdst = tm->tm_isdst;\n>>  }\n>> +\n>> +int os_setjmp(ulong *jmp, int size)\n>> +{\n>> +     if (size < sizeof(jmp_buf)) {\n>> +             printf(\"setjmp: jmpbuf is too small (%d bytes, need %d)\\n\",\n>> +                    size, sizeof(jmp_buf));\n>> +             return -ENOSPC;\n>> +     }\n>> +\n>> +     return setjmp((struct __jmp_buf_tag *)jmp);\n>> +}\n>> +\n>> +void os_longjmp(ulong *jmp, int ret)\n>> +{\n>> +     longjmp((struct __jmp_buf_tag *)jmp, ret);\n>> +}\n>> diff --git a/arch/sandbox/include/asm/setjmp.h b/arch/sandbox/include/asm/setjmp.h\n>> new file mode 100644\n>> index 0000000000..e25f50107c\n>> --- /dev/null\n>> +++ b/arch/sandbox/include/asm/setjmp.h\n>> @@ -0,0 +1,21 @@\n>> +/*\n>> + * (C) Copyright 2016\n>> + * Alexander Graf <agraf@suse.de>\n>> + *\n>> + * SPDX-License-Identifier:  GPL-2.0+\n>> + */\n>> +\n>> +#ifndef _SETJMP_H_\n>> +#define _SETJMP_H_   1\n>> +\n>> +struct jmp_buf_data {\n>> +     /* We're not sure how long this should be */\n>> +     ulong data[32];\n>> +};\n>> +\n>> +typedef struct jmp_buf_data jmp_buf[1];\n>> +\n>> +int setjmp(jmp_buf jmp);\n>> +__noreturn void longjmp(jmp_buf jmp, int ret);\n>> +\n>> +#endif /* _SETJMP_H_ */\n>> diff --git a/include/os.h b/include/os.h\n>> index 2bf4bdb1b8..ad1836ac9f 100644\n>> --- a/include/os.h\n>> +++ b/include/os.h\n>> @@ -310,4 +310,25 @@ int os_spl_to_uboot(const char *fname);\n>>   */\n>>  void os_localtime(struct rtc_time *rt);\n>>\n>> +/**\n>> + * os_setjmp() - Call setjmp()\n>> + *\n>> + * Call the host system's setjmp() function.\n>> + *\n>> + * @jmp: Buffer to store current execution state\n>> + * @size: Size of buffer\n>> + * @return normal setjmp() value if OK, -ENOSPC if @size is too small\n>> + */\n>> +int os_setjmp(ulong *jmp, int size);\n>> +\n>> +/**\n>> + * os_longjmp() - Call longjmp()\n>> + *\n>> + * Call the host system's longjmp() function.\n>> + *\n>> + * @jmp: Buffer where previous execution state was stored\n>> + * @ret: Value to pass to longjmp()\n>> + */\n>> +void os_longjmp(ulong *jmp, int ret);\n>> +\n>>  #endif\n>>\n>\n> Please, fix this warning:\n>\n> arch/sandbox/cpu/cpu.c: In function ‘setjmp’:\n> arch/sandbox/cpu/cpu.c:161:39: warning: ‘sizeof’ on array function\n> parameter ‘jmp’ will return size of ‘struct jmp_buf_data *’\n> [-Wsizeof-array-argument]\n>   return os_setjmp((ulong *)jmp, sizeof(jmp));\n>                                        ^\n> arch/sandbox/cpu/cpu.c:159:20: note: declared here\n>  int setjmp(jmp_buf jmp)\n>\n\nwith the sizeof changed to sizeof(jmp_buf), I'm getting:\n\n...\nEFI: Entry efi_exit(00007fffffffc198, 2147483662, 0, 0000000000000000)\n\nProgram received signal SIGSEGV, Segmentation fault.\nos_longjmp (jmp=0x7fffffffc200,\n    jmp@entry=<error reading variable: DWARF-2 expression error: Loop\ndetected (257).>, ret=1,\n    ret@entry=<error reading variable: DWARF-2 expression error: Loop\ndetected (257).>)\n    at ../arch/sandbox/cpu/os.c:627\n627        longjmp((struct __jmp_buf_tag *)jmp, ret);\n\n\nSo it seems like something not quite right still..\n\nBR,\n-R","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"ZAaBs8mL\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xwwZl0LWMz9t2M\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 19 Sep 2017 05:10:53 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 5E2ECC21D92; Mon, 18 Sep 2017 19:10:35 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 3DFB2C21C41;\n\tMon, 18 Sep 2017 19:10:32 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 3B05CC21C41; Mon, 18 Sep 2017 19:10:31 +0000 (UTC)","from mail-lf0-f68.google.com (mail-lf0-f68.google.com\n\t[209.85.215.68])\n\tby lists.denx.de (Postfix) with ESMTPS id C1CB0C21C2B\n\tfor <u-boot@lists.denx.de>; Mon, 18 Sep 2017 19:10:30 +0000 (UTC)","by mail-lf0-f68.google.com with SMTP id m199so799014lfe.5\n\tfor <u-boot@lists.denx.de>; Mon, 18 Sep 2017 12:10:30 -0700 (PDT)","by 10.46.41.75 with HTTP; Mon, 18 Sep 2017 12:10:29 -0700 (PDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-0.0 required=5.0 tests=FREEMAIL_FROM,\n\tRCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID\n\tautolearn=unavailable autolearn_force=no version=3.4.0","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=mime-version:in-reply-to:references:from:date:message-id:subject:to\n\t:cc:content-transfer-encoding;\n\tbh=TXyVCr0bgiRS8BddVbBfJcIb2U9v6yK4UOe7L4ZTWko=;\n\tb=ZAaBs8mL6BMN+VOzVjq1mYqu4B6YirNjW9LJG3SqVVpo7B7oMw177+VvK06tJKWPIO\n\tJ1w0Q1jZ9PTAmpPS4BpocY+owDrTvhOCLjrOsHar+0d3tWuHArWNSqCzbOGqHWVJbkvd\n\tx97GEW//+rUg9HwK9EP81DkyHW977lnRpyKe5trHaJxWMigxQO57Pth5s18zupxA8JVi\n\tP5h3C/WEBubNmL2zSUjlOnNB601niZpDsGl6y8MngfIUgPK7bzxbwIFrQ3aminas1atS\n\tZkZeXn8czLuxQlFKeRqkWVN4pCUOW7j7JhCqz1kf58QSsrSPZJoeNu+t4AA2DhTZ/11H\n\t7VKw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:in-reply-to:references:from:date\n\t:message-id:subject:to:cc:content-transfer-encoding;\n\tbh=TXyVCr0bgiRS8BddVbBfJcIb2U9v6yK4UOe7L4ZTWko=;\n\tb=JZ2iIl86lwWucGuT1u8gC7On/K6y4RCB0Ypb1d0lHKNqQ994/2KspBi3eSf2v4iyFi\n\tGEr39D9VwL1P0NrS3RAAZjns/+DvTipzTA9l0HxSTHwYsEK1Ih3Gj//O01ftIDUIOzlP\n\tN2y53W6BSnfPtOxj6I1JGNEw6gR/s0Bwew3Ia6xubYSFHRGk3NJUdEfRPRnWRN6FsZz6\n\ttTcPflR0z/9QI3JxW3mRHMJOAcR5BxLEoQUPS8CbGD1twOHCWQbvLFqKTqKlR6ZQIGNd\n\t3TKXx0eP7QERlJTqr/5D7axCAfc9Ro+UoZXfGljIygzGNmdZnEAYxZetKxnlGL2C85u9\n\tMxjA==","X-Gm-Message-State":"AHPjjUhGbkLYcANwN4y+CgpQF22ps+V+Q6eXzRd5gRBFO0gXoV0/Z5JA\n\twV126D0VTHr/QGsLirmSLX7L2ga/ppgpQ7I73X8=","X-Google-Smtp-Source":"AOwi7QD2bqTgOKYdabz4zduCQC0bEKqRqfooeJfyt3aEkRX8gZWbrxiAnSSB/Adng5MgtKLq0pXrGco+VbjBzNG2Mhw=","X-Received":"by 10.25.20.167 with SMTP id 39mr3896551lfu.224.1505761830129;\n\tMon, 18 Sep 2017 12:10:30 -0700 (PDT)","MIME-Version":"1.0","In-Reply-To":"<1835b614-f375-dedc-9e88-9a238a904283@gmx.de>","References":"<20170917225927.117917-1-sjg@chromium.org>\n\t<20170917225927.117917-9-sjg@chromium.org>\n\t<1835b614-f375-dedc-9e88-9a238a904283@gmx.de>","From":"Rob Clark <robdclark@gmail.com>","Date":"Mon, 18 Sep 2017 15:10:29 -0400","Message-ID":"<CAF6AEGub4RmtLxwZAUcWn2De67xT-mSNJ6xvjVReNPfWRJfb0A@mail.gmail.com>","To":"Heinrich Schuchardt <xypron.glpk@gmx.de>","Cc":"U-Boot Mailing List <u-boot@lists.denx.de>,\n\tAndy Shevchenko <andriy.shevchenko@linux.intel.com>","Subject":"Re: [U-Boot] [PATCH 08/16] sandbox: Add a setjmp() implementation","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}},{"id":1774390,"web_url":"http://patchwork.ozlabs.org/comment/1774390/","msgid":"<CAPnjgZ0J8PDSZL73szDQCxSCN6pgWtH0DnAX4hKVfEVQhxgJwA@mail.gmail.com>","list_archive_url":null,"date":"2017-09-25T02:12:58","subject":"Re: [U-Boot] [PATCH 08/16] sandbox: Add a setjmp() implementation","submitter":{"id":6170,"url":"http://patchwork.ozlabs.org/api/people/6170/","name":"Simon Glass","email":"sjg@chromium.org"},"content":"Hi,\n\nOn 18 September 2017 at 13:10, Rob Clark <robdclark@gmail.com> wrote:\n> On Mon, Sep 18, 2017 at 2:01 AM, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:\n>> On 09/18/2017 12:59 AM, Simon Glass wrote:\n>>> Add an implementation of setjmp() and longjmp() which rely on the\n>>> underlying host C library. Since we cannot know how large the jump buffer\n>>> needs to be, pick something that should be suitable and check it at\n>>> runtime. At present we need access to the underlying struct as well.\n>>>\n>>> Signed-off-by: Simon Glass <sjg@chromium.org>\n>>> ---\n>>>\n>>>  arch/sandbox/cpu/cpu.c            | 13 +++++++++++++\n>>>  arch/sandbox/cpu/os.c             | 17 +++++++++++++++++\n>>>  arch/sandbox/include/asm/setjmp.h | 21 +++++++++++++++++++++\n>>>  include/os.h                      | 21 +++++++++++++++++++++\n>>>  4 files changed, 72 insertions(+)\n>>>  create mode 100644 arch/sandbox/include/asm/setjmp.h\n>>>\n>>> diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c\n>>> index 01991049cc..de5862a53b 100644\n>>> --- a/arch/sandbox/cpu/cpu.c\n>>> +++ b/arch/sandbox/cpu/cpu.c\n>>> @@ -9,6 +9,7 @@\n>>>  #include <libfdt.h>\n>>>  #include <os.h>\n>>>  #include <asm/io.h>\n>>> +#include <asm/setjmp.h>\n>>>  #include <asm/state.h>\n>>>  #include <dm/root.h>\n>>>\n>>> @@ -154,3 +155,15 @@ ulong timer_get_boot_us(void)\n>>>\n>>>       return (count - base_count) / 1000;\n>>>  }\n>>> +\n>>> +int setjmp(jmp_buf jmp)\n>>> +{\n>>> +     return os_setjmp((ulong *)jmp, sizeof(jmp));\n>>> +}\n>>> +\n>>> +void longjmp(jmp_buf jmp, int ret)\n>>> +{\n>>> +     os_longjmp((ulong *)jmp, ret);\n>>> +     while (1)\n>>> +             ;\n>>> +}\n>>> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c\n>>> index 22d6aab534..909034fa4b 100644\n>>> --- a/arch/sandbox/cpu/os.c\n>>> +++ b/arch/sandbox/cpu/os.c\n>>> @@ -7,6 +7,7 @@\n>>>  #include <errno.h>\n>>>  #include <fcntl.h>\n>>>  #include <getopt.h>\n>>> +#include <setjmp.h>\n>>>  #include <stdio.h>\n>>>  #include <stdint.h>\n>>>  #include <stdlib.h>\n>>> @@ -609,3 +610,19 @@ void os_localtime(struct rtc_time *rt)\n>>>       rt->tm_yday = tm->tm_yday;\n>>>       rt->tm_isdst = tm->tm_isdst;\n>>>  }\n>>> +\n>>> +int os_setjmp(ulong *jmp, int size)\n>>> +{\n>>> +     if (size < sizeof(jmp_buf)) {\n>>> +             printf(\"setjmp: jmpbuf is too small (%d bytes, need %d)\\n\",\n>>> +                    size, sizeof(jmp_buf));\n>>> +             return -ENOSPC;\n>>> +     }\n>>> +\n>>> +     return setjmp((struct __jmp_buf_tag *)jmp);\n>>> +}\n>>> +\n>>> +void os_longjmp(ulong *jmp, int ret)\n>>> +{\n>>> +     longjmp((struct __jmp_buf_tag *)jmp, ret);\n>>> +}\n>>> diff --git a/arch/sandbox/include/asm/setjmp.h b/arch/sandbox/include/asm/setjmp.h\n>>> new file mode 100644\n>>> index 0000000000..e25f50107c\n>>> --- /dev/null\n>>> +++ b/arch/sandbox/include/asm/setjmp.h\n>>> @@ -0,0 +1,21 @@\n>>> +/*\n>>> + * (C) Copyright 2016\n>>> + * Alexander Graf <agraf@suse.de>\n>>> + *\n>>> + * SPDX-License-Identifier:  GPL-2.0+\n>>> + */\n>>> +\n>>> +#ifndef _SETJMP_H_\n>>> +#define _SETJMP_H_   1\n>>> +\n>>> +struct jmp_buf_data {\n>>> +     /* We're not sure how long this should be */\n>>> +     ulong data[32];\n>>> +};\n>>> +\n>>> +typedef struct jmp_buf_data jmp_buf[1];\n>>> +\n>>> +int setjmp(jmp_buf jmp);\n>>> +__noreturn void longjmp(jmp_buf jmp, int ret);\n>>> +\n>>> +#endif /* _SETJMP_H_ */\n>>> diff --git a/include/os.h b/include/os.h\n>>> index 2bf4bdb1b8..ad1836ac9f 100644\n>>> --- a/include/os.h\n>>> +++ b/include/os.h\n>>> @@ -310,4 +310,25 @@ int os_spl_to_uboot(const char *fname);\n>>>   */\n>>>  void os_localtime(struct rtc_time *rt);\n>>>\n>>> +/**\n>>> + * os_setjmp() - Call setjmp()\n>>> + *\n>>> + * Call the host system's setjmp() function.\n>>> + *\n>>> + * @jmp: Buffer to store current execution state\n>>> + * @size: Size of buffer\n>>> + * @return normal setjmp() value if OK, -ENOSPC if @size is too small\n>>> + */\n>>> +int os_setjmp(ulong *jmp, int size);\n>>> +\n>>> +/**\n>>> + * os_longjmp() - Call longjmp()\n>>> + *\n>>> + * Call the host system's longjmp() function.\n>>> + *\n>>> + * @jmp: Buffer where previous execution state was stored\n>>> + * @ret: Value to pass to longjmp()\n>>> + */\n>>> +void os_longjmp(ulong *jmp, int ret);\n>>> +\n>>>  #endif\n>>>\n>>\n>> Please, fix this warning:\n>>\n>> arch/sandbox/cpu/cpu.c: In function ‘setjmp’:\n>> arch/sandbox/cpu/cpu.c:161:39: warning: ‘sizeof’ on array function\n>> parameter ‘jmp’ will return size of ‘struct jmp_buf_data *’\n>> [-Wsizeof-array-argument]\n>>   return os_setjmp((ulong *)jmp, sizeof(jmp));\n>>                                        ^\n>> arch/sandbox/cpu/cpu.c:159:20: note: declared here\n>>  int setjmp(jmp_buf jmp)\n>>\n>\n> with the sizeof changed to sizeof(jmp_buf), I'm getting:\n>\n> ...\n> EFI: Entry efi_exit(00007fffffffc198, 2147483662, 0, 0000000000000000)\n>\n> Program received signal SIGSEGV, Segmentation fault.\n> os_longjmp (jmp=0x7fffffffc200,\n>     jmp@entry=<error reading variable: DWARF-2 expression error: Loop\n> detected (257).>, ret=1,\n>     ret@entry=<error reading variable: DWARF-2 expression error: Loop\n> detected (257).>)\n>     at ../arch/sandbox/cpu/os.c:627\n> 627        longjmp((struct __jmp_buf_tag *)jmp, ret);\n>\n>\n> So it seems like something not quite right still..\n\nHmm I'm not sure what, yet.\n\nRegards,\nSimon","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"cYyg7KwE\"; \n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"jknlAe5V\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3y0pSb3B0bz9t30\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 25 Sep 2017 12:49:03 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 2B812C22212; Mon, 25 Sep 2017 02:28:21 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 1FEECC22197;\n\tMon, 25 Sep 2017 02:28:20 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid D8E7CC221A0; Mon, 25 Sep 2017 02:13:25 +0000 (UTC)","from mail-qt0-f169.google.com (mail-qt0-f169.google.com\n\t[209.85.216.169])\n\tby lists.denx.de (Postfix) with ESMTPS id ECCAAC21C26\n\tfor <u-boot@lists.denx.de>; Mon, 25 Sep 2017 02:13:20 +0000 (UTC)","by mail-qt0-f169.google.com with SMTP id s18so5533168qta.3\n\tfor <u-boot@lists.denx.de>; Sun, 24 Sep 2017 19:13:20 -0700 (PDT)","by 10.200.37.200 with HTTP; Sun, 24 Sep 2017 19:12:58 -0700 (PDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,\n\tRCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID autolearn=unavailable\n\tautolearn_force=no version=3.4.0","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=20161025; \n\th=mime-version:sender:in-reply-to:references:from:date:message-id\n\t:subject:to:cc:content-transfer-encoding;\n\tbh=4hmWBpaBMqPfxqk4XIvVQzthqw4JSE5U2BUJ95mKlUU=;\n\tb=cYyg7KwE52jGKlYuIlYwjSqwI3y3MrT8qiVhC30s6QIIDXQNK2c+o8Hc88894cW7ls\n\tLSv7p55a/YvUU+8Ppj2epYMGUfKZavwvlBVfPBmCx6DjnjPXOjAOjrgNG838xPf9rufP\n\tQbYoNQWMCaOZl9nHK1C8HusHZYHjjOtCGaMXDHnacOIvCWBpdM7+9gm/8L6JU2Ow7PKC\n\tiyReGdsnIb93S0xQAtDkIUEfO1kqHuuYOg5LqoEVUIWf5qIELPbaTpwcDiAicT8DRf4z\n\tG1wPazImzO1dUJE0NJT/DTbKHA2UqSuIytH6IclaUd/OzeB/uILodEEBg3m01g2IeQGM\n\tSucA==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=mime-version:sender:in-reply-to:references:from:date:message-id\n\t:subject:to:cc:content-transfer-encoding;\n\tbh=4hmWBpaBMqPfxqk4XIvVQzthqw4JSE5U2BUJ95mKlUU=;\n\tb=jknlAe5VURXXYW40LHumX2hhKvYvxBsNjsHB36H3GRPJVWyrUMXewDK3K+ZJ+KJLU8\n\tOd82NAVBjX+5n1kfXeMwpXawVUrbrsyW77yCHbO+CxO2NPRmKxdKtz7GhYR9KL18+Vv2\n\toEuYOb85HveDjjVSmlCr/MCFQZgo+toJqSJiE="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:sender:in-reply-to:references:from\n\t:date:message-id:subject:to:cc:content-transfer-encoding;\n\tbh=4hmWBpaBMqPfxqk4XIvVQzthqw4JSE5U2BUJ95mKlUU=;\n\tb=eUJ32L0KC/iCcNmUmJfDSg7sGDJ0BM7GV1N3YvZ/n6uYrjk7pXJuBmxSGTNEsDhD39\n\tuN+jbhw3nm1cbaHkFZH9WP2BpChm7iC0Cczw8t/yCpCSeWy3KUN34gHDCHD4MR9+iici\n\thlGRdGL5XJd9waI7JkJrAYDWiHFxFfsApl3MTKwSE7mRIzGZLmJx9c6JfEqaVZNsxEAC\n\tnewcXjIMj5SeDgipEKu/E4R4goaPqyqEvA44nareCupgmW2LmWd2WU39zRKZI66Y9AJ3\n\trKbzEv91BE6y7BnxwXu4lAC3fr7U8BkoSu9cYTh5PUvMG/Gr4M2oODTEESWkIN+XYps9\n\t9MoA==","X-Gm-Message-State":"AHPjjUhoJKPJ/HFDHokSYzN5fGu2rRdk1Vlt/eaKwKlRfI7O51MJ8TLG\n\t2gqfb+YMgX/ec881Seu0mMnRbkw2zXwXjpeE1pSHFg==","X-Google-Smtp-Source":"AOwi7QAtg2EDLVaZUlRmUOnjo8JV14CqE0qoyk3OTmYnXJdWAAzS5IxyDQN1JcLuAWcocIgVDu9dvZRs21CdqeURWSI=","X-Received":"by 10.200.23.252 with SMTP id r57mr9338422qtk.76.1506305599593; \n\tSun, 24 Sep 2017 19:13:19 -0700 (PDT)","MIME-Version":"1.0","In-Reply-To":"<CAF6AEGub4RmtLxwZAUcWn2De67xT-mSNJ6xvjVReNPfWRJfb0A@mail.gmail.com>","References":"<20170917225927.117917-1-sjg@chromium.org>\n\t<20170917225927.117917-9-sjg@chromium.org>\n\t<1835b614-f375-dedc-9e88-9a238a904283@gmx.de>\n\t<CAF6AEGub4RmtLxwZAUcWn2De67xT-mSNJ6xvjVReNPfWRJfb0A@mail.gmail.com>","From":"Simon Glass <sjg@chromium.org>","Date":"Sun, 24 Sep 2017 22:12:58 -0400","X-Google-Sender-Auth":"ox9eYX6Zn-if2DijLDcFl9PqpAw","Message-ID":"<CAPnjgZ0J8PDSZL73szDQCxSCN6pgWtH0DnAX4hKVfEVQhxgJwA@mail.gmail.com>","To":"Rob Clark <robdclark@gmail.com>","Cc":"Heinrich Schuchardt <xypron.glpk@gmx.de>,\n\tAndy Shevchenko <andriy.shevchenko@linux.intel.com>,\n\tU-Boot Mailing List <u-boot@lists.denx.de>","Subject":"Re: [U-Boot] [PATCH 08/16] sandbox: Add a setjmp() implementation","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}}]