[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mint-1.11h2



In article <199409121655.AA23875@irs.inf.tu-dresden.de> you write:
>I've put up a new re-sync patch...

hmm i'm always just a bit too late :)  here are some more fixes,
now relative to 11h2.

1. memory fragmentation, keep some more spawn/execs from failing.
i hope my next mintlib rebuilt with sticky compiler will no longer
die every 42 files... :)

Index: mem.c
@@ -1093,7 +1093,7 @@
 	BASEPAGE *b, *bparent = 0;
 	PROC *parent = 0;
 	short protmode;
-	int i;
+	int i, ismax = 1;
 
 /* if we're about to do an exec tell max_rsize which of the exec'ing
    process regions will be freed, but don't free them yet so the process
@@ -1127,12 +1127,16 @@
    load there; otherwise, if more than (minalt+1)*128K alt ram available
    for heap space, load in alt ram ("minalt" is the high byte of flags)
  */
+again2:
 	if (flags & (F_ALTLOAD|F_SHTEXT)) {
 		minalt = (flags & F_MINALT) >> 28L;
 		minalt = len = (minalt+1)*128*1024L + prgsize + 256;
 		if ((flags & F_MINALT) == F_MINALT)
 			len = 0;
+		else
+			ismax = 0;
 	}
+again1:
 	if (flags & F_ALTLOAD) {
 		coresize = max_rsize(core, len);
 		altsize = max_rsize(alt, len);
@@ -1156,7 +1160,10 @@
 		savemem->links = 1;
 
 	if (curproc->maxmem && len > curproc->maxmem) {
-		len = curproc->maxmem;
+		if (ismax >= 0)
+			len = curproc->maxmem;
+		else if (len > curproc->maxmem+fh->ftext)
+			len = curproc->maxmem+fh->ftext;
 	}
 
 /* make sure that a little bit of memory is left over */
@@ -1165,12 +1172,23 @@
 	}
 
 	if (s && !s->text &&
-	    (!(flags & F_ALTLOAD) || map == alt || altsize < fh->ftext ||
-	     0 == (s->text = addr2mem(alloc_region(alt, fh->ftext, PROT_P))))) {
+	    (!(flags & F_ALTLOAD) || map == alt || altsize < fh->ftext)) {
 		if (len > fh->ftext + KERNEL_MEM)
 			len -= fh->ftext + KERNEL_MEM;
 		else
 			len = 0;
+#if 1
+		if (prgsize && len < prgsize + 0x400) {
+			if (!ismax) {
+				len = minalt + fh->ftext;
+				ismax = -1;
+				goto again1;
+			}
+			if ((s->text = addr2mem(alloc_region(map, fh->ftext, PROT_P)))) {
+				goto again2;
+			}
+		}
+#endif
 	}
 
 	if (prgsize && len < prgsize + 0x400) {
@@ -1372,8 +1390,27 @@
 			shtext->links++;
 		reg = create_base(cmdlin, env, fh.flag, size,
 			isexec ? curproc : 0L, 0L, 0L, 0L, 0L);
-		if (shtext)
+		if (shtext) {
 			shtext->links--;
+#if 1
+/* if create_base failed maybe the (sticky) text segment itself is
+ * fragmenting memory... force it reloaded and have a second try
+ */
+			if (!reg && shtext->links == 1 && isexec) {
+				s->f = 0;
+				f->links--;
+				detach_region(curproc, shtext);
+				s = get_text_seg(f, &fh, xp, 0L, isexec);
+				if (!s) {
+					DEBUG(("load_region: unable to get shared text segment"));
+					goto failed;
+				}
+				reg = create_base(cmdlin, env, fh.flag, size,
+					curproc, s, f, &fh, xp);
+				shtext = s->text;
+			}
+#endif
+		}
 	}
 	env->links--;
 	if (reg && size+1024L > reg->len) {

2. catch open /dev/fd/just-opened-fd, and a race

Index: dosfile.c
@@ -213,7 +213,7 @@
 
 	if (dev == &fakedev) {		/* fake BIOS devices */
 		f = curproc->handle[devsp];
-		if (!f) {
+		if (!f || f == (FILEPTR *)1) {
 			mint_errno = EIHNDL;
 			return 0;
 		}
@@ -271,7 +271,7 @@
 			*tty = default_tty;
 			if (!creating)
 				tty->state = s;
-			if ((tty->use_cnt = u) > 1) {
+			if ((tty->use_cnt = u) > 1 || !creating) {
 				tty->aux_cnt = a;
 				tty->rsel = r, tty->wsel = w;
 			}

3. fix pty master reads with O_NDELAY off, check for VIRGIN_PIPE, and
ignore HPCL

Index: pipefs.c
@@ -866,15 +870,21 @@
 		while (tty->vmin > 1 && !tty->vtime &&
 		    !(f->flags & O_NDELAY) &&
 		    (tty->sg.sg_flags & (T_RAW|T_CBREAK)) &&
-		    this->inp->len < tty->vmin*4 && this->inp->writers > 0)
+		    this->inp->len < tty->vmin*4 && this->inp->writers > 0 &&
+		    this->inp->writers != VIRGIN_PIPE)
 			sleep (IO_Q, (long)this->inp);
 		return EUNDEV;
 	}
 /*
  * pty master reads are always RAW
  */
-	if (nbytes > 1 && nbytes > this->outp->len)
+	if (nbytes > 1 && nbytes > this->outp->len) {
+		while (!(f->flags & O_NDELAY) &&
+		    !this->outp->len && this->outp->writers > 0 &&
+		    this->outp->writers != VIRGIN_PIPE)
+			sleep (IO_Q, (long)this->outp);
 		nbytes = this->outp->len;
+	}
 	return pipe_read(f, buf, nbytes);
 }
 
@@ -977,6 +977,23 @@
 		else
 			lck->l_type = F_UNLCK;
 		break;
+/* ptys have no DTR line :)  ignore hang up on close...  */
+	case TIOCSSTATEB:
+	    {
+		long mask = ((long *)buf)[1] & ~(TS_HOLD|TS_BLIND|TS_HPCL);
+		struct tty *tty = this->tty;
+
+		if (!is_terminal(f) || !tty)
+			return EINVFN;
+		if (!(tty->sg.sg_flags & T_XKEY))
+			mask &= ~TS_ESC;
+		if (*(long *)buf != -1)
+			tty->state = (tty->state & ~mask) | (*((long *)buf) & mask);
+		*(long *)buf = tty->state;
+		return 0;
+	    }
+	case TIOCHPCL:
+		return 0;
 	case TIOCGVMIN:
 	case TIOCSVMIN:
 	    {

4. better example for iwake :)

Index: proc.c
@@ -714,23 +714,27 @@
  *
  * use like this:
  *	static ipid = -1;
- *	static sleepers = 0;	(optional, to save useless calls)
+ *	static volatile sleepers = 0;	(optional, to save useless calls)
  *	...
  *	device_read(...)
  *	{
  *		ipid = curproc->pid;	(p_getpid() for device drivers...)
- *		while (not ready for IO...) {
- *			++sleepers;
+ *		while (++sleepers, (not ready for IO...)) {
  *			sleep(IO_Q, cond);
- *			--sleepers;
+ *			if (--sleepers < 0)
+ *				sleepers = 0;
  *		}
+ *		if (--sleepers < 0)
+ *			sleepers = 0;
  *		ipid = -1;
  *		...
  *	}
  *
  * and in the interrupt handler:
- *	if (sleepers)
+ *	if (sleepers > 0) {
+ *		sleepers = 0;
  *		iwake(IO_Q, cond, ipid);
+ *	}
  *
  * caller is responsible for not trying to wake READY_Q or other nonsense :)
  * and making sure the passed pid is always -1 when curproc is calling

5. the new suid+gid in PROC confuse things like top and ps, moved them
down a bit...  (is this the best place?)

Index: proc.h
@@ -114,7 +114,6 @@
 	short	ruid;			/* process real user id 	*/
 	short	rgid;			/* process real group id 	*/
 	short	euid, egid;		/* effective user and group ids */
-	short	suid, sgid;		/* saved user and group ids	*/
 
 	ushort	memflags;		/* e.g. malloc from alternate ram */
 	short	pri;			/* base process priority 	*/
@@ -145,6 +144,7 @@
 	short	domain;			/* process domain (TOS or UNIX)	*/
 
 	short	curpri;			/* current process priority	*/
+	short	suid, sgid;		/* saved user and group ids	*/
 #define MIN_NICE -20
 #define MAX_NICE 20
 
6. and at least gcc 2.3.3 does not need this, is 2.5.8 different?

Index: proto.h
@@ -320,7 +320,6 @@
 /* tty.c */
 void tty_checkttou P_((FILEPTR *f, struct tty *tty));
 long tty_read P_((FILEPTR *f, void *buf, long nbytes));
-INLINE void tty_checkttou P_((FILEPTR *f, struct tty *tty));
 long tty_write P_((FILEPTR *f, const void *buf, long nbytes));
 long tty_ioctl P_((FILEPTR *f, int mode, void *arg));
 long tty_getchar P_((FILEPTR *f, int mode));

 btw has anyone with GEM problems tried h2 yet, does it still crash?

 have fun...
	Juergen