Index: arch/amd64/include/pm.h
===================================================================
--- arch/amd64/include/pm.h	(revision 97a7effc811599a0a052715fae6d7e97c2fa066c)
+++ arch/amd64/include/pm.h	(revision 9fa16b204b1d07e1406cbdc9803f00547dcadfa8)
@@ -68,4 +68,5 @@
 
 #define TSS_BASIC_SIZE	104
+#define TSS_IOMAP_SIZE	(16*1024+1)	/* 16K for bitmap + 1 terminating byte for convenience */
 
 #ifndef __ASM__
@@ -145,5 +146,5 @@
 	__u16 reserve4;
 	__u16 iomap_base;
-	__u8 iomap[0x10000 + 1];	/* 64K + 1 terminating byte */
+	__u8 iomap[TSS_IOMAP_SIZE];
 } __attribute__ ((packed));
 typedef struct tss tss_t;
Index: arch/amd64/include/proc/task.h
===================================================================
--- arch/amd64/include/proc/task.h	(revision 97a7effc811599a0a052715fae6d7e97c2fa066c)
+++ arch/amd64/include/proc/task.h	(revision 9fa16b204b1d07e1406cbdc9803f00547dcadfa8)
@@ -32,8 +32,8 @@
 #include <typedefs.h>
 #include <arch/types.h>
+#include <adt/bitmap.h>
 
 typedef struct {
-	count_t iomap_size;
-	__u8 *iomap;
+	bitmap_t iomap;
 } task_arch_t;
 
Index: arch/amd64/src/proc/scheduler.c
===================================================================
--- arch/amd64/src/proc/scheduler.c	(revision 97a7effc811599a0a052715fae6d7e97c2fa066c)
+++ arch/amd64/src/proc/scheduler.c	(revision 9fa16b204b1d07e1406cbdc9803f00547dcadfa8)
@@ -37,4 +37,5 @@
 #include <print.h>
 #include <arch/pm.h>
+#include <adt/bitmap.h>
 
 /** Perform amd64 specific tasks needed before the new task is run.
@@ -44,5 +45,5 @@
 void before_task_runs_arch(void)
 {
-	size_t iomap_size;
+	count_t bits;
 	ptr_16_64_t cpugdtr;
 	descriptor_t *gdt_p;
@@ -54,9 +55,15 @@
 	/* First, copy the I/O Permission Bitmap. */
 	spinlock_lock(&TASK->lock);
-	iomap_size = TASK->arch.iomap_size;
-	if (iomap_size) {
-		ASSERT(TASK->arch.iomap);
-		memcpy(CPU->arch.tss->iomap, TASK->arch.iomap, iomap_size);
-		CPU->arch.tss->iomap[iomap_size] = 0xff;        /* terminating byte */
+	if ((bits = TASK->arch.iomap.bits)) {
+		bitmap_t iomap;
+	
+		ASSERT(TASK->arch.iomap.map);
+		bitmap_initialize(&iomap, CPU->arch.tss->iomap, TSS_IOMAP_SIZE * 8);
+		bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
+		/*
+		 * It is safe to set the trailing four bits because of the extra
+		 * convenience byte in TSS_IOMAP_SIZE.
+		 */
+		bitmap_set_range(&iomap, TASK->arch.iomap.bits, 4);
 	}
 	spinlock_unlock(&TASK->lock);
@@ -65,5 +72,5 @@
 	gdtr_store(&cpugdtr);
 	gdt_p = (descriptor_t *) cpugdtr.base;
-	gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + iomap_size - 1);
+	gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits) - 1);
 	gdtr_load(&cpugdtr);
 }
Index: arch/amd64/src/proc/task.c
===================================================================
--- arch/amd64/src/proc/task.c	(revision 97a7effc811599a0a052715fae6d7e97c2fa066c)
+++ arch/amd64/src/proc/task.c	(revision 9fa16b204b1d07e1406cbdc9803f00547dcadfa8)
@@ -36,5 +36,4 @@
 void task_create_arch(task_t *t)
 {
-	t->arch.iomap = NULL;
-	t->arch.iomap_size = 0;
+	bitmap_initialize(&t->arch.iomap, NULL, 0);
 }
