Beispiel #1
0
 def call(self):
     if self.debug:
         print(self.args_dl_function_code.value)
     reset_lengths_of_output_fields(self)
     zos_system_call(self)
     self.rc = self.fn_and_rc.value
     self.fn_and_rc.value = self.fn
Beispiel #2
0
def dscb1data_from_dsname_and_volser(dsname,
                                     volser,
                                     debug=False,
                                     svc_args=None,
                                     encoding=None):
    if svc_args is None:
        svc_args = bytearray(5 * 8)
    if encoding is None:
        dsname = codecs.encode("{:44s}".format(dsname), encoding=cp1047_oe)
        volser = codecs.encode("{:6s}".format(volser), encoding=cp1047_oe)
    obtain_search = bytearray_set_address_size(
        bytearray(4 + 4 + 4 + 4 + 44 + 6 + 140), 31)
    struct.pack_into(
        '=IIII' + '44s6s',
        obtain_search,
        0,
        0xC1000000 + 0x801,  # CAMLST_SEARCH + CAMLST_EADSCB_OK
        bytearray_buffer_address(obtain_search) + 4 * 4,
        bytearray_buffer_address(obtain_search) + 4 * 4 + 44,
        bytearray_buffer_address(obtain_search) + 4 * 4 + 44 + 6,
        dsname,
        volser)
    struct.pack_into('QQQQQ', svc_args, 0, 0, 0,
                     bytearray_buffer_address(obtain_search), 27,
                     SYSTEM_CALL__SVC)  # CAMLST OBTAIN
    zos_system_call(svc_args)
    rc = struct.unpack_from('=4xI', svc_args, 0)[0]
    if rc != 0:
        raise OSError("CAMLIST SEARCH returned rc=0x%X" % (rc, ))
    if debug:
        print(
            dump_region(
                bytearray_buffer_address(obtain_search) + 4 * 4 + 44 + 6, 140))
    return (obtain_search, 4 * 4 + 44 + 6)
Beispiel #3
0
 def call(self, request_type, criteria={}, requested_fields=None):
     self.requested_fields = requested_fields
     ssob_and_stat = self.ssob_and_stat
     arglist = self.arglist
     save_area = self.save_area
     ssreq = self.ssreq
     request_types = ('job_terse', 'job_verbose', 'close', 'sysout_terse',
                      'sysout_verbose', 'data_set_list')
     struct.pack_into('B', ssob_and_stat, 0x2C,
                      request_types.index(request_type) + 1)
     for name, value in criteria.items():
         if not value:
             continue
         struct_fmt, position_list, bit_position, bit = criteria_fields[
             name]
         if isinstance(value, str):
             value = codecs.encode(
                 ("{:%ds}" % int(struct_fmt[:-1])).format(value),
                 encoding=cp1047_oe)
         if isinstance(position_list, tuple):
             for position in position_list:
                 struct.pack_into(struct_fmt, ssob_and_stat, position,
                                  value)
         else:
             position = position_list
             struct.pack_into(struct_fmt, ssob_and_stat, position, value)
         ssob_and_stat[bit_position] |= bit
     struct.pack_into('QQQQQ', ssreq, 0, ssreq_fn, 0,
                      bytearray_buffer_address(arglist),
                      bytearray_buffer_address(save_area),
                      SYSTEM_CALL__CALL31)
     zos_system_call(ssreq)
     self.ssi_return_code = struct.unpack_from('=4xI', self.ssreq, 0)[0]
     if self.ssi_return_code != 0:
         error_index = self.ssi_return_code / 4 - 1
         error_messages = (
             "The subsystem does not support this function.",
             "The subsystem exists, but is not active.",
             "The subsystem is not defined to MVS.",
             "Invalid SSOB, SSIB or function code",
             "The SSOB or SSIB have invalid lengths or formats",
             "The SSI has not been initialized.")
         raise Exception(error_messages[errior_index])
     self.subsystem_return_code = struct.unpack_from(
         '=I', ssob_and_stat, 0x0C)[0]  # SSOBRETN
     self.version, self.reason, self.reason2 = struct.unpack_from(
         '=BxBB', self.ssob_and_stat, 0x28)  # STATVER, STATREAS, STATREA2
     if self.ssi_return_code == 4:
         raise Exception("Invalid search arguments")
     elif self.ssi_return_code == 8:
         raise Exception("Logic error, reason=0x%X" % self.reason)
     elif self.ssi_return_code == 12:
         raise Exception("Unsupported call type")
     #print(dump_region(bytearray_buffer_address(ssob_and_stat), len(self.ssob_and_stat)))
     return None
