[cp-patches] [NATIVE-LAYER] Last methods implemented

Guilhem Lavaux guilhem at kaffe.org
Sat Mar 25 17:08:30 UTC 2006


Hi list,

Here is a patch to implement the last missing methods needed to override 
completely the target layer (which has already been removed). I have 
done some basic tests and I can run jamvm on some simple tests involving 
IOs, sockets and process spawning.

2006-03-25  Guilhem Lavaux  <guilhem at kaffe.org>

         * native/jni/java-io/Makefile.am,
         native/jni/java-lang/Makefile.am,
         native/jni/java-net/Makefile.am,
         native/jni/java-nio/Makefile.am: Link to libclasspathnative.la
	now.

         * native/jni/native-lib/Makefile.am: Added cpproc.c

         * native/jni/native-lib/cpio.c: Implemented missing functions
	for CPIO.

         * native/jni/native-lib/cpnet.c
         (cpnet_getHostByName): Fixed address array initialization.

         * native/jni/native-lib/cpproc.c: Implemented.

Cheers,

Guilhem.
-------------- next part --------------
Index: native/jni/java-io/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-io/Makefile.am,v
retrieving revision 1.23.2.1
diff -u -r1.23.2.1 Makefile.am
--- native/jni/java-io/Makefile.am	25 Mar 2006 13:03:57 -0000	1.23.2.1
+++ native/jni/java-io/Makefile.am	25 Mar 2006 17:07:50 -0000
@@ -4,7 +4,8 @@
 			java_io_VMObjectInputStream.c \
 			java_io_VMObjectStreamClass.c
 
-libjavaio_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo
+libjavaio_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo \
+		      $(top_builddir)/native/jni/native-lib/libclasspathnative.la
 
 AM_LDFLAGS = @CLASSPATH_MODULE@
 AM_CPPFLAGS = @CLASSPATH_INCLUDES@
