Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Superior ability breeds superior ambition. -- Spock, "Space Seed", stardate 3141.9


devel / comp.lang.c / Re: cc64 uninitialized variable (bart) and self-hosting near-C90 system

SubjectAuthor
* cc64 uninitialized variable (bart) and self-hosting near-C90 systemPaul Edwards
`* Re: cc64 uninitialized variable (bart) and self-hosting near-C90Bart
 `- Re: cc64 uninitialized variable (bart) and self-hosting near-C90 systemPaul Edwards

1
cc64 uninitialized variable (bart) and self-hosting near-C90 system

<2725dfbc-4281-4071-bc67-d1b74e6eb893n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29206&group=comp.lang.c#29206

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:3987:b0:658:8eb5:8561 with SMTP id ny7-20020a056214398700b006588eb58561mr15546qvb.2.1695206348968;
Wed, 20 Sep 2023 03:39:08 -0700 (PDT)
X-Received: by 2002:a05:6808:2102:b0:3a7:5314:e576 with SMTP id
r2-20020a056808210200b003a75314e576mr1042281oiw.4.1695206348581; Wed, 20 Sep
2023 03:39:08 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 20 Sep 2023 03:39:08 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=136.158.103.115; posting-account=CeHKkQoAAAAowY1GfiJYG55VVc0s1zaG
NNTP-Posting-Host: 136.158.103.115
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2725dfbc-4281-4071-bc67-d1b74e6eb893n@googlegroups.com>
Subject: cc64 uninitialized variable (bart) and self-hosting near-C90 system
From: mutazi...@gmail.com (Paul Edwards)
Injection-Date: Wed, 20 Sep 2023 10:39:08 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2588
 by: Paul Edwards - Wed, 20 Sep 2023 10:39 UTC

Hi Bart.

After a lot of effort, UCX64 and cc64 are now running
on real hardware, self-compiling/hosting. Pictures
and more technical information available here:

https://groups.io/g/hercules-380/message/2696

It took a Chinese computer with a Chinese BIOS (written
in actual Chinese characters) with a Zhaoxin Chinese
(ie not AMD or Intel) x64 CPU to find this bug that
wasn't showing on Virtualbox or qemu.

I made this commit:

https://sourceforge.net/p/pdos/gitcode/ci/81d0fa1b901803ae3198bd8df0cd9c8756e08cd4/

C:\devel\pdos\cc64>git show 81d0fa1b901803ae3198bd8df0cd9c8756e08cd4
commit 81d0fa1b901803ae3198bd8df0cd9c8756e08cd4 (HEAD -> master, origin/master, origin/HEAD)
Author: Paul Edwards <mutazilah@gmail.com>
Date: Wed Sep 20 15:42:07 2023 +0800

initialize a variable found to be a wild pointer

