@@ -18,11 +18,9 @@ type vfsShmFile struct {
18
18
* os.File
19
19
info os.FileInfo
20
20
21
- // +checklocks:vfsShmFilesMtx
22
- refs int
21
+ refs int // +checklocks:vfsShmFilesMtx
23
22
24
- // +checklocks:Mutex
25
- lock [_SHM_NLOCK ]int16
23
+ lock [_SHM_NLOCK ]int16 // +checklocks:Mutex
26
24
sync.Mutex
27
25
}
28
26
34
32
35
33
type vfsShm struct {
36
34
* vfsShmFile
37
- path string
38
- lock [_SHM_NLOCK ]bool
39
- regions []* util.MappedRegion
40
- readOnly bool
35
+ path string
36
+ lock [_SHM_NLOCK ]bool
37
+ regions []* util.MappedRegion
41
38
}
42
39
43
40
func (s * vfsShm ) Close () error {
@@ -69,7 +66,7 @@ func (s *vfsShm) Close() error {
69
66
panic (util .AssertErr ())
70
67
}
71
68
72
- func (s * vfsShm ) shmOpen () ( rc _ErrorCode ) {
69
+ func (s * vfsShm ) shmOpen () _ErrorCode {
73
70
if s .vfsShmFile != nil {
74
71
return _OK
75
72
}
@@ -100,17 +97,13 @@ func (s *vfsShm) shmOpen() (rc _ErrorCode) {
100
97
}
101
98
}
102
99
103
- // Lock and truncate the file, if not readonly .
100
+ // Lock and truncate the file.
104
101
// The lock is only released by closing the file.
105
- if s .readOnly {
106
- rc = _READONLY_CANTINIT
107
- } else {
108
- if rc := osLock (f , unix .LOCK_EX | unix .LOCK_NB , _IOERR_LOCK ); rc != _OK {
109
- return rc
110
- }
111
- if err := f .Truncate (0 ); err != nil {
112
- return _IOERR_SHMOPEN
113
- }
102
+ if rc := osLock (f , unix .LOCK_EX | unix .LOCK_NB , _IOERR_LOCK ); rc != _OK {
103
+ return rc
104
+ }
105
+ if err := f .Truncate (0 ); err != nil {
106
+ return _IOERR_SHMOPEN
114
107
}
115
108
116
109
// Add the new shared file.
@@ -122,11 +115,11 @@ func (s *vfsShm) shmOpen() (rc _ErrorCode) {
122
115
for i , g := range vfsShmFiles {
123
116
if g == nil {
124
117
vfsShmFiles [i ] = s .vfsShmFile
125
- return rc
118
+ return _OK
126
119
}
127
120
}
128
121
vfsShmFiles = append (vfsShmFiles , s .vfsShmFile )
129
- return rc
122
+ return _OK
130
123
}
131
124
132
125
func (s * vfsShm ) shmMap (ctx context.Context , mod api.Module , id , size int32 , extend bool ) (uint32 , _ErrorCode ) {
@@ -148,25 +141,17 @@ func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, ext
148
141
if ! extend {
149
142
return 0 , _OK
150
143
}
151
- if s . readOnly || osAllocate (s .File , n ) != nil {
144
+ if osAllocate (s .File , n ) != nil {
152
145
return 0 , _IOERR_SHMSIZE
153
146
}
154
147
}
155
148
156
- var prot int
157
- if s .readOnly {
158
- prot = unix .PROT_READ
159
- } else {
160
- prot = unix .PROT_READ | unix .PROT_WRITE
161
- }
162
- r , err := util .MapRegion (ctx , mod , s .File , int64 (id )* int64 (size ), size , prot )
149
+ r , err := util .MapRegion (ctx , mod , s .File , int64 (id )* int64 (size ), size ,
150
+ unix .PROT_READ | unix .PROT_WRITE )
163
151
if err != nil {
164
152
return 0 , _IOERR_SHMMAP
165
153
}
166
154
s .regions = append (s .regions , r )
167
- if s .readOnly {
168
- return r .Ptr , _READONLY
169
- }
170
155
return r .Ptr , _OK
171
156
}
172
157
0 commit comments