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
16 changes: 15 additions & 1 deletion library/crtbegin.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <proto/dos.h>
#include <proto/utility.h>

#include <workbench/startup.h>

#include "shared_library/interface.h"

#include "c.lib_rev.h"
Expand Down Expand Up @@ -112,12 +114,24 @@ clib4_start(char *args, const int32 arglen, struct Library *sysbase) {
int rc = -1;
void *old_r13 = r13;

struct Process *me;
struct WBStartup *sms = NULL;

r13 = &_SDA_BASE_;
SysBase = sysbase;

iexec = (struct ExecIFace *) ((struct ExecBase *) SysBase)->MainInterface;
iexec->Obtain();

/* Pick up the Workbench startup message, if available. */
me = (struct Process *) iexec->FindTask(NULL);
if (!me->pr_CLI) {
struct MsgPort *mp = &me->pr_MsgPort;
iexec->WaitPort(mp);
sms = (struct WBStartup *) iexec->GetMsg(mp);
iexec->DebugPrintF("<crtbegin> : NumArgs == %ld\n", sms->sm_NumArgs);
}

IExec = iexec;
idos = (struct DOSIFace *) OpenLibraryInterface(iexec, "dos.library", MIN_OS_VERSION);
if (idos) {
Expand All @@ -131,7 +145,7 @@ clib4_start(char *args, const int32 arglen, struct Library *sysbase) {
if (clib4base->lib_Version >= VERSION && clib4base->lib_Revision >= REVISION) {
IClib4 = iclib4;

rc = iclib4->library_start(args, arglen, main, __CTOR_LIST__, __DTOR_LIST__);
rc = iclib4->library_start(args, arglen, main, __CTOR_LIST__, __DTOR_LIST__, sms);
}
else {
idos->Printf("This program requires clib4.library version %ld.%ld\n", VERSION, REVISION);
Expand Down
5 changes: 3 additions & 2 deletions library/shared_library/clib4.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,10 @@ library_start(char *argstr,
int arglen,
int (*start_main)(int, char **),
void (*__EXT_CTOR_LIST__[])(void),
void (*__EXT_DTOR_LIST__[])(void)) {
void (*__EXT_DTOR_LIST__[])(void),
struct WBStartup *sms) {

int result = _main(argstr, arglen, start_main, __EXT_CTOR_LIST__, __EXT_DTOR_LIST__);
int result = _main(argstr, arglen, start_main, __EXT_CTOR_LIST__, __EXT_DTOR_LIST__, sms);

return result;
}
Expand Down
6 changes: 4 additions & 2 deletions library/shared_library/clib4.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ int library_start(char *argstr,
int arglen,
int (*start_main)(int, char **),
void (*__EXT_CTOR_LIST__[])(void),
void (*__EXT_DTOR_LIST__[])(void));
void (*__EXT_DTOR_LIST__[])(void),
struct WBStartup *sms);

int32 _start(STRPTR args,
int32 arglen,
Expand All @@ -103,7 +104,8 @@ extern int _main(char *argstr,
int arglen,
int (*start_main)(int, char **),
void (*__EXT_CTOR_LIST__[])(void),
void (*__EXT_DTOR_LIST__[])(void));
void (*__EXT_DTOR_LIST__[])(void),
struct WBStartup *sms);


#endif
2 changes: 1 addition & 1 deletion library/shared_library/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct Clib4IFace {
void APICALL (*Expunge)(struct Clib4IFace *Self); //68
struct Clib4IFace *APICALL (*Clone)(struct Clib4IFace *Self); //72
/* internal */
int (* library_start)(char *argstr, int arglen, int (* start_main)(int, char **), void (*__CTOR_LIST__[])(void), void (*__DTOR_LIST__[])(void)); //76
int (* library_start)(char *argstr, int arglen, int (* start_main)(int, char **), void (*__CTOR_LIST__[])(void), void (*__DTOR_LIST__[])(void), struct WBStartup *sms); //76
struct _clib4 * (* __getClib4)(void); //80
void (* internal1)(void); //84
void (* __translate_amiga_to_unix_path_name)(void); //88
Expand Down
14 changes: 4 additions & 10 deletions library/stdlib/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,16 @@ _main(
int arglen,
int (*start_main)(int, char **),
void (*__EXT_CTOR_LIST__[])(void),
void (*__EXT_DTOR_LIST__[])(void)) {
struct WBStartup *sms = NULL;
void (*__EXT_DTOR_LIST__[])(void),
struct WBStartup *sms
) {
struct Process *me;
APTR oldClib4Data;
int rc = RETURN_FAIL;
struct _clib4 *__clib4 = __CLIB4;

/* Pick up the Workbench startup message, if available. */
me = (struct Process *) FindTask(NULL);
if (!me->pr_CLI) {
struct MsgPort *mp = &me->pr_MsgPort;
WaitPort(mp);
sms = (struct WBStartup *) GetMsg(mp);
}

/* Store old Clib4Data */
me = (struct Process *) FindTask(NULL);
oldClib4Data = (APTR) me->pr_UID;

__clib4->__WBenchMsg = sms;
Expand Down
3 changes: 2 additions & 1 deletion library/stdlib/stdlib_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ extern int _main(char *argstr,
int arglen,
int (*start_main)(int, char **),
void (*__EXT_CTOR_LIST__[])(void),
void (*__EXT_DTOR_LIST__[])(void));
void (*__EXT_DTOR_LIST__[])(void),
struct WBStartup *sms);

#ifndef _STDLIB_PROTOS_H
#include "stdlib_protos.h"
Expand Down
15 changes: 9 additions & 6 deletions library/wmem/wmem_allocator_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ typedef struct _wmem_block_chunk_t {

#define WMEM_CHUNK_HEADER_SIZE WMEM_ALIGN_SIZE(sizeof(wmem_block_chunk_t))

#define WMEM_BLOCK_MAX_ALLOC_SIZE (WMEM_BLOCK_SIZE - \
(WMEM_BLOCK_HEADER_SIZE + WMEM_CHUNK_HEADER_SIZE))
// #define WMEM_BLOCK_MAX_ALLOC_SIZE (WMEM_BLOCK_SIZE - \
// (WMEM_BLOCK_HEADER_SIZE + WMEM_CHUNK_HEADER_SIZE))

/* other handy chunk macros */
#define WMEM_DATA_TO_PRE(DATA) ((wmem_block_pre_t *)((uintptr_t)(DATA) - sizeof(wmem_block_pre_t)))
Expand Down Expand Up @@ -660,7 +660,7 @@ wmem_block_split_free_chunk(wmem_block_allocator_t *allocator,
* recycler. */
static void
wmem_block_split_used_chunk(wmem_block_allocator_t *allocator,
wmem_block_chunk_t *chunk,
void *data,
const size_t size, const size_t alignment) {
wmem_block_chunk_t *extra;
size_t aligned_size, available;
Expand All @@ -670,9 +670,12 @@ wmem_block_split_used_chunk(wmem_block_allocator_t *allocator,
D(("[split_used :] chunk : 0x%lx\n", chunk));
#endif

aligned_size = WMEM_ALIGN_SIZE(size) + WMEM_CHUNK_HEADER_SIZE;
aligned_size = size + ((uintptr_t)data - (uintptr_t)WMEM_DATA_TO_CHUNK(data));
aligned_size = WMEM_ALIGN_SIZE(aligned_size);

wmem_block_chunk_t *chunk = WMEM_DATA_TO_CHUNK(data);

if (aligned_size > WMEM_CHUNK_DATA_LEN(chunk)) {
if (aligned_size + sizeof(wmem_block_chunk_t) > chunk->len) {
/* in this case we don't have enough space to really split it, so
* it's basically a no-op */
return;
Expand Down Expand Up @@ -990,7 +993,7 @@ wmem_block_realloc(void *private_data, void *ptr, const size_t size, int32_t ali
}
} else if (new_ptr_supremum < chunk_supremum) {
/* shrink */
wmem_block_split_used_chunk(allocator, chunk, size, alignment);
wmem_block_split_used_chunk(allocator, ptr, size, alignment);

/* Now cycle the recycler */
wmem_block_cycle_recycler(allocator);
Expand Down
2 changes: 1 addition & 1 deletion library/wmem/wmem_allocator_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ wmem_simple_free_all(void *private_data) {
wmem_free(NULL, allocator->ptrs[i]);
}
allocator->count = 0;
allocator->size = 0;
// allocator->size = 0;

#if MEMORY_DEBUG
dump_ptrs("simple_free_all", private_data);
Expand Down
6 changes: 5 additions & 1 deletion library/wmem/wmem_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ power_of_two(size_t alignment) {
}

uintptr_t align_address(uintptr_t address, size_t alignment) {
if(alignment == 0) return address;
return (address + alignment - 1) & ~(alignment - 1);
}

Expand Down Expand Up @@ -116,7 +117,10 @@ wmem_alloc_aligned(wmem_allocator_t *allocator, const size_t size, int32_t align
}
#endif

if (!r) errno = ENOMEM;
if (!r) {
Alert(AT_Recovery | AG_NoMemory | AO_ExecLib);
errno = ENOMEM;
}
#ifdef MEMORY_DEBUG
else allocs++;
#endif
Expand Down
Loading