Skip to content

Commit 6d13819

Browse files
JohnoKingMcDutchie
authored andcommitted
64-bit transition part 13: the rest of ksh93 (#973)
This is the thirteenth of the thickfold patch series, which enables ksh93 to operate within a 64-bit address space. This patch applies the rest of the changes to ksh93 necessary for 64-bit memory allocation, along with the usual warning fixes. Notable changes: - parse.c: Fixed a build error when using SHOPT_KIA (re: 63366e3). - sh_pipe(): Fix broken SOCK_CLOEXEC check. The !SOCK_CLOEXEC check in the #if directive apparently didn't work[*], as strace was showing unnecessary fcntl calls were still getting compiled in. Check for SOCK_CLOEXEC==0 in a non-preprocessor if statement and let the compiler optimize it away, which actually works correctly. - Also removed some unnecessary ptrdiff_t casts. - Add a (Linux-specific) regression test for allocating 5GB (we check if plenty of RAM is available via /proc/meminfo). - locale.sh: Disable a test that requires SHOPT_MULTIBYTE to work correctly. Change in the number of warnings on Linux when compiling with clang using -Wsign-compare -Wshorten-64-to-32 -Wsign-conversion -Wimplicit-int-conversion: 352 => 37 (progression from part 12 => part 13) The nvflags warnings that remain will be addressed in a separate follow-up patch of their own (which doesn't affect memory allocation). Resolves: #592 [*] (Martijn adds) On Linux, the SOCK_* macros defined in /usr/include/bits/socket_type.h are bizarrely defined as their own names (which refer to members of an enum type), which kills the #if logic in the preprocessor. This could be an issue with other macros on other systems too, so it's something to look out for in future.
1 parent 4788cdc commit 6d13819

35 files changed

Lines changed: 444 additions & 377 deletions

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ This documents significant changes in the 1.0 branch of ksh 93u+m.
22
For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
33
Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
44

5+
2026-04-14:
6+
7+
- Ksh is now capable of allocating memory within a 64-bit address space. This
8+
means variables can now contain multi-gigabyte values without ksh crashing.
9+
510
2026-04-13:
611

712
- Fixed a potential crash that could occur if a shell discipline function

src/cmd/ksh93/builtins.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ int optget(char *\fIargv\fP[], const char *\fIoptstring\fP)
488488
.EX
489489
\fIyourfunction\fP()
490490
{
491-
char *savebase;
492-
int saveoffset;
491+
char *savebase;
492+
ptrdiff_t saveoffset;
493493
if(saveoffset=stktell(stkstd))
494494
savebase = stkfreeze(stkstd,0);
495495
\fR...\fP

src/cmd/ksh93/features/externs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ tst note{ determining default number of extra bytes per argument for arguments l
5454

5555
int main(int argc,char *argv[])
5656
{
57-
int extra_bytes = 0, envlen, argmax, i;
57+
size_t extra_bytes = 0, envlen;
58+
int argmax, i;
5859
pid_t childpid;
5960
Sfio_t *notebuf;
6061
char *note;
@@ -69,7 +70,7 @@ tst note{ determining default number of extra bytes per argument for arguments l
6970
for(i=0; environ[i]; i++)
7071
envlen += strlen(environ[i]) + 1 + extra_bytes;
7172
envlen += 1 + extra_bytes; /* final null element */
72-
argmax = (int)astconf_long(CONF_ARG_MAX) - envlen;
73+
argmax = (int)astconf_long(CONF_ARG_MAX) - (int)envlen;
7374
if (argmax < 2048)
7475
{
7576
error(ERROR_ERROR|2, "argmax too small");
@@ -82,7 +83,7 @@ tst note{ determining default number of extra bytes per argument for arguments l
8283
int bytec;
8384

8485
error_info.id="_arg_extrabytes test (child)";
85-
argv = stkalloc(stkstd, (argmax / 2 + 1) * sizeof(char*));
86+
argv = stkalloc(stkstd, (size_t)(argmax / 2 + 1) * sizeof(char*));
8687
argc = bytec = 0;
8788
while(bytec < argmax)
8889
{
@@ -137,13 +138,13 @@ tst note{ determining default number of extra bytes per argument for arguments l
137138
}
138139
/* show note in iffe output via inherited FD 9 */
139140
notebuf = sfstropen();
140-
sfprintf(notebuf," %d ...",extra_bytes);
141+
sfprintf(notebuf," %zu ...",extra_bytes);
141142
note = sfstruse(notebuf);
142143
write(9,note,strlen(note));
143144
sfclose(notebuf);
144145
/* add #define to header via stdout */
145146
sfprintf(sfstdout,
146-
"#define _arg_extrabytes\t%d\t/* extra bytes per argument for arguments list */\n",
147+
"#define _arg_extrabytes\t%zu\t/* extra bytes per argument for arguments list */\n",
147148
extra_bytes);
148149
return 0;
149150
}

src/cmd/ksh93/features/fchdir

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ tst openat_enotdir note{ does openat set ENOTDIR when it fails because the file
4646
int main(void)
4747
{
4848
char filename[64];
49-
int n, saverrno;
50-
pid_t child;
51-
sprintf(filename,".file.%u",(unsigned int)getpid());
49+
int saverrno;
50+
sprintf(filename,".file.%ju",(uintmax_t)getpid());
5251
open(filename,O_RDWR|O_CREAT); /* let the OS close the fd after completion */
5352
openat(AT_FDCWD, filename, O_DIRECTORY|O_NONBLOCK|O_cloexec|O_SEARCH);
5453
saverrno = errno;

src/cmd/ksh93/features/poll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ tst pipe_socketpair note{ use socketpair() for peekable pipe() }end execute{
1919
#endif
2020
static void handler(int sig)
2121
{
22+
NOT_USED(sig);
2223
_exit(0);
2324
}
2425
int main(void)
@@ -72,7 +73,6 @@ tst socketpair_devfd note{ /dev/fd/N handles socketpair() }end execute{
7273
#include <sys/socket.h>
7374
int main(void)
7475
{
75-
int devfd;
7676
int n;
7777
int sfd[2];
7878
ast_close(0);

src/cmd/ksh93/include/argnod.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct ionod
3131
struct ionod *iolst;
3232
char *iodelim;
3333
off_t iooffset;
34-
long iosize;
34+
Sfoff_t iosize;
3535
char *iovname;
3636
};
3737

src/cmd/ksh93/include/io.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
/* used for output of shell errors */
3737
#define ERRIO 2
3838

39-
#define IOREAD 001
40-
#define IOWRITE 002
41-
#define IODUP 004
42-
#define IOSEEK 010
43-
#define IONOSEEK 020
44-
#define IOTTY 040
45-
#define IOCLEX 0100
39+
#define IOREAD 001U
40+
#define IOWRITE 002U
41+
#define IODUP 004U
42+
#define IOSEEK 010U
43+
#define IONOSEEK 020U
44+
#define IOTTY 040U
45+
#define IOCLEX 0100U
4646
#define IOCLOSE (IOSEEK|IONOSEEK)
4747

4848
#define IOSUBSHELL 0x8000 /* must be larger than any file descriptor */
@@ -74,7 +74,7 @@
7474
#define sh_editor_active() 0
7575
#endif
7676

77-
extern int sh_iocheckfd(int);
77+
extern uint8_t sh_iocheckfd(int);
7878
extern void sh_ioinit(void);
7979
extern int sh_iomovefd(int,int);
8080
extern int sh_iorenumber(int,int);

src/cmd/ksh93/include/jobs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct jobs
6363
{
6464
struct process *pwlist; /* head of process list */
6565
int *exitval; /* pipe exit values */
66+
unsigned char *freejobs; /* free jobs numbers */
6667
pid_t curpgid; /* current process GID */
6768
pid_t parent; /* set by fork() */
6869
pid_t mypid; /* process ID of shell */
@@ -75,13 +76,12 @@ struct jobs
7576
#if SHOPT_BGX
7677
int numbjob; /* number of background jobs */
7778
#endif /* SHOPT_BGX */
78-
short fd; /* tty descriptor number */
79-
int suspend; /* suspend character */
79+
int fd; /* tty descriptor number */
80+
cc_t suspend; /* suspend character */
8081
char jobcontrol; /* turned on for interactive shell with control of terminal */
8182
char waitsafe; /* wait will not block */
8283
char waitall; /* wait for all jobs in pipe */
8384
char toclear; /* job table needs clearing */
84-
unsigned char *freejobs; /* free jobs numbers */
8585
};
8686

8787
/* flags for joblist */

src/cmd/ksh93/include/path.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
# endif
3434
#endif /* !SHOPT_SPAWN */
3535

36-
#define PATH_PATH 0001
37-
#define PATH_FPATH 0002
38-
#define PATH_CDPATH 0004
39-
#define PATH_BFPATH 0010
40-
#define PATH_SKIP 0020
41-
#define PATH_STD_DIR 0100 /* directory is on $(getconf PATH) */
36+
#define PATH_PATH 0001U
37+
#define PATH_FPATH 0002U
38+
#define PATH_CDPATH 0004U
39+
#define PATH_BFPATH 0010U
40+
#define PATH_SKIP 0020U
41+
#define PATH_STD_DIR 0100U /* directory is on $(getconf PATH) */
4242

4343
#define PATH_OFFSET 2 /* path offset for path_join */
4444
#define MAXDEPTH 1024 /* maximum shell function recursion depth */
@@ -57,8 +57,8 @@ typedef struct pathcomp
5757
char *lib;
5858
char *bbuf;
5959
char *blib;
60-
unsigned short len;
61-
unsigned short flags;
60+
size_t len;
61+
uint16_t flags;
6262
} Pathcomp_t;
6363

6464
#ifndef _ARGNOD_H
@@ -69,15 +69,15 @@ typedef struct pathcomp
6969
extern void path_newdir(Pathcomp_t*);
7070
extern Pathcomp_t *path_dirfind(Pathcomp_t*,const char*,int);
7171
extern Pathcomp_t *path_unsetfpath(void);
72-
extern Pathcomp_t *path_addpath(Pathcomp_t*,const char*,int);
72+
extern Pathcomp_t *path_addpath(Pathcomp_t*,const char*,uint16_t);
7373
extern Pathcomp_t *path_dup(Pathcomp_t*);
7474
extern void path_delete(Pathcomp_t*);
7575
extern void path_settrackedalias(const char*,Pathcomp_t*);
7676
extern Namval_t *path_gettrackedalias(const char*);
7777
extern Pathcomp_t *path_absolute(const char*, Pathcomp_t*, int);
7878
extern char *path_basename(const char*);
7979
extern char *path_fullname(const char*);
80-
extern int path_expand(const char*, struct argnod**, int);
80+
extern size_t path_expand(const char*, struct argnod**, int);
8181
extern noreturn void path_exec(const char*,char*[],struct argnod*);
8282
extern pid_t path_spawn(const char*,char*[],char*[],Pathcomp_t*,int);
8383
extern int path_open(const char*,Pathcomp_t*);
@@ -86,9 +86,9 @@ extern char *path_pwd(void);
8686
extern Pathcomp_t *path_nextcomp(Pathcomp_t*,const char*,Pathcomp_t*);
8787
extern int path_search(const char*,Pathcomp_t**,int);
8888
extern char *path_relative(const char*);
89-
extern int path_complete(const char*, const char*,struct argnod**);
89+
extern size_t path_complete(const char*, const char*,struct argnod**);
9090
#if SHOPT_BRACEPAT
91-
extern int path_generate(struct argnod*,struct argnod**, int);
91+
extern ssize_t path_generate(struct argnod*,struct argnod**, int);
9292
#endif /* SHOPT_BRACEPAT */
9393

9494
#if SHOPT_DYNAMIC

src/cmd/ksh93/include/shell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ struct Shell_s
364364
Shbltin_t bltindata;
365365
ptrdiff_t offsets[10];
366366
Sfio_t **sftable;
367-
unsigned char *fdstatus;
367+
uint8_t *fdstatus;
368368
char *pwd;
369369
#if _lib_openat
370370
int pwdfd; /* file descriptor for pwd */

0 commit comments

Comments
 (0)