Provide Mac_sysalloc() and Mac_sysfree() for memory allocation in MacOS

system heap zone. Use them for network related data dynamically allocated.

TODO: check performance in emulated mode!
This commit is contained in:
gbeauche 2004-05-10 16:16:26 +00:00
parent f32e5ee9ab
commit 21607e19ad
3 changed files with 47 additions and 4 deletions

View File

@ -86,7 +86,7 @@ struct DLPIStream {
void AddMulticast(uint8 *addr)
{
multicast_node *n = new multicast_node;
multicast_node *n = (multicast_node *)Mac_sysalloc(sizeof(multicast_node));
memcpy(n->addr, addr, kEnetPhysicalAddressLength);
n->next = multicast_list;
multicast_list = n;
@ -106,7 +106,7 @@ struct DLPIStream {
while (q) {
if (q->next == p) {
q->next = p->next;
delete p;
Mac_sysfree(p);
return;
}
q = q->next;
@ -1542,7 +1542,7 @@ static void DLPI_enable_multi(DLPIStream *the_stream, queue_t *q, mblk_t *mp)
AO_enable_multicast(reqaddr);
// Add new address to multicast list
uint8 *addr = new uint8[kEnetPhysicalAddressLength];
uint8 *addr = (uint8 *)Mac_sysalloc(kEnetPhysicalAddressLength);
OTCopy48BitAddress(reqaddr, addr);
the_stream->AddMulticast(addr);
@ -1580,7 +1580,7 @@ static void DLPI_disable_multi(DLPIStream *the_stream, queue_t *q, mblk_t *mp)
// Found, then remove
the_stream->RemoveMulticast(addr);
delete addr;
Mac_sysfree(addr);
// Tell add-on to disable multicast address
AO_disable_multicast(reqaddr);

View File

@ -357,6 +357,8 @@ extern void *FindLibSymbol(char *lib, char *sym); // Find symbol in shared libr
extern void InitCallUniversalProc(void); // Init CallUniversalProc()
extern long CallUniversalProc(void *upp, uint32 info); // CallUniversalProc()
extern uint32 TimeToMacTime(time_t t); // Convert time_t value to MacOS time
extern void *Mac_sysalloc(uint32 size); // Allocate block in MacOS system heap zone
extern void Mac_sysfree(void * p); // Release block occupied by the nonrelocatable block p
// Construct four-character-code from string
#define FOURCC(a,b,c,d) (((uint32)(a) << 24) | ((uint32)(b) << 16) | ((uint32)(c) << 8) | (uint32)(d))

View File

@ -58,6 +58,18 @@ static inline int16 CloseConnection(uint32 *arg1)
{
return (int16)CallMacOS1(cc_ptr, cc_tvect, arg1);
}
typedef void *(*nps_ptr)(uint32);
static uint32 nps_tvect = 0;
static inline void *NewPtrSys(uint32 arg1)
{
return (void *)CallMacOS1(nps_ptr, nps_tvect, arg1);
}
typedef void (*d_ptr)(void *);
static uint32 d_tvect = 0;
static inline void DisposePtr(void *arg1)
{
CallMacOS1(d_ptr, d_tvect, arg1);
}
/*
@ -270,6 +282,20 @@ void InitCallUniversalProc()
printf("FATAL: Can't find CloseConnection()\n");
QuitEmulator();
}
nps_tvect = (uint32)FindLibSymbol("\014InterfaceLib", "\011NewPtrSys");
D(bug("NewPtrSys TVECT at %08lx\n", nps_tvect));
if (nps_tvect == 0) {
printf("FATAL: Can't find NewPtrSys()\n");
QuitEmulator();
}
d_tvect = (uint32)FindLibSymbol("\014InterfaceLib", "\012DisposePtr");
D(bug("DisposePtr TVECT at %08lx\n", d_tvect));
if (d_tvect == 0) {
printf("FATAL: Can't find DisposePtr()\n");
QuitEmulator();
}
}
@ -309,3 +335,18 @@ uint32 TimeToMacTime(time_t t)
uint32 days = local->tm_yday + 365 * (local->tm_year - 4) + intervening_leap_days;
return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * days));
}
/*
* Memory allocators in MacOS system heap zone
*/
void *Mac_sysalloc(uint32 size)
{
return NewPtrSys(size);
}
void Mac_sysfree(void *p)
{
DisposePtr(p);
}