Index: arch/ia32/include/pm.h
===================================================================
--- arch/ia32/include/pm.h	(revision 97a7effc811599a0a052715fae6d7e97c2fa066c)
+++ arch/ia32/include/pm.h	(revision 9fa16b204b1d07e1406cbdc9803f00547dcadfa8)
@@ -57,4 +57,5 @@
 
 #define TSS_BASIC_SIZE	104
+#define TSS_IOMAP_SIZE	(16*1024+1)	/* 16K for bitmap + 1 terminating byte for convenience */
 
 #ifndef __ASM__
@@ -132,5 +133,5 @@
 	unsigned : 16;
 	__u16 iomap_base;
-	__u8 iomap[0x10000+1];	/* 64K + 1 terminating byte */
+	__u8 iomap[TSS_IOMAP_SIZE];
 } __attribute__ ((packed));
 typedef struct tss tss_t;
Index: arch/ia32/include/proc/task.h
===================================================================
--- arch/ia32/include/proc/task.h	(revision 97a7effc811599a0a052715fae6d7e97c2fa066c)
+++ arch/ia32/include/proc/task.h	(revision 9fa16b204b1d07e1406cbdc9803f00547dcadfa8)
@@ -32,8 +32,8 @@
 #include <typedefs.h>
 #include <arch/types.h>
+#include <adt/bitmap.h>
 
 typedef struct {
-	count_t iomap_size;
-	__u8 *iomap;
+	bitmap_t iomap;
 } task_arch_t;
 
Index: arch/ia32/src/proc/scheduler.c
===================================================================
--- arch/ia32/src/proc/scheduler.c	(revision 97a7effc811599a0a052715fae6d7e97c2fa066c)
+++ arch/ia32/src/proc/scheduler.c	(revision 9fa16b204b1d07e1406cbdc9803f00547dcadfa8)
@@ -36,4 +36,5 @@
 #include <arch/pm.h>
 #include <arch/asm.h>
+#include <adt/bitmap.h>
 
 /** Perform ia32 specific tasks needed before the new task is run.
@@ -43,5 +44,5 @@
 void before_task_runs_arch(void)
 {
-	size_t iomap_size;
+	count_t bits;
 	ptr_16_32_t cpugdtr;
 	descriptor_t *gdt_p;
@@ -53,16 +54,22 @@
 	/* First, copy the I/O Permission Bitmap. */
 	spinlock_lock(&TASK->lock);
-	iomap_size = TASK->arch.iomap_size;
-	if (iomap_size) {
-		ASSERT(TASK->arch.iomap);
-		memcpy(CPU->arch.tss->iomap, TASK->arch.iomap, iomap_size);
-		CPU->arch.tss->iomap[iomap_size] = 0xff;	/* terminating byte */
+	if ((bits = TASK->arch.iomap.bits)) {
+		bitmap_t iomap;
+
+		ASSERT(TASK->arch.iomap.map);
+		bitmap_initialize(&iomap, CPU->arch.tss->iomap, TSS_IOMAP_SIZE * 8);
+		bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
+		/*
+		 * It is safe to set the trailing four bits because of the extra
+		 * convenience byte in TSS_IOMAP_SIZE.
+		 */
+		bitmap_set_range(&iomap, TASK->arch.iomap.bits, 4);
 	}
-	spinlock_unlock(&TASK->lock);	
+	spinlock_unlock(&TASK->lock);
 
 	/* Second, adjust TSS segment limit. */
 	gdtr_store(&cpugdtr);
 	gdt_p = (descriptor_t *) cpugdtr.base;
-	gdt_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + iomap_size - 1);
+	gdt_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits) - 1);
 	gdtr_load(&cpugdtr);
 }
Index: arch/ia32/src/proc/task.c
===================================================================
--- arch/ia32/src/proc/task.c	(revision 97a7effc811599a0a052715fae6d7e97c2fa066c)
+++ arch/ia32/src/proc/task.c	(revision 9fa16b204b1d07e1406cbdc9803f00547dcadfa8)
@@ -29,4 +29,5 @@
 #include <proc/task.h>
 #include <arch/types.h>
+#include <adt/bitmap.h>
 
 /** Perform ia32 specific task initialization.
@@ -36,5 +37,4 @@
 void task_create_arch(task_t *t)
 {
-	t->arch.iomap = NULL;
-	t->arch.iomap_size = 0;
+	bitmap_initialize(&t->arch.iomap, NULL, 0);
 }
