hurd: Initial support.

This adds minimal Hurd support by implementing the _exit function.

* AUTHORS: Update.
* .gitignore: Ignore a.out, core, .config.
* include/sys/wait.h (W_EXITCODE): New define.
* lib/linux/x86-mes-gcc/crt1.c (_start): Call _exit to allow reuse.
* lib/gnu/x86-mes-gcc/crt1.c: New file.
* lib/gnu/x86-mes-gcc/mini.c: New file.
* lib/gnu/hurd-start.c: New file.
* lib/gnu/_exit.c: New file.
* include/gnu/syscall.h: New file.
* include/gnu/hurd.h: New file.
* lib/gnu/_exit.c: New file.
* lib/gnu/exec-startup-get-data.c: New file.
* lib/gnu/hurd-start.c: New file.
* lib/gnu/proc-mark-exit.c: New file.
* lib/gnu/syscall.c: New file.
* lib/gnu/task-get-special-port.c: New file.
* lib/gnu/task-terminate.c: New file.
* lib/gnu/vm-statistics.c: New file.
* build-aux/configure-lib.sh (libc_mini_SOURCES): Add Hurd sources.
* build-aux/build.sh.in (CPPFLAGS): Add lib to includes, to find linux
crt1.c.
* build-aux/test-c.sh: Always use at least -l c+mini for GNU.
* lib/tests/scaffold/00-exit-42.exit: New file.
* lib/tests/scaffold/00-exit-42.c: New test.
* build-aux/check-mescc.sh (TESTS): Add it.
* lib/tests/scaffold/00-exit-0.c (main): Rewrite, use _exit.
* include/gnu/hurd-types.h: Import from GNU C Library.
* include/mach/mach-init.h: Likewise.
* lib/mach/mach-init.c: Likewise.
* lib/mach/mach_host_self.S: Likewise.
* lib/mach/mach_msg_trap.S: Likewise.
* lib/mach/mach_reply_port.S: Likewise.
* lib/mach/mach_task_self.S: Likewise.
* lib/mach/mach_thread_self.S: Likewise.
* lib/mach/msg.c: Likewise.
This commit is contained in:
Jan Nieuwenhuizen 2019-03-10 16:52:05 -04:00
parent 8910030b89
commit 5eaa46a5e7
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
32 changed files with 1353 additions and 38 deletions

3
.gitignore vendored
View File

@ -169,3 +169,6 @@
/body-hello-mes
/exit-42
/hello-mes
core
/.config
a.out

View File

