Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions GNUmakefile.os4
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ endif

CFLAGS := $(WARNINGS) $(OPTIMIZE) $(OPTIONS) $(INCLUDES) -D__USE_INLINE__
CFLAGS_N := $(WARNINGS) $(OPTIMIZE) $(OPTIONS) $(INCLUDES)
AFLAGS := -Wa,-mregnames -mstrict-align
AFLAGS := -Wa,-mregnames

ifdef SPE
CC := ppc-amigaos-gcc-6.4.0
Expand All @@ -146,7 +146,8 @@ ifdef SPE
endif

ifdef PROFILE
CFLAGS += -pg
CFLAGS += -pg -falign-functions=32 -fno-omit-frame-pointer
AFLAGS += -fno-omit-frame-pointer
DLIBS += -Lbuild/lib -lprofile
endif

Expand Down Expand Up @@ -196,6 +197,7 @@ include libpthread.gmk
include libcrypt.gmk
include librt.gmk
include shared.gmk
# Leave profile as latest one
include libprofile.gmk

prepare:
Expand Down
11 changes: 11 additions & 0 deletions installer/Install
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(complete 0)
(set @default-dest "LIBS:")
(set @default-sdk-dest "SDK:clib4")
(set @default-env-dest "ENVARC:")
(set @default-dest
(askdir
(prompt "Where would you like to install clib4.library?\nA new Drawer will be created if necessary")
Expand All @@ -19,6 +20,16 @@
(dest @default-dest)
(confirm)
)
(complete 45)
(copyfiles
(prompt "Do you want to install Terminfo files?")
(help @copyfiles-help)
(source "misc")
(choices "terminfo")
(dest @default-env-dest)
(confirm)
)

(complete 60)
(copyfiles
(prompt "Do you want to install development files?")
Expand Down
1 change: 1 addition & 0 deletions libc.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ C_STDLIB := \
stdlib/atoll.o \
stdlib/bsearch.o \
stdlib/calloc.o \
stdlib/canonicalize_file_name.o \
stdlib/div.o \
stdlib/divsi3.o \
stdlib/dladdr.o \
Expand Down
33 changes: 33 additions & 0 deletions library/cpu/4xx/ppc4xx.inc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,39 @@
#define r30 %r30
#define r31 %r31

#define fp0 %f0
#define fp1 %f1
#define fp2 %f2
#define fp3 %f3
#define fp4 %f4
#define fp5 %f5
#define fp6 %f6
#define fp7 %f7
#define fp8 %f8
#define fp9 %f9
#define fp10 %f10
#define fp11 %f11
#define fp12 %f12
#define fp13 %f13
#define fp14 %f14
#define fp15 %f15
#define fp16 %f16
#define fp17 %f17
#define fp18 %f18
#define fp19 %f19
#define fp20 %f20
#define fp21 %f21
#define fp22 %f22
#define fp23 %f23
#define fp24 %f24
#define fp25 %f25
#define fp26 %f26
#define fp27 %f27
#define fp28 %f28
#define fp29 %f29
#define fp30 %f30
#define fp31 %f31

#define cr0 %cr0
#define cr1 %cr1
#define cr2 %cr2
Expand Down
2 changes: 2 additions & 0 deletions library/include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ extern void srand48(long);
extern unsigned short *seed48(unsigned short subi[3]);
extern void lcong48(unsigned short subi[7]);

extern char *canonicalize_file_name(const char *name);

#endif

extern int system(const char *command);
Expand Down
2 changes: 1 addition & 1 deletion library/profile/_mcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ __mcount(uint32 frompc, uint32 selfpc) {
*/
frompc -= p->lowpc;
selfpc -= p->lowpc;
if (frompc > p->textsize)
if (frompc > p->text_start + p->textsize)
goto done;

/* The following test used to be
Expand Down
4 changes: 3 additions & 1 deletion library/profile/gmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ write_call_graph(int fd) {
nfilled = 0;
from_len = _gmonparam.fromssize / sizeof(*_gmonparam.froms);
for (from_index = 0; from_index < from_len; ++from_index) {
if (_gmonparam.froms[from_index] == 0)
if (_gmonparam.froms[from_index] == 0) {
continue;
}

frompc = _gmonparam.text_start;
frompc += from_index * _gmonparam.hashfraction * sizeof(*_gmonparam.froms);
Expand Down Expand Up @@ -309,6 +310,7 @@ void moncleanup(void) {
sizeof(ghdr) != sizeof(struct gmon_hdr) ||
(offsetof(struct real_gmon_hdr, cookie) != offsetof(struct gmon_hdr, cookie)) ||
(offsetof(struct real_gmon_hdr, version) != offsetof(struct gmon_hdr, version))) {
close(fd);
goto out;
}

Expand Down
2 changes: 1 addition & 1 deletion library/profile/mcount.S
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
/ $Id: profile_mcount.S,v 1.1 2023-10-20 12:04:26 clib4devs Exp $
/*
*/

/* We do profiling as described in the SYSV ELF ABI, except that glibc
_mcount manages its own counters. The caller has put the address the
Expand Down
2 changes: 2 additions & 0 deletions library/shared_library/clib4_vectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -1194,5 +1194,7 @@ static void *clib4Vectors[] = {
(void *) (roundevenf), /* 4452 */
(void *) (roundevenl), /* 4456 */

(void *) (canonicalize_file_name), /* 4460 */

(void *)-1
};
2 changes: 2 additions & 0 deletions library/shared_library/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,8 @@ struct Clib4IFace {
double (* roundeven) (double x); /* 4448 */
float (* roundevenf) (float x); /* 4452 */
long double (* roundevenl) (long double x); /* 4456 */

char * (* canonicalize_file_name) (const char *name); /* 4460 */
};

#ifdef __PIC__
Expand Down
2 changes: 2 additions & 0 deletions library/shared_library/stubs_canonicalize_file_name.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "stubs_common.h"
Clib4Call(canonicalize_file_name, 4460);
12 changes: 12 additions & 0 deletions library/stdlib/canonicalize_file_name.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* $Id: stdlib_canonicalize_file_name.c,v 1.0 2025-06-27 12:59:00 clib4devs Exp $
*/

#ifndef _STDLIB_HEADERS_H
#include "stdlib_headers.h"
#endif /* _STDLIB_HEADERS_H */

char *
canonicalize_file_name(const char *name) {
return realpath(name, NULL);
}
30 changes: 25 additions & 5 deletions library/unistd/realpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,27 @@ realpath(const char *path_name, char *buffer) {

__check_abort_f(__clib4);

if (path_name == NULL || buffer == NULL) {
SHOWSTRING("invalid parameters");
/*
If buffer is specified as NULL, then realpath() uses
malloc to allocate a buffer of up to PATH_MAX bytes to hold the
resolved pathname, and returns a pointer to this buffer. The
caller should deallocate this buffer using free.
*/
if (buffer == NULL) {
buffer = __malloc_r(__clib4, PATH_MAX);
}

if (path_name == NULL) {
SHOWSTRING("Invalid parameters");

__set_errno(EFAULT);
__set_errno(EINVAL);
goto out;
}

if (buffer == NULL) {
SHOWSTRING("Out of memory");

__set_errno(ENOMEM);
goto out;
}

Expand Down Expand Up @@ -78,8 +95,11 @@ realpath(const char *path_name, char *buffer) {

out:

FreeDeviceProc(dvp);
UnLock(lock);
if (dvp != NULL)
FreeDeviceProc(dvp);

if (lock != BZERO)
UnLock(lock);

RETURN(result);
return (result);
Expand Down
40 changes: 40 additions & 0 deletions test_programs/setjmp/bugsetjmp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>
#include <setjmp.h>
#include <alloca.h>

static void
sub5 (jmp_buf buf)
{
longjmp (buf, 1);
}

static void
test (int x)
{
jmp_buf buf;
char *volatile foo;
int arr[100];

arr[77] = x;
if (setjmp (buf))
{
printf ("made it ok; %d\n", arr[77]);
return;
}

foo = (char *) alloca (128);
(void) foo;
sub5 (buf);
}

int
main (void)
{
int i;

for (i = 123; i < 345; ++i)
test (i);

return 0;
}

98 changes: 98 additions & 0 deletions test_programs/setjmp/test_setjmp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* Copyright (C) 2004 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, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */ ;
/* Test case for Bugzilla # 269 */
#include <stdio.h>
#include <setjmp.h>
#include <stdlib.h>
#include <proto/dos.h>

jmp_buf buf1;
jmp_buf buf2;
int *p;
int n_x = 6;

static int g_counter = 0;

int
f(void) {
static int counter = 0;
static int way_point1 = 3;
static int way_point2 = 2;
int lose = 0;
int ret = setjmp(buf1);
if (ret != 101) {
IDOS->Printf("1) setjmp return %d\n", ret);
int a[n_x]; /* reallocate stack space */
g_counter++;
p = &a[0];
if (g_counter < 5) {
IDOS->Printf("1) Calling longjmp(buf1, 2)\n");
longjmp (buf1, 2);
}
else if (g_counter == 5) {
IDOS->Printf("1) Calling longjmp(buf1, 101)\n");
longjmp (buf1, 101);
}
else {
IDOS->Printf("1) Calling _setjmp(buf2)\n");
_setjmp (buf2);
IDOS->Printf("1) Calling _longjmp(buf1, 101)\n");
_longjmp (buf1, 101);
}
}
way_point1--;
if (counter == 0) {
counter++;
{
int a[n_x]; /* reallocate stack space */
g_counter++;
p = &a[0];
if (g_counter < 5) {
IDOS->Printf("2) Calling longjmp(buf1, 2)\n");
longjmp (buf1, 2);
}
else if (g_counter == 5) {
IDOS->Printf("2) Calling longjmp(buf1, 101)\n");
longjmp (buf1, 101);
}
else {
IDOS->Printf("2) Calling _setjmp(buf2)\n");
_setjmp (buf2);
IDOS->Printf("2) Calling longjmp(buf1, 101)\n");
_longjmp (buf1, 101);
}
}
}
way_point2--;
if (counter == 1) {
counter++;
IDOS->Printf("3) Calling longjmp(buf2, 2)\n");
longjmp(buf2, 2);
}
lose = !(way_point1 == 0 && way_point2 == 0 && g_counter == 6 && counter == 2);
IDOS->Printf("lose = %ld\n", lose);
return lose;
}

int
main(void) {
int lose;
lose = f();
if (lose)
puts ("Test FAILED!");
else
puts ("Test succeeded!");
return lose ? EXIT_FAILURE : EXIT_SUCCESS;
}
24 changes: 24 additions & 0 deletions test_programs/stdlib/canonicalize_file_name.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#define _GNU_SOURCE // Enable GNU extensions (including canonicalize_file_name)
#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <path>\n", argv[0]);
return 1;
}

char *canon_path = canonicalize_file_name(argv[1]);

if (canon_path == NULL) {
perror("Error canonicalizing path");
return 1;
}

printf("Original path: %s\n", argv[1]);
printf("Canonical path: %s\n", canon_path);

free(canon_path); // Must free allocated memory
return 0;
}