Beispiel #4
0
 def close(self):
     # CLOSE (MYDCB),MODE=31
     a24 = self.a24
     bldl_list = self.bldl_list
     close_args = bytearray_set_address_size(bytearray(8), 31)
     struct.pack_into('=B3xI', close_args, 0,
                         0x80, bytearray_buffer_address(a24) + dcb_offset)
     struct.pack_into('QQQQQ', self.svc_args, 0,
                      0, bytearray_buffer_address(close_args), 0,
                      20, SYSTEM_CALL__SVC) 
     zos_system_call(self.svc_args)
     rc = struct.unpack_from('Q', self.svc_args, 0)
Beispiel #5
0
 def bldl(self, name):
     a24 = self.a24
     # BLDL bldl_list,dcb
     self.bldl_list = bytearray_set_address_size(bytearray(72), 31)
     bldl_list = self.bldl_list
     struct.pack_into('=HH8s', self.bldl_list, 0,
                         1, 68, codecs.encode("{:8s}".format(name), encoding=cp1047_oe) )
     if self.verbose:
         print(["%08X" % v for v in struct.unpack_from('III', self.bldl_list, 0)])
     struct.pack_into('QQQQQ', self.svc_args, 0,
                      0, bytearray_buffer_address(bldl_list), bytearray_buffer_address(a24) + dcb_offset,
                      18, SYSTEM_CALL__SVC) 
     zos_system_call(self.svc_args)
     rc, reason = struct.unpack_from('7xB7xB', self.svc_args, 0)
     if rc > 0:
         raise OSError("BLDL failed for %s, rc=%X, reason=%X" % (self.name, rc, reason))
Beispiel #6
0
 def load(self):
     # LOAD DE=bldl_list,DCB=dcb,ERRRET=NEXT
     a24 = self.a24
     bldl_list = self.bldl_list
     struct.pack_into('QQQQQ', self.svc_args, 0,
                      0, bytearray_buffer_address(bldl_list)+4, 0x80000000 + (bytearray_buffer_address(a24) + dcb_offset),
                      8, SYSTEM_CALL__SVC) 
     zos_system_call(self.svc_args)
     #unsigned int r15; /* good:0                         bad:returnCode */
     #unsigned int r0;  /* good:ep_including_amode        bad:n/a  */
     #unsigned int r1;  /* good:apf+length_in_doublewords bad:reasonCode */
     codes = struct.unpack_from("4xI8x4xI", self.svc_args, 0) # ignore the high order 32 bits
     if codes[0] == 0:
         self.ep = struct.unpack_from("4xI", self.svc_args, 1*8)[0]
     else:
         raise OSError("LOAD return_code=%X, reason_code=%X" % codes)
Beispiel #7
0
 def open(self):
     # OPEN (dcb,(INPUT)),MODE=31
     a24 = self.a24
     open_args = bytearray_set_address_size(bytearray(8), 31)
     struct.pack_into('=B3xI', open_args, 0,
                         0x80, bytearray_buffer_address(a24) + dcb_offset)
     struct.pack_into('QQQQQ', self.svc_args, 0,
                      0, bytearray_buffer_address(open_args), 0,
                      19, SYSTEM_CALL__SVC) 
     zos_system_call(self.svc_args)
     rc = struct.unpack_from('7xB', self.svc_args, 0)[0]
     if rc > 4:
         abend_code = struct.unpack_from('I', a24, 0)[0]
         if abend_code:
             raise OSError("OPEN abend %X" % abend_code)
         else:
             raise OSError("OPEN failed, rc=%X" % rc)
Beispiel #8
0
 def __next__(self):
     BPX1GTH_args = self.BPX1GTH_args
     rc = struct.unpack_from('i', BPX1GTH_args, 9 * 8 + 2 * 4)[0]
     if rc == -1:
         raise StopIteration()
     struct.pack_into('QQQQQ', self.call_args, 0, BPX1GTH_addr, 0,
                      bytearray_buffer_address(BPX1GTH_args), 0,
                      SYSTEM_CALL__CALL)
     zos_system_call(self.call_args)
     rc = struct.unpack_from('I', BPX1GTH_args, 9 * 8 + 2 * 4)[0]
     if rc == -1:
         raise StopIteration()
     self.move_next_from_pgthb_to_pgtha()
     if self.pid and self.pid != self.pgtha_pid:
         raise StopIteration()
     if self.thid and self.thid != self.pgtha_thid:
         raise StopIteration()
     return self.extract_data_from_pgthb()