@ -73,6 +73,13 @@ mes/module/srfi/srfi-26.scm
GNU FDL in texinfo from GNU
doc/fdl-1.3.texi
Hurd and Mach support from GNU C Library
include/gnu/hurd-types.h
include/mach/mach-init.h
lib/mach/msg.c
lib/mach/mach-init.c
lib/mach/*.S
* legalese
Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>

View File

@ -66,6 +66,7 @@ fi
CPPFLAGS="
-D HAVE_CONFIG_H=1
-I ${srcdir}/../lib
-I ../include
-I ${srcdir}/../include
-I ${srcdir}/../include/$mes_kernel/$mes_cpu
@ -98,6 +99,7 @@ if test $compiler = gcc; then
fi
CPPFLAGS="
-D HAVE_CONFIG_H=1
-I ${srcdest}lib
-I include
-I ${srcdest}include
-I ${srcdest}include/$mes_kernel/$mes_cpu
@ -116,6 +118,7 @@ fi
CPPFLAGS="
-D HAVE_CONFIG_H=1
-I ${srcdest}lib
-I include
-I ${srcdest}include
-I ${srcdest}include/$mes_kernel/$mes_cpu
@ -137,6 +140,7 @@ fi
fi
CPPFLAGS="
-D HAVE_CONFIG_H=1
-I ${srcdest}lib
-I include
-I ${srcdest}include
-I ${srcdest}include/$mes_kernel/$mes_cpu

View File

@ -25,6 +25,7 @@ set -u
TESTS="
lib/tests/scaffold/t.c
lib/tests/scaffold/00-exit-0.c
lib/tests/scaffold/00-exit-42.c
lib/tests/scaffold/01-return-0.c
lib/tests/scaffold/02-return-1.c
lib/tests/scaffold/03-call.c

View File

@ -41,6 +41,26 @@ lib/stdlib/exit.c
lib/stdlib/puts.c
lib/string/strlen.c
"
if test $mes_kernel = gnu; then
libc_mini_shared_SOURCES="$libc_mini_shared_SOURCES
lib/gnu/_exit.c
lib/gnu/exec-startup-get-data.c
lib/gnu/hurd-start.c
lib/gnu/proc-mark-exit.c
lib/gnu/syscall.c
lib/gnu/task-get-special-port.c
lib/gnu/task-terminate.c
lib/gnu/vm-statistics.c
lib/mach/mach-init.c
lib/mach/mach_host_self.S
lib/mach/mach_msg_trap.S
lib/mach/mach_reply_port.S
lib/mach/mach_task_self.S
lib/mach/mach_thread_self.S
lib/mach/msg.c
"
fi
fi
libc_mini_SOURCES="$libc_mini_shared_SOURCES"

View File

@ -52,6 +52,11 @@ else
LIBS='-l c'
fi
if test $mes_kernel = gnu\
&& test -z "$LIBS"; then
LIBS="-l c-mini"
fi
if test $mes_libc = system; then
crt1=
LIBS='-l mes'

393
include/gnu/hurd-types.h Normal file
View File

@ -0,0 +1,393 @@
/* C declarations for Hurd server interfaces
Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2001, 2002,
2010 Free Software Foundation, Inc.
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 the GNU Hurd; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _HURD_TYPES_H
#define _HURD_TYPES_H
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 32
#endif
#include <time.h> /* For struct timespec. */
#include <mach/std_types.h> /* For mach_port_t et al. */
#include <mach/message.h> /* For mach_msg_id_t et al. */
#include <sys/types.h> /* For pid_t and uid_t. */
/* A string identifying this release of the GNU Hurd. Our
interpretation of the term "release" is that it refers to a set of
server interface definitions. A "version" in Posix terminology is
a distribution of the Hurd; there may be more than one distribution
without changing the release number. */
#define HURD_RELEASE "0.0"
/* Simple type declarations */
/* These types identify certain kinds of ports used by the Hurd. */
typedef mach_port_t file_t;
typedef mach_port_t fsys_t;
typedef mach_port_t io_t;
typedef mach_port_t process_t;
typedef mach_port_t auth_t;
typedef mach_port_t socket_t;
typedef mach_port_t pf_t; /* Protocol family */
typedef mach_port_t addr_port_t;
typedef mach_port_t startup_t;
typedef mach_port_t fs_notify_t;
typedef mach_port_t exec_startup_t;
typedef mach_port_t interrupt_t;
typedef mach_port_t proccoll_t;
typedef mach_port_t ctty_t;
#include <errno.h> /* Defines `error_t'. */
/* These names exist only because of MiG deficiencies.
You should not use them in C source; use the normal C types instead. */
typedef char *data_t;
typedef const char *const_data_t;
typedef char string_t [1024];
typedef int *intarray_t;
typedef const int *const_intarray_t;
typedef int *fd_mask_t;
typedef const int *const_fd_mask_t;
typedef mach_port_t *portarray_t;
typedef const mach_port_t *const_portarray_t;
typedef pid_t *pidarray_t;
typedef const pid_t *const_pidarray_t;
typedef uid_t *idarray_t;
typedef const uid_t *const_idarray_t;
#if 0
typedef __loff_t *off_array_t;
typedef const __loff_t *const_off_array_t;
#endif
typedef struct rusage rusage_t;
typedef struct flock flock_t;
typedef struct utsname utsname_t;
#if _FILE_OFFSET_BITS == 64
typedef struct stat io_statbuf_t;
typedef struct statfs fsys_statfsbuf_t;
#else
typedef struct stat64 io_statbuf_t;
typedef struct statfs64 fsys_statfsbuf_t;
#endif
typedef struct timespec timespec_t;
/* Parameters and flags in RPC calls */
/* Many such parameters and flags are also defined in various libc
headers. */
/* Bits for flags in fs.defs:file_exec_paths and exec.defs:exec_* calls: */
#define EXEC_NEWTASK 0x00000001 /* Create new task; kill old one. */
#define EXEC_SECURE 0x00000002 /* Use secure values of portarray, etc. */
#define EXEC_DEFAULTS 0x00000004 /* Use defaults for unspecified ports. */
#define EXEC_SIGTRAP 0x00000008 /* Simulate SIGTRAP on startup. */
/* This flag is passed through by the exec server but not examined by it. */
#define EXEC_STACK_ARGS 0x00000010 /* Use arguments from stack, not RPC. */
/* Bits for flags in fs.defs:file_set_translator call: */
#define FS_TRANS_FORCE 0x00000001 /* Must use translator(no sht circuit) */
#define FS_TRANS_EXCL 0x00000002 /* Don't do it if already translated. */
#define FS_TRANS_SET 0x00000004 /* Set or clear translator */
#define FS_TRANS_ORPHAN 0x00000008 /* Orphan the active translator. */
/* Values for retry field in fs.defs:dir_lookup call: */
enum retry_type
{
FS_RETRY_NORMAL = 1, /* Retry normally if retry_name is not null. */
FS_RETRY_REAUTH = 2, /* Retry after reauthenticating retry port.
Even if the retry name is null, a retry
is still necessary with this code after the
reauthentication is complete. */
FS_RETRY_MAGICAL = 3, /* Retry string is magical. */
/* "tty" means controlling tty;
"fd/%u" means file descriptor N;
"machtype/..." means replace `machtype' with the numbers in decimal
returned by the user's kernel as the cpu_type (N) and
cpu_subtype (M) (producing N/M/...) and then retry
as for FS_RETRY_NORMAL.
"/..." means retry "...", but starting from the users root directory.
"pid/..." means replace `pid' with the PID of the current process in %u
format and then retry as for FS_RETRY_NORMAL.
*/
};
typedef enum retry_type retry_type;
/* Types for fs_notify.defs:dir_changed call: */
enum dir_changed_type
{
DIR_CHANGED_NULL, /* Always sent first for sync. */
DIR_CHANGED_NEW, /* Specified name has been added. */
DIR_CHANGED_UNLINK, /* Specified name has been removed. */
DIR_CHANGED_RENUMBER, /* Name has been the target of rename. */
};
typedef enum dir_changed_type dir_changed_type_t;
/* Types for fs_notify.defs:file_changed call: */
enum file_changed_type
{
FILE_CHANGED_NULL, /* Always sent first for sync. */
FILE_CHANGED_WRITE, /* File data has been written. */
FILE_CHANGED_EXTEND, /* File has grown. */
FILE_CHANGED_TRUNCATE, /* File has been truncated. */
FILE_CHANGED_META, /* Stat information has changed, and none
of the previous three apply. Not sent
for changes in node times. */
};
typedef enum file_changed_type file_changed_type_t;
/* Select types for io.defs:io_select call: */
#define SELECT_READ 0x00000001
#define SELECT_WRITE 0x00000002
#define SELECT_URG 0x00000004
/* Flags for fsys.defs:fsys_goaway. Also, these flags are sent as the
oldtrans_flags in fs.defs:file_set_translator to describe how to
terminate the old translator. */
#define FSYS_GOAWAY_NOWAIT 0x00000001 /* Return immediately. */
#define FSYS_GOAWAY_NOSYNC 0x00000002 /* Don't update physical media. */
#define FSYS_GOAWAY_FORCE 0x00000004 /* Go away despite current users. */
#define FSYS_GOAWAY_UNLINK 0x00000008 /* Go away only if non-directory. */
#define FSYS_GOAWAY_RECURSE 0x00000010 /* Shutdown children too. */
/* Types of ports the terminal driver can run on top of;
used in term.defs:term_get_bottom_type. */
enum term_bottom_type
{
TERM_ON_MACHDEV,
TERM_ON_HURDIO,
TERM_ON_MASTERPTY,
};
/* Types of storage, as returned by file_get_storage_info.
STORAGE_DEVICE is a mach device_t (for random access devices)
STORAGE_HURD_FILE is a hurd file_t (as if a file were mapped)
STORAGE_TASK is a task_t (the storage is in the vm of the task)
STORAGE_MEMORY is a memory object port
STORAGE_ZERO is a fixed-size constant source of zeros
STORAGE_INTERLEAVE is a set of other storage types interleaved at a fixed
interval
STORAGE_CONCAT is a set of other storage types concatenated end-to-end
STORAGE_LAYER is a set of storage types, representing the same address
range; all will be written too, and will be read in turn until one
succeeds
STORAGE_REMAP is a layer on top of another store that remaps its blocks
STORAGE_COPY is a memory snapshot of another store
STORAGE_NETWORK means that the file is stored elsewhere on the
network; all the remaining fields contan type-specific information.
STORAGE_OTHER means none of these apply; and should be used when no
meaningful answer can be given
The vectors returned by file_get_storage_info encode each of the above
(note that the first int is always the storage type). There are four:
ports, ints, offsets (off_t), and data (char); each type of store uses the
following entries in each vector:
-type- -ports- -ints- -offsets- -data- -kids-
device DEVICE TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
file FILE TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
memory MEMOBJ TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
task TASK TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
(the data for the above is a name (incl '\0') and a misc data block)
null - TY, FL SIZE - -
(BS is 1)
ileave - TY, FL, IL, NC - - NC
(BS is the LCM of its children; SIZE is the minimum of theirs * IL)
concat - TY, FL, NC - - NC
(BS is the LCM of its children; SIZE is the sum of theirs)
layer - TY, FL, NC - - NC
(BS is the LCM of its children; SIZE is the minimum of theirs)
remap - TY, FL, NR NR * (OFFS, LEN) - 1
(BS and SIZE are that of the child)
copy - TY, FL, SIZE - DATA -
(DATA is preceded by padding to the next page boundary, and is
SIZE bytes long itself)
For ileave, concat, and layer, the children are encoded following the parent.
The first int must always be TY.
key: TY = type code, FL = flags, BS = block size, NR = num runs,
NL = name len, ML = misc len, NC = num children,
IL = interleave (bytes), SIZE = Size of storage (blocks),
LEN = run length (blocks), OFFS = run offset (blocks),
The NR * (OFFS, LEN) offsets for some of the types is the set of block
ranges in the underlying address space that, concatenated, make up the
contents of the storage -- for instance, doing file_get_storage_info on a
file may return storage of type STORAGE_DEVICE, and the accompanying block
ranges are the set of blocks on the given device that correspond to that
file. Any OFFS == -1 designates a hole in the address range. Note that
the total size (SIZE) for these types is the sum of their LEN's.
The optional NAME returned by some types (if NL != 0) is a type specific
name for the same object referenced by the port also returned. E.g.:
device -- The mach device name
file -- The file name (unreliable, as the root may not be the same)
task -- The pid
Unless it is MACH_PORT_NULL, the port should generally be used instead of
trying to regenerate it from the associated name, which is intended more for
printing messages, etc. */
enum file_storage_class
{
STORAGE_OTHER,
STORAGE_DEVICE,
STORAGE_HURD_FILE,
STORAGE_NETWORK,
STORAGE_MEMORY,
STORAGE_TASK,
STORAGE_ZERO,
STORAGE_CONCAT,
STORAGE_INTERLEAVE,
STORAGE_LAYER,
STORAGE_REMAP,
STORAGE_COPY,
};
/* Flags for the flags word returned by some types . */
#define STORAGE_MUTATED 0x00000001 /* data as stored is munged from file */
/* Data types */
#include <mach/task_info.h>
#include <mach/thread_info.h>
#ifndef THREAD_SCHED_INFO
#include <mach/policy.h>
#endif
/* Flags sent in proc_getprocinfo request. */
#define PI_FETCH_TASKINFO 0x0001
#define PI_FETCH_TASKEVENTS 0x0020
#define PI_FETCH_THREADS 0x0002
#define PI_FETCH_THREAD_BASIC 0x0004
#define PI_FETCH_THREAD_SCHED 0x0008
#define PI_FETCH_THREAD_WAITS 0x0010
struct procinfo
{
int state;
uid_t owner;
pid_t ppid;
pid_t pgrp;
pid_t session;
pid_t logincollection;
int exitstatus;
int sigcode;
int nthreads; /* size of pi_threadinfos */
struct task_basic_info taskinfo;
struct task_events_info taskevents;
#ifdef TASK_SCHED_TIMESHARE_INFO
struct policy_timeshare_base timeshare_base_info;
#endif
struct
{
int died; /* this thread died in the middle of call */
mach_msg_id_t rpc_block; /* thread is blocked on this RPC */
struct thread_basic_info pis_bi;
#ifdef THREAD_SCHED_INFO
struct thread_sched_info pis_si;
#else
struct policy_infos pis_pi;
#endif
} threadinfos[0];
};
typedef int *procinfo_t;
typedef const int *const_procinfo_t;
/* Bits in struct procinfo state: */
#define PI_STOPPED 0x00000001 /* Proc server thinks is stopped. */
#define PI_EXECED 0x00000002 /* Has called proc_exec. */
#define PI_WAITING 0x00000004 /* Process is waiting for child to exit */
#define PI_ORPHAN 0x00000008 /* Process group is orphaned. */
#define PI_NOMSG 0x00000010 /* Process has no message port. */
#define PI_SESSLD 0x00000020 /* Session leader. */
#define PI_NOTOWNED 0x0000040 /* Process has no owner. */
#define PI_NOPARENT 0x0000080 /* Hasn't identified a parent. */
#define PI_ZOMBIE 0x00000100 /* Has no associated task. */
#define PI_TRACED 0x00000200 /* Process is being traced */
#define PI_GETMSG 0x00000400 /* Process is blocked in proc_getmsgport. */
#define PI_LOGINLD 0x00000800 /* Process is leader of login collection */
/* Conventions */
/* st_fstype in struct stat and fsys_stb_type in fsys_statfsbuf is one of: */
#define FSTYPE_UFS 0x00000000 /* 4.x BSD Fast File System */
#define FSTYPE_NFS 0x00000001 /* Network File System ala Sun */
#define FSTYPE_GFS 0x00000002 /* GNU file system */
#define FSTYPE_LFS 0x00000003 /* Logging File System ala Sprite */
#define FSTYPE_SYSV 0x00000004 /* Old U*x filesystem ala System V */
#define FSTYPE_FTP 0x00000005 /* Transparent FTP */
#define FSTYPE_TAR 0x00000006 /* Transparent TAR */
#define FSTYPE_AR 0x00000007 /* Transparent AR */
#define FSTYPE_CPIO 0x00000008 /* Transparent CPIO */
#define FSTYPE_MSLOSS 0x00000009 /* MS-DOS */
#define FSTYPE_CPM 0x0000000a /* CP/M */
#define FSTYPE_HFS 0x0000000b /* Don't ask */
#define FSTYPE_DTFS 0x0000000c /* used by desktop to provide more info */
#define FSTYPE_GRFS 0x0000000d /* GNU Remote File System */
#define FSTYPE_TERM 0x0000000e /* GNU Terminal driver */
#define FSTYPE_DEV 0x0000000f /* GNU Special file server */
#define FSTYPE_PROC 0x00000010 /* /proc filesystem ala Version 9 */
#define FSTYPE_IFSOCK 0x00000011 /* PF_LOCAL socket naming point */
#define FSTYPE_AFS 0x00000012 /* Andrew File System 3.xx */
#define FSTYPE_DFS 0x00000013 /* Distributed File Sys (OSF) == AFS 4.xx */
#define FSTYPE_PROC9 0x00000014 /* /proc filesystem ala Plan 9 */
#define FSTYPE_SOCKET 0x00000015 /* io_t that isn't a file but a socket */
#define FSTYPE_MISC 0x00000016 /* generic trivfs server */
#define FSTYPE_EXT2FS 0x00000017 /* Linux filesystem by Remy Card */
#define FSTYPE_HTTP 0x00000018 /* Transparent HTTP */
#define FSTYPE_MEMFS 0x00000019 /* In-core filesystem */
#define FSTYPE_ISO9660 0x0000001a /* ISO9660 */
/* Standard port assignments for file_exec_paths and exec_* */
enum
{
INIT_PORT_CWDIR,
INIT_PORT_CRDIR,
INIT_PORT_AUTH,
INIT_PORT_PROC,
INIT_PORT_CTTYID,
/* If MACH_PORT_NULL is given for the bootstrap port,
the bootstrap port of the old task is used. */
INIT_PORT_BOOTSTRAP,
INIT_PORT_MAX
};
/* Standard ints for file_exec_paths and exec_* */
enum
{
INIT_UMASK,
INIT_SIGMASK,
INIT_SIGIGN,
INIT_SIGPENDING,
INIT_TRACEMASK,
INIT_INT_MAX,
};
#endif // _HURD_TYPES_H

