Skip to content

Commit

Permalink
o Correct possible memory leak in platform/darwin.c
Browse files Browse the repository at this point in the history
o Stop trying to finesse the number of CPU's reported
  in kernel/user.c
o General code cleanup
  • Loading branch information
Mike Miller committed Nov 14, 2023
1 parent 059752c commit 1f947d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 0 additions & 4 deletions kernel/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,9 @@ int user_write(addr_t addr, const void *buf, size_t count) {
}

int user_read_string(addr_t addr, char *buf, size_t max) {
////modify_critical_region_counter(current, 1, __FILE__, __LINE__);
if (addr == 0) {
////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
return 1;
}
//modify_critical_region_counter(current, 1, __FILE__, __LINE__);
read_lock(&current->mem->lock, __FILE__, __LINE__);
size_t i = 0;
while (i < max) {
Expand All @@ -102,7 +99,6 @@ int user_read_string(addr_t addr, char *buf, size_t max) {
i++;
}
read_unlock(&current->mem->lock, __FILE__, __LINE__);
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
return 0;
}

Expand Down
7 changes: 2 additions & 5 deletions platform/darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ struct uptime_info get_uptime(void) {
struct uptime_info uptime = {
//.uptime_ticks = now.tv_sec - kern_boottime[0],
.uptime_ticks = (now.tv_sec - boot_time) * 100, // Note that busybox uptime doesn't like the multiplier. -mke
//.uptime_ticks = getSystemUptime() * 100, // This works but shouldn't. -mke
.load_1m = vm_loadavg.ldavg[0],
.load_5m = vm_loadavg.ldavg[1],
.load_15m = vm_loadavg.ldavg[2],
Expand All @@ -99,10 +98,7 @@ struct uptime_info get_uptime(void) {
int get_cpu_count(void) {
int ncpu;
size_t size = sizeof(int);
if((!doEnableMulticore))
ncpu = 1; // Return one when Multicore is disabled -mke
else
sysctlbyname("hw.ncpu", &ncpu, &size, NULL, 0);
sysctlbyname("hw.ncpu", &ncpu, &size, NULL, 0);
return ncpu;
}

Expand All @@ -119,6 +115,7 @@ int get_per_cpu_usage(struct cpu_usage** cpus_usage) {

struct cpu_usage* cpus_load_data = (struct cpu_usage*)calloc(ncpu, sizeof(struct cpu_usage));
if (!cpus_load_data) {
munmap(sys_load_data, vm_page_size);
return _ENOMEM;
}

Expand Down
9 changes: 8 additions & 1 deletion util/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ typedef struct {
extern lock_t atomic_l_lock; // Used to make all lock operations atomic, even read->write and right->read -mke

static inline void lock_init(lock_t *lock, char lname[16]) {
pthread_mutex_init(&lock->m, NULL);
int ret = pthread_mutex_init(&lock->m, NULL);
if (ret != 0) {
// Handle the error according to your application's needs
printk("ERROR: Failed to initialize mutex: %s:(%s)\n", lname, strerror(ret));
// Depending on how critical this failure is, you might choose to exit, return, or take other actions.
return;
}

if(lname != NULL) {
strncpy(lock->lname, lname, 16);
} else {
Expand Down

0 comments on commit 1f947d5

Please sign in to comment.