Replaced kmalloc(), kfree(), and kstrdup() with the POSIX equivalents.

Implemented realloc().
Adapted all other sources, some minor cleanups in some files as well.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1773 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2002-10-29 23:07:06 +00:00
parent f2e04b5fa6
commit 41691b996a
31 changed files with 567 additions and 416 deletions
+15 -14
View File
@@ -100,32 +100,33 @@ KernelLd stage2
KernelLd kernel
:
<$(SOURCE_GRIST)!core>cbuf.o
<$(SOURCE_GRIST)!core>console.o
<$(SOURCE_GRIST)!core>cpu.o
<$(SOURCE_GRIST)!core>debug.o
<$(SOURCE_GRIST)!core>cbuf.o
<$(SOURCE_GRIST)!core>console.o
<$(SOURCE_GRIST)!core>cpu.o
<$(SOURCE_GRIST)!core>debug.o
<$(SOURCE_GRIST)!core>driver_settings.o
<$(SOURCE_GRIST)!core>elf.o
<$(SOURCE_GRIST)!core>faults.o
<$(SOURCE_GRIST)!core>fd.o
<$(SOURCE_GRIST)!core>gdb.o
<$(SOURCE_GRIST)!core>heap.o
<$(SOURCE_GRIST)!core>int.o
<$(SOURCE_GRIST)!core>khash.o
<$(SOURCE_GRIST)!core>lock.o
<$(SOURCE_GRIST)!core>main.o
<$(SOURCE_GRIST)!core>khash.o
<$(SOURCE_GRIST)!core>lock.o
<$(SOURCE_GRIST)!core>main.o
<$(SOURCE_GRIST)!core>misc.o
<$(SOURCE_GRIST)!core>module.o
<$(SOURCE_GRIST)!core>pools.o
<$(SOURCE_GRIST)!core>pools.o
<$(SOURCE_GRIST)!core>port.o
<$(SOURCE_GRIST)!core>queue.o
<$(SOURCE_GRIST)!core>queue.o
<$(SOURCE_GRIST)!core>scheduler.o
<$(SOURCE_GRIST)!core>sem.o
<$(SOURCE_GRIST)!core>signal.o
<$(SOURCE_GRIST)!core>sem.o
<$(SOURCE_GRIST)!core>signal.o
<$(SOURCE_GRIST)!core>smp.o
<$(SOURCE_GRIST)!core>syscalls.o
<$(SOURCE_GRIST)!core>syscalls.o
<$(SOURCE_GRIST)!core>sysctl.o
<$(SOURCE_GRIST)!core>team.o
<$(SOURCE_GRIST)!core>thread.o
<$(SOURCE_GRIST)!core>team.o
<$(SOURCE_GRIST)!core>thread.o
<$(SOURCE_GRIST)!core>timer.o
linkhack.so
@@ -7,7 +7,7 @@
#include <kernel.h>
#include <lock.h>
#include <debug.h>
#include <memheap.h>
#include <malloc.h>
#include <vfs.h>
#include <bus.h>
#include <string.h>
@@ -61,16 +61,16 @@ bus_register_bus(const char *path)
mutex_lock(&bus_lock);
if (!find_bus(path)) {
b = (bus *)kmalloc(sizeof(bus));
b = (bus *)malloc(sizeof(bus));
if (b == NULL) {
err = ENOMEM;
goto err;
}
b->path = kmalloc(strlen(path)+1);
b->path = malloc(strlen(path)+1);
if (b->path == NULL) {
err = ENOMEM;
kfree(b);
free(b);
goto err;
}
strcpy((char *)b->path, path);
+11 -11
View File
@@ -6,7 +6,7 @@
#include <kernel.h>
#include <console.h>
#include <debug.h>
#include <memheap.h>
#include <malloc.h>
#include <int.h>
#include <lock.h>
#include <vm.h>
@@ -903,18 +903,18 @@ pci_bridge(uint8 bus, uint8 dev, uint8 func)
write_pci_config(bus, dev, func, PCI_subordinate_bus, 1, pci_max_bus);
pcii = (pci_info*)kmalloc(sizeof(pci_info));
pcii = (pci_info *)malloc(sizeof(pci_info));
if (!pcii)
goto pci_bridge_skip_infolist;
pcid = (struct pci_device*)kmalloc(sizeof(struct pci_device));
pcid = (struct pci_device *)malloc(sizeof(struct pci_device));
if (!pcid) {
kfree(pcii);
free(pcii);
goto pci_bridge_skip_infolist;
}
pcib = (struct pci_bus *)kmalloc(sizeof(struct pci_bus));
pcib = (struct pci_bus *)malloc(sizeof(struct pci_bus));
if (!pcib) {
kfree(pcii);
kfree(pcid);
free(pcii);
free(pcid);
goto pci_bridge_skip_infolist;
}
@@ -1039,12 +1039,12 @@ pci_device_probe(uint8 bus, uint8 dev, uint8 func)
}
/* If we get here then it's not a bridge, so we add it... */
pcii = (pci_info*)kmalloc(sizeof(pci_info));
pcii = (pci_info *)malloc(sizeof(pci_info));
if (!pcii)
return;
pcid = (struct pci_device*)kmalloc(sizeof(struct pci_device));
pcid = (struct pci_device *)malloc(sizeof(struct pci_device));
if (!pcid) {
kfree(pcii);
free(pcii);
return;
}
@@ -1169,7 +1169,7 @@ scan_pci(void)
* but we may want to review if we need to add 8 version of the
* same device if only the functions differ?
*/
if ((pcii = (pci_info*)kmalloc(sizeof(pci_info))) == NULL) {
if ((pcii = (pci_info *)malloc(sizeof(pci_info))) == NULL) {
dprintf("Failed to get memory for a pic_info structure in scan_pci\n");
return;
}
+3 -3
View File
@@ -5,7 +5,7 @@
#include <kernel.h>
#include <arch/cpu.h>
#include <memheap.h>
#include <malloc.h>
#include <vm.h>
#include <debug.h>
#include <smp.h>
@@ -55,13 +55,13 @@ arch_cpu_init2(kernel_args *ka)
i386_selector_init( gdt ); // pass the new gdt
tss = kmalloc(sizeof(struct tss *) * ka->num_cpus);
tss = malloc(sizeof(struct tss *) * ka->num_cpus);
if (tss == NULL) {
panic("arch_cpu_init2: could not allocate buffer for tss pointers\n");
return ENOMEM;
}
tss_loaded = kmalloc(sizeof(int) * ka->num_cpus);
tss_loaded = malloc(sizeof(int) * ka->num_cpus);
if (tss == NULL) {
panic("arch_cpu_init2: could not allocate buffer for tss booleans\n");
return ENOMEM;
@@ -4,7 +4,7 @@
*/
#include <kernel.h>
#include <memheap.h>
#include <malloc.h>
#include <int.h>
#include <smp.h>
#include <vm.h>
@@ -175,10 +175,10 @@ static void destroy_tmap(vm_translation_map *map)
vm_page_set_state(page, PAGE_STATE_FREE);
}
}
kfree(map->arch_data->pgdir_virt);
free(map->arch_data->pgdir_virt);
}
kfree(map->arch_data);
free(map->arch_data);
recursive_lock_destroy(&map->lock);
}
@@ -583,7 +583,7 @@ dprintf("vm_translation_map_create\n");
if(recursive_lock_create(&new_map->lock) < 0)
return ENOMEM;
new_map->arch_data = (vm_translation_map_arch_info *)kmalloc(sizeof(vm_translation_map_arch_info));
new_map->arch_data = (vm_translation_map_arch_info *)malloc(sizeof(vm_translation_map_arch_info));
if(new_map == NULL) {
recursive_lock_destroy(&new_map->lock);
return ENOMEM;
@@ -594,9 +594,9 @@ dprintf("vm_translation_map_create\n");
if(!kernel) {
// user
// allocate a pgdir
new_map->arch_data->pgdir_virt = kmalloc(PAGE_SIZE);
new_map->arch_data->pgdir_virt = malloc(PAGE_SIZE);
if(new_map->arch_data->pgdir_virt == NULL) {
kfree(new_map->arch_data);
free(new_map->arch_data);
recursive_lock_destroy(&new_map->lock);
return ENOMEM;
}
+9 -10
View File
@@ -21,6 +21,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <ctype.h>
@@ -337,7 +338,7 @@ add_debugger_command(char *name, int (*func)(int, char **), char *desc)
int flags;
struct debugger_command *cmd;
cmd = (struct debugger_command *)kmalloc(sizeof(struct debugger_command));
cmd = (struct debugger_command *)malloc(sizeof(struct debugger_command));
if (cmd == NULL)
return ENOMEM;
@@ -361,23 +362,21 @@ add_debugger_command(char *name, int (*func)(int, char **), char *desc)
int
remove_debugger_command(char * name, int (*func)(int, char **))
{
struct debugger_command *cmd = commands;
struct debugger_command *prev = NULL;
int flags;
struct debugger_command *cmd;
struct debugger_command *prev;
flags = disable_interrupts();
acquire_spinlock(&dbg_spinlock);
prev = NULL;
cmd = commands;
while (cmd) {
if (strcmp(cmd->name, name) == 0 &&
cmd->func == func)
if (!strcmp(cmd->name, name) && cmd->func == func)
break;
prev = cmd;
cmd = cmd->next;
}
if (cmd) {
if (cmd == commands)
commands = cmd->next;
@@ -389,10 +388,10 @@ remove_debugger_command(char * name, int (*func)(int, char **))
restore_interrupts(flags);
if (cmd) {
kfree(cmd);
free(cmd);
return B_NO_ERROR;
}
return B_NAME_NOT_FOUND;
}
+19 -19
View File
@@ -13,7 +13,7 @@
#include <vm.h>
#include <thread.h>
#include <debug.h>
#include <memheap.h>
#include <malloc.h>
#include <atomic.h>
#include <stdlib.h>
@@ -229,8 +229,8 @@ find_image_by_vnode(void *vnode)
mutex_lock(&image_lock);
for(image = kernel_images; image; image = image->next) {
if(image->vnode == vnode)
for (image = kernel_images; image; image = image->next) {
if (image->vnode == vnode)
break;
}
mutex_unlock(&image_lock);
@@ -244,7 +244,7 @@ create_image_struct()
{
struct elf_image_info *image;
image = (struct elf_image_info *)kmalloc(sizeof(struct elf_image_info));
image = (struct elf_image_info *)malloc(sizeof(struct elf_image_info));
if(!image)
return NULL;
memset(image, 0, sizeof(struct elf_image_info));
@@ -655,7 +655,7 @@ elf_load_uspace(const char *path, struct team *p, int flags, addr *entry)
// read program header
pheaders = (struct Elf32_Phdr *)kmalloc(eheader.e_phnum * eheader.e_phentsize);
pheaders = (struct Elf32_Phdr *)malloc(eheader.e_phnum * eheader.e_phentsize);
if (pheaders == NULL) {
dprintf("error allocating space for program headers\n");
err = ENOMEM;
@@ -774,7 +774,7 @@ elf_load_uspace(const char *path, struct team *p, int flags, addr *entry)
error:
if (pheaders)
kfree(pheaders);
free(pheaders);
sys_close(fd);
return err;
@@ -815,7 +815,7 @@ elf_load_kspace(const char *path, const char *sym_prepend)
goto done;
}
eheader = (struct Elf32_Ehdr *)kmalloc(sizeof(*eheader));
eheader = (struct Elf32_Ehdr *)malloc(sizeof(*eheader));
if (!eheader) {
err = ENOMEM;
goto error;
@@ -842,9 +842,9 @@ elf_load_kspace(const char *path, const char *sym_prepend)
}
image->vnode = vnode;
image->eheader = eheader;
image->name = kstrdup(path);
image->name = strdup(path);
pheaders = (struct Elf32_Phdr *)kmalloc(eheader->e_phnum * eheader->e_phentsize);
pheaders = (struct Elf32_Phdr *)malloc(eheader->e_phnum * eheader->e_phentsize);
if (pheaders == NULL) {
dprintf("error allocating space for program headers\n");
err = ENOMEM;
@@ -955,7 +955,7 @@ elf_load_kspace(const char *path, const char *sym_prepend)
err = 0;
kfree(pheaders);
free(pheaders);
sys_close(fd);
insert_image_in_list(image);
@@ -971,11 +971,11 @@ error4:
if (image->regions[0].id >= 0)
vm_delete_region(vm_get_kernel_aspace_id(), image->regions[0].id);
error3:
kfree(image);
free(image);
error2:
kfree(pheaders);
free(pheaders);
error1:
kfree(eheader);
free(eheader);
error:
mutex_unlock(&image_load_lock);
error0:
@@ -995,8 +995,8 @@ elf_unlink_relocs(struct elf_image_info *image)
for (link = image->linked_images; link; link = next_link) {
next_link = link->next;
elf_unload_image( link->image );
kfree( link );
elf_unload_image(link->image);
free(link);
}
return B_NO_ERROR;
@@ -1016,9 +1016,9 @@ elf_unload_image_final(struct elf_image_info *image)
vfs_put_vnode_ptr(image->vnode);
remove_image_from_list(image);
kfree(image->eheader);
kfree(image->name);
kfree(image);
free(image->eheader);
free(image->name);
free(image);
}
@@ -1084,7 +1084,7 @@ elf_init(kernel_args *ka)
// build a image structure for the kernel, which has already been loaded
kernel_image = create_image_struct();
kernel_image->name = kstrdup("kernel");
kernel_image->name = strdup("kernel");
// text segment
kernel_image->regions[0].id = vm_find_region_by_name(vm_get_kernel_aspace_id(), "kernel_ro");
+3 -3
View File
@@ -12,8 +12,8 @@
#include <vfs.h>
#include <debug.h>
#include <memheap.h>
#include <malloc.h>
#include <string.h>
#define CHECK_USER_ADDR(x) \
@@ -52,7 +52,7 @@ alloc_fd(void)
{
struct file_descriptor *descriptor;
descriptor = kmalloc(sizeof(struct file_descriptor));
descriptor = malloc(sizeof(struct file_descriptor));
if (descriptor == NULL)
return NULL;
@@ -110,7 +110,7 @@ put_fd(struct file_descriptor *descriptor)
if (descriptor->ops->fd_free)
descriptor->ops->fd_free(descriptor);
kfree(descriptor);
free(descriptor);
}
}
+16 -15
View File
@@ -7,7 +7,7 @@
#include <vfs.h>
#include <debug.h>
#include <khash.h>
#include <memheap.h>
#include <malloc.h>
#include <lock.h>
#include <vm.h>
#include <Errors.h>
@@ -122,16 +122,16 @@ bootfs_create_vnode(struct bootfs *fs, const char *name)
{
struct bootfs_vnode *v;
v = kmalloc(sizeof(struct bootfs_vnode));
v = malloc(sizeof(struct bootfs_vnode));
if (v == NULL)
return NULL;
memset(v, 0, sizeof(struct bootfs_vnode));
v->id = atomic_add(&fs->next_vnode_id, 1);
v->name = kstrdup(name);
v->name = strdup(name);
if (v->name == NULL) {
kfree(v);
free(v);
return NULL;
}
@@ -144,16 +144,17 @@ bootfs_delete_vnode(struct bootfs *fs, struct bootfs_vnode *v, bool force_delete
{
// cant delete it if it's in a directory or is a directory
// and has children
if(!force_delete && ((v->stream.type == STREAM_TYPE_DIR && v->stream.u.dir.dir_head != NULL) || v->dir_next != NULL)) {
if (!force_delete
&& ((v->stream.type == STREAM_TYPE_DIR && v->stream.u.dir.dir_head != NULL)
|| v->dir_next != NULL))
return EPERM;
}
// remove it from the global hash table
hash_remove(fs->vnode_list_hash, v);
if(v->name != NULL)
kfree(v->name);
kfree(v);
if (v->name != NULL)
free(v->name);
free(v);
return 0;
}
@@ -397,7 +398,7 @@ bootfs_mount(mount_id id, const char *device, void *args, fs_volume *_fs, vnode_
TRACE(("bootfs_mount: entry\n"));
fs = kmalloc(sizeof(struct bootfs));
fs = malloc(sizeof(struct bootfs));
if(fs == NULL) {
err = ENOMEM;
goto err;
@@ -452,7 +453,7 @@ err3:
err2:
mutex_destroy(&fs->lock);
err1:
kfree(fs);
free(fs);
err:
return err;
}
@@ -476,7 +477,7 @@ bootfs_unmount(fs_volume _fs)
hash_uninit(fs->vnode_list_hash);
mutex_destroy(&fs->lock);
kfree(fs);
free(fs);
return 0;
}
@@ -620,7 +621,7 @@ bootfs_open(fs_volume _fs, fs_vnode _v, int oflags, fs_cookie *_cookie)
TRACE(("bootfs_open: vnode %p, oflags 0x%x\n", vnode, oflags));
cookie = kmalloc(sizeof(struct bootfs_cookie));
cookie = malloc(sizeof(struct bootfs_cookie));
if (cookie == NULL)
return ENOMEM;
@@ -659,7 +660,7 @@ bootfs_free_cookie(fs_volume _fs, fs_vnode _v, fs_cookie _cookie)
TRACE(("bootfs_freecookie: entry vnode %p, cookie %p\n", v, cookie));
if (cookie)
kfree(cookie);
free(cookie);
return 0;
}
@@ -804,7 +805,7 @@ bootfs_open_dir(fs_volume _fs, fs_vnode _v, fs_cookie *_cookie)
if (vnode->stream.type != STREAM_TYPE_DIR)
return EINVAL;
cookie = kmalloc(sizeof(struct bootfs_cookie));
cookie = malloc(sizeof(struct bootfs_cookie));
if (cookie == NULL)
return ENOMEM;
+15 -15
View File
@@ -7,7 +7,7 @@
#include <vfs.h>
#include <debug.h>
#include <khash.h>
#include <memheap.h>
#include <malloc.h>
#include <lock.h>
#include <vm.h>
#include <Errors.h>
@@ -137,16 +137,16 @@ devfs_create_vnode(struct devfs *fs, const char *name)
{
struct devfs_vnode *v;
v = kmalloc(sizeof(struct devfs_vnode));
v = malloc(sizeof(struct devfs_vnode));
if (v == NULL)
return NULL;
memset(v, 0, sizeof(struct devfs_vnode));
v->id = fs->next_vnode_id++;
v->name = kstrdup(name);
v->name = strdup(name);
if (v->name == NULL) {
kfree(v);
free(v);
return NULL;
}
@@ -172,8 +172,8 @@ devfs_delete_vnode(struct devfs *fs, struct devfs_vnode *v, bool force_delete)
vfs_put_vnode(fs->id, v->stream.u.dev.part_map->raw_vnode->id);
if (v->name != NULL)
kfree(v->name);
kfree(v);
free(v->name);
free(v);
return 0;
}
@@ -336,7 +336,7 @@ devfs_set_partition( struct devfs *fs, struct devfs_vnode *v,
return EINVAL;
// create partition map
part_map = kmalloc(sizeof(*part_map));
part_map = malloc(sizeof(*part_map));
if (!part_map)
return ENOMEM;
@@ -389,14 +389,14 @@ devfs_set_partition( struct devfs *fs, struct devfs_vnode *v,
err1:
mutex_unlock(&gDeviceFileSystem->lock);
kfree(part_map);
free(part_map);
return res;
err2:
mutex_unlock(&gDeviceFileSystem->lock);
vfs_put_vnode(fs->id, v->id);
kfree(part_map);
free(part_map);
return res;
}
@@ -419,7 +419,7 @@ devfs_mount(mount_id id, const char *devfs, void *args, fs_volume *_fs, vnode_id
goto err;
}
fs = kmalloc(sizeof(struct devfs));
fs = malloc(sizeof(struct devfs));
if (fs == NULL) {
err = ENOMEM;
goto err;
@@ -471,7 +471,7 @@ err3:
err2:
mutex_destroy(&fs->lock);
err1:
kfree(fs);
free(fs);
err:
return err;
}
@@ -495,7 +495,7 @@ devfs_unmount(fs_volume _fs)
hash_uninit(fs->vnode_list_hash);
mutex_destroy(&fs->lock);
kfree(fs);
free(fs);
return 0;
}
@@ -637,7 +637,7 @@ devfs_open(fs_volume _fs, fs_vnode _v, int oflags, fs_cookie *_cookie)
TRACE(("devfs_open: fs_cookie %p vnode %p, oflags 0x%x, fs_cookie %p \n", fs, vnode, oflags, _cookie));
cookie = kmalloc(sizeof(struct devfs_cookie));
cookie = malloc(sizeof(struct devfs_cookie));
if (cookie == NULL)
return ENOMEM;
@@ -682,7 +682,7 @@ devfs_free_cookie(fs_volume _fs, fs_vnode _v, fs_cookie _cookie)
}
if (cookie)
kfree(cookie);
free(cookie);
return 0;
}
@@ -792,7 +792,7 @@ devfs_open_dir(fs_volume _fs, fs_vnode _v, fs_cookie *_cookie)
if (vnode->stream.type != STREAM_TYPE_DIR)
return EINVAL;
cookie = kmalloc(sizeof(struct devfs_cookie));
cookie = malloc(sizeof(struct devfs_cookie));
if (cookie == NULL)
return ENOMEM;
+16 -16
View File
@@ -7,7 +7,7 @@
#include <vfs.h>
#include <debug.h>
#include <khash.h>
#include <memheap.h>
#include <malloc.h>
#include <lock.h>
#include <vm.h>
#include <Errors.h>
@@ -105,7 +105,7 @@ rootfs_create_vnode(struct rootfs *fs)
{
struct rootfs_vnode *v;
v = kmalloc(sizeof(struct rootfs_vnode));
v = malloc(sizeof(struct rootfs_vnode));
if (v == NULL)
return NULL;
@@ -128,8 +128,8 @@ rootfs_delete_vnode(struct rootfs *fs, struct rootfs_vnode *v, bool force_delete
hash_remove(fs->vnode_list_hash, v);
if (v->name != NULL)
kfree(v->name);
kfree(v);
free(v->name);
free(v);
return 0;
}
@@ -274,7 +274,7 @@ rootfs_mount(mount_id id, const char *device, void *args, fs_volume *_fs, vnode_
TRACE(("rootfs_mount: entry\n"));
fs = kmalloc(sizeof(struct rootfs));
fs = malloc(sizeof(struct rootfs));
if (fs == NULL)
return ENOMEM;
@@ -301,7 +301,7 @@ rootfs_mount(mount_id id, const char *device, void *args, fs_volume *_fs, vnode_
// set it up
vnode->parent = vnode;
vnode->name = kstrdup("");
vnode->name = strdup("");
if (vnode->name == NULL) {
err = ENOMEM;
goto err4;
@@ -324,7 +324,7 @@ err3:
err2:
mutex_destroy(&fs->lock);
err1:
kfree(fs);
free(fs);
return err;
}
@@ -351,7 +351,7 @@ rootfs_unmount(fs_volume _fs)
hash_uninit(fs->vnode_list_hash);
mutex_destroy(&fs->lock);
kfree(fs);
free(fs);
return 0;
}
@@ -517,7 +517,7 @@ rootfs_free_cookie(fs_volume _fs, fs_vnode _v, fs_cookie _cookie)
TRACE(("rootfs_freecookie: entry vnode %p, cookie %p\n", v, cookie));
#endif
if (cookie)
kfree(cookie);
free(cookie);
return 0;
}
@@ -579,7 +579,7 @@ rootfs_create_dir(fs_volume _fs, fs_vnode _dir, const char *name, int perms, vno
goto err;
}
created_vnode = true;
vnode->name = kstrdup(name);
vnode->name = strdup(name);
if (vnode->name == NULL) {
status = B_NO_MEMORY;
goto err1;
@@ -630,7 +630,7 @@ rootfs_open_dir(fs_volume _fs, fs_vnode _v, fs_cookie *_cookie)
if (vnode->stream.type != STREAM_TYPE_DIR)
return B_BAD_VALUE;
cookie = kmalloc(sizeof(struct rootfs_cookie));
cookie = malloc(sizeof(struct rootfs_cookie));
if (cookie == NULL)
return B_NO_MEMORY;
@@ -777,7 +777,7 @@ rootfs_symlink(fs_volume _fs, fs_vnode _dir, const char *name, const char *path,
goto err;
}
created_vnode = true;
vnode->name = kstrdup(name);
vnode->name = strdup(name);
if (vnode->name == NULL) {
status = B_NO_MEMORY;
goto err1;
@@ -788,7 +788,7 @@ rootfs_symlink(fs_volume _fs, fs_vnode _dir, const char *name, const char *path,
hash_insert(fs->vnode_list_hash, vnode);
vnode->stream.symlink.path = kstrdup(path);
vnode->stream.symlink.path = strdup(path);
if (vnode->stream.symlink.path == NULL) {
status = ENOMEM;
goto err1;
@@ -856,14 +856,14 @@ rootfs_rename(fs_volume _fs, fs_vnode _olddir, const char *oldname, fs_vnode _ne
} else {
char *ptr = v1->name;
v1->name = kstrdup(newname);
if(!v1->name) {
v1->name = strdup(newname);
if (!v1->name) {
// bad place to be, at least restore
v1->name = ptr;
err = ENOMEM;
goto err;
}
kfree(ptr);
free(ptr);
}
/* no need to remove and add it unless the dir is sorting */
+42 -37
View File
@@ -21,7 +21,7 @@
#include <khash.h>
#include <lock.h>
#include <thread.h>
#include <memheap.h>
#include <malloc.h>
#include <arch/cpu.h>
#include <elf.h>
#include <Errors.h>
@@ -301,7 +301,7 @@ new_file_system(const char *name, struct fs_ops *ops)
ASSERT_LOCKED_MUTEX(&gFileSystemsMutex);
fs = (struct file_system *)kmalloc(sizeof(struct file_system));
fs = (struct file_system *)malloc(sizeof(struct file_system));
if (fs == NULL)
return NULL;
@@ -333,7 +333,7 @@ unload_file_system(file_system *fs)
uninit();
// ToDo: unloading is not yet supported - we need a unload image_id first...
kfree(fs);
free(fs);
return B_OK;
}
@@ -505,7 +505,7 @@ create_new_vnode(void)
{
struct vnode *vnode;
vnode = (struct vnode *)kmalloc(sizeof(struct vnode));
vnode = (struct vnode *)malloc(sizeof(struct vnode));
if (vnode == NULL)
return NULL;
@@ -550,7 +550,7 @@ dec_vnode_ref_count(struct vnode *vnode, bool reenter)
hash_remove(gVnodeTable, vnode);
mutex_unlock(&gVnodeMutex);
kfree(vnode);
free(vnode);
err = 1;
} else {
@@ -660,7 +660,7 @@ err1:
err:
mutex_unlock(&gVnodeMutex);
if (vnode)
kfree(vnode);
free(vnode);
return err;
}
@@ -783,7 +783,7 @@ vnode_path_to_vnode(struct vnode *vnode, char *path, bool traverseLeafLink, stru
goto resolve_link_error;
}
buffer = kmalloc(SYS_MAX_PATH_LEN);
buffer = malloc(SYS_MAX_PATH_LEN);
if (buffer == NULL) {
status = B_NO_MEMORY;
goto resolve_link_error;
@@ -791,7 +791,7 @@ vnode_path_to_vnode(struct vnode *vnode, char *path, bool traverseLeafLink, stru
status = FS_CALL(nextVnode, read_link)(nextVnode->mount->cookie, nextVnode->private_node, buffer, SYS_MAX_PATH_LEN);
if (status < B_OK) {
kfree(buffer);
free(buffer);
resolve_link_error:
put_vnode(vnode);
@@ -817,7 +817,7 @@ resolve_link_error:
status = vnode_path_to_vnode(vnode, path, traverseLeafLink, &nextVnode, count + 1);
kfree(buffer);
free(buffer);
if (status < B_OK) {
put_vnode(vnode);
@@ -1185,7 +1185,7 @@ get_new_fd(int type, struct vnode *vnode, fs_cookie cookie, int openMode, bool k
fd = new_fd(get_current_io_context(kernel), descriptor);
if (fd < 0) {
kfree(descriptor);
free(descriptor);
return B_NO_MORE_FDS;
}
@@ -1369,7 +1369,7 @@ vfs_new_io_context(void *_parentContext)
struct io_context *context;
struct io_context *parentContext;
context = kmalloc(sizeof(struct io_context));
context = malloc(sizeof(struct io_context));
if (context == NULL)
return NULL;
@@ -1381,17 +1381,17 @@ vfs_new_io_context(void *_parentContext)
else
table_size = DEFAULT_FD_TABLE_SIZE;
context->fds = kmalloc(sizeof(struct file_descriptor *) * table_size);
context->fds = malloc(sizeof(struct file_descriptor *) * table_size);
if (context->fds == NULL) {
kfree(context);
free(context);
return NULL;
}
memset(context->fds, 0, sizeof(struct file_descriptor *) * table_size);
if (mutex_init(&context->io_mutex, "I/O context") < 0) {
kfree(context->fds);
kfree(context);
free(context->fds);
free(context);
return NULL;
}
@@ -1447,8 +1447,8 @@ vfs_free_io_context(void *_ioContext)
mutex_destroy(&context->io_mutex);
kfree(context->fds);
kfree(context);
free(context->fds);
free(context);
return 0;
}
@@ -1476,7 +1476,7 @@ vfs_resize_fd_table(struct io_context *context, const int newSize)
}
}
fds = kmalloc(sizeof(struct file_descriptor *) * newSize);
fds = malloc(sizeof(struct file_descriptor *) * newSize);
if (fds == NULL) {
status = ENOMEM;
goto out;
@@ -1486,7 +1486,7 @@ vfs_resize_fd_table(struct io_context *context, const int newSize)
} else {
// enlarge the fd table
fds = kmalloc(sizeof(struct file_descriptor *) * newSize);
fds = malloc(sizeof(struct file_descriptor *) * newSize);
if (fds == NULL) {
status = ENOMEM;
goto out;
@@ -1498,7 +1498,7 @@ vfs_resize_fd_table(struct io_context *context, const int newSize)
sizeof(void *) * (newSize - context->table_size));
}
kfree(context->fds);
free(context->fds);
context->fds = fds;
context->table_size = newSize;
@@ -1512,7 +1512,12 @@ status_t
notify_select_event(selectsync *_sync, uint32 ref)
{
select_sync *sync = (select_sync *)_sync;
// ToDo: check if we have to be compatible and have to export
// this function - it would be nice if we could have one
// where the callee can specify which event has occured
// (instead of this crypted "ref" thingie).
if (sync == NULL
|| sync->sem < B_OK
|| INDEX_FROM_REF(ref) > sync->count)
@@ -2584,7 +2589,7 @@ common_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet,
set_sem_owner(sync.sem, B_SYSTEM_TEAM);
sync.set = kmalloc(sizeof(select_info) * numfds);
sync.set = malloc(sizeof(select_info) * numfds);
if (sync.set == NULL) {
delete_sem(sync.sem);
return B_NO_MEMORY;
@@ -2666,7 +2671,7 @@ common_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet,
err:
delete_sem(sync.sem);
kfree(sync.set);
free(sync.set);
return count;
}
@@ -2690,7 +2695,7 @@ common_poll(struct pollfd *fds, nfds_t numfds, bigtime_t timeout, bool kernel)
set_sem_owner(sync.sem, B_SYSTEM_TEAM);
sync.set = kmalloc(sizeof(select_info) * numfds);
sync.set = malloc(sizeof(select_info) * numfds);
if (sync.set == NULL) {
delete_sem(sync.sem);
return B_NO_MEMORY;
@@ -2795,7 +2800,7 @@ common_poll(struct pollfd *fds, nfds_t numfds, bigtime_t timeout, bool kernel)
err:
delete_sem(sync.sem);
kfree(sync.set);
free(sync.set);
return count;
}
@@ -3356,7 +3361,7 @@ fs_mount(char *path, const char *device, const char *fsName, void *args, bool ke
mutex_lock(&gMountOpMutex);
mount = (struct fs_mount *)kmalloc(sizeof(struct fs_mount));
mount = (struct fs_mount *)malloc(sizeof(struct fs_mount));
if (mount == NULL) {
err = B_NO_MEMORY;
goto err;
@@ -3364,7 +3369,7 @@ fs_mount(char *path, const char *device, const char *fsName, void *args, bool ke
mount->vnodes_head = mount->vnodes_tail = NULL;
mount->mount_point = kstrdup(path);
mount->mount_point = strdup(path);
if (mount->mount_point == NULL) {
err = B_NO_MEMORY;
goto err1;
@@ -3451,9 +3456,9 @@ err3:
recursive_lock_destroy(&mount->rlock);
put_file_system(mount->fs);
err2:
kfree(mount->mount_point);
free(mount->mount_point);
err1:
kfree(mount);
free(mount);
err:
mutex_unlock(&gMountOpMutex);
@@ -3539,8 +3544,8 @@ fs_unmount(char *path, bool kernel)
// release the file system
put_file_system(mount->fs);
kfree(mount->mount_point);
kfree(mount);
free(mount->mount_point);
free(mount);
return 0;
@@ -4496,7 +4501,7 @@ user_select(int numfds, fd_set *userReadSet, fd_set *userWriteSet, fd_set *userE
// copy parameters
if (userReadSet != NULL) {
readSet = kmalloc(bytes);
readSet = malloc(bytes);
if (readSet == NULL) {
result = B_NO_MEMORY;
goto err;
@@ -4508,7 +4513,7 @@ user_select(int numfds, fd_set *userReadSet, fd_set *userWriteSet, fd_set *userE
}
if (userWriteSet != NULL) {
writeSet = kmalloc(bytes);
writeSet = malloc(bytes);
if (writeSet == NULL) {
result = B_NO_MEMORY;
goto err;
@@ -4520,7 +4525,7 @@ user_select(int numfds, fd_set *userReadSet, fd_set *userWriteSet, fd_set *userE
}
if (userErrorSet != NULL) {
errorSet = kmalloc(bytes);
errorSet = malloc(bytes);
if (errorSet == NULL) {
result = B_NO_MEMORY;
goto err;
@@ -4545,9 +4550,9 @@ user_select(int numfds, fd_set *userReadSet, fd_set *userWriteSet, fd_set *userE
result = B_BAD_ADDRESS;
err:
kfree(readSet);
kfree(writeSet);
kfree(errorSet);
free(readSet);
free(writeSet);
free(errorSet);
return result;
}
+92 -17
View File
@@ -8,6 +8,7 @@
#include <vm.h>
#include <lock.h>
#include <memheap.h>
#include <malloc.h>
#include <debug.h>
#include <arch/cpu.h>
@@ -60,6 +61,7 @@ struct heap_bin {
char *raw_list;
unsigned int raw_count;
};
static struct heap_bin bins[] = {
{16, PAGE_SIZE, 0, 0, 0, 0, 0},
{32, PAGE_SIZE, 0, 0, 0, 0, 0},
@@ -227,8 +229,11 @@ raw_alloc(unsigned int size, int bin_index)
}
// #pragma mark -
void *
kmalloc(unsigned int size)
malloc(size_t size)
{
void *address = NULL;
int bin_index;
@@ -317,7 +322,7 @@ out:
void
kfree(void *address)
free(void *address)
{
struct heap_page *page;
struct heap_bin *bin;
@@ -327,7 +332,7 @@ kfree(void *address)
return;
if ((addr)address < heap_base || (addr)address >= (heap_base + heap_size))
panic("kfree: asked to free invalid address %p\n", address);
panic("free(): asked to free invalid address %p\n", address);
#if USE_WALL
{
@@ -346,28 +351,28 @@ kfree(void *address)
#if PARANOID_POINTER_CHECK
if (!ptrchecklist_remove(address))
panic("kfree: asked to free invalid pointer %p\n", address);
panic("free(): asked to free invalid pointer %p\n", address);
#endif
mutex_lock(&heap_lock);
TRACE(("kfree: asked to free at ptr = %p\n", address));
TRACE(("free(): asked to free at ptr = %p\n", address));
page = &heap_alloc_table[((unsigned)address - heap_base) / PAGE_SIZE];
TRACE(("kfree: page %p: bin_index %d, free_count %d\n", page, page->bin_index, page->free_count));
TRACE(("free(): page %p: bin_index %d, free_count %d\n", page, page->bin_index, page->free_count));
if (page[0].bin_index >= bin_count)
panic("kfree: page %p: invalid bin_index %d\n", page, page->bin_index);
panic("free(): page %p: invalid bin_index %d\n", page, page->bin_index);
bin = &bins[page[0].bin_index];
// if((addr)address % bin->element_size != 0)
// panic("kfree: passed invalid pointer 0x%x! Supposed to be in bin for esize 0x%x\n", address, bin->element_size);
for(i = 0; i < bin->element_size / PAGE_SIZE; i++) {
if(page[i].bin_index != page[0].bin_index)
panic("kfree: not all pages in allocation match bin_index\n");
for (i = 0; i < bin->element_size / PAGE_SIZE; i++) {
if (page[i].bin_index != page[0].bin_index)
panic("free(): not all pages in allocation match bin_index\n");
page[i].free_count++;
}
@@ -375,10 +380,9 @@ kfree(void *address)
// walk the free list on this bin to make sure this address doesn't exist already
{
unsigned int *temp;
for(temp = bin->free_list; temp != NULL; temp = (unsigned int *)*temp) {
if(temp == (unsigned int *)address) {
panic("kfree: address %p already exists in bin free list\n", address);
}
for (temp = bin->free_list; temp != NULL; temp = (unsigned int *)*temp) {
if (temp == (unsigned int *)address)
panic("free(): address %p already exists in bin free list\n", address);
}
}
#endif
@@ -388,18 +392,89 @@ kfree(void *address)
bin->alloc_count--;
bin->free_count++;
//out:
mutex_unlock(&heap_lock);
}
/** Naive implementation of realloc() - it's very simple but
* it's there and working.
* It takes the bin of the current allocation if the new size
* fits in and is larger than the size of the next smaller bin.
* If not, it allocates a new chunk of memory, and copies and
* frees the old buffer.
*/
void *
realloc(void *address, size_t newSize)
{
void *newAddress = NULL;
size_t maxSize = 0, minSize;
if (address != NULL && ((addr)address < heap_base || (addr)address >= (heap_base + heap_size)))
panic("realloc(): asked to realloc invalid address %p\n", address);
if (newSize == 0) {
free(address);
return NULL;
}
// find out the size of the old allocation first
if (address != NULL) {
struct heap_page *page;
mutex_lock(&heap_lock);
page = &heap_alloc_table[((unsigned)address - heap_base) / PAGE_SIZE];
TRACE(("realloc(): page %p: bin_index %d, free_count %d\n", page, page->bin_index, page->free_count));
if (page[0].bin_index >= bin_count)
panic("realloc(): page %p: invalid bin_index %d\n", page, page->bin_index);
maxSize = bins[page[0].bin_index].element_size;
minSize = page[0].bin_index > 0 ? bins[page[0].bin_index - 1].element_size : 0;
mutex_unlock(&heap_lock);
// does the new allocation simply fit in the bin?
if (newSize > minSize && newSize < maxSize)
return address;
}
// if not, allocate a new chunk of memory
newAddress = malloc(newSize);
if (newAddress == NULL)
return NULL;
// copy the old data and free the old allocation
if (address) {
// we do have the maxSize of the bin at this point
memcpy(newAddress, address, min(maxSize, newSize));
free(address);
}
return newAddress;
}
void *
calloc(size_t numElements, size_t size)
{
void *address = malloc(numElements * size);
if (address != NULL)
memset(address, 0, numElements * size);
return address;
}
/*
char *
kstrdup(const char *text)
{
char *buf = (char *)kmalloc(strlen(text) + 1);
if (buf != NULL)
strcpy(buf,text);
strcpy(buf, text);
return buf;
}
*/
+5 -4
View File
@@ -6,7 +6,7 @@
#include <kernel.h>
#include <int.h>
#include <debug.h>
#include <memheap.h>
#include <malloc.h>
#include <smp.h>
#include <arch/int.h>
#include <errno.h>
@@ -58,7 +58,7 @@ int_init(kernel_args *ka)
int
int_init2(kernel_args *ka)
{
io_vectors = (struct io_vector *)kmalloc(sizeof(struct io_vector) * NUM_IO_VECTORS);
io_vectors = (struct io_vector *)malloc(sizeof(struct io_vector) * NUM_IO_VECTORS);
if (io_vectors == NULL)
panic("int_init2: could not create io vector table!\n");
@@ -88,9 +88,10 @@ install_interrupt_handler(long vector, interrupt_handler handler, void *data)
* PCI drivers. Where we have multiple handlers we will call each in turn
* until one returns a value other than B_UNHANDLED_INTERRUPT.
*/
io = (struct io_handler *)kmalloc(sizeof(struct io_handler));
io = (struct io_handler *)malloc(sizeof(struct io_handler));
if (io == NULL)
return ENOMEM;
io->func = handler;
io->data = data;
@@ -164,7 +165,7 @@ remove_interrupt_handler(long vector, interrupt_handler handler, void *data)
/* we have to match both function and data */
if (io->func == handler && io->data == data) {
remque(io);
kfree(io);
free(io);
rv = 0;
break;
}
+5 -9
View File
@@ -4,7 +4,7 @@
** Distributed under the terms of the NewOS License.
*/
#include <memheap.h>
#include <malloc.h>
#include <debug.h>
#include <Errors.h>
#include <string.h>
@@ -13,10 +13,6 @@
// ToDo: this file apparently contains two different hash implementations
// get rid of one of them, and update the external code.
// ToDo: remove these
#define malloc kmalloc
#define free kfree
struct hash_table {
struct hash_elem **table;
int next_ptr_offset;
@@ -249,14 +245,14 @@ hash_make(void)
{
new_hash_table *nn;
nn = (new_hash_table *)kmalloc(sizeof(new_hash_table));
nn = (new_hash_table *)malloc(sizeof(new_hash_table));
if (!nn)
return NULL;
nn->count = 0;
nn->max = MAX_INITIAL;
nn->array = (hash_entry **)kmalloc(sizeof(hash_entry) * (nn->max + 1));
nn->array = (hash_entry **)malloc(sizeof(hash_entry) * (nn->max + 1));
memset(nn->array, 0, sizeof(hash_entry) * (nn->max +1));
pool_init(&nn->pool, sizeof(hash_entry));
if (!nn->pool)
@@ -298,14 +294,14 @@ expand_array(new_hash_table *nh)
int new_max = nh->max * 2 +1;
int i;
new_array = (hash_entry **)kmalloc(sizeof(hash_entry) * new_max);
new_array = (hash_entry **)malloc(sizeof(hash_entry) * new_max);
memset(new_array, 0, sizeof(hash_entry) * new_max);
for (hi = new_hash_first(nh); hi; hi = new_hash_next(hi)) {
i = hi->this_idx->hash & new_max;
hi->this_idx->next = new_array[i];
new_array[i] = hi->this_idx;
}
kfree(nh->array);
free(nh->array);
nh->array = new_array;
nh->max = new_max;
}
+27 -27
View File
@@ -13,7 +13,7 @@
#include <debug.h>
#include <khash.h>
#include <kqueue.h>
#include <memheap.h>
#include <malloc.h>
#include <elf.h>
#include <stdio.h>
#include <string.h>
@@ -192,20 +192,20 @@ load_module_file(const char *path)
return NULL;
}
lm = (loaded_module*)kmalloc(sizeof(loaded_module));
lm = (loaded_module*)malloc(sizeof(loaded_module));
if (!lm)
return NULL;
lm->info = (module_info**) elf_lookup_symbol(file_image, "modules");
if (!lm->info) {
dprintf("Failed to load %s due to lack of 'modules' symbol\n", path);
kfree(lm);
free(lm);
return NULL;
}
lm->path = (char*)kmalloc(strlen(path) + 1);
lm->path = (char*)malloc(strlen(path) + 1);
if (!lm->path) {
kfree(lm);
free(lm);
return NULL;
}
strcpy(lm->path, path);
@@ -245,7 +245,7 @@ dprintf("unload_mdoule_file: %s\n", path);
recursive_lock_unlock(&modules_lock);
elf_unload_kspace(themod->path);
kfree(themod);
free(themod);
}
@@ -272,23 +272,23 @@ simple_module_info(module_info *mod, const char *file, int offset)
return -1;
}
if ((m = (module*)kmalloc(sizeof(module))) == NULL)
if ((m = (module*)malloc(sizeof(module))) == NULL)
return -1;
SHOW_FLOW(3, "simple_module_info(%s, %s)\n", mod->name, file);
dprintf("simple_module_info: '%s'\n", mod->name);
m->module = NULL; /* back pointer */
m->name = (char*)kmalloc(strlen(mod->name) + 1);
m->name = (char*)malloc(strlen(mod->name) + 1);
if (!m->name) {
kfree(m);
free(m);
return -1;
}
strcpy(m->name, mod->name);
m->state = MOD_QUERIED;
/* Record where the module_info can be found */
m->offset = offset;
m->file = (char*)kstrdup(file);
m->file = strdup(file);
m->ref_cnt = 0;
/* set the keep_loaded flag */
if (mod->flags & B_KEEP_LOADED) {
@@ -378,7 +378,7 @@ recurse_directory(const char *path, const char *match)
if ((dir = sys_open_dir(path)) < 0)
return -1;
dirent = kmalloc(bufferSize);
dirent = malloc(bufferSize);
if (!dirent) {
sys_close(dir);
return -1;
@@ -397,13 +397,13 @@ recurse_directory(const char *path, const char *match)
dirent->d_name[dirent->d_reclen] = '\0';
slen = strlen(path) + strlen(dirent->d_name) + 2;
newpath = (char*)kmalloc(slen);
newpath = (char*)malloc(slen);
strlcpy(newpath, path, slen);
strlcat(newpath, "/", slen);
strlcat(newpath, dirent->d_name, slen);
if ((res = stat(newpath, &st)) != B_NO_ERROR) {
kfree(newpath);
free(newpath);
break;
}
@@ -426,10 +426,10 @@ recurse_directory(const char *path, const char *match)
} else if (S_ISDIR(st.st_mode)) {
res = recurse_directory(newpath, match);
}
kfree(newpath);
free(newpath);
}
kfree(dirent);
free(dirent);
sys_close(dir);
return res;
@@ -594,13 +594,13 @@ module_create_dir_iterator(module_iterator *iter, int file, const char *name)
*/
iter->cur_header = NULL;
dir = (struct module_dir_iterator *)kmalloc(sizeof(*dir));
dir = (struct module_dir_iterator *)malloc(sizeof(*dir));
if (dir == NULL )
return ENOMEM;
dir->name = (char *)kstrdup(name);
dir->name = strdup(name);
if (dir->name == NULL) {
kfree(dir);
free(dir);
return ENOMEM;
}
@@ -660,8 +660,8 @@ destroy_dir_iterator( module_iterator *iter )
iter->cur_dir = dir->parent_dir;
kfree(dir->name);
kfree(dir);
free(dir->name);
free(dir);
}
@@ -764,7 +764,7 @@ module_traverse_dir(module_iterator *iter)
module_info **hdrs = NULL;
if ((hdrs = load_module_file(path)) != NULL) {
iter->cur_header = hdrs;
iter->cur_path = (char*)kstrdup(path);
iter->cur_path = strdup(path);
return B_NO_ERROR;
}
return EINVAL; /* not sure what we should return here */
@@ -828,13 +828,13 @@ open_module_list(const char *prefix)
SHOW_FLOW( 3, "prefix: %s\n", prefix );
iter = (module_iterator *)kmalloc(sizeof( module_iterator));
iter = (module_iterator *)malloc(sizeof( module_iterator));
if (!iter)
return NULL;
iter->prefix = (char *)kstrdup( prefix );
if(iter->prefix == NULL) {
kfree(iter);
iter->prefix = strdup(prefix);
if (iter->prefix == NULL) {
free(iter);
return NULL;
}
@@ -906,8 +906,8 @@ close_module_list(void *cookie)
while(iter->cur_dir)
module_leave_dir(iter);
kfree(iter->prefix);
kfree(iter);
free(iter->prefix);
free(iter);
return 0;
}
+10 -10
View File
@@ -6,7 +6,7 @@
#include <KernelExport.h>
#include <pools.h>
#include <vm.h>
#include <memheap.h>
#include <malloc.h>
#include <atomic.h>
#include <ktypes.h>
#include <stdio.h>
@@ -70,7 +70,7 @@ static struct pool_mem *get_mem_block(struct pool_ctl *pool)
{
struct pool_mem *block;
block = (struct pool_mem *)kmalloc(sizeof(struct pool_mem));
block = (struct pool_mem *)malloc(sizeof(struct pool_mem));
if (block == NULL)
return NULL;
@@ -83,7 +83,7 @@ static struct pool_mem *get_mem_block(struct pool_ctl *pool)
REGION_WIRING_WIRED_CONTIG,
LOCK_KERNEL|LOCK_RW);
if (block->aid < 0) {
kfree(block);
free(block);
return NULL;
}
@@ -119,7 +119,7 @@ static struct pool_mem *get_mem_block(struct pool_ctl *pool)
UNINIT_BENAPHORE(block->lock);
vm_delete_region(vm_get_kernel_aspace_id(), block->aid);
kfree(block);
free(block);
return NULL;
}
@@ -138,7 +138,7 @@ int32 pool_init(struct pool_ctl **_newPool, size_t size)
// acquire_sem_etc(init_sem, 1, B_CAN_INTERRUPT, 0);
pool = (struct pool_ctl*)kmalloc(sizeof(struct pool_ctl));
pool = (struct pool_ctl *)malloc(sizeof(struct pool_ctl));
if (pool == NULL)
return ENOMEM;
@@ -147,13 +147,13 @@ int32 pool_init(struct pool_ctl **_newPool, size_t size)
#if POOL_USES_BENAPHORES
INIT_BENAPHORE(pool->lock, "pool_lock");
if (CHECK_BENAPHORE(pool->lock) < 0) {
kfree(pool);
free(pool);
return ENOLCK;
}
#else
INIT_RW_LOCK(pool->lock, "pool_lock");
if (CHECK_RW_LOCK(pool->lock) < 0) {
kfree(pool);
free(pool);
return ENOLCK;
}
#endif
@@ -172,7 +172,7 @@ int32 pool_init(struct pool_ctl **_newPool, size_t size)
#else
UNINIT_RW_LOCK(pool->lock);
#endif
kfree(pool);
free(pool);
return ENOMEM;
}
@@ -312,7 +312,7 @@ void pool_destroy(struct pool_ctl *p)
temp = mp;
mp = mp->next;
UNINIT_BENAPHORE(mp->lock);
kfree(temp);
free(temp);
}
#if POOL_USES_BENAPHORES
@@ -320,5 +320,5 @@ void pool_destroy(struct pool_ctl *p)
#else
UNINIT_RW_LOCK(p->lock);
#endif
kfree(p);
free(p);
}
+15 -15
View File
@@ -10,7 +10,7 @@
#include <kernel.h>
#include <arch/int.h>
#include <debug.h>
#include <memheap.h>
#include <malloc.h>
#include <cbuf.h>
#include <Errors.h>
#include <int.h>
@@ -21,7 +21,7 @@
struct port_msg {
int msg_code;
cbuf* data_cbuf;
cbuf *data_cbuf;
size_t data_len;
};
@@ -192,15 +192,15 @@ create_port(int32 queue_length, const char *name)
name_len = strlen(name) + 1;
name_len = min(name_len, SYS_MAX_OS_NAME_LEN);
temp_name = (char *)kmalloc(name_len);
temp_name = (char *)malloc(name_len);
if (temp_name == NULL)
return ENOMEM;
strlcpy(temp_name, name, name_len);
// alloc queue
q = (struct port_msg *)kmalloc( queue_length * sizeof(struct port_msg) );
q = (struct port_msg *)malloc(queue_length * sizeof(struct port_msg));
if (q == NULL) {
kfree(temp_name); // dealloc name, too
free(temp_name); // dealloc name, too
return ENOMEM;
}
@@ -212,8 +212,8 @@ create_port(int32 queue_length, const char *name)
sem_r = create_sem_etc(0, temp_name, -1);
if (sem_r < 0) {
// cleanup
kfree(temp_name);
kfree(q);
free(temp_name);
free(q);
return sem_r;
}
@@ -222,8 +222,8 @@ create_port(int32 queue_length, const char *name)
if (sem_w < 0) {
// cleanup
delete_sem(sem_r);
kfree(temp_name);
kfree(q);
free(temp_name);
free(q);
return sem_w;
}
owner = team_get_current_team_id();
@@ -269,8 +269,8 @@ create_port(int32 queue_length, const char *name)
// cleanup
delete_sem(sem_w);
delete_sem(sem_r);
kfree(temp_name);
kfree(q);
free(temp_name);
free(q);
out:
restore_interrupts(state);
@@ -334,7 +334,7 @@ delete_port(port_id id)
state = disable_interrupts();
GRAB_PORT_LOCK(ports[slot]);
if(ports[slot].id != id) {
if (ports[slot].id != id) {
RELEASE_PORT_LOCK(ports[slot]);
restore_interrupts(state);
dprintf("delete_port: invalid port_id %ld\n", id);
@@ -354,13 +354,13 @@ delete_port(port_id id)
restore_interrupts(state);
// delete the cbuf's that are left in the queue (if any)
for (i=0; i<capacity; i++) {
for (i = 0; i < capacity; i++) {
if (q[i].data_cbuf != NULL)
cbuf_free_chain(q[i].data_cbuf);
}
kfree(q);
kfree(old_name);
free(q);
free(old_name);
// release the threads that were blocking on this port by deleting the sem
// read_port() will see the B_BAD_SEM_ID acq_sem() return value, and act accordingly
+56 -31
View File
@@ -4,9 +4,10 @@
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#include <kernel.h>
#include <queue.h>
#include <memheap.h>
#include <malloc.h>
#include <errno.h>
typedef struct queue_element {
@@ -19,28 +20,32 @@ typedef struct queue_typed {
int count;
} queue_typed;
int queue_init(queue *q)
int
queue_init(queue *q)
{
q->head = q->tail = NULL;
q->count = 0;
return 0;
}
int queue_remove_item(queue *_q, void *e)
int
queue_remove_item(queue *_q, void *e)
{
queue_typed *q = (queue_typed *)_q;
queue_element *elem = (queue_element *)e;
queue_element *temp, *last = NULL;
temp = (queue_element *)q->head;
while(temp) {
if(temp == elem) {
if(last) {
while (temp) {
if (temp == elem) {
if (last)
last->next = temp->next;
} else {
else
q->head = temp->next;
}
if(q->tail == temp)
if (q->tail == temp)
q->tail = last;
q->count--;
return 0;
@@ -52,12 +57,14 @@ int queue_remove_item(queue *_q, void *e)
return -1;
}
int queue_enqueue(queue *_q, void *e)
int
queue_enqueue(queue *_q, void *e)
{
queue_typed *q = (queue_typed *)_q;
queue_element *elem = (queue_element *)e;
if(q->tail == NULL) {
if (q->tail == NULL) {
q->tail = elem;
q->head = elem;
} else {
@@ -69,37 +76,45 @@ int queue_enqueue(queue *_q, void *e)
return 0;
}
void *queue_dequeue(queue *_q)
void *
queue_dequeue(queue *_q)
{
queue_typed *q = (queue_typed *)_q;
queue_element *elem;
elem = q->head;
if(q->head != NULL)
if (q->head != NULL)
q->head = q->head->next;
if(q->tail == elem)
if (q->tail == elem)
q->tail = NULL;
if(elem != NULL)
if (elem != NULL)
q->count--;
return elem;
}
void *queue_peek(queue *q)
void *
queue_peek(queue *q)
{
return q->head;
}
// #pragma mark -
/* fixed queue stuff */
int fixed_queue_init(fixed_queue *q, int size)
int
fixed_queue_init(fixed_queue *q, int size)
{
if(size <= 0)
if (size <= 0)
return EINVAL;
q->table = kmalloc(size * sizeof(void *));
if(!q->table)
q->table = malloc(size * sizeof(void *));
if (!q->table)
return ENOMEM;
q->head = 0;
q->tail = 0;
@@ -109,41 +124,51 @@ int fixed_queue_init(fixed_queue *q, int size)
return 0;
}
void fixed_queue_destroy(fixed_queue *q)
void
fixed_queue_destroy(fixed_queue *q)
{
if(q->table)
kfree(q->table);
if (q->table)
free(q->table);
}
int fixed_queue_enqueue(fixed_queue *q, void *e)
int
fixed_queue_enqueue(fixed_queue *q, void *e)
{
if(q->count == q->size)
if (q->count == q->size)
return ENOMEM;
q->table[q->head++] = e;
if(q->head >= q->size) q->head = 0;
if (q->head >= q->size)
q->head = 0;
q->count++;
return 0;
}
void *fixed_queue_dequeue(fixed_queue *q)
void *
fixed_queue_dequeue(fixed_queue *q)
{
void *e;
if(q->count <= 0)
if (q->count <= 0)
return NULL;
e = q->table[q->tail++];
if(q->tail >= q->size) q->tail = 0;
if (q->tail >= q->size)
q->tail = 0;
q->count--;
return e;
}
void *fixed_queue_peek(fixed_queue *q)
void *
fixed_queue_peek(fixed_queue *q)
{
if(q->count <= 0)
if (q->count <= 0)
return NULL;
return q->table[q->tail];
+5 -4
View File
@@ -4,6 +4,7 @@
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#include <kernel.h>
#include <OS.h>
#include <sem.h>
@@ -12,7 +13,7 @@
#include <arch/int.h>
#include <timer.h>
#include <debug.h>
#include <memheap.h>
#include <malloc.h>
#include <thread.h>
#include <Errors.h>
#include <kerrors.h>
@@ -186,7 +187,7 @@ create_sem_etc(int32 count, const char *name, team_id owner)
name_len = strlen(name) + 1;
name_len = min(name_len, SYS_MAX_OS_NAME_LEN);
temp_name = (char *)kmalloc(name_len);
temp_name = (char *)malloc(name_len);
if (temp_name == NULL)
return B_NO_MEMORY;
strlcpy(temp_name, name, name_len);
@@ -226,7 +227,7 @@ create_sem_etc(int32 count, const char *name, team_id owner)
}
RELEASE_SEM_LIST_LOCK();
kfree(temp_name);
free(temp_name);
out:
restore_interrupts(state);
@@ -306,7 +307,7 @@ delete_sem_etc(sem_id id, status_t return_code, bool interrupted)
restore_interrupts(state);
kfree(old_name);
free(old_name);
return B_OK;
}
+87 -54
View File
@@ -4,6 +4,7 @@
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#include <kernel.h>
#include <thread.h>
#include <console.h>
@@ -12,7 +13,7 @@
#include <arch/int.h>
#include <smp_priv.h>
#include <smp.h>
#include <memheap.h>
#include <malloc.h>
#include <Errors.h>
#include <atomic.h>
@@ -97,10 +98,13 @@ release_spinlock(spinlock *lock)
*lock = 0;
}
// finds a free message and gets it
// NOTE: has side effect of disabling interrupts
// return value is interrupt state
static int find_free_message(struct smp_msg **msg)
static int
find_free_message(struct smp_msg **msg)
{
int state;
@@ -112,7 +116,7 @@ retry:
state = disable_interrupts();
acquire_spinlock(&free_msg_spinlock);
if(free_msg_count <= 0) {
if (free_msg_count <= 0) {
// someone grabbed one while we were getting the lock,
// go back to waiting for it
release_spinlock(&free_msg_spinlock);
@@ -131,7 +135,9 @@ retry:
return state;
}
static void return_free_message(struct smp_msg *msg)
static void
return_free_message(struct smp_msg *msg)
{
// dprintf("return_free_message: returning msg 0x%x\n", msg);
acquire_spinlock_nocheck(&free_msg_spinlock);
@@ -141,13 +147,15 @@ static void return_free_message(struct smp_msg *msg)
release_spinlock(&free_msg_spinlock);
}
static struct smp_msg *smp_check_for_message(int curr_cpu, int *source_mailbox)
static struct smp_msg *
smp_check_for_message(int curr_cpu, int *source_mailbox)
{
struct smp_msg *msg;
acquire_spinlock_nocheck(&cpu_msg_spinlock[curr_cpu]);
msg = smp_msgs[curr_cpu];
if(msg != NULL) {
if (msg != NULL) {
smp_msgs[curr_cpu] = msg->next;
release_spinlock(&cpu_msg_spinlock[curr_cpu]);
// dprintf(" found msg 0x%x in cpu mailbox\n", msg);
@@ -159,8 +167,8 @@ static struct smp_msg *smp_check_for_message(int curr_cpu, int *source_mailbox)
acquire_spinlock_nocheck(&broadcast_msg_spinlock);
msg = smp_broadcast_msgs;
while(msg != NULL) {
if(CHECK_BIT(msg->proc_bitmap, curr_cpu) != 0) {
while (msg != NULL) {
if (CHECK_BIT(msg->proc_bitmap, curr_cpu) != 0) {
// we have handled this one already
msg = msg->next;
continue;
@@ -184,14 +192,14 @@ smp_finish_message_processing(int curr_cpu, struct smp_msg *msg, int source_mail
int old_refcount;
old_refcount = atomic_add(&msg->ref_count, -1);
if(old_refcount == 1) {
if (old_refcount == 1) {
// we were the last one to decrement the ref_count
// it's our job to remove it from the list & possibly clean it up
struct smp_msg **mbox = NULL;
spinlock *spinlock = NULL;
// clean up the message from one of the mailboxes
switch(source_mailbox) {
switch (source_mailbox) {
case MAILBOX_BCAST:
mbox = &smp_broadcast_msgs;
spinlock = &broadcast_msg_spinlock;
@@ -206,7 +214,7 @@ smp_finish_message_processing(int curr_cpu, struct smp_msg *msg, int source_mail
// dprintf("cleaning up message 0x%x\n", msg);
if(msg == *mbox) {
if (msg == *mbox) {
(*mbox) = msg->next;
} else {
// we need to walk to find the message in the list.
@@ -217,25 +225,24 @@ smp_finish_message_processing(int curr_cpu, struct smp_msg *msg, int source_mail
struct smp_msg *msg1;
msg1 = *mbox;
while(msg1 != NULL && msg1 != msg) {
while (msg1 != NULL && msg1 != msg) {
last = msg1;
msg1 = msg1->next;
}
// by definition, last must be something
if(msg1 == msg && last != NULL) {
if (msg1 == msg && last != NULL)
last->next = msg->next;
} else {
else
dprintf("last == NULL or msg != msg1!!!\n");
}
}
release_spinlock(spinlock);
if(msg->data_ptr != NULL)
kfree(msg->data_ptr);
if (msg->data_ptr != NULL)
free(msg->data_ptr);
if(msg->flags == SMP_MSG_FLAG_SYNC) {
if (msg->flags == SMP_MSG_FLAG_SYNC) {
msg->done = true;
// the caller cpu should now free the message
} else {
@@ -245,7 +252,9 @@ smp_finish_message_processing(int curr_cpu, struct smp_msg *msg, int source_mail
}
}
static int smp_process_pending_ici(int curr_cpu)
static int
smp_process_pending_ici(int curr_cpu)
{
struct smp_msg *msg;
bool halt = false;
@@ -253,11 +262,11 @@ static int smp_process_pending_ici(int curr_cpu)
int retval = B_HANDLED_INTERRUPT;
msg = smp_check_for_message(curr_cpu, &source_mailbox);
if(msg == NULL)
if (msg == NULL)
return retval;
// dprintf(" message = %d\n", msg->message);
switch(msg->message) {
switch (msg->message) {
case SMP_MSG_INVL_PAGE_RANGE:
arch_cpu_invalidate_TLB_range((addr)msg->data, (addr)msg->data2);
break;
@@ -284,7 +293,7 @@ static int smp_process_pending_ici(int curr_cpu)
// special case for the halt message
// we otherwise wouldn't have gotten the opportunity to clean up
if(halt) {
if (halt) {
disable_interrupts();
for(;;);
}
@@ -292,7 +301,9 @@ static int smp_process_pending_ici(int curr_cpu)
return retval;
}
int smp_intercpu_int_handler(void)
int
smp_intercpu_int_handler(void)
{
int retval;
int curr_cpu = smp_get_current_cpu();
@@ -306,14 +317,16 @@ int smp_intercpu_int_handler(void)
return retval;
}
void smp_send_ici(int target_cpu, int message, unsigned long data, unsigned long data2, unsigned long data3, void *data_ptr, int flags)
void
smp_send_ici(int target_cpu, int message, unsigned long data, unsigned long data2, unsigned long data3, void *data_ptr, int flags)
{
struct smp_msg *msg;
// dprintf("smp_send_ici: target 0x%x, mess 0x%x, data 0x%x, data2 0x%x, data3 0x%x, ptr 0x%x, flags 0x%x\n",
// target_cpu, message, data, data2, data3, data_ptr, flags);
if(ici_enabled) {
if (ici_enabled) {
int state;
int curr_cpu;
@@ -321,7 +334,7 @@ void smp_send_ici(int target_cpu, int message, unsigned long data, unsigned long
state = find_free_message(&msg);
curr_cpu = smp_get_current_cpu();
if(target_cpu == curr_cpu) {
if (target_cpu == curr_cpu) {
return_free_message(msg);
restore_interrupts(state);
return; // nope, cant do that
@@ -345,11 +358,11 @@ void smp_send_ici(int target_cpu, int message, unsigned long data, unsigned long
arch_smp_send_ici(target_cpu);
if(flags == SMP_MSG_FLAG_SYNC) {
if (flags == SMP_MSG_FLAG_SYNC) {
// wait for the other cpu to finish processing it
// the interrupt handler will ref count it to <0
// if the message is sync after it has removed it from the mailbox
while(msg->done == false)
while (msg->done == false)
smp_process_pending_ici(curr_cpu);
// for SYNC messages, it's our responsibility to put it
// back into the free list
@@ -360,14 +373,16 @@ void smp_send_ici(int target_cpu, int message, unsigned long data, unsigned long
}
}
void smp_send_broadcast_ici(int message, unsigned long data, unsigned long data2, unsigned long data3, void *data_ptr, int flags)
void
smp_send_broadcast_ici(int message, unsigned long data, unsigned long data2, unsigned long data3, void *data_ptr, int flags)
{
struct smp_msg *msg;
// dprintf("smp_send_broadcast_ici: cpu %d mess 0x%x, data 0x%x, data2 0x%x, data3 0x%x, ptr 0x%x, flags 0x%x\n",
// smp_get_current_cpu(), message, data, data2, data3, data_ptr, flags);
if(ici_enabled) {
if (ici_enabled) {
int state;
int curr_cpu;
@@ -398,12 +413,12 @@ void smp_send_broadcast_ici(int message, unsigned long data, unsigned long data2
// dprintf("smp_send_broadcast_ici: sent interrupt\n");
if(flags == SMP_MSG_FLAG_SYNC) {
if (flags == SMP_MSG_FLAG_SYNC) {
// wait for the other cpus to finish processing it
// the interrupt handler will ref count it to <0
// if the message is sync after it has removed it from the mailbox
// dprintf("smp_send_broadcast_ici: waiting for ack\n");
while(msg->done == false)
while (msg->done == false)
smp_process_pending_ici(curr_cpu);
// dprintf("smp_send_broadcast_ici: returning message to free list\n");
// for SYNC messages, it's our responsibility to put it
@@ -416,26 +431,31 @@ void smp_send_broadcast_ici(int message, unsigned long data, unsigned long data2
// dprintf("smp_send_broadcast_ici: done\n");
}
int smp_trap_non_boot_cpus(kernel_args *ka, int cpu)
int
smp_trap_non_boot_cpus(kernel_args *ka, int cpu)
{
if(cpu > 0) {
if (cpu > 0) {
boot_cpu_spin[cpu] = 1;
acquire_spinlock(&boot_cpu_spin[cpu]);
return 1;
} else {
return 0;
}
return 0;
}
void smp_wake_up_all_non_boot_cpus()
void
smp_wake_up_all_non_boot_cpus()
{
int i;
for(i=1; i < smp_num_cpus; i++) {
for (i = 1; i < smp_num_cpus; i++) {
release_spinlock(&boot_cpu_spin[i]);
}
}
void smp_wait_for_ap_cpus(kernel_args *ka)
void
smp_wait_for_ap_cpus(kernel_args *ka)
{
unsigned int i;
int retry;
@@ -445,22 +465,24 @@ void smp_wait_for_ap_cpus(kernel_args *ka)
if(boot_cpu_spin[i] != 1)
retry = 1;
}
} while(retry == 1);
} while (retry == 1);
}
int smp_init(kernel_args *ka)
int
smp_init(kernel_args *ka)
{
struct smp_msg *msg;
int i;
dprintf("smp_init: entry\n");
if(ka->num_cpus > 1) {
if (ka->num_cpus > 1) {
free_msgs = NULL;
free_msg_count = 0;
for(i=0; i<MSG_POOL_SIZE; i++) {
msg = (struct smp_msg *)kmalloc(sizeof(struct smp_msg));
if(msg == NULL) {
for (i = 0; i < MSG_POOL_SIZE; i++) {
msg = (struct smp_msg *)malloc(sizeof(struct smp_msg));
if (msg == NULL) {
panic("error creating smp mailboxes\n");
return B_ERROR;
}
@@ -475,33 +497,44 @@ int smp_init(kernel_args *ka)
return arch_smp_init(ka);
}
void smp_set_num_cpus(int num_cpus)
void
smp_set_num_cpus(int num_cpus)
{
smp_num_cpus = num_cpus;
}
int smp_get_num_cpus()
int
smp_get_num_cpus()
{
return smp_num_cpus;
}
int smp_get_current_cpu(void)
int
smp_get_current_cpu(void)
{
struct thread *t = thread_get_current_thread();
if(t)
if (t)
return t->cpu->info.cpu_num;
else
return 0;
return 0;
}
int smp_enable_ici()
int
smp_enable_ici()
{
if(smp_num_cpus > 1) // dont actually do it if we only have one cpu
if (smp_num_cpus > 1) // dont actually do it if we only have one cpu
ici_enabled = true;
return B_NO_ERROR;
}
int smp_disable_ici()
int
smp_disable_ici()
{
ici_enabled = false;
return B_NO_ERROR;
+42 -29
View File
@@ -4,7 +4,7 @@
#include <errno.h>
#include <vm.h>
#include <debug.h>
#include <memheap.h>
#include <malloc.h>
#include <sysctl.h>
#include <KernelExport.h>
#include <Errors.h>
@@ -14,7 +14,7 @@
* XXX - horrible hack!
*/
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256 /* max hostname size */
# define MAXHOSTNAMELEN 256 /* max hostname size */
#endif
/* This is the place we store a few of the "global variables" that the OS
@@ -38,8 +38,8 @@ char kernel[] = "DEV";
char machine[] = "Intel";
char model[] = "MODEL";
int sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen)
int
sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
{
sysctlfn *fn = NULL;
int error = 0;
@@ -61,8 +61,10 @@ int sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
}
int sys_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen)
int
sys_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen)
{
int error = 0;
/* This will need to be uncommented when the definitions above have been removed and
@@ -96,8 +98,9 @@ int sys_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
/* If we get here we're in trouble... */
}
int hw_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen)
int
hw_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
{
/* This will need to be uncommented when the definitions above have been removed and
* we have these defined elsewhere...
@@ -115,42 +118,51 @@ int hw_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
/* If we get here we're in trouble... */
}
int sysctl_int (void *oldp, size_t *oldlenp, void *newp, size_t newlen,
int *valp)
int
sysctl_int(void *oldp, size_t *oldlenp, void *newp, size_t newlen, int *valp)
{
if (oldp && *oldlenp < sizeof(int))
return ENOMEM;
if (newp && newlen != sizeof(int))
return EINVAL;
*oldlenp = sizeof(int);
if (oldp)
*(int*)oldp = *valp;
if (newp)
*valp = *(int*)newp;
return 0;
}
int sysctl_rdint (void *oldp, size_t *oldlenp, void *newp, int val)
int
sysctl_rdint(void *oldp, size_t *oldlenp, void *newp, int val)
{
if (oldp && *oldlenp < sizeof(int))
return ENOMEM;
if (newp)
return EPERM;
*oldlenp = sizeof(int);
if (oldp)
*(int*)oldp = val;
return 0;
}
/* Copy string, truncating if required */
int sysctl_tstring(void *oldp, size_t *oldlenp, void *newp, size_t newlen,
char *str, int maxlen)
int
sysctl_tstring(void *oldp, size_t *oldlenp, void *newp, size_t newlen, char *str, int maxlen)
{
return sysctl__string(oldp, oldlenp, newp, newlen, str, maxlen, 1);
}
int sysctl__string(void *oldp, size_t *oldlenp, void *newp, size_t newlen,
char *str, int maxlen, int trunc)
int
sysctl__string(void *oldp, size_t *oldlenp, void *newp, size_t newlen,
char *str, int maxlen, int trunc)
{
int len = strlen(str) + 1;
int c;
@@ -161,6 +173,7 @@ int sysctl__string(void *oldp, size_t *oldlenp, void *newp, size_t newlen,
}
if (newp && newlen >= maxlen)
return EINVAL;
if (oldp) {
if (trunc && *oldlenp < len) {
/* need to truncate */
@@ -181,7 +194,9 @@ int sysctl__string(void *oldp, size_t *oldlenp, void *newp, size_t newlen,
return 0;
}
int sysctl_rdstring(void *oldp, size_t *oldlenp, void *newp, char *str)
int
sysctl_rdstring(void *oldp, size_t *oldlenp, void *newp, char *str)
{
int len = strlen(str) + 1;
if (oldp && *oldlenp < len)
@@ -194,7 +209,9 @@ int sysctl_rdstring(void *oldp, size_t *oldlenp, void *newp, char *str)
return 0;
}
int user_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
int
user_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen)
{
void *a1 = NULL, *a2 = NULL;
@@ -205,28 +222,28 @@ int user_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
return EINVAL;
if (name && namelen > 0) {
nam = (int*)kmalloc(namelen * sizeof(int));
nam = (int *)malloc(namelen * sizeof(int));
if (!nam)
return ENOMEM;
user_memcpy(nam, name, namelen * sizeof(int));
}
if (oldp && oldlenp) {
a1 = kmalloc(olen);
a1 = malloc(olen);
user_memcpy(a1, oldp, olen);
}
if (oldlenp) {
ov = (size_t*)kmalloc(sizeof(oldlenp));
ov = (size_t*)malloc(sizeof(oldlenp));
user_memcpy(ov, oldlenp, sizeof(oldlenp));
}
if (newp && newlen > 0) {
a2 = kmalloc(newlen);
a2 = malloc(newlen);
user_memcpy(a2, newp, newlen);
}
rc = sysctl(nam, namelen, a1, ov, a2, newlen);
if (nam)
kfree(nam);
free(nam);
if (rc != 0)
goto bailout;
@@ -241,14 +258,10 @@ int user_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
memcpy(newp, a2, newlen);
}
bailout:
if (a1)
kfree(a1);
if (a2)
kfree(a2);
if (ov)
kfree(ov);
free(a1);
free(a2);
free(ov);
return rc;
}
+17 -21
View File
@@ -1,8 +1,4 @@
/* team.c
*
* Team functions
*
*/
/* Team functions */
/*
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
@@ -15,7 +11,7 @@
#include <thread_types.h>
#include <int.h>
#include <khash.h>
#include <memheap.h>
#include <malloc.h>
#include <user_runtime.h>
#include <Errors.h>
#include <kerrors.h>
@@ -152,11 +148,11 @@ kfree_strings_array(char **strings, int strc)
{
int cnt = strc;
if(strings != NULL) {
for(cnt = 0; cnt < strc; cnt++){
kfree(strings[cnt]);
if (strings != NULL) {
for (cnt = 0; cnt < strc; cnt++){
free(strings[cnt]);
}
kfree(strings);
free(strings);
}
}
@@ -183,7 +179,7 @@ user_copy_strings_array(char **strings, int strc, char ***kstrings)
if ((addr)strings >= KERNEL_BASE && (addr)strings <= KERNEL_TOP)
return ERR_VM_BAD_USER_MEMORY;
lstrings = (char **)kmalloc((strc + 1) * sizeof(char *));
lstrings = (char **)malloc((strc + 1) * sizeof(char *));
if (lstrings == NULL){
return ENOMEM;
}
@@ -205,7 +201,7 @@ user_copy_strings_array(char **strings, int strc, char ***kstrings)
goto error;
buf[SYS_THREAD_STRING_LENGTH_MAX - 1] = 0;
lstrings[cnt] = (char *)kstrdup(buf);
lstrings[cnt] = strdup(buf);
if (lstrings[cnt] == NULL){
err = ENOMEM;
goto error;
@@ -359,7 +355,7 @@ create_team_struct(const char *name, bool kernel)
{
struct team *p;
p = (struct team *)kmalloc(sizeof(struct team));
p = (struct team *)malloc(sizeof(struct team));
if (p == NULL)
goto error;
@@ -386,7 +382,7 @@ create_team_struct(const char *name, bool kernel)
return p;
error1:
kfree(p);
free(p);
error:
return NULL;
}
@@ -395,7 +391,7 @@ error:
static void
delete_team_struct(struct team *p)
{
kfree(p);
free(p);
}
@@ -493,8 +489,8 @@ team_create_team2(void *args)
}
// free the args
kfree(pargs->path);
kfree(pargs);
free(pargs->path);
free(pargs);
dprintf("team_create_team2: loaded elf. entry = 0x%lx\n", entry);
@@ -534,12 +530,12 @@ team_create_team(const char *path, const char *name, char **args, int argc, char
restore_interrupts(state);
// copy the args over
pargs = (struct team_arg *)kmalloc(sizeof(struct team_arg));
pargs = (struct team_arg *)malloc(sizeof(struct team_arg));
if (pargs == NULL){
err = ENOMEM;
goto err1;
}
pargs->path = (char *)kstrdup(path);
pargs->path = strdup(path);
if (pargs->path == NULL){
err = ENOMEM;
goto err2;
@@ -583,9 +579,9 @@ err5:
err4:
vfs_free_io_context(p->ioctx);
err3:
kfree(pargs->path);
free(pargs->path);
err2:
kfree(pargs);
free(pargs);
err1:
// remove the team structure from the team hash table and delete the team structure
state = disable_interrupts();
+6 -6
View File
@@ -23,7 +23,7 @@
#include <port.h>
#include <vfs.h>
#include <elf.h>
#include <memheap.h>
#include <malloc.h>
#include <user_runtime.h>
#include <Errors.h>
#include <stage2.h>
@@ -242,7 +242,7 @@ create_thread_struct(const char *name)
restore_interrupts(state);
if (t == NULL) {
t = (struct thread *)kmalloc(sizeof(struct thread));
t = (struct thread *)malloc(sizeof(struct thread));
if (t == NULL)
goto err;
}
@@ -300,7 +300,7 @@ err3:
err2:
delete_sem_etc(t->return_code_sem, -1, false);
err1:
kfree(t);
free(t);
err:
return NULL;
}
@@ -315,7 +315,7 @@ delete_thread_struct(struct thread *t)
delete_sem_etc(t->msg.write_sem, -1, false);
if (t->msg.read_sem >= 0)
delete_sem_etc(t->msg.read_sem, -1, false);
kfree(t);
free(t);
}
@@ -838,7 +838,7 @@ thread_init(kernel_args *ka)
num_death_stacks = 8*sizeof(death_stack_bitmap);
}
death_stack_bitmap = 0;
death_stacks = (struct death_stack *)kmalloc(num_death_stacks * sizeof(struct death_stack));
death_stacks = (struct death_stack *)malloc(num_death_stacks * sizeof(struct death_stack));
if (death_stacks == NULL) {
panic("error creating death stacks\n");
return ENOMEM;
@@ -1049,7 +1049,7 @@ thread_exit(void)
delete_owned_ports(p->id);
sem_delete_owned_sems(p->id);
vfs_free_io_context(p->ioctx);
kfree(p);
free(p);
}
// delete the sem that others will use to wait on us and get the retcode
+15 -14
View File
@@ -15,6 +15,7 @@
#include <vm_store_null.h>
#include <vm_store_vnode.h>
#include <memheap.h>
#include <malloc.h>
#include <debug.h>
#include <console.h>
#include <int.h>
@@ -163,12 +164,12 @@ static vm_region *_vm_create_region_struct(vm_address_space *aspace, const char
{
vm_region *region = NULL;
region = (vm_region *)kmalloc(sizeof(vm_region));
region = (vm_region *)malloc(sizeof(vm_region));
if(region == NULL)
return NULL;
region->name = (char *)kmalloc(strlen(name) + 1);
region->name = (char *)malloc(strlen(name) + 1);
if(region->name == NULL) {
kfree(region);
free(region);
return NULL;
}
strcpy(region->name, name);
@@ -448,8 +449,8 @@ err1a:
vm_cache_release_ref(cache_ref);
}
err:
kfree(region->name);
kfree(region);
free(region->name);
free(region);
return err;
}
@@ -992,8 +993,8 @@ static void _vm_put_region(vm_region *region, bool aspace_locked)
vm_put_aspace(aspace);
if(region->name)
kfree(region->name);
kfree(region);
free(region->name);
free(region);
return;
}
@@ -1467,9 +1468,9 @@ void vm_put_aspace(vm_address_space *aspace)
(*aspace->translation_map.ops->destroy)(&aspace->translation_map);
kfree(aspace->name);
free(aspace->name);
delete_sem(aspace->virtual_map.sem);
kfree(aspace);
free(aspace);
return;
}
@@ -1480,15 +1481,15 @@ aspace_id vm_create_aspace(const char *name, addr base, addr size, bool kernel)
int err;
aspace = (vm_address_space *)kmalloc(sizeof(vm_address_space));
aspace = (vm_address_space *)malloc(sizeof(vm_address_space));
if(aspace == NULL)
return ENOMEM;
dprintf("vm_create_aspace: %s: %lx bytes starting at 0x%lx => %p\n", name, size, base, aspace);
aspace->name = (char *)kmalloc(strlen(name) + 1);
aspace->name = (char *)malloc(strlen(name) + 1);
if(aspace->name == NULL ) {
kfree(aspace);
free(aspace);
return ENOMEM;
}
strcpy(aspace->name, name);
@@ -1506,8 +1507,8 @@ aspace_id vm_create_aspace(const char *name, addr base, addr size, bool kernel)
// initialize the corresponding translation map
err = vm_translation_map_create(&aspace->translation_map, kernel);
if(err < 0) {
kfree(aspace->name);
kfree(aspace);
free(aspace->name);
free(aspace);
return err;
}
+6 -5
View File
@@ -2,12 +2,13 @@
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#include <kernel.h>
#include <vm.h>
#include <vm_priv.h>
#include <vm_cache.h>
#include <vm_page.h>
#include <memheap.h>
#include <malloc.h>
#include <int.h>
#include <khash.h>
#include <lock.h>
@@ -78,7 +79,7 @@ vm_cache *vm_cache_create(vm_store *store)
{
vm_cache *cache;
cache = kmalloc(sizeof(vm_cache));
cache = malloc(sizeof(vm_cache));
if(cache == NULL)
return NULL;
@@ -99,7 +100,7 @@ vm_cache_ref *vm_cache_ref_create(vm_cache *cache)
{
vm_cache_ref *ref;
ref = kmalloc(sizeof(vm_cache_ref));
ref = malloc(sizeof(vm_cache_ref));
if(ref == NULL)
return NULL;
@@ -168,8 +169,8 @@ void vm_cache_release_ref(vm_cache_ref *cache_ref)
vm_cache_release_ref(cache_ref->cache->source->ref);
mutex_destroy(&cache_ref->lock);
kfree(cache_ref->cache);
kfree(cache_ref);
free(cache_ref->cache);
free(cache_ref);
return;
}
@@ -2,9 +2,10 @@
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#include <kernel.h>
#include <vm.h>
#include <memheap.h>
#include <malloc.h>
#include <debug.h>
#include <vm_store_anonymous_noswap.h>
#include <Errors.h>
@@ -14,7 +15,7 @@
static void anonymous_destroy(struct vm_store *store)
{
if(store) {
kfree(store);
free(store);
}
}
@@ -70,7 +71,7 @@ vm_store *vm_store_create_anonymous_noswap()
{
vm_store *store;
store = kmalloc(sizeof(vm_store));
store = malloc(sizeof(vm_store));
if(store == NULL)
return NULL;
+4 -3
View File
@@ -2,9 +2,10 @@
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#include <kernel.h>
#include <vm.h>
#include <memheap.h>
#include <malloc.h>
#include <debug.h>
#include <lock.h>
#include <vm_store_device.h>
@@ -19,7 +20,7 @@ struct device_store_data {
static void device_destroy(struct vm_store *store)
{
if(store) {
kfree(store);
free(store);
}
}
@@ -100,7 +101,7 @@ vm_store *vm_store_create_device(addr base_addr)
vm_store *store;
struct device_store_data *d;
store = kmalloc(sizeof(vm_store) + sizeof(struct device_store_data));
store = malloc(sizeof(vm_store) + sizeof(struct device_store_data));
if(store == NULL)
return NULL;
+4 -3
View File
@@ -2,9 +2,10 @@
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#include <kernel.h>
#include <vm.h>
#include <memheap.h>
#include <malloc.h>
#include <debug.h>
#include <lock.h>
#include <vm_store_null.h>
@@ -15,7 +16,7 @@
static void null_destroy(struct vm_store *store)
{
if(store) {
kfree(store);
free(store);
}
}
@@ -61,7 +62,7 @@ vm_store *vm_store_create_null(void)
{
vm_store *store;
store = kmalloc(sizeof(vm_store));
store = malloc(sizeof(vm_store));
if(store == NULL) {
return NULL;
}
+3 -3
View File
@@ -5,7 +5,7 @@
#include <kernel.h>
#include <vm.h>
#include <memheap.h>
#include <malloc.h>
#include <debug.h>
#include <lock.h>
#include <vm_store_vnode.h>
@@ -21,7 +21,7 @@ struct vnode_store_data {
static void vnode_destroy(struct vm_store *store)
{
if(store) {
kfree(store);
free(store);
}
}
@@ -83,7 +83,7 @@ vm_store *vm_store_create_vnode(void *vnode)
vm_store *store;
struct vnode_store_data *d;
store = kmalloc(sizeof(vm_store) + sizeof(struct vnode_store_data));
store = malloc(sizeof(vm_store) + sizeof(struct vnode_store_data));
if(store == NULL) {
vfs_put_vnode_ptr(vnode);
return NULL;
+5 -5
View File
@@ -6,7 +6,7 @@
#include <kernel.h>
#include <console.h>
#include <debug.h>
#include <memheap.h>
#include <malloc.h>
#include <int.h>
#include <vm.h>
#include <lock.h>
@@ -434,12 +434,12 @@ fb_console_dev_init(kernel_args *ka)
dprintf("console %p\n", &console);
// allocate some memory for this
console.render_buf = kmalloc(console.fb_x * console.fb_pixel_bytes);
console.render_buf = malloc(console.fb_x * console.fb_pixel_bytes);
memset((void *)console.render_buf, 0, console.fb_x * console.fb_pixel_bytes);
console.buf = kmalloc(console.rows * (console.columns+1));
console.buf = malloc(console.rows * (console.columns+1));
memset(console.buf, 0, console.rows * (console.columns+1));
console.lines = kmalloc(console.rows * sizeof(char *));
console.dirty_lines = kmalloc(console.rows);
console.lines = malloc(console.rows * sizeof(char *));
console.dirty_lines = malloc(console.rows);
// set up the line pointers
for (i = 0; i < console.rows; i++) {
console.lines[i] = (char *)((addr)console.buf + i*(console.columns+1));