51
include/gnu/hurd.h Normal file
View File

@ -0,0 +1,51 @@
/*
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MES_GNU_HURD_H
#define __MES_GNU_HURD_H
#define _GNU_SOURCE 1
#define __USE_GNU 1
#include <mach/mach_types.h>
#include <mach/message.h>
#include <mach/port.h>
struct hurd_startup_data
{
int flags;
mach_port_t *dtable;
mach_msg_type_number_t dtablesize;
mach_port_t *portarray;
mach_msg_type_number_t portarraysize;
int *intarray;
mach_msg_type_number_t intarraysize;
vm_address_t stack_base;
vm_size_t stack_size;
vm_address_t phdr;
vm_size_t phdrsz;
vm_address_t user_entry;
};
extern mach_port_t *_hurd_init_dtable;
extern mach_msg_type_number_t _hurd_init_dtablesize;
extern struct hurd_startup_data _hurd_startup_data;
#endif // __MES_GNU_HURD_H

115
include/gnu/syscall.h Normal file
View File

@ -0,0 +1,115 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MES_GNU_SYSCALL_H
#define __MES_GNU_SYSCALL_H
#define _GNU_SOURCE 1
#define __USE_GNU 1
#include <mach/mach_types.h>
#include <mach/port.h>
#include <mach/message.h>
#include <gnu/hurd.h>
#include <gnu/hurd-types.h>
// mach/mach.defs
enum
{
SYS__task_terminate = 2008,
SYS__vm_statistics = 2030,
SYS__task_get_special_port = 2058,
};
// hurd/process.defs
enum
{
SYS__proc_mark_exit = 24025,
};
// hurd/startup.defs
enum
{
SYS__exec_startup_get_info = 30500,
};
extern mach_msg_type_t mach_msg_type_int32;
struct mach_msg
{
mach_msg_header_t header;
};
struct mach_msg_1
{
mach_msg_header_t header;
mach_msg_type_t type_one; int one;
};
struct mach_msg_2
{
mach_msg_header_t header;
mach_msg_type_t type_one; int one;
mach_msg_type_t type_two; int two;
};
struct mach_msg_startup_info
{
mach_msg_header_t header;
mach_msg_type_t RetCodeType;
kern_return_t RetCode;
mach_msg_type_t user_entryType;
vm_address_t user_entry;
mach_msg_type_t phdrType;
vm_address_t phdr;
mach_msg_type_t phdr_sizeType;
vm_size_t phdr_size;
mach_msg_type_t stack_baseType;
vm_address_t stack_base;
mach_msg_type_t stack_sizeType;
vm_size_t stack_size;
mach_msg_type_t flagsType;
int flags;
mach_msg_type_long_t argvType;
char *argv;
mach_msg_type_long_t envpType;
char *envp;
mach_msg_type_long_t dtableType;
mach_port_t *dtable;
mach_msg_type_long_t portarrayType;
mach_port_t *portarray;
mach_msg_type_long_t intarrayType;
int *intarray;
};
kern_return_t __syscall (mach_port_t port, int sys_call);
kern_return_t __syscall2 (mach_port_t port, int sys_call, int one, int two);
kern_return_t __syscall_get (mach_port_t port, int sys_call, mach_msg_header_t *message, size_t size);
// mach.defs
kern_return_t __task_terminate (mach_port_t task);
kern_return_t __task_get_special_port (mach_port_t task, int which, mach_port_t *port);
kern_return_t __vm_statistics (mach_port_t task, vm_statistics_data_t *vm_stats);
// process.defs
kern_return_t __proc_mark_exit (mach_port_t process, int one, int two);
kern_return_t __exec_startup_get_data (mach_port_t bootstrap, struct hurd_startup_data *data);
#endif // __MES_GNU_SYSCALL_H

52
include/mach/mach-init.h Normal file
View File

@ -0,0 +1,52 @@
/* Declarations and macros for the basic Mach things set at startup.
Copyright (C) 1993-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef _MACH_INIT_H
#define _MACH_INIT_H 1
#include <mach/mach_types.h>
/* Return the current task's task port. */
extern mach_port_t __mach_task_self (void);
extern mach_port_t mach_task_self (void);
/* This cache is initialized at startup. */
extern mach_port_t __mach_task_self_;
#define __mach_task_self() (__mach_task_self_ + 0) /* Not an lvalue. */
#define mach_task_self() (__mach_task_self ())
/* This cache is initialized at startup. */
extern mach_port_t __mach_host_self_;
#define __mach_host_self() (__mach_host_self_ + 0) /* Not an lvalue. */
#define mach_host_self() (__mach_host_self ())
/* Kernel page size. */
extern vm_size_t __vm_page_size;
extern vm_size_t vm_page_size;
/* Round the address X up to a page boundary. */
#define round_page(x) \
((((vm_offset_t) (x) + __vm_page_size - 1) / __vm_page_size) * \
__vm_page_size)
/* Truncate the address X down to a page boundary. */
#define trunc_page(x) \
((((vm_offset_t) (x)) / __vm_page_size) * __vm_page_size)
#endif /* mach_init.h */

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -31,6 +31,7 @@ typedef int pid_t;
#endif
#define WNOHANG 1
#define W_EXITCODE(status, signal) ((status) << 8 | (signal))
pid_t waitpid (pid_t pid, int *status_ptr, int options);
pid_t wait (int *status_ptr);