Beispiel #9
0
def volser_from_dsname(dsname, svc_args=None, encoding=None):
    if svc_args is None:
        svc_args = bytearray(5 * 8)
    if encoding is None:
        dsname = codecs.encode("{:44s}".format(dsname), encoding=cp1047_oe)
    locate = bytearray_set_address_size(
        bytearray(4 + 4 + 4 + 4 + 44 + 4 + 265), 31)
    struct.pack_into('=IIII' + '44s', locate, 0, 0x44000000,
                     bytearray_buffer_address(locate) + 4 * 4, 0,
                     bytearray_buffer_address(locate) + 4 * 4 + 44 + 4, dsname)
    struct.pack_into('QQQQQ', svc_args, 0, 0, 0,
                     bytearray_buffer_address(locate), 26,
                     SYSTEM_CALL__SVC)  # LOCATE
    zos_system_call(svc_args)
    rc = struct.unpack_from('=4xI', svc_args, 0)[0]
    if rc != 0:
        raise OSError("LOCATE NAME returned rc=0x%X" % (rc, ))
    volser = struct.unpack_from('6s', locate, 4 * 4 + 44 + 4 + 2 + 4)[0]
    if encoding is None:
        volser = codecs.decode(volser_ebcdic, cp1047_oe)
    locate = None
    return volser
Beispiel #10
0
def load(name):
    name_buffer = bytearray_set_address_size(bytearray(8), 31)
    struct.pack_into("8s", name_buffer, 0, codecs.encode("{:8s}".format(name), encoding=cp1047_oe))
    
    load_params = bytearray_set_address_size(bytearray(3*4), 31)
    struct.pack_into('IIBBBB', load_params, 0,
                     bytearray_buffer_address(name_buffer), 0, 0, 0, 0x20, 0)

    svc_args = bytearray(5*8)
    struct.pack_into('QQQQQ', svc_args, 0,
                     9, 0, bytearray_buffer_address(load_params),
                     122, SYSTEM_CALL__SVC)

    zos_system_call(svc_args)
    
    #unsigned int r15; /* good:0                         bad:returnCode */
    #unsigned int r0;  /* good:ep_including_amode        bad:n/a  */
    #unsigned int r1;  /* good:apf+length_in_doublewords bad:reasonCode */
    codes = struct.unpack_from("4xI8x4xI", svc_args, 0) # ignore the high order 32 bits
    if codes[0] == 0:
        return struct.unpack_from("4xI", svc_args, 1*8)[0]
    else:
        raise OSError("LOAD return_code=%X, reason_code=%X" % codes)
