#ifndef _KERNEL_PROC_RESOURCE_H
#define _KERNEL_PROC_RESOURCE_H

#include <libk/rbtree.h>
#include <libk/std.h>
#include <sync/spin_lock.h>

#define PR_MEM 0

#define RV_PRIVATE 0
#define RV_PUBLIC  1

struct proc;

struct proc_resource_mem {
  uintptr_t paddr;
  size_t pages;
};

struct proc_resource_mem_init {
  size_t pages;
};

struct proc_resource {
  int type;
  int rid;
  int visibility;
  spin_lock_t lock;
  atomic_int refs;
  struct rb_node_link proc_resource_tree_link;
  union {
    struct proc_resource_mem mem;
  } u;
  struct {
    void (*cleanup) (struct proc_resource* resource);
  } ops;
};

struct proc_resource* proc_create_resource (struct proc* proc, int rid, int type, int vis,
                                            void* data);
void proc_drop_resource (struct proc* proc, struct proc_resource* resource);
void proc_cleanup_resources (struct proc* proc);

#endif // _KERNEL_PROC_RESOURCE_H