38
lib/gnu/_exit.c Normal file
View File

@ -0,0 +1,38 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
/** Commentary:
Inspired by implementation in GNU C Library:
_hurd_exit
Copyright (C) 1993-2016 Free Software Foundation, Inc.
*/
#include <gnu/hurd.h>
#include <gnu/hurd-types.h>
#include <gnu/syscall.h>
#include <mach/mach-init.h>
void
_exit (int status)
{
__proc_mark_exit (_hurd_startup_data.portarray[INIT_PORT_PROC], status, 0);
__task_terminate (__mach_task_self ());
while (1) {* (int *) 0 = 0;}
}

View File

@ -0,0 +1,57 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gnu/syscall.h>
static void
mach_startup_info2hurd_startup_data (struct mach_msg_startup_info *info,
struct hurd_startup_data *data)
{
data->flags = info->flags;
data->dtable = info->dtable;
data->dtablesize = info->dtableType.msgtl_number;
data->portarray = info->portarray;
data->portarraysize = info->portarrayType.msgtl_number;
data->intarray = info->intarray;
data->intarraysize = info->intarrayType.msgtl_number;
data->stack_base = info->stack_base;
data->stack_size = info->stack_size;
data->phdr = info->phdr;
data->phdrsz = info->phdr_size;
data->user_entry = info->user_entry;
}
kern_return_t
__exec_startup_get_data (mach_port_t bootstrap, struct hurd_startup_data *data)
{
union message
{
mach_msg_header_t header;
struct mach_msg_startup_info info;
};
union message message;
message.header.msgh_size = sizeof (struct mach_msg);
kern_return_t result = __syscall_get (bootstrap, SYS__exec_startup_get_info,
&message.header, sizeof (message));
mach_startup_info2hurd_startup_data (&message.info, data);
return result;
}

