Paste: bad ffi call
Author: | erg |
Mode: | factor |
Date: | Sun, 19 Sep 2010 00:21:56 |
Plain Text |
//put into string.[hc]pp lol
VM_C_API int my_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
VM_C_API int my_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
{
printf("%p, %d, %p, %p, %p, %d\n", name, (int)namelen, oldp, oldlenp, newp, (int)newlen);
//return sysctl(name, namelen, oldp, oldlenp, newp, newlen);
if(oldlenp)
{
if(oldp)
{
//for(int i = 0; i < *oldlenp; i++)
//(((char*)oldp)[i]) = 1;
}
*oldlenp = 45360;
}
return 0;
}
USING: alien alien.c-types alien.data alien.syntax byte-arrays
classes.struct generalizations kernel literals locals math
sequences specialized-arrays unix unix.ffi unix.time unix.types ;
FUNCTION: int sysctl ( int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen ) ;
FUNCTION: int my_sysctl ( int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen ) ;
CONSTANT: CTL_KERN 1
CONSTANT: KERN_PROC 14
CONSTANT: KERN_PROC_ALL 0
SPECIALIZED-ARRAY: int
FROM: alien.c-types => short ;
: sysctl-enum-processes ( -- obj )
int-array{ $ CTL_KERN $ KERN_PROC $ KERN_PROC_ALL 0 } ;
: get-buffer-size ( -- n )
sysctl-enum-processes
[ ]
[ length 1 - f ]
[ length <int> f 0 ] tri
[ my_sysctl io-error ] 3keep 2drop *uint ;
:: get-result ( len -- byte-array n )
sysctl-enum-processes
[ ]
[ length 1 - len <byte-array> ] bi
len <int> f 0
[ my_sysctl io-error ] 4 nkeep 2drop *uint ;
: list-processes ( -- seq )
get-buffer-size get-result head kinfo_proc-array-cast ;
New Annotation