MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vnet_data_alloc

Function vnet_data_alloc

freebsd/net/vnet.c:373–399  ·  view source on GitHub ↗

* When a module is loaded and requires storage for a virtualized global * variable, allocate space from the modspace free list. This interface * should be used only by the kernel linker. */

Source from the content-addressed store, hash-verified

371 * should be used only by the kernel linker.
372 */
373void *
374vnet_data_alloc(int size)
375{
376 struct vnet_data_free *df;
377 void *s;
378
379 s = NULL;
380 size = roundup2(size, sizeof(void *));
381 sx_xlock(&vnet_data_free_lock);
382 TAILQ_FOREACH(df, &vnet_data_free_head, vnd_link) {
383 if (df->vnd_len < size)
384 continue;
385 if (df->vnd_len == size) {
386 s = (void *)df->vnd_start;
387 TAILQ_REMOVE(&vnet_data_free_head, df, vnd_link);
388 free(df, M_VNET_DATA_FREE);
389 break;
390 }
391 s = (void *)df->vnd_start;
392 df->vnd_len -= size;
393 df->vnd_start = df->vnd_start + size;
394 break;
395 }
396 sx_xunlock(&vnet_data_free_lock);
397
398 return (s);
399}
400
401/*
402 * Free space for a virtualized global variable on module unload.

Callers 3

link_elf_link_preloadFunction · 0.85
ifFunction · 0.85
parse_vnetFunction · 0.85

Calls 1

freeFunction · 0.50

Tested by

no test coverage detected