47
lib/gnu/hurd-start.c Normal file
View File

@ -0,0 +1,47 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
/** Commentary:
Inspired by implementation in GNU C Library:
Initialization code run first thing by the ELF startup code. For i386/Hurd.
Copyright (C) 1995-2016 Free Software Foundation, Inc.
*/
#include <gnu/hurd.h>
#include <gnu/syscall.h>
#include <mach/mach-init.h>
#include <mach/mach_types.h>
#include <mach/message.h>
#include <mach/port.h>
struct hurd_startup_data _hurd_startup_data;
void __mach_init (void);
void
_hurd_start ()
{
mach_port_t bootstrap;
__mach_init ();
__task_get_special_port (__mach_task_self (), TASK_BOOTSTRAP_PORT,
&bootstrap);
__exec_startup_get_data (bootstrap, &_hurd_startup_data);
}

28
lib/gnu/proc-mark-exit.c Normal file
View File

@ -0,0 +1,28 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gnu/syscall.h>
#include <sys/wait.h>
kern_return_t
__proc_mark_exit (mach_port_t process, int status, int signal)
{
return __syscall2 (process, SYS__proc_mark_exit, W_EXITCODE (status, 0), signal);
}

99
lib/gnu/syscall.c Normal file
View File

@ -0,0 +1,99 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gnu/syscall.h>
#include <mach/mach_traps.h>
mach_msg_type_t mach_msg_type_int32 =
{
.msgt_name = (unsigned char) MACH_MSG_TYPE_INTEGER_32, // msgt_name
.msgt_size = 32, // msgt_size
.msgt_number = 1, // msgt_number
.msgt_inline = 1, // msgt_inline
.msgt_longform = 0, // msgt_longform
.msgt_deallocate = 0, // msgt_deallocate
.msgt_unused = 0 // msgt_unused
};
kern_return_t
__syscall (mach_port_t port, int sys_call)
{
struct mach_msg message =
{
{
MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE),
0,
port,
{__mach_reply_port (),},
0,
sys_call,
}
};
return __mach_msg (&message.header,
MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE,
sizeof (message),
sizeof (message),
message.header.msgh_local_port,
MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL);
}
kern_return_t
__syscall2 (mach_port_t port, int sys_call, int one, int two)
{
struct mach_msg_2 message =
{
{
MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE),
0,
port,
{__mach_reply_port (),},
0,
sys_call,
},
mach_msg_type_int32, one,
mach_msg_type_int32, two,
};
return __mach_msg (&message.header,
MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE,
sizeof (message),
sizeof (message),
message.header.msgh_local_port,
MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL);
}
kern_return_t
__syscall_get (mach_port_t port, int sys_call, mach_msg_header_t *message, size_t size)
{
message->msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE);
message->msgh_remote_port = port;
message->msgh_local_port = __mach_reply_port ();
message->msgh_seqno = 0;
message->msgh_id = sys_call;
return __mach_msg (message,
MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE,
message->msgh_size,
size,
message->msgh_local_port,
MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL);
}

