Loading [MathJax]/extensions/tex2jax.js
CS350 COS
COS
All Data Structures Files Functions Variables Typedefs Macros
handle.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include <sys/kassert.h>
#include <sys/queue.h>
#include <sys/kmem.h>
#include <sys/handle.h>
#include <sys/thread.h>
#include <sys/syscall.h>
Include dependency graph for handle.c:

Go to the source code of this file.

Functions

void Handle_GlobalInit ()
 
 DEFINE_SLAB (Handle, &handleSlab)
 
void Handle_Init (Process *proc)
 
void Handle_Destroy (Process *proc)
 
uint64_t Handle_Add (Process *proc, Handle *handle)
 
void Handle_Remove (Process *proc, Handle *handle)
 
HandleHandle_Lookup (Process *proc, uint64_t fd)
 

Variables

Slab handleSlab
 

Function Documentation

◆ DEFINE_SLAB()

DEFINE_SLAB ( Handle  ,
handleSlab 
)

◆ Handle_Add()

uint64_t Handle_Add ( Process proc,
Handle handle 
)

Definition at line 47 of file handle.c.

48{
49 int slot;
50
51 handle->fd = proc->nextFD;
52 proc->nextFD++;
53 handle->processId = proc->pid;
54
55 slot = handle->fd % PROCESS_HANDLE_SLOTS;
56
57 TAILQ_INSERT_HEAD(&proc->handles[slot], handle, handleList);
58
59 return handle->fd;
60}
#define PROCESS_HANDLE_SLOTS
Definition: thread.h:58
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:628
uint64_t fd
Definition: handle.h:18
uint64_t processId
Definition: handle.h:20
uint64_t nextFD
Definition: thread.h:91
HandleQueue handles[PROCESS_HANDLE_SLOTS]
Definition: thread.h:92
uint64_t pid
Definition: thread.h:66
Here is the caller graph for this function:

◆ Handle_Destroy()

void Handle_Destroy ( Process proc)

Definition at line 33 of file handle.c.

34{
35 int i;
36 Handle *handle, *handle_tmp;
37
38 for (i = 0; i < PROCESS_HANDLE_SLOTS; i++) {
39 TAILQ_FOREACH_SAFE(handle, &proc->handles[i], handleList, handle_tmp) {
40 TAILQ_REMOVE(&proc->handles[i], handle, handleList);
41 (handle->close)(handle);
42 }
43 }
44}
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:567
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:659
Definition: handle.h:17
int(* close)(Handle *)
Definition: handle.h:26
Here is the caller graph for this function:

◆ Handle_GlobalInit()

void Handle_GlobalInit ( )

Definition at line 15 of file handle.c.

16{
17 Slab_Init(&handleSlab, "Handle Objects", sizeof(Handle), 16);
18}
Slab handleSlab
Definition: handle.c:12
void Slab_Init(Slab *slab, const char *name, uintptr_t objsz, uintptr_t align)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Handle_Init()

void Handle_Init ( Process proc)

Definition at line 23 of file handle.c.

24{
25 int i;
26
27 for (i = 0; i < PROCESS_HANDLE_SLOTS; i++) {
28 TAILQ_INIT(&proc->handles[i]);
29 }
30}
#define TAILQ_INIT(head)
Definition: queue.h:597
Here is the caller graph for this function:

◆ Handle_Lookup()

Handle * Handle_Lookup ( Process proc,
uint64_t  fd 
)

Definition at line 71 of file handle.c.

72{
73 int slot = fd % PROCESS_HANDLE_SLOTS;
74 Handle *handle;
75
76 TAILQ_FOREACH(handle, &proc->handles[slot], handleList) {
77 if (handle->fd == fd)
78 return handle;
79 }
80
81 return NULL;
82}
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:557
#define NULL
Definition: stddef.h:6
Here is the caller graph for this function:

◆ Handle_Remove()

void Handle_Remove ( Process proc,
Handle handle 
)

Definition at line 63 of file handle.c.

64{
65 int slot = handle->fd % PROCESS_HANDLE_SLOTS;
66
67 TAILQ_REMOVE(&proc->handles[slot], handle, handleList);
68}

Variable Documentation

◆ handleSlab

Slab handleSlab

Definition at line 12 of file handle.c.