static struct posix_thread *tid_thread[TIDMAP_SIZE];
static unsigned long tid_map[UK_BITS_TO_LONGS(TIDMAP_SIZE)] = { [0] = 0x01UL };
+/* Process Table */
+struct posix_process *pid_process[TIDMAP_SIZE];
+
/**
* Thread-local posix_thread reference
*/
pprocess_release(orig_pprocess);
}
+ /* Add to process table */
+ if (unlikely((unsigned long)pprocess->pid >= ARRAY_SIZE(pid_process))) {
+ uk_pr_err("Process limit reached, could not create new process\n");
+ ret = -EAGAIN;
+ goto err_free_pprocess;
+ }
+
(*pthread)->parent = parent_pthread;
pprocess->parent = parent_pprocess;
uk_list_add_tail(&pprocess->child_list_entry,
&parent_pprocess->children);
}
+ pid_process[pprocess->pid] = pprocess;
uk_pr_debug("Process PID %d created (parent PID: %d)\n",
(int) pprocess->pid,
}
}
+ pid_process[pprocess->pid] = NULL;
+
uk_pr_debug("Process PID %d released\n",
pprocess->pid);
uk_free(pprocess->_a, pprocess);
UK_THREAD_INIT_PRIO(posix_thread_init, posix_thread_fini, UK_PRIO_EARLIEST);
+struct posix_process *pid2pprocess(pid_t pid)
+{
+ UK_ASSERT((__sz)pid < ARRAY_SIZE(pid_process));
+
+ return pid_process[pid];
+}
+
struct posix_thread *tid2pthread(pid_t tid)
{
if ((__sz)tid >= ARRAY_SIZE(tid_thread) || tid < 0)
/* TODO: Mutex */
};
+extern struct posix_process *pid_process[TIDMAP_SIZE];
+
+#define uk_pprocess_foreach(_p) \
+ for (int _j = 1, _i = 0; _i != ARRAY_SIZE(pid_process); \
+ _j = !_j, _i++) \
+ for ((_p) = pid_process[_i]; _j; _j = !_j) \
+ if ((_p))
+
+#define uk_pprocess_foreach_pthread(_proc, _pthread, _pthreadn) \
+ uk_list_for_each_entry_safe((_pthread), (_pthreadn), \
+ &(_proc)->threads, thread_list_entry)
+
#if CONFIG_LIBPOSIX_PROCESS_PIDS
+struct posix_process *pid2pprocess(pid_t pid);
struct uk_thread *tid2ukthread(pid_t tid);
struct posix_thread *tid2pthread(pid_t tid);
struct posix_process *tid2pprocess(pid_t tid);