From 7e0dc553966e9ac1d0506e8cce9ae3f4708f124b Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Fri, 13 Aug 2010 19:05:13 +0200 Subject: update_pid_entries(): fix awkwardly indented uninitialized memory leak * procfs_pid_files.c (update_pid_entries): Replace dynamic allocation of `stat' with automatic allocation. Memset `stat' to 0. --- procfs_pid_files.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/procfs_pid_files.c b/procfs_pid_files.c index 46861531..d44a2a22 100644 --- a/procfs_pid_files.c +++ b/procfs_pid_files.c @@ -46,14 +46,12 @@ update_pid_entries (struct procfs_dir *dir, const char *name, time_t timestamp, const char *symlink_target) { - struct procfs_dir_entry *dir_entry; - struct stat *stat = (struct stat *) malloc (sizeof (struct stat)); - stat->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; + struct stat stat; - dir_entry = update_entries_list (dir, name, stat, - timestamp, symlink_target); + memset (&stat, 0, sizeof stat); + stat->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; - return dir_entry; + return update_entries_list (dir, name, &stat, timestamp, symlink_target); } /* Creates files to store process information for DIR -- cgit v1.2.3 From 0e63733ee60d0b9fa56ec47bdb088d4b835ec217 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Fri, 13 Aug 2010 19:05:14 +0200 Subject: Set an appropriate st_mode on symlinks. * procfs_pid_files.c (update_pid_entries): When symlink_target is not NULL, set st_size to the symlink length and st_mode to S_IFLNK | 0777. --- procfs_pid_files.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/procfs_pid_files.c b/procfs_pid_files.c index d44a2a22..26a0af33 100644 --- a/procfs_pid_files.c +++ b/procfs_pid_files.c @@ -49,7 +49,16 @@ update_pid_entries (struct procfs_dir *dir, const char *name, struct stat stat; memset (&stat, 0, sizeof stat); - stat->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; + if (symlink_target) + { + stat.st_size = strlen (symlink_target); + stat.st_mode = S_IFLNK | 0777; + } + else + { + stat.st_size = 0; + stat.st_mode = S_IFREG | 0444; + } return update_entries_list (dir, name, &stat, timestamp, symlink_target); } -- cgit v1.2.3 From 7070feccb2e4d135d5620805de6cec177722b837 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Mon, 16 Aug 2010 13:36:52 +0200 Subject: Implement /proc/mounts as a symlink to /etc/mtab * procfs_nonpid_files.c (procfs_create_mounts): New function. * procfs_dir.c (procfs_fill_root_dir): Call procfs_create_mounts. Signed-off-by: Jeremie Koenig --- procfs_dir.c | 3 +++ procfs_nonpid_files.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/procfs_dir.c b/procfs_dir.c index f76e6a4b..bd1e49d6 100644 --- a/procfs_dir.c +++ b/procfs_dir.c @@ -654,6 +654,9 @@ procfs_fill_root_dir(struct procfs_dir *dir, time_t timestamp) if ((err = procfs_create_loadavg (dir, &node, timestamp)) != 0) return err; + if ((err = procfs_create_mounts (dir, &node, timestamp)) != 0) + return err; + return 0; } diff --git a/procfs_nonpid_files.c b/procfs_nonpid_files.c index 2c1209ee..f1300666 100644 --- a/procfs_nonpid_files.c +++ b/procfs_nonpid_files.c @@ -166,6 +166,19 @@ error_t procfs_create_loadavg (struct procfs_dir *dir, return err; } +error_t procfs_create_mounts (struct procfs_dir *dir, + struct node **node, + time_t timestamp) +{ + struct procfs_dir_entry *dir_entry; + int err; + + dir_entry = update_pid_entries (dir, "mounts", timestamp, "/etc/mtab"); + err = procfs_create_node (dir_entry, "mounts", node); + + return err; +} + error_t get_uptime (struct timeval *uptime) { struct timeval boot_time, now; -- cgit v1.2.3 From 2a16fe6746b96aff3b54c36e02ad1628ecf0dd8e Mon Sep 17 00:00:00 2001 From: Sergio Lopez Date: Fri, 27 Aug 2010 00:08:36 +0200 Subject: Fix missing mutex unlock. * serverboot/default_pager.c (pager_read_offset): Properly unlock the mutex before returning NO_BLOCK. --- serverboot/default_pager.c | 1 + 1 file changed, 1 insertion(+) diff --git a/serverboot/default_pager.c b/serverboot/default_pager.c index c40f7181..aa7b0885 100644 --- a/serverboot/default_pager.c +++ b/serverboot/default_pager.c @@ -1154,6 +1154,7 @@ pager_read_offset(pager, offset) { ddprintf ("%spager_read_offset pager %x: bad page %d >= size %d", my_name, pager, f_page, pager->size); + mutex_unlock(&pager->lock); return (union dp_map) (union dp_map *) NO_BLOCK; #if 0 panic("%spager_read_offset",my_name); -- cgit v1.2.3 From a6eab640cacccec9b6ca18915c2bc6e4746df1e6 Mon Sep 17 00:00:00 2001 From: Sergio Lopez Date: Fri, 27 Aug 2010 00:24:01 +0200 Subject: make unblocked reads from external objects return a zeroed page. * serverboot/default_pager.c (struct dstruct): Add boolean_t external field. (default_pager_add): Set ds->external to TRUE or FALSE depending whether the object is external. (default_read): Add external parameter. If no_block(block) returns 1, if external is TRUE, zero fill the page and return PAGER_SUCCESS instead of PAGER_ABSENT. (seqnos_memory_object_data_request): Pass ds->external as additional parameter to default_read. --- serverboot/default_pager.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/serverboot/default_pager.c b/serverboot/default_pager.c index aa7b0885..3a3f0e4f 100644 --- a/serverboot/default_pager.c +++ b/serverboot/default_pager.c @@ -1668,7 +1668,7 @@ ok: * if it is different from , it must be deallocated after use. */ int -default_read(ds, addr, size, offset, out_addr, deallocate) +default_read(ds, addr, size, offset, out_addr, deallocate, external) register dpager_t ds; vm_offset_t addr; /* pointer to block to fill */ register vm_size_t size; @@ -1676,6 +1676,7 @@ default_read(ds, addr, size, offset, out_addr, deallocate) vm_offset_t *out_addr; /* returns pointer to data */ boolean_t deallocate; + boolean_t external; { register union dp_map block; vm_offset_t raddr; @@ -1692,8 +1693,18 @@ default_read(ds, addr, size, offset, out_addr, deallocate) * Find the block in the paging partition */ block = pager_read_offset(ds, offset); - if ( no_block(block) ) + if ( no_block(block) ) { + if (external) { + /* + * An external object is requesting unswapped data, + * zero fill the page and return. + */ + bzero((char *) addr, vm_page_size); + *out_addr = addr; + return (PAGER_SUCCESS); + } return (PAGER_ABSENT); + } /* * Read it, trying for the entire page. @@ -1844,6 +1855,7 @@ struct dstruct { mach_port_urefs_t request_refs; /* Request port user-refs */ mach_port_t pager_name; /* Name port */ mach_port_urefs_t name_refs; /* Name port user-refs */ + boolean_t external; /* Is an external object? */ unsigned int readers; /* Reads in progress */ unsigned int writers; /* Writes in progress */ @@ -2301,10 +2313,12 @@ void default_pager_add(ds, internal) /* possibly generate an immediate no-senders notification */ sync = 0; pset = default_pager_internal_set; + ds->external = FALSE; } else { /* delay notification till send right is created */ sync = 1; pset = default_pager_external_set; + ds->external = TRUE; } kr = mach_port_request_notification(default_pager_self, pager, @@ -2655,7 +2669,8 @@ ddprintf ("seqnos_memory_object_data_request <%p>: pager_port_unlock: <%p>[s:%d, else rc = default_read(&ds->dpager, dpt->dpt_buffer, vm_page_size, offset, - &addr, protection_required & VM_PROT_WRITE); + &addr, protection_required & VM_PROT_WRITE, + ds->external); switch (rc) { case PAGER_SUCCESS: -- cgit v1.2.3 From 53bd6dda08f8df6736ddc49bfc7038a92174a8ea Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Fri, 27 Aug 2010 00:51:18 +0200 Subject: Fix default_pager default_pager_object_set_size parameters As suggested by Sergio Lopez. * serverboot/default_pager.c (S_default_pager_object_set_size): Exchange `seqno' and `reply_to' parameters. --- serverboot/default_pager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serverboot/default_pager.c b/serverboot/default_pager.c index 3a3f0e4f..41c2768d 100644 --- a/serverboot/default_pager.c +++ b/serverboot/default_pager.c @@ -3724,8 +3724,8 @@ S_default_pager_object_pages (mach_port_t pager, kern_return_t S_default_pager_object_set_size (mach_port_t pager, - mach_port_seqno_t seqno, mach_port_t reply_to, + mach_port_seqno_t seqno, vm_size_t limit) { kern_return_t kr; -- cgit v1.2.3