mirror of
https://github.com/clearlinux/graphene.git
synced 2026-09-06 22:01:29 +00:00
Cleanup and uppercase list.h macros
This commit is contained in:
@@ -70,7 +70,7 @@ void dump_threads (void)
|
||||
struct shim_thread * tmp;
|
||||
|
||||
lock(&thread_list_lock);
|
||||
listp_for_each_entry(tmp, &thread_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &thread_list, list) {
|
||||
debug("thread %d, vmid = %d, pgid = %d, ppid = %d, tgid = %d, in_vm = %d\n",
|
||||
tmp->tid, tmp->vmid, tmp->pgid, tmp->ppid, tmp->tgid, tmp->in_vm);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ struct shim_thread * __lookup_thread (IDTYPE tid)
|
||||
{
|
||||
struct shim_thread * tmp;
|
||||
|
||||
listp_for_each_entry(tmp, &thread_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &thread_list, list) {
|
||||
if (tmp->tid == tid) {
|
||||
get_thread(tmp);
|
||||
return tmp;
|
||||
@@ -265,7 +265,7 @@ struct shim_simple_thread * __lookup_simple_thread (IDTYPE tid)
|
||||
{
|
||||
struct shim_simple_thread * tmp;
|
||||
|
||||
listp_for_each_entry(tmp, &simple_thread_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &simple_thread_list, list) {
|
||||
if (tmp->tid == tid) {
|
||||
get_simple_thread(tmp);
|
||||
return tmp;
|
||||
@@ -357,7 +357,7 @@ void put_simple_thread (struct shim_simple_thread * thread)
|
||||
|
||||
if (!ref_count) {
|
||||
/* Simple threads always live on the simple thread list */
|
||||
listp_del(thread, &simple_thread_list, list);
|
||||
LISTP_DEL(thread, &simple_thread_list, list);
|
||||
if (thread->exit_event)
|
||||
DkObjectClose(thread->exit_event);
|
||||
destroy_lock(&thread->lock);
|
||||
@@ -379,7 +379,7 @@ void set_as_child (struct shim_thread * parent,
|
||||
child->parent = parent;
|
||||
|
||||
lock(&parent->lock);
|
||||
listp_add_tail(child, &parent->children, siblings);
|
||||
LISTP_ADD_TAIL(child, &parent->children, siblings);
|
||||
unlock(&parent->lock);
|
||||
|
||||
unlock(&child->lock);
|
||||
@@ -387,14 +387,14 @@ void set_as_child (struct shim_thread * parent,
|
||||
|
||||
void add_thread (struct shim_thread * thread)
|
||||
{
|
||||
if (is_internal(thread) || !list_empty(thread, list))
|
||||
if (is_internal(thread) || !LIST_EMPTY(thread, list))
|
||||
return;
|
||||
|
||||
struct shim_thread * tmp, * prev = NULL;
|
||||
lock(&thread_list_lock);
|
||||
|
||||
/* keep it sorted */
|
||||
listp_for_each_entry_reverse(tmp, &thread_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY_REVERSE(tmp, &thread_list, list) {
|
||||
if (tmp->tid == thread->tid) {
|
||||
unlock(&thread_list_lock);
|
||||
return;
|
||||
@@ -406,7 +406,7 @@ void add_thread (struct shim_thread * thread)
|
||||
}
|
||||
|
||||
get_thread(thread);
|
||||
listp_add_after(thread, prev, &thread_list, list);
|
||||
LISTP_ADD_AFTER(thread, prev, &thread_list, list);
|
||||
unlock(&thread_list_lock);
|
||||
}
|
||||
|
||||
@@ -415,28 +415,28 @@ void del_thread (struct shim_thread * thread)
|
||||
debug("del_thread(%p, %d, %ld)\n", thread, thread ? thread->tid : -1,
|
||||
atomic_read(&thread->ref_count));
|
||||
|
||||
if (is_internal(thread) || list_empty(thread, list)) {
|
||||
if (is_internal(thread) || LIST_EMPTY(thread, list)) {
|
||||
debug("del_thread: internal\n");
|
||||
return;
|
||||
}
|
||||
|
||||
lock(&thread_list_lock);
|
||||
/* thread->list goes on the thread_list */
|
||||
listp_del_init(thread, &thread_list, list);
|
||||
LISTP_DEL_INIT(thread, &thread_list, list);
|
||||
unlock(&thread_list_lock);
|
||||
put_thread(thread);
|
||||
}
|
||||
|
||||
void add_simple_thread (struct shim_simple_thread * thread)
|
||||
{
|
||||
if (!list_empty(thread, list))
|
||||
if (!LIST_EMPTY(thread, list))
|
||||
return;
|
||||
|
||||
struct shim_simple_thread * tmp, * prev = NULL;
|
||||
lock(&thread_list_lock);
|
||||
|
||||
/* keep it sorted */
|
||||
listp_for_each_entry_reverse(tmp, &simple_thread_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY_REVERSE(tmp, &simple_thread_list, list) {
|
||||
if (tmp->tid == thread->tid) {
|
||||
unlock(&thread_list_lock);
|
||||
return;
|
||||
@@ -448,17 +448,17 @@ void add_simple_thread (struct shim_simple_thread * thread)
|
||||
}
|
||||
|
||||
get_simple_thread(thread);
|
||||
listp_add_after(thread, prev, &simple_thread_list, list);
|
||||
LISTP_ADD_AFTER(thread, prev, &simple_thread_list, list);
|
||||
unlock(&thread_list_lock);
|
||||
}
|
||||
|
||||
void del_simple_thread (struct shim_simple_thread * thread)
|
||||
{
|
||||
if (list_empty(thread, list))
|
||||
if (LIST_EMPTY(thread, list))
|
||||
return;
|
||||
|
||||
lock(&thread_list_lock);
|
||||
listp_del_init(thread, &simple_thread_list, list);
|
||||
LISTP_DEL_INIT(thread, &simple_thread_list, list);
|
||||
unlock(&thread_list_lock);
|
||||
put_simple_thread(thread);
|
||||
}
|
||||
@@ -471,7 +471,7 @@ int check_last_thread (struct shim_thread * self)
|
||||
/* find out if there is any thread that is
|
||||
1) no current thread 2) in current vm
|
||||
3) still alive */
|
||||
listp_for_each_entry(tmp, &thread_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &thread_list, list) {
|
||||
if (tmp->tid &&
|
||||
(!self || tmp->tid != self->tid) && tmp->in_vm && tmp->is_alive) {
|
||||
debug("check_last_thread: thread %d is alive\n", tmp->tid);
|
||||
@@ -498,7 +498,7 @@ relock:
|
||||
|
||||
debug("walk_thread_list(callback=%p)\n", callback);
|
||||
|
||||
listp_for_each_entry_safe(tmp, n, &thread_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &thread_list, list) {
|
||||
if (tmp->tid <= min_tid)
|
||||
continue;
|
||||
|
||||
@@ -537,7 +537,7 @@ int walk_simple_thread_list (int (*callback) (struct shim_simple_thread *,
|
||||
relock:
|
||||
lock(&thread_list_lock);
|
||||
|
||||
listp_for_each_entry_safe(tmp, n, &simple_thread_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &simple_thread_list, list) {
|
||||
if (tmp->tid <= min_tid)
|
||||
continue;
|
||||
bool unlocked = false;
|
||||
@@ -792,7 +792,7 @@ BEGIN_CP_FUNC(all_running_threads)
|
||||
struct shim_thread * thread;
|
||||
lock(&thread_list_lock);
|
||||
|
||||
listp_for_each_entry(thread, &thread_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(thread, &thread_list, list) {
|
||||
if (!thread->in_vm || !thread->is_alive)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ static inline void __assert_vma_list (void)
|
||||
struct shim_vma * tmp;
|
||||
struct shim_vma * prev __attribute__((unused)) = NULL;
|
||||
|
||||
listp_for_each_entry(tmp, &vma_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &vma_list, list) {
|
||||
/* Assert we are really sorted */
|
||||
assert(tmp->end > tmp->start);
|
||||
assert(!prev || prev->end <= tmp->start);
|
||||
@@ -202,7 +202,7 @@ __lookup_vma (void * addr, struct shim_vma ** pprev)
|
||||
{
|
||||
struct shim_vma * vma, * prev = NULL;
|
||||
|
||||
listp_for_each_entry(vma, &vma_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(vma, &vma_list, list) {
|
||||
if (addr < vma->start)
|
||||
goto none;
|
||||
if (test_vma_contain(vma, addr, addr + 1))
|
||||
@@ -233,15 +233,15 @@ __insert_vma (struct shim_vma * vma, struct shim_vma * prev)
|
||||
|
||||
/* check the next entry */
|
||||
struct shim_vma * next = prev ?
|
||||
listp_next_entry(prev, &vma_list, list) :
|
||||
listp_first_entry(&vma_list, struct shim_vma, list);
|
||||
LISTP_NEXT_ENTRY(prev, &vma_list, list) :
|
||||
LISTP_FIRST_ENTRY(&vma_list, struct shim_vma, list);
|
||||
|
||||
assert(!next || vma->end <= next->start);
|
||||
|
||||
if (prev)
|
||||
listp_add_after(vma, prev, &vma_list, list);
|
||||
LISTP_ADD_AFTER(vma, prev, &vma_list, list);
|
||||
else
|
||||
listp_add(vma, &vma_list, list);
|
||||
LISTP_ADD(vma, &vma_list, list);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -253,7 +253,7 @@ static inline void
|
||||
__remove_vma (struct shim_vma * vma, struct shim_vma * prev)
|
||||
{
|
||||
assert(vma != prev);
|
||||
listp_del(vma, &vma_list, list);
|
||||
LISTP_DEL(vma, &vma_list, list);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -321,7 +321,7 @@ int init_vma (void)
|
||||
struct shim_vma * new = get_mem_obj_from_mgr(vma_mgr);
|
||||
assert(new);
|
||||
struct shim_vma * e = &early_vmas[i];
|
||||
struct shim_vma * prev = listp_prev_entry(e, &vma_list, list);
|
||||
struct shim_vma * prev = LISTP_PREV_ENTRY(e, &vma_list, list);
|
||||
debug("Converting early VMA [%p] %p-%p\n", e, e->start, e->end);
|
||||
memcpy(new, e, sizeof(*e));
|
||||
INIT_LIST_HEAD(new, list);
|
||||
@@ -612,14 +612,14 @@ static int __bkeep_munmap (struct shim_vma ** pprev,
|
||||
struct shim_vma * cur, * next;
|
||||
|
||||
if (!prev) {
|
||||
cur = listp_first_entry(&vma_list, struct shim_vma, list);
|
||||
cur = LISTP_FIRST_ENTRY(&vma_list, struct shim_vma, list);
|
||||
if (!cur)
|
||||
return 0;
|
||||
} else {
|
||||
cur = listp_next_entry(prev, &vma_list, list);
|
||||
cur = LISTP_NEXT_ENTRY(prev, &vma_list, list);
|
||||
}
|
||||
|
||||
next = cur ? listp_next_entry(cur, &vma_list, list) : NULL;
|
||||
next = cur ? LISTP_NEXT_ENTRY(cur, &vma_list, list) : NULL;
|
||||
|
||||
while (cur) {
|
||||
struct shim_vma * tail = NULL;
|
||||
@@ -659,13 +659,13 @@ static int __bkeep_munmap (struct shim_vma ** pprev,
|
||||
|
||||
cont:
|
||||
cur = next;
|
||||
next = cur ? listp_next_entry(cur, &vma_list, list) : NULL;
|
||||
next = cur ? LISTP_NEXT_ENTRY(cur, &vma_list, list) : NULL;
|
||||
}
|
||||
|
||||
if (prev)
|
||||
assert(cur == listp_next_entry(prev, &vma_list, list));
|
||||
assert(cur == LISTP_NEXT_ENTRY(prev, &vma_list, list));
|
||||
else
|
||||
assert(cur == listp_first_entry(&vma_list, struct shim_vma, list));
|
||||
assert(cur == LISTP_FIRST_ENTRY(&vma_list, struct shim_vma, list));
|
||||
|
||||
assert(!prev || prev->end <= start);
|
||||
assert(!cur || end <= cur->start);
|
||||
@@ -706,14 +706,14 @@ static int __bkeep_mprotect (struct shim_vma * prev,
|
||||
struct shim_vma * cur, * next;
|
||||
|
||||
if (!prev) {
|
||||
cur = listp_first_entry(&vma_list, struct shim_vma, list);
|
||||
cur = LISTP_FIRST_ENTRY(&vma_list, struct shim_vma, list);
|
||||
if (!cur)
|
||||
return 0;
|
||||
} else {
|
||||
cur = listp_next_entry(prev, &vma_list, list);
|
||||
cur = LISTP_NEXT_ENTRY(prev, &vma_list, list);
|
||||
}
|
||||
|
||||
next = cur ? listp_next_entry(cur, &vma_list, list) : NULL;
|
||||
next = cur ? LISTP_NEXT_ENTRY(cur, &vma_list, list) : NULL;
|
||||
|
||||
while (cur) {
|
||||
struct shim_vma * new, * tail = NULL;
|
||||
@@ -778,7 +778,7 @@ static int __bkeep_mprotect (struct shim_vma * prev,
|
||||
cont:
|
||||
prev = cur;
|
||||
cur = next;
|
||||
next = cur ? listp_next_entry(cur, &vma_list, list) : NULL;
|
||||
next = cur ? LISTP_NEXT_ENTRY(cur, &vma_list, list) : NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -845,7 +845,7 @@ static void * __bkeep_unmapped (void * top_addr, void * bottom_addr,
|
||||
break;
|
||||
|
||||
cur = prev;
|
||||
prev = listp_prev_entry(cur, &vma_list, list);
|
||||
prev = LISTP_PREV_ENTRY(cur, &vma_list, list);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -970,7 +970,7 @@ int lookup_overlap_vma (void * addr, uint64_t length,
|
||||
|
||||
lock(&vma_list_lock);
|
||||
|
||||
listp_for_each_entry(tmp, &vma_list, list)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &vma_list, list)
|
||||
if (test_vma_overlap (tmp, addr, addr + length)) {
|
||||
vma = tmp;
|
||||
break;
|
||||
@@ -994,7 +994,7 @@ bool is_in_one_vma (void * addr, size_t length)
|
||||
struct shim_vma* vma;
|
||||
|
||||
lock(&vma_list_lock);
|
||||
listp_for_each_entry(vma, &vma_list, list)
|
||||
LISTP_FOR_EACH_ENTRY(vma, &vma_list, list)
|
||||
if (test_vma_contain(vma, addr, addr + length)) {
|
||||
unlock(&vma_list_lock);
|
||||
return true;
|
||||
@@ -1011,7 +1011,7 @@ int dump_all_vmas (struct shim_vma_val * vmas, size_t max_count)
|
||||
int cnt = 0;
|
||||
lock(&vma_list_lock);
|
||||
|
||||
listp_for_each_entry(vma, &vma_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(vma, &vma_list, list) {
|
||||
if (VMA_TYPE(vma->flags))
|
||||
continue;
|
||||
if (vma->flags & VMA_UNMAPPED)
|
||||
@@ -1260,7 +1260,7 @@ void debug_print_vma_list (void)
|
||||
SYS_PRINTF("vma bookkeeping:\n");
|
||||
|
||||
struct shim_vma * vma;
|
||||
listp_for_each_entry(vma, &vma_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(vma, &vma_list, list) {
|
||||
const char * type = "", * name = "";
|
||||
|
||||
if (vma->file) {
|
||||
|
||||
@@ -138,7 +138,7 @@ void put_dentry (struct shim_dentry * dent) {
|
||||
debug("XXX Churn Warning: Freeing dentry %p; may not be expected\n", dent);
|
||||
// Add some assertions that the dentry is properly cleaned up, like it
|
||||
// isn't on a parent's children list
|
||||
assert(list_empty(dent, siblings));
|
||||
assert(LIST_EMPTY(dent, siblings));
|
||||
free_dentry(dent);
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ struct shim_dentry * get_new_dentry (struct shim_mount *mount,
|
||||
// Increment both dentries' ref counts once they are linked
|
||||
get_dentry(parent);
|
||||
get_dentry(dent);
|
||||
listp_add_tail(dent, &parent->children, siblings);
|
||||
LISTP_ADD_TAIL(dent, &parent->children, siblings);
|
||||
dent->parent = parent;
|
||||
parent->nchildren++;
|
||||
|
||||
@@ -255,7 +255,7 @@ __lookup_dcache (struct shim_dentry * start, const char * name, int namelen,
|
||||
goto out;
|
||||
}
|
||||
|
||||
listp_for_each_entry(dent, &start->children, siblings) {
|
||||
LISTP_FOR_EACH_ENTRY(dent, &start->children, siblings) {
|
||||
/* DEP 6/20/XX: The old code skipped mountpoints; I don't see any good
|
||||
* reason for mount point lookup to fail, at least in this code.
|
||||
* Keeping a note just in case. That is why you always leave a note.
|
||||
@@ -305,12 +305,12 @@ out:
|
||||
int __del_dentry_tree(struct shim_dentry * root) {
|
||||
struct shim_dentry *cursor, *n;
|
||||
|
||||
listp_for_each_entry_safe(cursor, n, &root->children, siblings) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(cursor, n, &root->children, siblings) {
|
||||
// Recur if this is a non-empty directory
|
||||
if (!listp_empty(&cursor->children))
|
||||
if (!LISTP_EMPTY(&cursor->children))
|
||||
__del_dentry_tree(cursor);
|
||||
|
||||
listp_del_init(cursor, &root->children, siblings);
|
||||
LISTP_DEL_INIT(cursor, &root->children, siblings);
|
||||
cursor->parent = NULL;
|
||||
root->nchildren--;
|
||||
// Clear the hashed flag, in case there is any vestigial code based
|
||||
@@ -389,7 +389,7 @@ BEGIN_RS_FUNC(dentry)
|
||||
if (dent->parent) {
|
||||
get_dentry(dent->parent);
|
||||
get_dentry(dent);
|
||||
listp_add_tail(dent, &dent->parent->children, siblings);
|
||||
LISTP_ADD_TAIL(dent, &dent->parent->children, siblings);
|
||||
}
|
||||
|
||||
DEBUG_RS("hash=%08lx,path=%s,fs=%s", dent->rel_path.hash,
|
||||
|
||||
@@ -327,7 +327,7 @@ int __mount_fs (struct shim_mount * mount, struct shim_dentry * dent)
|
||||
|
||||
lock(&mount_list_lock);
|
||||
get_mount(mount);
|
||||
listp_add_tail(mount, &mount_list, list);
|
||||
LISTP_ADD_TAIL(mount, &mount_list, list);
|
||||
unlock(&mount_list_lock);
|
||||
|
||||
do {
|
||||
@@ -513,7 +513,7 @@ int walk_mounts (int (*walk) (struct shim_mount * mount, void * arg),
|
||||
|
||||
lock(&mount_list_lock);
|
||||
|
||||
listp_for_each_entry_safe(mount, n, &mount_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(mount, n, &mount_list, list) {
|
||||
if ((ret = (*walk) (mount, arg)) < 0)
|
||||
break;
|
||||
|
||||
@@ -531,7 +531,7 @@ struct shim_mount * find_mount_from_uri (const char * uri)
|
||||
int longest_path = 0;
|
||||
|
||||
lock(&mount_list_lock);
|
||||
listp_for_each_entry(mount, &mount_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(mount, &mount_list, list) {
|
||||
if (qstrempty(&mount->uri))
|
||||
continue;
|
||||
|
||||
@@ -630,7 +630,7 @@ BEGIN_RS_FUNC(mount)
|
||||
mount->fs_ops = fs->fs_ops;
|
||||
mount->d_ops = fs->d_ops;
|
||||
|
||||
listp_add_tail(mount, &mount_list, list);
|
||||
LISTP_ADD_TAIL(mount, &mount_list, list);
|
||||
|
||||
if (!qstrempty(&mount->path)) {
|
||||
DEBUG_RS("type=%s,uri=%s,path=%s", mount->type, qstrgetstr(&mount->uri),
|
||||
@@ -645,7 +645,7 @@ BEGIN_CP_FUNC(all_mounts)
|
||||
{
|
||||
struct shim_mount * mount;
|
||||
lock(&mount_list_lock);
|
||||
listp_for_each_entry(mount, &mount_list, list)
|
||||
LISTP_FOR_EACH_ENTRY(mount, &mount_list, list)
|
||||
DO_CP(mount, mount, NULL);
|
||||
unlock(&mount_list_lock);
|
||||
|
||||
|
||||
@@ -781,7 +781,7 @@ int list_directory_handle (struct shim_dentry * dent, struct shim_handle * hdl)
|
||||
return -ENOMEM;
|
||||
|
||||
lock(&dcache_lock);
|
||||
listp_for_each_entry(child, &dent->children, siblings) {
|
||||
LISTP_FOR_EACH_ENTRY(child, &dent->children, siblings) {
|
||||
if (count >= nchildren)
|
||||
break;
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ lookup_and_alloc_client (IDTYPE vmid, const char * uri)
|
||||
assert(vmid);
|
||||
|
||||
lock(&ipc_info_lock);
|
||||
listp_for_each_entry(p, head, hlist)
|
||||
LISTP_FOR_EACH_ENTRY(p, head, hlist)
|
||||
if (p->vmid == vmid && !qstrcmpstr(&p->uri, uri, len)) {
|
||||
get_ipc_info(p);
|
||||
unlock(&ipc_info_lock);
|
||||
@@ -206,7 +206,7 @@ lookup_and_alloc_client (IDTYPE vmid, const char * uri)
|
||||
|
||||
p = __get_new_ipc_info(vmid, uri, len);
|
||||
if (p) {
|
||||
listp_add(p, head, hlist);
|
||||
LISTP_ADD(p, head, hlist);
|
||||
get_ipc_info(p);
|
||||
}
|
||||
unlock(&ipc_info_lock);
|
||||
@@ -220,7 +220,7 @@ void put_client (struct shim_ipc_info * info)
|
||||
LISTP_TYPE(shim_ipc_info) *head = client_table + CLIENT_HASH(info->vmid);
|
||||
__put_ipc_info(info);
|
||||
if (REF_GET(info->ref_count) == 1) {
|
||||
listp_del_init(info, head, hlist);
|
||||
LISTP_DEL_INIT(info, head, hlist);
|
||||
__put_ipc_info(info);
|
||||
}
|
||||
unlock(&ipc_info_lock);
|
||||
@@ -235,7 +235,7 @@ struct shim_ipc_info * discover_client (struct shim_ipc_port * port,
|
||||
assert(vmid);
|
||||
|
||||
lock(&ipc_info_lock);
|
||||
listp_for_each_entry(p, head, hlist)
|
||||
LISTP_FOR_EACH_ENTRY(p, head, hlist)
|
||||
if (p->vmid == vmid && !qstrempty(&p->uri)) {
|
||||
__get_ipc_info(p);
|
||||
unlock(&ipc_info_lock);
|
||||
@@ -389,8 +389,8 @@ int close_ipc_message_duplex (struct shim_ipc_msg_obj * msg,
|
||||
// Check if the message is pending on the port for response. If so,
|
||||
// remove the message from the list.
|
||||
lock(&port->msgs_lock);
|
||||
if (!list_empty(msg, list))
|
||||
listp_del_init(msg, &port->msgs, list);
|
||||
if (!LIST_EMPTY(msg, list))
|
||||
LISTP_DEL_INIT(msg, &port->msgs, list);
|
||||
unlock(&port->msgs_lock);
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ int send_ipc_message_duplex (struct shim_ipc_msg_obj * msg,
|
||||
if (save) {
|
||||
lock(&port->msgs_lock);
|
||||
msg->private = private_data;
|
||||
listp_add_tail(msg, &port->msgs, list);
|
||||
LISTP_ADD_TAIL(msg, &port->msgs, list);
|
||||
unlock(&port->msgs_lock);
|
||||
}
|
||||
|
||||
@@ -434,10 +434,10 @@ struct shim_ipc_msg_obj * find_ipc_msg_duplex (struct shim_ipc_port * port,
|
||||
{
|
||||
struct shim_ipc_msg_obj * tmp, * found = NULL;
|
||||
lock(&port->msgs_lock);
|
||||
listp_for_each_entry(tmp, &port->msgs, list)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &port->msgs, list)
|
||||
if (tmp->msg.seq == seq) {
|
||||
found = tmp;
|
||||
listp_del_init(tmp, &port->msgs, list);
|
||||
LISTP_DEL_INIT(tmp, &port->msgs, list);
|
||||
break;
|
||||
}
|
||||
unlock(&port->msgs_lock);
|
||||
|
||||
@@ -246,10 +246,10 @@ static bool __add_ipc_port (struct shim_ipc_port * port, IDTYPE vmid,
|
||||
port->update = true;
|
||||
}
|
||||
|
||||
if (port->info.vmid && list_empty(port, hlist)) {
|
||||
if (port->info.vmid && LIST_EMPTY(port, hlist)) {
|
||||
LISTP_TYPE(shim_ipc_port) * head = &ipc_port_pool[PID_HASH(vmid)];
|
||||
__get_ipc_port(port);
|
||||
listp_add(port, head, hlist);
|
||||
LISTP_ADD(port, head, hlist);
|
||||
}
|
||||
|
||||
if (!(port->info.type & IPC_PORT_IFPOLL) && (type & IPC_PORT_IFPOLL))
|
||||
@@ -271,22 +271,22 @@ static bool __add_ipc_port (struct shim_ipc_port * port, IDTYPE vmid,
|
||||
}
|
||||
|
||||
if (need_restart) {
|
||||
if (list_empty(port, list)) {
|
||||
if (LIST_EMPTY(port, list)) {
|
||||
__get_ipc_port(port);
|
||||
listp_add(port, &pobj_list, list);
|
||||
LISTP_ADD(port, &pobj_list, list);
|
||||
port->recent = true;
|
||||
} else {
|
||||
if (!port->recent) {
|
||||
listp_del_init(port, &pobj_list, list);
|
||||
listp_add(port, &pobj_list, list);
|
||||
LISTP_DEL_INIT(port, &pobj_list, list);
|
||||
LISTP_ADD(port, &pobj_list, list);
|
||||
port->recent = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if (list_empty(port, list)) {
|
||||
if (LIST_EMPTY(port, list)) {
|
||||
__get_ipc_port(port);
|
||||
listp_add_tail(port, &pobj_list, list);
|
||||
LISTP_ADD_TAIL(port, &pobj_list, list);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -341,7 +341,7 @@ void add_ipc_port_by_id (IDTYPE vmid, PAL_HANDLE hdl, int type,
|
||||
struct shim_ipc_port * tmp, * port = NULL;
|
||||
|
||||
if (vmid)
|
||||
listp_for_each_entry(tmp, head, hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, head, hlist)
|
||||
if (tmp->info.vmid == vmid && tmp->pal_handle == hdl) {
|
||||
port = tmp;
|
||||
__get_ipc_port(port);
|
||||
@@ -349,7 +349,7 @@ void add_ipc_port_by_id (IDTYPE vmid, PAL_HANDLE hdl, int type,
|
||||
}
|
||||
|
||||
if (!port)
|
||||
listp_for_each_entry(tmp, &pobj_list, list)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &pobj_list, list)
|
||||
if (tmp->pal_handle == hdl) {
|
||||
port = tmp;
|
||||
__get_ipc_port(port);
|
||||
@@ -362,8 +362,8 @@ void add_ipc_port_by_id (IDTYPE vmid, PAL_HANDLE hdl, int type,
|
||||
}
|
||||
|
||||
bool need_restart = __add_ipc_port(port, vmid, type, fini);
|
||||
assert(!list_empty(port, list));
|
||||
assert(!vmid || !list_empty(port, hlist));
|
||||
assert(!LIST_EMPTY(port, list));
|
||||
assert(!vmid || !LIST_EMPTY(port, hlist));
|
||||
|
||||
if (portptr)
|
||||
*portptr = port;
|
||||
@@ -383,7 +383,7 @@ static bool __del_ipc_port (struct shim_ipc_port * port, int type)
|
||||
port, port->pal_handle, port->info.vmid);
|
||||
|
||||
__get_ipc_port(port); // Prevent the object from being freed during deletion
|
||||
assert(!list_empty(port, list)); // Never delete a port twice
|
||||
assert(!LIST_EMPTY(port, list)); // Never delete a port twice
|
||||
|
||||
bool need_restart = false;
|
||||
type = type ? (type & port->info.type) : port->info.type;
|
||||
@@ -407,14 +407,14 @@ static bool __del_ipc_port (struct shim_ipc_port * port, int type)
|
||||
need_restart = true;
|
||||
|
||||
// Officially delete the port
|
||||
listp_del_init(port, &pobj_list, list);
|
||||
LISTP_DEL_INIT(port, &pobj_list, list);
|
||||
port->info.type &= IPC_PORT_IFPOLL;
|
||||
__put_ipc_port(port);
|
||||
|
||||
if (!list_empty(port, hlist)) {
|
||||
if (!LIST_EMPTY(port, hlist)) {
|
||||
// Re-fetch head pointer
|
||||
LISTP_TYPE(shim_ipc_port) * head = &ipc_port_pool[PID_HASH(port->info.vmid)];
|
||||
listp_del_init(port, head, hlist);
|
||||
LISTP_DEL_INIT(port, head, hlist);
|
||||
__put_ipc_port(port);
|
||||
}
|
||||
|
||||
@@ -422,8 +422,8 @@ static bool __del_ipc_port (struct shim_ipc_port * port, int type)
|
||||
// some threads might be blocking for responses.
|
||||
lock(&port->msgs_lock);
|
||||
struct shim_ipc_msg_obj * msg, * n;
|
||||
listp_for_each_entry_safe(msg, n, &port->msgs, list) {
|
||||
listp_del_init(msg, &port->msgs, list);
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(msg, n, &port->msgs, list) {
|
||||
LISTP_DEL_INIT(msg, &port->msgs, list);
|
||||
msg->retval = -ECONNRESET;
|
||||
if (msg->thread) {
|
||||
debug("wake up thread %d\n", msg->thread->tid);
|
||||
@@ -443,7 +443,7 @@ void del_ipc_port (struct shim_ipc_port * port, int type)
|
||||
lock(&ipc_helper_lock);
|
||||
|
||||
// If the port is already deleted, don't delete it again.
|
||||
if (list_empty(port, list)) {
|
||||
if (LIST_EMPTY(port, list)) {
|
||||
unlock(&ipc_helper_lock);
|
||||
return;
|
||||
}
|
||||
@@ -464,8 +464,8 @@ void del_ipc_port_by_id (IDTYPE vmid, int type)
|
||||
|
||||
lock(&ipc_helper_lock);
|
||||
|
||||
listp_for_each_entry_safe(port, n, head, hlist) {
|
||||
if (list_empty(port, list))
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(port, n, head, hlist) {
|
||||
if (LIST_EMPTY(port, list))
|
||||
continue;
|
||||
|
||||
debug("port %p (handle %p) for process %u in list %p\n",
|
||||
@@ -489,7 +489,7 @@ void del_ipc_port_fini (struct shim_ipc_port * port, unsigned int exitcode)
|
||||
lock(&ipc_helper_lock);
|
||||
|
||||
// If the port is already deleted, don't delete it again.
|
||||
if (list_empty(port, list)) {
|
||||
if (LIST_EMPTY(port, list)) {
|
||||
unlock(&ipc_helper_lock);
|
||||
return;
|
||||
}
|
||||
@@ -517,7 +517,7 @@ static struct shim_ipc_port * __lookup_ipc_port (IDTYPE vmid, int type)
|
||||
LISTP_TYPE(shim_ipc_port) * head = &ipc_port_pool[PID_HASH(vmid)];
|
||||
struct shim_ipc_port * tmp;
|
||||
|
||||
listp_for_each_entry(tmp, head, hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, head, hlist)
|
||||
if (tmp->info.vmid == vmid && (!type || tmp->info.type & type)) {
|
||||
debug("found port %p (handle %p) for process %u (type %04x)\n",
|
||||
tmp, tmp->pal_handle, tmp->info.vmid, tmp->info.type);
|
||||
@@ -533,8 +533,8 @@ struct shim_ipc_port * lookup_ipc_port (IDTYPE vmid, int type)
|
||||
lock(&ipc_helper_lock);
|
||||
struct shim_ipc_port * port = __lookup_ipc_port(vmid, type);
|
||||
if (port) {
|
||||
assert(!list_empty(port, list));
|
||||
assert(!vmid || !list_empty(port, hlist));
|
||||
assert(!LIST_EMPTY(port, list));
|
||||
assert(!vmid || !LIST_EMPTY(port, hlist));
|
||||
}
|
||||
unlock(&ipc_helper_lock);
|
||||
return port;
|
||||
@@ -569,7 +569,7 @@ void del_all_ipc_ports (int type)
|
||||
|
||||
lock(&ipc_helper_lock);
|
||||
|
||||
listp_for_each_entry_safe(pobj, n, &pobj_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(pobj, n, &pobj_list, list) {
|
||||
if (__del_ipc_port(pobj, type))
|
||||
need_restart = true;
|
||||
}
|
||||
@@ -600,7 +600,7 @@ int broadcast_ipc (struct shim_ipc_msg * msg, struct shim_ipc_port ** exclude,
|
||||
lock(&ipc_helper_lock);
|
||||
|
||||
int ntargets = 0;
|
||||
listp_for_each_entry(pobj, &pobj_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(pobj, &pobj_list, list) {
|
||||
debug("found port %p (handle %p) for process %u (type %04x)\n", pobj,
|
||||
pobj->pal_handle, pobj->info.vmid, pobj->info.type);
|
||||
if (pobj->info.type & target_type)
|
||||
@@ -610,7 +610,7 @@ int broadcast_ipc (struct shim_ipc_msg * msg, struct shim_ipc_port ** exclude,
|
||||
struct shim_ipc_port ** targets = __alloca(sizeof(struct shim_ipc_port *)
|
||||
* ntargets);
|
||||
int i = 0;
|
||||
listp_for_each_entry(pobj, &pobj_list, list)
|
||||
LISTP_FOR_EACH_ENTRY(pobj, &pobj_list, list)
|
||||
if (pobj->info.type & target_type) {
|
||||
get_ipc_port(pobj);
|
||||
targets[i++] = pobj;
|
||||
@@ -944,7 +944,7 @@ update_list:
|
||||
|
||||
// If the port is removed from the list or intended to be deleted,
|
||||
// remove the port from the polling array
|
||||
if (list_empty(pobj, list)) {
|
||||
if (LIST_EMPTY(pobj, list)) {
|
||||
if (polled == pobj->pal_handle) {
|
||||
polled = NULL;
|
||||
count = -1;
|
||||
@@ -978,7 +978,7 @@ update_list:
|
||||
}
|
||||
port_num -= compact;
|
||||
|
||||
listp_for_each_entry(pobj, &pobj_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(pobj, &pobj_list, list) {
|
||||
/* we only update among recently updated ports */
|
||||
if (!pobj->recent)
|
||||
break;
|
||||
@@ -1099,7 +1099,7 @@ int exit_with_ipc_helper (bool handover, struct shim_thread ** ret)
|
||||
if (handover) {
|
||||
handover = false;
|
||||
struct shim_ipc_port * pobj;
|
||||
listp_for_each_entry(pobj, &pobj_list, list)
|
||||
LISTP_FOR_EACH_ENTRY(pobj, &pobj_list, list)
|
||||
if (pobj->info.type & IPC_PORT_KEEPALIVE) {
|
||||
handover = true;
|
||||
break;
|
||||
|
||||
@@ -140,7 +140,7 @@ void CONCAT3(debug_print, NS, ranges) (void)
|
||||
LISTP_TYPE(range) * head = range_table + RANGE_HASH(off);
|
||||
struct range * tmp, * r = NULL;
|
||||
|
||||
listp_for_each_entry(tmp, head, hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, head, hlist)
|
||||
if (tmp->offset == off) {
|
||||
r = tmp;
|
||||
break;
|
||||
@@ -243,7 +243,7 @@ static struct range * __get_range (int off)
|
||||
|
||||
struct range * r;
|
||||
|
||||
listp_for_each_entry(r, head, hlist)
|
||||
LISTP_FOR_EACH_ENTRY(r, head, hlist)
|
||||
if (r->offset == off)
|
||||
return r;
|
||||
|
||||
@@ -278,18 +278,18 @@ static int __add_range (struct range * r, int off, IDTYPE owner,
|
||||
if (ret == -EEXIST) {
|
||||
struct range * tmp;
|
||||
|
||||
listp_for_each_entry(tmp, head, hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, head, hlist)
|
||||
if (tmp->offset == off) {
|
||||
listp_del(tmp, head, hlist);
|
||||
LISTP_DEL(tmp, head, hlist);
|
||||
|
||||
/* Chia-Che Tsai 10/17/17: only when tmp->owner is non-NULL,
|
||||
* and tmp->owner->vmid == cur_process.vmid, tmp is on the
|
||||
* owned list, otherwise it is an offered. */
|
||||
if (tmp->owner && tmp->owner->vmid == cur_process.vmid) {
|
||||
listp_del(tmp, &owned_ranges, list);
|
||||
LISTP_DEL(tmp, &owned_ranges, list);
|
||||
nowned--;
|
||||
} else {
|
||||
listp_del(tmp, &offered_ranges, list);
|
||||
LISTP_DEL(tmp, &offered_ranges, list);
|
||||
noffered--;
|
||||
}
|
||||
|
||||
@@ -304,22 +304,22 @@ static int __add_range (struct range * r, int off, IDTYPE owner,
|
||||
}
|
||||
|
||||
INIT_LIST_HEAD(r, hlist);
|
||||
listp_add(r, head, hlist);
|
||||
LISTP_ADD(r, head, hlist);
|
||||
INIT_LIST_HEAD(r, list);
|
||||
|
||||
LISTP_TYPE(range)* list = (owner == cur_process.vmid) ? &owned_ranges
|
||||
: &offered_ranges;
|
||||
struct range * prev = listp_first_entry(list, range, list);
|
||||
struct range * prev = LISTP_FIRST_ENTRY(list, range, list);
|
||||
struct range * tmp;
|
||||
|
||||
|
||||
listp_for_each_entry(tmp, list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tmp, list, list) {
|
||||
if (tmp->offset >= off)
|
||||
break;
|
||||
prev = tmp;
|
||||
}
|
||||
|
||||
listp_add_after(r, prev, list, list);
|
||||
LISTP_ADD_AFTER(r, prev, list, list);
|
||||
|
||||
if (owner == cur_process.vmid)
|
||||
nowned++;
|
||||
@@ -550,15 +550,15 @@ int CONCAT3(del, NS, range) (IDTYPE idx)
|
||||
free(r->used);
|
||||
// Re-acquire the head; kind of ugly
|
||||
LISTP_TYPE(range) * head = range_table + RANGE_HASH(off);
|
||||
listp_del(r, head, hlist);
|
||||
LISTP_DEL(r, head, hlist);
|
||||
|
||||
/* Chia-Che Tsai 10/17/17: only when r->owner is non-NULL,
|
||||
* and r->owner->vmid == cur_process.vmid, r is on the
|
||||
* owned list, otherwise it is an offered. */
|
||||
if (r->owner && r->owner->vmid == cur_process.vmid)
|
||||
listp_del(r, &owned_ranges, list);
|
||||
LISTP_DEL(r, &owned_ranges, list);
|
||||
else
|
||||
listp_del(r, &offered_ranges, list);
|
||||
LISTP_DEL(r, &offered_ranges, list);
|
||||
|
||||
put_ipc_info(r->owner);
|
||||
free(r);
|
||||
@@ -642,7 +642,7 @@ IDTYPE CONCAT2(allocate, NS) (IDTYPE min, IDTYPE max)
|
||||
struct range * r;
|
||||
lock(&range_map_lock);
|
||||
|
||||
listp_for_each_entry (r, &owned_ranges, list) {
|
||||
LISTP_FOR_EACH_ENTRY(r, &owned_ranges, list) {
|
||||
if (max && idx >= max)
|
||||
break;
|
||||
|
||||
@@ -1041,7 +1041,7 @@ int NS_CALLBACK(findns) (IPC_CALLBACK_ARGS)
|
||||
get_ipc_port(port);
|
||||
query->port = port;
|
||||
INIT_LIST_HEAD(query, list);
|
||||
listp_add_tail(query, &ns_queries, list);
|
||||
LISTP_ADD_TAIL(query, &ns_queries, list);
|
||||
} else {
|
||||
ret = -ENOMEM;
|
||||
}
|
||||
@@ -1103,8 +1103,8 @@ int NS_CALLBACK(tellns) (IPC_CALLBACK_ARGS)
|
||||
|
||||
struct ns_query * query, * pos;
|
||||
|
||||
listp_for_each_entry_safe(query, pos, &ns_queries, list) {
|
||||
listp_del(query, &ns_queries, list);
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(query, pos, &ns_queries, list) {
|
||||
LISTP_DEL(query, &ns_queries, list);
|
||||
NS_SEND(tellns)(query->port, query->dest, NS_LEADER, query->seq);
|
||||
put_ipc_port(query->port);
|
||||
free(query);
|
||||
@@ -1561,7 +1561,7 @@ int NS_CALLBACK(queryall) (IPC_CALLBACK_ARGS)
|
||||
int owner_offset = 0;
|
||||
|
||||
retry:
|
||||
listp_for_each_entry (r, list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(r, list, list) {
|
||||
struct shim_ipc_info * p = r->owner;
|
||||
int datasz = sizeof(struct ipc_ns_client) + p->uri.len;
|
||||
struct ipc_ns_client * owner = __alloca(datasz);
|
||||
@@ -1734,7 +1734,7 @@ int CONCAT2(NS, add_key) (NS_KEY * key, IDTYPE id)
|
||||
|
||||
lock(&range_map_lock);
|
||||
|
||||
listp_for_each_entry(k, head, hlist)
|
||||
LISTP_FOR_EACH_ENTRY(k, head, hlist)
|
||||
if (!KEY_COMP(&k->key, key))
|
||||
goto out;
|
||||
|
||||
@@ -1747,7 +1747,7 @@ int CONCAT2(NS, add_key) (NS_KEY * key, IDTYPE id)
|
||||
KEY_COPY(&k->key, key);
|
||||
k->id = id;
|
||||
INIT_LIST_HEAD(k, hlist);
|
||||
listp_add(k, head, hlist);
|
||||
LISTP_ADD(k, head, hlist);
|
||||
|
||||
debug("add key/id pair (%lu, %u) to hash list: %p\n",
|
||||
KEY_HASH(key), id, head);
|
||||
@@ -1765,11 +1765,11 @@ int CONCAT2(NS, get_key) (NS_KEY * key, bool delete)
|
||||
|
||||
lock(&range_map_lock);
|
||||
|
||||
listp_for_each_entry(k, head, hlist)
|
||||
LISTP_FOR_EACH_ENTRY(k, head, hlist)
|
||||
if (!KEY_COMP(&k->key, key)) {
|
||||
id = k->id;
|
||||
if (delete) {
|
||||
listp_del(k, head, hlist);
|
||||
LISTP_DEL(k, head, hlist);
|
||||
free(k);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -330,7 +330,7 @@ int get_all_pid_status (struct pid_status ** status)
|
||||
lock(&range_map_lock);
|
||||
|
||||
retry:
|
||||
listp_for_each_entry (r, list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(r, list, list) {
|
||||
struct subrange * s = NULL;
|
||||
struct shim_ipc_info * p;
|
||||
int off, idx;
|
||||
@@ -377,12 +377,12 @@ next_sub:
|
||||
add_ipc_port_by_id(owner, pal_handle, type, NULL, &port);
|
||||
|
||||
lock(&range_map_lock);
|
||||
listp_for_each_entry(r, list, list)
|
||||
LISTP_FOR_EACH_ENTRY(r, list, list)
|
||||
if (r->offset >= off)
|
||||
break;
|
||||
/* DEP 5/15/17: I believe this is checking if the list is empty */
|
||||
//if (&r->list == list)
|
||||
if (listp_empty(list))
|
||||
if (LISTP_EMPTY(list))
|
||||
break;
|
||||
if (r->offset > off)
|
||||
goto next_range;
|
||||
@@ -756,9 +756,9 @@ int get_rpc_msg (IDTYPE * sender, void * buf, int len)
|
||||
create_lock_runtime(&rpc_queue_lock);
|
||||
lock(&rpc_queue_lock);
|
||||
|
||||
if (!listp_empty(&rpc_msgs)) {
|
||||
struct rpcmsg * m = listp_first_entry(&rpc_msgs, struct rpcmsg, list);
|
||||
listp_del(m, &rpc_msgs, list);
|
||||
if (!LISTP_EMPTY(&rpc_msgs)) {
|
||||
struct rpcmsg * m = LISTP_FIRST_ENTRY(&rpc_msgs, struct rpcmsg, list);
|
||||
LISTP_DEL(m, &rpc_msgs, list);
|
||||
if (m->len < len)
|
||||
len = m->len;
|
||||
if (sender)
|
||||
@@ -779,7 +779,7 @@ int get_rpc_msg (IDTYPE * sender, void * buf, int len)
|
||||
r->len = len;
|
||||
r->buffer = buf;
|
||||
thread_setwait(&r->thread, NULL);
|
||||
listp_add_tail(r, &rpc_reqs, list);
|
||||
LISTP_ADD_TAIL(r, &rpc_reqs, list);
|
||||
unlock(&rpc_queue_lock);
|
||||
thread_sleep(NO_TIMEOUT);
|
||||
put_thread(r->thread);
|
||||
@@ -801,9 +801,9 @@ int ipc_pid_sendrpc_callback (IPC_CALLBACK_ARGS)
|
||||
create_lock_runtime(&rpc_queue_lock);
|
||||
lock(&rpc_queue_lock);
|
||||
|
||||
if (!listp_empty(&rpc_reqs)) {
|
||||
struct rpcreq * r = listp_first_entry(&rpc_reqs, struct rpcreq, list);
|
||||
listp_del(r, &rpc_reqs, list);
|
||||
if (!LISTP_EMPTY(&rpc_reqs)) {
|
||||
struct rpcreq * r = LISTP_FIRST_ENTRY(&rpc_reqs, struct rpcreq, list);
|
||||
LISTP_DEL(r, &rpc_reqs, list);
|
||||
if (msgin->len < r->len)
|
||||
r->len = msgin->len;
|
||||
r->sender = msgin->sender;
|
||||
@@ -822,7 +822,7 @@ int ipc_pid_sendrpc_callback (IPC_CALLBACK_ARGS)
|
||||
m->sender = msgin->sender;
|
||||
m->len = msgin->len;
|
||||
memcpy(m->payload, msgin->payload, msgin->len);
|
||||
listp_add_tail(m, &rpc_msgs, list);
|
||||
LISTP_ADD_TAIL(m, &rpc_msgs, list);
|
||||
out:
|
||||
unlock(&rpc_queue_lock);
|
||||
SAVE_PROFILE_INTERVAL(ipc_pid_sendrpc_callback);
|
||||
|
||||
+10
-10
@@ -77,7 +77,7 @@ int64_t install_async_event (PAL_HANDLE object, unsigned long time,
|
||||
|
||||
struct async_event * tmp;
|
||||
|
||||
listp_for_each_entry(tmp, &async_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &async_list, list) {
|
||||
if (event->expire_time && tmp->expire_time > event->expire_time)
|
||||
break;
|
||||
}
|
||||
@@ -90,8 +90,8 @@ int64_t install_async_event (PAL_HANDLE object, unsigned long time,
|
||||
* If seconds is zero, any pending alarm is canceled.
|
||||
* In any event any previously set alarm() is canceled.
|
||||
*/
|
||||
if (!listp_empty(&async_list)) {
|
||||
tmp = listp_first_entry(&async_list, struct async_event, list);
|
||||
if (!LISTP_EMPTY(&async_list)) {
|
||||
tmp = LISTP_FIRST_ENTRY(&async_list, struct async_event, list);
|
||||
tmp = tmp->list.prev;
|
||||
|
||||
rv = tmp->expire_time - install_time;
|
||||
@@ -100,7 +100,7 @@ int64_t install_async_event (PAL_HANDLE object, unsigned long time,
|
||||
* any previously set alarm() is canceled.
|
||||
* There should be exactly only one timer pending
|
||||
*/
|
||||
listp_del(tmp, &async_list, list);
|
||||
LISTP_DEL(tmp, &async_list, list);
|
||||
free(tmp);
|
||||
} else {
|
||||
tmp = NULL;
|
||||
@@ -110,7 +110,7 @@ int64_t install_async_event (PAL_HANDLE object, unsigned long time,
|
||||
if (!time) // If seconds is zero, any pending alarm is canceled.
|
||||
free(event);
|
||||
else
|
||||
listp_add_tail(event, &async_list, list);
|
||||
LISTP_ADD_TAIL(event, &async_list, list);
|
||||
|
||||
if (async_helper_state == HELPER_NOTALIVE)
|
||||
create_async_helper();
|
||||
@@ -201,7 +201,7 @@ static void shim_async_helper (void * arg)
|
||||
|
||||
lock(&async_helper_lock);
|
||||
/* DEP: Events can only be on the async list */
|
||||
listp_del(next_event, &async_list, list);
|
||||
LISTP_DEL(next_event, &async_list, list);
|
||||
free(next_event);
|
||||
goto update_list;
|
||||
}
|
||||
@@ -224,7 +224,7 @@ update_status:
|
||||
|
||||
lock(&async_helper_lock);
|
||||
|
||||
listp_for_each_entry_safe(tmp, n, &async_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &async_list, list) {
|
||||
if (tmp->object == polled) {
|
||||
debug("async event trigger at %lu\n",
|
||||
latest_time);
|
||||
@@ -239,10 +239,10 @@ update_list:
|
||||
next_event = NULL;
|
||||
object_num = 0;
|
||||
|
||||
if (!listp_empty(&async_list)) {
|
||||
if (!LISTP_EMPTY(&async_list)) {
|
||||
struct async_event * tmp, * n;
|
||||
|
||||
listp_for_each_entry_safe(tmp, n, &async_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &async_list, list) {
|
||||
if (tmp->object) {
|
||||
local_objects[object_num + 1] = tmp->object;
|
||||
object_num++;
|
||||
@@ -258,7 +258,7 @@ update_list:
|
||||
|
||||
debug("async event trigger at %lu (expire at %lu)\n",
|
||||
latest_time, tmp->expire_time);
|
||||
listp_del(tmp, &async_list, list);
|
||||
LISTP_DEL(tmp, &async_list, list);
|
||||
unlock(&async_helper_lock);
|
||||
tmp->callback(tmp->caller, tmp->arg);
|
||||
free(tmp);
|
||||
|
||||
@@ -154,7 +154,7 @@ get_cp_map_entry (void * map, void * addr, bool create)
|
||||
struct cp_map_entry * tmp;
|
||||
struct shim_cp_map_entry * e = NULL;
|
||||
|
||||
listp_for_each_entry(tmp, head, hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, head, hlist)
|
||||
if (tmp->entry.addr == addr)
|
||||
e = &tmp->entry;
|
||||
|
||||
@@ -166,7 +166,7 @@ get_cp_map_entry (void * map, void * addr, bool create)
|
||||
|
||||
struct cp_map_entry *new = &buffer->entries[buffer->cnt++];
|
||||
INIT_LIST_HEAD(new, hlist);
|
||||
listp_add(new, head, hlist);
|
||||
LISTP_ADD(new, head, hlist);
|
||||
|
||||
new->entry.addr = addr;
|
||||
new->entry.off = 0;
|
||||
|
||||
@@ -113,7 +113,7 @@ static void update_epoll (struct shim_epoll_handle * epoll)
|
||||
int npals = 0;
|
||||
epoll->nread = 0;
|
||||
|
||||
listp_for_each_entry(tmp, &epoll->fds, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &epoll->fds, list) {
|
||||
if (!tmp->pal_handle)
|
||||
continue;
|
||||
|
||||
@@ -138,15 +138,15 @@ int delete_from_epoll_handles (struct shim_handle * handle)
|
||||
while (1) {
|
||||
lock(&handle->lock);
|
||||
|
||||
if (listp_empty(&handle->epolls)) {
|
||||
if (LISTP_EMPTY(&handle->epolls)) {
|
||||
unlock(&handle->lock);
|
||||
break;
|
||||
}
|
||||
|
||||
struct shim_epoll_fd * epoll_fd = listp_first_entry(&handle->epolls,
|
||||
struct shim_epoll_fd * epoll_fd = LISTP_FIRST_ENTRY(&handle->epolls,
|
||||
struct shim_epoll_fd, back);
|
||||
|
||||
listp_del(epoll_fd, &handle->epolls, back);
|
||||
LISTP_DEL(epoll_fd, &handle->epolls, back);
|
||||
unlock(&handle->lock);
|
||||
put_handle(handle);
|
||||
|
||||
@@ -158,7 +158,7 @@ int delete_from_epoll_handles (struct shim_handle * handle)
|
||||
|
||||
lock(&epoll_hdl->lock);
|
||||
|
||||
listp_del(epoll_fd, &epoll->fds, list);
|
||||
LISTP_DEL(epoll_fd, &epoll->fds, list);
|
||||
free(epoll_fd);
|
||||
|
||||
epoll_hdl->info.epoll.nfds--;
|
||||
@@ -191,7 +191,7 @@ int shim_do_epoll_ctl (int epfd, int op, int fd,
|
||||
|
||||
switch (op) {
|
||||
case EPOLL_CTL_ADD: {
|
||||
listp_for_each_entry(epoll_fd, &epoll->fds, list)
|
||||
LISTP_FOR_EACH_ENTRY(epoll_fd, &epoll->fds, list)
|
||||
if (epoll_fd->fd == fd) {
|
||||
ret = -EEXIST;
|
||||
goto out;
|
||||
@@ -229,17 +229,17 @@ int shim_do_epoll_ctl (int epfd, int op, int fd,
|
||||
get_handle(epoll_hdl);
|
||||
lock(&hdl->lock);
|
||||
INIT_LIST_HEAD(epoll_fd, back);
|
||||
listp_add_tail(epoll_fd, &hdl->epolls, back);
|
||||
LISTP_ADD_TAIL(epoll_fd, &hdl->epolls, back);
|
||||
unlock(&hdl->lock);
|
||||
|
||||
INIT_LIST_HEAD(epoll_fd, list);
|
||||
listp_add_tail(epoll_fd, &epoll->fds, list);
|
||||
LISTP_ADD_TAIL(epoll_fd, &epoll->fds, list);
|
||||
epoll->nfds++;
|
||||
goto update;
|
||||
}
|
||||
|
||||
case EPOLL_CTL_MOD: {
|
||||
listp_for_each_entry(epoll_fd, &epoll->fds, list)
|
||||
LISTP_FOR_EACH_ENTRY(epoll_fd, &epoll->fds, list)
|
||||
if (epoll_fd->fd == fd) {
|
||||
epoll_fd->events = event->events;
|
||||
epoll_fd->data = event->data;
|
||||
@@ -251,20 +251,20 @@ int shim_do_epoll_ctl (int epfd, int op, int fd,
|
||||
}
|
||||
|
||||
case EPOLL_CTL_DEL: {
|
||||
listp_for_each_entry(epoll_fd, &epoll->fds, list)
|
||||
LISTP_FOR_EACH_ENTRY(epoll_fd, &epoll->fds, list)
|
||||
if (epoll_fd->fd == fd) {
|
||||
struct shim_handle * hdl = epoll_fd->handle;
|
||||
|
||||
/* Unregister the epoll handle */
|
||||
lock(&hdl->lock);
|
||||
listp_del(epoll_fd, &hdl->epolls, back);
|
||||
LISTP_DEL(epoll_fd, &hdl->epolls, back);
|
||||
unlock(&hdl->lock);
|
||||
put_handle(epoll_hdl);
|
||||
|
||||
debug("delete handle %p from epoll handle %p\n",
|
||||
hdl, epoll);
|
||||
|
||||
listp_del(epoll_fd, &epoll->fds, list);
|
||||
LISTP_DEL(epoll_fd, &epoll->fds, list);
|
||||
epoll->nfds--;
|
||||
free(epoll_fd);
|
||||
goto update;
|
||||
@@ -341,7 +341,7 @@ retry:
|
||||
if (!DkStreamAttributesQueryByHandle(polled, &attr))
|
||||
goto reply;
|
||||
|
||||
listp_for_each_entry(epoll_fd, &epoll->fds, list)
|
||||
LISTP_FOR_EACH_ENTRY(epoll_fd, &epoll->fds, list)
|
||||
if (polled == epoll_fd->pal_handle) {
|
||||
|
||||
debug("epoll: fd %d (handle %p) polled\n", epoll_fd->fd,
|
||||
@@ -360,7 +360,7 @@ retry:
|
||||
}
|
||||
|
||||
reply:
|
||||
listp_for_each_entry(epoll_fd, &epoll->fds, list) {
|
||||
LISTP_FOR_EACH_ENTRY(epoll_fd, &epoll->fds, list) {
|
||||
if (nevents == maxevents)
|
||||
break;
|
||||
|
||||
@@ -415,7 +415,7 @@ BEGIN_CP_FUNC(epoll_fd)
|
||||
|
||||
INIT_LISTP(new_list);
|
||||
|
||||
listp_for_each_entry(epoll_fd, old_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(epoll_fd, old_list, list) {
|
||||
ptr_t off = ADD_CP_OFFSET(sizeof(struct shim_epoll_fd));
|
||||
|
||||
struct shim_epoll_fd * new_epoll_fd =
|
||||
@@ -427,7 +427,7 @@ BEGIN_CP_FUNC(epoll_fd)
|
||||
new_epoll_fd->revents = epoll_fd->revents;
|
||||
new_epoll_fd->pal_handle = NULL;
|
||||
|
||||
listp_add(new_epoll_fd, new_list, list);
|
||||
LISTP_ADD(new_epoll_fd, new_list, list);
|
||||
|
||||
DO_CP(handle, epoll_fd->handle, &new_epoll_fd->handle);
|
||||
}
|
||||
@@ -443,7 +443,7 @@ BEGIN_RS_FUNC(epoll_fd)
|
||||
|
||||
CP_REBASE(*list);
|
||||
|
||||
listp_for_each_entry(epoll_fd, list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(epoll_fd, list, list) {
|
||||
|
||||
CP_REBASE(epoll_fd->handle);
|
||||
CP_REBASE(epoll_fd->back);
|
||||
|
||||
@@ -391,7 +391,7 @@ err:
|
||||
}
|
||||
if (*c == ' ' || *c == '\n') {
|
||||
INIT_LIST_HEAD(next, list);
|
||||
listp_add_tail(next, &new_shargs, list);
|
||||
LISTP_ADD_TAIL(next, &new_shargs, list);
|
||||
next = NULL;
|
||||
s = c + 1;
|
||||
if (*c == '\n') {
|
||||
@@ -406,15 +406,15 @@ err:
|
||||
if (started) {
|
||||
if (next) {
|
||||
INIT_LIST_HEAD(next, list);
|
||||
listp_add_tail(next, &new_shargs, list);
|
||||
LISTP_ADD_TAIL(next, &new_shargs, list);
|
||||
}
|
||||
|
||||
struct sharg * first =
|
||||
listp_first_entry(&new_shargs, struct sharg, list);
|
||||
LISTP_FIRST_ENTRY(&new_shargs, struct sharg, list);
|
||||
assert(first);
|
||||
debug("detected as script: run by %s\n", first->arg);
|
||||
file = first->arg;
|
||||
listp_splice(&new_shargs, &shargs, list, sharg);
|
||||
LISTP_SPLICE(&new_shargs, &shargs, list, sharg);
|
||||
put_handle(exec);
|
||||
goto reopen;
|
||||
}
|
||||
@@ -435,16 +435,16 @@ err:
|
||||
|
||||
INC_PROFILE_OCCURENCE(syscall_use_ipc);
|
||||
|
||||
if (!listp_empty(&shargs)) {
|
||||
if (!LISTP_EMPTY(&shargs)) {
|
||||
struct sharg * sh;
|
||||
int shargc = 0, cnt = 0;
|
||||
listp_for_each_entry(sh, &shargs, list)
|
||||
LISTP_FOR_EACH_ENTRY(sh, &shargs, list)
|
||||
shargc++;
|
||||
|
||||
const char ** new_argv =
|
||||
__alloca(sizeof(const char *) * (argc + shargc + 1));
|
||||
|
||||
listp_for_each_entry(sh, &shargs, list)
|
||||
LISTP_FOR_EACH_ENTRY(sh, &shargs, list)
|
||||
new_argv[cnt++] = sh->arg;
|
||||
|
||||
for (cnt = 0 ; cnt < argc ; cnt++)
|
||||
|
||||
@@ -83,8 +83,8 @@ int thread_exit(struct shim_thread * self, bool send_ipc)
|
||||
debug("thread exits, notifying thread %d\n", parent->tid);
|
||||
|
||||
lock(&parent->lock);
|
||||
listp_del_init(self, &parent->children, siblings);
|
||||
listp_add_tail(self, &parent->exited_children, siblings);
|
||||
LISTP_DEL_INIT(self, &parent->children, siblings);
|
||||
LISTP_ADD_TAIL(self, &parent->exited_children, siblings);
|
||||
|
||||
if (!self->in_vm) {
|
||||
debug("deliver SIGCHLD (thread = %d, exitval = %d)\n",
|
||||
|
||||
@@ -72,7 +72,7 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
|
||||
create_lock_runtime(&futex_list_lock);
|
||||
lock(&futex_list_lock);
|
||||
|
||||
listp_for_each_entry(tmp, &futex_list, list)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &futex_list, list)
|
||||
if (tmp->uaddr == uaddr) {
|
||||
futex = tmp;
|
||||
break;
|
||||
@@ -93,12 +93,12 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
|
||||
get_handle(hdl);
|
||||
INIT_LISTP(&futex->waiters);
|
||||
INIT_LIST_HEAD(futex, list);
|
||||
listp_add_tail(futex, &futex_list, list);
|
||||
LISTP_ADD_TAIL(futex, &futex_list, list);
|
||||
}
|
||||
|
||||
if (futex_op == FUTEX_WAKE_OP || futex_op == FUTEX_REQUEUE ||
|
||||
futex_op == FUTEX_CMP_REQUEUE) {
|
||||
listp_for_each_entry(tmp, &futex_list, list)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &futex_list, list)
|
||||
if (tmp->uaddr == uaddr2) {
|
||||
futex2 = tmp;
|
||||
break;
|
||||
@@ -119,7 +119,7 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
|
||||
get_handle(hdl2);
|
||||
INIT_LISTP(&futex2->waiters);
|
||||
INIT_LIST_HEAD(futex2, list);
|
||||
listp_add_tail(futex2, &futex_list, list);
|
||||
LISTP_ADD_TAIL(futex2, &futex_list, list);
|
||||
}
|
||||
|
||||
val2 = (uint32_t)(uint64_t) utime;
|
||||
@@ -180,7 +180,7 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
|
||||
thread_setwait(&waiter.thread, NULL);
|
||||
INIT_LIST_HEAD(&waiter, list);
|
||||
waiter.bitset = bitset;
|
||||
listp_add_tail(&waiter, &futex->waiters, list);
|
||||
LISTP_ADD_TAIL(&waiter, &futex->waiters, list);
|
||||
|
||||
unlock(&hdl->lock);
|
||||
ret = thread_sleep(timeout_us);
|
||||
@@ -188,12 +188,12 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
|
||||
if (ret == -EAGAIN)
|
||||
ret = -ETIMEDOUT;
|
||||
if (ret == -ETIMEDOUT)
|
||||
listp_del(&waiter, &futex->waiters, list);
|
||||
LISTP_DEL(&waiter, &futex->waiters, list);
|
||||
lock(&hdl->lock);
|
||||
/* Chia-Che 10/17/17: FUTEX_WAKE should remove the waiter
|
||||
* from the list; if not, we should remove it now. */
|
||||
if (!list_empty(&waiter, list))
|
||||
listp_del(&waiter, &futex->waiters, list);
|
||||
if (!LIST_EMPTY(&waiter, list))
|
||||
LISTP_DEL(&waiter, &futex->waiters, list);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -207,14 +207,14 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
|
||||
debug("FUTEX_WAKE: %p (val = %d) count = %d mask = %08x\n",
|
||||
uaddr, *uaddr, val, bitset);
|
||||
|
||||
listp_for_each_entry_safe(waiter, wtmp, &futex->waiters, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(waiter, wtmp, &futex->waiters, list) {
|
||||
if (!(bitset & waiter->bitset))
|
||||
continue;
|
||||
|
||||
debug("FUTEX_WAKE wake thread %d: %p (val = %d)\n",
|
||||
waiter->thread->tid, uaddr, *uaddr);
|
||||
|
||||
listp_del_init(waiter, &futex->waiters, list);
|
||||
LISTP_DEL_INIT(waiter, &futex->waiters, list);
|
||||
thread_wakeup(waiter->thread);
|
||||
nwaken++;
|
||||
if (nwaken >= val) break;
|
||||
@@ -252,10 +252,10 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
|
||||
struct futex_waiter * waiter, * wtmp;
|
||||
int nwaken = 0;
|
||||
debug("FUTEX_WAKE_OP: %p (val = %d) count = %d\n", uaddr, *uaddr, val);
|
||||
listp_for_each_entry_safe(waiter, wtmp, &futex->waiters, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(waiter, wtmp, &futex->waiters, list) {
|
||||
debug("FUTEX_WAKE_OP wake thread %d: %p (val = %d)\n",
|
||||
waiter->thread->tid, uaddr, *uaddr);
|
||||
listp_del_init(waiter, &futex->waiters, list);
|
||||
LISTP_DEL_INIT(waiter, &futex->waiters, list);
|
||||
thread_wakeup(waiter->thread);
|
||||
nwaken++;
|
||||
}
|
||||
@@ -267,10 +267,10 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
|
||||
lock(&hdl->lock);
|
||||
debug("FUTEX_WAKE: %p (val = %d) count = %d\n", uaddr2,
|
||||
*uaddr2, val2);
|
||||
listp_for_each_entry_safe(waiter, wtmp, &futex2->waiters, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(waiter, wtmp, &futex2->waiters, list) {
|
||||
debug("FUTEX_WAKE_OP(2) wake thread %d: %p (val = %d)\n",
|
||||
waiter->thread->tid, uaddr2, *uaddr2);
|
||||
listp_del_init(waiter, &futex2->waiters, list);
|
||||
LISTP_DEL_INIT(waiter, &futex2->waiters, list);
|
||||
thread_wakeup(waiter->thread);
|
||||
nwaken++;
|
||||
}
|
||||
@@ -289,8 +289,8 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
|
||||
assert(futex2);
|
||||
struct futex_waiter * waiter, * wtmp;
|
||||
int nwaken = 0;
|
||||
listp_for_each_entry_safe(waiter, wtmp, &futex->waiters, list) {
|
||||
listp_del_init(waiter, &futex->waiters, list);
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(waiter, wtmp, &futex->waiters, list) {
|
||||
LISTP_DEL_INIT(waiter, &futex->waiters, list);
|
||||
thread_wakeup(waiter->thread);
|
||||
nwaken++;
|
||||
if (nwaken >= val)
|
||||
@@ -298,7 +298,7 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
|
||||
}
|
||||
|
||||
lock(&hdl2->lock);
|
||||
listp_splice_init(&futex->waiters, &futex2->waiters, list, futex_waiter);
|
||||
LISTP_SPLICE_INIT(&futex->waiters, &futex2->waiters, list, futex_waiter);
|
||||
unlock(&hdl2->lock);
|
||||
put_handle(hdl2);
|
||||
ret = nwaken;
|
||||
@@ -367,7 +367,7 @@ void release_robust_list (struct robust_list_head * head)
|
||||
|
||||
lock(&futex_list_lock);
|
||||
|
||||
listp_for_each_entry(tmp, &futex_list, list)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &futex_list, list)
|
||||
if (tmp->uaddr == futex_addr) {
|
||||
futex = tmp;
|
||||
break;
|
||||
@@ -386,8 +386,8 @@ void release_robust_list (struct robust_list_head * head)
|
||||
|
||||
debug("release robust list: %p\n", futex_addr);
|
||||
*(int *) futex_addr = 0;
|
||||
listp_for_each_entry_safe(waiter, wtmp, &futex->waiters, list) {
|
||||
listp_del_init(waiter, &futex->waiters, list);
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(waiter, wtmp, &futex->waiters, list) {
|
||||
LISTP_DEL_INIT(waiter, &futex->waiters, list);
|
||||
thread_wakeup(waiter->thread);
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ void release_clear_child_id (int * clear_child_tid)
|
||||
struct shim_futex_handle * tmp, * futex = NULL;
|
||||
lock(&futex_list_lock);
|
||||
|
||||
listp_for_each_entry(tmp, &futex_list, list)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &futex_list, list)
|
||||
if (tmp->uaddr == (void *) clear_child_tid) {
|
||||
futex = tmp;
|
||||
break;
|
||||
@@ -425,8 +425,8 @@ void release_clear_child_id (int * clear_child_tid)
|
||||
|
||||
debug("release futex at %p\n", clear_child_tid);
|
||||
*clear_child_tid = 0;
|
||||
listp_for_each_entry_safe(waiter, wtmp, &futex->waiters, list) {
|
||||
listp_del_init(waiter, &futex->waiters, list);
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(waiter, wtmp, &futex->waiters, list) {
|
||||
LISTP_DEL_INIT(waiter, &futex->waiters, list);
|
||||
thread_wakeup(waiter->thread);
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ int create_checkpoint (const char * cpdir, IDTYPE * sid)
|
||||
|
||||
struct cp_session * s;
|
||||
if (*sid) {
|
||||
listp_for_each_entry(s, &cp_sessions, list)
|
||||
LISTP_FOR_EACH_ENTRY(s, &cp_sessions, list)
|
||||
if (s->sid == *sid) {
|
||||
ret = 0;
|
||||
goto err_locked;
|
||||
@@ -119,14 +119,14 @@ retry:
|
||||
goto err_locked;
|
||||
}
|
||||
|
||||
listp_for_each_entry(s, &cp_sessions, list)
|
||||
LISTP_FOR_EACH_ENTRY(s, &cp_sessions, list)
|
||||
if (s->sid == cpsession->sid)
|
||||
goto retry;
|
||||
|
||||
*sid = cpsession->sid;
|
||||
}
|
||||
|
||||
listp_add_tail(cpsession, &cp_sessions, list);
|
||||
LISTP_ADD_TAIL(cpsession, &cp_sessions, list);
|
||||
MASTER_UNLOCK();
|
||||
return 0;
|
||||
|
||||
@@ -152,7 +152,7 @@ static int check_thread (struct shim_thread * thread, void * arg,
|
||||
if (!thread->in_vm || !thread->is_alive)
|
||||
return 0;
|
||||
|
||||
listp_for_each_entry(t, registered, list)
|
||||
LISTP_FOR_EACH_ENTRY(t, registered, list)
|
||||
if (t->thread == thread)
|
||||
return 0;
|
||||
|
||||
@@ -169,7 +169,7 @@ int join_checkpoint (struct shim_thread * thread, ucontext_t * context,
|
||||
|
||||
MASTER_LOCK();
|
||||
|
||||
listp_for_each_entry(s, &cp_sessions, list)
|
||||
LISTP_FOR_EACH_ENTRY(s, &cp_sessions, list)
|
||||
if (s->sid == sid) {
|
||||
cpsession = s;
|
||||
break;
|
||||
@@ -182,7 +182,7 @@ int join_checkpoint (struct shim_thread * thread, ucontext_t * context,
|
||||
|
||||
INIT_LIST_HEAD(&cpthread, list);
|
||||
cpthread.thread = thread;
|
||||
listp_add_tail(&cpthread, &cpsession->registered_threads, list);
|
||||
LISTP_ADD_TAIL(&cpthread, &cpsession->registered_threads, list);
|
||||
|
||||
/* find out if there is any thread that is not registered yet */
|
||||
ret = walk_thread_list(&check_thread,
|
||||
|
||||
@@ -70,7 +70,7 @@ static int __add_msg_handle (unsigned long key, IDTYPE msqid, bool owned,
|
||||
struct shim_msg_handle * tmp;
|
||||
|
||||
if (key_head)
|
||||
listp_for_each_entry(tmp, key_head, key_hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, key_head, key_hlist)
|
||||
if (tmp->msqkey == key) {
|
||||
if (tmp->msqid == msqid) {
|
||||
if (msghdl)
|
||||
@@ -81,7 +81,7 @@ static int __add_msg_handle (unsigned long key, IDTYPE msqid, bool owned,
|
||||
}
|
||||
|
||||
if (qid_head)
|
||||
listp_for_each_entry(tmp, qid_head, qid_hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, qid_head, qid_hlist)
|
||||
if (tmp->msqid == msqid) {
|
||||
if (key)
|
||||
tmp->msqkey = key;
|
||||
@@ -115,17 +115,17 @@ static int __add_msg_handle (unsigned long key, IDTYPE msqid, bool owned,
|
||||
|
||||
INIT_LIST_HEAD(msgq, list);
|
||||
get_handle(hdl);
|
||||
listp_add_tail(msgq, &msgq_list, list);
|
||||
LISTP_ADD_TAIL(msgq, &msgq_list, list);
|
||||
|
||||
INIT_LIST_HEAD(msgq, key_hlist);
|
||||
if (key_head) {
|
||||
get_handle(hdl);
|
||||
listp_add(msgq, key_head, key_hlist);
|
||||
LISTP_ADD(msgq, key_head, key_hlist);
|
||||
}
|
||||
INIT_LIST_HEAD(msgq, qid_hlist);
|
||||
if (qid_head) {
|
||||
get_handle(hdl);
|
||||
listp_add(msgq, qid_head, qid_hlist);
|
||||
LISTP_ADD(msgq, qid_head, qid_hlist);
|
||||
}
|
||||
|
||||
if (!msghdl) {
|
||||
@@ -153,7 +153,7 @@ struct shim_msg_handle * get_msg_handle_by_key (unsigned long key)
|
||||
|
||||
lock(&msgq_list_lock);
|
||||
|
||||
listp_for_each_entry(tmp, key_head, key_hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, key_head, key_hlist)
|
||||
if (tmp->msqkey == key) {
|
||||
found = tmp;
|
||||
break;
|
||||
@@ -173,7 +173,7 @@ struct shim_msg_handle * get_msg_handle_by_id (IDTYPE msqid)
|
||||
|
||||
lock(&msgq_list_lock);
|
||||
|
||||
listp_for_each_entry(tmp, qid_head, qid_hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, qid_head, qid_hlist)
|
||||
if (tmp->msqid == msqid) {
|
||||
found = tmp;
|
||||
break;
|
||||
@@ -243,18 +243,18 @@ static int __del_msg_handle (struct shim_msg_handle * msgq)
|
||||
struct shim_handle * hdl = MSG_TO_HANDLE(msgq);
|
||||
|
||||
lock(&msgq_list_lock);
|
||||
listp_del_init(msgq, &msgq_list, list);
|
||||
LISTP_DEL_INIT(msgq, &msgq_list, list);
|
||||
put_handle(hdl);
|
||||
if (!list_empty(msgq, key_hlist)) {
|
||||
if (!LIST_EMPTY(msgq, key_hlist)) {
|
||||
// DEP: Yuck, re-find the head; maybe we can do better...
|
||||
LISTP_TYPE(shim_msg_handle) * key_head = &msgq_key_hlist[MSGQ_HASH(msgq->msqkey)];
|
||||
listp_del_init(msgq, key_head, key_hlist);
|
||||
LISTP_DEL_INIT(msgq, key_head, key_hlist);
|
||||
put_handle(hdl);
|
||||
}
|
||||
if (!list_empty(msgq, qid_hlist)) {
|
||||
if (!LIST_EMPTY(msgq, qid_hlist)) {
|
||||
// DEP: Yuck, re-find the head; maybe we can do better...
|
||||
LISTP_TYPE(shim_msg_handle) * qid_head = &msgq_qid_hlist[MSGQ_HASH(msgq->msqid)];
|
||||
listp_del_init(msgq, qid_head, qid_hlist);
|
||||
LISTP_DEL_INIT(msgq, qid_head, qid_hlist);
|
||||
put_handle(hdl);
|
||||
}
|
||||
unlock(&msgq_list_lock);
|
||||
@@ -933,7 +933,7 @@ int store_all_msg_persist (void)
|
||||
|
||||
lock(&msgq_list_lock);
|
||||
|
||||
listp_for_each_entry_safe(msgq, n, &msgq_list, list)
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(msgq, n, &msgq_list, list)
|
||||
if (msgq->owned) {
|
||||
struct shim_handle * hdl = container_of(msgq, struct shim_handle,
|
||||
info.msg);
|
||||
|
||||
@@ -68,7 +68,7 @@ static int __add_sem_handle (unsigned long key, IDTYPE semid,
|
||||
int ret = 0;
|
||||
|
||||
if (key_head)
|
||||
listp_for_each_entry(tmp, key_head, key_hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, key_head, key_hlist)
|
||||
if (tmp->semkey == key) {
|
||||
if (tmp->semid == semid)
|
||||
goto out;
|
||||
@@ -76,7 +76,7 @@ static int __add_sem_handle (unsigned long key, IDTYPE semid,
|
||||
}
|
||||
|
||||
if (sid_head)
|
||||
listp_for_each_entry(tmp, sid_head, sid_hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, sid_head, sid_hlist)
|
||||
if (tmp->semid == semid) {
|
||||
if (key)
|
||||
tmp->semkey = key;
|
||||
@@ -115,15 +115,15 @@ static int __add_sem_handle (unsigned long key, IDTYPE semid,
|
||||
INIT_LISTP(&tmp->migrated);
|
||||
INIT_LIST_HEAD(tmp, list);
|
||||
get_handle(hdl);
|
||||
listp_add_tail(tmp, &sem_list, list);
|
||||
LISTP_ADD_TAIL(tmp, &sem_list, list);
|
||||
INIT_LIST_HEAD(tmp, key_hlist);
|
||||
if (key_head) {
|
||||
get_handle(hdl);
|
||||
listp_add(tmp, key_head, key_hlist);
|
||||
LISTP_ADD(tmp, key_head, key_hlist);
|
||||
}
|
||||
if (sid_head) {
|
||||
get_handle(hdl);
|
||||
listp_add(tmp, sid_head, sid_hlist);
|
||||
LISTP_ADD(tmp, sid_head, sid_hlist);
|
||||
}
|
||||
|
||||
out:
|
||||
@@ -155,7 +155,7 @@ struct shim_sem_handle * get_sem_handle_by_key (unsigned long key)
|
||||
|
||||
lock(&sem_list_lock);
|
||||
|
||||
listp_for_each_entry(tmp, key_head, key_hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, key_head, key_hlist)
|
||||
if (tmp->semkey == key) {
|
||||
found = tmp;
|
||||
break;
|
||||
@@ -175,7 +175,7 @@ struct shim_sem_handle * get_sem_handle_by_id (IDTYPE semid)
|
||||
|
||||
lock(&sem_list_lock);
|
||||
|
||||
listp_for_each_entry(tmp, sid_head, sid_hlist)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, sid_head, sid_hlist)
|
||||
if (tmp->semid == semid) {
|
||||
found = tmp;
|
||||
break;
|
||||
@@ -203,18 +203,18 @@ static int __del_sem_handle (struct shim_sem_handle * sem)
|
||||
struct shim_handle * hdl = SEM_TO_HANDLE(sem);
|
||||
|
||||
lock(&sem_list_lock);
|
||||
listp_del_init(sem, &sem_list, list);
|
||||
LISTP_DEL_INIT(sem, &sem_list, list);
|
||||
put_handle(hdl);
|
||||
if (!list_empty(sem, key_hlist)) {
|
||||
if (!LIST_EMPTY(sem, key_hlist)) {
|
||||
// DEP: Yuck
|
||||
LISTP_TYPE(shim_sem_handle) * key_head = &sem_key_hlist[SEM_HASH(sem->semkey)];
|
||||
listp_del_init(sem, key_head, key_hlist);
|
||||
LISTP_DEL_INIT(sem, key_head, key_hlist);
|
||||
put_handle(hdl);
|
||||
}
|
||||
if (!list_empty(sem, sid_hlist)) {
|
||||
if (!LIST_EMPTY(sem, sid_hlist)) {
|
||||
// DEP: Yuck
|
||||
LISTP_TYPE(shim_sem_handle) * sid_head = &sem_sid_hlist[SEM_HASH(sem->semid)];
|
||||
listp_del_init(sem, sid_head, sid_hlist);
|
||||
LISTP_DEL_INIT(sem, sid_head, sid_hlist);
|
||||
put_handle(hdl);
|
||||
}
|
||||
unlock(&sem_list_lock);
|
||||
@@ -342,7 +342,7 @@ int recover_sem_ownership (struct shim_sem_handle * sem,
|
||||
op->client.port = NULL;
|
||||
op->client.seq = clients[i].seq;
|
||||
INIT_LIST_HEAD(op, progress);
|
||||
listp_add_tail(op, &sem->migrated, progress);
|
||||
LISTP_ADD_TAIL(op, &sem->migrated, progress);
|
||||
}
|
||||
|
||||
sem->owned = true;
|
||||
@@ -501,15 +501,15 @@ static bool __handle_sysv_sems (struct shim_sem_handle * sem)
|
||||
|
||||
struct sem_obj * sobj;
|
||||
for (sobj = sem->sems ; sobj < &sem->sems[sem->nsems] ; sobj++)
|
||||
listp_splice_tail_init(&sobj->next_ops, &sobj->ops, progress, sem_ops);
|
||||
LISTP_SPLICE_TAIL_INIT(&sobj->next_ops, &sobj->ops, progress, sem_ops);
|
||||
|
||||
for (sobj = sem->sems ; sobj < &sem->sems[sem->nsems] ; sobj++) {
|
||||
struct sem_ops * sops, * n;
|
||||
|
||||
listp_for_each_entry_safe(sops, n, &sobj->ops, progress) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(sops, n, &sobj->ops, progress) {
|
||||
struct sembuf * op = &sops->ops[sops->stat.current];
|
||||
assert(op->sem_num == sobj->num);
|
||||
// first_iter is a variable defined by listp_for_each_entry_safe
|
||||
// first_iter is a variable defined by LISTP_FOR_EACH_ENTRY_SAFE
|
||||
// The second part of this assertion is only valid after the first attempt
|
||||
assert(first_iter || (sops != n));
|
||||
if (sops->stat.completed)
|
||||
@@ -551,7 +551,7 @@ again:
|
||||
|
||||
op = &sops->ops[sops->stat.current];
|
||||
if (op->sem_num != sobj->num) {
|
||||
listp_move_tail(sops,
|
||||
LISTP_MOVE_TAIL(sops,
|
||||
&sem->sems[op->sem_num].next_ops,
|
||||
&sobj->ops,
|
||||
progress);
|
||||
@@ -565,7 +565,7 @@ failed:
|
||||
send_result:
|
||||
/* Chia-Che 10/17/17: If the code reaches this point, sops should
|
||||
* still be in sobj->ops. */
|
||||
listp_del_init(sops, &sobj->ops, progress);
|
||||
LISTP_DEL_INIT(sops, &sobj->ops, progress);
|
||||
sem->nreqs--;
|
||||
if (!sops->client.vmid) {
|
||||
setevent = true;
|
||||
@@ -773,10 +773,10 @@ unowned:
|
||||
if (seq) {
|
||||
struct sem_ops * op;
|
||||
|
||||
listp_for_each_entry(op, &sem->migrated, progress)
|
||||
LISTP_FOR_EACH_ENTRY(op, &sem->migrated, progress)
|
||||
if (op->client.vmid == (client ? client->vmid : cur_process.vmid)
|
||||
&& seq == op->client.seq) {
|
||||
listp_del_init(op, &sem->migrated, progress);
|
||||
LISTP_DEL_INIT(op, &sem->migrated, progress);
|
||||
sem_ops = op;
|
||||
stat = sem_ops->stat;
|
||||
malloced = true;
|
||||
@@ -833,9 +833,9 @@ unowned:
|
||||
|
||||
LISTP_TYPE(sem_ops) * next_ops =
|
||||
&sem->sems[sops[stat.current].sem_num].next_ops;
|
||||
assert(list_empty(sem_ops, progress));
|
||||
listp_add_tail(sem_ops, next_ops, progress);
|
||||
//check_list_head(next_ops);
|
||||
assert(LIST_EMPTY(sem_ops, progress));
|
||||
LISTP_ADD_TAIL(sem_ops, next_ops, progress);
|
||||
//CHECK_LIST_HEAD(next_ops);
|
||||
sem->nreqs++;
|
||||
SAVE_PROFILE_INTERVAL(sem_append_semop);
|
||||
|
||||
@@ -854,7 +854,7 @@ unowned:
|
||||
/* Chia-Che 10/17/17: sem_ops may move from semaphore to semaphore
|
||||
base on its current state */
|
||||
next_ops = &sem->sems[sem_ops->ops[sem_ops->stat.current].sem_num].next_ops;
|
||||
listp_del_init(sem_ops, next_ops, progress);
|
||||
LISTP_DEL_INIT(sem_ops, next_ops, progress);
|
||||
goto unowned;
|
||||
}
|
||||
|
||||
@@ -900,10 +900,10 @@ static int sem_balance_migrate (struct shim_handle * hdl,
|
||||
b->ncnt = sobj->ncnt;
|
||||
b->pid = sobj->pid;
|
||||
|
||||
listp_splice_tail(&sobj->next_ops, &sobj->ops, progress, sem_ops);
|
||||
LISTP_SPLICE_TAIL(&sobj->next_ops, &sobj->ops, progress, sem_ops);
|
||||
|
||||
struct sem_ops * sops;
|
||||
listp_for_each_entry(sops, &sobj->ops, progress) {
|
||||
LISTP_FOR_EACH_ENTRY(sops, &sobj->ops, progress) {
|
||||
assert(client_cnt < sem->nreqs);
|
||||
struct sem_client_backup * c = clients + (client_cnt)++;
|
||||
c->vmid = sops->client.vmid;
|
||||
@@ -932,8 +932,8 @@ static int sem_balance_migrate (struct shim_handle * hdl,
|
||||
|
||||
for (sobj = sem->sems ; sobj < &sem->sems[sem->nsems] ; sobj++) {
|
||||
struct sem_ops * sops, * n;
|
||||
listp_for_each_entry_safe(sops, n, &sobj->ops, progress) {
|
||||
listp_del_init(sops, &sobj->ops, progress);
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(sops, n, &sobj->ops, progress) {
|
||||
LISTP_DEL_INIT(sops, &sobj->ops, progress);
|
||||
sem->nreqs--;
|
||||
sops->stat.failed = true;
|
||||
if (!sops->client.vmid)
|
||||
|
||||
@@ -69,7 +69,7 @@ block_pid:
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!list_empty(thread, siblings)) {
|
||||
if (!LIST_EMPTY(thread, siblings)) {
|
||||
debug("reaping thread %p\n", thread);
|
||||
struct shim_thread * parent = thread->parent;
|
||||
assert(parent);
|
||||
@@ -77,7 +77,7 @@ block_pid:
|
||||
lock(&parent->lock);
|
||||
/* DEP 5/15/17: These threads are exited */
|
||||
assert(!thread->is_alive);
|
||||
listp_del_init(thread, &thread->parent->exited_children, siblings);
|
||||
LISTP_DEL_INIT(thread, &thread->parent->exited_children, siblings);
|
||||
unlock(&parent->lock);
|
||||
|
||||
put_thread(parent);
|
||||
@@ -91,8 +91,8 @@ block_pid:
|
||||
|
||||
lock(&cur->lock);
|
||||
|
||||
if (listp_empty(&cur->children) &&
|
||||
listp_empty(&cur->exited_children)) {
|
||||
if (LISTP_EMPTY(&cur->children) &&
|
||||
LISTP_EMPTY(&cur->exited_children)) {
|
||||
unlock(&cur->lock);
|
||||
return -ECHILD;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ block_pid:
|
||||
if (!(option & WNOHANG)) {
|
||||
block:
|
||||
if (cur->child_exit_event)
|
||||
while (listp_empty(&cur->exited_children)) {
|
||||
while (LISTP_EMPTY(&cur->exited_children)) {
|
||||
unlock(&cur->lock);
|
||||
object_wait_with_retry(cur->child_exit_event);
|
||||
lock(&cur->lock);
|
||||
@@ -111,15 +111,15 @@ block:
|
||||
if (pid == 0)
|
||||
pid = -cur->pgid;
|
||||
|
||||
listp_for_each_entry(thread, &cur->exited_children, siblings)
|
||||
LISTP_FOR_EACH_ENTRY(thread, &cur->exited_children, siblings)
|
||||
if (thread->pgid == -pid)
|
||||
goto found_child;
|
||||
|
||||
if (!(option & WNOHANG))
|
||||
goto block;
|
||||
} else {
|
||||
if (!listp_empty(&cur->exited_children)) {
|
||||
thread = listp_first_entry(&cur->exited_children,
|
||||
if (!LISTP_EMPTY(&cur->exited_children)) {
|
||||
thread = LISTP_FIRST_ENTRY(&cur->exited_children,
|
||||
struct shim_thread, siblings);
|
||||
goto found_child;
|
||||
}
|
||||
@@ -129,11 +129,11 @@ block:
|
||||
return 0;
|
||||
|
||||
found_child:
|
||||
listp_del_init(thread, &cur->exited_children, siblings);
|
||||
LISTP_DEL_INIT(thread, &cur->exited_children, siblings);
|
||||
put_thread(cur);
|
||||
thread->parent = NULL;
|
||||
|
||||
if (listp_empty(&cur->exited_children))
|
||||
if (LISTP_EMPTY(&cur->exited_children))
|
||||
DkEventClear(cur->child_exit_event);
|
||||
|
||||
unlock(&cur->lock);
|
||||
|
||||
+17
-17
@@ -60,7 +60,7 @@ static int __add_config (struct config_store * store,
|
||||
if (token[len] == '.')
|
||||
break;
|
||||
|
||||
listp_for_each_entry(e, list, siblings)
|
||||
LISTP_FOR_EACH_ENTRY(e, list, siblings)
|
||||
if (e->klen == len && !memcmp(e->key, token, len))
|
||||
goto next;
|
||||
|
||||
@@ -74,10 +74,10 @@ static int __add_config (struct config_store * store,
|
||||
e->vlen = 0;
|
||||
e->buf = NULL;
|
||||
INIT_LIST_HEAD(e, list);
|
||||
listp_add_tail(e, &store->entries, list);
|
||||
LISTP_ADD_TAIL(e, &store->entries, list);
|
||||
INIT_LISTP(&e->children);
|
||||
INIT_LIST_HEAD(e, siblings);
|
||||
listp_add_tail(e, list, siblings);
|
||||
LISTP_ADD_TAIL(e, list, siblings);
|
||||
if (parent)
|
||||
parent->vlen += (len + 1);
|
||||
|
||||
@@ -90,7 +90,7 @@ next:
|
||||
parent = e;
|
||||
}
|
||||
|
||||
if (!e || e->val || !listp_empty(&e->children))
|
||||
if (!e || e->val || !LISTP_EMPTY(&e->children))
|
||||
return -PAL_ERROR_INVAL;
|
||||
|
||||
e->val = val;
|
||||
@@ -115,7 +115,7 @@ static struct config * __get_config (struct config_store * store,
|
||||
if (token[len] == '.')
|
||||
break;
|
||||
|
||||
listp_for_each_entry(e, list, siblings)
|
||||
LISTP_FOR_EACH_ENTRY(e, list, siblings)
|
||||
if (e->klen == len && !memcmp(e->key, token, len))
|
||||
goto next;
|
||||
|
||||
@@ -158,7 +158,7 @@ int get_config_entries (struct config_store * store, const char * key,
|
||||
LISTP_TYPE(config) * children = &e->children;
|
||||
int nentries = 0;
|
||||
|
||||
listp_for_each_entry(e, children, siblings) {
|
||||
LISTP_FOR_EACH_ENTRY(e, children, siblings) {
|
||||
if (e->klen + 1 > key_bufsize)
|
||||
return -PAL_ERROR_TOOLONG;
|
||||
memcpy(key_buf, e->key, e->klen);
|
||||
@@ -192,7 +192,7 @@ static int __del_config (struct config_store * store,
|
||||
if (key[len] == '.')
|
||||
break;
|
||||
|
||||
listp_for_each_entry(e, root, siblings)
|
||||
LISTP_FOR_EACH_ENTRY(e, root, siblings)
|
||||
if (e->klen == len && !memcmp(e->key, key, len)) {
|
||||
found = e;
|
||||
break;
|
||||
@@ -207,7 +207,7 @@ static int __del_config (struct config_store * store,
|
||||
int ret = __del_config(store, &found->children, found, key + len + 1);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (!listp_empty(&found->children))
|
||||
if (!LISTP_EMPTY(&found->children))
|
||||
return 0;
|
||||
} else {
|
||||
if (!found->val)
|
||||
@@ -216,8 +216,8 @@ static int __del_config (struct config_store * store,
|
||||
|
||||
if (p)
|
||||
p->vlen -= (found->klen + 1);
|
||||
listp_del(found, root, siblings);
|
||||
listp_del(found, &store->entries, list);
|
||||
LISTP_DEL(found, root, siblings);
|
||||
LISTP_DEL(found, &store->entries, list);
|
||||
if (found->buf)
|
||||
store->free(found->buf);
|
||||
store->free(found);
|
||||
@@ -372,7 +372,7 @@ inval:
|
||||
int free_config (struct config_store * store)
|
||||
{
|
||||
struct config * e, * n;
|
||||
listp_for_each_entry_safe(e, n, &store->entries, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(e, n, &store->entries, list) {
|
||||
store->free(e->buf);
|
||||
store->free(e);
|
||||
}
|
||||
@@ -390,7 +390,7 @@ static int __dup_config (const struct config_store * ss,
|
||||
{
|
||||
struct config * e, * new;
|
||||
|
||||
listp_for_each_entry(e, sr, siblings) {
|
||||
LISTP_FOR_EACH_ENTRY(e, sr, siblings) {
|
||||
char * key = NULL, * val = NULL, * buf = NULL;
|
||||
int need = 0;
|
||||
|
||||
@@ -439,12 +439,12 @@ static int __dup_config (const struct config_store * ss,
|
||||
new->vlen = e->vlen;
|
||||
new->buf = buf;
|
||||
INIT_LIST_HEAD(new, list);
|
||||
listp_add_tail(new, &ts->entries, list);
|
||||
LISTP_ADD_TAIL(new, &ts->entries, list);
|
||||
INIT_LISTP(&new->children);
|
||||
INIT_LIST_HEAD(new, siblings);
|
||||
listp_add_tail(new, tr, siblings);
|
||||
LISTP_ADD_TAIL(new, tr, siblings);
|
||||
|
||||
if (!listp_empty(&e->children)) {
|
||||
if (!LISTP_EMPTY(&e->children)) {
|
||||
int ret = __dup_config(ss, &e->children,
|
||||
ts, &new->children,
|
||||
data, size);
|
||||
@@ -464,7 +464,7 @@ int copy_config (struct config_store * store, struct config_store * new_store)
|
||||
struct config * e;
|
||||
int size = 0;
|
||||
|
||||
listp_for_each_entry(e, &store->entries, list) {
|
||||
LISTP_FOR_EACH_ENTRY(e, &store->entries, list) {
|
||||
if (e->key)
|
||||
size += e->klen;
|
||||
if (e->val)
|
||||
@@ -497,7 +497,7 @@ static int __write_config (void * f, int (*write) (void *, void *, int),
|
||||
char * buf = NULL;
|
||||
int bufsz = 0;
|
||||
|
||||
listp_for_each_entry(e, root, siblings)
|
||||
LISTP_FOR_EACH_ENTRY(e, root, siblings)
|
||||
if (e->val) {
|
||||
int total = klen + e->klen + e->vlen + 2;
|
||||
|
||||
|
||||
+60
-60
@@ -48,7 +48,7 @@ int sol8[17] = {7, 5, 3, 1, 13, 12, 11, 10, 9, 8, 20, 19, 18, 17, 16, 15, 14};
|
||||
void print_list(LISTP_TYPE(simple) *listp) {
|
||||
struct simple *tmp;
|
||||
printf("Beginning of list\n");
|
||||
listp_for_each_entry(tmp, listp, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tmp, listp, list) {
|
||||
printf("List element %d\n", tmp->idx);
|
||||
}
|
||||
printf("End of list\n\n");
|
||||
@@ -58,8 +58,8 @@ void assert_list(LISTP_TYPE(simple) *listp, int len, int *array, int stop_early_
|
||||
int j = 0;
|
||||
struct simple *tmp;
|
||||
int stop_early = 0;
|
||||
check_list_head(struct simple *, listp, list);
|
||||
listp_for_each_entry(tmp, listp, list) {
|
||||
CHECK_LIST_HEAD(struct simple *, listp, list);
|
||||
LISTP_FOR_EACH_ENTRY(tmp, listp, list) {
|
||||
if (j >= len) {
|
||||
stop_early = 1;
|
||||
break;
|
||||
@@ -78,7 +78,7 @@ void assert_list(LISTP_TYPE(simple) *listp, int len, int *array, int stop_early_
|
||||
void print_list_reverse(LISTP_TYPE(simple) *listp) {
|
||||
struct simple *tmp;
|
||||
printf("Beginning of list\n");
|
||||
listp_for_each_entry_reverse(tmp, listp, list) {
|
||||
LISTP_FOR_EACH_ENTRY_REVERSE(tmp, listp, list) {
|
||||
printf("List element %d\n", tmp->idx);
|
||||
}
|
||||
printf("End of list\n\n");
|
||||
@@ -89,7 +89,7 @@ int main() {
|
||||
int i;
|
||||
struct simple *tmp, *tmp2, *n;
|
||||
|
||||
assert(listp_empty(&list_in_the_sky));
|
||||
assert(LISTP_EMPTY(&list_in_the_sky));
|
||||
|
||||
/* Try printing an empty list */
|
||||
print_list(&list_in_the_sky);
|
||||
@@ -99,24 +99,24 @@ int main() {
|
||||
tmp = malloc(sizeof(struct simple));
|
||||
tmp->idx = 7 - i;
|
||||
INIT_LIST_HEAD(tmp, list);
|
||||
assert(list_empty(tmp, list));
|
||||
listp_add(tmp, &list_in_the_sky, list);
|
||||
assert(!list_empty(tmp, list));
|
||||
assert(LIST_EMPTY(tmp, list));
|
||||
LISTP_ADD(tmp, &list_in_the_sky, list);
|
||||
assert(!LIST_EMPTY(tmp, list));
|
||||
assert_list(&list_in_the_sky, i, &sol1[6-i], 1);
|
||||
}
|
||||
assert(!listp_empty(&list_in_the_sky));
|
||||
assert(!LISTP_EMPTY(&list_in_the_sky));
|
||||
|
||||
assert_list(&list_in_the_sky, 7, sol1, 0);
|
||||
|
||||
/* Test list_add - i.e., adding things in the middle of the list*/
|
||||
listp_for_each_entry_safe(tmp, n, &list_in_the_sky, list) {
|
||||
/* Test LIST_ADD - i.e., adding things in the middle of the list*/
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &list_in_the_sky, list) {
|
||||
if ((tmp->idx % 2) == 0) {
|
||||
tmp2 = malloc(sizeof(struct simple));
|
||||
tmp2->idx = (tmp->idx * 10) + 5;
|
||||
INIT_LIST_HEAD(tmp2, list);
|
||||
assert(list_empty(tmp2, list));
|
||||
list_add(tmp2, tmp, list);
|
||||
assert(!list_empty(tmp2, list));
|
||||
assert(LIST_EMPTY(tmp2, list));
|
||||
LIST_ADD(tmp2, tmp, list);
|
||||
assert(!LIST_EMPTY(tmp2, list));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,16 +129,16 @@ int main() {
|
||||
tmp = malloc(sizeof(struct simple));
|
||||
tmp->idx = 8 + i;
|
||||
INIT_LIST_HEAD(tmp, list);
|
||||
assert(list_empty(tmp, list));
|
||||
listp_add_tail(tmp, &list_in_the_sky, list);
|
||||
assert(!list_empty(tmp, list));
|
||||
assert(LIST_EMPTY(tmp, list));
|
||||
LISTP_ADD_TAIL(tmp, &list_in_the_sky, list);
|
||||
assert(!LIST_EMPTY(tmp, list));
|
||||
}
|
||||
assert(!listp_empty(&list_in_the_sky));
|
||||
assert(!LISTP_EMPTY(&list_in_the_sky));
|
||||
|
||||
assert_list(&list_in_the_sky, 17, sol3, 0);
|
||||
|
||||
/* Test list_add_tail by adding ints from end */
|
||||
listp_for_each_entry(tmp, &list_in_the_sky, list) {
|
||||
/* Test LIST_ADD_TAIL by adding ints from end */
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &list_in_the_sky, list) {
|
||||
if (tmp->idx <= 7 || tmp->idx > 20)
|
||||
continue;
|
||||
|
||||
@@ -146,9 +146,9 @@ int main() {
|
||||
tmp2 = malloc(sizeof(struct simple));
|
||||
tmp2->idx = ((tmp->idx - 1) * 10) + 5;
|
||||
INIT_LIST_HEAD(tmp2, list);
|
||||
assert(list_empty(tmp2, list));
|
||||
list_add_tail(tmp2, tmp, list);
|
||||
assert(!list_empty(tmp2, list));
|
||||
assert(LIST_EMPTY(tmp2, list));
|
||||
LIST_ADD_TAIL(tmp2, tmp, list);
|
||||
assert(!LIST_EMPTY(tmp2, list));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,12 +159,12 @@ int main() {
|
||||
printf("Deletion test starting\n\n");
|
||||
|
||||
/* Test list deletion and safe iteration by destroying the list*/
|
||||
listp_for_each_entry_safe(tmp, n, &list_in_the_sky, list) {
|
||||
listp_del(tmp, &list_in_the_sky, list);
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &list_in_the_sky, list) {
|
||||
LISTP_DEL(tmp, &list_in_the_sky, list);
|
||||
free(tmp);
|
||||
//print_list(&list_in_the_sky);
|
||||
}
|
||||
assert(listp_empty(&list_in_the_sky));
|
||||
assert(LISTP_EMPTY(&list_in_the_sky));
|
||||
|
||||
printf("Deletion test Ending\n\n");
|
||||
|
||||
@@ -173,29 +173,29 @@ int main() {
|
||||
tmp = malloc(sizeof(struct simple));
|
||||
tmp->idx = 7 - i;
|
||||
INIT_LIST_HEAD(tmp, list);
|
||||
assert(list_empty(tmp, list));
|
||||
listp_add(tmp, &list_in_the_sky, list);
|
||||
assert(!list_empty(tmp, list));
|
||||
assert(LIST_EMPTY(tmp, list));
|
||||
LISTP_ADD(tmp, &list_in_the_sky, list);
|
||||
assert(!LIST_EMPTY(tmp, list));
|
||||
}
|
||||
assert(!listp_empty(&list_in_the_sky));
|
||||
assert(!LISTP_EMPTY(&list_in_the_sky));
|
||||
|
||||
printf("Deletion test 2 starting\n\n");
|
||||
|
||||
/* Test listp_del_init by migrating to another list */
|
||||
listp_for_each_entry_safe(tmp, n, &list_in_the_sky, list) {
|
||||
listp_del(tmp, &list_in_the_sky, list);
|
||||
listp_add(tmp, &list_in_the_basement, list);
|
||||
/* Test LISTP_DEL_INIT by migrating to another list */
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &list_in_the_sky, list) {
|
||||
LISTP_DEL(tmp, &list_in_the_sky, list);
|
||||
LISTP_ADD(tmp, &list_in_the_basement, list);
|
||||
//print_list(&list_in_the_sky);
|
||||
//print_list(&list_in_the_basement);
|
||||
}
|
||||
|
||||
//print_list(&list_in_the_sky);
|
||||
//print_list(&list_in_the_basement);
|
||||
assert(listp_empty(&list_in_the_sky));
|
||||
assert(LISTP_EMPTY(&list_in_the_sky));
|
||||
assert_list(&list_in_the_basement, 7, sol5, 0);
|
||||
|
||||
/* Test listp_first_entry, for funzies */
|
||||
assert(listp_first_entry(&list_in_the_basement, simple, list)->idx == 7);
|
||||
/* Test LISTP_FIRST_ENTRY, for funzies */
|
||||
assert(LISTP_FIRST_ENTRY(&list_in_the_basement, simple, list)->idx == 7);
|
||||
|
||||
/*
|
||||
printf("List in the sky:\n");
|
||||
@@ -213,13 +213,13 @@ int main() {
|
||||
|
||||
printf("Deletion test 2 Ending\n\n");
|
||||
|
||||
/* Test listp_for_each_entry_safe_continue; stop on 4
|
||||
/* Test LISTP_FOR_EACH_ENTRY_SAFE_CONTINUE; stop on 4
|
||||
* after deleting 6 and 4, break, and continue.
|
||||
* */
|
||||
listp_for_each_entry_safe(tmp, n, &list_in_the_basement, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &list_in_the_basement, list) {
|
||||
if (0 == (tmp->idx % 2)) {
|
||||
int idx = tmp->idx;
|
||||
listp_del(tmp, &list_in_the_basement, list);
|
||||
LISTP_DEL(tmp, &list_in_the_basement, list);
|
||||
// NB: The continue pointer needs to be valid (will probably work
|
||||
// by accident even if 4 isn't freed, so better to leak one node
|
||||
if (idx == 4)
|
||||
@@ -232,16 +232,16 @@ int main() {
|
||||
|
||||
//printf("Continuing\n");
|
||||
|
||||
listp_for_each_entry_safe_continue(tmp, n, &list_in_the_basement, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE_CONTINUE(tmp, n, &list_in_the_basement, list) {
|
||||
if (0 == (tmp->idx % 2)) {
|
||||
listp_del(tmp, &list_in_the_basement, list);
|
||||
LISTP_DEL(tmp, &list_in_the_basement, list);
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
//print_list(&list_in_the_sky);
|
||||
//print_list(&list_in_the_basement);
|
||||
assert(listp_empty(&list_in_the_sky));
|
||||
assert(LISTP_EMPTY(&list_in_the_sky));
|
||||
assert_list(&list_in_the_basement, 4, sol6, 0);
|
||||
|
||||
/* Test list_splice variants. Rebuild sky list again */
|
||||
@@ -250,24 +250,24 @@ int main() {
|
||||
tmp = malloc(sizeof(struct simple));
|
||||
tmp->idx = i;
|
||||
INIT_LIST_HEAD(tmp, list);
|
||||
assert(list_empty(tmp, list));
|
||||
listp_add(tmp, &list_in_the_sky, list);
|
||||
assert(!list_empty(tmp, list));
|
||||
assert(LIST_EMPTY(tmp, list));
|
||||
LISTP_ADD(tmp, &list_in_the_sky, list);
|
||||
assert(!LIST_EMPTY(tmp, list));
|
||||
}
|
||||
assert(!listp_empty(&list_in_the_sky));
|
||||
assert(!LISTP_EMPTY(&list_in_the_sky));
|
||||
|
||||
printf("Begin splice tests \n\n");
|
||||
|
||||
/* Test listp splice */
|
||||
listp_splice_init(&list_in_the_basement, &list_in_the_sky, list, simple);
|
||||
LISTP_SPLICE_INIT(&list_in_the_basement, &list_in_the_sky, list, simple);
|
||||
|
||||
assert(listp_empty(&list_in_the_basement));
|
||||
assert(LISTP_EMPTY(&list_in_the_basement));
|
||||
assert_list(&list_in_the_sky, 10, sol7, 0);
|
||||
|
||||
listp_splice(&list_in_the_sky, &list_in_the_basement, list, simple);
|
||||
LISTP_SPLICE(&list_in_the_sky, &list_in_the_basement, list, simple);
|
||||
INIT_LISTP(&list_in_the_sky);
|
||||
|
||||
assert(listp_empty(&list_in_the_sky));
|
||||
assert(LISTP_EMPTY(&list_in_the_sky));
|
||||
assert_list(&list_in_the_basement, 10, sol7, 0);
|
||||
|
||||
/* Test splicing onto the tail */
|
||||
@@ -276,14 +276,14 @@ int main() {
|
||||
tmp = malloc(sizeof(struct simple));
|
||||
tmp->idx = i;
|
||||
INIT_LIST_HEAD(tmp, list);
|
||||
assert(list_empty(tmp, list));
|
||||
listp_add(tmp, &list_in_the_sky, list);
|
||||
assert(!list_empty(tmp, list));
|
||||
assert(LIST_EMPTY(tmp, list));
|
||||
LISTP_ADD(tmp, &list_in_the_sky, list);
|
||||
assert(!LIST_EMPTY(tmp, list));
|
||||
}
|
||||
assert(!listp_empty(&list_in_the_sky));
|
||||
assert(!LISTP_EMPTY(&list_in_the_sky));
|
||||
|
||||
|
||||
listp_splice_tail(&list_in_the_sky, &list_in_the_basement, list, simple);
|
||||
LISTP_SPLICE_TAIL(&list_in_the_sky, &list_in_the_basement, list, simple);
|
||||
INIT_LISTP(&list_in_the_sky);
|
||||
|
||||
/*
|
||||
@@ -299,12 +299,12 @@ int main() {
|
||||
|
||||
printf("Before list move test \n\n");
|
||||
|
||||
/* Test listp_move_tail */
|
||||
listp_for_each_entry_safe(tmp, n, &list_in_the_basement, list) {
|
||||
listp_move_tail(tmp, &list_in_the_sky, &list_in_the_basement, list);
|
||||
/* Test LISTP_MOVE_TAIL */
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &list_in_the_basement, list) {
|
||||
LISTP_MOVE_TAIL(tmp, &list_in_the_sky, &list_in_the_basement, list);
|
||||
}
|
||||
|
||||
assert(listp_empty(&list_in_the_basement));
|
||||
assert(LISTP_EMPTY(&list_in_the_basement));
|
||||
assert_list(&list_in_the_sky, 17, sol8, 0);
|
||||
|
||||
printf("After list move test \n\n");
|
||||
|
||||
+75
-75
@@ -60,12 +60,12 @@
|
||||
*
|
||||
* -----
|
||||
*
|
||||
* From here, you can use listp_add variants to add an object from the list:
|
||||
* From here, you can use LISTP_ADD variants to add an object from the list:
|
||||
*
|
||||
* struct foo *f = malloc(sizeof(struct foo));
|
||||
* f->x = 1;
|
||||
* INIT_LIST_HEAD(f, list); // The second parameter is the structure member
|
||||
* listp_add(f, &the_list, list);
|
||||
* LISTP_ADD(f, &the_list, list);
|
||||
*
|
||||
* -----
|
||||
*
|
||||
@@ -75,37 +75,37 @@
|
||||
* You can search for an object using a variant of listp_for_each_entry. The
|
||||
* safe variants are safe against deletion.
|
||||
*
|
||||
* You can remove an object from a list using listp_del.
|
||||
* You can remove an object from a list using LISTP_DEL.
|
||||
*
|
||||
* In this example, we delete everything with a key bigger than 5.
|
||||
*
|
||||
* LIST_TYPE(foo) *f, *n; // n is not used, just for scratch space
|
||||
* listp_for_each_entry_safe(f, n, &the_list, list) {
|
||||
* LISTP_FOR_EACH_ENTRY_SAFE(f, n, &the_list, list) {
|
||||
* if (f->x > 4) {
|
||||
* listp_del(f, &the_list, list);
|
||||
* LISTP_DEL(f, &the_list, list);
|
||||
* free(f);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*
|
||||
* listp_splice moves an entire listp onto another, and list_move_tail takes
|
||||
* LISTP_SPLICE moves an entire listp onto another, and list_move_tail takes
|
||||
* an element off of one list and places it on another.
|
||||
*
|
||||
* static LISTP_TYPE(foo) other_list; // Assume it is full of goodies
|
||||
* // Move everything on other_list to the_list
|
||||
* listp_splice_tail(&other_list, &the_list, list, foo); // the third argument
|
||||
* LISTP_SPLICE_TAIL(&other_list, &the_list, list, foo); // the third argument
|
||||
* // is the field; the
|
||||
* // fourth is the type
|
||||
* // of the nodes (not
|
||||
* // the head pointer).
|
||||
*
|
||||
* // Use listp_empty to test for emptiness of the list
|
||||
* assert(listp_empty(&other_ist));
|
||||
* // Use LISTP_EMPTY to test for emptiness of the list
|
||||
* assert(LISTP_EMPTY(&other_ist));
|
||||
*
|
||||
* // Now move back anythign less than 6 back to other_list
|
||||
* listp_for_each_entry_safe(f, n, &the_list, list) {
|
||||
* LISTP_FOR_EACH_ENTRY_SAFE(f, n, &the_list, list) {
|
||||
* if (f->x < 6)
|
||||
* listp_move_tail(f, &other_list, &the_list, list);
|
||||
* LISTP_MOVE_TAIL(f, &other_list, &the_list, list);
|
||||
* }
|
||||
*
|
||||
*/
|
||||
@@ -123,22 +123,22 @@
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <assert.h>
|
||||
#define LIST_ASSERT(cond) assert(cond)
|
||||
#define LIST_ASSERT(COND) assert(COND)
|
||||
#else
|
||||
#define LIST_ASSERT(cond)
|
||||
#define LIST_ASSERT(COND)
|
||||
#endif
|
||||
|
||||
/* For these macros, do not include the string 'struct' */
|
||||
#define LIST_TYPE(STRUCT) struct list_head ##_## STRUCT
|
||||
#define LISTP_TYPE(STRUCT) struct listp ##_## STRUCT
|
||||
#define LIST_TYPE(STRUCT_NAME) struct list_head##_##STRUCT_NAME
|
||||
#define LISTP_TYPE(STRUCT_NAME) struct listp##_##STRUCT_NAME
|
||||
|
||||
/* Declare the enclosing struct for convenience, on
|
||||
* the assumption that this is primarily used in structure
|
||||
* definitions, and harmless if duplicated. */
|
||||
#define DEFINE_LIST(STRUCT) \
|
||||
struct STRUCT; \
|
||||
LIST_TYPE(STRUCT) { \
|
||||
struct STRUCT *next, *prev; \
|
||||
#define DEFINE_LIST(STRUCT_NAME) \
|
||||
struct STRUCT_NAME; \
|
||||
LIST_TYPE(STRUCT_NAME) { \
|
||||
struct STRUCT_NAME* next; \
|
||||
struct STRUCT_NAME* prev; \
|
||||
}
|
||||
|
||||
/* We use LISTP for pointers to a list. This project only really needs
|
||||
@@ -147,7 +147,7 @@
|
||||
* lists. */
|
||||
#define DEFINE_LISTP(STRUCT) \
|
||||
LISTP_TYPE(STRUCT) { \
|
||||
struct STRUCT * first; \
|
||||
struct STRUCT* first; \
|
||||
}
|
||||
|
||||
#define LISTP_INIT {NULL}
|
||||
@@ -164,14 +164,14 @@
|
||||
(OBJECT)->first = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define listp_empty(HEAD) ((HEAD)->first == NULL)
|
||||
#define LISTP_EMPTY(HEAD) ((HEAD)->first == NULL)
|
||||
|
||||
#define list_empty(NODE, FIELD) \
|
||||
#define LIST_EMPTY(NODE, FIELD) \
|
||||
((NODE)->FIELD.next == NULL)
|
||||
|
||||
/* This helper takes 3 arguments - all should be containing structures,
|
||||
* and the field to use for the offset to the list node */
|
||||
#define __list_add(NEW, NEXT, PREV, FIELD) do { \
|
||||
#define __LIST_ADD(NEW, NEXT, PREV, FIELD) do { \
|
||||
__typeof__(NEW) __tmp_next = (NEXT); \
|
||||
__typeof__(NEW) __tmp_prev = (PREV); \
|
||||
__tmp_prev->FIELD.next = (NEW); \
|
||||
@@ -180,45 +180,45 @@
|
||||
(NEW)->FIELD.prev = __tmp_prev; \
|
||||
} while (0)
|
||||
|
||||
#define list_add(NEW, HEAD, FIELD) \
|
||||
__list_add(NEW, (HEAD)->FIELD.next, HEAD, FIELD)
|
||||
#define LIST_ADD(NEW, HEAD, FIELD) \
|
||||
__LIST_ADD(NEW, (HEAD)->FIELD.next, HEAD, FIELD)
|
||||
|
||||
#define listp_add(NEW, HEAD, FIELD) do { \
|
||||
#define LISTP_ADD(NEW, HEAD, FIELD) do { \
|
||||
if ((HEAD)->first == NULL) { \
|
||||
(HEAD)->first = (NEW); \
|
||||
(NEW)->FIELD.next = (NEW); \
|
||||
(NEW)->FIELD.prev = (NEW); \
|
||||
} else { \
|
||||
__list_add(NEW, (HEAD)->first, (HEAD)->first->FIELD.prev, FIELD); \
|
||||
__LIST_ADD(NEW, (HEAD)->first, (HEAD)->first->FIELD.prev, FIELD); \
|
||||
(HEAD)->first = (NEW); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* If NODE is defined, add NEW after NODE; if not,
|
||||
* put NEW at the front of the list */
|
||||
#define listp_add_after(NEW, NODE, HEAD, FIELD) do { \
|
||||
if (NODE) \
|
||||
list_add(NEW, NODE, FIELD); \
|
||||
else \
|
||||
listp_add(NEW, HEAD, FIELD); \
|
||||
#define LISTP_ADD_AFTER(NEW, NODE, HEAD, FIELD) do { \
|
||||
if (NODE) \
|
||||
LIST_ADD(NEW, NODE, FIELD); \
|
||||
else \
|
||||
LISTP_ADD(NEW, HEAD, FIELD); \
|
||||
} while(0)
|
||||
|
||||
#define list_add_tail(NEW, HEAD, FIELD) \
|
||||
__list_add(NEW, HEAD, (HEAD)->FIELD.prev, FIELD)
|
||||
#define LIST_ADD_TAIL(NEW, HEAD, FIELD) \
|
||||
__LIST_ADD(NEW, HEAD, (HEAD)->FIELD.prev, FIELD)
|
||||
|
||||
#define listp_add_tail(NEW, HEAD, FIELD) do { \
|
||||
#define LISTP_ADD_TAIL(NEW, HEAD, FIELD) do { \
|
||||
if ((HEAD)->first == NULL) { \
|
||||
(HEAD)->first = (NEW); \
|
||||
(NEW)->FIELD.next = (NEW); \
|
||||
(NEW)->FIELD.prev = (NEW); \
|
||||
} else \
|
||||
list_add_tail(NEW, (HEAD)->first, FIELD); \
|
||||
LIST_ADD_TAIL(NEW, (HEAD)->first, FIELD); \
|
||||
} while (0)
|
||||
|
||||
/* Or deletion needs to know the list root */
|
||||
#define listp_del(NODE, HEAD, FIELD) do { \
|
||||
#define LISTP_DEL(NODE, HEAD, FIELD) do { \
|
||||
if ((HEAD)->first == (NODE)) { \
|
||||
if ((NODE)->FIELD.next == (NODE)) { \
|
||||
if ((NODE)->FIELD.next == (NODE)) { \
|
||||
(HEAD)->first = NULL; \
|
||||
} else { \
|
||||
(HEAD)->first = (NODE)->FIELD.next; \
|
||||
@@ -230,37 +230,37 @@
|
||||
(NODE)->FIELD.next->FIELD.prev = (NODE)->FIELD.prev; \
|
||||
} while(0)
|
||||
|
||||
#define listp_del_init(NODE, HEAD, FIELD) do { \
|
||||
listp_del(NODE, HEAD, FIELD); \
|
||||
#define LISTP_DEL_INIT(NODE, HEAD, FIELD) do { \
|
||||
LISTP_DEL(NODE, HEAD, FIELD); \
|
||||
INIT_LIST_HEAD(NODE, FIELD); \
|
||||
} while(0)
|
||||
|
||||
/* Keep vestigial TYPE and FIELD parameters to minimize disruption
|
||||
* when switching from Linux list implementation */
|
||||
#define listp_first_entry(LISTP, TYPE, FIELD) ((LISTP)->first)
|
||||
#define LISTP_FIRST_ENTRY(LISTP, TYPE, FIELD) ((LISTP)->first)
|
||||
|
||||
/* New API: return last entry in list */
|
||||
#define listp_last_entry(LISTP, TYPE, FIELD) ((LISTP)->first->FIELD.prev)
|
||||
#define LISTP_LAST_ENTRY(LISTP, TYPE, FIELD) ((LISTP)->first->FIELD.prev)
|
||||
|
||||
/* New API: return next entry in list */
|
||||
#define listp_next_entry(NODE, LISTP, FIELD) \
|
||||
#define LISTP_NEXT_ENTRY(NODE, LISTP, FIELD) \
|
||||
((NODE) == (LISTP)->first->FIELD.prev ? NULL : (NODE)->FIELD.next)
|
||||
|
||||
/* New API: return previous entry in list */
|
||||
#define listp_prev_entry(NODE, LISTP, FIELD) \
|
||||
#define LISTP_PREV_ENTRY(NODE, LISTP, FIELD) \
|
||||
((NODE) == (LISTP)->first ? NULL : (NODE)->FIELD.prev)
|
||||
|
||||
/* Vestigial - for compat with Linux list code; rename to listp?
|
||||
*/
|
||||
#define list_entry(LISTP, TYPE, FIELD) (LISTP)
|
||||
#define LIST_ENTRY(LISTP, TYPE, FIELD) (LISTP)
|
||||
|
||||
#define listp_for_each_entry(CURSOR, HEAD, FIELD) \
|
||||
#define LISTP_FOR_EACH_ENTRY(CURSOR, HEAD, FIELD) \
|
||||
for (bool first_iter = ((CURSOR) = (HEAD)->first, \
|
||||
!!(HEAD)->first); \
|
||||
first_iter || (CURSOR) != (HEAD)->first; \
|
||||
(CURSOR) = (CURSOR)->FIELD.next, first_iter = false)
|
||||
|
||||
#define listp_for_each_entry_reverse(CURSOR, HEAD, FIELD) \
|
||||
#define LISTP_FOR_EACH_ENTRY_REVERSE(CURSOR, HEAD, FIELD) \
|
||||
for (bool first_iter = ((CURSOR) = ((HEAD)->first \
|
||||
? (HEAD)->first->FIELD.prev \
|
||||
: (HEAD)->first), \
|
||||
@@ -268,7 +268,7 @@
|
||||
first_iter || ((CURSOR) && (CURSOR)->FIELD.next != (HEAD)->first); \
|
||||
(CURSOR) = (CURSOR)->FIELD.prev, first_iter = false)
|
||||
|
||||
#define listp_for_each_entry_safe(CURSOR, TMP, HEAD, FIELD) \
|
||||
#define LISTP_FOR_EACH_ENTRY_SAFE(CURSOR, TMP, HEAD, FIELD) \
|
||||
for (bool first_iter = ((CURSOR) = (HEAD)->first, \
|
||||
(TMP) = ((CURSOR) \
|
||||
? (CURSOR)->FIELD.next \
|
||||
@@ -281,7 +281,7 @@
|
||||
(TMP) = (TMP)->FIELD.next)
|
||||
|
||||
/* Continue safe iteration with CURSOR->next */
|
||||
#define listp_for_each_entry_safe_continue(CURSOR, TMP, HEAD, FIELD) \
|
||||
#define LISTP_FOR_EACH_ENTRY_SAFE_CONTINUE(CURSOR, TMP, HEAD, FIELD) \
|
||||
for ((CURSOR) = (CURSOR)->FIELD.next, \
|
||||
(TMP) = (CURSOR)->FIELD.next; \
|
||||
(CURSOR) != (HEAD)->first && (HEAD)->first; \
|
||||
@@ -289,10 +289,10 @@
|
||||
(TMP) = (TMP)->FIELD.next)
|
||||
|
||||
/* Assertion code written in Graphene project */
|
||||
#define check_list_head(TYPE, head, FIELD) \
|
||||
#define CHECK_LIST_HEAD(TYPE, HEAD, FIELD) \
|
||||
do { \
|
||||
TYPE pos; \
|
||||
listp_for_each_entry(pos, head, FIELD) { \
|
||||
LISTP_FOR_EACH_ENTRY(pos, HEAD, FIELD) { \
|
||||
assert((pos->FIELD.prev != pos && pos->FIELD.next != pos) \
|
||||
|| (pos->FIELD.prev == pos && pos->FIELD.next == pos)); \
|
||||
assert(pos->FIELD.prev->FIELD.next == pos); \
|
||||
@@ -302,16 +302,16 @@
|
||||
|
||||
// Add NEW to OLD at position first (assuming first is all we need for now)
|
||||
// Can probably drop TYPE with some preprocessor smarts
|
||||
#define listp_splice(NEW, OLD, FIELD, TYPE) do { \
|
||||
if(!listp_empty(NEW)) { \
|
||||
if(listp_empty(OLD)) { \
|
||||
#define LISTP_SPLICE(NEW, OLD, FIELD, TYPE) do { \
|
||||
if(!LISTP_EMPTY(NEW)) { \
|
||||
if(LISTP_EMPTY(OLD)) { \
|
||||
(OLD)->first = (NEW)->first; \
|
||||
} else { \
|
||||
struct TYPE *last_old = (OLD)->first->FIELD.prev; \
|
||||
(OLD)->first->FIELD.prev->FIELD.next = (NEW)->first; \
|
||||
(OLD)->first->FIELD.prev = (NEW)->first->FIELD.prev; \
|
||||
(NEW)->first->FIELD.prev->FIELD.next = (OLD)->first; \
|
||||
(NEW)->first->FIELD.prev = last_old; \
|
||||
struct TYPE* last_old = (OLD)->first->FIELD.prev; \
|
||||
(OLD)->first->FIELD.prev->FIELD.next = (NEW)->first; \
|
||||
(OLD)->first->FIELD.prev = (NEW)->first->FIELD.prev; \
|
||||
(NEW)->first->FIELD.prev->FIELD.next = (OLD)->first; \
|
||||
(NEW)->first->FIELD.prev = last_old; \
|
||||
(OLD)->first = (NEW)->first; \
|
||||
} \
|
||||
} \
|
||||
@@ -319,35 +319,35 @@
|
||||
|
||||
// Add NEW to OLD at last position
|
||||
// Can probably drop TYPE with some preprocessor smarts
|
||||
#define listp_splice_tail(NEW, OLD, FIELD, TYPE) do { \
|
||||
if(!listp_empty(NEW)) { \
|
||||
if(listp_empty(OLD)) { \
|
||||
#define LISTP_SPLICE_TAIL(NEW, OLD, FIELD, TYPE) do { \
|
||||
if(!LISTP_EMPTY(NEW)) { \
|
||||
if(LISTP_EMPTY(OLD)) { \
|
||||
(OLD)->first = (NEW)->first; \
|
||||
} else { \
|
||||
struct TYPE *last_old = (OLD)->first->FIELD.prev; \
|
||||
last_old->FIELD.next = (NEW)->first; \
|
||||
(OLD)->first->FIELD.prev = (NEW)->first->FIELD.prev; \
|
||||
(NEW)->first->FIELD.prev->FIELD.next = (OLD)->first; \
|
||||
(NEW)->first->FIELD.prev = last_old; \
|
||||
struct TYPE* last_old = (OLD)->first->FIELD.prev; \
|
||||
last_old->FIELD.next = (NEW)->first; \
|
||||
(OLD)->first->FIELD.prev = (NEW)->first->FIELD.prev; \
|
||||
(NEW)->first->FIELD.prev->FIELD.next = (OLD)->first; \
|
||||
(NEW)->first->FIELD.prev = last_old; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define listp_splice_init(NEW, OLD, FIELD, TYPE) do { \
|
||||
listp_splice(NEW, OLD, FIELD, TYPE); \
|
||||
#define LISTP_SPLICE_INIT(NEW, OLD, FIELD, TYPE) do { \
|
||||
LISTP_SPLICE(NEW, OLD, FIELD, TYPE); \
|
||||
INIT_LISTP(NEW); \
|
||||
} while(0);
|
||||
|
||||
|
||||
#define listp_splice_tail_init(NEW, OLD, FIELD, TYPE) do { \
|
||||
listp_splice_tail(NEW, OLD, FIELD, TYPE); \
|
||||
#define LISTP_SPLICE_TAIL_INIT(NEW, OLD, FIELD, TYPE) do { \
|
||||
LISTP_SPLICE_TAIL(NEW, OLD, FIELD, TYPE); \
|
||||
INIT_LISTP(NEW); \
|
||||
} while(0);
|
||||
|
||||
// list_move_tail - delete from OLD, make tail of NEW
|
||||
#define listp_move_tail(NODE, NEW, OLD, FIELD) do { \
|
||||
listp_del_init(NODE, OLD, FIELD); \
|
||||
listp_add_tail(NODE, NEW, FIELD); \
|
||||
#define LISTP_MOVE_TAIL(NODE, NEW, OLD, FIELD) do { \
|
||||
LISTP_DEL_INIT(NODE, OLD, FIELD); \
|
||||
LISTP_ADD_TAIL(NODE, NEW, FIELD); \
|
||||
} while (0)
|
||||
|
||||
|
||||
|
||||
+20
-20
@@ -133,7 +133,7 @@ static inline MEM_MGR create_mem_mgr (unsigned int size)
|
||||
|
||||
INIT_LIST_HEAD(area, __list);
|
||||
INIT_LISTP(&mgr->area_list);
|
||||
listp_add(area, &mgr->area_list, __list);
|
||||
LISTP_ADD(area, &mgr->area_list, __list);
|
||||
|
||||
INIT_LISTP(&mgr->free_list);
|
||||
__set_free_mem_area(area, mgr);
|
||||
@@ -153,7 +153,7 @@ static inline MEM_MGR enlarge_mem_mgr (MEM_MGR mgr, unsigned int size)
|
||||
SYSTEM_LOCK();
|
||||
area->size = size;
|
||||
INIT_LIST_HEAD(area, __list);
|
||||
listp_add(area, &mgr->area_list, __list);
|
||||
LISTP_ADD(area, &mgr->area_list, __list);
|
||||
__set_free_mem_area(area, mgr);
|
||||
SYSTEM_UNLOCK();
|
||||
return mgr;
|
||||
@@ -163,13 +163,13 @@ static inline void destroy_mem_mgr (MEM_MGR mgr)
|
||||
{
|
||||
MEM_AREA tmp, n, first = NULL;
|
||||
|
||||
first = tmp = listp_first_entry(&mgr->area_list, MEM_AREA_TYPE, __list);
|
||||
first = tmp = LISTP_FIRST_ENTRY(&mgr->area_list, MEM_AREA_TYPE, __list);
|
||||
|
||||
if (!first)
|
||||
goto free_mgr;
|
||||
|
||||
listp_for_each_entry_safe_continue(tmp, n, &mgr->area_list, __list) {
|
||||
listp_del(tmp, &mgr->area_list, __list);
|
||||
LISTP_FOR_EACH_ENTRY_SAFE_CONTINUE(tmp, n, &mgr->area_list, __list) {
|
||||
LISTP_DEL(tmp, &mgr->area_list, __list);
|
||||
system_free(tmp, sizeof(MEM_AREA_TYPE) + __SUM_OBJ_SIZE(tmp->size));
|
||||
}
|
||||
|
||||
@@ -182,15 +182,15 @@ static inline OBJ_TYPE * get_mem_obj_from_mgr (MEM_MGR mgr)
|
||||
MEM_OBJ mobj;
|
||||
|
||||
SYSTEM_LOCK();
|
||||
if (mgr->obj == mgr->obj_top && listp_empty(&mgr->free_list)) {
|
||||
if (mgr->obj == mgr->obj_top && LISTP_EMPTY(&mgr->free_list)) {
|
||||
SYSTEM_UNLOCK();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!listp_empty(&mgr->free_list)) {
|
||||
mobj = listp_first_entry(&mgr->free_list, MEM_OBJ_TYPE, __list);
|
||||
listp_del_init(mobj, &mgr->free_list, __list);
|
||||
check_list_head(MEM_OBJ, &mgr->free_list, __list);
|
||||
if (!LISTP_EMPTY(&mgr->free_list)) {
|
||||
mobj = LISTP_FIRST_ENTRY(&mgr->free_list, MEM_OBJ_TYPE, __list);
|
||||
LISTP_DEL_INIT(mobj, &mgr->free_list, __list);
|
||||
CHECK_LIST_HEAD(MEM_OBJ, &mgr->free_list, __list);
|
||||
} else {
|
||||
mobj = mgr->obj++;
|
||||
}
|
||||
@@ -204,12 +204,12 @@ static inline OBJ_TYPE * get_mem_obj_from_mgr_enlarge (MEM_MGR mgr,
|
||||
MEM_OBJ mobj;
|
||||
|
||||
SYSTEM_LOCK();
|
||||
if (mgr->obj == mgr->obj_top && listp_empty(&mgr->free_list)) {
|
||||
if (mgr->obj == mgr->obj_top && LISTP_EMPTY(&mgr->free_list)) {
|
||||
size_t mgr_size = mgr->size;
|
||||
MEM_AREA area;
|
||||
|
||||
/* If there is a previously allocated area, just activate it. */
|
||||
area = listp_prev_entry(mgr->active_area, &mgr->area_list, __list);
|
||||
area = LISTP_PREV_ENTRY(mgr->active_area, &mgr->area_list, __list);
|
||||
if (area) {
|
||||
__set_free_mem_area(area, mgr);
|
||||
goto alloc;
|
||||
@@ -234,16 +234,16 @@ static inline OBJ_TYPE * get_mem_obj_from_mgr_enlarge (MEM_MGR mgr,
|
||||
/* There can be concurrent operations to extend the manager. In case
|
||||
* someone has already enlarged the space, we just add the new area to
|
||||
* the list for later use. */
|
||||
listp_add(area, &mgr->area_list, __list);
|
||||
LISTP_ADD(area, &mgr->area_list, __list);
|
||||
if (mgr_size == mgr->size) /* check if the size has changed */
|
||||
__set_free_mem_area(area, mgr);
|
||||
}
|
||||
|
||||
alloc:
|
||||
if (!listp_empty(&mgr->free_list)) {
|
||||
mobj = listp_first_entry(&mgr->free_list, MEM_OBJ_TYPE, __list);
|
||||
listp_del_init(mobj, &mgr->free_list, __list);
|
||||
check_list_head(MEM_OBJ, &mgr->free_list, __list);
|
||||
if (!LISTP_EMPTY(&mgr->free_list)) {
|
||||
mobj = LISTP_FIRST_ENTRY(&mgr->free_list, MEM_OBJ_TYPE, __list);
|
||||
LISTP_DEL_INIT(mobj, &mgr->free_list, __list);
|
||||
CHECK_LIST_HEAD(MEM_OBJ, &mgr->free_list, __list);
|
||||
} else {
|
||||
mobj = mgr->obj++;
|
||||
}
|
||||
@@ -258,7 +258,7 @@ static inline void free_mem_obj_to_mgr (MEM_MGR mgr, OBJ_TYPE * obj)
|
||||
|
||||
SYSTEM_LOCK();
|
||||
MEM_AREA area, found = NULL;
|
||||
listp_for_each_entry(area, &mgr->area_list, __list)
|
||||
LISTP_FOR_EACH_ENTRY(area, &mgr->area_list, __list)
|
||||
if (mobj >= area->objs && mobj < area->objs + area->size) {
|
||||
found = area;
|
||||
break;
|
||||
@@ -266,8 +266,8 @@ static inline void free_mem_obj_to_mgr (MEM_MGR mgr, OBJ_TYPE * obj)
|
||||
|
||||
if (found) {
|
||||
INIT_LIST_HEAD(mobj, __list);
|
||||
listp_add_tail(mobj, &mgr->free_list, __list);
|
||||
check_list_head(MEM_OBJ, &mgr->free_list, __list);
|
||||
LISTP_ADD_TAIL(mobj, &mgr->free_list, __list);
|
||||
CHECK_LIST_HEAD(MEM_OBJ, &mgr->free_list, __list);
|
||||
}
|
||||
|
||||
SYSTEM_UNLOCK();
|
||||
|
||||
+9
-9
@@ -265,7 +265,7 @@ static inline SLAB_MGR create_slab_mgr (void)
|
||||
|
||||
INIT_LIST_HEAD(area, __list);
|
||||
INIT_LISTP(&mgr->area_list[i]);
|
||||
listp_add_tail(area, &mgr->area_list[i], __list);
|
||||
LISTP_ADD_TAIL(area, &mgr->area_list[i], __list);
|
||||
|
||||
INIT_LISTP(&mgr->free_list[i]);
|
||||
mgr->size[i] = 0;
|
||||
@@ -285,7 +285,7 @@ static inline void destroy_slab_mgr (SLAB_MGR mgr)
|
||||
for (i = 0 ; i < SLAB_LEVEL; i++) {
|
||||
area = (SLAB_AREA) addr;
|
||||
|
||||
listp_for_each_entry_safe(tmp, n, &mgr->area_list[i], __list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &mgr->area_list[i], __list) {
|
||||
if (tmp != area)
|
||||
system_free(area,
|
||||
__MAX_MEM_SIZE(slab_levels[i], area->size));
|
||||
@@ -310,7 +310,7 @@ static inline int enlarge_slab_mgr (SLAB_MGR mgr, int level)
|
||||
SLAB_AREA area;
|
||||
|
||||
/* If there is a previously allocated area, just activate it. */
|
||||
area = listp_prev_entry(mgr->active_area[level], &mgr->area_list[level], __list);
|
||||
area = LISTP_PREV_ENTRY(mgr->active_area[level], &mgr->area_list[level], __list);
|
||||
if (area) {
|
||||
__set_free_slab_area(area, mgr, level);
|
||||
return 0;
|
||||
@@ -340,7 +340,7 @@ static inline int enlarge_slab_mgr (SLAB_MGR mgr, int level)
|
||||
/* There can be concurrent operations to extend the SLAB manager. In case
|
||||
* someone has already enlarged the space, we just add the new area to the
|
||||
* list for later use. */
|
||||
listp_add(area, &mgr->area_list[level], __list);
|
||||
LISTP_ADD(area, &mgr->area_list[level], __list);
|
||||
if (mgr->size[level] == size) /* check if the size has changed */
|
||||
__set_free_slab_area(area, mgr, level);
|
||||
|
||||
@@ -374,7 +374,7 @@ static inline void * slab_alloc (SLAB_MGR mgr, int size)
|
||||
SYSTEM_LOCK();
|
||||
assert(mgr->addr[level] <= mgr->addr_top[level]);
|
||||
if (mgr->addr[level] == mgr->addr_top[level] &&
|
||||
listp_empty(&mgr->free_list[level])) {
|
||||
LISTP_EMPTY(&mgr->free_list[level])) {
|
||||
int ret = enlarge_slab_mgr(mgr, level);
|
||||
if (ret < 0) {
|
||||
SYSTEM_UNLOCK();
|
||||
@@ -382,9 +382,9 @@ static inline void * slab_alloc (SLAB_MGR mgr, int size)
|
||||
}
|
||||
}
|
||||
|
||||
if (!listp_empty(&mgr->free_list[level])) {
|
||||
mobj = listp_first_entry(&mgr->free_list[level], SLAB_OBJ_TYPE, __list);
|
||||
listp_del(mobj, &mgr->free_list[level], __list);
|
||||
if (!LISTP_EMPTY(&mgr->free_list[level])) {
|
||||
mobj = LISTP_FIRST_ENTRY(&mgr->free_list[level], SLAB_OBJ_TYPE, __list);
|
||||
LISTP_DEL(mobj, &mgr->free_list[level], __list);
|
||||
} else {
|
||||
mobj = (void *) mgr->addr[level];
|
||||
mgr->addr[level] += slab_levels[level] + SLAB_HDR_SIZE;
|
||||
@@ -490,7 +490,7 @@ static inline void slab_free (SLAB_MGR mgr, void * obj)
|
||||
|
||||
SYSTEM_LOCK();
|
||||
INIT_LIST_HEAD(mobj, __list);
|
||||
listp_add_tail(mobj, &mgr->free_list[level], __list);
|
||||
LISTP_ADD_TAIL(mobj, &mgr->free_list[level], __list);
|
||||
SYSTEM_UNLOCK();
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ int register_trusted_child(const char * uri, const char * mrenclave_str)
|
||||
|
||||
_DkSpinLock(&trusted_children_lock);
|
||||
|
||||
listp_for_each_entry(tc, &trusted_children, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tc, &trusted_children, list) {
|
||||
if (!memcmp(tc->uri, uri, uri_len + 1)) {
|
||||
_DkSpinUnlock(&trusted_children_lock);
|
||||
return 0;
|
||||
@@ -121,7 +121,7 @@ int register_trusted_child(const char * uri, const char * mrenclave_str)
|
||||
|
||||
_DkSpinLock(&trusted_children_lock);
|
||||
|
||||
listp_for_each_entry(tc, &trusted_children, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tc, &trusted_children, list) {
|
||||
if (!memcmp(tc->uri, uri, uri_len + 1)) {
|
||||
_DkSpinUnlock(&trusted_children_lock);
|
||||
free(new);
|
||||
@@ -129,7 +129,7 @@ int register_trusted_child(const char * uri, const char * mrenclave_str)
|
||||
}
|
||||
}
|
||||
|
||||
listp_add_tail(new, &trusted_children, list);
|
||||
LISTP_ADD_TAIL(new, &trusted_children, list);
|
||||
_DkSpinUnlock(&trusted_children_lock);
|
||||
return 0;
|
||||
}
|
||||
@@ -178,7 +178,7 @@ static int check_child_mrenclave (sgx_arch_hash_t * mrenclave,
|
||||
struct trusted_child * tc;
|
||||
_DkSpinLock(&trusted_children_lock);
|
||||
|
||||
listp_for_each_entry(tc, &trusted_children, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tc, &trusted_children, list) {
|
||||
if (!memcmp(mrenclave, tc->mrenclave, sizeof(sgx_arch_hash_t))) {
|
||||
_DkSpinUnlock(&trusted_children_lock);
|
||||
SGX_DBG(DBG_S, "trusted child: %s\n", tc->uri);
|
||||
|
||||
@@ -70,7 +70,7 @@ void pal_start_thread (void)
|
||||
struct pal_handle_thread *new_thread = NULL, *tmp;
|
||||
|
||||
_DkInternalLock(&thread_list_lock);
|
||||
listp_for_each_entry(tmp, &thread_list, list)
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &thread_list, list)
|
||||
if (!tmp->tcs) {
|
||||
new_thread = tmp;
|
||||
new_thread->tid = pal_assign_tid();
|
||||
@@ -116,7 +116,7 @@ int _DkThreadCreate (PAL_HANDLE * handle, int (*callback) (void *),
|
||||
new_thread->thread.param = (void *) thread_param;
|
||||
|
||||
_DkInternalLock(&thread_list_lock);
|
||||
listp_add_tail(&new_thread->thread, &thread_list, list);
|
||||
LISTP_ADD_TAIL(&new_thread->thread, &thread_list, list);
|
||||
_DkInternalUnlock(&thread_list_lock);
|
||||
|
||||
int ret = ocall_wake_thread(NULL);
|
||||
|
||||
@@ -251,7 +251,7 @@ int load_trusted_file (PAL_HANDLE file, sgx_stub_t ** stubptr,
|
||||
|
||||
_DkSpinLock(&trusted_file_lock);
|
||||
|
||||
listp_for_each_entry(tmp, &trusted_file_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tmp, &trusted_file_list, list) {
|
||||
if (tmp->stubs) {
|
||||
/* trusted files: must be exactly the same URI */
|
||||
if (tmp->uri_len == uri_len && !memcmp(tmp->uri, normpath, uri_len + 1)) {
|
||||
@@ -564,7 +564,7 @@ static int register_trusted_file (const char * uri, const char * checksum_str)
|
||||
|
||||
_DkSpinLock(&trusted_file_lock);
|
||||
|
||||
listp_for_each_entry(tf, &trusted_file_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tf, &trusted_file_list, list) {
|
||||
if (tf->uri_len == uri_len && !memcmp(tf->uri, uri, uri_len)) {
|
||||
_DkSpinUnlock(&trusted_file_lock);
|
||||
return 0;
|
||||
@@ -637,7 +637,7 @@ static int register_trusted_file (const char * uri, const char * checksum_str)
|
||||
|
||||
_DkSpinLock(&trusted_file_lock);
|
||||
|
||||
listp_for_each_entry(tf, &trusted_file_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(tf, &trusted_file_list, list) {
|
||||
if (tf->uri_len == uri_len && !memcmp(tf->uri, uri, uri_len)) {
|
||||
_DkSpinUnlock(&trusted_file_lock);
|
||||
free(new);
|
||||
@@ -645,7 +645,7 @@ static int register_trusted_file (const char * uri, const char * checksum_str)
|
||||
}
|
||||
}
|
||||
|
||||
listp_add_tail(new, &trusted_file_list, list);
|
||||
LISTP_ADD_TAIL(new, &trusted_file_list, list);
|
||||
_DkSpinUnlock(&trusted_file_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ void init_pages (void)
|
||||
vma->top = pal_sec.exec_addr + pal_sec.exec_size;
|
||||
vma->bottom = pal_sec.exec_addr;
|
||||
INIT_LIST_HEAD(vma, list);
|
||||
listp_add(vma, &heap_vma_list, list);
|
||||
LISTP_ADD(vma, &heap_vma_list, list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ static void assert_vma_list (void)
|
||||
void * last_addr = heap_base + heap_size;
|
||||
struct heap_vma * vma;
|
||||
|
||||
listp_for_each_entry(vma, &heap_vma_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(vma, &heap_vma_list, list) {
|
||||
SGX_DBG(DBG_M, "[%d] %p - %p\n", pal_sec.pid, vma->bottom, vma->top);
|
||||
if (last_addr < vma->top || vma->top <= vma->bottom) {
|
||||
SGX_DBG(DBG_E, "*** [%d] corrupted heap vma: %p - %p (last = %p) ***\n", pal_sec.pid, vma->bottom, vma->top, last_addr);
|
||||
@@ -104,7 +104,7 @@ void * get_reserved_pages(void * addr, uint64_t size)
|
||||
*/
|
||||
if (addr && addr >= heap_base &&
|
||||
addr + size <= heap_base + heap_size) {
|
||||
listp_for_each_entry(vma, &heap_vma_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(vma, &heap_vma_list, list) {
|
||||
if (vma->bottom < addr)
|
||||
break;
|
||||
prev = vma;
|
||||
@@ -119,7 +119,7 @@ void * get_reserved_pages(void * addr, uint64_t size)
|
||||
|
||||
void * avail_top = heap_base + heap_size;
|
||||
|
||||
listp_for_each_entry(vma, &heap_vma_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY(vma, &heap_vma_list, list) {
|
||||
if (avail_top - vma->top > size) {
|
||||
addr = avail_top - size;
|
||||
goto allocated;
|
||||
@@ -142,7 +142,7 @@ void * get_reserved_pages(void * addr, uint64_t size)
|
||||
allocated:
|
||||
if (prev) {
|
||||
// If this is the last entry, don't wrap around
|
||||
if (prev->list.next == listp_first_entry(&heap_vma_list, struct heap_vma, list))
|
||||
if (prev->list.next == LISTP_FIRST_ENTRY(&heap_vma_list, struct heap_vma, list))
|
||||
next = NULL;
|
||||
else
|
||||
next = prev->list.next;
|
||||
@@ -154,8 +154,8 @@ allocated:
|
||||
* they overlap, until the vmas drop below the requested addr
|
||||
* (traversing in decreasing virtual address order)
|
||||
*/
|
||||
next = listp_empty(&heap_vma_list) ? NULL :
|
||||
listp_first_entry(&heap_vma_list, struct heap_vma, list);
|
||||
next = LISTP_EMPTY(&heap_vma_list) ? NULL :
|
||||
LISTP_FIRST_ENTRY(&heap_vma_list, struct heap_vma, list);
|
||||
}
|
||||
|
||||
if (prev && next)
|
||||
@@ -175,8 +175,8 @@ allocated:
|
||||
|
||||
/* This appears to be doing a reverse search; we should stop before we
|
||||
* wrap back to the last entry */
|
||||
if (prev->list.prev != listp_last_entry(&heap_vma_list, struct heap_vma, list))
|
||||
prev_prev = list_entry(prev->list.prev, struct heap_vma, list);
|
||||
if (prev->list.prev != LISTP_LAST_ENTRY(&heap_vma_list, struct heap_vma, list))
|
||||
prev_prev = LIST_ENTRY(prev->list.prev, struct heap_vma, list);
|
||||
|
||||
if (!vma) {
|
||||
SGX_DBG(DBG_M, "merge %p-%p and %p-%p\n", addr, addr + size,
|
||||
@@ -190,7 +190,7 @@ allocated:
|
||||
prev->bottom, prev->top);
|
||||
|
||||
vma->top = (prev->top > vma->top) ? prev->top : vma->top;
|
||||
listp_del(prev, &heap_vma_list,list);
|
||||
LISTP_DEL(prev, &heap_vma_list,list);
|
||||
free(prev);
|
||||
}
|
||||
|
||||
@@ -203,8 +203,8 @@ allocated:
|
||||
if (next->top < addr)
|
||||
break;
|
||||
|
||||
if (next->list.next != listp_first_entry(&heap_vma_list, struct heap_vma, list))
|
||||
next_next = list_entry(next->list.next, struct heap_vma, list);
|
||||
if (next->list.next != LISTP_FIRST_ENTRY(&heap_vma_list, struct heap_vma, list))
|
||||
next_next = LIST_ENTRY(next->list.next, struct heap_vma, list);
|
||||
|
||||
if (!vma) {
|
||||
SGX_DBG(DBG_M, "merge %p-%p and %p-%p\n", addr, addr + size,
|
||||
@@ -217,7 +217,7 @@ allocated:
|
||||
next->bottom, next->top);
|
||||
|
||||
vma->bottom = next->bottom;
|
||||
listp_del(next, &heap_vma_list, list);
|
||||
LISTP_DEL(next, &heap_vma_list, list);
|
||||
free(next);
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ allocated:
|
||||
vma->top = addr + size;
|
||||
vma->bottom = addr;
|
||||
INIT_LIST_HEAD(vma, list);
|
||||
listp_add_after(vma, prev, &heap_vma_list, list);
|
||||
LISTP_ADD_AFTER(vma, prev, &heap_vma_list, list);
|
||||
}
|
||||
|
||||
if (vma->bottom >= vma->top) {
|
||||
@@ -282,7 +282,7 @@ void free_pages(void * addr, uint64_t size)
|
||||
|
||||
struct heap_vma * vma, * p;
|
||||
|
||||
listp_for_each_entry_safe(vma, p, &heap_vma_list, list) {
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(vma, p, &heap_vma_list, list) {
|
||||
if (vma->bottom >= addr_top)
|
||||
continue;
|
||||
if (vma->top <= addr)
|
||||
@@ -292,12 +292,12 @@ void free_pages(void * addr, uint64_t size)
|
||||
new->top = addr;
|
||||
new->bottom = vma->bottom;
|
||||
INIT_LIST_HEAD(new, list);
|
||||
list_add(new, vma, list);
|
||||
LIST_ADD(new, vma, list);
|
||||
}
|
||||
|
||||
vma->bottom = addr_top;
|
||||
if (vma->top <= vma->bottom) {
|
||||
listp_del(vma, &heap_vma_list, list); free(vma);
|
||||
LISTP_DEL(vma, &heap_vma_list, list); free(vma);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ static void _DkTerminateSighandler (int signum, siginfo_t * info,
|
||||
|
||||
INIT_LIST_HEAD(ev, list);
|
||||
ev->event_num = event_num;
|
||||
listp_add_tail(ev, &tcb->pending_queue, list);
|
||||
LISTP_ADD_TAIL(ev, &tcb->pending_queue, list);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -271,11 +271,11 @@ void __check_pending_event (void)
|
||||
tcb->pending_event = 0;
|
||||
_DkGenericSignalHandle(event, NULL, NULL);
|
||||
|
||||
if (!listp_empty(&tcb->pending_queue)) {
|
||||
if (!LISTP_EMPTY(&tcb->pending_queue)) {
|
||||
// If there are more than one pending events, process them from the queue
|
||||
struct event_queue * ev, * n;
|
||||
listp_for_each_entry_safe(ev, n, &tcb->pending_queue, list) {
|
||||
listp_del(ev, &tcb->pending_queue, list);
|
||||
LISTP_FOR_EACH_ENTRY_SAFE(ev, n, &tcb->pending_queue, list) {
|
||||
LISTP_DEL(ev, &tcb->pending_queue, list);
|
||||
_DkGenericSignalHandle(ev->event_num, NULL, NULL);
|
||||
free(ev);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user