MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / alloc_chunk

Function alloc_chunk

src/hx/cppia/sljit_src/sljitProtExecAllocator.c:168–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166}
167
168static SLJIT_INLINE struct chunk_header* alloc_chunk(sljit_uw size)
169{
170 struct chunk_header *retval;
171 int fd;
172
173 fd = create_tempfile();
174 if (fd == -1)
175 return NULL;
176
177 if (ftruncate(fd, size)) {
178 close(fd);
179 return NULL;
180 }
181
182 retval = (struct chunk_header *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
183
184 if (retval == MAP_FAILED) {
185 close(fd);
186 return NULL;
187 }
188
189 retval->executable = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_SHARED, fd, 0);
190
191 if (retval->executable == MAP_FAILED) {
192 munmap(retval, size);
193 close(fd);
194 return NULL;
195 }
196
197 retval->fd = fd;
198 return retval;
199}
200
201static SLJIT_INLINE void free_chunk(void *chunk, sljit_uw size)
202{

Callers 1

sljit_malloc_execFunction · 0.70

Calls 2

create_tempfileFunction · 0.85
closeFunction · 0.85

Tested by

no test coverage detected