Author: jfrederic.clere(a)jboss.com
Date: 2007-10-14 03:52:27 -0400 (Sun, 14 Oct 2007)
New Revision: 1109
Modified:
trunk/sight/native/os/solaris/module.c
Log:
Port to Solaris.
Modified: trunk/sight/native/os/solaris/module.c
===================================================================
--- trunk/sight/native/os/solaris/module.c 2007-10-12 11:44:30 UTC (rev 1108)
+++ trunk/sight/native/os/solaris/module.c 2007-10-14 07:52:27 UTC (rev 1109)
@@ -35,6 +35,15 @@
#include "sight_types.h"
#include "sight_private.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mkdev.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <libelf.h>
+#include <procfs.h>
+
/*
* Module
*/
@@ -76,7 +85,22 @@
"J"
};
+extern apr_pool_t *sight_temp_pool;
+typedef struct module_enum_t {
+ int nummodules;
+ apr_pool_t *pool;
+ module *first_module;
+ module *current_module;
+} module_enum_t;
+
+struct module {
+ char *name;
+ int base;
+ int size;
+ module *next;
+};
+
SIGHT_CLASS_LDEF(Module)
{
if (sight_load_class(_E, &_clazzn))
@@ -103,11 +127,97 @@
return NULL;
}
+static int proc_map_f(void *ptr, const prmap_t *map, const char *car)
+{
+ module_enum_t *module = ptr;
+ struct module *current;
+ // fill first, use current and put next in current...
+ if (module->ptr == NULL) {
+ module->ptr = apr_palloc(module->pool, sizeof(struct module));
+ current = module->ptr;
+ } else {
+ current = module->current;
+ current->next = apr_palloc(module->pool, sizeof(struct module));
+ current = current->next;
+ }
+ current->next = NULL;
+ current->name = apr_pstrdup(module->pool, car);
+ current->base = pr_vaddr;
+ current->size = pr_size;
+ module->nummodules++;
+ return 0;
+}
SIGHT_EXPORT_DECLARE(jobjectArray, Module, enum0)(SIGHT_STDARGS,
jint pid)
{
- UNREFERENCED_STDARGS;
- UNREFERENCED(pid);
- return NULL;
+ int mpid = getpid();
+ apr_pool_t *pool;
+ int j;
+ int ret;
+ struct ps_prochandle *ph;
+ module_enum_t *module;
+ struct module *current;
+ jobjectArray mods = NULL;
+
+ UNREFERENCED_O;
+ if (pid >= 0)
+ mpid = pid;
+
+ if ((rc = sight_create_pool(&pool, sight_temp_pool)) != APR_SUCCESS) {
+ throwAprMemoryException(_E, THROW_FMARK, rc);
+ return NULL;
+ }
+ ph = Pgrab(pid, 0, &ret);
+ if (ph == NULL) {
+ throwOSException(_E, Pgrab_error(ret));
+ apr_pool_destroy(pool);
+ return NULL;
+ }
+
+ /* Process all entries */
+ module = apr_palloc(pool, sizeof(module_enum_t));
+ if (module == NULL) {
+ throwAprMemoryException(_E, THROW_FMARK, apr_get_os_error());
+ Prelease(ph, 0);
+ apr_pool_destroy(pool);
+ return NULL;
+ }
+ module->pool = pool;
+ module->nummodules = 0;
+ module->first_module = NULL;
+ module->current_module = NULL;
+ Pobject_iter(ph, proc_map_f, module);
+ if (ret<0) {
+ throwOSException(_E, Pgrab_error(ret));
+ apr_pool_destroy(pool);
+ return NULL;
+ }
+
+ /* Release the proc file system */
+ Prelease(ph, 0);
+
+ /* Fill the java objects */
+ mods = (*_E)->NewObjectArray(_E, module->nummodules, _clazzn.a, NULL);
+ if (!mods || (*_E)->ExceptionCheck(_E)) {
+ apr_pool_destroy(pool);
+ return NULL;
+ }
+ current = module->current;
+ for (j = 0; j < module->nummodules; j++) {
+ jobject m = new_module_class(_E, _O, pid, j);
+ if (!m || (*_E)->ExceptionCheck(_E)) {
+ apr_pool_destroy(pool);
+ return NULL;
+ }
+ SET_IFIELD_S(0000, m, current->name);
+ SET_IFIELD_S(0001, m, current->name); /* should be basename */
+ SET_IFIELD_J(0002, m, current->base);
+ SET_IFIELD_J(0002, m, current->size);
+ (*_E)->SetObjectArrayElement(_E, mods, j, m);
+ (*_E)->DeleteLocalRef(_E, m);
+ }
+ apr_pool_destroy(pool);
+
+ return mods;
}