Skip to content

Commit c5732c8

Browse files
committed
runtime: integrated network poller for freebsd/amd64,386, openbsd/amd64,386
Update #5199 R=golang-dev, dvyukov CC=golang-dev https://golang.org/cl/8825043
1 parent 1a94895 commit c5732c8

10 files changed

+241
-15
lines changed

src/pkg/runtime/defs_freebsd.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package runtime
1919
#include <sys/time.h>
2020
#include <signal.h>
2121
#include <errno.h>
22+
#include <sys/event.h>
2223
#include <sys/mman.h>
2324
#include <sys/ucontext.h>
2425
#include <sys/umtx.h>
@@ -30,6 +31,9 @@ package runtime
3031
import "C"
3132

3233
const (
34+
EINTR = C.EINTR
35+
EFAULT = C.EFAULT
36+
3337
PROT_NONE = C.PROT_NONE
3438
PROT_READ = C.PROT_READ
3539
PROT_WRITE = C.PROT_WRITE
@@ -48,8 +52,6 @@ const (
4852
UMTX_OP_WAIT_UINT = C.UMTX_OP_WAIT_UINT
4953
UMTX_OP_WAKE = C.UMTX_OP_WAKE
5054

51-
EINTR = C.EINTR
52-
5355
SIGHUP = C.SIGHUP
5456
SIGINT = C.SIGINT
5557
SIGQUIT = C.SIGQUIT
@@ -101,6 +103,14 @@ const (
101103
ITIMER_REAL = C.ITIMER_REAL
102104
ITIMER_VIRTUAL = C.ITIMER_VIRTUAL
103105
ITIMER_PROF = C.ITIMER_PROF
106+
107+
EV_ADD = C.EV_ADD
108+
EV_DELETE = C.EV_DELETE
109+
EV_CLEAR = C.EV_CLEAR
110+
EV_RECEIPT = C.EV_RECEIPT
111+
EV_ERROR = C.EV_ERROR
112+
EVFILT_READ = C.EVFILT_READ
113+
EVFILT_WRITE = C.EVFILT_WRITE
104114
)
105115

106116
type Rtprio C.struct_rtprio
@@ -117,3 +127,5 @@ type Ucontext C.ucontext_t
117127
type Timespec C.struct_timespec
118128
type Timeval C.struct_timeval
119129
type Itimerval C.struct_itimerval
130+
131+
type Kevent C.struct_kevent

src/pkg/runtime/defs_freebsd_386.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44

55
enum {
6+
EINTR = 0x4,
7+
EFAULT = 0xe,
8+
69
PROT_NONE = 0x0,
710
PROT_READ = 0x1,
811
PROT_WRITE = 0x2,
@@ -21,8 +24,6 @@ enum {
2124
UMTX_OP_WAIT_UINT = 0xb,
2225
UMTX_OP_WAKE = 0x3,
2326

24-
EINTR = 0x4,
25-
2627
SIGHUP = 0x1,
2728
SIGINT = 0x2,
2829
SIGQUIT = 0x3,
@@ -74,6 +75,14 @@ enum {
7475
ITIMER_REAL = 0x0,
7576
ITIMER_VIRTUAL = 0x1,
7677
ITIMER_PROF = 0x2,
78+
79+
EV_ADD = 0x1,
80+
EV_DELETE = 0x2,
81+
EV_CLEAR = 0x20,
82+
EV_RECEIPT = 0x40,
83+
EV_ERROR = 0x4000,
84+
EVFILT_READ = -0x1,
85+
EVFILT_WRITE = -0x2,
7786
};
7887

7988
typedef struct Rtprio Rtprio;
@@ -87,6 +96,7 @@ typedef struct Ucontext Ucontext;
8796
typedef struct Timespec Timespec;
8897
typedef struct Timeval Timeval;
8998
typedef struct Itimerval Itimerval;
99+
typedef struct Kevent Kevent;
90100

91101
#pragma pack on
92102

@@ -157,11 +167,13 @@ struct Mcontext {
157167
int32 mc_len;
158168
int32 mc_fpformat;
159169
int32 mc_ownedfp;
160-
int32 mc_spare1[1];
170+
int32 mc_flags;
161171
int32 mc_fpstate[128];
162172
int32 mc_fsbase;
163173
int32 mc_gsbase;
164-
int32 mc_spare2[6];
174+
int32 mc_xfpustate;
175+
int32 mc_xfpustate_len;
176+
int32 mc_spare2[4];
165177
};
166178
struct Ucontext {
167179
Sigset uc_sigmask;
@@ -186,5 +198,14 @@ struct Itimerval {
186198
Timeval it_value;
187199
};
188200

201+
struct Kevent {
202+
uint32 ident;
203+
int16 filter;
204+
uint16 flags;
205+
uint32 fflags;
206+
int32 data;
207+
byte *udata;
208+
};
209+
189210

190211
#pragma pack off

src/pkg/runtime/defs_freebsd_amd64.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44

55
enum {
6+
EINTR = 0x4,
7+
EFAULT = 0xe,
8+
69
PROT_NONE = 0x0,
710
PROT_READ = 0x1,
811
PROT_WRITE = 0x2,
@@ -21,8 +24,6 @@ enum {
2124
UMTX_OP_WAIT_UINT = 0xb,
2225
UMTX_OP_WAKE = 0x3,
2326

24-
EINTR = 0x4,
25-
2627
SIGHUP = 0x1,
2728
SIGINT = 0x2,
2829
SIGQUIT = 0x3,
@@ -74,6 +75,14 @@ enum {
7475
ITIMER_REAL = 0x0,
7576
ITIMER_VIRTUAL = 0x1,
7677
ITIMER_PROF = 0x2,
78+
79+
EV_ADD = 0x1,
80+
EV_DELETE = 0x2,
81+
EV_CLEAR = 0x20,
82+
EV_RECEIPT = 0x40,
83+
EV_ERROR = 0x4000,
84+
EVFILT_READ = -0x1,
85+
EVFILT_WRITE = -0x2,
7786
};
7887

7988
typedef struct Rtprio Rtprio;
@@ -87,6 +96,7 @@ typedef struct Ucontext Ucontext;
8796
typedef struct Timespec Timespec;
8897
typedef struct Timeval Timeval;
8998
typedef struct Itimerval Itimerval;
99+
typedef struct Kevent Kevent;
90100

91101
#pragma pack on
92102

@@ -172,7 +182,9 @@ struct Mcontext {
172182
int64 mc_fpstate[64];
173183
int64 mc_fsbase;
174184
int64 mc_gsbase;
175-
int64 mc_spare[6];
185+
int64 mc_xfpustate;
186+
int64 mc_xfpustate_len;
187+
int64 mc_spare[4];
176188
};
177189
struct Ucontext {
178190
Sigset uc_sigmask;
@@ -197,5 +209,14 @@ struct Itimerval {
197209
Timeval it_value;
198210
};
199211

212+
struct Kevent {
213+
uint64 ident;
214+
int16 filter;
215+
uint16 flags;
216+
uint32 fflags;
217+
int64 data;
218+
byte *udata;
219+
};
220+
200221

201222
#pragma pack off

src/pkg/runtime/defs_openbsd.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package runtime
1515

1616
/*
1717
#include <sys/types.h>
18+
#include <sys/event.h>
1819
#include <sys/mman.h>
1920
#include <sys/time.h>
2021
#include <sys/unistd.h>
@@ -25,6 +26,9 @@ package runtime
2526
import "C"
2627

2728
const (
29+
EINTR = C.EINTR
30+
EFAULT = C.EFAULT
31+
2832
PROT_NONE = C.PROT_NONE
2933
PROT_READ = C.PROT_READ
3034
PROT_WRITE = C.PROT_WRITE
@@ -40,8 +44,6 @@ const (
4044
SA_RESTART = C.SA_RESTART
4145
SA_ONSTACK = C.SA_ONSTACK
4246

43-
EINTR = C.EINTR
44-
4547
SIGHUP = C.SIGHUP
4648
SIGINT = C.SIGINT
4749
SIGQUIT = C.SIGQUIT
@@ -93,6 +95,13 @@ const (
9395
ITIMER_REAL = C.ITIMER_REAL
9496
ITIMER_VIRTUAL = C.ITIMER_VIRTUAL
9597
ITIMER_PROF = C.ITIMER_PROF
98+
99+
EV_ADD = C.EV_ADD
100+
EV_DELETE = C.EV_DELETE
101+
EV_CLEAR = C.EV_CLEAR
102+
EV_ERROR = C.EV_ERROR
103+
EVFILT_READ = C.EVFILT_READ
104+
EVFILT_WRITE = C.EVFILT_WRITE
96105
)
97106

98107
type Tfork C.struct___tfork
@@ -108,3 +117,5 @@ type StackT C.stack_t
108117
type Timespec C.struct_timespec
109118
type Timeval C.struct_timeval
110119
type Itimerval C.struct_itimerval
120+
121+
type Kevent C.struct_kevent

src/pkg/runtime/defs_openbsd_386.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44

55
enum {
6+
EINTR = 0x4,
7+
EFAULT = 0xe,
8+
69
PROT_NONE = 0x0,
710
PROT_READ = 0x1,
811
PROT_WRITE = 0x2,
@@ -18,8 +21,6 @@ enum {
1821
SA_RESTART = 0x2,
1922
SA_ONSTACK = 0x1,
2023

21-
EINTR = 0x4,
22-
2324
SIGHUP = 0x1,
2425
SIGINT = 0x2,
2526
SIGQUIT = 0x3,
@@ -71,6 +72,13 @@ enum {
7172
ITIMER_REAL = 0x0,
7273
ITIMER_VIRTUAL = 0x1,
7374
ITIMER_PROF = 0x2,
75+
76+
EV_ADD = 0x1,
77+
EV_DELETE = 0x2,
78+
EV_CLEAR = 0x20,
79+
EV_ERROR = 0x4000,
80+
EVFILT_READ = -0x1,
81+
EVFILT_WRITE = -0x2,
7482
};
7583

7684
typedef struct Tfork Tfork;
@@ -81,6 +89,7 @@ typedef struct StackT StackT;
8189
typedef struct Timespec Timespec;
8290
typedef struct Timeval Timeval;
8391
typedef struct Itimerval Itimerval;
92+
typedef struct Kevent Kevent;
8493

8594
#pragma pack on
8695

@@ -146,5 +155,14 @@ struct Itimerval {
146155
Timeval it_value;
147156
};
148157

158+
struct Kevent {
159+
uint32 ident;
160+
int16 filter;
161+
uint16 flags;
162+
uint32 fflags;
163+
int32 data;
164+
byte *udata;
165+
};
166+
149167

150168
#pragma pack off

src/pkg/runtime/defs_openbsd_amd64.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44

55
enum {
6+
EINTR = 0x4,
7+
EFAULT = 0xe,
8+
69
PROT_NONE = 0x0,
710
PROT_READ = 0x1,
811
PROT_WRITE = 0x2,
@@ -18,8 +21,6 @@ enum {
1821
SA_RESTART = 0x2,
1922
SA_ONSTACK = 0x1,
2023

21-
EINTR = 0x4,
22-
2324
SIGHUP = 0x1,
2425
SIGINT = 0x2,
2526
SIGQUIT = 0x3,
@@ -71,6 +72,13 @@ enum {
7172
ITIMER_REAL = 0x0,
7273
ITIMER_VIRTUAL = 0x1,
7374
ITIMER_PROF = 0x2,
75+
76+
EV_ADD = 0x1,
77+
EV_DELETE = 0x2,
78+
EV_CLEAR = 0x20,
79+
EV_ERROR = 0x4000,
80+
EVFILT_READ = -0x1,
81+
EVFILT_WRITE = -0x2,
7482
};
7583

7684
typedef struct Tfork Tfork;
@@ -81,6 +89,7 @@ typedef struct StackT StackT;
8189
typedef struct Timespec Timespec;
8290
typedef struct Timeval Timeval;
8391
typedef struct Itimerval Itimerval;
92+
typedef struct Kevent Kevent;
8493

8594
#pragma pack on
8695

@@ -158,5 +167,14 @@ struct Itimerval {
158167
Timeval it_value;
159168
};
160169

170+
struct Kevent {
171+
uint32 ident;
172+
int16 filter;
173+
uint16 flags;
174+
uint32 fflags;
175+
int32 data;
176+
byte *udata;
177+
};
178+
161179

162180
#pragma pack off

src/pkg/runtime/sys_freebsd_386.s

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,33 @@ TEXT runtime·sigprocmask(SB),7,$16
345345
MOVL $0xf1, 0xf1 // crash
346346
RET
347347

348+
// int32 runtime·kqueue(void);
349+
TEXT runtime·kqueue(SB),7,$0
350+
MOVL $269, AX
351+
INT $0x80
352+
JAE 2(PC)
353+
NEGL AX
354+
RET
355+
356+
// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
357+
TEXT runtime·kevent(SB),7,$0
358+
MOVL $270, AX
359+
INT $0x80
360+
JAE 2(PC)
361+
NEGL AX
362+
RET
363+
364+
// int32 runtime·closeonexec(int32 fd);
365+
TEXT runtime·closeonexec(SB),7,$32
366+
MOVL $92, AX // fcntl
367+
// 0(SP) is where the caller PC would be; kernel skips it
368+
MOVL fd+0(FP), BX
369+
MOVL BX, 4(SP) // fd
370+
MOVL $2, 8(SP) // F_SETFD
371+
MOVL $1, 12(SP) // FD_CLOEXEC
372+
INT $0x80
373+
JAE 2(PC)
374+
NEGL AX
375+
RET
376+
348377
GLOBL runtime·tlsoffset(SB),$4

0 commit comments

Comments
 (0)