diff --git a/cc64/cc64.c b/cc64/cc64.c
index 525e5f2b..4dcbc4db 100644
--- a/cc64/cc64.c
+++ b/cc64/cc64.c
@@ -22449,6 +22449,7 @@ void cc_libmcl_genmc(i64 opcode,struct cc_libmcl_opndrec * a,struct cc_libmcl_op
struct cc_libmcl_mclrec * m;
struct cc_libmcl_mclrec * oldm;
m = (struct cc_libmcl_mclrec *)(mlib_pcm_alloc((i64)32));
+ (*m).nextmcl = NULL; /* paul added this - should allocz be used instead? */
(*m).lineno = cc_decls_clineno;
(*m).opcode = (u64)(opcode);
(*m).a = a;

C:\devel\pdos\cc64>

Any comment on my comment?

I don't know if there are similar issues in other
parts of the code, but if they exist they're
probably not very important.

Thanks. Paul.

Re: cc64 uninitialized variable (bart) and self-hosting near-C90 system

<ueenbi$2u1f9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29208&group=comp.lang.c#29208

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: cc64 uninitialized variable (bart) and self-hosting near-C90
system
Date: Wed, 20 Sep 2023 13:08:18 +0100
Organization: A noiseless patient Spider
Lines: 88
Message-ID: <ueenbi$2u1f9$1@dont-email.me>
References: <2725dfbc-4281-4071-bc67-d1b74e6eb893n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 20 Sep 2023 12:08:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="72a9d5a408f397da031adfcb3ec4a860";
logging-data="3081705"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18X//W9ydgauj/SulcxzvnV7qHFliGhq28="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:WcaqKjjveaEr4JWSUYsuFK9HT68=
In-Reply-To: <2725dfbc-4281-4071-bc67-d1b74e6eb893n@googlegroups.com>
 by: Bart - Wed, 20 Sep 2023 12:08 UTC

On 20/09/2023 11:39, Paul Edwards wrote:
> Hi Bart.
>
> After a lot of effort, UCX64 and cc64 are now running
> on real hardware, self-compiling/hosting. Pictures
> and more technical information available here:
>
> https://groups.io/g/hercules-380/message/2696
>
>
> It took a Chinese computer with a Chinese BIOS (written
> in actual Chinese characters) with a Zhaoxin Chinese
> (ie not AMD or Intel) x64 CPU to find this bug that
> wasn't showing on Virtualbox or qemu.
>
>
> I made this commit:
>
> https://sourceforge.net/p/pdos/gitcode/ci/81d0fa1b901803ae3198bd8df0cd9c8756e08cd4/
>
> C:\devel\pdos\cc64>git show 81d0fa1b901803ae3198bd8df0cd9c8756e08cd4
> commit 81d0fa1b901803ae3198bd8df0cd9c8756e08cd4 (HEAD -> master, origin/master, origin/HEAD)
> Author: Paul Edwards <mutazilah@gmail.com>
> Date: Wed Sep 20 15:42:07 2023 +0800
>
> initialize a variable found to be a wild pointer
>
> diff --git a/cc64/cc64.c b/cc64/cc64.c
> index 525e5f2b..4dcbc4db 100644
> --- a/cc64/cc64.c
> +++ b/cc64/cc64.c
> @@ -22449,6 +22449,7 @@ void cc_libmcl_genmc(i64 opcode,struct cc_libmcl_opndrec * a,struct cc_libmcl_op
> struct cc_libmcl_mclrec * m;
> struct cc_libmcl_mclrec * oldm;
> m = (struct cc_libmcl_mclrec *)(mlib_pcm_alloc((i64)32));
> + (*m).nextmcl = NULL; /* paul added this - should allocz be used instead? */
> (*m).lineno = cc_decls_clineno;
> (*m).opcode = (u64)(opcode);
> (*m).a = a;
>
> C:\devel\pdos\cc64>
>
>
> Any comment on my comment?

Yes, that was an oversight. Either pcm_allocz should be called or, more
efficient as most fields are initialised anyway, just set that extra
field as you have done.

Although under tests, that is consistently all zeros, and I'm not sure
why. Calling malloc() here instead will immediately return garbage.
pcm_alloc() will allocate space from a large pool, but that was itself
allocated with malloc.

This is an interesting little program:

#include <stdio.h>
#include <stdlib.h>

int main(void) {
enum {N=1024};
long long int sum=0;
unsigned char* p = malloc(N);

for (int i=0; i<N; ++i) sum+=*p++;

printf("Sum of bytes: %lld\n", sum);
}

This allocates memory with malloc then adds up all the byte values.

When N is small, like 1024, it will give results of around 80,000. For
16K, it's 3000, and at 512K, it's 700.

But at 1MB (N=1048576), it's always exactly zero. So perhaps it grabs
memory direct from the OS or something, which happens to be zeroed.

The memory pools used by pcm_alloc() in cc64.c are 2MB in size.

Still, the code should be fixed and not rely on such accidents. (Perhaps
allocated memory should be randomised during testing.)

(Newer versions of both this code and the alloc functions work
differently, for example the pool is explicitly zeroed, which for
allocations that are never freed, means they do not need individual
zeroing.)

Re: cc64 uninitialized variable (bart) and self-hosting near-C90 system

<07d73890-d8a8-46be-af05-c939433f9781n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29209&group=comp.lang.c#29209

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:19a5:b0:411:fca1:76a with SMTP id u37-20020a05622a19a500b00411fca1076amr33563qtc.10.1695215869396;
Wed, 20 Sep 2023 06:17:49 -0700 (PDT)
X-Received: by 2002:a05:6830:1315:b0:6bf:192d:31dc with SMTP id
p21-20020a056830131500b006bf192d31dcmr802300otq.2.1695215869144; Wed, 20 Sep
2023 06:17:49 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 20 Sep 2023 06:17:48 -0700 (PDT)
In-Reply-To: <ueenbi$2u1f9$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=136.158.103.115; posting-account=CeHKkQoAAAAowY1GfiJYG55VVc0s1zaG
NNTP-Posting-Host: 136.158.103.115
References: <2725dfbc-4281-4071-bc67-d1b74e6eb893n@googlegroups.com> <ueenbi$2u1f9$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <07d73890-d8a8-46be-af05-c939433f9781n@googlegroups.com>
Subject: Re: cc64 uninitialized variable (bart) and self-hosting near-C90 system
From: mutazi...@gmail.com (Paul Edwards)
Injection-Date: Wed, 20 Sep 2023 13:17:49 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2137
 by: Paul Edwards - Wed, 20 Sep 2023 13:17 UTC

On Wednesday, September 20, 2023 at 8:08:33 PM UTC+8, Bart wrote:

> Yes, that was an oversight. Either pcm_allocz should be called or, more
> efficient as most fields are initialised anyway, just set that extra
> field as you have done.

Ok, thanks, I'll leave it as-is then.

> But at 1MB (N=1048576), it's always exactly zero. So perhaps it grabs
> memory direct from the OS or something, which happens to be zeroed.
>
> The memory pools used by pcm_alloc() in cc64.c are 2MB in size.

Ok, so that's why it works under Windows. I switched to UEFI
(sort of - effectively).

> Still, the code should be fixed and not rely on such accidents. (Perhaps
> allocated memory should be randomised during testing.)

This commit helped find the problem - I got x'99':

https://sourceforge.net/p/pdos/gitcode/ci/9231911169702297ff25b818c40733fcb35d97a3/

BFN. Paul.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor