summaryrefslogtreecommitdiff
path: root/kern
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-01-13 00:16:09 +0100
committerRichard Braun <rbraun@sceen.net>2017-01-13 00:16:09 +0100
commitcf59c5fa63b4639777fbe28fba79cfbd63fa6d4e (patch)
tree6cd4b64fc94f7cc9c2c1f75ba298169a88248657 /kern
parent27e9a04a0a07707d7a85dc65198b4ab8f32888f6 (diff)
Replace unsigned long with uintptr_t for integer/pointer conversions
This is mostly done for the machine-independent part.
Diffstat (limited to 'kern')
-rw-r--r--kern/kmem.c30
-rw-r--r--kern/percpu.c7
-rw-r--r--kern/percpu.h5
-rw-r--r--kern/rbtree.c7
-rw-r--r--kern/rbtree.h15
-rw-r--r--kern/rbtree_i.h21
-rw-r--r--kern/sprintf.c2
-rw-r--r--kern/sref.c12
-rw-r--r--kern/stdint.h4
9 files changed, 57 insertions, 46 deletions
diff --git a/kern/kmem.c b/kern/kmem.c
index 0f3b496..8d3ce49 100644
--- a/kern/kmem.c
+++ b/kern/kmem.c
@@ -181,7 +181,7 @@ kmem_buf_fill(void *buf, uint64_t pattern, size_t size)
{
uint64_t *ptr, *end;
- assert(P2ALIGNED((unsigned long)buf, sizeof(uint64_t)));
+ assert(P2ALIGNED((uintptr_t)buf, sizeof(uint64_t)));
assert(P2ALIGNED(size, sizeof(uint64_t)));
end = buf + size;
@@ -196,7 +196,7 @@ kmem_buf_verify_fill(void *buf, uint64_t old, uint64_t new, size_t size)
{
uint64_t *ptr, *end;
- assert(P2ALIGNED((unsigned long)buf, sizeof(uint64_t)));
+ assert(P2ALIGNED((uintptr_t)buf, sizeof(uint64_t)));
assert(P2ALIGNED(size, sizeof(uint64_t)));
end = buf + size;
@@ -263,7 +263,7 @@ kmem_pagefree(void *ptr, size_t size)
} else {
struct vm_page *page;
- page = vm_page_lookup(vm_page_direct_pa((unsigned long)ptr));
+ page = vm_page_lookup(vm_page_direct_pa((uintptr_t)ptr));
assert(page != NULL);
vm_page_free(page, vm_page_order(size));
}
@@ -341,10 +341,10 @@ kmem_slab_create(struct kmem_cache *cache, size_t color)
return slab;
}
-static inline unsigned long
+static inline uintptr_t
kmem_slab_buf(const struct kmem_slab *slab)
{
- return P2ALIGN((unsigned long)slab->addr, PAGE_SIZE);
+ return P2ALIGN((uintptr_t)slab->addr, PAGE_SIZE);
}
static void
@@ -628,7 +628,7 @@ kmem_cache_buf_to_slab(const struct kmem_cache *cache, void *buf)
return NULL;
}
- return (struct kmem_slab *)vm_page_end((unsigned long)buf) - 1;
+ return (struct kmem_slab *)vm_page_end((uintptr_t)buf) - 1;
}
static inline bool
@@ -643,7 +643,7 @@ static void
kmem_cache_register(struct kmem_cache *cache, struct kmem_slab *slab)
{
struct vm_page *page;
- unsigned long va, end;
+ uintptr_t va, end;
phys_addr_t pa;
bool virtual;
int error;
@@ -677,7 +677,7 @@ kmem_cache_lookup(struct kmem_cache *cache, void *buf)
{
struct kmem_slab *slab;
struct vm_page *page;
- unsigned long va;
+ uintptr_t va;
phys_addr_t pa;
bool virtual;
int error;
@@ -685,7 +685,7 @@ kmem_cache_lookup(struct kmem_cache *cache, void *buf)
assert(kmem_cache_registration_required(cache));
virtual = kmem_pagealloc_virtual(cache->slab_size);
- va = (unsigned long)buf;
+ va = (uintptr_t)buf;
if (virtual) {
error = pmap_kextract(va, &pa);
@@ -709,8 +709,8 @@ kmem_cache_lookup(struct kmem_cache *cache, void *buf)
}
slab = vm_page_get_priv(page);
- assert((unsigned long)buf >= kmem_slab_buf(slab));
- assert((unsigned long)buf < (kmem_slab_buf(slab) + cache->slab_size));
+ assert((uintptr_t)buf >= kmem_slab_buf(slab));
+ assert((uintptr_t)buf < (kmem_slab_buf(slab) + cache->slab_size));
return slab;
}
@@ -965,7 +965,7 @@ kmem_cache_free_verify(struct kmem_cache *cache, void *buf)
struct kmem_slab *slab;
union kmem_bufctl *bufctl;
unsigned char *redzone_byte;
- unsigned long slabend;
+ uintptr_t slabend;
slab = kmem_cache_lookup(cache, buf);
@@ -973,13 +973,13 @@ kmem_cache_free_verify(struct kmem_cache *cache, void *buf)
kmem_cache_error(cache, buf, KMEM_ERR_INVALID, NULL);
}
- slabend = P2ALIGN((unsigned long)slab->addr + cache->slab_size, PAGE_SIZE);
+ slabend = P2ALIGN((uintptr_t)slab->addr + cache->slab_size, PAGE_SIZE);
- if ((unsigned long)buf >= slabend) {
+ if ((uintptr_t)buf >= slabend) {
kmem_cache_error(cache, buf, KMEM_ERR_INVALID, NULL);
}
- if ((((unsigned long)buf - (unsigned long)slab->addr) % cache->buf_size)
+ if ((((uintptr_t)buf - (uintptr_t)slab->addr) % cache->buf_size)
!= 0) {
kmem_cache_error(cache, buf, KMEM_ERR_INVALID, NULL);
}
diff --git a/kern/percpu.c b/kern/percpu.c
index 5b9690c..ab7b4fb 100644
--- a/kern/percpu.c
+++ b/kern/percpu.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 Richard Braun.
+ * Copyright (c) 2014-2017 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
#include <kern/percpu.h>
#include <kern/printk.h>
#include <kern/stddef.h>
+#include <kern/stdint.h>
#include <kern/string.h>
#include <machine/cpu.h>
#include <vm/vm_kmem.h>
@@ -111,9 +112,9 @@ void
percpu_cleanup(void)
{
struct vm_page *page;
- unsigned long va;
+ uintptr_t va;
- va = (unsigned long)percpu_area_content;
+ va = (uintptr_t)percpu_area_content;
page = vm_page_lookup(vm_page_direct_pa(va));
vm_page_free(page, vm_page_order(percpu_area_size));
}
diff --git a/kern/percpu.h b/kern/percpu.h
index 820fed6..a9d1eb3 100644
--- a/kern/percpu.h
+++ b/kern/percpu.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 Richard Braun.
+ * Copyright (c) 2014-2017 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -55,6 +55,7 @@
#include <kern/assert.h>
#include <kern/macros.h>
+#include <kern/stdint.h>
#define PERCPU_SECTION .percpu
#define __percpu __section(QUOTE(PERCPU_SECTION))
@@ -72,7 +73,7 @@ extern char _epercpu;
* Expands to the address of a percpu variable.
*/
#define percpu_ptr(var, cpu) \
- ((typeof(var) *)(percpu_area(cpu) + ((unsigned long)(&(var)))))
+ ((typeof(var) *)(percpu_area(cpu) + ((uintptr_t)(&(var)))))
/*
* Expands to the lvalue of a percpu variable.
diff --git a/kern/rbtree.c b/kern/rbtree.c
index 49cb097..0d0a844 100644
--- a/kern/rbtree.c
+++ b/kern/rbtree.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2012 Richard Braun.
+ * Copyright (c) 2010-2017 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
#include <kern/rbtree.h>
#include <kern/rbtree_i.h>
#include <kern/stddef.h>
+#include <kern/stdint.h>
/*
* Return the index of a node in the children array of its parent.
@@ -79,7 +80,7 @@ rbtree_node_set_parent(struct rbtree_node *node, struct rbtree_node *parent)
assert(rbtree_node_check_alignment(node));
assert(rbtree_node_check_alignment(parent));
- node->parent = (unsigned long)parent | (node->parent & RBTREE_COLOR_MASK);
+ node->parent = (uintptr_t)parent | (node->parent & RBTREE_COLOR_MASK);
}
/*
@@ -179,7 +180,7 @@ rbtree_insert_rebalance(struct rbtree *tree, struct rbtree_node *parent,
assert(rbtree_node_check_alignment(parent));
assert(rbtree_node_check_alignment(node));
- node->parent = (unsigned long)parent | RBTREE_COLOR_RED;
+ node->parent = (uintptr_t)parent | RBTREE_COLOR_RED;
node->children[RBTREE_LEFT] = NULL;
node->children[RBTREE_RIGHT] = NULL;
diff --git a/kern/rbtree.h b/kern/rbtree.h
index 0e552b4..dd17e95 100644
--- a/kern/rbtree.h
+++ b/kern/rbtree.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2011, 2012 Richard Braun.
+ * Copyright (c) 2010-2017 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
#include <kern/assert.h>
#include <kern/macros.h>
#include <kern/stddef.h>
+#include <kern/stdint.h>
/*
* Indexes of the left and right nodes in the children array of a node.
@@ -41,6 +42,11 @@ struct rbtree_node;
*/
struct rbtree;
+/*
+ * Insertion point identifier.
+ */
+typedef uintptr_t rbtree_slot_t;
+
#include <kern/rbtree_i.h>
/*
@@ -62,7 +68,7 @@ rbtree_node_init(struct rbtree_node *node)
{
assert(rbtree_node_check_alignment(node));
- node->parent = (unsigned long)node | RBTREE_COLOR_RED;
+ node->parent = (uintptr_t)node | RBTREE_COLOR_RED;
node->children[RBTREE_LEFT] = NULL;
node->children[RBTREE_RIGHT] = NULL;
}
@@ -200,8 +206,7 @@ MACRO_END
* This macro essentially acts as rbtree_lookup() but in addition to a node,
* it also returns a slot, which identifies an insertion point in the tree.
* If the returned node is null, the slot can be used by rbtree_insert_slot()
- * to insert without the overhead of an additional lookup. The slot is a
- * simple unsigned long integer.
+ * to insert without the overhead of an additional lookup.
*
* The constraints that apply to the key parameter are the same as for
* rbtree_lookup().
@@ -240,7 +245,7 @@ MACRO_END
* must denote a null node).
*/
static inline void
-rbtree_insert_slot(struct rbtree *tree, unsigned long slot,
+rbtree_insert_slot(struct rbtree *tree, rbtree_slot_t slot,
struct rbtree_node *node)
{
struct rbtree_node *parent;
diff --git a/kern/rbtree_i.h b/kern/rbtree_i.h
index 7f9650e..f788e83 100644
--- a/kern/rbtree_i.h
+++ b/kern/rbtree_i.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2011, 2012 Richard Braun.
+ * Copyright (c) 2010-2017 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
#include <kern/assert.h>
#include <kern/macros.h>
#include <kern/stddef.h>
+#include <kern/stdint.h>
/*
* Red-black node structure.
@@ -37,7 +38,7 @@
* special alignment constraints such as member packing.
*/
struct rbtree_node {
- unsigned long parent;
+ uintptr_t parent;
struct rbtree_node *children[2];
};
@@ -52,8 +53,8 @@ struct rbtree {
* Masks applied on the parent member of a node to obtain either the
* color or the parent address.
*/
-#define RBTREE_COLOR_MASK 0x1UL
-#define RBTREE_PARENT_MASK (~0x3UL)
+#define RBTREE_COLOR_MASK ((uintptr_t)1)
+#define RBTREE_PARENT_MASK (~(uintptr_t)0x3)
/*
* Node colors.
@@ -65,7 +66,7 @@ struct rbtree {
* Masks applied on slots to obtain either the child index or the parent
* address.
*/
-#define RBTREE_SLOT_INDEX_MASK 0x1UL
+#define RBTREE_SLOT_INDEX_MASK ((uintptr_t)0x1)
#define RBTREE_SLOT_PARENT_MASK (~RBTREE_SLOT_INDEX_MASK)
/*
@@ -95,7 +96,7 @@ rbtree_d2i(int diff)
static inline int
rbtree_node_check_alignment(const struct rbtree_node *node)
{
- return ((unsigned long)node & (~RBTREE_PARENT_MASK)) == 0;
+ return ((uintptr_t)node & (~RBTREE_PARENT_MASK)) == 0;
}
/*
@@ -110,19 +111,19 @@ rbtree_node_parent(const struct rbtree_node *node)
/*
* Translate an insertion point into a slot.
*/
-static inline unsigned long
+static inline rbtree_slot_t
rbtree_slot(struct rbtree_node *parent, int index)
{
assert(rbtree_node_check_alignment(parent));
assert(rbtree_check_index(index));
- return (unsigned long)parent | index;
+ return (rbtree_slot_t)parent | index;
}
/*
* Extract the parent address from a slot.
*/
static inline struct rbtree_node *
-rbtree_slot_parent(unsigned long slot)
+rbtree_slot_parent(rbtree_slot_t slot)
{
return (struct rbtree_node *)(slot & RBTREE_SLOT_PARENT_MASK);
}
@@ -131,7 +132,7 @@ rbtree_slot_parent(unsigned long slot)
* Extract the index from a slot.
*/
static inline int
-rbtree_slot_index(unsigned long slot)
+rbtree_slot_index(rbtree_slot_t slot)
{
return slot & RBTREE_SLOT_INDEX_MASK;
}
diff --git a/kern/sprintf.c b/kern/sprintf.c
index 7117dbe..386d9d3 100644
--- a/kern/sprintf.c
+++ b/kern/sprintf.c
@@ -340,7 +340,7 @@ integer:
}
break;
case SPRINTF_MODIFIER_PTR:
- n = (unsigned long)va_arg(ap, void *);
+ n = (uintptr_t)va_arg(ap, void *);
break;
case SPRINTF_MODIFIER_SIZE:
if (flags & SPRINTF_FORMAT_CONV_SIGNED) {
diff --git a/kern/sref.c b/kern/sref.c
index 528eb22..a9253dc 100644
--- a/kern/sref.c
+++ b/kern/sref.c
@@ -240,18 +240,18 @@ sref_queue_concat(struct sref_queue *queue1, struct sref_queue *queue2)
queue1->size += queue2->size;
}
-static inline unsigned long
+static inline uintptr_t
sref_counter_hash(const struct sref_counter *counter)
{
- unsigned long va;
+ uintptr_t va;
- va = (unsigned long)counter;
+ va = (uintptr_t)counter;
assert(P2ALIGNED(va, 1UL << SREF_HASH_SHIFT));
return (va >> SREF_HASH_SHIFT);
}
-static inline unsigned long
+static inline uintptr_t
sref_counter_index(const struct sref_counter *counter)
{
return (sref_counter_hash(counter) & (SREF_MAX_DELTAS - 1));
@@ -430,7 +430,7 @@ sref_end_epoch(struct sref_queue *queue)
}
static inline struct sref_delta *
-sref_cache_delta(struct sref_cache *cache, unsigned int i)
+sref_cache_delta(struct sref_cache *cache, unsigned long i)
{
assert(i < ARRAY_SIZE(cache->deltas));
return &cache->deltas[i];
@@ -441,7 +441,7 @@ sref_cache_init(struct sref_cache *cache, unsigned int cpu)
{
char name[EVCNT_NAME_SIZE];
struct sref_delta *delta;
- unsigned int i;
+ unsigned long i;
mutex_init(&cache->lock);
diff --git a/kern/stdint.h b/kern/stdint.h
index d6794c4..7aac917 100644
--- a/kern/stdint.h
+++ b/kern/stdint.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2011 Richard Braun.
+ * Copyright (c) 2010-2017 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,6 +18,8 @@
#ifndef _KERN_STDINT_H
#define _KERN_STDINT_H
+typedef unsigned long uintptr_t;
+
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;