cvsuser 04/02/19 09:06:32
Modified: config/gen makefiles.pl platform.pl
config/gen/makefiles root.in
config/init data.pl
lib/Parrot/Configure Step.pm
. MANIFEST
Added: config/gen/platform/aix asm.s
config/gen/platform/ansi dl.c exec.c io.h time.c
config/gen/platform/darwin begin.c dl.c
config/gen/platform/generic dl.c dl.h env.c exec.c io.h
itimer.c memalign.c memexec.c signal.c signal.h
threads.h time.c
config/gen/platform/ia64 asm.s
config/gen/platform/openbsd memexec.c misc.h
config/gen/platform/win32 begin.c dl.c env.c exec.c io.h
misc.c misc.h time.c
Log:
#25239 Platform-specific files not granular enough
Hopefully in time to make the feature freeze, here's an effort at solving this
problem. I went through the platform .c and .h files and broke out the
redundant bits into the following "modules", which were already delimited by
comments in generic.*:
dl: dynamic library loading
env: environment twiddling
exec: system()
io: I/O
itimer: system timers
memalign: memory alignment
memexec: executable memory protection
signal: signal handling
threads: pthreads interface
time: time() and get
I've removed the .c and .h files from platform/ and created per-platform
subdirectories there. generic/ has the pieces split out from generic.c and
generic.h, openbsd/ has those from openbsd.c, etc. Those pieces which were
just copied from generic.* are now gone, instead relying on platform.pl to fall
back to generic/ code when platform-specific versions aren't needed. This
eliminates a fair bit of duplication.
Courtesy of Adam Thomason
Revision Changes Path
1.1 parrot/config/gen/platform/aix/asm.s
Index: asm.s
===================================================================
# Branch hints suppressed.
.machine "pwr"
.set r0,0; .set SP,1; .set RTOC,2; .set r3,3; .set r4,4
.set r5,5; .set r6,6; .set r7,7; .set r8,8; .set r9,9
.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14
.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19
.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24
.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29
.set r30,30; .set r31,31
.set fp0,0; .set fp1,1; .set fp2,2; .set fp3,3; .set fp4,4
.set fp5,5; .set fp6,6; .set fp7,7; .set fp8,8; .set fp9,9
.set fp10,10; .set fp11,11; .set fp12,12; .set fp13,13; .set fp14,14
.set fp15,15; .set fp16,16; .set fp17,17; .set fp18,18; .set fp19,19
.set fp20,20; .set fp21,21; .set fp22,22; .set fp23,23; .set fp24,24
.set fp25,25; .set fp26,26; .set fp27,27; .set fp28,28; .set fp29,29
.set fp30,30; .set fp31,31
.set MQ,0; .set XER,1; .set FROM_RTCU,4; .set FROM_RTCL,5; .set FROM_DEC,6
.set LR,8; .set CTR,9; .set TID,17; .set DSISR,18; .set DAR,19; .set TO_RTCU,20
.set TO_RTCL,21; .set TO_DEC,22; .set SDR_0,24; .set SDR_1,25; .set SRR_0,26
.set SRR_1,27
.set BO_dCTR_NZERO_AND_NOT,0; .set BO_dCTR_NZERO_AND_NOT_1,1
.set BO_dCTR_ZERO_AND_NOT,2; .set BO_dCTR_ZERO_AND_NOT_1,3
.set BO_IF_NOT,4; .set BO_IF_NOT_1,5; .set BO_IF_NOT_2,6
.set BO_IF_NOT_3,7; .set BO_dCTR_NZERO_AND,8; .set BO_dCTR_NZERO_AND_1,9
.set BO_dCTR_ZERO_AND,10; .set BO_dCTR_ZERO_AND_1,11; .set BO_IF,12
.set BO_IF_1,13; .set BO_IF_2,14; .set BO_IF_3,15; .set BO_dCTR_NZERO,16
.set BO_dCTR_NZERO_1,17; .set BO_dCTR_ZERO,18; .set BO_dCTR_ZERO_1,19
.set BO_ALWAYS,20; .set BO_ALWAYS_1,21; .set BO_ALWAYS_2,22
.set BO_ALWAYS_3,23; .set BO_dCTR_NZERO_8,24; .set BO_dCTR_NZERO_9,25
.set BO_dCTR_ZERO_8,26; .set BO_dCTR_ZERO_9,27; .set BO_ALWAYS_8,28
.set BO_ALWAYS_9,29; .set BO_ALWAYS_10,30; .set BO_ALWAYS_11,31
.set CR0_LT,0; .set CR0_GT,1; .set CR0_EQ,2; .set CR0_SO,3
.set CR1_FX,4; .set CR1_FEX,5; .set CR1_VX,6; .set CR1_OX,7
.set CR2_LT,8; .set CR2_GT,9; .set CR2_EQ,10; .set CR2_SO,11
.set CR3_LT,12; .set CR3_GT,13; .set CR3_EQ,14; .set CR3_SO,15
.set CR4_LT,16; .set CR4_GT,17; .set CR4_EQ,18; .set CR4_SO,19
.set CR5_LT,20; .set CR5_GT,21; .set CR5_EQ,22; .set CR5_SO,23
.set CR6_LT,24; .set CR6_GT,25; .set CR6_EQ,26; .set CR6_SO,27
.set CR7_LT,28; .set CR7_GT,29; .set CR7_EQ,30; .set CR7_SO,31
.set TO_LT,16; .set TO_GT,8; .set TO_EQ,4; .set TO_LLT,2; .set TO_LGT,1
.rename H.19.NO_SYMBOL{PR},""
.rename H.51.ppc_get_toc{TC},"ppc_get_toc"
.rename H.55.ppc_sync{TC},"ppc_sync"
.rename H.59.ppc_dcbf{TC},"ppc_dcbf"
.lglobl H.19.NO_SYMBOL{PR}
.globl .ppc_get_toc
.globl .ppc_sync
.globl .ppc_dcbf
.globl ppc_get_toc{DS}
.globl ppc_sync{DS}
.globl ppc_dcbf{DS}
# .text section
.file "sync-cache-factored.c"
.stabx "__default_char:t18=-5",0x00,0x8c,0x0
.stabx ":t2=-2",0x00,0x8c,0x0
.stabx ":t1=-11",0x00,0x8c,0x0
.stabx ":t3=*-2",0x00,0x8c,0x0
.stabx ":t4=f-11;",0x00,0x8c,0x0
.stabx ":t5=f-11;",0x00,0x8c,0x0
.stabx ":t6=*-11",0x00,0x8c,0x0
.stabx ":t7=f6;",0x00,0x8c,0x0
.stabx ":t19=Z",0x00,0x8c,0x0
.csect H.19.NO_SYMBOL{PR}
.ppc_get_toc: # 0x00000000 (H.19.NO_SYMBOL)
.stabx "ppc_get_toc:F6",0x00,0x8e,0x0
.function .ppc_get_toc,.ppc_get_toc,2,0
stu SP,-80(SP)
.bf 26
.stabx "x:6",0x040,0x81,0x0
.line 1
st RTOC,64(SP)
.line 2
l r3,64(SP)
st r3,68(SP)
b __L1c
.line 3
__L1c: # 0x0000001c (H.19.NO_SYMBOL+0x1c)
cal SP,80(SP)
bcr BO_ALWAYS,CR0_LT
.ef 28
.long 0x00000000
# traceback table
.byte 0x00 # VERSION=0
.byte 0x00 # LANG=TB_C
.byte 0x20 # IS_GL=0,IS_EPROL=0,HAS_TBOFF=1
# INT_PROC=0,HAS_CTL=0,TOCLESS=0
# FP_PRESENT=0,LOG_ABORT=0
.byte 0x40 # INT_HNDL=0,NAME_PRESENT=1
# USES_ALLOCA=0,CL_DIS_INV=WALK_ONCOND
# SAVES_CR=0,SAVES_LR=0
.byte 0x80 # STORES_BC=1,FPR_SAVED=0
.byte 0x00 # GPR_SAVED=0
.byte 0x00 # FIXEDPARMS=0
.byte 0x01 # FLOATPARMS=0,PARMSONSTK=1
.long 0x00000024 # TB_OFFSET
.short 11 # NAME_LEN
.byte "ppc_get_toc"
.byte 0 # padding
.byte 0 # padding
.byte 0 # padding
# End of traceback table
.ppc_sync: # 0x00000044 (H.19.NO_SYMBOL+0x44)
.stabx "ppc_sync:F-11",0x044,0x8e,0x0
.function .ppc_sync,.ppc_sync,2,0
.bf 17
.line 1
dcs
bcr BO_ALWAYS,CR0_LT
.ef 21
.long 0x00000000
# traceback table
.byte 0x00 # VERSION=0
.byte 0x00 # LANG=TB_C
.byte 0x20 # IS_GL=0,IS_EPROL=0,HAS_TBOFF=1
# INT_PROC=0,HAS_CTL=0,TOCLESS=0
# FP_PRESENT=0,LOG_ABORT=0
.byte 0x40 # INT_HNDL=0,NAME_PRESENT=1
# USES_ALLOCA=0,CL_DIS_INV=WALK_ONCOND
# SAVES_CR=0,SAVES_LR=0
.byte 0x00 # STORES_BC=0,FPR_SAVED=0
.byte 0x00 # GPR_SAVED=0
.byte 0x00 # FIXEDPARMS=0
.byte 0x01 # FLOATPARMS=0,PARMSONSTK=1
.long 0x00000010 # TB_OFFSET
.short 8 # NAME_LEN
.byte "ppc_sync"
.byte 0 # padding
.byte 0 # padding
# End of traceback table
.ppc_dcbf: # 0x00000070 (H.19.NO_SYMBOL+0x70)
.stabx "ppc_dcbf:F-11",0x070,0x8e,0x0
.function .ppc_dcbf,.ppc_dcbf,2,0
.bf 4
.stabx "_sync:p3",0x058,0x82,0x0
.line 1
stm 30,-8(1) # *(r1-8)=(r30,r31)
stu 1,-48(1) # *(r1-48)=r1, r1-=48
mr 30,1 # r30=r1=r1.orig-48
st 3,72(30) # *(r30+72==r1.orig+24)=r3
l 0,72(30) # r0=*(r30+72)=r3
clf 0,0 # clear r3
l 1,0(1) # r1=r1
lmw 30,-8(1) # (r30,r31)=*(r1-8)
bcr BO_ALWAYS,CR0_LT
.ef 12
.long 0x00000000
# traceback table
.byte 0x00 # VERSION=0
.byte 0x00 # LANG=TB_C
.byte 0x20 # IS_GL=0,IS_EPROL=0,HAS_TBOFF=1
# INT_PROC=0,HAS_CTL=0,TOCLESS=0
# FP_PRESENT=0,LOG_ABORT=0
.byte 0x40 # INT_HNDL=0,NAME_PRESENT=1
# USES_ALLOCA=0,CL_DIS_INV=WALK_ONCOND
# SAVES_CR=0,SAVES_LR=0
.byte 0x80 # STORES_BC=1,FPR_SAVED=0
.byte 0x00 # GPR_SAVED=0
.byte 0x01 # FIXEDPARMS=1
.byte 0x01 # FLOATPARMS=0,PARMSONSTK=1
.long 0x00000000 #
.long 0x0000001c # TB_OFFSET
.short 8 # NAME_LEN
.byte "ppc_dcbf"
.byte 0 # padding
.byte 0 # padding
# End of traceback table
.long 0x00000000 # "\0\0\0\0"
# End csect H.19.NO_SYMBOL{PR}
# .data section
.toc # 0x000000b0
T.51.ppc_get_toc:
.tc H.51.ppc_get_toc{TC},ppc_get_toc{DS}
T.55.ppc_sync:
.tc H.55.ppc_sync{TC},ppc_sync{DS}
T.59.ppc_dcbf:
.tc H.59.ppc_dcbf{TC},ppc_dcbf{DS}
.csect ppc_get_toc{DS}
.long .ppc_get_toc # "\0\0\0\0"
.long TOC{TC0} # "\0\0\0\260"
.long 0x00000000 # "\0\0\0\0"
# End csect ppc_get_toc{DS}
.csect ppc_sync{DS}
.long .ppc_sync # "\0\0\0D"
.long TOC{TC0} # "\0\0\0\260"
.long 0x00000000 # "\0\0\0\0"
# End csect ppc_sync{DS}
.csect ppc_dcbf{DS}
.long .ppc_dcbf # "\0\0\0p"
.long TOC{TC0} # "\0\0\0\260"
.long 0x00000000 # "\0\0\0\0"
# End csect ppc_dcbf{DS}
# .bss section
1.1 parrot/config/gen/platform/ansi/dl.c
Index: dl.c
===================================================================
/*
** Parrot_dlopen()
*/
void *
Parrot_dlopen(const char *filename)
{
Parrot_warn(NULL, PARROT_WARNINGS_PLATFORM_FLAG, "Parrot_dlopen not
implemented");
return NULL;
}
/*
** Parrot_dlerror()
*/
const char *
Parrot_dlerror(void)
{
return "Parrot_dlerror not implemented";
}
/*
** Parrot_dlsym()
*/
void *
Parrot_dlsym(void *handle, const char *symbol)
{
Parrot_warn(NULL, PARROT_WARNINGS_PLATFORM_FLAG, "Parrot_dlsym not implemented");
return NULL;
}
/*
** Parrot_dlclose()
*/
int
Parrot_dlclose(void *handle)
{
Parrot_warn(NULL, PARROT_WARNINGS_PLATFORM_FLAG, "Parrot_dlclose not
implemented");
return 0;
}
1.1 parrot/config/gen/platform/ansi/exec.c
Index: exec.c
===================================================================
/*
* Spawn a subprocess
*
*/
INTVAL Parrot_Run_OS_Command(Parrot_Interp interpreter, STRING *command) {
Parrot_warn(NULL, PARROT_WARNINGS_PLATFORM_FLAG, "Parrot_Run_OS_Command not
implemented");
return 0;
}
1.1 parrot/config/gen/platform/ansi/io.h
Index: io.h
===================================================================
/*
** I/O:
*/
#define DEFAULT_OPEN_MODE 0
#ifndef S_ISREG
# define S_ISREG(m) 1
#endif
1.1 parrot/config/gen/platform/ansi/time.c
Index: time.c
===================================================================
#include <time.h>
/*
** Parrot_intval_time()
*/
INTVAL
Parrot_intval_time(void)
{
return time(NULL);
}
/*
** Parrot_floatval_time()
*/
FLOATVAL
Parrot_floatval_time(void)
{
/* unable to provide this level of precision under ANSI-C, so just fall
back to intval time for this. */
Parrot_warn(NULL, PARROT_WARNINGS_PLATFORM_FLAG, "Parrot_floatval_time not
accurate");
return (FLOATVAL)Parrot_intval_time();
}
/*
** Parrot_sleep()
*/
void
Parrot_sleep(unsigned int seconds)
{
Parrot_warn(NULL, PARROT_WARNINGS_PLATFORM_FLAG, "Parrot_sleep not implemented");
return;
}
1.1 parrot/config/gen/platform/darwin/begin.c
Index: begin.c
===================================================================
#undef environ
#undef bool
1.1 parrot/config/gen/platform/darwin/dl.c
Index: dl.c
===================================================================
#import <mach-o/dyld.h>
#define PARROT_DLOPEN_FLAGS RTLD_LAZY
/* The dl* functions showed up in OS X 10.3, but they are just a
wrapper around the native dyld and NSModule API, so we'll use
the base API directly. This gives us wider compatibility, and
more control over the behavior. */
/*
** Parrot_dlopen()
*/
void *
Parrot_dlopen(const char *filename)
{
int dyld_result;
NSObjectFileImage ofile;
/* try bundle-style loading first */
dyld_result = NSCreateObjectFileImageFromFile(filename, &ofile);
if (NSObjectFileImageSuccess == dyld_result)
{
NSModule module = NSLinkModule(ofile, filename,
NSLINKMODULE_OPTION_RETURN_ON_ERROR
| NSLINKMODULE_OPTION_PRIVATE);
NSDestroyObjectFileImage(ofile);
return module; /* NSModule is typedef'd to void* */
}
else
{ /* bundle-style loading didn't work; try dylib-style before giving up */
const struct mach_header *header =
NSAddImage( filename,
NSADDIMAGE_OPTION_RETURN_ON_ERROR
| NSADDIMAGE_OPTION_WITH_SEARCHING);
if (header)
{
union {
const void * __c_ptr;
void * __ptr;
} __ptr_u;
#define const_cast(b) (__ptr_u.__c_ptr = (b), __ptr_u.__ptr)
return const_cast(header);
}
else
{ /* that didn't work either; go ahead and report the orignal error */
switch(dyld_result) {
case NSObjectFileImageFailure:
fprintf(stderr,
"open result was Failure (%i) for filename [%s]\n",
dyld_result, filename);
break;
case NSObjectFileImageInappropriateFile:
fprintf(stderr,
"open result was InappropriateFile (%i) for filename [%s]\n",
dyld_result, filename);
break;
case NSObjectFileImageArch:
fprintf(stderr,
"open result was Arch (%i) for filename [%s]\n",
dyld_result, filename);
break;
case NSObjectFileImageFormat:
fprintf(stderr,
"open result was Format (%i) for filename [%s]\n",
dyld_result, filename);
break;
case NSObjectFileImageAccess:
fprintf(stderr,
"open result was Access (%i) for filename [%s]\n",
dyld_result, filename);
break;
default:
fprintf(stderr,
"open result was unknown (%i) for filename [%s]\n",
dyld_result, filename);
break;
}
return NULL;
}
}
}
/*
** Parrot_dlerror()
*/
const char *
Parrot_dlerror(void)
{
return NULL;
}
/*
** Parrot_dlsym()
*/
void *
Parrot_dlsym(void *handle, const char *symbol)
{
NSSymbol found_symbol = NULL;
char *fixed_name = malloc(strlen(symbol) + 2);
/* Need to prepend underscore to symbol name to match the C convention
for symbol naming. */
strcpy(fixed_name, "_");
strcat(fixed_name, symbol);
if (!handle) /* must be looking up global symbol */
{
if (NSIsSymbolNameDefined(fixed_name))
{
found_symbol = NSLookupAndBindSymbol(fixed_name);
}
}
else if ( ((struct mach_header *)handle)->magic == MH_MAGIC
|| ((struct mach_header *)handle)->magic == MH_CIGAM )
{
if (NSIsSymbolNameDefinedInImage(handle, fixed_name))
{
found_symbol = NSLookupSymbolInImage(handle, fixed_name,
NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
| NSLOOKUPSYMBOLINIMAGE_OPTION_BIND);
}
}
else
{
found_symbol = NSLookupSymbolInModule(handle, fixed_name);
}
free(fixed_name);
if (!symbol)
{
return NULL;
}
else
{
return NSAddressOfSymbol(found_symbol);
}
}
/*
** Parrot_dlclose()
*/
int
Parrot_dlclose(void *handle)
{
if ( handle && !( ((struct mach_header *)handle)->magic == MH_MAGIC
|| ((struct mach_header *)handle)->magic == MH_CIGAM ) )
{
unsigned long options = NSUNLINKMODULE_OPTION_NONE;
#ifdef __ppc__
options = NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
#endif
return (int)NSUnLinkModule(handle, options);
}
else
{
return 0;
}
}
1.1 parrot/config/gen/platform/generic/dl.c
Index: dl.c
===================================================================
/*
** Dynlib stuff
*/
#ifdef PARROT_HAS_HEADER_DLFCN
# include <dlfcn.h>
#endif
#define PARROT_DLOPEN_FLAGS RTLD_LAZY
/*
** Parrot_dlopen()
*/
void *
Parrot_dlopen(const char *filename)
{
#ifdef PARROT_HAS_HEADER_DLFCN
return dlopen(filename, PARROT_DLOPEN_FLAGS);
#else
return 0;
#endif
}
/*
** Parrot_dlerror()
*/
const char *
Parrot_dlerror(void)
{
#ifdef PARROT_HAS_HEADER_DLFCN
return dlerror();
#else
return 0;
#endif
}
/*
** Parrot_dlsym()
*/
void *
Parrot_dlsym(void *handle, const char *symbol)
{
#ifdef PARROT_HAS_HEADER_DLFCN
return dlsym(handle, symbol);
#else
return 0;
#endif
}
/*
** Parrot_dlclose()
*/
int
Parrot_dlclose(void *handle)
{
#ifdef PARROT_HAS_HEADER_DLFCN
return dlclose(handle);
#else
return -1;
#endif
}
1.1 parrot/config/gen/platform/generic/dl.h
Index: dl.h
===================================================================
/*
* Dynamic loading stuff:
*/
#define PARROT_DLOPEN_FLAGS RTLD_LAZY
1.1 parrot/config/gen/platform/generic/env.c
Index: env.c
===================================================================
/*
* Environment manipulation stuff
*/
/*
** Parrot_setenv()
*/
void
Parrot_setenv(const char *name, const char *value)
{
#ifdef PARROT_HAS_SETENV
setenv(name, value, 1);
#else
int name_len = strlen(name);
int val_len = strlen(value);
char *envs = malloc(name_len + 1 + val_len + 1);
if (envs == NULL)
return;
/* Save a bit of time, by using the fact we already have the
lengths, avoiding strcat */
strcpy(envs, name);
strcpy(envs + name_len, "=");
strcpy(envs + name_len + 1, value);
putenv(envs);
/* The buffer is intentionally not freed! */
#endif
}
void
Parrot_unsetenv(const char *name)
{
#ifdef PARROT_HAS_UNSETENV
unsetenv(name);
#else
Parrot_setenv(name, "");
#endif
}
char *
Parrot_getenv(const char *name, int *free_it)
{
*free_it = 0;
return getenv(name);
}
1.1 parrot/config/gen/platform/generic/exec.c
Index: exec.c
===================================================================
/*
* system() stuff
*/
/*
* Spawn off a subprocess and wait for the damn thing to complete,
* returning the return value of the process
*
*/
#include <sys/types.h>
#include <sys/wait.h>
INTVAL Parrot_Run_OS_Command(Parrot_Interp interpreter, STRING *command) {
pid_t child;
child = fork();
/* Did we fail? */
if (-1 == child) {
internal_exception(NOSPAWN, "Can't spawn child process");
}
/* Are we the parent or child? */
if (child) {
/* parent */
int status;
pid_t returnstat;
returnstat = waitpid(child, &status, 0);
return status;
} else {
/* child. Be horribly profligate with memory, since we're
about to be something else */
int status;
status = execlp("sh", "sh", "-c", string_to_cstring(interpreter, command),
NULL);
/* if we get here, something's horribly wrong... */
if (status) {
exit(status);
}
}
}
1.1 parrot/config/gen/platform/generic/io.h
Index: io.h
===================================================================
/*
* I/O:
*/
#define DEFAULT_OPEN_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
#ifndef S_ISREG
# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
#endif
1.1 parrot/config/gen/platform/generic/itimer.c
Index: itimer.c
===================================================================
/*
* itimer stuff
*/
#ifdef PARROT_HAS_SETITIMER
/*
* Start a system timer with the passed value in milli seconds.
*
* The handle is that, what new_sys_timer_ms() returned.
* We could pass ITIMER_REAL in handle, but for now we ignore it
* as we are just having one timer.
*/
void
start_sys_timer_ms(void *handle, int ms)
{
struct itimerval its;
memset(&its, 0, sizeof(its));
if (ms) {
its.it_interval.tv_sec = its.it_value.tv_sec = ms/1000;
its.it_interval.tv_usec = its.it_value.tv_usec = 1000 *(ms%1000);
}
setitimer(ITIMER_REAL, &its, NULL);
}
/* Stop the given timer. */
void
stop_sys_timer_ms(void *handle)
{
start_sys_timer_ms(handle, 0);
}
/*
* Return the programmed timer interval or 0 if none for the
* given timer handle.
*/
int
get_sys_timer_ms(void *handle)
{
struct itimerval ots;
getitimer(ITIMER_REAL, &ots);
return ots.it_interval.tv_sec * 1000 + ots.it_interval.tv_usec/1000;
}
/*
* Create a new system timer with ~ms resolution.
* The returned handle is passed to the other timer functions.
*/
void *
new_sys_timer_ms()
{
return 0;
}
#else
#endif
1.1 parrot/config/gen/platform/generic/memalign.c
Index: memalign.c
===================================================================
/*
* memalign related stuff
*/
#if defined(PARROT_HAS_POSIX_MEMALIGN)
#include <stdlib.h>
void *
Parrot_memalign(size_t align, size_t size)
{
void *p;
int i = posix_memalign(&p, align, size);
return i == 0 ? p : NULL;
}
void *
Parrot_memalign_if_possible(size_t align, size_t size)
{
void *p;
int i = posix_memalign(&p, align, size);
return i == 0 ? p : NULL;
}
#elif defined(PARROT_HAS_MEMALIGN)
#if defined(PARROT_HAS_HEADER_MALLOC)
#include <malloc.h>
#else
#include <stdlib.h>
#endif
void *
Parrot_memalign(size_t align, size_t size)
{
return memalign(align, size);
}
void *
Parrot_memalign_if_possible(size_t align, size_t size)
{
return memalign(align, size);
}
#endif
void
Parrot_free_memalign(void *p)
{
free(p);
}
1.1 parrot/config/gen/platform/generic/memexec.c
Index: memexec.c
===================================================================
/*
* Memory protection stuff
*/
#ifdef PARROT_HAS_EXEC_PROTECT
/*
* Allocate executable memory
* Round up to page size because the whole page will be marked as
* executable
*/
void *
mem_alloc_executable(size_t size)
{
void *p;
size_t pagesize = sysconf(_SC_PAGESIZE);
size = (size + pagesize - 1) & ~(pagesize-1);
if (posix_memalign(&p, pagesize, size))
return NULL;
mprotect(p, size, PROT_READ|PROT_WRITE|PROT_EXEC);
return p;
}
void
mem_free_executable(void *p)
{
free(p);
}
/*
* Reallocate executable memory
* Round up to page size because the whole page will be marked as
* executable
* The intermediate temp is required because we don't know the old size
*/
void *
mem_realloc_executable(void* old, size_t newsize)
{
void *temp;
void *new;
size_t pagesize = sysconf(_SC_PAGESIZE);
size_t roundup;
temp = realloc(old, newsize);
if (temp == NULL)
return NULL;
free(old);
roundup = (newsize + pagesize - 1) & ~(pagesize-1);
if (posix_memalign(&new, pagesize, roundup))
new = NULL;
if (new) {
mprotect(new, roundup, PROT_READ|PROT_WRITE|PROT_EXEC);
memcpy(new, temp, newsize);
}
free(temp);
return new;
}
#endif
1.1 parrot/config/gen/platform/generic/signal.c
Index: signal.c
===================================================================
/*
* Signal handling stuff
*/
#ifdef PARROT_HAS_HEADER_SIGNAL
#include <signal.h>
/*
* for now use signal based functions
*/
Parrot_sighandler_t
Parrot_set_sighandler(int signum, Parrot_sighandler_t handler)
{
return signal(signum, handler);
}
#endif
1.1 parrot/config/gen/platform/generic/signal.h
Index: signal.h
===================================================================
/*
* Signal handling stuff
*/
#if defined(PARROT_HAS_HEADER_SIGNAL) && defined(PARROT_HAS_HEADER_SYSTYPES)
# include <signal.h>
# include <sys/types.h>
# define dumpcore() raise(SIGQUIT)
#endif
#ifdef PARROT_HAS_HEADER_SIGNAL
# undef Parrot_set_sighandler
# ifdef PARROT_HAS___SIGHANDLER_T
typedef __sighandler_t Parrot_sighandler_t;
# else
typedef void (*Parrot_sighandler_t) (int);
# endif
Parrot_sighandler_t Parrot_set_sighandler(int s, Parrot_sighandler_t f);
#endif
1.1 parrot/config/gen/platform/generic/threads.h
Index: threads.h
===================================================================
/*
* POSIX threading stuff
*/
#ifdef PARROT_HAS_HEADER_PTHREAD
# include "parrot/thr_pthread.h"
#endif
#ifdef PARROT_HAS_HEADER_UNISTD
# include <unistd.h>
# ifdef _POSIX_PRIORITY_SCHEDULING
# define YIELD sched_yield()
# endif
#endif
1.1 parrot/config/gen/platform/generic/time.c
Index: time.c
===================================================================
/*
** Time stuff
*/
#include <time.h>
#include <sys/time.h>
/*
** Parrot_intval_time()
*/
INTVAL
Parrot_intval_time(void)
{
return time(NULL);
}
/*
** Parrot_floatval_time()
*/
FLOATVAL
Parrot_floatval_time(void)
{
struct timeval t;
gettimeofday(&t, NULL);
return (FLOATVAL)t.tv_sec + ((FLOATVAL)t.tv_usec / 1000000.0);
}
/*
** Parrot_sleep()
*/
void
Parrot_sleep(unsigned int seconds)
{
sleep(seconds);
}
1.1 parrot/config/gen/platform/ia64/asm.s
Index: asm.s
===================================================================
.file "ia64.s"
.text
.psr abi64
.psr lsb
.lsb
.align 16
.global flush_reg_store
.proc flush_reg_store
flush_reg_store:
.body
flushrs
;;
mov r8=ar.bsp
br.ret.sptk.few rp
.endp flush_reg_store
1.1 parrot/config/gen/platform/openbsd/memexec.c
Index: memexec.c
===================================================================
#ifdef PARROT_HAS_EXEC_PROTECT
/*
* Allocate executable memory
* Round up to page size because the whole page will be marked as
* executable
* malloc() under OpenBSD page-aligns allocations >= page size
*/
void *
mem_alloc_executable(size_t size)
{
void *p;
size_t pagesize = sysconf(_SC_PAGESIZE);
size = (size + pagesize - 1) & ~(pagesize-1);
p = malloc(size);
if (p != NULL) {
mprotect(p, size, PROT_READ|PROT_WRITE|PROT_EXEC);
}
return p;
}
void
mem_free_executable(void *p)
{
free(p);
}
/*
* Reallocate executable memory
* Round up to page size because the whole page will be marked as
* executable
*/
void *
mem_realloc_executable(void* old, size_t newsize)
{
size_t pagesize = sysconf(_SC_PAGESIZE);
size_t roundup = (newsize + pagesize - 1) & ~(pagesize-1);
void *new = realloc(old, roundup);
if (new != NULL) {
mprotect(new, roundup, PROT_READ|PROT_WRITE|PROT_EXEC);
}
return new;
}
#endif
1.1 parrot/config/gen/platform/openbsd/misc.h
Index: misc.h
===================================================================
/*
** Miscellaneous:
*/
#include <i386/exec.h>
#ifdef NATIVE_EXEC_ELF
#define PARROT_OPENBSD_ELF
#endif
1.1 parrot/config/gen/platform/win32/begin.c
Index: begin.c
===================================================================
#include <windows.h>
1.1 parrot/config/gen/platform/win32/dl.c
Index: dl.c
===================================================================
/*
** Parrot_dlopen()
*/
void *
Parrot_dlopen(const char *filename)
{
return LoadLibrary(filename);
}
/*
** Parrot_dlerror()
*/
const char *
Parrot_dlerror(void)
{
return NULL;
}
/*
** Parrot_dlsym()
*/
void *
Parrot_dlsym(void *handle, const char *symbol)
{
return (void *)(ptrcast_t)GetProcAddress(handle, symbol);
}
/*
** Parrot_dlclose()
*/
int
Parrot_dlclose(void *handle)
{
return FreeLibrary(handle)? 0: 1;
}
1.1 parrot/config/gen/platform/win32/env.c
Index: env.c
===================================================================
/*
** Parrot_setenv()
*/
void
Parrot_setenv(const char *name, const char *value)
{
SetEnvironmentVariable(name, value);
}
char *
Parrot_getenv(const char *name, int *free_it)
{
DWORD size = GetEnvironmentVariable(name, NULL, 0);
char *buffer;
if (size == 0) {
*free_it = 0;
return NULL;
} else
*free_it = 1;
buffer = mem_sys_allocate(size);
GetEnvironmentVariable(name, buffer, size);
return buffer;
}
void
Parrot_unsetenv(const char *name)
{
SetEnvironmentVariable(name, NULL);
}
1.1 parrot/config/gen/platform/win32/exec.c
Index: exec.c
===================================================================
/*
* Spawn a subprocess
*
*/
INTVAL Parrot_Run_OS_Command(Parrot_Interp interpreter, STRING *command) {
Parrot_warn(NULL, PARROT_WARNINGS_PLATFORM_FLAG, "Parrot_Run_OS_Command not
implemented");
return 0;
}
1.1 parrot/config/gen/platform/win32/io.h
Index: io.h
===================================================================
#define DEFAULT_OPEN_MODE 0
typedef void* Parrot_WIN32_HANDLE;
typedef HUGEINTVAL Parrot_OFF_T;
#ifndef S_ISREG
# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
#endif
1.1 parrot/config/gen/platform/win32/misc.c
Index: misc.c
===================================================================
void
Parrot_platform_init_code(void)
{
SetErrorMode(SEM_NOGPFAULTERRORBOX);
}
1.1 parrot/config/gen/platform/win32/misc.h
Index: misc.h
===================================================================
#define PARROT_HAS_PLATFORM_INIT_CODE
void Parrot_platform_init_code(void);
#ifdef _MSC_VER
/* These disable certain Level 4 Warnings */
#pragma warning( disable: 4100 ) /* disables 'unreferenced formal parameter'
* warnings */
#pragma warning( disable: 4115 ) /* disables 'named type definition in
* parentheses' warnings triggered in VC98
* include files */
#pragma warning( disable: 4505 ) /* disables 'unreferenced local function has
* been removed' warnings in header files */
#endif /* defined(_MSC_VER) */
1.1 parrot/config/gen/platform/win32/time.c
Index: time.c
===================================================================
#include <time.h>
/*
** Parrot_intval_time()
*/
INTVAL
Parrot_intval_time(void)
{
return time(NULL);
}
/*
** Parrot_floatval_time()
*/
FLOATVAL
Parrot_floatval_time(void)
{
SYSTEMTIME sysTime;
FILETIME fileTime; /* 100ns == 1 */
LARGE_INTEGER i;
GetSystemTime(&sysTime);
SystemTimeToFileTime(&sysTime, &fileTime);
/* Documented as the way to get a 64 bit from a FILETIME. */
memcpy(&i, &fileTime, sizeof(LARGE_INTEGER));
return (FLOATVAL)i.QuadPart / 10000000.0; /*1e7 */
}
/*
** Parrot_sleep()
*/
void
Parrot_sleep(unsigned int seconds)
{
Sleep(seconds * 1000);
}
1.26 +1 -1 parrot/config/gen/makefiles.pl
Index: makefiles.pl
===================================================================
RCS file: /cvs/public/parrot/config/gen/makefiles.pl,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -w -r1.25 -r1.26
--- makefiles.pl 7 Jan 2004 13:35:52 -0000 1.25
+++ makefiles.pl 19 Feb 2004 17:06:25 -0000 1.26
@@ -10,7 +10,7 @@
sub runstep {
genfile('config/gen/makefiles/root.in', 'Makefile',
- commentType => '#', replace_slashes => 1);
+ commentType => '#', replace_slashes => 1, conditioned_lines => 1);
genfile('config/gen/makefiles/classes.in', 'classes/Makefile',
commentType => '#', replace_slashes => 1);
genfile('config/gen/makefiles/imcc.in', 'imcc/Makefile',
1.6 +119 -5 parrot/config/gen/platform.pl
Index: platform.pl
===================================================================
RCS file: /cvs/public/parrot/config/gen/platform.pl,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -r1.5 -r1.6
--- platform.pl 23 Oct 2003 19:54:07 -0000 1.5
+++ platform.pl 19 Feb 2004 17:06:25 -0000 1.6
@@ -13,10 +13,124 @@
$platform =~ s/^ms//;
$platform="ansi" if defined($_[0]);
- $platform="generic" unless -e "config/gen/platform/$platform.c";
+ $platform="generic" unless -d "config/gen/platform/$platform";
- copy_if_diff("config/gen/platform/$platform.c", "src/platform.c");
- copy_if_diff("config/gen/platform/$platform.h", "include/parrot/platform.h");
+ # headers are merged into platform.h
+ my @headers = qw/
+ io.h
+ misc.h
+ dl.h
+ signal.h
+ threads.h
+ /;
+
+ open PLATFORM_H, "> include/parrot/platform.h"
+ or die "Can't open include/parrot/platform.h: $!";
+
+ print PLATFORM_H <<HERE;
+#if !defined(PARROT_PLATFORM_H_GUARD)
+#define PARROT_PLATFORM_H_GUARD
+
+/*
+** platform.h [$platform version]
+**
+** DO NOT EDIT THIS FILE
+**
+** Generated by config/gen/platform.pl
+*/
+
+HERE
+
+ for ( @headers ) {
+ my $header_file = "config/gen/platform/generic/$_";
+ if ( -e "config/gen/platform/$platform/$_" ) {
+ $header_file = "config/gen/platform/$platform/$_";
+ }
+
+ if ( -e $header_file ) {
+ local $/ = undef;
+ open IN_H, "< $header_file" or die "Can't open $header_file: $!";
+ print PLATFORM_H <<HERE;
+/*
+** $header_file:
+*/
+
+HERE
+ print PLATFORM_H <IN_H>, "\n\n";
+ close IN_H;
+ }
+
+ # just fall through if file is missing; means neither this platform nor
+ # generic has anything to contribute for this feature. this might not
+ # be desirable if porters don't see the appropriate file in generic/ and
+ # shoehorn their function into the wrong file rather than creating the
+ # correct one from the above list in their $platform/ dir (e.g. misc.c).
+ }
+
+ print PLATFORM_H <<HERE;
+#endif
+HERE
+
+ close PLATFORM_H;
+
+ # implementation files are merged into platform.c
+ my @impls = qw/
+ begin.c
+ time.c
+ env.c
+ dl.c
+ memalign.c
+ signal.c
+ itimer.c
+ memexec.c
+ exec.c
+ misc.c
+ /;
+
+ open PLATFORM_C, "> src/platform.c" or die "Can't open src/platform.c: $!";
+
+ print PLATFORM_C <<HERE;
+/*
+** platform.c [$platform version]
+**
+** DO NOT EDIT THIS FILE
+**
+** Generated by config/gen/platform.pl
+*/
+
+#include "parrot/parrot.h"
+
+HERE
+
+ for ( @impls ) {
+ my $impl_file = "config/gen/platform/generic/$_";
+ if ( -e "config/gen/platform/$platform/$_" ) {
+ $impl_file = "config/gen/platform/$platform/$_";
+ }
+
+ if ( -e $impl_file ) {
+ local $/ = undef;
+ open IN_C, "< $impl_file" or die "Can't open $impl_file: $!";
+ print PLATFORM_C <<HERE;
+/*
+** $impl_file:
+*/
+
+HERE
+ print PLATFORM_C <IN_C>, "\n\n";
+ close IN_C;
+ }
+ }
+ close PLATFORM_C;
+
+ if ( Configure::Data->get( 'platform_asm' ) ) {
+ my $asm_file = "config/gen/platform/$platform/asm.s";
+ if ( -e $asm_file ) {
+ copy_if_diff( $asm_file, "src/platform_asm.s" );
+ }
+ }
+
+ # interface is the same for all platforms
copy_if_diff("config/gen/platform/platform_interface.h",
"include/parrot/platform_interface.h");
}
1.181 +6 -2 parrot/config/gen/makefiles/root.in
Index: root.in
===================================================================
RCS file: /cvs/public/parrot/config/gen/makefiles/root.in,v
retrieving revision 1.180
retrieving revision 1.181
diff -u -w -r1.180 -r1.181
--- root.in 18 Jan 2004 10:10:01 -0000 1.180
+++ root.in 19 Feb 2004 17:06:26 -0000 1.181
@@ -1,4 +1,4 @@
-# $Id: root.in,v 1.180 2004/01/18 10:10:01 leo Exp $
+# $Id: root.in,v 1.181 2004/02/19 17:06:26 leo Exp $
###############################################################################
#
@@ -110,11 +110,12 @@
lib/Parrot/Config.pm \
lib/Parrot/PMC.pm \
$(SRC)/platform.c \
+#CONDITIONED_LINE(platform_asm): $(SRC)/platform_asm.s \
$(SRC)/core_pmcs.c \
CFLAGS imcc/CFLAGS \
libparrot.def
-# most of these are generatey by config/gen/parrot_include.pl
+# most of these are generated by config/gen/parrot_include.pl
GEN_PASM_INCLUDES = \
runtime/parrot/include/signal.pasm \
@@ -251,6 +252,7 @@
$(SRC)/key$(O) \
$(SRC)/hash$(O) \
$(SRC)/core_pmcs$(O) \
+#CONDITIONED_LINE(platform_asm): $(SRC)/platform_asm$(O) \
$(SRC)/platform$(O) ${jit_o} \
$(SRC)/rx$(O) \
$(SRC)/rxstacks$(O) \
@@ -659,6 +661,8 @@
$(SRC)/platform$(O) : $(GENERAL_H_FILES)
+#CONDITIONED_LINE(platform_asm):$(SRC)/platform_asm$(O) : $(GENERAL_H_FILES)
+#CONDITIONED_LINE(platform_asm):
$(SRC)/core_pmcs$(O) : $(GENERAL_H_FILES)
$(SRC)/trace$(O) : $(GENERAL_H_FILES)
1.20 +3 -0 parrot/config/init/data.pl
Index: data.pl
===================================================================
RCS file: /cvs/public/parrot/config/init/data.pl,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -w -r1.19 -r1.20
--- data.pl 27 Nov 2003 18:23:45 -0000 1.19
+++ data.pl 19 Feb 2004 17:06:28 -0000 1.20
@@ -79,6 +79,9 @@
make_and => '&&',
make_c => '$(PERL) -e \'chdir shift @ARGV; system q{$(MAKE)}, @ARGV;
exit $$? >> 8;\'',
+ platform_asm => 0, # if platform has a .s file that needs to
be assembled
+ as => 'as', # assembler
+
cp => 'cp',
slash => '/',
1.20 +55 -49 parrot/lib/Parrot/Configure/Step.pm
Index: Step.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/Configure/Step.pm,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -w -r1.19 -r1.20
--- Step.pm 1 Dec 2003 09:30:16 -0000 1.19
+++ Step.pm 19 Feb 2004 17:06:30 -0000 1.20
@@ -120,7 +120,7 @@
} elsif ($options{commentType} eq '/*') {
$_ = " * $_\n" foreach (@comment);
$comment[0] =~ s!^ \*!/*!;
- $comment[-1] =~ s!$! */!;
+ $comment[-1] =~ s{$}{ */};
} else {
die "Unknown comment type '$options{commentType}'";
}
@@ -139,6 +139,12 @@
last;
}
+ if ($options{conditioned_lines} && /^#CONDITIONED_LINE\(([^)]+)\):(.*)/s) {
+ # lines of the form "CONDITIONED_LINE(var):..." are skipped if
+ # the "var" condition is false.
+ next unless Configure::Data->get($1);
+ $_ = $2;
+ }
if ($options{replace_slashes}) {
s{(/+)}{
my $len = length $1;
1.555 +30 -11 parrot/MANIFEST
Index: MANIFEST
===================================================================
RCS file: /cvs/public/parrot/MANIFEST,v
retrieving revision 1.554
retrieving revision 1.555
diff -u -w -r1.554 -r1.555
--- MANIFEST 17 Feb 2004 10:38:10 -0000 1.554
+++ MANIFEST 19 Feb 2004 17:06:32 -0000 1.555
@@ -138,18 +138,37 @@
config/gen/myconfig/myconfig.in []
config/gen/parrot_include.pl []
config/gen/platform.pl []
-config/gen/platform/ansi.c []
-config/gen/platform/ansi.h []
-config/gen/platform/darwin.c []
-config/gen/platform/darwin.h []
-config/gen/platform/generic.c []
-config/gen/platform/generic.h []
-config/gen/platform/ia64.s []
-config/gen/platform/openbsd.c []
-config/gen/platform/openbsd.h []
+config/gen/platform/aix/asm.s []
+config/gen/platform/ansi/dl.c []
+config/gen/platform/ansi/exec.c []
+config/gen/platform/ansi/io.h []
+config/gen/platform/ansi/time.c []
+config/gen/platform/darwin/begin.c []
+config/gen/platform/darwin/dl.c []
+config/gen/platform/generic/dl.c []
+config/gen/platform/generic/dl.h []
+config/gen/platform/generic/env.c []
+config/gen/platform/generic/exec.c []
+config/gen/platform/generic/io.h []
+config/gen/platform/generic/itimer.c []
+config/gen/platform/generic/memalign.c []
+config/gen/platform/generic/memexec.c []
+config/gen/platform/generic/signal.c []
+config/gen/platform/generic/signal.h []
+config/gen/platform/generic/threads.h []
+config/gen/platform/generic/time.c []
+config/gen/platform/ia64/asm.s []
+config/gen/platform/openbsd/memexec.c []
+config/gen/platform/openbsd/misc.h []
config/gen/platform/platform_interface.h []
-config/gen/platform/win32.c []
-config/gen/platform/win32.h []
+config/gen/platform/win32/begin.c []
+config/gen/platform/win32/dl.c []
+config/gen/platform/win32/env.c []
+config/gen/platform/win32/exec.c []
+config/gen/platform/win32/io.h []
+config/gen/platform/win32/misc.c []
+config/gen/platform/win32/misc.h []
+config/gen/platform/win32/time.c []
config/init/data.pl []
config/init/headers.pl []
config/init/hints.pl []