View File

@ -0,0 +1,37 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gnu/syscall.h>
kern_return_t
__task_get_special_port (mach_port_t task, int which, mach_port_t *port)
{
struct mach_msg_2 message = {0};
message.header.msgh_size = sizeof (struct mach_msg_1);
message.type_one = mach_msg_type_int32;
message.one = which;
message.type_two = mach_msg_type_int32;
message.two = 0;
kern_return_t result = __syscall_get (task, SYS__task_get_special_port,
&message.header, sizeof (message));
if (result == KERN_SUCCESS)
*port = message.two;
return result;
}

27
lib/gnu/task-terminate.c Normal file
View File

@ -0,0 +1,27 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gnu/syscall.h>
kern_return_t
__task_terminate (mach_port_t task)
{
return __syscall (task, SYS__task_terminate);
}

41
lib/gnu/vm-statistics.c Normal file
View File

@ -0,0 +1,41 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gnu/syscall.h>
struct mach_msg_int32_vm_statistics_data
{
mach_msg_header_t header;
mach_msg_type_t type_one; int one;
mach_msg_type_t type_two; vm_statistics_data_t two;
};
kern_return_t
__vm_statistics (mach_port_t task, vm_statistics_data_t *vm_stats)
{
struct mach_msg_int32_vm_statistics_data message = {0};
message.header.msgh_size = sizeof (struct mach_msg);
message.type_one = mach_msg_type_int32;
message.type_two = mach_msg_type_int32;
kern_return_t result = __syscall_get (task, SYS__vm_statistics,
&message.header, sizeof (message));
*vm_stats = message.two;
return result;
}

