The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: Paul Ruizendaal <pnr@planet.nl>
To: tuhs@minnie.tuhs.org
Subject: Re: [TUHS] V6 networking & alarm syscall
Date: Sat, 12 Jan 2019 12:13:24 +0100	[thread overview]
Message-ID: <D10210D4-B796-44C5-8862-866B5FFD6CBC@planet.nl> (raw)
In-Reply-To: <mailman.1.1547258402.6716.tuhs@minnie.tuhs.org>


> / uses the system sleep call rather than the standard C library
> / sleep (sleep (III)) because there is a critical race in the
> / C library implementation which could result in the process
> / pausing forever. This is a horrible bug in the UNIX process
> / control mechanism.
> 
> Quoted without comment from me!

Intriguing comment. I think your v6+ system probably has a lot of
PWB stuff in there. The libc source for sleep() in stock V6 is:

.globl	_sleep
sleep = 35.

_sleep:
	mov	r5,-(sp)
	mov	sp,r5
	mov	4(r5),r0
	sys	sleep
	mov	(sp)+,r5
	rts	pc

The PWB version uses something alarm/pause based, but apparently
gets it wrong:

.globl	_sleep
alarm = 27.
pause = 29.
rti = 2

_sleep:
	mov	r5,-(sp)
	mov	sp,r5
	sys	signal; 14.; 1f
	mov	4(r5),r0
	sys	alarm
	sys	pause
	clr	r0
	sys	alarm
	mov	(sp)+,r5
	rts	pc

1:
	rti

I think the race occurs when an interrupt arrives between the sys alarm
and the sys pause lines, and the handler calls sleep again.

sleep() in the V7 libc is a much more elaborate C routine.

When I first read the race condition comment, I thought the issue would
be like that of write:

_write:
	mov	r5,-(sp)
	mov	sp,r5
	mov	4(r5),r0
	mov	6(r5),0f
	mov	8(r5),0f+2
	sys	0; 9f
	bec	1f
	jmp	cerror
1:
	mov	(sp)+,r5
	rts	pc
.data
9:
	sys	write; 0:..; ..

This pattern appears in several V6 sys call routines, and would
not be safe when used in a context with signal based multi-
threading.




       reply	other threads:[~2019-01-12 11:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1.1547258402.6716.tuhs@minnie.tuhs.org>
2019-01-12 11:13 ` Paul Ruizendaal [this message]
2019-01-13 10:52 Paul Ruizendaal
2019-01-13 15:39 ` Warner Losh
  -- strict thread matches above, loose matches on Subject: below --
2019-01-12  4:14 Noel Chiappa
2019-01-12  1:24 Noel Chiappa
2019-01-12  1:58 ` Dave Horsfall
2019-01-12  2:33   ` Warner Losh
2019-01-11 23:27 Paul Ruizendaal
2019-01-10 23:12 Paul Ruizendaal
2019-01-11  0:17 ` Clem cole
2019-01-11 15:33 ` ron
2019-01-11 18:45   ` Clem Cole
2019-01-11 19:06     ` David
2019-01-11 22:08     ` reed
2019-01-11 22:18       ` Larry McVoy
2019-01-12 12:04         ` reed
2019-01-12 17:20           ` Clem Cole
2019-01-12 18:16             ` Eric Allman
2019-01-13  1:16               ` Madeline Autumn-Rose
2019-01-11 22:47       ` Clem Cole
2019-01-11 22:55         ` Eric Allman
2019-01-11 23:32         ` Warner Losh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D10210D4-B796-44C5-8862-866B5FFD6CBC@planet.nl \
    --to=pnr@planet.nl \
    --cc=tuhs@minnie.tuhs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).