ref: 25f04a68a168a948783618910e115316eb0ed3fc
parent: 34ec2056041a193a471701dd50e2032dc300fb0e
author: cinap_lenrek <[email protected]>
date: Mon Mar 11 14:57:22 EDT 2013
ape: threadsafe errno store errno on the private process stack so its always per process and not just per memory space. errno itself becomes a macro dereferencing int *_errnoloc; which is initialized from main9.s pointing to the private stack location. various fixes in programs that just imported errno variable with "extern int errno;" instead of including <errno.h>.
--- a/sys/include/ape/errno.h
+++ b/sys/include/ape/errno.h
@@ -2,7 +2,8 @@
#define __ERRNO
#pragma lib "/$M/lib/ape/libap.a"
-extern int errno;
+extern int *_errnoloc;
+#define errno (*_errnoloc)
#define EDOM 1000
#define ERANGE 1001
--- a/sys/src/ape/lib/ap/386/main9.s
+++ b/sys/src/ape/lib/ap/386/main9.s
@@ -1,14 +1,17 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _main(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _main(SB), 1, $(16+NPRIVATES*4)
/* _tos = arg */
MOVL AX, _tos(SB)
- LEAL 8(SP), AX
+ LEAL 12(SP), AX
+ MOVL AX, _errnoloc(SB)
+ LEAL 16(SP), AX
MOVL AX, _privates(SB)
MOVL $NPRIVATES, _nprivates(SB)
--- a/sys/src/ape/lib/ap/386/main9p.s
+++ b/sys/src/ape/lib/ap/386/main9p.s
@@ -1,14 +1,17 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _mainp(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _mainp(SB), 1, $(16+NPRIVATES*4)
/* _tos = arg */
MOVL AX, _tos(SB)
- LEAL 8(SP), AX
+ LEAL 12(SP), AX
+ MOVL AX, _errnoloc(SB)
+ LEAL 16(SP), AX
MOVL AX, _privates(SB)
MOVL $NPRIVATES, _nprivates(SB)
--- a/sys/src/ape/lib/ap/68020/main9.s
+++ b/sys/src/ape/lib/ap/68020/main9.s
@@ -1,15 +1,17 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _main(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _main(SB), 1, $(16+NPRIVATES*4)
MOVL $a6base(SB), A6
/* _tos = arg */
MOVL R0, _tos(SB) /* return value of sys exec!! */
- LEA private+8(SP), _privates(SB)
+ LEA errno+12(SB), _errnoloc(SB)
+ LEA private+16(SP), _privates(SB)
MOVL $NPRIVATES, _nprivates(SB)
PEA inargv+0(FP)
--- a/sys/src/ape/lib/ap/68020/main9p.s
+++ b/sys/src/ape/lib/ap/68020/main9p.s
@@ -1,15 +1,17 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _mainp(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _mainp(SB), 1, $(16+NPRIVATES*4)
MOVL $a6base(SB), A6
/* _tos = arg */
MOVL R0, _tos(SB) /* return value of sys exec!! */
- LEA private+8(SP), _privates(SB)
+ LEA errno+12(SP), _errnoloc(SB)
+ LEA private+16(SP), _privates(SB)
MOVL $NPRIVATES, _nprivates(SB)
/* _profmain(); */
--- a/sys/src/ape/lib/ap/alpha/main9.s
+++ b/sys/src/ape/lib/ap/alpha/main9.s
@@ -1,15 +1,18 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _main(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _main(SB), 1, $(16+NPRIVATES*4)
MOVQ $setSB(SB), R29
/* _tos = arg */
MOVL R0, _tos(SB)
- MOVQ $8(SP), R1
+ MOVQ $12(SP), R1
+ MOVL R1, _errnoloc(SB)
+ MOVQ $16(SP), R1
MOVL R1, _privates(SB)
MOVQ $NPRIVATES, R1
MOVL R1, _nprivates(SB)
--- a/sys/src/ape/lib/ap/alpha/main9p.s
+++ b/sys/src/ape/lib/ap/alpha/main9p.s
@@ -1,15 +1,18 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _mainp(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _mainp(SB), 1, $(16+NPRIVATES*4)
MOVQ $setSB(SB), R29
/* _tos = arg */
MOVL R0, _tos(SB)
- MOVQ $8(SP), R1
+ MOVQ $12(SP), R1
+ MOVL R1, _errnoloc(SB)
+ MOVQ $16(SP), R1
MOVL R1, _privates(SB)
MOVQ $NPRIVATES, R1
MOVL R1, _nprivates(SB)
--- a/sys/src/ape/lib/ap/arm/main9.s
+++ b/sys/src/ape/lib/ap/arm/main9.s
@@ -5,16 +5,19 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _main(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _main(SB), 1, $(16+NPRIVATES*4)
MOVW $setR12(SB), R(sb)
/* _tos = arg */
MOVW R(arg), _tos(SB)
- MOVW $private+8(SP), R1
+ MOVW $errno+12(SP), R1
+ MOVW R1, _errnoloc(SB)
+ MOVW $private+16(SP), R1
MOVW R1, _privates(SB)
MOVW $NPRIVATES, R1
MOVW R1, _nprivates(SB)
--- a/sys/src/ape/lib/ap/arm/main9p.s
+++ b/sys/src/ape/lib/ap/arm/main9p.s
@@ -5,16 +5,19 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _mainp(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _mainp(SB), 1, $(16+NPRIVATES*4)
MOVW $setR12(SB), R(sb)
/* _tos = arg */
MOVW R(arg), _tos(SB)
- MOVW $private+8(SP), R1
+ MOVW $errno+12(SP), R1
+ MOVW R1, _errnoloc(SB)
+ MOVW $private+16(SP), R1
MOVW R1, _privates(SB)
MOVW $NPRIVATES, R1
MOVW R1, _nprivates(SB)
--- a/sys/src/ape/lib/ap/mips/main9.s
+++ b/sys/src/ape/lib/ap/mips/main9.s
@@ -1,10 +1,11 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _main(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _main(SB), 1, $(16+NPRIVATES*4)
MOVW $setR30(SB), R30
/* _tos = arg */
@@ -17,7 +18,9 @@
ADDD F26, F26, F28
ADDD F28, F28, F30
*/
- MOVW $8(SP), R1
+ MOVW $12(SP), R1
+ MOVW R1, _errnoloc(SB)
+ MOVW $16(SP), R1
MOVW R1, _privates(SB)
MOVW $NPRIVATES, R1
MOVW R1, _nprivates(SB)
--- a/sys/src/ape/lib/ap/mips/main9p.s
+++ b/sys/src/ape/lib/ap/mips/main9p.s
@@ -1,10 +1,11 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _mainp(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _mainp(SB), 1, $(16+NPRIVATES*4)
MOVW $setR30(SB), R30
/* _tos = arg */
@@ -17,7 +18,9 @@
ADDD F26, F26, F28
ADDD F28, F28, F30
*/
- MOVW $8(SP), R1
+ MOVW $12(SP), R1
+ MOVW R1, _errnoloc(SB)
+ MOVW $16(SP), R1
MOVW R1, _privates(SB)
MOVW $NPRIVATES, R1
MOVW R1, _nprivates(SB)
--- a/sys/src/ape/lib/ap/plan9/_envsetup.c
+++ b/sys/src/ape/lib/ap/plan9/_envsetup.c
@@ -19,7 +19,7 @@
*/
char **environ;
-int errno;
+int *_errnoloc;
unsigned long _clock;
static void fdsetup(char *, char *);
static void sigsetup(char *, char *);
--- a/sys/src/ape/lib/ap/plan9/_errno.c
+++ b/sys/src/ape/lib/ap/plan9/_errno.c
@@ -10,7 +10,7 @@
char _plan9err[ERRMAX];
static struct errmap {
- int errno;
+ int num;
char *ename;
} map[] = {
/* from /sys/src/9/port/errstr.h */
@@ -119,6 +119,6 @@
if(strstr(_plan9err, map[i].ename) != 0)
break;
_ERRSTR(_plan9err, sizeof _plan9err);
- errno = (i < NERRMAP)? map[i].errno : EINVAL;
+ errno = (i < NERRMAP)? map[i].num : EINVAL;
}
}
--- a/sys/src/ape/lib/ap/plan9/_fdinfo.c
+++ b/sys/src/ape/lib/ap/plan9/_fdinfo.c
@@ -1,12 +1,12 @@
#define _BSDTIME_EXTENSION
#include "lib.h"
#include <sys/stat.h>
-#include <stdlib.h>
#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
#include "sys9.h"
#include <string.h>
-extern int errno;
Fdinfo _fdinfo[OPEN_MAX];
/*
--- a/sys/src/ape/lib/ap/power/main9.s
+++ b/sys/src/ape/lib/ap/power/main9.s
@@ -1,16 +1,19 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _main(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _main(SB), 1, $(16+NPRIVATES*4)
MOVW $setSB(SB), R2
/* _tos = arg */
MOVW R3, _tos(SB)
- MOVW $8(SP), R1
+ MOVW $12(SP), R1
+ MOVW R1, _errnoloc(SB)
+ MOVW $16(SP), R1
MOVW R1, _privates(SB)
MOVW $NPRIVATES, R1
MOVW R1, _nprivates(SB)
--- a/sys/src/ape/lib/ap/power/main9p.s
+++ b/sys/src/ape/lib/ap/power/main9p.s
@@ -1,16 +1,19 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBAL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _mainp(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _mainp(SB), 1, $(16+NPRIVATES*4)
MOVW $setSB(SB), R2
/* _tos = arg */
MOVW R3, _tos(SB)
- MOVW $8(SP), R1
+ MOVW $12(SP), R1
+ MOVW R1, _errnoloc(SB)
+ MOVW $16(SP), R1
MOVW R1, _privates(SB)
MOVW $NPRIVATES, R1
MOVW R1, _nprivates(SB)
--- a/sys/src/ape/lib/ap/sparc/main9.s
+++ b/sys/src/ape/lib/ap/sparc/main9.s
@@ -1,10 +1,11 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _main(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _main(SB), 1, $(16+NPRIVATES*4)
MOVW $setSB(SB), R2
/* _tos = arg */
@@ -16,7 +17,9 @@
FADDD F26, F26, F28
FADDD F28, F28, F30
*/
- MOVW $8(SP), R1
+ MOVW $12(SP), R1
+ MOVW R1, _errnoloc(SB)
+ MOVW $16(SP), R1
MOVW R1, _privates(SB)
MOVW $NPRIVATES, R1
MOVW R1, _nprivates(SB)
--- a/sys/src/ape/lib/ap/sparc/main9p.s
+++ b/sys/src/ape/lib/ap/sparc/main9p.s
@@ -1,10 +1,11 @@
#define NPRIVATES 16
GLOBL _tos(SB), $4
+GLOBL _errnoloc(SB), $4
GLOBL _privates(SB), $4
GLOBL _nprivates(SB), $4
-TEXT _mainp(SB), 1, $(3*4+NPRIVATES*4)
+TEXT _mainp(SB), 1, $(16+NPRIVATES*4)
MOVW $setSB(SB), R2
/* _tos = arg */
@@ -16,7 +17,9 @@
FADDD F26, F26, F28
FADDD F28, F28, F30
*/
- MOVW $8(SP), R1
+ MOVW $12(SP), R1
+ MOVW R1, _errnoloc(SB)
+ MOVW $16(SP), R1
MOVW R1, _privates(SB)
MOVW $NPRIVATES, R1
MOVW R1, _nprivates(SB)
--- a/sys/src/ape/lib/ap/stdio/iolib.h
+++ b/sys/src/ape/lib/ap/stdio/iolib.h
@@ -37,7 +37,7 @@
#define WR 4 /* open, buffer allocated, ok to write but not read */
#define ERR 5 /* open, but an uncleared error occurred */
#define END 6 /* open, but at eof */
-char *strerror(int errno);
+char *strerror(int);
int _IO_setvbuf(FILE *);
FILE *_IO_sopenr(const char*);
FILE *_IO_sopenw(void);
--- a/sys/src/ape/lib/ap/stdio/perror.c
+++ b/sys/src/ape/lib/ap/stdio/perror.c
@@ -2,8 +2,9 @@
* pANS stdio -- perror
*/
#include "iolib.h"
+#include <errno.h>
+
void perror(const char *s){
- extern int errno;
if(s!=NULL && *s != '\0') fputs(s, stderr), fputs(": ", stderr);
fputs(strerror(errno), stderr);
putc('\n', stderr);
--- a/sys/src/cmd/eqn/lex.c
+++ b/sys/src/cmd/eqn/lex.c
@@ -1,6 +1,7 @@
#include "e.h"
#include "y.tab.h"
#include <ctype.h>
+#include <errno.h>
#define SSIZE 1000
char token[SSIZE];
@@ -234,7 +235,6 @@
char name[100];
FILE *fin;
int c;
- extern int errno;
while ((c = input()) == ' ')
;
--- a/sys/src/cmd/eqn/main.c
+++ b/sys/src/cmd/eqn/main.c
@@ -1,4 +1,5 @@
#include "e.h"
+#include <errno.h>
#define MAXLINE 3600 /* maximum input line */
@@ -92,7 +93,6 @@
{
int i, type, ln;
char fname[100];
- extern int errno;
errno = 0;
curfile->lineno = 0;