Index: native/jni/java-lang/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-lang/Makefile.am,v
retrieving revision 1.14.2.2
diff -u -r1.14.2.2 Makefile.am
--- native/jni/java-lang/Makefile.am	25 Mar 2006 13:03:57 -0000	1.14.2.2
+++ native/jni/java-lang/Makefile.am	25 Mar 2006 17:07:50 -0000
@@ -7,7 +7,8 @@
 			 java_lang_VMProcess.c
 
 libjavalang_la_LIBADD = $(wildcard $(top_builddir)/native/fdlibm/*.lo) \
-			$(top_builddir)/native/jni/classpath/jcl.lo
+			$(top_builddir)/native/jni/classpath/jcl.lo \
+			$(top_builddir)/native/jni/native-lib/libclasspathnative.la
 
 libjavalangreflect_la_SOURCES = java_lang_reflect_Array.c
 
Index: native/jni/java-net/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-net/Makefile.am,v
retrieving revision 1.13.2.1
diff -u -r1.13.2.1 Makefile.am
--- native/jni/java-net/Makefile.am	25 Mar 2006 13:03:57 -0000	1.13.2.1
+++ native/jni/java-net/Makefile.am	25 Mar 2006 17:07:50 -0000
@@ -7,7 +7,8 @@
 			gnu_java_net_VMPlainDatagramSocketImpl.c \
                         gnu_java_net_VMPlainSocketImpl.c
 
-libjavanet_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo
+libjavanet_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo \
+		       $(top_builddir)/native/jni/native-lib/libclasspathnative.la
 
 AM_LDFLAGS = @CLASSPATH_MODULE@
 AM_CPPFLAGS = @CLASSPATH_INCLUDES@
Index: native/jni/java-nio/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-nio/Makefile.am,v
retrieving revision 1.21.2.1
diff -u -r1.21.2.1 Makefile.am
--- native/jni/java-nio/Makefile.am	25 Mar 2006 13:03:57 -0000	1.21.2.1
+++ native/jni/java-nio/Makefile.am	25 Mar 2006 17:07:50 -0000
@@ -9,6 +9,7 @@
 			java_nio_VMDirectByteBuffer.c
 
 libjavanio_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo \
+		       $(top_builddir)/native/jni/native-lib/libclasspathnative.la \
 		       $(LTLIBICONV) 
 
 AM_LDFLAGS = @CLASSPATH_MODULE@
Index: native/jni/native-lib/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/native-lib/Attic/Makefile.am,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 Makefile.am
--- native/jni/native-lib/Makefile.am	28 Jan 2006 15:49:45 -0000	1.1.2.1
+++ native/jni/native-lib/Makefile.am	25 Mar 2006 17:07:50 -0000
@@ -5,7 +5,9 @@
 				cpio.h \
 				cpnative.c \
 				cpnative.h \
-				cpmath.h
+				cpmath.h \
+				cpproc.h \
+				cpproc.c
 
 AM_LDFLAGS = @CLASSPATH_MODULE@
 AM_CPPFLAGS = @CLASSPATH_INCLUDES@
Index: native/jni/native-lib/cpio.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/native-lib/Attic/cpio.c,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 cpio.c
--- native/jni/native-lib/cpio.c	19 Feb 2006 11:43:54 -0000	1.1.2.2
+++ native/jni/native-lib/cpio.c	25 Mar 2006 17:07:50 -0000
@@ -70,6 +70,8 @@
 #include <sys/select.h>
 #endif
 
+#include <utime.h>
+
 #include "cpnative.h"
 #include "cpio.h"
 
@@ -323,3 +325,97 @@
 
   return CPNATIVE_OK;
 }
+
+int cpio_setFileReadonly (const char *filename)
+{
+  struct stat statbuf;
+
+  if (stat(filename, &statbuf) < 0)
+    return errno;
+ 
+  if (chmod(filename, statbuf.st_mode & ~(S_IRUSR | S_IRGRP | S_IROTH)) < 0)
+    return errno;
+
+  return 0;
+}
+
+int cpio_isFileExists (const char *filename)
+{
+  struct stat statbuf;
+
+  if (stat(filename, &statbuf) < 0)
+    {
+      return errno;
+    }
+
+  return 0;
+}
+
+int cpio_checkType (const char *filename, jint *entryType)
+{
+  struct stat statbuf;
+
+  if (stat(filename, &statbuf) < 0)
+    return errno;
+
+  if (S_ISDIR(statbuf.st_mode))
+    *entryType = CPFILE_DIRECTORY;
+  else
+    *entryType = CPFILE_FILE;
+
+  return 0;
+}
+
+int cpio_getModificationTime (const char *filename, jlong *mtime)
+{
+  struct stat statbuf;
+
+  if (stat(filename, &statbuf) < 0)
+    return errno;
+
+  *mtime = statbuf.st_mtime * 1000;
+
+  return 0;
+}
+
+int cpio_setModificationTime (const char *filename, jlong mtime)
+{
+  struct stat statbuf;
+  struct utimbuf buf;
+
+  if (stat(filename, &statbuf) < 0)
+    return errno;
+
+  buf.actime = statbuf.st_atime;
+  buf.modtime = mtime / 1000;
+
+  if (utime(filename, &buf) < 0)
+    return errno;
+
+  return 0;
+}
+
+int cpio_removeFile (const char *filename)
+{
+  if (unlink(filename) < 0)
+    return errno;
+
+  return 0;
+}
+
+int cpio_mkdir (const char *path)
+{
+  if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
+    return errno;
+  
+  return 0;
+}
+
+int cpio_rename (const char *old_name, const char *new_name)
+{
+  if (rename(old_name, new_name) < 0)
+    return errno;
+
+  return 0;
+}
+
Index: native/jni/native-lib/cpnet.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/native-lib/Attic/cpnet.c,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 cpnet.c
--- native/jni/native-lib/cpnet.c	19 Feb 2006 17:10:27 -0000	1.1.2.2
+++ native/jni/native-lib/cpnet.c	25 Mar 2006 17:07:50 -0000
@@ -588,14 +588,14 @@
       for (i = 0; i < counter; i++)
 	{
 	  addr_arr[i] = cpnet_newIPV4Address(env);
-	  cpnet_bytesToIPV4Address(addr_arr[i], (jbyte *)hret.h_addr_list[counter]);
+	  cpnet_bytesToIPV4Address(addr_arr[i], (jbyte *)hret.h_addr_list[i]);
 	}
       break;
     case AF_INET6:
       for (i = 0; i < counter; i++)
 	{
 	  addr_arr[i] = cpnet_newIPV6Address(env);
-	  cpnet_bytesToIPV6Address(addr_arr[i], (jbyte *)hret.h_addr_list[counter]);
+	  cpnet_bytesToIPV6Address(addr_arr[i], (jbyte *)hret.h_addr_list[i]);
 	}
       break;
     default:
Index: native/jni/native-lib/cpproc.c
===================================================================
RCS file: native/jni/native-lib/cpproc.c
diff -N native/jni/native-lib/cpproc.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ native/jni/native-lib/cpproc.c	25 Mar 2006 17:07:50 -0000
@@ -0,0 +1,131 @@
+/* cpproc.c -
+   Copyright (C) 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include "config.h"
+#include <jni.h>
+#include "cpproc.h"
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+static void close_all_fds(int *fds, int numFds)
+{
+  int i;
+
+  for (i = 0; i < numFds; i++)
+    close(fds[i]);
+}
+
+int cpproc_forkAndExec (char * const *commandLine, char * const * newEnviron, int *fds, pid_t *out_pid, const char *wd)
+{
+  int local_fds[6];
+  int i;
+  pid_t pid;
+
+  for (i = 0; i < 6; i += 2)
+    {
+      if (pipe(&local_fds[i]) < 0)
+	{
+	  int err = errno;
+
+	  close_all_fds(local_fds, i);
+	  
+	  return err;
+	}
+    }
+  
+  pid = fork();
+  
+  switch (pid)
+    {
+    case 0:
+      dup2(local_fds[0], 0);
+      dup2(local_fds[3], 1);
+      dup2(local_fds[5], 2);
+
+      close_all_fds(local_fds, 6);
+
+      chdir(wd);
+      if (newEnviron == NULL)
+	execvp(commandLine[0], commandLine);
+      else
+	execve(commandLine[0], commandLine, newEnviron);
+      
+      abort();
+      
+      break;
+    case -1:
+      {
+	int err = errno;
+	
+	close_all_fds(local_fds, 6);
+	return err;
+      }
+    default: 
+      close(local_fds[0]);
+      close(local_fds[3]);
+      close(local_fds[5]);
+
+      fds[0] = local_fds[1];
+      fds[1] = local_fds[2];
+      fds[2] = local_fds[4];
+      *out_pid = pid;
+      return 0;
+    }
+}
+
+int cpproc_waitpid (pid_t pid, int *status, pid_t *outpid, int options)
+{
+  pid_t wp = waitpid(pid, status, options);
+
+  if (wp < 0)
+    return errno;
+
+  *outpid = wp;
+  return 0;
+}
+
+int cpproc_kill (pid_t pid, int signal)
+{
+  if (kill(pid, signal) < 0)
+    return errno;
+
+  return 0;
+}


More information about the Classpath-patches mailing list