View File

@ -0,0 +1,43 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of Mes.
*
* Mes 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 3 of the License, or (at
* your option) any later version.
*
* Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#if 0
#include <mes/lib-mini.h>
#else // FIXME
#define __MES_LIB_MINI_H 1
char **environ;
int __stdin;
int __stdout;
int __stderr;
#endif
void _hurd_start (void);
void _posix_start (void);
void
_start ()
{
_hurd_start ();
_posix_start ();
}
#define _start _posix_start
#include <linux/x86-mes-gcc/crt1.c>

View File

@ -0,0 +1,23 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mes/lib-mini.h"
// your mini mach here

View File

@ -69,9 +69,8 @@ _start ()
"call main\n\t"
"mov %eax,%ebx\n\t"
"mov $1,%eax\n\t"
"int $0x80\n\t"
"push %eax\n\t"
"call _exit\n\t"
"hlt \n\t"
);
}

52
lib/mach/mach-init.c Normal file
View File

@ -0,0 +1,52 @@
/* Copyright (C) 1992-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#define _GNU_SOURCE 1
#define __USE_GNU 1
#include <mach.h>
#include <mach/mach-init.h>
//#include <mach/mig_support.h>
#include <unistd.h>
mach_port_t __mach_task_self_;
mach_port_t __mach_host_self_;
vm_size_t __vm_page_size = 0;
void
__mach_init (void)
{
kern_return_t err;
__mach_task_self_ = (__mach_task_self) ();
__mach_host_self_ = (__mach_host_self) ();
#if 0
__mig_init (0);
#endif
#ifdef HAVE_HOST_PAGE_SIZE
if (err = __host_page_size (__mach_host_self (), &__vm_page_size))
_exit (err);
#else
{
vm_statistics_data_t stats;
if (err = __vm_statistics (__mach_task_self (), &stats))
_exit (err);
__vm_page_size = stats.pagesize;
}
#endif
}

View File

@ -0,0 +1,3 @@
#include <mach/machine/syscall_sw.h>
kernel_trap (__mach_host_self,-29,0)
// weak_alias (__mach_host_self, mach_host_self)

3
lib/mach/mach_msg_trap.S Normal file
View File

@ -0,0 +1,3 @@
#include <mach/machine/syscall_sw.h>
kernel_trap (__mach_msg_trap,-25,7)
// weak_alias (__mach_msg_trap, mach_msg_trap)

View File

@ -0,0 +1,3 @@
#include <mach/machine/syscall_sw.h>
kernel_trap (__mach_reply_port,-26,0)
// weak_alias (__mach_reply_port, mach_reply_port)

View File

@ -0,0 +1,3 @@
#include <mach/machine/syscall_sw.h>
kernel_trap (__mach_task_self,-28,0)
// weak_alias (__mach_task_self, mach_task_self)

View File

@ -0,0 +1,19 @@
#if 1
#include <mach/machine/syscall_sw.h>
kernel_trap (__mach_thread_self,-27,0)
// weak_alias (__mach_thread_self, mach_thread_self)
#else
.globl __mach_thread_self
.type __mach_thread_self,@function
.align 1<<4
__mach_thread_self: .cfi_startproc
movl $ -27,%eax
.byte 0x9a
.long 0
.word 0x7
ret
.cfi_endproc
.size __mach_thread_self,.-__mach_thread_self
.weak mach_thread_self
mach_thread_self = __mach_thread_self
#endif

145
lib/mach/msg.c Normal file
View File

@ -0,0 +1,145 @@
/*
* Mach Operating System
* Copyright (c) 1991,1990,1989, 1995 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
#include <mach/port.h>
#include <mach/message.h>
#ifdef MACH_MSG_OVERWRITE
/* In variants with this feature, the actual system call is
__mach_msg_overwrite_trap. */
mach_msg_return_t
__mach_msg_trap (mach_msg_header_t *msg,
mach_msg_option_t option,
mach_msg_size_t send_size,
mach_msg_size_t rcv_size,
mach_port_t rcv_name,
mach_msg_timeout_t timeout,
mach_port_t notify)
{
return __mach_msg_overwrite_trap (msg, option, send_size,
rcv_size, rcv_name, timeout, notify,
MACH_MSG_NULL, 0);
}
weak_alias (__mach_msg_trap, mach_msg_trap)
/* See comments below in __mach_msg. */
mach_msg_return_t
__mach_msg_overwrite (mach_msg_header_t *msg,
mach_msg_option_t option,
mach_msg_size_t send_size,
mach_msg_size_t rcv_size,
mach_port_t rcv_name,
mach_msg_timeout_t timeout,
mach_port_t notify,
mach_msg_header_t *rcv_msg,
mach_msg_size_t rcv_msg_size)
{
mach_msg_return_t ret;
/* Consider the following cases:
1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
plus special bits).
2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
3. RPC calls with interruptions in one/both halves.
*/
ret = __mach_msg_overwrite_trap (msg, option, send_size,
rcv_size, rcv_name, timeout, notify,
rcv_msg, rcv_msg_size);
if (ret == MACH_MSG_SUCCESS)
return MACH_MSG_SUCCESS;
if (!(option & MACH_SEND_INTERRUPT))
while (ret == MACH_SEND_INTERRUPTED)
ret = __mach_msg_overwrite_trap (msg, option, send_size,
rcv_size, rcv_name, timeout, notify,
rcv_msg, rcv_msg_size);
if (!(option & MACH_RCV_INTERRUPT))
while (ret == MACH_RCV_INTERRUPTED)
ret = __mach_msg_overwrite_trap (msg, option & ~MACH_SEND_MSG,
0, rcv_size, rcv_name, timeout, notify,
rcv_msg, rcv_msg_size);
return ret;
}
weak_alias (__mach_msg_overwrite, mach_msg_overwrite)
#endif
mach_msg_return_t
__mach_msg (mach_msg_header_t *msg,
mach_msg_option_t option,
mach_msg_size_t send_size,
mach_msg_size_t rcv_size,
mach_port_t rcv_name,
mach_msg_timeout_t timeout,
mach_port_t notify)
{
mach_msg_return_t ret;
/* Consider the following cases:
1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
plus special bits).
2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
3. RPC calls with interruptions in one/both halves.
*/
ret = __mach_msg_trap (msg, option, send_size,
rcv_size, rcv_name, timeout, notify);
if (ret == MACH_MSG_SUCCESS)
return MACH_MSG_SUCCESS;
if (!(option & MACH_SEND_INTERRUPT))
while (ret == MACH_SEND_INTERRUPTED)
ret = __mach_msg_trap (msg, option, send_size,
rcv_size, rcv_name, timeout, notify);
if (!(option & MACH_RCV_INTERRUPT))
while (ret == MACH_RCV_INTERRUPTED)
ret = __mach_msg_trap (msg, option & ~MACH_SEND_MSG,
0, rcv_size, rcv_name, timeout, notify);
return ret;
}
// weak_alias (__mach_msg, mach_msg)
mach_msg_return_t
__mach_msg_send (mach_msg_header_t *msg)
{
return __mach_msg (msg, MACH_SEND_MSG,
msg->msgh_size, 0, MACH_PORT_NULL,
MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
}
// weak_alias (__mach_msg_send, mach_msg_send)
mach_msg_return_t
__mach_msg_receive (mach_msg_header_t *msg)
{
return __mach_msg (msg, MACH_RCV_MSG,
0, msg->msgh_size, msg->msgh_local_port,
MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
}
// weak_alias (__mach_msg_receive, mach_msg_receive)

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -21,37 +21,6 @@
int
main ()
{
#if __i386__
#if __MESC__
asm ("mov____$i32,%ebx %0");
asm ("mov____$i32,%eax SYS_exit");
asm ("int____$0x80");
#elif __TINYC__
asm ("mov $0,%ebx");
asm ("mov $1,%eax");
asm ("int $128");
#else // !__TINYC__
asm ("mov $0,%ebx");
asm ("mov $1,%eax");
asm ("int $0x80");
#endif // !__TINYC__
#elif __x86_64__
#if __MESC__
asm ("mov____$i32,%rdi %0");
asm ("mov____$i32,%rax SYS_exit");
asm ("syscall");
#elif __TINYC__
asm ("mov $0,%rdi");
asm ("mov $0x3c,%rax");
asm ("syscall");
#else // !__TINYC__
asm ("mov $0,%rdi");
asm ("mov $60,%rax");
asm ("syscall");
#endif // !__TINYC__
#endif // ! __x86_64__
_exit (0);
return 1;
}

View File

@ -0,0 +1,26 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes 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 3 of the License, or (at
* your option) any later version.
*
* GNU Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
main ()
{
_exit (42);
return 0;
}

View File

@ -0,0 +1 @@
42