Beispiel #11
0
def dynallocInternal(verb,
                     text_unit_mapping,
                     flags1=0,
                     flags2=0,
                     verbose=False,
                     message_level=0,
                     message_function=print_message):
    keyword_definitions = text_keyword_definitions[verb]
    text_unit_array_size = process_text_units(text_unit_mapping,
                                              keyword_definitions,
                                              None,
                                              verbose=verbose)
    if verbose:
        print("test_unit_array_size = %r" % text_unit_array_size)
    text_unit_array = bytearray_set_address_size(
        bytearray(text_unit_array_size), 31)
    process_text_units(text_unit_mapping,
                       keyword_definitions,
                       text_unit_array,
                       verbose=verbose)
    if verbose:
        show_text_units(text_unit_array)

    message_severity_level = 0  # informational, that is, include all the messages
    message_block_subpool = 4
    message_options = 0x48  # return message to caller + specified subpool

    svc99rbx = bytearray_set_address_size(bytearray(36), 31)
    struct.pack_into(
        'BBBBBBBBBBB',
        svc99rbx,
        0,
        0xE2,
        0xF9,
        0xF9,
        0xD9,
        0xC2,
        0xE7,
        1,  #'S99RBX', version
        message_options,
        message_block_subpool,
        8,
        message_severity_level)

    svc99rb = bytearray_set_address_size(bytearray(20), 31)
    struct.pack_into('BBHHHIII', svc99rb, 0, 20, verb_codes[verb], flags1, 0,
                     0, bytearray_buffer_address(text_unit_array),
                     bytearray_buffer_address(svc99rbx), flags2)

    svc99plist = bytearray_set_address_size(bytearray(4), 31)
    struct.pack_into('I', svc99plist, 0,
                     0x80000000 | bytearray_buffer_address(svc99rb))

    svc_args = bytearray(5 * 8)
    struct.pack_into('QQQQQ', svc_args, 0, 0, 0,
                     bytearray_buffer_address(svc99plist), 99,
                     SYSTEM_CALL__SVC)

    zos_system_call(svc_args)
    svc99_rc = struct.unpack_from('L', svc_args, 0)[0]

    if verbose:
        s99error_and_info = struct.unpack_from('HH', svc99rb, 4)
        print("s99rc=%X, error=%04X, info=%04X" %
              (svc99_rc, s99error_and_info[0], s99error_and_info[1]))
        show_text_units(text_unit_array)
    retrieve_dynalloc_messages(message_function,
                               verb,
                               keyword_definitions,
                               svc99rbx,
                               svc99rb,
                               svc_args,
                               verbose=verbose)

    output_mapping = process_text_units(text_unit_mapping,
                                        keyword_definitions,
                                        text_unit_array,
                                        tu_input=False,
                                        verbose=verbose)
    return (svc99_rc, output_mapping)
Beispiel #12
0
def retrieve_dynalloc_messages(message_function,
                               verbName,
                               keyword_definitions,
                               svc99rbx,
                               svc99rb,
                               svc_args,
                               verbose=False):
    svc99_rc = struct.unpack_from('L', svc_args, 0)[0]
    s99error = struct.unpack_from('H', svc99rb, 4)[0]
    s99info = struct.unpack_from('H', svc99rb, 6)[0]
    if svc99_rc != 0:
        message_function("%s failed, return code=%d, error=%04X, info=%04X" %
                         (verbName, svc99_rc, s99error, s99info))
    block_count = svc99rbx[11]
    if verbose:
        print("s99rbx message_count = %d" % block_count)
    if block_count == 0:
        return
    if block_count > MAX_EM_MESSAGES:
        block_count = MAX_EM_MESSAGES

    emMessages = bytearray_set_address_size(bytearray(256 * block_count), 31)

    emCall = bytearray_set_address_size(bytearray(28), 31)
    struct.pack_into('BBBxII4xI', emCall, 0, 0x20, 50, block_count,
                     bytearray_buffer_address(svc99rb), svc99_rc,
                     bytearray_buffer_address(emMessages))
    if verbose:
        print(["%08X" % v for v in struct.unpack_from('IIIII', emCall, 0)])

    emCallPlist = bytearray_set_address_size(bytearray(4), 31)
    struct.pack_into('I', emCallPlist, 0,
                     0x80000000 | bytearray_buffer_address(emCall))

    save_area = bytearray_set_address_size(bytearray(18 * 4), 31)

    call_args = bytearray(5 * 8)
    struct.pack_into('QQQQQ', call_args, 0, get_IEFDB476(), 0,
                     bytearray_buffer_address(emCallPlist),
                     bytearray_buffer_address(save_area), SYSTEM_CALL__CALL31)

    zos_system_call(call_args)
    IEFDB476_rc = struct.unpack_from('Q', call_args, 0)[0]
    if verbose:
        print("IEFDB476_rc=%X" % IEFDB476_rc)

    if verbose:
        print(
            ["%X" % v for v in struct.unpack_from('xxBBIIHHI', svc99rbx, 16)])
        print(["%X" % v for v in struct.unpack_from('BBBxII4xI', emCall, 0)])
        print("block_count=%X" % block_count)
    for i in range(block_count):
        message_length = struct.unpack_from('H', emMessages, 256 * i)[0]
        if verbose:
            print('message_length=%d' % message_length)
        message_text = emMessages[256 * i + 4:256 * i + 4 + message_length]
        message = str.rstrip(codecs.decode(message_text, cp1047_oe))
        message_function(message)

    if s99error == 0x035C:  # Invalid PARM specified in text unit, with corresponding message IKJ56231I
        info = keyword_definitions[s99info]
        if info:
            message_function("text unit %04X is %s %s" %
                             (s99info, info[0][0], info[0][2]))