diff options
author | Flavio Cruz <flaviocruz@gmail.com> | 2008-07-29 15:39:26 +0000 |
---|---|---|
committer | Flavio Cruz <flaviocruz@gmail.com> | 2008-07-29 15:39:26 +0000 |
commit | 4d5d60f5b24c7ec92a55e36147573304fe9ba267 (patch) | |
tree | 4f6114a306ca5303dfaf4086cc5adb9338246676 | |
parent | a4300345c8318cee308be3dc2a6a0424c0ce0cd4 (diff) |
Move helper libraries to /libs.
--HG--
rename : hurd/helper-libs/fetch-root.c => libs/fetch-root.c
rename : hurd/helper-libs/file-utimes.c => libs/file-utimes.c
rename : hurd/helper-libs/Makefile => libs/Makefile
rename : hurd/helper-libs/file-exec.c => libs/file-exec.c
rename : hurd/helper-libs/portset-demuxer.c => libs/portset-demuxer.c
rename : hurd/helper-libs/round-page.c => libs/round-page.c
-rw-r--r-- | libs/Makefile | 27 | ||||
-rw-r--r-- | libs/fetch-root.c | 129 | ||||
-rw-r--r-- | libs/file-exec.c | 134 | ||||
-rw-r--r-- | libs/file-utimes.c | 12 | ||||
-rw-r--r-- | libs/portset-demuxer.c | 65 | ||||
-rw-r--r-- | libs/round-page.c | 8 |
6 files changed, 375 insertions, 0 deletions
diff --git a/libs/Makefile b/libs/Makefile new file mode 100644 index 000000000..232361abc --- /dev/null +++ b/libs/Makefile @@ -0,0 +1,27 @@ + +include ../defs.mk + +TARGETS = portset-demuxer.so \ + fetch-root.so \ + round-page.so \ + file-utimes.so \ + file-exec.so + +LDFLAGS = + +all: $(TARGETS) + +fetch-root.so: fetch-root.o + $(CC) -shared -Wl \ + -o fetch-root.so fetch-root.o $(LDFLAGS) -lfshelp + +file-exec.so: file-exec.o + $(CC) -shared -Wl \ + -o file-exec.so file-exec.o $(LDFLAGS) -lthreads + +%.so: %.o + $(CC) -shared -Wl\ + -o $*.so $*.o $(LDFLAGS) + +clean: + rm -f *.so *.o diff --git a/libs/fetch-root.c b/libs/fetch-root.c new file mode 100644 index 000000000..e036f2046 --- /dev/null +++ b/libs/fetch-root.c @@ -0,0 +1,129 @@ +/* + Copyright (C) 1995,96,99,2000,02 Free Software Foundation, Inc. + Written by Michael I. Bushnell. + + This file is part of the GNU Hurd. + + The GNU Hurd 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. + + The GNU Hurd 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 this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + + +#include <unistd.h> +#include <assert.h> +#include <string.h> +#include <hurd.h> +#include <hurd/fsys.h> +#include <hurd/fshelp.h> +#include <hurd/auth.h> +#include <hurd/io.h> + +typedef error_t (*mycallback2_t)(int, mach_port_t *, mach_msg_type_name_t *); + +error_t +helper_fetch_root (file_t dotdot, + mycallback2_t callback2, + uid_t uid, gid_t gid, + char *argz, size_t argz_len, + mach_port_t *control_port) +{ + error_t err; + mach_port_t control; + int i; + mach_port_t ports[INIT_PORT_MAX]; + int ints[INIT_INT_MAX]; + mach_port_t fds[STDERR_FILENO + 1]; + auth_t ourauth, newauth; + + mach_port_t reauth (mach_port_t port) /* Consumes PORT. */ + { + mach_port_t rend, ret; + error_t err; + + if (port == MACH_PORT_NULL) + return port; + + if (ourauth == MACH_PORT_NULL) + /* We have no auth server, so we aren't doing reauthentications. + Just pass on our own ports directly. */ + return port; + + rend = mach_reply_port (); + + /* MAKE_SEND is safe here because we destroy REND ourselves. */ + err = io_reauthenticate (port, rend, + MACH_MSG_TYPE_MAKE_SEND); + mach_port_deallocate (mach_task_self (), port); + if (! err) + err = auth_user_authenticate (newauth, rend, + MACH_MSG_TYPE_MAKE_SEND, &ret); + if (err) + ret = MACH_PORT_NULL; + + mach_port_destroy (mach_task_self (), rend); + + return ret; + } + + error_t fetch_underlying (int flags, mach_port_t *underlying, + mach_msg_type_name_t *underlying_type, + task_t task, void *cookie) + { + return + (*callback2) (flags, underlying, underlying_type); + } + + ourauth = getauth (); + if (ourauth == MACH_PORT_NULL) + newauth = ourauth; + else + { + uid_t uidarray[2] = { uid, uid }; + gid_t gidarray[2] = { gid, gid }; + err = auth_makeauth (ourauth, 0, MACH_MSG_TYPE_COPY_SEND, 0, + uidarray, 1, uidarray, 2, + gidarray, 1, gidarray, 2, &newauth); + if (err) + return err; + } + + bzero (ports, INIT_PORT_MAX * sizeof (mach_port_t)); + bzero (fds, (STDERR_FILENO + 1) * sizeof (mach_port_t)); + bzero (ints, INIT_INT_MAX * sizeof (int)); + + ports[INIT_PORT_CWDIR] = dotdot; + ports[INIT_PORT_CRDIR] = reauth (getcrdir ()); + ports[INIT_PORT_AUTH] = newauth; + + fds[STDERR_FILENO] = reauth (getdport (STDERR_FILENO)); + + err = fshelp_start_translator_long (fetch_underlying, NULL, + argz, argz, argz_len, + fds, MACH_MSG_TYPE_COPY_SEND, + STDERR_FILENO + 1, + ports, MACH_MSG_TYPE_COPY_SEND, + INIT_PORT_MAX, + ints, INIT_INT_MAX, + uid, + 0, &control); + for (i = 0; i <= STDERR_FILENO; i++) + mach_port_deallocate (mach_task_self (), fds[i]); + + for (i = 0; i < INIT_PORT_MAX; i++) + if (i != INIT_PORT_CWDIR) + mach_port_deallocate (mach_task_self (), ports[i]); + + *control_port = control; + + return err; +} diff --git a/libs/file-exec.c b/libs/file-exec.c new file mode 100644 index 000000000..3092ade74 --- /dev/null +++ b/libs/file-exec.c @@ -0,0 +1,134 @@ + +#include <stdio.h> +#include <hurd.h> +#include <hurd/exec.h> +#include <cthreads.h> + +typedef struct { + int ended; + kern_return_t err; + file_t execserver; + mach_port_t file; + mach_msg_type_name_t filePoly; + mach_port_t oldtask; + int flags; + data_t argv; + mach_msg_type_number_t argvCnt; + data_t envp; + mach_msg_type_number_t envpCnt; + portarray_t dtable; + mach_msg_type_name_t dtablePoly; + mach_msg_type_number_t dtableCnt; + portarray_t portarray; + mach_msg_type_name_t portarrayPoly; + mach_msg_type_number_t portarrayCnt; + intarray_t intarray; + mach_msg_type_number_t intarrayCnt; + mach_port_array_t deallocnames; + mach_msg_type_number_t deallocnamesCnt; + mach_port_array_t destroynames; + mach_msg_type_number_t destroynamesCnt; +} exec_data; + +any_t +thread_exec(any_t arg) +{ + //exec_data *data = (exec_data*)arg; + exec_data *data; + +fprintf(stderr, "starting exec_exec\n"); + return(NULL); + /* + + data->err = + exec_exec(data->execserver, data->file, data->filePoly, + data->oldtask, data->flags, data->argv, data->argvCnt, + data->envp, data->envpCnt, data->dtable, data->dtablePoly, + data->dtableCnt, data->portarray, data->portarrayPoly, + data->portarrayCnt, data->intarray, data->intarrayCnt, + data->deallocnames, data->deallocnamesCnt, + data->destroynames, data->destroynamesCnt); + + fprintf(stderr, "exec_exec done\n"); + + data->ended = 1; + + if(!data->err) { + + unsigned int i; + + mach_port_deallocate(mach_task_self(), data->oldtask); + + for(i = 0; i < data->dtableCnt; ++i) { + mach_port_deallocate(mach_task_self(), data->dtable[i]); + } + + for(i = 0; i < data->portarrayCnt; ++i) { + mach_port_deallocate(mach_task_self(), data->portarray[i]); + } + + } + + fprintf(stderr, "ending thread_exec\n"); + return(NULL); + */ +} + +exec_data* +do_exec_exec(file_t execserver0, + mach_port_t file0, + mach_msg_type_name_t filePoly0, + mach_port_t oldtask0, + int flags0, + data_t argv0, + mach_msg_type_number_t argvCnt0, + data_t envp0, + mach_msg_type_number_t envpCnt0, + portarray_t dtable0, + mach_msg_type_name_t dtablePoly0, + mach_msg_type_number_t dtableCnt0, + portarray_t portarray0, + mach_msg_type_name_t portarrayPoly0, + mach_msg_type_number_t portarrayCnt0, + intarray_t intarray0, + mach_msg_type_number_t intarrayCnt0, + mach_port_array_t deallocnames0, + mach_msg_type_number_t deallocnamesCnt0, + mach_port_array_t destroynames0, + mach_msg_type_number_t destroynamesCnt0) +{ + exec_data *data = (exec_data*)malloc(sizeof(exec_data)); + + fprintf(stderr, "Data created\n"); + + data->ended = 0; + data->err = 0; + data->execserver = execserver0; + data->file = file0; + data->filePoly = filePoly0; + data->oldtask = oldtask0; + data->flags = flags0; + data->argv = argv0; + data->argvCnt = argvCnt0; + data->envp = envp0; + data->envpCnt = envpCnt0; + data->dtable = dtable0; + data->dtablePoly = dtablePoly0; + data->dtableCnt = dtableCnt0; + data->portarray = portarray0; + data->portarrayPoly = portarrayPoly0; + data->portarrayCnt = portarrayCnt0; + data->intarray = intarray0; + data->intarrayCnt = intarrayCnt0; + data->deallocnames = deallocnames0; + data->deallocnamesCnt = deallocnamesCnt0; + data->destroynames = destroynames0; + data->destroynamesCnt = destroynamesCnt0; + + fprintf(stderr, "Running cthread_fork\n"); + cthread_fork(thread_exec, NULL); + return(NULL); + + return(data); +} + diff --git a/libs/file-utimes.c b/libs/file-utimes.c new file mode 100644 index 000000000..8d02aa8a8 --- /dev/null +++ b/libs/file-utimes.c @@ -0,0 +1,12 @@ + +#include <hurd/fs.h> +#include <mach/time_value.h> + +/* Wrap file_utimes to pass pointers as arguments. */ +kern_return_t +helper_file_utimes(file_t utimes_file, + time_value_t *new_atime, + time_value_t *new_mtime) +{ + return(file_utimes(utimes_file, *new_atime, *new_mtime)); +} diff --git a/libs/portset-demuxer.c b/libs/portset-demuxer.c new file mode 100644 index 000000000..0343c8d77 --- /dev/null +++ b/libs/portset-demuxer.c @@ -0,0 +1,65 @@ + +#include <mach.h> +#include <mach/notify.h> +#include <mach/mig_errors.h> +#include <stdlib.h> +#include <assert.h> +#include <errno.h> +#include <stdio.h> + +typedef int (*demuxer_fun_type)(mach_port_t, + mach_msg_header_t *, + mach_msg_header_t *); + +static demuxer_fun_type demuxer = NULL; + +int +portset_demuxer(mach_msg_header_t *inp, + mach_msg_header_t *outheadp) +{ + assert(demuxer != NULL); + + register mig_reply_header_t *outp = (mig_reply_header_t *) outheadp; + static const mach_msg_type_t RetCodeType = { + /* msgt_name = */ MACH_MSG_TYPE_INTEGER_32, + /* msgt_size = */ 32, + /* msgt_number = */ 1, + /* msgt_inline = */ TRUE, + /* msgt_longform = */ FALSE, + /* msgt_deallocate = */ FALSE, + /* msgt_unused = */ 0 + }; + + /* Fill in default response */ + outp->Head.msgh_bits + = MACH_MSGH_BITS(MACH_MSGH_BITS_REMOTE(inp->msgh_bits), 0); + outp->Head.msgh_size = sizeof(*outp); + outp->Head.msgh_remote_port = inp->msgh_remote_port; + outp->Head.msgh_local_port = MACH_PORT_NULL; + outp->Head.msgh_seqno = 0; + outp->Head.msgh_id = inp->msgh_id + 100; + outp->RetCodeType = RetCodeType; + outp->RetCode = MIG_BAD_ID; + + //fprintf(stderr, "=====Got message=====!\n"); + + int ret = demuxer(inp->msgh_local_port, inp, outheadp); + + //fprintf(stderr, "=====End Message!=====\n"); + + if(ret == EOPNOTSUPP) { + outp->RetCode = EOPNOTSUPP; + return(1); + } else { + //fprintf(stderr, "ret demuxer: %d\n", ret); + return(ret); + } +} + +void +set_demuxer(demuxer_fun_type fun) +{ + assert(fun != NULL); + + demuxer = fun; +} diff --git a/libs/round-page.c b/libs/round-page.c new file mode 100644 index 000000000..15af2d297 --- /dev/null +++ b/libs/round-page.c @@ -0,0 +1,8 @@ + +#include <mach/vm_param.h> + +vm_offset_t +helper_round_page(vm_offset_t address) +{ + return round_page(address); +} |